Commit 29401c30 by Neil Booth Committed by Neil Booth

cpperror.c (print_location): Don't show _Pragma.

	* cpperror.c (print_location): Don't show _Pragma.
	* cppfiles.c (_cpp_pop_file_buffer): Handle -include file pushing
	and file change callback generation here.
	(stack_include_file): Update use of cpp_push_buffer.
	* cpphash.h (_cpp_pop_file_buffer): Update prototype.
	(struct cpp_buffer): Remove type, pfile members.
	* cppinit.c (cpp_handle_option): Use free_chain.
	* cpplex.c (_cpp_lex_token): Don't do -include file pushing here.
	(skip_escaped_newlines, get_effective_char, lex_percent): Take
	a cpp_reader rather than a cpp_buffer.
	(skip_escaped_newlines, get_effective_char, skip_block_comment,
	skip_line_comment, parse_string, lex_percent, lex_dot,
	_cpp_lex_token): Update accordingly.
	* cpplib.c (_cpp_pop_buffer): Don't do file change callback
	generation here.
	(cpp_push_buffer): Update prototype.
	(run_directive): Update use of cpp_push_buffer.
	(_cpp_do__Pragma, cpp_define, cpp_define_builtin, cpp_undef,
	handle_assertion): Update use of run_directive.
	* cpplib.h (enum cpp_buffer_type): Remove.
	(cpp_push_buffer): Update prototype.
	* fix-header.c (read_scan_file): Update.

