diff options
Diffstat (limited to 'libcpp')
-rw-r--r-- | libcpp/include/rich-location.h | 14 | ||||
-rw-r--r-- | libcpp/line-map.cc | 29 |
2 files changed, 33 insertions, 10 deletions
diff --git a/libcpp/include/rich-location.h b/libcpp/include/rich-location.h index cc4f888..ae4886f 100644 --- a/libcpp/include/rich-location.h +++ b/libcpp/include/rich-location.h @@ -69,6 +69,9 @@ struct location_range /* If non-NULL, the label for this range. */ const range_label *m_label; + + /* If non-null, the name of the color to use for this range. */ + const char *m_highlight_color; }; /* A partially-embedded vec for use within rich_location for storing @@ -378,7 +381,8 @@ class rich_location /* Constructing from a location. */ rich_location (line_maps *set, location_t loc, - const range_label *label = NULL); + const range_label *label = nullptr, + const char *label_highlight_color = nullptr); /* Destructor. */ ~rich_location (); @@ -393,15 +397,19 @@ class rich_location location_t get_loc () const { return get_loc (0); } location_t get_loc (unsigned int idx) const; + void set_highlight_color (const char *highlight_color); + void add_range (location_t loc, enum range_display_kind range_display_kind = SHOW_RANGE_WITHOUT_CARET, - const range_label *label = NULL); + const range_label *label = nullptr, + const char *highlight_color = nullptr); void set_range (unsigned int idx, location_t loc, - enum range_display_kind range_display_kind); + enum range_display_kind range_display_kind, + const char *highlight_color = nullptr); unsigned int get_num_locations () const { return m_ranges.count (); } diff --git a/libcpp/line-map.cc b/libcpp/line-map.cc index d5200b3..41aee98 100644 --- a/libcpp/line-map.cc +++ b/libcpp/line-map.cc @@ -2160,8 +2160,9 @@ line_table_dump (FILE *stream, const line_maps *set, unsigned int num_ordinary, /* Construct a rich_location with location LOC as its initial range. */ rich_location::rich_location (line_maps *set, location_t loc, - const range_label *label) : - m_line_table (set), + const range_label *label, + const char *label_highlight_color) +: m_line_table (set), m_ranges (), m_column_override (0), m_have_expanded_location (false), @@ -2171,7 +2172,7 @@ rich_location::rich_location (line_maps *set, location_t loc, m_fixit_hints (), m_path (NULL) { - add_range (loc, SHOW_RANGE_WITH_CARET, label); + add_range (loc, SHOW_RANGE_WITH_CARET, label, label_highlight_color); } /* The destructor for class rich_location. */ @@ -2244,22 +2245,34 @@ rich_location::override_column (int column) m_have_expanded_location = false; } +/* Set (or clear) the highlight color of the primary location. */ + +void +rich_location::set_highlight_color (const char *highlight_color) +{ + location_range *locrange = get_range (0); + locrange->m_highlight_color = highlight_color; +} + /* Add the given range. */ void rich_location::add_range (location_t loc, enum range_display_kind range_display_kind, - const range_label *label) + const range_label *label, + const char *label_highlight_color) { location_range range; range.m_loc = loc; range.m_range_display_kind = range_display_kind; range.m_label = label; + range.m_highlight_color = label_highlight_color; m_ranges.push (range); } /* Add or overwrite the location given by IDX, setting its location to LOC, - and setting its m_range_display_kind to RANGE_DISPLAY_KIND. + setting its m_range_display_kind to RANGE_DISPLAY_KIND, and setting + its m_highlight_color to HIGHLIGHT_COLOR (which may be nullptr). It must either overwrite an existing location, or add one *exactly* on the end of the array. @@ -2273,19 +2286,21 @@ rich_location::add_range (location_t loc, void rich_location::set_range (unsigned int idx, location_t loc, - enum range_display_kind range_display_kind) + enum range_display_kind range_display_kind, + const char *highlight_color) { /* We can either overwrite an existing range, or add one exactly on the end of the array. */ linemap_assert (idx <= m_ranges.count ()); if (idx == m_ranges.count ()) - add_range (loc, range_display_kind); + add_range (loc, range_display_kind, nullptr, highlight_color); else { location_range *locrange = get_range (idx); locrange->m_loc = loc; locrange->m_range_display_kind = range_display_kind; + locrange->m_highlight_color = highlight_color; } if (idx == 0) |