aboutsummaryrefslogtreecommitdiff
path: root/gcc/diagnostic-show-locus.c
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 /gcc/diagnostic-show-locus.c
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 'gcc/diagnostic-show-locus.c')
-rw-r--r--gcc/diagnostic-show-locus.c41
1 files changed, 29 insertions, 12 deletions
diff --git a/gcc/diagnostic-show-locus.c b/gcc/diagnostic-show-locus.c
index 3acdb32..a940f24 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)