]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
cpplib.h (enum node_type): Remove NT_ASSERTION.
authorNathan Sidwell <nathan@acm.org>
Thu, 2 Aug 2018 20:44:34 +0000 (20:44 +0000)
committerNathan Sidwell <nathan@gcc.gnu.org>
Thu, 2 Aug 2018 20:44:34 +0000 (20:44 +0000)
libcpp/
* include/cpplib.h (enum node_type): Remove NT_ASSERTION.
(NTV_NONE): Delete.
(CPP_HASHNODE_VALUE_IDX): Adjust.
* macro.c (_cpp_free_definition): Zap macro pointer.
(_cpp_create_definition): Move _cpp_free_definition call.
* directives.c (find_answer): Initialize result.
(_cpp_test_assertion): Check macro pointer.
(do_assert): Likewise.
(do_unassert): Don't node type.
* pch.c (write_macdef, count_Defs, write_defs)
(save_macros): Adjust fo loss of NT_ASSERTION.

From-SVN: r263278

ChangeLog.name-lookup
libcpp/directives.c
libcpp/include/cpplib.h
libcpp/macro.c
libcpp/pch.c

index 4b7dd0b71c99ff66d80517f1e825ed2e8e418e21..a5a6a0a027673b446460e6c70201d3e29632cdbb 100644 (file)
@@ -1,5 +1,18 @@
 2018-08-02  Nathan Sidwell  <nathan@acm.org>
 
+       libcpp/
+       * include/cpplib.h (enum node_type): Remove NT_ASSERTION.
+       (NTV_NONE): Delete.
+       (CPP_HASHNODE_VALUE_IDX): Adjust.
+       * macro.c (_cpp_free_definition): Zap macro pointer.
+       (_cpp_create_definition): Move _cpp_free_definition call.
+       * directives.c (find_answer): Initialize result.
+       (_cpp_test_assertion): Check macro pointer.
+       (do_assert): Likewise.
+       (do_unassert): Don't node type.
+       * pch.c (write_macdef, count_Defs, write_defs)
+       (save_macros): Adjust fo loss of NT_ASSERTION.
+
        Asserts are now macro variants
        libcpp/
        * directives.c (parse_answer, parse_assertion, find_answer): Use
