From c468587ac23c889abfa67ce8979e8baedcb349e9 Mon Sep 17 00:00:00 2001 From: Dodji Seketeli Date: Wed, 16 Jul 2014 10:33:27 +0000 Subject: Support location tracking for built-in macro tokens 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 From-SVN: r212637 --- libcpp/macro.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'libcpp/macro.c') diff --git a/libcpp/macro.c b/libcpp/macro.c index ab4817e..3b8fa40 100644 --- a/libcpp/macro.c +++ b/libcpp/macro.c @@ -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)); -- cgit v1.1