]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
cpplib.h (NODE_...): Reenumerate.
authorNathan Sidwell <nathan@acm.org>
Wed, 15 Aug 2018 12:33:04 +0000 (12:33 +0000)
committerNathan Sidwell <nathan@gcc.gnu.org>
Wed, 15 Aug 2018 12:33:04 +0000 (12:33 +0000)
libcpp/
* incude/cpplib.h (NODE_...): Reenumerate.
(enum node_type): NT_VOID may be assert.
(struct _cpp_hashnode_value): Add assert field.
(cpp_user_macro_p): Don't check for assert here.
* directives.c (find_answer): Rename to ...
(find_assert): ... here. Adjust.
(undefine_macros): Zap value.assert.
(_cpp_test_assertion, do_assert, do_unassert): Adjust.

From-SVN: r263558

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

index 9ed2faf0595832f87c8175820d704f45413c05e1..885c7a4d616e49b466d197622cf96ad644646ac0 100644 (file)
@@ -1,3 +1,15 @@
+2018-08-15  Nathan Sidwell  <nathan@acm.org>
+
+       libcpp/
+       * incude/cpplib.h (NODE_...): Reenumerate.
+       (enum node_type): NT_VOID may be assert.
+       (struct _cpp_hashnode_value): Add assert field.
+       (cpp_user_macro_p): Don't check for assert here.
+       * directives.c (find_answer): Rename to ...
+       (find_assert): ... here. Adjust.
+       (undefine_macros): Zap value.assert.
+       (_cpp_test_assertion, do_assert, do_unassert): Adjust.
+
 2018-08-08  Nathan Sidwell  <nathan@acm.org>
 
        gcc/c-family/
index ec5f14506fb51902a17962ab50184bf1e06e54f9..0ccbf06d21eea2b52deb9abe577e8e3b3a966b81 100644 (file)
@@ -126,7 +126,7 @@ static void destringize_and_run (cpp_reader *, const cpp_string *,
                                 source_location);
 static bool parse_answer (cpp_reader *, int, source_location, cpp_macro **);
 static cpp_hashnode *parse_assertion (cpp_reader *, int, cpp_macro **);
-static cpp_macro **find_answer (cpp_hashnode *, const cpp_macro *);
+static cpp_macro **find_assert (cpp_hashnode *, const cpp_macro *);
 static void handle_assertion (cpp_reader *, const char *, int);
 static void do_pragma_push_macro (cpp_reader *);
 static void do_pragma_pop_macro (cpp_reader *);
@@ -696,7 +696,7 @@ undefine_macros (cpp_reader *pfile ATTRIBUTE_UNUSED, cpp_hashnode *h,
      Macros and assertions no longer have anything to free.  */
   h->type = NT_VOID;
   h->flags &= ~(NODE_POISONED|NODE_DISABLED|NODE_USED);
-  h->value.macro = NULL;
+  h->value.assert = NULL;
   return 1;
 }
 
@@ -2256,12 +2256,12 @@ parse_assertion (cpp_reader *pfile, int type, cpp_macro **answer_ptr)
 /* Returns a pointer to the pointer to CANDIDATE in the answer chain,
    or a pointer to NULL if the answer is not in the chain.  */
 static cpp_macro **
