]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Support location tracking for built-in macro tokens
authordodji <dodji@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 16 Jul 2014 10:33:27 +0000 (10:33 +0000)
committerdodji <dodji@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 16 Jul 2014 10:33:27 +0000 (10:33 +0000)
When a built-in macro is expanded, the location of the token in the
epansion list is the location of the expansion point of the built-in
macro.

This patch creates a virtual location for that token instead,
effectively tracking locations of tokens resulting from built-in macro
tokens.

libcpp/
* include/line-map.h (line_maps::builtin_location): New data
member.
(line_map_init): Add a new parameter to initialize the new
line_maps::builtin_location data member.
* line-map.c (linemap_init): Initialize the
line_maps::builtin_location data member.
* macro.c (builtin_macro): Create a macro map and track the token
resulting from the expansion of a built-in macro.
gcc/
* input.h (is_location_from_builtin_token): New function
declaration.
* input.c (is_location_from_builtin_token): New function
definition.
* toplev.c (general_init): Tell libcpp what the pre-defined
spelling location for built-in tokens is.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@212637 138bc75d-0d04-0410-961f-82ee72b054a4

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

index 11d7551cf42f7717b1f2d9c5978f6e21fbbf73e7..6680787ba4189b626933b3b1c7ea11a58f914572 100644 (file)
@@ -1,3 +1,13 @@
+2014-07-16  Dodji Seketeli  <dodji@redhat.com>
+
+       Support location tracking for built-in macro tokens
+       * input.h (is_location_from_builtin_token): New function
+       declaration.
+       * input.c (is_location_from_builtin_token): New function
+       definition.
+       * toplev.c (general_init): Tell libcpp what the pre-defined
+       spelling location for built-in tokens is.
+
 2014-07-16  Jakub Jelinek  <jakub@redhat.com>
 
        * omp-low.c (create_omp_child_function): Don't set DECL_NAMELESS
index 63cd062ec5b276afc25e4239721285f56e29f11a..f3fd0e9d755b8047393ce4b5a4a099e76255734b 100644 (file)
@@ -713,6 +713,22 @@ location_get_source_line (expanded_location xloc,
   return read ? buffer : NULL;
 }
 
+/* Test if the location originates from the spelling location of a
+   builtin-tokens.  That is, return TRUE if LOC is a (possibly
+   virtual) location of a built-in token that appears in the expansion
+   list of a macro.  Please note that this function also works on
+   tokens that result from built-in tokens.  For instance, the
+   function would return true if passed a token "4" that is the result
+   of the expansion of the built-in __LINE__ macro.  */
+bool
+is_location_from_builtin_token (source_location loc)
+{
+  const line_map *map = NULL;
+  loc = linemap_resolve_location (line_table, loc,
+                                 LRK_SPELLING_LOCATION, &map);
+  return loc == BUILTINS_LOCATION;
+}
+
 /* Expand the source location LOC into a human readable location.  If
    LOC is virtual, it resolves to the expansion point of the involved
    macro.  If LOC resolves to a builtin location, the file name of the
index d910bb88f9779fc95e0a073ff839d000b12401b6..1def793ae30fc14a0fa5dd1c6dfa30ab9ef428ca 100644 (file)
@@ -36,6 +36,7 @@ extern GTY(()) struct line_maps *line_table;
 extern char builtins_location_check[(BUILTINS_LOCATION
                                     < RESERVED_LOCATION_COUNT) ? 1 : -1];
 
+extern bool is_location_from_builtin_token (source_location);
 extern expanded_location expand_location (source_location);
 extern const char *location_get_source_line (expanded_location xloc,
                                             int *line_size);
index e35b826e89d65ca7ac679501c43d868bb12f5946..9e747e50b7ec39f6f07b100bf2093869a60025be 100644 (file)
@@ -1157,7 +1157,7 @@ general_init (const char *argv0)
   init_ggc ();
   init_stringpool ();
   line_table = ggc_alloc<line_maps> ();
-  linemap_init (line_table);
+  linemap_init (line_table, BUILTINS_LOCATION);
   line_table->reallocator = realloc_for_line_map;
   line_table->round_alloc_size = ggc_round_alloc_size;
   init_ttree ();
index 490bf4e50d15d0fa622c9237af1eba771786e316..7a6b8e3a5cc18b1a7ab07f807bd8a0a7802381ec 100644 (file)
@@ -1,3 +1,15 @@
+2014-07-16  Dodji Seketeli  <dodji@redhat.com>
+
+       Support location tracking for built-in macro tokens
+       * include/line-map.h (line_maps::builtin_location): New data
+       member.
+       (line_map_init): Add a new parameter to initialize the new
+       line_maps::builtin_location data member.
+       * line-map.c (linemap_init): Initialize the
+       line_maps::builtin_location data member.
+       * macro.c (builtin_macro): Create a macro map and track the token
+       resulting from the expansion of a built-in macro.
+
 2014-07-10  Edward Smith-Rowland  <3dw4rd@verizon.net>
            Jonathan Wakely  <jwakely@redhat.com>
 
index 9886314b25a03bb4a06dd8e0d23db3b01c972552..0c8f588abc51ad640ce95861d98438f312abd74c 100644 (file)
@@ -315,6 +315,10 @@ struct GTY(()) line_maps {
   line_map_round_alloc_size_func round_alloc_size;
 
   struct location_adhoc_data_map location_adhoc_data_map;
+
+  /* The special location value that is used as spelling location for
+     built-in tokens.  */
+  source_location builtin_location;
 };
 
 /* Returns the pointer to the memory region where information about
@@ -447,8 +451,12 @@ extern source_location get_location_from_adhoc_loc (struct line_maps *,
 
 extern void rebuild_location_adhoc_htab (struct line_maps *);
 
-/* Initialize a line map set.  */
-extern void linemap_init (struct line_maps *);
+/* Initialize a line map set.  SET is the line map set to initialize
+   and BUILTIN_LOCATION is the special location value to be used as
+   spelling location for built-in tokens.  This BUILTIN_LOCATION has
+   to be strictly less than RESERVED_LOCATION_COUNT.  */
+extern void linemap_init (struct line_maps *set,
+                         source_location builtin_location);
 
 /* Check for and warn about line_maps entered but not exited.  */
 