index 976c87c02dc2846406729da344d5b46a41045125..9232f8383d7c8a5f4ae112ceab731da42bc37be5 100644 (file)
@@ -2290,7 +2290,7 @@ static cpp_macro **
 find_answer (cpp_hashnode *node, const cpp_macro *candidate)
 {
   unsigned int i;
-  cpp_macro **result;
+  cpp_macro **result = NULL;
 
   for (result = &node->value.macro; *result; result = &(*result)->parm.next)
     {
@@ -2325,8 +2325,10 @@ _cpp_test_assertion (cpp_reader *pfile, unsigned int *value)
   *value = 0;
 
   if (node)
-    *value = (node->type == NT_ASSERTION &&
-             (answer == 0 || *find_answer (node, answer) != 0));
+    {
+      if (node->value.macro)
+       *value = !answer || *find_answer (node, answer);
+    }
   else if (pfile->cur_token[-1].type == CPP_EOF)
     _cpp_backup_tokens (pfile, 1);
 
@@ -2343,19 +2345,13 @@ do_assert (cpp_reader *pfile)
 
   if (node)
     {
-      cpp_macro *next = NULL;
-
       /* Place the new answer in the answer list.  First check there
          is not a duplicate.  */
-      if (node->type == NT_ASSERTION)
+      if (*find_answer (node, answer))
        {
-         if (*find_answer (node, answer))
-           {
-             cpp_error (pfile, CPP_DL_WARNING, "\"%s\" re-asserted",
-                        NODE_NAME (node) + 1);
-             return;
-           }
-         next = node->value.macro;
+         cpp_error (pfile, CPP_DL_WARNING, "\"%s\" re-asserted",
+                    NODE_NAME (node) + 1);
+         return;
        }
 
       /* Commit or allocate storage for the answer.  */
@@ -2363,9 +2359,9 @@ do_assert (cpp_reader *pfile)
        (pfile, sizeof (cpp_macro) - sizeof (cpp_token)
         + sizeof (cpp_token) * answer->count);
 
-      answer->parm.next = next;
+      answer->parm.next = node->value.macro;
 
-      node->type = NT_ASSERTION;
+      node->type = NT_MACRO;
       node->value.macro = answer;
 
       check_eol (pfile, false);
@@ -2376,12 +2372,11 @@ do_assert (cpp_reader *pfile)
 static void
 do_unassert (cpp_reader *pfile)
 {
-  cpp_hashnode *node;
   cpp_macro *answer;
+  cpp_hashnode *node = parse_assertion (pfile, T_UNASSERT, &answer);
 
-  node = parse_assertion (pfile, T_UNASSERT, &answer);
   /* It isn't an error to #unassert something that isn't asserted.  */
-  if (node && node->type == NT_ASSERTION)
+  if (node)
     {
       if (answer)
        {
index 1873e6a0af34279cf0ced7b1de892cd419e734f1..810e3bd45f69831dd7cb503fac773875516801bc 100644 (file)
@@ -673,7 +673,7 @@ struct cpp_dir
 /* The structure of a node in the hash table.  The hash table has
    entries for all identifiers: either macros defined by #define
    commands (type NT_MACRO), assertions created with #assert
-   (NT_ASSERTION), or neither of the above (NT_VOID).  Builtin macros
+   (NT_MACRO), or neither of the above (NT_VOID).  Builtin macros
    like __LINE__ are flagged NODE_BUILTIN.  Poisoned identifiers are
    flagged NODE_POISONED.  NODE_OPERATOR (C++ only) indicates an
    identifier that behaves like an operator such as "xor".
@@ -698,8 +698,7 @@ struct cpp_dir
 enum node_type
 {
   NT_VOID = 0,    /* No definition yet.  */
-  NT_MACRO,       /* A macro of some form.  */
-  NT_ASSERTION    /* Predicate for #assert.  */
+  NT_MACRO        /* A macro or assert.  */
 };
 
 /* Different flavors of builtin macro.  _Pragma is an operator, but we
@@ -731,16 +730,13 @@ enum cpp_builtin_type
 enum {
   NTV_MACRO,
   NTV_BUILTIN,
-  NTV_ARGUMENT,
-  NTV_NONE
+  NTV_ARGUMENT
 };
 
 #define CPP_HASHNODE_VALUE_IDX(HNODE)                          \
-  ((HNODE.flags & NODE_MACRO_ARG) ? NTV_ARGUMENT               \
-   : HNODE.type == NT_MACRO ? ((HNODE.flags & NODE_BUILTIN)    \
-                              ? NTV_BUILTIN : NTV_MACRO)       \
-   : HNODE.type == NT_ASSERTION ? NTV_MACRO                    \
-   : NTV_NONE)
+  ((HNODE).flags & NODE_MACRO_ARG ? NTV_ARGUMENT               \
+   : (HNODE).flags & NODE_BUILTIN ? NTV_BUILTIN                        \
+   : NTV_MACRO)
 
 /* The common part of an identifier node shared amongst all 3 C front
    ends.  Also used to store CPP identifiers, which are a superset of
index c2f5b0d4950d3d88340cfc189ec8632c5e1a06d6..96841bc6ecfbafe52fed655bdc1642a694404432 100644 (file)
@@ -3057,6 +3057,7 @@ _cpp_free_definition (cpp_hashnode *h)
   h->type = NT_VOID;
   /* Clear builtin flag in case of redefinition.  */
   h->flags &= ~(NODE_BUILTIN | NODE_DISABLED | NODE_USED);
+  h->value.macro = NULL;
 }
 
 /* Save parameter NODE (spelling SPELLING) to the parameter list of
@@ -3540,11 +3541,9 @@ _cpp_create_definition (cpp_reader *pfile, cpp_hashnode *node)
                                 node->value.macro->line, 0,
                         "this is the location of the previous definition");
        }
+      _cpp_free_definition (node);
     }
 
-  if (node->type != NT_VOID)
-    _cpp_free_definition (node);
-
   /* Enter definition in hash table.  */
   node->type = NT_MACRO;
   node->value.macro = macro;
index 997c4da5faaf1be48cd7185106141196799ab0ee..88bbdc5eb2a2181955fa8ddfdc56ffcb08da76df 100644 (file)
@@ -59,9 +59,13 @@ write_macdef (cpp_reader *pfile, cpp_hashnode *hn, void *file_p)
       /* FALLTHRU */
 
     case NT_MACRO:
-      if ((hn->flags & NODE_BUILTIN)
-         && (!pfile->cb.user_builtin_macro
-             || !pfile->cb.user_builtin_macro (pfile, hn)))
+      if (hn->flags & NODE_BUILTIN)
+       {
+         if (!pfile->cb.user_builtin_macro
+             || !pfile->cb.user_builtin_macro (pfile, hn))
+           return 1;
+       }
+      else if (hn->value.macro->kind == cmk_assert)
        return 1;
 
       {
@@ -92,10 +96,6 @@ write_macdef (cpp_reader *pfile, cpp_hashnode *hn, void *file_p)
       }
       return 1;
 
-    case NT_ASSERTION:
-      /* Not currently implemented.  */
-      return 1;
-
     default:
       abort ();
     }
@@ -231,6 +231,8 @@ count_defs (cpp_reader *pfile ATTRIBUTE_UNUSED, cpp_hashnode *hn, void *ss_p)
     case NT_MACRO:
       if (hn->flags & NODE_BUILTIN)
        return 1;
+      if (hn->value.macro->kind == cmk_assert)
+       return 1;
 
       /* fall through.  */
 
@@ -250,10 +252,6 @@ count_defs (cpp_reader *pfile ATTRIBUTE_UNUSED, cpp_hashnode *hn, void *ss_p)
       }
       return 1;
 
-    case NT_ASSERTION:
-      /* Not currently implemented.  */
-      return 1;
-
     default:
       abort ();
     }
@@ -270,6 +268,8 @@ write_defs (cpp_reader *pfile ATTRIBUTE_UNUSED, cpp_hashnode *hn, void *ss_p)
     case NT_MACRO:
       if (hn->flags & NODE_BUILTIN)
        return 1;
+      if (hn->value.macro->kind == cmk_assert)
+       return 1;
 
       /* fall through.  */
 
@@ -289,10 +289,6 @@ write_defs (cpp_reader *pfile ATTRIBUTE_UNUSED, cpp_hashnode *hn, void *ss_p)
       }
       return 1;
 
