From: Nathan Sidwell Date: Thu, 2 Aug 2018 16:53:21 +0000 (+0000) Subject: Asserts are now macro variants X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cc9a73d9a364a6622b6344ed22e32a6a584bcdf6;p=thirdparty%2Fgcc.git Asserts are now macro variants 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 --- diff --git a/ChangeLog.name-lookup b/ChangeLog.name-lookup index e10fc240efe6..4b7dd0b71c99 100644 --- a/ChangeLog.name-lookup +++ b/ChangeLog.name-lookup @@ -1,5 +1,17 @@ 2018-08-02 Nathan Sidwell + 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 libcpp/ diff --git a/libcpp/directives.c b/libcpp/directives.c index 85bb2763403f..976c87c02dc2 100644 --- a/libcpp/directives.c +++ b/libcpp/directives.c @@ -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); diff --git a/libcpp/include/cpp-id-data.h b/libcpp/include/cpp-id-data.h index 77b0b77fb6fc..ab5f9ef831ad 100644 --- a/libcpp/include/cpp-id-data.h +++ b/libcpp/include/cpp-id-data.h @@ -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). */ diff --git a/libcpp/include/cpplib.h b/libcpp/include/cpplib.h index d773c9a602b8..1873e6a0af34 100644 --- a/libcpp/include/cpplib.h +++ b/libcpp/include/cpplib.h @@ -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 *); diff --git a/libcpp/macro.c b/libcpp/macro.c index dc1462dafb8a..c2f5b0d4950d 100644 --- a/libcpp/macro.c +++ b/libcpp/macro.c @@ -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) {