From: Nathan Sidwell Date: Wed, 8 Aug 2018 17:26:45 +0000 (+0000) Subject: internal.h (_cpp_notify_macro_use): Declare. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2b2bcdcab0f4bfc41335b8e89fa66f3bbfb22199;p=thirdparty%2Fgcc.git internal.h (_cpp_notify_macro_use): Declare. 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. From-SVN: r263428 --- diff --git a/ChangeLog.name-lookup b/ChangeLog.name-lookup index 03437a968a84..91d282159f1a 100644 --- a/ChangeLog.name-lookup +++ b/ChangeLog.name-lookup @@ -1,5 +1,17 @@ 2018-08-08 Nathan Sidwell + 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. diff --git a/libcpp/directives.c b/libcpp/directives.c index 7c707b70d87c..35055872771d 100644 --- a/libcpp/directives.c +++ b/libcpp/directives.c @@ -1963,22 +1963,7 @@ do_ifdef (cpp_reader *pfile) 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); @@ -2008,22 +1993,7 @@ do_ifndef (cpp_reader *pfile) 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); diff --git a/libcpp/expr.c b/libcpp/expr.c index 58d65d50ac30..c8882804612c 100644 --- a/libcpp/expr.c +++ b/libcpp/expr.c @@ -1065,22 +1065,7 @@ parse_defined (cpp_reader *pfile) "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. */ diff --git a/libcpp/internal.h b/libcpp/internal.h index c4df933c898b..e03b2ea3681c 100644 --- a/libcpp/internal.h +++ b/libcpp/internal.h @@ -622,13 +622,11 @@ cpp_in_primary_file (cpp_reader *pfile) } /* 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 *); diff --git a/libcpp/macro.c b/libcpp/macro.c index 80b90f4ff44e..e88a5885fc81 100644 --- a/libcpp/macro.c +++ b/libcpp/macro.c @@ -1276,7 +1276,7 @@ enter_macro_context (cpp_reader *pfile, cpp_hashnode *node, 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) @@ -1320,13 +1320,9 @@ enter_macro_context (cpp_reader *pfile, cpp_hashnode *node, /* 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); @@ -3003,7 +2999,14 @@ warn_of_redefinition (cpp_reader *pfile, cpp_hashnode *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). */ @@ -3559,14 +3562,39 @@ cpp_define_lazily (cpp_reader *pfile, cpp_hashnode *node, unsigned num) 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