Commit a949941c by Neil Booth Committed by Neil Booth

cpphash.c: Move cpp_defined here from cpplib.c.

        * cpphash.c: Move cpp_defined here from cpplib.c.
        * cpplib.c: Update comments, move cpp_defined to cpphash.c.
        * cpplex.c (_cpp_lex_token): Don't leave the lexer at EOL.
        * cppmacro.c (cpp_get_token): Update comments, no need now
        to catch the CPP_EOF meaning EOL case.

From-SVN: r37345
parent 9a0662b4
2000-11-09 Neil Booth <neilb@earthling.net>
* cpphash.c: Move cpp_defined here from cpplib.c.
* cpplib.c: Update comments, move cpp_defined to cpphash.c.
* cpplex.c (_cpp_lex_token): Don't leave the lexer at EOL.
* cppmacro.c (cpp_get_token): Update comments, no need now
to catch the CPP_EOF meaning EOL case.
2000-11-08 Geoffrey Keating <geoffk@redhat.com> 2000-11-08 Geoffrey Keating <geoffk@redhat.com>
* config/sparc/sparc.c (sparc_va_arg): When the required alignment * config/sparc/sparc.c (sparc_va_arg): When the required alignment
......
...@@ -281,3 +281,16 @@ cpp_forall_identifiers (pfile, cb, v) ...@@ -281,3 +281,16 @@ cpp_forall_identifiers (pfile, cb, v)
} }
while (++p < limit); while (++p < limit);
} }
/* Determine whether the identifier ID, of length LEN, is a defined macro. */
int
cpp_defined (pfile, id, len)
cpp_reader *pfile;
const U_CHAR *id;
int len;
{
cpp_hashnode *hp = cpp_lookup (pfile, id, len);
/* If it's of type NT_MACRO, it cannot be poisoned. */
return hp->type == NT_MACRO;
}
...@@ -846,8 +846,7 @@ _cpp_lex_token (pfile, result) ...@@ -846,8 +846,7 @@ _cpp_lex_token (pfile, result)
cppchar_t c; cppchar_t c;
cpp_buffer *buffer; cpp_buffer *buffer;
const unsigned char *comment_start; const unsigned char *comment_start;
unsigned char was_skip_newlines = pfile->state.skip_newlines; unsigned char bol = pfile->state.skip_newlines;
unsigned char newline_in_args = 0;
done_directive: done_directive:
buffer = pfile->buffer; buffer = pfile->buffer;
...@@ -884,33 +883,23 @@ _cpp_lex_token (pfile, result) ...@@ -884,33 +883,23 @@ _cpp_lex_token (pfile, result)
goto next_char2; goto next_char2;
case '\n': case '\r': case '\n': case '\r':
/* Don't let directives spill over to the next line. */ if (!pfile->state.in_directive)
if (pfile->state.in_directive)
buffer->read_ahead = c;
else
{ {
handle_newline (buffer, c); handle_newline (buffer, c);
bol = 1;
pfile->lexer_pos.output_line = buffer->lineno; pfile->lexer_pos.output_line = buffer->lineno;
/* Skip newlines in macro arguments (except in directives). */ /* Newlines in arguments are white space (6.10.3.10).
Otherwise, clear any white space flag. */
if (pfile->state.parsing_args) if (pfile->state.parsing_args)
{ result->flags |= PREV_WHITE;
/* Set the whitespace flag. */ else
newline_in_args = 1; result->flags &= ~PREV_WHITE;
result->flags |= PREV_WHITE; goto next_char;
goto next_char;
}
if (was_skip_newlines)
{
/* Clear any whitespace flag. */
result->flags &= ~PREV_WHITE;
goto next_char;
}
} }
/* Next we're at BOL, so skip new lines. */ /* Don't let directives spill over to the next line. */
buffer->read_ahead = c;
pfile->state.skip_newlines = 1; pfile->state.skip_newlines = 1;
result->type = CPP_EOF; result->type = CPP_EOF;
break; break;
...@@ -1172,12 +1161,16 @@ _cpp_lex_token (pfile, result) ...@@ -1172,12 +1161,16 @@ _cpp_lex_token (pfile, result)
c = get_effective_char (buffer); c = get_effective_char (buffer);
if (c == '#') if (c == '#')
ACCEPT_CHAR (CPP_PASTE);
else
{ {
result->type = CPP_HASH; ACCEPT_CHAR (CPP_PASTE);
do_hash: break;
if (newline_in_args) }
result->type = CPP_HASH;
do_hash:
if (bol)
{
if (pfile->state.parsing_args)
{ {
/* 6.10.3 paragraph 11: If there are sequences of /* 6.10.3 paragraph 11: If there are sequences of
preprocessing tokens within the list of arguments that preprocessing tokens within the list of arguments that
...@@ -1200,11 +1193,11 @@ _cpp_lex_token (pfile, result) ...@@ -1200,11 +1193,11 @@ _cpp_lex_token (pfile, result)
if (pfile->lexer_pos.col == 1) if (pfile->lexer_pos.col == 1)
result->flags &= ~PREV_WHITE; result->flags &= ~PREV_WHITE;
} }
else if (was_skip_newlines) else
{ {
/* This is the hash introducing a directive. */ /* This is the hash introducing a directive. */
if (_cpp_handle_directive (pfile, result->flags & PREV_WHITE)) if (_cpp_handle_directive (pfile, result->flags & PREV_WHITE))
goto done_directive; /* was_skip_newlines still 1. */ goto done_directive; /* bol still 1. */
/* This is in fact an assembler #. */ /* This is in fact an assembler #. */
} }
} }
......
/* CPP Library. /* CPP Library. (Directive handling.)
Copyright (C) 1986, 1987, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, Copyright (C) 1986, 1987, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
1999, 2000 Free Software Foundation, Inc. 1999, 2000 Free Software Foundation, Inc.
Contributed by Per Bothner, 1994-95. Contributed by Per Bothner, 1994-95.
...@@ -837,12 +837,7 @@ do_ident (pfile) ...@@ -837,12 +837,7 @@ do_ident (pfile)
to the front end. C99 defines three pragmas and says that no macro to the front end. C99 defines three pragmas and says that no macro
expansion is to be performed on them; whether or not macro expansion is to be performed on them; whether or not macro
expansion happens for other pragmas is implementation defined. expansion happens for other pragmas is implementation defined.
This implementation never macro-expands the text after #pragma. This implementation never macro-expands the text after #pragma. */
We currently do not support the _Pragma operator. Support for that
has to be coordinated with the front end. Proposed implementation:
both #pragma blah blah and _Pragma("blah blah") become
__builtin_pragma(blah blah) and we teach the parser about that. */
/* Sub-handlers for the pragmas needing treatment here. /* Sub-handlers for the pragmas needing treatment here.
They return 1 if the token buffer is to be popped, 0 if not. */ They return 1 if the token buffer is to be popped, 0 if not. */
...@@ -1700,19 +1695,6 @@ handle_assertion (pfile, str, type) ...@@ -1700,19 +1695,6 @@ handle_assertion (pfile, str, type)
run_directive (pfile, type, str, count, 0); run_directive (pfile, type, str, count, 0);
} }
/* Determine whether the identifier ID, of length LEN, is a defined macro. */
int
cpp_defined (pfile, id, len)
cpp_reader *pfile;
const U_CHAR *id;
int len;
{
cpp_hashnode *hp = cpp_lookup (pfile, id, len);
/* If it's of type NT_MACRO, it cannot be poisoned. */
return hp->type == NT_MACRO;
}
/* Allocate a new cpp_buffer for PFILE, and push it on the input /* Allocate a new cpp_buffer for PFILE, and push it on the input
buffer stack. If BUFFER != NULL, then use the LENGTH characters in buffer stack. If BUFFER != NULL, then use the LENGTH characters in
BUFFER as the new input buffer. Return the new buffer, or NULL on BUFFER as the new input buffer. Return the new buffer, or NULL on
......
...@@ -902,9 +902,10 @@ _cpp_pop_context (pfile) ...@@ -902,9 +902,10 @@ _cpp_pop_context (pfile)
} }
/* Internal routine to return a token, either from an in-progress /* Internal routine to return a token, either from an in-progress
macro expansion, or from the source file as appropriate. Handles macro expansion, or from the source file as appropriate.
macros, so tokens returned are post-expansion. Does not filter Transparently enters included files. Handles macros, so tokens
CPP_PLACEMARKER tokens. Returns CPP_EOF at EOL and EOF. */ returned are post-expansion. Does not filter CPP_PLACEMARKER
tokens. Returns CPP_EOF at EOL and EOF. */
void void
_cpp_get_token (pfile, token) _cpp_get_token (pfile, token)
cpp_reader *pfile; cpp_reader *pfile;
...@@ -929,6 +930,7 @@ _cpp_get_token (pfile, token) ...@@ -929,6 +930,7 @@ _cpp_get_token (pfile, token)
_cpp_pop_context (pfile); _cpp_pop_context (pfile);
continue; continue;
} }
/* End of argument pre-expansion. */
token->type = CPP_EOF; token->type = CPP_EOF;
token->flags = 0; token->flags = 0;
} }
...@@ -981,12 +983,13 @@ _cpp_get_token (pfile, token) ...@@ -981,12 +983,13 @@ _cpp_get_token (pfile, token)
/* External interface to get a token. Tokens are returned after macro /* External interface to get a token. Tokens are returned after macro
expansion and directives have been handled, as a continuous stream. expansion and directives have been handled, as a continuous stream.
Transparently enters included files. CPP_EOF indicates end of Compared to the function above, CPP_EOF means EOF, and placemarker
original source file. Filters out CPP_PLACEMARKER tokens. tokens are filtered out. Also, it skips tokens if we're skipping,
and saves tokens to lookahead.
For the benefit of #pragma callbacks which may want to get the CPP_EOF indicates end of original source file. For the benefit of
pragma's tokens, returns CPP_EOF to indicate end-of-directive in #pragma callbacks which may want to get the pragma's tokens,
this case. */ returns CPP_EOF to indicate end-of-directive in this case. */
void void
cpp_get_token (pfile, token) cpp_get_token (pfile, token)
cpp_reader *pfile; cpp_reader *pfile;
...@@ -997,13 +1000,7 @@ cpp_get_token (pfile, token) ...@@ -997,13 +1000,7 @@ cpp_get_token (pfile, token)
_cpp_get_token (pfile, token); _cpp_get_token (pfile, token);
if (token->type == CPP_EOF) if (token->type == CPP_EOF)
{ break;
/* In directives we should pass through EOLs for the callbacks. */
if (pfile->buffer->cur == pfile->buffer->rlimit
|| pfile->state.in_directive || pfile->state.parsing_args)
break;
continue;
}
/* We are not merging the PREV_WHITE of CPP_PLACEMARKERS. I /* We are not merging the PREV_WHITE of CPP_PLACEMARKERS. I
don't think it really matters. */ don't think it really matters. */
else if (pfile->skipping || token->type == CPP_PLACEMARKER) else if (pfile->skipping || token->type == CPP_PLACEMARKER)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment