[pph] Stream scope_chain->bindings instead of global namespace (issue4661045)

Gabriel Charette gchare@google.com
Wed Jun 22 22:39:00 GMT 2011


gcc/cp/pph-streamer-in.c:1003: namespace.
 1001       /* FIXME pph: this carried over from pph_add_names_to_namespace,
 1002 »        it only makes sense to use this when merging names in an existing
 1003 »        namespace.

pph_add_names_to_namespace does not exist anymore.  I don't understand this
comment.

What I meant is that pph_add_bindings_to_namespace is just a modified version of
the old pph_add_names_to_namespace in which this recursive call was made (and was
already useless before, i.e. commenting it out wouldn't introduce any changes in the
test results...).

I changed the comment, adding it to the FIXME just above it which mentions we should
check if this namespace already exists (i.e. it only makes sense to add bindings
in the "streamed in" namespace to the actual namespace IF they are NOT the same object
(otherwise the bindings are already part of the "streamed in" namespace so this call is useless).

######################################
gcc/cp/pph-streamer-out.c:947: gcc_assert ( ss->old_namespace ==
global_namespace
  945   /* old_namespace should be global_namespace and all entries listed below
  946      should be NULL or 0; otherwise the header parsed was incomplete.  */
  947   gcc_assert ( ss->old_namespace == global_namespace

No space after '('.

FIXED.

######################################
gcc/cp/pph-streamer-out.c:949: || ss->function_decl || ss->template_parms ||
ss->x_saved_tree
  948       && !(ss->class_name || ss->class_type || ss->access_specifier
  949            || ss->function_decl || ss->template_parms || ss->x_saved_tree

Align '&&' vertically with the open brace.

FIXED.

######################################
gcc/cp/pph-streamer.c:34: #include "name-lookup.h"
  33 #include "cppbuiltin.h"
+ 34 #include "name-lookup.h"

You also need to add cp/name-lookup.h to the list of dependencies for cp/pph.o
in cp/Make-lang.in.

I simply removed the include, I originally added it because it holds global_namespace, but it
compiles without it (which I guess is fine if we don't try to stick to "include what you use").

2011-06-22  Gabriel Charette  <gchare@google.com>

	* gcc/cp/pph-streamer-in.c (pph_add_names_to_namespace): Replaced by
	pph_add_bindings_to_namespace.
	(pph_add_bindings_to_namespace): New.
	(pph_in_scope_chain): New.
	(pph_read_file_contents): Remove unused variable file_ns.
	(pph_read_file_contents): Call pph_in_scope_chain.
	* gcc/cp/pph-streamer-out.c (pph_out_scope_chain): New.
	(pph_write_file_contents): Call pph_out_scope_chain.
	* gcc/cp/pph-streamer.c (pph_preload_common_nodes):
	Call lto_streamer_cache_append.

diff --git a/gcc/cp/pph-streamer-in.c b/gcc/cp/pph-streamer-in.c
index e71f744..c16b88d 100644
--- a/gcc/cp/pph-streamer-in.c
+++ b/gcc/cp/pph-streamer-in.c
@@ -976,15 +976,14 @@ pph_in_lang_type (pph_stream *stream)
 }
 
 
-/* Add all the new names declared in NEW_NS to NS.  */
+/* Add all bindings declared in BL to NS.  */
 
 static void
-pph_add_names_to_namespace (tree ns, tree new_ns)
+pph_add_bindings_to_namespace (struct cp_binding_level *bl, tree ns)
 {
   tree t, chain;
-  struct cp_binding_level *level = NAMESPACE_LEVEL (new_ns);
 
-  for (t = level->names; t; t = chain)
+  for (t = bl->names; t; t = chain)
     {
       /* Pushing a decl into a scope clobbers its DECL_CHAIN.
 	 Preserve it.  */
@@ -992,18 +991,33 @@ pph_add_names_to_namespace (tree ns, tree new_ns)
       pushdecl_into_namespace (t, ns);
     }
 
-  for (t = level->namespaces; t; t = chain)
+  for (t = bl->namespaces; t; t = chain)
     {
       /* Pushing a decl into a scope clobbers its DECL_CHAIN.
 	 Preserve it.  */
-      /* FIXME pph: we should first check to see if it isn't already there.  */
+      /* FIXME pph: we should first check to see if it isn't already there.  
+		    If it is, we should use this function recursively to merge
+		    the bindings in T in the corresponding namespace.  */
       chain = DECL_CHAIN (t);
       pushdecl_into_namespace (t, ns);
-      pph_add_names_to_namespace (t, t);
     }
 }
 
 
+/* Merge scope_chain bindings from the stream into SS. */
+
+static void
+pph_in_scope_chain (pph_stream *stream)
+{
+  struct cp_binding_level *pph_bindings;
+
+  pph_bindings = pph_in_binding_level (stream);
+
+  /* Merge the bindings obtained from STREAM in the global namespace.  */
+  pph_add_bindings_to_namespace (pph_bindings, global_namespace);
+}
+
+
 /* Wrap a macro DEFINITION for printing in an error.  */
 
 static char *
@@ -1128,7 +1142,6 @@ pph_read_file_contents (pph_stream *stream)
   cpp_ident_use *bad_use;
   const char *cur_def;
   cpp_idents_used idents_used;
-  tree file_ns;
 
   pth_load_identifiers (&idents_used, stream);
 
@@ -1141,12 +1154,12 @@ pph_read_file_contents (pph_stream *stream)
   /* Re-instantiate all the pre-processor symbols defined by STREAM.  */
   cpp_lt_replay (parse_in, &idents_used);
 
-  /* Read global_namespace from STREAM and add all the names defined
-     there to the current global_namespace.  */
-  file_ns = pph_in_tree (stream);
+  /* Read the bindings from STREAM and merge them with the current bindings.  */
+  pph_in_scope_chain (stream);
+
   if (flag_pph_dump_tree)
-    pph_dump_namespace (pph_logfile, file_ns);
-  pph_add_names_to_namespace (global_namespace, file_ns);
+    pph_dump_namespace (pph_logfile, global_namespace);
+
   keyed_classes = pph_in_tree (stream);
   unemitted_tinfo_decls = pph_in_tree_vec (stream);
   /* FIXME pph: This call replaces the tinfo, we should merge instead.
diff --git a/gcc/cp/pph-streamer-out.c b/gcc/cp/pph-streamer-out.c
index 3187338..4c3e4a5 100644
--- a/gcc/cp/pph-streamer-out.c
+++ b/gcc/cp/pph-streamer-out.c
@@ -935,6 +935,34 @@ pph_out_lang_type (pph_stream *stream, tree type, bool ref_p)
 }
 
 
+/* Write saved_scope information stored in SS, does NOT output all fields,
+   meant to be used for the global variable "scope_chain" only.
+   Output bindings as references if REF_P is true.  */
+
+static void
+pph_out_scope_chain (pph_stream *stream, struct saved_scope *ss, bool ref_p)
+{
+  /* old_namespace should be global_namespace and all entries listed below
+     should be NULL or 0; otherwise the header parsed was incomplete.  */
+  gcc_assert (ss->old_namespace == global_namespace
+	      && !(ss->class_name || ss->class_type || ss->access_specifier
+		   || ss->function_decl || ss->template_parms
+		   || ss->x_saved_tree || ss->class_bindings || ss->prev
+		   || ss->unevaluated_operand
+		   || ss->inhibit_evaluation_warnings
+		   || ss->x_processing_template_decl
+		   || ss->x_processing_specialization
+		   || ss->x_processing_explicit_instantiation
+		   || ss->need_pop_function_context
+		   || ss->x_stmt_tree.x_cur_stmt_list
+		   || ss->x_stmt_tree.stmts_are_full_exprs_p));
+
+  /* We only need to write out the bindings, everything else should
+     be NULL or be some temporary disposable state.  */
+  pph_out_binding_level (stream, ss->bindings, ref_p);
+}
+
+
 /* Save the IDENTIFIERS to the STREAM.  */
 
 static void
@@ -991,9 +1019,9 @@ static void
 pph_write_file_contents (pph_stream *stream, cpp_idents_used *idents_used)
 { 
   pth_save_identifiers (idents_used, stream);
+  pph_out_scope_chain (stream, scope_chain, false);
   if (flag_pph_dump_tree)
     pph_dump_namespace (pph_logfile, global_namespace);
-  pph_out_tree (stream, global_namespace, false);
   pph_out_tree (stream, keyed_classes, false);
   pph_out_tree_vec (stream, unemitted_tinfo_decls, false);
 }
diff --git a/gcc/cp/pph-streamer.c b/gcc/cp/pph-streamer.c
index 7c9b862..e919baf 100644
--- a/gcc/cp/pph-streamer.c
+++ b/gcc/cp/pph-streamer.c
@@ -78,6 +78,8 @@ pph_preload_common_nodes (struct lto_streamer_cache_d *cache)
   for (i = 0; i < CTI_MAX; i++)
     if (c_global_trees[i])
       lto_streamer_cache_append (cache, c_global_trees[i]);
+
+  lto_streamer_cache_append (cache, global_namespace);
 }
 
 

--
This patch is available for review at http://codereview.appspot.com/4661045



More information about the Gcc-patches mailing list