-find_answer (cpp_hashnode *node, const cpp_macro *candidate)
+find_assert (cpp_hashnode *node, const cpp_macro *candidate)
 {
   unsigned int i;
   cpp_macro **result = NULL;
 
-  for (result = &node->value.macro; *result; result = &(*result)->parm.next)
+  for (result = &node->value.assert; *result; result = &(*result)->parm.next)
     {
       cpp_macro *answer = *result;
 
@@ -2295,8 +2295,8 @@ _cpp_test_assertion (cpp_reader *pfile, unsigned int *value)
 
   if (node)
     {
-      if (node->value.macro)
-       *value = !answer || *find_answer (node, answer);
+      if (node->value.assert)
+       *value = !answer || *find_assert (node, answer);
     }
   else if (pfile->cur_token[-1].type == CPP_EOF)
     _cpp_backup_tokens (pfile, 1);
@@ -2316,7 +2316,7 @@ do_assert (cpp_reader *pfile)
     {
       /* Place the new answer in the answer list.  First check there
          is not a duplicate.  */
-      if (*find_answer (node, answer))
+      if (*find_assert (node, answer))
        {
          cpp_error (pfile, CPP_DL_WARNING, "\"%s\" re-asserted",
                     NODE_NAME (node) + 1);
@@ -2328,10 +2328,9 @@ do_assert (cpp_reader *pfile)
        (pfile, sizeof (cpp_macro) - sizeof (cpp_token)
         + sizeof (cpp_token) * answer->count);
 
-      answer->parm.next = node->value.macro;
+      answer->parm.next = node->value.assert;
 
-      node->type = NT_USER_MACRO;
-      node->value.macro = answer;
+      node->value.assert = answer;
 
       check_eol (pfile, false);
     }
@@ -2349,17 +2348,12 @@ do_unassert (cpp_reader *pfile)
     {
       if (answer)
        {
-         cpp_macro **p = find_answer (node, answer), *temp;
+         cpp_macro **p = find_assert (node, answer);
 
-         /* Remove the answer from the list.  */
-         temp = *p;
-         if (temp)
+         /* Remove the assert from the list.  */
+         if (cpp_macro *temp = *p)
            *p = temp->parm.next;
 
-         /* Did we free the last answer?  */
-         if (node->value.macro == 0)
-           node->type = NT_VOID;
-
          check_eol (pfile, false);
        }
       else
index 8d224ad751e52f8fd021caee895a0154666ff675..e1810f71718844f10e144ceafb93f98e69edae7f 100644 (file)
@@ -743,36 +743,22 @@ struct GTY(()) cpp_macro {
   } GTY ((desc ("%1.kind == cmk_traditional"))) exp;
 };
 
-/* 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_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".
-   NODE_DIAGNOSTIC is for speed in lex_token: it indicates a
-   diagnostic may be required for this node.  Currently this only
-   applies to __VA_ARGS__, poisoned identifiers, and -Wc++-compat
-   warnings about NODE_OPERATOR.  */
-
 /* Hash node flags.  */
 #define NODE_OPERATOR  (1 << 0)        /* C++ named operator.  */
 #define NODE_POISONED  (1 << 1)        /* Poisoned identifier.  */
-
-#define NODE_DIAGNOSTIC (1 << 3)       /* Possible diagnostic when lexed.  */
-#define NODE_WARN      (1 << 4)        /* Warn if redefined or undefined.  */
-#define NODE_DISABLED  (1 << 5)        /* A disabled macro.  */
-
-#define NODE_USED      (1 << 7)        /* Dumped with -dU.  */
-#define NODE_CONDITIONAL (1 << 8)      /* Conditional macro */
-#define NODE_WARN_OPERATOR (1 << 9)    /* Warn about C++ named operator.  */
+#define NODE_DIAGNOSTIC (1 << 2)       /* Possible diagnostic when lexed.  */
+#define NODE_WARN      (1 << 3)        /* Warn if redefined or undefined.  */
+#define NODE_DISABLED  (1 << 4)        /* A disabled macro.  */
+#define NODE_USED      (1 << 5)        /* Dumped with -dU.  */
+#define NODE_CONDITIONAL (1 << 6)      /* Conditional macro */
+#define NODE_WARN_OPERATOR (1 << 7)    /* Warn about C++ named operator.  */
 
 /* Different flavors of hash node.  */
 enum node_type
 {
-  NT_VOID = 0,    /* No definition yet.  */
+  NT_VOID = 0,    /* Maybe an assert?  */
   NT_MACRO_ARG,           /* A macro arg.  */
-  NT_USER_MACRO,   /* A user macro or assert (#node).  */
+  NT_USER_MACRO,   /* A user macro.  */
   NT_BUILTIN_MACRO /* A builtin macro.  */
 };
 
@@ -803,7 +789,9 @@ enum cpp_builtin_type
    identifiers in the grammatical sense.  */
 
 union GTY(()) _cpp_hashnode_value {
-  /* Macro or assert  */
+  /* Assert (maybe NULL) */
+  cpp_macro * GTY((tag ("NT_VOID"))) assert;
+  /* Macro (never NULL) */
   cpp_macro * GTY((tag ("NT_USER_MACRO"))) macro;
   /* Code for a builtin macro.  */
   enum cpp_builtin_type GTY ((tag ("NT_BUILTIN_MACRO"))) builtin;
@@ -818,8 +806,13 @@ struct GTY(()) cpp_hashnode {
                                           then index into directive table.
                                           Otherwise, a NODE_OPERATOR.  */
   unsigned char rid_code;              /* Rid code - for front ends.  */
-  ENUM_BITFIELD(node_type) type : 6;   /* CPP node type.  */
-  unsigned int flags : 10;             /* CPP flags.  */
+  ENUM_BITFIELD(node_type) type : 2;   /* CPP node type.  */
+  unsigned int flags : 14;             /* CPP flags.  */
+
+  /* 32-bits of padding on 64-bit arch.  We could shrink this by
+     making ht_identifier hold an offset to a trailing string value.
+     That would require FE's expose their IDENTIFIER_NODE size to
+     us.  */
 
   union _cpp_hashnode_value GTY ((desc ("%1.type"))) value;
 };
@@ -944,16 +937,12 @@ extern const cpp_token *cpp_get_token_with_location (cpp_reader *,
                                                     source_location *);
 inline bool cpp_user_macro_p (const cpp_hashnode *node)
 {
-  return node->type == NT_USER_MACRO && node->value.macro->kind != cmk_assert;
+  return node->type == NT_USER_MACRO;
 }
 inline bool cpp_builtin_macro_p (const cpp_hashnode *node)
 {
   return node->type == NT_BUILTIN_MACRO;
 }
-/* Although a macro may actually turn out to be an assert, they are
-   separated by namespace, in that the latter have special
-   '#'-starting names, that macros cannot have.  We don't have to
-   check that here.  */
 inline bool cpp_macro_p (const cpp_hashnode *node)
 {
   return node->type & NT_USER_MACRO;