Jason Merrill ja...@redhat.com writes:
On 10/21/2011 07:37 PM, Dodji Seketeli wrote:
It also makes linemap_expand_location_full to return the location it
resolved to.
I think I'd prefer to have expand_location call
linemap_resolve_location and then linemap_expand_location, and perhaps
remove linemap_expand_location_full.
OK.
Incidentally, I notice that there's no assert to enforce the
requirement that linemap_expand_location only takes spelling
locations.
Done.
Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk.
From: Dodji Seketeli do...@redhat.com
Date: Wed, 19 Oct 2011 15:34:51 +0200
Subject: [PATCH 1/2] Support expansion of reserved locations wrapped in
virtual locations
libcpp/
* include/line-map.h (linemap_expand_location): Take a line table
parameter. Update comment.
(linemap_resolve_location): Update comment.
(linemap_expand_location_full): Remove.
* line-map.c (linemap_resolve_location): Handle reserved
locations; return a NULL map in those cases.
(linemap_expand_location): If location is reserved, return a
zeroed expanded location. Update comment. Take a line table to
assert that the function takes non-virtual locations only.
(linemap_expand_location_full): remove.
(linemap_dump_location): Handle the fact that
linemap_resolve_location can return NULL line maps when the
location resolves to a reserved location.
gcc/
* input.c (expand_location): Rewrite using
linemap_resolve_location and linemap_expand_location. Add a
comment.
---
gcc/input.c | 21 +
libcpp/include/line-map.h | 21 -
libcpp/line-map.c | 109 +++--
3 files changed, 87 insertions(+), 64 deletions(-)
diff --git a/gcc/input.c b/gcc/input.c
index a780f5c..4077f9e 100644
--- a/gcc/input.c
+++ b/gcc/input.c
@@ -30,20 +30,23 @@ location_t input_location;
struct line_maps *line_table;
+/* Expand the source location LOC into a human readable location. If
+ LOC resolves to a builtin location, the file name of the readable
+ location is set to the string built-in. */
+
expanded_location
expand_location (source_location loc)
{
expanded_location xloc;
+ const struct line_map *map;
+
+ loc = linemap_resolve_location (line_table, loc,
+ LRK_SPELLING_LOCATION, map);
+ xloc = linemap_expand_location (line_table, map, loc);
+
if (loc = BUILTINS_LOCATION)
-{
- xloc.file = loc == UNKNOWN_LOCATION ? NULL : _(built-in);
- xloc.line = 0;
- xloc.column = 0;
- xloc.sysp = 0;
-}
- else
-xloc = linemap_expand_location_full (line_table, loc,
-LRK_SPELLING_LOCATION);
+xloc.file = loc == UNKNOWN_LOCATION ? NULL : _(built-in);
+
return xloc;
}
diff --git a/libcpp/include/line-map.h b/libcpp/include/line-map.h
index ef98f59..112bc02 100644
--- a/libcpp/include/line-map.h
+++ b/libcpp/include/line-map.h
@@ -651,7 +651,10 @@ enum location_resolution_kind
LRK_SPELLING_LOCATION.
If LOC_MAP is not NULL, *LOC_MAP is set to the map encoding the
- returned location. */
+ returned location. Note that if the resturned location wasn't originally
+ encoded by a map, the *MAP is set to NULL. This can happen if LOC
+ resolves to a location reserved for the client code, like
+ UNKNOWN_LOCATION or BUILTINS_LOCATION in GCC. */
source_location linemap_resolve_location (struct line_maps *,
source_location loc,
@@ -670,19 +673,13 @@ source_location linemap_unwind_toward_expansion (struct
line_maps *,
const struct line_map
**loc_map);
/* Expand source code location LOC and return a user readable source
- code location. LOC must be a spelling (non-virtual) location. */
-
-expanded_location linemap_expand_location (const struct line_map *,
+ code location. LOC must be a spelling (non-virtual) location. If
+ it's a location RESERVED_LOCATION_COUNT a zeroed expanded source
+ location is returned. */
+expanded_location linemap_expand_location (struct line_maps *,
+ const struct line_map *,
source_location loc);
-/* Expand source code location LOC and return a user readable source
- code location. LOC can be a virtual location. The LRK parameter
- is the same as for linemap_resolve_location. */
-
-expanded_location linemap_expand_location_full (struct line_maps *,
- source_location loc,
- enum location_resolution_kind
lrk);
-
/* Statistics about maps allocation and usage as returned by
linemap_get_statistics. */
struct linemap_stats
diff --git a/libcpp/line-map.c