I've made a couple of minor edits to comments and formatting and committed to the branch (final patch below).
Diego. commit 2f0fa40cd3e0c9debb4efae6c65530a7c6d3fb0f Author: dnovillo <dnovillo@138bc75d-0d04-0410-961f-82ee72b054a4> Date: Thu Jun 23 17:18:27 2011 +0000 2011-06-22 Gabriel Charette <gch...@google.com> * 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. * pph-streamer-out.c (pph_out_scope_chain): New. (pph_write_file_contents): Call pph_out_scope_chain. * pph-streamer.c (pph_preload_common_nodes): Call lto_streamer_cache_append. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/pph@175346 138bc75d-0d04-0410-961f-82ee72b054a4 diff --git a/gcc/cp/ChangeLog.pph b/gcc/cp/ChangeLog.pph index 8cdc575..24e1584 100644 --- a/gcc/cp/ChangeLog.pph +++ b/gcc/cp/ChangeLog.pph @@ -1,5 +1,18 @@ 2011-06-22 Gabriel Charette <gch...@google.com> + * 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. + * pph-streamer-out.c (pph_out_scope_chain): New. + (pph_write_file_contents): Call pph_out_scope_chain. + * pph-streamer.c (pph_preload_common_nodes): + Call lto_streamer_cache_append. + +2011-06-22 Gabriel Charette <gch...@google.com> + * pph-streamer-out.c (pph_out_lang_specific): Removed extra space. (pph_write_tree): Removed extra space. diff --git a/gcc/cp/pph-streamer-in.c b/gcc/cp/pph-streamer-in.c index 0e8c6bf..7d501ef 100644 --- a/gcc/cp/pph-streamer-in.c +++ b/gcc/cp/pph-streamer-in.c @@ -977,15 +977,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. */ @@ -993,18 +992,34 @@ 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. */ chain = DECL_CHAIN (t); + + /* 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. */ pushdecl_into_namespace (t, ns); - pph_add_names_to_namespace (t, t); } } +/* Merge scope_chain bindings from STREAM into global_namespace. */ + +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 * @@ -1129,7 +1144,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); @@ -1142,16 +1156,16 @@ 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. - See pph_in_tree_VEC. */ + See pph_in_tree_vec. */ + unemitted_tinfo_decls = pph_in_tree_vec (stream); } diff --git a/gcc/cp/pph-streamer-out.c b/gcc/cp/pph-streamer-out.c index f219cef..dd26571 100644 --- a/gcc/cp/pph-streamer-out.c +++ b/gcc/cp/pph-streamer-out.c @@ -912,6 +912,35 @@ pph_out_lang_type (pph_stream *stream, tree type, bool ref_p) } +/* Write saved_scope information stored in SS into STREAM. + This does NOT output all fields, it is 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 @@ -968,9 +997,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); }