diff mbox

[c++] mark EXPR_PACK_EXPANSION as typed only, v2

Message ID 20110509234118.GS23480@codesourcery.com
State New
Headers show

Commit Message

Nathan Froyd May 9, 2011, 11:41 p.m. UTC
Following on:

http://gcc.gnu.org/ml/gcc-patches/2011-03/msg00563.html

and the review received in:

http://gcc.gnu.org/ml/gcc-patches/2011-04/msg00651.html

I present the patch below.  We have a new function,
cp_tree_operand_length, and the code has been retrofitted to use it in
various places.

Tested on x86_64-unknown-linux-gnu.  OK to commit?

-Nathan

gcc/cp/
        * cp-tree.def (EXPR_PACK_EXPANSION): Add an operand.
        * cp-objcp-common.c (cp_common_init_ts): Mark it as TS_TYPED.
        * cp-tree.h (PACK_EXPANSION_PARAMETER_PACKS): Use the new
        operand of EXPR_PACK_EXPANSION.
	(cp_tree_operand_length): Declare.
        * tree.c (cp_tree_operand_length): Define.
	(cp_tree_equal): Call it.
        * pt.c (value_dependent_expr_P): Likewise.
        * mangle.c (write_expression): Likewise.

Comments

Jason Merrill May 10, 2011, 4:52 a.m. UTC | #1
OK.

Jason
diff mbox

Patch

diff --git a/gcc/cp/cp-objcp-common.c b/gcc/cp/cp-objcp-common.c
index d15aed0..00f525b 100644
--- a/gcc/cp/cp-objcp-common.c
+++ b/gcc/cp/cp-objcp-common.c
@@ -241,11 +241,11 @@  cp_common_init_ts (void)
   MARK_TS_COMMON (UNDERLYING_TYPE);
   MARK_TS_COMMON (BASELINK);
   MARK_TS_COMMON (TYPE_PACK_EXPANSION);
-  MARK_TS_COMMON (EXPR_PACK_EXPANSION);
   MARK_TS_COMMON (DECLTYPE_TYPE);
   MARK_TS_COMMON (BOUND_TEMPLATE_TEMPLATE_PARM);
   MARK_TS_COMMON (UNBOUND_CLASS_TEMPLATE);
 
+  MARK_TS_TYPED (EXPR_PACK_EXPANSION);
   MARK_TS_TYPED (SWITCH_STMT);
   MARK_TS_TYPED (IF_STMT);
   MARK_TS_TYPED (FOR_STMT);
diff --git a/gcc/cp/cp-tree.def b/gcc/cp/cp-tree.def
index 7bd35e0..001ef10 100644
--- a/gcc/cp/cp-tree.def
+++ b/gcc/cp/cp-tree.def
@@ -413,7 +413,7 @@  DEFTREECODE (TYPE_PACK_EXPANSION, "type_pack_expansion", tcc_type, 0)
 
    EXPR_PACK_EXPANSION plays precisely the same role as TYPE_PACK_EXPANSION,
    but will be used for expressions.  */
-DEFTREECODE (EXPR_PACK_EXPANSION, "expr_pack_expansion", tcc_expression, 1)
+DEFTREECODE (EXPR_PACK_EXPANSION, "expr_pack_expansion", tcc_expression, 2)
 
 /* Selects the Ith parameter out of an argument pack. This node will
    be used when instantiating pack expansions; see
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index 53092ff..efcdeef 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -2734,7 +2734,10 @@  extern void decl_shadowed_for_var_insert (tree, tree);
 
 /* The list of parameter packs used in the PACK_EXPANSION_* node. The
    TREE_VALUE of each TREE_LIST contains the parameter packs.  */
-#define PACK_EXPANSION_PARAMETER_PACKS(NODE) TREE_CHAIN (NODE)
+#define PACK_EXPANSION_PARAMETER_PACKS(NODE)		\
+  *(TREE_CODE (NODE) == EXPR_PACK_EXPANSION		\
+    ? &TREE_OPERAND (NODE, 1)				\
+    : &TREE_CHAIN (TYPE_PACK_EXPANSION_CHECK (NODE)))
 
 /* Determine if this is an argument pack.  */
 #define ARGUMENT_PACK_P(NODE)                          \
@@ -5430,6 +5433,7 @@  extern tree nonlambda_method_basetype		(void);
 extern void maybe_add_lambda_conv_op            (tree);
 
 /* in tree.c */
