aboutsummaryrefslogtreecommitdiff
path: root/libcpp
diff options
context:
space:
mode:
Diffstat (limited to 'libcpp')
-rw-r--r--libcpp/ChangeLog7
-rw-r--r--libcpp/include/line-map.h8
-rw-r--r--libcpp/line-map.c44
3 files changed, 59 insertions, 0 deletions
diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog
index aa860b5..b75d521 100644
--- a/libcpp/ChangeLog
+++ b/libcpp/ChangeLog
@@ -1,3 +1,10 @@
+2014-11-11 Manuel López-Ibáñez <manu@gcc.gnu.org>
+
+ PR fortran/44054
+ * include/line-map.h (linemap_position_for_loc_and_offset):
+ Declare.
+ * line-map.c (linemap_position_for_loc_and_offset): New.
+
2014-11-11 David Malcolm <dmalcolm@redhat.com>
* ChangeLog.jit: New.
diff --git a/libcpp/include/line-map.h b/libcpp/include/line-map.h
index 1f6553c..2fcee19 100644
--- a/libcpp/include/line-map.h
+++ b/libcpp/include/line-map.h
@@ -603,6 +603,14 @@ source_location
linemap_position_for_line_and_column (const struct line_map *,
linenum_type, unsigned int);
+/* Encode and return a source_location starting from location LOC and
+ shifting it by OFFSET columns. This function does not support
+ virtual locations. */
+source_location
+linemap_position_for_loc_and_offset (struct line_maps *set,
+ source_location loc,
+ unsigned int offset);
+
/* Return the file this map is for. */
#define LINEMAP_FILE(MAP) \
(linemap_check_ordinary (MAP)->d.ordinary.to_file)
diff --git a/libcpp/line-map.c b/libcpp/line-map.c
index d10d578..aff0294 100644
--- a/libcpp/line-map.c
+++ b/libcpp/line-map.c
@@ -633,6 +633,50 @@ linemap_position_for_line_and_column (const struct line_map *map,
+ (column & ((1 << ORDINARY_MAP_NUMBER_OF_COLUMN_BITS (map)) - 1)));
}
+/* Encode and return a source_location starting from location LOC and
+ shifting it by OFFSET columns. This function does not support
+ virtual locations. */
+
+source_location
+linemap_position_for_loc_and_offset (struct line_maps *set,
+ source_location loc,
+ unsigned int offset)
+{
+ const struct line_map * map = NULL;
+
+ /* This function does not support virtual locations yet. */
+ linemap_assert (!linemap_location_from_macro_expansion_p (set, loc));
+
+ if (offset == 0
+ /* Adding an offset to a reserved location (like
+ UNKNOWN_LOCATION for the C/C++ FEs) does not really make
+ sense. So let's leave the location intact in that case. */
+ || loc < RESERVED_LOCATION_COUNT)
+ return loc;
+
+ /* We find the real location and shift it. */
+ loc = linemap_resolve_location (set, loc, LRK_SPELLING_LOCATION, &map);
+ /* The new location (loc + offset) should be higher than the first
+ location encoded by MAP. */
+ linemap_assert (MAP_START_LOCATION (map) < loc + offset);
+
+ /* If MAP is not the last line map of its set, then the new location
+ (loc + offset) should be less than the first location encoded by
+ the next line map of the set. */
+ if (map != LINEMAPS_LAST_ORDINARY_MAP (set))
+ linemap_assert (loc + offset < MAP_START_LOCATION (&map[1]));
+
+ offset += SOURCE_COLUMN (map, loc);
+ linemap_assert (offset < (1u << map->d.ordinary.column_bits));
+
+ source_location r =
+ linemap_position_for_line_and_column (map,
+ SOURCE_LINE (map, loc),
+ offset);
+ linemap_assert (map == linemap_lookup (set, r));
+ return r;
+}
+
/* Given a virtual source location yielded by a map (either an
ordinary or a macro map), returns that map. */