2018-07-06 Nathan Sidwell <nathan@acm.org>
+ 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.
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;
}
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;
}
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),
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;
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);
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);
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),
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 *);
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