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]

Re: PATCH: small pre-compile-server patches


Oops.  I also need to change cpp_rename_file ->
to cpp_change_file in fix-header.c.  Here is a fixed
version of the patch.
--
	--Per Bothner
per at bothner dot com   http://per.bothner.com/

2003-03-19  Per Bothner  <per at bothner dot com>

	Various cleanups to help compile server.

	* cppinit.c (cpp_create_reader):  Take extra hash_table* argument,
	and pass that to _cpp_init_hashtable.
	(cpp_read_main_file):  Drop hash_table* argument; don't call
	_cpp_init_hashtable.
	* cpplib.h:  Update declarations to match.
	* c-opts.c (c_common_init_options):  Pass ident_hash to
	cpp_create_reader.
	(c_common_post_options):  Don't pass ident_hash to cpp_read_main_file.
	* fix-header.c (read_scan_file):  Likewise pass NULL table to
	cpp_create_reader rather than cpp_read_main_file.
	
	* cppfiles.c (cpp_rename_file):  Generalized and renamed
	to cpp_change_file.
	* cpplib.h:  Update declaration to match.
	* c-opts.c (push_command_line_line, finish_options):  Change
	cpp_rename_file calls to cpp_change_file.
	* fix-header.c (read_scan_file):  Likewise.
	
	* line-map.c (add_line_map):  Allow leaving the outermost file.
	Allowing entering an outermost-file after the initial time. 

	* toplev.c (pop_srcloc):  Allow popping from initial file.

Index: c-opts.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-opts.c,v
retrieving revision 1.39
diff -u -p -r1.39 c-opts.c
--- c-opts.c	17 Mar 2003 06:41:06 -0000	1.39
+++ c-opts.c	19 Mar 2003 23:56:01 -0000
@@ -587,7 +587,8 @@ c_common_init_options (lang)
 #endif
 
   c_language = lang;
-  parse_in = cpp_create_reader (lang == clk_c ? CLK_GNUC89 : CLK_GNUCXX);
+  parse_in = cpp_create_reader (lang == clk_c ? CLK_GNUC89 : CLK_GNUCXX,
+				ident_hash);
   cpp_opts = cpp_get_options (parse_in);
   if (flag_objc)
     cpp_opts->objc = 1;
@@ -1569,7 +1570,7 @@ c_common_post_options (pfilename)
   cpp_get_callbacks (parse_in)->file_change = cb_file_change;
 
   /* NOTE: we use in_fname here, not the one supplied.  */
-  *pfilename = cpp_read_main_file (parse_in, in_fname, ident_hash);
+  *pfilename = cpp_read_main_file (parse_in, in_fname);
 
   saved_lineno = lineno;
   lineno = 0;
