Commit c56c2073 by Zack Weinberg Committed by Zack Weinberg

cpplib.h (CPP_POP, [...]): Delete.

	* cpplib.h (CPP_POP, parse_cleanup_t): Delete.
	(cpp_buffer): Remove cleanup, seen_eof, manual_pop members.

	* cppfiles.c (file_cleanup): Delete.
	* cpphash.c (macro_cleanup): Delete.
	(collect_objlike_expansion, collect_funlike_expansion,
	macarg, scan_arguments): Remove CPP_POP case.

	* cpplex.c (null_cleanup): Delete.
	(cpp_pop_buffer): Do the work that was done in the cleanups
	here.  Call _cpp_unwind_if_stack from here.
	(_cpp_expand_to_buffer, cpp_scan_buffer_nooutput,
	cpp_scan_buffer): Run until we see CPP_EOF and the top of
	stack is the buffer _below_ the one we stacked.
	(cpp_get_token): Always pop an exhausted buffer.  Return
	CPP_EOF unless it's a macro buffer.  Don't call _cpp_handle_eof.
	* cpplib.c (skip_if_group): Don't call cpp_get_token to
	increment the line number.
	(_cpp_handle_eof): Rename to _cpp_unwind_if_stack.

	* fix-header.c (read_scan_file) [parsing getchar()]: Run until
	we see CPP_EOF and the top of stack is the buffer _below_ the
	one we stacked.
	* scan-decls.c: Likewise.

