On 10/23/2015 02:41 PM, David Malcolm wrote:
This patch:

   - generalizes the meaning of the source_location (aka location_t) type
     from being a caret within the source code to being a caret plus
     a source_range.  The latter data is stored purely in the ad-hoc data
     lookaside for now.

   - captures ranges for libcpp tokens by generating source_location
     values with caret == start and finish == the last character of the
     token

This is elegant, since we can store caret+range data in location_t as
before, without having to track ranges everywhere: all location_t
values (such as input_location) become the ranges of tokens; a followup
patch fixes the diagnostic machinery to automatically extract the
ranges when building rich_location instances, which means that all
calls to warning, warning_at, error, error_at etc get underlines
showing the range of the pertinent token "for free".

However, it's inefficient, since it means generating an ad-hoc location
for every token in libcpp.  A followup patch optimizes this by packing
short ranges into location_t, without needing to use ad-hoc locations,
which covers most tokens efficiently.

gcc/ChangeLog:
        * gimple.h (gimple_set_block): Use set_block function.
        * tree-cfg.c (move_block_to_fn): Likewise.
        (move_block_to_fn): Likewise.
        * tree-inline.c (copy_phis_for_bb): Likewise.
        * tree.c (tree_set_block): Likewise.
        (set_block): New function.
        * tree.h (set_block): New declaration.

libcpp/ChangeLog:
        * include/cpplib.h (struct cpp_token): Update comment for src_loc
        to indicate that the range of the token is "baked into" the
        source_location.
        * include/line-map.h (location_adhoc_data): Add source_range
        field.
        (get_combined_adhoc_loc): Add source_range param.
        (get_range_from_adhoc_loc): New declaration.
        (get_range_from_loc): New inline function.
        (COMBINE_LOCATION_DATA):  Add source_range param.
        * lex.c (_cpp_lex_direct): Capture the range of the token, baking
        it into token->src_loc via a call to COMBINE_LOCATION_DATA.
        * line-map.c (location_adhoc_data_hash): Add the src_range into
        the hash value.
        (location_adhoc_data_eq): Require equality of the src_range
        values.
        (get_combined_adhoc_loc): Add src_range param, and store it
        within the lookaside table.  Remove the requirement that data
        is non-NULL.
        (get_range_from_adhoc_loc): New function.
        (linemap_expand_location): Extract the data pointer before
        extracting the location.
---
  gcc/gimple.h              |  6 +-----
  gcc/tree-cfg.c            |  9 ++-------
  gcc/tree-inline.c         |  5 +----
  gcc/tree.c                | 11 +++++++----
  gcc/tree.h                |  3 +++
  libcpp/include/cpplib.h   |  3 ++-
  libcpp/include/line-map.h | 23 ++++++++++++++++++++---
  libcpp/lex.c              | 10 ++++++++++
  libcpp/line-map.c         | 26 ++++++++++++++++++++------
  9 files changed, 66 insertions(+), 30 deletions(-)

diff --git a/gcc/gimple.h b/gcc/gimple.h
index a456f54..ba66931 100644
--- a/gcc/gimple.h
+++ b/gcc/gimple.h
@@ -13656,5 +13653,11 @@ nonnull_arg_p (const_tree arg)
    return false;
  }

+location_t
+set_block (location_t loc, tree block)
+{
+  source_range src_range = get_range_from_loc (line_table, loc);
+  return COMBINE_LOCATION_DATA (line_table, loc, src_range, block);
+}
Needs a function comment.



  #include "gt-tree.h"
diff --git a/gcc/tree.h b/gcc/tree.h
index 4c803f4..92cc929 100644
--- a/gcc/tree.h
+++ b/gcc/tree.h
@@ -5139,6 +5139,9 @@ type_with_alias_set_p (const_tree t)
    return false;
  }

+extern location_t
+set_block (location_t loc, tree block);
Single line please.

diff --git a/libcpp/include/line-map.h b/libcpp/include/line-map.h
index 84a5ab7..de1c55c 100644
--- a/libcpp/include/line-map.h
+++ b/libcpp/include/line-map.h
@@ -826,14 +832,25 @@ IS_ADHOC_LOC (source_location loc)
    return (loc & MAX_SOURCE_LOCATION) != loc;
  }

+inline source_range
+get_range_from_loc (struct line_maps *set,
+                   source_location loc)
+{
+  if (IS_ADHOC_LOC (loc))
+    return get_range_from_adhoc_loc (set, loc);
+  else
+    return source_range::from_location (loc);
+}
Needs a function comment.

 diff --git a/libcpp/lex.c b/libcpp/lex.c
index 0aa1090..f4c964f 100644
--- a/libcpp/lex.c
+++ b/libcpp/lex.c
@@ -2723,6 +2723,16 @@ _cpp_lex_direct (cpp_reader *pfile)
        break;
      }

+  source_range tok_range;
+  tok_range.m_start = result->src_loc;
+  tok_range.m_finish =
+    linemap_position_for_column (pfile->line_table,
+                                CPP_BUF_COLUMN (buffer, buffer->cur));
Line wrapping is wrong.  Break before the "=".

diff --git a/libcpp/line-map.c b/libcpp/line-map.c
index 3c19f93..3810c88 100644
--- a/libcpp/line-map.c
+++ b/libcpp/line-map.c
@@ -177,6 +184,13 @@ get_location_from_adhoc_loc (struct line_maps *set, 
source_location loc)
    return set->location_adhoc_data_map.data[loc & MAX_SOURCE_LOCATION].locus;
  }

+source_range
+get_range_from_adhoc_loc (struct line_maps *set, source_location loc)
+{
+  linemap_assert (IS_ADHOC_LOC (loc));
+  return set->location_adhoc_data_map.data[loc & 
MAX_SOURCE_LOCATION].src_range;
+}
Function comment.


OK with those nits fixed. However please don't install into the prerequisites are in *and* the later optimization bits are approved & installed too.

jeff

Reply via email to