2018-08-08 Nathan Sidwell <nathan@acm.org>
+ libcpp/
+ * internal.h (_cpp_notify_macro_use): Declare.
+ (_cpp_maybe_notify_macro_use): Define.
+ (_cpp_do_lazy_macro, _cpp_maybe_lazy_macro): Delete.
+ * directives.c (do_ifdef, do_ifndef): Call
+ _cpp_maybe_notify_macro_use.
+ * expr.c (parse_defined): Likewise.
+ * macro.c (enter_macro_context): Use _cpp_maybe_notify_macro_use.
+ (warn_of_redefinition): Do lazy definition explicitly.
+ (_cpp_notify_macro_use): Define.
+ (_cpp_do_lazy_macro): Delete.
+
Move NODE_BUILTIN to NT_BUILTIN.
gcc/c-family/
* c-ppoutput.c (cb_used_define): Use cpp_macro_p.
skip = (node->type == NT_VOID
|| ((node->flags & NODE_CONDITIONAL) != 0));
_cpp_mark_macro_used (node);
- if (!(node->flags & NODE_USED))
- {
- node->flags |= NODE_USED;
- if (node->type & NT_MACRO)
- {
- if (node->type == NT_MACRO)
- _cpp_maybe_lazy_macro (pfile, node);
- if (pfile->cb.used_define)
- pfile->cb.used_define (pfile, pfile->directive_line, node);
- }
- else
- {
- if (pfile->cb.used_undef)
- pfile->cb.used_undef (pfile, pfile->directive_line, node);
- }
- }
+ _cpp_maybe_notify_macro_use (pfile, node);
if (pfile->cb.used)
pfile->cb.used (pfile, pfile->directive_line, node);
check_eol (pfile, false);
skip = (node->type != NT_VOID
&& ((node->flags & NODE_CONDITIONAL) == 0));
_cpp_mark_macro_used (node);
- if (!(node->flags & NODE_USED))
- {
- node->flags |= NODE_USED;
- if (node->type & NT_MACRO)
- {
- if (node->type == NT_MACRO)
- _cpp_maybe_lazy_macro (pfile, node);
- if (pfile->cb.used_define)
- pfile->cb.used_define (pfile, pfile->directive_line, node);
- }
- else
- {
- if (pfile->cb.used_undef)
- pfile->cb.used_undef (pfile, pfile->directive_line, node);
- }
- }
+ _cpp_maybe_notify_macro_use (pfile, node);
if (pfile->cb.used)
pfile->cb.used (pfile, pfile->directive_line, node);
check_eol (pfile, false);
"this use of \"defined\" may not be portable");
_cpp_mark_macro_used (node);
- if (!(node->flags & NODE_USED))
- {
- node->flags |= NODE_USED;
- if (node->type & NT_MACRO)
- {
- if (node->type == NT_MACRO)
- _cpp_maybe_lazy_macro (pfile, node);
- if (pfile->cb.used_define)
- pfile->cb.used_define (pfile, pfile->directive_line, node);
- }
- else
- {
- if (pfile->cb.used_undef)
- pfile->cb.used_undef (pfile, pfile->directive_line, node);
- }
- }
+ _cpp_maybe_notify_macro_use (pfile, node);
/* A possible controlling macro of the form #if !defined ().
_cpp_parse_expr checks there was no other junk on the line. */
}
/* In macro.c */
-extern cpp_macro *_cpp_do_lazy_macro (cpp_reader *pfile, cpp_macro *macro);
-inline cpp_macro *_cpp_maybe_lazy_macro (cpp_reader *pfile, cpp_hashnode *node)
+extern void _cpp_notify_macro_use (cpp_reader *pfile, cpp_hashnode *node);
+inline void _cpp_maybe_notify_macro_use (cpp_reader *pfile, cpp_hashnode *node)
{
- cpp_macro *macro = node->value.macro;
- if (macro->lazy)
- macro = _cpp_do_lazy_macro (pfile, macro);
- return macro;
+ if (!(node->flags & NODE_USED))
+ _cpp_notify_macro_use (pfile, node);
}
extern cpp_macro *_cpp_new_macro (cpp_reader *, cpp_macro_kind, void *);
extern void _cpp_free_definition (cpp_hashnode *);
if (node->type == NT_MACRO)
{
- cpp_macro *macro = _cpp_maybe_lazy_macro (pfile, node);
+ cpp_macro *macro = node->value.macro;
_cpp_buff *pragma_buff = NULL;
if (macro->fun_like)
/* Disable the macro within its expansion. */
node->flags |= NODE_DISABLED;
- if (!(node->flags & NODE_USED))
- {
- node->flags |= NODE_USED;
- if (pfile->cb.used_define)
- pfile->cb.used_define (pfile, pfile->directive_line, node);
- }
-
+ /* Laziness can only affect the expansion tokens of the macro,
+ not its fun-likeness or parameters. */
+ _cpp_maybe_notify_macro_use (pfile, node);
if (pfile->cb.used)
pfile->cb.used (pfile, location, node);
if (node->flags & NODE_CONDITIONAL)
return false;
- const cpp_macro *macro1 = _cpp_maybe_lazy_macro (pfile, node);
+ cpp_macro *macro1 = node->value.macro;
+ if (macro1->lazy)
+ {
+ /* We don't want to mark MACRO as used, but do need to finalize
+ its laziness. */
+ pfile->cb.user_lazy_macro (pfile, macro1, macro1->lazy - 1);
+ macro1->lazy = 0;
+ }
/* Redefinition of a macro is allowed if and only if the old and new
definitions are the same. (6.10.3 paragraph 2). */
macro->lazy = num + 1;
}
-extern cpp_macro *
-_cpp_do_lazy_macro (cpp_reader *pfile, cpp_macro *macro)
+/* Notify the use of NODE in a macro-aware context (i.e. expanding it,
+ or testing its existance). Also applies any lazy definition. */
+
+extern void
+_cpp_notify_macro_use (cpp_reader *pfile, cpp_hashnode *node)
{
- unsigned num = macro->lazy - 1;
- macro->lazy = 0;
- pfile->cb.user_lazy_macro (pfile, macro, num);
+ node->flags |= NODE_USED;
+ switch (node->type)
+ {
+ case NT_MACRO:
+ {
+ cpp_macro *macro = node->value.macro;
+ if (macro->lazy)
+ {
+ pfile->cb.user_lazy_macro (pfile, macro, macro->lazy - 1);
+ macro->lazy = 0;
+ }
+ }
+ /* FALLTHROUGH. */
- return macro;
+ case NT_BUILTIN:
+ if (pfile->cb.used_define)
+ pfile->cb.used_define (pfile, pfile->directive_line, node);
+ break;
+
+ case NT_VOID:
+ if (pfile->cb.used_undef)
+ pfile->cb.used_undef (pfile, pfile->directive_line, node);
+ break;
+
+ default:
+ abort ();
+ }
}
/* Warn if a token in STRING matches one of a function-like MACRO's