]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Asserts are now macro variants
authorNathan Sidwell <nathan@acm.org>
Thu, 2 Aug 2018 16:53:21 +0000 (16:53 +0000)
committerNathan Sidwell <nathan@gcc.gnu.org>
Thu, 2 Aug 2018 16:53:21 +0000 (16:53 +0000)
Asserts are now macro variants
libcpp/
* directives.c (parse_answer, parse_assertion, find_answer): Use
cpp_macro, not struct answer.
(do_assert, do_unassert): Adjust.
* include/cpp-id-data.h (struct answer): Delete.
* include/cpplib.h (NTV_ANSWER): Delete.
(CPP_HASNODE_VALUE_IDX): Adjust.
(_cpp_hashnode_value): Remove answer.
(cpp_macro_p): Make outline ...
* macro.c (cpp_macro_p): ... here.

From-SVN: r263268

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

index e10fc240efe648905e889c5e3b2b989479b1e349..4b7dd0b71c99ff66d80517f1e825ed2e8e418e21 100644 (file)
@@ -1,5 +1,17 @@
 2018-08-02  Nathan Sidwell  <nathan@acm.org>
 
+       Asserts are now macro variants
+       libcpp/
+       * directives.c (parse_answer, parse_assertion, find_answer): Use
+       cpp_macro, not struct answer.
+       (do_assert, do_unassert): Adjust.
+       * include/cpp-id-data.h (struct answer): Delete.
+       * include/cpplib.h (NTV_ANSWER): Delete.
+       (CPP_HASNODE_VALUE_IDX): Adjust.
+       (_cpp_hashnode_value): Remove answer.
+       (cpp_macro_p): Make outline ...
+       * macro.c (cpp_macro_p): ... here.
+
        Assert body is back as trailing array
        libcpp/
        * include/cpp-id-data.h (struct answer): Make body a trailing array
@@ -8,7 +20,6 @@
        Return whole answer struct.
        (_cpp_test_assertion, do_assert, do_unassert): Adjust.
 
-
 2018-08-01  Nathan Sidwell  <nathan@acm.org>
 
        libcpp/
index 85bb2763403ff441b42aebcef454954123038ea7..976c87c02dc2846406729da344d5b46a41045125 100644 (file)
@@ -124,9 +124,9 @@ static const cpp_token *get_token_no_padding (cpp_reader *);
 static const cpp_token *get__Pragma_string (cpp_reader *);
 static void destringize_and_run (cpp_reader *, const cpp_string *,
                                 source_location);
-static bool parse_answer (cpp_reader *, int, source_location, struct answer **);
-static cpp_hashnode *parse_assertion (cpp_reader *, int, struct answer **);
-static struct answer ** find_answer (cpp_hashnode *, const struct answer *);
+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 void handle_assertion (cpp_reader *, const char *, int);
 static void do_pragma_push_macro (cpp_reader *);
 static void do_pragma_pop_macro (cpp_reader *);
