From dc40bd56f3001b9dc8e4990a76183e38f9dec11d Mon Sep 17 00:00:00 2001 From: David Malcolm Date: Tue, 8 Mar 2016 14:21:17 -0500 Subject: [PATCH 03/14] FIXME: add linemaps_debug_location --- libcpp/include/line-map.h | 4 +++ libcpp/line-map.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) diff --git a/libcpp/include/line-map.h b/libcpp/include/line-map.h index 90d65d7..9e5fbae 100644 --- a/libcpp/include/line-map.h +++ b/libcpp/include/line-map.h @@ -1871,6 +1871,10 @@ void linemap_get_statistics (struct line_maps *, struct linemap_stats *); stream STREAM. SET is the line map set LOC comes from. */ void linemap_dump_location (struct line_maps *, source_location, FILE *); +/* FIXME. */ +void linemaps_debug_location (struct line_maps *set, source_location loc, + FILE *out); + /* Dump line map at index IX in line table SET to STREAM. If STREAM is NULL, use stderr. IS_MACRO is true if the caller wants to dump a macro map, false otherwise. */ diff --git a/libcpp/line-map.c b/libcpp/line-map.c index c4b7cb2..ab50759 100644 --- a/libcpp/line-map.c +++ b/libcpp/line-map.c @@ -1861,6 +1861,69 @@ linemap_dump_location (struct line_maps *set, path, from, l, c, s, (void*)map, e, loc, location); } +/* FIXME. */ + +static void +debug_location (struct line_maps *set, source_location loc, + FILE *out, int indent) +{ + for (int i = 0; i < indent; i++) + fprintf (out, " "); + fprintf (out, "0x%x: ", loc); + if (IS_ADHOC_LOC (loc)) + { + location_adhoc_data data + = set->location_adhoc_data_map.data[loc & MAX_SOURCE_LOCATION]; + fprintf (out, + "ad-hoc location: locus: 0x%x, m_start: 0x%x m_finish: 0x%x\n", + data.locus, data.src_range.m_start, data.src_range.m_finish); + debug_location (set, data.locus, out, indent + 1); + debug_location (set, data.src_range.m_start, out, indent + 1); + debug_location (set, data.src_range.m_finish, out, indent + 1); + return; + } + + const line_map *map = linemap_lookup (set, loc); + linemap_assert (map); + + if (linemap_macro_expansion_map_p (map)) + { + const line_map_macro *macro_map = linemap_check_macro (map); + source_location def_point + = linemap_macro_map_loc_to_def_point (macro_map, loc); + unsigned token_no = loc - MAP_START_LOCATION (map); + linemap_assert (token_no < MACRO_MAP_NUM_MACRO_TOKENS (macro_map)); + source_location toward_spelling + = MACRO_MAP_LOCATIONS (macro_map)[2 * token_no]; + fprintf (out, + ("in macro map %p: expansion of %s at 0x%x;" + " def_point: 0x%x toward_spelling: 0x%x\n"), + (void *)macro_map, linemap_map_get_macro_name (macro_map), + macro_map->expansion, def_point, toward_spelling); + debug_location (set, macro_map->expansion, out, indent + 1); + debug_location (set, def_point, out, indent + 1); + debug_location (set, toward_spelling, out, indent + 1); + return; + } + else + { + const line_map_ordinary *ord_map = linemap_check_ordinary (map); + fprintf (out, "in ordinary map %p: %s:%i:%i\n", (void *)ord_map, + LINEMAP_FILE (ord_map), SOURCE_LINE (ord_map, loc), + SOURCE_COLUMN (ord_map, loc)); + } +} + +/* FIXME. */ + +void +linemaps_debug_location (struct line_maps *set, source_location line, + FILE *out) +{ + debug_location (set, line, out, 0); + fflush (out); +} + /* Return the highest location emitted for a given file for which there is a line map in SET. FILE_NAME is the file name to consider. If the function returns TRUE, *LOC is set to the highest -- 1.8.5.3