@@ -1784,10 +1785,10 @@ finish_options ()
     {
       size_t i;
 
-      cpp_rename_file (parse_in, _("<built-in>"));
+      cpp_change_file (parse_in, LC_RENAME, _("<built-in>"));
       cpp_init_builtins (parse_in);
       c_cpp_builtins (parse_in);
-      cpp_rename_file (parse_in, _("<command line>"));
+      cpp_change_file (parse_in, LC_RENAME, _("<command line>"));
       for (i = 0; i < deferred_count; i++)
 	{
 	  struct deferred_opt *opt = &deferred_opts[i];
@@ -1837,7 +1838,7 @@ push_command_line_include ()
   if (include_cursor == deferred_count)
     {
       /* Restore the line map from <command line>.  */
-      cpp_rename_file (parse_in, main_input_filename);
+      cpp_change_file (parse_in, LC_RENAME, main_input_filename);
       /* -Wunused-macros should only warn about macros defined hereafter.  */
       cpp_opts->warn_unused_macros = warn_unused_macros;
       include_cursor++;
Index: cppfiles.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cppfiles.c,v
retrieving revision 1.165
diff -u -p -r1.165 cppfiles.c
--- cppfiles.c	12 Mar 2003 21:31:48 -0000	1.165
+++ cppfiles.c	19 Mar 2003 23:56:01 -0000
@@ -756,14 +756,16 @@ cpp_make_system_header (pfile, syshdr, e
 		       SOURCE_LINE (pfile->map, pfile->line), flags);
 }
 
-/* Allow the client to rename the current file.  Used by the front end
-   to achieve pseudo-file names like <built-in>.  */
+/* Allow the client to change the current file.  Used by the front end
+   to achieve pseudo-file names like <built-in>.
+   If REASON is LC_LEAVE, then NEW_NAME must be NULL.  */
 void
-cpp_rename_file (pfile, new_name)
+cpp_change_file (pfile, reason, new_name)
      cpp_reader *pfile;
+     enum lc_reason reason;
      const char *new_name;
 {
-  _cpp_do_file_change (pfile, LC_RENAME, new_name, 1, 0);
+  _cpp_do_file_change (pfile, reason, new_name, 1, 0);
 }
 
 /* Report on all files that might benefit from a multiple include guard.
Index: cppinit.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cppinit.c,v
retrieving revision 1.274
diff -u -p -r1.274 cppinit.c
--- cppinit.c	15 Mar 2003 12:18:45 -0000	1.274
+++ cppinit.c	19 Mar 2003 23:56:02 -0000
@@ -132,8 +132,9 @@ init_library ()
 
 /* Initialize a cpp_reader structure.  */
 cpp_reader *
-cpp_create_reader (lang)
+cpp_create_reader (lang, table)
      enum c_lang lang;
+     hash_table *table;
 {
   cpp_reader *pfile;
 
@@ -199,6 +200,8 @@ cpp_create_reader (lang)
 
   _cpp_init_includes (pfile);
 
+  _cpp_init_hashtable (pfile, table);
+
   return pfile;
 }
 
@@ -429,19 +432,13 @@ cpp_add_dependency_target (pfile, target
    or stdin if it is the empty string.  Return the original filename
    on success (e.g. foo.i->foo.c), or NULL on failure.  */
 const char *
-cpp_read_main_file (pfile, fname, table)
+cpp_read_main_file (pfile, fname)
      cpp_reader *pfile;
      const char *fname;
-     hash_table *table;
 {
   sanity_checks (pfile);
 
   post_options (pfile);
-
-  /* The front ends don't set up the hash table until they have
-     finished processing the command line options, so initializing the
-     hashtable is deferred until now.  */
-  _cpp_init_hashtable (pfile, table);
 
   /* Mark named operators before handling command line macros.  */
   if (CPP_OPTION (pfile, cplusplus) && CPP_OPTION (pfile, operator_names))
Index: cpplib.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cpplib.h,v
retrieving revision 1.249
diff -u -p -r1.249 cpplib.h
--- cpplib.h	17 Mar 2003 06:41:06 -0000	1.249
+++ cpplib.h	19 Mar 2003 23:56:02 -0000
@@ -485,8 +485,13 @@ struct cpp_hashnode GTY(())
   } GTY ((desc ("0"))) value;
 };
 
-/* Call this first to get a handle to pass to other functions.  */
-extern cpp_reader *cpp_create_reader PARAMS ((enum c_lang));
+/* Call this first to get a handle to pass to other functions.
+
+   If you want cpplib to manage its own hashtable, pass in a NULL
+   pointer.  Otherwise you should pass in an initialized hash table
+   that cpplib will share; this technique is used by the C front
+   ends.  */
+extern cpp_reader *cpp_create_reader PARAMS ((enum c_lang, struct ht *));
 
 /* Call this to change the selected language standard (e.g. because of
    command line options).  */
@@ -518,14 +523,8 @@ extern void cpp_set_callbacks PARAMS ((c
    returns the name of the original file; this is the same as the
    input file, except for preprocessed input.  This will generate at
    least one file change callback, and possibly a line change callback
-   too.  If there was an error opening the file, it returns NULL.
-
-   If you want cpplib to manage its own hashtable, pass in a NULL
-   pointer.  Otherwise you should pass in an initialized hash table
-   that cpplib will share; this technique is used by the C front
-   ends.  */
-extern const char *cpp_read_main_file PARAMS ((cpp_reader *, const char *,
-					       struct ht *));
+   too.  If there was an error opening the file, it returns NULL.  */
+extern const char *cpp_read_main_file PARAMS ((cpp_reader *, const char *));
 
 /* Set up built-ins like __FILE__.  */
 extern void cpp_init_builtins PARAMS ((cpp_reader *));
@@ -708,7 +707,8 @@ extern int cpp_included	PARAMS ((cpp_rea
 extern void cpp_make_system_header PARAMS ((cpp_reader *, int, int));
 extern void cpp_simplify_path PARAMS ((char *));
 extern bool cpp_push_include PARAMS ((cpp_reader *, const char *));
-extern void cpp_rename_file PARAMS ((cpp_reader *, const char *));
+extern void cpp_change_file PARAMS ((cpp_reader *, enum lc_reason,
+				     const char *));
 
 /* In cpppch.c */
 struct save_macro_data;
Index: line-map.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/line-map.c,v
retrieving revision 1.7
diff -u -p -r1.7 line-map.c
--- line-map.c	16 Dec 2002 18:19:42 -0000	1.7
+++ line-map.c	19 Mar 2003 23:56:03 -0000
@@ -106,9 +106,9 @@ add_line_map (set, reason, sysp, from_li
 
       if (MAIN_FILE_P (map - 1))
 	{
-	  error = true;
-	  reason = LC_RENAME;
-	  from = map - 1;
+	  set->depth--;
+	  set->used--;
+	  return NULL;
 	}
       else
 	{
@@ -139,8 +139,8 @@ add_line_map (set, reason, sysp, from_li
 
   if (reason == LC_ENTER)
     {
+      map->included_from = set->depth == 0 ? -1 : (int) (set->used - 2);
       set->depth++;
-      map->included_from = set->used - 2;
       if (set->trace_includes)
 	trace_include (set, map);
     }
Index: toplev.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/toplev.c,v
retrieving revision 1.735
diff -u -p -r1.735 toplev.c
--- toplev.c	12 Mar 2003 00:19:37 -0000	1.735
+++ toplev.c	19 Mar 2003 23:56:06 -0000
@@ -2166,11 +2166,17 @@ pop_srcloc ()
   input_file_stack = fs->next;
   free (fs);
   input_file_stack_tick++;
-  /* The initial source file is never popped.  */
-  if (!input_file_stack)
-    abort ();
-  input_filename = input_file_stack->name;
-  lineno = input_file_stack->line;
+
+  if (input_file_stack)
+    {
+      input_filename = input_file_stack->name;
+      lineno = input_file_stack->line;
+    }
+  else
+    {
+      input_filename = NULL;
+      lineno = 0;
+    }
 }
 
 /* Compile an entire translation unit.  Write a file of assembly
Index: fix-header.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fix-header.c,v
retrieving revision 1.91
diff -u -p -r1.91 fix-header.c
--- fix-header.c	17 Mar 2003 06:39:37 -0000	1.91
+++ fix-header.c	19 Mar 2003 23:56:06 -0000
@@ -622,7 +622,7 @@ read_scan_file (in_fname, argc, argv)
 
   obstack_init (&scan_file_obstack);
 
-  scan_in = cpp_create_reader (CLK_GNUC89);
+  scan_in = cpp_create_reader (CLK_GNUC89, NULL);
   cb = cpp_get_callbacks (scan_in);
   cb->file_change = cb_file_change;
 
@@ -632,7 +632,7 @@ read_scan_file (in_fname, argc, argv)
   options->inhibit_warnings = 1;
   options->inhibit_errors = 1;
 
-  if (! cpp_read_main_file (scan_in, in_fname, NULL))
+  if (! cpp_read_main_file (scan_in, in_fname))
     exit (FATAL_EXIT_CODE);
 
   for (i = 0; i < argc; i += strings_processed)
@@ -675,9 +675,9 @@ read_scan_file (in_fname, argc, argv)
 			   true /* stdinc */, false /* cxx_stdinc */,
 			   false /* verbose */);
 
-  cpp_rename_file (scan_in, "<built-in>");
+  cpp_change_file (scan_in, LC_RENAME, "<built-in>");
   cpp_init_builtins (scan_in);
-  cpp_rename_file (scan_in, in_fname);
+  cpp_change_file (scan_in, LC_RENAME, in_fname);
 
   /* We are scanning a system header, so mark it as such.  */
   cpp_make_system_header (scan_in, 1, 0);

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