diff options
author | Neil Booth <neil@daikokuya.demon.co.uk> | 2002-06-05 20:27:12 +0000 |
---|---|---|
committer | Neil Booth <neil@gcc.gnu.org> | 2002-06-05 20:27:12 +0000 |
commit | cbc69f844ef9dcec70f15d45467026c5fd937db2 (patch) | |
tree | b098c6dcb911ae0a74ccb0f807fc5136f1aaecd4 /gcc/cpplib.c | |
parent | dbf87f32ae756cd4efd33b05003929206169bda3 (diff) | |
download | gcc-cbc69f844ef9dcec70f15d45467026c5fd937db2.zip gcc-cbc69f844ef9dcec70f15d45467026c5fd937db2.tar.gz gcc-cbc69f844ef9dcec70f15d45467026c5fd937db2.tar.bz2 |
cpphash.h (_cpp_create_definition): Update prototype.
* cpphash.h (_cpp_create_definition): Update prototype.
(_cpp_push_text_context, _cpp_create_trad_definition): New.
( cpp_lex_identifier_trad): New.
(_cpp_set_trad_context): New.
* cppinit.c (cpp_finish_options): Don't conditionalize builtins.
* cpplib.c (SEEN_EOL): Update.
(lex_macro_node): Update for -traditional.
(cpp_push_buffer, _cpp_pop_buffer): Similarly.
* cppmacro.c (_cpp_create_definition): Split into
create_iso_definition() and _cpp_create_trad_definition().
(warn_of_redefinition): Update prototype; handle traditional
macros.
(_cpp_push_text_context): New.
* cpptrad.c (skip_whitespace, push_replacement_text): New.
(lex_identifier): Call ht_lookup with correct start.
(_cpp_lex_identifier_tradm _cpp_create_trad_definition,
_cpp_set_trad_context): New.
(scan_out_logical_line): Update to handle changing contexts.
From-SVN: r54293
Diffstat (limited to 'gcc/cpplib.c')
-rw-r--r-- | gcc/cpplib.c | 66 |
1 files changed, 38 insertions, 28 deletions
diff --git a/gcc/cpplib.c b/gcc/cpplib.c index e819ffc..acc6f11 100644 --- a/gcc/cpplib.c +++ b/gcc/cpplib.c @@ -202,7 +202,8 @@ static const directive linemarker_dir = do_linemarker, U"#", 1, KANDR, IN_I }; -#define SEEN_EOL() (pfile->cur_token[-1].type == CPP_EOF) +#define SEEN_EOL() (CPP_OPTION (pfile, traditional) \ + || pfile->cur_token[-1].type == CPP_EOF) /* Skip any remaining tokens in a directive. */ static void @@ -447,7 +448,6 @@ lex_macro_node (pfile) cpp_reader *pfile; { cpp_hashnode *node; - 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. @@ -459,39 +459,43 @@ lex_macro_node (pfile) Note that if we're copying comments into macro expansions, we could encounter comment tokens here, so eat them all up first. */ - if (! CPP_OPTION (pfile, discard_comments_in_macro_exp)) + if (CPP_OPTION (pfile, traditional)) + node = _cpp_lex_identifier_trad (pfile); + else { - while (token->type == CPP_COMMENT) - token = _cpp_lex_token (pfile); - } + const cpp_token *token = _cpp_lex_token (pfile); + + if (! CPP_OPTION (pfile, discard_comments_in_macro_exp)) + { + while (token->type == CPP_COMMENT) + token = _cpp_lex_token (pfile); + } - if (token->type != CPP_NAME) - { if (token->type == CPP_EOF) - cpp_error (pfile, DL_ERROR, "no macro name given in #%s directive", - pfile->directive->name); - else if (token->flags & NAMED_OP) - cpp_error (pfile, DL_ERROR, - "\"%s\" cannot be used as a macro name as it is an operator in C++", - NODE_NAME (token->val.node)); + { + cpp_error (pfile, DL_ERROR, "no macro name given in #%s directive", + pfile->directive->name); + return NULL; + } + + if (token->type == CPP_NAME || (token->flags & NAMED_OP)) + node = token->val.node; else - cpp_error (pfile, DL_ERROR, "macro names must be identifiers"); - - return 0; + node = NULL; } - node = token->val.node; - if (node->flags & NODE_POISONED) - return 0; - - if (node == pfile->spec_nodes.n_defined) - { - cpp_error (pfile, DL_ERROR, "\"%s\" cannot be used as a macro name", - NODE_NAME (node)); - return 0; - } + if (!node) + cpp_error (pfile, DL_ERROR, "macro names must be identifiers"); + else if (node->flags & NODE_OPERATOR) + cpp_error (pfile, DL_ERROR, + "\"%s\" cannot be used as a macro name as it is an operator in C++", + NODE_NAME (node)); + else if (node == pfile->spec_nodes.n_defined) + cpp_error (pfile, DL_ERROR, "\"defined\" cannot be used as a macro name"); + else if (! (node->flags & NODE_POISONED)) + return node; - return node; + return NULL; } /* Process a #define directive. Most work is done in cppmacro.c. */ @@ -1890,6 +1894,9 @@ cpp_push_buffer (pfile, buffer, len, from_stage3, return_at_eof) pfile->buffer = new; + if (CPP_OPTION (pfile, traditional)) + _cpp_set_trad_context (pfile); + return new; } @@ -1934,6 +1941,9 @@ _cpp_pop_buffer (pfile) _cpp_maybe_push_include_file (pfile); } } + + if (pfile->buffer && CPP_OPTION (pfile, traditional)) + _cpp_set_trad_context (pfile); } /* Enter all recognised directives in the hash table. */ |