diff options
author | bkoz <bkoz@138bc75d-0d04-0410-961f-82ee72b054a4> | 2011-10-18 02:58:06 +0000 |
---|---|---|
committer | bkoz <bkoz@138bc75d-0d04-0410-961f-82ee72b054a4> | 2011-10-18 02:58:06 +0000 |
commit | e6014a82ae8a4aec4fb4bee768401c7da3549d97 (patch) | |
tree | 025d5854011b99cfe93205d711317cfd2947da24 /gcc/cp/semantics.c | |
parent | 05d36c46715e8b9ad4692b7c91da4594cf0d9826 (diff) | |
download | ppe42-gcc-e6014a82ae8a4aec4fb4bee768401c7da3549d97.tar.gz ppe42-gcc-e6014a82ae8a4aec4fb4bee768401c7da3549d97.zip |
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.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@180121 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/cp/semantics.c')
-rw-r--r-- | gcc/cp/semantics.c | 143 |
1 files changed, 143 insertions, 0 deletions
diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 1efe57907b0..3e847fa5ce5 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. */ |