]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Add cpp_macro_kind
authorNathan Sidwell <nathan@acm.org>
Wed, 11 Jul 2018 14:46:07 +0000 (14:46 +0000)
committerNathan Sidwell <nathan@gcc.gnu.org>
Wed, 11 Jul 2018 14:46:07 +0000 (14:46 +0000)
Add cpp_macro_kind
libcpp/
* include/cpp-id-data.h (enum cpp_macro_kind): New.
(struct cpp_macro): Replace traditional with kind.  Adjust GTY.
* macro.c (create_iso_definition): Set kind.
* traditional.c (push_replacement_text): Assert trad.
(save_replacement_text): Set kind.

From-SVN: r262555

ChangeLog.name-lookup
libcpp/include/cpp-id-data.h
libcpp/macro.c
libcpp/traditional.c

index f699cf49e611dd1cef93f03e6e40f3e077dcab8e..06e100379d21a2d80401828abf588c029547b587 100644 (file)
@@ -1,5 +1,13 @@
 2018-07-11  Nathan Sidwell  <nathan@acm.org>
 
+       Add cpp_macro_kind
+       libcpp/
+       * include/cpp-id-data.h (enum cpp_macro_kind): New.
+       (struct cpp_macro): Replace traditional with kind.  Adjust GTY.
+       * macro.c (create_iso_definition): Set kind.
+       * traditional.c (push_replacement_text): Assert trad.
+       (save_replacement_text): Set kind.
+
        Store include-from as a location, not line-map index.
        libcpp/
        * include/line-map.h (line_map_ordinary): Replace included_from
index 0299984efb7baf8ffe94d1e43b7d0004d7f7033b..f4596b69dc41cefd6e5ac2f22f2fc70bf1c5dc50 100644 (file)
@@ -30,6 +30,12 @@ struct GTY(()) answer {
   cpp_token GTY ((length ("%h.count"))) first[1];
 };
 
+/* The kind of the cpp_macro.  */
+enum cpp_macro_kind {
+  cmk_macro,   /* An ISO macro (token expansion).  */
+  cmk_traditional,     /* A traditional macro (text expansion).  */
+};
+
 /* Each macro definition is recorded in a cpp_macro structure.
    Variadic macros cannot occur with traditional cpp.  */
 struct GTY(()) cpp_macro {
@@ -37,29 +43,34 @@ struct GTY(()) cpp_macro {
      the original spelling of those identifiers, not the canonical
      UTF-8 spelling, goes here.  */
   cpp_hashnode ** GTY ((nested_ptr (union tree_node,
-               "%h ? CPP_HASHNODE (GCC_IDENT_TO_HT_IDENT (%h)) : NULL",
-                       "%h ? HT_IDENT_TO_GCC_IDENT (HT_NODE (%h)) : NULL"),
-                       length ("%h.paramc")))
-    params;
-
-  /* Replacement tokens (ISO) or replacement text (traditional).  See
-     comment at top of cpptrad.c for how traditional function-like
-     macros are encoded.  */
-  union cpp_macro_u
+       "%h ? CPP_HASHNODE (GCC_IDENT_TO_HT_IDENT (%h)) : NULL",
+       "%h ? HT_IDENT_TO_GCC_IDENT (HT_NODE (%h)) : NULL"),
+                         length ("%h.paramc"))) params;
+
+  union cpp_exp_u
   {
-    cpp_token * GTY ((tag ("0"), length ("%0.count"))) tokens;
-    const unsigned char * GTY ((tag ("1"))) text;
-  } GTY ((desc ("%1.traditional"))) exp;
+    /* Replacement tokens (ISO), or assertion body value.  */
+    cpp_token * GTY ((tag ("false"), length ("%0.count"))) tokens;
+
+    /* Replacement text (traditional).  See comment at top of
+       cpptrad.c for how traditional function-like macros are
+       encoded.  */
+    const unsigned char * GTY ((tag ("true"))) text;
+  } GTY ((desc ("%1.kind == cmk_traditional"))) exp;
 
   /* Definition line number.  */
   source_location line;
 
-  /* Number of tokens in expansion, or bytes for traditional macros.  */
+  /* Number of tokens in body, or bytes for traditional macros.  */
+  /* Do we really need 2^32-1 range here?  */
   unsigned int count;
 
   /* Number of parameters.  */
   unsigned short paramc;
 
+  /* The kind of this macro (ISO, trad or assert) */
+  unsigned kind : 2;
+
   /* If a function-like macro.  */
   unsigned int fun_like : 1;
 
@@ -72,11 +83,10 @@ struct GTY(()) cpp_macro {
   /* Nonzero if it has been expanded or had its existence tested.  */
   unsigned int used     : 1;
 
-  /* Indicate which field of 'exp' is in use.  */
-  unsigned int traditional : 1;
-
   /* Indicate whether the tokens include extra CPP_PASTE tokens at the
      end to track invalid redefinitions with consecutive CPP_PASTE
      tokens.  */
   unsigned int extra_tokens : 1;
+
+  /* 9 bits spare (32-bit). 41 on 64-bit target.  */
 };
index deb7540077991fcb117cdebb66daba06f08834ec..d8ea69230c1d8afd78a8e051124416cf567d5630 100644 (file)
@@ -3406,7 +3406,7 @@ create_iso_definition (cpp_reader *pfile, cpp_macro *macro)
     return false;
 
   macro->exp.tokens = (cpp_token *) BUFF_FRONT (pfile->a_buff);
-  macro->traditional = 0;
+  macro->kind = cmk_macro;
 
   /* Don't count the CPP_EOF.  */
   macro->count--;
index b25d5222d8a879cbeeb4982d01c907dca388be13..3cb967371437d8a662069c52411b536b2fbf6844 100644 (file)
@@ -851,9 +851,9 @@ push_replacement_text (cpp_reader *pfile, cpp_hashnode *node)
   else
     {
       cpp_macro *macro = node->value.macro;
+      gcc_assert (macro->kind == cmk_traditional);
       macro->used = 1;
       text = macro->exp.text;
-      macro->traditional = 1;
       len = macro->count;
     }
 
@@ -1131,6 +1131,8 @@ save_replacement_text (cpp_reader *pfile, cpp_macro *macro,
   size_t len = pfile->out.cur - pfile->out.base;
   uchar *exp;
 
+  /* This is a traditional macro now.  */
+  macro->kind = cmk_traditional;
   if (macro->paramc == 0)
     {
       /* Object-like and function-like macros without parameters
@@ -1139,7 +1141,6 @@ save_replacement_text (cpp_reader *pfile, cpp_macro *macro,
       memcpy (exp, pfile->out.base, len);
       exp[len] = '\n';
       macro->exp.text = exp;
-      macro->traditional = 1;
       macro->count = len;
     }
   else
@@ -1155,7 +1156,6 @@ save_replacement_text (cpp_reader *pfile, cpp_macro *macro,
       exp = BUFF_FRONT (pfile->a_buff);
       block = (struct block *) (exp + macro->count);
       macro->exp.text = exp;
-      macro->traditional = 1;
 
       /* Write out the block information.  */
       block->text_len = len;