aboutsummaryrefslogtreecommitdiff
path: root/gcc/cpplib.c
diff options
context:
space:
mode:
authorZack Weinberg <zack@gcc.gnu.org>2000-07-19 20:18:08 +0000
committerZack Weinberg <zack@gcc.gnu.org>2000-07-19 20:18:08 +0000
commit92936ecf1a27517ac0b96c5af6a5ae9664faf3f3 (patch)
treefb27fc4ef85133963af7127518d36e07b5e1d021 /gcc/cpplib.c
parentb86db3ebc22f22aae3f7dddadc90c9b1841ebe1a (diff)
downloadgcc-92936ecf1a27517ac0b96c5af6a5ae9664faf3f3.zip
gcc-92936ecf1a27517ac0b96c5af6a5ae9664faf3f3.tar.gz
gcc-92936ecf1a27517ac0b96c5af6a5ae9664faf3f3.tar.bz2
cpplib.h (TTYPE_TABLE): Move CPP_MIN and CPP_MAX into block of operators allowed in #if...
* cpplib.h (TTYPE_TABLE): Move CPP_MIN and CPP_MAX into block of operators allowed in #if and having an _EQ variant. Add CPP_MIN_EQ, CPP_MAX_EQ, and CPP_DEFINED. (cpp_token flags): Add NAMED_OP. (enum node_type): Add T_OPERATOR. (struct cpp_hashnode): Add code slot to value union. * cpphash.h (spec_nodes): Remove n_defined. * cpplex.c (lex_line): Convert T_OPERATOR nodes to their proper types. (spell_token, can_paste, maybe_paste_with_next): Handle named operators. (is_macro_disabled): Tweak error messages. * cpplib.c (get_define_node): Disallow all named operators as macro names. Tweak error messages. (_cpp_init_stacks): Don't set up spec_nodes->n_defined. * cppinit.c (builtin_array): Add entries for the named operators. * cppexp.c (lex): Check for CPP_DEFINED token. (priority table): Add entries for CPP_MIN and CPP_MAX. (_cpp_parse_expr): Handle CPP_MIN and CPP_MAX. testsuite: * gcc.dg/cpp/directiv.c, gcc.dg/cpp/macsyntx.c, gcc.dg/cpp/undef1.c: Tweak error regexps. From-SVN: r35137
Diffstat (limited to 'gcc/cpplib.c')
-rw-r--r--gcc/cpplib.c44
1 files changed, 22 insertions, 22 deletions
diff --git a/gcc/cpplib.c b/gcc/cpplib.c
index 520821a..f39ff0e 100644
--- a/gcc/cpplib.c
+++ b/gcc/cpplib.c
@@ -236,39 +236,42 @@ static cpp_hashnode *
get_define_node (pfile)
cpp_reader *pfile;
{
- cpp_hashnode *node;
const cpp_token *token;
/* Skip any -C comments. */
while ((token = _cpp_get_token (pfile))->type == CPP_COMMENT)
;
+ /* The token immediately after #define must be an identifier. That
+ identifier is not allowed to be "defined". See predefined macro
+ names (6.10.8.4). In C++, it is not allowed to be any of the
+ <iso646.h> macro names (which are keywords in C++) either. */
+
if (token->type != CPP_NAME)
{
- cpp_error_with_line (pfile, token->line, token->col,
+ if (token->type == CPP_DEFINED)
+ cpp_error_with_line (pfile, token->line, token->col,
+ "\"defined\" cannot be used as a macro name");
+ else if (token->flags & NAMED_OP)
+ cpp_error_with_line (pfile, token->line, token->col,
+ "\"%s\" cannot be used as a macro name in C++",
+ token->val.node->name);
+ else
+ cpp_error_with_line (pfile, token->line, token->col,
"macro names must be identifiers");
return 0;
}
- /* That identifier is not allowed to be "defined". See predefined
- macro names (6.10.8.4). */
- node = token->val.node;
-
- if (node == pfile->spec_nodes->n_defined)
- {
- cpp_error_with_line (pfile, pfile->token_list.line, token->col,
- "\"defined\" is not a legal macro name");
- return 0;
- }
-
/* Check for poisoned identifiers now. */
- if (node->type == T_POISON)
+ if (token->val.node->type == T_POISON)
{
- cpp_error (pfile, "attempt to use poisoned \"%s\"", node->name);
+ cpp_error_with_line (pfile, token->line, token->col,
+ "attempt to use poisoned \"%s\"",
+ token->val.node->name);
return 0;
}
- return node;
+ return token->val.node;
}
/* Process a #define command. */
@@ -876,8 +879,8 @@ do_pragma_dependency (pfile)
_cpp_dump_list (pfile, &pfile->token_list, msg, 0);
limit = pfile->limit;
pfile->limit = text;
+ /* There must be something non-whitespace after. */
while (*text == ' ')
- /* There must be something non-whitespace after. */
text++;
cpp_warning (pfile, "%.*s", (int)(limit - text), text);
}
@@ -915,8 +918,7 @@ detect_if_not_defined (pfile)
return 0;
token++;
- if (token->type != CPP_NAME
- || token->val.node != pfile->spec_nodes->n_defined)
+ if (token->type != CPP_DEFINED)
return 0;
token++;
@@ -1338,8 +1340,7 @@ do_assert (pfile)
return;
err:
- cpp_warning (pfile, "\"%.*s\" re-asserted",
- node->length - 1, node->name + 1);
+ cpp_warning (pfile, "\"%s\" re-asserted", node->name + 1);
FREE_ANSWER (new_answer);
}
@@ -1535,7 +1536,6 @@ _cpp_init_stacks (pfile)
/* Perhaps not the ideal place to put this. */
pfile->spec_nodes = s = xnew (struct spec_nodes);
s->n_L = cpp_lookup (pfile, DSC("L"));
- s->n_defined = cpp_lookup (pfile, DSC("defined"));
s->n__STRICT_ANSI__ = cpp_lookup (pfile, DSC("__STRICT_ANSI__"));
s->n__CHAR_UNSIGNED__ = cpp_lookup (pfile, DSC("__CHAR_UNSIGNED__"));
s->n__VA_ARGS__ = cpp_lookup (pfile, DSC("__VA_ARGS__"));