@@ -2183,7 +2183,7 @@ push_conditional (cpp_reader *pfile, int skip, int type,
    predicate.  */
 static bool
 parse_answer (cpp_reader *pfile, int type, source_location pred_loc,
-             struct answer **answer_ptr)
+             cpp_macro **answer_ptr)
 {
   /* In a conditional, it is legal to not have an open paren.  We
      should save the following token in this case.  */
@@ -2209,9 +2209,10 @@ parse_answer (cpp_reader *pfile, int type, source_location pred_loc,
       return false;
     }
 
-  struct answer *answer
-    = (struct answer *)_cpp_reserve_room (pfile, 0, sizeof (struct answer));
-  answer->next = NULL;
+  cpp_macro *answer = _cpp_new_macro (pfile, cmk_assert,
+                                     _cpp_reserve_room (pfile, 0,
+                                                        sizeof (cpp_macro)));
+  answer->parm.next = NULL;
   unsigned count = 0;
   for (;;)
     {
@@ -2226,10 +2227,10 @@ parse_answer (cpp_reader *pfile, int type, source_location pred_loc,
          return false;
        }
 
-      answer = (struct answer *)_cpp_reserve_room
-       (pfile, sizeof (struct answer) + count * sizeof (cpp_token),
+      answer = (cpp_macro *)_cpp_reserve_room
+       (pfile, sizeof (cpp_macro) + count * sizeof (cpp_token),
         sizeof (cpp_token));
-      answer->exp[count++] = *token;
+      answer->exp.tokens[count++] = *token;
     }
 
   if (!count)
@@ -2239,7 +2240,7 @@ parse_answer (cpp_reader *pfile, int type, source_location pred_loc,
     }
 
   /* Drop whitespace at start, for answer equivalence purposes.  */
-  answer->exp[0].flags &= ~PREV_WHITE;
+  answer->exp.tokens[0].flags &= ~PREV_WHITE;
 
   answer->count = count;
   *answer_ptr = answer;
@@ -2252,7 +2253,7 @@ parse_answer (cpp_reader *pfile, int type, source_location pred_loc,
    supplied, it is placed in EXP_PTR & EXP_COUNT, which is otherwise
    set to 0.  */
 static cpp_hashnode *
-parse_assertion (cpp_reader *pfile, int type, struct answer **answer_ptr)
+parse_assertion (cpp_reader *pfile, int type, cpp_macro **answer_ptr)
 {
   cpp_hashnode *result = 0;
 
@@ -2285,20 +2286,21 @@ parse_assertion (cpp_reader *pfile, int type, struct answer **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 struct answer **
-find_answer (cpp_hashnode *node, const struct answer *candidate)
+static cpp_macro **
+find_answer (cpp_hashnode *node, const cpp_macro *candidate)
 {
   unsigned int i;
-  struct answer **result;
+  cpp_macro **result;
 
-  for (result = &node->value.answers; *result; result = &(*result)->next)
+  for (result = &node->value.macro; *result; result = &(*result)->parm.next)
     {
-      struct answer *answer = *result;
+      cpp_macro *answer = *result;
 
       if (answer->count == candidate->count)
        {
          for (i = 0; i < answer->count; i++)
-           if (!_cpp_equiv_tokens (&answer->exp[i], &candidate->exp[i]))
+           if (!_cpp_equiv_tokens (&answer->exp.tokens[i],
+                                   &candidate->exp.tokens[i]))
              break;
 
          if (i == answer->count)
@@ -2315,7 +2317,7 @@ find_answer (cpp_hashnode *node, const struct answer *candidate)
 int
 _cpp_test_assertion (cpp_reader *pfile, unsigned int *value)
 {
-  struct answer *answer;
+  cpp_macro *answer;
   cpp_hashnode *node = parse_assertion (pfile, T_IF, &answer);
 
   /* For recovery, an erroneous assertion expression is handled as a
@@ -2336,12 +2338,12 @@ _cpp_test_assertion (cpp_reader *pfile, unsigned int *value)
 static void
 do_assert (cpp_reader *pfile)
 {
-  struct answer *answer;
+  cpp_macro *answer;
   cpp_hashnode *node = parse_assertion (pfile, T_ASSERT, &answer);
 
   if (node)
     {
-      struct answer *next = NULL;
+      cpp_macro *next = NULL;
 
       /* Place the new answer in the answer list.  First check there
          is not a duplicate.  */
@@ -2353,18 +2355,18 @@ do_assert (cpp_reader *pfile)
                         NODE_NAME (node) + 1);
              return;
            }
-         next = node->value.answers;
+         next = node->value.macro;
        }
 
       /* Commit or allocate storage for the answer.  */
-      answer = (struct answer *)_cpp_commit_buff
-       (pfile, sizeof (struct answer) - sizeof (cpp_token)
+      answer = (cpp_macro *)_cpp_commit_buff
+       (pfile, sizeof (cpp_macro) - sizeof (cpp_token)
         + sizeof (cpp_token) * answer->count);
 
-      answer->next = next;
+      answer->parm.next = next;
 
       node->type = NT_ASSERTION;
-      node->value.answers = answer;
+      node->value.macro = answer;
 
       check_eol (pfile, false);
     }
@@ -2375,7 +2377,7 @@ static void
 do_unassert (cpp_reader *pfile)
 {
   cpp_hashnode *node;
-  struct answer *answer;
+  cpp_macro *answer;
 
   node = parse_assertion (pfile, T_UNASSERT, &answer);
   /* It isn't an error to #unassert something that isn't asserted.  */
@@ -2383,15 +2385,15 @@ do_unassert (cpp_reader *pfile)
     {
       if (answer)
        {
-         struct answer **p = find_answer (node, answer), *temp;
+         cpp_macro **p = find_answer (node, answer), *temp;
 
          /* Remove the answer from the list.  */
          temp = *p;
          if (temp)
-           *p = temp->next;
+           *p = temp->parm.next;
 
          /* Did we free the last answer?  */
-         if (node->value.answers == 0)
+         if (node->value.macro == 0)
            node->type = NT_VOID;
 
          check_eol (pfile, false);
index 77b0b77fb6fc6ad851b05e4e2f3c2b61065d7ac1..ab5f9ef831ad42c295e0dfb7b858c0c225953821 100644 (file)
@@ -23,13 +23,6 @@ typedef unsigned char uchar;
 
 #define UC (const unsigned char *)  /* Intended use: UC"string" */
 
-/* Chained list of answers to an assertion.  */
-struct GTY(()) answer {
-  struct answer *next;
-  unsigned int count;
-  cpp_token GTY ((length ("%h.count"))) exp[1];
-};
-
 /* The kind of the cpp_macro.  */
 enum cpp_macro_kind {
   cmk_macro,   /* An ISO macro (token expansion).  */
index d773c9a602b822ef684607ab53324f109d9c8754..1873e6a0af34279cf0ced7b1de892cd419e734f1 100644 (file)
@@ -36,7 +36,6 @@ typedef struct cpp_macro cpp_macro;
 typedef struct cpp_callbacks cpp_callbacks;
 typedef struct cpp_dir cpp_dir;
 
-struct answer;
 struct _cpp_file;
 
 /* The first three groups, apart from '=', can appear in preprocessor
@@ -731,7 +730,6 @@ enum cpp_builtin_type
 
 enum {
   NTV_MACRO,
-  NTV_ANSWER,
   NTV_BUILTIN,
   NTV_ARGUMENT,
   NTV_NONE
@@ -741,7 +739,7 @@ enum {
   ((HNODE.flags & NODE_MACRO_ARG) ? NTV_ARGUMENT               \
    : HNODE.type == NT_MACRO ? ((HNODE.flags & NODE_BUILTIN)    \
                               ? NTV_BUILTIN : NTV_MACRO)       \
-   : HNODE.type == NT_ASSERTION ? NTV_ANSWER                   \
+   : HNODE.type == NT_ASSERTION ? NTV_MACRO                    \
    : NTV_NONE)
 
 /* The common part of an identifier node shared amongst all 3 C front
@@ -749,10 +747,8 @@ enum {
    identifiers in the grammatical sense.  */
 
 union GTY(()) _cpp_hashnode_value {
-  /* If a macro.  */
+  /* Macro or assert  */
   cpp_macro * GTY((tag ("NTV_MACRO"))) macro;
-  /* Answers to an assertion.  */
-  struct answer * GTY ((tag ("NTV_ANSWER"))) answers;
   /* Code for a builtin macro.  */
   enum cpp_builtin_type GTY ((tag ("NTV_BUILTIN"))) builtin;
   /* Macro argument index.  */
@@ -890,11 +886,7 @@ extern int cpp_avoid_paste (cpp_reader *, const cpp_token *,
 extern const cpp_token *cpp_get_token (cpp_reader *);
 extern const cpp_token *cpp_get_token_with_location (cpp_reader *,
                                                     source_location *);
-inline bool cpp_macro_p (cpp_hashnode *node, bool builtin_ok = false)
-{
-  return (node->type == NT_MACRO
-         && (builtin_ok || !(node->flags & NODE_BUILTIN)));
-}
+extern bool cpp_macro_p (cpp_hashnode *node, bool builtin_ok = false);
 extern bool cpp_fun_like_macro_p (cpp_hashnode *);
 extern const unsigned char *cpp_macro_definition (cpp_reader *,
                                                  cpp_hashnode *);
index dc1462dafb8ae274b81abdff09b0661e6c9c8b69..c2f5b0d4950d3d88340cfc189ec8632c5e1a06d6 100644 (file)
@@ -3607,7 +3607,18 @@ check_trad_stringification (cpp_reader *pfile, const cpp_macro *macro,
     }
 }
 
-/* Returns true of NODE is a function-like macro.  */
+/* Returns true if NODE is a macro.  */
+bool
+cpp_macro_p (cpp_hashnode *node, bool builtin_ok)
+{
+  if (node->type != NT_MACRO)
+    return false;
+  if (node->flags & NODE_BUILTIN)
+    return builtin_ok;
+  return node->value.macro->kind != cmk_assert;
+}
+
+/* Returns true if NODE is a function-like macro.  */
 bool
 cpp_fun_like_macro_p (cpp_hashnode *node)
 {