Commit 84756fd4 by Dodji Seketeli Committed by Dodji Seketeli

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.

From-SVN: r180426
parent ae5f5715
2011-10-24 Dodji Seketeli <dodji@redhat.com>
* input.c (expand_location): Rewrite using
linemap_resolve_location and linemap_expand_location. Add a
comment.
2011-10-25 Jakub Jelinek <jakub@redhat.com> 2011-10-25 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/50596 PR tree-optimization/50596
...@@ -30,20 +30,23 @@ location_t input_location; ...@@ -30,20 +30,23 @@ location_t input_location;
struct line_maps *line_table; 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 expanded_location
expand_location (source_location loc) expand_location (source_location loc)
{ {
expanded_location xloc; 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) if (loc <= BUILTINS_LOCATION)
{
xloc.file = loc == UNKNOWN_LOCATION ? NULL : _("<built-in>"); 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);
return xloc; return xloc;
} }
......
2011-10-24 Dodji Seketeli <dodji@redhat.com>
* 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.
* line-map.c (linemap_macro_map_lookup): Fix logic.
2011-10-22 Dodji Seketeli <dodji@redhat.com> 2011-10-22 Dodji Seketeli <dodji@redhat.com>
PR bootstrap/50778 PR bootstrap/50778
......
...@@ -651,7 +651,10 @@ enum location_resolution_kind ...@@ -651,7 +651,10 @@ enum location_resolution_kind
LRK_SPELLING_LOCATION. LRK_SPELLING_LOCATION.
If LOC_MAP is not NULL, *LOC_MAP is set to the map encoding the 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 linemap_resolve_location (struct line_maps *,
source_location loc, source_location loc,
...@@ -670,19 +673,13 @@ source_location linemap_unwind_toward_expansion (struct line_maps *, ...@@ -670,19 +673,13 @@ source_location linemap_unwind_toward_expansion (struct line_maps *,
const struct line_map **loc_map); const struct line_map **loc_map);
/* Expand source code location LOC and return a user readable source /* Expand source code location LOC and return a user readable source
code location. LOC must be a spelling (non-virtual) location. */ code location. LOC must be a spelling (non-virtual) location. If
it's a location < RESERVED_LOCATION_COUNT a zeroed expanded source
expanded_location linemap_expand_location (const struct line_map *, location is returned. */
expanded_location linemap_expand_location (struct line_maps *,
const struct line_map *,
source_location loc); 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 /* Statistics about maps allocation and usage as returned by
linemap_get_statistics. */ linemap_get_statistics. */
struct linemap_stats struct linemap_stats
......
...@@ -755,12 +755,12 @@ linemap_location_in_system_header_p (struct line_maps *set, ...@@ -755,12 +755,12 @@ linemap_location_in_system_header_p (struct line_maps *set,
{ {
const struct line_map *map = NULL; const struct line_map *map = NULL;
if (location < RESERVED_LOCATION_COUNT)
return false;
location = location =
linemap_resolve_location (set, location, LRK_SPELLING_LOCATION, &map); linemap_resolve_location (set, location, LRK_SPELLING_LOCATION, &map);
if (location < RESERVED_LOCATION_COUNT)
return false;
return LINEMAP_SYSP (map); return LINEMAP_SYSP (map);
} }
...@@ -1039,7 +1039,10 @@ linemap_macro_loc_to_exp_point (struct line_maps *set, ...@@ -1039,7 +1039,10 @@ linemap_macro_loc_to_exp_point (struct line_maps *set,
LRK_SPELLING_LOCATION. LRK_SPELLING_LOCATION.
If MAP is non-NULL, *MAP is set to the map of the resolved If MAP is non-NULL, *MAP is set to the map of the resolved
location. */ 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 source_location
linemap_resolve_location (struct line_maps *set, linemap_resolve_location (struct line_maps *set,
...@@ -1047,7 +1050,15 @@ linemap_resolve_location (struct line_maps *set, ...@@ -1047,7 +1050,15 @@ linemap_resolve_location (struct line_maps *set,
enum location_resolution_kind lrk, enum location_resolution_kind lrk,
const struct line_map **map) const struct line_map **map)
{ {
linemap_assert (set && loc >= RESERVED_LOCATION_COUNT); if (loc < RESERVED_LOCATION_COUNT)
{
/* A reserved location wasn't encoded in a map. Let's return a
NULL map here, just like what linemap_ordinary_map_lookup
does. */
if (map)
*map = NULL;
return loc;
}
switch (lrk) switch (lrk)
{ {
...@@ -1101,40 +1112,47 @@ linemap_unwind_toward_expansion (struct line_maps *set, ...@@ -1101,40 +1112,47 @@ linemap_unwind_toward_expansion (struct line_maps *set,
} }
/* Expand source code location LOC and return a user readable source /* Expand source code location LOC and return a user readable source
code location. LOC must be a spelling (non-virtual) location. */ 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 expanded_location
linemap_expand_location (const struct line_map *map, linemap_expand_location (struct line_maps *set,
const struct line_map *map,
source_location loc) source_location loc)
{ {
expanded_location xloc; expanded_location xloc;
memset (&xloc, 0, sizeof (xloc));
if (loc < RESERVED_LOCATION_COUNT)
/* The location for this token wasn't generated from a line map.
It was probably a location for a builtin token, chosen by some
client code. Let's not try to expand the location in that
case. */;
else if (map == NULL)
/* We shouldn't be getting a NULL map with a location that is not
reserved by the client code. */
abort ();
else
{
/* MAP must be an ordinary map and LOC must be non-virtual,
encoded into this map, obviously; the accessors used on MAP
below ensure it is ordinary. Let's just assert the
non-virtualness of LOC here. */
if (linemap_location_from_macro_expansion_p (set, loc))
abort ();
xloc.file = LINEMAP_FILE (map); xloc.file = LINEMAP_FILE (map);
xloc.line = SOURCE_LINE (map, loc); xloc.line = SOURCE_LINE (map, loc);
xloc.column = SOURCE_COLUMN (map, loc); xloc.column = SOURCE_COLUMN (map, loc);
xloc.sysp = LINEMAP_SYSP (map) != 0; xloc.sysp = LINEMAP_SYSP (map) != 0;
}
return xloc; return xloc;
} }
/* 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 *set,
source_location loc,
enum location_resolution_kind lrk)
{
const struct line_map *map;
expanded_location xloc;
loc = linemap_resolve_location (set, loc, lrk, &map);
xloc = linemap_expand_location (map, loc);
return xloc;
}
/* Dump debugging information about source location LOC into the file /* Dump debugging information about source location LOC into the file
stream STREAM. SET is the line map set LOC comes from. */ stream STREAM. SET is the line map set LOC comes from. */
...@@ -1145,32 +1163,37 @@ linemap_dump_location (struct line_maps *set, ...@@ -1145,32 +1163,37 @@ linemap_dump_location (struct line_maps *set,
{ {
const struct line_map *map; const struct line_map *map;
source_location location; source_location location;
const char *path, *from; const char *path = "", *from = "";
int l,c,s,e; int l = -1, c = -1, s = -1, e = -1;
if (loc == 0) if (loc == 0)
return; return;
location = location =
linemap_resolve_location (set, loc, LRK_MACRO_DEFINITION_LOCATION, &map); linemap_resolve_location (set, loc, LRK_MACRO_DEFINITION_LOCATION, &map);
path = LINEMAP_FILE (map);
if (map == NULL)
/* Only reserved locations can be tolerated in this case. */
linemap_assert (location < RESERVED_LOCATION_COUNT);
else
{
path = LINEMAP_FILE (map);
l = SOURCE_LINE (map, location); l = SOURCE_LINE (map, location);
c = SOURCE_COLUMN (map, location); c = SOURCE_COLUMN (map, location);
s = LINEMAP_SYSP (map) != 0; s = LINEMAP_SYSP (map) != 0;
e = location != loc; e = location != loc;
if (e) if (e)
from = "N/A"; from = "N/A";
else else
from = (INCLUDED_FROM (set, map)) from = (INCLUDED_FROM (set, map))
? LINEMAP_FILE (INCLUDED_FROM (set, map)) ? LINEMAP_FILE (INCLUDED_FROM (set, map))
: "<NULL>"; : "<NULL>";
}
/* P: path, L: line, C: column, S: in-system-header, M: map address, /* P: path, L: line, C: column, S: in-system-header, M: map address,
E: macro expansion?. */ E: macro expansion?, LOC: original location, R: resolved location */
fprintf (stream, "{P:%s;F:%s;L:%d;C:%d;S:%d;M:%p;E:%d,LOC:%d}", fprintf (stream, "{P:%s;F:%s;L:%d;C:%d;S:%d;M:%p;E:%d,LOC:%d,R:%d}",
path, from, l, c, s, (void*)map, e, loc); path, from, l, c, s, (void*)map, e, loc, location);
} }
/* Compute and return statistics about the memory consumption of some /* Compute and return statistics about the memory consumption of some
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment