diff options
author | Douglas Gregor <doug.gregor@gmail.com> | 2007-01-02 14:23:26 +0000 |
---|---|---|
committer | Doug Gregor <dgregor@gcc.gnu.org> | 2007-01-02 14:23:26 +0000 |
commit | 06d40de8bb03594e0f0eb7d0636f8ca84ce7d86d (patch) | |
tree | c7764f44cdfd0ac83984115b7e6b9f215d169dc5 /gcc/cp/pt.c | |
parent | eca0d5e8cef314a820425453b74f7bc4bb26100a (diff) | |
download | gcc-06d40de8bb03594e0f0eb7d0636f8ca84ce7d86d.zip gcc-06d40de8bb03594e0f0eb7d0636f8ca84ce7d86d.tar.gz gcc-06d40de8bb03594e0f0eb7d0636f8ca84ce7d86d.tar.bz2 |
c-common.c (c_common_nodes_and_builtins): Since variants of void_type_node get built before it is given a name...
2007-01-02 Douglas Gregor <doug.gregor@gmail.com>
* c-common.c(c_common_nodes_and_builtins): Since variants of
void_type_node get built before it is given a name, we need to
give those variants the name, too.
(complete_array_type): We need to work with the canonical main
type of the array, from which we will build the qualified version.
* params.def (PARAM_VERIFY_CANONICAL_TYPES): New.
* print-tree.c (print_node): Display canonical type information
for each type.
* stor-layout.c (layout_type): When we don't know the
alignment of a type for which we're building an array, we end up
guessing wrong, so make the type require structural equality.
* tree.c (make_node_stat): When we build a new type, it is its
own canonical type.
(build_type_attribute_qual_variant): When building an attribute
variant, its canonical type is the non-attribute variant. However,
if the attributes are target-dependent and they differ, we need to
use structural equality checks for this type.
(build_qualified_type): A qualified type is not equivalent to its
unqualified variant; set the canonical type appropriately.
(build_distinct_type_copy): When building a distinct type from
another type, the new type is its own canonical type.
(build_variant_type_copy): When building a new type variant, we
assume that it is equivalent to the original type.
(build_pointer_type_for_mode): When building a pointer type, also
build a canonical type pointer.
(build_reference_type_for_mode): When building a reference type,
also build a canonical type reference.
(build_index_type): When we can't hash an index type (e.g.,
because its maximum value is negative), the index type requires
structural equality tests.
(build_array_type): Build the canonical form of an array type.
(build_function_type): Function types require structural equality,
because they contain default arguments, attributes, etc.
(build_method_type_directly): Ditto for method types.
(build_offset_type): Build the canonical offset type.
(build_complex_type): Build the canonical vector type.
(make_vector_type): Build the canonical vector type.
* tree.h (TYPE_CANONICAL): New.
(TYPE_STRUCTURAL_EQUALITY_P): New.
(SET_TYPE_STRUCTURAL_EQUALITY): New.
(struct tree_type): Added "canonical" field.
* params.h (VERIFY_CANONICAL_TYPES): New.
* doc/c-tree.texi (TYPE_CANONICAL): Document.
(TYPE_STRUCTURAL_EQUALITY_P): Document.
(SET_TYPE_STRUCTURAL_EQUALITY): Document.
* doc/invoke.texi (verify-canonical-types): Document --param
parameter for verifying canonical types.
2007-01-02 Douglas Gregor <doug.gregor@gmail.com>
* typeck.c (structural_comptypes): Renamed from "comptypes".
(comptypes): Use canonical type information to perform fast type
comparison. When VERIFY_CANONICAL_TYPES, verify that the
canonical type comparison returns the same results as we would see
from the current, structural check. Support COMPARE_STRUCTURAL
when we need structural checks.
* decl.c (typename_compare): Fix comment.
(build_typename_type): TYPENAME_TYPE nodes require structural
equality checks, because they resolve different based on the
current class type.
(make_unbound_class_template): UNBOUND_CLASS_TEMPLATE nodes
require structural equality checks (for now).
(build_ptrmemfunc_type): Build the canonical pointer to member
function type.
(compute_array_index_type): Whenever we build a new index type
to represent the size of an array in a template, we need to mark
this index type as requiring structural equality. This goes for
arrays with value-dependent sizes with the current ABI, or all
arrays with ABI-1.
* tree.c (cplus_array_hash): New.
(struct cplus_array_info): New.
(cplus_array_compare): New.
(cplus_array_htab): New.
(build_cplus_array_type_1): Use a hash table to cache the array
types we build. Build the canonical array type for each array
type.
(cp_build_qualified_type_real): When building a cv-qualified array
type, use the hash table of array types and build canonical array
types as necessary.
(bind_template_template_parm): BOUND_TEMPLATE_TEMPLATE_PARM nodes
use structural equality (for now).
* cp-tree.h (COMPARE_STRUCTURAL): New.
* pt.c (canonical_template_parms): New.
(canonical_type_parameter): New.
(process_template_parm): Find the canonical type parameter.
(lookup_template_class): When we have named the primary template
type, set the canonical type for our template class to the primary
template type. If any of the template arguments need structural
equality checks, the template class needs structural equality
checks.
(tsubst): When reducing the level of a template template
parameter, we require structural equality tests for the resulting
parameter because its template parameters have not had their types
canonicalized. When reducing a template type parameter, find the
canonical reduced type parameter.
(any_template_arguments_need_structural_equality_p): New.
2007-01-02 Douglas Gregor <doug.gregor@gmail.com>
* objc-act.c (objc_build_volatilized_type): Keep track of
canonical types.
(objc_get_protocol_qualified_type): Ditto.
From-SVN: r120341
Diffstat (limited to 'gcc/cp/pt.c')
-rw-r--r-- | gcc/cp/pt.c | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index f9a728f..1e90751 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -80,6 +80,12 @@ static tree cur_stmt_expr; local variables. */ static htab_t local_specializations; +/* Contains canonical template parameter types. The vector is index by + the TEMPLATE_TYPE_IDX of the template parameter. Each element is a + TREE_LIST, whose TREE_VALUEs contain the canonical template + parameters of various types and levels. */ +static GTY(()) VEC(tree,gc) *canonical_template_parms; + #define UNIFY_ALLOW_NONE 0 #define UNIFY_ALLOW_MORE_CV_QUAL 1 #define UNIFY_ALLOW_LESS_CV_QUAL 2 @@ -157,6 +163,7 @@ static tree copy_default_args_to_explicit_spec_1 (tree, tree); static void copy_default_args_to_explicit_spec (tree); static int invalid_nontype_parm_type_p (tree, tsubst_flags_t); static int eq_local_specializations (const void *, const void *); +static bool any_template_arguments_need_structural_equality_p (tree); static bool dependent_type_p_r (tree); static tree tsubst (tree, tree, tsubst_flags_t, tree); static tree tsubst_expr (tree, tree, tsubst_flags_t, tree, bool); @@ -2335,6 +2342,35 @@ build_template_parm_index (int index, return t; } +/* Find the canonical type parameter for the given template type + parmaeter. Returns the canonical type parameter, which may be TYPE + if no such parameter existed. */ +static tree +canonical_type_parameter (tree type) +{ + tree list; + int idx = TEMPLATE_TYPE_IDX (type); + if (!canonical_template_parms) + canonical_template_parms = VEC_alloc (tree, gc, idx+1); + + while (VEC_length (tree, canonical_template_parms) <= (unsigned)idx) + VEC_safe_push (tree, gc, canonical_template_parms, NULL_TREE); + + list = VEC_index (tree, canonical_template_parms, idx); + while (list && !comptypes (type, TREE_VALUE (list), COMPARE_STRUCTURAL)) + list = TREE_CHAIN (list); + + if (list) + return TREE_VALUE (list); + else + { + VEC_replace(tree, canonical_template_parms, idx, + tree_cons (NULL_TREE, type, + VEC_index (tree, canonical_template_parms, idx))); + return type; + } +} + /* Return a TEMPLATE_PARM_INDEX, similar to INDEX, but whose TEMPLATE_PARM_LEVEL has been decreased by LEVELS. If such a TEMPLATE_PARM_INDEX already exists, it is returned; otherwise, a @@ -2473,6 +2509,7 @@ process_template_parm (tree list, tree parm, bool is_non_type) = build_template_parm_index (idx, processing_template_decl, processing_template_decl, decl, TREE_TYPE (parm)); + TYPE_CANONICAL (t) = canonical_type_parameter (t); } DECL_ARTIFICIAL (decl) = 1; SET_DECL_TEMPLATE_PARM_P (decl); @@ -4807,6 +4844,17 @@ lookup_template_class (tree d1, /* A local class. Make sure the decl gets registered properly. */ if (context == current_function_decl) pushtag (DECL_NAME (template), t, /*tag_scope=*/ts_current); + + if (comp_template_args (CLASSTYPE_TI_ARGS (template_type), arglist)) + /* This instantiation is another name for the primary + template type. Set the TYPE_CANONICAL field + appropriately. */ + TYPE_CANONICAL (t) = template_type; + else if (any_template_arguments_need_structural_equality_p (arglist)) + /* Some of the template arguments require structural + equality testing, so this template class requires + structural equality testing. */ + SET_TYPE_STRUCTURAL_EQUALITY (t); } /* If we called start_enum or pushtag above, this information @@ -7473,6 +7521,18 @@ tsubst (tree t, tree args, tsubst_flags_t complain, tree in_decl) TYPE_POINTER_TO (r) = NULL_TREE; TYPE_REFERENCE_TO (r) = NULL_TREE; + if (TREE_CODE (r) == TEMPLATE_TEMPLATE_PARM) + /* We have reduced the level of the template + template parameter, but not the levels of its + template parameters, so canonical_type_parameter + will not be able to find the canonical template + template parameter for this level. Thus, we + require structural equality checking to compare + TEMPLATE_TEMPLATE_PARMs. */ + SET_TYPE_STRUCTURAL_EQUALITY (r); + else + TYPE_CANONICAL (r) = canonical_type_parameter (r); + if (TREE_CODE (t) == BOUND_TEMPLATE_TEMPLATE_PARM) { tree argvec = tsubst (TYPE_TI_ARGS (t), args, @@ -13168,6 +13228,40 @@ dependent_template_arg_p (tree arg) } /* Returns true if ARGS (a collection of template arguments) contains + any types that require structural equality testing. */ + +bool +any_template_arguments_need_structural_equality_p (tree args) +{ + int i; + int j; + + if (!args) + return false; + if (args == error_mark_node) + return true; + + for (i = 0; i < TMPL_ARGS_DEPTH (args); ++i) + { + tree level = TMPL_ARGS_LEVEL (args, i + 1); + for (j = 0; j < TREE_VEC_LENGTH (level); ++j) + { + tree arg = TREE_VEC_ELT (level, j); + if (TREE_CODE (arg) == TEMPLATE_DECL + || TREE_CODE (arg) == TEMPLATE_TEMPLATE_PARM) + continue; + else if (TYPE_P (arg) && TYPE_STRUCTURAL_EQUALITY_P (arg)) + return true; + else if (!TYPE_P (arg) && TREE_TYPE (arg) + && TYPE_STRUCTURAL_EQUALITY_P (TREE_TYPE (arg))) + return true; + } + } + + return false; +} + +/* Returns true if ARGS (a collection of template arguments) contains any dependent arguments. */ bool |