This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: Objective C lexer - small cleanup
- To: Neil Booth <neil at daikokuya dot demon dot co dot uk>
- Subject: Re: Objective C lexer - small cleanup
- From: "Zack Weinberg" <zackw at Stanford dot EDU>
- Date: Sun, 1 Jul 2001 11:47:42 -0700
- Cc: Stan Shebs <shebs at apple dot com>, gcc-patches at gcc dot gnu dot org
I've now applied the original patch. Also, I found a place in
cpplib.c where we were doing an unnecessary test for leading '@'
in identifiers (which never happens, since we've decided that that
doesn't work).
Bootstrapped i686-linux.
A word about references to the C standard: "6.10.8.4" is ambiguous.
It could mean paragraph 4 of section 6.10.8, or all of section
6.10.8.4. I prefer to indicate that the last digit is a paragraph
number, "6.10.8p4".
The C++ standard nicely avoids this problem by giving all the sections
names.
--
zw Actually, we have scientifically determined that Heisenberg did indeed
sleep exactly here. However, we have no idea whatsoever just how fast
asleep he was.
-- Dave Aronson
* cpplib.c (lex_macro_node): Remove unnecessary check for
leading '@' on identifier. Clarify control flow and commentary.
===================================================================
Index: cpplib.c
--- cpplib.c 2001/05/27 18:06:00 1.253
+++ cpplib.c 2001/07/01 18:45:01
@@ -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
- {
- 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;
+ node = token.val.node;
+ if (node->flags & NODE_POISONED)
+ return 0;
+
+ if (node == pfile->spec_nodes.n_defined)
+ {
+ 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. */