Add from_macro_definition_at predicate for locations.
authorJason Merrill <jason@redhat.com>
Wed, 21 Sep 2016 19:59:29 +0000 (15:59 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Wed, 21 Sep 2016 19:59:29 +0000 (15:59 -0400)
gcc/
* input.h (from_macro_definition_at): New.
libcpp/
* line-map.c (linemap_location_from_macro_definition_p): New.
* line-map.h: Declare it.

From-SVN: r240330

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

index 330d9fd..bb998d1 100644 (file)
@@ -1,3 +1,7 @@
+2016-09-21  Jason Merrill  <jason@redhat.com>
+
+       * input.h (from_macro_definition_at): New.
+
 2016-09-21  Segher Boessenkool  <segher@kernel.crashing.org>
 
        * doc/rtl.texi (JUMP_LABEL): Document RETURN and SIMPLE_RETURN values.
index e95bd3c..fe80605 100644 (file)
@@ -77,6 +77,11 @@ extern location_t input_location;
    comes from a macro expansion, O otherwise.  */
 #define from_macro_expansion_at(LOC) \
   ((linemap_location_from_macro_expansion_p (line_table, LOC)))
+/* Return a positive value if LOCATION is the locus of a token that comes from
+   a macro definition, O otherwise.  This differs from from_macro_expansion_at
+   in its treatment of macro arguments, for which this returns false.  */
+#define from_macro_definition_at(LOC) \
+  ((linemap_location_from_macro_definition_p (line_table, LOC)))
 
 static inline location_t
 get_pure_location (location_t loc)
index b2b3603..e039069 100644 (file)
@@ -1,3 +1,8 @@
+2016-09-21  Jason Merrill  <jason@redhat.com>
+
+       * line-map.c (linemap_location_from_macro_definition_p): New.
+       * line-map.h: Declare it.
+
 2016-09-15  David Malcolm  <dmalcolm@redhat.com>
 
        * include/line-map.h (class rich_location): Note that newlines
index 747609d..8be98b5 100644 (file)
@@ -1086,12 +1086,16 @@ const char* linemap_map_get_macro_name (const line_map_macro *);
 int linemap_location_in_system_header_p (struct line_maps *,
                                         source_location);
 
-/* Return TRUE if LOCATION is a source code location of a token coming
-   from a macro replacement-list at a macro expansion point, FALSE
-   otherwise.  */
+/* Return TRUE if LOCATION is a source code location of a token that is part of
+   a macro expansion, FALSE otherwise.  */
 bool linemap_location_from_macro_expansion_p (const struct line_maps *,
                                              source_location);
 
+/* TRUE if LOCATION is a source code location of a token that is part of the
+   definition of a macro, FALSE otherwise.  */
+bool linemap_location_from_macro_definition_p (struct line_maps *,
+                                              source_location);
+
 /* With the precondition that LOCATION is the locus of a token that is
    an argument of a function-like macro MACRO_MAP and appears in the
    expansion of MACRO_MAP, return the locus of that argument in the
index 07e3acb..c5c42f0 100644 (file)
@@ -1223,9 +1223,8 @@ linemap_location_in_system_header_p (struct line_maps *set,
   return false;
 }
 
-/* Return TRUE if LOCATION is a source code location of a token coming
-   from a macro replacement-list at a macro expansion point, FALSE
-   otherwise.  */
+/* Return TRUE if LOCATION is a source code location of a token that is part of
+   a macro expansion, FALSE otherwise.  */
 
 bool
 linemap_location_from_macro_expansion_p (const struct line_maps *set,
@@ -1570,6 +1569,37 @@ linemap_resolve_location (struct line_maps *set,
   return loc;
 }
 
+/* TRUE if LOCATION is a source code location of a token that is part of the
+   definition of a macro, FALSE otherwise.  */
+
+bool
+linemap_location_from_macro_definition_p (struct line_maps *set,
+                                         source_location loc)
+{
+  if (IS_ADHOC_LOC (loc))
+    loc = get_location_from_adhoc_loc (set, loc);
+
+  if (!linemap_location_from_macro_expansion_p (set, loc))
+    return false;
+
+  while (true)
+    {
+      const struct line_map_macro *map
+       = linemap_check_macro (linemap_lookup (set, loc));
+
+      source_location s_loc
+       = linemap_macro_map_loc_unwind_toward_spelling (set, map, loc);
+      if (linemap_location_from_macro_expansion_p (set, s_loc))
+       loc = s_loc;
+      else
+       {
+         source_location def_loc
+           = linemap_macro_map_loc_to_def_point (map, loc);
+         return s_loc == def_loc;
+       }
+    }
+}
+
 /* 
    Suppose that LOC is the virtual location of a token T coming from
    the expansion of a macro M.  This function then steps up to get the