aboutsummaryrefslogtreecommitdiff
path: root/gcc/cpplex.c
diff options
context:
space:
mode:
authorNeil Booth <neil@daikokuya.demon.co.uk>2001-11-26 23:44:54 +0000
committerNeil Booth <neil@gcc.gnu.org>2001-11-26 23:44:54 +0000
commit4d6baafa31576db4b1f5bc2d79913c9ce96e3a61 (patch)
treec1a2c9c7c2d1ce0412550e13966b5458cdbb8bbe /gcc/cpplex.c
parentd4b4b319a23400caa59bbf0e2db01a8f0e38b34e (diff)
downloadgcc-4d6baafa31576db4b1f5bc2d79913c9ce96e3a61.zip
gcc-4d6baafa31576db4b1f5bc2d79913c9ce96e3a61.tar.gz
gcc-4d6baafa31576db4b1f5bc2d79913c9ce96e3a61.tar.bz2
cppfiles.c (stack_include_file): Don't optimize zero-length files.
* cppfiles.c (stack_include_file): Don't optimize zero-length files. (read_include_file): NUL-terminate read files. * cpplex.c (handle_newline, skip_escaped_newlines, get_effective_char, skip_whitespace, parse_identifier, parse_identifier_slow, parse_number, parse_string, _cpp_lex_direct): Optimize for the fact that buffers are guaranteed NUL-terminated. * cpplib.c (destringize_and_run, cpp_define, handle_assertion): Be sure buffers are NUL terminated. * cppmacro.c (warn_of_redefinition): Kill compile warning. * c-common.c: Include tree-inline.h. (c_language): Move separate definitions here. (c_common_init_options, c_common_post_options): New. (c_common_lang_init): Rename c_common_init. * c-common.h (c_common_lang_init): Similarly. (c_common_init_options, c_common_post_options): New. * c-lang.c (c_post_options): Move body to c_common_post_options. (c_init_options): Use c_common_init_options. (c_init): Update. * langhooks.def: Rearrange. * langhooks.h: Rearrange, and improve comments. * toplev.c (do_compile): New function. (toplev_main): Use it. (lang_independent_f_options, parse_options_and_default_flags, process_options): Remove trailing periods. * Makefile.in: Update. cp: * decl2.c (c_language): Move to c-common.c. * lex.c (cxx_post_options, cxx_init_options): Use c-common.c functions. (cxx_init): Update. objc: * objc-act.c (objc_post_options, objc_init_options): Use c-common.c functions. (ojbc_init): Update. From-SVN: r47362
Diffstat (limited to 'gcc/cpplex.c')
-rw-r--r--gcc/cpplex.c103
1 files changed, 42 insertions, 61 deletions
diff --git a/gcc/cpplex.c b/gcc/cpplex.c
index 35411e6..08223bd 100644
--- a/gcc/cpplex.c
+++ b/gcc/cpplex.c
@@ -75,7 +75,7 @@ static cppchar_t get_effective_char PARAMS ((cpp_reader *));
static int skip_block_comment PARAMS ((cpp_reader *));
static int skip_line_comment PARAMS ((cpp_reader *));
static void adjust_column PARAMS ((cpp_reader *));
-static void skip_whitespace PARAMS ((cpp_reader *, cppchar_t));
+static int skip_whitespace PARAMS ((cpp_reader *, cppchar_t));
static cpp_hashnode *parse_identifier PARAMS ((cpp_reader *));
static cpp_hashnode *parse_identifier_slow PARAMS ((cpp_reader *,
const U_CHAR *));
@@ -119,12 +119,8 @@ handle_newline (pfile)
cpp_buffer *buffer = pfile->buffer;
/* Handle CR-LF and LF-CR. Most other implementations (e.g. java)
- only accept CR-LF; maybe we should fall back to that behaviour?
-
- NOTE: the EOF case in _cpp_lex_direct currently requires the
- buffer->cur != buffer->rlimit test here for 0-length files. */
- if (buffer->cur != buffer->rlimit
- && buffer->cur[-1] + buffer->cur[0] == '\r' + '\n')
+ only accept CR-LF; maybe we should fall back to that behaviour? */
+ if (buffer->cur[-1] + buffer->cur[0] == '\r' + '\n')
buffer->cur++;
buffer->line_base = buffer->cur;
@@ -190,24 +186,21 @@ skip_escaped_newlines (pfile)
do
{
- if (buffer->cur == buffer->rlimit)
- break;
-
if (next == '?')
{
- if (buffer->cur[0] != '?' || buffer->cur + 1 == buffer->rlimit)
- break;
-
- if (!trigraph_p (pfile))
+ if (buffer->cur[0] != '?' || !trigraph_p (pfile))
break;
/* Translate the trigraph. */
next = _cpp_trigraph_map[buffer->cur[1]];
buffer->cur += 2;
- if (next != '\\' || buffer->cur == buffer->rlimit)
+ if (next != '\\')
break;
}
+ if (buffer->cur == buffer->rlimit)
+ break;
+
/* We have a backslash, and room for at least one more
character. Skip horizontal whitespace. */
saved_cur = buffer->cur;
@@ -250,16 +243,13 @@ static cppchar_t
get_effective_char (pfile)
cpp_reader *pfile;
{
- cppchar_t next = EOF;
+ cppchar_t next;
cpp_buffer *buffer = pfile->buffer;
buffer->backup_to = buffer->cur;
- if (buffer->cur < buffer->rlimit)
- {
- next = *buffer->cur++;
- if (__builtin_expect (next == '?' || next == '\\', 0))
- next = skip_escaped_newlines (pfile);
- }
+ next = *buffer->cur++;
+ if (__builtin_expect (next == '?' || next == '\\', 0))
+ next = skip_escaped_newlines (pfile);
return next;
}
@@ -295,7 +285,6 @@ skip_block_comment (pfile)
comes immediately before the true comment delimiter.
Don't bother to get it right across escaped newlines. */
if (CPP_OPTION (pfile, warn_comments)
- && buffer->cur + 1 < buffer->rlimit
&& buffer->cur[0] == '*' && buffer->cur[1] != '/')
cpp_warning_with_line (pfile,
pfile->line, CPP_BUF_COL (buffer),
@@ -360,7 +349,7 @@ adjust_column (pfile)
/* Skips whitespace, saving the next non-whitespace character.
Adjusts pfile->col_adjust to account for tabs. Without this,
tokens might be assigned an incorrect column. */
-static void
+static int
skip_whitespace (pfile, c)
cpp_reader *pfile;
cppchar_t c;
@@ -378,6 +367,8 @@ skip_whitespace (pfile, c)
/* Just \f \v or \0 left. */
else if (c == '\0')
{
+ if (buffer->cur - 1 == buffer->rlimit)
+ return 0;
if (!warned)
{
cpp_warning (pfile, "null character(s) ignored");
@@ -390,14 +381,13 @@ skip_whitespace (pfile, c)
"%s in preprocessing directive",
c == '\f' ? "form feed" : "vertical tab");
- if (buffer->cur == buffer->rlimit)
- return;
c = *buffer->cur++;
}
/* We only want non-vertical space, i.e. ' ' \t \f \v \0. */
while (is_nvspace (c));
buffer->cur--;
+ return 1;
}
/* See if the characters of a number token are valid in a name (no
@@ -430,18 +420,16 @@ parse_identifier (pfile)
cpp_reader *pfile;
{
cpp_hashnode *result;
- const U_CHAR *cur, *rlimit;
+ const U_CHAR *cur;
/* Fast-path loop. Skim over a normal identifier.
N.B. ISIDNUM does not include $. */
- cur = pfile->buffer->cur - 1;
- rlimit = pfile->buffer->rlimit;
- do
+ cur = pfile->buffer->cur;
+ while (ISIDNUM (*cur))
cur++;
- while (cur < rlimit && ISIDNUM (*cur));
/* Check for slow-path cases. */
- if (cur < rlimit && (*cur == '?' || *cur == '\\' || *cur == '$'))
+ if (*cur == '?' || *cur == '\\' || *cur == '$')
result = parse_identifier_slow (pfile, cur);
else
{
@@ -501,9 +489,6 @@ parse_identifier_slow (pfile, cur)
if (c == '$')
saw_dollar++;
- if (buffer->cur == buffer->rlimit)
- goto at_eof;
-
c = *buffer->cur++;
}
@@ -515,9 +500,8 @@ parse_identifier_slow (pfile, cur)
}
while (is_idchar (c));
- /* Step back over the unwanted char, except at EOF. */
+ /* Step back over the unwanted char. */
BACKUP ();
- at_eof:
/* $ is not an identifier character in the standard, but is commonly
accepted as an extension. Don't warn about it in skipped
@@ -573,9 +557,6 @@ parse_number (pfile, number, c, leading_period)
}
*dest++ = c;
- if (buffer->cur == buffer->rlimit)
- goto at_eof;
-
c = *buffer->cur++;
}
while (is_numchar (c) || c == '.' || VALID_SIGN (c, dest[-1]));
@@ -588,9 +569,8 @@ parse_number (pfile, number, c, leading_period)
}
while (is_numchar (c) || c == '.' || VALID_SIGN (c, dest[-1]));
- /* Step back over the unwanted char, except at EOF. */
+ /* Step back over the unwanted char. */
BACKUP ();
- at_eof:
/* Null-terminate the number. */
*dest = '\0';
@@ -671,12 +651,6 @@ parse_string (pfile, token, terminator)
limit = BUFF_LIMIT (pfile->u_buff);
}
- if (buffer->cur == buffer->rlimit)
- {
- unterminated (pfile, terminator);
- break;
- }
-
/* Handle trigraphs, escaped newlines etc. */
c = *buffer->cur++;
if (c == '?' || c == '\\')
@@ -724,10 +698,19 @@ parse_string (pfile, token, terminator)
handle_newline (pfile);
c = '\n';
}
- else if (c == '\0' && !warned_nulls)
+ else if (c == '\0')
{
- warned_nulls = true;
- cpp_warning (pfile, "null character(s) preserved in literal");
+ if (buffer->cur - 1 == buffer->rlimit)
+ {
+ unterminated (pfile, terminator);
+ buffer->cur--;
+ break;
+ }
+ if (!warned_nulls)
+ {
+ warned_nulls = true;
+ cpp_warning (pfile, "null character(s) preserved in literal");
+ }
}
*dest++ = c;
@@ -907,15 +890,19 @@ _cpp_lex_direct (pfile)
result->line = pfile->line;
skipped_white:
- if (buffer->cur == buffer->rlimit)
- goto at_eof;
c = *buffer->cur++;
result->col = CPP_BUF_COLUMN (buffer, buffer->cur);
trigraph:
switch (c)
{
- at_eof:
+ case ' ': case '\t': case '\f': case '\v': case '\0':
+ result->flags |= PREV_WHITE;
+ if (skip_whitespace (pfile, c))
+ goto skipped_white;
+
+ /* EOF. */
+ buffer->cur--;
buffer->saved_flags = BOL;
if (!pfile->state.parsing_args && !pfile->state.in_directive)
{
@@ -941,11 +928,6 @@ _cpp_lex_direct (pfile)
result->type = CPP_EOF;
break;
- case ' ': case '\t': case '\f': case '\v': case '\0':
- skip_whitespace (pfile, c);
- result->flags |= PREV_WHITE;
- goto skipped_white;
-
case '\n': case '\r':
handle_newline (pfile);
buffer->saved_flags = BOL;
@@ -1016,8 +998,7 @@ _cpp_lex_direct (pfile)
result->val.node = parse_identifier (pfile);
/* 'L' may introduce wide characters or strings. */
- if (result->val.node == pfile->spec_nodes.n_L
- && buffer->cur < buffer->rlimit)
+ if (result->val.node == pfile->spec_nodes.n_L)
{
c = *buffer->cur;
if (c == '\'' || c == '"')