#include "config.h"
#include "system.h"
#include "tree.h"
#include "cp-tree.h"
#include "flags.h"
#include "rtl.h"
#include "output.h"
#include "toplev.h"
#include "lex.h"
#include "target.h"
int current_class_depth;
typedef struct class_stack_node {
tree name;
tree type;
tree access;
splay_tree names_used;
}* class_stack_node_t;
typedef struct vtbl_init_data_s
{
tree binfo;
tree derived;
tree rtti_binfo;
tree inits;
tree* last_init;
tree vbase;
varray_type fns;
tree index;
int primary_vtbl_p;
int ctor_vtbl_p;
bool generate_vcall_entries;
} vtbl_init_data;
typedef int (*subobject_offset_fn) PARAMS ((tree, tree, splay_tree));
static int current_class_stack_size;
static class_stack_node_t current_class_stack;
varray_type local_classes;
static tree get_vfield_name PARAMS ((tree));
static void finish_struct_anon PARAMS ((tree));
static tree get_vtable_name PARAMS ((tree));
static tree get_basefndecls PARAMS ((tree, tree));
static int build_primary_vtable PARAMS ((tree, tree));
static int build_secondary_vtable PARAMS ((tree, tree));
static void finish_vtbls PARAMS ((tree));
static void modify_vtable_entry PARAMS ((tree, tree, tree, tree, tree *));
static tree delete_duplicate_fields_1 PARAMS ((tree, tree));
static void delete_duplicate_fields PARAMS ((tree));
static void finish_struct_bits PARAMS ((tree));
static int alter_access PARAMS ((tree, tree, tree));
static void handle_using_decl PARAMS ((tree, tree));
static void check_for_override PARAMS ((tree, tree));
static tree dfs_modify_vtables PARAMS ((tree, void *));
static tree modify_all_vtables PARAMS ((tree, tree));
static void determine_primary_base PARAMS ((tree));
static void finish_struct_methods PARAMS ((tree));
static void maybe_warn_about_overly_private_class PARAMS ((tree));
static int field_decl_cmp PARAMS ((const void *, const void *));
static int resort_field_decl_cmp PARAMS ((const void *, const void *));
static int method_name_cmp PARAMS ((const void *, const void *));
static int resort_method_name_cmp PARAMS ((const void *, const void *));
static void add_implicitly_declared_members PARAMS ((tree, int, int, int));
static tree fixed_type_or_null PARAMS ((tree, int *, int *));
static tree resolve_address_of_overloaded_function PARAMS ((tree, tree, int,
int, int, tree));
static tree build_vtable_entry_ref PARAMS ((tree, tree, tree));
static tree build_vtbl_ref_1 PARAMS ((tree, tree));
static tree build_vtbl_initializer PARAMS ((tree, tree, tree, tree, int *));
static int count_fields PARAMS ((tree));
static int add_fields_to_vec PARAMS ((tree, tree, int));
static void check_bitfield_decl PARAMS ((tree));
static void check_field_decl (tree, tree, int *, int *, int *, int *);
static void check_field_decls (tree, tree *, int *, int *, int *);
static tree *build_base_field (record_layout_info, tree, splay_tree, tree *);
static void build_base_fields (record_layout_info, splay_tree, tree *);
static void check_methods PARAMS ((tree));
static void remove_zero_width_bit_fields PARAMS ((tree));
static void check_bases PARAMS ((tree, int *, int *, int *));
static void check_bases_and_members (tree);
static tree create_vtable_ptr (tree, tree *);
static void include_empty_classes (record_layout_info);
static void layout_class_type (tree, tree *);
static void fixup_pending_inline PARAMS ((tree));
static void fixup_inline_methods PARAMS ((tree));
static void set_primary_base PARAMS ((tree, tree));
static void propagate_binfo_offsets PARAMS ((tree, tree, tree));
static void layout_virtual_bases (record_layout_info, splay_tree);
static tree dfs_set_offset_for_unshared_vbases PARAMS ((tree, void *));
static void build_vbase_offset_vtbl_entries PARAMS ((tree, vtbl_init_data *));
static void add_vcall_offset_vtbl_entries_r PARAMS ((tree, vtbl_init_data *));
static void add_vcall_offset_vtbl_entries_1 PARAMS ((tree, vtbl_init_data *));
static void build_vcall_offset_vtbl_entries PARAMS ((tree, vtbl_init_data *));
static void add_vcall_offset (tree, tree, vtbl_init_data *);
static void layout_vtable_decl PARAMS ((tree, int));
static tree dfs_find_final_overrider PARAMS ((tree, void *));
static tree find_final_overrider PARAMS ((tree, tree, tree));
static int make_new_vtable PARAMS ((tree, tree));
static int maybe_indent_hierarchy PARAMS ((FILE *, int, int));
static void dump_class_hierarchy_r PARAMS ((FILE *, int, tree, tree, int));
static void dump_class_hierarchy PARAMS ((tree));
static void dump_array PARAMS ((FILE *, tree));
static void dump_vtable PARAMS ((tree, tree, tree));
static void dump_vtt PARAMS ((tree, tree));
static tree build_vtable PARAMS ((tree, tree, tree));
static void initialize_vtable PARAMS ((tree, tree));
static void initialize_array PARAMS ((tree, tree));
static void layout_nonempty_base_or_field PARAMS ((record_layout_info,
tree, tree, splay_tree));
static tree end_of_class PARAMS ((tree, int));
static bool layout_empty_base PARAMS ((tree, tree, splay_tree, tree));
static void accumulate_vtbl_inits PARAMS ((tree, tree, tree, tree, tree));
static tree dfs_accumulate_vtbl_inits PARAMS ((tree, tree, tree, tree,
tree));
static void build_rtti_vtbl_entries PARAMS ((tree, vtbl_init_data *));
static void build_vcall_and_vbase_vtbl_entries PARAMS ((tree,
vtbl_init_data *));
static void force_canonical_binfo_r PARAMS ((tree, tree, tree, tree));
static void force_canonical_binfo PARAMS ((tree, tree, tree, tree));
static tree dfs_unshared_virtual_bases PARAMS ((tree, void *));
static void mark_primary_bases PARAMS ((tree));
static tree mark_primary_virtual_base PARAMS ((tree, tree));
static void clone_constructors_and_destructors PARAMS ((tree));
static tree build_clone PARAMS ((tree, tree));
static void update_vtable_entry_for_fn PARAMS ((tree, tree, tree, tree *));
static tree copy_virtuals PARAMS ((tree));
static void build_ctor_vtbl_group PARAMS ((tree, tree));
static void build_vtt PARAMS ((tree));
static tree binfo_ctor_vtable PARAMS ((tree));
static tree *build_vtt_inits PARAMS ((tree, tree, tree *, tree *));
static tree dfs_build_secondary_vptr_vtt_inits PARAMS ((tree, void *));
static tree dfs_ctor_vtable_bases_queue_p PARAMS ((tree, void *data));
static tree dfs_fixup_binfo_vtbls PARAMS ((tree, void *));
static tree get_original_base PARAMS ((tree, tree));
static tree dfs_get_primary_binfo PARAMS ((tree, void*));
static int record_subobject_offset PARAMS ((tree, tree, splay_tree));
static int check_subobject_offset PARAMS ((tree, tree, splay_tree));
static int walk_subobject_offsets PARAMS ((tree, subobject_offset_fn,
tree, splay_tree, tree, int));
static void record_subobject_offsets PARAMS ((tree, tree, splay_tree, int));
static int layout_conflict_p PARAMS ((tree, tree, splay_tree, int));
static int splay_tree_compare_integer_csts PARAMS ((splay_tree_key k1,
splay_tree_key k2));
static void warn_about_ambiguous_bases PARAMS ((tree));
static bool type_requires_array_cookie PARAMS ((tree));
static bool contains_empty_class_p (tree);
static tree dfs_base_derived_from (tree, void *);
static bool base_derived_from (tree, tree);
static int empty_base_at_nonzero_offset_p (tree, tree, splay_tree);
static tree end_of_base (tree);
static tree get_vcall_index (tree, tree);
#define VTT_TOP_LEVEL_P(NODE) TREE_UNSIGNED (NODE)
#define VTT_MARKED_BINFO_P(NODE) TREE_USED (NODE)
#ifdef GATHER_STATISTICS
int n_vtables = 0;
int n_vtable_entries = 0;
int n_vtable_searches = 0;
int n_vtable_elems = 0;
int n_convert_harshness = 0;
int n_compute_conversion_costs = 0;
int n_build_method_call = 0;
int n_inner_fields_searched = 0;
#endif
extern int darwin_align_is_first_member_of_class;
tree
build_base_path (code, expr, binfo, nonnull)
enum tree_code code;
tree expr;
tree binfo;
int nonnull;
{
tree v_binfo = NULL_TREE;
tree d_binfo = NULL_TREE;
tree probe;
tree offset;
tree target_type;
tree null_test = NULL;
tree ptr_target_type;
int fixed_type_p;
int want_pointer = TREE_CODE (TREE_TYPE (expr)) == POINTER_TYPE;
if (expr == error_mark_node || binfo == error_mark_node || !binfo)
return error_mark_node;
for (probe = binfo; probe; probe = BINFO_INHERITANCE_CHAIN (probe))
{
d_binfo = probe;
if (!v_binfo && TREE_VIA_VIRTUAL (probe))
v_binfo = probe;
}
probe = TYPE_MAIN_VARIANT (TREE_TYPE (expr));
if (want_pointer)
probe = TYPE_MAIN_VARIANT (TREE_TYPE (probe));
my_friendly_assert (code == MINUS_EXPR
? same_type_p (BINFO_TYPE (binfo), probe)
: code == PLUS_EXPR
? same_type_p (BINFO_TYPE (d_binfo), probe)
: false, 20010723);
if (code == MINUS_EXPR && v_binfo)
{
error ("cannot convert from base `%T' to derived type `%T' via virtual base `%T'",
BINFO_TYPE (binfo), BINFO_TYPE (d_binfo), BINFO_TYPE (v_binfo));
return error_mark_node;
}
if (!want_pointer)
expr = build_unary_op (ADDR_EXPR, expr, 0);
fixed_type_p = resolves_to_fixed_type_p (expr, &nonnull);
if (fixed_type_p <= 0 && TREE_SIDE_EFFECTS (expr))
expr = save_expr (expr);
if (want_pointer && !nonnull)
null_test = build (EQ_EXPR, boolean_type_node, expr, integer_zero_node);
offset = BINFO_OFFSET (binfo);
if (v_binfo && fixed_type_p <= 0)
{
tree v_offset = build_vfield_ref (build_indirect_ref (expr, NULL),
TREE_TYPE (TREE_TYPE (expr)));
v_binfo = binfo_for_vbase (BINFO_TYPE (v_binfo), BINFO_TYPE (d_binfo));
v_offset = build (PLUS_EXPR, TREE_TYPE (v_offset),
v_offset, BINFO_VPTR_FIELD (v_binfo));
v_offset = build1 (NOP_EXPR,
build_pointer_type (ptrdiff_type_node),
v_offset);
v_offset = build_indirect_ref (v_offset, NULL);
TREE_CONSTANT (v_offset) = 1;
offset = cp_convert (ptrdiff_type_node,
size_diffop (offset, BINFO_OFFSET (v_binfo)));
if (!integer_zerop (offset))
v_offset = build (code, ptrdiff_type_node, v_offset, offset);
if (fixed_type_p < 0)
offset = build (COND_EXPR, ptrdiff_type_node,
build (EQ_EXPR, boolean_type_node,
current_in_charge_parm, integer_zero_node),
v_offset,
BINFO_OFFSET (binfo));
else
offset = v_offset;
}
target_type = code == PLUS_EXPR ? BINFO_TYPE (binfo) : BINFO_TYPE (d_binfo);
target_type = cp_build_qualified_type
(target_type, cp_type_quals (TREE_TYPE (TREE_TYPE (expr))));
ptr_target_type = build_pointer_type (target_type);
if (want_pointer)
target_type = ptr_target_type;
expr = build1 (NOP_EXPR, ptr_target_type, expr);
if (!integer_zerop (offset))
expr = build (code, ptr_target_type, expr, offset);
else
null_test = NULL;
if (!want_pointer)
expr = build_indirect_ref (expr, NULL);
if (null_test)
expr = build (COND_EXPR, target_type, null_test,
build1 (NOP_EXPR, target_type, integer_zero_node),
expr);
return expr;
}
tree
convert_to_base (tree object, tree type, bool check_access)
{
tree binfo;
binfo = lookup_base (TREE_TYPE (object), type,
check_access ? ba_check : ba_ignore,
NULL);
if (!binfo || binfo == error_mark_node)
return error_mark_node;
return build_base_path (PLUS_EXPR, object, binfo, 1);
}
static tree
build_vtable_entry_ref (array_ref, instance, idx)
tree array_ref, instance, idx;
{
tree i, i2, vtable, first_fn, basetype;
basetype = TREE_TYPE (instance);
if (TREE_CODE (basetype) == REFERENCE_TYPE)
basetype = TREE_TYPE (basetype);
vtable = get_vtbl_decl_for_binfo (TYPE_BINFO (basetype));
first_fn = TYPE_BINFO_VTABLE (basetype);
i = fold (build_array_ref (first_fn, idx));
i = fold (build_c_cast (ptrdiff_type_node,
build_unary_op (ADDR_EXPR, i, 0)));
i2 = fold (build_array_ref (vtable, build_int_2 (0,0)));
i2 = fold (build_c_cast (ptrdiff_type_node,
build_unary_op (ADDR_EXPR, i2, 0)));
i = fold (cp_build_binary_op (MINUS_EXPR, i, i2));
if (TREE_CODE (i) != INTEGER_CST)
abort ();
return build (VTABLE_REF, TREE_TYPE (array_ref), array_ref, vtable, i);
}
static tree
build_vtbl_ref_1 (instance, idx)
tree instance, idx;
{
tree aref;
tree vtbl = NULL_TREE;
int cdtorp = 0;
tree fixed_type = fixed_type_or_null (instance, NULL, &cdtorp);
tree basetype = TREE_TYPE (instance);
if (TREE_CODE (basetype) == REFERENCE_TYPE)
basetype = TREE_TYPE (basetype);
if (fixed_type && !cdtorp)
{
tree binfo = lookup_base (fixed_type, basetype,
ba_ignore|ba_quiet, NULL);
if (binfo)
vtbl = BINFO_VTABLE (binfo);
}
if (!vtbl)
{
vtbl = build_vfield_ref (instance, basetype);
}
assemble_external (vtbl);
#ifdef ADJUST_VTABLE_INDEX
ADJUST_VTABLE_INDEX (idx, vtbl);
#endif
aref = build_array_ref (vtbl, idx);
TREE_CONSTANT (aref) = 1;
return aref;
}
tree
build_vtbl_ref (instance, idx)
tree instance, idx;
{
tree aref = build_vtbl_ref_1 (instance, idx);
if (flag_vtable_gc)
aref = build_vtable_entry_ref (aref, instance, idx);
return aref;
}
tree
build_vfn_ref (instance, idx)
tree instance, idx;
{
tree aref = build_vtbl_ref_1 (instance, idx);
if (TARGET_VTABLE_USES_DESCRIPTORS)
aref = build1 (NOP_EXPR, TREE_TYPE (aref),
build_unary_op (ADDR_EXPR, aref, 1));
if (flag_vtable_gc)
aref = build_vtable_entry_ref (aref, instance, idx);
return aref;
}
tree
build_vfn_ref_using_vtable (basetype, vtbl, idx)
tree basetype, vtbl, idx;
{
tree aref;
assemble_external (vtbl);
if (flag_vtable_gc)
build_vtable_entry_ref (basetype, vtbl, idx);
#ifdef ADJUST_VTABLE_INDEX
ADJUST_VTABLE_INDEX (idx, vtbl);
#endif
aref = build_array_ref (vtbl, idx);
return aref;
}
static tree
get_vtable_name (type)
tree type;
{
return mangle_vtbl_for_type (type);
}
tree
get_vtt_name (type)
tree type;
{
return mangle_vtt_for_type (type);
}
static tree
build_vtable (class_type, name, vtable_type)
tree class_type;
tree name;
tree vtable_type;
{
tree decl;
decl = build_lang_decl (VAR_DECL, name, vtable_type);
SET_DECL_ASSEMBLER_NAME (decl, name);
DECL_CONTEXT (decl) = class_type;
DECL_ARTIFICIAL (decl) = 1;
TREE_STATIC (decl) = 1;
TREE_READONLY (decl) = 1;
DECL_VIRTUAL_P (decl) = 1;
DECL_ALIGN (decl) = TARGET_VTABLE_ENTRY_ALIGN;
import_export_vtable (decl, class_type, 0);
return decl;
}
tree
get_vtable_decl (type, complete)
tree type;
int complete;
{
tree decl;
if (CLASSTYPE_VTABLES (type))
return CLASSTYPE_VTABLES (type);
decl = build_vtable (type, get_vtable_name (type), void_type_node);
CLASSTYPE_VTABLES (type) = decl;
DECL_ALIGN (decl) = MAX (TYPE_ALIGN (double_type_node),
DECL_ALIGN (decl));
if (complete)
{
DECL_EXTERNAL (decl) = 1;
cp_finish_decl (decl, NULL_TREE, NULL_TREE, 0);
}
return decl;
}
static tree
copy_virtuals (binfo)
tree binfo;
{
tree copies;
tree t;
copies = copy_list (BINFO_VIRTUALS (binfo));
for (t = copies; t; t = TREE_CHAIN (t))
BV_VCALL_INDEX (t) = NULL_TREE;
return copies;
}
static int
build_primary_vtable (binfo, type)
tree binfo, type;
{
tree decl;
tree virtuals;
decl = get_vtable_decl (type, 0);
if (binfo)
{
if (BINFO_NEW_VTABLE_MARKED (binfo, type))
return 0;
virtuals = copy_virtuals (binfo);
TREE_TYPE (decl) = TREE_TYPE (get_vtbl_decl_for_binfo (binfo));
DECL_SIZE (decl) = TYPE_SIZE (TREE_TYPE (decl));
DECL_SIZE_UNIT (decl) = TYPE_SIZE_UNIT (TREE_TYPE (decl));
}
else
{
my_friendly_assert (TREE_CODE (TREE_TYPE (decl)) == VOID_TYPE,
20000118);
virtuals = NULL_TREE;
}
#ifdef GATHER_STATISTICS
n_vtables += 1;
n_vtable_elems += list_length (virtuals);
#endif
TYPE_BINFO_VTABLE (type) = decl;
TYPE_BINFO_VIRTUALS (type) = virtuals;
SET_BINFO_NEW_VTABLE_MARKED (TYPE_BINFO (type), type);
return 1;
}
static int
build_secondary_vtable (binfo, for_type)
tree binfo, for_type;
{
my_friendly_assert (binfo == CANONICAL_BINFO (binfo, for_type), 20010605);
if (BINFO_NEW_VTABLE_MARKED (binfo, for_type))
return 0;
SET_BINFO_NEW_VTABLE_MARKED (binfo, for_type);
BINFO_VIRTUALS (binfo) = copy_virtuals (binfo);
BINFO_VTABLE (binfo) = NULL_TREE;
return 1;
}
static int
make_new_vtable (t, binfo)
tree t;
tree binfo;
{
if (binfo == TYPE_BINFO (t))
return build_primary_vtable (TYPE_BINFO (DECL_CONTEXT (TYPE_VFIELD (t))),
t);
else
return build_secondary_vtable (binfo, t);
}
static void
modify_vtable_entry (t, binfo, fndecl, delta, virtuals)
tree t;
tree binfo;
tree fndecl;
tree delta;
tree *virtuals;
{
tree v;
v = *virtuals;
if (fndecl != BV_FN (v)
|| !tree_int_cst_equal (delta, BV_DELTA (v)))
{
tree base_fndecl;
if (make_new_vtable (t, binfo))
{
*virtuals = BINFO_VIRTUALS (binfo);
while (BV_FN (*virtuals) != BV_FN (v))
*virtuals = TREE_CHAIN (*virtuals);
v = *virtuals;
}
base_fndecl = BV_FN (v);
BV_DELTA (v) = delta;
BV_VCALL_INDEX (v) = NULL_TREE;
BV_FN (v) = fndecl;
}
}
void
add_method (type, method, error_p)
tree type;
tree method;
int error_p;
{
int using = (DECL_CONTEXT (method) != type);
int len;
int slot;
tree method_vec;
int template_conv_p = (TREE_CODE (method) == TEMPLATE_DECL
&& DECL_TEMPLATE_CONV_FN_P (method));
if (!CLASSTYPE_METHOD_VEC (type))
CLASSTYPE_METHOD_VEC (type) = make_tree_vec (8);
method_vec = CLASSTYPE_METHOD_VEC (type);
len = TREE_VEC_LENGTH (method_vec);
if (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (method))
slot = CLASSTYPE_CONSTRUCTOR_SLOT;
else if (DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (method))
slot = CLASSTYPE_DESTRUCTOR_SLOT;
else
{
int have_template_convs_p = 0;
for (slot = CLASSTYPE_FIRST_CONVERSION_SLOT; slot < len; ++slot)
{
tree m = TREE_VEC_ELT (method_vec, slot);
if (!m)
break;
m = OVL_CURRENT (m);
if (template_conv_p)
{
have_template_convs_p = (TREE_CODE (m) == TEMPLATE_DECL
&& DECL_TEMPLATE_CONV_FN_P (m));
if (!have_template_convs_p)
{
slot = len - 1;
if (TREE_VEC_ELT (method_vec, slot))
slot++;
}
break;
}
if (DECL_NAME (m) == DECL_NAME (method))
break;
}
if (slot == len)
{
int new_len;
tree new_vec;
if (!error_p)
new_len = 2 * len;
else
new_len = len + 1;
new_vec = make_tree_vec (new_len);
memcpy (&TREE_VEC_ELT (new_vec, 0), &TREE_VEC_ELT (method_vec, 0),
len * sizeof (tree));
len = new_len;
method_vec = CLASSTYPE_METHOD_VEC (type) = new_vec;
}
if (DECL_CONV_FN_P (method) && !TREE_VEC_ELT (method_vec, slot))
{
if (template_conv_p)
slot = CLASSTYPE_FIRST_CONVERSION_SLOT;
else
for (slot = CLASSTYPE_FIRST_CONVERSION_SLOT; slot < len; ++slot)
{
tree fn = TREE_VEC_ELT (method_vec, slot);
if (!fn)
break;
if (!DECL_CONV_FN_P (OVL_CURRENT (fn)))
break;
}
if (template_conv_p && have_template_convs_p)
;
else if (!TREE_VEC_ELT (method_vec, slot))
;
else
{
memmove (&TREE_VEC_ELT (method_vec, slot + 1),
&TREE_VEC_ELT (method_vec, slot),
(len - slot - 1) * sizeof (tree));
TREE_VEC_ELT (method_vec, slot) = NULL_TREE;
}
}
}
if (template_class_depth (type))
;
else
{
tree fns;
for (fns = TREE_VEC_ELT (method_vec, slot);
fns;
fns = OVL_NEXT (fns))
{
tree fn = OVL_CURRENT (fns);
tree parms1;
tree parms2;
bool same = 1;
if (TREE_CODE (fn) != TREE_CODE (method))
continue;
parms1 = TYPE_ARG_TYPES (TREE_TYPE (fn));
parms2 = TYPE_ARG_TYPES (TREE_TYPE (method));
if (! DECL_STATIC_FUNCTION_P (fn)
&& ! DECL_STATIC_FUNCTION_P (method)
&& (TYPE_QUALS (TREE_TYPE (TREE_VALUE (parms1)))
!= TYPE_QUALS (TREE_TYPE (TREE_VALUE (parms2)))))
same = 0;
if (TREE_CODE (fn) == TEMPLATE_DECL
&& !comp_template_parms (DECL_TEMPLATE_PARMS (fn),
DECL_TEMPLATE_PARMS (method)))
same = 0;
if (! DECL_STATIC_FUNCTION_P (fn))
parms1 = TREE_CHAIN (parms1);
if (! DECL_STATIC_FUNCTION_P (method))
parms2 = TREE_CHAIN (parms2);
if (same && compparms (parms1, parms2)
&& (!DECL_CONV_FN_P (fn)
|| same_type_p (TREE_TYPE (TREE_TYPE (fn)),
TREE_TYPE (TREE_TYPE (method)))))
{
if (using && DECL_CONTEXT (fn) == type)
return;
else
{
cp_error_at ("`%#D' and `%#D' cannot be overloaded",
method, fn, method);
return;
}
}
}
}
TREE_VEC_ELT (method_vec, slot)
= build_overload (method, TREE_VEC_ELT (method_vec, slot));
if (!DECL_CONSTRUCTOR_P (method)
&& !DECL_DESTRUCTOR_P (method))
push_class_level_binding (DECL_NAME (method),
TREE_VEC_ELT (method_vec, slot));
}
static tree
delete_duplicate_fields_1 (field, fields)
tree field, fields;
{
tree x;
tree prev = 0;
if (DECL_NAME (field) == 0)
{
if (! ANON_AGGR_TYPE_P (TREE_TYPE (field)))
return fields;
for (x = TYPE_FIELDS (TREE_TYPE (field)); x; x = TREE_CHAIN (x))
fields = delete_duplicate_fields_1 (x, fields);
return fields;
}
else
{
for (x = fields; x; prev = x, x = TREE_CHAIN (x))
{
if (DECL_NAME (x) == 0)
{
if (! ANON_AGGR_TYPE_P (TREE_TYPE (x)))
continue;
TYPE_FIELDS (TREE_TYPE (x))
= delete_duplicate_fields_1 (field, TYPE_FIELDS (TREE_TYPE (x)));
if (TYPE_FIELDS (TREE_TYPE (x)) == 0)
{
if (prev == 0)
fields = TREE_CHAIN (fields);
else
TREE_CHAIN (prev) = TREE_CHAIN (x);
}
}
else if (TREE_CODE (field) == USING_DECL)
;
else if (DECL_NAME (field) == DECL_NAME (x))
{
if (TREE_CODE (field) == CONST_DECL
&& TREE_CODE (x) == CONST_DECL)
cp_error_at ("duplicate enum value `%D'", x);
else if (TREE_CODE (field) == CONST_DECL
|| TREE_CODE (x) == CONST_DECL)
cp_error_at ("duplicate field `%D' (as enum and non-enum)",
x);
else if (DECL_DECLARES_TYPE_P (field)
&& DECL_DECLARES_TYPE_P (x))
{
if (same_type_p (TREE_TYPE (field), TREE_TYPE (x)))
continue;
cp_error_at ("duplicate nested type `%D'", x);
}
else if (DECL_DECLARES_TYPE_P (field)
|| DECL_DECLARES_TYPE_P (x))
{
if ((TREE_CODE (field) == TYPE_DECL
&& DECL_ARTIFICIAL (field))
|| (TREE_CODE (x) == TYPE_DECL
&& DECL_ARTIFICIAL (x)))
continue;
cp_error_at ("duplicate field `%D' (as type and non-type)",
x);
}
else
cp_error_at ("duplicate member `%D'", x);
if (prev == 0)
fields = TREE_CHAIN (fields);
else
TREE_CHAIN (prev) = TREE_CHAIN (x);
}
}
}
return fields;
}
static void
delete_duplicate_fields (fields)
tree fields;
{
tree x;
for (x = fields; x && TREE_CHAIN (x); x = TREE_CHAIN (x))
TREE_CHAIN (x) = delete_duplicate_fields_1 (x, TREE_CHAIN (x));
}
static int
alter_access (t, fdecl, access)
tree t;
tree fdecl;
tree access;
{
tree elem;
if (!DECL_LANG_SPECIFIC (fdecl))
retrofit_lang_decl (fdecl);
if (DECL_DISCRIMINATOR_P (fdecl))
abort ();
elem = purpose_member (t, DECL_ACCESS (fdecl));
if (elem)
{
if (TREE_VALUE (elem) != access)
{
if (TREE_CODE (TREE_TYPE (fdecl)) == FUNCTION_DECL)
cp_error_at ("conflicting access specifications for method `%D', ignored", TREE_TYPE (fdecl));
else
error ("conflicting access specifications for field `%s', ignored",
IDENTIFIER_POINTER (DECL_NAME (fdecl)));
}
else
{
;
}
}
else
{
enforce_access (t, fdecl);
DECL_ACCESS (fdecl) = tree_cons (t, access, DECL_ACCESS (fdecl));
return 1;
}
return 0;
}
static void
handle_using_decl (using_decl, t)
tree using_decl;
tree t;
{
tree ctype = DECL_INITIAL (using_decl);
tree name = DECL_NAME (using_decl);
tree access
= TREE_PRIVATE (using_decl) ? access_private_node
: TREE_PROTECTED (using_decl) ? access_protected_node
: access_public_node;
tree fdecl, binfo;
tree flist = NULL_TREE;
tree old_value;
binfo = lookup_base (t, ctype, ba_any, NULL);
if (! binfo)
{
error_not_base_type (t, ctype);
return;
}
if (constructor_name_p (name, ctype))
{
cp_error_at ("`%D' names constructor", using_decl);
return;
}
if (constructor_name_p (name, t))
{
cp_error_at ("`%D' invalid in `%T'", using_decl, t);
return;
}
fdecl = lookup_member (binfo, name, 0, 0);
if (!fdecl)
{
cp_error_at ("no members matching `%D' in `%#T'", using_decl, ctype);
return;
}
if (BASELINK_P (fdecl))
fdecl = BASELINK_FUNCTIONS (fdecl);
old_value = IDENTIFIER_CLASS_VALUE (name);
if (old_value)
{
if (is_overloaded_fn (old_value))
old_value = OVL_CURRENT (old_value);
if (DECL_P (old_value) && DECL_CONTEXT (old_value) == t)
;
else
old_value = NULL_TREE;
}
if (is_overloaded_fn (fdecl))
flist = fdecl;
if (! old_value)
;
else if (is_overloaded_fn (old_value))
{
if (flist)
;
else
{
cp_error_at ("`%D' invalid in `%#T'", using_decl, t);
cp_error_at (" because of local method `%#D' with same name",
OVL_CURRENT (old_value));
return;
}
}
else if (!DECL_ARTIFICIAL (old_value))
{
cp_error_at ("`%D' invalid in `%#T'", using_decl, t);
cp_error_at (" because of local member `%#D' with same name", old_value);
return;
}
if (flist)
for (; flist; flist = OVL_NEXT (flist))
{
add_method (t, OVL_CURRENT (flist), 0);
alter_access (t, OVL_CURRENT (flist), access);
}
else
alter_access (t, fdecl, access);
}
static void
check_bases (t, cant_have_default_ctor_p, cant_have_const_ctor_p,
no_const_asn_ref_p)
tree t;
int *cant_have_default_ctor_p;
int *cant_have_const_ctor_p;
int *no_const_asn_ref_p;
{
int n_baseclasses;
int i;
int seen_non_virtual_nearly_empty_base_p;
tree binfos;
binfos = TYPE_BINFO_BASETYPES (t);
n_baseclasses = CLASSTYPE_N_BASECLASSES (t);
seen_non_virtual_nearly_empty_base_p = 0;
CLASSTYPE_NON_AGGREGATE (t) |= (n_baseclasses != 0);
for (i = 0; i < n_baseclasses; ++i)
{
tree base_binfo;
tree basetype;
base_binfo = TREE_VEC_ELT (binfos, i);
basetype = TREE_TYPE (base_binfo);
if (!COMPLETE_TYPE_P (basetype))
{
int j;
if (i == n_baseclasses-1)
TREE_VEC_ELT (binfos, i) = NULL_TREE;
TREE_VEC_LENGTH (binfos) -= 1;
n_baseclasses -= 1;
for (j = i; j+1 < n_baseclasses; j++)
TREE_VEC_ELT (binfos, j) = TREE_VEC_ELT (binfos, j+1);
continue;
}
if (warn_ecpp && ! TYPE_POLYMORPHIC_P (basetype)
&& TYPE_HAS_DESTRUCTOR (basetype))
warning ("base class `%#T' has a non-virtual destructor",
basetype);
if (! TYPE_HAS_CONST_INIT_REF (basetype))
*cant_have_const_ctor_p = 1;
if (TYPE_HAS_ASSIGN_REF (basetype)
&& !TYPE_HAS_CONST_ASSIGN_REF (basetype))
*no_const_asn_ref_p = 1;
if (TYPE_HAS_CONSTRUCTOR (basetype)
&& ! TYPE_HAS_DEFAULT_CONSTRUCTOR (basetype))
{
*cant_have_default_ctor_p = 1;
if (! TYPE_HAS_CONSTRUCTOR (t))
pedwarn ("base `%T' with only non-default constructor in class without a constructor",
basetype);
}
if (TREE_VIA_VIRTUAL (base_binfo))
;
else if (CLASSTYPE_NEARLY_EMPTY_P (basetype))
{
if (seen_non_virtual_nearly_empty_base_p)
CLASSTYPE_NEARLY_EMPTY_P (t) = 0;
else
seen_non_virtual_nearly_empty_base_p = 1;
}
else if (!is_empty_class (basetype))
CLASSTYPE_NEARLY_EMPTY_P (t) = 0;
TYPE_NEEDS_CONSTRUCTING (t) |= TYPE_NEEDS_CONSTRUCTING (basetype);
TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)
|= TYPE_HAS_NONTRIVIAL_DESTRUCTOR (basetype);
TYPE_HAS_COMPLEX_ASSIGN_REF (t)
|= TYPE_HAS_COMPLEX_ASSIGN_REF (basetype);
TYPE_HAS_COMPLEX_INIT_REF (t) |= TYPE_HAS_COMPLEX_INIT_REF (basetype);
TYPE_OVERLOADS_CALL_EXPR (t) |= TYPE_OVERLOADS_CALL_EXPR (basetype);
TYPE_OVERLOADS_ARRAY_REF (t) |= TYPE_OVERLOADS_ARRAY_REF (basetype);
TYPE_OVERLOADS_ARROW (t) |= TYPE_OVERLOADS_ARROW (basetype);
TYPE_POLYMORPHIC_P (t) |= TYPE_POLYMORPHIC_P (basetype);
CLASSTYPE_CONTAINS_EMPTY_CLASS_P (t)
|= CLASSTYPE_CONTAINS_EMPTY_CLASS_P (basetype);
}
}
static void
force_canonical_binfo_r (to, from, type, mappings)
tree to;
tree from;
tree type;
tree mappings;
{
int i, n_baseclasses = BINFO_N_BASETYPES (from);
my_friendly_assert (to != from, 20010905);
BINFO_INDIRECT_PRIMARY_P (to)
= BINFO_INDIRECT_PRIMARY_P (from);
BINFO_INDIRECT_PRIMARY_P (from) = 0;
BINFO_UNSHARED_MARKED (to) = BINFO_UNSHARED_MARKED (from);
BINFO_UNSHARED_MARKED (from) = 0;
BINFO_LOST_PRIMARY_P (to) = BINFO_LOST_PRIMARY_P (from);
BINFO_LOST_PRIMARY_P (from) = 0;
if (BINFO_PRIMARY_P (from))
{
tree primary = BINFO_PRIMARY_BASE_OF (from);
tree assoc;
assoc = purpose_member (primary, mappings);
if (assoc)
primary = TREE_VALUE (assoc);
BINFO_PRIMARY_BASE_OF (to) = primary;
BINFO_PRIMARY_BASE_OF (from) = NULL_TREE;
}
my_friendly_assert (same_type_p (BINFO_TYPE (to), BINFO_TYPE (from)),
20010104);
mappings = tree_cons (from, to, mappings);
if (CLASSTYPE_HAS_PRIMARY_BASE_P (BINFO_TYPE (from))
&& TREE_VIA_VIRTUAL (CLASSTYPE_PRIMARY_BINFO (BINFO_TYPE (from))))
{
tree from_primary = get_primary_binfo (from);
if (BINFO_PRIMARY_BASE_OF (from_primary) == from)
force_canonical_binfo (get_primary_binfo (to), from_primary,
type, mappings);
}
for (i = 0; i != n_baseclasses; i++)
{
tree from_binfo = BINFO_BASETYPE (from, i);
tree to_binfo = BINFO_BASETYPE (to, i);
if (TREE_VIA_VIRTUAL (from_binfo))
{
if (BINFO_PRIMARY_P (from_binfo) &&
purpose_member (BINFO_PRIMARY_BASE_OF (from_binfo), mappings))
force_canonical_binfo (to_binfo, from_binfo, type, mappings);
}
else
force_canonical_binfo_r (to_binfo, from_binfo, type, mappings);
}
}
static void
force_canonical_binfo (to, from, type, mappings)
tree to;
tree from;
tree type;
tree mappings;
{
tree assoc = purpose_member (BINFO_TYPE (to),
CLASSTYPE_VBASECLASSES (type));
if (TREE_VALUE (assoc) != to)
{
TREE_VALUE (assoc) = to;
force_canonical_binfo_r (to, from, type, mappings);
}
}
static tree
mark_primary_virtual_base (base_binfo, type)
tree base_binfo;
tree type;
{
tree shared_binfo = binfo_for_vbase (BINFO_TYPE (base_binfo), type);
if (BINFO_PRIMARY_P (shared_binfo))
{
return NULL_TREE;
}
if (base_binfo != shared_binfo)
force_canonical_binfo (base_binfo, shared_binfo, type, NULL);
return base_binfo;
}
static tree
dfs_unshared_virtual_bases (binfo, data)
tree binfo;
void *data;
{
tree t = (tree) data;
if (!BINFO_UNSHARED_MARKED (binfo)
&& CLASSTYPE_HAS_PRIMARY_BASE_P (BINFO_TYPE (binfo)))
{
tree vbase;
tree unshared_base;
for (vbase = binfo; !TREE_VIA_VIRTUAL (vbase);
vbase = BINFO_INHERITANCE_CHAIN (vbase))
continue;
unshared_base = get_original_base (binfo,
binfo_for_vbase (BINFO_TYPE (vbase),
t));
my_friendly_assert (unshared_base != binfo, 20010612);
BINFO_LOST_PRIMARY_P (binfo) = BINFO_LOST_PRIMARY_P (unshared_base);
if (!BINFO_LOST_PRIMARY_P (binfo))
BINFO_PRIMARY_BASE_OF (get_primary_binfo (binfo)) = binfo;
}
if (binfo != TYPE_BINFO (t))
BINFO_VTABLE (binfo) = NULL_TREE;
if (BINFO_PRIMARY_P (binfo) && TREE_VIA_VIRTUAL (binfo) &&
binfo_for_vbase (BINFO_TYPE (binfo), t) == binfo)
{
tree delta = size_diffop (BINFO_OFFSET (BINFO_PRIMARY_BASE_OF (binfo)),
BINFO_OFFSET (binfo));
if (!integer_zerop (delta))
propagate_binfo_offsets (binfo, delta, t);
}
BINFO_UNSHARED_MARKED (binfo) = 0;
return NULL;
}
static void
mark_primary_bases (type)
tree type;
{
tree binfo;
for (binfo = TYPE_BINFO (type); binfo; binfo = TREE_CHAIN (binfo))
{
tree base_binfo;
if (!CLASSTYPE_HAS_PRIMARY_BASE_P (BINFO_TYPE (binfo)))
continue;
base_binfo = get_primary_binfo (binfo);
if (TREE_VIA_VIRTUAL (base_binfo))
base_binfo = mark_primary_virtual_base (base_binfo, type);
if (base_binfo)
BINFO_PRIMARY_BASE_OF (base_binfo) = binfo;
else
BINFO_LOST_PRIMARY_P (binfo) = 1;
BINFO_UNSHARED_MARKED (binfo) = 1;
}
dfs_walk (TYPE_BINFO (type), dfs_unshared_virtual_bases, NULL, type);
}
static void
set_primary_base (t, binfo)
tree t;
tree binfo;
{
tree basetype;
CLASSTYPE_PRIMARY_BINFO (t) = binfo;
basetype = BINFO_TYPE (binfo);
TYPE_BINFO_VTABLE (t) = TYPE_BINFO_VTABLE (basetype);
TYPE_BINFO_VIRTUALS (t) = TYPE_BINFO_VIRTUALS (basetype);
TYPE_VFIELD (t) = TYPE_VFIELD (basetype);
}
static void
determine_primary_base (t)
tree t;
{
int i, n_baseclasses = CLASSTYPE_N_BASECLASSES (t);
tree vbases;
tree type_binfo;
if (n_baseclasses == 0)
return;
type_binfo = TYPE_BINFO (t);
for (i = 0; i < n_baseclasses; i++)
{
tree base_binfo = BINFO_BASETYPE (type_binfo, i);
tree basetype = BINFO_TYPE (base_binfo);
if (TYPE_CONTAINS_VPTR_P (basetype))
{
if (TREE_VIA_VIRTUAL (base_binfo))
continue;
if (!CLASSTYPE_HAS_PRIMARY_BASE_P (t))
{
set_primary_base (t, base_binfo);
CLASSTYPE_VFIELDS (t) = copy_list (CLASSTYPE_VFIELDS (basetype));
}
else
{
tree vfields;
for (vfields = CLASSTYPE_VFIELDS (basetype);
vfields;
vfields = TREE_CHAIN (vfields))
if (VF_BINFO_VALUE (vfields) == NULL_TREE
|| ! TREE_VIA_VIRTUAL (VF_BINFO_VALUE (vfields)))
CLASSTYPE_VFIELDS (t)
= tree_cons (base_binfo,
VF_BASETYPE_VALUE (vfields),
CLASSTYPE_VFIELDS (t));
}
}
}
if (!TYPE_VFIELD (t))
CLASSTYPE_PRIMARY_BINFO (t) = NULL_TREE;
for (vbases = CLASSTYPE_VBASECLASSES (t);
vbases;
vbases = TREE_CHAIN (vbases))
{
tree vbase_binfo = TREE_VALUE (vbases);
for (i = 0; i < n_baseclasses; ++i)
{
tree basetype = TYPE_BINFO_BASETYPE (t, i);
tree v;
for (v = CLASSTYPE_VBASECLASSES (basetype);
v;
v = TREE_CHAIN (v))
{
tree base_vbase = TREE_VALUE (v);
if (BINFO_PRIMARY_P (base_vbase)
&& same_type_p (BINFO_TYPE (base_vbase),
BINFO_TYPE (vbase_binfo)))
{
BINFO_INDIRECT_PRIMARY_P (vbase_binfo) = 1;
break;
}
}
if (BINFO_INDIRECT_PRIMARY_P (vbase_binfo))
break;
}
}
if (!CLASSTYPE_HAS_PRIMARY_BASE_P (t))
{
tree candidate = NULL_TREE;
tree base_binfo;
for (base_binfo = TYPE_BINFO (t);
base_binfo;
base_binfo = TREE_CHAIN (base_binfo))
{
tree basetype = BINFO_TYPE (base_binfo);
if (TREE_VIA_VIRTUAL (base_binfo)
&& CLASSTYPE_NEARLY_EMPTY_P (basetype))
{
if (!BINFO_INDIRECT_PRIMARY_P (base_binfo))
{
candidate = base_binfo;
break;
}
if (!candidate)
candidate = base_binfo;
}
}
if (candidate)
{
set_primary_base (t, candidate);
CLASSTYPE_VFIELDS (t)
= copy_list (CLASSTYPE_VFIELDS (BINFO_TYPE (candidate)));
}
}
mark_primary_bases (t);
}
static void
finish_struct_bits (t)
tree t;
{
int i, n_baseclasses = CLASSTYPE_N_BASECLASSES (t);
tree variants = TYPE_NEXT_VARIANT (t);
while (variants)
{
TYPE_HAS_CONSTRUCTOR (variants) = TYPE_HAS_CONSTRUCTOR (t);
TYPE_HAS_DESTRUCTOR (variants) = TYPE_HAS_DESTRUCTOR (t);
TYPE_NEEDS_CONSTRUCTING (variants) = TYPE_NEEDS_CONSTRUCTING (t);
TYPE_HAS_NONTRIVIAL_DESTRUCTOR (variants)
= TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t);
TYPE_BASE_CONVS_MAY_REQUIRE_CODE_P (variants)
= TYPE_BASE_CONVS_MAY_REQUIRE_CODE_P (t);
TYPE_POLYMORPHIC_P (variants) = TYPE_POLYMORPHIC_P (t);
TYPE_USES_VIRTUAL_BASECLASSES (variants) = TYPE_USES_VIRTUAL_BASECLASSES (t);
TYPE_MIN_VALUE (variants) = TYPE_MIN_VALUE (t);
TYPE_MAX_VALUE (variants) = TYPE_MAX_VALUE (t);
TYPE_FIELDS (variants) = TYPE_FIELDS (t);
TYPE_SIZE (variants) = TYPE_SIZE (t);
TYPE_SIZE_UNIT (variants) = TYPE_SIZE_UNIT (t);
variants = TYPE_NEXT_VARIANT (variants);
}
if (n_baseclasses && TYPE_POLYMORPHIC_P (t))
get_pure_virtuals (t);
if (n_baseclasses)
{
tree binfo = TYPE_BINFO (t);
tree binfos = BINFO_BASETYPES (binfo);
tree basetype;
for (i = n_baseclasses-1; i >= 0; i--)
{
basetype = BINFO_TYPE (TREE_VEC_ELT (binfos, i));
TYPE_HAS_CONVERSION (t) |= TYPE_HAS_CONVERSION (basetype);
}
}
if (! TYPE_HAS_TRIVIAL_INIT_REF (t) || TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t))
{
tree variants;
DECL_MODE (TYPE_MAIN_DECL (t)) = BLKmode;
for (variants = t; variants; variants = TYPE_NEXT_VARIANT (variants))
{
TYPE_MODE (variants) = BLKmode;
TREE_ADDRESSABLE (variants) = 1;
}
}
}
static void
maybe_warn_about_overly_private_class (t)
tree t;
{
int has_member_fn = 0;
int has_nonprivate_method = 0;
tree fn;
if (!warn_ctor_dtor_privacy
|| (CLASSTYPE_FRIEND_CLASSES (t)
|| DECL_FRIENDLIST (TYPE_MAIN_DECL (t)))
|| CLASSTYPE_TEMPLATE_INSTANTIATION (t))
return;
for (fn = TYPE_METHODS (t); fn; fn = TREE_CHAIN (fn))
if (!DECL_ARTIFICIAL (fn))
{
if (!TREE_PRIVATE (fn))
{
if (DECL_STATIC_FUNCTION_P (fn))
return;
has_nonprivate_method = 1;
}
else if (!DECL_CONSTRUCTOR_P (fn) && !DECL_DESTRUCTOR_P (fn))
has_member_fn = 1;
}
if (!has_nonprivate_method && has_member_fn)
{
int i;
tree binfos = BINFO_BASETYPES (TYPE_BINFO (t));
for (i = 0; i < CLASSTYPE_N_BASECLASSES (t); i++)
if (TREE_VIA_PUBLIC (TREE_VEC_ELT (binfos, i))
|| TREE_VIA_PROTECTED (TREE_VEC_ELT (binfos, i)))
{
has_nonprivate_method = 1;
break;
}
if (!has_nonprivate_method)
{
warning ("all member functions in class `%T' are private", t);
return;
}
}
if (TYPE_HAS_DESTRUCTOR (t))
{
tree dtor = TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (t), 1);
if (TREE_PRIVATE (dtor))
{
warning ("`%#T' only defines a private destructor and has no friends",
t);
return;
}
}
if (TYPE_HAS_CONSTRUCTOR (t))
{
int nonprivate_ctor = 0;
if (!TYPE_HAS_INIT_REF (t))
nonprivate_ctor = 1;
else
for (fn = TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (t), 0);
fn;
fn = OVL_NEXT (fn))
{
tree ctor = OVL_CURRENT (fn);
if (! TREE_PRIVATE (ctor))
{
nonprivate_ctor = 1;
break;
}
}
if (nonprivate_ctor == 0)
{
warning ("`%#T' only defines private constructors and has no friends",
t);
return;
}
}
}
static int
field_decl_cmp (x_p, y_p)
const void *x_p, *y_p;
{
const tree *const x = x_p;
const tree *const y = y_p;
if (DECL_NAME (*x) == DECL_NAME (*y))
return DECL_DECLARES_TYPE_P (*y) - DECL_DECLARES_TYPE_P (*x);
if (DECL_NAME (*x) == NULL_TREE)
return -1;
if (DECL_NAME (*y) == NULL_TREE)
return 1;
if (DECL_NAME (*x) < DECL_NAME (*y))
return -1;
return 1;
}
static struct {
gt_pointer_operator new_value;
void *cookie;
} resort_data;
static int
resort_field_decl_cmp (x_p, y_p)
const void *x_p, *y_p;
{
const tree *const x = x_p;
const tree *const y = y_p;
if (DECL_NAME (*x) == DECL_NAME (*y))
return DECL_DECLARES_TYPE_P (*y) - DECL_DECLARES_TYPE_P (*x);
if (DECL_NAME (*x) == NULL_TREE)
return -1;
if (DECL_NAME (*y) == NULL_TREE)
return 1;
{
tree d1 = DECL_NAME (*x);
tree d2 = DECL_NAME (*y);
resort_data.new_value (&d1, resort_data.cookie);
resort_data.new_value (&d2, resort_data.cookie);
if (d1 < d2)
return -1;
}
return 1;
}
void
resort_sorted_fields (obj, orig_obj, new_value, cookie)
void *obj;
void *orig_obj;
gt_pointer_operator new_value;
void *cookie;
{
tree sf = obj;
resort_data.new_value = new_value;
resort_data.cookie = cookie;
qsort (&TREE_VEC_ELT (sf, 0), TREE_VEC_LENGTH (sf), sizeof (tree),
resort_field_decl_cmp);
}
static int
method_name_cmp (m1_p, m2_p)
const void *m1_p, *m2_p;
{
const tree *const m1 = m1_p;
const tree *const m2 = m2_p;
if (*m1 == NULL_TREE && *m2 == NULL_TREE)
return 0;
if (*m1 == NULL_TREE)
return -1;
if (*m2 == NULL_TREE)
return 1;
if (DECL_NAME (OVL_CURRENT (*m1)) < DECL_NAME (OVL_CURRENT (*m2)))
return -1;
return 1;
}
static int
resort_method_name_cmp (m1_p, m2_p)
const void *m1_p, *m2_p;
{
const tree *const m1 = m1_p;
const tree *const m2 = m2_p;
if (*m1 == NULL_TREE && *m2 == NULL_TREE)
return 0;
if (*m1 == NULL_TREE)
return -1;
if (*m2 == NULL_TREE)
return 1;
{
tree d1 = DECL_NAME (OVL_CURRENT (*m1));
tree d2 = DECL_NAME (OVL_CURRENT (*m2));
resort_data.new_value (&d1, resort_data.cookie);
resort_data.new_value (&d2, resort_data.cookie);
if (d1 < d2)
return -1;
}
return 1;
}
void
resort_type_method_vec (obj, orig_obj, new_value, cookie)
void *obj;
void *orig_obj;
gt_pointer_operator new_value;
void *cookie;
{
tree method_vec = obj;
int len = TREE_VEC_LENGTH (method_vec);
int slot;
for (slot = 2; slot < len; ++slot)
{
tree fn = TREE_VEC_ELT (method_vec, slot);
if (!DECL_CONV_FN_P (OVL_CURRENT (fn)))
break;
}
if (len - slot > 1)
{
resort_data.new_value = new_value;
resort_data.cookie = cookie;
qsort (&TREE_VEC_ELT (method_vec, slot), len - slot, sizeof (tree),
resort_method_name_cmp);
}
}
static void
finish_struct_methods (t)
tree t;
{
tree fn_fields;
tree method_vec;
int slot, len;
if (!TYPE_METHODS (t))
{
TYPE_HAS_CONSTRUCTOR (t) = 0;
TYPE_HAS_DESTRUCTOR (t) = 0;
CLASSTYPE_METHOD_VEC (t) = NULL_TREE;
return;
}
method_vec = CLASSTYPE_METHOD_VEC (t);
my_friendly_assert (method_vec != NULL_TREE, 19991215);
len = TREE_VEC_LENGTH (method_vec);
for (fn_fields = TYPE_METHODS (t); fn_fields;
fn_fields = TREE_CHAIN (fn_fields))
DECL_IN_AGGR_P (fn_fields) = 0;
if (TYPE_HAS_DESTRUCTOR (t) && !CLASSTYPE_DESTRUCTORS (t))
TYPE_HAS_DESTRUCTOR (t) = 0;
maybe_warn_about_overly_private_class (t);
while (len > 2 && TREE_VEC_ELT (method_vec, len-1) == NULL_TREE)
len--;
TREE_VEC_LENGTH (method_vec) = len;
for (slot = 2; slot < len; ++slot)
{
tree fn = TREE_VEC_ELT (method_vec, slot);
if (!DECL_CONV_FN_P (OVL_CURRENT (fn)))
break;
}
if (len - slot > 1)
qsort (&TREE_VEC_ELT (method_vec, slot), len-slot, sizeof (tree),
method_name_cmp);
}
void
duplicate_tag_error (t)
tree t;
{
error ("redefinition of `%#T'", t);
cp_error_at ("previous definition of `%#T'", t);
if (CLASSTYPE_METHOD_VEC (t))
{
tree method_vec = CLASSTYPE_METHOD_VEC (t);
int i, len = TREE_VEC_LENGTH (method_vec);
for (i = 0; i < len; i++)
{
tree unchain = TREE_VEC_ELT (method_vec, i);
while (unchain != NULL_TREE)
{
TREE_CHAIN (OVL_CURRENT (unchain)) = NULL_TREE;
unchain = OVL_NEXT (unchain);
}
}
}
if (TYPE_LANG_SPECIFIC (t))
{
tree binfo = TYPE_BINFO (t);
int interface_only = CLASSTYPE_INTERFACE_ONLY (t);
int interface_unknown = CLASSTYPE_INTERFACE_UNKNOWN (t);
tree template_info = CLASSTYPE_TEMPLATE_INFO (t);
int use_template = CLASSTYPE_USE_TEMPLATE (t);
memset ((char *) TYPE_LANG_SPECIFIC (t), 0, sizeof (struct lang_type));
BINFO_BASETYPES(binfo) = NULL_TREE;
TYPE_LANG_SPECIFIC (t)->u.h.is_lang_type_class = 1;
TYPE_BINFO (t) = binfo;
CLASSTYPE_INTERFACE_ONLY (t) = interface_only;
SET_CLASSTYPE_INTERFACE_UNKNOWN_X (t, interface_unknown);
TYPE_REDEFINED (t) = 1;
CLASSTYPE_TEMPLATE_INFO (t) = template_info;
CLASSTYPE_USE_TEMPLATE (t) = use_template;
CLASSTYPE_DECL_LIST (t) = NULL_TREE;
}
TYPE_SIZE (t) = NULL_TREE;
TYPE_MODE (t) = VOIDmode;
TYPE_FIELDS (t) = NULL_TREE;
TYPE_METHODS (t) = NULL_TREE;
TYPE_VFIELD (t) = NULL_TREE;
TYPE_CONTEXT (t) = NULL_TREE;
TYPE_LANG_FLAG_0 (t) = 0;
TYPE_LANG_FLAG_1 (t) = 0;
TYPE_LANG_FLAG_2 (t) = 0;
TYPE_LANG_FLAG_3 (t) = 0;
TYPE_LANG_FLAG_4 (t) = 0;
TYPE_LANG_FLAG_5 (t) = 0;
TYPE_LANG_FLAG_6 (t) = 0;
SET_IS_AGGR_TYPE (t, 1);
}
static void
layout_vtable_decl (binfo, n)
tree binfo;
int n;
{
tree atype;
tree vtable;
int n_entries;
n_entries = n;
if (flag_terminated_vtables || flag_indirect_virtual_calls)
n_entries += 1;
atype = build_cplus_array_type (vtable_entry_type,
build_index_type (size_int (n_entries - 1)));
layout_type (atype);
vtable = get_vtbl_decl_for_binfo (binfo);
if (!same_type_p (TREE_TYPE (vtable), atype))
{
TREE_TYPE (vtable) = atype;
DECL_SIZE (vtable) = DECL_SIZE_UNIT (vtable) = NULL_TREE;
layout_decl (vtable, 0);
DECL_ALIGN (vtable) = MAX (TYPE_ALIGN (double_type_node),
DECL_ALIGN (vtable));
}
}
int
same_signature_p (fndecl, base_fndecl)
tree fndecl, base_fndecl;
{
if (DECL_DESTRUCTOR_P (base_fndecl) && DECL_DESTRUCTOR_P (fndecl)
&& special_function_p (base_fndecl) == special_function_p (fndecl))
return 1;
if (DECL_DESTRUCTOR_P (base_fndecl) || DECL_DESTRUCTOR_P (fndecl))
return 0;
if (DECL_NAME (fndecl) == DECL_NAME (base_fndecl))
{
tree types, base_types;
types = TYPE_ARG_TYPES (TREE_TYPE (fndecl));
base_types = TYPE_ARG_TYPES (TREE_TYPE (base_fndecl));
if ((TYPE_QUALS (TREE_TYPE (TREE_VALUE (base_types)))
== TYPE_QUALS (TREE_TYPE (TREE_VALUE (types))))
&& compparms (TREE_CHAIN (base_types), TREE_CHAIN (types)))
return 1;
}
return 0;
}
static tree
dfs_base_derived_from (tree binfo, void *data)
{
tree base = (tree) data;
if (same_type_p (TREE_TYPE (base), TREE_TYPE (binfo))
&& tree_int_cst_equal (BINFO_OFFSET (base), BINFO_OFFSET (binfo)))
return error_mark_node;
return NULL_TREE;
}
static bool
base_derived_from (tree derived, tree base)
{
return dfs_walk (derived, dfs_base_derived_from, NULL, base) != NULL_TREE;
}
typedef struct find_final_overrider_data_s {
tree fn;
tree declaring_base;
tree most_derived_type;
tree candidates;
} find_final_overrider_data;
static tree
dfs_find_final_overrider (binfo, data)
tree binfo;
void *data;
{
find_final_overrider_data *ffod = (find_final_overrider_data *) data;
if (same_type_p (BINFO_TYPE (binfo),
BINFO_TYPE (ffod->declaring_base))
&& tree_int_cst_equal (BINFO_OFFSET (binfo),
BINFO_OFFSET (ffod->declaring_base)))
{
tree path;
tree method;
method = NULL_TREE;
path = reverse_path (binfo);
while (!same_type_p (BINFO_TYPE (TREE_VALUE (path)),
ffod->most_derived_type))
path = TREE_CHAIN (path);
while (path)
{
method = look_for_overrides_here (BINFO_TYPE (TREE_VALUE (path)),
ffod->fn);
if (method)
{
path = TREE_VALUE (path);
break;
}
path = TREE_CHAIN (path);
}
if (path)
{
tree *candidate;
candidate = &ffod->candidates;
while (*candidate)
{
if (base_derived_from (TREE_VALUE (*candidate), path))
return NULL_TREE;
if (base_derived_from (path, TREE_VALUE (*candidate)))
*candidate = TREE_CHAIN (*candidate);
else
candidate = &TREE_CHAIN (*candidate);
}
ffod->candidates = tree_cons (method, path, ffod->candidates);
}
}
return NULL_TREE;
}
static tree
find_final_overrider (derived, binfo, fn)
tree derived;
tree binfo;
tree fn;
{
find_final_overrider_data ffod;
ffod.fn = fn;
ffod.declaring_base = binfo;
ffod.most_derived_type = BINFO_TYPE (derived);
ffod.candidates = NULL_TREE;
dfs_walk (derived,
dfs_find_final_overrider,
NULL,
&ffod);
if (!ffod.candidates || TREE_CHAIN (ffod.candidates))
{
error ("no unique final overrider for `%D' in `%T'", fn,
BINFO_TYPE (derived));
return error_mark_node;
}
return ffod.candidates;
}
static tree
get_vcall_index (tree fn, tree type)
{
tree v;
for (v = CLASSTYPE_VCALL_INDICES (type); v; v = TREE_CHAIN (v))
if ((DECL_DESTRUCTOR_P (fn) && DECL_DESTRUCTOR_P (TREE_PURPOSE (v)))
|| same_signature_p (fn, TREE_PURPOSE (v)))
break;
my_friendly_assert (v, 20021103);
return TREE_VALUE (v);
}
static void
update_vtable_entry_for_fn (t, binfo, fn, virtuals)
tree t;
tree binfo;
tree fn;
tree *virtuals;
{
tree b;
tree overrider;
tree delta;
tree virtual_base;
tree first_defn;
bool lost = false;
for (b = binfo; ; b = get_primary_binfo (b))
{
if (look_for_overrides_here (BINFO_TYPE (b), fn))
break;
if (BINFO_LOST_PRIMARY_P (b))
lost = true;
}
first_defn = b;
overrider = find_final_overrider (TYPE_BINFO (t), b, fn);
if (overrider == error_mark_node)
return;
check_final_overrider (TREE_PURPOSE (overrider), fn);
virtual_base = NULL_TREE;
for (; b; b = BINFO_INHERITANCE_CHAIN (b))
{
if (same_type_p (BINFO_TYPE (b),
BINFO_TYPE (TREE_VALUE (overrider))))
break;
if (!virtual_base && TREE_VIA_VIRTUAL (b))
virtual_base = b;
}
if (virtual_base)
delta = size_diffop (BINFO_OFFSET (virtual_base),
BINFO_OFFSET (first_defn));
else if (lost)
delta = size_zero_node;
else
delta = size_diffop (BINFO_OFFSET (TREE_VALUE (overrider)),
BINFO_OFFSET (binfo));
modify_vtable_entry (t,
binfo,
TREE_PURPOSE (overrider),
delta,
virtuals);
if (virtual_base)
BV_VCALL_INDEX (*virtuals)
= get_vcall_index (TREE_PURPOSE (overrider),
BINFO_TYPE (virtual_base));
}
static tree
dfs_modify_vtables (binfo, data)
tree binfo;
void *data;
{
if (
(!BINFO_PRIMARY_P (binfo) || TREE_VIA_VIRTUAL (binfo))
&& CLASSTYPE_VFIELDS (BINFO_TYPE (binfo)))
{
tree t;
tree virtuals;
tree old_virtuals;
t = (tree) data;
make_new_vtable (t, binfo);
for (virtuals = BINFO_VIRTUALS (binfo),
old_virtuals = BINFO_VIRTUALS (TYPE_BINFO (BINFO_TYPE (binfo)));
virtuals;
virtuals = TREE_CHAIN (virtuals),
old_virtuals = TREE_CHAIN (old_virtuals))
update_vtable_entry_for_fn (t,
binfo,
BV_FN (old_virtuals),
&virtuals);
}
SET_BINFO_MARKED (binfo);
return NULL_TREE;
}
static tree
modify_all_vtables (t, virtuals)
tree t;
tree virtuals;
{
tree binfo = TYPE_BINFO (t);
tree *fnsp;
dfs_walk (binfo,
dfs_modify_vtables,
dfs_unmarked_real_bases_queue_p,
t);
dfs_walk (binfo, dfs_unmark, dfs_marked_real_bases_queue_p, t);
for (fnsp = &virtuals; *fnsp; )
{
tree fn = TREE_VALUE (*fnsp);
if (!value_member (fn, BINFO_VIRTUALS (binfo))
|| DECL_VINDEX (fn) == error_mark_node)
{
BV_DELTA (*fnsp) = integer_zero_node;
BV_VCALL_INDEX (*fnsp) = NULL_TREE;
fnsp = &TREE_CHAIN (*fnsp);
}
else
*fnsp = TREE_CHAIN (*fnsp);
}
return virtuals;
}
static tree
get_basefndecls (name, t)
tree name, t;
{
tree methods;
tree base_fndecls = NULL_TREE;
int n_baseclasses = CLASSTYPE_N_BASECLASSES (t);
int i;
for (methods = TYPE_METHODS (t); methods; methods = TREE_CHAIN (methods))
if (TREE_CODE (methods) == FUNCTION_DECL
&& DECL_VINDEX (methods) != NULL_TREE
&& DECL_NAME (methods) == name)
base_fndecls = tree_cons (NULL_TREE, methods, base_fndecls);
if (base_fndecls)
return base_fndecls;
for (i = 0; i < n_baseclasses; i++)
{
tree basetype = TYPE_BINFO_BASETYPE (t, i);
base_fndecls = chainon (get_basefndecls (name, basetype),
base_fndecls);
}
return base_fndecls;
}
static void
check_for_override (decl, ctype)
tree decl, ctype;
{
if (TREE_CODE (decl) == TEMPLATE_DECL)
return;
if ((DECL_DESTRUCTOR_P (decl)
|| IDENTIFIER_VIRTUAL_P (DECL_NAME (decl)))
&& look_for_overrides (ctype, decl)
&& !DECL_STATIC_FUNCTION_P (decl))
DECL_VINDEX (decl) = decl;
if (DECL_VIRTUAL_P (decl))
{
if (!DECL_VINDEX (decl))
DECL_VINDEX (decl) = error_mark_node;
IDENTIFIER_VIRTUAL_P (DECL_NAME (decl)) = 1;
}
}
void
warn_hidden (t)
tree t;
{
tree method_vec = CLASSTYPE_METHOD_VEC (t);
int n_methods = method_vec ? TREE_VEC_LENGTH (method_vec) : 0;
int i;
for (i = 2; i < n_methods && TREE_VEC_ELT (method_vec, i); ++i)
{
tree fns;
tree name;
tree fndecl;
tree base_fndecls;
int j;
name = DECL_NAME (OVL_CURRENT (TREE_VEC_ELT (method_vec, i)));
base_fndecls = NULL_TREE;
for (j = 0; j < CLASSTYPE_N_BASECLASSES (t); j++)
{
tree basetype = TYPE_BINFO_BASETYPE (t, j);
base_fndecls = chainon (get_basefndecls (name, basetype),
base_fndecls);
}
if (!base_fndecls)
continue;
for (fns = TREE_VEC_ELT (method_vec, i); fns; fns = OVL_NEXT (fns))
{
fndecl = OVL_CURRENT (fns);
if (DECL_VINDEX (fndecl))
{
tree *prev = &base_fndecls;
while (*prev)
if (same_signature_p (fndecl, TREE_VALUE (*prev)))
*prev = TREE_CHAIN (*prev);
else
prev = &TREE_CHAIN (*prev);
}
}
while (base_fndecls)
{
cp_warning_at ("`%D' was hidden", TREE_VALUE (base_fndecls));
cp_warning_at (" by `%D'",
OVL_CURRENT (TREE_VEC_ELT (method_vec, i)));
base_fndecls = TREE_CHAIN (base_fndecls);
}
}
}
static void
finish_struct_anon (t)
tree t;
{
tree field;
for (field = TYPE_FIELDS (t); field; field = TREE_CHAIN (field))
{
if (TREE_STATIC (field))
continue;
if (TREE_CODE (field) != FIELD_DECL)
continue;
if (DECL_NAME (field) == NULL_TREE
&& ANON_AGGR_TYPE_P (TREE_TYPE (field)))
{
tree elt = TYPE_FIELDS (TREE_TYPE (field));
for (; elt; elt = TREE_CHAIN (elt))
{
if (DECL_ARTIFICIAL (elt)
&& (!DECL_IMPLICIT_TYPEDEF_P (elt)
|| TYPE_ANONYMOUS_P (TREE_TYPE (elt))))
continue;
if (DECL_NAME (elt) == constructor_name (t))
cp_pedwarn_at ("ISO C++ forbids member `%D' with same name as enclosing class",
elt);
if (TREE_CODE (elt) != FIELD_DECL)
{
cp_pedwarn_at ("`%#D' invalid; an anonymous union can only have non-static data members",
elt);
continue;
}
if (TREE_PRIVATE (elt))
cp_pedwarn_at ("private member `%#D' in anonymous union",
elt);
else if (TREE_PROTECTED (elt))
cp_pedwarn_at ("protected member `%#D' in anonymous union",
elt);
TREE_PRIVATE (elt) = TREE_PRIVATE (field);
TREE_PROTECTED (elt) = TREE_PROTECTED (field);
}
}
}
}
void
maybe_add_class_template_decl_list (type, t, friend_p)
tree type;
tree t;
int friend_p;
{
if (CLASSTYPE_TEMPLATE_INFO (type))
CLASSTYPE_DECL_LIST (type)
= tree_cons (friend_p ? NULL_TREE : type,
t, CLASSTYPE_DECL_LIST (type));
}
static void
add_implicitly_declared_members (t, cant_have_default_ctor,
cant_have_const_cctor,
cant_have_const_assignment)
tree t;
int cant_have_default_ctor;
int cant_have_const_cctor;
int cant_have_const_assignment;
{
tree default_fn;
tree implicit_fns = NULL_TREE;
tree virtual_dtor = NULL_TREE;
tree *f;
++adding_implicit_members;
if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t) && !TYPE_HAS_DESTRUCTOR (t))
{
default_fn = implicitly_declare_fn (sfk_destructor, t, 0);
check_for_override (default_fn, t);
if (default_fn == void_type_node)
TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t) = 0;
else
{
TREE_CHAIN (default_fn) = implicit_fns;
implicit_fns = default_fn;
if (DECL_VINDEX (default_fn))
virtual_dtor = default_fn;
}
}
else
TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t) |= TYPE_HAS_DESTRUCTOR (t);
if (! TYPE_HAS_CONSTRUCTOR (t) && ! cant_have_default_ctor)
{
default_fn = implicitly_declare_fn (sfk_constructor, t, 0);
TREE_CHAIN (default_fn) = implicit_fns;
implicit_fns = default_fn;
}
if (! TYPE_HAS_INIT_REF (t) && ! TYPE_FOR_JAVA (t))
{
default_fn
= implicitly_declare_fn (sfk_copy_constructor, t,
!cant_have_const_cctor);
TREE_CHAIN (default_fn) = implicit_fns;
implicit_fns = default_fn;
}
if (! TYPE_HAS_ASSIGN_REF (t) && ! TYPE_FOR_JAVA (t))
{
default_fn
= implicitly_declare_fn (sfk_assignment_operator, t,
!cant_have_const_assignment);
TREE_CHAIN (default_fn) = implicit_fns;
implicit_fns = default_fn;
}
for (f = &implicit_fns; *f; f = &TREE_CHAIN (*f))
{
add_method (t, *f, 0);
maybe_add_class_template_decl_list (current_class_type, *f, 0);
}
if (abi_version_at_least (2))
TYPE_METHODS (t) = chainon (TYPE_METHODS (t), implicit_fns);
else
{
if (warn_abi && virtual_dtor)
warning ("vtable layout for class `%T' may not be ABI-compliant "
"and may change in a future version of GCC due to implicit "
"virtual destructor",
t);
*f = TYPE_METHODS (t);
TYPE_METHODS (t) = implicit_fns;
}
--adding_implicit_members;
}
static int
count_fields (fields)
tree fields;
{
tree x;
int n_fields = 0;
for (x = fields; x; x = TREE_CHAIN (x))
{
if (TREE_CODE (x) == FIELD_DECL && ANON_AGGR_TYPE_P (TREE_TYPE (x)))
n_fields += count_fields (TYPE_FIELDS (TREE_TYPE (x)));
else
n_fields += 1;
}
return n_fields;
}
static int
add_fields_to_vec (fields, field_vec, idx)
tree fields, field_vec;
int idx;
{
tree x;
for (x = fields; x; x = TREE_CHAIN (x))
{
if (TREE_CODE (x) == FIELD_DECL && ANON_AGGR_TYPE_P (TREE_TYPE (x)))
idx = add_fields_to_vec (TYPE_FIELDS (TREE_TYPE (x)), field_vec, idx);
else
TREE_VEC_ELT (field_vec, idx++) = x;
}
return idx;
}
static void
check_bitfield_decl (field)
tree field;
{
tree type = TREE_TYPE (field);
tree w = NULL_TREE;
if (DECL_INITIAL (field)
&& ! INTEGRAL_TYPE_P (TREE_TYPE (field)))
{
cp_error_at ("bit-field `%#D' with non-integral type", field);
w = error_mark_node;
}
if (DECL_INITIAL (field))
{
w = DECL_INITIAL (field);
STRIP_NOPS (w);
if (TREE_CODE (w) == CONST_DECL)
w = DECL_INITIAL (w);
else
w = decl_constant_value (w);
if (TREE_CODE (w) != INTEGER_CST)
{
cp_error_at ("bit-field `%D' width not an integer constant",
field);
w = error_mark_node;
}
else if (tree_int_cst_sgn (w) < 0)
{
cp_error_at ("negative width in bit-field `%D'", field);
w = error_mark_node;
}
else if (integer_zerop (w) && DECL_NAME (field) != 0)
{
cp_error_at ("zero width for bit-field `%D'", field);
w = error_mark_node;
}
else if (compare_tree_int (w, TYPE_PRECISION (type)) > 0
&& TREE_CODE (type) != ENUMERAL_TYPE
&& TREE_CODE (type) != BOOLEAN_TYPE)
cp_warning_at ("width of `%D' exceeds its type", field);
else if (TREE_CODE (type) == ENUMERAL_TYPE
&& (0 > compare_tree_int (w,
min_precision (TYPE_MIN_VALUE (type),
TREE_UNSIGNED (type)))
|| 0 > compare_tree_int (w,
min_precision
(TYPE_MAX_VALUE (type),
TREE_UNSIGNED (type)))))
cp_warning_at ("`%D' is too small to hold all values of `%#T'",
field, type);
}
DECL_INITIAL (field) = NULL_TREE;
if (w != error_mark_node)
{
DECL_SIZE (field) = convert (bitsizetype, w);
DECL_BIT_FIELD (field) = 1;
if (integer_zerop (w)
&& ! (* targetm.ms_bitfield_layout_p) (DECL_FIELD_CONTEXT (field)))
{
#ifdef EMPTY_FIELD_BOUNDARY
DECL_ALIGN (field) = MAX (DECL_ALIGN (field),
EMPTY_FIELD_BOUNDARY);
#endif
#ifdef PCC_BITFIELD_TYPE_MATTERS
if (PCC_BITFIELD_TYPE_MATTERS)
{
DECL_ALIGN (field) = MAX (DECL_ALIGN (field),
TYPE_ALIGN (type));
DECL_USER_ALIGN (field) |= TYPE_USER_ALIGN (type);
}
#endif
}
}
else
{
DECL_BIT_FIELD (field) = 0;
CLEAR_DECL_C_BIT_FIELD (field);
DECL_ALIGN (field) = MAX (DECL_ALIGN (field), TYPE_ALIGN (type));
DECL_USER_ALIGN (field) |= TYPE_USER_ALIGN (type);
}
}
static void
check_field_decl (field, t, cant_have_const_ctor,
cant_have_default_ctor, no_const_asn_ref,
any_default_members)
tree field;
tree t;
int *cant_have_const_ctor;
int *cant_have_default_ctor;
int *no_const_asn_ref;
int *any_default_members;
{
tree type = strip_array_types (TREE_TYPE (field));
if (ANON_UNION_TYPE_P (type))
;
else if (ANON_AGGR_TYPE_P (type))
{
tree fields;
for (fields = TYPE_FIELDS (type); fields; fields = TREE_CHAIN (fields))
if (TREE_CODE (fields) == FIELD_DECL && !DECL_C_BIT_FIELD (field))
check_field_decl (fields, t, cant_have_const_ctor,
cant_have_default_ctor, no_const_asn_ref,
any_default_members);
}
else if (CLASS_TYPE_P (type))
{
abstract_virtuals_error (field, type);
if (TREE_CODE (t) == UNION_TYPE)
{
if (TYPE_NEEDS_CONSTRUCTING (type))
cp_error_at ("member `%#D' with constructor not allowed in union",
field);
if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type))
cp_error_at ("member `%#D' with destructor not allowed in union",
field);
if (TYPE_HAS_COMPLEX_ASSIGN_REF (type))
cp_error_at ("member `%#D' with copy assignment operator not allowed in union",
field);
}
else
{
TYPE_NEEDS_CONSTRUCTING (t) |= TYPE_NEEDS_CONSTRUCTING (type);
TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)
|= TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type);
TYPE_HAS_COMPLEX_ASSIGN_REF (t) |= TYPE_HAS_COMPLEX_ASSIGN_REF (type);
TYPE_HAS_COMPLEX_INIT_REF (t) |= TYPE_HAS_COMPLEX_INIT_REF (type);
}
if (!TYPE_HAS_CONST_INIT_REF (type))
*cant_have_const_ctor = 1;
if (!TYPE_HAS_CONST_ASSIGN_REF (type))
*no_const_asn_ref = 1;
if (TYPE_HAS_CONSTRUCTOR (type)
&& ! TYPE_HAS_DEFAULT_CONSTRUCTOR (type))
*cant_have_default_ctor = 1;
}
if (DECL_INITIAL (field) != NULL_TREE)
{
if (TREE_CODE (t) == UNION_TYPE && any_default_members != 0)
cp_error_at ("multiple fields in union `%T' initialized");
*any_default_members = 1;
}
DECL_ALIGN (field) = MAX (DECL_ALIGN (field),
(DECL_PACKED (field)
? BITS_PER_UNIT
: TYPE_ALIGN (TREE_TYPE (field))));
if (! DECL_PACKED (field))
DECL_USER_ALIGN (field) |= TYPE_USER_ALIGN (TREE_TYPE (field));
}
static void
check_field_decls (tree t, tree *access_decls,
int *cant_have_default_ctor_p,
int *cant_have_const_ctor_p,
int *no_const_asn_ref_p)
{
tree *field;
tree *next;
int has_pointers;
int any_default_members;
delete_duplicate_fields (TYPE_FIELDS (t));
*access_decls = NULL_TREE;
has_pointers = 0;
any_default_members = 0;
for (field = &TYPE_FIELDS (t); *field; field = next)
{
tree x = *field;
tree type = TREE_TYPE (x);
next = &TREE_CHAIN (x);
if (TREE_CODE (x) == FIELD_DECL)
{
DECL_PACKED (x) |= TYPE_PACKED (t);
if (DECL_C_BIT_FIELD (x) && integer_zerop (DECL_INITIAL (x)))
;
else
{
tree element_type;
CLASSTYPE_EMPTY_P (t) = 0;
CLASSTYPE_NEARLY_EMPTY_P (t) = 0;
element_type = strip_array_types (type);
if (CLASS_TYPE_P (element_type)
&& CLASSTYPE_CONTAINS_EMPTY_CLASS_P (element_type))
CLASSTYPE_CONTAINS_EMPTY_CLASS_P (t) = 1;
}
}
if (TREE_CODE (x) == USING_DECL)
{
*field = TREE_CHAIN (x);
*access_decls = tree_cons (NULL_TREE, x, *access_decls);
next = field;
continue;
}
if (TREE_CODE (x) == TYPE_DECL
|| TREE_CODE (x) == TEMPLATE_DECL)
continue;
DECL_CONTEXT (x) = t;
if (current_function_decl && TREE_STATIC (x))
cp_error_at ("field `%D' in local class cannot be static", x);
if (TREE_CODE (type) == FUNCTION_TYPE)
{
cp_error_at ("field `%D' invalidly declared function type",
x);
type = build_pointer_type (type);
TREE_TYPE (x) = type;
}
else if (TREE_CODE (type) == METHOD_TYPE)
{
cp_error_at ("field `%D' invalidly declared method type", x);
type = build_pointer_type (type);
TREE_TYPE (x) = type;
}
else if (TREE_CODE (type) == OFFSET_TYPE)
{
cp_error_at ("field `%D' invalidly declared offset type", x);
type = build_pointer_type (type);
TREE_TYPE (x) = type;
}
if (type == error_mark_node)
continue;
DECL_NONLOCAL (x) = 1;
if (TREE_CODE (x) == CONST_DECL)
continue;
if (TREE_CODE (x) == VAR_DECL)
{
if (TREE_CODE (t) == UNION_TYPE)
cp_error_at ("field `%D' declared static in union", x);
continue;
}
if (TREE_PRIVATE (x) || TREE_PROTECTED (x))
CLASSTYPE_NON_AGGREGATE (t) = 1;
if (TREE_CODE (type) == REFERENCE_TYPE)
{
CLASSTYPE_NON_POD_P (t) = 1;
if (DECL_INITIAL (x) == NULL_TREE)
SET_CLASSTYPE_REF_FIELDS_NEED_INIT (t, 1);
*cant_have_default_ctor_p = 1;
TYPE_HAS_COMPLEX_ASSIGN_REF (t) = 1;
if (! TYPE_HAS_CONSTRUCTOR (t) && CLASSTYPE_NON_AGGREGATE (t)
&& extra_warnings)
cp_warning_at ("non-static reference `%#D' in class without a constructor", x);
}
type = strip_array_types (type);
if (TREE_CODE (type) == POINTER_TYPE)
has_pointers = 1;
if (DECL_MUTABLE_P (x) || TYPE_HAS_MUTABLE_P (type))
CLASSTYPE_HAS_MUTABLE (t) = 1;
if (! pod_type_p (type))
CLASSTYPE_NON_POD_P (t) = 1;
if (! zero_init_p (type))
CLASSTYPE_NON_ZERO_INIT_P (t) = 1;
if (CP_TYPE_CONST_P (type))
{
C_TYPE_FIELDS_READONLY (t) = 1;
if (DECL_INITIAL (x) == NULL_TREE)
SET_CLASSTYPE_READONLY_FIELDS_NEED_INIT (t, 1);
*cant_have_default_ctor_p = 1;
TYPE_HAS_COMPLEX_ASSIGN_REF (t) = 1;
if (! TYPE_HAS_CONSTRUCTOR (t) && CLASSTYPE_NON_AGGREGATE (t)
&& extra_warnings)
cp_warning_at ("non-static const member `%#D' in class without a constructor", x);
}
else if (IS_AGGR_TYPE (type))
{
C_TYPE_FIELDS_READONLY (t) |= C_TYPE_FIELDS_READONLY (type);
SET_CLASSTYPE_READONLY_FIELDS_NEED_INIT (t,
CLASSTYPE_READONLY_FIELDS_NEED_INIT (t)
| CLASSTYPE_READONLY_FIELDS_NEED_INIT (type));
}
if (DECL_NAME (x) == constructor_name (t)
&& TYPE_HAS_CONSTRUCTOR (t))
cp_pedwarn_at ("field `%#D' with same name as class", x);
if (DECL_C_BIT_FIELD (x))
check_bitfield_decl (x);
else
check_field_decl (x, t,
cant_have_const_ctor_p,
cant_have_default_ctor_p,
no_const_asn_ref_p,
&any_default_members);
}
if (has_pointers && warn_ecpp && TYPE_HAS_CONSTRUCTOR (t)
&& ! (TYPE_HAS_INIT_REF (t) && TYPE_HAS_ASSIGN_REF (t)))
{
warning ("`%#T' has pointer data members", t);
if (! TYPE_HAS_INIT_REF (t))
{
warning (" but does not override `%T(const %T&)'", t, t);
if (! TYPE_HAS_ASSIGN_REF (t))
warning (" or `operator=(const %T&)'", t);
}
else if (! TYPE_HAS_ASSIGN_REF (t))
warning (" but does not override `operator=(const %T&)'", t);
}
finish_struct_anon (t);
*access_decls = nreverse (*access_decls);
}
static int
record_subobject_offset (type, offset, offsets)
tree type;
tree offset;
splay_tree offsets;
{
splay_tree_node n;
if (!is_empty_class (type))
return 0;
n = splay_tree_lookup (offsets, (splay_tree_key) offset);
if (!n)
n = splay_tree_insert (offsets,
(splay_tree_key) offset,
(splay_tree_value) NULL_TREE);
n->value = ((splay_tree_value)
tree_cons (NULL_TREE,
type,
(tree) n->value));
return 0;
}
static int
check_subobject_offset (type, offset, offsets)
tree type;
tree offset;
splay_tree offsets;
{
splay_tree_node n;
tree t;
if (!is_empty_class (type))
return 0;
n = splay_tree_lookup (offsets, (splay_tree_key) offset);
if (!n)
return 0;
for (t = (tree) n->value; t; t = TREE_CHAIN (t))
if (same_type_p (TREE_VALUE (t), type))
return 1;
return 0;
}
static int
walk_subobject_offsets (type, f, offset, offsets, max_offset, vbases_p)
tree type;
subobject_offset_fn f;
tree offset;
splay_tree offsets;
tree max_offset;
int vbases_p;
{
int r = 0;
tree type_binfo = NULL_TREE;
if (max_offset && INT_CST_LT (max_offset, offset))
return 0;
if (!TYPE_P (type))
{
if (abi_version_at_least (2))
type_binfo = type;
type = BINFO_TYPE (type);
}
if (CLASS_TYPE_P (type))
{
tree field;
tree binfo;
int i;
if (!CLASSTYPE_CONTAINS_EMPTY_CLASS_P (type))
return 0;
r = (*f) (type, offset, offsets);
if (r)
return r;
if (!type_binfo)
type_binfo = TYPE_BINFO (type);
for (i = 0; i < BINFO_N_BASETYPES (type_binfo); ++i)
{
tree binfo_offset;
binfo = BINFO_BASETYPE (type_binfo, i);
if (abi_version_at_least (2)
&& TREE_VIA_VIRTUAL (binfo))
continue;
if (!vbases_p
&& TREE_VIA_VIRTUAL (binfo)
&& !BINFO_PRIMARY_P (binfo))
continue;
if (!abi_version_at_least (2))
binfo_offset = size_binop (PLUS_EXPR,
offset,
BINFO_OFFSET (binfo));
else
{
tree orig_binfo;
orig_binfo = BINFO_BASETYPE (TYPE_BINFO (type), i);
binfo_offset = size_binop (PLUS_EXPR,
offset,
BINFO_OFFSET (orig_binfo));
}
r = walk_subobject_offsets (binfo,
f,
binfo_offset,
offsets,
max_offset,
(abi_version_at_least (2)
? 0 : vbases_p));
if (r)
return r;
}
if (abi_version_at_least (2))
{
tree vbase;
if (vbases_p)
for (vbase = CLASSTYPE_VBASECLASSES (type);
vbase;
vbase = TREE_CHAIN (vbase))
{
binfo = TREE_VALUE (vbase);
r = walk_subobject_offsets (binfo,
f,
size_binop (PLUS_EXPR,
offset,
BINFO_OFFSET (binfo)),
offsets,
max_offset,
0);
if (r)
return r;
}
else
{
vbase = get_primary_binfo (type_binfo);
if (vbase && TREE_VIA_VIRTUAL (vbase))
{
tree derived = type_binfo;
while (BINFO_INHERITANCE_CHAIN (derived))
derived = BINFO_INHERITANCE_CHAIN (derived);
derived = TREE_TYPE (derived);
vbase = binfo_for_vbase (TREE_TYPE (vbase), derived);
if (BINFO_PRIMARY_BASE_OF (vbase) == type_binfo)
{
r = (walk_subobject_offsets
(vbase, f, offset,
offsets, max_offset, 0));
if (r)
return r;
}
}
}
}
for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
if (TREE_CODE (field) == FIELD_DECL && !DECL_ARTIFICIAL (field))
{
tree field_offset;
if (abi_version_at_least (2))
field_offset = byte_position (field);
else
field_offset = DECL_FIELD_OFFSET (field);
r = walk_subobject_offsets (TREE_TYPE (field),
f,
size_binop (PLUS_EXPR,
offset,
field_offset),
offsets,
max_offset,
1);
if (r)
return r;
}
}
else if (TREE_CODE (type) == ARRAY_TYPE)
{
tree element_type = strip_array_types (type);
tree domain = TYPE_DOMAIN (type);
tree index;
if (!CLASS_TYPE_P (element_type)
|| !CLASSTYPE_CONTAINS_EMPTY_CLASS_P (element_type))
return 0;
for (index = size_zero_node;
(abi_version_at_least (2)
? !INT_CST_LT (TYPE_MAX_VALUE (domain), index)
: INT_CST_LT (index, TYPE_MAX_VALUE (domain)));
index = size_binop (PLUS_EXPR, index, size_one_node))
{
r = walk_subobject_offsets (TREE_TYPE (type),
f,
offset,
offsets,
max_offset,
1);
if (r)
return r;
offset = size_binop (PLUS_EXPR, offset,
TYPE_SIZE_UNIT (TREE_TYPE (type)));
if (max_offset && INT_CST_LT (max_offset, offset))
break;
}
}
return 0;
}
static void
record_subobject_offsets (type, offset, offsets, vbases_p)
tree type;
tree offset;
splay_tree offsets;
int vbases_p;
{
walk_subobject_offsets (type, record_subobject_offset, offset,
offsets, NULL_TREE, vbases_p);
}
static int
layout_conflict_p (type, offset, offsets, vbases_p)
tree type;
tree offset;
splay_tree offsets;
int vbases_p;
{
splay_tree_node max_node;
max_node = splay_tree_max (offsets);
if (!max_node)
return 0;
return walk_subobject_offsets (type, check_subobject_offset, offset,
offsets, (tree) (max_node->key),
vbases_p);
}
static void
layout_nonempty_base_or_field (record_layout_info rli,
tree decl,
tree binfo,
splay_tree offsets)
{
tree t = rli->t;
tree offset = NULL_TREE;
bool field_p;
tree type;
if (binfo)
{
type = TREE_TYPE (binfo);
field_p = false;
}
else
{
type = TREE_TYPE (decl);
field_p = true;
}
while (1)
{
struct record_layout_info_s old_rli = *rli;
place_field (rli, decl);
offset = byte_position (decl);
if (!abi_version_at_least (2) && binfo && TREE_VIA_VIRTUAL (binfo))
break;
if (layout_conflict_p (field_p ? type : binfo, offset,
offsets, field_p))
{
*rli = old_rli;
rli->bitpos
= size_binop (PLUS_EXPR, rli->bitpos,
bitsize_int (binfo
? CLASSTYPE_ALIGN (type)
: TYPE_ALIGN (type)));
normalize_rli (rli);
}
else
break;
}
if (binfo && CLASS_TYPE_P (BINFO_TYPE (binfo)))
propagate_binfo_offsets (binfo,
size_diffop (convert (ssizetype, offset),
convert (ssizetype,
BINFO_OFFSET (binfo))),
t);
}
static int
empty_base_at_nonzero_offset_p (tree type,
tree offset,
splay_tree offsets ATTRIBUTE_UNUSED)
{
return is_empty_class (type) && !integer_zerop (offset);
}
static bool
layout_empty_base (binfo, eoc, offsets, t)
tree binfo;
tree eoc;
splay_tree offsets;
tree t;
{
tree alignment;
tree basetype = BINFO_TYPE (binfo);
bool atend = false;
my_friendly_assert (is_empty_class (basetype), 20000321);
alignment = ssize_int (CLASSTYPE_ALIGN_UNIT (basetype));
if (abi_version_at_least (2))
BINFO_OFFSET (binfo) = size_zero_node;
if (warn_abi && !integer_zerop (BINFO_OFFSET (binfo)))
warning ("offset of empty base `%T' may not be ABI-compliant and may"
"change in a future version of GCC",
BINFO_TYPE (binfo));
if (layout_conflict_p (binfo,
BINFO_OFFSET (binfo),
offsets,
0))
{
atend = true;
propagate_binfo_offsets (binfo, convert (ssizetype, eoc), t);
while (1)
{
if (!layout_conflict_p (binfo,
BINFO_OFFSET (binfo),
offsets,
0))
break;
propagate_binfo_offsets (binfo, alignment, t);
}
}
return atend;
}
static tree *
build_base_field (record_layout_info rli, tree binfo,
splay_tree offsets, tree *next_field)
{
tree t = rli->t;
tree basetype = BINFO_TYPE (binfo);
if (!COMPLETE_TYPE_P (basetype))
return next_field;
if (!is_empty_class (basetype))
{
tree decl;
CLASSTYPE_EMPTY_P (t) = 0;
decl = build_decl (FIELD_DECL, NULL_TREE, CLASSTYPE_AS_BASE (basetype));
DECL_ARTIFICIAL (decl) = 1;
DECL_FIELD_CONTEXT (decl) = t;
DECL_SIZE (decl) = CLASSTYPE_SIZE (basetype);
DECL_SIZE_UNIT (decl) = CLASSTYPE_SIZE_UNIT (basetype);
DECL_ALIGN (decl) = CLASSTYPE_ALIGN (basetype);
DECL_USER_ALIGN (decl) = CLASSTYPE_USER_ALIGN (basetype);
DECL_IGNORED_P (decl) = 1;
layout_nonempty_base_or_field (rli, decl, binfo, offsets);
TREE_CHAIN (decl) = *next_field;
*next_field = decl;
next_field = &TREE_CHAIN (decl);
}
else
{
tree eoc;
bool atend;
eoc = round_up (rli_size_unit_so_far (rli),
CLASSTYPE_ALIGN_UNIT (basetype));
atend = layout_empty_base (binfo, eoc, offsets, t);
if (!TREE_VIA_VIRTUAL (binfo) && CLASSTYPE_NEARLY_EMPTY_P (t))
{
if (atend)
CLASSTYPE_NEARLY_EMPTY_P (t) = 0;
else if (walk_subobject_offsets (basetype,
empty_base_at_nonzero_offset_p,
size_zero_node,
NULL,
NULL_TREE,
true))
{
if (abi_version_at_least (2))
CLASSTYPE_NEARLY_EMPTY_P (t) = 0;
else if (warn_abi)
warning ("class `%T' will be considered nearly empty in a "
"future version of GCC", t);
}
}
}
record_subobject_offsets (binfo,
BINFO_OFFSET (binfo),
offsets,
0);
return next_field;
}
static void
build_base_fields (record_layout_info rli,
splay_tree offsets, tree *next_field)
{
tree t = rli->t;
int n_baseclasses = CLASSTYPE_N_BASECLASSES (t);
int i;
if (CLASSTYPE_HAS_PRIMARY_BASE_P (t))
next_field = build_base_field (rli, CLASSTYPE_PRIMARY_BINFO (t),
offsets, next_field);
for (i = 0; i < n_baseclasses; ++i)
{
tree base_binfo;
base_binfo = BINFO_BASETYPE (TYPE_BINFO (t), i);
if (base_binfo == CLASSTYPE_PRIMARY_BINFO (t))
continue;
if (TREE_VIA_VIRTUAL (base_binfo)
&& !BINFO_PRIMARY_P (base_binfo))
continue;
next_field = build_base_field (rli, base_binfo,
offsets, next_field);
}
}
static void
check_methods (t)
tree t;
{
tree x;
for (x = TYPE_METHODS (t); x; x = TREE_CHAIN (x))
{
if (DECL_ASSEMBLER_NAME_SET_P (x)
&& IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (x)))
continue;
check_for_override (x, t);
if (DECL_PURE_VIRTUAL_P (x) && ! DECL_VINDEX (x))
cp_error_at ("initializer specified for non-virtual method `%D'", x);
if (DECL_VINDEX (x))
{
TYPE_POLYMORPHIC_P (t) = 1;
if (DECL_PURE_VIRTUAL_P (x))
CLASSTYPE_PURE_VIRTUALS (t)
= tree_cons (NULL_TREE, x, CLASSTYPE_PURE_VIRTUALS (t));
}
}
}
static tree
build_clone (fn, name)
tree fn;
tree name;
{
tree parms;
tree clone;
clone = copy_decl (fn);
DECL_CLONED_FUNCTION (clone) = fn;
DECL_ABSTRACT_ORIGIN (clone) = fn;
DECL_NAME (clone) = name;
SET_DECL_ASSEMBLER_NAME (clone, NULL_TREE);
DECL_PENDING_INLINE_INFO (clone) = NULL;
DECL_PENDING_INLINE_P (clone) = 0;
DECL_DEFERRED_FN (clone) = 0;
if (name == base_dtor_identifier)
{
DECL_VIRTUAL_P (clone) = 0;
if (TREE_CODE (clone) != TEMPLATE_DECL)
DECL_VINDEX (clone) = NULL_TREE;
}
if (DECL_HAS_IN_CHARGE_PARM_P (clone))
{
tree basetype;
tree parmtypes;
tree exceptions;
exceptions = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (clone));
basetype = TYPE_METHOD_BASETYPE (TREE_TYPE (clone));
parmtypes = TYPE_ARG_TYPES (TREE_TYPE (clone));
parmtypes = TREE_CHAIN (parmtypes);
parmtypes = TREE_CHAIN (parmtypes);
if (DECL_HAS_VTT_PARM_P (fn)
&& ! DECL_NEEDS_VTT_PARM_P (clone))
parmtypes = TREE_CHAIN (parmtypes);
TREE_TYPE (clone)
= build_cplus_method_type (basetype,
TREE_TYPE (TREE_TYPE (clone)),
parmtypes);
if (exceptions)
TREE_TYPE (clone) = build_exception_variant (TREE_TYPE (clone),
exceptions);
}
if (TREE_CODE (clone) != TEMPLATE_DECL)
{
DECL_ARGUMENTS (clone) = copy_list (DECL_ARGUMENTS (clone));
if (DECL_HAS_IN_CHARGE_PARM_P (clone))
{
TREE_CHAIN (DECL_ARGUMENTS (clone))
= TREE_CHAIN (TREE_CHAIN (DECL_ARGUMENTS (clone)));
DECL_HAS_IN_CHARGE_PARM_P (clone) = 0;
}
if (DECL_HAS_VTT_PARM_P (fn))
{
if (DECL_NEEDS_VTT_PARM_P (clone))
DECL_HAS_VTT_PARM_P (clone) = 1;
else
{
TREE_CHAIN (DECL_ARGUMENTS (clone))
= TREE_CHAIN (TREE_CHAIN (DECL_ARGUMENTS (clone)));
DECL_HAS_VTT_PARM_P (clone) = 0;
}
}
for (parms = DECL_ARGUMENTS (clone); parms; parms = TREE_CHAIN (parms))
{
DECL_CONTEXT (parms) = clone;
cxx_dup_lang_specific_decl (parms);
}
}
SET_DECL_RTL (clone, NULL_RTX);
rest_of_decl_compilation (clone, NULL, 1, at_eof);
TREE_CHAIN (clone) = TREE_CHAIN (fn);
TREE_CHAIN (fn) = clone;
if (TREE_CODE (clone) == TEMPLATE_DECL)
{
tree result;
DECL_TEMPLATE_RESULT (clone)
= build_clone (DECL_TEMPLATE_RESULT (clone), name);
result = DECL_TEMPLATE_RESULT (clone);
DECL_TEMPLATE_INFO (result) = copy_node (DECL_TEMPLATE_INFO (result));
DECL_TI_TEMPLATE (result) = clone;
}
else if (DECL_DEFERRED_FN (fn))
defer_fn (clone);
return clone;
}
int
has_apple_kext_compatibility_attr_p (class)
tree class;
{
while (class != NULL)
{
if (TYPE_USES_MULTIPLE_INHERITANCE (class))
return 0;
if (lookup_attribute ("apple_kext_compatibility",
TYPE_ATTRIBUTES (class)))
return 1;
if (CLASSTYPE_N_BASECLASSES (class) == 1)
class = TYPE_BINFO_BASETYPE (class, 0);
else
break;
}
return 0;
}
int
has_empty_operator_delete_p (class)
tree class;
{
if (class != NULL)
{
if (TYPE_USES_MULTIPLE_INHERITANCE (class))
return 0;
if (TYPE_GETS_DELETE (class))
{
tree f = lookup_fnfields (TYPE_BINFO (class),
ansi_opname (DELETE_EXPR), 0);
if (f == error_mark_node)
return 0;
if (BASELINK_P (f))
f = TREE_VALUE (f);
if (OVL_CURRENT (f))
{
f = OVL_CURRENT (f);
if (TREE_SIDE_EFFECTS (f))
return 1;
if (DECL_SAVED_TREE (f)
&& TREE_CODE (DECL_SAVED_TREE (f)) == COMPOUND_STMT
&& COMPOUND_BODY (DECL_SAVED_TREE (f)))
return compound_body_is_empty_p (COMPOUND_BODY
(DECL_SAVED_TREE (f)));
}
}
}
return 0;
}
int
compound_body_is_empty_p (t)
tree t;
{
while (t && t != error_mark_node)
{
enum tree_code tc = TREE_CODE (t);
if (tc == COMPOUND_STMT)
{
if (compound_body_is_empty_p (COMPOUND_BODY (t)))
t = TREE_CHAIN (t);
else
return 0;
}
else
if (tc == SCOPE_STMT)
t = TREE_CHAIN (t);
else
return 0;
}
return 1;
}
void
clone_function_decl (fn, update_method_vec_p)
tree fn;
int update_method_vec_p;
{
tree clone;
if (TREE_CHAIN (fn)
&& DECL_CLONED_FUNCTION (TREE_CHAIN (fn)))
return;
if (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (fn))
{
clone = build_clone (fn, complete_ctor_identifier);
if (update_method_vec_p)
add_method (DECL_CONTEXT (clone), clone, 0);
clone = build_clone (fn, base_ctor_identifier);
if (update_method_vec_p)
add_method (DECL_CONTEXT (clone), clone, 0);
}
else
{
my_friendly_assert (DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (fn), 20000411);
if (DECL_VIRTUAL_P (fn))
{
clone = build_clone (fn, deleting_dtor_identifier);
if (update_method_vec_p)
add_method (DECL_CONTEXT (clone), clone, 0);
}
if (! flag_apple_kext
|| ! has_apple_kext_compatibility_attr_p (DECL_CONTEXT (clone)))
{
clone = build_clone (fn, complete_dtor_identifier);
if (update_method_vec_p)
add_method (DECL_CONTEXT (clone), clone, 0);
}
clone = build_clone (fn, base_dtor_identifier);
if (update_method_vec_p)
add_method (DECL_CONTEXT (clone), clone, 0);
}
DECL_ABSTRACT (fn) = 1;
}
void
adjust_clone_args (decl)
tree decl;
{
tree clone;
for (clone = TREE_CHAIN (decl); clone && DECL_CLONED_FUNCTION (clone);
clone = TREE_CHAIN (clone))
{
tree orig_clone_parms = TYPE_ARG_TYPES (TREE_TYPE (clone));
tree orig_decl_parms = TYPE_ARG_TYPES (TREE_TYPE (decl));
tree decl_parms, clone_parms;
clone_parms = orig_clone_parms;
orig_clone_parms = TREE_CHAIN (orig_clone_parms);
orig_decl_parms = TREE_CHAIN (orig_decl_parms);
if (DECL_HAS_IN_CHARGE_PARM_P (decl))
orig_decl_parms = TREE_CHAIN (orig_decl_parms);
if (DECL_HAS_VTT_PARM_P (decl))
orig_decl_parms = TREE_CHAIN (orig_decl_parms);
clone_parms = orig_clone_parms;
if (DECL_HAS_VTT_PARM_P (clone))
clone_parms = TREE_CHAIN (clone_parms);
for (decl_parms = orig_decl_parms; decl_parms;
decl_parms = TREE_CHAIN (decl_parms),
clone_parms = TREE_CHAIN (clone_parms))
{
my_friendly_assert (same_type_p (TREE_TYPE (decl_parms),
TREE_TYPE (clone_parms)), 20010424);
if (TREE_PURPOSE (decl_parms) && !TREE_PURPOSE (clone_parms))
{
tree exceptions = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (clone));
tree basetype = TYPE_METHOD_BASETYPE (TREE_TYPE (clone));
tree type;
clone_parms = orig_decl_parms;
if (DECL_HAS_VTT_PARM_P (clone))
{
clone_parms = tree_cons (TREE_PURPOSE (orig_clone_parms),
TREE_VALUE (orig_clone_parms),
clone_parms);
TREE_TYPE (clone_parms) = TREE_TYPE (orig_clone_parms);
}
type = build_cplus_method_type (basetype,
TREE_TYPE (TREE_TYPE (clone)),
clone_parms);
if (exceptions)
type = build_exception_variant (type, exceptions);
TREE_TYPE (clone) = type;
clone_parms = NULL_TREE;
break;
}
}
my_friendly_assert (!clone_parms, 20010424);
}
}
static void
clone_constructors_and_destructors (t)
tree t;
{
tree fns;
if (!CLASSTYPE_METHOD_VEC (t))
return;
for (fns = CLASSTYPE_CONSTRUCTORS (t); fns; fns = OVL_NEXT (fns))
clone_function_decl (OVL_CURRENT (fns), 1);
for (fns = CLASSTYPE_DESTRUCTORS (t); fns; fns = OVL_NEXT (fns))
clone_function_decl (OVL_CURRENT (fns), 1);
}
static void
remove_zero_width_bit_fields (t)
tree t;
{
tree *fieldsp;
fieldsp = &TYPE_FIELDS (t);
while (*fieldsp)
{
if (TREE_CODE (*fieldsp) == FIELD_DECL
&& DECL_C_BIT_FIELD (*fieldsp)
&& DECL_INITIAL (*fieldsp))
*fieldsp = TREE_CHAIN (*fieldsp);
else
fieldsp = &TREE_CHAIN (*fieldsp);
}
}
static bool
type_requires_array_cookie (type)
tree type;
{
tree fns;
bool has_two_argument_delete_p = false;
my_friendly_assert (CLASS_TYPE_P (type), 20010712);
if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type))
return true;
fns = lookup_fnfields (TYPE_BINFO (type),
ansi_opname (VEC_DELETE_EXPR),
0);
if (!fns || fns == error_mark_node)
return false;
for (fns = BASELINK_FUNCTIONS (fns); fns; fns = OVL_NEXT (fns))
{
tree fn;
tree second_parm;
fn = OVL_CURRENT (fns);
second_parm = TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (fn)));
if (second_parm == void_list_node)
return false;
if (TREE_CHAIN (second_parm) == void_list_node
&& same_type_p (TREE_VALUE (second_parm), sizetype))
has_two_argument_delete_p = true;
}
return has_two_argument_delete_p;
}
static void
check_bases_and_members (tree t)
{
int cant_have_default_ctor;
int cant_have_const_ctor;
int no_const_asn_ref;
tree access_decls;
cant_have_default_ctor = 0;
cant_have_const_ctor = 0;
no_const_asn_ref = 0;
CLASSTYPE_NEARLY_EMPTY_P (t) = 1;
check_bases (t, &cant_have_default_ctor, &cant_have_const_ctor,
&no_const_asn_ref);
check_field_decls (t, &access_decls,
&cant_have_default_ctor,
&cant_have_const_ctor,
&no_const_asn_ref);
check_methods (t);
if (!TYPE_CONTAINS_VPTR_P (t))
CLASSTYPE_NEARLY_EMPTY_P (t) = 0;
TYPE_HAS_COMPLEX_INIT_REF (t)
|= (TYPE_HAS_INIT_REF (t)
|| TYPE_USES_VIRTUAL_BASECLASSES (t)
|| TYPE_POLYMORPHIC_P (t));
TYPE_NEEDS_CONSTRUCTING (t)
|= (TYPE_HAS_CONSTRUCTOR (t)
|| TYPE_USES_VIRTUAL_BASECLASSES (t)
|| TYPE_POLYMORPHIC_P (t));
CLASSTYPE_NON_AGGREGATE (t) |= (TYPE_HAS_CONSTRUCTOR (t)
|| TYPE_POLYMORPHIC_P (t));
CLASSTYPE_NON_POD_P (t)
|= (CLASSTYPE_NON_AGGREGATE (t) || TYPE_HAS_DESTRUCTOR (t)
|| TYPE_HAS_ASSIGN_REF (t));
TYPE_HAS_REAL_ASSIGN_REF (t) |= TYPE_HAS_ASSIGN_REF (t);
TYPE_HAS_COMPLEX_ASSIGN_REF (t)
|= TYPE_HAS_ASSIGN_REF (t) || TYPE_CONTAINS_VPTR_P (t);
add_implicitly_declared_members (t, cant_have_default_ctor,
cant_have_const_ctor,
no_const_asn_ref);
clone_constructors_and_destructors (t);
for (; access_decls; access_decls = TREE_CHAIN (access_decls))
handle_using_decl (TREE_VALUE (access_decls), t);
finish_struct_methods (t);
TYPE_LANG_SPECIFIC (t)->u.c.vec_new_uses_cookie
= type_requires_array_cookie (t);
}
static tree
create_vtable_ptr (t, virtuals_p)
tree t;
tree *virtuals_p;
{
tree fn;
for (fn = TYPE_METHODS (t); fn; fn = TREE_CHAIN (fn))
if (DECL_VINDEX (fn) && !DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (fn)
&& TREE_CODE (DECL_VINDEX (fn)) != INTEGER_CST)
{
tree new_virtual = make_node (TREE_LIST);
BV_FN (new_virtual) = fn;
BV_DELTA (new_virtual) = integer_zero_node;
TREE_CHAIN (new_virtual) = *virtuals_p;
*virtuals_p = new_virtual;
}
if (!TYPE_VFIELD (t) && (*virtuals_p || TYPE_CONTAINS_VPTR_P (t)))
{
tree field;
field = build_decl (FIELD_DECL, get_vfield_name (t), vtbl_ptr_type_node);
SET_DECL_ASSEMBLER_NAME (field, get_identifier (VFIELD_BASE));
DECL_VIRTUAL_P (field) = 1;
DECL_ARTIFICIAL (field) = 1;
DECL_FIELD_CONTEXT (field) = t;
DECL_FCONTEXT (field) = t;
DECL_ALIGN (field) = TYPE_ALIGN (vtbl_ptr_type_node);
DECL_USER_ALIGN (field) = TYPE_USER_ALIGN (vtbl_ptr_type_node);
TYPE_VFIELD (t) = field;
CLASSTYPE_EMPTY_P (t) = 0;
if (CLASSTYPE_N_BASECLASSES (t))
TYPE_BASE_CONVS_MAY_REQUIRE_CODE_P (t) = 1;
return field;
}
return NULL_TREE;
}
static void
fixup_pending_inline (fn)
tree fn;
{
if (DECL_PENDING_INLINE_INFO (fn))
{
tree args = DECL_ARGUMENTS (fn);
while (args)
{
DECL_CONTEXT (args) = fn;
args = TREE_CHAIN (args);
}
}
}
static void
fixup_inline_methods (type)
tree type;
{
tree method = TYPE_METHODS (type);
if (method && TREE_CODE (method) == TREE_VEC)
{
if (TREE_VEC_ELT (method, 1))
method = TREE_VEC_ELT (method, 1);
else if (TREE_VEC_ELT (method, 0))
method = TREE_VEC_ELT (method, 0);
else
method = TREE_VEC_ELT (method, 2);
}
for (; method; method = TREE_CHAIN (method))
fixup_pending_inline (method);
for (method = CLASSTYPE_INLINE_FRIENDS (type);
method;
method = TREE_CHAIN (method))
fixup_pending_inline (TREE_VALUE (method));
CLASSTYPE_INLINE_FRIENDS (type) = NULL_TREE;
}
static void
propagate_binfo_offsets (binfo, offset, t)
tree binfo;
tree offset;
tree t;
{
int i;
tree primary_binfo;
BINFO_OFFSET (binfo)
= convert (sizetype,
size_binop (PLUS_EXPR,
convert (ssizetype, BINFO_OFFSET (binfo)),
offset));
primary_binfo = get_primary_binfo (binfo);
for (i = -1; i < BINFO_N_BASETYPES (binfo); ++i)
{
tree base_binfo;
if (i == -1)
{
if (!primary_binfo)
continue;
base_binfo = primary_binfo;
}
else
{
base_binfo = BINFO_BASETYPE (binfo, i);
if (base_binfo == primary_binfo)
continue;
}
if (TREE_VIA_VIRTUAL (base_binfo)
&& (BINFO_PRIMARY_BASE_OF (base_binfo) != binfo
|| base_binfo != binfo_for_vbase (BINFO_TYPE (base_binfo), t)))
continue;
propagate_binfo_offsets (base_binfo, offset, t);
}
}
static tree
dfs_set_offset_for_unshared_vbases (binfo, data)
tree binfo;
void *data;
{
if (TREE_VIA_VIRTUAL (binfo))
{
tree t = (tree) data;
tree vbase;
tree offset;
vbase = binfo_for_vbase (BINFO_TYPE (binfo), t);
if (vbase != binfo)
{
offset = size_diffop (BINFO_OFFSET (vbase), BINFO_OFFSET (binfo));
propagate_binfo_offsets (binfo, offset, t);
}
}
return NULL_TREE;
}
static void
layout_virtual_bases (record_layout_info rli, splay_tree offsets)
{
tree vbases;
tree t = rli->t;
bool first_vbase = true;
tree *next_field;
if (CLASSTYPE_N_BASECLASSES (t) == 0)
return;
if (!abi_version_at_least(2))
{
finish_record_layout (rli, false);
#ifdef STRUCTURE_SIZE_BOUNDARY
if (! TYPE_PACKED (t))
TYPE_ALIGN (t) = MAX (TYPE_ALIGN (t), STRUCTURE_SIZE_BOUNDARY);
#endif
rli->offset = TYPE_SIZE_UNIT (t);
rli->bitpos = bitsize_zero_node;
rli->record_align = TYPE_ALIGN (t);
}
next_field = &TYPE_FIELDS (t);
while (*next_field)
next_field = &TREE_CHAIN (*next_field);
for (vbases = TYPE_BINFO (t);
vbases;
vbases = TREE_CHAIN (vbases))
{
tree vbase;
if (!TREE_VIA_VIRTUAL (vbases))
continue;
vbase = binfo_for_vbase (BINFO_TYPE (vbases), t);
if (!BINFO_PRIMARY_P (vbase))
{
tree basetype = TREE_TYPE (vbase);
next_field = build_base_field (rli, vbase,
offsets, next_field);
if (warn_abi
&& first_vbase
&& (tree_int_cst_lt
(size_binop (CEIL_DIV_EXPR,
round_up (CLASSTYPE_SIZE (t),
CLASSTYPE_ALIGN (basetype)),
bitsize_unit_node),
BINFO_OFFSET (vbase))))
warning ("offset of virtual base `%T' is not ABI-compliant and may change in a future version of GCC",
basetype);
first_vbase = false;
}
}
dfs_walk (TYPE_BINFO (t), dfs_set_offset_for_unshared_vbases, NULL, t);
}
static tree
end_of_base (tree binfo)
{
tree size;
if (is_empty_class (BINFO_TYPE (binfo)))
size = TYPE_SIZE_UNIT (BINFO_TYPE (binfo));
else
size = CLASSTYPE_SIZE_UNIT (BINFO_TYPE (binfo));
return size_binop (PLUS_EXPR, BINFO_OFFSET (binfo), size);
}
static tree
end_of_class (t, include_virtuals_p)
tree t;
int include_virtuals_p;
{
tree result = size_zero_node;
tree binfo;
tree offset;
int i;
for (i = 0; i < CLASSTYPE_N_BASECLASSES (t); ++i)
{
binfo = BINFO_BASETYPE (TYPE_BINFO (t), i);
if (!include_virtuals_p
&& TREE_VIA_VIRTUAL (binfo)
&& !BINFO_PRIMARY_P (binfo))
continue;
offset = end_of_base (binfo);
if (INT_CST_LT_UNSIGNED (result, offset))
result = offset;
}
if (abi_version_at_least (2) && include_virtuals_p)
for (binfo = CLASSTYPE_VBASECLASSES (t);
binfo;
binfo = TREE_CHAIN (binfo))
{
offset = end_of_base (TREE_VALUE (binfo));
if (INT_CST_LT_UNSIGNED (result, offset))
result = offset;
}
return result;
}
static void
warn_about_ambiguous_bases (t)
tree t;
{
int i;
tree vbases;
tree basetype;
for (i = 0; i < CLASSTYPE_N_BASECLASSES (t); ++i)
{
basetype = TYPE_BINFO_BASETYPE (t, i);
if (!lookup_base (t, basetype, ba_ignore | ba_quiet, NULL))
warning ("direct base `%T' inaccessible in `%T' due to ambiguity",
basetype, t);
}
if (extra_warnings)
for (vbases = CLASSTYPE_VBASECLASSES (t);
vbases;
vbases = TREE_CHAIN (vbases))
{
basetype = BINFO_TYPE (TREE_VALUE (vbases));
if (!lookup_base (t, basetype, ba_ignore | ba_quiet, NULL))
warning ("virtual base `%T' inaccessible in `%T' due to ambiguity",
basetype, t);
}
}
static int
splay_tree_compare_integer_csts (k1, k2)
splay_tree_key k1;
splay_tree_key k2;
{
return tree_int_cst_compare ((tree) k1, (tree) k2);
}
static void
include_empty_classes (record_layout_info rli)
{
tree eoc;
tree rli_size;
eoc = end_of_class (rli->t,
CLASSTYPE_AS_BASE (rli->t) != NULL_TREE);
rli_size = rli_size_unit_so_far (rli);
if (TREE_CODE (rli_size) == INTEGER_CST
&& INT_CST_LT_UNSIGNED (rli_size, eoc))
{
rli->bitpos = round_up (rli->bitpos, BITS_PER_UNIT);
rli->bitpos
= size_binop (PLUS_EXPR,
rli->bitpos,
size_binop (MULT_EXPR,
convert (bitsizetype,
size_binop (MINUS_EXPR,
eoc, rli_size)),
bitsize_int (BITS_PER_UNIT)));
normalize_rli (rli);
}
}
static void
layout_class_type (tree t, tree *virtuals_p)
{
tree non_static_data_members;
tree field;
tree vptr;
record_layout_info rli;
splay_tree empty_base_offsets;
bool last_field_was_bitfield = false;
tree *next_field;
tree base_t;
non_static_data_members = TYPE_FIELDS (t);
rli = start_record_layout (t);
determine_primary_base (t);
vptr = create_vtable_ptr (t, virtuals_p);
if (vptr)
{
TREE_CHAIN (vptr) = TYPE_FIELDS (t);
TYPE_FIELDS (t) = vptr;
next_field = &TREE_CHAIN (vptr);
place_field (rli, vptr);
}
else
next_field = &TYPE_FIELDS (t);
empty_base_offsets = splay_tree_new (splay_tree_compare_integer_csts,
NULL, NULL);
build_base_fields (rli, empty_base_offsets, next_field);
darwin_align_is_first_member_of_class = 1;
for (field = non_static_data_members; field; field = TREE_CHAIN (field))
{
tree type;
tree padding;
if (TREE_CODE (field) != FIELD_DECL)
{
place_field (rli, field);
if (TREE_CODE (field) == VAR_DECL)
maybe_register_incomplete_var (field);
continue;
}
type = TREE_TYPE (field);
if (DECL_C_BIT_FIELD (field)
&& INT_CST_LT (TYPE_SIZE (type), DECL_SIZE (field)))
{
integer_type_kind itk;
tree integer_type;
for (itk = itk_char; itk != itk_none; ++itk)
if (INT_CST_LT (DECL_SIZE (field),
TYPE_SIZE (integer_types[itk])))
break;
integer_type = integer_types[itk - 1];
if (abi_version_at_least (2) && TREE_CODE (t) == UNION_TYPE)
padding = DECL_SIZE (field);
else
{
if (warn_abi && TREE_CODE (t) == UNION_TYPE)
warning ("size assigned to `%T' may not be "
"ABI-compliant and may change in a future "
"version of GCC",
t);
padding = size_binop (MINUS_EXPR, DECL_SIZE (field),
TYPE_SIZE (integer_type));
}
DECL_SIZE (field) = TYPE_SIZE (integer_type);
DECL_ALIGN (field) = TYPE_ALIGN (integer_type);
DECL_USER_ALIGN (field) = TYPE_USER_ALIGN (integer_type);
}
else
padding = NULL_TREE;
layout_nonempty_base_or_field (rli, field, NULL_TREE,
empty_base_offsets);
darwin_align_is_first_member_of_class = 0;
if (abi_version_at_least (2))
record_subobject_offsets (TREE_TYPE (field),
byte_position(field),
empty_base_offsets,
1);
if (warn_abi
&& DECL_C_BIT_FIELD (field)
&& !last_field_was_bitfield
&& !integer_zerop (size_binop (TRUNC_MOD_EXPR,
DECL_FIELD_BIT_OFFSET (field),
bitsize_unit_node)))
cp_warning_at ("offset of `%D' is not ABI-compliant and may change in a future version of GCC",
field);
if (warn_abi
&& !tree_int_cst_equal (DECL_FIELD_OFFSET (field),
byte_position (field))
&& contains_empty_class_p (TREE_TYPE (field)))
cp_warning_at ("`%D' contains empty classes which may cause base "
"classes to be placed at different locations in a "
"future version of GCC",
field);
if (padding)
{
tree padding_field;
padding_field = build_decl (FIELD_DECL,
NULL_TREE,
char_type_node);
DECL_BIT_FIELD (padding_field) = 1;
DECL_SIZE (padding_field) = padding;
DECL_ALIGN (padding_field) = 1;
DECL_USER_ALIGN (padding_field) = 0;
layout_nonempty_base_or_field (rli, padding_field,
NULL_TREE,
empty_base_offsets);
}
last_field_was_bitfield = DECL_C_BIT_FIELD (field);
}
darwin_align_is_first_member_of_class = 0;
if (abi_version_at_least (2) && !integer_zerop (rli->bitpos))
{
rli->bitpos = round_up (rli->bitpos, BITS_PER_UNIT);
normalize_rli (rli);
}
if (!abi_version_at_least (2))
include_empty_classes(rli);
remove_zero_width_bit_fields (t);
if (CLASSTYPE_NON_POD_P (t) || CLASSTYPE_EMPTY_P (t))
{
base_t = make_node (TREE_CODE (t));
if (!abi_version_at_least (2) && CLASSTYPE_EMPTY_P (t))
{
TYPE_SIZE (base_t) = bitsize_zero_node;
TYPE_SIZE_UNIT (base_t) = size_zero_node;
if (warn_abi && !integer_zerop (rli_size_unit_so_far (rli)))
warning ("layout of classes derived from empty class `%T' "
"may change in a future version of GCC",
t);
}
else
{
tree eoc;
eoc = end_of_class (t, 0);
TYPE_SIZE_UNIT (base_t)
= size_binop (MAX_EXPR,
convert (sizetype,
size_binop (CEIL_DIV_EXPR,
rli_size_so_far (rli),
bitsize_int (BITS_PER_UNIT))),
eoc);
TYPE_SIZE (base_t)
= size_binop (MAX_EXPR,
rli_size_so_far (rli),
size_binop (MULT_EXPR,
convert (bitsizetype, eoc),
bitsize_int (BITS_PER_UNIT)));
}
TYPE_ALIGN (base_t) = rli->record_align;
TYPE_USER_ALIGN (base_t) = TYPE_USER_ALIGN (t);
next_field = &TYPE_FIELDS (base_t);
for (field = TYPE_FIELDS (t); field; field = TREE_CHAIN (field))
if (TREE_CODE (field) == FIELD_DECL)
{
*next_field = build_decl (FIELD_DECL,
DECL_NAME (field),
TREE_TYPE (field));
DECL_CONTEXT (*next_field) = base_t;
DECL_FIELD_OFFSET (*next_field) = DECL_FIELD_OFFSET (field);
DECL_FIELD_BIT_OFFSET (*next_field)
= DECL_FIELD_BIT_OFFSET (field);
next_field = &TREE_CHAIN (*next_field);
}
CLASSTYPE_AS_BASE (t) = base_t;
TYPE_CONTEXT (base_t) = t;
}
else
CLASSTYPE_AS_BASE (t) = t;
if (CLASSTYPE_EMPTY_P (t))
CLASSTYPE_CONTAINS_EMPTY_CLASS_P (t) = 1;
layout_decl (TYPE_MAIN_DECL (t), 0);
layout_virtual_bases (rli, empty_base_offsets);
include_empty_classes(rli);
if (integer_zerop (rli_size_unit_so_far (rli)) && CLASSTYPE_EMPTY_P (t))
place_field (rli,
build_decl (FIELD_DECL, NULL_TREE, char_type_node));
finish_record_layout (rli, true);
warn_about_ambiguous_bases (t);
splay_tree_delete (empty_base_offsets);
}
static tree
key_method (tree type)
{
tree method;
if (TYPE_FOR_JAVA (type)
|| processing_template_decl
|| CLASSTYPE_TEMPLATE_INSTANTIATION (type)
|| CLASSTYPE_INTERFACE_KNOWN (type))
return NULL_TREE;
for (method = TYPE_METHODS (type); method != NULL_TREE;
method = TREE_CHAIN (method))
if (DECL_VINDEX (method) != NULL_TREE
&& ! DECL_DECLARED_INLINE_P (method)
&& ! DECL_PURE_VIRTUAL_P (method))
return method;
return NULL_TREE;
}
void
finish_struct_1 (t)
tree t;
{
tree x;
tree virtuals = NULL_TREE;
int n_fields = 0;
tree vfield;
if (COMPLETE_TYPE_P (t))
{
if (IS_AGGR_TYPE (t))
error ("redefinition of `%#T'", t);
else
abort ();
popclass ();
return;
}
TYPE_SIZE (t) = NULL_TREE;
CLASSTYPE_GOT_SEMICOLON (t) = 0;
CLASSTYPE_PRIMARY_BINFO (t) = NULL_TREE;
fixup_inline_methods (t);
CLASSTYPE_EMPTY_P (t) = 1;
CLASSTYPE_NEARLY_EMPTY_P (t) = 1;
CLASSTYPE_CONTAINS_EMPTY_CLASS_P (t) = 0;
check_bases_and_members (t);
if (TYPE_CONTAINS_VPTR_P (t))
{
CLASSTYPE_KEY_METHOD (t) = key_method (t);
if (CLASSTYPE_KEY_METHOD (t) == NULL_TREE)
keyed_classes = tree_cons (NULL_TREE, t, keyed_classes);
}
layout_class_type (t, &virtuals);
vfield = TYPE_VFIELD (t);
if (vfield && CLASSTYPE_HAS_PRIMARY_BASE_P (t))
{
tree primary = CLASSTYPE_PRIMARY_BINFO (t);
my_friendly_assert (same_type_p (DECL_FIELD_CONTEXT (vfield),
BINFO_TYPE (primary)),
20010726);
my_friendly_assert (integer_zerop (DECL_FIELD_OFFSET (vfield)),
20010726);
my_friendly_assert (integer_zerop (BINFO_OFFSET (primary)),
20010726);
vfield = copy_decl (vfield);
DECL_FIELD_CONTEXT (vfield) = t;
TYPE_VFIELD (t) = vfield;
}
else
my_friendly_assert (!vfield || DECL_FIELD_CONTEXT (vfield) == t, 20010726);
virtuals = modify_all_vtables (t, nreverse (virtuals));
if (TYPE_VFIELD (t) && !CLASSTYPE_HAS_PRIMARY_BASE_P (t))
CLASSTYPE_VFIELDS (t)
= chainon (CLASSTYPE_VFIELDS (t), build_tree_list (NULL_TREE, t));
if (virtuals || TYPE_CONTAINS_VPTR_P (t))
{
if (!CLASSTYPE_HAS_PRIMARY_BASE_P (t))
build_primary_vtable (NULL_TREE, t);
else if (! BINFO_NEW_VTABLE_MARKED (TYPE_BINFO (t), t))
build_primary_vtable (CLASSTYPE_PRIMARY_BINFO (t), t);
}
if (TYPE_CONTAINS_VPTR_P (t))
{
int vindex;
tree fn;
if (TYPE_BINFO_VTABLE (t))
my_friendly_assert (DECL_VIRTUAL_P (TYPE_BINFO_VTABLE (t)),
20000116);
if (!CLASSTYPE_HAS_PRIMARY_BASE_P (t))
my_friendly_assert (TYPE_BINFO_VIRTUALS (t) == NULL_TREE,
20000116);
TYPE_BINFO_VIRTUALS (t) = chainon (TYPE_BINFO_VIRTUALS (t), virtuals);
for (vindex = 0, fn = BINFO_VIRTUALS (TYPE_BINFO (t));
fn;
fn = TREE_CHAIN (fn),
vindex += (TARGET_VTABLE_USES_DESCRIPTORS
? TARGET_VTABLE_USES_DESCRIPTORS : 1))
if (TREE_CODE (DECL_VINDEX (BV_FN (fn))) != INTEGER_CST)
DECL_VINDEX (BV_FN (fn)) = build_shared_int_cst (vindex);
}
finish_struct_bits (t);
for (x = TYPE_FIELDS (t); x; x = TREE_CHAIN (x))
if (TREE_CODE (x) == VAR_DECL && TREE_STATIC (x)
&& same_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (x)), t))
DECL_MODE (x) = TYPE_MODE (t);
n_fields = count_fields (TYPE_FIELDS (t));
if (n_fields > 7)
{
tree field_vec = make_tree_vec (n_fields);
add_fields_to_vec (TYPE_FIELDS (t), field_vec, 0);
qsort (&TREE_VEC_ELT (field_vec, 0), n_fields, sizeof (tree),
field_decl_cmp);
if (! DECL_LANG_SPECIFIC (TYPE_MAIN_DECL (t)))
retrofit_lang_decl (TYPE_MAIN_DECL (t));
DECL_SORTED_FIELDS (TYPE_MAIN_DECL (t)) = field_vec;
}
if (TYPE_HAS_CONSTRUCTOR (t))
{
tree vfields = CLASSTYPE_VFIELDS (t);
for (vfields = CLASSTYPE_VFIELDS (t);
vfields; vfields = TREE_CHAIN (vfields))
if (VF_BINFO_VALUE (vfields))
TREE_ADDRESSABLE (vfields) = 1;
}
finish_vtbls (t);
build_vtt (t);
if (warn_nonvdtor && TYPE_POLYMORPHIC_P (t) && TYPE_HAS_DESTRUCTOR (t)
&& DECL_VINDEX (TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (t), 1)) == NULL_TREE)
warning ("`%#T' has virtual functions but non-virtual destructor", t);
complete_vars (t);
if (warn_overloaded_virtual)
warn_hidden (t);
maybe_suppress_debug_info (t);
dump_class_hierarchy (t);
rest_of_type_compilation (t, ! LOCAL_CLASS_P (t));
}
void
unreverse_member_declarations (t)
tree t;
{
tree next;
tree prev;
tree x;
TYPE_METHODS (t) = nreverse (TYPE_METHODS (t));
CLASSTYPE_TAGS (t) = nreverse (CLASSTYPE_TAGS (t));
CLASSTYPE_DECL_LIST (t) = nreverse (CLASSTYPE_DECL_LIST (t));
prev = NULL_TREE;
for (x = TYPE_FIELDS (t);
x && TREE_CODE (x) != TYPE_DECL;
x = next)
{
next = TREE_CHAIN (x);
TREE_CHAIN (x) = prev;
prev = x;
}
if (prev)
{
TREE_CHAIN (TYPE_FIELDS (t)) = x;
if (prev)
TYPE_FIELDS (t) = prev;
}
}
tree
finish_struct (t, attributes)
tree t, attributes;
{
const char *saved_filename = input_filename;
int saved_lineno = lineno;
unreverse_member_declarations (t);
cplus_decl_attributes (&t, attributes, (int) ATTR_FLAG_TYPE_IN_PLACE);
input_filename = DECL_SOURCE_FILE (TYPE_NAME (t));
lineno = DECL_SOURCE_LINE (TYPE_NAME (t));
if (processing_template_decl)
{
finish_struct_methods (t);
TYPE_SIZE (t) = bitsize_zero_node;
}
else
finish_struct_1 (t);
input_filename = saved_filename;
lineno = saved_lineno;
TYPE_BEING_DEFINED (t) = 0;
if (current_class_type)
popclass ();
else
error ("trying to finish struct, but kicked out due to previous parse errors");
if (processing_template_decl && at_function_scope_p ())
add_stmt (build_min (TAG_DEFN, t));
return t;
}
static tree
fixed_type_or_null (instance, nonnull, cdtorp)
tree instance;
int *nonnull;
int *cdtorp;
{
switch (TREE_CODE (instance))
{
case INDIRECT_REF:
if (POINTER_TYPE_P (TREE_TYPE (instance)))
return NULL_TREE;
else
return fixed_type_or_null (TREE_OPERAND (instance, 0),
nonnull, cdtorp);
case CALL_EXPR:
if (TREE_HAS_CONSTRUCTOR (instance))
{
if (nonnull)
*nonnull = 1;
return TREE_TYPE (instance);
}
return NULL_TREE;
case SAVE_EXPR:
if (TREE_HAS_CONSTRUCTOR (instance))
{
if (nonnull)
*nonnull = 1;
return TREE_TYPE (instance);
}
return fixed_type_or_null (TREE_OPERAND (instance, 0), nonnull, cdtorp);
case RTL_EXPR:
return NULL_TREE;
case PLUS_EXPR:
case MINUS_EXPR:
if (TREE_CODE (TREE_OPERAND (instance, 0)) == ADDR_EXPR)
return fixed_type_or_null (TREE_OPERAND (instance, 0), nonnull, cdtorp);
if (TREE_CODE (TREE_OPERAND (instance, 1)) == INTEGER_CST)
return fixed_type_or_null (TREE_OPERAND (instance, 0), nonnull, cdtorp);
return NULL_TREE;
case NOP_EXPR:
case CONVERT_EXPR:
return fixed_type_or_null (TREE_OPERAND (instance, 0), nonnull, cdtorp);
case ADDR_EXPR:
if (nonnull)
*nonnull = 1;
return fixed_type_or_null (TREE_OPERAND (instance, 0), nonnull, cdtorp);
case COMPONENT_REF:
return fixed_type_or_null (TREE_OPERAND (instance, 1), nonnull, cdtorp);
case VAR_DECL:
case FIELD_DECL:
if (TREE_CODE (TREE_TYPE (instance)) == ARRAY_TYPE
&& IS_AGGR_TYPE (TREE_TYPE (TREE_TYPE (instance))))
{
if (nonnull)
*nonnull = 1;
return TREE_TYPE (TREE_TYPE (instance));
}
case TARGET_EXPR:
case PARM_DECL:
case RESULT_DECL:
if (IS_AGGR_TYPE (TREE_TYPE (instance)))
{
if (nonnull)
*nonnull = 1;
return TREE_TYPE (instance);
}
else if (instance == current_class_ptr)
{
if (nonnull)
*nonnull = 1;
if (DECL_LANG_SPECIFIC (current_function_decl)
&& (DECL_CONSTRUCTOR_P (current_function_decl)
|| DECL_DESTRUCTOR_P (current_function_decl)))
{
if (cdtorp)
*cdtorp = 1;
return TREE_TYPE (TREE_TYPE (instance));
}
}
else if (TREE_CODE (TREE_TYPE (instance)) == REFERENCE_TYPE)
{
if (nonnull)
*nonnull = 1;
if (TREE_CODE (instance) == VAR_DECL
&& DECL_INITIAL (instance))
return fixed_type_or_null (DECL_INITIAL (instance),
nonnull, cdtorp);
}
return NULL_TREE;
default:
return NULL_TREE;
}
}
int
resolves_to_fixed_type_p (instance, nonnull)
tree instance;
int *nonnull;
{
tree t = TREE_TYPE (instance);
int cdtorp = 0;
tree fixed = fixed_type_or_null (instance, nonnull, &cdtorp);
if (fixed == NULL_TREE)
return 0;
if (POINTER_TYPE_P (t))
t = TREE_TYPE (t);
if (!same_type_ignoring_top_level_qualifiers_p (t, fixed))
return 0;
return cdtorp ? -1 : 1;
}
void
init_class_processing ()
{
current_class_depth = 0;
current_class_stack_size = 10;
current_class_stack
= (class_stack_node_t) xmalloc (current_class_stack_size
* sizeof (struct class_stack_node));
VARRAY_TREE_INIT (local_classes, 8, "local_classes");
access_default_node = build_int_2 (0, 0);
access_public_node = build_int_2 (ak_public, 0);
access_protected_node = build_int_2 (ak_protected, 0);
access_private_node = build_int_2 (ak_private, 0);
access_default_virtual_node = build_int_2 (4, 0);
access_public_virtual_node = build_int_2 (4 | ak_public, 0);
access_protected_virtual_node = build_int_2 (4 | ak_protected, 0);
access_private_virtual_node = build_int_2 (4 | ak_private, 0);
ridpointers[(int) RID_PUBLIC] = access_public_node;
ridpointers[(int) RID_PRIVATE] = access_private_node;
ridpointers[(int) RID_PROTECTED] = access_protected_node;
}
void
pushclass (type, modify)
tree type;
int modify;
{
type = TYPE_MAIN_VARIANT (type);
if (current_class_depth + 1 >= current_class_stack_size)
{
current_class_stack_size *= 2;
current_class_stack
= (class_stack_node_t) xrealloc (current_class_stack,
current_class_stack_size
* sizeof (struct class_stack_node));
}
current_class_stack[current_class_depth].name = current_class_name;
current_class_stack[current_class_depth].type = current_class_type;
current_class_stack[current_class_depth].access = current_access_specifier;
current_class_stack[current_class_depth].names_used = 0;
current_class_depth++;
current_class_name = TYPE_NAME (type);
if (TREE_CODE (current_class_name) == TYPE_DECL)
current_class_name = DECL_NAME (current_class_name);
current_class_type = type;
current_access_specifier = (CLASSTYPE_DECLARED_CLASS (type)
? access_private_node
: access_public_node);
if (previous_class_type != NULL_TREE
&& (type != previous_class_type
|| !COMPLETE_TYPE_P (previous_class_type))
&& current_class_depth == 1)
{
invalidate_class_lookup_cache ();
}
if (modify && current_class_depth > 1)
clear_identifier_class_values ();
pushlevel_class ();
if (modify)
{
if (type != previous_class_type || current_class_depth > 1)
push_class_decls (type);
else
{
tree item;
set_class_shadows (previous_class_values);
for (item = previous_class_values; item; item = TREE_CHAIN (item))
{
tree id = TREE_PURPOSE (item);
tree decl = TREE_TYPE (item);
push_class_binding (id, decl);
if (TREE_CODE (decl) == TYPE_DECL)
set_identifier_type_value (id, TREE_TYPE (decl));
}
unuse_fields (type);
}
storetags (CLASSTYPE_TAGS (type));
}
}
void
invalidate_class_lookup_cache ()
{
tree t;
for (t = previous_class_values; t; t = TREE_CHAIN (t))
IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (t)) = NULL_TREE;
previous_class_values = NULL_TREE;
previous_class_type = NULL_TREE;
}
void
popclass ()
{
poplevel_class ();
pop_class_decls ();
current_class_depth--;
current_class_name = current_class_stack[current_class_depth].name;
current_class_type = current_class_stack[current_class_depth].type;
current_access_specifier = current_class_stack[current_class_depth].access;
if (current_class_stack[current_class_depth].names_used)
splay_tree_delete (current_class_stack[current_class_depth].names_used);
}
int
currently_open_class (t)
tree t;
{
int i;
if (t == current_class_type)
return 1;
for (i = 1; i < current_class_depth; ++i)
if (current_class_stack [i].type == t)
return 1;
return 0;
}
tree
currently_open_derived_class (t)
tree t;
{
int i;
if (DERIVED_FROM_P (t, current_class_type))
return current_class_type;
for (i = current_class_depth - 1; i > 0; --i)
if (DERIVED_FROM_P (t, current_class_stack[i].type))
return current_class_stack[i].type;
return NULL_TREE;
}
void
push_nested_class (type, modify)
tree type;
int modify;
{
tree context;
if (type == NULL_TREE
|| type == error_mark_node
|| TREE_CODE (type) == NAMESPACE_DECL
|| ! IS_AGGR_TYPE (type)
|| TREE_CODE (type) == TEMPLATE_TYPE_PARM
|| TREE_CODE (type) == BOUND_TEMPLATE_TEMPLATE_PARM)
return;
context = DECL_CONTEXT (TYPE_MAIN_DECL (type));
if (context && CLASS_TYPE_P (context))
push_nested_class (context, 2);
pushclass (type, modify);
}
void
pop_nested_class ()
{
tree context = DECL_CONTEXT (TYPE_MAIN_DECL (current_class_type));
popclass ();
if (context && CLASS_TYPE_P (context))
pop_nested_class ();
}
int
current_lang_depth ()
{
return VARRAY_ACTIVE_SIZE (current_lang_base);
}
void
push_lang_context (name)
tree name;
{
VARRAY_PUSH_TREE (current_lang_base, current_lang_name);
if (name == lang_name_cplusplus)
{
current_lang_name = name;
}
else if (name == lang_name_java)
{
current_lang_name = name;
DECL_IGNORED_P (TYPE_NAME (java_byte_type_node)) = 0;
DECL_IGNORED_P (TYPE_NAME (java_short_type_node)) = 0;
DECL_IGNORED_P (TYPE_NAME (java_int_type_node)) = 0;
DECL_IGNORED_P (TYPE_NAME (java_long_type_node)) = 0;
DECL_IGNORED_P (TYPE_NAME (java_float_type_node)) = 0;
DECL_IGNORED_P (TYPE_NAME (java_double_type_node)) = 0;
DECL_IGNORED_P (TYPE_NAME (java_char_type_node)) = 0;
DECL_IGNORED_P (TYPE_NAME (java_boolean_type_node)) = 0;
}
else if (name == lang_name_c)
{
current_lang_name = name;
}
else if (name == lang_name_objc)
{
current_lang_name = lang_name_c;
}
else
error ("language string `\"%s\"' not recognized", IDENTIFIER_POINTER (name));
}
void
pop_lang_context ()
{
current_lang_name = VARRAY_TOP_TREE (current_lang_base);
VARRAY_POP (current_lang_base);
}
static tree
resolve_address_of_overloaded_function (target_type,
overload,
complain,
ptrmem,
template_only,
explicit_targs)
tree target_type;
tree overload;
int complain;
int ptrmem;
int template_only;
tree explicit_targs;
{
int is_ptrmem = 0;
int is_reference = 0;
tree matches = NULL_TREE;
tree fn;
my_friendly_assert (!(TREE_CODE (target_type) == POINTER_TYPE
&& (TREE_CODE (TREE_TYPE (target_type))
== METHOD_TYPE)), 0);
if (TREE_CODE (overload) == COMPONENT_REF)
overload = TREE_OPERAND (overload, 1);
if (TYPE_PTRFN_P (target_type))
;
else if (TYPE_PTRMEMFUNC_P (target_type))
is_ptrmem = 1;
else if (TREE_CODE (target_type) == FUNCTION_TYPE)
{
target_type = build_reference_type (target_type);
is_reference = 1;
}
else
{
if (complain)
error ("\
cannot resolve overloaded function `%D' based on conversion to type `%T'",
DECL_NAME (OVL_FUNCTION (overload)), target_type);
return error_mark_node;
}
if (!template_only)
{
tree fns;
for (fns = overload; fns; fns = OVL_CHAIN (fns))
{
tree fn = OVL_FUNCTION (fns);
tree fntype;
if (TREE_CODE (fn) == TEMPLATE_DECL)
continue;
if ((TREE_CODE (TREE_TYPE (fn)) == METHOD_TYPE)
!= is_ptrmem)
continue;
fntype = TREE_TYPE (fn);
if (is_ptrmem)
fntype = build_ptrmemfunc_type (build_pointer_type (fntype));
else if (!is_reference)
fntype = build_pointer_type (fntype);
if (can_convert_arg (target_type, fntype, fn))
matches = tree_cons (fn, NULL_TREE, matches);
}
}
if (!matches)
{
tree target_fn_type;
tree target_arg_types;
tree target_ret_type;
tree fns;
if (is_ptrmem)
target_fn_type
= TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (target_type));
else
target_fn_type = TREE_TYPE (target_type);
target_arg_types = TYPE_ARG_TYPES (target_fn_type);
target_ret_type = TREE_TYPE (target_fn_type);
if (TREE_CODE (target_fn_type) == METHOD_TYPE)
target_arg_types = TREE_CHAIN (target_arg_types);
for (fns = overload; fns; fns = OVL_CHAIN (fns))
{
tree fn = OVL_FUNCTION (fns);
tree instantiation;
tree instantiation_type;
tree targs;
if (TREE_CODE (fn) != TEMPLATE_DECL)
continue;
if ((TREE_CODE (TREE_TYPE (fn)) == METHOD_TYPE)
!= is_ptrmem)
continue;
targs = make_tree_vec (DECL_NTPARMS (fn));
if (fn_type_unification (fn, explicit_targs, targs,
target_arg_types, target_ret_type,
DEDUCE_EXACT, -1) != 0)
continue;
instantiation = instantiate_template (fn, targs);
if (instantiation == error_mark_node)
continue;
instantiation_type = TREE_TYPE (instantiation);
if (is_ptrmem)
instantiation_type =
build_ptrmemfunc_type (build_pointer_type (instantiation_type));
else if (!is_reference)
instantiation_type = build_pointer_type (instantiation_type);
if (can_convert_arg (target_type, instantiation_type, instantiation))
matches = tree_cons (instantiation, fn, matches);
}
if (matches)
{
tree match = most_specialized_instantiation (matches);
if (match != error_mark_node)
matches = tree_cons (match, NULL_TREE, NULL_TREE);
}
}
if (matches == NULL_TREE)
{
if (complain)
{
error ("no matches converting function `%D' to type `%#T'",
DECL_NAME (OVL_FUNCTION (overload)),
target_type);
for (; overload; overload = OVL_NEXT (overload))
matches = tree_cons (NULL_TREE, OVL_CURRENT (overload),
matches);
print_candidates (matches);
}
return error_mark_node;
}
else if (TREE_CHAIN (matches))
{
if (complain)
{
tree match;
error ("converting overloaded function `%D' to type `%#T' is ambiguous",
DECL_NAME (OVL_FUNCTION (overload)),
target_type);
for (match = matches; match; match = TREE_CHAIN (match))
TREE_VALUE (match) = TREE_PURPOSE (match);
print_candidates (matches);
}
return error_mark_node;
}
fn = TREE_PURPOSE (matches);
if (DECL_NONSTATIC_MEMBER_FUNCTION_P (fn)
&& !ptrmem && !flag_ms_extensions)
{
static int explained;
if (!complain)
return error_mark_node;
pedwarn ("assuming pointer to member `%D'", fn);
if (!explained)
{
pedwarn ("(a pointer to member can only be formed with `&%E')", fn);
explained = 1;
}
}
mark_used (fn);
if (TYPE_PTRFN_P (target_type) || TYPE_PTRMEMFUNC_P (target_type))
return build_unary_op (ADDR_EXPR, fn, 0);
else
{
cxx_mark_addressable (fn);
return fn;
}
}
tree
instantiate_type (lhstype, rhs, flags)
tree lhstype, rhs;
tsubst_flags_t flags;
{
int complain = (flags & tf_error);
int strict = (flags & tf_no_attributes)
? COMPARE_NO_ATTRIBUTES : COMPARE_STRICT;
int allow_ptrmem = flags & tf_ptrmem_ok;
flags &= ~tf_ptrmem_ok;
if (TREE_CODE (lhstype) == UNKNOWN_TYPE)
{
if (complain)
error ("not enough type information");
return error_mark_node;
}
if (TREE_TYPE (rhs) != NULL_TREE && ! (type_unknown_p (rhs)))
{
if (comptypes (lhstype, TREE_TYPE (rhs), strict))
return rhs;
if (complain)
error ("argument of type `%T' does not match `%T'",
TREE_TYPE (rhs), lhstype);
return error_mark_node;
}
if (TREE_CODE (rhs) == BASELINK)
rhs = BASELINK_FUNCTIONS (rhs);
if (TREE_CODE (rhs) != OVERLOAD)
rhs = copy_node (rhs);
switch (TREE_CODE (rhs))
{
case TYPE_EXPR:
case CONVERT_EXPR:
case SAVE_EXPR:
case CONSTRUCTOR:
case BUFFER_REF:
abort ();
return error_mark_node;
case INDIRECT_REF:
case ARRAY_REF:
{
tree new_rhs;
new_rhs = instantiate_type (build_pointer_type (lhstype),
TREE_OPERAND (rhs, 0), flags);
if (new_rhs == error_mark_node)
return error_mark_node;
TREE_TYPE (rhs) = lhstype;
TREE_OPERAND (rhs, 0) = new_rhs;
return rhs;
}
case NOP_EXPR:
rhs = copy_node (TREE_OPERAND (rhs, 0));
TREE_TYPE (rhs) = unknown_type_node;
return instantiate_type (lhstype, rhs, flags);
case COMPONENT_REF:
return instantiate_type (lhstype, TREE_OPERAND (rhs, 1), flags);
case OFFSET_REF:
rhs = TREE_OPERAND (rhs, 1);
if (BASELINK_P (rhs))
return instantiate_type (lhstype, BASELINK_FUNCTIONS (rhs),
flags | allow_ptrmem);
my_friendly_assert (TREE_CODE (rhs) == TEMPLATE_ID_EXPR, 0);
case TEMPLATE_ID_EXPR:
{
tree fns = TREE_OPERAND (rhs, 0);
tree args = TREE_OPERAND (rhs, 1);
return
resolve_address_of_overloaded_function (lhstype,
fns,
complain,
allow_ptrmem,
1,
args);
}
case OVERLOAD:
return
resolve_address_of_overloaded_function (lhstype,
rhs,
complain,
allow_ptrmem,
0,
NULL_TREE);
case TREE_LIST:
my_friendly_assert (BASELINK_P (rhs), 990412);
return instantiate_type (lhstype, BASELINK_FUNCTIONS (rhs), flags);
case CALL_EXPR:
abort ();
return error_mark_node;
case PLUS_EXPR:
case MINUS_EXPR:
case COMPOUND_EXPR:
TREE_OPERAND (rhs, 0)
= instantiate_type (lhstype, TREE_OPERAND (rhs, 0), flags);
if (TREE_OPERAND (rhs, 0) == error_mark_node)
return error_mark_node;
TREE_OPERAND (rhs, 1)
= instantiate_type (lhstype, TREE_OPERAND (rhs, 1), flags);
if (TREE_OPERAND (rhs, 1) == error_mark_node)
return error_mark_node;
TREE_TYPE (rhs) = lhstype;
return rhs;
case MULT_EXPR:
case TRUNC_DIV_EXPR:
case FLOOR_DIV_EXPR:
case CEIL_DIV_EXPR:
case ROUND_DIV_EXPR:
case RDIV_EXPR:
case TRUNC_MOD_EXPR:
case FLOOR_MOD_EXPR:
case CEIL_MOD_EXPR:
case ROUND_MOD_EXPR:
case FIX_ROUND_EXPR:
case FIX_FLOOR_EXPR:
case FIX_CEIL_EXPR:
case FIX_TRUNC_EXPR:
case FLOAT_EXPR:
case NEGATE_EXPR:
case ABS_EXPR:
case MAX_EXPR:
case MIN_EXPR:
case FFS_EXPR:
case BIT_AND_EXPR:
case BIT_IOR_EXPR:
case BIT_XOR_EXPR:
case LSHIFT_EXPR:
case RSHIFT_EXPR:
case LROTATE_EXPR:
case RROTATE_EXPR:
case PREINCREMENT_EXPR:
case PREDECREMENT_EXPR:
case POSTINCREMENT_EXPR:
case POSTDECREMENT_EXPR:
if (complain)
error ("invalid operation on uninstantiated type");
return error_mark_node;
case TRUTH_AND_EXPR:
case TRUTH_OR_EXPR:
case TRUTH_XOR_EXPR:
case LT_EXPR:
case LE_EXPR:
case GT_EXPR:
case GE_EXPR:
case EQ_EXPR:
case NE_EXPR:
case TRUTH_ANDIF_EXPR:
case TRUTH_ORIF_EXPR:
case TRUTH_NOT_EXPR:
if (complain)
error ("not enough type information");
return error_mark_node;
case COND_EXPR:
if (type_unknown_p (TREE_OPERAND (rhs, 0)))
{
if (complain)
error ("not enough type information");
return error_mark_node;
}
TREE_OPERAND (rhs, 1)
= instantiate_type (lhstype, TREE_OPERAND (rhs, 1), flags);
if (TREE_OPERAND (rhs, 1) == error_mark_node)
return error_mark_node;
TREE_OPERAND (rhs, 2)
= instantiate_type (lhstype, TREE_OPERAND (rhs, 2), flags);
if (TREE_OPERAND (rhs, 2) == error_mark_node)
return error_mark_node;
TREE_TYPE (rhs) = lhstype;
return rhs;
case MODIFY_EXPR:
TREE_OPERAND (rhs, 1)
= instantiate_type (lhstype, TREE_OPERAND (rhs, 1), flags);
if (TREE_OPERAND (rhs, 1) == error_mark_node)
return error_mark_node;
TREE_TYPE (rhs) = lhstype;
return rhs;
case ADDR_EXPR:
{
if (PTRMEM_OK_P (rhs))
flags |= tf_ptrmem_ok;
return instantiate_type (lhstype, TREE_OPERAND (rhs, 0), flags);
}
case ENTRY_VALUE_EXPR:
abort ();
return error_mark_node;
case ERROR_MARK:
return error_mark_node;
default:
abort ();
return error_mark_node;
}
}
static tree
get_vfield_name (type)
tree type;
{
tree binfo = TYPE_BINFO (type);
char *buf;
while (BINFO_BASETYPES (binfo)
&& TYPE_CONTAINS_VPTR_P (BINFO_TYPE (BINFO_BASETYPE (binfo, 0)))
&& ! TREE_VIA_VIRTUAL (BINFO_BASETYPE (binfo, 0)))
binfo = BINFO_BASETYPE (binfo, 0);
type = BINFO_TYPE (binfo);
buf = (char *) alloca (sizeof (VFIELD_NAME_FORMAT)
+ TYPE_NAME_LENGTH (type) + 2);
sprintf (buf, VFIELD_NAME_FORMAT,
IDENTIFIER_POINTER (constructor_name (type)));
return get_identifier (buf);
}
void
print_class_statistics ()
{
#ifdef GATHER_STATISTICS
fprintf (stderr, "convert_harshness = %d\n", n_convert_harshness);
fprintf (stderr, "compute_conversion_costs = %d\n", n_compute_conversion_costs);
fprintf (stderr, "build_method_call = %d (inner = %d)\n",
n_build_method_call, n_inner_fields_searched);
if (n_vtables)
{
fprintf (stderr, "vtables = %d; vtable searches = %d\n",
n_vtables, n_vtable_searches);
fprintf (stderr, "vtable entries = %d; vtable elems = %d\n",
n_vtable_entries, n_vtable_elems);
}
#endif
}
void
build_self_reference ()
{
tree name = constructor_name (current_class_type);
tree value = build_lang_decl (TYPE_DECL, name, current_class_type);
tree saved_cas;
DECL_NONLOCAL (value) = 1;
DECL_CONTEXT (value) = current_class_type;
DECL_ARTIFICIAL (value) = 1;
if (processing_template_decl)
value = push_template_decl (value);
saved_cas = current_access_specifier;
current_access_specifier = access_public_node;
finish_member_declaration (value);
current_access_specifier = saved_cas;
}
int
is_empty_class (type)
tree type;
{
if (type == error_mark_node)
return 0;
if (! IS_AGGR_TYPE (type))
return 0;
if (abi_version_at_least (2))
return CLASSTYPE_EMPTY_P (type);
else
return integer_zerop (CLASSTYPE_SIZE (type));
}
static bool
contains_empty_class_p (tree type)
{
if (is_empty_class (type))
return true;
if (CLASS_TYPE_P (type))
{
tree field;
int i;
for (i = 0; i < CLASSTYPE_N_BASECLASSES (type); ++i)
if (contains_empty_class_p (TYPE_BINFO_BASETYPE (type, i)))
return true;
for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
if (TREE_CODE (field) == FIELD_DECL
&& !DECL_ARTIFICIAL (field)
&& is_empty_class (TREE_TYPE (field)))
return true;
}
else if (TREE_CODE (type) == ARRAY_TYPE)
return contains_empty_class_p (TREE_TYPE (type));
return false;
}
tree
get_enclosing_class (type)
tree type;
{
tree node = type;
while (node && TREE_CODE (node) != NAMESPACE_DECL)
{
switch (TREE_CODE_CLASS (TREE_CODE (node)))
{
case 'd':
node = DECL_CONTEXT (node);
break;
case 't':
if (node != type)
return node;
node = TYPE_CONTEXT (node);
break;
default:
abort ();
}
}
return NULL_TREE;
}
int
is_base_of_enclosing_class (base, type)
tree base, type;
{
while (type)
{
if (lookup_base (type, base, ba_any, NULL))
return 1;
type = get_enclosing_class (type);
}
return 0;
}
void
maybe_note_name_used_in_class (name, decl)
tree name;
tree decl;
{
splay_tree names_used;
if (!current_class_type || !TYPE_BEING_DEFINED (current_class_type))
return;
if (IDENTIFIER_CLASS_VALUE (name))
return;
if (!current_class_stack[current_class_depth - 1].names_used)
current_class_stack[current_class_depth - 1].names_used
= splay_tree_new (splay_tree_compare_pointers, 0, 0);
names_used = current_class_stack[current_class_depth - 1].names_used;
splay_tree_insert (names_used,
(splay_tree_key) name,
(splay_tree_value) decl);
}
void
note_name_declared_in_class (name, decl)
tree name;
tree decl;
{
splay_tree names_used;
splay_tree_node n;
names_used
= current_class_stack[current_class_depth - 1].names_used;
if (!names_used)
return;
n = splay_tree_lookup (names_used, (splay_tree_key) name);
if (n)
{
error ("declaration of `%#D'", decl);
cp_error_at ("changes meaning of `%D' from `%+#D'",
DECL_NAME (OVL_CURRENT (decl)),
(tree) n->value);
}
}
tree
get_vtbl_decl_for_binfo (binfo)
tree binfo;
{
tree decl;
decl = BINFO_VTABLE (binfo);
if (decl && TREE_CODE (decl) == PLUS_EXPR)
{
my_friendly_assert (TREE_CODE (TREE_OPERAND (decl, 0)) == ADDR_EXPR,
2000403);
decl = TREE_OPERAND (TREE_OPERAND (decl, 0), 0);
}
if (decl)
my_friendly_assert (TREE_CODE (decl) == VAR_DECL, 20000403);
return decl;
}
static tree
dfs_get_primary_binfo (binfo, data)
tree binfo;
void *data;
{
tree cons = (tree) data;
tree primary_base = TREE_PURPOSE (cons);
if (TREE_VIA_VIRTUAL (binfo)
&& same_type_p (BINFO_TYPE (binfo), primary_base))
TREE_VALUE (cons) = tree_cons (NULL, binfo, TREE_VALUE (cons));
return NULL_TREE;
}
tree
get_primary_binfo (binfo)
tree binfo;
{
tree primary_base;
tree result = NULL_TREE;
tree virtuals;
primary_base = CLASSTYPE_PRIMARY_BINFO (BINFO_TYPE (binfo));
if (!primary_base)
return NULL_TREE;
if (!TREE_VIA_VIRTUAL (primary_base))
{
int i;
for (i = 0; i < BINFO_N_BASETYPES (binfo); ++i)
{
tree base_binfo = BINFO_BASETYPE (binfo, i);
if (same_type_p (BINFO_TYPE (base_binfo),
BINFO_TYPE (primary_base)))
return base_binfo;
}
abort ();
}
virtuals = build_tree_list (BINFO_TYPE (primary_base), NULL_TREE);
dfs_walk (binfo, dfs_get_primary_binfo, NULL, virtuals);
virtuals = TREE_VALUE (virtuals);
my_friendly_assert (virtuals, 20010612);
if (TREE_CHAIN (virtuals))
{
tree complete_binfo;
tree canonical;
for (complete_binfo = binfo;
BINFO_INHERITANCE_CHAIN (complete_binfo);
complete_binfo = BINFO_INHERITANCE_CHAIN (complete_binfo))
continue;
canonical = binfo_for_vbase (BINFO_TYPE (primary_base),
BINFO_TYPE (complete_binfo));
for (; virtuals; virtuals = TREE_CHAIN (virtuals))
{
result = TREE_VALUE (virtuals);
if (canonical == result)
{
my_friendly_assert (!TREE_CHAIN (virtuals), 20010612);
break;
}
}
}
else
result = TREE_VALUE (virtuals);
return result;
}
static int
maybe_indent_hierarchy (stream, indent, indented_p)
FILE *stream;
int indent;
int indented_p;
{
if (!indented_p)
fprintf (stream, "%*s", indent, "");
return 1;
}
static void
dump_class_hierarchy_r (stream, flags, t, binfo, indent)
FILE *stream;
int flags;
tree t;
tree binfo;
int indent;
{
int i;
int indented = 0;
indented = maybe_indent_hierarchy (stream, indent, 0);
fprintf (stream, "%s (0x%lx) ",
type_as_string (binfo, TFF_PLAIN_IDENTIFIER),
(unsigned long) binfo);
fprintf (stream, HOST_WIDE_INT_PRINT_DEC,
tree_low_cst (BINFO_OFFSET (binfo), 0));
if (is_empty_class (BINFO_TYPE (binfo)))
fprintf (stream, " empty");
else if (CLASSTYPE_NEARLY_EMPTY_P (BINFO_TYPE (binfo)))
fprintf (stream, " nearly-empty");
if (TREE_VIA_VIRTUAL (binfo))
{
tree canonical = binfo_for_vbase (BINFO_TYPE (binfo), t);
fprintf (stream, " virtual");
if (canonical == binfo)
fprintf (stream, " canonical");
else
fprintf (stream, " non-canonical");
}
fprintf (stream, "\n");
indented = 0;
if (BINFO_PRIMARY_BASE_OF (binfo))
{
indented = maybe_indent_hierarchy (stream, indent + 3, indented);
fprintf (stream, " primary-for %s (0x%lx)",
type_as_string (BINFO_PRIMARY_BASE_OF (binfo),
TFF_PLAIN_IDENTIFIER),
(unsigned long)BINFO_PRIMARY_BASE_OF (binfo));
}
if (BINFO_LOST_PRIMARY_P (binfo))
{
indented = maybe_indent_hierarchy (stream, indent + 3, indented);
fprintf (stream, " lost-primary");
}
if (indented)
fprintf (stream, "\n");
if (!(flags & TDF_SLIM))
{
int indented = 0;
if (BINFO_SUBVTT_INDEX (binfo))
{
indented = maybe_indent_hierarchy (stream, indent + 3, indented);
fprintf (stream, " subvttidx=%s",
expr_as_string (BINFO_SUBVTT_INDEX (binfo),
TFF_PLAIN_IDENTIFIER));
}
if (BINFO_VPTR_INDEX (binfo))
{
indented = maybe_indent_hierarchy (stream, indent + 3, indented);
fprintf (stream, " vptridx=%s",
expr_as_string (BINFO_VPTR_INDEX (binfo),
TFF_PLAIN_IDENTIFIER));
}
if (BINFO_VPTR_FIELD (binfo))
{
indented = maybe_indent_hierarchy (stream, indent + 3, indented);
fprintf (stream, " vbaseoffset=%s",
expr_as_string (BINFO_VPTR_FIELD (binfo),
TFF_PLAIN_IDENTIFIER));
}
if (BINFO_VTABLE (binfo))
{
indented = maybe_indent_hierarchy (stream, indent + 3, indented);
fprintf (stream, " vptr=%s",
expr_as_string (BINFO_VTABLE (binfo),
TFF_PLAIN_IDENTIFIER));
}
if (indented)
fprintf (stream, "\n");
}
for (i = 0; i < BINFO_N_BASETYPES (binfo); ++i)
dump_class_hierarchy_r (stream, flags,
t, BINFO_BASETYPE (binfo, i),
indent + 2);
}
static void
dump_class_hierarchy (t)
tree t;
{
int flags;
FILE *stream = dump_begin (TDI_class, &flags);
if (!stream)
return;
fprintf (stream, "Class %s\n", type_as_string (t, TFF_PLAIN_IDENTIFIER));
fprintf (stream, " size=%lu align=%lu\n",
(unsigned long)(tree_low_cst (TYPE_SIZE (t), 0) / BITS_PER_UNIT),
(unsigned long)(TYPE_ALIGN (t) / BITS_PER_UNIT));
dump_class_hierarchy_r (stream, flags, t, TYPE_BINFO (t), 0);
fprintf (stream, "\n");
dump_end (TDI_class, stream);
}
static void
dump_array (stream, decl)
FILE *stream;
tree decl;
{
tree inits;
int ix;
HOST_WIDE_INT elt;
tree size = TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (decl)));
elt = (tree_low_cst (TYPE_SIZE (TREE_TYPE (TREE_TYPE (decl))), 0)
/ BITS_PER_UNIT);
fprintf (stream, "%s:", decl_as_string (decl, TFF_PLAIN_IDENTIFIER));
fprintf (stream, " %s entries",
expr_as_string (size_binop (PLUS_EXPR, size, size_one_node),
TFF_PLAIN_IDENTIFIER));
fprintf (stream, "\n");
for (ix = 0, inits = TREE_OPERAND (DECL_INITIAL (decl), 1);
inits; ix++, inits = TREE_CHAIN (inits))
fprintf (stream, "%-4ld %s\n", (long)(ix * elt),
expr_as_string (TREE_VALUE (inits), TFF_PLAIN_IDENTIFIER));
}
static void
dump_vtable (t, binfo, vtable)
tree t;
tree binfo;
tree vtable;
{
int flags;
FILE *stream = dump_begin (TDI_class, &flags);
if (!stream)
return;
if (!(flags & TDF_SLIM))
{
int ctor_vtbl_p = TYPE_BINFO (t) != binfo;
fprintf (stream, "%s for %s",
ctor_vtbl_p ? "Construction vtable" : "Vtable",
type_as_string (binfo, TFF_PLAIN_IDENTIFIER));
if (ctor_vtbl_p)
{
if (!TREE_VIA_VIRTUAL (binfo))
fprintf (stream, " (0x%lx instance)", (unsigned long)binfo);
fprintf (stream, " in %s", type_as_string (t, TFF_PLAIN_IDENTIFIER));
}
fprintf (stream, "\n");
dump_array (stream, vtable);
fprintf (stream, "\n");
}
dump_end (TDI_class, stream);
}
static void
dump_vtt (t, vtt)
tree t;
tree vtt;
{
int flags;
FILE *stream = dump_begin (TDI_class, &flags);
if (!stream)
return;
if (!(flags & TDF_SLIM))
{
fprintf (stream, "VTT for %s\n",
type_as_string (t, TFF_PLAIN_IDENTIFIER));
dump_array (stream, vtt);
fprintf (stream, "\n");
}
dump_end (TDI_class, stream);
}
static void
finish_vtbls (t)
tree t;
{
tree list;
tree vbase;
int i;
list = build_tree_list (TYPE_BINFO_VTABLE (t), NULL_TREE);
accumulate_vtbl_inits (TYPE_BINFO (t), TYPE_BINFO (t),
TYPE_BINFO (t), t, list);
for (vbase = TYPE_BINFO (t); vbase; vbase = TREE_CHAIN (vbase))
{
tree real_base;
if (!TREE_VIA_VIRTUAL (vbase))
continue;
real_base = binfo_for_vbase (BINFO_TYPE (vbase), t);
accumulate_vtbl_inits (real_base, real_base,
TYPE_BINFO (t), t, list);
}
for (i = 0; i < BINFO_N_BASETYPES (TYPE_BINFO (t)); ++i)
{
tree base = BINFO_BASETYPE (TYPE_BINFO (t), i);
if (TREE_VIA_VIRTUAL (base))
{
vbase = binfo_for_vbase (BINFO_TYPE (base), t);
BINFO_VPTR_FIELD (base) = BINFO_VPTR_FIELD (vbase);
}
}
if (TYPE_BINFO_VTABLE (t))
initialize_vtable (TYPE_BINFO (t), TREE_VALUE (list));
}
static void
initialize_vtable (binfo, inits)
tree binfo;
tree inits;
{
tree decl;
layout_vtable_decl (binfo, list_length (inits));
decl = get_vtbl_decl_for_binfo (binfo);
initialize_array (decl, inits);
dump_vtable (BINFO_TYPE (binfo), binfo, decl);
}
static void
initialize_array (decl, inits)
tree decl;
tree inits;
{
tree context;
context = DECL_CONTEXT (decl);
DECL_CONTEXT (decl) = NULL_TREE;
DECL_INITIAL (decl) = build_nt (CONSTRUCTOR, NULL_TREE, inits);
TREE_HAS_CONSTRUCTOR (DECL_INITIAL (decl)) = 1;
cp_finish_decl (decl, DECL_INITIAL (decl), NULL_TREE, 0);
DECL_CONTEXT (decl) = context;
}
static void
build_vtt (t)
tree t;
{
tree inits;
tree type;
tree vtt;
tree index;
inits = NULL_TREE;
index = size_zero_node;
build_vtt_inits (TYPE_BINFO (t), t, &inits, &index);
if (!inits)
return;
type = build_index_type (size_int (list_length (inits) - 1));
type = build_cplus_array_type (const_ptr_type_node, type);
vtt = build_vtable (t, get_vtt_name (t), type);
initialize_array (vtt, inits);
TREE_CHAIN (vtt) = TREE_CHAIN (CLASSTYPE_VTABLES (t));
TREE_CHAIN (CLASSTYPE_VTABLES (t)) = vtt;
dump_vtt (t, vtt);
}
static tree
get_original_base (base_binfo, binfo)
tree base_binfo;
tree binfo;
{
tree derived;
int ix;
if (same_type_p (BINFO_TYPE (base_binfo), BINFO_TYPE (binfo)))
return binfo;
if (TREE_VIA_VIRTUAL (base_binfo))
return binfo_for_vbase (BINFO_TYPE (base_binfo), BINFO_TYPE (binfo));
derived = get_original_base (BINFO_INHERITANCE_CHAIN (base_binfo), binfo);
for (ix = 0; ix != BINFO_N_BASETYPES (derived); ix++)
if (same_type_p (BINFO_TYPE (base_binfo),
BINFO_TYPE (BINFO_BASETYPE (derived, ix))))
return BINFO_BASETYPE (derived, ix);
abort ();
return NULL;
}
static tree
binfo_ctor_vtable (binfo)
tree binfo;
{
tree vt;
while (1)
{
vt = BINFO_VTABLE (binfo);
if (TREE_CODE (vt) == TREE_LIST)
vt = TREE_VALUE (vt);
if (TREE_CODE (vt) == TREE_VEC)
binfo = vt;
else
break;
}
return vt;
}
static tree *
build_vtt_inits (binfo, t, inits, index)
tree binfo;
tree t;
tree *inits;
tree *index;
{
int i;
tree b;
tree init;
tree secondary_vptrs;
int top_level_p = same_type_p (TREE_TYPE (binfo), t);
if (!TYPE_USES_VIRTUAL_BASECLASSES (BINFO_TYPE (binfo)))
return inits;
if (!top_level_p)
{
build_ctor_vtbl_group (binfo, t);
BINFO_SUBVTT_INDEX (binfo) = *index;
}
init = binfo_ctor_vtable (binfo);
*inits = build_tree_list (NULL_TREE, init);
inits = &TREE_CHAIN (*inits);
if (top_level_p)
{
my_friendly_assert (!BINFO_VPTR_INDEX (binfo), 20010129);
BINFO_VPTR_INDEX (binfo) = *index;
}
*index = size_binop (PLUS_EXPR, *index, TYPE_SIZE_UNIT (ptr_type_node));
for (i = 0; i < BINFO_N_BASETYPES (binfo); ++i)
{
b = BINFO_BASETYPE (binfo, i);
if (!TREE_VIA_VIRTUAL (b))
inits = build_vtt_inits (BINFO_BASETYPE (binfo, i), t,
inits, index);
}
secondary_vptrs = tree_cons (t, NULL_TREE, BINFO_TYPE (binfo));
TREE_TYPE (secondary_vptrs) = *index;
VTT_TOP_LEVEL_P (secondary_vptrs) = top_level_p;
VTT_MARKED_BINFO_P (secondary_vptrs) = 0;
dfs_walk_real (binfo,
dfs_build_secondary_vptr_vtt_inits,
NULL,
dfs_ctor_vtable_bases_queue_p,
secondary_vptrs);
VTT_MARKED_BINFO_P (secondary_vptrs) = 1;
dfs_walk (binfo, dfs_unmark, dfs_ctor_vtable_bases_queue_p,
secondary_vptrs);
*index = TREE_TYPE (secondary_vptrs);
secondary_vptrs = TREE_VALUE (secondary_vptrs);
if (secondary_vptrs)
{
*inits = nreverse (secondary_vptrs);
inits = &TREE_CHAIN (secondary_vptrs);
my_friendly_assert (*inits == NULL_TREE, 20000517);
}
if (top_level_p)
for (b = TYPE_BINFO (BINFO_TYPE (binfo)); b; b = TREE_CHAIN (b))
{
tree vbase;
if (!TREE_VIA_VIRTUAL (b))
continue;
vbase = binfo_for_vbase (BINFO_TYPE (b), t);
inits = build_vtt_inits (vbase, t, inits, index);
}
if (!top_level_p)
{
tree data = tree_cons (t, binfo, NULL_TREE);
VTT_TOP_LEVEL_P (data) = 0;
VTT_MARKED_BINFO_P (data) = 0;
dfs_walk (binfo, dfs_fixup_binfo_vtbls,
dfs_ctor_vtable_bases_queue_p,
data);
}
return inits;
}
static tree
dfs_build_secondary_vptr_vtt_inits (binfo, data)
tree binfo;
void *data;
{
tree l;
tree t;
tree init;
tree index;
int top_level_p;
l = (tree) data;
t = TREE_CHAIN (l);
top_level_p = VTT_TOP_LEVEL_P (l);
SET_BINFO_MARKED (binfo);
if (!TYPE_VFIELD (BINFO_TYPE (binfo)))
return NULL_TREE;
if (same_type_p (BINFO_TYPE (binfo), t))
return NULL_TREE;
if (!TREE_VIA_VIRTUAL (binfo) && BINFO_PRIMARY_P (binfo))
return NULL_TREE;
if (!TYPE_USES_VIRTUAL_BASECLASSES (BINFO_TYPE (binfo))
&& !binfo_via_virtual (binfo, t))
return NULL_TREE;
index = TREE_TYPE (l);
if (top_level_p)
{
my_friendly_assert (!BINFO_VPTR_INDEX (binfo), 20010129);
BINFO_VPTR_INDEX (binfo) = index;
}
TREE_TYPE (l) = size_binop (PLUS_EXPR, index,
TYPE_SIZE_UNIT (ptr_type_node));
if (top_level_p && TREE_VIA_VIRTUAL (binfo))
{
while (BINFO_PRIMARY_BASE_OF (binfo))
binfo = BINFO_PRIMARY_BASE_OF (binfo);
}
init = binfo_ctor_vtable (binfo);
TREE_VALUE (l) = tree_cons (NULL_TREE, init, TREE_VALUE (l));
return NULL_TREE;
}
static tree
dfs_ctor_vtable_bases_queue_p (binfo, data)
tree binfo;
void *data;
{
if (TREE_VIA_VIRTUAL (binfo))
binfo = binfo_for_vbase (BINFO_TYPE (binfo), TREE_PURPOSE ((tree) data));
if (!BINFO_MARKED (binfo) == VTT_MARKED_BINFO_P ((tree) data))
return NULL_TREE;
return binfo;
}
static tree
dfs_fixup_binfo_vtbls (binfo, data)
tree binfo;
void *data;
{
CLEAR_BINFO_MARKED (binfo);
if (!TYPE_VFIELD (BINFO_TYPE (binfo)))
return NULL_TREE;
if (BINFO_VTABLE (binfo)
&& TREE_CODE (BINFO_VTABLE (binfo)) == TREE_LIST
&& (TREE_PURPOSE (BINFO_VTABLE (binfo))
== TREE_VALUE ((tree) data)))
BINFO_VTABLE (binfo) = TREE_CHAIN (BINFO_VTABLE (binfo));
return NULL_TREE;
}
static void
build_ctor_vtbl_group (binfo, t)
tree binfo;
tree t;
{
tree list;
tree type;
tree vtbl;
tree inits;
tree id;
tree vbase;
id = mangle_ctor_vtbl_for_type (t, binfo);
if (IDENTIFIER_GLOBAL_VALUE (id))
return;
my_friendly_assert (!same_type_p (BINFO_TYPE (binfo), t), 20010124);
vtbl = build_vtable (t, id, ptr_type_node);
list = build_tree_list (vtbl, NULL_TREE);
accumulate_vtbl_inits (binfo, TYPE_BINFO (TREE_TYPE (binfo)),
binfo, t, list);
for (vbase = TYPE_BINFO (BINFO_TYPE (binfo));
vbase;
vbase = TREE_CHAIN (vbase))
{
tree b;
tree orig_base;
if (!TREE_VIA_VIRTUAL (vbase))
continue;
b = binfo_for_vbase (BINFO_TYPE (vbase), t);
orig_base = binfo_for_vbase (BINFO_TYPE (vbase), BINFO_TYPE (binfo));
accumulate_vtbl_inits (b, orig_base, binfo, t, list);
}
inits = TREE_VALUE (list);
type = build_index_type (size_int (list_length (inits) - 1));
type = build_cplus_array_type (vtable_entry_type, type);
TREE_TYPE (vtbl) = type;
CLASSTYPE_VTABLES (t) = chainon (CLASSTYPE_VTABLES (t), vtbl);
initialize_array (vtbl, inits);
dump_vtable (t, binfo, vtbl);
}
static void
accumulate_vtbl_inits (binfo, orig_binfo, rtti_binfo, t, inits)
tree binfo;
tree orig_binfo;
tree rtti_binfo;
tree t;
tree inits;
{
int i;
int ctor_vtbl_p = !same_type_p (BINFO_TYPE (rtti_binfo), t);
my_friendly_assert (same_type_p (BINFO_TYPE (binfo),
BINFO_TYPE (orig_binfo)),
20000517);
if (!TYPE_CONTAINS_VPTR_P (BINFO_TYPE (binfo)))
return;
if (ctor_vtbl_p
&& !TYPE_USES_VIRTUAL_BASECLASSES (BINFO_TYPE (binfo))
&& !binfo_via_virtual (orig_binfo, BINFO_TYPE (rtti_binfo)))
return;
TREE_VALUE (inits)
= chainon (TREE_VALUE (inits),
dfs_accumulate_vtbl_inits (binfo, orig_binfo,
rtti_binfo, t, inits));
for (i = 0; i < BINFO_N_BASETYPES (binfo); ++i)
{
tree base_binfo = BINFO_BASETYPE (binfo, i);
if (TREE_VIA_VIRTUAL (base_binfo))
continue;
accumulate_vtbl_inits (base_binfo,
BINFO_BASETYPE (orig_binfo, i),
rtti_binfo, t,
inits);
}
}
static tree
dfs_accumulate_vtbl_inits (binfo, orig_binfo, rtti_binfo, t, l)
tree binfo;
tree orig_binfo;
tree rtti_binfo;
tree t;
tree l;
{
tree inits = NULL_TREE;
tree vtbl = NULL_TREE;
int ctor_vtbl_p = !same_type_p (BINFO_TYPE (rtti_binfo), t);
if (ctor_vtbl_p
&& TREE_VIA_VIRTUAL (orig_binfo) && BINFO_PRIMARY_P (orig_binfo))
{
tree b = BINFO_PRIMARY_BASE_OF (binfo);
tree last = NULL_TREE;
for (; b; b = BINFO_PRIMARY_BASE_OF (b))
{
last = b;
if (TREE_VIA_VIRTUAL (b) || b == rtti_binfo)
break;
}
if (b == NULL_TREE)
for (b = last; b; b = BINFO_INHERITANCE_CHAIN (b))
if (TREE_VIA_VIRTUAL (b) || b == rtti_binfo)
break;
if (b == rtti_binfo
|| (b && binfo_for_vbase (BINFO_TYPE (b),
BINFO_TYPE (rtti_binfo))))
vtbl = last;
}
else if (!BINFO_NEW_VTABLE_MARKED (orig_binfo, BINFO_TYPE (rtti_binfo)))
return inits;
if (!vtbl)
{
tree index;
int non_fn_entries;
inits = build_vtbl_initializer (binfo, orig_binfo, t, rtti_binfo,
&non_fn_entries);
vtbl = TREE_PURPOSE (l);
vtbl = build1 (ADDR_EXPR,
vtbl_ptr_type_node,
vtbl);
TREE_CONSTANT (vtbl) = 1;
index = size_binop (PLUS_EXPR,
size_int (non_fn_entries),
size_int (list_length (TREE_VALUE (l))));
index = size_binop (MULT_EXPR,
TYPE_SIZE_UNIT (vtable_entry_type),
index);
#ifdef VPTR_INITIALIZER_ADJUSTMENT
if (flag_apple_kext && !ctor_vtbl_p && ! BINFO_PRIMARY_P (binfo)
&& TREE_CODE (index) == INTEGER_CST
&& TREE_INT_CST_LOW (index) >= VPTR_INITIALIZER_ADJUSTMENT
&& TREE_INT_CST_HIGH (index) == 0)
index = fold (build (MINUS_EXPR,
TREE_TYPE (index), index,
size_int (VPTR_INITIALIZER_ADJUSTMENT)));
#endif
vtbl = build (PLUS_EXPR, TREE_TYPE (vtbl), vtbl, index);
TREE_CONSTANT (vtbl) = 1;
}
if (ctor_vtbl_p)
BINFO_VTABLE (binfo) = tree_cons (rtti_binfo, vtbl, BINFO_VTABLE (binfo));
else if (BINFO_PRIMARY_P (binfo) && TREE_VIA_VIRTUAL (binfo))
inits = NULL_TREE;
else
BINFO_VTABLE (binfo) = vtbl;
return inits;
}
static tree
build_vtbl_initializer (binfo, orig_binfo, t, rtti_binfo, non_fn_entries_p)
tree binfo;
tree orig_binfo;
tree t;
tree rtti_binfo;
int *non_fn_entries_p;
{
tree v, b;
tree vfun_inits;
tree vbase;
vtbl_init_data vid;
memset (&vid, 0, sizeof (vid));
vid.binfo = binfo;
vid.derived = t;
vid.rtti_binfo = rtti_binfo;
vid.last_init = &vid.inits;
vid.primary_vtbl_p = (binfo == TYPE_BINFO (t));
vid.ctor_vtbl_p = !same_type_p (BINFO_TYPE (rtti_binfo), t);
vid.generate_vcall_entries = true;
vid.index = ssize_int (-3 * TARGET_VTABLE_DATA_ENTRY_DISTANCE);
build_rtti_vtbl_entries (binfo, &vid);
VARRAY_TREE_INIT (vid.fns, 32, "fns");
build_vcall_and_vbase_vtbl_entries (binfo, &vid);
for (vbase = CLASSTYPE_VBASECLASSES (t);
vbase;
vbase = TREE_CHAIN (vbase))
CLEAR_BINFO_VTABLE_PATH_MARKED (TREE_VALUE (vbase));
if (TARGET_VTABLE_DATA_ENTRY_DISTANCE > 1)
{
tree cur, *prev;
for (prev = &vid.inits; (cur = *prev); prev = &TREE_CHAIN (cur))
{
tree add = cur;
int i;
for (i = 1; i < TARGET_VTABLE_DATA_ENTRY_DISTANCE; ++i)
add = tree_cons (NULL_TREE,
build1 (NOP_EXPR, vtable_entry_type,
null_pointer_node),
add);
*prev = add;
}
}
if (non_fn_entries_p)
*non_fn_entries_p = list_length (vid.inits);
vfun_inits = NULL_TREE;
for (v = BINFO_VIRTUALS (orig_binfo); v; v = TREE_CHAIN (v))
{
tree delta;
tree vcall_index;
tree fn;
tree init = NULL_TREE;
fn = BV_FN (v);
for (b = binfo; ; b = get_primary_binfo (b))
{
if (look_for_overrides_here (BINFO_TYPE (b), fn))
break;
if (BINFO_LOST_PRIMARY_P (b))
{
init = size_zero_node;
break;
}
}
if (! init)
{
delta = BV_DELTA (v);
vcall_index = BV_VCALL_INDEX (v);
my_friendly_assert (TREE_CODE (delta) == INTEGER_CST, 19990727);
my_friendly_assert (TREE_CODE (fn) == FUNCTION_DECL, 19990727);
if (DECL_PURE_VIRTUAL_P (fn))
fn = abort_fndecl;
else if (!integer_zerop (delta) || vcall_index)
fn = make_thunk (fn, delta, vcall_index);
init = build1 (ADDR_EXPR, vfunc_ptr_type_node, fn);
TREE_CONSTANT (init) = 1;
}
if (TARGET_VTABLE_USES_DESCRIPTORS)
{
int i;
if (init == size_zero_node)
for (i = 0; i < TARGET_VTABLE_USES_DESCRIPTORS; ++i)
vfun_inits = tree_cons (NULL_TREE, init, vfun_inits);
else
for (i = 0; i < TARGET_VTABLE_USES_DESCRIPTORS; ++i)
{
tree fdesc = build (FDESC_EXPR, vfunc_ptr_type_node,
TREE_OPERAND (init, 0),
build_int_2 (i, 0));
TREE_CONSTANT (fdesc) = 1;
vfun_inits = tree_cons (NULL_TREE, fdesc, vfun_inits);
}
}
else
vfun_inits = tree_cons (NULL_TREE, init, vfun_inits);
}
vfun_inits = nreverse (vfun_inits);
vid.inits = nreverse (vid.inits);
return chainon (vid.inits, vfun_inits);
}
static void
build_vcall_and_vbase_vtbl_entries (binfo, vid)
tree binfo;
vtbl_init_data *vid;
{
tree b;
b = get_primary_binfo (binfo);
if (b)
build_vcall_and_vbase_vtbl_entries (b, vid);
build_vbase_offset_vtbl_entries (binfo, vid);
build_vcall_offset_vtbl_entries (binfo, vid);
}
static void
build_vbase_offset_vtbl_entries (binfo, vid)
tree binfo;
vtbl_init_data *vid;
{
tree vbase;
tree t;
tree non_primary_binfo;
if (!TYPE_USES_VIRTUAL_BASECLASSES (BINFO_TYPE (binfo)))
return;
t = vid->derived;
non_primary_binfo = binfo;
while (BINFO_INHERITANCE_CHAIN (non_primary_binfo))
{
tree b;
if (TREE_VIA_VIRTUAL (non_primary_binfo))
{
non_primary_binfo = vid->binfo;
break;
}
b = BINFO_INHERITANCE_CHAIN (non_primary_binfo);
if (get_primary_binfo (b) != non_primary_binfo)
break;
non_primary_binfo = b;
}
for (vbase = TYPE_BINFO (BINFO_TYPE (binfo));
vbase;
vbase = TREE_CHAIN (vbase))
{
tree b;
tree delta;
if (!TREE_VIA_VIRTUAL (vbase))
continue;
b = binfo_for_vbase (BINFO_TYPE (vbase), t);
if (BINFO_VTABLE_PATH_MARKED (b))
continue;
SET_BINFO_VTABLE_PATH_MARKED (b);
delta = size_binop (MULT_EXPR,
vid->index,
convert (ssizetype,
TYPE_SIZE_UNIT (vtable_entry_type)));
if (vid->primary_vtbl_p)
BINFO_VPTR_FIELD (b) = delta;
if (binfo != TYPE_BINFO (t))
{
tree orig_vbase;
orig_vbase = binfo_for_vbase (BINFO_TYPE (vbase),
BINFO_TYPE (binfo));
if (!tree_int_cst_equal (delta,
BINFO_VPTR_FIELD (orig_vbase)))
abort ();
}
vid->index = size_binop (MINUS_EXPR, vid->index,
ssize_int (TARGET_VTABLE_DATA_ENTRY_DISTANCE));
delta = size_diffop (BINFO_OFFSET (b), BINFO_OFFSET (non_primary_binfo));
*vid->last_init
= build_tree_list (NULL_TREE,
fold (build1 (NOP_EXPR,
vtable_entry_type,
delta)));
vid->last_init = &TREE_CHAIN (*vid->last_init);
}
}
static void
build_vcall_offset_vtbl_entries (binfo, vid)
tree binfo;
vtbl_init_data *vid;
{
if (TREE_VIA_VIRTUAL (binfo) || binfo == TYPE_BINFO (vid->derived))
{
vid->vbase = binfo;
if (!TREE_VIA_VIRTUAL (binfo))
vid->generate_vcall_entries = false;
add_vcall_offset_vtbl_entries_r (binfo, vid);
}
}
static void
add_vcall_offset_vtbl_entries_r (binfo, vid)
tree binfo;
vtbl_init_data *vid;
{
int i;
tree primary_binfo;
if (TREE_VIA_VIRTUAL (binfo) && vid->vbase != binfo)
return;
primary_binfo = get_primary_binfo (binfo);
if (primary_binfo)
add_vcall_offset_vtbl_entries_r (primary_binfo, vid);
add_vcall_offset_vtbl_entries_1 (binfo, vid);
for (i = 0; i < BINFO_N_BASETYPES (binfo); ++i)
{
tree base_binfo;
base_binfo = BINFO_BASETYPE (binfo, i);
if (base_binfo != primary_binfo)
add_vcall_offset_vtbl_entries_r (base_binfo, vid);
}
}
static void
add_vcall_offset_vtbl_entries_1 (binfo, vid)
tree binfo;
vtbl_init_data* vid;
{
if (abi_version_at_least (2))
{
tree orig_fn;
for (orig_fn = TYPE_METHODS (BINFO_TYPE (binfo));
orig_fn;
orig_fn = TREE_CHAIN (orig_fn))
if (DECL_VINDEX (orig_fn))
add_vcall_offset (orig_fn, binfo, vid);
}
else
{
tree derived_virtuals;
tree base_virtuals;
tree orig_virtuals;
tree non_primary_binfo;
non_primary_binfo = binfo;
while (BINFO_INHERITANCE_CHAIN (non_primary_binfo))
{
tree b;
if (TREE_VIA_VIRTUAL (non_primary_binfo))
{
if (non_primary_binfo != vid->vbase)
abort ();
non_primary_binfo = vid->binfo;
break;
}
b = BINFO_INHERITANCE_CHAIN (non_primary_binfo);
if (get_primary_binfo (b) != non_primary_binfo)
break;
non_primary_binfo = b;
}
if (vid->ctor_vtbl_p)
non_primary_binfo = get_original_base
(non_primary_binfo, TYPE_BINFO (BINFO_TYPE (vid->rtti_binfo)));
for (base_virtuals = BINFO_VIRTUALS (binfo),
derived_virtuals = BINFO_VIRTUALS (non_primary_binfo),
orig_virtuals = BINFO_VIRTUALS (TYPE_BINFO (BINFO_TYPE (binfo)));
base_virtuals;
base_virtuals = TREE_CHAIN (base_virtuals),
derived_virtuals = TREE_CHAIN (derived_virtuals),
orig_virtuals = TREE_CHAIN (orig_virtuals))
{
tree orig_fn;
orig_fn = BV_FN (orig_virtuals);
if (!same_type_p (DECL_CONTEXT (orig_fn), BINFO_TYPE (binfo)))
continue;
add_vcall_offset (orig_fn, binfo, vid);
}
}
}
static void
add_vcall_offset (tree orig_fn, tree binfo, vtbl_init_data *vid)
{
size_t i;
tree vcall_offset;
for (i = 0; i < VARRAY_ACTIVE_SIZE (vid->fns); ++i)
{
tree derived_entry;
derived_entry = VARRAY_TREE (vid->fns, i);
if (same_signature_p (derived_entry, orig_fn)
|| (DECL_DESTRUCTOR_P (derived_entry)
&& DECL_DESTRUCTOR_P (orig_fn)))
return;
}
if (vid->binfo == TYPE_BINFO (vid->derived))
CLASSTYPE_VCALL_INDICES (vid->derived)
= tree_cons (orig_fn, vid->index,
CLASSTYPE_VCALL_INDICES (vid->derived));
vid->index = size_binop (MINUS_EXPR, vid->index,
ssize_int (TARGET_VTABLE_DATA_ENTRY_DISTANCE));
VARRAY_PUSH_TREE (vid->fns, orig_fn);
if (vid->generate_vcall_entries)
{
tree base;
tree fn;
fn = find_final_overrider (vid->rtti_binfo, binfo, orig_fn);
if (fn == error_mark_node)
vcall_offset = build1 (NOP_EXPR, vtable_entry_type,
integer_zero_node);
else
{
base = TREE_VALUE (fn);
vcall_offset = size_diffop (BINFO_OFFSET (base),
BINFO_OFFSET (vid->binfo));
vcall_offset = fold (build1 (NOP_EXPR, vtable_entry_type,
vcall_offset));
}
*vid->last_init = build_tree_list (NULL_TREE, vcall_offset);
vid->last_init = &TREE_CHAIN (*vid->last_init);
}
}
static void
build_rtti_vtbl_entries (binfo, vid)
tree binfo;
vtbl_init_data *vid;
{
tree b;
tree t;
tree basetype;
tree offset;
tree decl;
tree init;
basetype = BINFO_TYPE (binfo);
t = BINFO_TYPE (vid->rtti_binfo);
b = binfo;
while (CLASSTYPE_HAS_PRIMARY_BASE_P (BINFO_TYPE (b))
&& !BINFO_LOST_PRIMARY_P (b))
{
tree primary_base;
primary_base = get_primary_binfo (b);
my_friendly_assert (BINFO_PRIMARY_BASE_OF (primary_base) == b, 20010127);
b = primary_base;
}
offset = size_diffop (BINFO_OFFSET (vid->rtti_binfo), BINFO_OFFSET (b));
if (flag_rtti)
decl = build_address (get_tinfo_decl (t));
else
decl = integer_zero_node;
init = build_nop (vfunc_ptr_type_node, decl);
*vid->last_init = build_tree_list (NULL_TREE, init);
vid->last_init = &TREE_CHAIN (*vid->last_init);
init = build_nop (vfunc_ptr_type_node, offset);
*vid->last_init = build_tree_list (NULL_TREE, init);
vid->last_init = &TREE_CHAIN (*vid->last_init);
}