mirror of
https://gcc.gnu.org/git/gcc.git
synced 2024-11-28 22:34:03 +08:00
Move directive handling into the lexer itself.
* cpplex.c (_cpp_lex_token): Handle directives directly. In the case of a directive interrupting a function-like macro invocation, use extra_char since read_ahead is used to store the '#'. Return a CPP_EOF in this case. * cppmacro.c (parse_arg): No need to handle CPP_DHASH any more. (cpp_get_token): Don't handle directives here. * cpplib.h: Remove CPP_DHASH token type. From-SVN: r37329
This commit is contained in:
parent
09ff8283a8
commit
adb84b4254
@ -1,3 +1,15 @@
|
||||
2000-11-08 Neil Booth <neilb@earthling.net>
|
||||
|
||||
Move directive handling into the lexer itself.
|
||||
|
||||
* cpplex.c (_cpp_lex_token): Handle directives directly.
|
||||
In the case of a directive interrupting a function-like
|
||||
macro invocation, use extra_char since read_ahead is
|
||||
used to store the '#'. Return a CPP_EOF in this case.
|
||||
* cppmacro.c (parse_arg): No need to handle CPP_DHASH any more.
|
||||
(cpp_get_token): Don't handle directives here.
|
||||
* cpplib.h: Remove CPP_DHASH token type.
|
||||
|
||||
Wed Nov 8 21:53:41 MET 2000 Jan Hubicka <jh@suse.cz>
|
||||
|
||||
* regmove.c (combine_stack_adjustments_for_blocks): Recognize pushes
|
||||
|
43
gcc/cpplex.c
43
gcc/cpplex.c
@ -844,11 +844,13 @@ _cpp_lex_token (pfile, result)
|
||||
cpp_token *result;
|
||||
{
|
||||
cppchar_t c;
|
||||
cpp_buffer *buffer = pfile->buffer;
|
||||
cpp_buffer *buffer;
|
||||
const unsigned char *comment_start;
|
||||
unsigned char was_skip_newlines = pfile->state.skip_newlines;
|
||||
unsigned char newline_in_args = 0;
|
||||
|
||||
done_directive:
|
||||
buffer = pfile->buffer;
|
||||
pfile->state.skip_newlines = 0;
|
||||
result->flags = 0;
|
||||
next_char:
|
||||
@ -1160,20 +1162,51 @@ _cpp_lex_token (pfile, result)
|
||||
break;
|
||||
|
||||
case '#':
|
||||
if (get_effective_char (buffer) == '#')
|
||||
c = buffer->extra_char; /* Can be set by error condition below. */
|
||||
if (c != EOF)
|
||||
{
|
||||
buffer->read_ahead = c;
|
||||
buffer->extra_char = EOF;
|
||||
}
|
||||
else
|
||||
c = get_effective_char (buffer);
|
||||
|
||||
if (c == '#')
|
||||
ACCEPT_CHAR (CPP_PASTE);
|
||||
else
|
||||
{
|
||||
result->type = CPP_HASH;
|
||||
do_hash:
|
||||
/* CPP_DHASH is the hash introducing a directive. */
|
||||
if (was_skip_newlines || newline_in_args)
|
||||
if (newline_in_args)
|
||||
{
|
||||
result->type = CPP_DHASH;
|
||||
/* 6.10.3 paragraph 11: If there are sequences of
|
||||
preprocessing tokens within the list of arguments that
|
||||
would otherwise act as preprocessing directives, the
|
||||
behavior is undefined.
|
||||
|
||||
This implementation will report a hard error, terminate
|
||||
the macro invocation, and proceed to process the
|
||||
directive. */
|
||||
cpp_error (pfile,
|
||||
"directives may not be used inside a macro argument");
|
||||
|
||||
/* Put a '#' in lookahead, return CPP_EOF for parse_arg. */
|
||||
buffer->extra_char = buffer->read_ahead;
|
||||
buffer->read_ahead = '#';
|
||||
pfile->state.skip_newlines = 1;
|
||||
result->type = CPP_EOF;
|
||||
|
||||
/* Get whitespace right - newline_in_args sets it. */
|
||||
if (pfile->lexer_pos.col == 1)
|
||||
result->flags &= ~PREV_WHITE;
|
||||
}
|
||||
else if (was_skip_newlines)
|
||||
{
|
||||
/* This is the hash introducing a directive. */
|
||||
if (_cpp_handle_directive (pfile, result->flags & PREV_WHITE))
|
||||
goto done_directive; /* was_skip_newlines still 1. */
|
||||
/* This is in fact an assembler #. */
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -139,7 +139,6 @@ struct htab;
|
||||
TK(CPP_HEADER_NAME, SPELL_STRING) /* <stdio.h> in #include */ \
|
||||
\
|
||||
TK(CPP_COMMENT, SPELL_STRING) /* Only if output comments. */ \
|
||||
TK(CPP_DHASH, SPELL_NONE) /* The # of a directive. */ \
|
||||
TK(CPP_MACRO_ARG, SPELL_NONE) /* Macro argument. */ \
|
||||
TK(CPP_PLACEMARKER, SPELL_NONE) /* Placemarker token. */ \
|
||||
OP(CPP_EOF, "EOL") /* End of line or file. */
|
||||
|
@ -534,21 +534,6 @@ parse_arg (pfile, arg, var_args)
|
||||
break;
|
||||
else if (result == CPP_EOF)
|
||||
break; /* Error reported by caller. */
|
||||
else if (result == CPP_DHASH)
|
||||
{
|
||||
/* 6.10.3 paragraph 11: If there are sequences of
|
||||
preprocessing tokens within the list of arguments that
|
||||
would otherwise act as preprocessing directives, the
|
||||
behavior is undefined.
|
||||
|
||||
This implementation will report a hard error, terminate
|
||||
the macro invocation, and proceed to process the
|
||||
directive. */
|
||||
cpp_error (pfile, "directives may not be used inside a macro argument");
|
||||
_cpp_push_token (pfile, token, &pfile->lexer_pos);
|
||||
result = CPP_EOF;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Empty arguments become a single placemarker token. */
|
||||
@ -1019,16 +1004,6 @@ cpp_get_token (pfile, token)
|
||||
break;
|
||||
continue;
|
||||
}
|
||||
else if (token->type == CPP_DHASH)
|
||||
{
|
||||
/* Handle directives. */
|
||||
if (_cpp_handle_directive (pfile, token->flags & PREV_WHITE))
|
||||
continue;
|
||||
/* This is in fact an assembler #. */
|
||||
if (pfile->skipping)
|
||||
continue;
|
||||
token->type = CPP_HASH;
|
||||
}
|
||||
/* We are not merging the PREV_WHITE of CPP_PLACEMARKERS. I
|
||||
don't think it really matters. */
|
||||
else if (pfile->skipping || token->type == CPP_PLACEMARKER)
|
||||
|
Loading…
Reference in New Issue
Block a user