Makefile.in (LIBCPP_OBJS): Add cpplex.o.
* Makefile.in (LIBCPP_OBJS): Add cpplex.o. (cpplex.o): New target. * po/POTFILES.in: Add cpplex.c. * cpplex.c (_cpp_grow_token_buffer, null_cleanup, cpp_push_buffer, cpp_pop_buffer, cpp_scan_buffer, cpp_expand_to_buffer, cpp_buf_line_and_col, cpp_file_buffer, skip_block_comment, skip_line_comment, skip_comment, copy_comment, _cpp_skip_hspace, _cpp_skip_rest_of_line, _cpp_parse_name, skip_string, parse_string, _cpp_parse_assertion, cpp_get_token, cpp_get_non_space_token, _cpp_get_directive_token, find_position, _cpp_read_and_prescan, _cpp_init_input_buffer): Move here. (maybe_macroexpand, _cpp_lex_token): New functions. * cpplib.c (SKIP_WHITE_SPACE, eval_if_expr, parse_set_mark, parse_goto_mark): Delete. (_cpp_handle_eof): New function. (_cpp_handle_directive): Rename from handle_directive. (_cpp_output_line_command): Rename from output_line_command. (do_if, do_elif): Call _cpp_parse_expr directly. * cppfiles.c (_cpp_read_include_file): Don't call init_input_buffer here. * cpphash.c (quote_string): Move here, rename _cpp_quote_string. * cppexp.c (_cpp_parse_expr): Diddle parsing_if_directive here; pop the token_buffer and skip the rest of the line here. * cppinit.c (cpp_start_read): Call _cpp_init_input_buffer here. * cpphash.h (CPP_RESERVE, CPP_IS_MACRO_BUFFER, ACTIVE_MARK_P): Define here. (CPP_SET_BUF_MARK, CPP_GOTO_BUF_MARK, CPP_SET_MARK, CPP_GOTO_MARK): New macros. (_cpp_quote_string, _cpp_parse_name, _cpp_skip_rest_of_line, _cpp_skip_hspace, _cpp_parse_assertion, _cpp_lex_token, _cpp_read_and_prescan, _cpp_init_input_buffer, _cpp_grow_token_buffer, _cpp_get_directive_token, _cpp_handle_directive, _cpp_handle_eof, _cpp_output_line_command): Prototype them here. * cpplib.h (enum cpp_token): Add CPP_MACRO. (CPP_RESERVE, get_directive_token, cpp_grow_buffer, quote_string, output_line_command): Remove. From-SVN: r32513
This commit is contained in:
parent
46089b8642
commit
45b966db65
11 changed files with 1978 additions and 1913 deletions
|
@ -1,3 +1,48 @@
|
|||
2000-03-13 Zack Weinberg <zack@wolery.cumb.org>
|
||||
|
||||
* Makefile.in (LIBCPP_OBJS): Add cpplex.o.
|
||||
(cpplex.o): New target.
|
||||
* po/POTFILES.in: Add cpplex.c.
|
||||
|
||||
* cpplex.c (_cpp_grow_token_buffer, null_cleanup,
|
||||
cpp_push_buffer, cpp_pop_buffer, cpp_scan_buffer,
|
||||
cpp_expand_to_buffer, cpp_buf_line_and_col, cpp_file_buffer,
|
||||
skip_block_comment, skip_line_comment, skip_comment,
|
||||
copy_comment, _cpp_skip_hspace, _cpp_skip_rest_of_line,
|
||||
_cpp_parse_name, skip_string, parse_string,
|
||||
_cpp_parse_assertion, cpp_get_token, cpp_get_non_space_token,
|
||||
_cpp_get_directive_token, find_position,
|
||||
_cpp_read_and_prescan, _cpp_init_input_buffer): Move here.
|
||||
(maybe_macroexpand, _cpp_lex_token): New functions.
|
||||
|
||||
* cpplib.c (SKIP_WHITE_SPACE, eval_if_expr, parse_set_mark,
|
||||
parse_goto_mark): Delete.
|
||||
(_cpp_handle_eof): New function.
|
||||
(_cpp_handle_directive): Rename from handle_directive.
|
||||
(_cpp_output_line_command): Rename from output_line_command.
|
||||
(do_if, do_elif): Call _cpp_parse_expr directly.
|
||||
* cppfiles.c (_cpp_read_include_file): Don't call
|
||||
init_input_buffer here.
|
||||
* cpphash.c (quote_string): Move here, rename _cpp_quote_string.
|
||||
* cppexp.c (_cpp_parse_expr): Diddle parsing_if_directive
|
||||
here; pop the token_buffer and skip the rest of the line here.
|
||||
* cppinit.c (cpp_start_read): Call _cpp_init_input_buffer
|
||||
here.
|
||||
|
||||
* cpphash.h (CPP_RESERVE, CPP_IS_MACRO_BUFFER, ACTIVE_MARK_P):
|
||||
Define here.
|
||||
(CPP_SET_BUF_MARK, CPP_GOTO_BUF_MARK, CPP_SET_MARK,
|
||||
CPP_GOTO_MARK): New macros.
|
||||
(_cpp_quote_string, _cpp_parse_name, _cpp_skip_rest_of_line,
|
||||
_cpp_skip_hspace, _cpp_parse_assertion, _cpp_lex_token,
|
||||
_cpp_read_and_prescan, _cpp_init_input_buffer,
|
||||
_cpp_grow_token_buffer, _cpp_get_directive_token,
|
||||
_cpp_handle_directive, _cpp_handle_eof,
|
||||
_cpp_output_line_command): Prototype them here.
|
||||
* cpplib.h (enum cpp_token): Add CPP_MACRO.
|
||||
(CPP_RESERVE, get_directive_token, cpp_grow_buffer,
|
||||
quote_string, output_line_command): Remove.
|
||||
|
||||
2000-03-13 Bernd Schmidt <bernds@cygnus.co.uk>
|
||||
|
||||
* stmt.c (expand_end_case): RANGE may be signed, and when checking
|
||||
|
|
|
@ -2025,7 +2025,7 @@ cccp.o: cccp.c $(CONFIG_H) intl.h pcp.h version.c config.status system.h \
|
|||
-c `echo $(srcdir)/cccp.c | sed 's,^\./,,'`
|
||||
|
||||
LIBCPP_OBJS = cpplib.o cpphash.o cpperror.o cppexp.o cppfiles.o \
|
||||
cppinit.o cppulp.o mkdeps.o \
|
||||
cppinit.o cppulp.o cpplex.o mkdeps.o \
|
||||
prefix.o version.o mbchar.o @extra_cpp_objs@
|
||||
|
||||
LIBCPP_DEPS = cpplib.h cpphash.h intl.h system.h
|
||||
|
@ -2048,6 +2048,7 @@ cppmain.o: cppmain.c $(CONFIG_H) cpplib.h intl.h system.h
|
|||
cppulp.o: cppulp.c $(CONFIG_H) system.h output.h
|
||||
cpperror.o: cpperror.c $(CONFIG_H) $(LIBCPP_DEPS)
|
||||
cppexp.o: cppexp.c $(CONFIG_H) $(LIBCPP_DEPS)
|
||||
cpplex.o: cpplex.c $(CONFIG_H) $(LIBCPP_DEPS)
|
||||
cppfiles.o: cppfiles.c $(CONFIG_H) $(LIBCPP_DEPS) $(HASHTAB_H)
|
||||
cpphash.o: cpphash.c $(CONFIG_H) $(LIBCPP_DEPS) $(HASHTAB_H)
|
||||
cpplib.o: cpplib.c $(CONFIG_H) $(LIBCPP_DEPS) $(HASHTAB_H) mkdeps.h
|
||||
|
|
23
gcc/cppexp.c
23
gcc/cppexp.c
|
@ -352,12 +352,12 @@ parse_defined (pfile)
|
|||
op.op = INT;
|
||||
|
||||
pfile->no_macro_expand++;
|
||||
token = get_directive_token (pfile);
|
||||
token = _cpp_get_directive_token (pfile);
|
||||
if (token == CPP_LPAREN)
|
||||
{
|
||||
paren++;
|
||||
CPP_SET_WRITTEN (pfile, old_written);
|
||||
token = get_directive_token (pfile);
|
||||
token = _cpp_get_directive_token (pfile);
|
||||
}
|
||||
|
||||
if (token != CPP_NAME)
|
||||
|
@ -369,7 +369,7 @@ parse_defined (pfile)
|
|||
|
||||
if (paren)
|
||||
{
|
||||
if (get_directive_token (pfile) != CPP_RPAREN)
|
||||
if (_cpp_get_directive_token (pfile) != CPP_RPAREN)
|
||||
goto oops;
|
||||
}
|
||||
CPP_SET_WRITTEN (pfile, old_written);
|
||||
|
@ -419,7 +419,7 @@ lex (pfile, skip_evaluation)
|
|||
long old_written;
|
||||
|
||||
old_written = CPP_WRITTEN (pfile);
|
||||
token = get_directive_token (pfile);
|
||||
token = _cpp_get_directive_token (pfile);
|
||||
|
||||
tok_start = pfile->token_buffer + old_written;
|
||||
tok_end = CPP_PWRITTEN (pfile);
|
||||
|
@ -689,7 +689,10 @@ _cpp_parse_expr (pfile)
|
|||
register struct operation *top = stack;
|
||||
unsigned int lprio, rprio = 0;
|
||||
int skip_evaluation = 0;
|
||||
long old_written = CPP_WRITTEN (pfile);
|
||||
int result;
|
||||
|
||||
pfile->parsing_if_directive++;
|
||||
top->rprio = 0;
|
||||
top->flags = 0;
|
||||
for (;;)
|
||||
|
@ -999,9 +1002,8 @@ _cpp_parse_expr (pfile)
|
|||
{
|
||||
if (top != stack)
|
||||
cpp_ice (pfile, "unbalanced stack in #if expression");
|
||||
if (stack != init_stack)
|
||||
free (stack);
|
||||
return (top->value != 0);
|
||||
result = (top->value != 0);
|
||||
goto done;
|
||||
}
|
||||
top++;
|
||||
|
||||
|
@ -1041,7 +1043,12 @@ _cpp_parse_expr (pfile)
|
|||
}
|
||||
}
|
||||
syntax_error:
|
||||
_cpp_skip_rest_of_line (pfile);
|
||||
result = 0;
|
||||
done:
|
||||
pfile->parsing_if_directive--;
|
||||
CPP_SET_WRITTEN (pfile, old_written);
|
||||
if (stack != init_stack)
|
||||
free (stack);
|
||||
return 0;
|
||||
return result;
|
||||
}
|
||||
|
|
405
gcc/cppfiles.c
405
gcc/cppfiles.c
|
@ -38,17 +38,13 @@ static struct file_name_map *read_name_map
|
|||
static char *read_filename_string PARAMS ((int, FILE *));
|
||||
static char *remap_filename PARAMS ((cpp_reader *, char *,
|
||||
struct file_name_list *));
|
||||
static long read_and_prescan PARAMS ((cpp_reader *, cpp_buffer *,
|
||||
int, size_t));
|
||||
static struct file_name_list *actual_directory
|
||||
PARAMS ((cpp_reader *, const char *));
|
||||
|
||||
static unsigned int hash_IHASH PARAMS ((const void *));
|
||||
static int eq_IHASH PARAMS ((const void *, const void *));
|
||||
|
||||
static void init_input_buffer PARAMS ((cpp_reader *, int, struct stat *));
|
||||
static int file_cleanup PARAMS ((cpp_buffer *, cpp_reader *));
|
||||
static U_CHAR *find_position PARAMS ((U_CHAR *, U_CHAR *, unsigned long *));
|
||||
|
||||
#if 0
|
||||
static void hack_vms_include_specification PARAMS ((char *));
|
||||
|
@ -587,14 +583,11 @@ _cpp_read_include_file (pfile, fd, ihash)
|
|||
goto fail;
|
||||
}
|
||||
|
||||
if (pfile->input_buffer == NULL)
|
||||
init_input_buffer (pfile, fd, &st);
|
||||
|
||||
/* Read the file, converting end-of-line characters and trigraphs
|
||||
(if enabled). */
|
||||
fp->ihash = ihash;
|
||||
fp->nominal_fname = ihash->name;
|
||||
length = read_and_prescan (pfile, fp, fd, st_size);
|
||||
length = _cpp_read_and_prescan (pfile, fp, fd, st_size);
|
||||
if (length < 0)
|
||||
goto fail;
|
||||
if (length == 0)
|
||||
|
@ -687,402 +680,6 @@ actual_directory (pfile, fname)
|
|||
return x;
|
||||
}
|
||||
|
||||
/* Determine the current line and column. Used only by read_and_prescan. */
|
||||
static U_CHAR *
|
||||
find_position (start, limit, linep)
|
||||
U_CHAR *start;
|
||||
U_CHAR *limit;
|
||||
unsigned long *linep;
|
||||
{
|
||||
unsigned long line = *linep;
|
||||
U_CHAR *lbase = start;
|
||||
while (start < limit)
|
||||
{
|
||||
U_CHAR ch = *start++;
|
||||
if (ch == '\n' || ch == '\r')
|
||||
{
|
||||
line++;
|
||||
lbase = start;
|
||||
}
|
||||
}
|
||||
*linep = line;
|
||||
return lbase;
|
||||
}
|
||||
|
||||
/* Read the entire contents of file DESC into buffer BUF. LEN is how
|
||||
much memory to allocate initially; more will be allocated if
|
||||
necessary. Convert end-of-line markers (\n, \r, \r\n, \n\r) to
|
||||
canonical form (\n). If enabled, convert and/or warn about
|
||||
trigraphs. Convert backslash-newline to a one-character escape
|
||||
(\r) and remove it from "embarrassing" places (i.e. the middle of a
|
||||
token). If there is no newline at the end of the file, add one and
|
||||
warn. Returns -1 on failure, or the actual length of the data to
|
||||
be scanned.
|
||||
|
||||
This function does a lot of work, and can be a serious performance
|
||||
bottleneck. It has been tuned heavily; make sure you understand it
|
||||
before hacking. The common case - no trigraphs, Unix style line
|
||||
breaks, backslash-newline set off by whitespace, newline at EOF -
|
||||
has been optimized at the expense of the others. The performance
|
||||
penalty for DOS style line breaks (\r\n) is about 15%.
|
||||
|
||||
Warnings lose particularly heavily since we have to determine the
|
||||
line number, which involves scanning from the beginning of the file
|
||||
or from the last warning. The penalty for the absence of a newline
|
||||
at the end of reload1.c is about 60%. (reload1.c is 329k.)
|
||||
|
||||
If your file has more than one kind of end-of-line marker, you
|
||||
will get messed-up line numbering. */
|
||||
|
||||
/* Table of characters that can't be handled in the inner loop.
|
||||
Keep these contiguous to optimize the performance of the code generated
|
||||
for the switch that uses them. */
|
||||
#define SPECCASE_EMPTY 0
|
||||
#define SPECCASE_NUL 1
|
||||
#define SPECCASE_CR 2
|
||||
#define SPECCASE_BACKSLASH 3
|
||||
#define SPECCASE_QUESTION 4
|
||||
|
||||
static long
|
||||
read_and_prescan (pfile, fp, desc, len)
|
||||
cpp_reader *pfile;
|
||||
cpp_buffer *fp;
|
||||
int desc;
|
||||
size_t len;
|
||||
{
|
||||
U_CHAR *buf = (U_CHAR *) xmalloc (len);
|
||||
U_CHAR *ip, *op, *line_base;
|
||||
U_CHAR *ibase;
|
||||
U_CHAR *speccase = pfile->input_speccase;
|
||||
unsigned long line;
|
||||
unsigned int deferred_newlines;
|
||||
int count;
|
||||
size_t offset;
|
||||
|
||||
offset = 0;
|
||||
op = buf;
|
||||
line_base = buf;
|
||||
line = 1;
|
||||
ibase = pfile->input_buffer + 2;
|
||||
deferred_newlines = 0;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
read_next:
|
||||
|
||||
count = read (desc, pfile->input_buffer + 2, pfile->input_buffer_len);
|
||||
if (count < 0)
|
||||
goto error;
|
||||
else if (count == 0)
|
||||
break;
|
||||
|
||||
offset += count;
|
||||
ip = ibase;
|
||||
ibase = pfile->input_buffer + 2;
|
||||
ibase[count] = ibase[count+1] = '\0';
|
||||
|
||||
if (offset > len)
|
||||
{
|
||||
size_t delta_op;
|
||||
size_t delta_line_base;
|
||||
len *= 2;
|
||||
if (offset > len)
|
||||
/* len overflowed.
|
||||
This could happen if the file is larger than half the
|
||||
maximum address space of the machine. */
|
||||
goto too_big;
|
||||
|
||||
delta_op = op - buf;
|
||||
delta_line_base = line_base - buf;
|
||||
buf = (U_CHAR *) xrealloc (buf, len);
|
||||
op = buf + delta_op;
|
||||
line_base = buf + delta_line_base;
|
||||
}
|
||||
|
||||
for (;;)
|
||||
{
|
||||
unsigned int span = 0;
|
||||
|
||||
/* Deal with \-newline in the middle of a token. */
|
||||
if (deferred_newlines)
|
||||
{
|
||||
while (speccase[ip[span]] == SPECCASE_EMPTY
|
||||
&& ip[span] != '\n'
|
||||
&& ip[span] != '\t'
|
||||
&& ip[span] != ' ')
|
||||
span++;
|
||||
memcpy (op, ip, span);
|
||||
op += span;
|
||||
ip += span;
|
||||
/* If ip[0] is SPECCASE_EMPTY, we have hit white space.
|
||||
Dump out the remaining deferred \-newlines. */
|
||||
if (speccase[ip[0]] == SPECCASE_EMPTY)
|
||||
while (deferred_newlines)
|
||||
deferred_newlines--, *op++ = '\r';
|
||||
span = 0;
|
||||
}
|
||||
|
||||
/* Copy as much as we can without special treatment. */
|
||||
while (speccase[ip[span]] == SPECCASE_EMPTY) span++;
|
||||
memcpy (op, ip, span);
|
||||
op += span;
|
||||
ip += span;
|
||||
|
||||
switch (speccase[*ip++])
|
||||
{
|
||||
case SPECCASE_NUL: /* \0 */
|
||||
ibase[-1] = op[-1];
|
||||
goto read_next;
|
||||
|
||||
case SPECCASE_CR: /* \r */
|
||||
if (ip[-2] == '\n')
|
||||
continue;
|
||||
else if (*ip == '\n')
|
||||
ip++;
|
||||
else if (*ip == '\0')
|
||||
{
|
||||
*--ibase = '\r';
|
||||
goto read_next;
|
||||
}
|
||||
*op++ = '\n';
|
||||
break;
|
||||
|
||||
case SPECCASE_BACKSLASH: /* \ */
|
||||
backslash:
|
||||
{
|
||||
/* If we're at the end of the intermediate buffer,
|
||||
we have to shift the backslash down to the start
|
||||
and come back next pass. */
|
||||
if (*ip == '\0')
|
||||
{
|
||||
*--ibase = '\\';
|
||||
goto read_next;
|
||||
}
|
||||
else if (*ip == '\n')
|
||||
{
|
||||
ip++;
|
||||
if (*ip == '\r') ip++;
|
||||
if (*ip == '\n' || *ip == '\t' || *ip == ' ')
|
||||
*op++ = '\r';
|
||||
else if (op[-1] == '\t' || op[-1] == ' '
|
||||
|| op[-1] == '\r' || op[-1] == '\n')
|
||||
*op++ = '\r';
|
||||
else
|
||||
deferred_newlines++;
|
||||
}
|
||||
else if (*ip == '\r')
|
||||
{
|
||||
ip++;
|
||||
if (*ip == '\n') ip++;
|
||||
else if (*ip == '\0')
|
||||
{
|
||||
*--ibase = '\r';
|
||||
*--ibase = '\\';
|
||||
goto read_next;
|
||||
}
|
||||
else if (*ip == '\r' || *ip == '\t' || *ip == ' ')
|
||||
*op++ = '\r';
|
||||
else
|
||||
deferred_newlines++;
|
||||
}
|
||||
else
|
||||
*op++ = '\\';
|
||||
}
|
||||
break;
|
||||
|
||||
case SPECCASE_QUESTION: /* ? */
|
||||
{
|
||||
unsigned int d, t;
|
||||
/* If we're at the end of the intermediate buffer,
|
||||
we have to shift the ?'s down to the start and
|
||||
come back next pass. */
|
||||
d = ip[0];
|
||||
if (d == '\0')
|
||||
{
|
||||
*--ibase = '?';
|
||||
goto read_next;
|
||||
}
|
||||
if (d != '?')
|
||||
{
|
||||
*op++ = '?';
|
||||
break;
|
||||
}
|
||||
d = ip[1];
|
||||
if (d == '\0')
|
||||
{
|
||||
*--ibase = '?';
|
||||
*--ibase = '?';
|
||||
goto read_next;
|
||||
}
|
||||
|
||||
/* Trigraph map:
|
||||
* from to from to from to
|
||||
* ?? = # ?? ) ] ?? ! |
|
||||
* ?? ( [ ?? ' ^ ?? > }
|
||||
* ?? / \ ?? < { ?? - ~
|
||||
*/
|
||||
if (d == '=') t = '#';
|
||||
else if (d == ')') t = ']';
|
||||
else if (d == '!') t = '|';
|
||||
else if (d == '(') t = '[';
|
||||
else if (d == '\'') t = '^';
|
||||
else if (d == '>') t = '}';
|
||||
else if (d == '/') t = '\\';
|
||||
else if (d == '<') t = '{';
|
||||
else if (d == '-') t = '~';
|
||||
else
|
||||
{
|
||||
*op++ = '?';
|
||||
break;
|
||||
}
|
||||
ip += 2;
|
||||
if (CPP_OPTIONS (pfile)->warn_trigraphs)
|
||||
{
|
||||
unsigned long col;
|
||||
line_base = find_position (line_base, op, &line);
|
||||
col = op - line_base + 1;
|
||||
if (CPP_OPTIONS (pfile)->trigraphs)
|
||||
cpp_warning_with_line (pfile, line, col,
|
||||
"trigraph ??%c converted to %c", d, t);
|
||||
else
|
||||
cpp_warning_with_line (pfile, line, col,
|
||||
"trigraph ??%c ignored", d);
|
||||
}
|
||||
if (CPP_OPTIONS (pfile)->trigraphs)
|
||||
{
|
||||
if (t == '\\')
|
||||
goto backslash;
|
||||
else
|
||||
*op++ = t;
|
||||
}
|
||||
else
|
||||
{
|
||||
*op++ = '?';
|
||||
*op++ = '?';
|
||||
*op++ = d;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (offset == 0)
|
||||
return 0;
|
||||
|
||||
/* Deal with pushed-back chars at true EOF.
|
||||
This may be any of: ?? ? \ \r \n \\r \\n.
|
||||
\r must become \n, \\r or \\n must become \r.
|
||||
We know we have space already. */
|
||||
if (ibase == pfile->input_buffer)
|
||||
{
|
||||
if (*ibase == '?')
|
||||
{
|
||||
*op++ = '?';
|
||||
*op++ = '?';
|
||||
}
|
||||
else
|
||||
*op++ = '\r';
|
||||
}
|
||||
else if (ibase == pfile->input_buffer + 1)
|
||||
{
|
||||
if (*ibase == '\r')
|
||||
*op++ = '\n';
|
||||
else
|
||||
*op++ = *ibase;
|
||||
}
|
||||
|
||||
if (op[-1] != '\n')
|
||||
{
|
||||
unsigned long col;
|
||||
line_base = find_position (line_base, op, &line);
|
||||
col = op - line_base + 1;
|
||||
cpp_warning_with_line (pfile, line, col, "no newline at end of file\n");
|
||||
if (offset + 1 > len)
|
||||
{
|
||||
len += 1;
|
||||
if (offset + 1 > len)
|
||||
goto too_big;
|
||||
buf = (U_CHAR *) xrealloc (buf, len);
|
||||
op = buf + offset;
|
||||
}
|
||||
*op++ = '\n';
|
||||
}
|
||||
|
||||
fp->buf = ((len - offset < 20) ? buf : (U_CHAR *)xrealloc (buf, op - buf));
|
||||
return op - buf;
|
||||
|
||||
too_big:
|
||||
cpp_error (pfile, "file is too large (>%lu bytes)\n", (unsigned long)offset);
|
||||
free (buf);
|
||||
return -1;
|
||||
|
||||
error:
|
||||
cpp_error_from_errno (pfile, fp->ihash->name);
|
||||
free (buf);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Initialize the `input_buffer' and `input_speccase' tables.
|
||||
These are only used by read_and_prescan, but they're large and
|
||||
somewhat expensive to set up, so we want them allocated once for
|
||||
the duration of the cpp run. */
|
||||
|
||||
static void
|
||||
init_input_buffer (pfile, fd, st)
|
||||
cpp_reader *pfile;
|
||||
int fd;
|
||||
struct stat *st;
|
||||
{
|
||||
long pipe_buf;
|
||||
U_CHAR *tmp;
|
||||
|
||||
/* Table of characters that cannot be handled by the
|
||||
read_and_prescan inner loop. The number of non-EMPTY entries
|
||||
should be as small as humanly possible. */
|
||||
|
||||
tmp = (U_CHAR *) xmalloc (1 << CHAR_BIT);
|
||||
memset (tmp, SPECCASE_EMPTY, 1 << CHAR_BIT);
|
||||
tmp['\0'] = SPECCASE_NUL;
|
||||
tmp['\r'] = SPECCASE_CR;
|
||||
tmp['\\'] = SPECCASE_BACKSLASH;
|
||||
if (CPP_OPTIONS (pfile)->trigraphs || CPP_OPTIONS (pfile)->warn_trigraphs)
|
||||
tmp['?'] = SPECCASE_QUESTION;
|
||||
|
||||
pfile->input_speccase = tmp;
|
||||
|
||||
/* Determine the appropriate size for the input buffer. Normal C
|
||||
source files are smaller than eight K. If we are reading a pipe,
|
||||
we want to make sure the input buffer is bigger than the kernel's
|
||||
pipe buffer. */
|
||||
pipe_buf = -1;
|
||||
|
||||
if (! S_ISREG (st->st_mode))
|
||||
{
|
||||
#ifdef _PC_PIPE_BUF
|
||||
pipe_buf = fpathconf (fd, _PC_PIPE_BUF);
|
||||
#endif
|
||||
if (pipe_buf == -1)
|
||||
{
|
||||
#ifdef PIPE_BUF
|
||||
pipe_buf = PIPE_BUF;
|
||||
#else
|
||||
pipe_buf = 8192;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
if (pipe_buf < 8192)
|
||||
pipe_buf = 8192;
|
||||
/* PIPE_BUF bytes of buffer proper, 2 to detect running off the end
|
||||
without address arithmetic all the time, and 2 for pushback in
|
||||
the case there's a potential trigraph or end-of-line digraph at
|
||||
the end of a block. */
|
||||
|
||||
tmp = (U_CHAR *) xmalloc (pipe_buf + 2 + 2);
|
||||
pfile->input_buffer = tmp;
|
||||
pfile->input_buffer_len = pipe_buf;
|
||||
}
|
||||
|
||||
/* Simplify a path name in place, deleting redundant components. This
|
||||
reduces OS overhead and guarantees that equivalent paths compare
|
||||
the same (modulo symlinks).
|
||||
|
|
|
@ -307,7 +307,7 @@ collect_expansion (pfile, arglist)
|
|||
last -= 2; /* two extra chars for the leading escape */
|
||||
for (;;)
|
||||
{
|
||||
/* We use cpp_get_token because get_directive_token would
|
||||
/* We use cpp_get_token because _cpp_get_directive_token would
|
||||
discard whitespace and we can't cope with that yet. Macro
|
||||
expansion is off, so we are guaranteed not to see POP or EOF. */
|
||||
|
||||
|
@ -570,7 +570,7 @@ collect_formal_parameters (pfile)
|
|||
long old_written;
|
||||
|
||||
old_written = CPP_WRITTEN (pfile);
|
||||
token = get_directive_token (pfile);
|
||||
token = _cpp_get_directive_token (pfile);
|
||||
if (token != CPP_LPAREN)
|
||||
{
|
||||
cpp_ice (pfile, "first token = %d not %d in collect_formal_parameters",
|
||||
|
@ -584,7 +584,7 @@ collect_formal_parameters (pfile)
|
|||
for (;;)
|
||||
{
|
||||
CPP_SET_WRITTEN (pfile, old_written);
|
||||
token = get_directive_token (pfile);
|
||||
token = _cpp_get_directive_token (pfile);
|
||||
switch (token)
|
||||
{
|
||||
case CPP_NAME:
|
||||
|
@ -660,7 +660,7 @@ collect_formal_parameters (pfile)
|
|||
|
||||
argv[argc].rest_arg = 1;
|
||||
|
||||
token = get_directive_token (pfile);
|
||||
token = _cpp_get_directive_token (pfile);
|
||||
if (token != CPP_RPAREN)
|
||||
{
|
||||
cpp_error (pfile, "another parameter follows `...'");
|
||||
|
@ -826,6 +826,43 @@ static const char * const monthnames[] =
|
|||
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
|
||||
};
|
||||
|
||||
/* Place into PFILE a quoted string representing the string SRC.
|
||||
Caller must reserve enough space in pfile->token_buffer. */
|
||||
|
||||
void
|
||||
_cpp_quote_string (pfile, src)
|
||||
cpp_reader *pfile;
|
||||
const char *src;
|
||||
{
|
||||
U_CHAR c;
|
||||
|
||||
CPP_PUTC_Q (pfile, '\"');
|
||||
for (;;)
|
||||
switch ((c = *src++))
|
||||
{
|
||||
default:
|
||||
if (ISPRINT (c))
|
||||
CPP_PUTC_Q (pfile, c);
|
||||
else
|
||||
{
|
||||
sprintf ((char *)CPP_PWRITTEN (pfile), "\\%03o", c);
|
||||
CPP_ADJUST_WRITTEN (pfile, 4);
|
||||
}
|
||||
break;
|
||||
|
||||
case '\"':
|
||||
case '\\':
|
||||
CPP_PUTC_Q (pfile, '\\');
|
||||
CPP_PUTC_Q (pfile, c);
|
||||
break;
|
||||
|
||||
case '\0':
|
||||
CPP_PUTC_Q (pfile, '\"');
|
||||
CPP_NUL_TERMINATE_Q (pfile);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* expand things like __FILE__. Place the expansion into the output
|
||||
* buffer *without* rescanning.
|
||||
|
@ -857,7 +894,7 @@ special_symbol (hp, pfile)
|
|||
if (!buf)
|
||||
buf = "";
|
||||
CPP_RESERVE (pfile, 3 + 4 * strlen (buf));
|
||||
quote_string (pfile, buf);
|
||||
_cpp_quote_string (pfile, buf);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1597,7 +1634,7 @@ _cpp_dump_definition (pfile, sym, len, defn)
|
|||
DEFINITION *defn;
|
||||
{
|
||||
if (pfile->lineno == 0)
|
||||
output_line_command (pfile, same_file);
|
||||
_cpp_output_line_command (pfile, same_file);
|
||||
|
||||
CPP_RESERVE (pfile, len + sizeof "#define ");
|
||||
CPP_PUTS_Q (pfile, "#define ", sizeof "#define " -1);
|
||||
|
|
|
@ -217,6 +217,11 @@ extern unsigned char _cpp_IStable[256];
|
|||
((BUFFER)->cur < (BUFFER)->rlimit ? *(BUFFER)->cur++ : EOF)
|
||||
#define CPP_FORWARD(BUFFER, N) ((BUFFER)->cur += (N))
|
||||
|
||||
/* Make sure PFILE->token_buffer has space for at least N more characters. */
|
||||
#define CPP_RESERVE(PFILE, N) \
|
||||
(CPP_WRITTEN (PFILE) + (size_t)(N) > (PFILE)->token_buffer_size \
|
||||
&& (_cpp_grow_token_buffer (PFILE, N), 0))
|
||||
|
||||
/* Append string STR (of length N) to PFILE's output buffer.
|
||||
Assume there is enough space. */
|
||||
#define CPP_PUTS_Q(PFILE, STR, N) \
|
||||
|
@ -242,6 +247,29 @@ extern unsigned char _cpp_IStable[256];
|
|||
#define CPP_PEDANTIC(PFILE) \
|
||||
(CPP_OPTIONS (PFILE)->pedantic && !CPP_BUFFER (pfile)->system_header_p)
|
||||
|
||||
/* CPP_IS_MACRO_BUFFER is true if the buffer contains macro expansion.
|
||||
(Note that it is false while we're expanding macro *arguments*.) */
|
||||
#define CPP_IS_MACRO_BUFFER(PBUF) ((PBUF)->data != NULL)
|
||||
|
||||
/* Remember the current position of PFILE so it may be returned to
|
||||
after looking ahead a bit.
|
||||
|
||||
Note that when you set a mark, you _must_ return to that mark. You
|
||||
may not forget about it and continue parsing. You may not pop a
|
||||
buffer with an active mark. You may not call CPP_BUMP_LINE while a
|
||||
mark is active. */
|
||||
#define CPP_SET_BUF_MARK(IP) ((IP)->mark = (IP)->cur - (IP)->buf)
|
||||
#define CPP_GOTO_BUF_MARK(IP) ((IP)->cur = (IP)->buf + (IP)->mark, \
|
||||
(IP)->mark = -1)
|
||||
#define CPP_SET_MARK(PFILE) CPP_SET_BUF_MARK(CPP_BUFFER(PFILE))
|
||||
#define CPP_GOTO_MARK(PFILE) CPP_GOTO_BUF_MARK(CPP_BUFFER(PFILE))
|
||||
|
||||
/* ACTIVE_MARK_P is true if there's a live mark in the buffer. */
|
||||
#define ACTIVE_MARK_P(PFILE) (CPP_BUFFER (PFILE)->mark != -1)
|
||||
|
||||
/* Last arg to output_line_command. */
|
||||
enum file_change_code {same_file, rename_file, enter_file, leave_file};
|
||||
|
||||
/* In cpphash.c */
|
||||
extern HASHNODE *_cpp_make_hashnode PARAMS ((const U_CHAR *, size_t,
|
||||
enum node_type,
|
||||
|
@ -257,6 +285,7 @@ extern void _cpp_dump_definition PARAMS ((cpp_reader *, const U_CHAR *,
|
|||
long, DEFINITION *));
|
||||
extern int _cpp_compare_defs PARAMS ((cpp_reader *, DEFINITION *,
|
||||
DEFINITION *));
|
||||
extern void _cpp_quote_string PARAMS ((cpp_reader *, const char *));
|
||||
extern void _cpp_macroexpand PARAMS ((cpp_reader *, HASHNODE *));
|
||||
extern void _cpp_init_macro_hash PARAMS ((cpp_reader *));
|
||||
extern void _cpp_dump_macro_hash PARAMS ((cpp_reader *));
|
||||
|
@ -272,4 +301,24 @@ extern void _cpp_init_include_hash PARAMS ((cpp_reader *));
|
|||
/* In cppexp.c */
|
||||
extern int _cpp_parse_expr PARAMS ((cpp_reader *));
|
||||
|
||||
/* In cpplex.c */
|
||||
extern void _cpp_parse_name PARAMS ((cpp_reader *, int));
|
||||
extern void _cpp_skip_rest_of_line PARAMS ((cpp_reader *));
|
||||
extern void _cpp_skip_hspace PARAMS ((cpp_reader *));
|
||||
extern int _cpp_parse_assertion PARAMS ((cpp_reader *));
|
||||
extern enum cpp_token _cpp_lex_token PARAMS ((cpp_reader *));
|
||||
extern long _cpp_read_and_prescan PARAMS ((cpp_reader *, cpp_buffer *,
|
||||
int, size_t));
|
||||
extern void _cpp_init_input_buffer PARAMS ((cpp_reader *));
|
||||
extern void _cpp_grow_token_buffer PARAMS ((cpp_reader *, long));
|
||||
extern enum cpp_token _cpp_get_directive_token
|
||||
PARAMS ((cpp_reader *));
|
||||
|
||||
/* In cpplib.c */
|
||||
extern int _cpp_handle_directive PARAMS ((cpp_reader *));
|
||||
extern void _cpp_handle_eof PARAMS ((cpp_reader *));
|
||||
extern void _cpp_output_line_command PARAMS ((cpp_reader *,
|
||||
enum file_change_code));
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -519,7 +519,7 @@ dump_special_to_buffer (pfile, macro_name)
|
|||
{
|
||||
static const char define_directive[] = "#define ";
|
||||
int macro_name_length = strlen (macro_name);
|
||||
output_line_command (pfile, same_file);
|
||||
_cpp_output_line_command (pfile, same_file);
|
||||
CPP_RESERVE (pfile, sizeof(define_directive) + macro_name_length);
|
||||
CPP_PUTS_Q (pfile, define_directive, sizeof(define_directive)-1);
|
||||
CPP_PUTS_Q (pfile, macro_name, macro_name_length);
|
||||
|
@ -872,6 +872,9 @@ cpp_start_read (pfile, fname)
|
|||
with a compiler that supports C99 designated initializers. */
|
||||
init_IStable ();
|
||||
|
||||
/* Set up the tables used by read_and_prescan. */
|
||||
_cpp_init_input_buffer (pfile);
|
||||
|
||||
/* Set up the include search path now. */
|
||||
if (! opts->no_standard_includes)
|
||||
initialize_standard_includes (pfile);
|
||||
|
@ -933,7 +936,7 @@ cpp_start_read (pfile, fname)
|
|||
counter accordingly. */
|
||||
pfile->lineno = CPP_BUFFER (pfile)->lineno;
|
||||
else
|
||||
output_line_command (pfile, same_file);
|
||||
_cpp_output_line_command (pfile, same_file);
|
||||
pfile->only_seen_white = 2;
|
||||
|
||||
/* The -imacros files can be scanned now, but the -include files
|
||||
|
@ -957,7 +960,7 @@ cpp_start_read (pfile, fname)
|
|||
while (p)
|
||||
{
|
||||
if (cpp_read_file (pfile, p->arg))
|
||||
output_line_command (pfile, enter_file);
|
||||
_cpp_output_line_command (pfile, enter_file);
|
||||
|
||||
q = p->next;
|
||||
free (p);
|
||||
|
|
1620
gcc/cpplex.c
Normal file
1620
gcc/cpplex.c
Normal file
File diff suppressed because it is too large
Load diff
1673
gcc/cpplib.c
1673
gcc/cpplib.c
File diff suppressed because it is too large
Load diff
14
gcc/cpplib.h
14
gcc/cpplib.h
|
@ -40,6 +40,7 @@ enum cpp_token
|
|||
CPP_HSPACE,
|
||||
CPP_VSPACE, /* newlines and #line directives */
|
||||
CPP_NAME,
|
||||
CPP_MACRO,
|
||||
CPP_NUMBER,
|
||||
CPP_CHAR,
|
||||
CPP_WCHAR,
|
||||
|
@ -233,11 +234,6 @@ struct cpp_reader
|
|||
#define CPP_ADJUST_WRITTEN(PFILE,DELTA) ((PFILE)->limit += (DELTA))
|
||||
#define CPP_SET_WRITTEN(PFILE,N) ((PFILE)->limit = (PFILE)->token_buffer + (N))
|
||||
|
||||
/* Make sure PFILE->token_buffer has space for at least N more characters. */
|
||||
#define CPP_RESERVE(PFILE, N) \
|
||||
(CPP_WRITTEN (PFILE) + (size_t)(N) > (PFILE)->token_buffer_size \
|
||||
&& (cpp_grow_buffer (PFILE, N), 0))
|
||||
|
||||
#define CPP_OPTIONS(PFILE) ((PFILE)->opts)
|
||||
#define CPP_BUFFER(PFILE) ((PFILE)->buffer)
|
||||
|
||||
|
@ -438,7 +434,6 @@ extern const char *progname;
|
|||
extern int cpp_handle_options PARAMS ((cpp_reader *, int, char **));
|
||||
extern enum cpp_token cpp_get_token PARAMS ((cpp_reader *));
|
||||
extern enum cpp_token cpp_get_non_space_token PARAMS ((cpp_reader *));
|
||||
extern enum cpp_token get_directive_token PARAMS ((cpp_reader *));
|
||||
|
||||
extern void cpp_reader_init PARAMS ((cpp_reader *));
|
||||
extern void cpp_options_init PARAMS ((cpp_options *));
|
||||
|
@ -482,22 +477,15 @@ extern void cpp_pedwarn_with_file_and_line PARAMS ((cpp_reader *, const char *,
|
|||
extern void cpp_error_from_errno PARAMS ((cpp_reader *, const char *));
|
||||
extern void cpp_notice_from_errno PARAMS ((cpp_reader *, const char *));
|
||||
|
||||
extern void cpp_grow_buffer PARAMS ((cpp_reader *, long));
|
||||
extern cpp_buffer *cpp_push_buffer PARAMS ((cpp_reader *,
|
||||
const unsigned char *, long));
|
||||
extern cpp_buffer *cpp_pop_buffer PARAMS ((cpp_reader *));
|
||||
extern int cpp_defined PARAMS ((cpp_reader *, const unsigned char *, int));
|
||||
|
||||
extern void quote_string PARAMS ((cpp_reader *, const char *));
|
||||
extern void cpp_expand_to_buffer PARAMS ((cpp_reader *,
|
||||
const unsigned char *, int));
|
||||
extern void cpp_scan_buffer PARAMS ((cpp_reader *));
|
||||
|
||||
/* Last arg to output_line_command. */
|
||||
enum file_change_code {same_file, rename_file, enter_file, leave_file};
|
||||
extern void output_line_command PARAMS ((cpp_reader *,
|
||||
enum file_change_code));
|
||||
|
||||
/* In cppfiles.c */
|
||||
extern int cpp_included PARAMS ((cpp_reader *, const char *));
|
||||
extern int cpp_read_file PARAMS ((cpp_reader *, const char *));
|
||||
|
|
|
@ -594,6 +594,7 @@ cppfiles.c
|
|||
cpphash.c
|
||||
cpphash.h
|
||||
cppinit.c
|
||||
cpplex.c
|
||||
cpplib.c
|
||||
cpplib.h
|
||||
cppmain.c
|
||||
|
|
Loading…
Add table
Reference in a new issue