aboutsummaryrefslogtreecommitdiff
path: root/gcc/line-map.c
diff options
context:
space:
mode:
authorNeil Booth <neil@daikokuya.demon.co.uk>2001-08-06 21:07:41 +0000
committerNeil Booth <neil@gcc.gnu.org>2001-08-06 21:07:41 +0000
commitfde84349bec539f5e49273d4e05465b52c6aa7e6 (patch)
tree31a1005e7788f3f63227ac0f3097f1ff9111a46e /gcc/line-map.c
parentdf4556a3aaebc1b9e4da76be5ad806c431653eb8 (diff)
downloadgcc-fde84349bec539f5e49273d4e05465b52c6aa7e6.zip
gcc-fde84349bec539f5e49273d4e05465b52c6aa7e6.tar.gz
gcc-fde84349bec539f5e49273d4e05465b52c6aa7e6.tar.bz2
cpperror.c (print_containing_files): Moved to line-map.c.
* cpperror.c (print_containing_files): Moved to line-map.c. (print_location): line-map.c handles re-listing or otherwise. * cpphash.h (struct lexer_state): Remove next_bol. (struct cpp_buffer): Remove include_stack_listed. * cpplib.c (do_line, cpp_push_buffer, _cpp_pop_buffer): Remove faked buffer handling. (_cpp_do_file_change): Tweak. * cpplib.h (enum cpp_buffer_type): Remove BUF_FAKE. * cppmain.c (struct printer): Remove filename. (print_line, cb_file_change): Update accordingly. * line-map.c: Include intl.h. (init_line_maps): Initialize last_listed. (free_line_maps): Sanity check, warn if ENABLED_CHECKING. (add_line_map): Sanity check inputs, warn if ENABLED_CHECKING. (print_containing_files): New. * line-map.h (struct line_maps): New member last_listed. (print_containing_files, INCLUDED_FROM): New. * Makefile.in: Update. * po/POTFILES.in: Add line-map.c. From-SVN: r44670
Diffstat (limited to 'gcc/line-map.c')
-rw-r--r--gcc/line-map.c82
1 files changed, 73 insertions, 9 deletions
diff --git a/gcc/line-map.c b/gcc/line-map.c
index 27bcf2f..1cd1bfd 100644
--- a/gcc/line-map.c
+++ b/gcc/line-map.c
@@ -23,6 +23,7 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "config.h"
#include "system.h"
#include "line-map.h"
+#include "intl.h"
/* Initialize a line map set. */
@@ -33,15 +34,27 @@ init_line_maps (set)
set->maps = 0;
set->allocated = 0;
set->used = 0;
+ set->last_listed = -1;
}
/* Free a line map set. */
-void free_line_maps (set)
+void
+free_line_maps (set)
struct line_maps *set;
{
if (set->maps)
- free (set->maps);
+ {
+#ifdef ENABLE_CHECKING
+ struct line_map *map;
+
+ for (map = CURRENT_LINE_MAP (set); ! MAIN_FILE_P (map);
+ map = INCLUDED_FROM (set, map))
+ fprintf (stderr, "line-map.c: file \"%s\" entered but not left\n",
+ map->to_file);
+#endif
+ free (set->maps);
+ }
}
/* Add a mapping of logical source line to physical source file and
@@ -76,18 +89,29 @@ add_line_map (set, reason, from_line, to_file, to_line)
map->to_file = to_file;
map->to_line = to_line;
+ /* If we don't keep our line maps consistent, we can easily
+ segfault. Don't rely on the client to do it for us. */
if (set->used == 0)
- map->included_from = -1;
- else if (reason == LC_ENTER)
+ reason = LC_ENTER;
+ else if (reason == LC_LEAVE)
+ {
+ if (MAIN_FILE_P (map - 1)
+ || strcmp (INCLUDED_FROM (set, map - 1)->to_file, to_file))
+ {
+#ifdef ENABLE_CHECKING
+ fprintf (stderr, "line-map.c: file \"%s\" left but not entered\n",
+ to_file);
+#endif
+ reason = LC_RENAME;
+ }
+ }
+
+ if (reason == LC_ENTER)
map->included_from = set->used - 1;
else if (reason == LC_RENAME)
map->included_from = map[-1].included_from;
else if (reason == LC_LEAVE)
- {
- if (map[-1].included_from < 0)
- abort ();
- map->included_from = set->maps[map[-1].included_from].included_from;
- }
+ map->included_from = INCLUDED_FROM (set, map - 1)->included_from;
set->used++;
return map;
@@ -119,3 +143,43 @@ lookup_line (set, line)
return &set->maps[mn];
}
+
+/* Print the file names and line numbers of the #include commands
+ which led to the map MAP, if any, to stderr. Nothing is output if
+ the most recently listed stack is the same as the current one. */
+
+void
+print_containing_files (set, map)
+ struct line_maps *set;
+ struct line_map *map;
+{
+ if (MAIN_FILE_P (map) || set->last_listed == map->included_from)
+ return;
+
+ set->last_listed = map->included_from;
+ map = INCLUDED_FROM (set, map);
+
+ fprintf (stderr, _("In file included from %s:%u"),
+ map->to_file, LAST_SOURCE_LINE (map));
+
+ while (! MAIN_FILE_P (map))
+ {
+ map = INCLUDED_FROM (set, map);
+ /* Translators note: this message is used in conjunction
+ with "In file included from %s:%ld" and some other
+ tricks. We want something like this:
+
+ | In file included from sys/select.h:123,
+ | from sys/types.h:234,
+ | from userfile.c:31:
+ | bits/select.h:45: <error message here>
+
+ with all the "from"s lined up.
+ The trailing comma is at the beginning of this message,
+ and the trailing colon is not translated. */
+ fprintf (stderr, _(",\n from %s:%u"),
+ map->to_file, LAST_SOURCE_LINE (map));
+ }
+
+ fputs (":\n", stderr);
+}