From d26e59864b3ea46ad8d4671a3c55f86cf5f2fa94 Mon Sep 17 00:00:00 2001 From: Nathan Froyd Date: Tue, 10 May 2011 17:23:31 +0000 Subject: [PATCH] mark EXPR_PACK_EXPANSION as typed only mark EXPR_PACK_EXPANSION as typed only * 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. From-SVN: r173625 --- gcc/cp/ChangeLog | 12 ++++++++++++ gcc/cp/cp-objcp-common.c | 2 +- gcc/cp/cp-tree.def | 2 +- gcc/cp/cp-tree.h | 6 +++++- gcc/cp/mangle.c | 18 +----------------- gcc/cp/pt.c | 35 +++++++++++++++-------------------- gcc/cp/tree.c | 28 +++++++++++++++++++++++++++- 7 files changed, 62 insertions(+), 41 deletions(-) diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index b89280dbda3..f7a5683cd0b 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,15 @@ +2011-05-10 Nathan Froyd + + * 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. + 2011-05-09 Paolo Carlini PR c++/48737 diff --git a/gcc/cp/cp-objcp-common.c b/gcc/cp/cp-objcp-common.c index d15aed0c2c2..00f525bb1e6 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 7bd35e0d6b2..001ef100a13 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 53092ffc6e7..efcdeefd38d 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 c72e6d2fc64..c1f3b44e905 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 76fc69bc0ef..f6392d63b81 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -18279,35 +18279,30 @@ 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 d6365488957..6b3680e8099 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,32 @@ 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 -- 2.30.2