Commit 345894b4 by Neil Booth Committed by Neil Booth

cpphash.h (_cpp_lex_token): Update prototype.

	* cpphash.h (_cpp_lex_token): Update prototype.
	* cpplex.c (_cpp_lex_token): New prototype.
	* cpplib.c (skip_rest_of_line, check_eol, _cpp_handle_directive,
	lex_macro_node, read_flag, do_pragma_poison): Update.
	* cppmacro.c (cpp_get_token, parse_params,
	lex_expansion_token): Update.

From-SVN: r45646
parent 18a9d8ff
2001-09-16 Neil Booth <neil@daikokuya.demon.co.uk> 2001-09-16 Neil Booth <neil@daikokuya.demon.co.uk>
* cpphash.h (_cpp_lex_token): Update prototype.
* cpplex.c (_cpp_lex_token): New prototype.
* cpplib.c (skip_rest_of_line, check_eol, _cpp_handle_directive,
lex_macro_node, read_flag, do_pragma_poison): Update.
* cppmacro.c (cpp_get_token, parse_params,
lex_expansion_token): Update.
2001-09-16 Neil Booth <neil@daikokuya.demon.co.uk>
* cppmain.c (scan_translation_unit): Don't worry about * cppmain.c (scan_translation_unit): Don't worry about
putting a space after hashes. putting a space after hashes.
* cpplib.c (directive_diagnostics): New. * cpplib.c (directive_diagnostics): New.
......
...@@ -398,7 +398,7 @@ extern void _cpp_pop_file_buffer PARAMS ((cpp_reader *, ...@@ -398,7 +398,7 @@ extern void _cpp_pop_file_buffer PARAMS ((cpp_reader *,
extern int _cpp_parse_expr PARAMS ((cpp_reader *)); extern int _cpp_parse_expr PARAMS ((cpp_reader *));
/* In cpplex.c */ /* In cpplex.c */
extern void _cpp_lex_token PARAMS ((cpp_reader *, cpp_token *)); extern const cpp_token *_cpp_lex_token PARAMS ((cpp_reader *));
extern int _cpp_equiv_tokens PARAMS ((const cpp_token *, extern int _cpp_equiv_tokens PARAMS ((const cpp_token *,
const cpp_token *)); const cpp_token *));
extern void _cpp_init_tokenrun PARAMS ((tokenrun *, unsigned int)); extern void _cpp_init_tokenrun PARAMS ((tokenrun *, unsigned int));
......
...@@ -933,10 +933,9 @@ next_tokenrun (run) ...@@ -933,10 +933,9 @@ next_tokenrun (run)
} }
/* Lex a token into RESULT (external interface). */ /* Lex a token into RESULT (external interface). */
void const cpp_token *
_cpp_lex_token (pfile, dest) _cpp_lex_token (pfile)
cpp_reader *pfile; cpp_reader *pfile;
cpp_token *dest;
{ {
cpp_token *result; cpp_token *result;
...@@ -979,7 +978,7 @@ _cpp_lex_token (pfile, dest) ...@@ -979,7 +978,7 @@ _cpp_lex_token (pfile, dest)
break; break;
} }
*dest = *result; return result;
} }
/* Lex a token into RESULT. When meeting a newline, returns CPP_EOF /* Lex a token into RESULT. When meeting a newline, returns CPP_EOF
......
...@@ -185,15 +185,14 @@ static void ...@@ -185,15 +185,14 @@ static void
skip_rest_of_line (pfile) skip_rest_of_line (pfile)
cpp_reader *pfile; cpp_reader *pfile;
{ {
cpp_token token;
/* Discard all stacked contexts. */ /* Discard all stacked contexts. */
while (pfile->context != &pfile->base_context) while (pfile->context != &pfile->base_context)
_cpp_pop_context (pfile); _cpp_pop_context (pfile);
/* Sweep up all tokens remaining on the line. */ /* Sweep up all tokens remaining on the line. */
while (! SEEN_EOL ()) if (! SEEN_EOL ())
_cpp_lex_token (pfile, &token); while (_cpp_lex_token (pfile)->type != CPP_EOF)
;
} }
/* Ensure there are no stray tokens at the end of a directive. */ /* Ensure there are no stray tokens at the end of a directive. */
...@@ -201,15 +200,9 @@ static void ...@@ -201,15 +200,9 @@ static void
check_eol (pfile) check_eol (pfile)
cpp_reader *pfile; cpp_reader *pfile;
{ {
if (! SEEN_EOL ()) if (! SEEN_EOL () && _cpp_lex_token (pfile)->type != CPP_EOF)
{ cpp_pedwarn (pfile, "extra tokens at end of #%s directive",
cpp_token token; pfile->directive->name);
_cpp_lex_token (pfile, &token);
if (token.type != CPP_EOF)
cpp_pedwarn (pfile, "extra tokens at end of #%s directive",
pfile->directive->name);
}
} }
/* Called when entering a directive, _Pragma or command-line directive. */ /* Called when entering a directive, _Pragma or command-line directive. */
...@@ -307,20 +300,20 @@ _cpp_handle_directive (pfile, indented) ...@@ -307,20 +300,20 @@ _cpp_handle_directive (pfile, indented)
int indented; int indented;
{ {
const directive *dir = 0; const directive *dir = 0;
cpp_token dname; const cpp_token *dname;
int skip = 1; int skip = 1;
start_directive (pfile); start_directive (pfile);
_cpp_lex_token (pfile, &dname); dname = _cpp_lex_token (pfile);
if (dname.type == CPP_NAME) if (dname->type == CPP_NAME)
{ {
if (dname.val.node->directive_index) if (dname->val.node->directive_index)
dir = &dtable[dname.val.node->directive_index - 1]; dir = &dtable[dname->val.node->directive_index - 1];
} }
/* We do not recognise the # followed by a number extension in /* We do not recognise the # followed by a number extension in
assembler code. */ assembler code. */
else if (dname.type == CPP_NUMBER && CPP_OPTION (pfile, lang) != CLK_ASM) else if (dname->type == CPP_NUMBER && CPP_OPTION (pfile, lang) != CLK_ASM)
{ {
dir = &dtable[T_LINE]; dir = &dtable[T_LINE];
pfile->state.line_extension = 1; pfile->state.line_extension = 1;
...@@ -361,7 +354,7 @@ _cpp_handle_directive (pfile, indented) ...@@ -361,7 +354,7 @@ _cpp_handle_directive (pfile, indented)
dir = 0; dir = 0;
} }
} }
else if (dname.type == CPP_EOF) else if (dname->type == CPP_EOF)
; /* CPP_EOF is the "null directive". */ ; /* CPP_EOF is the "null directive". */
else else
{ {
...@@ -373,7 +366,7 @@ _cpp_handle_directive (pfile, indented) ...@@ -373,7 +366,7 @@ _cpp_handle_directive (pfile, indented)
skip = 0; skip = 0;
else if (!pfile->state.skipping) else if (!pfile->state.skipping)
cpp_error (pfile, "invalid preprocessing directive #%s", cpp_error (pfile, "invalid preprocessing directive #%s",
cpp_token_as_text (pfile, &dname)); cpp_token_as_text (pfile, dname));
} }
if (dir) if (dir)
...@@ -414,11 +407,8 @@ static cpp_hashnode * ...@@ -414,11 +407,8 @@ static cpp_hashnode *
lex_macro_node (pfile) lex_macro_node (pfile)
cpp_reader *pfile; cpp_reader *pfile;
{ {
cpp_token token;
cpp_hashnode *node; cpp_hashnode *node;
const cpp_token *token = _cpp_lex_token (pfile);
/* Lex the macro name directly. */
_cpp_lex_token (pfile, &token);
/* The token immediately after #define must be an identifier. That /* The token immediately after #define must be an identifier. That
identifier may not be "defined", per C99 6.10.8p4. identifier may not be "defined", per C99 6.10.8p4.
...@@ -427,22 +417,22 @@ lex_macro_node (pfile) ...@@ -427,22 +417,22 @@ lex_macro_node (pfile)
Finally, the identifier may not have been poisoned. (In that case Finally, the identifier may not have been poisoned. (In that case
the lexer has issued the error message for us.) */ the lexer has issued the error message for us.) */
if (token.type != CPP_NAME) if (token->type != CPP_NAME)
{ {
if (token.type == CPP_EOF) if (token->type == CPP_EOF)
cpp_error (pfile, "no macro name given in #%s directive", cpp_error (pfile, "no macro name given in #%s directive",
pfile->directive->name); pfile->directive->name);
else if (token.flags & NAMED_OP) else if (token->flags & NAMED_OP)
cpp_error (pfile, 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)); NODE_NAME (token->val.node));
else else
cpp_error (pfile, "macro names must be identifiers"); cpp_error (pfile, "macro names must be identifiers");
return 0; return 0;
} }
node = token.val.node; node = token->val.node;
if (node->flags & NODE_POISONED) if (node->flags & NODE_POISONED)
return 0; return 0;
...@@ -654,12 +644,11 @@ read_flag (pfile, last) ...@@ -654,12 +644,11 @@ read_flag (pfile, last)
cpp_reader *pfile; cpp_reader *pfile;
unsigned int last; unsigned int last;
{ {
cpp_token token; const cpp_token *token = _cpp_lex_token (pfile);
_cpp_lex_token (pfile, &token); if (token->type == CPP_NUMBER && token->val.str.len == 1)
if (token.type == CPP_NUMBER && token.val.str.len == 1)
{ {
unsigned int flag = token.val.str.text[0] - '0'; unsigned int flag = token->val.str.text[0] - '0';
if (flag > last && flag <= 4 if (flag > last && flag <= 4
&& (flag != 4 || last == 3) && (flag != 4 || last == 3)
...@@ -667,9 +656,9 @@ read_flag (pfile, last) ...@@ -667,9 +656,9 @@ read_flag (pfile, last)
return flag; return flag;
} }
if (token.type != CPP_EOF) if (token->type != CPP_EOF)
cpp_error (pfile, "invalid flag \"%s\" in line directive", cpp_error (pfile, "invalid flag \"%s\" in line directive",
cpp_token_as_text (pfile, &token)); cpp_token_as_text (pfile, token));
return 0; return 0;
} }
...@@ -1033,22 +1022,22 @@ do_pragma_poison (pfile) ...@@ -1033,22 +1022,22 @@ do_pragma_poison (pfile)
{ {
/* Poison these symbols so that all subsequent usage produces an /* Poison these symbols so that all subsequent usage produces an
error message. */ error message. */
cpp_token tok; const cpp_token *tok;
cpp_hashnode *hp; cpp_hashnode *hp;
pfile->state.poisoned_ok = 1; pfile->state.poisoned_ok = 1;
for (;;) for (;;)
{ {
_cpp_lex_token (pfile, &tok); tok = _cpp_lex_token (pfile);
if (tok.type == CPP_EOF) if (tok->type == CPP_EOF)
break; break;
if (tok.type != CPP_NAME) if (tok->type != CPP_NAME)
{ {
cpp_error (pfile, "invalid #pragma GCC poison directive"); cpp_error (pfile, "invalid #pragma GCC poison directive");
break; break;
} }
hp = tok.val.node; hp = tok->val.node;
if (hp->flags & NODE_POISONED) if (hp->flags & NODE_POISONED)
continue; continue;
......
...@@ -912,7 +912,7 @@ cpp_get_token (pfile, token) ...@@ -912,7 +912,7 @@ cpp_get_token (pfile, token)
/* Context->prev == 0 <=> base context. */ /* Context->prev == 0 <=> base context. */
if (!context->prev) if (!context->prev)
_cpp_lex_token (pfile, token); *token = *_cpp_lex_token (pfile);
else if (context->list.first != context->list.limit) else if (context->list.first != context->list.limit)
{ {
*token = *context->list.first++; *token = *context->list.first++;
...@@ -1124,19 +1124,18 @@ parse_params (pfile, macro) ...@@ -1124,19 +1124,18 @@ parse_params (pfile, macro)
cpp_reader *pfile; cpp_reader *pfile;
cpp_macro *macro; cpp_macro *macro;
{ {
cpp_token token;
unsigned int prev_ident = 0; unsigned int prev_ident = 0;
macro->params = (cpp_hashnode **) POOL_FRONT (&pfile->macro_pool); macro->params = (cpp_hashnode **) POOL_FRONT (&pfile->macro_pool);
for (;;) for (;;)
{ {
_cpp_lex_token (pfile, &token); const cpp_token *token = _cpp_lex_token (pfile);
switch (token.type) switch (token->type)
{ {
default: default:
cpp_error (pfile, "\"%s\" may not appear in macro parameter list", cpp_error (pfile, "\"%s\" may not appear in macro parameter list",
cpp_token_as_text (pfile, &token)); cpp_token_as_text (pfile, token));
return 0; return 0;
case CPP_NAME: case CPP_NAME:
...@@ -1147,7 +1146,7 @@ parse_params (pfile, macro) ...@@ -1147,7 +1146,7 @@ parse_params (pfile, macro)
} }
prev_ident = 1; prev_ident = 1;
if (save_parameter (pfile, macro, token.val.node)) if (save_parameter (pfile, macro, token->val.node))
return 0; return 0;
continue; continue;
...@@ -1179,8 +1178,8 @@ parse_params (pfile, macro) ...@@ -1179,8 +1178,8 @@ parse_params (pfile, macro)
cpp_pedwarn (pfile, "ISO C does not permit named variadic macros"); cpp_pedwarn (pfile, "ISO C does not permit named variadic macros");
/* We're at the end, and just expect a closing parenthesis. */ /* We're at the end, and just expect a closing parenthesis. */
_cpp_lex_token (pfile, &token); token = _cpp_lex_token (pfile);
if (token.type == CPP_CLOSE_PAREN) if (token->type == CPP_CLOSE_PAREN)
break; break;
/* Fall through. */ /* Fall through. */
...@@ -1214,7 +1213,7 @@ lex_expansion_token (pfile, macro) ...@@ -1214,7 +1213,7 @@ lex_expansion_token (pfile, macro)
} }
macro->count++; macro->count++;
_cpp_lex_token (pfile, token); *token = *_cpp_lex_token (pfile);
/* Is this an argument? */ /* Is this an argument? */
if (token->type == CPP_NAME && token->val.node->arg_index) if (token->type == CPP_NAME && token->val.node->arg_index)
......
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