aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gcc/ChangeLog17
-rw-r--r--gcc/cppexp.c9
-rw-r--r--gcc/cpphash.h1
-rw-r--r--gcc/cpplex.c4
-rw-r--r--gcc/cpplib.c33
-rw-r--r--gcc/cppmacro.c56
6 files changed, 69 insertions, 51 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 570dbe5..57c300f 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,20 @@
+2000-11-14 Neil Booth <neilb@earthling.net>
+
+ * cppexp.c (parse_defined): Call cpp_get_token not
+ _cpp_get_token.
+ (lex): Similarly.
+ * cpplex.c (cpp_output_line): Similarly.
+ * cpplib.c (glue_header_name, do_line, do_ident,
+ parse_answer, parse_assertion): Similarly.
+ (_cpp_handle_diretive): Don't save to lookaheads
+ when processing directives.
+ * cppmacro.c (parse_arg, expand_arg): Call cpp_get_token not
+ _cpp_get_token.
+ (funlike_invocation_p): Don't save to lookaheads
+ when pre-expanding arguments.
+ (_cpp_get_token): Delete.
+ (cpp_get_token): Merge contents of _cpp_get_token.
+
2000-11-14 Jakub Jelinek <jakub@redhat.com>
* builtins.c (expand_builtin_setjmp): Set
diff --git a/gcc/cppexp.c b/gcc/cppexp.c
index 82f8aab..98bd94e 100644
--- a/gcc/cppexp.c
+++ b/gcc/cppexp.c
@@ -321,11 +321,11 @@ parse_defined (pfile)
/* Don't expand macros. */
pfile->state.prevent_expansion++;
- _cpp_get_token (pfile, &token);
+ cpp_get_token (pfile, &token);
if (token.type == CPP_OPEN_PAREN)
{
paren = 1;
- _cpp_get_token (pfile, &token);
+ cpp_get_token (pfile, &token);
}
if (token.type == CPP_NAME)
@@ -333,7 +333,7 @@ parse_defined (pfile)
node = token.val.node;
if (paren)
{
- _cpp_get_token (pfile, &token);
+ cpp_get_token (pfile, &token);
if (token.type != CPP_CLOSE_PAREN)
{
cpp_error (pfile, "missing ')' after \"defined\"");
@@ -378,13 +378,14 @@ lex (pfile, skip_evaluation, token)
{
struct op op;
- _cpp_get_token (pfile, token);
+ cpp_get_token (pfile, token);
switch (token->type)
{
case CPP_INT:
case CPP_NUMBER:
return parse_number (pfile, token);
+
case CPP_CHAR:
case CPP_WCHAR:
return parse_charconst (pfile, token);
diff --git a/gcc/cpphash.h b/gcc/cpphash.h
index ebccda6..ccbe1c7 100644
--- a/gcc/cpphash.h
+++ b/gcc/cpphash.h
@@ -158,7 +158,6 @@ extern int _cpp_begin_message PARAMS ((cpp_reader *, enum error_type,
extern void _cpp_free_definition PARAMS ((cpp_hashnode *));
extern int _cpp_create_definition PARAMS ((cpp_reader *, cpp_hashnode *));
extern void _cpp_pop_context PARAMS ((cpp_reader *));
-extern void _cpp_get_token PARAMS ((cpp_reader *, cpp_token *));
extern void _cpp_free_lookaheads PARAMS ((cpp_reader *));
extern void _cpp_release_lookahead PARAMS ((cpp_reader *));
extern void _cpp_push_token PARAMS ((cpp_reader *, const cpp_token *,
diff --git a/gcc/cpplex.c b/gcc/cpplex.c
index 8717104..96e2454 100644
--- a/gcc/cpplex.c
+++ b/gcc/cpplex.c
@@ -1677,12 +1677,12 @@ cpp_output_line (pfile, fp)
{
cpp_token token;
- _cpp_get_token (pfile, &token);
+ cpp_get_token (pfile, &token);
token.flags &= ~PREV_WHITE;
while (token.type != CPP_EOF)
{
cpp_output_token (&token, fp);
- _cpp_get_token (pfile, &token);
+ cpp_get_token (pfile, &token);
}
putc ('\n', fp);
diff --git a/gcc/cpplib.c b/gcc/cpplib.c
index 77cf6cd..caa319a 100644
--- a/gcc/cpplib.c
+++ b/gcc/cpplib.c
@@ -183,7 +183,7 @@ skip_rest_of_line (pfile)
{
cpp_token token;
- /* Discard all lookaheads. */
+ /* Discard all input lookaheads. */
while (pfile->la_read)
_cpp_release_lookahead (pfile);
@@ -221,18 +221,22 @@ _cpp_handle_directive (pfile, indented)
cpp_reader *pfile;
int indented;
{
+ struct cpp_lookahead *la_saved;
cpp_buffer *buffer = pfile->buffer;
const directive *dir = 0;
cpp_token dname;
int not_asm = 1;
+ /* Setup in-directive state. */
+ pfile->state.in_directive = 1;
+ pfile->state.save_comments = 0;
+
/* Some handlers need the position of the # for diagnostics. */
pfile->directive_pos = pfile->lexer_pos;
- /* We're now in a directive. This ensures we get pedantic warnings
- about /v and /f in whitespace. */
- pfile->state.in_directive = 1;
- pfile->state.save_comments = 0;
+ /* Don't save directive tokens for external clients. */
+ la_saved = pfile->la_write;
+ pfile->la_write = 0;
/* Lex the directive name directly. */
_cpp_lex_token (pfile, &dname);
@@ -334,6 +338,9 @@ _cpp_handle_directive (pfile, indented)
/* Save the lookahead token for assembler. */
if (not_asm)
skip_rest_of_line (pfile);
+
+ /* Restore state. */
+ pfile->la_write = la_saved;
pfile->state.save_comments = ! CPP_OPTION (pfile, discard_comments);
pfile->state.in_directive = 0;
pfile->state.angled_headers = 0;
@@ -496,7 +503,7 @@ glue_header_name (pfile, header)
buffer = (unsigned char *) xmalloc (capacity);
for (;;)
{
- _cpp_get_token (pfile, &token);
+ cpp_get_token (pfile, &token);
if (token.type == CPP_GREATER || token.type == CPP_EOF)
break;
@@ -703,7 +710,7 @@ do_line (pfile)
cpp_token token;
/* #line commands expand macros. */
- _cpp_get_token (pfile, &token);
+ cpp_get_token (pfile, &token);
if (token.type != CPP_NUMBER
|| strtoul_for_line (token.val.str.text, token.val.str.len, &new_lineno))
{
@@ -715,7 +722,7 @@ do_line (pfile)
if (CPP_PEDANTIC (pfile) && (new_lineno == 0 || new_lineno > cap))
cpp_pedwarn (pfile, "line number out of range");
- _cpp_get_token (pfile, &token);
+ cpp_get_token (pfile, &token);
if (token.type != CPP_EOF)
{
@@ -829,7 +836,7 @@ do_ident (pfile)
{
cpp_token str;
- _cpp_get_token (pfile, &str);
+ cpp_get_token (pfile, &str);
if (str.type != CPP_STRING)
cpp_error (pfile, "invalid #ident");
else if (pfile->cb.ident)
@@ -1403,7 +1410,7 @@ parse_answer (pfile, answerp, type)
token = &answer->first[answer->count];
}
- _cpp_get_token (pfile, token);
+ cpp_get_token (pfile, token);
if (token->type == CPP_CLOSE_PAREN)
break;
@@ -1432,9 +1439,7 @@ parse_answer (pfile, answerp, type)
/* Parses an assertion, returning a pointer to the hash node of the
predicate, or 0 on error. If an answer was supplied, it is placed
- in ANSWERP, otherwise it is set to 0. We use _cpp_get_raw_token,
- since we cannot assume tokens are consecutive in a #if statement
- (we may be in a macro), and we don't want to macro expand. */
+ in ANSWERP, otherwise it is set to 0. */
static cpp_hashnode *
parse_assertion (pfile, answerp, type)
cpp_reader *pfile;
@@ -1451,7 +1456,7 @@ parse_assertion (pfile, answerp, type)
pfile->string_pool = &pfile->ident_pool;
*answerp = 0;
- _cpp_get_token (pfile, &predicate);
+ cpp_get_token (pfile, &predicate);
if (predicate.type == CPP_EOF)
cpp_error (pfile, "assertion without predicate");
else if (predicate.type != CPP_NAME)
diff --git a/gcc/cppmacro.c b/gcc/cppmacro.c
index 3d4af7e..35ecc4d 100644
--- a/gcc/cppmacro.c
+++ b/gcc/cppmacro.c
@@ -488,7 +488,7 @@ parse_arg (pfile, arg, var_args)
token = &arg->first[arg->count];
}
- _cpp_get_token (pfile, token);
+ cpp_get_token (pfile, token);
result = token->type;
if (result == CPP_OPEN_PAREN)
@@ -619,7 +619,13 @@ funlike_invocation_p (pfile, node, list)
if (args)
{
if (node->value.macro->paramc > 0)
- replace_args (pfile, node->value.macro, args, list);
+ {
+ /* Don't save tokens during pre-expansion. */
+ struct cpp_lookahead *la_saved = pfile->la_write;
+ pfile->la_write = 0;
+ replace_args (pfile, node->value.macro, args, list);
+ pfile->la_write = la_saved;
+ }
free (args);
}
@@ -846,7 +852,7 @@ expand_arg (pfile, arg)
xrealloc (arg->expanded, capacity * sizeof (cpp_token));
}
token = &arg->expanded[arg->expanded_count++];
- _cpp_get_token (pfile, token);
+ cpp_get_token (pfile, token);
}
while (token->type != CPP_EOF);
@@ -872,12 +878,19 @@ _cpp_pop_context (pfile)
}
}
-/* Internal routine to return a token, either from an in-progress
- macro expansion, or from the source file as appropriate.
- Transparently enters included files. Handles macros, so tokens
- returned are post-expansion. Returns CPP_EOF at EOL and EOF. */
+/* Eternal routine to get a token. Also used nearly everywhere
+ internally, except for places where we know we can safely call
+ the lexer directly, such as lexing a directive name.
+
+ Macro expansions and directives are transparently handled,
+ including entering included files. Thus tokens are post-macro
+ expansion, and after any intervening directives. External callers
+ see CPP_EOF only at EOF. Internal callers also see it when meeting
+ a directive inside a macro call, when at the end of a directive and
+ state.in_directive is still 1, and at the end of argument
+ pre-expansion. */
void
-_cpp_get_token (pfile, token)
+cpp_get_token (pfile, token)
cpp_reader *pfile;
cpp_token *token;
{
@@ -897,6 +910,9 @@ _cpp_get_token (pfile, token)
*token = *context->list.first++;
token->flags |= flags;
flags = 0;
+ /* PASTE_LEFT tokens can only appear in macro expansions. */
+ if (token->flags & PASTE_LEFT && !pfile->skipping)
+ paste_all_tokens (pfile, token);
}
else
{
@@ -915,9 +931,6 @@ _cpp_get_token (pfile, token)
if (pfile->skipping)
continue;
- if (token->flags & PASTE_LEFT)
- paste_all_tokens (pfile, token);
-
if (token->type != CPP_NAME)
break;
@@ -949,27 +962,10 @@ _cpp_get_token (pfile, token)
if (token->val.node != pfile->spec_nodes.n__Pragma)
break;
- /* Handle it, and get another token. */
- pfile->mi_state = MI_FAILED;
+ /* Handle it, and loop back for another token. MI is cleared
+ since this token came from either the lexer or a macro. */
_cpp_do__Pragma (pfile);
}
-}
-
-/* External interface to get a token. Tokens are returned after macro
- expansion and directives have been handled, as a continuous stream.
- 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.
-
- 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;
- cpp_token *token;
-{
- _cpp_get_token (pfile, token);
if (pfile->la_write)
save_lookahead_token (pfile, token);