From-SVN: r45112
parent 8060c8ee
2001-08-22 Neil Booth <neil@daikokuya.demon.co.uk>
* cpperror.c (print_location): Don't show _Pragma.
* cppfiles.c (_cpp_pop_file_buffer): Handle -include file pushing
and file change callback generation here.
(stack_include_file): Update use of cpp_push_buffer.
* cpphash.h (_cpp_pop_file_buffer): Update prototype.
(struct cpp_buffer): Remove type, pfile members.
* cppinit.c (cpp_handle_option): Use free_chain.
* cpplex.c (_cpp_lex_token): Don't do -include file pushing here.
(skip_escaped_newlines, get_effective_char, lex_percent): Take
a cpp_reader rather than a cpp_buffer.
(skip_escaped_newlines, get_effective_char, skip_block_comment,
skip_line_comment, parse_string, lex_percent, lex_dot,
_cpp_lex_token): Update accordingly.
* cpplib.c (_cpp_pop_buffer): Don't do file change callback
generation here.
(cpp_push_buffer): Update prototype.
(run_directive): Update use of cpp_push_buffer.
(_cpp_do__Pragma, cpp_define, cpp_define_builtin, cpp_undef,
handle_assertion): Update use of run_directive.
* cpplib.h (enum cpp_buffer_type): Remove.
(cpp_push_buffer): Update prototype.
* fix-header.c (read_scan_file): Update.
2001-08-22 Matt Kraai <kraai@alumni.carnegiemellon.edu> 2001-08-22 Matt Kraai <kraai@alumni.carnegiemellon.edu>
* gcc.c (struct prefix_list): Change prefix to const char *. * gcc.c (struct prefix_list): Change prefix to const char *.
......
...@@ -69,8 +69,6 @@ print_location (pfile, pos) ...@@ -69,8 +69,6 @@ print_location (pfile, pos)
else else
fprintf (stderr, "%s:%u:%u:", map->to_file, line, col); fprintf (stderr, "%s:%u:%u:", map->to_file, line, col);
if (buffer->type == BUF_PRAGMA)
fprintf (stderr, "_Pragma:");
fputc (' ', stderr); fputc (' ', stderr);
} }
} }
......
...@@ -317,7 +317,8 @@ stack_include_file (pfile, inc) ...@@ -317,7 +317,8 @@ stack_include_file (pfile, inc)
inc->include_count++; inc->include_count++;
/* Push a buffer. */ /* Push a buffer. */
fp = cpp_push_buffer (pfile, inc->buffer, inc->st.st_size, BUF_FILE, 0); fp = cpp_push_buffer (pfile, inc->buffer, inc->st.st_size,
/* from_stage3 */ CPP_OPTION (pfile, preprocessed), 0);
fp->inc = inc; fp->inc = inc;
fp->inc->refcnt++; fp->inc->refcnt++;
...@@ -720,14 +721,12 @@ _cpp_read_file (pfile, fname) ...@@ -720,14 +721,12 @@ _cpp_read_file (pfile, fname)
} }
/* Do appropriate cleanup when a file buffer is popped off the input /* Do appropriate cleanup when a file buffer is popped off the input
stack. */ stack. Push the next -include file, if any remain. */
void void
_cpp_pop_file_buffer (pfile, buf) _cpp_pop_file_buffer (pfile, inc)
cpp_reader *pfile; cpp_reader *pfile;
cpp_buffer *buf; struct include_file *inc;
{ {
struct include_file *inc = buf->inc;
/* Record the inclusion-preventing macro, which could be NULL /* Record the inclusion-preventing macro, which could be NULL
meaning no controlling macro. */ meaning no controlling macro. */
if (pfile->mi_valid && inc->cmacro == NULL) if (pfile->mi_valid && inc->cmacro == NULL)
...@@ -739,6 +738,16 @@ _cpp_pop_file_buffer (pfile, buf) ...@@ -739,6 +738,16 @@ _cpp_pop_file_buffer (pfile, buf)
inc->refcnt--; inc->refcnt--;
if (inc->refcnt == 0 && DO_NOT_REREAD (inc)) if (inc->refcnt == 0 && DO_NOT_REREAD (inc))
purge_cache (inc); purge_cache (inc);
/* Don't generate a callback for popping the main file. */
if (pfile->buffer)
{
_cpp_do_file_change (pfile, LC_LEAVE, 0, 0, 0);
/* Finally, push the next -included file, if any. */
if (!pfile->buffer->prev)
_cpp_push_next_buffer (pfile);
}
} }
/* Returns the first place in the include chain to start searching for /* Returns the first place in the include chain to start searching for
...@@ -772,8 +781,7 @@ search_from (pfile, type) ...@@ -772,8 +781,7 @@ search_from (pfile, type)
if (dlen) if (dlen)
{ {
/* We don't guarantee NAME is null-terminated. This saves /* We don't guarantee NAME is null-terminated. This saves
allocating and freeing memory, and duplicating it when faking allocating and freeing memory. Drop a trailing '/'. */
buffers in cpp_push_buffer. Drop a trailing '/'. */
buffer->dir.name = buffer->inc->name; buffer->dir.name = buffer->inc->name;
if (dlen > 1) if (dlen > 1)
dlen--; dlen--;
......
...@@ -171,13 +171,12 @@ struct cpp_buffer ...@@ -171,13 +171,12 @@ struct cpp_buffer
cppchar_t read_ahead; /* read ahead character */ cppchar_t read_ahead; /* read ahead character */
cppchar_t extra_char; /* extra read-ahead for long tokens. */ cppchar_t extra_char; /* extra read-ahead for long tokens. */
struct cpp_reader *pfile; /* Owns this buffer. */
struct cpp_buffer *prev; struct cpp_buffer *prev;
const unsigned char *buf; /* entire buffer */ const unsigned char *buf; /* Entire buffer. */
/* Pointer into the include table. Used for include_next and /* Pointer into the include table; non-NULL if this is a file
to record control macros. */ buffer. Used for include_next and to record control macros. */
struct include_file *inc; struct include_file *inc;
/* Value of if_stack at start of this file. /* Value of if_stack at start of this file.
...@@ -214,9 +213,6 @@ struct cpp_buffer ...@@ -214,9 +213,6 @@ struct cpp_buffer
token from the enclosing buffer is returned. */ token from the enclosing buffer is returned. */
bool return_at_eof; bool return_at_eof;
/* Buffer type. */
ENUM_BITFIELD (cpp_buffer_type) type : 8;
/* The directory of the this buffer's file. Its NAME member is not /* The directory of the this buffer's file. Its NAME member is not
allocated, so we don't need to worry about freeing it. */ allocated, so we don't need to worry about freeing it. */
struct search_path dir; struct search_path dir;
...@@ -391,7 +387,8 @@ extern int _cpp_compare_file_date PARAMS ((cpp_reader *, ...@@ -391,7 +387,8 @@ extern int _cpp_compare_file_date PARAMS ((cpp_reader *,
extern void _cpp_report_missing_guards PARAMS ((cpp_reader *)); extern void _cpp_report_missing_guards PARAMS ((cpp_reader *));
extern void _cpp_init_includes PARAMS ((cpp_reader *)); extern void _cpp_init_includes PARAMS ((cpp_reader *));
extern void _cpp_cleanup_includes PARAMS ((cpp_reader *)); extern void _cpp_cleanup_includes PARAMS ((cpp_reader *));
extern void _cpp_pop_file_buffer PARAMS ((cpp_reader *, cpp_buffer *)); extern void _cpp_pop_file_buffer PARAMS ((cpp_reader *,
struct include_file *));
/* In cppexp.c */ /* In cppexp.c */
extern int _cpp_parse_expr PARAMS ((cpp_reader *)); extern int _cpp_parse_expr PARAMS ((cpp_reader *));
......
...@@ -1546,15 +1546,7 @@ cpp_handle_option (pfile, argc, argv) ...@@ -1546,15 +1546,7 @@ cpp_handle_option (pfile, argc, argv)
if (arg[1] == '\0') if (arg[1] == '\0')
{ {
struct pending_option *o1, *o2; free_chain (pend->directive_head);
o1 = pend->directive_head;
while (o1)
{
o2 = o1->next;
free (o1);
o1 = o2;
}
pend->directive_head = NULL; pend->directive_head = NULL;
pend->directive_tail = NULL; pend->directive_tail = NULL;
} }
......
...@@ -83,7 +83,6 @@ static void check_eol PARAMS ((cpp_reader *)); ...@@ -83,7 +83,6 @@ static void check_eol PARAMS ((cpp_reader *));
static void start_directive PARAMS ((cpp_reader *)); static void start_directive PARAMS ((cpp_reader *));
static void end_directive PARAMS ((cpp_reader *, int)); static void end_directive PARAMS ((cpp_reader *, int));
static void run_directive PARAMS ((cpp_reader *, int, static void run_directive PARAMS ((cpp_reader *, int,
enum cpp_buffer_type,
const char *, size_t)); const char *, size_t));
static int glue_header_name PARAMS ((cpp_reader *, cpp_token *)); static int glue_header_name PARAMS ((cpp_reader *, cpp_token *));
static int parse_include PARAMS ((cpp_reader *, cpp_token *)); static int parse_include PARAMS ((cpp_reader *, cpp_token *));
...@@ -394,16 +393,14 @@ _cpp_handle_directive (pfile, indented) ...@@ -394,16 +393,14 @@ _cpp_handle_directive (pfile, indented)
/* Directive handler wrapper used by the command line option /* Directive handler wrapper used by the command line option
processor. */ processor. */
static void static void
run_directive (pfile, dir_no, type, buf, count) run_directive (pfile, dir_no, buf, count)
cpp_reader *pfile; cpp_reader *pfile;
int dir_no; int dir_no;
enum cpp_buffer_type type;
const char *buf; const char *buf;
size_t count; size_t count;
{ {
cpp_buffer *buffer; cpp_push_buffer (pfile, (const U_CHAR *) buf, count,
/* from_stage3 */ true, 1);
buffer = cpp_push_buffer (pfile, (const U_CHAR *) buf, count, type, 1);
start_directive (pfile); start_directive (pfile);
pfile->state.prevent_expansion++; pfile->state.prevent_expansion++;
pfile->directive = &dtable[dir_no]; pfile->directive = &dtable[dir_no];
...@@ -1160,7 +1157,7 @@ _cpp_do__Pragma (pfile) ...@@ -1160,7 +1157,7 @@ _cpp_do__Pragma (pfile)
else else
{ {
buffer = destringize (&string.val.str, &len); buffer = destringize (&string.val.str, &len);
run_directive (pfile, T_PRAGMA, BUF_PRAGMA, (char *) buffer, len); run_directive (pfile, T_PRAGMA, (char *) buffer, len);
free ((PTR) buffer); free ((PTR) buffer);
pfile->lexer_pos = orig_pos; pfile->lexer_pos = orig_pos;
pfile->line = pfile->lexer_pos.line; pfile->line = pfile->lexer_pos.line;
...@@ -1627,7 +1624,7 @@ cpp_define (pfile, str) ...@@ -1627,7 +1624,7 @@ cpp_define (pfile, str)
buf[count++] = '1'; buf[count++] = '1';
} }
run_directive (pfile, T_DEFINE, BUF_CL_OPTION, buf, count); run_directive (pfile, T_DEFINE, buf, count);
} }
/* Slight variant of the above for use by initialize_builtins. */ /* Slight variant of the above for use by initialize_builtins. */
...@@ -1636,7 +1633,7 @@ _cpp_define_builtin (pfile, str) ...@@ -1636,7 +1633,7 @@ _cpp_define_builtin (pfile, str)
cpp_reader *pfile; cpp_reader *pfile;
const char *str; const char *str;
{ {
run_directive (pfile, T_DEFINE, BUF_BUILTIN, str, strlen (str)); run_directive (pfile, T_DEFINE, str, strlen (str));
} }
/* Process MACRO as if it appeared as the body of an #undef. */ /* Process MACRO as if it appeared as the body of an #undef. */
...@@ -1645,7 +1642,7 @@ cpp_undef (pfile, macro) ...@@ -1645,7 +1642,7 @@ cpp_undef (pfile, macro)
cpp_reader *pfile; cpp_reader *pfile;
const char *macro; const char *macro;
{ {
run_directive (pfile, T_UNDEF, BUF_CL_OPTION, macro, strlen (macro)); run_directive (pfile, T_UNDEF, macro, strlen (macro));
} }
/* Process the string STR as if it appeared as the body of a #assert. */ /* Process the string STR as if it appeared as the body of a #assert. */
...@@ -1688,7 +1685,7 @@ handle_assertion (pfile, str, type) ...@@ -1688,7 +1685,7 @@ handle_assertion (pfile, str, type)
str = buf; str = buf;
} }
run_directive (pfile, type, BUF_CL_OPTION, str, count); run_directive (pfile, type, str, count);
} }
/* The number of errors for a given reader. */ /* The number of errors for a given reader. */
...@@ -1736,11 +1733,11 @@ cpp_set_callbacks (pfile, cb) ...@@ -1736,11 +1733,11 @@ cpp_set_callbacks (pfile, cb)
doesn't fail. It does not generate a file change call back; that doesn't fail. It does not generate a file change call back; that
is the responsibility of the caller. */ is the responsibility of the caller. */
cpp_buffer * cpp_buffer *
cpp_push_buffer (pfile, buffer, len, type, return_at_eof) cpp_push_buffer (pfile, buffer, len, from_stage3, return_at_eof)
cpp_reader *pfile; cpp_reader *pfile;
const U_CHAR *buffer; const U_CHAR *buffer;
size_t len; size_t len;
enum cpp_buffer_type type; int from_stage3;
int return_at_eof; int return_at_eof;
{ {
cpp_buffer *new = xobnew (&pfile->buffer_ob, cpp_buffer); cpp_buffer *new = xobnew (&pfile->buffer_ob, cpp_buffer);
...@@ -1754,14 +1751,8 @@ cpp_push_buffer (pfile, buffer, len, type, return_at_eof) ...@@ -1754,14 +1751,8 @@ cpp_push_buffer (pfile, buffer, len, type, return_at_eof)
/* No read ahead or extra char initially. */ /* No read ahead or extra char initially. */
new->read_ahead = EOF; new->read_ahead = EOF;
new->extra_char = EOF; new->extra_char = EOF;
new->from_stage3 = from_stage3;
/* Preprocessed files, builtins, _Pragma and command line
options don't do trigraph and escaped newline processing. */
new->from_stage3 = type != BUF_FILE || CPP_OPTION (pfile, preprocessed);
new->type = type;
new->prev = pfile->buffer; new->prev = pfile->buffer;
new->pfile = pfile;
new->return_at_eof = return_at_eof; new->return_at_eof = return_at_eof;
pfile->buffer = new; pfile->buffer = new;
...@@ -1785,26 +1776,20 @@ _cpp_pop_buffer (pfile) ...@@ -1785,26 +1776,20 @@ _cpp_pop_buffer (pfile)
cpp_error_with_line (pfile, ifs->pos.line, ifs->pos.col, cpp_error_with_line (pfile, ifs->pos.line, ifs->pos.col,
"unterminated #%s", dtable[ifs->type].name); "unterminated #%s", dtable[ifs->type].name);
/* Update the reader's buffer before _cpp_do_file_change. */
pfile->buffer = buffer->prev;
if (buffer->type == BUF_FILE)
{
/* Callbacks are not generated for popping the main file. */
if (buffer->prev)
_cpp_do_file_change (pfile, LC_LEAVE, 0, 0, 0);
_cpp_pop_file_buffer (pfile, buffer);
}
obstack_free (&pfile->buffer_ob, buffer);
/* The output line can fall out of sync if we missed the final /* The output line can fall out of sync if we missed the final
newline from the previous buffer, for example because of an newline from the previous buffer, for example because of an
unterminated comment. Similarly, skipping needs to be cleared in unterminated comment. Similarly, skipping needs to be cleared in
case of a missing #endif. */ case of a missing #endif. */
pfile->lexer_pos.output_line = pfile->line; pfile->lexer_pos.output_line = pfile->line;
pfile->state.skipping = 0; pfile->state.skipping = 0;
/* Update the reader's buffer before _cpp_do_file_change. */
pfile->buffer = buffer->prev;
if (buffer->inc)
_cpp_pop_file_buffer (pfile, buffer->inc);
obstack_free (&pfile->buffer_ob, buffer);
} }
void void
......
...@@ -405,10 +405,6 @@ struct cpp_callbacks ...@@ -405,10 +405,6 @@ struct cpp_callbacks
/* Name under which this program was invoked. */ /* Name under which this program was invoked. */
extern const char *progname; extern const char *progname;
/* Where does this buffer come from? A source file, a builtin macro,
a command-line option, or a _Pragma operator. */
enum cpp_buffer_type {BUF_FILE, BUF_BUILTIN, BUF_CL_OPTION, BUF_PRAGMA};
/* The structure of a node in the hash table. The hash table has /* The structure of a node in the hash table. The hash table has
entries for all identifiers: either macros defined by #define entries for all identifiers: either macros defined by #define
commands (type NT_MACRO), assertions created with #assert commands (type NT_MACRO), assertions created with #assert
...@@ -541,7 +537,7 @@ extern void cpp_unassert PARAMS ((cpp_reader *, const char *)); ...@@ -541,7 +537,7 @@ extern void cpp_unassert PARAMS ((cpp_reader *, const char *));
extern cpp_buffer *cpp_push_buffer PARAMS ((cpp_reader *, extern cpp_buffer *cpp_push_buffer PARAMS ((cpp_reader *,
const unsigned char *, size_t, const unsigned char *, size_t,
enum cpp_buffer_type, int)); int, int));
extern int cpp_defined PARAMS ((cpp_reader *, const unsigned char *, int)); extern int cpp_defined PARAMS ((cpp_reader *, const unsigned char *, int));
/* N.B. The error-message-printer prototypes have not been nicely /* N.B. The error-message-printer prototypes have not been nicely
......
...@@ -658,7 +658,7 @@ read_scan_file (in_fname, argc, argv) ...@@ -658,7 +658,7 @@ read_scan_file (in_fname, argc, argv)
/* Scan the macro expansion of "getchar();". */ /* Scan the macro expansion of "getchar();". */
cpp_push_buffer (scan_in, getchar_call, sizeof(getchar_call) - 1, cpp_push_buffer (scan_in, getchar_call, sizeof(getchar_call) - 1,
BUF_BUILTIN, 1); /* from_stage3 */ true, 1);
for (;;) for (;;)
{ {
cpp_token t; cpp_token t;
......
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