diff options
Diffstat (limited to 'libcpp')
| -rw-r--r-- | libcpp/ChangeLog | 7 | ||||
| -rw-r--r-- | libcpp/include/line-map.h | 8 | ||||
| -rw-r--r-- | libcpp/line-map.c | 40 |
3 files changed, 55 insertions, 0 deletions
diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog index 669b0ccb98c..90512820eb9 100644 --- a/libcpp/ChangeLog +++ b/libcpp/ChangeLog @@ -1,3 +1,10 @@ +2014-01-23 Dodji Seketeli <dodji@redhat.com> + + PR PR preprocessor/58580 + * include/line-map.h (linemap_get_file_highest_location): Declare + new function. + * line-map.c (linemap_get_file_highest_location): Define it. + 2014-01-02 Richard Sandiford <rdsandiford@googlemail.com> Update copyright years diff --git a/libcpp/include/line-map.h b/libcpp/include/line-map.h index 996eae5eafb..9886314b25a 100644 --- a/libcpp/include/line-map.h +++ b/libcpp/include/line-map.h @@ -756,6 +756,14 @@ struct linemap_stats long duplicated_macro_maps_locations_size; }; +/* 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 + location emitted for that file. */ +bool linemap_get_file_highest_location (struct line_maps * set, + const char *file_name, + source_location *loc); + /* Compute and return statistics about the memory consumption of some parts of the line table SET. */ void linemap_get_statistics (struct line_maps *, struct linemap_stats *); diff --git a/libcpp/line-map.c b/libcpp/line-map.c index 052072abdf9..7c7facbc760 100644 --- a/libcpp/line-map.c +++ b/libcpp/line-map.c @@ -1502,6 +1502,46 @@ linemap_dump_location (struct line_maps *set, path, from, l, c, s, (void*)map, e, loc, location); } +/* 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 + location emitted for that file. */ + +bool +linemap_get_file_highest_location (struct line_maps *set, + const char *file_name, + source_location *loc) +{ + /* If the set is empty or no ordinary map has been created then + there is no file to look for ... */ + if (set == NULL || set->info_ordinary.used == 0) + return false; + + /* Now look for the last ordinary map created for FILE_NAME. */ + int i; + for (i = set->info_ordinary.used - 1; i >= 0; --i) + { + const char *fname = set->info_ordinary.maps[i].d.ordinary.to_file; + if (fname && !filename_cmp (fname, file_name)) + break; + } + + if (i < 0) + return false; + + /* The highest location for a given map is either the starting + location of the next map minus one, or -- if the map is the + latest one -- the highest location of the set. */ + source_location result; + if (i == (int) set->info_ordinary.used - 1) + result = set->highest_location; + else + result = set->info_ordinary.maps[i + 1].start_location - 1; + + *loc = result; + return true; +} + /* Compute and return statistics about the memory consumption of some parts of the line table SET. */ |

