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
This commit is contained in:
Neil Booth 2000-09-18 18:43:05 +00:00 committed by Neil Booth
parent 9f8e169eb7
commit 0d9f234d93
8 changed files with 1131 additions and 1165 deletions

View File

@ -1,3 +1,49 @@
Mon 18-Sep-2000 19:21:35 BST Neil Booth <NeilB@earthling.net>
* 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.
2000-09-18 Richard Henderson <rth@cygnus.com>
* combine.c (simplify_comparison): Shift a NOT out of a single

View File

@ -104,7 +104,7 @@ cpp_lookup (pfile, name, len)
do
{
r = HASHSTEP (r, str);
r = HASHSTEP (r, *str);
str++;
}
while (--n);

View File

@ -211,7 +211,7 @@ extern unsigned char _cpp_trigraph_map[UCHAR_MAX + 1];
/* Hash step. The hash calculation is duplicated in cpp_lookup and
parse_name. */
#define HASHSTEP(r, str) ((r) * 67 + (*str - 113));
#define HASHSTEP(r, c) ((r) * 67 + (c - 113));
/* Flags for _cpp_init_toklist. */
#define DUMMY_TOKEN 0
@ -280,9 +280,9 @@ extern const cpp_token *_cpp_glue_header_name PARAMS ((cpp_reader *));
/* In cpplib.c */
extern const struct directive *_cpp_check_directive
PARAMS ((cpp_reader *, const cpp_token *, int));
PARAMS ((cpp_reader *, const cpp_token *));
extern const struct directive *_cpp_check_linemarker
PARAMS ((cpp_reader *, const cpp_token *, int));
PARAMS ((cpp_reader *, const cpp_token *));
extern cpp_hashnode *_cpp_parse_assertion PARAMS ((cpp_reader *,
struct answer **));
extern struct answer **_cpp_find_answer PARAMS ((cpp_hashnode *,

File diff suppressed because it is too large Load Diff

View File

@ -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;
}
break;
/* 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 (i == N_DIRECTIVES)
return 0;
if (bol && dtable[i].origin != KANDR)
cpp_warning (pfile,
"suggest hiding #%s from traditional C with an indented #",
dtable[i].name);
}
/* We should lex headers correctly, regardless of whether we're
skipping or not. */
pfile->state.angled_headers = dtable[i].flags & INCL;
/* If we are skipping a failed conditional group, all non-conditional
directives are ignored. */
if (pfile->skipping && !(dtable[i].flags & COND))
return 0;
/* 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);
/* 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);
else if (!pfile->state.indented && dtable[i].origin != KANDR)
cpp_warning (pfile,
"suggest hiding #%s from traditional C with an indented #",
dtable[i].name);
}
return &dtable[i];
}
/* If we are skipping a failed conditional group, all non-conditional
directives are ignored. */
if (pfile->skipping && !(dtable[i].flags & COND))
return 0;
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;

View File

@ -215,15 +215,22 @@ struct cpp_toklist
unsigned short flags;
};
/* A standalone character. We may want to make it unsigned for the
same reason we use unsigned char - to avoid signedness issues. */
typedef int cppchar_t;
struct cpp_buffer
{
const unsigned char *cur; /* current position */
const unsigned char *rlimit; /* end of valid data */
const unsigned char *buf; /* entire buffer */
const unsigned char *line_base; /* start of current line */
cppchar_t read_ahead; /* read ahead character */
struct cpp_reader *pfile; /* Owns this buffer. */
struct cpp_buffer *prev;
const unsigned char *buf; /* entire buffer */
/* Filename specified with #line command. */
const char *nominal_fname;
@ -238,6 +245,9 @@ struct cpp_buffer
Used to prohibit unmatched #endif (etc) in an include file. */
struct if_stack *if_stack;
/* Token column position adjustment owing to tabs in whitespace. */
unsigned int col_adjust;
/* Line number at line_base (above). */
unsigned int lineno;
@ -431,6 +441,31 @@ struct cpp_options
unsigned char show_column;
};
struct lexer_state
{
/* Nonzero if first token on line is CPP_HASH. */
unsigned char in_directive;
/* Nonzero if the directive's # was not in the first column. Used
by -Wtraditional. */
unsigned char indented;
/* Nonzero if in a directive that takes angle-bracketed headers. */
unsigned char angled_headers;
/* Nonzero to save comments. Turned off if discard_comments, and in
all directives apart from #define. */
unsigned char save_comments;
/* Nonzero to get force the lexer to skip newlines. */
unsigned char skip_newlines;
/* If we're in the subroutine lex_line. */
unsigned char in_lex_line;
};
#define IN_DIRECTIVE(pfile) (pfile->state.in_directive)
#define KNOWN_DIRECTIVE(list) (list->directive != 0)
/* A cpp_reader encapsulates the "state" of a pre-processor run.
Applying cpp_get_token repeatedly yields a stream of pre-processor
tokens. Usually, there is only one cpp_reader object active. */
@ -440,12 +475,16 @@ struct cpp_reader
/* Top of buffer stack. */
cpp_buffer *buffer;
/* Lexer state. */
struct lexer_state state;
/* Error counter for exit code */
unsigned int errors;
/* Line and column where a newline was first seen in a string constant. */
unsigned int multiline_string_line;
unsigned int multiline_string_column;
/* Line and column where a newline was first seen in a string
constant (multi-line strings). */
unsigned int mls_line;
unsigned int mls_column;
/* Current depth in #include directives that use <...>. */
unsigned int system_include_depth;
@ -475,9 +514,6 @@ struct cpp_reader
be one at a time, so it is per-reader not per-buffer. */
const cpp_hashnode *potential_control_macro;
/* Token column position adjustment owing to tabs in whitespace. */
unsigned int col_adjust;
/* Token list used to store logical lines with new lexer. */
cpp_toklist token_list;
@ -557,9 +593,6 @@ struct cpp_reader
or we might need to write out definitions. */
unsigned char save_parameter_spellings;
/* If we're in lex_line. */
unsigned char in_lex_line;
/* True if output_line_command needs to output a newline. */
unsigned char need_newline;
@ -586,7 +619,7 @@ struct cpp_printer
#define CPP_OPTION(PFILE, OPTION) ((PFILE)->opts.OPTION)
#define CPP_BUFFER(PFILE) ((PFILE)->buffer)
#define CPP_BUF_LINE(BUF) ((BUF)->lineno)
#define CPP_BUF_COLUMN(BUF, CUR) ((CUR) - (BUF)->line_base + pfile->col_adjust)
#define CPP_BUF_COLUMN(BUF, CUR) ((CUR) - (BUF)->line_base + (BUF)->col_adjust)
#define CPP_BUF_COL(BUF) CPP_BUF_COLUMN(BUF, (BUF)->cur)
/* Name under which this program was invoked. */

View File

@ -1,3 +1,7 @@
Mon 18-Sep-2000 19:23:11 BST Neil Booth <NeilB@earthling.net>
* gcc.dg/cpp/cmdlne-C.c: Remove bogus warning test.
2000-09-18 Joseph S. Myers <jsm28@cam.ac.uk>
* gcc.dg/format-ext-1.c: Add tests for mixing %m with $ formats.

View File

@ -10,7 +10,7 @@
the beginning of a directive turns it into a non-directive. */
#define simple no comments
#/**/define bad_directive /* { dg-error "invalid" } */
#define/**/obj_like/**/(some)/**/thing/**/
#define fun_like(/**/x/**/,/**/y/**/)/**/
/**/#define not_a_macro