diff options
author | Nathan Sidwell <nathan@acm.org> | 2018-08-08 18:13:00 +0000 |
---|---|---|
committer | Nathan Sidwell <nathan@gcc.gnu.org> | 2018-08-08 18:13:00 +0000 |
commit | f10a91352f83232394646df5a67bdb8f4366a067 (patch) | |
tree | a4ec7ecbde7bfc84329e5a2bb1dc8dea689d7d31 /libcpp/line-map.c | |
parent | a801991954f70fb9470502d305065719849c5660 (diff) | |
download | gcc-f10a91352f83232394646df5a67bdb8f4366a067.tar.gz |
[PATCH] line-map include-from representation
https://gcc.gnu.org/ml/gcc-patches/2018-08/msg00554.html
Make linemap::included_from a location
libcpp/
* include/line-map.h (struct line_map_ordinary): Replace
included_from map index with included_at source_location.
(ORDINARY_MAP_INCLUDER_FILE_INDEX): Delete.
(LAST_SOURCE_LINE_LOCATION): Delete.
(LAST_SOURCE_LINE, LAST_SOURCE_COLUMN): Delete.
(linemap_included_from): New.
(linemap_included_from_linemap): Declare.
(MAIN_FILE_P): Adjust.
* line-map.c (linemap_included_from_linemap): New.
(lonemap_check_files_exited): Use linemap_included_at.
(linemap_add): Adjust inclusion setting.
(linemap_dump, linemap_dump_location): Adjust.
* directives.c (do_linemarker): Use linemap_included_at.
gcc/
* diagnostic.c (diagnostic_report_current_module): Use
linemap_included_from & linemap_included_from_linemap.
gcc/c-family/
* c-common.c (try_to_locate_new_include_inertion_point): Use
linemap_included_from_linemap.
* c-lex.c (fe_file_change): Use linemap_included_from.
* c-ppoutput.c (pp_file_change): Likewise.
gcc/fortran/
* cpp.c (cb_file_change): Use linemap_included_from.
gcc/testsuite/
* c-c++-common/inc-from-1a.h, c-c++-common/inc-from-1b.h,
c-c++-common/inc-from-1.c: New
From-SVN: r263429
Diffstat (limited to 'libcpp/line-map.c')
-rw-r--r-- | libcpp/line-map.c | 53 |
1 files changed, 32 insertions, 21 deletions
diff --git a/libcpp/line-map.c b/libcpp/line-map.c index a5dc485e79e..555cd129a9c 100644 --- a/libcpp/line-map.c +++ b/libcpp/line-map.c @@ -355,17 +355,25 @@ linemap_init (struct line_maps *set, set->builtin_location = builtin_location; } +/* Return the ordinary line map from whence MAP was included. Returns + NULL if MAP was not an include. */ + +const line_map_ordinary * +linemap_included_from_linemap (line_maps *set, const line_map_ordinary *map) +{ + return linemap_ordinary_map_lookup (set, linemap_included_from (map)); +} + /* Check for and warn about line_maps entered but not exited. */ void linemap_check_files_exited (struct line_maps *set) { - const line_map_ordinary *map; /* Depending upon whether we are handling preprocessed input or not, this can be a user error or an ICE. */ - for (map = LINEMAPS_LAST_ORDINARY_MAP (set); + for (const line_map_ordinary *map = LINEMAPS_LAST_ORDINARY_MAP (set); ! MAIN_FILE_P (map); - map = INCLUDED_FROM (set, map)) + map = linemap_included_from_linemap (set, map)) fprintf (stderr, "line-map.c: file \"%s\" entered but not left\n", ORDINARY_MAP_FILE_NAME (map)); } @@ -494,19 +502,19 @@ linemap_add (struct line_maps *set, enum lc_reason reason, if (reason == LC_RENAME_VERBATIM) reason = LC_RENAME; + const line_map_ordinary *from = NULL; if (reason == LC_LEAVE) { /* When we are just leaving an "included" file, and jump to the next location inside the "includer" right after the #include "included", this variable points the map in use right before the #include "included", inside the same "includer" file. */ - line_map_ordinary *from; linemap_assert (!MAIN_FILE_P (map - 1)); /* (MAP - 1) points to the map we are leaving. The map from which (MAP - 1) got included should be the map that comes right before MAP in the same file. */ - from = INCLUDED_FROM (set, map - 1); + from = linemap_included_from_linemap (set, map - 1); /* A TO_FILE of NULL is special - we use the natural values. */ if (to_file == NULL) @@ -538,19 +546,24 @@ linemap_add (struct line_maps *set, enum lc_reason reason, if (reason == LC_ENTER) { - map->included_from = - set->depth == 0 ? -1 : (int) (LINEMAPS_ORDINARY_USED (set) - 2); + if (set->depth == 0) + map->included_from = 0; + else + /* The location of the end of the just-closed map. */ + map->included_from + = (((map[0].start_location - 1 - map[-1].start_location) + & ~((1 << map[-1].m_column_and_range_bits) - 1)) + + map[-1].start_location); set->depth++; if (set->trace_includes) trace_include (set, map); } else if (reason == LC_RENAME) - map->included_from = ORDINARY_MAP_INCLUDER_FILE_INDEX (&map[-1]); + map->included_from = linemap_included_from (&map[-1]); else if (reason == LC_LEAVE) { set->depth--; - map->included_from = - ORDINARY_MAP_INCLUDER_FILE_INDEX (INCLUDED_FROM (set, map - 1)); + map->included_from = linemap_included_from (from); } return map; @@ -1761,17 +1774,13 @@ linemap_dump (FILE *stream, struct line_maps *set, unsigned ix, bool is_macro) if (!is_macro) { const line_map_ordinary *ord_map = linemap_check_ordinary (map); - unsigned includer_ix; - const line_map_ordinary *includer_map; - - includer_ix = ORDINARY_MAP_INCLUDER_FILE_INDEX (ord_map); - includer_map = includer_ix < LINEMAPS_ORDINARY_USED (set) - ? LINEMAPS_ORDINARY_MAP_AT (set, includer_ix) - : NULL; + const line_map_ordinary *includer_map + = linemap_included_from_linemap (set, ord_map); fprintf (stream, "File: %s:%d\n", ORDINARY_MAP_FILE_NAME (ord_map), ORDINARY_MAP_STARTING_LINE_NUMBER (ord_map)); - fprintf (stream, "Included from: [%d] %s\n", includer_ix, + fprintf (stream, "Included from: [%d] %s\n", + includer_map ? int (includer_map - set->info_ordinary.maps) : -1, includer_map ? ORDINARY_MAP_FILE_NAME (includer_map) : "None"); } else @@ -1821,9 +1830,11 @@ linemap_dump_location (struct line_maps *set, if (e) from = "N/A"; else - from = (INCLUDED_FROM (set, map)) - ? LINEMAP_FILE (INCLUDED_FROM (set, map)) - : "<NULL>"; + { + const line_map_ordinary *from_map + = linemap_included_from_linemap (set, map); + from = from_map ? LINEMAP_FILE (from_map) : "<NULL>"; + } } /* P: path, L: line, C: column, S: in-system-header, M: map address, |