diff options
author | Nathan Sidwell <nathan@acm.org> | 2018-08-20 16:32:29 +0000 |
---|---|---|
committer | Nathan Sidwell <nathan@gcc.gnu.org> | 2018-08-20 16:32:29 +0000 |
commit | a570d97f5b8612ad2756333e5f21098be64057df (patch) | |
tree | 8ef03edd4d66a34af550bf97a6a1ea02e32c7bc6 /libcpp/macro.c | |
parent | 7692e253ee0bdab40fb896991f9208112ebfff61 (diff) | |
download | gcc-a570d97f5b8612ad2756333e5f21098be64057df.zip gcc-a570d97f5b8612ad2756333e5f21098be64057df.tar.gz gcc-a570d97f5b8612ad2756333e5f21098be64057df.tar.bz2 |
[CPP PATCH] node type
https://gcc.gnu.org/ml/gcc-patches/2018-08/msg01164.html
* include/cpplib.h (NODE_BUILTIN, NODE_MACRO_ARG): Delete.
Renumber others.
(enum node_type): Replace NT_MACRO with NT_USER_MACRO,
NT_BUILTIN_MACRO, NT_MACRO_ARG. Delete NT_ASSERTION.
(NTV_MACRO, NTV_ANSWER, NTV_BUILTIN, NTV_ARGUMENT, NTV_NONE):
Delete.
(CPP_HASHNODE_VALUE_IDX): Delete.
(union _cpp_hashnode_value): GTY tag from enum node_type directly.
(struct cpp_hashnode): Adjust GTY desc for value field.
(cpp_user_macro_p, cpp_builtin_macro_p, cpp_macro_p): Adjust.
* directives.c (undefine_macros): Clear value.anwers, adjust flag
clearing.
(_cpp_test_assertion): No need to check NT_ASSERTION.
(do_assert, do_unassert): Likewise.
* init.c (cpp_init_special_builtins): Set type not flags.
* macro.c (struct macro_arg_saved_data): Add type field.
(cpp_get_token_1): Check type not NT_VOID.
(_cpp_free_definition): Adjust flag clearing. Nullify
value.answers.
(_cpp_save_parameter, _cpp_unsave_parameters): Save and restore
type.
(lex_expansion_token): Check type not flags.
(_cpp_create_definition): Set type to NT_USER_MACRO.
(_cpp_notify_macro_use): Adjust type checking.
* pch.c (write_macdef, count_defs, write_defs, cpp_valid_state)
(save_macros): Adjust node type/flag handling.
* traditional.c (_cpp_scan_out_logical_line): Check type not flags.
From-SVN: r263667
Diffstat (limited to 'libcpp/macro.c')
-rw-r--r-- | libcpp/macro.c | 44 |
1 files changed, 24 insertions, 20 deletions
diff --git a/libcpp/macro.c b/libcpp/macro.c index 123f63d..3629e83 100644 --- a/libcpp/macro.c +++ b/libcpp/macro.c @@ -85,8 +85,9 @@ struct macro_arg_token_iter struct macro_arg_saved_data { /* The canonical (UTF-8) spelling of this identifier. */ cpp_hashnode *canonical_node; - /* The previous value of this identifier. */ + /* The previous value & type of this identifier. */ union _cpp_hashnode_value value; + node_type type; }; static const char *vaopt_paste_error = @@ -2730,7 +2731,7 @@ cpp_get_token_1 (cpp_reader *pfile, source_location *location) node = result->val.node.node; - if (node->type != NT_MACRO || (result->flags & NO_EXPAND)) + if (node->type == NT_VOID || (result->flags & NO_EXPAND)) break; if (!(node->flags & NODE_DISABLED)) @@ -3040,8 +3041,8 @@ _cpp_free_definition (cpp_hashnode *h) { /* Macros and assertions no longer have anything to free. */ h->type = NT_VOID; - /* Clear builtin flag in case of redefinition. */ - h->flags &= ~(NODE_BUILTIN | NODE_DISABLED | NODE_USED); + h->value.answers = NULL; + h->flags &= ~(NODE_DISABLED | NODE_USED); } /* Save parameter NODE (spelling SPELLING) to the parameter list of @@ -3051,7 +3052,7 @@ _cpp_save_parameter (cpp_reader *pfile, unsigned n, cpp_hashnode *node, cpp_hashnode *spelling) { /* Constraint 6.10.3.6 - duplicate parameter names. */ - if (node->flags & NODE_MACRO_ARG) + if (node->type == NT_MACRO_ARG) { cpp_error (pfile, CPP_DL_ERROR, "duplicate macro parameter \"%s\"", NODE_NAME (node)); @@ -3069,13 +3070,14 @@ _cpp_save_parameter (cpp_reader *pfile, unsigned n, cpp_hashnode *node, macro_arg_saved_data *saved = (macro_arg_saved_data *)pfile->macro_buffer; saved[n].canonical_node = node; saved[n].value = node->value; + saved[n].type = node->type; void *base = _cpp_reserve_room (pfile, n * sizeof (cpp_hashnode *), sizeof (cpp_hashnode *)); ((cpp_hashnode **)base)[n] = spelling; /* Morph into a macro arg. */ - node->flags |= NODE_MACRO_ARG; + node->type = NT_MACRO_ARG; /* Index is 1 based. */ node->value.arg_index = n + 1; @@ -3093,8 +3095,8 @@ _cpp_unsave_parameters (cpp_reader *pfile, unsigned n) &((struct macro_arg_saved_data *) pfile->macro_buffer)[n]; struct cpp_hashnode *node = save->canonical_node; + node->type = save->type; node->value = save->value; - node->flags &= ~NODE_MACRO_ARG; } } @@ -3109,6 +3111,7 @@ _cpp_unsave_parameters (cpp_reader *pfile, unsigned n) | name '...' | '...' */ + static bool parse_params (cpp_reader *pfile, unsigned *n_ptr, bool *varadic_ptr) { @@ -3232,9 +3235,9 @@ lex_expansion_token (cpp_reader *pfile, cpp_macro *macro) pfile->cur_token = saved_cur_token; /* Is this a parameter? */ - if (token->type == CPP_NAME - && (token->val.node.node->flags & NODE_MACRO_ARG) != 0) + if (token->type == CPP_NAME && token->val.node.node->type == NT_MACRO_ARG) { + /* Morph into a parameter reference. */ cpp_hashnode *spelling = token->val.node.spelling; token->type = CPP_MACRO_ARG; token->val.macro_arg.arg_no = token->val.node.node->value.arg_index; @@ -3527,7 +3530,7 @@ _cpp_create_definition (cpp_reader *pfile, cpp_hashnode *node) } /* Enter definition in hash table. */ - node->type = NT_MACRO; + node->type = NT_USER_MACRO; node->value.macro = macro; if (! ustrncmp (NODE_NAME (node), DSC ("__STDC_")) && ustrcmp (NODE_NAME (node), (const uchar *) "__STDC_FORMAT_MACROS") @@ -3565,17 +3568,18 @@ _cpp_notify_macro_use (cpp_reader *pfile, cpp_hashnode *node) node->flags |= NODE_USED; switch (node->type) { - case NT_MACRO: - if (!(node->flags & NODE_BUILTIN)) - { - cpp_macro *macro = node->value.macro; - if (macro->lazy) - { - pfile->cb.user_lazy_macro (pfile, macro, macro->lazy - 1); - macro->lazy = 0; - } - } + case NT_USER_MACRO: + { + cpp_macro *macro = node->value.macro; + if (macro->lazy) + { + pfile->cb.user_lazy_macro (pfile, macro, macro->lazy - 1); + macro->lazy = 0; + } + } + /* FALLTHROUGH. */ + case NT_BUILTIN_MACRO: if (pfile->cb.used_define) pfile->cb.used_define (pfile, pfile->directive_line, node); break; |