From 3eef3a1923820d0000bbc35c00e56748fa3e7eca Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Wed, 11 Jul 2018 14:46:07 +0000 Subject: [PATCH] Add cpp_macro_kind 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 | 8 +++++++ libcpp/include/cpp-id-data.h | 42 ++++++++++++++++++++++-------------- libcpp/macro.c | 2 +- libcpp/traditional.c | 6 +++--- 4 files changed, 38 insertions(+), 20 deletions(-) diff --git a/ChangeLog.name-lookup b/ChangeLog.name-lookup index f699cf49e611..06e100379d21 100644 --- a/ChangeLog.name-lookup +++ b/ChangeLog.name-lookup @@ -1,5 +1,13 @@ 2018-07-11 Nathan Sidwell + 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 diff --git a/libcpp/include/cpp-id-data.h b/libcpp/include/cpp-id-data.h index 0299984efb7b..f4596b69dc41 100644 --- a/libcpp/include/cpp-id-data.h +++ b/libcpp/include/cpp-id-data.h @@ -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. */ }; diff --git a/libcpp/macro.c b/libcpp/macro.c index deb754007799..d8ea69230c1d 100644 --- a/libcpp/macro.c +++ b/libcpp/macro.c @@ -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--; diff --git a/libcpp/traditional.c b/libcpp/traditional.c index b25d5222d8a8..3cb967371437 100644 --- a/libcpp/traditional.c +++ b/libcpp/traditional.c @@ -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; -- 2.47.2