index f9a7658cbdbe4ffcc70773911a2efa9d6d41ce85..a4055c29c740c8ac7bc7b42cca8338bc29d2f94b 100644 (file)
@@ -175,13 +175,15 @@ location_adhoc_data_fini (struct line_maps *set)
 /* Initialize a line map set.  */
 
 void
-linemap_init (struct line_maps *set)
+linemap_init (struct line_maps *set,
+             source_location builtin_location)
 {
   memset (set, 0, sizeof (struct line_maps));
   set->highest_location = RESERVED_LOCATION_COUNT - 1;
   set->highest_line = RESERVED_LOCATION_COUNT - 1;
   set->location_adhoc_data_map.htab =
       htab_create (100, location_adhoc_data_hash, location_adhoc_data_eq, NULL);
+  set->builtin_location = builtin_location;
 }
 
 /* Check for and warn about line_maps entered but not exited.  */
index ab4817e8af60c599d1e5d64b056dcc15c7358f98..3b8fa4069352918166dc1cbf434d1de5028ea677 100644 (file)
@@ -428,7 +428,28 @@ builtin_macro (cpp_reader *pfile, cpp_hashnode *node)
 
   /* Set pfile->cur_token as required by _cpp_lex_direct.  */
   pfile->cur_token = _cpp_temp_token (pfile);
-  _cpp_push_token_context (pfile, NULL, _cpp_lex_direct (pfile), 1);
+  cpp_token *token = _cpp_lex_direct (pfile);
+  if (pfile->context->tokens_kind == TOKENS_KIND_EXTENDED)
+    {
+      /* We are tracking tokens resulting from macro expansion.
+        Create a macro line map and generate a virtual location for
+        the token resulting from the expansion of the built-in
+        macro.  */
+      source_location *virt_locs = NULL;
+      _cpp_buff *token_buf = tokens_buff_new (pfile, 1, &virt_locs);
+      const line_map * map =
+       linemap_enter_macro (pfile->line_table, node,
+                                           token->src_loc, 1);
+      tokens_buff_add_token (token_buf, virt_locs, token,
+                            pfile->line_table->builtin_location,
+                            pfile->line_table->builtin_location,
+                           map, /*macro_token_index=*/0);
+      push_extended_tokens_context (pfile, node, token_buf, virt_locs,
+                                   (const cpp_token **)token_buf->base,
+                                   1);
+    }
+  else
+    _cpp_push_token_context (pfile, NULL, token, 1);
   if (pfile->buffer->cur != pfile->buffer->rlimit)
     cpp_error (pfile, CPP_DL_ICE, "invalid built-in macro \"%s\"",
               NODE_NAME (node));