summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornathan <nathan@138bc75d-0d04-0410-961f-82ee72b054a4>2004-10-08 09:33:55 +0000
committernathan <nathan@138bc75d-0d04-0410-961f-82ee72b054a4>2004-10-08 09:33:55 +0000
commit398b91ef0e2238be7cfc61286307d87819b322b0 (patch)
tree788c086498884f0d4d0b84c27c99cb6582b7f4b9
parentbca30b067fb03fbaeccca1407ad94902cf8c660f (diff)
downloadgcc-398b91ef0e2238be7cfc61286307d87819b322b0.tar.gz
* cp-tree.h (dfs_walk, dfs_walk_real, dfs_unmark, markedp,
unmarkedp): Remove. (dfs_skip_bases, dfs_walk_all, dfs_walk_once): New. * class.c (struct find_final_overrider_data): Remove most_derived, vpath_list and vpath fields. Add path field. (dfs_find_final_ocerrider_1): Add DEPTH parameter. Adjust. (dfs_find_final_overrider): Rename to ... (dfs_find_final_overrider_pre): ... here. Adjust. (dfs_find_final_overrider_post): Adjust. (dfs_find_final_overrider_q): Fold into dfs_find_final_overrider_pre. (find_final_overrider): Adjust dfs searching. (dfs_modify_vtables): Don't mark binfo here. (modify_all_vtables): Use dfs_walk_once. (build_vtt_inits): Likwise. Use dfs_walk_all. (dfs_build_secondary_vptr_vtt_inits): Don't mark binfo here. Return dfs_skip_bases as appropriate. (dfs_fixup_binfo_vtbls): Return dfs_skip_bases as appropriate. * init.c (dfs_initialized_vtbl_ptrs): Return dfs_skip_bases as appropriate. Don't mark binfo here. (initialize_vtbl_ptrs): Use dfs_walk_once. * search.c (struct vbase_info): Remove unused struct. (access_in_type): Use dfs_walk_once. (dfs_access_in_type): Don't mark binfo here. (dfs_accessible_queue_p, dfs_accessible_p) Remove. Fold into ... (accessible_r): ... here. New. Specialize dfs_walk_once. (accessible_p): Use accessible_r. (lookup_field_queue_p): Remove. Fold into ... (lookup_field_r): ... here. Adjust. (lookup_member): Use dfs_walk_all. (dfs_walk_real, dfs_walk): Replace with ... (dfs_walk_all, dfs_walk_once): ... these. (dfs_walk_once_r, dfs_unmark_r): Workers for dfs_walk_once. (dfs_unmark, unmarkedp, markedp): Remove. (dfs_get_pure_virtuals): Don't mark binfo here. (get_pure_virtuals): Use dfs_walk_once. (dfs_debug_unmarked_p): Remove. Fold into ... (dfs_debug_mark): ... here. (note_debug_info_needed): Use dfs_walk_all. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@88738 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/cp/ChangeLog43
-rw-r--r--gcc/cp/class.c121
-rw-r--r--gcc/cp/cp-tree.h17
-rw-r--r--gcc/cp/init.c12
-rw-r--r--gcc/cp/search.c388
5 files changed, 312 insertions, 269 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index df14e9c26e9..427a1e49ef8 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,46 @@
+2004-10-08 Nathan Sidwell <nathan@codesourcery.com>
+
+ * cp-tree.h (dfs_walk, dfs_walk_real, dfs_unmark, markedp,
+ unmarkedp): Remove.
+ (dfs_skip_bases, dfs_walk_all, dfs_walk_once): New.
+ * class.c (struct find_final_overrider_data): Remove most_derived,
+ vpath_list and vpath fields. Add path field.
+ (dfs_find_final_ocerrider_1): Add DEPTH parameter. Adjust.
+ (dfs_find_final_overrider): Rename to ...
+ (dfs_find_final_overrider_pre): ... here. Adjust.
+ (dfs_find_final_overrider_post): Adjust.
+ (dfs_find_final_overrider_q): Fold into
+ dfs_find_final_overrider_pre.
+ (find_final_overrider): Adjust dfs searching.
+ (dfs_modify_vtables): Don't mark binfo here.
+ (modify_all_vtables): Use dfs_walk_once.
+ (build_vtt_inits): Likwise. Use dfs_walk_all.
+ (dfs_build_secondary_vptr_vtt_inits): Don't mark binfo here.
+ Return dfs_skip_bases as appropriate.
+ (dfs_fixup_binfo_vtbls): Return dfs_skip_bases as appropriate.
+ * init.c (dfs_initialized_vtbl_ptrs): Return dfs_skip_bases as
+ appropriate. Don't mark binfo here.
+ (initialize_vtbl_ptrs): Use dfs_walk_once.
+ * search.c (struct vbase_info): Remove unused struct.
+ (access_in_type): Use dfs_walk_once.
+ (dfs_access_in_type): Don't mark binfo here.
+ (dfs_accessible_queue_p, dfs_accessible_p) Remove.
+ Fold into ...
+ (accessible_r): ... here. New. Specialize dfs_walk_once.
+ (accessible_p): Use accessible_r.
+ (lookup_field_queue_p): Remove. Fold into ...
+ (lookup_field_r): ... here. Adjust.
+ (lookup_member): Use dfs_walk_all.
+ (dfs_walk_real, dfs_walk): Replace with ...
+ (dfs_walk_all, dfs_walk_once): ... these.
+ (dfs_walk_once_r, dfs_unmark_r): Workers for dfs_walk_once.
+ (dfs_unmark, unmarkedp, markedp): Remove.
+ (dfs_get_pure_virtuals): Don't mark binfo here.
+ (get_pure_virtuals): Use dfs_walk_once.
+ (dfs_debug_unmarked_p): Remove. Fold into ...
+ (dfs_debug_mark): ... here.
+ (note_debug_info_needed): Use dfs_walk_all.
+
2004-10-07 Andrew Pinski <pinskia@physics.uc.edu>
* pt.c (tsubst_expr) <case ASM_EXPR>: Look passed the
diff --git a/gcc/cp/class.c b/gcc/cp/class.c
index e955560ffcd..d93ee228796 100644
--- a/gcc/cp/class.c
+++ b/gcc/cp/class.c
@@ -155,9 +155,8 @@ static void add_vcall_offset_vtbl_entries_1 (tree, vtbl_init_data *);
static void build_vcall_offset_vtbl_entries (tree, vtbl_init_data *);
static void add_vcall_offset (tree, tree, vtbl_init_data *);
static void layout_vtable_decl (tree, int);
-static tree dfs_find_final_overrider (tree, void *);
+static tree dfs_find_final_overrider_pre (tree, void *);
static tree dfs_find_final_overrider_post (tree, void *);
-static tree dfs_find_final_overrider_q (tree, int, void *);
static tree find_final_overrider (tree, tree, tree);
static int make_new_vtable (tree, tree);
static int maybe_indent_hierarchy (FILE *, int, int);
@@ -171,15 +170,14 @@ static void dump_thunk (FILE *, int, tree);
static tree build_vtable (tree, tree, tree);
static void initialize_vtable (tree, tree);
static void layout_nonempty_base_or_field (record_layout_info,
- tree, tree, splay_tree);
+ tree, tree, splay_tree);
static tree end_of_class (tree, int);
static bool layout_empty_base (tree, tree, splay_tree);
static void accumulate_vtbl_inits (tree, tree, tree, tree, tree);
static tree dfs_accumulate_vtbl_inits (tree, tree, tree, tree,
tree);
static void build_rtti_vtbl_entries (tree, vtbl_init_data *);
-static void build_vcall_and_vbase_vtbl_entries (tree,
- vtbl_init_data *);
+static void build_vcall_and_vbase_vtbl_entries (tree, vtbl_init_data *);
static void clone_constructors_and_destructors (tree);
static tree build_clone (tree, tree);
static void update_vtable_entry_for_fn (tree, tree, tree, tree *, unsigned);
@@ -192,11 +190,11 @@ static tree dfs_fixup_binfo_vtbls (tree, void *);
static int record_subobject_offset (tree, tree, splay_tree);
static int check_subobject_offset (tree, tree, splay_tree);
static int walk_subobject_offsets (tree, subobject_offset_fn,
- tree, splay_tree, tree, int);
+ tree, splay_tree, tree, int);
static void record_subobject_offsets (tree, tree, splay_tree, int);
static int layout_conflict_p (tree, tree, splay_tree, int);
static int splay_tree_compare_integer_csts (splay_tree_key k1,
- splay_tree_key k2);
+ splay_tree_key k2);
static void warn_about_ambiguous_bases (tree);
static bool type_requires_array_cookie (tree);
static bool contains_empty_class_p (tree);
@@ -1788,15 +1786,10 @@ typedef struct find_final_overrider_data_s {
tree fn;
/* The base class in which the function was declared. */
tree declaring_base;
- /* The most derived class in the hierarchy. */
- tree most_derived_type;
/* The candidate overriders. */
tree candidates;
- /* Each entry in this array is the next-most-derived class for a
- virtual base class along the current path. */
- tree *vpath_list;
- /* A pointer one past the top of the VPATH_LIST. */
- tree *vpath;
+ /* Path to most derived. */
+ VEC (tree) *path;
} find_final_overrider_data;
/* Add the overrider along the current path to FFOD->CANDIDATES.
@@ -1804,22 +1797,18 @@ typedef struct find_final_overrider_data_s {
static bool
dfs_find_final_overrider_1 (tree binfo,
- tree *vpath,
- find_final_overrider_data *ffod)
+ find_final_overrider_data *ffod,
+ unsigned depth)
{
tree method;
/* If BINFO is not the most derived type, try a more derived class.
A definition there will overrider a definition here. */
- if (!same_type_p (BINFO_TYPE (binfo), ffod->most_derived_type))
+ if (depth)
{
- tree derived;
-
- if (BINFO_VIRTUAL_P (binfo))
- derived = *--vpath;
- else
- derived = BINFO_INHERITANCE_CHAIN (binfo);
- if (dfs_find_final_overrider_1 (derived, vpath, ffod))
+ depth--;
+ if (dfs_find_final_overrider_1
+ (VEC_index (tree, ffod->path, depth), ffod, depth))
return true;
}
@@ -1853,36 +1842,23 @@ dfs_find_final_overrider_1 (tree binfo,
/* Called from find_final_overrider via dfs_walk. */
static tree
-dfs_find_final_overrider (tree binfo, void* data)
+dfs_find_final_overrider_pre (tree binfo, void *data)
{
find_final_overrider_data *ffod = (find_final_overrider_data *) data;
if (binfo == ffod->declaring_base)
- dfs_find_final_overrider_1 (binfo, ffod->vpath, ffod);
+ dfs_find_final_overrider_1 (binfo, ffod, VEC_length (tree, ffod->path));
+ VEC_safe_push (tree, ffod->path, binfo);
return NULL_TREE;
}
static tree
-dfs_find_final_overrider_q (tree derived, int ix, void *data)
-{
- tree binfo = BINFO_BASE_BINFO (derived, ix);
- find_final_overrider_data *ffod = (find_final_overrider_data *) data;
-
- if (BINFO_VIRTUAL_P (binfo))
- *ffod->vpath++ = derived;
-
- return binfo;
-}
-
-static tree
-dfs_find_final_overrider_post (tree binfo, void *data)
+dfs_find_final_overrider_post (tree binfo ATTRIBUTE_UNUSED, void *data)
{
find_final_overrider_data *ffod = (find_final_overrider_data *) data;
+ VEC_pop (tree, ffod->path);
- if (BINFO_VIRTUAL_P (binfo))
- ffod->vpath--;
-
return NULL_TREE;
}
@@ -1920,23 +1896,14 @@ find_final_overrider (tree derived, tree binfo, tree fn)
/* Determine the depth of the hierarchy. */
ffod.fn = fn;
ffod.declaring_base = binfo;
- ffod.most_derived_type = BINFO_TYPE (derived);
ffod.candidates = NULL_TREE;
- /* The virtual depth cannot be greater than the number of virtual
- bases. */
- ffod.vpath_list = (tree *) xcalloc
- (VEC_length (tree, CLASSTYPE_VBASECLASSES (BINFO_TYPE (derived))),
- sizeof (tree));
- ffod.vpath = ffod.vpath_list;
-
- dfs_walk_real (derived,
- dfs_find_final_overrider,
- dfs_find_final_overrider_post,
- dfs_find_final_overrider_q,
- &ffod);
+ ffod.path = VEC_alloc (tree, 30);
- free (ffod.vpath_list);
+ dfs_walk_all (derived, dfs_find_final_overrider_pre,
+ dfs_find_final_overrider_post, &ffod);
+ VEC_free (tree, ffod.path);
+
/* If there was no winner, issue an error message. */
if (!ffod.candidates || TREE_CHAIN (ffod.candidates))
{
@@ -2208,8 +2175,6 @@ dfs_modify_vtables (tree binfo, void* data)
&virtuals, ix);
}
- BINFO_MARKED (binfo) = 1;
-
return NULL_TREE;
}
@@ -2229,8 +2194,7 @@ modify_all_vtables (tree t, tree virtuals)
tree *fnsp;
/* Update all of the vtables. */
- dfs_walk (binfo, dfs_modify_vtables, unmarkedp, t);
- dfs_walk (binfo, dfs_unmark, markedp, t);
+ dfs_walk_once (binfo, NULL, dfs_modify_vtables, t);
/* Add virtual functions not already in our primary vtable. These
will be both those introduced by this class, and those overridden
@@ -6763,7 +6727,7 @@ build_vtt_inits (tree binfo, tree t, tree *inits, tree *index)
/* Recursively add the secondary VTTs for non-virtual bases. */
for (i = 0; BINFO_BASE_ITERATE (binfo, i, b); ++i)
if (!BINFO_VIRTUAL_P (b))
- inits = build_vtt_inits (BINFO_BASE_BINFO (binfo, i), t, inits, index);
+ inits = build_vtt_inits (b, t, inits, index);
/* Add secondary virtual pointers for all subobjects of BINFO with
either virtual bases or reachable along a virtual path, except
@@ -6773,9 +6737,7 @@ build_vtt_inits (tree binfo, tree t, tree *inits, tree *index)
data.inits = NULL;
data.type_being_constructed = BINFO_TYPE (binfo);
- dfs_walk_real (binfo, dfs_build_secondary_vptr_vtt_inits,
- NULL, unmarkedp, &data);
- dfs_walk (binfo, dfs_unmark, markedp, 0);
+ dfs_walk_once (binfo, dfs_build_secondary_vptr_vtt_inits, NULL, &data);
*index = data.index;
@@ -6802,7 +6764,7 @@ build_vtt_inits (tree binfo, tree t, tree *inits, tree *index)
}
else
/* Remove the ctor vtables we created. */
- dfs_walk (binfo, dfs_fixup_binfo_vtbls, 0, binfo);
+ dfs_walk_all (binfo, dfs_fixup_binfo_vtbls, NULL, binfo);
return inits;
}
@@ -6815,27 +6777,25 @@ dfs_build_secondary_vptr_vtt_inits (tree binfo, void *data_)
{
secondary_vptr_vtt_init_data *data = (secondary_vptr_vtt_init_data *)data_;
- BINFO_MARKED (binfo) = 1;
-
/* We don't care about bases that don't have vtables. */
if (!TYPE_VFIELD (BINFO_TYPE (binfo)))
- return NULL_TREE;
+ return dfs_skip_bases;
/* We're only interested in proper subobjects of the type being
constructed. */
if (same_type_p (BINFO_TYPE (binfo), data->type_being_constructed))
return NULL_TREE;
- /* We're not interested in non-virtual primary bases. */
- if (!BINFO_VIRTUAL_P (binfo) && BINFO_PRIMARY_P (binfo))
- return NULL_TREE;
-
/* We're only interested in bases with virtual bases or reachable
via a virtual path from the type being constructed. */
- if (!CLASSTYPE_VBASECLASSES (BINFO_TYPE (binfo))
- && !binfo_via_virtual (binfo, data->type_being_constructed))
+ if (!(CLASSTYPE_VBASECLASSES (BINFO_TYPE (binfo))
+ || binfo_via_virtual (binfo, data->type_being_constructed)))
+ return dfs_skip_bases;
+
+ /* We're not interested in non-virtual primary bases. */
+ if (!BINFO_VIRTUAL_P (binfo) && BINFO_PRIMARY_P (binfo))
return NULL_TREE;
-
+
/* Record the index where this secondary vptr can be found. */
if (data->top_level_p)
{
@@ -6873,9 +6833,18 @@ dfs_fixup_binfo_vtbls (tree binfo, void* data)
{
tree vtable = BINFO_VTABLE (binfo);
+ if (!TYPE_CONTAINS_VPTR_P (BINFO_TYPE (binfo)))
+ /* If this class has no vtable, none of its bases do. */
+ return dfs_skip_bases;
+
+ if (!vtable)
+ /* This might be a primary base, so have no vtable in this
+ hierarchy. */
+ return NULL_TREE;
+
/* If we scribbled the construction vtable vptr into BINFO, clear it
out now. */
- if (vtable && TREE_CODE (vtable) == TREE_LIST
+ if (TREE_CODE (vtable) == TREE_LIST
&& (TREE_PURPOSE (vtable) == (tree) data))
BINFO_VTABLE (binfo) = TREE_CHAIN (vtable);
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index 58dae736170..826bd51cf29 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -4014,18 +4014,11 @@ extern tree binfo_from_vbase (tree);
extern tree binfo_for_vbase (tree, tree);
extern tree look_for_overrides_here (tree, tree);
extern int check_final_overrider (tree, tree);
-extern tree dfs_walk (tree,
- tree (*) (tree, void *),
- tree (*) (tree, int, void *),
- void *);
-extern tree dfs_walk_real (tree,
- tree (*) (tree, void *),
- tree (*) (tree, void *),
- tree (*) (tree, int, void *),
- void *);
-extern tree dfs_unmark (tree, void *);
-extern tree markedp (tree, int, void *);
-extern tree unmarkedp (tree, int, void *);
+#define dfs_skip_bases ((tree)1)
+extern tree dfs_walk_all (tree, tree (*) (tree, void *),
+ tree (*) (tree, void *), void *);
+extern tree dfs_walk_once (tree, tree (*) (tree, void *),
+ tree (*) (tree, void *), void *);
extern tree binfo_via_virtual (tree, tree);
extern tree build_baselink (tree, tree, tree, tree);
extern tree adjust_result_of_qualified_name_lookup
diff --git a/gcc/cp/init.c b/gcc/cp/init.c
index 12886836d1b..ceb6d690a6a 100644
--- a/gcc/cp/init.c
+++ b/gcc/cp/init.c
@@ -101,8 +101,10 @@ finish_init_stmts (bool is_global, tree stmt_expr, tree compound_stmt)
static tree
dfs_initialize_vtbl_ptrs (tree binfo, void *data)
{
- if ((!BINFO_PRIMARY_P (binfo) || BINFO_VIRTUAL_P (binfo))
- && TYPE_CONTAINS_VPTR_P (BINFO_TYPE (binfo)))
+ if (!TYPE_CONTAINS_VPTR_P (BINFO_TYPE (binfo)))
+ return dfs_skip_bases;
+
+ if (!BINFO_PRIMARY_P (binfo) || BINFO_VIRTUAL_P (binfo))
{
tree base_ptr = TREE_VALUE ((tree) data);
@@ -111,8 +113,6 @@ dfs_initialize_vtbl_ptrs (tree binfo, void *data)
expand_virtual_init (binfo, base_ptr);
}
- BINFO_MARKED (binfo) = 1;
-
return NULL_TREE;
}
@@ -132,9 +132,7 @@ initialize_vtbl_ptrs (tree addr)
class. We do these in pre-order because we can't find the virtual
bases for a class until we've initialized the vtbl for that
class. */
- dfs_walk_real (TYPE_BINFO (type), dfs_initialize_vtbl_ptrs,
- NULL, unmarkedp, list);
- dfs_walk (TYPE_BINFO (type), dfs_unmark, markedp, type);
+ dfs_walk_once (TYPE_BINFO (type), dfs_initialize_vtbl_ptrs, NULL, list);
}
/* Return an expression for the zero-initialization of an object with
diff --git a/gcc/cp/search.c b/gcc/cp/search.c
index 514f868692d..79c6839fdec 100644
--- a/gcc/cp/search.c
+++ b/gcc/cp/search.c
@@ -36,29 +36,20 @@ Boston, MA 02111-1307, USA. */
#include "toplev.h"
#include "stack.h"
-struct vbase_info
-{
- /* The class dominating the hierarchy. */
- tree type;
- /* A pointer to a complete object of the indicated TYPE. */
- tree decl_ptr;
- tree inits;
-};
-
static int is_subobject_of_p (tree, tree);
static base_kind lookup_base_r (tree, tree, base_access, bool, tree *);
static int dynamic_cast_base_recurse (tree, tree, bool, tree *);
-static tree dfs_debug_unmarkedp (tree, int, void *);
static tree dfs_debug_mark (tree, void *);
+static tree dfs_walk_once_r (tree, tree (*pre_fn) (tree, void *),
+ tree (*post_fn) (tree, void *), void *data);
+static void dfs_unmark_r (tree);
static int check_hidden_convs (tree, int, int, tree, tree, tree);
static tree split_conversions (tree, tree, tree, tree);
static int lookup_conversions_r (tree, int, int,
tree, tree, tree, tree, tree *, tree *);
static int look_for_overrides_r (tree, tree);
-static tree lookup_field_queue_p (tree, int, void *);
static tree lookup_field_r (tree, void *);
-static tree dfs_accessible_queue_p (tree, int, void *);
-static tree dfs_accessible_p (tree, void *);
+static tree accessible_r (tree, bool);
static tree dfs_access_in_type (tree, void *);
static access_kind access_in_type (tree, tree);
static int protected_accessible_p (tree, tree, tree);
@@ -663,10 +654,6 @@ dfs_access_in_type (tree binfo, void *data)
/* Note the access to DECL in TYPE. */
SET_BINFO_ACCESS (binfo, access);
- /* Mark TYPE as visited so that if we reach it again we do not
- duplicate our efforts here. */
- BINFO_MARKED (binfo) = 1;
-
return NULL_TREE;
}
@@ -688,47 +675,11 @@ access_in_type (tree type, tree decl)
The algorithm we use is to make a post-order depth-first traversal
of the base-class hierarchy. As we come up the tree, we annotate
each node with the most lenient access. */
- dfs_walk_real (binfo, 0, dfs_access_in_type, unmarkedp, decl);
- dfs_walk (binfo, dfs_unmark, markedp, 0);
+ dfs_walk_once (binfo, NULL, dfs_access_in_type, decl);
return BINFO_ACCESS (binfo);
}
-/* Called from accessible_p via dfs_walk. */
-
-static tree
-dfs_accessible_queue_p (tree derived, int ix, void *data ATTRIBUTE_UNUSED)
-{
- tree binfo = BINFO_BASE_BINFO (derived, ix);
-
- if (BINFO_MARKED (binfo))
- return NULL_TREE;
-
- /* If this class is inherited via private or protected inheritance,
- then we can't see it, unless we are a friend of the derived class. */
- if (BINFO_BASE_ACCESS (derived, ix) != access_public_node
- && !is_friend (BINFO_TYPE (derived), current_scope ()))
- return NULL_TREE;
-
- return binfo;
-}
-
-/* Called from accessible_p via dfs_walk. */
-
-static tree
-dfs_accessible_p (tree binfo, void *data ATTRIBUTE_UNUSED)
-{
- access_kind access;
-
- BINFO_MARKED (binfo) = 1;
- access = BINFO_ACCESS (binfo);
- if (access != ak_none
- && is_friend (BINFO_TYPE (binfo), current_scope ()))
- return binfo;
-
- return NULL_TREE;
-}
-
/* Returns nonzero if it is OK to access DECL through an object
indicated by BINFO in the context of DERIVED. */
@@ -855,6 +806,43 @@ friend_accessible_p (tree scope, tree decl, tree binfo)
return 0;
}
+static tree
+accessible_r (tree binfo, bool once)
+{
+ tree rval = NULL_TREE;
+ unsigned ix;
+ tree base_binfo;
+
+ /* Find the next child binfo to walk. */
+ for (ix = 0; BINFO_BASE_ITERATE (binfo, ix, base_binfo); ix++)
+ {
+ bool mark = once && BINFO_VIRTUAL_P (base_binfo);
+
+ if (mark && BINFO_MARKED (base_binfo))
+ continue;
+
+ /* If the base is inherited via private or protected
+ inheritance, then we can't see it, unless we are a friend of
+ the current binfo. */
+ if (BINFO_BASE_ACCESS (binfo, ix) != access_public_node
+ && !is_friend (BINFO_TYPE (binfo), current_scope ()))
+ continue;
+
+ if (mark)
+ BINFO_MARKED (base_binfo) = 1;
+
+ rval = accessible_r (base_binfo, once);
+ if (rval)
+ return rval;
+ }
+
+ if (BINFO_ACCESS (binfo) != ak_none
+ && is_friend (BINFO_TYPE (binfo), current_scope ()))
+ rval = binfo;
+
+ return rval;
+}
+
/* DECL is a declaration from a base class of TYPE, which was the
class used to name DECL. Return nonzero if, in the current
context, DECL is accessible. If TYPE is actually a BINFO node,
@@ -941,12 +929,28 @@ accessible_p (tree type, tree decl)
{
/* Walk the hierarchy again, looking for a base class that allows
access. */
- t = dfs_walk (binfo, dfs_accessible_p, dfs_accessible_queue_p, 0);
- /* Clear any mark bits. Note that we have to walk the whole tree
- here, since we have aborted the previous walk from some point
- deep in the tree. */
- dfs_walk (binfo, dfs_unmark, 0, 0);
+ t = accessible_r
+ (binfo, CLASSTYPE_DIAMOND_SHAPED_P (BINFO_TYPE (binfo)));
+ if (!CLASSTYPE_DIAMOND_SHAPED_P (BINFO_TYPE (binfo)))
+ ;/* We are not diamond shaped, and therefore cannot
+ encounter the same binfo twice. */
+ else if (!BINFO_INHERITANCE_CHAIN (binfo))
+ {
+ /* We are at the top of the hierachy, and can use the
+ CLASSTYPE_VBASECLASSES list for unmarking the virtual
+ bases. */
+ VEC (tree) *vbases;
+ unsigned ix;
+ tree base_binfo;
+
+ for (vbases = CLASSTYPE_VBASECLASSES (BINFO_TYPE (binfo)), ix = 0;
+ VEC_iterate (tree, vbases, ix, base_binfo); ix++)
+ BINFO_MARKED (base_binfo) = 0;
+ }
+ else
+ dfs_unmark_r (binfo);
+
return t != NULL_TREE;
}
}
@@ -969,33 +973,6 @@ struct lookup_field_info {
const char *errstr;
};
-/* Returns nonzero if BINFO is not hidden by the value found by the
- lookup so far. If BINFO is hidden, then there's no need to look in
- it. DATA is really a struct lookup_field_info. Called from
- lookup_field via breadth_first_search. */
-
-static tree
-lookup_field_queue_p (tree derived, int ix, void *data)
-{
- tree binfo = BINFO_BASE_BINFO (derived, ix);
- struct lookup_field_info *lfi = (struct lookup_field_info *) data;
-
- /* Don't look for constructors or destructors in base classes. */
- if (IDENTIFIER_CTOR_OR_DTOR_P (lfi->name))
- return NULL_TREE;
-
- /* If this base class is hidden by the best-known value so far, we
- don't need to look. */
- if (lfi->rval_binfo && derived == lfi->rval_binfo)
- return NULL_TREE;
-
- /* If this is a dependent base, don't look in it. */
- if (BINFO_DEPENDENT_BASE_P (binfo))
- return NULL_TREE;
-
- return binfo;
-}
-
/* Within the scope of a template class, you can refer to the to the
current specialization with the name of the template itself. For
example:
@@ -1075,6 +1052,16 @@ lookup_field_r (tree binfo, void *data)
tree type = BINFO_TYPE (binfo);
tree nval = NULL_TREE;
+ /* If this is a dependent base, don't look in it. */
+ if (BINFO_DEPENDENT_BASE_P (binfo))
+ return NULL_TREE;
+
+ /* If this base class is hidden by the best-known value so far, we
+ don't need to look. */
+ if (lfi->rval_binfo && BINFO_INHERITANCE_CHAIN (binfo) == lfi->rval_binfo
+ && !BINFO_VIRTUAL_P (binfo))
+ return dfs_skip_bases;
+
/* First, look for a function. There can't be a function and a data
member with the same name, and if there's a function and a type
with the same name, the type is hidden by the function. */
@@ -1092,7 +1079,7 @@ lookup_field_r (tree binfo, void *data)
/* If there is no declaration with the indicated name in this type,
then there's nothing to do. */
if (!nval)
- return NULL_TREE;
+ goto done;
/* If we're looking up a type (as with an elaborated type specifier)
we ignore all non-types we find. */
@@ -1119,14 +1106,14 @@ lookup_field_r (tree binfo, void *data)
if (e != NULL)
nval = TYPE_MAIN_DECL (e->type);
else
- return NULL_TREE;
+ goto done;
}
}
/* You must name a template base class with a template-id. */
if (!same_type_p (type, lfi->type)
&& template_self_reference_p (type, nval))
- return NULL_TREE;
+ goto done;
/* If the lookup already found a match, and the new value doesn't
hide the old one, we might have an ambiguity. */
@@ -1165,6 +1152,10 @@ lookup_field_r (tree binfo, void *data)
lfi->rval_binfo = binfo;
}
+ done:
+ /* Don't look for constructors or destructors in base classes. */
+ if (IDENTIFIER_CTOR_OR_DTOR_P (lfi->name))
+ return dfs_skip_bases;
return NULL_TREE;
}
@@ -1251,8 +1242,7 @@ lookup_member (tree xbasetype, tree name, int protect, bool want_type)
lfi.type = type;
lfi.name = name;
lfi.want_type = want_type;
- dfs_walk_real (basetype_path, &lookup_field_r, 0,
- &lookup_field_queue_p, &lfi);
+ dfs_walk_all (basetype_path, &lookup_field_r, NULL, &lfi);
rval = lfi.rval;
rval_binfo = lfi.rval_binfo;
if (rval_binfo)
@@ -1526,66 +1516,158 @@ adjust_result_of_qualified_name_lookup (tree decl,
/* Walk the class hierarchy within BINFO, in a depth-first traversal.
- PREFN is called in preorder, while POSTFN is called in postorder.
- If they ever returns a non-NULL value, that value is immediately
- returned and the walk is terminated. Both PREFN and POSTFN can be
- NULL. At each node, PREFN and POSTFN are passed the binfo to
- examine. Before each base-binfo of BINFO is walked, QFN is called.
- If the value returned is nonzero, the base-binfo is walked;
- otherwise it is not. If QFN is NULL, it is treated as a function
- which always returns 1. All callbacks are passed DATA whenever
- they are called. */
+ PRE_FN is called in preorder, while POST_FN is called in postorder.
+ If PRE_FN returns DFS_SKIP_BASES, child binfos will not be
+ walked. If PRE_FN or POST_FN returns a different non-NULL value,
+ that value is immediately returned and the walk is terminated. One
+ of PRE_FN and POST_FN can be NULL. At each node, PRE_FN and
+ POST_FN are passed the binfo to examine and the caller's DATA
+ value. All paths are walked, thus virtual and morally virtual
+ binfos can be multiply walked. */
tree
-dfs_walk_real (tree binfo,
- tree (*prefn) (tree, void *),
- tree (*postfn) (tree, void *),
- tree (*qfn) (tree, int, void *),
- void *data)
+dfs_walk_all (tree binfo, tree (*pre_fn) (tree, void *),
+ tree (*post_fn) (tree, void *), void *data)
{
- int i;
+ tree rval;
+ unsigned ix;
tree base_binfo;
- tree rval = NULL_TREE;
-
+
/* Call the pre-order walking function. */
- if (prefn)
+ if (pre_fn)
+ {
+ rval = pre_fn (binfo, data);
+ if (rval)
+ {
+ if (rval == dfs_skip_bases)
+ goto skip_bases;
+ return rval;
+ }
+ }
+
+ /* Find the next child binfo to walk. */
+ for (ix = 0; BINFO_BASE_ITERATE (binfo, ix, base_binfo); ix++)
{
- rval = (*prefn) (binfo, data);
+ rval = dfs_walk_all (base_binfo, pre_fn, post_fn, data);
if (rval)
return rval;
}
- /* Process the basetypes. */
- for (i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
+ skip_bases:
+ /* Call the post-order walking function. */
+ if (post_fn)
+ return post_fn (binfo, data);
+ return NULL_TREE;
+}
+
+/* Worker for dfs_walk_once. This behaves as dfs_walk_all, except
+ that binfos are walked at most once. */
+
+static tree
+dfs_walk_once_r (tree binfo, tree (*pre_fn) (tree, void *),
+ tree (*post_fn) (tree, void *), void *data)
+{
+ tree rval;
+ unsigned ix;
+ tree base_binfo;
+
+ /* Call the pre-order walking function. */
+ if (pre_fn)
{
- if (qfn)
+ rval = pre_fn (binfo, data);
+ if (rval)
{
- base_binfo = (*qfn) (binfo, i, data);
- if (!base_binfo)
+ if (rval == dfs_skip_bases)
+ goto skip_bases;
+
+ return rval;
+ }
+ }
+
+ /* Find the next child binfo to walk. */
+ for (ix = 0; BINFO_BASE_ITERATE (binfo, ix, base_binfo); ix++)
+ {
+ if (BINFO_VIRTUAL_P (base_binfo))
+ {
+ if (BINFO_MARKED (base_binfo))
continue;
+ BINFO_MARKED (base_binfo) = 1;
}
- rval = dfs_walk_real (base_binfo, prefn, postfn, qfn, data);
+
+ rval = dfs_walk_once_r (base_binfo, pre_fn, post_fn, data);
if (rval)
return rval;
}
-
+
+ skip_bases:
/* Call the post-order walking function. */
- if (postfn)
- rval = (*postfn) (binfo, data);
+ if (post_fn)
+ return post_fn (binfo, data);
- return rval;
+ return NULL_TREE;
}
-/* Exactly like dfs_walk_real, except that there is no pre-order
- function call and FN is called in post-order. */
+/* Worker for dfs_walk_once. Recursively unmark the virtual base binfos of
+ BINFO. */
+
+static void
+dfs_unmark_r (tree binfo)
+{
+ unsigned ix;
+ tree base_binfo;
+
+ /* Process the basetypes. */
+ for (ix = 0; BINFO_BASE_ITERATE (binfo, ix, base_binfo); ix++)
+ {
+ if (BINFO_VIRTUAL_P (base_binfo))
+ {
+ if (!BINFO_MARKED (base_binfo))
+ continue;
+ BINFO_MARKED (base_binfo) = 0;
+ }
+ /* Only walk, if it can contain more virtual bases. */
+ if (CLASSTYPE_VBASECLASSES (BINFO_TYPE (base_binfo)))
+ dfs_unmark_r (base_binfo);
+ }
+}
+
+/* Like dfs_walk_all, except that binfos are not multiply walked. For
+ non-diamond shaped hierarchies this is the same as dfs_walk_all.
+ For diamond shaped hierarchies we must mark the virtual bases, to
+ avoid multiple walks. */
tree
-dfs_walk (tree binfo,
- tree (*fn) (tree, void *),
- tree (*qfn) (tree, int, void *),
- void *data)
+dfs_walk_once (tree binfo, tree (*pre_fn) (tree, void *),
+ tree (*post_fn) (tree, void *), void *data)
{
- return dfs_walk_real (binfo, 0, fn, qfn, data);
+ tree rval;
+
+ gcc_assert (pre_fn || post_fn);
+
+ if (!CLASSTYPE_DIAMOND_SHAPED_P (BINFO_TYPE (binfo)))
+ /* We are not diamond shaped, and therefore cannot encounter the
+ same binfo twice. */
+ rval = dfs_walk_all (binfo, pre_fn, post_fn, data);
+ else
+ {
+ rval = dfs_walk_once_r (binfo, pre_fn, post_fn, data);
+ if (!BINFO_INHERITANCE_CHAIN (binfo))
+ {
+ /* We are at the top of the hierachy, and can use the
+ CLASSTYPE_VBASECLASSES list for unmarking the virtual
+ bases. */
+ VEC (tree) *vbases;
+ unsigned ix;
+ tree base_binfo;
+
+ for (vbases = CLASSTYPE_VBASECLASSES (BINFO_TYPE (binfo)), ix = 0;
+ VEC_iterate (tree, vbases, ix, base_binfo); ix++)
+ BINFO_MARKED (base_binfo) = 0;
+ }
+ else
+ dfs_unmark_r (binfo);
+ }
+ return rval;
}
/* Check that virtual overrider OVERRIDER is acceptable for base function
@@ -1805,8 +1887,6 @@ dfs_get_pure_virtuals (tree binfo, void *data)
VEC_safe_push (tree, CLASSTYPE_PURE_VIRTUALS (type),
BV_FN (virtuals));
}
-
- BINFO_MARKED (binfo) = 1;
return NULL_TREE;
}
@@ -1825,39 +1905,8 @@ get_pure_virtuals (tree type)
(A primary base is not interesting because the derived class of
which it is a primary base will contain vtable entries for the
pure virtuals in the base class. */
- dfs_walk (TYPE_BINFO (type), dfs_get_pure_virtuals, unmarkedp, type);
- dfs_walk (TYPE_BINFO (type), dfs_unmark, markedp, type);
-}
-
-/* DEPTH-FIRST SEARCH ROUTINES. */
-
-tree
-markedp (tree derived, int ix, void *data ATTRIBUTE_UNUSED)
-{
- tree binfo = BINFO_BASE_BINFO (derived, ix);
-
- return BINFO_MARKED (binfo) ? binfo : NULL_TREE;
-}
-
-tree
-unmarkedp (tree derived, int ix, void *data ATTRIBUTE_UNUSED)
-{
- tree binfo = BINFO_BASE_BINFO (derived, ix);
-
- return !BINFO_MARKED (binfo) ? binfo : NULL_TREE;
-}
-
-/* The worker functions for `dfs_walk'. These do not need to
- test anything (vis a vis marking) if they are paired with
- a predicate function (above). */
-
-tree
-dfs_unmark (tree binfo, void *data ATTRIBUTE_UNUSED)
-{
- BINFO_MARKED (binfo) = 0;
- return NULL_TREE;
+ dfs_walk_once (TYPE_BINFO (type), NULL, dfs_get_pure_virtuals, type);
}
-
/* Debug info for C++ classes can get very large; try to avoid
emitting it everywhere.
@@ -1905,23 +1954,14 @@ dfs_debug_mark (tree binfo, void *data ATTRIBUTE_UNUSED)
{
tree t = BINFO_TYPE (binfo);
+ if (CLASSTYPE_DEBUG_REQUESTED (t))
+ return dfs_skip_bases;
+
CLASSTYPE_DEBUG_REQUESTED (t) = 1;
return NULL_TREE;
}
-/* Returns BINFO if we haven't already noted that we want debugging
- info for this base class. */
-
-static tree
-dfs_debug_unmarkedp (tree derived, int ix, void *data ATTRIBUTE_UNUSED)
-{
- tree binfo = BINFO_BASE_BINFO (derived, ix);
-
- return (!CLASSTYPE_DEBUG_REQUESTED (BINFO_TYPE (binfo))
- ? binfo : NULL_TREE);
-}
-
/* Write out the debugging information for TYPE, whose vtable is being
emitted. Also walk through our bases and note that we want to
write out information for them. This avoids the problem of not
@@ -1938,7 +1978,7 @@ note_debug_info_needed (tree type)
rest_of_type_compilation (type, toplevel_bindings_p ());
}
- dfs_walk (TYPE_BINFO (type), dfs_debug_mark, dfs_debug_unmarkedp, 0);
+ dfs_walk_all (TYPE_BINFO (type), dfs_debug_mark, NULL, 0);
}
void