diff options
-rw-r--r-- | gcc/ChangeLog | 16 | ||||
-rw-r--r-- | gcc/cppinit.c | 1 | ||||
-rw-r--r-- | gcc/cpplex.c | 18 | ||||
-rw-r--r-- | gcc/cpplib.c | 8 | ||||
-rw-r--r-- | gcc/cpplib.h | 4 | ||||
-rw-r--r-- | gcc/cppmacro.c | 27 |
6 files changed, 45 insertions, 29 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 6cc1677..e5d730e 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,19 @@ +2000-12-01 Neil Booth <neilb@earthling.net> + + * cppinit.c (initialize): Forgotten prototype. + * cpplex.c (_cpp_lex_token): Loop until not skipping. + Always clear PREV_WHITE upon meeting a new line. + * cpplib.c (end_directive): Set pfile->skipping after + skip_rest_of_line. + * cpplib.h (cpp_reader): Remove macro_pos. + * cppmacro.c (cpp_get_line): Don't do anything special inside + macros. + (parse_arg): Add PREV_WHITE if a token appears after new lines. + (funlike_invocation_p): Save and restore the output position + over a successful check for a '('. + (enter_macro_context): Delete uses of macro_pos. + (cpp_get_token): Don't use pfile->skipping. + 2000-12-01 Phil Edwards <pme@sources.redhat.com> * diagnostic.c: Fix typos in comments. diff --git a/gcc/cppinit.c b/gcc/cppinit.c index a91a6d1..e3d12213 100644 --- a/gcc/cppinit.c +++ b/gcc/cppinit.c @@ -94,6 +94,7 @@ struct cpp_pending static void print_help PARAMS ((void)); static void path_include PARAMS ((cpp_reader *, char *, int)); +static void initialize PARAMS ((void)); static void initialize_builtins PARAMS ((cpp_reader *)); static void append_include_chain PARAMS ((cpp_reader *, char *, int, int)); diff --git a/gcc/cpplex.c b/gcc/cpplex.c index 3cfd8e3..f681830 100644 --- a/gcc/cpplex.c +++ b/gcc/cpplex.c @@ -850,8 +850,10 @@ _cpp_lex_token (pfile, result) cppchar_t c; cpp_buffer *buffer; const unsigned char *comment_start; - unsigned char bol = pfile->state.next_bol; + unsigned char bol; + skip: + bol = pfile->state.next_bol; done_directive: buffer = pfile->buffer; pfile->state.next_bol = 0; @@ -894,13 +896,10 @@ _cpp_lex_token (pfile, result) handle_newline (buffer, c); bol = 1; pfile->lexer_pos.output_line = buffer->lineno; - - /* Newlines in arguments are white space (6.10.3.10). - Otherwise, clear any white space flag. */ - if (pfile->state.parsing_args) - result->flags |= PREV_WHITE; - else - result->flags &= ~PREV_WHITE; + /* This is a new line, so clear any white space flag. + Newlines in arguments are white space (6.10.3.10); + parse_arg takes care of that. */ + result->flags &= ~PREV_WHITE; goto next_char; } @@ -1276,6 +1275,9 @@ _cpp_lex_token (pfile, result) break; } + if (pfile->skipping) + goto skip; + /* If not in a directive, this token invalidates controlling macros. */ if (!pfile->state.in_directive) pfile->mi_state = MI_FAILED; diff --git a/gcc/cpplib.c b/gcc/cpplib.c index de72e98..2eaf755 100644 --- a/gcc/cpplib.c +++ b/gcc/cpplib.c @@ -247,14 +247,14 @@ end_directive (pfile, skip_line) { cpp_buffer *buffer = pfile->buffer; - /* Restore pfile->skipping before skip_rest_of_line. This avoids - warning about poisoned identifiers in skipped #error lines. */ - pfile->skipping = buffer->was_skipping; - /* We don't skip for an assembler #. */ if (skip_line) skip_rest_of_line (pfile); + /* Restore pfile->skipping after skip_rest_of_line. Otherwise the + lexer might not return! */ + pfile->skipping = buffer->was_skipping; + /* Restore state. */ pfile->la_write = pfile->la_saved; pfile->state.save_comments = ! CPP_OPTION (pfile, discard_comments); diff --git a/gcc/cpplib.h b/gcc/cpplib.h index 9f2961a..faccc6a 100644 --- a/gcc/cpplib.h +++ b/gcc/cpplib.h @@ -498,10 +498,8 @@ struct cpp_reader /* Lexer state. */ struct lexer_state state; - /* The position of the last lexed token, last lexed directive, and - last macro invocation. */ + /* The position of the last lexed token and last lexed directive. */ cpp_lexer_pos lexer_pos; - cpp_lexer_pos macro_pos; cpp_lexer_pos directive_pos; /* Memory pools. */ diff --git a/gcc/cppmacro.c b/gcc/cppmacro.c index 637e5e9..eed2798 100644 --- a/gcc/cppmacro.c +++ b/gcc/cppmacro.c @@ -236,10 +236,6 @@ const cpp_lexer_pos * cpp_get_line (pfile) cpp_reader *pfile; { - /* Within a macro expansion, return the position of the outermost - invocation. */ - if (pfile->context->prev) - return &pfile->macro_pos; return &pfile->lexer_pos; } @@ -489,6 +485,7 @@ parse_arg (pfile, arg, var_args) { enum cpp_ttype result; unsigned int paren = 0; + unsigned int line; arg->first = (cpp_token *) POOL_FRONT (&pfile->argument_pool); for (;; arg->count++) @@ -501,9 +498,13 @@ parse_arg (pfile, arg, var_args) token = &arg->first[arg->count]; } + /* Newlines in arguments are white space (6.10.3.10). */ + line = pfile->lexer_pos.output_line; cpp_get_token (pfile, token); - result = token->type; + if (line != pfile->lexer_pos.output_line) + token->flags |= PREV_WHITE; + result = token->type; if (result == CPP_OPEN_PAREN) paren++; else if (result == CPP_CLOSE_PAREN && paren-- == 0) @@ -608,7 +609,9 @@ funlike_invocation_p (pfile, node, list) cpp_context *orig_context; cpp_token maybe_paren; macro_arg *args = 0; + cpp_lexer_pos macro_pos; + macro_pos = pfile->lexer_pos; pfile->state.parsing_args = 1; pfile->state.prevent_expansion++; orig_context = pfile->context; @@ -631,6 +634,9 @@ funlike_invocation_p (pfile, node, list) if (args) { + /* The macro's expansion appears where the name would have. */ + pfile->lexer_pos = macro_pos; + if (node->value.macro->paramc > 0) { /* Don't save tokens during pre-expansion. */ @@ -660,10 +666,7 @@ enter_macro_context (pfile, node) /* Save the position of the outermost macro invocation. */ if (!pfile->context->prev) - { - pfile->macro_pos = pfile->lexer_pos; - lock_pools (pfile); - } + lock_pools (pfile); if (macro->fun_like && !funlike_invocation_p (pfile, node, &list)) { @@ -924,7 +927,7 @@ cpp_get_token (pfile, token) token->flags |= flags; flags = 0; /* PASTE_LEFT tokens can only appear in macro expansions. */ - if (token->flags & PASTE_LEFT && !pfile->skipping) + if (token->flags & PASTE_LEFT) paste_all_tokens (pfile, token); } else @@ -940,10 +943,6 @@ cpp_get_token (pfile, token) return; } - /* Loop until we're not skipping. */ - if (pfile->skipping) - continue; - if (token->type != CPP_NAME) break; |