This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[6/6] Preprocessor forced macro location


There's an API for forcing all macro definition token positions to be X. That takes a pointer to X, so one can distinguish between not forcing a location, and forcing the location to be UNKNOWN_LOCATION.

However, we only use this to force BUILTINS_LOCATION, and if you're forcing UNKNOWN_LOCATION, I'd argue you're doing it wrong.

This patch changes that API to take a location directly, and ban forcing UNKNOWN_LOCATION.

booted & tested on x86_64-linux (as were all the others).

Applying to trunk.


nathan

--
Nathan Sidwell
2018-10-31  Nathan Sidwell  <nathan@acm.org>

	libcpp/
	* internal.h (struct cpp_reader): Rename forced_token_location_p
	to forced_token_location and drop its pointerness.
	* include/cpplib.h (cpp_force_token_locations): Take location, not
	pointer to one.
	* init.c (cpp_create_reader): Adjust.
	* lex.c (cpp_read_main_file): 

	gcc/c-family/
	* c-opts.c (c_finish_options): Adjust cpp_force_token_locations call.

	gcc/fortran/
	* cpp.c (gfc_cpp_init): Adjust cpp_force_token_locations call.

Index: libcpp/include/cpplib.h
===================================================================
--- libcpp/include/cpplib.h	(revision 265688)
+++ libcpp/include/cpplib.h	(working copy)
@@ -1281,7 +1281,7 @@ extern int cpp_read_state (cpp_reader *,
 			   struct save_macro_data *);
 
 /* In lex.c */
-extern void cpp_force_token_locations (cpp_reader *, source_location *);
+extern void cpp_force_token_locations (cpp_reader *, source_location);
 extern void cpp_stop_forcing_token_locations (cpp_reader *);
 
 /* In expr.c */
Index: libcpp/init.c
===================================================================
--- libcpp/init.c	(revision 265671)
+++ libcpp/init.c	(working copy)
@@ -264,7 +264,7 @@ cpp_create_reader (enum c_lang lang, cpp
   pfile->pushed_macros = 0;
 
   /* Do not force token locations by default.  */
-  pfile->forced_token_location_p = NULL;
+  pfile->forced_token_location = 0;
 
   /* Initialize source_date_epoch to -2 (not yet set).  */
   pfile->source_date_epoch = (time_t) -2;
Index: libcpp/internal.h
===================================================================
--- libcpp/internal.h	(revision 265671)
+++ libcpp/internal.h	(working copy)
@@ -570,9 +570,9 @@ 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
+  /* If non-zero, the lexer will use this location for the next token
      instead of getting a location from the linemap.  */
-  source_location *forced_token_location_p;
+  source_location forced_token_location;
 };
 
 /* Character classes.  Based on the more primitive macros in safe-ctype.h.
Index: libcpp/lex.c
===================================================================
--- libcpp/lex.c	(revision 265671)
+++ libcpp/lex.c	(working copy)
@@ -2757,8 +2757,8 @@ _cpp_lex_direct (cpp_reader *pfile)
     }
   c = *buffer->cur++;
 
-  if (pfile->forced_token_location_p)
-    result->src_loc = *pfile->forced_token_location_p;
+  if (pfile->forced_token_location)
+    result->src_loc = pfile->forced_token_location;
   else
     result->src_loc = linemap_position_for_column (pfile->line_table,
 					  CPP_BUF_COLUMN (buffer, buffer->cur));
@@ -3773,14 +3773,14 @@ cpp_token_val_index (const cpp_token *to
     }
 }
 
-/* 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
+/* All tokens lexed in R after calling this function will be forced to
+   have their source_location to be P, until
    cpp_stop_forcing_token_locations is called for R.  */
 
 void
-cpp_force_token_locations (cpp_reader *r, source_location *p)
+cpp_force_token_locations (cpp_reader *r, source_location loc)
 {
-  r->forced_token_location_p = p;
+  r->forced_token_location = loc;
 }
 
 /* Go back to assigning locations naturally for lexed tokens.  */
@@ -3788,5 +3788,5 @@ cpp_force_token_locations (cpp_reader *r
 void
 cpp_stop_forcing_token_locations (cpp_reader *r)
 {
-  r->forced_token_location_p = NULL;
+  r->forced_token_location = 0;
 }
Index: gcc/c-family/c-opts.c
===================================================================
--- gcc/c-family/c-opts.c	(revision 265671)
+++ gcc/c-family/c-opts.c	(working copy)
@@ -1396,8 +1396,7 @@ c_finish_options (void)
 							   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_force_token_locations (parse_in, BUILTINS_LOCATION);
 
       cpp_init_builtins (parse_in, flag_hosted);
       c_cpp_builtins (parse_in);
Index: gcc/fortran/cpp.c
===================================================================
--- gcc/fortran/cpp.c	(revision 265671)
+++ gcc/fortran/cpp.c	(working copy)
@@ -579,8 +579,7 @@ gfc_cpp_init (void)
     {
       /* 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_force_token_locations (cpp_in, BUILTINS_LOCATION);
 
       cpp_define_builtins (cpp_in);
 

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]