diff options
author | Benjamin Kosnik <bkoz@gcc.gnu.org> | 2011-10-18 02:58:06 +0000 |
---|---|---|
committer | Benjamin Kosnik <bkoz@gcc.gnu.org> | 2011-10-18 02:58:06 +0000 |
commit | 4daba88481ad29c76f24b70485017e54f9a19fe3 (patch) | |
tree | 025d5854011b99cfe93205d711317cfd2947da24 /gcc | |
parent | 9d4dedaa7b3ddd81934489e200dc7a4b97836dbc (diff) | |
download | gcc-4daba88481ad29c76f24b70485017e54f9a19fe3.zip gcc-4daba88481ad29c76f24b70485017e54f9a19fe3.tar.gz gcc-4daba88481ad29c76f24b70485017e54f9a19fe3.tar.bz2 |
[multiple changes]
2011-10-17 Michael Spertus <mike_spertus@symantec.com>
* gcc/c-family/c-common.c (c_common_reswords): Add __bases,
__direct_bases.
* gcc/c-family/c-common.h: Add RID_BASES and RID_DIRECT_BASES.
2011-10-17 Michael Spertus <mike_spertus@symantec.com>
* cp-tree.def: Add BASES as a new tree code.
* cp-tree.h (enum cp_trait_kind): Add CPTK_BASES, CPTK_DIRECT_BASES.
(BASES_TYPE, BASES_DIRECT): Define.
(calculate_bases, finish_bases, calculate_direct_bases): Declare.
* parser.c (cp_parser_trait_expr, cp_parser_template_argument_list,
(cp_parser_simple_type_specifier, cp_parser_save_nsdmi): Use them.
* pt.c (find_parameter_packs_r, tsubst_pack_expansion): Likewise.
* semantics.c (calculate_bases, finish_bases, calculate_direct_bases,
dfs_calculate_bases_pre, dfs_calculate_bases_post,
calculate_bases_helper): Define.
2011-10-17 Michael Spertus <mike_spertus@symantec.com>
* g++.dg/ext/bases.C: New test.
2011-10-17 Michael Spertus <mike_spertus@symantec.com>
* include/tr2/type_traits (bases, direct_bases, typelist): New.
2011-10-17 Benjamin Kosnik <bkoz@redhat.com>
* libstdc++-v3/include/Makefile.am: Add tr2 directory and includes.
* libstdc++-v3/include/Makefile.in: Regenerate.
* scripts/create_testsuite_files: Search tr2 directory.
* testsuite/libstdc++-dg/conformance.exp: Same.
* testsuite/tr2/bases/requirements/explicit_instantiation.cc: New.
* testsuite/tr2/bases/requirements/typedefs.cc: New.
* testsuite/tr2/bases/value.cc: New.
* testsuite/tr2/direct_bases/requirements/
explicit_instantiation.cc: New.
* testsuite/tr2/direct_bases/requirements/typedefs.cc: New.
* testsuite/tr2/direct_bases/value.cc: New.
From-SVN: r180121
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/c-family/c-common.c | 2 | ||||
-rw-r--r-- | gcc/c-family/c-common.h | 3 | ||||
-rw-r--r-- | gcc/cp/ChangeLog | 13 | ||||
-rw-r--r-- | gcc/cp/cp-tree.def | 4 | ||||
-rw-r--r-- | gcc/cp/cp-tree.h | 12 | ||||
-rw-r--r-- | gcc/cp/parser.c | 32 | ||||
-rw-r--r-- | gcc/cp/pt.c | 12 | ||||
-rw-r--r-- | gcc/cp/semantics.c | 143 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/ext/bases.C | 35 |
11 files changed, 260 insertions, 6 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index ddc5149..6c73404 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2011-10-17 Michael Spertus <mike_spertus@symantec.com> + + * gcc/c-family/c-common.c (c_common_reswords): Add __bases, + __direct_bases. + * gcc/c-family/c-common.h: Add RID_BASES and RID_DIRECT_BASES. + 2011-10-17 Simon Baldwin <simonb@google.com> Ian Lance Taylor <iant@google.com> diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index 0aa0fef..9d20d80 100644 --- a/gcc/c-family/c-common.c +++ b/gcc/c-family/c-common.c @@ -423,6 +423,7 @@ const struct c_common_resword c_common_reswords[] = { "__asm__", RID_ASM, 0 }, { "__attribute", RID_ATTRIBUTE, 0 }, { "__attribute__", RID_ATTRIBUTE, 0 }, + { "__bases", RID_BASES, D_CXXONLY }, { "__builtin_choose_expr", RID_CHOOSE_EXPR, D_CONLY }, { "__builtin_complex", RID_BUILTIN_COMPLEX, D_CONLY }, { "__builtin_shuffle", RID_BUILTIN_SHUFFLE, D_CONLY }, @@ -434,6 +435,7 @@ const struct c_common_resword c_common_reswords[] = { "__const", RID_CONST, 0 }, { "__const__", RID_CONST, 0 }, { "__decltype", RID_DECLTYPE, D_CXXONLY }, + { "__direct_bases", RID_DIRECT_BASES, D_CXXONLY }, { "__extension__", RID_EXTENSION, 0 }, { "__func__", RID_C99_FUNCTION_NAME, 0 }, { "__has_nothrow_assign", RID_HAS_NOTHROW_ASSIGN, D_CXXONLY }, diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h index 8996eef..9818c9c 100644 --- a/gcc/c-family/c-common.h +++ b/gcc/c-family/c-common.h @@ -128,12 +128,13 @@ enum rid RID_CONSTCAST, RID_DYNCAST, RID_REINTCAST, RID_STATCAST, /* C++ extensions */ + RID_BASES, RID_DIRECT_BASES, RID_HAS_NOTHROW_ASSIGN, RID_HAS_NOTHROW_CONSTRUCTOR, RID_HAS_NOTHROW_COPY, RID_HAS_TRIVIAL_ASSIGN, RID_HAS_TRIVIAL_CONSTRUCTOR, RID_HAS_TRIVIAL_COPY, RID_HAS_TRIVIAL_DESTRUCTOR, RID_HAS_VIRTUAL_DESTRUCTOR, RID_IS_ABSTRACT, RID_IS_BASE_OF, - RID_IS_CONVERTIBLE_TO, RID_IS_CLASS, + RID_IS_CLASS, RID_IS_CONVERTIBLE_TO, RID_IS_EMPTY, RID_IS_ENUM, RID_IS_LITERAL_TYPE, RID_IS_POD, RID_IS_POLYMORPHIC, RID_IS_STD_LAYOUT, diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index ed7d832..2a4bdbb 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,16 @@ +2011-10-17 Michael Spertus <mike_spertus@symantec.com> + + * cp-tree.def: Add BASES as a new tree code. + * cp-tree.h (enum cp_trait_kind): Add CPTK_BASES, CPTK_DIRECT_BASES. + (BASES_TYPE, BASES_DIRECT): Define. + (calculate_bases, finish_bases, calculate_direct_bases): Declare. + * parser.c (cp_parser_trait_expr, cp_parser_template_argument_list, + (cp_parser_simple_type_specifier, cp_parser_save_nsdmi): Use them. + * pt.c (find_parameter_packs_r, tsubst_pack_expansion): Likewise. + * semantics.c (calculate_bases, finish_bases, calculate_direct_bases, + dfs_calculate_bases_pre, dfs_calculate_bases_post, + calculate_bases_helper): Define. + 2011-10-17 Jason Merrill <jason@redhat.com> PR c++/50736 diff --git a/gcc/cp/cp-tree.def b/gcc/cp/cp-tree.def index be29870..4eec9f9 100644 --- a/gcc/cp/cp-tree.def +++ b/gcc/cp/cp-tree.def @@ -462,6 +462,10 @@ DEFTREECODE (DECLTYPE_TYPE, "decltype_type", tcc_type, 0) UNDERLYING_TYPE_TYPE is the type in question. */ DEFTREECODE (UNDERLYING_TYPE, "underlying_type", tcc_type, 0) +/* A type designated by one of the bases type traits. + BASES_TYPE is the type in question. */ +DEFTREECODE (BASES, "bases", tcc_type, 0) + /* Used to represent the template information stored by template specializations. The accessors are: diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 88f7fbd..bda18d9 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -564,6 +564,8 @@ struct GTY (()) tree_argument_pack_select { typedef enum cp_trait_kind { + CPTK_BASES, + CPTK_DIRECT_BASES, CPTK_HAS_NOTHROW_ASSIGN, CPTK_HAS_NOTHROW_CONSTRUCTOR, CPTK_HAS_NOTHROW_COPY, @@ -3433,6 +3435,13 @@ more_aggr_init_expr_args_p (const aggr_init_expr_arg_iterator *iter) #define UNDERLYING_TYPE_TYPE(NODE) \ (TYPE_VALUES_RAW (UNDERLYING_TYPE_CHECK (NODE))) +/* The type in question for BASES. */ +#define BASES_TYPE(NODE) \ + (TYPE_VALUES_RAW (BASES_CHECK (NODE))) + +#define BASES_DIRECT(NODE) \ + TREE_LANG_FLAG_0 (BASES_CHECK (NODE)) + /* The expression in question for a DECLTYPE_TYPE. */ #define DECLTYPE_TYPE_EXPR(NODE) (TYPE_VALUES_RAW (DECLTYPE_TYPE_CHECK (NODE))) @@ -5462,6 +5471,9 @@ extern tree finish_id_expression (tree, tree, tree, location_t); extern tree finish_typeof (tree); extern tree finish_underlying_type (tree); +extern tree calculate_bases (tree); +extern tree finish_bases (tree, bool); +extern tree calculate_direct_bases (tree); extern tree finish_offsetof (tree); extern void finish_decl_cleanup (tree, tree); extern void finish_eh_cleanup (tree); diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index bf362f2..c0e9001 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -7304,6 +7304,12 @@ cp_parser_trait_expr (cp_parser* parser, enum rid keyword) case RID_UNDERLYING_TYPE: kind = CPTK_UNDERLYING_TYPE; break; + case RID_BASES: + kind = CPTK_BASES; + break; + case RID_DIRECT_BASES: + kind = CPTK_DIRECT_BASES; + break; default: gcc_unreachable (); } @@ -7348,9 +7354,17 @@ cp_parser_trait_expr (cp_parser* parser, enum rid keyword) /* Complete the trait expression, which may mean either processing the trait expr now or saving it for template instantiation. */ - return kind != CPTK_UNDERLYING_TYPE - ? finish_trait_expr (kind, type1, type2) - : finish_underlying_type (type1); + switch(kind) + { + case CPTK_UNDERLYING_TYPE: + return finish_underlying_type (type1); + case CPTK_BASES: + return finish_bases (type1, false); + case CPTK_DIRECT_BASES: + return finish_bases (type1, true); + default: + return finish_trait_expr (kind, type1, type2); + } } /* Lambdas that appear in variable initializer or default argument scope @@ -12040,6 +12054,7 @@ cp_parser_template_argument_list (cp_parser* parser) parser->integral_constant_expression_p = false; saved_non_ice_p = parser->non_integral_constant_expression_p; parser->non_integral_constant_expression_p = false; + /* Parse the arguments. */ do { @@ -12857,7 +12872,6 @@ cp_parser_simple_type_specifier (cp_parser* parser, case RID_UNDERLYING_TYPE: type = cp_parser_trait_expr (parser, RID_UNDERLYING_TYPE); - if (decl_specs) cp_parser_set_decl_spec_type (decl_specs, type, token->location, @@ -12865,6 +12879,14 @@ cp_parser_simple_type_specifier (cp_parser* parser, return type; + case RID_BASES: + case RID_DIRECT_BASES: + type = cp_parser_trait_expr (parser, token->keyword); + if (decl_specs) + cp_parser_set_decl_spec_type (decl_specs, type, + token->location, + /*type_definition_p=*/false); + return type; default: break; } @@ -20652,7 +20674,7 @@ cp_parser_save_nsdmi (cp_parser* parser) /* Parse a template-argument-list, as well as the trailing ">" (but - not the opening ">"). See cp_parser_template_argument_list for the + not the opening "<"). See cp_parser_template_argument_list for the return value. */ static tree diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index bbe1139..6fc60d5 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -2980,6 +2980,9 @@ find_parameter_packs_r (tree *tp, int *walk_subtrees, void* data) } break; + case BASES: + parameter_pack_p = true; + break; default: /* Not a parameter pack. */ break; @@ -9127,6 +9130,15 @@ tsubst_pack_expansion (tree t, tree args, tsubst_flags_t complain, tree arg_pack = NULL_TREE; tree orig_arg = NULL_TREE; + if (TREE_CODE (parm_pack) == BASES) + { + if (BASES_DIRECT (parm_pack)) + return calculate_direct_bases (tsubst_expr (BASES_TYPE (parm_pack), + args, complain, in_decl, false)); + else + return calculate_bases (tsubst_expr (BASES_TYPE (parm_pack), + args, complain, in_decl, false)); + } if (TREE_CODE (parm_pack) == PARM_DECL) { if (!cp_unevaluated_operand) diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 1efe579..3e847fa 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -3394,6 +3394,149 @@ finish_underlying_type (tree type) return underlying_type; } +/* Implement the __direct_bases keyword: Return the direct base classes + of type */ + +tree +calculate_direct_bases (tree type) +{ + VEC(tree, gc) *vector = make_tree_vector(); + tree bases_vec = NULL_TREE; + VEC(tree, none) *base_binfos; + tree binfo; + unsigned i; + + complete_type (type); + + if (!NON_UNION_CLASS_TYPE_P (type)) + return make_tree_vec (0); + + base_binfos = BINFO_BASE_BINFOS (TYPE_BINFO (type)); + + /* Virtual bases are initialized first */ + for (i = 0; VEC_iterate (tree, base_binfos, i, binfo); i++) + { + if (BINFO_VIRTUAL_P (binfo)) + { + VEC_safe_push (tree, gc, vector, binfo); + } + } + + /* Now non-virtuals */ + for (i = 0; VEC_iterate (tree, base_binfos, i, binfo); i++) + { + if (!BINFO_VIRTUAL_P (binfo)) + { + VEC_safe_push (tree, gc, vector, binfo); + } + } + + + bases_vec = make_tree_vec (VEC_length (tree, vector)); + + for (i = 0; i < VEC_length (tree, vector); ++i) + { + TREE_VEC_ELT (bases_vec, i) = BINFO_TYPE (VEC_index (tree, vector, i)); + } + return bases_vec; +} + +/* Implement the __bases keyword: Return the base classes + of type */ + +/* Find morally non-virtual base classes by walking binfo hierarchy */ +/* Virtual base classes are handled separately in finish_bases */ + +static tree +dfs_calculate_bases_pre (tree binfo, ATTRIBUTE_UNUSED void *data_) +{ + /* Don't walk bases of virtual bases */ + return BINFO_VIRTUAL_P (binfo) ? dfs_skip_bases : NULL_TREE; +} + +static tree +dfs_calculate_bases_post (tree binfo, void *data_) +{ + VEC(tree, gc) **data = (VEC(tree, gc) **) data_; + if (!BINFO_VIRTUAL_P (binfo)) + { + VEC_safe_push (tree, gc, *data, BINFO_TYPE (binfo)); + } + return NULL_TREE; +} + +/* Calculates the morally non-virtual base classes of a class */ +static VEC(tree, gc) * +calculate_bases_helper (tree type) +{ + VEC(tree, gc) *vector = make_tree_vector(); + + /* Now add non-virtual base classes in order of construction */ + dfs_walk_all (TYPE_BINFO (type), + dfs_calculate_bases_pre, dfs_calculate_bases_post, &vector); + return vector; +} + +tree +calculate_bases (tree type) +{ + VEC(tree, gc) *vector = make_tree_vector(); + tree bases_vec = NULL_TREE; + unsigned i; + VEC(tree, gc) *vbases; + VEC(tree, gc) *nonvbases; + tree binfo; + + complete_type (type); + + if (!NON_UNION_CLASS_TYPE_P (type)) + return make_tree_vec (0); + + /* First go through virtual base classes */ + for (vbases = CLASSTYPE_VBASECLASSES (type), i = 0; + VEC_iterate (tree, vbases, i, binfo); i++) + { + VEC(tree, gc) *vbase_bases = calculate_bases_helper (BINFO_TYPE (binfo)); + VEC_safe_splice (tree, gc, vector, vbase_bases); + release_tree_vector (vbase_bases); + } + + /* Now for the non-virtual bases */ + nonvbases = calculate_bases_helper (type); + VEC_safe_splice (tree, gc, vector, nonvbases); + release_tree_vector (nonvbases); + + /* Last element is entire class, so don't copy */ + bases_vec = make_tree_vec (VEC_length (tree, vector) - 1); + + for (i = 0; i < VEC_length (tree, vector) - 1; ++i) + { + TREE_VEC_ELT (bases_vec, i) = VEC_index (tree, vector, i); + } + release_tree_vector (vector); + return bases_vec; +} + +tree +finish_bases (tree type, bool direct) +{ + tree bases = NULL_TREE; + + if (!processing_template_decl) + { + /* Parameter packs can only be used in templates */ + error ("Parameter pack __bases only valid in template declaration"); + return error_mark_node; + } + + bases = cxx_make_type (BASES); + BASES_TYPE (bases) = type; + BASES_DIRECT (bases) = direct; + SET_TYPE_STRUCTURAL_EQUALITY (bases); + + return bases; +} + /* Perform C++-specific checks for __builtin_offsetof before calling fold_offsetof. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 500c142..39efdcc 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2011-10-17 Michael Spertus <mike_spertus@symantec.com> + + * g++.dg/ext/bases.C: New test. + 2011-10-17 David S. Miller <davem@davemloft.net> * gcc.target/sparc/fand.c: Remove __LP64__ ifdefs and expect diff --git a/gcc/testsuite/g++.dg/ext/bases.C b/gcc/testsuite/g++.dg/ext/bases.C new file mode 100644 index 0000000..0582f72 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/bases.C @@ -0,0 +1,35 @@ +// { dg-options "-std=gnu++0x -w" } +// { dg-do run } + +#include<typeinfo> +#include<cassert> + +// A simple typelist +template<typename... _Elements> struct types {}; + +// Simple bases implementation +template<typename T> struct b { + typedef types<__bases(T)...> type; +}; + +// Simple direct_bases implementation +template<typename T> struct db { + typedef types<__direct_bases(T)...> type; +}; + +template <class,class> struct assert_same_type; +template <class T> struct assert_same_type<T,T> {}; + +struct A {}; +struct C : virtual A {}; +struct D : public C {}; +struct B : D, virtual A {}; +struct E : C, virtual D, B {}; +struct F : A, B, E {}; + +int main() { + assert_same_type<b<F>::type, types<A,C,D,A,C,D,B,C,C,D,B,E>>(); + assert_same_type<db<F>::type, types<A,B,E>>(); + assert_same_type<db<int>::type, types<>>(); + return 0; +} |