public:
~line_maps ();
+
+ bool pure_location_p (location_t loc) const;
+ location_t get_pure_location (location_t loc) const;
+
+ source_range get_range_from_loc (location_t loc) const;
+ location_t get_start (location_t loc) const
+ {
+ return get_range_from_loc (loc).m_start;
+ }
+ location_t
+ get_finish (location_t loc) const
+ {
+ return get_range_from_loc (loc).m_finish;
+ }
+
+ location_t make_location (location_t caret,
+ location_t start,
+ location_t finish);
maps_info_ordinary info_ordinary;
extern location_t get_location_from_adhoc_loc (const line_maps *,
location_t);
-extern source_range get_range_from_loc (line_maps *set, location_t loc);
-extern unsigned get_discriminator_from_loc (line_maps *set, location_t loc);
+extern source_range get_range_from_loc (const line_maps *set, location_t loc);
+extern unsigned get_discriminator_from_loc (const line_maps *set, location_t loc);
/* Get whether location LOC is a "pure" location, or
whether it is an ad-hoc location, or embeds range information. */
bool
-pure_location_p (line_maps *set, location_t loc);
+pure_location_p (const line_maps *set, location_t loc);
/* Given location LOC within SET, strip away any packed range information
or ad-hoc information. */
-extern location_t get_pure_location (line_maps *set, location_t loc);
+extern location_t get_pure_location (const line_maps *set, location_t loc);
/* Combine LOC and BLOCK, giving a combined adhoc location. */
/* Check for and warn about line_maps entered but not exited. */
-extern void linemap_check_files_exited (class line_maps *);
+extern void linemap_check_files_exited (const line_maps *);
/* Return a location_t for the start (i.e. column==0) of
(physical) line TO_LINE in the current source file (as in the
/* Returns TRUE if the line table set tracks token locations across
macro expansion, FALSE otherwise. */
-bool linemap_tracks_macro_expansion_locs_p (class line_maps *);
+bool linemap_tracks_macro_expansion_locs_p (const line_maps *);
/* Return the name of the macro associated to MACRO_MAP. */
const char* linemap_map_get_macro_name (const line_map_macro *);
Note that this function returns 1 if LOCATION belongs to a token
that is part of a macro replacement-list defined in a system
header, but expanded in a non-system file. */
-int linemap_location_in_system_header_p (class line_maps *,
+int linemap_location_in_system_header_p (const line_maps *,
location_t);
/* Return TRUE if LOCATION is a source code location of a token that is part of
/* TRUE if LOCATION is a source code location of a token that is part of the
definition of a macro, FALSE otherwise. */
-bool linemap_location_from_macro_definition_p (class line_maps *,
+bool linemap_location_from_macro_definition_p (const line_maps *,
location_t);
/* With the precondition that LOCATION is the locus of a token that is
expansion of MACRO_MAP, return the locus of that argument in the
context of the caller of MACRO_MAP. */
-extern location_t linemap_macro_map_loc_unwind_toward_spelling
- (line_maps *set, const line_map_macro *macro_map, location_t location);
+extern location_t
+linemap_macro_map_loc_unwind_toward_spelling (const line_maps *set,
+ const line_map_macro *macro_map,
+ location_t location);
/* location_t values from 0 to RESERVED_LOCATION_COUNT-1 will
be reserved for libcpp user as special values, no token from libcpp
}
/* The linemap containing the included-from location of MAP. */
-const line_map_ordinary *linemap_included_from_linemap
- (line_maps *set, const line_map_ordinary *map);
+const line_map_ordinary *
+linemap_included_from_linemap (const line_maps *set,
+ const line_map_ordinary *map);
/* True if the map is at the bottom of the include stack. */
return ord_map->sysp;
}
-const struct line_map *first_map_in_common (line_maps *set,
+const struct line_map *first_map_in_common (const line_maps *set,
location_t loc0,
location_t loc1,
location_t *res_loc0,
comes before the token of POST, 0 if PRE denotes the location of
the same token as the token for POST, and a negative value
otherwise. */
-int linemap_compare_locations (class line_maps *set,
+int linemap_compare_locations (const line_maps *set,
location_t pre,
location_t post);
topogically before the token denoted by location LOC_B, or if they
are equal. */
inline bool
-linemap_location_before_p (class line_maps *set,
+linemap_location_before_p (const line_maps *set,
location_t loc_a,
location_t loc_b)
{
resolves to a location reserved for the client code, like
UNKNOWN_LOCATION or BUILTINS_LOCATION in GCC. */
-location_t linemap_resolve_location (class line_maps *,
+location_t linemap_resolve_location (const line_maps *,
location_t loc,
enum location_resolution_kind lrk,
const line_map_ordinary **loc_map);
the point where M' was expanded. LOC_MAP is an output parameter.
When non-NULL, *LOC_MAP is set to the map of the returned
location. */
-location_t linemap_unwind_toward_expansion (class line_maps *,
+location_t linemap_unwind_toward_expansion (const line_maps *,
location_t loc,
const line_map **loc_map);
*MAP is set to the map of the returned location if the later is
different from LOC. */
-location_t linemap_unwind_to_first_non_reserved_loc (class line_maps *,
+location_t linemap_unwind_to_first_non_reserved_loc (const line_maps *,
location_t loc,
const line_map **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 (class line_maps *,
+expanded_location linemap_expand_location (const line_maps *,
const line_map *,
location_t loc);
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 (class line_maps * set,
+bool linemap_get_file_highest_location (const line_maps * set,
const char *file_name,
location_t *loc);
/* Compute and return statistics about the memory consumption of some
parts of the line table SET. */
-void linemap_get_statistics (line_maps *, struct linemap_stats *);
+void linemap_get_statistics (const line_maps *, struct linemap_stats *);
/* Dump debugging information about source location LOC into the file
stream STREAM. SET is the line map set LOC comes from. */
-void linemap_dump_location (line_maps *, location_t, FILE *);
+void linemap_dump_location (const line_maps *, location_t, FILE *);
/* 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. */
-void linemap_dump (FILE *, line_maps *, unsigned, bool);
+void linemap_dump (FILE *, const line_maps *, unsigned, bool);
/* Dump line table SET to STREAM. If STREAM is NULL, stderr is used.
NUM_ORDINARY specifies how many ordinary maps to dump. NUM_MACRO
specifies how many macro maps to dump. */
-void line_table_dump (FILE *, line_maps *, unsigned int, unsigned int);
+void line_table_dump (FILE *, const line_maps *, unsigned int, unsigned int);
/* An enum for distinguishing the various parts within a location_t. */
static location_t linemap_macro_map_loc_to_exp_point
(const line_map_macro *, location_t);
static location_t linemap_macro_loc_to_spelling_point
-(line_maps *, location_t, const line_map_ordinary **);
-static location_t linemap_macro_loc_to_def_point (line_maps *,
+(const line_maps *, location_t, const line_map_ordinary **);
+static location_t linemap_macro_loc_to_def_point (const line_maps *,
location_t,
const line_map_ordinary **);
-static location_t linemap_macro_loc_to_exp_point (line_maps *,
+static location_t linemap_macro_loc_to_exp_point (const line_maps *,
location_t,
const line_map_ordinary **);
within a location_t, without needing to use an ad-hoc location. */
static bool
-can_be_stored_compactly_p (line_maps *set,
+can_be_stored_compactly_p (const line_maps *set,
location_t locus,
source_range src_range,
void *data,
return ((*slot) - set->location_adhoc_data_map.data) | 0x80000000;
}
+/* Construct a location with caret at CARET, ranging from START to
+ FINISH.
+
+ For example, consider:
+
+ 11111111112
+ 12345678901234567890
+ 522
+ 523 return foo + bar;
+ ~~~~^~~~~
+ 524
+
+ The location's caret is at the "+", line 523 column 15, but starts
+ earlier, at the "f" of "foo" at column 11. The finish is at the "r"
+ of "bar" at column 19. */
+
+location_t
+line_maps::make_location (location_t caret, location_t start, location_t finish)
+{
+ location_t pure_loc = get_pure_location (caret);
+ source_range src_range;
+ src_range.m_start = get_start (start);
+ src_range.m_finish = get_finish (finish);
+ location_t combined_loc = COMBINE_LOCATION_DATA (this,
+ pure_loc,
+ src_range,
+ NULL,
+ 0);
+ return combined_loc;
+}
+
/* Return the data for the adhoc loc. */
void *
-get_data_from_adhoc_loc (const class line_maps *set, location_t loc)
+get_data_from_adhoc_loc (const line_maps *set, location_t loc)
{
linemap_assert (IS_ADHOC_LOC (loc));
return set->location_adhoc_data_map.data[loc & MAX_LOCATION_T].data;
}
unsigned
-get_discriminator_from_adhoc_loc (const class line_maps *set, location_t loc)
+get_discriminator_from_adhoc_loc (const line_maps *set, location_t loc)
{
linemap_assert (IS_ADHOC_LOC (loc));
return set->location_adhoc_data_map.data[loc & MAX_LOCATION_T].discriminator;
/* Return the location for the adhoc loc. */
location_t
-get_location_from_adhoc_loc (const class line_maps *set, location_t loc)
+get_location_from_adhoc_loc (const line_maps *set, location_t loc)
{
linemap_assert (IS_ADHOC_LOC (loc));
return set->location_adhoc_data_map.data[loc & MAX_LOCATION_T].locus;
/* Return the source_range for adhoc location LOC. */
static source_range
-get_range_from_adhoc_loc (const class line_maps *set, location_t loc)
+get_range_from_adhoc_loc (const line_maps *set, location_t loc)
{
linemap_assert (IS_ADHOC_LOC (loc));
return set->location_adhoc_data_map.data[loc & MAX_LOCATION_T].src_range;
lookaside table, or embedded inside LOC itself. */
source_range
-get_range_from_loc (line_maps *set,
- location_t loc)
+line_maps::get_range_from_loc (location_t loc) const
{
if (IS_ADHOC_LOC (loc))
- return get_range_from_adhoc_loc (set, loc);
+ return get_range_from_adhoc_loc (this, loc);
/* For ordinary maps, extract packed range. */
if (loc >= RESERVED_LOCATION_COUNT
- && loc < LINEMAPS_MACRO_LOWEST_LOCATION (set)
+ && loc < LINEMAPS_MACRO_LOWEST_LOCATION (this)
&& loc <= LINE_MAP_MAX_LOCATION_WITH_PACKED_RANGES)
{
- const line_map *map = linemap_lookup (set, loc);
+ const line_map *map = linemap_lookup (this, loc);
const line_map_ordinary *ordmap = linemap_check_ordinary (map);
source_range result;
int offset = loc & ((1 << ordmap->m_range_bits) - 1);
return source_range::from_location (loc);
}
+source_range
+get_range_from_loc (const line_maps *set,
+ location_t loc)
+{
+ return set->get_range_from_loc (loc);
+}
+
unsigned
-get_discriminator_from_loc (line_maps *set,
+get_discriminator_from_loc (const line_maps *set,
location_t loc)
{
if (IS_ADHOC_LOC (loc))
whether it is an ad-hoc location, or embeds range information. */
bool
-pure_location_p (line_maps *set, location_t loc)
+line_maps::pure_location_p (location_t loc) const
{
if (IS_ADHOC_LOC (loc))
return false;
- const line_map *map = linemap_lookup (set, loc);
+ const line_map *map = linemap_lookup (this, loc);
if (map == NULL)
return true;
const line_map_ordinary *ordmap = linemap_check_ordinary (map);
return true;
}
+bool
+pure_location_p (const line_maps *set, location_t loc)
+{
+ return set->pure_location_p (loc);
+}
+
/* Given location LOC within SET, strip away any packed range information
or ad-hoc information. */
location_t
-get_pure_location (line_maps *set, location_t loc)
+line_maps::get_pure_location (location_t loc) const
{
if (IS_ADHOC_LOC (loc))
- loc = get_location_from_adhoc_loc (set, loc);
+ loc = get_location_from_adhoc_loc (this, loc);
- if (loc >= LINEMAPS_MACRO_LOWEST_LOCATION (set))
+ if (loc >= LINEMAPS_MACRO_LOWEST_LOCATION (this))
return loc;
if (loc < RESERVED_LOCATION_COUNT)
return loc;
- const line_map *map = linemap_lookup (set, loc);
+ const line_map *map = linemap_lookup (this, loc);
const line_map_ordinary *ordmap = linemap_check_ordinary (map);
return loc & ~((1 << ordmap->m_range_bits) - 1);
}
+location_t
+get_pure_location (const line_maps *set, location_t loc)
+{
+ return set->get_pure_location (loc);
+}
+
/* Initialize a line map set. */
void
NULL if MAP was not an include. */
const line_map_ordinary *
-linemap_included_from_linemap (line_maps *set, const line_map_ordinary *map)
+linemap_included_from_linemap (const 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 (line_maps *set)
+linemap_check_files_exited (const line_maps *set)
{
/* Depending upon whether we are handling preprocessed input or
not, this can be a user error or an ICE. */
macro expansion, FALSE otherwise. */
bool
-linemap_tracks_macro_expansion_locs_p (line_maps *set)
+linemap_tracks_macro_expansion_locs_p (const line_maps *set)
{
return LINEMAPS_MACRO_MAPS (set) != NULL;
}
In other words, this returns the xI location presented in the
comments of line_map_macro above. */
location_t
-linemap_macro_map_loc_unwind_toward_spelling (line_maps *set,
+linemap_macro_map_loc_unwind_toward_spelling (const line_maps *set,
const line_map_macro* map,
location_t location)
{
macro expansion point. */
int
-linemap_get_expansion_line (line_maps *set,
+linemap_get_expansion_line (const line_maps *set,
location_t location)
{
const line_map_ordinary *map = NULL;
SET is the line map set LOCATION comes from. */
const char*
-linemap_get_expansion_filename (line_maps *set,
+linemap_get_expansion_filename (const line_maps *set,
location_t location)
{
const struct line_map_ordinary *map = NULL;
header, but expanded in a non-system file. */
int
-linemap_location_in_system_header_p (line_maps *set,
+linemap_location_in_system_header_p (const line_maps *set,
location_t location)
{
const struct line_map *map = NULL;
virtual location of the token inside the resulting macro. */
static const struct line_map*
-first_map_in_common_1 (line_maps *set,
+first_map_in_common_1 (const line_maps *set,
location_t *loc0,
location_t *loc1)
{
return of a non-NULL result. */
const struct line_map*
-first_map_in_common (line_maps *set,
+first_map_in_common (const line_maps *set,
location_t loc0,
location_t loc1,
location_t *res_loc0,
otherwise. */
int
-linemap_compare_locations (line_maps *set,
+linemap_compare_locations (const line_maps *set,
location_t pre,
location_t post)
{
This is a subroutine for linemap_resolve_location. */
static location_t
-linemap_macro_loc_to_spelling_point (line_maps *set,
+linemap_macro_loc_to_spelling_point (const line_maps *set,
location_t location,
const line_map_ordinary **original_map)
{
This is a subroutine of linemap_resolve_location. */
static location_t
-linemap_macro_loc_to_def_point (line_maps *set,
+linemap_macro_loc_to_def_point (const line_maps *set,
location_t location,
const line_map_ordinary **original_map)
{
This is a subroutine of linemap_resolve_location. */
static location_t
-linemap_macro_loc_to_exp_point (line_maps *set,
+linemap_macro_loc_to_exp_point (const line_maps *set,
location_t location,
const line_map_ordinary **original_map)
{
UNKNOWN_LOCATION or BUILTINS_LOCATION in GCC. */
location_t
-linemap_resolve_location (line_maps *set,
+linemap_resolve_location (const line_maps *set,
location_t loc,
enum location_resolution_kind lrk,
const line_map_ordinary **map)
definition of a macro, FALSE otherwise. */
bool
-linemap_location_from_macro_definition_p (line_maps *set,
+linemap_location_from_macro_definition_p (const line_maps *set,
location_t loc)
{
if (IS_ADHOC_LOC (loc))
to the map of the returned location. */
location_t
-linemap_unwind_toward_expansion (line_maps *set,
+linemap_unwind_toward_expansion (const line_maps *set,
location_t loc,
const struct line_map **map)
{
*MAP is set to the map of the returned location if the later is
different from LOC. */
location_t
-linemap_unwind_to_first_non_reserved_loc (line_maps *set,
+linemap_unwind_to_first_non_reserved_loc (const line_maps *set,
location_t loc,
const struct line_map **map)
{
location is returned. */
expanded_location
-linemap_expand_location (line_maps *set,
+linemap_expand_location (const line_maps *set,
const struct line_map *map,
location_t loc)
dump a macro map, false otherwise. */
void
-linemap_dump (FILE *stream, class line_maps *set, unsigned ix, bool is_macro)
+linemap_dump (FILE *stream, const line_maps *set, unsigned ix, bool is_macro)
{
const char *const lc_reasons_v[LC_HWM]
= { "LC_ENTER", "LC_LEAVE", "LC_RENAME", "LC_RENAME_VERBATIM",
stream STREAM. SET is the line map set LOC comes from. */
void
-linemap_dump_location (line_maps *set,
+linemap_dump_location (const line_maps *set,
location_t loc,
FILE *stream)
{
location emitted for that file. */
bool
-linemap_get_file_highest_location (line_maps *set,
+linemap_get_file_highest_location (const line_maps *set,
const char *file_name,
location_t *loc)
{
parts of the line table SET. */
void
-linemap_get_statistics (line_maps *set,
+linemap_get_statistics (const line_maps *set,
struct linemap_stats *s)
{
long ordinary_maps_allocated_size, ordinary_maps_used_size,
specifies how many macro maps to dump. */
void
-line_table_dump (FILE *stream, class line_maps *set, unsigned int num_ordinary,
+line_table_dump (FILE *stream, const line_maps *set, unsigned int num_ordinary,
unsigned int num_macro)
{
unsigned int i;