diff options
author | neil <neil@138bc75d-0d04-0410-961f-82ee72b054a4> | 2000-12-11 07:45:16 +0000 |
---|---|---|
committer | neil <neil@138bc75d-0d04-0410-961f-82ee72b054a4> | 2000-12-11 07:45:16 +0000 |
commit | 6cee446440f9e5ec98caa17a412ec0e95f45b79d (patch) | |
tree | 1cf059e8adaf7964d2336feb8095b222fd1c04cb /gcc/cpperror.c | |
parent | 47230e8adcb52c4e9504ee37c50055cc13a79188 (diff) | |
download | gcc-6cee446440f9e5ec98caa17a412ec0e95f45b79d.tar.gz |
* cpperror.c (print_location): New function.
(print_containing_files): Simplify.
(_cpp_begin_message): Simplify and use print_location.
* cppfiles.c (stack_include_file): Update.
(_cpp_pop_file_buffer): Update.
* cpphash.h (struct cpp_buffer): New members
include_stack_listed and type.
* cpplib.c (_cpp_handle_directive): Buffer->inc is not null.
(run_directive): Take buffer type. cpp_push_buffer cannot fail.
(_cpp_do__Pragma, cpp_define, _cpp_define_builtin, cpp_undef,
handle_assertion): Update.
(cpp_push_buffer): Take a buffer type and file name.
(cpp_pop_buffer): Update. Clear include_stack_listed.
* cpplib.h (input_stack_listing_current): Remove.
(enum cpp_buffer_type): New.
(cpp_push_buffer): New prototype.
* cppmacro.c (builtin_macro): Simplify; buffer cannot be null.
* fix-header.c (read_scan_file): Update.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@38186 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/cpperror.c')
-rw-r--r-- | gcc/cpperror.c | 104 |
1 files changed, 63 insertions, 41 deletions
diff --git a/gcc/cpperror.c b/gcc/cpperror.c index ff83c6fb87b..87ef2cbc45d 100644 --- a/gcc/cpperror.c +++ b/gcc/cpperror.c @@ -29,30 +29,23 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "cpphash.h" #include "intl.h" -static void print_containing_files PARAMS ((cpp_reader *, cpp_buffer *)); -static void print_file_and_line PARAMS ((const char *, unsigned int, - unsigned int)); - +static void print_containing_files PARAMS ((cpp_buffer *)); +static void print_location PARAMS ((cpp_reader *, + const char *, + const cpp_lexer_pos *)); #define v_message(msgid, ap) \ do { vfprintf (stderr, _(msgid), ap); putc ('\n', stderr); } while (0) /* Print the file names and line numbers of the #include commands which led to the current file. */ - static void -print_containing_files (pfile, ip) - cpp_reader *pfile; +print_containing_files (ip) cpp_buffer *ip; { int first = 1; - /* If stack of files hasn't changed since we last printed - this info, don't repeat it. */ - if (pfile->input_stack_listing_current) - return; - /* Find the other, outer source files. */ - for (ip = CPP_PREV_BUFFER (ip); ip != NULL; ip = CPP_PREV_BUFFER (ip)) + for (ip = ip->prev; ip; ip = ip->prev) { if (first) { @@ -78,27 +71,69 @@ print_containing_files (pfile, ip) fprintf (stderr, _(",\n from %s:%u"), ip->nominal_fname, CPP_BUF_LINE (ip) - 1); } - if (first == 0) - fputs (":\n", stderr); - - /* Record we have printed the status as of this time. */ - pfile->input_stack_listing_current = 1; + fputs (":\n", stderr); } static void -print_file_and_line (filename, line, col) +print_location (pfile, filename, pos) + cpp_reader *pfile; const char *filename; - unsigned int line, col; + const cpp_lexer_pos *pos; { - if (filename == 0 || *filename == '\0') - filename = "<stdin>"; + cpp_buffer *buffer = pfile->buffer; - if (line == 0) - fprintf (stderr, "%s: ", filename); - else if (col == 0) - fprintf (stderr, "%s:%u: ", filename, line); + if (!buffer) + fprintf (stderr, "%s: ", progname); else - fprintf (stderr, "%s:%u:%u: ", filename, line, col); + { + unsigned int line, col; + enum cpp_buffer_type type = buffer->type; + + /* For _Pragma buffers, we want to print the location as + "foo.c:5:8: _Pragma:", where foo.c is the containing buffer. + For diagnostics relating to command line options, we want to + print "<command line>:" with no line number. */ + if (type == BUF_CL_OPTION || type == BUF_BUILTIN) + line = 0; + else + { + if (type == BUF_PRAGMA) + { + buffer = buffer->prev; + line = CPP_BUF_LINE (buffer); + col = CPP_BUF_COL (buffer); + } + else + { + if (pos == 0) + pos = cpp_get_line (pfile); + line = pos->line; + col = pos->col; + } + + /* Don't repeat the include stack unnecessarily. */ + if (buffer->prev && ! buffer->include_stack_listed) + { + buffer->include_stack_listed = 1; + print_containing_files (buffer); + } + } + + if (filename == 0) + filename = buffer->nominal_fname; + if (*filename == '\0') + filename = _("<stdin>"); + + if (line == 0) + fprintf (stderr, "%s: ", filename); + else if (CPP_OPTION (pfile, show_column) == 0) + fprintf (stderr, "%s:%u: ", filename, line); + else + fprintf (stderr, "%s:%u:%u: ", filename, line, col); + + if (type == BUF_PRAGMA) + fprintf (stderr, "_Pragma: "); + } } /* Set up for an error message: print the file and line, bump the error @@ -112,7 +147,6 @@ _cpp_begin_message (pfile, code, file, pos) const char *file; const cpp_lexer_pos *pos; { - cpp_buffer *ip = CPP_BUFFER (pfile); int is_warning = 0; switch (code) @@ -171,19 +205,7 @@ _cpp_begin_message (pfile, code, file, pos) break; } - if (ip) - { - if (file == NULL) - file = ip->nominal_fname; - if (pos == 0) - pos = cpp_get_line (pfile); - print_containing_files (pfile, ip); - print_file_and_line (file, pos->line, - CPP_OPTION (pfile, show_column) ? pos->col : 0); - } - else - fprintf (stderr, "%s: ", progname); - + print_location (pfile, file, pos); if (is_warning) fputs (_("warning: "), stderr); |