aboutsummaryrefslogtreecommitdiff
path: root/libcpp/line-map.c
diff options
context:
space:
mode:
Diffstat (limited to 'libcpp/line-map.c')
-rw-r--r--libcpp/line-map.c118
1 files changed, 40 insertions, 78 deletions
diff --git a/libcpp/line-map.c b/libcpp/line-map.c
index 264ae20..de6eafc 100644
--- a/libcpp/line-map.c
+++ b/libcpp/line-map.c
@@ -1993,29 +1993,13 @@ source_range::intersects_line_p (const char *file, int line) const
/* Construct a rich_location with location LOC as its initial range. */
-rich_location::rich_location (line_maps *set, source_location loc) :
- m_loc (loc),
+rich_location::rich_location (line_maps */*set*/, source_location loc) :
m_num_ranges (0),
+ m_column_override (0),
m_have_expanded_location (false),
m_num_fixit_hints (0)
{
- /* Set up the 0th range, extracting any range from LOC. */
- source_range src_range = get_range_from_loc (set, loc);
- add_range (src_range, true);
- m_ranges[0].m_caret = lazily_expand_location ();
-}
-
-/* Construct a rich_location with source_range SRC_RANGE as its
- initial range. */
-
-rich_location::rich_location (source_range src_range)
-: m_loc (src_range.m_start),
- m_num_ranges (0),
- m_have_expanded_location (false),
- m_num_fixit_hints (0)
-{
- /* Set up the 0th range: */
- add_range (src_range, true);
+ add_range (loc, true);
}
/* The destructor for class rich_location. */
@@ -2026,73 +2010,62 @@ rich_location::~rich_location ()
delete m_fixit_hints[i];
}
+/* Get location IDX within this rich_location. */
+
+source_location
+rich_location::get_loc (unsigned int idx) const
+{
+ linemap_assert (idx < m_num_ranges);
+ return m_ranges[idx].m_loc;
+}
+
+/* Expand location IDX within this rich_location. */
/* Get an expanded_location for this rich_location's primary
location. */
expanded_location
-rich_location::lazily_expand_location ()
+rich_location::get_expanded_location (unsigned int idx)
{
- if (!m_have_expanded_location)
- {
- m_expanded_location
- = linemap_client_expand_location_to_spelling_point (m_loc);
- m_have_expanded_location = true;
- }
-
- return m_expanded_location;
+ if (idx == 0)
+ {
+ /* Cache the expansion of the primary location. */
+ if (!m_have_expanded_location)
+ {
+ m_expanded_location
+ = linemap_client_expand_location_to_spelling_point (get_loc (0));
+ if (m_column_override)
+ m_expanded_location.column = m_column_override;
+ m_have_expanded_location = true;
+ }
+
+ return m_expanded_location;
+ }
+ else
+ return linemap_client_expand_location_to_spelling_point (get_loc (idx));
}
-/* Set the column of the primary location. This can only be called for
- rich_location instances for which the primary location has
- caret==start==finish. */
+/* Set the column of the primary location, with 0 meaning
+ "don't override it". */
void
rich_location::override_column (int column)
{
- lazily_expand_location ();
- gcc_assert (m_ranges[0].m_show_caret_p);
- gcc_assert (m_ranges[0].m_caret.column == m_expanded_location.column);
- gcc_assert (m_ranges[0].m_start.column == m_expanded_location.column);
- gcc_assert (m_ranges[0].m_finish.column == m_expanded_location.column);
- m_expanded_location.column = column;
- m_ranges[0].m_caret.column = column;
- m_ranges[0].m_start.column = column;
- m_ranges[0].m_finish.column = column;
+ m_column_override = column;
+ m_have_expanded_location = false;
}
/* Add the given range. */
void
-rich_location::add_range (source_location start, source_location finish,
- bool show_caret_p)
+rich_location::add_range (source_location loc, bool show_caret_p)
{
linemap_assert (m_num_ranges < MAX_RANGES);
location_range *range = &m_ranges[m_num_ranges++];
- range->m_start = linemap_client_expand_location_to_spelling_point (start);
- range->m_finish = linemap_client_expand_location_to_spelling_point (finish);
- range->m_caret = range->m_start;
+ range->m_loc = loc;
range->m_show_caret_p = show_caret_p;
}
-/* Add the given range. */
-
-void
-rich_location::add_range (source_range src_range, bool show_caret_p)
-{
- linemap_assert (m_num_ranges < MAX_RANGES);
-
- add_range (src_range.m_start, src_range.m_finish, show_caret_p);
-}
-
-void
-rich_location::add_range (location_range *src_range)
-{
- linemap_assert (m_num_ranges < MAX_RANGES);
-
- m_ranges[m_num_ranges++] = *src_range;
-}
-
/* Add or overwrite the location given by IDX, setting its location to LOC,
and setting its "should my caret be printed" flag to SHOW_CARET_P.
@@ -2107,7 +2080,7 @@ rich_location::add_range (location_range *src_range)
- the "%C" and "%L" format codes in the Fortran frontend. */
void
-rich_location::set_range (line_maps *set, unsigned int idx,
+rich_location::set_range (line_maps * /*set*/, unsigned int idx,
source_location loc, bool show_caret_p)
{
linemap_assert (idx < MAX_RANGES);
@@ -2116,28 +2089,17 @@ rich_location::set_range (line_maps *set, unsigned int idx,
on the end of the array. */
linemap_assert (idx <= m_num_ranges);
- source_range src_range = get_range_from_loc (set, loc);
-
location_range *locrange = &m_ranges[idx];
- locrange->m_start
- = linemap_client_expand_location_to_spelling_point (src_range.m_start);
- locrange->m_finish
- = linemap_client_expand_location_to_spelling_point (src_range.m_finish);
-
+ locrange->m_loc = loc;
locrange->m_show_caret_p = show_caret_p;
- locrange->m_caret
- = linemap_client_expand_location_to_spelling_point (loc);
/* Are we adding a range onto the end? */
if (idx == m_num_ranges)
m_num_ranges = idx + 1;
if (idx == 0)
- {
- m_loc = loc;
- /* Mark any cached value here as dirty. */
- m_have_expanded_location = false;
- }
+ /* Mark any cached value here as dirty. */
+ m_have_expanded_location = false;
}
/* Add a fixit-hint, suggesting insertion of NEW_CONTENT