From: Nathan Sidwell Date: Fri, 6 Jul 2018 17:49:52 +0000 (+0000) Subject: Hide NT_MACRO X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b0a5308b059430a60d156ca0401103889b29dfce;p=thirdparty%2Fgcc.git Hide NT_MACRO Hide NT_MACRO libcpp/ * include/cpplib.h (cpp_macro_p): New. * macro.c (cpp_fun_like_macro_p): Use it. gcc/c-family/ * c-ada-spec.c (count_ada_macro, store_ada_macro): Use cpp_macro_p. * c-ppoutput.c (dump_macro): Likewise. * c-spellcheck.cc (should_suggest_as_macro_p): Likewise. gcc/ * config/rs6000/rs6000-c.c (rs6000_macro_to_expand): Use cpp_macro_p. * config/powerpcspe/powerpcspe-c.c (rs6000_macro_to_expand): Likewise. gcc/fortran/ * cpp.c (dump_macro): Use cpp_macro_p. From-SVN: r262483 --- diff --git a/ChangeLog.name-lookup b/ChangeLog.name-lookup index 22a99a292d95..03bb9c698481 100644 --- a/ChangeLog.name-lookup +++ b/ChangeLog.name-lookup @@ -1,5 +1,20 @@ 2018-07-06 Nathan Sidwell + Hide NT_MACRO + libcpp/ + * include/cpplib.h (cpp_macro_p): New. + * macro.c (cpp_fun_like_macro_p): Use it. + gcc/c-family/ + * c-ada-spec.c (count_ada_macro, store_ada_macro): Use + cpp_macro_p. + * c-ppoutput.c (dump_macro): Likewise. + * c-spellcheck.cc (should_suggest_as_macro_p): Likewise. + gcc/ + * config/rs6000/rs6000-c.c (rs6000_macro_to_expand): Use cpp_macro_p. + * config/powerpcspe/powerpcspe-c.c (rs6000_macro_to_expand): Likewise. + gcc/fortran/ + * cpp.c (dump_macro): Use cpp_macro_p. + Merge trunk r262473. Merge trunk r260623. diff --git a/gcc/c-family/c-ada-spec.c b/gcc/c-family/c-ada-spec.c index 982b850919e0..99b6f0581431 100644 --- a/gcc/c-family/c-ada-spec.c +++ b/gcc/c-family/c-ada-spec.c @@ -171,13 +171,12 @@ static int count_ada_macro (cpp_reader *pfile ATTRIBUTE_UNUSED, cpp_hashnode *node, void *v ATTRIBUTE_UNUSED) { - const cpp_macro *macro = node->value.macro; - - if (node->type == NT_MACRO && !(node->flags & NODE_BUILTIN) - && macro->count - && *NODE_NAME (node) != '_' - && LOCATION_FILE (macro->line) == macro_source_file) - max_ada_macros++; + if (cpp_macro_p (node) && *NODE_NAME (node) != '_') + { + const cpp_macro *macro = node->value.macro; + if (macro->count && LOCATION_FILE (macro->line) == macro_source_file) + max_ada_macros++; + } return 1; } @@ -190,15 +189,13 @@ static int store_ada_macro (cpp_reader *pfile ATTRIBUTE_UNUSED, cpp_hashnode *node, void *macros) { - const cpp_macro *macro = node->value.macro; - - if (node->type == NT_MACRO - && !(node->flags & NODE_BUILTIN) - && macro->count - && *NODE_NAME (node) != '_' - && LOCATION_FILE (macro->line) == macro_source_file) - ((cpp_hashnode **) macros)[store_ada_macro_index++] = node; - + if (cpp_macro_p (node) && *NODE_NAME (node) != '_') + { + const cpp_macro *macro = node->value.macro; + if (macro->count + && LOCATION_FILE (macro->line) == macro_source_file) + ((cpp_hashnode **) macros)[store_ada_macro_index++] = node; + } return 1; } diff --git a/gcc/c-family/c-ppoutput.c b/gcc/c-family/c-ppoutput.c index 8c525caf28da..fb30248e5d09 100644 --- a/gcc/c-family/c-ppoutput.c +++ b/gcc/c-family/c-ppoutput.c @@ -690,7 +690,7 @@ cb_def_pragma (cpp_reader *pfile, source_location line) static int dump_macro (cpp_reader *pfile, cpp_hashnode *node, void *v ATTRIBUTE_UNUSED) { - if (node->type == NT_MACRO && !(node->flags & NODE_BUILTIN)) + if (cpp_macro_p (node)) { fputs ("#define ", print.outf); fputs ((const char *) cpp_macro_definition (pfile, node), diff --git a/gcc/c-family/c-spellcheck.cc b/gcc/c-family/c-spellcheck.cc index c0975d32ea49..f1da61eb33f0 100644 --- a/gcc/c-family/c-spellcheck.cc +++ b/gcc/c-family/c-spellcheck.cc @@ -45,13 +45,13 @@ name_reserved_for_implementation_p (const char *str) static bool should_suggest_as_macro_p (cpp_hashnode *hashnode) { - if (hashnode->type != NT_MACRO) + if (!cpp_macro_p (hashnode, true)) return false; - /* Don't suggest names reserved for the implementation, but do suggest the builtin - macros such as __FILE__, __LINE__ etc. */ - if (name_reserved_for_implementation_p ((const char *)hashnode->ident.str) - && !(hashnode->flags & NODE_BUILTIN)) + /* Don't suggest names reserved for the implementation, but do + suggest the builtin macros such as __FILE__, __LINE__ etc. */ + if (cpp_macro_p (hashnode, false) + && name_reserved_for_implementation_p ((const char *)hashnode->ident.str)) return false; return true; diff --git a/gcc/config/powerpcspe/powerpcspe-c.c b/gcc/config/powerpcspe/powerpcspe-c.c index 157c1853aa45..9b8f698a79ce 100644 --- a/gcc/config/powerpcspe/powerpcspe-c.c +++ b/gcc/config/powerpcspe/powerpcspe-c.c @@ -220,21 +220,22 @@ rs6000_macro_to_expand (cpp_reader *pfile, const cpp_token *tok) else if (ident && (ident != C_CPP_HASHNODE (__vector_keyword))) { enum rid rid_code = (enum rid)(ident->rid_code); - enum node_type itype = ident->type; + bool is_macro = cpp_macro_p (ident, true); + /* If there is a function-like macro, check if it is going to be invoked with or without arguments. Without following ( treat it like non-macro, otherwise the following cpp_get_token eats what should be preserved. */ - if (itype == NT_MACRO && cpp_fun_like_macro_p (ident)) + if (is_macro && cpp_fun_like_macro_p (ident)) { int idx2 = idx; do tok = cpp_peek_token (pfile, idx2++); while (tok->type == CPP_PADDING); if (tok->type != CPP_OPEN_PAREN) - itype = NT_VOID; + is_macro = false; } - if (itype == NT_MACRO) + if (is_macro) { do (void) cpp_get_token (pfile); diff --git a/gcc/config/rs6000/rs6000-c.c b/gcc/config/rs6000/rs6000-c.c index f37f0b1503d3..02e606c03138 100644 --- a/gcc/config/rs6000/rs6000-c.c +++ b/gcc/config/rs6000/rs6000-c.c @@ -220,21 +220,23 @@ rs6000_macro_to_expand (cpp_reader *pfile, const cpp_token *tok) else if (ident && (ident != C_CPP_HASHNODE (__vector_keyword))) { enum rid rid_code = (enum rid)(ident->rid_code); - enum node_type itype = ident->type; + bool is_macro = cpp_macro_p (ident, true); + /* If there is a function-like macro, check if it is going to be invoked with or without arguments. Without following ( treat it like non-macro, otherwise the following cpp_get_token eats what should be preserved. */ - if (itype == NT_MACRO && cpp_fun_like_macro_p (ident)) + if (is_macro && cpp_fun_like_macro_p (ident)) { int idx2 = idx; do tok = cpp_peek_token (pfile, idx2++); while (tok->type == CPP_PADDING); if (tok->type != CPP_OPEN_PAREN) - itype = NT_VOID; + is_macro = false; } - if (itype == NT_MACRO) + + if (is_macro) { do (void) cpp_get_token (pfile); diff --git a/gcc/fortran/cpp.c b/gcc/fortran/cpp.c index 82e890f015c8..2b2b89d0c977 100644 --- a/gcc/fortran/cpp.c +++ b/gcc/fortran/cpp.c @@ -993,7 +993,7 @@ cb_include (cpp_reader *pfile ATTRIBUTE_UNUSED, source_location line, static int dump_macro (cpp_reader *pfile, cpp_hashnode *node, void *v ATTRIBUTE_UNUSED) { - if (node->type == NT_MACRO && !(node->flags & NODE_BUILTIN)) + if (cpp_macro_p (node)) { fputs ("#define ", print.outf); fputs ((const char *) cpp_macro_definition (pfile, node), diff --git a/libcpp/include/cpplib.h b/libcpp/include/cpplib.h index 3ad52d5e01e5..d773c9a602b8 100644 --- a/libcpp/include/cpplib.h +++ b/libcpp/include/cpplib.h @@ -890,6 +890,11 @@ 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_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 776af7bd00ea..deb754007799 100644 --- a/libcpp/macro.c +++ b/libcpp/macro.c @@ -3594,9 +3594,7 @@ check_trad_stringification (cpp_reader *pfile, const cpp_macro *macro, bool cpp_fun_like_macro_p (cpp_hashnode *node) { - return (node->type == NT_MACRO - && (node->flags & (NODE_BUILTIN | NODE_MACRO_ARG)) == 0 - && node->value.macro->fun_like); + return cpp_macro_p (node) && node->value.macro->fun_like; } /* Returns the name, arguments and expansion of a macro, in a format