Move make_location from tree.h/c to input.h/c
authorDavid Malcolm <dmalcolm@redhat.com>
Wed, 27 Jul 2016 17:21:20 +0000 (17:21 +0000)
committerDavid Malcolm <dmalcolm@gcc.gnu.org>
Wed, 27 Jul 2016 17:21:20 +0000 (17:21 +0000)
For some reason I added make_location and some related functions to
tree.h/c, rather than to input.h/c.  Move them there, so we can use them
without requiring tree, and add some selftest coverage.

gcc/ChangeLog:
* input.c (get_pure_location): Move here from tree.c.
(make_location): Likewise.  Add header comment.
(selftest::test_accessing_ordinary_linemaps): Verify
pure_location_p, make_location, get_location_from_adhoc_loc and
get_range_from_loc.
* input.h (get_pure_location): Move declaration here from tree.h.
(get_finish): Likewise for inline function.
(make_location): Likewise for declaration.
* tree.c (get_pure_location): Move to input.c.
(make_location): Likewise.
* tree.h (get_pure_location): Move declaration to tree.h.
(get_finish): Likewise for inline function.
(make_location): Likewise for declaration.

libcpp/ChangeLog:
* include/line-map.h (source_location): Fix line numbers in
comment.

From-SVN: r238792

gcc/ChangeLog
gcc/input.c
gcc/input.h
gcc/tree.c
gcc/tree.h
libcpp/ChangeLog
libcpp/include/line-map.h

index 0caa798e4f56e067bc8350f6cf114f6d9920ded8..9e359bc1e6948807b1e36ae251b694e97d146d6c 100644 (file)
@@ -1,3 +1,19 @@
+2016-07-27  David Malcolm  <dmalcolm@redhat.com>
+
+       * input.c (get_pure_location): Move here from tree.c.
+       (make_location): Likewise.  Add header comment.
+       (selftest::test_accessing_ordinary_linemaps): Verify
+       pure_location_p, make_location, get_location_from_adhoc_loc and
+       get_range_from_loc.
+       * input.h (get_pure_location): Move declaration here from tree.h.
+       (get_finish): Likewise for inline function.
+       (make_location): Likewise for declaration.
+       * tree.c (get_pure_location): Move to input.c.
+       (make_location): Likewise.
+       * tree.h (get_pure_location): Move declaration to tree.h.
+       (get_finish): Likewise for inline function.
+       (make_location): Likewise for declaration.
+
 2016-07-27  Prathamesh Kulkarni  <prathamesh.kulkarni@linaro.org>
 
        PR middle-end/71078
index 47845d000705953b94144df6a83fe4d7ca14a5d9..f91a702d47b533f004e82caad34ebf47d8ec116e 100644 (file)
@@ -801,6 +801,56 @@ expansion_point_location (source_location location)
                                   LRK_MACRO_EXPANSION_POINT, NULL);
 }
 
+/* Given location LOC, strip away any packed range information
+   or ad-hoc information.  */
+
+location_t
+get_pure_location (location_t loc)
+{
+  if (IS_ADHOC_LOC (loc))
+    loc
+      = line_table->location_adhoc_data_map.data[loc & MAX_SOURCE_LOCATION].locus;
+
+  if (loc >= LINEMAPS_MACRO_LOWEST_LOCATION (line_table))
+    return loc;
+
+  if (loc < RESERVED_LOCATION_COUNT)
+    return loc;
+
+  const line_map *map = linemap_lookup (line_table, loc);
+  const line_map_ordinary *ordmap = linemap_check_ordinary (map);
+
+  return loc & ~((1 << ordmap->m_range_bits) - 1);
+}
+
+/* Construct a location with caret at CARET, ranging from START to
+   finish e.g.
+
+                 11111111112
+        12345678901234567890
+     522
+     523   return foo + bar;
+                  ~~~~^~~~~
+     524
+
+   The location's caret is at the "+", line 523 column 15, but starts
+   earlier, at the "f" of "foo" at column 11.  The finish is at the "r"
+   of "bar" at column 19.  */
+
+location_t
+make_location (location_t caret, location_t start, location_t finish)
+{
+  location_t pure_loc = get_pure_location (caret);
+  source_range src_range;
+  src_range.m_start = start;
+  src_range.m_finish = finish;
+  location_t combined_loc = COMBINE_LOCATION_DATA (line_table,
+                                                  pure_loc,
+                                                  src_range,
+                                                  NULL);
+  return combined_loc;
+}
+
 #define ONE_K 1024
 #define ONE_M (ONE_K * ONE_K)
 
@@ -1335,6 +1385,16 @@ test_accessing_ordinary_linemaps (const line_table_case &case_)
   assert_loceq ("bar.c", 1, 150, loc_f);
 
   ASSERT_FALSE (is_location_from_builtin_token (loc_a));
