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]

[pph] Reconstruct a header file from a pph image (issue4392047)


This patch, together with the others I sent today, allows us to
reconstruct all the symbols and types stored inside a pph image.  This
is not all we need, but it allows me to get basic declarations and
types reconstructed from pph images.

This causes ~57 failures in pph.exp.  The more problematic one is an
infinite recursion that causes memory bloat.  I'm not committing this
patch yet until I figure this one out.

Other failures are due to missing bits in the pickling.  I'll be
fixing those in subsequent patches.


2011-04-12  Diego Novillo  <dnovillo@google.com>

	* pph.c (pph_add_names_to_namespace): New.
	(pph_read_file_contents): Call it.
	Call cpp_lt_replay.

diff --git a/gcc/cp/pph.c b/gcc/cp/pph.c
index 74d1d50..6584e72 100644
--- a/gcc/cp/pph.c
+++ b/gcc/cp/pph.c
@@ -1937,6 +1937,28 @@ report_validation_error (const char *filename,
 }
 
 
+
+/* Add all the new names declared in NEW_NS to NS.  */
+
+static void
+pph_add_names_to_namespace (tree ns, tree new_ns)
+{
+  struct cp_binding_level *new_level, *level;
+  tree t, chain;
+
+  level = NAMESPACE_LEVEL (ns);
+  new_level = NAMESPACE_LEVEL (new_ns);
+
+  for (t = new_level->names; t; t = chain)
+    {
+      /* Pushing a decl into a scope clobbers its DECL_CHAIN.
+	 Preserve it.  */
+      chain = DECL_CHAIN (t);
+      pushdecl_with_scope (t, level, /*is_friend=*/false);
+    }
+}
+
+
 /* Read contents of PPH file in STREAM.  */
 
 static void
@@ -1946,25 +1968,27 @@ 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);
 
-  /*FIXME pph: This validation is weak.  */
+  /* FIXME pph: This validation is weak.  */
   verified = cpp_lt_verify_1 (parse_in, &idents_used, &bad_use, &cur_def, true);
   if (!verified)
     report_validation_error (stream->name, bad_use->ident_str, cur_def,
                              bad_use->before_str, bad_use->after_str);
 
-  /* FIXME pph: We cannot replay the macro definitions
-     as long as we are still reading the actual file.
+  /* Re-instantiate all the pre-processor symbols defined by STREAM.  */
   cpp_lt_replay (parse_in, &idents_used);
-  */
 
-  pph_input_tree (stream);
+  /* Read global_namespace from STREAM and add all the names defined
+     there to the current global_namespace.  */
+  file_ns = pph_input_tree (stream);
+  pph_add_names_to_namespace (global_namespace, file_ns);
 }
 
 
-/* Read PPH file.  */
+/* Read PPH file FILENAME.  */
 
 static void
 pph_read_file (const char *filename)

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


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