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]

Have C++ use LANG_HOOKS_WRITE_GLOBALS


This changes the C++ frontend to use LANG_HOOKS_WRITE_GLOBALS rather
than doing work in finish_file, making it more consistent with other
frontends.  (Eventually I think finish_file should go away.)

The change to toplev.c helps with diagnostic output.  It preserves the
C++ frontend's ability to output diagnostics for template
instantiation and so on even if there were diagnostics output
earlier.  The C version of LANG_HOOKS_WRITE_GLOBALS is unaffected
because it already bails out early if there were errors.  The other
version in the tree is generic, and appears to be safe even if errors
have already occurred; it might now be able to produce the second error in
scenarios like

foo.c:7:`fooble' is not declared
foo.c:5:static variable `foobel' never used

which of course helps a lot when you're trying to fix the first error.

Bootstrapped & tested on powerpc-darwin8; queued for 4.3.

-- 
- Geoffrey Keating <geoffk@apple.com>

===File ~/patches/gcc-cp-writeglobaldecls.patch=============
2006-09-25  Geoffrey Keating  <geoffk@apple.com>

	* toplev.c (compile_file): Call final_write_globals
	even if there have been errors.

Index: cp/ChangeLog
2006-09-25  Geoffrey Keating  <geoffk@apple.com>

	* decl2.c (cp_write_global_declarations): Rename from
	cp_finish_file.
	* cp-lang.c (finish_file): Don't call cp_finish_file.
	* cp-tree.h (cp_write_global_declarations): Rename from
	cp_finish_file.
	* cp-objcp-common.h (LANG_HOOKS_WRITE_GLOBALS): Define to
	cp_write_global_declarations.

Index: toplev.c
===================================================================
--- toplev.c	(revision 118166)
+++ toplev.c	(working copy)
@@ -1040,10 +1040,14 @@
      what's left of the symbol table output.  */
   timevar_pop (TV_PARSE);
 
-  if (flag_syntax_only || errorcount || sorrycount)
+  if (flag_syntax_only)
     return;
 
   lang_hooks.decls.final_write_globals ();
+
+  if (errorcount || sorrycount)
+    return;
+
   cgraph_varpool_assemble_pending_decls ();
   finish_aliases_2 ();
 
Index: cp/cp-objcp-common.h
===================================================================
--- cp/cp-objcp-common.h	(revision 118166)
+++ cp/cp-objcp-common.h	(working copy)
@@ -84,7 +84,7 @@
 #undef LANG_HOOKS_WARN_UNUSED_GLOBAL_DECL
 #define LANG_HOOKS_WARN_UNUSED_GLOBAL_DECL cxx_warn_unused_global_decl
 #undef LANG_HOOKS_WRITE_GLOBALS
-#define LANG_HOOKS_WRITE_GLOBALS lhd_do_nothing
+#define LANG_HOOKS_WRITE_GLOBALS cp_write_global_declarations
 #undef LANG_HOOKS_COMDAT_GROUP
 #define LANG_HOOKS_COMDAT_GROUP cxx_comdat_group
 
Index: cp/cp-tree.h
===================================================================
--- cp/cp-tree.h	(revision 118166)
+++ cp/cp-tree.h	(working copy)
@@ -3971,7 +3971,7 @@
 			  tree);
 extern void cplus_decl_attributes		(tree *, tree, int);
 extern void finish_anon_union			(tree);
-extern void cp_finish_file			(void);
+extern void cp_write_global_declarations	(void);
 extern tree coerce_new_type			(tree);
 extern tree coerce_delete_type			(tree);
 extern void comdat_linkage			(tree);
Index: cp/cp-lang.c
===================================================================
--- cp/cp-lang.c	(revision 118166)
+++ cp/cp-lang.c	(working copy)
@@ -141,7 +141,6 @@
 void
 finish_file (void)
 {
-  cp_finish_file ();
 }
 
 #include "gtype-cp.h"
Index: cp/decl2.c
===================================================================
--- cp/decl2.c	(revision 118166)
+++ cp/decl2.c	(working copy)
@@ -3029,13 +3029,13 @@
     }
 }
 
-/* This routine is called from the last rule in yyparse ().
+/* This routine is called at the end of compilation.
    Its job is to create all the code needed to initialize and
    destroy the global aggregates.  We do the destruction
    first, since that way we only need to reverse the decls once.  */
 
 void
-cp_finish_file (void)
+cp_write_global_declarations (void)
 {
   tree vars;
   bool reconsider;
============================================================


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