+extern int cp_tree_operand_length		(const_tree);
 void cp_free_lang_data 				(tree t);
 extern tree force_target_expr			(tree, tree, tsubst_flags_t);
 extern tree build_target_expr_with_type		(tree, tree, tsubst_flags_t);
diff --git a/gcc/cp/mangle.c b/gcc/cp/mangle.c
index c72e6d2..c1f3b44 100644
--- a/gcc/cp/mangle.c
+++ b/gcc/cp/mangle.c
@@ -2701,23 +2701,7 @@  write_expression (tree expr)
 	default:
 	  /* In the middle-end, some expressions have more operands than
 	     they do in templates (and mangling).  */
-	  switch (code)
-	    {
-	    case PREINCREMENT_EXPR:
-	    case PREDECREMENT_EXPR:
-	    case POSTINCREMENT_EXPR:
-	    case POSTDECREMENT_EXPR:
-	      len = 1;
-	      break;
-
-	    case ARRAY_REF:
-	      len = 2;
-	      break;
-
-	    default:
-	      len = TREE_OPERAND_LENGTH (expr);
-	      break;
-	    }
+	  len = cp_tree_operand_length (expr);
 
 	  for (i = 0; i < len; ++i)
 	    {
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 76fc69b..8ffac49 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -18279,35 +18279,31 @@  value_dependent_expression_p (tree expression)
 	{
 	case tcc_reference:
 	case tcc_unary:
-	  return (value_dependent_expression_p
-		  (TREE_OPERAND (expression, 0)));
-
 	case tcc_comparison:
 	case tcc_binary:
-	  return ((value_dependent_expression_p
-		   (TREE_OPERAND (expression, 0)))
-		  || (value_dependent_expression_p
-		      (TREE_OPERAND (expression, 1))));
-
 	case tcc_expression:
 	case tcc_vl_exp:
 	  {
-	    int i;
-	    for (i = 0; i < TREE_OPERAND_LENGTH (expression); ++i)
-	      /* In some cases, some of the operands may be missing.
-		 (For example, in the case of PREDECREMENT_EXPR, the
-		 amount to increment by may be missing.)  That doesn't
-		 make the expression dependent.  */
-	      if (TREE_OPERAND (expression, i)
-		  && (value_dependent_expression_p
-		      (TREE_OPERAND (expression, i))))
-		return true;
-	    return false;
-	  }
+	    int i, len = cp_tree_operand_length (expression);
 
+	    for (i = 0; i < len; i++)
+	      {
+		tree t = TREE_OPERAND (expression, i);
+
+		/* In some cases, some of the operands may be missing.l
+		   (For example, in the case of PREDECREMENT_EXPR, the
+		   amount to increment by may be missing.)  That doesn't
+		   make the expression dependent.  */
+		if (t && value_dependent_expression_p (t))
+		  return true;
+	      }
+	  }
+	  break;
 	default:
 	  break;
 	}
+      break;
     }
 
   /* The expression is not value-dependent.  */
diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c
index d636548..98abd6a 100644
--- a/gcc/cp/tree.c
+++ b/gcc/cp/tree.c
@@ -2342,7 +2342,7 @@  cp_tree_equal (tree t1, tree t2)
       {
 	int i, n;
 
-	n = TREE_OPERAND_LENGTH (t1);
+	n = cp_tree_operand_length (t1);
 	if (TREE_CODE_CLASS (code1) == tcc_vl_exp
 	    && n != TREE_OPERAND_LENGTH (t2))
 	  return false;
@@ -3408,6 +3408,33 @@  c_register_addr_space (const char *word ATTRIBUTE_UNUSED,
 {
 }
 
+/* Return the number of operands in T that we care about for things like
+   mangling.  */
+
+int
+cp_tree_operand_length (const_tree t)
+{
+  enum tree_code code = TREE_CODE (t);
+
+  switch (code)
+    {
+    case PREINCREMENT_EXPR:
+    case PREDECREMENT_EXPR:
+    case POSTINCREMENT_EXPR:
+    case POSTDECREMENT_EXPR:
+      return 1;
+
+    case ARRAY_REF:
+      return 2;
+
+    case EXPR_PACK_EXPANSION:
+      return 1;
+
+    default:
+      return TREE_OPERAND_LENGTH (t);
+    }
+}
+
 
 #if defined ENABLE_TREE_CHECKING && (GCC_VERSION >= 2007)
 /* Complain that some language-specific thing hanging off a tree