diff options
author | Neil Booth <neilb@earthling.net> | 2000-09-18 18:43:05 +0000 |
---|---|---|
committer | Neil Booth <neil@gcc.gnu.org> | 2000-09-18 18:43:05 +0000 |
commit | 0d9f234d9317f291eb49dab50277efeee85e5b91 (patch) | |
tree | 46f9c8a95640d0cd590d2e287982ab8e1099e35e /gcc/cpplib.c | |
parent | 9f8e169eb7a21b2f374df31dd32beef667676a13 (diff) | |
download | gcc-0d9f234d9317f291eb49dab50277efeee85e5b91.zip gcc-0d9f234d9317f291eb49dab50277efeee85e5b91.tar.gz gcc-0d9f234d9317f291eb49dab50277efeee85e5b91.tar.bz2 |
cpphash.h (HASHSTEP): Take character rather than pointer to character.
* cpphash.h (HASHSTEP): Take character rather than pointer
to character.
(_cpp_check_directive, _cpp_check_linemarker): Update prototypes.
* cpphash.c (cpp_loookup): Update for new HASHSTEP.
* cpplex.c (auto_expand_name_space, trigraph_replace,
backslash_start, handle_newline, parse_name, INIT_TOKEN_STR,
IMMED_TOKEN, PREV_TOKEN_TYPE, PUSH_TOKEN, REVISE_TOKEN,
BACKUP_TOKEN, BACKUP_TRIGRAPH, MIGHT_BE_DIRECTIVE,
KNOWN_DIRECTIVE): Delete.
(handle_newline, check_long_token, skip_escaped_newlines,
unterminated): New functions.
(ACCEPT_CHAR, SAVE_STATE, RESTORE_STATE): New macros.
(parse_identifier): Was parse_name, new implementation.
(skip_line_comment, skip_block_comment, skip_whitespace,
parse_number, parse_string, trigraph_ok, save_comment,
adjust_column, _cpp_get_line): New implementations.
(lex_token): New function. Lexes a token at a time, looking
forwards. Contains most of the guts of the old lex_line.
(lex_line): New implementation, using lex_token to obtain
individual tokens.
(cpp_scan_buffer): Use the token's line, not the list's line.
* cpplib.c (_cpp_check_directive, _cpp_check_linemarker):
New implementations.
(do_assert): Don't bother setting the answer's list's line.
(cpp_push_buffer): Initialise new pfile and read_ahead members
of struct cpp_buffer.
* cpplib.h (cppchar_t): New typedef.
(struct cpp_buffer): read_ahead, pfile and col_adjust are
new members.
(struct lexer_state): New structure that determines the state
and behaviour of the lexer.
(IN_DIRECTIVE, KNOWN_DIRECTIVE): New macros.
(struct cpp_reader): New member "state". Rename
multiline_string_line and multiline_string_column. Delete
col_adjust, in_lex_line members.
(CPP_BUF_COLUMN): Update.
* gcc.dg/cpp/cmdlne-C.c: Remove bogus warning test.
From-SVN: r36509
Diffstat (limited to 'gcc/cpplib.c')
-rw-r--r-- | gcc/cpplib.c | 112 |
1 files changed, 65 insertions, 47 deletions
diff --git a/gcc/cpplib.c b/gcc/cpplib.c index 3273dce..3106486 100644 --- a/gcc/cpplib.c +++ b/gcc/cpplib.c @@ -133,64 +133,81 @@ DIRECTIVE_TABLE /* Check if a token's name matches that of a known directive. Put in this file to save exporting dtable and other unneeded information. */ const struct directive * -_cpp_check_directive (pfile, token, bol) +_cpp_check_directive (pfile, token) cpp_reader *pfile; const cpp_token *token; - int bol; { unsigned int i; + if (token->type != CPP_NAME) + { + if (token->type == CPP_EOF && CPP_WTRADITIONAL (pfile) + && pfile->state.indented) + cpp_warning (pfile, "traditional C ignores #\\n with the # indented"); + + return 0; + } + for (i = 0; i < N_DIRECTIVES; i++) if (pfile->spec_nodes->dirs[i] == token->val.node) - { - /* If we are rescanning preprocessed input, only directives - tagged with IN_I are to be honored, and the warnings below - are suppressed. */ - if (CPP_OPTION (pfile, preprocessed)) - { - if (dtable[i].flags & IN_I) - return &dtable[i]; - return 0; - } - - /* In -traditional mode, a directive is ignored unless its # - is in column 1. In code intended to work with K+R compilers, - therefore, directives added by C89 must have their # indented, - and directives present in traditional C must not. This is true - even of directives in skipped conditional blocks. */ - if (CPP_WTRADITIONAL (pfile)) - { - if (!bol && dtable[i].origin == KANDR) - cpp_warning (pfile, - "traditional C ignores #%s with the # indented", - dtable[i].name); - - if (bol && dtable[i].origin != KANDR) - cpp_warning (pfile, - "suggest hiding #%s from traditional C with an indented #", - dtable[i].name); - } - - /* If we are skipping a failed conditional group, all non-conditional - directives are ignored. */ - if (pfile->skipping && !(dtable[i].flags & COND)) - return 0; - - /* Issue -pedantic warnings for extended directives. */ - if (CPP_PEDANTIC (pfile) && dtable[i].origin == EXTENSION) - cpp_pedwarn (pfile, "ISO C does not allow #%s", dtable[i].name); - - return &dtable[i]; - } + break; - return 0; + if (i == N_DIRECTIVES) + return 0; + + /* We should lex headers correctly, regardless of whether we're + skipping or not. */ + pfile->state.angled_headers = dtable[i].flags & INCL; + + /* If we are rescanning preprocessed input, only directives tagged + with IN_I are honored, and the warnings below are suppressed. */ + if (CPP_OPTION (pfile, preprocessed)) + { + if (!dtable[i].flags & IN_I) + return 0; + } + else + { + /* Traditionally, a directive is ignored unless its # is in + column 1. Therefore in code intended to work with K+R + compilers, directives added by C89 must have their # + indented, and directives present in traditional C must not. + This is true even of directives in skipped conditional + blocks. */ + if (CPP_WTRADITIONAL (pfile)) + { + if (pfile->state.indented && dtable[i].origin == KANDR) + cpp_warning (pfile, + "traditional C ignores #%s with the # indented", + dtable[i].name); + + else if (!pfile->state.indented && dtable[i].origin != KANDR) + cpp_warning (pfile, + "suggest hiding #%s from traditional C with an indented #", + dtable[i].name); + } + + /* If we are skipping a failed conditional group, all non-conditional + directives are ignored. */ + if (pfile->skipping && !(dtable[i].flags & COND)) + return 0; + + /* Issue -pedantic warnings for extended directives. */ + if (CPP_PEDANTIC (pfile) && dtable[i].origin == EXTENSION) + cpp_pedwarn (pfile, "ISO C does not allow #%s", dtable[i].name); + } + + /* Only flag to save comments if we process the directive. */ + pfile->state.save_comments = (! CPP_OPTION (pfile, discard_comments) + && (dtable[i].flags & COMMENTS)); + + return &dtable[i]; } const struct directive * -_cpp_check_linemarker (pfile, token, bol) +_cpp_check_linemarker (pfile, token) cpp_reader *pfile; const cpp_token *token ATTRIBUTE_UNUSED; - int bol; { /* # followed by a number is equivalent to #line. Do not recognize this form in assembly language source files or skipped @@ -206,7 +223,7 @@ _cpp_check_linemarker (pfile, token, bol) /* In -traditional mode, a directive is ignored unless its # is in column 1. */ - if (!bol && CPP_WTRADITIONAL (pfile)) + if (pfile->state.indented && CPP_WTRADITIONAL (pfile)) cpp_warning (pfile, "traditional C ignores #%s with the # indented", dtable[T_LINE].name); @@ -1319,7 +1336,6 @@ do_assert (pfile) if (node) { new_answer->next = 0; - new_answer->list.line = pfile->token_list.line; new_answer->list.file = pfile->token_list.file; if (node->type == T_ASSERTION) @@ -1499,6 +1515,8 @@ cpp_push_buffer (pfile, buffer, length) new->line_base = new->buf = new->cur = buffer; new->rlimit = buffer + length; new->prev = buf; + new->pfile = pfile; + new->read_ahead = EOF; CPP_BUFFER (pfile) = new; return new; |