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>
* config/sparc/sparc.c (sparc_va_arg): When the required alignment
......
......@@ -281,3 +281,16 @@ cpp_forall_identifiers (pfile, cb, v)
}
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)
cppchar_t c;
cpp_buffer *buffer;
const unsigned char *comment_start;
unsigned char was_skip_newlines = pfile->state.skip_newlines;
unsigned char newline_in_args = 0;
unsigned char bol = pfile->state.skip_newlines;
done_directive:
buffer = pfile->buffer;
......@@ -884,33 +883,23 @@ _cpp_lex_token (pfile, result)
goto next_char2;
case '\n': case '\r':
/* Don't let directives spill over to the next line. */
if (pfile->state.in_directive)
buffer->read_ahead = c;
else
if (!pfile->state.in_directive)
{
handle_newline (buffer, c);
bol = 1;
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)
{
/* Set the whitespace flag. */
newline_in_args = 1;
result->flags |= PREV_WHITE;
goto next_char;
}
if (was_skip_newlines)
{
/* Clear any whitespace flag. */
result->flags &= ~PREV_WHITE;
goto next_char;
}
result->flags |= PREV_WHITE;
else
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;
result->type = CPP_EOF;
break;
......@@ -1172,12 +1161,16 @@ _cpp_lex_token (pfile, result)
c = get_effective_char (buffer);
if (c == '#')
ACCEPT_CHAR (CPP_PASTE);
else
{
result->type = CPP_HASH;
do_hash:
if (newline_in_args)
ACCEPT_CHAR (CPP_PASTE);
break;
}
result->type = CPP_HASH;
do_hash:
if (bol)
{
if (pfile->state.parsing_args)
{
/* 6.10.3 paragraph 11: If there are sequences of
preprocessing tokens within the list of arguments that
......@@ -1200,11 +1193,11 @@ _cpp_lex_token (pfile, result)
if (pfile->lexer_pos.col == 1)
result->flags &= ~PREV_WHITE;
}
else if (was_skip_newlines)
else
{
/* This is the hash introducing a directive. */
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 #. */
}
}
......
/* CPP Library.
/* CPP Library. (Directive handling.)
Copyright (C) 1986, 1987, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
1999, 2000 Free Software Foundation, Inc.
Contributed by Per Bothner, 1994-95.
......@@ -837,12 +837,7 @@ do_ident (pfile)
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 happens for other pragmas is implementation defined.
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. */
This implementation never macro-expands the text after #pragma. */
/* Sub-handlers for the pragmas needing treatment here.
They return 1 if the token buffer is to be popped, 0 if not. */
......@@ -1700,19 +1695,6 @@ handle_assertion (pfile, str, type)
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
buffer stack. If BUFFER != NULL, then use the LENGTH characters in
BUFFER as the new input buffer. Return the new buffer, or NULL on
......
......@@ -902,9 +902,10 @@ _cpp_pop_context (pfile)
}
/* Internal routine to return a token, either from an in-progress
macro expansion, or from the source file as appropriate. Handles
macros, so tokens returned are post-expansion. Does not filter
CPP_PLACEMARKER tokens. Returns CPP_EOF at EOL and EOF. */
macro expansion, or from the source file as appropriate.
Transparently enters included files. Handles macros, so tokens
returned are post-expansion. Does not filter CPP_PLACEMARKER
tokens. Returns CPP_EOF at EOL and EOF. */
void
_cpp_get_token (pfile, token)
cpp_reader *pfile;
......@@ -929,6 +930,7 @@ _cpp_get_token (pfile, token)
_cpp_pop_context (pfile);
continue;
}
/* End of argument pre-expansion. */
token->type = CPP_EOF;
token->flags = 0;
}
......@@ -981,12 +983,13 @@ _cpp_get_token (pfile, token)
/* External interface to get a token. Tokens are returned after macro
expansion and directives have been handled, as a continuous stream.
Transparently enters included files. CPP_EOF indicates end of
original source file. Filters out CPP_PLACEMARKER tokens.
Compared to the function above, CPP_EOF means EOF, and placemarker
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
pragma's tokens, returns CPP_EOF to indicate end-of-directive in
this case. */
CPP_EOF indicates end of original source file. For the benefit of
#pragma callbacks which may want to get the pragma's tokens,
returns CPP_EOF to indicate end-of-directive in this case. */
void
cpp_get_token (pfile, token)
cpp_reader *pfile;
......@@ -997,13 +1000,7 @@ cpp_get_token (pfile, token)
_cpp_get_token (pfile, token);
if (token->type == CPP_EOF)
{
/* 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;
}
break;
/* 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)
......
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