* [PATCH,c++] mark EXPR_PACK_EXPANSION as typed only, v2
@ 2011-05-10 7:03 Nathan Froyd
2011-05-10 8:58 ` Jason Merrill
2011-07-01 0:01 ` Jason Merrill
0 siblings, 2 replies; 3+ messages in thread
From: Nathan Froyd @ 2011-05-10 7:03 UTC (permalink / raw)
To: gcc-patches; +Cc: jason
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.
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);
+ }
+}
+
\f
#if defined ENABLE_TREE_CHECKING && (GCC_VERSION >= 2007)
/* Complain that some language-specific thing hanging off a tree
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH,c++] mark EXPR_PACK_EXPANSION as typed only, v2
2011-05-10 7:03 [PATCH,c++] mark EXPR_PACK_EXPANSION as typed only, v2 Nathan Froyd
@ 2011-05-10 8:58 ` Jason Merrill
2011-07-01 0:01 ` Jason Merrill
1 sibling, 0 replies; 3+ messages in thread
From: Jason Merrill @ 2011-05-10 8:58 UTC (permalink / raw)
To: Nathan Froyd; +Cc: gcc-patches
OK.
Jason
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH,c++] mark EXPR_PACK_EXPANSION as typed only, v2
2011-05-10 7:03 [PATCH,c++] mark EXPR_PACK_EXPANSION as typed only, v2 Nathan Froyd
2011-05-10 8:58 ` Jason Merrill
@ 2011-07-01 0:01 ` Jason Merrill
1 sibling, 0 replies; 3+ messages in thread
From: Jason Merrill @ 2011-07-01 0:01 UTC (permalink / raw)
To: Nathan Froyd; +Cc: gcc-patches
[-- Attachment #1: Type: text/plain, Size: 298 bytes --]
On 05/09/2011 07:41 PM, Nathan Froyd wrote:
> 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.
I've changed iterative_hash_template_arg to use it as well.
Tested x86_64-pc-linux-gnu, applying to trunk.
[-- Attachment #2: hash-op-length.patch --]
[-- Type: text/x-patch, Size: 649 bytes --]
commit 9a83e9c63ea02e71cfb9df81478a4aed98a58611
Author: Jason Merrill <jason@redhat.com>
Date: Thu Jun 30 18:35:10 2011 -0400
* pt.c (iterative_hash_template_arg): Use cp_tree_operand_length.
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index dc6cd50..4903044 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -1609,7 +1609,7 @@ iterative_hash_template_arg (tree arg, hashval_t val)
default:
gcc_assert (IS_EXPR_CODE_CLASS (tclass));
{
- unsigned n = TREE_OPERAND_LENGTH (arg);
+ unsigned n = cp_tree_operand_length (arg);
for (i = 0; i < n; ++i)
val = iterative_hash_template_arg (TREE_OPERAND (arg, i), val);
return val;
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2011-07-01 0:01 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-05-10 7:03 [PATCH,c++] mark EXPR_PACK_EXPANSION as typed only, v2 Nathan Froyd
2011-05-10 8:58 ` Jason Merrill
2011-07-01 0:01 ` Jason Merrill
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).