From-SVN: r33611
parent 753e6cf1
2000-05-02 Zack Weinberg <zack@wolery.cumb.org>
* cpplib.h (CPP_POP, parse_cleanup_t): Delete.
(cpp_buffer): Remove cleanup, seen_eof, manual_pop members.
* cppfiles.c (file_cleanup): Delete.
* cpphash.c (macro_cleanup): Delete.
(collect_objlike_expansion, collect_funlike_expansion,
macarg, scan_arguments): Remove CPP_POP case.
* cpplex.c (null_cleanup): Delete.
(cpp_pop_buffer): Do the work that was done in the cleanups
here. Call _cpp_unwind_if_stack from here.
(_cpp_expand_to_buffer, cpp_scan_buffer_nooutput,
cpp_scan_buffer): Run until we see CPP_EOF and the top of
stack is the buffer _below_ the one we stacked.
(cpp_get_token): Always pop an exhausted buffer. Return
CPP_EOF unless it's a macro buffer. Don't call _cpp_handle_eof.
* cpplib.c (skip_if_group): Don't call cpp_get_token to
increment the line number.
(_cpp_handle_eof): Rename to _cpp_unwind_if_stack.
* fix-header.c (read_scan_file) [parsing getchar()]: Run until
we see CPP_EOF and the top of stack is the buffer _below_ the
one we stacked.
* scan-decls.c: Likewise.
2000-05-02 Andrew Haley <aph@cygnus.com> 2000-05-02 Andrew Haley <aph@cygnus.com>
* config/ia64/ia64.c (ia64_encode_section_info): Handle the case * config/ia64/ia64.c (ia64_encode_section_info): Handle the case
......
...@@ -42,7 +42,6 @@ static struct file_name_list *actual_directory ...@@ -42,7 +42,6 @@ static struct file_name_list *actual_directory
PARAMS ((cpp_reader *, const char *)); PARAMS ((cpp_reader *, const char *));
static unsigned int hash_IHASH PARAMS ((const void *)); static unsigned int hash_IHASH PARAMS ((const void *));
static int eq_IHASH PARAMS ((const void *, const void *)); static int eq_IHASH PARAMS ((const void *, const void *));
static int file_cleanup PARAMS ((cpp_buffer *, cpp_reader *));
static int find_include_file PARAMS ((cpp_reader *, const char *, static int find_include_file PARAMS ((cpp_reader *, const char *,
struct file_name_list *, struct file_name_list *,
IHASH **, int *)); IHASH **, int *));
...@@ -194,24 +193,6 @@ make_IHASH (name, fname, path, hash, slot) ...@@ -194,24 +193,6 @@ make_IHASH (name, fname, path, hash, slot)
return ih; return ih;
} }
static int
file_cleanup (pbuf, pfile)
cpp_buffer *pbuf;
cpp_reader *pfile;
{
if (pbuf->buf)
free ((PTR) pbuf->buf);
if (pfile->system_include_depth)
pfile->system_include_depth--;
if (pfile->potential_control_macro)
{
pbuf->ihash->control_macro = pfile->potential_control_macro;
pfile->potential_control_macro = 0;
}
pfile->input_stack_listing_current = 0;
return 0;
}
/* Centralize calls to open(2) here. This provides a hook for future /* Centralize calls to open(2) here. This provides a hook for future
changes which might, e.g. look for and open a precompiled version changes which might, e.g. look for and open a precompiled version
of the header. It also means all the magic currently associated of the header. It also means all the magic currently associated
...@@ -639,7 +620,7 @@ _cpp_execute_include (pfile, fname, len, no_reinclude, search_start) ...@@ -639,7 +620,7 @@ _cpp_execute_include (pfile, fname, len, no_reinclude, search_start)
if (read_include_file (pfile, fd, ihash)) if (read_include_file (pfile, fd, ihash))
{ {
if (angle_brackets) if (angle_brackets)
pfile->system_include_depth++; /* Decremented in file_cleanup. */ pfile->system_include_depth++;
} }
} }
...@@ -771,7 +752,6 @@ read_include_file (pfile, fd, ihash) ...@@ -771,7 +752,6 @@ read_include_file (pfile, fd, ihash)
fp->system_header_p = ihash->foundhere->sysp; fp->system_header_p = ihash->foundhere->sysp;
fp->lineno = 1; fp->lineno = 1;
fp->line_base = fp->buf; fp->line_base = fp->buf;
fp->cleanup = file_cleanup;
/* The ->actual_dir field is only used when ignore_srcdir is not in effect; /* The ->actual_dir field is only used when ignore_srcdir is not in effect;
see do_include */ see do_include */
......
...@@ -113,7 +113,6 @@ static int dump_hash_helper PARAMS ((void **, void *)); ...@@ -113,7 +113,6 @@ static int dump_hash_helper PARAMS ((void **, void *));
static void push_macro_expansion PARAMS ((cpp_reader *, const U_CHAR *, static void push_macro_expansion PARAMS ((cpp_reader *, const U_CHAR *,
int, HASHNODE *)); int, HASHNODE *));
static int unsafe_chars PARAMS ((cpp_reader *, int, int)); static int unsafe_chars PARAMS ((cpp_reader *, int, int));
static int macro_cleanup PARAMS ((cpp_buffer *, cpp_reader *));
static enum cpp_ttype macarg PARAMS ((cpp_reader *, int)); static enum cpp_ttype macarg PARAMS ((cpp_reader *, int));
static void special_symbol PARAMS ((cpp_reader *, HASHNODE *)); static void special_symbol PARAMS ((cpp_reader *, HASHNODE *));
static int compare_defs PARAMS ((cpp_reader *, static int compare_defs PARAMS ((cpp_reader *,
...@@ -332,22 +331,6 @@ _cpp_free_definition (h) ...@@ -332,22 +331,6 @@ _cpp_free_definition (h)
h->value.cpval = NULL; h->value.cpval = NULL;
} }
static int
macro_cleanup (pbuf, pfile)
cpp_buffer *pbuf;
cpp_reader *pfile ATTRIBUTE_UNUSED;
{
HASHNODE *m = pbuf->macro;
m->disabled = 0;
if ((m->type == T_FMACRO && pbuf->buf != m->value.fdefn->expansion)
|| m->type == T_SPECLINE || m->type == T_FILE
|| m->type == T_BASE_FILE || m->type == T_INCLUDE_LEVEL
|| m->type == T_STDC)
free ((PTR) pbuf->buf);
return 0;
}
/* Create pat nodes. */ /* Create pat nodes. */
static void static void
...@@ -485,7 +468,6 @@ collect_objlike_expansion (pfile, list) ...@@ -485,7 +468,6 @@ collect_objlike_expansion (pfile, list)
{ {
switch (list->tokens[i].type) switch (list->tokens[i].type)
{ {
case CPP_POP:
case CPP_EOF: case CPP_EOF:
cpp_ice (pfile, "EOF in collect_expansion"); cpp_ice (pfile, "EOF in collect_expansion");
/* fall through */ /* fall through */
...@@ -576,7 +558,6 @@ collect_funlike_expansion (pfile, list, arglist, replacement) ...@@ -576,7 +558,6 @@ collect_funlike_expansion (pfile, list, arglist, replacement)
len = list->tokens[i].val.name.len; len = list->tokens[i].val.name.len;
switch (token) switch (token)
{ {
case CPP_POP:
case CPP_EOF: case CPP_EOF:
cpp_ice (pfile, "EOF in collect_expansion"); cpp_ice (pfile, "EOF in collect_expansion");
/* fall through */ /* fall through */
...@@ -1034,14 +1015,9 @@ macarg (pfile, rest_args) ...@@ -1034,14 +1015,9 @@ macarg (pfile, rest_args)
switch (token) switch (token)
{ {
case CPP_EOF: case CPP_EOF:
/* We've hit end of file; this is an error.
Caller will report it. */
return token; return token;
case CPP_POP:
/* If we've hit end of file, it's an error (reported by caller).
Ditto if it's the end of cpp_expand_to_buffer text.
If we've hit end of macro, just continue. */
if (!CPP_IS_MACRO_BUFFER (CPP_BUFFER (pfile)))
return token;
break;
case CPP_OPEN_PAREN: case CPP_OPEN_PAREN:
paren++; paren++;
break; break;
...@@ -1361,7 +1337,7 @@ scan_arguments (pfile, defn, args, name) ...@@ -1361,7 +1337,7 @@ scan_arguments (pfile, defn, args, name)
} }
else else
token = macarg (pfile, 0); token = macarg (pfile, 0);
if (token == CPP_EOF || token == CPP_POP) if (token == CPP_EOF)
cpp_error_with_line (pfile, start_line, start_column, cpp_error_with_line (pfile, start_line, start_column,
"unterminated macro call"); "unterminated macro call");
i++; i++;
...@@ -1663,6 +1639,9 @@ funlike_macroexpand (pfile, hp, args) ...@@ -1663,6 +1639,9 @@ funlike_macroexpand (pfile, hp, args)
/* Now put the expansion on the input stack /* Now put the expansion on the input stack
so our caller will commence reading from it. */ so our caller will commence reading from it. */
push_macro_expansion (pfile, xbuf, totlen, hp); push_macro_expansion (pfile, xbuf, totlen, hp);
/* Overload buffer->mapped to indicate that xbuf needs to be freed. */
CPP_BUFFER (pfile)->mapped = 1;
} }
/* Return 1 iff a token ending in C1 followed directly by a token C2 /* Return 1 iff a token ending in C1 followed directly by a token C2
...@@ -1771,7 +1750,6 @@ push_macro_expansion (pfile, xbuf, len, hp) ...@@ -1771,7 +1750,6 @@ push_macro_expansion (pfile, xbuf, len, hp)
return; return;
if (advance_cur) if (advance_cur)
mbuf->cur += 2; mbuf->cur += 2;
mbuf->cleanup = macro_cleanup;
mbuf->macro = hp; mbuf->macro = hp;
mbuf->has_escapes = 1; mbuf->has_escapes = 1;
......
...@@ -253,7 +253,7 @@ extern void _cpp_scan_line PARAMS ((cpp_reader *, cpp_toklist *)); ...@@ -253,7 +253,7 @@ extern void _cpp_scan_line PARAMS ((cpp_reader *, cpp_toklist *));
/* In cpplib.c */ /* In cpplib.c */
extern int _cpp_handle_directive PARAMS ((cpp_reader *)); extern int _cpp_handle_directive PARAMS ((cpp_reader *));
extern void _cpp_handle_eof PARAMS ((cpp_reader *)); extern void _cpp_unwind_if_stack PARAMS ((cpp_reader *, cpp_buffer *));
extern void _cpp_check_directive PARAMS((cpp_toklist *, cpp_token *)); extern void _cpp_check_directive PARAMS((cpp_toklist *, cpp_token *));
#endif #endif
...@@ -45,7 +45,6 @@ static int copy_comment PARAMS ((cpp_reader *, int)); ...@@ -45,7 +45,6 @@ static int copy_comment PARAMS ((cpp_reader *, int));
static void skip_string PARAMS ((cpp_reader *, int)); static void skip_string PARAMS ((cpp_reader *, int));
static void parse_string PARAMS ((cpp_reader *, int)); static void parse_string PARAMS ((cpp_reader *, int));
static U_CHAR *find_position PARAMS ((U_CHAR *, U_CHAR *, unsigned long *)); static U_CHAR *find_position PARAMS ((U_CHAR *, U_CHAR *, unsigned long *));
static int null_cleanup PARAMS ((cpp_buffer *, cpp_reader *));
static void null_warning PARAMS ((cpp_reader *, unsigned int)); static void null_warning PARAMS ((cpp_reader *, unsigned int));
static void safe_fwrite PARAMS ((cpp_reader *, const U_CHAR *, static void safe_fwrite PARAMS ((cpp_reader *, const U_CHAR *,
...@@ -77,14 +76,6 @@ _cpp_grow_token_buffer (pfile, n) ...@@ -77,14 +76,6 @@ _cpp_grow_token_buffer (pfile, n)
CPP_SET_WRITTEN (pfile, old_written); CPP_SET_WRITTEN (pfile, old_written);
} }
static int
null_cleanup (pbuf, pfile)
cpp_buffer *pbuf ATTRIBUTE_UNUSED;
cpp_reader *pfile ATTRIBUTE_UNUSED;
{
return 0;
}
/* Allocate a new cpp_buffer for PFILE, and push it on the input buffer stack. /* Allocate a new cpp_buffer for PFILE, and push it on the input buffer stack.
If BUFFER != NULL, then use the LENGTH characters in BUFFER If BUFFER != NULL, then use the LENGTH characters in BUFFER
as the new input buffer. as the new input buffer.
...@@ -107,7 +98,6 @@ cpp_push_buffer (pfile, buffer, length) ...@@ -107,7 +98,6 @@ cpp_push_buffer (pfile, buffer, length)
new = (cpp_buffer *) xcalloc (1, sizeof (cpp_buffer)); new = (cpp_buffer *) xcalloc (1, sizeof (cpp_buffer));
new->if_stack = pfile->if_stack; new->if_stack = pfile->if_stack;
new->cleanup = null_cleanup;
new->buf = new->cur = buffer; new->buf = new->cur = buffer;
new->rlimit = buffer + length; new->rlimit = buffer + length;
new->prev = buf; new->prev = buf;
...@@ -125,7 +115,32 @@ cpp_pop_buffer (pfile) ...@@ -125,7 +115,32 @@ cpp_pop_buffer (pfile)
cpp_buffer *buf = CPP_BUFFER (pfile); cpp_buffer *buf = CPP_BUFFER (pfile);
if (ACTIVE_MARK_P (pfile)) if (ACTIVE_MARK_P (pfile))
cpp_ice (pfile, "mark active in cpp_pop_buffer"); cpp_ice (pfile, "mark active in cpp_pop_buffer");
(*buf->cleanup) (buf, pfile);
if (buf->ihash)
{
_cpp_unwind_if_stack (pfile, buf);
if (buf->buf)
free ((PTR) buf->buf);
if (pfile->system_include_depth)
pfile->system_include_depth--;
if (pfile->potential_control_macro)
{
buf->ihash->control_macro = pfile->potential_control_macro;
pfile->potential_control_macro = 0;
}
pfile->input_stack_listing_current = 0;
}
else if (buf->macro)
{
HASHNODE *m = buf->macro;
m->disabled = 0;
if ((m->type == T_FMACRO && buf->mapped)
|| m->type == T_SPECLINE || m->type == T_FILE
|| m->type == T_BASE_FILE || m->type == T_INCLUDE_LEVEL
|| m->type == T_STDC)
free ((PTR) buf->buf);
}
CPP_BUFFER (pfile) = CPP_PREV_BUFFER (buf); CPP_BUFFER (pfile) = CPP_PREV_BUFFER (buf);
free (buf); free (buf);
pfile->buffer_stack_depth--; pfile->buffer_stack_depth--;
...@@ -321,7 +336,7 @@ _cpp_expand_to_buffer (pfile, buf, length) ...@@ -321,7 +336,7 @@ _cpp_expand_to_buffer (pfile, buf, length)
const U_CHAR *buf; const U_CHAR *buf;
int length; int length;
{ {
cpp_buffer *ip; cpp_buffer *stop;
enum cpp_ttype token; enum cpp_ttype token;
U_CHAR *buf1; U_CHAR *buf1;
...@@ -338,33 +353,27 @@ _cpp_expand_to_buffer (pfile, buf, length) ...@@ -338,33 +353,27 @@ _cpp_expand_to_buffer (pfile, buf, length)
memcpy (buf1, buf, length); memcpy (buf1, buf, length);
/* Set up the input on the input stack. */ /* Set up the input on the input stack. */
ip = cpp_push_buffer (pfile, buf1, length); stop = CPP_BUFFER (pfile);
if (ip == NULL) if (cpp_push_buffer (pfile, buf1, length) == NULL)
return; return;
ip->has_escapes = 1; CPP_BUFFER (pfile)->has_escapes = 1;
/* Scan the input, create the output. */ /* Scan the input, create the output. */
for (;;) for (;;)
{ {
token = cpp_get_token (pfile); token = cpp_get_token (pfile);
if (token == CPP_EOF) if (token == CPP_EOF && CPP_BUFFER (pfile) == stop)
break; break;
if (token == CPP_POP && CPP_BUFFER (pfile) == ip)
{
cpp_pop_buffer (pfile);
break;
}
} }
} }
/* Scan until CPP_BUFFER (PFILE) is exhausted, discarding output. /* Scan until CPP_BUFFER (PFILE) is exhausted, discarding output. */
Then pop the buffer. */
void void
cpp_scan_buffer_nooutput (pfile) cpp_scan_buffer_nooutput (pfile)
cpp_reader *pfile; cpp_reader *pfile;
{ {
cpp_buffer *buffer = CPP_BUFFER (pfile); cpp_buffer *stop = CPP_PREV_BUFFER (CPP_BUFFER (pfile));
enum cpp_ttype token; enum cpp_ttype token;
unsigned int old_written = CPP_WRITTEN (pfile); unsigned int old_written = CPP_WRITTEN (pfile);
/* In no-output mode, we can ignore everything but directives. */ /* In no-output mode, we can ignore everything but directives. */
...@@ -373,45 +382,33 @@ cpp_scan_buffer_nooutput (pfile) ...@@ -373,45 +382,33 @@ cpp_scan_buffer_nooutput (pfile)
if (! pfile->only_seen_white) if (! pfile->only_seen_white)
_cpp_skip_rest_of_line (pfile); _cpp_skip_rest_of_line (pfile);
token = cpp_get_token (pfile); token = cpp_get_token (pfile);
if (token == CPP_EOF) if (token == CPP_EOF && CPP_BUFFER (pfile) == stop)
break; break;
if (token == CPP_POP && CPP_BUFFER (pfile) == buffer)
{
cpp_pop_buffer (pfile);
break;
}
} }
CPP_SET_WRITTEN (pfile, old_written); CPP_SET_WRITTEN (pfile, old_written);
} }
/* Scan until CPP_BUFFER (pfile) is exhausted, writing output to PRINT. /* Scan until CPP_BUFFER (pfile) is exhausted, writing output to PRINT. */
Then pop the buffer. */
void void
cpp_scan_buffer (pfile, print) cpp_scan_buffer (pfile, print)
cpp_reader *pfile; cpp_reader *pfile;
cpp_printer *print; cpp_printer *print;
{ {
cpp_buffer *buffer = CPP_BUFFER (pfile); cpp_buffer *stop = CPP_PREV_BUFFER (CPP_BUFFER (pfile));
enum cpp_ttype token; enum cpp_ttype token;
for (;;) for (;;)
{ {
token = cpp_get_token (pfile); token = cpp_get_token (pfile);
if ((token == CPP_POP && !CPP_IS_MACRO_BUFFER (CPP_BUFFER (pfile))) if (token == CPP_EOF || token == CPP_VSPACE
|| token == CPP_EOF || token == CPP_VSPACE
/* XXX Temporary kluge - force flush after #include only */ /* XXX Temporary kluge - force flush after #include only */
|| (token == CPP_DIRECTIVE || (token == CPP_DIRECTIVE
&& CPP_BUFFER (pfile)->nominal_fname != print->last_fname)) && CPP_BUFFER (pfile)->nominal_fname != print->last_fname))
{ {
cpp_output_tokens (pfile, print); cpp_output_tokens (pfile, print);
if (token == CPP_EOF) if (token == CPP_EOF && CPP_BUFFER (pfile) == stop)
return; return;
if (token == CPP_POP && CPP_BUFFER (pfile) == buffer)
{
cpp_pop_buffer (pfile);
return;
}
} }
} }
} }
...@@ -1611,21 +1608,13 @@ cpp_get_token (pfile) ...@@ -1611,21 +1608,13 @@ cpp_get_token (pfile)
case CPP_EOF: case CPP_EOF:
if (CPP_BUFFER (pfile) == NULL) if (CPP_BUFFER (pfile) == NULL)
return CPP_EOF; return CPP_EOF;
if (CPP_BUFFER (pfile)->manual_pop) if (CPP_IS_MACRO_BUFFER (CPP_BUFFER (pfile)))
/* If we've been reading from redirected input, the
frontend will pop the buffer. */
return CPP_EOF;
if (CPP_BUFFER (pfile)->seen_eof)
{ {
cpp_pop_buffer (pfile); cpp_pop_buffer (pfile);
goto get_next; goto get_next;
} }
else cpp_pop_buffer (pfile);
{ return CPP_EOF;
_cpp_handle_eof (pfile);
return CPP_POP;
}
} }
} }
...@@ -1646,8 +1635,7 @@ cpp_get_non_space_token (pfile) ...@@ -1646,8 +1635,7 @@ cpp_get_non_space_token (pfile)
} }
/* Like cpp_get_token, except that it does not execute directives, /* Like cpp_get_token, except that it does not execute directives,
does not consume vertical space, discards horizontal space, and does not consume vertical space, and discards horizontal space. */
automatically pops off macro buffers. */
enum cpp_ttype enum cpp_ttype
_cpp_get_directive_token (pfile) _cpp_get_directive_token (pfile)
cpp_reader *pfile; cpp_reader *pfile;
......
...@@ -215,8 +215,8 @@ _cpp_handle_directive (pfile) ...@@ -215,8 +215,8 @@ _cpp_handle_directive (pfile)
return 0; return 0;
if (CPP_PEDANTIC (pfile) if (CPP_PEDANTIC (pfile)
&& ! CPP_OPTION (pfile, preprocessed) && CPP_BUFFER (pfile)->ihash
&& ! CPP_BUFFER (pfile)->manual_pop) && ! CPP_OPTION (pfile, preprocessed))
cpp_pedwarn (pfile, "# followed by integer"); cpp_pedwarn (pfile, "# followed by integer");
do_line (pfile); do_line (pfile);
return 1; return 1;
...@@ -1345,14 +1345,17 @@ skip_if_group (pfile) ...@@ -1345,14 +1345,17 @@ skip_if_group (pfile)
pfile->no_macro_expand++; pfile->no_macro_expand++;
for (;;) for (;;)
{ {
/* We are at the end of a line. Only cpp_get_token knows how to /* We are at the end of a line.
advance the line number correctly. */ XXX Serious layering violation here. */
token = cpp_get_token (pfile); int c = CPP_BUF_PEEK (CPP_BUFFER (pfile));
if (token == CPP_POP) if (c == EOF)
break; /* Caller will issue error. */ break; /* Caller will issue error. */
else if (token != CPP_VSPACE) else if (c != '\n')
cpp_ice (pfile, "cpp_get_token returned %d in skip_if_group", token); cpp_ice (pfile, "character %c at end of line in skip_if_group", c);
CPP_BUFFER (pfile)->cur++;
CPP_BUMP_LINE (pfile);
CPP_SET_WRITTEN (pfile, old_written); CPP_SET_WRITTEN (pfile, old_written);
pfile->only_seen_white = 1;
token = _cpp_get_directive_token (pfile); token = _cpp_get_directive_token (pfile);
...@@ -1458,15 +1461,18 @@ validate_else (pfile, directive) ...@@ -1458,15 +1461,18 @@ validate_else (pfile, directive)
pfile->no_macro_expand--; pfile->no_macro_expand--;
} }
/* Called when we reach the end of a macro buffer. Walk back up the
conditional stack till we reach its level at entry to this file,
issuing error messages. */
void void
_cpp_handle_eof (pfile) _cpp_unwind_if_stack (pfile, pbuf)
cpp_reader *pfile; cpp_reader *pfile;
cpp_buffer *pbuf;
{ {
struct if_stack *ifs, *nifs; struct if_stack *ifs, *nifs;
/* Unwind the conditional stack and generate error messages. */
for (ifs = pfile->if_stack; for (ifs = pfile->if_stack;
ifs != CPP_BUFFER (pfile)->if_stack; ifs != pbuf->if_stack;
ifs = nifs) ifs = nifs)
{ {
cpp_error_with_line (pfile, ifs->lineno, 0, cpp_error_with_line (pfile, ifs->lineno, 0,
...@@ -1477,7 +1483,6 @@ _cpp_handle_eof (pfile) ...@@ -1477,7 +1483,6 @@ _cpp_handle_eof (pfile)
free (ifs); free (ifs);
} }
pfile->if_stack = ifs; pfile->if_stack = ifs;
CPP_BUFFER (pfile)->seen_eof = 1;
} }
static int static int
...@@ -1658,7 +1663,7 @@ cpp_undef (pfile, macro) ...@@ -1658,7 +1663,7 @@ cpp_undef (pfile, macro)
memcpy (buf, macro, len); memcpy (buf, macro, len);
buf[len] = '\n'; buf[len] = '\n';
buf[len + 1] = '\0'; buf[len + 1] = '\0';
if (cpp_push_buffer (pfile, buf, len + 1)) if (cpp_push_buffer (pfile, buf, len + 1) != NULL)
{ {
do_undef (pfile); do_undef (pfile);
cpp_pop_buffer (pfile); cpp_pop_buffer (pfile);
......
...@@ -131,7 +131,6 @@ typedef struct cpp_name cpp_name; ...@@ -131,7 +131,6 @@ typedef struct cpp_name cpp_name;
/* Obsolete - will be removed when no code uses them still. */ \ /* Obsolete - will be removed when no code uses them still. */ \
H(CPP_COMMENT, 0) /* Only if output comments. */ \ H(CPP_COMMENT, 0) /* Only if output comments. */ \
N(CPP_HSPACE, 0) /* Horizontal white space. */ \ N(CPP_HSPACE, 0) /* Horizontal white space. */ \
N(CPP_POP, 0) /* End of buffer. */ \
N(CPP_DIRECTIVE, 0) /* #define and the like */ \ N(CPP_DIRECTIVE, 0) /* #define and the like */ \
N(CPP_MACRO, 0) /* Like a NAME, but expanded. */ N(CPP_MACRO, 0) /* Like a NAME, but expanded. */
...@@ -192,7 +191,6 @@ struct cpp_token ...@@ -192,7 +191,6 @@ struct cpp_token
#define SYNTAX_ASSERT (1 << 9) #define SYNTAX_ASSERT (1 << 9)
typedef int (*directive_handler) PARAMS ((cpp_reader *)); typedef int (*directive_handler) PARAMS ((cpp_reader *));
typedef int (*parse_cleanup_t) PARAMS ((cpp_buffer *, cpp_reader *));
struct cpp_toklist struct cpp_toklist
{ {
...@@ -238,8 +236,6 @@ struct cpp_buffer ...@@ -238,8 +236,6 @@ struct cpp_buffer
to record control macros. */ to record control macros. */
struct ihash *ihash; struct ihash *ihash;
parse_cleanup_t cleanup;
/* If the buffer is the expansion of a macro, this points to the /* If the buffer is the expansion of a macro, this points to the
macro's hash table entry. */ macro's hash table entry. */
struct hashnode *macro; struct hashnode *macro;
...@@ -254,9 +250,6 @@ struct cpp_buffer ...@@ -254,9 +250,6 @@ struct cpp_buffer
/* True if this is a header file included using <FILENAME>. */ /* True if this is a header file included using <FILENAME>. */
char system_header_p; char system_header_p;
/* True if end-of-file has already been hit once in this buffer. */
char seen_eof;
/* True if buffer contains escape sequences. /* True if buffer contains escape sequences.
Currently there are two kinds: Currently there are two kinds:
"\r-" means following identifier should not be macro-expanded. "\r-" means following identifier should not be macro-expanded.
...@@ -271,17 +264,15 @@ struct cpp_buffer ...@@ -271,17 +264,15 @@ struct cpp_buffer
from macro expansion text in collect_expansion and/or macarg. */ from macro expansion text in collect_expansion and/or macarg. */
char has_escapes; char has_escapes;
/* Used by the C++ frontend to implement redirected input (such as for
default argument and/or template parsing). */
char manual_pop;
/* True if we have already warned about C++ comments in this file. /* True if we have already warned about C++ comments in this file.
The warning happens only for C89 extended mode with -pedantic on, The warning happens only for C89 extended mode with -pedantic on,
or for -Wtraditional, and only once per file (otherwise it would or for -Wtraditional, and only once per file (otherwise it would
be far too noisy). */ be far too noisy). */
char warned_cplusplus_comments; char warned_cplusplus_comments;
/* True if this buffer's data is mmapped. */ /* In a file buffer, true if this buffer's data is mmapped
(currently never the case). In a macro buffer, true if this
buffer's data must be freed. */
char mapped; char mapped;
}; };
......
...@@ -658,10 +658,12 @@ read_scan_file (in_fname, argc, argv) ...@@ -658,10 +658,12 @@ read_scan_file (in_fname, argc, argv)
&& (fn = lookup_std_proto ("_filbuf", 7)) != NULL) && (fn = lookup_std_proto ("_filbuf", 7)) != NULL)
{ {
static char getchar_call[] = "getchar();"; static char getchar_call[] = "getchar();";
cpp_buffer *buf
= cpp_push_buffer (&scan_in, getchar_call, sizeof(getchar_call) - 1);
int old_written = CPP_WRITTEN (&scan_in); int old_written = CPP_WRITTEN (&scan_in);
int seen_filbuf = 0; int seen_filbuf = 0;
cpp_buffer *buf = CPP_BUFFER (&scan_in);
if (cpp_push_buffer (&scan_in, getchar_call,
sizeof(getchar_call) - 1) == NULL)
return;
/* Scan the macro expansion of "getchar();". */ /* Scan the macro expansion of "getchar();". */
for (;;) for (;;)
...@@ -671,13 +673,8 @@ read_scan_file (in_fname, argc, argv) ...@@ -671,13 +673,8 @@ read_scan_file (in_fname, argc, argv)
unsigned char *id = scan_in.token_buffer + old_written; unsigned char *id = scan_in.token_buffer + old_written;
CPP_SET_WRITTEN (&scan_in, old_written); CPP_SET_WRITTEN (&scan_in, old_written);
if (token == CPP_EOF) /* Should not happen ... */ if (token == CPP_EOF && CPP_BUFFER (&scan_in) == buf)
break; break;
if (token == CPP_POP && CPP_BUFFER (&scan_in) == buf)
{
cpp_pop_buffer (&scan_in);
break;
}
if (token == CPP_NAME && cpp_idcmp (id, length, "_filbuf") == 0) if (token == CPP_NAME && cpp_idcmp (id, length, "_filbuf") == 0)
seen_filbuf++; seen_filbuf++;
} }
......
...@@ -116,7 +116,12 @@ scan_decls (pfile, argc, argv) ...@@ -116,7 +116,12 @@ scan_decls (pfile, argc, argv)
goto new_statement; goto new_statement;
} }
if (token == CPP_EOF) if (token == CPP_EOF)
return 0; {
if (CPP_BUFFER (pfile) == NULL)
return 0;
else
goto new_statement;
}
if (token == CPP_SEMICOLON) if (token == CPP_SEMICOLON)
goto new_statement; goto new_statement;
if (token != CPP_NAME) if (token != CPP_NAME)
...@@ -235,13 +240,15 @@ scan_decls (pfile, argc, argv) ...@@ -235,13 +240,15 @@ scan_decls (pfile, argc, argv)
prev_id_end = CPP_WRITTEN (pfile); prev_id_end = CPP_WRITTEN (pfile);
break; break;
case CPP_EOF:
return 0;
case CPP_OPEN_BRACE: case CPP_CLOSE_BRACE: case CPP_DIRECTIVE: case CPP_OPEN_BRACE: case CPP_CLOSE_BRACE: case CPP_DIRECTIVE:
goto new_statement; /* handle_statement? */ goto new_statement; /* handle_statement? */
case CPP_HSPACE: case CPP_VSPACE: case CPP_COMMENT: case CPP_POP: case CPP_EOF:
if (CPP_BUFFER (pfile) == NULL)
return 0;
/* else fall through */
case CPP_HSPACE: case CPP_VSPACE: case CPP_COMMENT:
/* Skip initial white space. */ /* Skip initial white space. */
if (start_written == 0) if (start_written == 0)
CPP_SET_WRITTEN (pfile, 0); CPP_SET_WRITTEN (pfile, 0);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment