aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorNathan Sidwell <nathan@acm.org>2018-08-16 13:51:38 +0000
committerNathan Sidwell <nathan@gcc.gnu.org>2018-08-16 13:51:38 +0000
commit3f6677f418564e634e3b77b0fc385891d1fdf1da (patch)
treefee267b2fd8d26f1c657aea624e05d02e0f67a17 /gcc
parentba9d634f417a95d7efb875408573872c883f710a (diff)
downloadgcc-3f6677f418564e634e3b77b0fc385891d1fdf1da.zip
gcc-3f6677f418564e634e3b77b0fc385891d1fdf1da.tar.gz
gcc-3f6677f418564e634e3b77b0fc385891d1fdf1da.tar.bz2
[PATCH] CPP Macro predicates
https://gcc.gnu.org/ml/gcc-patches/2018-08/msg00897.html libcpp/ * include/cpplib.h (cpp_user_macro_p, cpp_builtin_macro_p) (cpp_macro_p): New inlines. * directives.c (do_pragma_poison): Use cpp_macro_p. (do_ifdef, do_ifndef): Likewise. Use _cpp_maybe_notify_macro_use. (cpp_pop_definition): Use cpp_macro_p. Move _cpp_free_definition earlier. Don't zap node directly. * expr.c (parse_defined): Use _cpp_maybe_notify_macro_use & cpp_macro_p. * files.c (should_stack_file): Use cpp_macro_p. * identifiers.c (cpp_defined): Likewise. * internal.h (_cpp_mark_macro): Use cpp_user_macro_p. (_cpp_notify_macro_use): Declare. (_cpp_maybe_notify_macro_use): New inline. * lex.c (is_macro): Use cpp_macro_p. * macro.c (_cpp_warn_if_unused_macro): Use cpp_user_macro_p. (enter_macro_context): Likewise. (_cpp_create_definition): Use cpp_builtin_macro_p, cpp_user_macro_p. Move _cpp_free_definition earlier. (_cpp_notify_macro_use): New, broken out of multiple call sites. * traditional.c (fun_like_macro_p): Use cpp_builtin_macro_p. (maybe_start_funlike, _cpp_scan_out_logical_line) (push_replacement_text): Likewise. gcc/c-family/ * c-ada-spec.c (count_ada_macro): Use cpp_user_macro_p. (store_ada_macro): Likewise. * c-ppoutput.c (cb_used_define, dump_macro): Likewise. * c-spellcheck.cc (should-suggest_as_macro_p): Likewise, gcc/ * config/rs6000/rs6000-c.c (rs6000_macro_to_expend): Use cpp_macro_p. * config/powerpcspc/powerpcspe-c.c (rs6000_macro_to_expend): Likewise. gcc/cp/ * name-lookup.c (lookup_name_fuzzy): Likewise. gcc/fortran/ * cpp.c (dump_macro): Use cpp_user_macro_p. From-SVN: r263587
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog5
-rw-r--r--gcc/c-family/ChangeLog7
-rw-r--r--gcc/c-family/c-ada-spec.c29
-rw-r--r--gcc/c-family/c-ppoutput.c17
-rw-r--r--gcc/c-family/c-spellcheck.cc10
-rw-r--r--gcc/config/powerpcspe/powerpcspe-c.c9
-rw-r--r--gcc/config/rs6000/rs6000-c.c10
-rw-r--r--gcc/cp/name-lookup.c8
-rw-r--r--gcc/fortran/ChangeLog4
-rw-r--r--gcc/fortran/cpp.c2
10 files changed, 59 insertions, 42 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index aaed5d5..fdac7e7 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,8 @@
+2018-08-16 Nathan Sidwell <nathan@acm.org>
+
+ * config/rs6000/rs6000-c.c (rs6000_macro_to_expend): Use cpp_macro_p.
+ * config/powerpcspc/powerpcspe-c.c (rs6000_macro_to_expend): Likewise.
+
2018-08-16 Tamar Christina <tamar.christina@arm.com>
PR target/84711
diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog
index b94a7ae..d293d99 100644
--- a/gcc/c-family/ChangeLog
+++ b/gcc/c-family/ChangeLog
@@ -1,3 +1,10 @@
+2018-08-16 Nathan Sidwell <nathan@acm.org>
+
+ * c-ada-spec.c (count_ada_macro): Use cpp_user_macro_p.
+ (store_ada_macro): Likewise.
+ * c-ppoutput.c (cb_used_define, dump_macro): Likewise.
+ * c-spellcheck.cc (should-suggest_as_macro_p): Likewise,
+
2018-08-15 David Malcolm <dmalcolm@redhat.com>
* c-format.c: Include "selftest-diagnostic.h" and
diff --git a/gcc/c-family/c-ada-spec.c b/gcc/c-family/c-ada-spec.c
index 9c7de23..c6447ab 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_user_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_user_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 b8fc1c6..2e5a44e 100644
--- a/gcc/c-family/c-ppoutput.c
+++ b/gcc/c-family/c-ppoutput.c
@@ -532,13 +532,14 @@ static void
cb_used_define (cpp_reader *pfile, source_location line ATTRIBUTE_UNUSED,
cpp_hashnode *node)
{
- macro_queue *q;
- if (node->flags & NODE_BUILTIN)
- return;
- q = XNEW (macro_queue);
- q->macro = xstrdup ((const char *) cpp_macro_definition (pfile, node));
- q->next = define_queue;
- define_queue = q;
+ if (cpp_user_macro_p (node))
+ {
+ macro_queue *q;
+ q = XNEW (macro_queue);
+ q->macro = xstrdup ((const char *) cpp_macro_definition (pfile, node));
+ q->next = define_queue;
+ define_queue = q;
+ }
}
static void
@@ -688,7 +689,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_user_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 c0975d3..85fd278 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))
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_user_macro_p (hashnode)
+ && 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 157c185..0e69ebb 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);
+
/* 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 f37f0b1..4d5e3c2 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);
+
/* 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/cp/name-lookup.c b/gcc/cp/name-lookup.c
index 0faf739..3ba7644 100644
--- a/gcc/cp/name-lookup.c
+++ b/gcc/cp/name-lookup.c
@@ -5954,10 +5954,10 @@ lookup_name_fuzzy (tree name, enum lookup_name_fuzzy_kind kind, location_t loc)
/* If we have an exact match for a macro name, then either the
macro was used with the wrong argument count, or the macro
has been used before it was defined. */
- cpp_hashnode *macro = bmm.blithely_get_best_candidate ();
- if (macro && (macro->flags & NODE_BUILTIN) == 0)
- return name_hint (NULL,
- macro_use_before_def::maybe_make (loc, macro));
+ if (cpp_hashnode *macro = bmm.blithely_get_best_candidate ())
+ if (cpp_user_macro_p (macro))
+ return name_hint (NULL,
+ macro_use_before_def::maybe_make (loc, macro));
}
/* Try the "starts_decl_specifier_p" keywords to detect
diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog
index e440352..dc4aa1a 100644
--- a/gcc/fortran/ChangeLog
+++ b/gcc/fortran/ChangeLog
@@ -1,3 +1,7 @@
+2018-08-16 Nathan Sidwell <nathan@acm.org>
+
+ * cpp.c (dump_macro): Use cpp_user_macro_p.
+
2018-08-14 Janus Weil <janus@gcc.gnu.org>
PR fortran/86116
diff --git a/gcc/fortran/cpp.c b/gcc/fortran/cpp.c
index 4320461..0b3de42 100644
--- a/gcc/fortran/cpp.c
+++ b/gcc/fortran/cpp.c
@@ -990,7 +990,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_user_macro_p (node))
{
fputs ("#define ", print.outf);
fputs ((const char *) cpp_macro_definition (pfile, node),