From c00e481c16b2a2036ff5f18f412d432e50f307d6 Mon Sep 17 00:00:00 2001 From: neil Date: Sun, 16 Sep 2001 13:44:29 +0000 Subject: [PATCH] * 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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@45646 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog | 9 ++++++++ gcc/cpphash.h | 2 +- gcc/cpplex.c | 7 +++--- gcc/cpplib.c | 71 +++++++++++++++++++++++++--------------------------------- gcc/cppmacro.c | 17 +++++++------- 5 files changed, 51 insertions(+), 55 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 4f0ad86..934d0b1 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,5 +1,14 @@ 2001-09-16 Neil Booth + * 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 + * cppmain.c (scan_translation_unit): Don't worry about putting a space after hashes. * cpplib.c (directive_diagnostics): New. diff --git a/gcc/cpphash.h b/gcc/cpphash.h index 292b05e..e6772b2 100644 --- a/gcc/cpphash.h +++ b/gcc/cpphash.h @@ -398,7 +398,7 @@ extern void _cpp_pop_file_buffer PARAMS ((cpp_reader *, extern int _cpp_parse_expr PARAMS ((cpp_reader *)); /* 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 *, const cpp_token *)); extern void _cpp_init_tokenrun PARAMS ((tokenrun *, unsigned int)); diff --git a/gcc/cpplex.c b/gcc/cpplex.c index f57d482..1bfca20 100644 --- a/gcc/cpplex.c +++ b/gcc/cpplex.c @@ -933,10 +933,9 @@ next_tokenrun (run) } /* Lex a token into RESULT (external interface). */ -void -_cpp_lex_token (pfile, dest) +const cpp_token * +_cpp_lex_token (pfile) cpp_reader *pfile; - cpp_token *dest; { cpp_token *result; @@ -979,7 +978,7 @@ _cpp_lex_token (pfile, dest) break; } - *dest = *result; + return result; } /* Lex a token into RESULT. When meeting a newline, returns CPP_EOF diff --git a/gcc/cpplib.c b/gcc/cpplib.c index b3eb24d..63d0c17 100644 --- a/gcc/cpplib.c +++ b/gcc/cpplib.c @@ -185,15 +185,14 @@ static void skip_rest_of_line (pfile) cpp_reader *pfile; { - cpp_token token; - /* Discard all stacked contexts. */ while (pfile->context != &pfile->base_context) _cpp_pop_context (pfile); /* Sweep up all tokens remaining on the line. */ - while (! SEEN_EOL ()) - _cpp_lex_token (pfile, &token); + if (! SEEN_EOL ()) + while (_cpp_lex_token (pfile)->type != CPP_EOF) + ; } /* Ensure there are no stray tokens at the end of a directive. */ @@ -201,15 +200,9 @@ static void check_eol (pfile) cpp_reader *pfile; { - if (! SEEN_EOL ()) - { - cpp_token token; - - _cpp_lex_token (pfile, &token); - if (token.type != CPP_EOF) - cpp_pedwarn (pfile, "extra tokens at end of #%s directive", - pfile->directive->name); - } + if (! SEEN_EOL () && _cpp_lex_token (pfile)->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. */ @@ -307,20 +300,20 @@ _cpp_handle_directive (pfile, indented) int indented; { const directive *dir = 0; - cpp_token dname; + const cpp_token *dname; int skip = 1; 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) - dir = &dtable[dname.val.node->directive_index - 1]; + if (dname->val.node->directive_index) + dir = &dtable[dname->val.node->directive_index - 1]; } /* We do not recognise the # followed by a number extension in 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]; pfile->state.line_extension = 1; @@ -361,7 +354,7 @@ _cpp_handle_directive (pfile, indented) dir = 0; } } - else if (dname.type == CPP_EOF) + else if (dname->type == CPP_EOF) ; /* CPP_EOF is the "null directive". */ else { @@ -373,7 +366,7 @@ _cpp_handle_directive (pfile, indented) skip = 0; else if (!pfile->state.skipping) cpp_error (pfile, "invalid preprocessing directive #%s", - cpp_token_as_text (pfile, &dname)); + cpp_token_as_text (pfile, dname)); } if (dir) @@ -414,11 +407,8 @@ static cpp_hashnode * lex_macro_node (pfile) cpp_reader *pfile; { - cpp_token token; cpp_hashnode *node; - - /* Lex the macro name directly. */ - _cpp_lex_token (pfile, &token); + const cpp_token *token = _cpp_lex_token (pfile); /* The token immediately after #define must be an identifier. That identifier may not be "defined", per C99 6.10.8p4. @@ -427,22 +417,22 @@ lex_macro_node (pfile) Finally, the identifier may not have been poisoned. (In that case 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", pfile->directive->name); - else if (token.flags & NAMED_OP) + else if (token->flags & NAMED_OP) cpp_error (pfile, "\"%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 cpp_error (pfile, "macro names must be identifiers"); return 0; } - node = token.val.node; + node = token->val.node; if (node->flags & NODE_POISONED) return 0; @@ -654,12 +644,11 @@ read_flag (pfile, last) cpp_reader *pfile; 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 && (flag != 4 || last == 3) @@ -667,9 +656,9 @@ read_flag (pfile, last) return flag; } - if (token.type != CPP_EOF) + if (token->type != CPP_EOF) cpp_error (pfile, "invalid flag \"%s\" in line directive", - cpp_token_as_text (pfile, &token)); + cpp_token_as_text (pfile, token)); return 0; } @@ -1033,22 +1022,22 @@ do_pragma_poison (pfile) { /* Poison these symbols so that all subsequent usage produces an error message. */ - cpp_token tok; + const cpp_token *tok; cpp_hashnode *hp; pfile->state.poisoned_ok = 1; for (;;) { - _cpp_lex_token (pfile, &tok); - if (tok.type == CPP_EOF) + tok = _cpp_lex_token (pfile); + if (tok->type == CPP_EOF) break; - if (tok.type != CPP_NAME) + if (tok->type != CPP_NAME) { cpp_error (pfile, "invalid #pragma GCC poison directive"); break; } - hp = tok.val.node; + hp = tok->val.node; if (hp->flags & NODE_POISONED) continue; diff --git a/gcc/cppmacro.c b/gcc/cppmacro.c index 80c0154..e2014712 100644 --- a/gcc/cppmacro.c +++ b/gcc/cppmacro.c @@ -912,7 +912,7 @@ cpp_get_token (pfile, token) /* Context->prev == 0 <=> base context. */ if (!context->prev) - _cpp_lex_token (pfile, token); + *token = *_cpp_lex_token (pfile); else if (context->list.first != context->list.limit) { *token = *context->list.first++; @@ -1124,19 +1124,18 @@ parse_params (pfile, macro) cpp_reader *pfile; cpp_macro *macro; { - cpp_token token; unsigned int prev_ident = 0; macro->params = (cpp_hashnode **) POOL_FRONT (&pfile->macro_pool); for (;;) { - _cpp_lex_token (pfile, &token); + const cpp_token *token = _cpp_lex_token (pfile); - switch (token.type) + switch (token->type) { default: 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; case CPP_NAME: @@ -1147,7 +1146,7 @@ parse_params (pfile, macro) } prev_ident = 1; - if (save_parameter (pfile, macro, token.val.node)) + if (save_parameter (pfile, macro, token->val.node)) return 0; continue; @@ -1179,8 +1178,8 @@ parse_params (pfile, macro) cpp_pedwarn (pfile, "ISO C does not permit named variadic macros"); /* We're at the end, and just expect a closing parenthesis. */ - _cpp_lex_token (pfile, &token); - if (token.type == CPP_CLOSE_PAREN) + token = _cpp_lex_token (pfile); + if (token->type == CPP_CLOSE_PAREN) break; /* Fall through. */ @@ -1214,7 +1213,7 @@ lex_expansion_token (pfile, macro) } macro->count++; - _cpp_lex_token (pfile, token); + *token = *_cpp_lex_token (pfile); /* Is this an argument? */ if (token->type == CPP_NAME && token->val.node->arg_index) -- 2.7.4