aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2016-03-09 18:14:43 +0000
committerDavid Malcolm <dmalcolm@redhat.com>2016-03-09 18:14:43 +0000
commitdd1d5b18e567a2d91dc2c28f82be139332c0032f (patch)
treeba81cb8d930007773d9d7556e938bf62e095d82e
parentfd357bf3eaf5d10b10897bcf10cb2f3557974861 (diff)
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. git-svn-id: https://gcc.gnu.org/svn/gcc/trunk@234087 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/ChangeLog19
-rw-r--r--gcc/diagnostic-show-locus.c41
-rw-r--r--gcc/diagnostic.c14
-rw-r--r--gcc/diagnostic.h2
-rw-r--r--gcc/gcc-rich-location.c28
-rw-r--r--gcc/testsuite/ChangeLog14
-rw-r--r--gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_show_trees.c8
-rw-r--r--gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_show_locus.c97
-rw-r--r--libcpp/ChangeLog34
-rw-r--r--libcpp/include/line-map.h51
-rw-r--r--libcpp/line-map.c118
11 files changed, 200 insertions, 226 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index e0e9ad17e8e..ee8e2088a50 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,22 @@
+2016-03-09 David Malcolm <dmalcolm@redhat.com>
+
+ 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.
+
2016-03-09 Richard Biener <rguenther@suse.de>
Jakub Jelinek <jakub@redhat.com>
diff --git a/gcc/diagnostic-show-locus.c b/gcc/diagnostic-show-locus.c
index 3acdb32089c..a940f24465e 100644
--- a/gcc/diagnostic-show-locus.c
+++ b/gcc/diagnostic-show-locus.c
@@ -117,7 +117,10 @@ class layout_point
class layout_range
{
public:
- layout_range (const location_range *loc_range);
+ layout_range (const expanded_location *start_exploc,
+ const expanded_location *finish_exploc,
+ bool show_caret_p,
+ const expanded_location *caret_exploc);
bool contains_point (int row, int column) const;
@@ -328,11 +331,14 @@ colorizer::finish_state (int state)
Initialize various layout_point fields from expanded_location
equivalents; we've already filtered on file. */
-layout_range::layout_range (const location_range *loc_range)
-: m_start (loc_range->m_start),
- m_finish (loc_range->m_finish),
- m_show_caret_p (loc_range->m_show_caret_p),
- m_caret (loc_range->m_caret)
+layout_range::layout_range (const expanded_location *start_exploc,
+ const expanded_location *finish_exploc,
+ bool show_caret_p,
+ const expanded_location *caret_exploc)
+: m_start (*start_exploc),
+ m_finish (*finish_exploc),
+ m_show_caret_p (show_caret_p),
+ m_caret (*caret_exploc)
{
}
@@ -473,7 +479,7 @@ layout::layout (diagnostic_context * context,
: m_context (context),
m_pp (context->printer),
m_diagnostic_kind (diagnostic->kind),
- m_exploc (diagnostic->richloc->lazily_expand_location ()),
+ m_exploc (diagnostic->richloc->get_expanded_location (0)),
m_colorizer (context, diagnostic),
m_colorize_source_p (context->colorize_source_p),
m_layout_ranges (rich_location::MAX_RANGES),
@@ -487,25 +493,36 @@ layout::layout (diagnostic_context * context,
Ignore any ranges that are awkward to handle. */
const location_range *loc_range = richloc->get_range (idx);
+ /* Split the "range" into caret and range information. */
+ source_range src_range = get_range_from_loc (line_table, loc_range->m_loc);
+
+ /* Expand the various locations. */
+ expanded_location start
+ = linemap_client_expand_location_to_spelling_point (src_range.m_start);
+ expanded_location finish
+ = linemap_client_expand_location_to_spelling_point (src_range.m_finish);
+ expanded_location caret
+ = linemap_client_expand_location_to_spelling_point (loc_range->m_loc);
+
/* If any part of the range isn't in the same file as the primary
location of this diagnostic, ignore the range. */
- if (loc_range->m_start.file != m_exploc.file)
+ if (start.file != m_exploc.file)
continue;
- if (loc_range->m_finish.file != m_exploc.file)
+ if (finish.file != m_exploc.file)
continue;
if (loc_range->m_show_caret_p)
- if (loc_range->m_caret.file != m_exploc.file)
+ if (caret.file != m_exploc.file)
continue;
/* Everything is now known to be in the correct source file,
but it may require further sanitization. */
- layout_range ri (loc_range);
+ layout_range ri (&start, &finish, loc_range->m_show_caret_p, &caret);
/* If we have a range that finishes before it starts (perhaps
from something built via macro expansion), printing the
range is likely to be nonsensical. Also, attempting to do so
breaks assumptions within the printing code (PR c/68473). */
- if (loc_range->m_start.line > loc_range->m_finish.line)
+ if (start.line > finish.line)
{
/* Is this the primary location? */
if (m_layout_ranges.length () == 0)
diff --git a/gcc/diagnostic.c b/gcc/diagnostic.c
index 322f2d9f5c0..6a679cb45a4 100644
--- a/gcc/diagnostic.c
+++ b/gcc/diagnostic.c
@@ -1338,17 +1338,3 @@ real_abort (void)
{
abort ();
}
-
-/* Display the given source_range instance, with MSG as a descriptive
- comment. This issues a "note" diagnostic at the range.
-
- This is declared within libcpp, but implemented here, since it
- makes use of the diagnostic-printing machinery. */
-
-DEBUG_FUNCTION void
-source_range::debug (const char *msg) const
-{
- rich_location richloc (line_table, m_start);
- richloc.add_range (m_start, m_finish, false);
- inform_at_rich_loc (&richloc, "%s", msg);
-}
diff --git a/gcc/diagnostic.h b/gcc/diagnostic.h
index 017ddcae0bf..ff573577084 100644
--- a/gcc/diagnostic.h
+++ b/gcc/diagnostic.h
@@ -339,7 +339,7 @@ diagnostic_num_locations (const diagnostic_info * diagnostic)
static inline expanded_location
diagnostic_expand_location (const diagnostic_info * diagnostic, int which = 0)
{
- return diagnostic->richloc->get_range (which)->m_caret;
+ return diagnostic->richloc->get_expanded_location (which);
}
/* This is somehow the right-side margin of a caret line, that is, we
diff --git a/gcc/gcc-rich-location.c b/gcc/gcc-rich-location.c
index 9ab4314a875..a03ce0ee5fa 100644
--- a/gcc/gcc-rich-location.c
+++ b/gcc/gcc-rich-location.c
@@ -41,28 +41,6 @@ along with GCC; see the file COPYING3. If not see
#include "cpplib.h"
#include "diagnostic.h"
-/* Extract any source range information from EXPR and write it
- to *R. */
-
-static bool
-get_range_for_expr (tree expr, location_range *r)
-{
- if (EXPR_HAS_RANGE (expr))
- {
- source_range sr = EXPR_LOCATION_RANGE (expr);
-
- /* Do we have meaningful data? */
- if (sr.m_start && sr.m_finish)
- {
- r->m_start = expand_location (sr.m_start);
- r->m_finish = expand_location (sr.m_finish);
- return true;
- }
- }
-
- return false;
-}
-
/* Add a range to the rich_location, covering expression EXPR. */
void
@@ -70,10 +48,8 @@ gcc_rich_location::add_expr (tree expr)
{
gcc_assert (expr);
- location_range r;
- r.m_show_caret_p = false;
- if (get_range_for_expr (expr, &r))
- add_range (&r);
+ if (CAN_HAVE_RANGE_P (expr))
+ add_range (EXPR_LOCATION (expr), false);
}
/* If T is an expression, add a range for it to the rich_location. */
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index b95a863aa31..014ee42f41d 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,17 @@
+2016-03-09 David Malcolm <dmalcolm@redhat.com>
+
+ 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.
+
2016-03-09 Richard Biener <rguenther@suse.de>
Jakub Jelinek <jakub@redhat.com>
diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_show_trees.c b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_show_trees.c
index c98034fb695..f025f963e69 100644
--- a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_show_trees.c
+++ b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_show_trees.c
@@ -52,13 +52,7 @@ show_tree (tree node)
enum tree_code code = TREE_CODE (node);
location_range *range = richloc.get_range (1);
- inform_at_rich_loc (&richloc,
- "%s at range %i:%i-%i:%i",
- get_tree_code_name (code),
- range->m_start.line,
- range->m_start.column,
- range->m_finish.line,
- range->m_finish.column);
+ inform_at_rich_loc (&richloc, "%s", get_tree_code_name (code));
/* Recurse. */
int min_idx = 0;
diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_show_locus.c b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_show_locus.c
index b4f12ba68c1..95078ce2f2b 100644
--- a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_show_locus.c
+++ b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_show_locus.c
@@ -140,6 +140,15 @@ custom_diagnostic_finalizer (diagnostic_context *context,
pp_flush (context->printer);
}
+/* Add a location to RICHLOC with caret==start at START, ranging to FINISH. */
+
+static void
+add_range (rich_location *richloc, location_t start, location_t finish,
+ bool show_caret_p)
+{
+ richloc->add_range (make_location (start, start, finish), show_caret_p);
+}
+
/* Exercise the diagnostic machinery to emit various warnings,
for use by diagnostic-test-show-locus-*.c.
@@ -165,8 +174,8 @@ test_show_locus (function *fun)
{
const int line = fnstart_line + 2;
rich_location richloc (line_table, get_loc (line, 15));
- richloc.add_range (get_loc (line, 10), get_loc (line, 14), false);
- richloc.add_range (get_loc (line, 16), get_loc (line, 16), false);
+ add_range (&richloc, get_loc (line, 10), get_loc (line, 14), false);
+ add_range (&richloc, get_loc (line, 16), get_loc (line, 16), false);
warning_at_rich_loc (&richloc, 0, "test");
}
@@ -174,10 +183,8 @@ test_show_locus (function *fun)
{
const int line = fnstart_line + 2;
rich_location richloc (line_table, get_loc (line, 24));
- richloc.add_range (get_loc (line, 6),
- get_loc (line, 22), false);
- richloc.add_range (get_loc (line, 26),
- get_loc (line, 43), false);
+ add_range (&richloc, get_loc (line, 6), get_loc (line, 22), false);
+ add_range (&richloc, get_loc (line, 26), get_loc (line, 43), false);
warning_at_rich_loc (&richloc, 0, "test");
}
@@ -185,10 +192,9 @@ test_show_locus (function *fun)
{
const int line = fnstart_line + 2;
rich_location richloc (line_table, get_loc (line + 1, 7));
- richloc.add_range (get_loc (line, 7),
- get_loc (line, 23), false);
- richloc.add_range (get_loc (line + 1, 9),
- get_loc (line + 1, 26), false);
+ add_range (&richloc, get_loc (line, 7), get_loc (line, 23), false);
+ add_range (&richloc, get_loc (line + 1, 9), get_loc (line + 1, 26),
+ false);
warning_at_rich_loc (&richloc, 0, "test");
}
@@ -196,22 +202,20 @@ test_show_locus (function *fun)
{
const int line = fnstart_line + 2;
rich_location richloc (line_table, get_loc (line + 5, 7));
- richloc.add_range (get_loc (line, 7),
- get_loc (line + 4, 65), false);
- richloc.add_range (get_loc (line + 5, 9),
- get_loc (line + 10, 61), false);
+ add_range (&richloc, get_loc (line, 7), get_loc (line + 4, 65), false);
+ add_range (&richloc, get_loc (line + 5, 9), get_loc (line + 10, 61),
+ false);
warning_at_rich_loc (&richloc, 0, "test");
}
- /* Example of a rich_location constructed directly from a
- source_range where the range is larger than one character. */
+ /* Example of a rich_location where the range is larger than
+ one character. */
if (0 == strcmp (fnname, "test_richloc_from_proper_range"))
{
const int line = fnstart_line + 2;
- source_range src_range;
- src_range.m_start = get_loc (line, 12);
- src_range.m_finish = get_loc (line, 16);
- rich_location richloc (src_range);
+ location_t start = get_loc (line, 12);
+ location_t finish = get_loc (line, 16);
+ rich_location richloc (line_table, make_location (start, start, finish));
warning_at_rich_loc (&richloc, 0, "test");
}
@@ -220,15 +224,9 @@ test_show_locus (function *fun)
if (0 == strcmp (fnname, "test_caret_within_proper_range"))
{
const int line = fnstart_line + 2;
- location_t caret = get_loc (line, 16);
- source_range src_range;
- src_range.m_start = get_loc (line, 12);
- src_range.m_finish = get_loc (line, 20);
- location_t combined_loc = COMBINE_LOCATION_DATA (line_table,
- caret,
- src_range,
- NULL);
- warning_at (combined_loc, 0, "test");
+ warning_at (make_location (get_loc (line, 16), get_loc (line, 12),
+ get_loc (line, 20)),
+ 0, "test");
}
/* Example of a very wide line, where the information of interest
@@ -236,15 +234,9 @@ test_show_locus (function *fun)
if (0 == strcmp (fnname, "test_very_wide_line"))
{
const int line = fnstart_line + 2;
- location_t caret = get_loc (line, 94);
- source_range src_range;
- src_range.m_start = get_loc (line, 90);
- src_range.m_finish = get_loc (line, 98);
- location_t combined_loc = COMBINE_LOCATION_DATA (line_table,
- caret,
- src_range,
- NULL);
- warning_at (combined_loc, 0, "test");
+ warning_at (make_location (get_loc (line, 94), get_loc (line, 90),
+ get_loc (line, 98)),
+ 0, "test");
}
/* Example of multiple carets. */
@@ -254,7 +246,7 @@ test_show_locus (function *fun)
location_t caret_a = get_loc (line, 7);
location_t caret_b = get_loc (line, 11);
rich_location richloc (line_table, caret_a);
- richloc.add_range (caret_b, caret_b, true);
+ add_range (&richloc, caret_b, caret_b, true);
global_dc->caret_chars[0] = 'A';
global_dc->caret_chars[1] = 'B';
warning_at_rich_loc (&richloc, 0, "test");
@@ -266,11 +258,10 @@ test_show_locus (function *fun)
if (0 == strcmp (fnname, "test_fixit_insert"))
{
const int line = fnstart_line + 2;
- source_range src_range;
- src_range.m_start = get_loc (line, 19);
- src_range.m_finish = get_loc (line, 22);
- rich_location richloc (src_range);
- richloc.add_fixit_insert (src_range.m_start, "{");
+ location_t start = get_loc (line, 19);
+ location_t finish = get_loc (line, 22);
+ rich_location richloc (line_table, make_location (start, start, finish));
+ richloc.add_fixit_insert (start, "{");
richloc.add_fixit_insert (get_loc (line, 23), "}");
warning_at_rich_loc (&richloc, 0, "example of insertion hints");
}
@@ -278,10 +269,12 @@ test_show_locus (function *fun)
if (0 == strcmp (fnname, "test_fixit_remove"))
{
const int line = fnstart_line + 2;
+ location_t start = get_loc (line, 8);
+ location_t finish = get_loc (line, 8);
+ rich_location richloc (line_table, make_location (start, start, finish));
source_range src_range;
- src_range.m_start = get_loc (line, 8);
- src_range.m_finish = get_loc (line, 8);
- rich_location richloc (src_range);
+ src_range.m_start = start;
+ src_range.m_finish = finish;
richloc.add_fixit_remove (src_range);
warning_at_rich_loc (&richloc, 0, "example of a removal hint");
}
@@ -289,10 +282,12 @@ test_show_locus (function *fun)
if (0 == strcmp (fnname, "test_fixit_replace"))
{
const int line = fnstart_line + 2;
+ location_t start = get_loc (line, 2);
+ location_t finish = get_loc (line, 19);
+ rich_location richloc (line_table, make_location (start, start, finish));
source_range src_range;
- src_range.m_start = get_loc (line, 2);
- src_range.m_finish = get_loc (line, 19);
- rich_location richloc (src_range);
+ src_range.m_start = start;
+ src_range.m_finish = finish;
richloc.add_fixit_replace (src_range, "gtk_widget_show_all");
warning_at_rich_loc (&richloc, 0, "example of a replacement hint");
}
@@ -310,7 +305,7 @@ test_show_locus (function *fun)
location_t caret_a = get_loc (line, 5);
location_t caret_b = get_loc (line - 1, 19);
rich_location richloc (line_table, caret_a);
- richloc.add_range (caret_b, caret_b, true);
+ richloc.add_range (caret_b, true);
global_dc->caret_chars[0] = '1';
global_dc->caret_chars[1] = '2';
warning_at_rich_loc (&richloc, 0, "test");
diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog
index 676272de0a8..d583e98a903 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 6e858a6e1fb..13cc6f81a9f 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 264ae2097b2..de6eafcbe9b 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