aboutsummaryrefslogtreecommitdiff
path: root/gcc/cpplib.c
diff options
context:
space:
mode:
authorZack Weinberg <zackw@stanford.edu>2001-07-01 18:48:13 +0000
committerZack Weinberg <zack@gcc.gnu.org>2001-07-01 18:48:13 +0000
commitb8363a243d4778afbdcc3794c86a7e08eb076f76 (patch)
tree3248bbe65b87f7c0868d63322c7f0b313358975f /gcc/cpplib.c
parent128e8aa95204284655c889767409150181ce0b19 (diff)
downloadgcc-b8363a243d4778afbdcc3794c86a7e08eb076f76.zip
gcc-b8363a243d4778afbdcc3794c86a7e08eb076f76.tar.gz
gcc-b8363a243d4778afbdcc3794c86a7e08eb076f76.tar.bz2
c-common.h (enum rid): Add RID_FIRST_AT, RID_LAST_AT, RID_LAST_PQ.
* c-common.h (enum rid): Add RID_FIRST_AT, RID_LAST_AT, RID_LAST_PQ. Move RID_FIRST_PQ down with the other FIRST/LAST enumerators. (OBJC_IS_AT_KEYWORD, OBJC_IS_PQ_KEYWORD): New macros. * c-parse.in (OBJC_STRING): Kill. (objc_string): Decompose to [objc_string] '@' STRING. (reswords): Take the leading '@' off all the Objective C keywords. (objc_rid_sans_at): Kill. (init_reswords): Don't initialize it. (yylexname): Use OBJC_IS_AT_KEYWORD and OBJC_IS_PQ_KEYWORD. (_yylex): Kill reconsider label. Look ahead one token after an '@'; if we get an identifier, check whether it's an Objective C @-keyword. If so, return the keyword. Otherwise, put back the token and return the '@' as a terminal. * cpplib.c (lex_macro_node): Remove unnecessary check for leading '@' on identifier. Clarify control flow and commentary. From-SVN: r43674
Diffstat (limited to 'gcc/cpplib.c')
-rw-r--r--gcc/cpplib.c34
1 files changed, 19 insertions, 15 deletions
diff --git a/gcc/cpplib.c b/gcc/cpplib.c
index cb49310..e0f6124 100644
--- a/gcc/cpplib.c
+++ b/gcc/cpplib.c
@@ -438,14 +438,17 @@ lex_macro_node (pfile)
cpp_reader *pfile;
{
cpp_token token;
+ cpp_hashnode *node;
/* Lex the macro name directly. */
_cpp_lex_token (pfile, &token);
/* 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. */
+ identifier may not be "defined", per C99 6.10.8p4.
+ In C++, it may not be any of the "named operators" either,
+ per C++98 [lex.digraph], [lex.key].
+ Finally, the identifier may not have been poisoned. (In that case
+ the lexer has issued the error message for us.) */
if (token.type != CPP_NAME)
{
@@ -454,25 +457,26 @@ lex_macro_node (pfile)
pfile->directive->name);
else if (token.flags & NAMED_OP)
cpp_error (pfile,
- "\"%s\" cannot be used as a macro name as it is an operator in C++",
+ "\"%s\" cannot be used as a macro name as it is an operator in C++",
NODE_NAME (token.val.node));
else
cpp_error (pfile, "macro names must be identifiers");
+
+ return 0;
}
- else
+
+ node = token.val.node;
+ if (node->flags & NODE_POISONED)
+ return 0;
+
+ if (node == pfile->spec_nodes.n_defined)
{
- cpp_hashnode *node = token.val.node;
-
- /* In Objective C, some keywords begin with '@', but general
- identifiers do not, and you're not allowed to #define them. */
- if (node == pfile->spec_nodes.n_defined || NODE_NAME (node)[0] == '@')
- cpp_error (pfile, "\"%s\" cannot be used as a macro name",
- NODE_NAME (node));
- else if (!(node->flags & NODE_POISONED))
- return node;
+ cpp_error (pfile, "\"%s\" cannot be used as a macro name",
+ NODE_NAME (node));
+ return 0;
}
- return 0;
+ return node;
}
/* Process a #define directive. Most work is done in cppmacro.c. */