Commit eb1f4d9d by Neil Booth Committed by Neil Booth

c-lex.c: s/change_file/file_change.

        * c-lex.c: s/change_file/file_change.
        * cpplib.h: Similarly.
        * cppmain.c: Similarly.
        * fix-header.c: Similarly.
        * cppfiles.c (stack_include_file): Pass the buffer location and
        size to cpp_push_buffer.  Generate the file_change callback,
        so that sysp is already set.
        * cpphash.h: Add _cpp_do_file_change.
        * cpplib.c (do_line): Set buffer->sysp directly. Generate the
        file_change callback after setting sysp.
        (_cpp_do_file_change): Handle FC_ENTER and the FC_RENAME exception
        here.
        (cpp_push_buffer): Don't generate a callback.  Clear sysp.
        (cpp_pop_buffer): Clean up logic.

From-SVN: r38357
parent e2187d3b
2000-12-18 Neil Booth <neil@daikokuya.demon.co.uk>
* c-lex.c: s/change_file/file_change.
* cpplib.h: Similarly.
* cppmain.c: Similarly.
* fix-header.c: Similarly.
* cppfiles.c (stack_include_file): Pass the buffer location and
size to cpp_push_buffer. Generate the file_change callback,
so that sysp is already set.
* cpphash.h: Add _cpp_do_file_change.
* cpplib.c (do_line): Set buffer->sysp directly. Generate the
file_change callback after setting sysp.
(_cpp_do_file_change): Handle FC_ENTER and the FC_RENAME exception
here.
(cpp_push_buffer): Don't generate a callback. Clear sysp.
(cpp_pop_buffer): Clean up logic.
2000-12-18 Benjamin Kosnik <bkoz@redhat.com> 2000-12-18 Benjamin Kosnik <bkoz@redhat.com>
* configure.in (gcc_gxx_include_dir): Simplify. * configure.in (gcc_gxx_include_dir): Simplify.
......
...@@ -90,7 +90,7 @@ static tree lex_charconst PARAMS ((const char *, unsigned int, int)); ...@@ -90,7 +90,7 @@ static tree lex_charconst PARAMS ((const char *, unsigned int, int));
static void update_header_times PARAMS ((const char *)); static void update_header_times PARAMS ((const char *));
static int dump_one_header PARAMS ((splay_tree_node, void *)); static int dump_one_header PARAMS ((splay_tree_node, void *));
static void cb_ident PARAMS ((cpp_reader *, const cpp_string *)); static void cb_ident PARAMS ((cpp_reader *, const cpp_string *));
static void cb_change_file PARAMS ((cpp_reader *, const cpp_file_change *)); static void cb_file_change PARAMS ((cpp_reader *, const cpp_file_change *));
static void cb_def_pragma PARAMS ((cpp_reader *)); static void cb_def_pragma PARAMS ((cpp_reader *));
const char * const char *
...@@ -120,7 +120,7 @@ init_c_lex (filename) ...@@ -120,7 +120,7 @@ init_c_lex (filename)
#endif #endif
parse_in->cb.ident = cb_ident; parse_in->cb.ident = cb_ident;
parse_in->cb.change_file = cb_change_file; parse_in->cb.file_change = cb_file_change;
parse_in->cb.def_pragma = cb_def_pragma; parse_in->cb.def_pragma = cb_def_pragma;
if (filename == 0 || !strcmp (filename, "-")) if (filename == 0 || !strcmp (filename, "-"))
...@@ -226,7 +226,7 @@ cb_ident (pfile, str) ...@@ -226,7 +226,7 @@ cb_ident (pfile, str)
} }
static void static void
cb_change_file (pfile, fc) cb_file_change (pfile, fc)
cpp_reader *pfile ATTRIBUTE_UNUSED; cpp_reader *pfile ATTRIBUTE_UNUSED;
const cpp_file_change *fc; const cpp_file_change *fc;
{ {
......
...@@ -245,21 +245,19 @@ stack_include_file (pfile, inc) ...@@ -245,21 +245,19 @@ stack_include_file (pfile, inc)
cpp_reader *pfile; cpp_reader *pfile;
struct include_file *inc; struct include_file *inc;
{ {
size_t len = 0;
cpp_buffer *fp; cpp_buffer *fp;
/* Not in cache? */ /* Not in cache? */
if (! inc->buffer) if (! inc->buffer)
read_include_file (pfile, inc); read_include_file (pfile, inc);
/* Push a null buffer. */
fp = cpp_push_buffer (pfile, NULL, 0, BUF_FILE, inc->name);
fp->inc = inc;
fp->buf = inc->buffer;
fp->rlimit = fp->buf;
if (! DO_NOT_REREAD (inc)) if (! DO_NOT_REREAD (inc))
fp->rlimit += inc->st.st_size; len = inc->st.st_size;
fp->cur = fp->buf;
fp->line_base = fp->buf; /* Push a buffer. */
fp = cpp_push_buffer (pfile, inc->buffer, len, BUF_FILE, inc->name);
fp->inc = inc;
fp->inc->refcnt++; fp->inc->refcnt++;
if (inc->foundhere) if (inc->foundhere)
fp->sysp = inc->foundhere->sysp; fp->sysp = inc->foundhere->sysp;
...@@ -273,6 +271,11 @@ stack_include_file (pfile, inc) ...@@ -273,6 +271,11 @@ stack_include_file (pfile, inc)
pfile->mi_state = MI_OUTSIDE; pfile->mi_state = MI_OUTSIDE;
pfile->mi_cmacro = 0; pfile->mi_cmacro = 0;
pfile->include_depth++; pfile->include_depth++;
/* Generate the call back. */
fp->lineno = 0;
_cpp_do_file_change (pfile, FC_ENTER, 0, 0);
fp->lineno = 1;
} }
/* Read the file referenced by INC into the file cache. /* Read the file referenced by INC into the file cache.
......
...@@ -229,6 +229,8 @@ extern void _cpp_do__Pragma PARAMS ((cpp_reader *)); ...@@ -229,6 +229,8 @@ extern void _cpp_do__Pragma PARAMS ((cpp_reader *));
extern void _cpp_init_stacks PARAMS ((cpp_reader *)); extern void _cpp_init_stacks PARAMS ((cpp_reader *));
extern void _cpp_cleanup_stacks PARAMS ((cpp_reader *)); extern void _cpp_cleanup_stacks PARAMS ((cpp_reader *));
extern void _cpp_init_internal_pragmas PARAMS ((cpp_reader *)); extern void _cpp_init_internal_pragmas PARAMS ((cpp_reader *));
extern void _cpp_do_file_change PARAMS ((cpp_reader *, enum cpp_fc_reason,
const char *, unsigned int));
/* Utility routines and macros. */ /* Utility routines and macros. */
#define DSC(str) (const U_CHAR *)str, sizeof str - 1 #define DSC(str) (const U_CHAR *)str, sizeof str - 1
......
...@@ -108,8 +108,6 @@ static cpp_hashnode *parse_assertion PARAMS ((cpp_reader *, struct answer **, ...@@ -108,8 +108,6 @@ static cpp_hashnode *parse_assertion PARAMS ((cpp_reader *, struct answer **,
static struct answer ** find_answer PARAMS ((cpp_hashnode *, static struct answer ** find_answer PARAMS ((cpp_hashnode *,
const struct answer *)); const struct answer *));
static void handle_assertion PARAMS ((cpp_reader *, const char *, int)); static void handle_assertion PARAMS ((cpp_reader *, const char *, int));
static void do_file_change PARAMS ((cpp_reader *, enum cpp_fc_reason,
const char *, unsigned int));
/* This is the table of directive handlers. It is ordered by /* This is the table of directive handlers. It is ordered by
frequency of occurrence; the numbers at the end are directive frequency of occurrence; the numbers at the end are directive
...@@ -768,10 +766,8 @@ do_line (pfile) ...@@ -768,10 +766,8 @@ do_line (pfile)
buffer->nominal_fname); buffer->nominal_fname);
} }
} }
buffer->sysp = sysp;
cpp_make_system_header (pfile, sysp, sysp == 2);
} }
buffer->nominal_fname = fname; buffer->nominal_fname = fname;
} }
else if (token.type != CPP_EOF) else if (token.type != CPP_EOF)
...@@ -783,37 +779,47 @@ do_line (pfile) ...@@ -783,37 +779,47 @@ do_line (pfile)
/* Our line number is incremented after the directive is processed. */ /* Our line number is incremented after the directive is processed. */
buffer->lineno = new_lineno - 1; buffer->lineno = new_lineno - 1;
_cpp_do_file_change (pfile, reason, filename, lineno);
if (reason == FC_RENAME)
{
/* Special case for file "foo.i" with "# 1 foo.c" on first line. */
if (! buffer->prev && pfile->directive_pos.line == 1)
filename = 0;
do_file_change (pfile, reason, filename, lineno);
}
} }
/* Arrange the file_change callback. */ /* Arrange the file_change callback. */
static void void
do_file_change (pfile, reason, from_file, from_lineno) _cpp_do_file_change (pfile, reason, from_file, from_lineno)
cpp_reader *pfile; cpp_reader *pfile;
enum cpp_fc_reason reason; enum cpp_fc_reason reason;
const char *from_file; const char *from_file;
unsigned int from_lineno; unsigned int from_lineno;
{ {
if (pfile->cb.change_file) if (pfile->cb.file_change)
{ {
cpp_file_change fc; cpp_file_change fc;
cpp_buffer *buffer = pfile->buffer; cpp_buffer *buffer = pfile->buffer;
fc.reason = reason; fc.reason = reason;
fc.from.filename = from_file;
fc.from.lineno = from_lineno;
fc.to.filename = buffer->nominal_fname; fc.to.filename = buffer->nominal_fname;
fc.to.lineno = buffer->lineno + 1; fc.to.lineno = buffer->lineno + 1;
fc.sysp = buffer->sysp; fc.sysp = buffer->sysp;
fc.externc = CPP_OPTION (pfile, cplusplus) && buffer->sysp == 2; fc.externc = CPP_OPTION (pfile, cplusplus) && buffer->sysp == 2;
pfile->cb.change_file (pfile, &fc);
/* Caller doesn't need to handle FC_ENTER. */
if (reason == FC_ENTER)
{
if (buffer->prev)
{
from_file = buffer->prev->nominal_fname;
from_lineno = buffer->prev->lineno;
}
else
from_file = 0;
}
/* Special case for file "foo.i" with "# 1 foo.c" on first line. */
else if (reason == FC_RENAME && ! buffer->prev
&& pfile->directive_pos.line == 1)
from_file = 0;
fc.from.filename = from_file;
fc.from.lineno = from_lineno;
pfile->cb.file_change (pfile, &fc);
} }
} }
...@@ -1708,9 +1714,9 @@ handle_assertion (pfile, str, type) ...@@ -1708,9 +1714,9 @@ handle_assertion (pfile, str, type)
run_directive (pfile, type, BUF_CL_OPTION, str, count); run_directive (pfile, type, BUF_CL_OPTION, str, count);
} }
/* Push a new buffer on the buffer stack. Buffer can be NULL, but /* Push a new buffer on the buffer stack. Returns the new buffer; it
then LEN should be 0. Returns the new buffer; it doesn't fail. */ doesn't fail. It does not generate a file change call back; that
is the responsibility of the caller. */
cpp_buffer * cpp_buffer *
cpp_push_buffer (pfile, buffer, len, type, filename) cpp_push_buffer (pfile, buffer, len, type, filename)
cpp_reader *pfile; cpp_reader *pfile;
...@@ -1741,6 +1747,7 @@ cpp_push_buffer (pfile, buffer, len, type, filename) ...@@ -1741,6 +1747,7 @@ cpp_push_buffer (pfile, buffer, len, type, filename)
new->line_base = new->buf = new->cur = buffer; new->line_base = new->buf = new->cur = buffer;
new->rlimit = buffer + len; new->rlimit = buffer + len;
new->sysp = 0;
/* No read ahead or extra char initially. */ /* No read ahead or extra char initially. */
new->read_ahead = EOF; new->read_ahead = EOF;
...@@ -1758,38 +1765,26 @@ cpp_push_buffer (pfile, buffer, len, type, filename) ...@@ -1758,38 +1765,26 @@ cpp_push_buffer (pfile, buffer, len, type, filename)
new->prev = pfile->buffer; new->prev = pfile->buffer;
new->pfile = pfile; new->pfile = pfile;
new->include_stack_listed = 0; new->include_stack_listed = 0;
new->lineno = 1;
pfile->state.next_bol = 1; pfile->state.next_bol = 1;
pfile->buffer_stack_depth++; pfile->buffer_stack_depth++;
pfile->buffer = new; pfile->buffer = new;
if (type == BUF_FILE || type == BUF_FAKE)
{
const char *filename = 0;
unsigned int lineno = 0;
if (new->prev)
{
filename = new->prev->nominal_fname;
lineno = new->prev->lineno;
}
new->lineno = 0;
do_file_change (pfile, FC_ENTER, filename, lineno);
}
new->lineno = 1;
return new; return new;
} }
/* If called from do_line, pops a single buffer. Otherwise pops all
buffers until a real file is reached. Generates appropriate
call-backs. */
cpp_buffer * cpp_buffer *
cpp_pop_buffer (pfile) cpp_pop_buffer (pfile)
cpp_reader *pfile; cpp_reader *pfile;
{ {
cpp_buffer *buffer; cpp_buffer *buffer;
struct if_stack *ifs; struct if_stack *ifs;
int in_do_line = pfile->directive == &dtable[T_LINE];
do for (;;)
{ {
buffer = pfile->buffer; buffer = pfile->buffer;
/* Walk back up the conditional stack till we reach its level at /* Walk back up the conditional stack till we reach its level at
...@@ -1799,28 +1794,34 @@ cpp_pop_buffer (pfile) ...@@ -1799,28 +1794,34 @@ cpp_pop_buffer (pfile)
"unterminated #%s", dtable[ifs->type].name); "unterminated #%s", dtable[ifs->type].name);
if (buffer->type == BUF_FAKE) if (buffer->type == BUF_FAKE)
{ buffer->prev->cur = buffer->cur;
if (!in_do_line)
cpp_warning (pfile, "file \"%s\" entered but not left",
buffer->nominal_fname);
buffer->prev->cur = buffer->cur;
}
else if (buffer->type == BUF_FILE) else if (buffer->type == BUF_FILE)
_cpp_pop_file_buffer (pfile, buffer); _cpp_pop_file_buffer (pfile, buffer);
pfile->buffer = buffer->prev; pfile->buffer = buffer->prev;
pfile->buffer_stack_depth--; pfile->buffer_stack_depth--;
if ((buffer->type == BUF_FILE || buffer->type == BUF_FAKE) /* Callbacks only generated for faked or real files. */
&& pfile->buffer) if (buffer->type != BUF_FILE && buffer->type != BUF_FAKE)
{ break;
do_file_change (pfile, FC_LEAVE, buffer->nominal_fname,
buffer->lineno); /* No callback for EOF of last file. */
pfile->buffer->include_stack_listed = 0; if (!pfile->buffer)
} break;
/* do_line does its own call backs. */
pfile->buffer->include_stack_listed = 0;
if (pfile->directive == &dtable[T_LINE])
break;
_cpp_do_file_change (pfile, FC_LEAVE, buffer->nominal_fname,
buffer->lineno);
if (pfile->buffer->type == BUF_FILE)
break;
cpp_warning (pfile, "file \"%s\" entered but not left",
buffer->nominal_fname);
} }
while (pfile->buffer && pfile->buffer->type == BUF_FAKE && !in_do_line);
obstack_free (pfile->buffer_ob, buffer); obstack_free (pfile->buffer_ob, buffer);
return pfile->buffer; return pfile->buffer;
......
...@@ -590,7 +590,7 @@ struct cpp_reader ...@@ -590,7 +590,7 @@ struct cpp_reader
/* Call backs. */ /* Call backs. */
struct { struct {
void (*change_file) PARAMS ((cpp_reader *, const cpp_file_change *)); void (*file_change) PARAMS ((cpp_reader *, const cpp_file_change *));
void (*include) PARAMS ((cpp_reader *, const unsigned char *, void (*include) PARAMS ((cpp_reader *, const unsigned char *,
const cpp_token *)); const cpp_token *));
void (*define) PARAMS ((cpp_reader *, cpp_hashnode *)); void (*define) PARAMS ((cpp_reader *, cpp_hashnode *));
......
...@@ -57,7 +57,7 @@ static void cb_undef PARAMS ((cpp_reader *, cpp_hashnode *)); ...@@ -57,7 +57,7 @@ static void cb_undef PARAMS ((cpp_reader *, cpp_hashnode *));
static void cb_include PARAMS ((cpp_reader *, const unsigned char *, static void cb_include PARAMS ((cpp_reader *, const unsigned char *,
const cpp_token *)); const cpp_token *));
static void cb_ident PARAMS ((cpp_reader *, const cpp_string *)); static void cb_ident PARAMS ((cpp_reader *, const cpp_string *));
static void cb_change_file PARAMS ((cpp_reader *, const cpp_file_change *)); static void cb_file_change PARAMS ((cpp_reader *, const cpp_file_change *));
static void cb_def_pragma PARAMS ((cpp_reader *)); static void cb_def_pragma PARAMS ((cpp_reader *));
static void do_pragma_implementation PARAMS ((cpp_reader *)); static void do_pragma_implementation PARAMS ((cpp_reader *));
...@@ -154,7 +154,7 @@ setup_callbacks () ...@@ -154,7 +154,7 @@ setup_callbacks ()
pfile->cb.ident = cb_ident; pfile->cb.ident = cb_ident;
pfile->cb.def_pragma = cb_def_pragma; pfile->cb.def_pragma = cb_def_pragma;
if (! CPP_OPTION (pfile, no_line_commands)) if (! CPP_OPTION (pfile, no_line_commands))
pfile->cb.change_file = cb_change_file; pfile->cb.file_change = cb_file_change;
} }
if (CPP_OPTION (pfile, dump_includes)) if (CPP_OPTION (pfile, dump_includes))
...@@ -374,7 +374,7 @@ cb_include (pfile, dir, header) ...@@ -374,7 +374,7 @@ cb_include (pfile, dir, header)
} }
static void static void
cb_change_file (pfile, fc) cb_file_change (pfile, fc)
cpp_reader *pfile ATTRIBUTE_UNUSED; cpp_reader *pfile ATTRIBUTE_UNUSED;
const cpp_file_change *fc; const cpp_file_change *fc;
{ {
......
...@@ -199,7 +199,7 @@ static int inf_skip_spaces PARAMS ((int)); ...@@ -199,7 +199,7 @@ static int inf_skip_spaces PARAMS ((int));
static int inf_read_upto PARAMS ((sstring *, int)); static int inf_read_upto PARAMS ((sstring *, int));
static int inf_scan_ident PARAMS ((sstring *, int)); static int inf_scan_ident PARAMS ((sstring *, int));
static int check_protection PARAMS ((int *, int *)); static int check_protection PARAMS ((int *, int *));
static void cb_change_file PARAMS ((cpp_reader *, const cpp_file_change *)); static void cb_file_change PARAMS ((cpp_reader *, const cpp_file_change *));
static void static void
add_symbols (flags, names) add_symbols (flags, names)
...@@ -598,7 +598,7 @@ check_macro_names (pfile, names) ...@@ -598,7 +598,7 @@ check_macro_names (pfile, names)
} }
static void static void
cb_change_file (pfile, fc) cb_file_change (pfile, fc)
cpp_reader *pfile ATTRIBUTE_UNUSED; cpp_reader *pfile ATTRIBUTE_UNUSED;
const cpp_file_change *fc; const cpp_file_change *fc;
{ {
...@@ -620,7 +620,7 @@ read_scan_file (in_fname, argc, argv) ...@@ -620,7 +620,7 @@ read_scan_file (in_fname, argc, argv)
obstack_init (&scan_file_obstack); obstack_init (&scan_file_obstack);
scan_in = cpp_create_reader (CLK_GNUC89); scan_in = cpp_create_reader (CLK_GNUC89);
scan_in->cb.change_file = cb_change_file; scan_in->cb.file_change = cb_file_change;
/* We are going to be scanning a header file out of its proper context, /* We are going to be scanning a header file out of its proper context,
so ignore warnings and errors. */ so ignore warnings and errors. */
......
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