diff mbox

[pph] Cleanup to support namespace aliases (1/2) (issue5434109)

Message ID 20111202190719.2F8DDAE1DE@tobiano.tor.corp.google.com
State New
Headers show

Commit Message

Diego Novillo Dec. 2, 2011, 7:07 p.m. UTC
This patch is part 1 of a cleanup needed to support namespace aliases.
When processing a namespace aliase, we cannot access its binding level
because it is NULL.  Besides, it does not make sense to do anything
with it, since the binding level for the original namespace would've
been processed before.

The creation of binding level on the reader is tripping us up because
we end up with two binding levels for the same namespace.  This is
partially addressed in the next patch.

Tested on x86_64.


Diego.

	* pph-in.c (pph_in_bool): New.
	(pph_in_merge_key_namespace_decl): Factor out of ...
	(pph_in_merge_key_tree): ... here.
	Handle namespace aliases. 
	* pph-out.c (pph_out_bool): New.
	(pph_out_merge_key_namespace_decl): Factor out of ...
	(pph_out_merge_key_tree): ... here.
	Handle namespace aliases.
diff mbox

Patch

diff --git a/gcc/cp/pph-in.c b/gcc/cp/pph-in.c
index 73c93df..088c1a2 100644
--- a/gcc/cp/pph-in.c
+++ b/gcc/cp/pph-in.c
@@ -210,6 +210,17 @@  pph_in_bitpack (pph_stream *stream)
 }
 
 
+/* Read a boolean value from STREAM.  */
+
+static inline bool
+pph_in_bool (pph_stream *stream)
+{
+  unsigned val = pph_in_uint (stream);
+  gcc_assert (val <= 1);
+  return (bool) val;
+}
+
+
 /******************************************************** source information */
 
 
@@ -1575,7 +1586,7 @@  pph_in_lang_specific (pph_stream *stream, tree decl)
 }
 
 
-/* Read language specific data in DECL from STREAM.  */
+/* Read and merge language specific data in DECL from STREAM.  */
 
 static void
 pph_in_merge_lang_specific (pph_stream *stream, tree decl)
@@ -2223,6 +2234,40 @@  pph_in_tree_header (pph_stream *stream, enum LTO_tags tag)
 }
 
 
+/* Read all the merge keys for the names under namespace DECL from
+   STREAM.  */
+
+static void
+pph_in_merge_key_namespace_decl (pph_stream *stream, tree decl)
+{
+  bool is_namespace_alias;
+
+  /* If EXPR is a namespace alias, we do not need to merge
+     its binding level (namespaces aliases do not have a
+     binding level, they use the one from the namespace they
+     alias).  */
+  is_namespace_alias = pph_in_bool (stream);
+  if (!is_namespace_alias)
+    {
+      cp_binding_level *bl;
+
+      if (DECL_LANG_SPECIFIC (decl))
+	/* Merging into an existing namespace.  */
+	bl = NAMESPACE_LEVEL (decl);
+      else
+	{
+	  /* This is a new namespace.  Allocate a lang_decl and a binding
+	     level to DECL.  */
+	  retrofit_lang_decl (decl);
+	  bl = ggc_alloc_cleared_cp_binding_level ();
+	  NAMESPACE_LEVEL (decl) = bl;
+	}
+
+      pph_in_binding_merge_keys (stream, bl);
+    }
+}
+
+
 /* Read a merge key from STREAM.  If the merge key read from STREAM
    is not found in *CHAIN, the newly allocated tree is added to it.  */
 
@@ -2268,20 +2313,7 @@  pph_in_merge_key_tree (pph_stream *stream, tree *chain)
   if (DECL_P (expr))
     {
       if (TREE_CODE (expr) == NAMESPACE_DECL)
-        {
-	  cp_binding_level *bl;
-	  if (DECL_LANG_SPECIFIC (expr))
-	    /* Merging into an existing namespace.  */
-	    bl = NAMESPACE_LEVEL (expr);
-	  else
-	    {
-	      /* This is a new namespace.  */
-	      retrofit_lang_decl (expr);
-	      bl = ggc_alloc_cleared_cp_binding_level ();
-	      NAMESPACE_LEVEL (expr) = bl;
-	    }
-	  pph_in_binding_merge_keys (stream, bl);
-        }
+	pph_in_merge_key_namespace_decl (stream, expr);
 #if 0
 /* FIXME pph: Disable type merging for the moment.  */
       else if (TREE_CODE (expr) == TYPE_DECL)
diff --git a/gcc/cp/pph-out.c b/gcc/cp/pph-out.c
index a4035f1..e1e21b9 100644
--- a/gcc/cp/pph-out.c
+++ b/gcc/cp/pph-out.c
@@ -168,6 +168,15 @@  pph_out_bitpack (pph_stream *stream, struct bitpack_d *bp)
 }
 
 
+/* Write a boolean value VAL to STREAM.  */
+
+static inline void
+pph_out_bool (pph_stream *stream, bool val)
+{
+  pph_out_uint (stream, val ? 1 : 0);
+}
+
+
 /******************************************************** source information */
 
 
@@ -2123,6 +2132,24 @@  pph_out_merge_name (pph_stream *stream, tree expr)
 }
 
 
+/* Write merge information for a namespace DECL to STREAM.  */
+
+static void
+pph_out_merge_key_namespace_decl (pph_stream *stream, tree decl)
+{
+  bool is_namespace_alias;
+
+  gcc_assert (TREE_CODE (decl) == NAMESPACE_DECL);
+
+  /* If EXPR is a namespace alias, it will not have an associated
+     binding.  In that case, tell the reader not to bother with it.  */
+  is_namespace_alias = (DECL_NAMESPACE_ALIAS (decl) != NULL_TREE);
+  pph_out_bool (stream, is_namespace_alias);
+  if (!is_namespace_alias)
+    pph_out_binding_merge_keys (stream, NAMESPACE_LEVEL (decl));
+}
+
+
 /* Write the merge key for tree EXPR to STREAM.  */
 
 static void
@@ -2144,7 +2171,7 @@  pph_out_merge_key_tree (pph_stream *stream, tree expr)
   if (DECL_P (expr))
     {
       if (TREE_CODE (expr) == NAMESPACE_DECL)
-        pph_out_binding_merge_keys (stream, NAMESPACE_LEVEL (expr));
+	pph_out_merge_key_namespace_decl (stream, expr);
 #if 0
 /* FIXME pph: Distable tree merging for the moment.  */
       else if (TREE_CODE (expr) == TYPE_DECL)