aboutsummaryrefslogtreecommitdiff
path: root/libcpp
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2016-03-09 18:14:43 +0000
committerDavid Malcolm <dmalcolm@gcc.gnu.org>2016-03-09 18:14:43 +0000
commit40499f81a6a65d903a8b6469797c58c52eaf8008 (patch)
treeba81cb8d930007773d9d7556e938bf62e095d82e /libcpp
parentc9e336624a5f3d3845b9b4a070f29d074418bd73 (diff)
downloadgcc-40499f81a6a65d903a8b6469797c58c52eaf8008.zip
gcc-40499f81a6a65d903a8b6469797c58c52eaf8008.tar.gz
gcc-40499f81a6a65d903a8b6469797c58c52eaf8008.tar.bz2
PR c++/70105: Defer location expansion until diagnostic_show_locus
gcc/ChangeLog: PR c/68473 PR c++/70105 * diagnostic-show-locus.c (layout_range::layout_range): Replace location_range param with three const expanded_locations * and a bool. (layout::layout): Replace call to rich_location::lazily_expand_location with get_expanded_location. Extract the range and perform location expansion here, passing the results to the layout_range ctor. * diagnostic.c (source_range::debug): Delete. * diagnostic.h (diagnostic_expand_location): Reimplement in terms of rich_location::get_expanded_location. * gcc-rich-location.c (get_range_for_expr): Delete. (gcc_rich_location::add_expr): Reimplement to avoid the rich_location::add_range overload that took a location_range, passing a location_t instead. gcc/testsuite/ChangeLog: PR c/68473 PR c++/70105 * gcc.dg/plugin/diagnostic_plugin_show_trees.c (show_tree): Drop range information from call to inform_at_rich_loc. * gcc.dg/plugin/diagnostic_plugin_test_show_locus.c (add_range): New. (test_show_locus): Replace calls to rich_location::add_range with calls to add_range. Rewrite the tests that used the now-defunct rich_location ctor taking a source_range. Simplify other tests by replacing calls to COMBINE_LOCATION_DATA with calls to make_location. libcpp/ChangeLog: PR c/68473 PR c++/70105 * include/line-map.h (source_range::debug): Delete. (struct location_range): Update comment. Replace expanded_location fields "m_start", "m_finish", and "m_caret" with a source_location field: "m_loc". (class rich_location): Reword comment. (rich_location::get_loc): Reimplement in terms of a new overloaded variant which takes an unsigned int. (rich_location::get_loc_addr): Delete. (rich_location::add_range): Drop params "start" and "finish" in favor of param "loc". Drop overloaded variants taking a source_range or location_range *. (rich_location::lazily_expand_location): Delete in favor of... (rich_location::get_expanded_location): New decl. (rich_location::m_loc): Delete field. (rich_location::m_column_override): New field. * line-map.c (rich_location::rich_location): Drop name of line_maps * param. Update initializations for deletion of field "m_loc" and addition of field "m_column_override". Reimplement body as a call to add_range. Delete overloaded variant taking a source_range. (rich_location::get_loc): New function. (rich_location::lazily_expand_location): Delete in favor of... (rich_location::get_expanded_location): New function. (rich_location::override_column): Reimplement. (rich_location::add_range): Drop params "start" and "finish" in favor of param "loc". Eliminate location expansion in favor of simply storing loc. Drop overloaded variants taking a source_range or location_range *. (rich_location::set_range): Eliminate location expansion. From-SVN: r234087
Diffstat (limited to 'libcpp')
-rw-r--r--libcpp/ChangeLog34
-rw-r--r--libcpp/include/line-map.h51
-rw-r--r--libcpp/line-map.c118
3 files changed, 88 insertions, 115 deletions
diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog
index 676272d..d583e98 100644
--- a/libcpp/ChangeLog
+++ b/libcpp/ChangeLog
@@ -1,3 +1,37 @@
+2016-03-09 David Malcolm <dmalcolm@redhat.com>
+
+ PR c/68473
+ PR c++/70105
+ * include/line-map.h (source_range::debug): Delete.
+ (struct location_range): Update comment. Replace
+ expanded_location fields "m_start", "m_finish", and "m_caret" with
+ a source_location field: "m_loc".
+ (class rich_location): Reword comment.
+ (rich_location::get_loc): Reimplement in terms of a new overloaded
+ variant which takes an unsigned int.
+ (rich_location::get_loc_addr): Delete.
+ (rich_location::add_range): Drop params "start" and "finish" in
+ favor of param "loc". Drop overloaded variants taking a
+ source_range or location_range *.
+ (rich_location::lazily_expand_location): Delete in favor of...
+ (rich_location::get_expanded_location): New decl.
+ (rich_location::m_loc): Delete field.
+ (rich_location::m_column_override): New field.
+ * line-map.c (rich_location::rich_location): Drop name of
+ line_maps * param. Update initializations for deletion of field
+ "m_loc" and addition of field "m_column_override". Reimplement
+ body as a call to add_range. Delete overloaded variant taking a
+ source_range.
+ (rich_location::get_loc): New function.
+ (rich_location::lazily_expand_location): Delete in favor of...
+ (rich_location::get_expanded_location): New function.
+ (rich_location::override_column): Reimplement.
+ (rich_location::add_range): Drop params "start" and "finish" in
+ favor of param "loc". Eliminate location expansion in favor of
+ simply storing loc. Drop overloaded variants taking a
+ source_range or location_range *.
+ (rich_location::set_range): Eliminate location expansion.
+
2016-02-29 David Malcolm <dmalcolm@redhat.com>
PR preprocessor/69985
diff --git a/libcpp/include/line-map.h b/libcpp/include/line-map.h
index 6e858a6..13cc6f8 100644
--- a/libcpp/include/line-map.h
+++ b/libcpp/include/line-map.h
@@ -273,20 +273,6 @@ struct GTY(()) source_range
source_location m_start;
source_location m_finish;
- /* Display this source_range instance, with MSG as a descriptive
- comment. This issues a "note" diagnostic at the range, using
- gcc's diagnostic machinery.
-
- This is declared here, but is implemented within gcc/diagnostic.c,
- since it makes use of gcc's diagnostic-printing machinery. This
- is a slight layering violation, but this is sufficiently useful
- for debugging that it's worth it.
-
- This declaration would have a DEBUG_FUNCTION annotation, but that
- is implemented in gcc/system.h and thus is not available here in
- libcpp. */
- void debug (const char *msg) const;
-
/* We avoid using constructors, since various structs that
don't yet have constructors will embed instances of
source_range. */
@@ -1249,13 +1235,12 @@ typedef struct
i.e. "3:1:" in GCC corresponds to "(3, 0)" in Emacs. */
-/* Ranges are closed
- m_start is the first location within the range, and
- m_finish is the last location within the range. */
+/* A location within a rich_location: a caret&range, with
+ the caret potentially flagged for display. */
+
struct location_range
{
- expanded_location m_start;
- expanded_location m_finish;
+ source_location m_loc;
/* Should a caret be drawn for this range? Typically this is
true for the 0th range, and false for subsequent ranges,
@@ -1267,7 +1252,6 @@ struct location_range
where "1" and "2" are notionally carets. */
bool m_show_caret_p;
- expanded_location m_caret;
};
class fixit_hint;
@@ -1276,9 +1260,10 @@ class fixit_hint;
class fixit_replace;
/* A "rich" source code location, for use when printing diagnostics.
- A rich_location has one or more ranges, each optionally with
- a caret. Typically the zeroth range has a caret; other ranges
- sometimes have carets.
+ A rich_location has one or more carets&ranges, where the carets
+ are optional. These are referred to as "ranges" from here.
+ Typically the zeroth range has a caret; other ranges sometimes
+ have carets.
The "primary" location of a rich_location is the caret of range 0,
used for determining the line/column when printing diagnostic
@@ -1361,19 +1346,11 @@ class rich_location
~rich_location ();
/* Accessors. */
- source_location get_loc () const { return m_loc; }
-
- source_location *get_loc_addr () { return &m_loc; }
-
- void
- add_range (source_location start, source_location finish,
- bool show_caret_p);
-
- void
- add_range (source_range src_range, bool show_caret_p);
+ source_location get_loc () const { return get_loc (0); }
+ source_location get_loc (unsigned int idx) const;
void
- add_range (location_range *src_range);
+ add_range (source_location loc, bool show_caret_p);
void
set_range (line_maps *set, unsigned int idx, source_location loc,
@@ -1387,7 +1364,7 @@ class rich_location
return &m_ranges[idx];
}
- expanded_location lazily_expand_location ();
+ expanded_location get_expanded_location (unsigned int idx);
void
override_column (int column);
@@ -1412,11 +1389,11 @@ public:
static const int MAX_FIXIT_HINTS = 2;
protected:
- source_location m_loc;
-
unsigned int m_num_ranges;
location_range m_ranges[MAX_RANGES];
+ int m_column_override;
+
bool m_have_expanded_location;
expanded_location m_expanded_location;
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