aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gcc/c-family/ChangeLog5
-rw-r--r--gcc/c-family/c-opts.c15
-rw-r--r--gcc/fortran/ChangeLog5
-rw-r--r--gcc/fortran/cpp.c12
-rw-r--r--libcpp/ChangeLog8
-rw-r--r--libcpp/include/cpplib.h4
-rw-r--r--libcpp/init.c3
-rw-r--r--libcpp/internal.h4
-rw-r--r--libcpp/lex.c25
9 files changed, 72 insertions, 9 deletions
diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog
index df9cdff..fb00ca9 100644
--- a/gcc/c-family/ChangeLog
+++ b/gcc/c-family/ChangeLog
@@ -1,3 +1,8 @@
+011-08-22 Gabriel Charette <gchare@google.com>
+
+ * c-opts.c (c_finish_options): Force BUILTINS_LOCATION for tokens
+ defined in cpp_init_builtins and c_cpp_builtins.
+
2011-08-19 Joseph Myers <joseph@codesourcery.com>
* c-common.c (c_common_reswords): Add __builtin_complex.
diff --git a/gcc/c-family/c-opts.c b/gcc/c-family/c-opts.c
index 3227f7b..49ff80d 100644
--- a/gcc/c-family/c-opts.c
+++ b/gcc/c-family/c-opts.c
@@ -1306,12 +1306,17 @@ c_finish_options (void)
{
size_t i;
- cb_file_change (parse_in,
- linemap_add (line_table, LC_RENAME, 0,
- _("<built-in>"), 0));
+ {
+ /* Make sure all of the builtins about to be declared have
+ BUILTINS_LOCATION has their source_location. */
+ source_location builtins_loc = BUILTINS_LOCATION;
+ cpp_force_token_locations (parse_in, &builtins_loc);
- cpp_init_builtins (parse_in, flag_hosted);
- c_cpp_builtins (parse_in);
+ cpp_init_builtins (parse_in, flag_hosted);
+ c_cpp_builtins (parse_in);
+
+ cpp_stop_forcing_token_locations (parse_in);
+ }
/* We're about to send user input to cpplib, so make it warn for
things that we previously (when we sent it internal definitions)
diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog
index 69d901e..075c366 100644
--- a/gcc/fortran/ChangeLog
+++ b/gcc/fortran/ChangeLog
@@ -1,3 +1,8 @@
+2011-08-22 Gabriel Charette <gchare@google.com>
+
+ * cpp.c (gfc_cpp_init): Force BUILTINS_LOCATION for tokens
+ defined in cpp_define_builtins.
+
2011-08-22 Mikael Morin <mikael.morin@gcc.gnu.org>
PR fortran/50050
diff --git a/gcc/fortran/cpp.c b/gcc/fortran/cpp.c
index a40442e..9368d89 100644
--- a/gcc/fortran/cpp.c
+++ b/gcc/fortran/cpp.c
@@ -565,9 +565,17 @@ gfc_cpp_init (void)
if (gfc_option.flag_preprocessed)
return;
- cpp_change_file (cpp_in, LC_RENAME, _("<built-in>"));
if (!gfc_cpp_option.no_predefined)
- cpp_define_builtins (cpp_in);
+ {
+ /* Make sure all of the builtins about to be declared have
+ BUILTINS_LOCATION has their source_location. */
+ source_location builtins_loc = BUILTINS_LOCATION;
+ cpp_force_token_locations (cpp_in, &builtins_loc);
+
+ cpp_define_builtins (cpp_in);
+
+ cpp_stop_forcing_token_locations (cpp_in);
+ }
/* Handle deferred options from command-line. */
cpp_change_file (cpp_in, LC_RENAME, _("<command-line>"));
diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog
index 81b3a94..8a5e899 100644
--- a/libcpp/ChangeLog
+++ b/libcpp/ChangeLog
@@ -1,3 +1,11 @@
+2011-08-22 Gabriel Charette <gchare@google.com>
+
+ * 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.
+
2011-08-18 Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE>
PR libstdc++/1773
diff --git a/libcpp/include/cpplib.h b/libcpp/include/cpplib.h
index 4d68fa7..0e90821 100644
--- a/libcpp/include/cpplib.h
+++ b/libcpp/include/cpplib.h
@@ -989,4 +989,8 @@ extern void cpp_prepare_state (cpp_reader *, struct save_macro_data **);
extern int cpp_read_state (cpp_reader *, const char *, FILE *,
struct save_macro_data *);
+/* In lex.c */
+extern void cpp_force_token_locations (cpp_reader *, source_location *);
+extern void cpp_stop_forcing_token_locations (cpp_reader *);
+
#endif /* ! LIBCPP_CPPLIB_H */
diff --git a/libcpp/init.c b/libcpp/init.c
index 93f12d0..c5c5325 100644
--- a/libcpp/init.c
+++ b/libcpp/init.c
@@ -223,6 +223,9 @@ cpp_create_reader (enum c_lang lang, hash_table *table,
/* Initialize table for push_macro/pop_macro. */
pfile->pushed_macros = 0;
+ /* Do not force token locations by default. */
+ pfile->forced_token_location_p = NULL;
+
/* The expression parser stack. */
_cpp_expand_op_stack (pfile);
diff --git a/libcpp/internal.h b/libcpp/internal.h
index d2872c4..6c423f0 100644
--- a/libcpp/internal.h
+++ b/libcpp/internal.h
@@ -499,6 +499,10 @@ struct cpp_reader
/* List of saved macros by push_macro. */
struct def_pragma_macro *pushed_macros;
+
+ /* If non-null, the lexer will use this location for the next token
+ instead of getting a location from the linemap. */
+ source_location *forced_token_location_p;
};
/* Character classes. Based on the more primitive macros in safe-ctype.h.
diff --git a/libcpp/lex.c b/libcpp/lex.c
index 463b5c8..75b2b1d 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;
+}