+  ASSERT_TRUE (pure_location_p (line_table, loc_a));
+
+  /* Verify using make_location to build a range, and extracting data
+     back from it.  */
+  location_t range_c_b_d = make_location (loc_c, loc_b, loc_d);
+  ASSERT_FALSE (pure_location_p (line_table, range_c_b_d));
+  ASSERT_EQ (loc_c, get_location_from_adhoc_loc (line_table, range_c_b_d));
+  source_range src_range = get_range_from_loc (line_table, range_c_b_d);
+  ASSERT_EQ (loc_b, src_range.m_start);
+  ASSERT_EQ (loc_d, src_range.m_finish);
 }
 
 /* Verify various properties of UNKNOWN_LOCATION.  */
index ae4fecfe11ce69ebeb320ce832ab6d8924eddf5d..d51f950bcc96da7aeade1b8497e527b98df023de 100644 (file)
@@ -76,6 +76,19 @@ extern location_t input_location;
 #define from_macro_expansion_at(LOC) \
   ((linemap_location_from_macro_expansion_p (line_table, LOC)))
 
+extern location_t get_pure_location (location_t loc);
+
+/* Get the endpoint of any range encoded within location LOC.  */
+
+static inline location_t
+get_finish (location_t loc)
+{
+  return get_range_from_loc (line_table, loc).m_finish;
+}
+
+extern location_t make_location (location_t caret,
+                                location_t start, location_t finish);
+
 void dump_line_table_statistics (void);
 
 void dump_location_info (FILE *stream);
index 661d385d43c6045e679102561f7361938f39c168..11d3b51e3127329fd87fa044842a255bb1853bc9 100644 (file)
@@ -14112,28 +14112,6 @@ nonnull_arg_p (const_tree arg)
   return false;
 }
 
-/* Given location LOC, strip away any packed range information
-   or ad-hoc information.  */
-
-location_t
-get_pure_location (location_t loc)
-{
-  if (IS_ADHOC_LOC (loc))
-    loc
-      = line_table->location_adhoc_data_map.data[loc & MAX_SOURCE_LOCATION].locus;
-
-  if (loc >= LINEMAPS_MACRO_LOWEST_LOCATION (line_table))
-    return loc;
-
-  if (loc < RESERVED_LOCATION_COUNT)
-    return loc;
-
-  const line_map *map = linemap_lookup (line_table, loc);
-  const line_map_ordinary *ordmap = linemap_check_ordinary (map);
-
-  return loc & ~((1 << ordmap->m_range_bits) - 1);
-}
-
 /* Combine LOC and BLOCK to a combined adhoc loc, retaining any range
    information.  */
 
@@ -14169,20 +14147,6 @@ set_source_range (tree expr, source_range src_range)
   return adhoc;
 }
 
-location_t
-make_location (location_t caret, location_t start, location_t finish)
-{
-  location_t pure_loc = get_pure_location (caret);
-  source_range src_range;
-  src_range.m_start = start;
-  src_range.m_finish = finish;
-  location_t combined_loc = COMBINE_LOCATION_DATA (line_table,
-                                                  pure_loc,
-                                                  src_range,
-                                                  NULL);
-  return combined_loc;
-}
-
 /* Return the name of combined function FN, for debugging purposes.  */
 
 const char *
index e2ffabfe173dfeadf197428630d0fa543ccac28f..14c8f7a59f4ac7f56f82e84c5a622d1c091c4cbe 100644 (file)
@@ -5425,16 +5425,6 @@ type_with_alias_set_p (const_tree t)
   return false;
 }
 
-extern location_t get_pure_location (location_t loc);
-
-/* Get the endpoint of any range encoded within location LOC.  */
-
-static inline location_t
-get_finish (location_t loc)
-{
-  return get_range_from_loc (line_table, loc).m_finish;
-}
-
 extern location_t set_block (location_t loc, tree block);
 
 extern void gt_ggc_mx (tree &);
@@ -5457,9 +5447,6 @@ get_decl_source_range (tree decl)
   return get_range_from_loc (line_table, loc);
 }
 
-extern location_t
-make_location (location_t caret, location_t start, location_t finish);
-
 /* Return true if it makes sense to promote/demote from_type to to_type. */
 inline bool
 desired_pro_or_demotion_p (const_tree to_type, const_tree from_type)
index 168e08c15cff3ba76640403beef5545a48fb103a..0cdd75d956ac55e3d72e2077b9a2f3e80d991268 100644 (file)
@@ -1,3 +1,8 @@
+2016-07-27  David Malcolm  <dmalcolm@redhat.com>
+
+       * include/line-map.h (source_location): Fix line numbers in
+       comment.
+
 2016-07-11  David Malcolm  <dmalcolm@redhat.com>
 
        * include/line-map.h (LINE_MAP_MAX_LOCATION_WITH_PACKED_RANGES):
index 43576761e63f13928666f8c471613cb356956045..443086a0b70a4309040668bbe07b939a9b216b96 100644 (file)
@@ -227,10 +227,10 @@ typedef unsigned int linenum_type;
 
                  11111111112
         12345678901234567890
-     521
+     522
      523   return foo + bar;
                   ~~~~^~~~~
-     523
+     524
 
    The location's caret is at the "+", line 523 column 15, but starts
    earlier, at the "f" of "foo" at column 11.  The finish is at the "r"