summaryrefslogtreecommitdiff
path: root/gcc/line-map.c
diff options
context:
space:
mode:
authorneil <neil@138bc75d-0d04-0410-961f-82ee72b054a4>2001-08-11 07:33:39 +0000
committerneil <neil@138bc75d-0d04-0410-961f-82ee72b054a4>2001-08-11 07:33:39 +0000
commitf85fcf2bb8dc7f1d1535a653d1e484e6fb06e2da (patch)
treec6597f82b6f803c65532fe99e5912e516912053f /gcc/line-map.c
parent4d0a576dd54fdd609039752499175699e117563c (diff)
downloadgcc-f85fcf2bb8dc7f1d1535a653d1e484e6fb06e2da.tar.gz
* c-lex.c (map): Make const.
(cb_file_change): Update for callback passing a line map. Don't assume we have a previous map. Remove sanity check about popping too many files. * cpperror.c (print_location): Make map const. * cppfiles.c (stack_include_file): Update; line maps now hold sysp. (cpp_make_system_header): Similarly. (search_from): Similarly. (_cpp_execute_include): Don't remember where we came from. * cpphash.h (struct cpp_buffer): Remove return_to_line, sysp. (struct cpp_reader): Make map const. (CPP_IN_SYSTEM_HEADER, _cpp_do_file_change): Update. * cpplib.c (do_line): Update; line maps now hold sysp. (cpp_push_buffer): Similarly. (_cpp_do_file_change): Similarly; callback with map instead. (cpp_get_line_maps): Constify return value. (_cpp_pop_buffer): Update. * cpplib.h (struct cpp_file_change): Remove. (struct cpp_callbacks): Update. (cpp_get_line_maps): Constify return value. * cppmacro.c (_cpp_create_definition): Update. * cppmain.c (struct printer): Constify map. (maybe_print_line): Similarly. (print_line): Similarly. Deduce flags 1 and 2 here. (cb_file_change): Update. * line-map.c (free_line_maps): Warn regardless. (add_line_map): Return pointer to const. When passed NULL to_file with LC_LEAVE, use the obvious values for the return point so the caller doesn't have to figure them out. (lookup_line): Return pointer to const. (print_containing_files): Take pointer to const. * line-map.h (struct line_map): New members reason, sysp. (add_line_map): Return pointer to const. (lookup_line): Similarly. (print_containing_files): Take pointer to const. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@44789 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/line-map.c')
-rw-r--r--gcc/line-map.c54
1 files changed, 39 insertions, 15 deletions
diff --git a/gcc/line-map.c b/gcc/line-map.c
index 1cd1bfdfc0f..d1df5572b83 100644
--- a/gcc/line-map.c
+++ b/gcc/line-map.c
@@ -45,14 +45,15 @@ free_line_maps (set)
{
if (set->maps)
{
-#ifdef ENABLE_CHECKING
struct line_map *map;
+ /* Depending upon whether we are handling preprocessed input or
+ not, this can be a user error or an ICE. */
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);
}
}
@@ -64,10 +65,11 @@ free_line_maps (set)
FROM_LINE should be monotonic increasing across calls to this
function. */
-struct line_map *
-add_line_map (set, reason, from_line, to_file, to_line)
+const struct line_map *
+add_line_map (set, reason, sysp, from_line, to_file, to_line)
struct line_maps *set;
enum lc_reason reason;
+ unsigned int sysp;
unsigned int from_line;
const char *to_file;
unsigned int to_line;
@@ -85,9 +87,6 @@ add_line_map (set, reason, from_line, to_file, to_line)
}
map = &set->maps[set->used];
- map->from_line = from_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. */
@@ -95,17 +94,42 @@ add_line_map (set, reason, from_line, to_file, to_line)
reason = LC_ENTER;
else if (reason == LC_LEAVE)
{
- if (MAIN_FILE_P (map - 1)
- || strcmp (INCLUDED_FROM (set, map - 1)->to_file, to_file))
+ struct line_map *from;
+ bool error;
+
+ if (MAIN_FILE_P (map - 1))
{
-#ifdef ENABLE_CHECKING
- fprintf (stderr, "line-map.c: file \"%s\" left but not entered\n",
- to_file);
-#endif
+ error = true;
reason = LC_RENAME;
+ from = map - 1;
+ }
+ else
+ {
+ from = INCLUDED_FROM (set, map - 1);
+ error = to_file && strcmp (from->to_file, to_file);
+ }
+
+ /* Depending upon whether we are handling preprocessed input or
+ not, this can be a user error or an ICE. */
+ if (error)
+ fprintf (stderr, "line-map.c: file \"%s\" left but not entered\n",
+ to_file);
+
+ /* A TO_FILE of NULL is special - we use the natural values. */
+ if (error || to_file == NULL)
+ {
+ to_file = from->to_file;
+ to_line = LAST_SOURCE_LINE (from) + 1;
+ sysp = from->sysp;
}
}
+ map->reason = reason;
+ map->sysp = sysp;
+ map->from_line = from_line;
+ map->to_file = to_file;
+ map->to_line = to_line;
+
if (reason == LC_ENTER)
map->included_from = set->used - 1;
else if (reason == LC_RENAME)
@@ -122,7 +146,7 @@ add_line_map (set, reason, from_line, to_file, to_line)
chronologically, the logical lines are monotonic increasing, and so
the list is sorted and we can use a binary search. */
-struct line_map *
+const struct line_map *
lookup_line (set, line)
struct line_maps *set;
unsigned int line;
@@ -151,7 +175,7 @@ lookup_line (set, line)
void
print_containing_files (set, map)
struct line_maps *set;
- struct line_map *map;
+ const struct line_map *map;
{
if (MAIN_FILE_P (map) || set->last_listed == map->included_from)
return;