diff options
author | gchare <gchare@138bc75d-0d04-0410-961f-82ee72b054a4> | 2011-08-22 20:41:07 +0000 |
---|---|---|
committer | gchare <gchare@138bc75d-0d04-0410-961f-82ee72b054a4> | 2011-08-22 20:41:07 +0000 |
commit | 6ea2c7a39e48b9b78626cec92b83a0a6e9b05f9f (patch) | |
tree | edc710dc37d6c755bf80f2e8489e337aeb7186da /libcpp/lex.c | |
parent | c3271fdb04f8f85e05e726ce72dc99c5dd82094c (diff) | |
download | gcc-6ea2c7a39e48b9b78626cec92b83a0a6e9b05f9f.tar.gz |
Add ability to force lexed tokens' source_locations.
Use it to force BUILTINS_LOCATION when declaring builtins instead of creating a <built-in> entry in the line_table which is wrong.
* c-opts.c (c_finish_options): Force BUILTINS_LOCATION for tokens
defined in cpp_init_builtins and c_cpp_builtins.
gcc/fortran/ChangeLog
* cpp.c (gfc_cpp_init): Force BUILTINS_LOCATION for tokens
defined in cpp_define_builtins.
libcpp/ChangeLog
* init.c (cpp_create_reader): Inititalize forced_token_location_p.
* internal.h (struct cpp_reader): Add field forced_token_location_p.
* lex.c (_cpp_lex_direct): Use forced_token_location_p.
(cpp_force_token_locations): New.
(cpp_stop_forcing_token_locations): New.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@177973 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libcpp/lex.c')
-rw-r--r-- | libcpp/lex.c | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/libcpp/lex.c b/libcpp/lex.c index 463b5c80eee..75b2b1dc7ff 100644 --- a/libcpp/lex.c +++ b/libcpp/lex.c @@ -1975,8 +1975,11 @@ _cpp_lex_direct (cpp_reader *pfile) } c = *buffer->cur++; - result->src_loc = linemap_position_for_column (pfile->line_table, - CPP_BUF_COLUMN (buffer, buffer->cur)); + if (pfile->forced_token_location_p) + result->src_loc = *pfile->forced_token_location_p; + else + result->src_loc = linemap_position_for_column (pfile->line_table, + CPP_BUF_COLUMN (buffer, buffer->cur)); switch (c) { @@ -2839,3 +2842,21 @@ cpp_token_val_index (cpp_token *tok) return CPP_TOKEN_FLD_NONE; } } + +/* All tokens lexed in R after calling this function will be forced to have + their source_location the same as the location referenced by P, until + cpp_stop_forcing_token_locations is called for R. */ + +void +cpp_force_token_locations (cpp_reader *r, source_location *p) +{ + r->forced_token_location_p = p; +} + +/* Go back to assigning locations naturally for lexed tokens. */ + +void +cpp_stop_forcing_token_locations (cpp_reader *r) +{ + r->forced_token_location_p = NULL; +} |