summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorneil <neil@138bc75d-0d04-0410-961f-82ee72b054a4>2000-12-17 00:13:54 +0000
committerneil <neil@138bc75d-0d04-0410-961f-82ee72b054a4>2000-12-17 00:13:54 +0000
commitf0c20935793936f286587ca5f6171f7524fb5778 (patch)
treedc9788c071208bc6125b57c49a68337f6a09eb53
parentd9953e000d67e404387efa5d86f037b59f890f7c (diff)
downloadppe42-gcc-f0c20935793936f286587ca5f6171f7524fb5778.tar.gz
ppe42-gcc-f0c20935793936f286587ca5f6171f7524fb5778.zip
* c-lex.c: Move main_input_filename handling to FC_ENTER. Clean up.
* cpperror.c (print_containing_files): Get right line number. (print_location): Output column of 1 if 0. * cppfiles.c (stack_include_file): cpp_push_buffer handles the callback. * cpphash.h (_cpp_do_file_change): No longer external. * cpplib.c (do_file_change): Now local to cpplib.c. (do_line): Fake a buffer stack for preprocessed files. (cpp_push_buffer): Create a file_change callback. Handle faked buffers. (cpp_pop_buffer): Similarly. * cpplib.h: BUF_FAKE: New buffer type. * cppmain.c: Update to handle correct file renaming where a #line is the first line of the main file, and produce only the renamed file, not the original file, as output. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@38319 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/ChangeLog18
-rw-r--r--gcc/c-lex.c12
-rw-r--r--gcc/cpperror.c5
-rw-r--r--gcc/cppfiles.c13
-rw-r--r--gcc/cpphash.h2
-rw-r--r--gcc/cpplib.c170
-rw-r--r--gcc/cpplib.h7
-rw-r--r--gcc/cppmain.c22
8 files changed, 166 insertions, 83 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 9ed5996da2b..74109d74d97 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,21 @@
+2000-12-17 Neil Booth <neil@daikokuya.demon.co.uk>
+
+ * c-lex.c: Move main_input_filename handling to FC_ENTER. Clean up.
+ * cpperror.c (print_containing_files): Get right line number.
+ (print_location): Output column of 1 if 0.
+ * cppfiles.c (stack_include_file): cpp_push_buffer handles
+ the callback.
+ * cpphash.h (_cpp_do_file_change): No longer external.
+ * cpplib.c (do_file_change): Now local to cpplib.c.
+ (do_line): Fake a buffer stack for preprocessed files.
+ (cpp_push_buffer): Create a file_change callback. Handle faked
+ buffers.
+ (cpp_pop_buffer): Similarly.
+ * cpplib.h: BUF_FAKE: New buffer type.
+ * cppmain.c: Update to handle correct file renaming where a
+ #line is the first line of the main file, and produce only
+ the renamed file, not the original file, as output.
+
2000-12-17 Michael Hayes <m.hayes@elec.canterbury.ac.nz>
* config/c4x/c4x.md: Remove redundant @s from output patterns.
diff --git a/gcc/c-lex.c b/gcc/c-lex.c
index cf65ceacb2c..13e0ef2468c 100644
--- a/gcc/c-lex.c
+++ b/gcc/c-lex.c
@@ -234,14 +234,10 @@ cb_change_file (pfile, fc)
cpp_reader *pfile ATTRIBUTE_UNUSED;
const cpp_file_change *fc;
{
- if (fc->from.filename == 0)
- main_input_filename = fc->to.filename;
- in_system_header = fc->sysp;
-
/* Do the actions implied by the preceding numbers. */
if (fc->reason == FC_ENTER)
{
- /* FIXME. Don't stack the main buffer on the input stack. */
+ /* Don't stack the main buffer on the input stack. */
if (fc->from.filename)
{
lineno = lex_lineno;
@@ -258,6 +254,8 @@ cb_change_file (pfile, fc)
}
#endif
}
+ else
+ main_input_filename = fc->to.filename;
}
else if (fc->reason == FC_LEAVE)
{
@@ -288,11 +286,9 @@ cb_change_file (pfile, fc)
else
error ("leaving more files than we entered");
}
- else if (fc->reason == FC_RENAME)
- input_filename = fc->to.filename;
update_header_times (fc->to.filename);
-
+ in_system_header = fc->sysp;
input_filename = fc->to.filename;
lex_lineno = fc->to.lineno;
diff --git a/gcc/cpperror.c b/gcc/cpperror.c
index 87ef2cbc45d..6a48a2a7c97 100644
--- a/gcc/cpperror.c
+++ b/gcc/cpperror.c
@@ -69,7 +69,7 @@ print_containing_files (ip)
The trailing comma is at the beginning of this message,
and the trailing colon is not translated. */
fprintf (stderr, _(",\n from %s:%u"),
- ip->nominal_fname, CPP_BUF_LINE (ip) - 1);
+ ip->nominal_fname, CPP_BUF_LINE (ip));
}
fputs (":\n", stderr);
}
@@ -111,6 +111,9 @@ print_location (pfile, filename, pos)
col = pos->col;
}
+ if (col == 0)
+ col = 1;
+
/* Don't repeat the include stack unnecessarily. */
if (buffer->prev && ! buffer->include_stack_listed)
{
diff --git a/gcc/cppfiles.c b/gcc/cppfiles.c
index 28bdfd0db4a..96ce7e48511 100644
--- a/gcc/cppfiles.c
+++ b/gcc/cppfiles.c
@@ -245,16 +245,8 @@ stack_include_file (pfile, inc)
cpp_reader *pfile;
struct include_file *inc;
{
- const char *filename = 0;
- unsigned int lineno = 0;
cpp_buffer *fp;
- if (pfile->buffer)
- {
- filename = pfile->buffer->nominal_fname;
- lineno = pfile->buffer->lineno;
- }
-
/* Not in cache? */
if (! inc->buffer)
read_include_file (pfile, inc);
@@ -268,7 +260,6 @@ stack_include_file (pfile, inc)
fp->rlimit += inc->st.st_size;
fp->cur = fp->buf;
fp->line_base = fp->buf;
- fp->lineno = 0; /* For _cpp_do_file_change. */
fp->inc->refcnt++;
if (inc->foundhere)
fp->sysp = inc->foundhere->sysp;
@@ -282,10 +273,6 @@ stack_include_file (pfile, inc)
pfile->mi_state = MI_OUTSIDE;
pfile->mi_cmacro = 0;
pfile->include_depth++;
-
- _cpp_do_file_change (pfile, FC_ENTER, filename, lineno);
-
- fp->lineno = 1;
}
/* Read the file referenced by INC into the file cache.
diff --git a/gcc/cpphash.h b/gcc/cpphash.h
index 6cd162181a0..a528f9127cd 100644
--- a/gcc/cpphash.h
+++ b/gcc/cpphash.h
@@ -229,8 +229,6 @@ extern void _cpp_do__Pragma PARAMS ((cpp_reader *));
extern void _cpp_init_stacks PARAMS ((cpp_reader *));
extern void _cpp_cleanup_stacks 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. */
#define DSC(str) (const U_CHAR *)str, sizeof str - 1
diff --git a/gcc/cpplib.c b/gcc/cpplib.c
index 74662fe635b..a032f7be24d 100644
--- a/gcc/cpplib.c
+++ b/gcc/cpplib.c
@@ -108,6 +108,8 @@ static cpp_hashnode *parse_assertion PARAMS ((cpp_reader *, struct answer **,
static struct answer ** find_answer PARAMS ((cpp_hashnode *,
const struct answer *));
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
frequency of occurrence; the numbers at the end are directive
@@ -721,7 +723,6 @@ do_line (pfile)
fname[len] = '\0';
_cpp_simplify_pathname (fname);
- buffer->nominal_fname = fname;
if (! pfile->state.line_extension)
check_eol (pfile);
@@ -748,8 +749,36 @@ do_line (pfile)
sysp = 2, read_flag (pfile, flag);
}
+ if (reason == FC_ENTER)
+ {
+ cpp_push_buffer (pfile, 0, 0, BUF_FAKE, fname);
+ buffer = pfile->buffer;
+ }
+ else if (reason == FC_LEAVE)
+ {
+ if (buffer->type != BUF_FAKE)
+ cpp_warning (pfile, "file \"%s\" left but not entered",
+ buffer->nominal_fname);
+ else
+ {
+ cpp_pop_buffer (pfile);
+ buffer = pfile->buffer;
+ if (strcmp (buffer->nominal_fname, fname))
+ cpp_warning (pfile, "expected to return to file \"%s\"",
+ buffer->nominal_fname);
+ if (buffer->lineno + 1 != new_lineno)
+ cpp_warning (pfile, "expected to return to line number %u",
+ buffer->lineno + 1);
+ if (buffer->sysp != sysp)
+ cpp_warning (pfile, "header flags for \"%s\" have changed",
+ buffer->nominal_fname);
+ }
+ }
+
cpp_make_system_header (pfile, sysp, sysp == 2);
}
+
+ buffer->nominal_fname = fname;
}
else if (token.type != CPP_EOF)
{
@@ -760,13 +789,19 @@ do_line (pfile)
/* Our line number is incremented after the directive is processed. */
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. The assumption is that the
- current buffer's lineno is one less than the next line. */
-void
-_cpp_do_file_change (pfile, reason, from_file, from_lineno)
+/* Arrange the file_change callback. */
+static void
+do_file_change (pfile, reason, from_file, from_lineno)
cpp_reader *pfile;
enum cpp_fc_reason reason;
const char *from_file;
@@ -1622,9 +1657,7 @@ cpp_define (pfile, str)
run_directive (pfile, T_DEFINE, BUF_CL_OPTION, buf, count);
}
-/* Slight variant of the above for use by initialize_builtins, which (a)
- knows how to set up the buffer itself, (b) needs a different "filename"
- tag. */
+/* Slight variant of the above for use by initialize_builtins. */
void
_cpp_define_builtin (pfile, str)
cpp_reader *pfile;
@@ -1698,35 +1731,63 @@ cpp_push_buffer (pfile, buffer, len, type, filename)
{
cpp_buffer *new = xobnew (pfile->buffer_ob, cpp_buffer);
- /* Clears, amongst other things, if_stack and mi_cmacro. */
- memset (new, 0, sizeof (cpp_buffer));
-
- switch (type)
+ if (type == BUF_FAKE)
+ {
+ /* A copy of the current buffer, just with a new name and type. */
+ memcpy (new, pfile->buffer, sizeof (cpp_buffer));
+ new->type = BUF_FAKE;
+ }
+ else
{
- case BUF_FILE: new->nominal_fname = filename; break;
- case BUF_BUILTIN: new->nominal_fname = _("<builtin>"); break;
- case BUF_CL_OPTION: new->nominal_fname = _("<command line>"); break;
- case BUF_PRAGMA: new->nominal_fname = _("<_Pragma>"); break;
+ if (type == BUF_BUILTIN)
+ filename = _("<builtin>");
+ else if (type == BUF_CL_OPTION)
+ filename = _("<command line>");
+ else if (type == BUF_PRAGMA)
+ filename = "<_Pragma>";
+
+ /* Clears, amongst other things, if_stack and mi_cmacro. */
+ memset (new, 0, sizeof (cpp_buffer));
+
+ new->line_base = new->buf = new->cur = buffer;
+ new->rlimit = buffer + len;
+
+ /* No read ahead or extra char initially. */
+ new->read_ahead = EOF;
+ new->extra_char = EOF;
+
+ /* 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);
+
+ pfile->lexer_pos.output_line = 1;
}
+
+ new->nominal_fname = filename;
new->type = type;
- new->line_base = new->buf = new->cur = buffer;
- new->rlimit = buffer + len;
new->prev = pfile->buffer;
new->pfile = pfile;
-
- /* No read ahead or extra char initially. */
- new->read_ahead = EOF;
- new->extra_char = EOF;
-
- /* 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->include_stack_listed = 0;
pfile->state.next_bol = 1;
pfile->buffer_stack_depth++;
- pfile->lexer_pos.output_line = 1;
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;
}
@@ -1734,31 +1795,44 @@ cpp_buffer *
cpp_pop_buffer (pfile)
cpp_reader *pfile;
{
- cpp_buffer *buffer = pfile->buffer;
- const char *filename = buffer->nominal_fname;
- unsigned int lineno = buffer->lineno;
- struct if_stack *ifs = buffer->if_stack;
- int file_buffer_p = buffer->type == BUF_FILE;
+ cpp_buffer *buffer;
+ struct if_stack *ifs;
+ int in_do_line = pfile->directive == &dtable[T_LINE];
- /* Walk back up the conditional stack till we reach its level at
- entry to this file, issuing error messages. */
- for (ifs = buffer->if_stack; ifs; ifs = ifs->next)
- cpp_error_with_line (pfile, ifs->pos.line, ifs->pos.col,
- "unterminated #%s", dtable[ifs->type].name);
+ do
+ {
+ buffer = pfile->buffer;
+ /* Walk back up the conditional stack till we reach its level at
+ entry to this file, issuing error messages. */
+ for (ifs = buffer->if_stack; ifs; ifs = ifs->next)
+ cpp_error_with_line (pfile, ifs->pos.line, ifs->pos.col,
+ "unterminated #%s", dtable[ifs->type].name);
+
+ if (buffer->type == BUF_FAKE)
+ {
+ if (!in_do_line)
+ cpp_warning (pfile, "file \"%s\" entered but not left",
+ buffer->nominal_fname);
- if (file_buffer_p)
- _cpp_pop_file_buffer (pfile, buffer);
+ buffer->prev->cur = buffer->cur;
+ }
+ else if (buffer->type == BUF_FILE)
+ _cpp_pop_file_buffer (pfile, buffer);
- pfile->buffer = buffer->prev;
- obstack_free (pfile->buffer_ob, buffer);
- pfile->buffer_stack_depth--;
+ pfile->buffer = buffer->prev;
+ pfile->buffer_stack_depth--;
- if (pfile->buffer && file_buffer_p)
- {
- _cpp_do_file_change (pfile, FC_LEAVE, filename, lineno);
- pfile->buffer->include_stack_listed = 0;
+ if ((buffer->type == BUF_FILE || buffer->type == BUF_FAKE)
+ && pfile->buffer)
+ {
+ do_file_change (pfile, FC_LEAVE, buffer->nominal_fname,
+ buffer->lineno);
+ pfile->buffer->include_stack_listed = 0;
+ }
}
-
+ while (pfile->buffer && pfile->buffer->type == BUF_FAKE && !in_do_line);
+
+ obstack_free (pfile->buffer_ob, buffer);
return pfile->buffer;
}
diff --git a/gcc/cpplib.h b/gcc/cpplib.h
index 552631b33f0..4c4b7e3a320 100644
--- a/gcc/cpplib.h
+++ b/gcc/cpplib.h
@@ -633,9 +633,10 @@ struct cpp_reader
/* Name under which this program was invoked. */
extern const char *progname;
-/* Where does this buffer come from? A 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};
+/* Where does this buffer come from? A faked include, a source file,
+ a builtin macro, a command-line option, or a _Pragma operator. */
+enum cpp_buffer_type {BUF_FAKE, BUF_FILE, BUF_BUILTIN,
+ BUF_CL_OPTION, BUF_PRAGMA};
/* The structure of a node in the hash table. The hash table has
entries for all identifiers: either macros defined by #define
diff --git a/gcc/cppmain.c b/gcc/cppmain.c
index cc958e00403..7e12d6befc7 100644
--- a/gcc/cppmain.c
+++ b/gcc/cppmain.c
@@ -263,7 +263,10 @@ maybe_print_line (line)
if (print.no_line_dirs)
return;
- if (line >= print.lineno && line < print.lineno + 8)
+ /* print.lineno is zero if this is the first token of the file. We
+ handle this specially, so that a first line of "# 1 "foo.c" in
+ file foo.i outputs just the foo.c line, and not a foo.i line. */
+ if (line >= print.lineno && line < print.lineno + 8 && print.lineno)
{
while (line > print.lineno)
{
@@ -358,7 +361,6 @@ cb_change_file (pfile, fc)
if (fc->reason == FC_ENTER && fc->from.filename)
maybe_print_line (fc->from.lineno);
- print.lineno = fc->to.lineno;
print.last_fname = fc->to.filename;
if (fc->externc)
print.syshdr_flags = " 3 4";
@@ -367,14 +369,18 @@ cb_change_file (pfile, fc)
else
print.syshdr_flags = "";
- switch (fc->reason)
+ if (print.lineno)
{
- case FC_ENTER : flags = fc->from.filename ? " 1": ""; break;
- case FC_LEAVE : flags = " 2"; break;
- case FC_RENAME: flags = ""; break;
- }
+ print.lineno = fc->to.lineno;
+ switch (fc->reason)
+ {
+ case FC_ENTER : flags = " 1"; break;
+ case FC_LEAVE : flags = " 2"; break;
+ case FC_RENAME: flags = ""; break;
+ }
- print_line (flags);
+ print_line (flags);
+ }
}
static void
OpenPOWER on IntegriCloud