make_location (location_t caret, source_range src_range)
{
location_t pure_loc = get_pure_location (caret);
- return COMBINE_LOCATION_DATA (line_table, pure_loc, src_range, NULL, 0);
+ return line_table->get_or_create_combined_loc (pure_loc, src_range,
+ nullptr, 0);
}
/* An expanded_location stores the column in byte units. This function
fprintf (stderr, "Ad-hoc table entries used: " PRsa (5) "\n",
SIZE_AMOUNT (s.adhoc_table_entries_used));
fprintf (stderr, "optimized_ranges: " PRsa (5) "\n",
- SIZE_AMOUNT (line_table->num_optimized_ranges));
+ SIZE_AMOUNT (line_table->m_num_optimized_ranges));
fprintf (stderr, "unoptimized_ranges: " PRsa (5) "\n",
- SIZE_AMOUNT (line_table->num_unoptimized_ranges));
+ SIZE_AMOUNT (line_table->m_num_unoptimized_ranges));
fprintf (stderr, "\n");
}
if (locus == UNKNOWN_LOCATION)
return locus;
- return COMBINE_LOCATION_DATA (line_table, locus, src_range, block, discriminator);
+ return line_table->get_or_create_combined_loc (locus, src_range, block,
+ discriminator);
}
/* Return TRUE if LOCUS represents a location with a discriminator. */
saved_line_table = line_table;
line_table = ggc_alloc<line_maps> ();
linemap_init (line_table, BUILTINS_LOCATION);
- gcc_assert (saved_line_table->reallocator);
- line_table->reallocator = saved_line_table->reallocator;
- gcc_assert (saved_line_table->round_alloc_size);
- line_table->round_alloc_size = saved_line_table->round_alloc_size;
+ gcc_assert (saved_line_table->m_reallocator);
+ line_table->m_reallocator = saved_line_table->m_reallocator;
+ gcc_assert (saved_line_table->m_round_alloc_size);
+ line_table->m_round_alloc_size = saved_line_table->m_round_alloc_size;
line_table->default_range_bits = 0;
}
saved_line_table = line_table;
line_table = ggc_alloc<line_maps> ();
linemap_init (line_table, BUILTINS_LOCATION);
- gcc_assert (saved_line_table->reallocator);
- line_table->reallocator = saved_line_table->reallocator;
- gcc_assert (saved_line_table->round_alloc_size);
- line_table->round_alloc_size = saved_line_table->round_alloc_size;
+ gcc_assert (saved_line_table->m_reallocator);
+ line_table->m_reallocator = saved_line_table->m_reallocator;
+ gcc_assert (saved_line_table->m_round_alloc_size);
+ line_table->m_round_alloc_size = saved_line_table->m_round_alloc_size;
line_table->default_range_bits = case_.m_default_range_bits;
if (case_.m_base_location)
{
location_t make_location (location_t caret,
location_t start,
location_t finish);
-
+
+ location_t
+ get_or_create_combined_loc (location_t locus,
+ source_range src_range,
+ void *data,
+ unsigned discriminator);
+
+ private:
+ bool can_be_stored_compactly_p (location_t locus,
+ source_range src_range,
+ void *data,
+ unsigned discriminator) const;
+ source_range get_range_from_adhoc_loc (location_t loc) const;
+
+ public:
maps_info_ordinary info_ordinary;
maps_info_macro info_macro;
unsigned int max_column_hint;
/* The allocator to use when resizing 'maps', defaults to xrealloc. */
- line_map_realloc GTY((callback)) reallocator;
+ line_map_realloc GTY((callback)) m_reallocator;
/* The allocators' function used to know the actual size it
allocated, for a certain allocation size requested. */
- line_map_round_alloc_size_func GTY((callback)) round_alloc_size;
+ line_map_round_alloc_size_func GTY((callback)) m_round_alloc_size;
- struct location_adhoc_data_map location_adhoc_data_map;
+ struct location_adhoc_data_map m_location_adhoc_data_map;
/* The special location value that is used as spelling location for
built-in tokens. */
/* The default value of range_bits in ordinary line maps. */
unsigned int default_range_bits;
- unsigned int num_optimized_ranges;
- unsigned int num_unoptimized_ranges;
+ unsigned int m_num_optimized_ranges;
+ unsigned int m_num_unoptimized_ranges;
};
/* Returns the number of allocated maps so far. MAP_KIND shall be TRUE
return (line_map_macro *)LINEMAPS_LAST_ALLOCATED_MAP (set, true);
}
-extern location_t get_combined_adhoc_loc (line_maps *, location_t,
- source_range, void *, unsigned);
extern void *get_data_from_adhoc_loc (const line_maps *, location_t);
extern unsigned get_discriminator_from_adhoc_loc (const line_maps *, location_t);
extern location_t get_location_from_adhoc_loc (const line_maps *,
extern location_t get_pure_location (const line_maps *set, location_t loc);
-/* Combine LOC and BLOCK, giving a combined adhoc location. */
-
-inline location_t
-COMBINE_LOCATION_DATA (class line_maps *set,
- location_t loc,
- source_range src_range,
- void *block,
- unsigned discriminator)
-{
- return get_combined_adhoc_loc (set, loc, src_range, block, discriminator);
-}
-
extern void rebuild_location_adhoc_htab (class line_maps *);
/* Initialize a line map set. SET is the line map set to initialize
line_maps::~line_maps ()
{
- if (location_adhoc_data_map.htab)
- htab_delete (location_adhoc_data_map.htab);
+ if (m_location_adhoc_data_map.htab)
+ htab_delete (m_location_adhoc_data_map.htab);
}
/* Hash function for location_adhoc_data hashtable. */
void
rebuild_location_adhoc_htab (line_maps *set)
{
- set->location_adhoc_data_map.htab =
+ set->m_location_adhoc_data_map.htab =
htab_create (100, location_adhoc_data_hash, location_adhoc_data_eq, NULL);
- for (auto p = set->location_adhoc_data_map.data,
- end = p + set->location_adhoc_data_map.curr_loc;
+ for (auto p = set->m_location_adhoc_data_map.data,
+ end = p + set->m_location_adhoc_data_map.curr_loc;
p != end; ++p)
{
const auto slot = reinterpret_cast<location_adhoc_data **>
- (htab_find_slot (set->location_adhoc_data_map.htab, p, INSERT));
+ (htab_find_slot (set->m_location_adhoc_data_map.htab, p, INSERT));
*slot = p;
}
}
Can the given LOCUS + SRC_RANGE and DATA pointer be stored compactly
within a location_t, without needing to use an ad-hoc location. */
-static bool
-can_be_stored_compactly_p (const line_maps *set,
- location_t locus,
- source_range src_range,
- void *data,
- unsigned discriminator)
+bool
+line_maps::can_be_stored_compactly_p (location_t locus,
+ source_range src_range,
+ void *data,
+ unsigned discriminator) const
{
/* If there's an ad-hoc pointer, we can't store it directly in the
location_t, we need the lookaside. */
/* All 3 locations must be within ordinary maps, typically, the same
ordinary map. */
- location_t lowest_macro_loc = LINEMAPS_MACRO_LOWEST_LOCATION (set);
+ location_t lowest_macro_loc = LINEMAPS_MACRO_LOWEST_LOCATION (this);
if (locus >= lowest_macro_loc)
return false;
if (src_range.m_start >= lowest_macro_loc)
/* Combine LOCUS and DATA to a combined adhoc loc. */
location_t
-get_combined_adhoc_loc (line_maps *set,
- location_t locus,
- source_range src_range,
- void *data,
- unsigned discriminator)
+line_maps::get_or_create_combined_loc (location_t locus,
+ source_range src_range,
+ void *data,
+ unsigned discriminator)
{
struct location_adhoc_data lb;
struct location_adhoc_data **slot;
if (IS_ADHOC_LOC (locus))
- locus = get_location_from_adhoc_loc (set, locus);
+ locus = get_location_from_adhoc_loc (this, locus);
if (locus == 0 && data == NULL)
return 0;
compressed ranges. */
linemap_assert (locus < RESERVED_LOCATION_COUNT
|| locus >= LINE_MAP_MAX_LOCATION_WITH_PACKED_RANGES
- || locus >= LINEMAPS_MACRO_LOWEST_LOCATION (set)
- || pure_location_p (set, locus));
+ || locus >= LINEMAPS_MACRO_LOWEST_LOCATION (this)
+ || pure_location_p (locus));
/* Consider short-range optimization. */
- if (can_be_stored_compactly_p (set, locus, src_range, data, discriminator))
+ if (can_be_stored_compactly_p (locus, src_range, data, discriminator))
{
/* The low bits ought to be clear. */
- linemap_assert (pure_location_p (set, locus));
- const line_map *map = linemap_lookup (set, locus);
+ linemap_assert (pure_location_p (locus));
+ const line_map *map = linemap_lookup (this, locus);
const line_map_ordinary *ordmap = linemap_check_ordinary (map);
unsigned int int_diff = src_range.m_finish - src_range.m_start;
unsigned int col_diff = (int_diff >> ordmap->m_range_bits);
if (col_diff < (1U << ordmap->m_range_bits))
{
location_t packed = locus | col_diff;
- set->num_optimized_ranges++;
+ m_num_optimized_ranges++;
return packed;
}
}
return locus;
if (!data && discriminator == 0)
- set->num_unoptimized_ranges++;
+ m_num_unoptimized_ranges++;
lb.locus = locus;
lb.src_range = src_range;
lb.data = data;
lb.discriminator = discriminator;
slot = (struct location_adhoc_data **)
- htab_find_slot (set->location_adhoc_data_map.htab, &lb, INSERT);
+ htab_find_slot (m_location_adhoc_data_map.htab, &lb, INSERT);
if (*slot == NULL)
{
- if (set->location_adhoc_data_map.curr_loc >=
- set->location_adhoc_data_map.allocated)
+ if (m_location_adhoc_data_map.curr_loc >=
+ m_location_adhoc_data_map.allocated)
{
- const auto orig_data = set->location_adhoc_data_map.data;
+ const auto orig_data = m_location_adhoc_data_map.data;
/* Cast away extern "C" from the type of xrealloc. */
- line_map_realloc reallocator = (set->reallocator
- ? set->reallocator
+ line_map_realloc reallocator = (m_reallocator
+ ? m_reallocator
: (line_map_realloc) xrealloc);
- if (set->location_adhoc_data_map.allocated == 0)
- set->location_adhoc_data_map.allocated = 128;
+ if (m_location_adhoc_data_map.allocated == 0)
+ m_location_adhoc_data_map.allocated = 128;
else
- set->location_adhoc_data_map.allocated *= 2;
- set->location_adhoc_data_map.data = (struct location_adhoc_data *)
- reallocator (set->location_adhoc_data_map.data,
- set->location_adhoc_data_map.allocated
+ m_location_adhoc_data_map.allocated *= 2;
+ m_location_adhoc_data_map.data = (struct location_adhoc_data *)
+ reallocator (m_location_adhoc_data_map.data,
+ m_location_adhoc_data_map.allocated
* sizeof (struct location_adhoc_data));
- if (set->location_adhoc_data_map.allocated > 128)
+ if (m_location_adhoc_data_map.allocated > 128)
{
location_adhoc_data *param[2]
- = {orig_data, set->location_adhoc_data_map.data};
- htab_traverse (set->location_adhoc_data_map.htab,
+ = {orig_data, m_location_adhoc_data_map.data};
+ htab_traverse (m_location_adhoc_data_map.htab,
location_adhoc_data_update, param);
}
}
- *slot = set->location_adhoc_data_map.data
- + set->location_adhoc_data_map.curr_loc;
- set->location_adhoc_data_map.data[set->location_adhoc_data_map.curr_loc++]
+ *slot = m_location_adhoc_data_map.data
+ + m_location_adhoc_data_map.curr_loc;
+ m_location_adhoc_data_map.data[m_location_adhoc_data_map.curr_loc++]
= lb;
}
- return ((*slot) - set->location_adhoc_data_map.data) | 0x80000000;
+ return ((*slot) - m_location_adhoc_data_map.data) | 0x80000000;
}
/* Construct a location with caret at CARET, ranging from START to
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);
+ location_t combined_loc = get_or_create_combined_loc (pure_loc,
+ src_range,
+ nullptr,
+ 0);
return combined_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;
+ return set->m_location_adhoc_data_map.data[loc & MAX_LOCATION_T].data;
}
unsigned
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 set->m_location_adhoc_data_map.data[loc & MAX_LOCATION_T].discriminator;
}
/* Return the location for the adhoc 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 set->m_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 line_maps *set, location_t loc)
+source_range
+line_maps::get_range_from_adhoc_loc (location_t loc) const
{
linemap_assert (IS_ADHOC_LOC (loc));
- return set->location_adhoc_data_map.data[loc & MAX_LOCATION_T].src_range;
+ return m_location_adhoc_data_map.data[loc & MAX_LOCATION_T].src_range;
}
/* Get the source_range of location LOC, either from the ad-hoc
line_maps::get_range_from_loc (location_t loc) const
{
if (IS_ADHOC_LOC (loc))
- return get_range_from_adhoc_loc (this, loc);
+ return get_range_from_adhoc_loc (loc);
/* For ordinary maps, extract packed range. */
if (loc >= RESERVED_LOCATION_COUNT
new (set) line_maps();
#endif
/* Set default reallocator (used for initial alloc too). */
- set->reallocator = xrealloc;
+ set->m_reallocator = xrealloc;
set->highest_location = RESERVED_LOCATION_COUNT - 1;
set->highest_line = RESERVED_LOCATION_COUNT - 1;
- set->location_adhoc_data_map.htab =
+ set->m_location_adhoc_data_map.htab =
htab_create (100, location_adhoc_data_hash, location_adhoc_data_eq, NULL);
set->builtin_location = builtin_location;
}
allocator may well be larger than what we ask for. Use this
hook to find what that size is. */
size_t alloc_size
- = set->round_alloc_size (num_maps_allocated * size_of_a_map);
+ = set->m_round_alloc_size (num_maps_allocated * size_of_a_map);
/* Now alloc_size contains the exact memory size we would get if
we have asked for the initial alloc_size amount of memory.
Let's get back to the number of map that amounts to. */
unsigned num_maps = alloc_size / size_of_a_map;
- buffer = set->reallocator (buffer, num_maps * size_of_a_map);
+ buffer = set->m_reallocator (buffer, num_maps * size_of_a_map);
memset ((char *)buffer + num_maps_used * size_of_a_map, 0,
(num_maps - num_maps_used) * size_of_a_map);
if (macro_p)
map->macro = macro_node;
map->n_tokens = num_tokens;
map->macro_locations
- = (location_t*) set->reallocator (NULL,
- 2 * num_tokens
- * sizeof (location_t));
+ = (location_t*) set->m_reallocator (nullptr,
+ 2 * num_tokens * sizeof (location_t));
map->expansion = expansion;
memset (MACRO_MAP_LOCATIONS (map), 0,
2 * num_tokens * sizeof (location_t));
s->macro_maps_used_size = macro_maps_used_size;
s->duplicated_macro_maps_locations_size =
duplicated_macro_maps_locations_size;
- s->adhoc_table_size = (set->location_adhoc_data_map.allocated
+ s->adhoc_table_size = (set->m_location_adhoc_data_map.allocated
* sizeof (struct location_adhoc_data));
- s->adhoc_table_entries_used = set->location_adhoc_data_map.curr_loc;
+ s->adhoc_table_entries_used = set->m_location_adhoc_data_map.curr_loc;
}