aboutsummaryrefslogtreecommitdiff
path: root/gcc/cpperror.c
diff options
context:
space:
mode:
authorNeil Booth <neil@gcc.gnu.org>2001-08-02 23:03:31 +0000
committerNeil Booth <neil@gcc.gnu.org>2001-08-02 23:03:31 +0000
commitd82fc1085fad2fd7a776bcc88dbac88f081dd10f (patch)
treeaedb0e3e4381261de71d4d7cee777f2ccde7880d /gcc/cpperror.c
parent6ff02a9579cfb21fd184f3e634c4c837732d7cb5 (diff)
downloadgcc-d82fc1085fad2fd7a776bcc88dbac88f081dd10f.zip
gcc-d82fc1085fad2fd7a776bcc88dbac88f081dd10f.tar.gz
gcc-d82fc1085fad2fd7a776bcc88dbac88f081dd10f.tar.bz2
line-map.c: New.
* line-map.c: New. * line-map.h: New. * Makefile.in (line-map.o): New. (LIBCPP_OBJS, LIBCPP_DEPS): Update. * c-lex.c (cb_file_change): Update for new cpp_file_change structure. * cpperror.c (print_containing_files): Similarly. (print_location): Update. Don't output a space before _Pragma. * cppfiles.c (stack_include_file): Set to line 1 immediately. (stack_include_filee, cpp_make_system_header): Update. (_cpp_execute_include): Get logical line number right for calling as-yet-unterminated #include. * cpphash.h (struct cpp_reader): Add line_maps. (_cpp_do_file_change): Update. * cppinit.c (cpp_create_reader): Initialize line maps. (cpp_destroy): Destroy line maps. (cpp_start_read): Get logical line number right. * cpplex.c (parse_string): Only warn once for multi-line strings. Use boolean variable for null warning. * cpplib.c (_cpp_handle_directive): End the directive if it isn't already. (do_include_common): End the directive early. (do_line): Don't warn about out-of-range lines in preprocessed source. Update. Remove unused variables. (_cpp_do_file_change): Update for new line mapping. (pragma_cb): New typedef. (cpp_register_pragma): Stop looking ahead before calling the handler. Clean up. (do_pragma_system_header): End directive early. (cpp_get_line_maps): New. (cpp_pop_buffer): Fudge logical line. Update. * cpplib.h: Include line-map.h (enum cpp_fc_reason): Remove. (struct cpp_file_change): Update. (cpp_get_line_maps): New. * cppmain.c (struct_printer): New member map. (cb_file_change): Update for new mappings. * fix-header.c (cb_file_change): Similarly. testsuite: * gcc.dg/cpp/19951025-1.c: Update. From-SVN: r44584
Diffstat (limited to 'gcc/cpperror.c')
-rw-r--r--gcc/cpperror.c48
1 files changed, 30 insertions, 18 deletions
diff --git a/gcc/cpperror.c b/gcc/cpperror.c
index 063489d..f101982 100644
--- a/gcc/cpperror.c
+++ b/gcc/cpperror.c
@@ -29,7 +29,8 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "cpphash.h"
#include "intl.h"
-static void print_containing_files PARAMS ((cpp_buffer *));
+static void print_containing_files PARAMS ((struct line_map *,
+ struct line_map *));
static void print_location PARAMS ((cpp_reader *,
const char *,
const cpp_lexer_pos *));
@@ -42,21 +43,25 @@ static void print_location PARAMS ((cpp_reader *,
/* Print the file names and line numbers of the #include
commands which led to the current file. */
static void
-print_containing_files (ip)
- cpp_buffer *ip;
+print_containing_files (map_array, map)
+ struct line_map *map_array;
+ struct line_map *map;
{
int first = 1;
- /* Find the other, outer source files. */
- for (ip = ip->prev; ip; ip = ip->prev)
+ for (;;)
{
+ if (MAIN_FILE_P (map))
+ break;
+ map = &map_array[map->included_from];
+
if (first)
{
first = 0;
/* The current line in each outer source file is now the
same as the line of the #include. */
fprintf (stderr, _("In file included from %s:%u"),
- ip->nominal_fname, CPP_BUF_LINE (ip));
+ map->to_file, LAST_SOURCE_LINE (map));
}
else
/* Translators note: this message is used in conjunction
@@ -72,8 +77,9 @@ 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));
+ map->to_file, LAST_SOURCE_LINE (map));
}
+
fputs (":\n", stderr);
}
@@ -100,19 +106,24 @@ print_location (pfile, filename, pos)
line = 0;
else
{
+ struct line_map *map;
+
+ line = pfile->line;
if (type == BUF_PRAGMA)
{
buffer = buffer->prev;
- line = CPP_BUF_LINE (buffer);
col = CPP_BUF_COL (buffer);
}
- else
+
+ map = lookup_line (&pfile->line_maps, line);
+ if (pos == 0)
{
- if (pos == 0)
- pos = cpp_get_line (pfile);
- line = pos->line;
- col = pos->col;
+ pos = cpp_get_line (pfile);
+ line = SOURCE_LINE (map, line);
}
+ else
+ line = pos->line;
+ col = pos->col;
if (col == 0)
col = 1;
@@ -121,7 +132,7 @@ print_location (pfile, filename, pos)
if (buffer->prev && ! buffer->include_stack_listed)
{
buffer->include_stack_listed = 1;
- print_containing_files (buffer);
+ print_containing_files (pfile->line_maps.maps, map);
}
}
@@ -129,14 +140,15 @@ print_location (pfile, filename, pos)
filename = buffer->nominal_fname;
if (line == 0)
- fprintf (stderr, "%s: ", filename);
+ fprintf (stderr, "%s:", filename);
else if (CPP_OPTION (pfile, show_column) == 0)
- fprintf (stderr, "%s:%u: ", filename, line);
+ fprintf (stderr, "%s:%u:", filename, line);
else
- fprintf (stderr, "%s:%u:%u: ", filename, line, col);
+ fprintf (stderr, "%s:%u:%u:", filename, line, col);
if (type == BUF_PRAGMA)
- fprintf (stderr, "_Pragma: ");
+ fprintf (stderr, "_Pragma:");
+ fputc (' ', stderr);
}
}