-    case NT_ASSERTION:
-      /* Not currently implemented.  */
-      return 1;
-
     default:
       abort ();
     }
@@ -760,13 +756,17 @@ save_macros (cpp_reader *r, cpp_hashnode *h, void *data_p)
 {
   struct save_macro_data *data = (struct save_macro_data *)data_p;
 
-  if ((h->flags & NODE_BUILTIN)
-      && h->type == NT_MACRO
-      && r->cb.user_builtin_macro)
-    r->cb.user_builtin_macro (r, h);
+  if (h->type != NT_MACRO)
+    return 1;
 
-  if (h->type != NT_VOID
-      && (h->flags & NODE_BUILTIN) == 0)
+  if (h->flags & NODE_BUILTIN)
+    {
+      if (r->cb.user_builtin_macro)
+       r->cb.user_builtin_macro (r, h);
+    }
+  else if (h->value.macro->kind == cmk_assert)
+    return 1;
+  else
     {
       if (data->count == data->array_size)
        {
@@ -774,28 +774,14 @@ save_macros (cpp_reader *r, cpp_hashnode *h, void *data_p)
          data->defns = XRESIZEVEC (uchar *, data->defns, (data->array_size));
        }
 
-      switch (h->type)
-       {
-       case NT_ASSERTION:
-         /* Not currently implemented.  */
-         return 1;
+      const uchar * defn = cpp_macro_definition (r, h);
+      size_t defnlen = ustrlen (defn);
 
-       case NT_MACRO:
-         {
-           const uchar * defn = cpp_macro_definition (r, h);
-           size_t defnlen = ustrlen (defn);
-
-           data->defns[data->count] = (uchar *) xmemdup (defn, defnlen,
-                                                          defnlen + 2);
-           data->defns[data->count][defnlen] = '\n';
-         }
-         break;
-
-       default:
-         abort ();
-       }
+      data->defns[data->count] = (uchar *) xmemdup (defn, defnlen, defnlen + 2);
+      data->defns[data->count][defnlen] = '\n';
       data->count++;
     }
+
   return 1;
 }