]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
internal.h (_cpp_notify_macro_use): Declare.
authorNathan Sidwell <nathan@acm.org>
Wed, 8 Aug 2018 17:26:45 +0000 (17:26 +0000)
committerNathan Sidwell <nathan@gcc.gnu.org>
Wed, 8 Aug 2018 17:26:45 +0000 (17:26 +0000)
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

ChangeLog.name-lookup
libcpp/directives.c
libcpp/expr.c
libcpp/internal.h
libcpp/macro.c

index 03437a968a84d1520e9e24ba1cca1744c570f2c0..91d282159f1a65da581ed528897436bf00a18407 100644 (file)
@@ -1,5 +1,17 @@
 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.
index 7c707b70d87cdcc3af2b4a359a7ef2f807df6707..35055872771ddc23b5e3d48d674c37d68f8059ed 100644 (file)
@@ -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);
index 58d65d50ac30ed2c2ea1452d27b67c39a46e57a7..c8882804612c254e2cd9a7b593faf35b2fcd60dd 100644 (file)
@@ -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.  */
index c4df933c898bdfd86cbb76cbbfb573dbff7160ad..e03b2ea3681cc227e197bbcb3f6eb4e61d0ded5d 100644 (file)
@@ -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 *);
index 80b90f4ff44ef5f005c81f85722fdf5f4dce4325..e88a5885fc815513e59029502eb6ad2f1504bf94 100644 (file)
@@ -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