00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include "config.h"
00031 #include "system.h"
00032 #include "tree.h"
00033 #include "cp-tree.h"
00034 #include "flags.h"
00035 #include "rtl.h"
00036 #include "output.h"
00037 #include "toplev.h"
00038 #include "ggc.h"
00039 #include "lex.h"
00040 #include "target.h"
00041 #ifdef SGI_MONGOOSE
00042 #include "defaults.h"
00043 #endif
00044
00045
00046
00047
00048 int current_class_depth;
00049
00050
00051
00052
00053
00054 typedef struct class_stack_node {
00055
00056 tree name;
00057
00058
00059 tree type;
00060
00061
00062
00063 tree access;
00064
00065
00066 splay_tree names_used;
00067 }* class_stack_node_t;
00068
00069 typedef struct vtbl_init_data_s
00070 {
00071
00072 tree binfo;
00073
00074 tree derived;
00075
00076
00077 tree rtti_binfo;
00078
00079
00080 tree inits;
00081
00082 tree* last_init;
00083
00084
00085 tree vbase;
00086
00087
00088 varray_type fns;
00089
00090 tree index;
00091
00092
00093 int primary_vtbl_p;
00094
00095
00096 int ctor_vtbl_p;
00097
00098
00099 bool generate_vcall_entries;
00100 } vtbl_init_data;
00101
00102
00103 typedef int (*subobject_offset_fn) PARAMS ((tree, tree, splay_tree));
00104
00105
00106
00107 static int current_class_stack_size;
00108 static class_stack_node_t current_class_stack;
00109
00110
00111
00112 varray_type local_classes;
00113
00114 static tree get_vfield_name PARAMS ((tree));
00115 static void finish_struct_anon PARAMS ((tree));
00116 static tree get_vtable_name PARAMS ((tree));
00117 static tree get_basefndecls PARAMS ((tree, tree));
00118 static int build_primary_vtable PARAMS ((tree, tree));
00119 static int build_secondary_vtable PARAMS ((tree, tree));
00120 static void finish_vtbls PARAMS ((tree));
00121 static void modify_vtable_entry PARAMS ((tree, tree, tree, tree, tree *));
00122 static tree delete_duplicate_fields_1 PARAMS ((tree, tree));
00123 static void delete_duplicate_fields PARAMS ((tree));
00124 static void finish_struct_bits PARAMS ((tree));
00125 static int alter_access PARAMS ((tree, tree, tree));
00126 static void handle_using_decl PARAMS ((tree, tree));
00127 static void check_for_override PARAMS ((tree, tree));
00128 static tree dfs_modify_vtables PARAMS ((tree, void *));
00129 static tree modify_all_vtables PARAMS ((tree, tree));
00130 static void determine_primary_base PARAMS ((tree));
00131 static void finish_struct_methods PARAMS ((tree));
00132 static void maybe_warn_about_overly_private_class PARAMS ((tree));
00133 static int field_decl_cmp PARAMS ((const tree *, const tree *));
00134 static int method_name_cmp PARAMS ((const tree *, const tree *));
00135 static void add_implicitly_declared_members PARAMS ((tree, int, int, int));
00136 static tree fixed_type_or_null PARAMS ((tree, int *, int *));
00137 static tree resolve_address_of_overloaded_function PARAMS ((tree, tree, int,
00138 int, int, tree));
00139 static tree build_vtable_entry_ref PARAMS ((tree, tree, tree));
00140 static tree build_vtbl_ref_1 PARAMS ((tree, tree));
00141 static tree build_vtbl_initializer PARAMS ((tree, tree, tree, tree, int *));
00142 static int count_fields PARAMS ((tree));
00143 static int add_fields_to_vec PARAMS ((tree, tree, int));
00144 static void check_bitfield_decl PARAMS ((tree));
00145 static void check_field_decl (tree, tree, int *, int *, int *, int *);
00146 static void check_field_decls (tree, tree *, int *, int *, int *);
00147 static tree *build_base_field (record_layout_info, tree, splay_tree, tree *);
00148 static void build_base_fields (record_layout_info, splay_tree, tree *);
00149 static void check_methods PARAMS ((tree));
00150 static void remove_zero_width_bit_fields PARAMS ((tree));
00151 static void check_bases PARAMS ((tree, int *, int *, int *));
00152 static void check_bases_and_members (tree);
00153 static tree create_vtable_ptr (tree, tree *);
00154 static void include_empty_classes (record_layout_info);
00155 static void layout_class_type (tree, tree *);
00156 static void fixup_pending_inline PARAMS ((tree));
00157 static void fixup_inline_methods PARAMS ((tree));
00158 static void set_primary_base PARAMS ((tree, tree));
00159 static void propagate_binfo_offsets PARAMS ((tree, tree, tree));
00160 static void layout_virtual_bases (record_layout_info, splay_tree);
00161 static tree dfs_set_offset_for_unshared_vbases PARAMS ((tree, void *));
00162 static void build_vbase_offset_vtbl_entries PARAMS ((tree, vtbl_init_data *));
00163 static void add_vcall_offset_vtbl_entries_r PARAMS ((tree, vtbl_init_data *));
00164 static void add_vcall_offset_vtbl_entries_1 PARAMS ((tree, vtbl_init_data *));
00165 static void build_vcall_offset_vtbl_entries PARAMS ((tree, vtbl_init_data *));
00166 static void add_vcall_offset (tree, tree, vtbl_init_data *);
00167 static void layout_vtable_decl PARAMS ((tree, int));
00168 static tree dfs_find_final_overrider PARAMS ((tree, void *));
00169 static tree find_final_overrider PARAMS ((tree, tree, tree));
00170 static int make_new_vtable PARAMS ((tree, tree));
00171 static int maybe_indent_hierarchy PARAMS ((FILE *, int, int));
00172 static void dump_class_hierarchy_r PARAMS ((FILE *, int, tree, tree, int));
00173 static void dump_class_hierarchy PARAMS ((tree));
00174 static void dump_array PARAMS ((FILE *, tree));
00175 static void dump_vtable PARAMS ((tree, tree, tree));
00176 static void dump_vtt PARAMS ((tree, tree));
00177 static tree build_vtable PARAMS ((tree, tree, tree));
00178 static void initialize_vtable PARAMS ((tree, tree));
00179 static void initialize_array PARAMS ((tree, tree));
00180 static void layout_nonempty_base_or_field PARAMS ((record_layout_info,
00181 tree, tree, splay_tree));
00182 static tree end_of_class PARAMS ((tree, int));
00183 static bool layout_empty_base PARAMS ((tree, tree, splay_tree, tree));
00184 static void accumulate_vtbl_inits PARAMS ((tree, tree, tree, tree, tree));
00185 static tree dfs_accumulate_vtbl_inits PARAMS ((tree, tree, tree, tree,
00186 tree));
00187 static void build_rtti_vtbl_entries PARAMS ((tree, vtbl_init_data *));
00188 static void build_vcall_and_vbase_vtbl_entries PARAMS ((tree,
00189 vtbl_init_data *));
00190 static void force_canonical_binfo_r PARAMS ((tree, tree, tree, tree));
00191 static void force_canonical_binfo PARAMS ((tree, tree, tree, tree));
00192 static tree dfs_unshared_virtual_bases PARAMS ((tree, void *));
00193 static void mark_primary_bases PARAMS ((tree));
00194 static tree mark_primary_virtual_base PARAMS ((tree, tree));
00195 static void clone_constructors_and_destructors PARAMS ((tree));
00196 static tree build_clone PARAMS ((tree, tree));
00197 static void update_vtable_entry_for_fn PARAMS ((tree, tree, tree, tree *));
00198 static tree copy_virtuals PARAMS ((tree));
00199 static void build_ctor_vtbl_group PARAMS ((tree, tree));
00200 static void build_vtt PARAMS ((tree));
00201 static tree binfo_ctor_vtable PARAMS ((tree));
00202 static tree *build_vtt_inits PARAMS ((tree, tree, tree *, tree *));
00203 static tree dfs_build_secondary_vptr_vtt_inits PARAMS ((tree, void *));
00204 static tree dfs_ctor_vtable_bases_queue_p PARAMS ((tree, void *data));
00205 static tree dfs_fixup_binfo_vtbls PARAMS ((tree, void *));
00206 static tree get_original_base PARAMS ((tree, tree));
00207 static tree dfs_get_primary_binfo PARAMS ((tree, void*));
00208 static int record_subobject_offset PARAMS ((tree, tree, splay_tree));
00209 static int check_subobject_offset PARAMS ((tree, tree, splay_tree));
00210 static int walk_subobject_offsets PARAMS ((tree, subobject_offset_fn,
00211 tree, splay_tree, tree, int));
00212 static void record_subobject_offsets PARAMS ((tree, tree, splay_tree, int));
00213 static int layout_conflict_p PARAMS ((tree, tree, splay_tree, int));
00214 static int splay_tree_compare_integer_csts PARAMS ((splay_tree_key k1,
00215 splay_tree_key k2));
00216 static void warn_about_ambiguous_bases PARAMS ((tree));
00217 static bool type_requires_array_cookie PARAMS ((tree));
00218 static bool contains_empty_class_p (tree);
00219 static tree dfs_base_derived_from (tree, void *);
00220 static bool base_derived_from (tree, tree);
00221 static int empty_base_at_nonzero_offset_p (tree, tree, splay_tree);
00222 static tree end_of_base (tree);
00223 static tree get_vcall_index (tree, tree);
00224
00225
00226
00227
00228 #define VTT_TOP_LEVEL_P(NODE) TREE_UNSIGNED (NODE)
00229 #define VTT_MARKED_BINFO_P(NODE) TREE_USED (NODE)
00230
00231
00232
00233 #ifdef GATHER_STATISTICS
00234 int n_vtables = 0;
00235 int n_vtable_entries = 0;
00236 int n_vtable_searches = 0;
00237 int n_vtable_elems = 0;
00238 int n_convert_harshness = 0;
00239 int n_compute_conversion_costs = 0;
00240 int n_build_method_call = 0;
00241 int n_inner_fields_searched = 0;
00242 #endif
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254 tree
00255 build_base_path (code, expr, binfo, nonnull)
00256 enum tree_code code;
00257 tree expr;
00258 tree binfo;
00259 int nonnull;
00260 {
00261 tree v_binfo = NULL_TREE;
00262 tree d_binfo = NULL_TREE;
00263 tree probe;
00264 tree offset;
00265 tree target_type;
00266 tree null_test = NULL;
00267 tree ptr_target_type;
00268 int fixed_type_p;
00269 int want_pointer = TREE_CODE (TREE_TYPE (expr)) == POINTER_TYPE;
00270
00271 if (expr == error_mark_node || binfo == error_mark_node || !binfo)
00272 return error_mark_node;
00273
00274 for (probe = binfo; probe; probe = BINFO_INHERITANCE_CHAIN (probe))
00275 {
00276 d_binfo = probe;
00277 if (!v_binfo && TREE_VIA_VIRTUAL (probe))
00278 v_binfo = probe;
00279 }
00280
00281 probe = TYPE_MAIN_VARIANT (TREE_TYPE (expr));
00282 if (want_pointer)
00283 probe = TYPE_MAIN_VARIANT (TREE_TYPE (probe));
00284
00285 my_friendly_assert (code == MINUS_EXPR
00286 ? same_type_p (BINFO_TYPE (binfo), probe)
00287 : code == PLUS_EXPR
00288 ? same_type_p (BINFO_TYPE (d_binfo), probe)
00289 : false, 20010723);
00290
00291 if (code == MINUS_EXPR && v_binfo)
00292 {
00293 error ("cannot convert from base `%T' to derived type `%T' via virtual base `%T'",
00294 BINFO_TYPE (binfo), BINFO_TYPE (d_binfo), BINFO_TYPE (v_binfo));
00295 return error_mark_node;
00296 }
00297
00298 if (!want_pointer)
00299
00300 expr = build_unary_op (ADDR_EXPR, expr, 0);
00301
00302 fixed_type_p = resolves_to_fixed_type_p (expr, &nonnull);
00303 if (fixed_type_p <= 0 && TREE_SIDE_EFFECTS (expr))
00304 expr = save_expr (expr);
00305
00306 if (want_pointer && !nonnull)
00307 null_test = build (EQ_EXPR, boolean_type_node, expr, integer_zero_node);
00308
00309 offset = BINFO_OFFSET (binfo);
00310
00311 if (v_binfo && fixed_type_p <= 0)
00312 {
00313
00314
00315
00316 tree v_offset;
00317
00318 if (fixed_type_p < 0 && in_base_initializer)
00319 {
00320
00321
00322 tree derived = v_binfo;
00323
00324 while (BINFO_INHERITANCE_CHAIN (derived))
00325 derived = BINFO_INHERITANCE_CHAIN (derived);
00326
00327 v_offset = build (PLUS_EXPR, TREE_TYPE (current_vtt_parm),
00328 current_vtt_parm, BINFO_VPTR_INDEX (derived));
00329
00330 v_offset = build1 (INDIRECT_REF,
00331 TREE_TYPE (TYPE_VFIELD (BINFO_TYPE (derived))),
00332 v_offset);
00333 }
00334 else
00335 v_offset = build_vfield_ref (build_indirect_ref (expr, NULL),
00336 TREE_TYPE (TREE_TYPE (expr)));
00337
00338 v_binfo = binfo_for_vbase (BINFO_TYPE (v_binfo), BINFO_TYPE (d_binfo));
00339
00340 v_offset = build (PLUS_EXPR, TREE_TYPE (v_offset),
00341 v_offset, BINFO_VPTR_FIELD (v_binfo));
00342 v_offset = build1 (NOP_EXPR,
00343 build_pointer_type (ptrdiff_type_node),
00344 v_offset);
00345 v_offset = build_indirect_ref (v_offset, NULL);
00346 TREE_CONSTANT (v_offset) = 1;
00347
00348 offset = cp_convert (ptrdiff_type_node,
00349 size_diffop (offset, BINFO_OFFSET (v_binfo)));
00350
00351 if (!integer_zerop (offset))
00352 v_offset = build (code, ptrdiff_type_node, v_offset, offset);
00353
00354 if (fixed_type_p < 0)
00355
00356
00357
00358 offset = build (COND_EXPR, ptrdiff_type_node,
00359 build (EQ_EXPR, boolean_type_node,
00360 current_in_charge_parm, integer_zero_node),
00361 v_offset,
00362 BINFO_OFFSET (binfo));
00363 else
00364 offset = v_offset;
00365 }
00366
00367 target_type = code == PLUS_EXPR ? BINFO_TYPE (binfo) : BINFO_TYPE (d_binfo);
00368
00369 target_type = cp_build_qualified_type
00370 (target_type, cp_type_quals (TREE_TYPE (TREE_TYPE (expr))));
00371 ptr_target_type = build_pointer_type (target_type);
00372 if (want_pointer)
00373 target_type = ptr_target_type;
00374
00375 expr = build1 (NOP_EXPR, ptr_target_type, expr);
00376
00377 if (!integer_zerop (offset))
00378 expr = build (code, ptr_target_type, expr, offset);
00379 else
00380 null_test = NULL;
00381
00382 if (!want_pointer)
00383 expr = build_indirect_ref (expr, NULL);
00384
00385 if (null_test)
00386 expr = build (COND_EXPR, target_type, null_test,
00387 build1 (NOP_EXPR, target_type, integer_zero_node),
00388 expr);
00389
00390 return expr;
00391 }
00392
00393
00394
00395
00396
00397 tree
00398 convert_to_base (tree object, tree type, bool check_access)
00399 {
00400 tree binfo;
00401
00402 binfo = lookup_base (TREE_TYPE (object), type,
00403 check_access ? ba_check : ba_ignore,
00404 NULL);
00405 if (!binfo || binfo == error_mark_node)
00406 return error_mark_node;
00407
00408 return build_base_path (PLUS_EXPR, object, binfo, 1);
00409 }
00410
00411
00412
00413
00414
00415
00416 tree
00417 convert_to_base_statically (tree expr, tree base)
00418 {
00419 tree expr_type;
00420
00421 expr_type = TREE_TYPE (expr);
00422 if (!same_type_p (expr_type, BINFO_TYPE (base)))
00423 {
00424 tree pointer_type;
00425
00426 pointer_type = build_pointer_type (expr_type);
00427 expr = build_unary_op (ADDR_EXPR, expr, 1);
00428 if (!integer_zerop (BINFO_OFFSET (base)))
00429 expr = build (PLUS_EXPR, pointer_type, expr,
00430 build_nop (pointer_type, BINFO_OFFSET (base)));
00431 expr = build_nop (build_pointer_type (BINFO_TYPE (base)), expr);
00432 expr = build1 (INDIRECT_REF, BINFO_TYPE (base), expr);
00433 }
00434
00435 return expr;
00436 }
00437
00438
00439
00440
00441 static tree
00442 build_vtable_entry_ref (array_ref, instance, idx)
00443 tree array_ref, instance, idx;
00444 {
00445 tree i, i2, vtable, first_fn, basetype;
00446
00447 basetype = TREE_TYPE (instance);
00448 if (TREE_CODE (basetype) == REFERENCE_TYPE)
00449 basetype = TREE_TYPE (basetype);
00450
00451 vtable = get_vtbl_decl_for_binfo (TYPE_BINFO (basetype));
00452 first_fn = TYPE_BINFO_VTABLE (basetype);
00453
00454 i = fold (build_array_ref (first_fn, idx));
00455 i = fold (build_c_cast (ptrdiff_type_node,
00456 build_unary_op (ADDR_EXPR, i, 0)));
00457 i2 = fold (build_array_ref (vtable, build_int_2 (0,0)));
00458 i2 = fold (build_c_cast (ptrdiff_type_node,
00459 build_unary_op (ADDR_EXPR, i2, 0)));
00460 i = fold (cp_build_binary_op (MINUS_EXPR, i, i2));
00461
00462 if (TREE_CODE (i) != INTEGER_CST)
00463 abort ();
00464
00465 return build (VTABLE_REF, TREE_TYPE (array_ref), array_ref, vtable, i);
00466 }
00467
00468
00469
00470
00471
00472
00473 static tree
00474 build_vtbl_ref_1 (instance, idx)
00475 tree instance, idx;
00476 {
00477 tree aref;
00478 tree vtbl = NULL_TREE;
00479
00480
00481
00482
00483 int cdtorp = 0;
00484 tree fixed_type = fixed_type_or_null (instance, NULL, &cdtorp);
00485
00486 tree basetype = TREE_TYPE (instance);
00487 if (TREE_CODE (basetype) == REFERENCE_TYPE)
00488 basetype = TREE_TYPE (basetype);
00489
00490 if (fixed_type && !cdtorp)
00491 {
00492 tree binfo = lookup_base (fixed_type, basetype,
00493 ba_ignore|ba_quiet, NULL);
00494 if (binfo)
00495 vtbl = BINFO_VTABLE (binfo);
00496 }
00497
00498 if (!vtbl)
00499 {
00500 vtbl = build_vfield_ref (instance, basetype);
00501 }
00502
00503 assemble_external (vtbl);
00504
00505 aref = build_array_ref (vtbl, idx);
00506 TREE_CONSTANT (aref) = 1;
00507
00508 return aref;
00509 }
00510
00511 tree
00512 build_vtbl_ref (instance, idx)
00513 tree instance, idx;
00514 {
00515 tree aref = build_vtbl_ref_1 (instance, idx);
00516
00517 if (flag_vtable_gc)
00518 aref = build_vtable_entry_ref (aref, instance, idx);
00519
00520 return aref;
00521 }
00522
00523
00524
00525
00526 tree
00527 build_vfn_ref (instance, idx)
00528 tree instance, idx;
00529 {
00530 tree aref = build_vtbl_ref_1 (instance, idx);
00531
00532
00533
00534 if (TARGET_VTABLE_USES_DESCRIPTORS)
00535 aref = build1 (NOP_EXPR, TREE_TYPE (aref),
00536 build_unary_op (ADDR_EXPR, aref, 1));
00537
00538 if (flag_vtable_gc)
00539 aref = build_vtable_entry_ref (aref, instance, idx);
00540
00541 return aref;
00542 }
00543
00544
00545
00546
00547 static tree
00548 get_vtable_name (type)
00549 tree type;
00550 {
00551 return mangle_vtbl_for_type (type);
00552 }
00553
00554
00555
00556
00557 tree
00558 get_vtt_name (type)
00559 tree type;
00560 {
00561 return mangle_vtt_for_type (type);
00562 }
00563
00564
00565
00566
00567
00568 static tree
00569 build_vtable (class_type, name, vtable_type)
00570 tree class_type;
00571 tree name;
00572 tree vtable_type;
00573 {
00574 tree decl;
00575
00576 decl = build_lang_decl (VAR_DECL, name, vtable_type);
00577
00578
00579 SET_DECL_ASSEMBLER_NAME (decl, name);
00580 DECL_CONTEXT (decl) = class_type;
00581 DECL_ARTIFICIAL (decl) = 1;
00582 TREE_STATIC (decl) = 1;
00583 TREE_READONLY (decl) = 1;
00584 DECL_VIRTUAL_P (decl) = 1;
00585 DECL_ALIGN (decl) = TARGET_VTABLE_ENTRY_ALIGN;
00586
00587 import_export_vtable (decl, class_type, 0);
00588
00589 return decl;
00590 }
00591
00592
00593
00594
00595
00596
00597
00598 tree
00599 get_vtable_decl (type, complete)
00600 tree type;
00601 int complete;
00602 {
00603 tree decl;
00604
00605 if (CLASSTYPE_VTABLES (type))
00606 return CLASSTYPE_VTABLES (type);
00607
00608 decl = build_vtable (type, get_vtable_name (type), void_type_node);
00609 CLASSTYPE_VTABLES (type) = decl;
00610
00611
00612
00613 DECL_ALIGN (decl) = MAX (TYPE_ALIGN (double_type_node),
00614 DECL_ALIGN (decl));
00615
00616 if (complete)
00617 {
00618 DECL_EXTERNAL (decl) = 1;
00619 cp_finish_decl (decl, NULL_TREE, NULL_TREE, 0);
00620 }
00621
00622 return decl;
00623 }
00624
00625
00626
00627
00628 static tree
00629 copy_virtuals (binfo)
00630 tree binfo;
00631 {
00632 tree copies;
00633 tree t;
00634
00635 copies = copy_list (BINFO_VIRTUALS (binfo));
00636 for (t = copies; t; t = TREE_CHAIN (t))
00637 BV_VCALL_INDEX (t) = NULL_TREE;
00638
00639 return copies;
00640 }
00641
00642
00643
00644
00645
00646
00647
00648 static int
00649 build_primary_vtable (binfo, type)
00650 tree binfo, type;
00651 {
00652 tree decl;
00653 tree virtuals;
00654
00655 decl = get_vtable_decl (type, 0);
00656
00657 if (binfo)
00658 {
00659 if (BINFO_NEW_VTABLE_MARKED (binfo, type))
00660
00661
00662 return 0;
00663
00664 virtuals = copy_virtuals (binfo);
00665 TREE_TYPE (decl) = TREE_TYPE (get_vtbl_decl_for_binfo (binfo));
00666 DECL_SIZE (decl) = TYPE_SIZE (TREE_TYPE (decl));
00667 DECL_SIZE_UNIT (decl) = TYPE_SIZE_UNIT (TREE_TYPE (decl));
00668 }
00669 else
00670 {
00671 my_friendly_assert (TREE_CODE (TREE_TYPE (decl)) == VOID_TYPE,
00672 20000118);
00673 virtuals = NULL_TREE;
00674 }
00675
00676 #ifdef GATHER_STATISTICS
00677 n_vtables += 1;
00678 n_vtable_elems += list_length (virtuals);
00679 #endif
00680
00681
00682
00683 TYPE_BINFO_VTABLE (type) = decl;
00684 TYPE_BINFO_VIRTUALS (type) = virtuals;
00685 SET_BINFO_NEW_VTABLE_MARKED (TYPE_BINFO (type), type);
00686 return 1;
00687 }
00688
00689
00690
00691
00692
00693
00694
00695
00696
00697
00698
00699
00700
00701
00702
00703 static int
00704 build_secondary_vtable (binfo, for_type)
00705 tree binfo, for_type;
00706 {
00707 my_friendly_assert (binfo == CANONICAL_BINFO (binfo, for_type), 20010605);
00708
00709 if (BINFO_NEW_VTABLE_MARKED (binfo, for_type))
00710
00711
00712 return 0;
00713
00714
00715
00716 SET_BINFO_NEW_VTABLE_MARKED (binfo, for_type);
00717
00718
00719 BINFO_VIRTUALS (binfo) = copy_virtuals (binfo);
00720
00721
00722
00723 BINFO_VTABLE (binfo) = NULL_TREE;
00724 return 1;
00725 }
00726
00727
00728
00729
00730 static int
00731 make_new_vtable (t, binfo)
00732 tree t;
00733 tree binfo;
00734 {
00735 if (binfo == TYPE_BINFO (t))
00736
00737
00738
00739
00740
00741 return build_primary_vtable (TYPE_BINFO (DECL_CONTEXT (TYPE_VFIELD (t))),
00742 t);
00743 else
00744
00745
00746
00747
00748 return build_secondary_vtable (binfo, t);
00749 }
00750
00751
00752
00753
00754
00755
00756
00757 static void
00758 modify_vtable_entry (t, binfo, fndecl, delta, virtuals)
00759 tree t;
00760 tree binfo;
00761 tree fndecl;
00762 tree delta;
00763 tree *virtuals;
00764 {
00765 tree v;
00766
00767 v = *virtuals;
00768
00769 if (fndecl != BV_FN (v)
00770 || !tree_int_cst_equal (delta, BV_DELTA (v)))
00771 {
00772 tree base_fndecl;
00773
00774
00775 if (make_new_vtable (t, binfo))
00776 {
00777
00778
00779
00780 *virtuals = BINFO_VIRTUALS (binfo);
00781 while (BV_FN (*virtuals) != BV_FN (v))
00782 *virtuals = TREE_CHAIN (*virtuals);
00783 v = *virtuals;
00784 }
00785
00786 base_fndecl = BV_FN (v);
00787 BV_DELTA (v) = delta;
00788 BV_VCALL_INDEX (v) = NULL_TREE;
00789 BV_FN (v) = fndecl;
00790 }
00791 }
00792
00793
00794
00795
00796
00797
00798
00799 void
00800 add_method (type, method, error_p)
00801 tree type;
00802 tree method;
00803 int error_p;
00804 {
00805 int using = (DECL_CONTEXT (method) != type);
00806 int len;
00807 int slot;
00808 tree method_vec;
00809 int template_conv_p = (TREE_CODE (method) == TEMPLATE_DECL
00810 && DECL_TEMPLATE_CONV_FN_P (method));
00811
00812 if (!CLASSTYPE_METHOD_VEC (type))
00813
00814
00815
00816
00817
00818
00819
00820
00821
00822
00823 CLASSTYPE_METHOD_VEC (type) = make_tree_vec (8);
00824
00825 method_vec = CLASSTYPE_METHOD_VEC (type);
00826 len = TREE_VEC_LENGTH (method_vec);
00827
00828
00829 if (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (method))
00830 slot = CLASSTYPE_CONSTRUCTOR_SLOT;
00831 else if (DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (method))
00832 slot = CLASSTYPE_DESTRUCTOR_SLOT;
00833 else
00834 {
00835 int have_template_convs_p = 0;
00836
00837
00838 for (slot = CLASSTYPE_FIRST_CONVERSION_SLOT; slot < len; ++slot)
00839 {
00840 tree m = TREE_VEC_ELT (method_vec, slot);
00841
00842 if (!m)
00843 break;
00844 m = OVL_CURRENT (m);
00845
00846 if (template_conv_p)
00847 {
00848 have_template_convs_p = (TREE_CODE (m) == TEMPLATE_DECL
00849 && DECL_TEMPLATE_CONV_FN_P (m));
00850
00851
00852
00853 if (!have_template_convs_p)
00854 {
00855 slot = len - 1;
00856 if (TREE_VEC_ELT (method_vec, slot))
00857 slot++;
00858 }
00859 break;
00860 }
00861 if (DECL_NAME (m) == DECL_NAME (method))
00862 break;
00863 }
00864
00865 if (slot == len)
00866 {
00867
00868 int new_len;
00869 tree new_vec;
00870
00871
00872
00873
00874 if (!error_p)
00875 new_len = 2 * len;
00876
00877
00878
00879 else
00880 new_len = len + 1;
00881
00882 new_vec = make_tree_vec (new_len);
00883 memcpy (&TREE_VEC_ELT (new_vec, 0), &TREE_VEC_ELT (method_vec, 0),
00884 len * sizeof (tree));
00885 len = new_len;
00886 method_vec = CLASSTYPE_METHOD_VEC (type) = new_vec;
00887 }
00888
00889 if (DECL_CONV_FN_P (method) && !TREE_VEC_ELT (method_vec, slot))
00890 {
00891
00892
00893
00894
00895
00896
00897 if (template_conv_p)
00898 slot = CLASSTYPE_FIRST_CONVERSION_SLOT;
00899 else
00900 for (slot = CLASSTYPE_FIRST_CONVERSION_SLOT; slot < len; ++slot)
00901 {
00902 tree fn = TREE_VEC_ELT (method_vec, slot);
00903
00904 if (!fn)
00905
00906
00907 break;
00908
00909 if (!DECL_CONV_FN_P (OVL_CURRENT (fn)))
00910
00911
00912 break;
00913 }
00914
00915 if (template_conv_p && have_template_convs_p)
00916 ;
00917 else if (!TREE_VEC_ELT (method_vec, slot))
00918
00919
00920 ;
00921 else
00922 {
00923
00924
00925
00926 memmove (&TREE_VEC_ELT (method_vec, slot + 1),
00927 &TREE_VEC_ELT (method_vec, slot),
00928 (len - slot - 1) * sizeof (tree));
00929 TREE_VEC_ELT (method_vec, slot) = NULL_TREE;
00930 }
00931 }
00932 }
00933
00934 if (template_class_depth (type))
00935
00936
00937 ;
00938 else
00939 {
00940 tree fns;
00941
00942
00943 for (fns = TREE_VEC_ELT (method_vec, slot);
00944 fns;
00945 fns = OVL_NEXT (fns))
00946 {
00947 tree fn = OVL_CURRENT (fns);
00948 tree parms1;
00949 tree parms2;
00950 bool same = 1;
00951
00952 if (TREE_CODE (fn) != TREE_CODE (method))
00953 continue;
00954
00955
00956
00957
00958
00959
00960
00961
00962
00963
00964
00965 parms1 = TYPE_ARG_TYPES (TREE_TYPE (fn));
00966 parms2 = TYPE_ARG_TYPES (TREE_TYPE (method));
00967
00968
00969
00970
00971 if (! DECL_STATIC_FUNCTION_P (fn)
00972 && ! DECL_STATIC_FUNCTION_P (method)
00973 && (TYPE_QUALS (TREE_TYPE (TREE_VALUE (parms1)))
00974 != TYPE_QUALS (TREE_TYPE (TREE_VALUE (parms2)))))
00975 same = 0;
00976
00977
00978 if (TREE_CODE (fn) == TEMPLATE_DECL
00979 && !comp_template_parms (DECL_TEMPLATE_PARMS (fn),
00980 DECL_TEMPLATE_PARMS (method)))
00981 same = 0;
00982
00983 if (! DECL_STATIC_FUNCTION_P (fn))
00984 parms1 = TREE_CHAIN (parms1);
00985 if (! DECL_STATIC_FUNCTION_P (method))
00986 parms2 = TREE_CHAIN (parms2);
00987
00988 if (same && compparms (parms1, parms2)
00989 && (!DECL_CONV_FN_P (fn)
00990 || same_type_p (TREE_TYPE (TREE_TYPE (fn)),
00991 TREE_TYPE (TREE_TYPE (method)))))
00992 {
00993 if (using && DECL_CONTEXT (fn) == type)
00994
00995 return;
00996 else
00997 {
00998 cp_error_at ("`%#D' and `%#D' cannot be overloaded",
00999 method, fn, method);
01000
01001
01002
01003
01004
01005
01006 return;
01007 }
01008 }
01009 }
01010 }
01011
01012
01013 TREE_VEC_ELT (method_vec, slot)
01014 = build_overload (method, TREE_VEC_ELT (method_vec, slot));
01015
01016
01017 if (!DECL_CONSTRUCTOR_P (method)
01018 && !DECL_DESTRUCTOR_P (method))
01019 push_class_level_binding (DECL_NAME (method),
01020 TREE_VEC_ELT (method_vec, slot));
01021 }
01022
01023
01024
01025
01026
01027
01028
01029
01030
01031
01032
01033
01034
01035
01036
01037
01038
01039 static tree
01040 delete_duplicate_fields_1 (field, fields)
01041 tree field, fields;
01042 {
01043 tree x;
01044 tree prev = 0;
01045 if (DECL_NAME (field) == 0)
01046 {
01047 if (! ANON_AGGR_TYPE_P (TREE_TYPE (field)))
01048 return fields;
01049
01050 for (x = TYPE_FIELDS (TREE_TYPE (field)); x; x = TREE_CHAIN (x))
01051 fields = delete_duplicate_fields_1 (x, fields);
01052 return fields;
01053 }
01054 else
01055 {
01056 for (x = fields; x; prev = x, x = TREE_CHAIN (x))
01057 {
01058 if (DECL_NAME (x) == 0)
01059 {
01060 if (! ANON_AGGR_TYPE_P (TREE_TYPE (x)))
01061 continue;
01062 TYPE_FIELDS (TREE_TYPE (x))
01063 = delete_duplicate_fields_1 (field, TYPE_FIELDS (TREE_TYPE (x)));
01064 if (TYPE_FIELDS (TREE_TYPE (x)) == 0)
01065 {
01066 if (prev == 0)
01067 fields = TREE_CHAIN (fields);
01068 else
01069 TREE_CHAIN (prev) = TREE_CHAIN (x);
01070 }
01071 }
01072 else if (TREE_CODE (field) == USING_DECL)
01073
01074
01075
01076
01077 ;
01078 else if (DECL_NAME (field) == DECL_NAME (x))
01079 {
01080 if (TREE_CODE (field) == CONST_DECL
01081 && TREE_CODE (x) == CONST_DECL)
01082 cp_error_at ("duplicate enum value `%D'", x);
01083 else if (TREE_CODE (field) == CONST_DECL
01084 || TREE_CODE (x) == CONST_DECL)
01085 cp_error_at ("duplicate field `%D' (as enum and non-enum)",
01086 x);
01087 else if (DECL_DECLARES_TYPE_P (field)
01088 && DECL_DECLARES_TYPE_P (x))
01089 {
01090 if (same_type_p (TREE_TYPE (field), TREE_TYPE (x)))
01091 continue;
01092 cp_error_at ("duplicate nested type `%D'", x);
01093 }
01094 else if (DECL_DECLARES_TYPE_P (field)
01095 || DECL_DECLARES_TYPE_P (x))
01096 {
01097
01098 if ((TREE_CODE (field) == TYPE_DECL
01099 && DECL_ARTIFICIAL (field))
01100 || (TREE_CODE (x) == TYPE_DECL
01101 && DECL_ARTIFICIAL (x)))
01102 continue;
01103 cp_error_at ("duplicate field `%D' (as type and non-type)",
01104 x);
01105 }
01106 else
01107 cp_error_at ("duplicate member `%D'", x);
01108 if (prev == 0)
01109 fields = TREE_CHAIN (fields);
01110 else
01111 TREE_CHAIN (prev) = TREE_CHAIN (x);
01112 }
01113 }
01114 }
01115 return fields;
01116 }
01117
01118 static void
01119 delete_duplicate_fields (fields)
01120 tree fields;
01121 {
01122 tree x;
01123 for (x = fields; x && TREE_CHAIN (x); x = TREE_CHAIN (x))
01124 TREE_CHAIN (x) = delete_duplicate_fields_1 (x, TREE_CHAIN (x));
01125 }
01126
01127
01128
01129
01130 static int
01131 alter_access (t, fdecl, access)
01132 tree t;
01133 tree fdecl;
01134 tree access;
01135 {
01136 tree elem;
01137
01138 if (!DECL_LANG_SPECIFIC (fdecl))
01139 retrofit_lang_decl (fdecl);
01140
01141 if (DECL_DISCRIMINATOR_P (fdecl))
01142 abort ();
01143
01144 elem = purpose_member (t, DECL_ACCESS (fdecl));
01145 if (elem)
01146 {
01147 if (TREE_VALUE (elem) != access)
01148 {
01149 if (TREE_CODE (TREE_TYPE (fdecl)) == FUNCTION_DECL)
01150 cp_error_at ("conflicting access specifications for method `%D', ignored", TREE_TYPE (fdecl));
01151 else
01152 error ("conflicting access specifications for field `%s', ignored",
01153 IDENTIFIER_POINTER (DECL_NAME (fdecl)));
01154 }
01155 else
01156 {
01157
01158
01159 ;
01160 }
01161 }
01162 else
01163 {
01164 enforce_access (t, fdecl);
01165 DECL_ACCESS (fdecl) = tree_cons (t, access, DECL_ACCESS (fdecl));
01166 return 1;
01167 }
01168 return 0;
01169 }
01170
01171
01172
01173 static void
01174 handle_using_decl (using_decl, t)
01175 tree using_decl;
01176 tree t;
01177 {
01178 tree ctype = DECL_INITIAL (using_decl);
01179 tree name = DECL_NAME (using_decl);
01180 tree access
01181 = TREE_PRIVATE (using_decl) ? access_private_node
01182 : TREE_PROTECTED (using_decl) ? access_protected_node
01183 : access_public_node;
01184 tree fdecl, binfo;
01185 tree flist = NULL_TREE;
01186 tree old_value;
01187
01188 if (ctype == error_mark_node)
01189 return;
01190
01191 binfo = lookup_base (t, ctype, ba_any, NULL);
01192 if (! binfo)
01193 {
01194 error_not_base_type (t, ctype);
01195 return;
01196 }
01197
01198 if (constructor_name_p (name, ctype))
01199 {
01200 cp_error_at ("`%D' names constructor", using_decl);
01201 return;
01202 }
01203 if (constructor_name_p (name, t))
01204 {
01205 cp_error_at ("`%D' invalid in `%T'", using_decl, t);
01206 return;
01207 }
01208
01209 fdecl = lookup_member (binfo, name, 0, 0);
01210
01211 if (!fdecl)
01212 {
01213 cp_error_at ("no members matching `%D' in `%#T'", using_decl, ctype);
01214 return;
01215 }
01216
01217 if (BASELINK_P (fdecl))
01218
01219 fdecl = BASELINK_FUNCTIONS (fdecl);
01220
01221 old_value = IDENTIFIER_CLASS_VALUE (name);
01222 if (old_value)
01223 {
01224 if (is_overloaded_fn (old_value))
01225 old_value = OVL_CURRENT (old_value);
01226
01227 if (DECL_P (old_value) && DECL_CONTEXT (old_value) == t)
01228 ;
01229 else
01230 old_value = NULL_TREE;
01231 }
01232
01233 if (is_overloaded_fn (fdecl))
01234 flist = fdecl;
01235
01236 if (! old_value)
01237 ;
01238 else if (is_overloaded_fn (old_value))
01239 {
01240 if (flist)
01241
01242 ;
01243 else
01244 {
01245 cp_error_at ("`%D' invalid in `%#T'", using_decl, t);
01246 cp_error_at (" because of local method `%#D' with same name",
01247 OVL_CURRENT (old_value));
01248 return;
01249 }
01250 }
01251 else if (!DECL_ARTIFICIAL (old_value))
01252 {
01253 cp_error_at ("`%D' invalid in `%#T'", using_decl, t);
01254 cp_error_at (" because of local member `%#D' with same name", old_value);
01255 return;
01256 }
01257
01258
01259 if (flist)
01260 for (; flist; flist = OVL_NEXT (flist))
01261 {
01262 add_method (t, OVL_CURRENT (flist), 0);
01263 alter_access (t, OVL_CURRENT (flist), access);
01264 }
01265 else
01266 alter_access (t, fdecl, access);
01267 }
01268
01269
01270
01271
01272
01273
01274 static void
01275 check_bases (t, cant_have_default_ctor_p, cant_have_const_ctor_p,
01276 no_const_asn_ref_p)
01277 tree t;
01278 int *cant_have_default_ctor_p;
01279 int *cant_have_const_ctor_p;
01280 int *no_const_asn_ref_p;
01281 {
01282 int n_baseclasses;
01283 int i;
01284 int seen_non_virtual_nearly_empty_base_p;
01285 tree binfos;
01286
01287 binfos = TYPE_BINFO_BASETYPES (t);
01288 n_baseclasses = CLASSTYPE_N_BASECLASSES (t);
01289 seen_non_virtual_nearly_empty_base_p = 0;
01290
01291
01292 CLASSTYPE_NON_AGGREGATE (t) |= (n_baseclasses != 0);
01293
01294 for (i = 0; i < n_baseclasses; ++i)
01295 {
01296 tree base_binfo;
01297 tree basetype;
01298
01299
01300 base_binfo = TREE_VEC_ELT (binfos, i);
01301 basetype = TREE_TYPE (base_binfo);
01302
01303
01304
01305
01306 if (!COMPLETE_TYPE_P (basetype))
01307 {
01308 int j;
01309
01310
01311
01312 if (i == n_baseclasses-1)
01313 TREE_VEC_ELT (binfos, i) = NULL_TREE;
01314 TREE_VEC_LENGTH (binfos) -= 1;
01315 n_baseclasses -= 1;
01316 for (j = i; j+1 < n_baseclasses; j++)
01317 TREE_VEC_ELT (binfos, j) = TREE_VEC_ELT (binfos, j+1);
01318 continue;
01319 }
01320
01321
01322
01323
01324 if (warn_ecpp && ! TYPE_POLYMORPHIC_P (basetype)
01325 && TYPE_HAS_DESTRUCTOR (basetype))
01326 warning ("base class `%#T' has a non-virtual destructor",
01327 basetype);
01328
01329
01330
01331
01332
01333 if (! TYPE_HAS_CONST_INIT_REF (basetype))
01334 *cant_have_const_ctor_p = 1;
01335 if (TYPE_HAS_ASSIGN_REF (basetype)
01336 && !TYPE_HAS_CONST_ASSIGN_REF (basetype))
01337 *no_const_asn_ref_p = 1;
01338
01339
01340
01341 if (TYPE_HAS_CONSTRUCTOR (basetype)
01342 && ! TYPE_HAS_DEFAULT_CONSTRUCTOR (basetype))
01343 {
01344 *cant_have_default_ctor_p = 1;
01345 if (! TYPE_HAS_CONSTRUCTOR (t))
01346 pedwarn ("base `%T' with only non-default constructor in class without a constructor",
01347 basetype);
01348 }
01349
01350 if (TREE_VIA_VIRTUAL (base_binfo))
01351
01352 ;
01353 else if (CLASSTYPE_NEARLY_EMPTY_P (basetype))
01354 {
01355 if (seen_non_virtual_nearly_empty_base_p)
01356
01357
01358 CLASSTYPE_NEARLY_EMPTY_P (t) = 0;
01359 else
01360
01361 seen_non_virtual_nearly_empty_base_p = 1;
01362 }
01363 else if (!is_empty_class (basetype))
01364
01365
01366 CLASSTYPE_NEARLY_EMPTY_P (t) = 0;
01367
01368
01369
01370 TYPE_NEEDS_CONSTRUCTING (t) |= TYPE_NEEDS_CONSTRUCTING (basetype);
01371 TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)
01372 |= TYPE_HAS_NONTRIVIAL_DESTRUCTOR (basetype);
01373 TYPE_HAS_COMPLEX_ASSIGN_REF (t)
01374 |= TYPE_HAS_COMPLEX_ASSIGN_REF (basetype);
01375 TYPE_HAS_COMPLEX_INIT_REF (t) |= TYPE_HAS_COMPLEX_INIT_REF (basetype);
01376 TYPE_OVERLOADS_CALL_EXPR (t) |= TYPE_OVERLOADS_CALL_EXPR (basetype);
01377 TYPE_OVERLOADS_ARRAY_REF (t) |= TYPE_OVERLOADS_ARRAY_REF (basetype);
01378 TYPE_OVERLOADS_ARROW (t) |= TYPE_OVERLOADS_ARROW (basetype);
01379 TYPE_POLYMORPHIC_P (t) |= TYPE_POLYMORPHIC_P (basetype);
01380 CLASSTYPE_CONTAINS_EMPTY_CLASS_P (t)
01381 |= CLASSTYPE_CONTAINS_EMPTY_CLASS_P (basetype);
01382 }
01383 }
01384
01385
01386
01387
01388
01389
01390 static void
01391 force_canonical_binfo_r (to, from, type, mappings)
01392 tree to;
01393 tree from;
01394 tree type;
01395 tree mappings;
01396 {
01397 int i, n_baseclasses = BINFO_N_BASETYPES (from);
01398
01399 my_friendly_assert (to != from, 20010905);
01400 BINFO_INDIRECT_PRIMARY_P (to)
01401 = BINFO_INDIRECT_PRIMARY_P (from);
01402 BINFO_INDIRECT_PRIMARY_P (from) = 0;
01403 BINFO_UNSHARED_MARKED (to) = BINFO_UNSHARED_MARKED (from);
01404 BINFO_UNSHARED_MARKED (from) = 0;
01405 BINFO_LOST_PRIMARY_P (to) = BINFO_LOST_PRIMARY_P (from);
01406 BINFO_LOST_PRIMARY_P (from) = 0;
01407 if (BINFO_PRIMARY_P (from))
01408 {
01409 tree primary = BINFO_PRIMARY_BASE_OF (from);
01410 tree assoc;
01411
01412
01413
01414 assoc = purpose_member (primary, mappings);
01415 if (assoc)
01416 primary = TREE_VALUE (assoc);
01417 BINFO_PRIMARY_BASE_OF (to) = primary;
01418 BINFO_PRIMARY_BASE_OF (from) = NULL_TREE;
01419 }
01420 my_friendly_assert (same_type_p (BINFO_TYPE (to), BINFO_TYPE (from)),
01421 20010104);
01422 mappings = tree_cons (from, to, mappings);
01423
01424 if (CLASSTYPE_HAS_PRIMARY_BASE_P (BINFO_TYPE (from))
01425 && TREE_VIA_VIRTUAL (CLASSTYPE_PRIMARY_BINFO (BINFO_TYPE (from))))
01426 {
01427 tree from_primary = get_primary_binfo (from);
01428
01429 if (BINFO_PRIMARY_BASE_OF (from_primary) == from)
01430 force_canonical_binfo (get_primary_binfo (to), from_primary,
01431 type, mappings);
01432 }
01433
01434 for (i = 0; i != n_baseclasses; i++)
01435 {
01436 tree from_binfo = BINFO_BASETYPE (from, i);
01437 tree to_binfo = BINFO_BASETYPE (to, i);
01438
01439 if (TREE_VIA_VIRTUAL (from_binfo))
01440 {
01441 if (BINFO_PRIMARY_P (from_binfo) &&
01442 purpose_member (BINFO_PRIMARY_BASE_OF (from_binfo), mappings))
01443
01444
01445 force_canonical_binfo (to_binfo, from_binfo, type, mappings);
01446 }
01447 else
01448 force_canonical_binfo_r (to_binfo, from_binfo, type, mappings);
01449 }
01450 }
01451
01452
01453
01454
01455
01456
01457
01458
01459
01460
01461
01462 static void
01463 force_canonical_binfo (to, from, type, mappings)
01464 tree to;
01465 tree from;
01466 tree type;
01467 tree mappings;
01468 {
01469 tree assoc = purpose_member (BINFO_TYPE (to),
01470 CLASSTYPE_VBASECLASSES (type));
01471 if (TREE_VALUE (assoc) != to)
01472 {
01473 TREE_VALUE (assoc) = to;
01474 force_canonical_binfo_r (to, from, type, mappings);
01475 }
01476 }
01477
01478
01479
01480
01481
01482 static tree
01483 mark_primary_virtual_base (base_binfo, type)
01484 tree base_binfo;
01485 tree type;
01486 {
01487 tree shared_binfo = binfo_for_vbase (BINFO_TYPE (base_binfo), type);
01488
01489 if (BINFO_PRIMARY_P (shared_binfo))
01490 {
01491
01492
01493
01494 return NULL_TREE;
01495 }
01496
01497
01498
01499
01500
01501 if (base_binfo != shared_binfo)
01502 force_canonical_binfo (base_binfo, shared_binfo, type, NULL);
01503
01504 return base_binfo;
01505 }
01506
01507
01508
01509
01510
01511 static tree dfs_unshared_virtual_bases (binfo, data)
01512 tree binfo;
01513 void *data;
01514 {
01515 tree t = (tree) data;
01516
01517 if (!BINFO_UNSHARED_MARKED (binfo)
01518 && CLASSTYPE_HAS_PRIMARY_BASE_P (BINFO_TYPE (binfo)))
01519 {
01520
01521
01522
01523
01524 tree vbase;
01525 tree unshared_base;
01526
01527 for (vbase = binfo; !TREE_VIA_VIRTUAL (vbase);
01528 vbase = BINFO_INHERITANCE_CHAIN (vbase))
01529 continue;
01530 unshared_base = get_original_base (binfo,
01531 binfo_for_vbase (BINFO_TYPE (vbase),
01532 t));
01533 my_friendly_assert (unshared_base != binfo, 20010612);
01534 BINFO_LOST_PRIMARY_P (binfo) = BINFO_LOST_PRIMARY_P (unshared_base);
01535 if (!BINFO_LOST_PRIMARY_P (binfo))
01536 BINFO_PRIMARY_BASE_OF (get_primary_binfo (binfo)) = binfo;
01537 }
01538
01539 if (binfo != TYPE_BINFO (t))
01540
01541
01542
01543 BINFO_VTABLE (binfo) = NULL_TREE;
01544
01545
01546
01547 if (BINFO_PRIMARY_P (binfo) && TREE_VIA_VIRTUAL (binfo) &&
01548 binfo_for_vbase (BINFO_TYPE (binfo), t) == binfo)
01549 {
01550 tree delta = size_diffop (BINFO_OFFSET (BINFO_PRIMARY_BASE_OF (binfo)),
01551 BINFO_OFFSET (binfo));
01552 if (!integer_zerop (delta))
01553 propagate_binfo_offsets (binfo, delta, t);
01554 }
01555
01556 BINFO_UNSHARED_MARKED (binfo) = 0;
01557 return NULL;
01558 }
01559
01560
01561
01562
01563 static void
01564 mark_primary_bases (type)
01565 tree type;
01566 {
01567 tree binfo;
01568
01569
01570 for (binfo = TYPE_BINFO (type); binfo; binfo = TREE_CHAIN (binfo))
01571 {
01572 tree base_binfo;
01573
01574 if (!CLASSTYPE_HAS_PRIMARY_BASE_P (BINFO_TYPE (binfo)))
01575
01576 continue;
01577
01578 base_binfo = get_primary_binfo (binfo);
01579
01580 if (TREE_VIA_VIRTUAL (base_binfo))
01581 base_binfo = mark_primary_virtual_base (base_binfo, type);
01582
01583 if (base_binfo)
01584 BINFO_PRIMARY_BASE_OF (base_binfo) = binfo;
01585 else
01586 BINFO_LOST_PRIMARY_P (binfo) = 1;
01587
01588 BINFO_UNSHARED_MARKED (binfo) = 1;
01589 }
01590
01591
01592
01593
01594
01595
01596
01597
01598 dfs_walk (TYPE_BINFO (type), dfs_unshared_virtual_bases, NULL, type);
01599 }
01600
01601
01602
01603 static void
01604 set_primary_base (t, binfo)
01605 tree t;
01606 tree binfo;
01607 {
01608 tree basetype;
01609
01610 CLASSTYPE_PRIMARY_BINFO (t) = binfo;
01611 basetype = BINFO_TYPE (binfo);
01612 TYPE_BINFO_VTABLE (t) = TYPE_BINFO_VTABLE (basetype);
01613 TYPE_BINFO_VIRTUALS (t) = TYPE_BINFO_VIRTUALS (basetype);
01614 TYPE_VFIELD (t) = TYPE_VFIELD (basetype);
01615 }
01616
01617
01618
01619 static void
01620 determine_primary_base (t)
01621 tree t;
01622 {
01623 int i, n_baseclasses = CLASSTYPE_N_BASECLASSES (t);
01624 tree vbases;
01625 tree type_binfo;
01626
01627
01628 if (n_baseclasses == 0)
01629 return;
01630
01631 type_binfo = TYPE_BINFO (t);
01632
01633 for (i = 0; i < n_baseclasses; i++)
01634 {
01635 tree base_binfo = BINFO_BASETYPE (type_binfo, i);
01636 tree basetype = BINFO_TYPE (base_binfo);
01637
01638 if (TYPE_CONTAINS_VPTR_P (basetype))
01639 {
01640
01641
01642 if (TREE_VIA_VIRTUAL (base_binfo))
01643 continue;
01644
01645 if (!CLASSTYPE_HAS_PRIMARY_BASE_P (t))
01646 {
01647 set_primary_base (t, base_binfo);
01648 CLASSTYPE_VFIELDS (t) = copy_list (CLASSTYPE_VFIELDS (basetype));
01649 }
01650 else
01651 {
01652 tree vfields;
01653
01654
01655 for (vfields = CLASSTYPE_VFIELDS (basetype);
01656 vfields;
01657 vfields = TREE_CHAIN (vfields))
01658 if (VF_BINFO_VALUE (vfields) == NULL_TREE
01659 || ! TREE_VIA_VIRTUAL (VF_BINFO_VALUE (vfields)))
01660 CLASSTYPE_VFIELDS (t)
01661 = tree_cons (base_binfo,
01662 VF_BASETYPE_VALUE (vfields),
01663 CLASSTYPE_VFIELDS (t));
01664 }
01665 }
01666 }
01667
01668 if (!TYPE_VFIELD (t))
01669 CLASSTYPE_PRIMARY_BINFO (t) = NULL_TREE;
01670
01671
01672
01673 for (vbases = CLASSTYPE_VBASECLASSES (t);
01674 vbases;
01675 vbases = TREE_CHAIN (vbases))
01676 {
01677 tree vbase_binfo = TREE_VALUE (vbases);
01678
01679
01680
01681
01682 for (i = 0; i < n_baseclasses; ++i)
01683 {
01684 tree basetype = TYPE_BINFO_BASETYPE (t, i);
01685 tree v;
01686
01687 for (v = CLASSTYPE_VBASECLASSES (basetype);
01688 v;
01689 v = TREE_CHAIN (v))
01690 {
01691 tree base_vbase = TREE_VALUE (v);
01692
01693 if (BINFO_PRIMARY_P (base_vbase)
01694 && same_type_p (BINFO_TYPE (base_vbase),
01695 BINFO_TYPE (vbase_binfo)))
01696 {
01697 BINFO_INDIRECT_PRIMARY_P (vbase_binfo) = 1;
01698 break;
01699 }
01700 }
01701
01702
01703
01704
01705 if (BINFO_INDIRECT_PRIMARY_P (vbase_binfo))
01706 break;
01707 }
01708 }
01709
01710
01711
01712 if (!CLASSTYPE_HAS_PRIMARY_BASE_P (t))
01713 {
01714
01715
01716 tree candidate = NULL_TREE;
01717 tree base_binfo;
01718
01719
01720 for (base_binfo = TYPE_BINFO (t);
01721 base_binfo;
01722 base_binfo = TREE_CHAIN (base_binfo))
01723 {
01724 tree basetype = BINFO_TYPE (base_binfo);
01725
01726 if (TREE_VIA_VIRTUAL (base_binfo)
01727 && CLASSTYPE_NEARLY_EMPTY_P (basetype))
01728 {
01729
01730
01731 if (!BINFO_INDIRECT_PRIMARY_P (base_binfo))
01732 {
01733 candidate = base_binfo;
01734 break;
01735 }
01736
01737
01738
01739
01740
01741 if (!candidate)
01742 candidate = base_binfo;
01743 }
01744 }
01745
01746
01747 if (candidate)
01748 {
01749 set_primary_base (t, candidate);
01750 CLASSTYPE_VFIELDS (t)
01751 = copy_list (CLASSTYPE_VFIELDS (BINFO_TYPE (candidate)));
01752 }
01753 }
01754
01755
01756 mark_primary_bases (t);
01757 }
01758
01759
01760
01761
01762 static void
01763 finish_struct_bits (t)
01764 tree t;
01765 {
01766 int i, n_baseclasses = CLASSTYPE_N_BASECLASSES (t);
01767
01768
01769 tree variants = TYPE_NEXT_VARIANT (t);
01770 while (variants)
01771 {
01772
01773
01774 TYPE_HAS_CONSTRUCTOR (variants) = TYPE_HAS_CONSTRUCTOR (t);
01775 TYPE_HAS_DESTRUCTOR (variants) = TYPE_HAS_DESTRUCTOR (t);
01776 TYPE_NEEDS_CONSTRUCTING (variants) = TYPE_NEEDS_CONSTRUCTING (t);
01777 TYPE_HAS_NONTRIVIAL_DESTRUCTOR (variants)
01778 = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t);
01779
01780 TYPE_BASE_CONVS_MAY_REQUIRE_CODE_P (variants)
01781 = TYPE_BASE_CONVS_MAY_REQUIRE_CODE_P (t);
01782 TYPE_POLYMORPHIC_P (variants) = TYPE_POLYMORPHIC_P (t);
01783 TYPE_USES_VIRTUAL_BASECLASSES (variants) = TYPE_USES_VIRTUAL_BASECLASSES (t);
01784
01785 TYPE_MIN_VALUE (variants) = TYPE_MIN_VALUE (t);
01786 TYPE_MAX_VALUE (variants) = TYPE_MAX_VALUE (t);
01787 TYPE_FIELDS (variants) = TYPE_FIELDS (t);
01788 TYPE_SIZE (variants) = TYPE_SIZE (t);
01789 TYPE_SIZE_UNIT (variants) = TYPE_SIZE_UNIT (t);
01790 variants = TYPE_NEXT_VARIANT (variants);
01791 }
01792
01793 if (n_baseclasses && TYPE_POLYMORPHIC_P (t))
01794
01795
01796
01797
01798
01799
01800
01801
01802 get_pure_virtuals (t);
01803
01804 if (n_baseclasses)
01805 {
01806
01807 tree binfo = TYPE_BINFO (t);
01808 tree binfos = BINFO_BASETYPES (binfo);
01809 tree basetype;
01810
01811 for (i = n_baseclasses-1; i >= 0; i--)
01812 {
01813 basetype = BINFO_TYPE (TREE_VEC_ELT (binfos, i));
01814
01815 TYPE_HAS_CONVERSION (t) |= TYPE_HAS_CONVERSION (basetype);
01816 }
01817 }
01818
01819
01820
01821
01822
01823 if (! TYPE_HAS_TRIVIAL_INIT_REF (t) || TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t))
01824 {
01825 tree variants;
01826 DECL_MODE (TYPE_MAIN_DECL (t)) = BLKmode;
01827 for (variants = t; variants; variants = TYPE_NEXT_VARIANT (variants))
01828 {
01829 TYPE_MODE (variants) = BLKmode;
01830 TREE_ADDRESSABLE (variants) = 1;
01831 }
01832 }
01833 }
01834
01835
01836
01837
01838
01839
01840
01841
01842 static void
01843 maybe_warn_about_overly_private_class (t)
01844 tree t;
01845 {
01846 int has_member_fn = 0;
01847 int has_nonprivate_method = 0;
01848 tree fn;
01849
01850 if (!warn_ctor_dtor_privacy
01851
01852
01853 || (CLASSTYPE_FRIEND_CLASSES (t)
01854 || DECL_FRIENDLIST (TYPE_MAIN_DECL (t)))
01855
01856
01857 || CLASSTYPE_TEMPLATE_INSTANTIATION (t))
01858
01859
01860 return;
01861
01862
01863
01864
01865
01866
01867
01868
01869
01870
01871
01872
01873
01874
01875
01876
01877
01878 for (fn = TYPE_METHODS (t); fn; fn = TREE_CHAIN (fn))
01879
01880
01881 if (!DECL_ARTIFICIAL (fn))
01882 {
01883 if (!TREE_PRIVATE (fn))
01884 {
01885 if (DECL_STATIC_FUNCTION_P (fn))
01886
01887
01888
01889
01890 return;
01891
01892 has_nonprivate_method = 1;
01893
01894 }
01895 else if (!DECL_CONSTRUCTOR_P (fn) && !DECL_DESTRUCTOR_P (fn))
01896 has_member_fn = 1;
01897 }
01898
01899 if (!has_nonprivate_method && has_member_fn)
01900 {
01901
01902
01903
01904
01905
01906
01907 int i;
01908 tree binfos = BINFO_BASETYPES (TYPE_BINFO (t));
01909 for (i = 0; i < CLASSTYPE_N_BASECLASSES (t); i++)
01910 if (TREE_VIA_PUBLIC (TREE_VEC_ELT (binfos, i))
01911 || TREE_VIA_PROTECTED (TREE_VEC_ELT (binfos, i)))
01912 {
01913 has_nonprivate_method = 1;
01914 break;
01915 }
01916 if (!has_nonprivate_method)
01917 {
01918 warning ("all member functions in class `%T' are private", t);
01919 return;
01920 }
01921 }
01922
01923
01924
01925
01926 if (TYPE_HAS_DESTRUCTOR (t))
01927 {
01928 tree dtor = TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (t), 1);
01929
01930 if (TREE_PRIVATE (dtor))
01931 {
01932 warning ("`%#T' only defines a private destructor and has no friends",
01933 t);
01934 return;
01935 }
01936 }
01937
01938 if (TYPE_HAS_CONSTRUCTOR (t))
01939 {
01940 int nonprivate_ctor = 0;
01941
01942
01943
01944
01945
01946
01947
01948
01949
01950
01951
01952 if (!TYPE_HAS_INIT_REF (t))
01953 nonprivate_ctor = 1;
01954 else
01955 for (fn = TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (t), 0);
01956 fn;
01957 fn = OVL_NEXT (fn))
01958 {
01959 tree ctor = OVL_CURRENT (fn);
01960
01961
01962
01963
01964
01965
01966 if (! TREE_PRIVATE (ctor))
01967 {
01968 nonprivate_ctor = 1;
01969 break;
01970 }
01971 }
01972
01973 if (nonprivate_ctor == 0)
01974 {
01975 warning ("`%#T' only defines private constructors and has no friends",
01976 t);
01977 return;
01978 }
01979 }
01980 }
01981
01982
01983
01984 static int
01985 field_decl_cmp (x, y)
01986 const tree *x, *y;
01987 {
01988 if (DECL_NAME (*x) == DECL_NAME (*y))
01989
01990 return DECL_DECLARES_TYPE_P (*y) - DECL_DECLARES_TYPE_P (*x);
01991 if (DECL_NAME (*x) == NULL_TREE)
01992 return -1;
01993 if (DECL_NAME (*y) == NULL_TREE)
01994 return 1;
01995 if (DECL_NAME (*x) < DECL_NAME (*y))
01996 return -1;
01997 return 1;
01998 }
01999
02000
02001
02002 static int
02003 method_name_cmp (m1, m2)
02004 const tree *m1, *m2;
02005 {
02006 if (*m1 == NULL_TREE && *m2 == NULL_TREE)
02007 return 0;
02008 if (*m1 == NULL_TREE)
02009 return -1;
02010 if (*m2 == NULL_TREE)
02011 return 1;
02012 if (DECL_NAME (OVL_CURRENT (*m1)) < DECL_NAME (OVL_CURRENT (*m2)))
02013 return -1;
02014 return 1;
02015 }
02016
02017
02018
02019
02020
02021
02022
02023
02024
02025
02026
02027
02028
02029
02030
02031
02032
02033 static void
02034 finish_struct_methods (t)
02035 tree t;
02036 {
02037 tree fn_fields;
02038 tree method_vec;
02039 int slot, len;
02040
02041 if (!TYPE_METHODS (t))
02042 {
02043
02044
02045 TYPE_HAS_CONSTRUCTOR (t) = 0;
02046 TYPE_HAS_DESTRUCTOR (t) = 0;
02047 CLASSTYPE_METHOD_VEC (t) = NULL_TREE;
02048 return;
02049 }
02050
02051 method_vec = CLASSTYPE_METHOD_VEC (t);
02052 my_friendly_assert (method_vec != NULL_TREE, 19991215);
02053 len = TREE_VEC_LENGTH (method_vec);
02054
02055
02056
02057 for (fn_fields = TYPE_METHODS (t); fn_fields;
02058 fn_fields = TREE_CHAIN (fn_fields))
02059
02060 DECL_IN_AGGR_P (fn_fields) = 0;
02061
02062 if (TYPE_HAS_DESTRUCTOR (t) && !CLASSTYPE_DESTRUCTORS (t))
02063
02064
02065 TYPE_HAS_DESTRUCTOR (t) = 0;
02066
02067
02068
02069 maybe_warn_about_overly_private_class (t);
02070
02071
02072 while (len > 2 && TREE_VEC_ELT (method_vec, len-1) == NULL_TREE)
02073 len--;
02074 TREE_VEC_LENGTH (method_vec) = len;
02075
02076
02077
02078 for (slot = 2; slot < len; ++slot)
02079 {
02080 tree fn = TREE_VEC_ELT (method_vec, slot);
02081
02082 if (!DECL_CONV_FN_P (OVL_CURRENT (fn)))
02083 break;
02084 }
02085 if (len - slot > 1)
02086 qsort (&TREE_VEC_ELT (method_vec, slot), len-slot, sizeof (tree),
02087 (int (*)(const void *, const void *))method_name_cmp);
02088 }
02089
02090
02091
02092 void
02093 duplicate_tag_error (t)
02094 tree t;
02095 {
02096 error ("redefinition of `%#T'", t);
02097 cp_error_at ("previous definition of `%#T'", t);
02098
02099
02100
02101
02102
02103
02104
02105
02106
02107
02108
02109 if (CLASSTYPE_METHOD_VEC (t))
02110 {
02111 tree method_vec = CLASSTYPE_METHOD_VEC (t);
02112 int i, len = TREE_VEC_LENGTH (method_vec);
02113 for (i = 0; i < len; i++)
02114 {
02115 tree unchain = TREE_VEC_ELT (method_vec, i);
02116 while (unchain != NULL_TREE)
02117 {
02118 TREE_CHAIN (OVL_CURRENT (unchain)) = NULL_TREE;
02119 unchain = OVL_NEXT (unchain);
02120 }
02121 }
02122 }
02123
02124 if (TYPE_LANG_SPECIFIC (t))
02125 {
02126 tree binfo = TYPE_BINFO (t);
02127 int interface_only = CLASSTYPE_INTERFACE_ONLY (t);
02128 int interface_unknown = CLASSTYPE_INTERFACE_UNKNOWN (t);
02129 tree template_info = CLASSTYPE_TEMPLATE_INFO (t);
02130 int use_template = CLASSTYPE_USE_TEMPLATE (t);
02131
02132 memset ((char *) TYPE_LANG_SPECIFIC (t), 0, sizeof (struct lang_type));
02133 BINFO_BASETYPES(binfo) = NULL_TREE;
02134
02135 TYPE_LANG_SPECIFIC (t)->u.h.is_lang_type_class = 1;
02136 TYPE_BINFO (t) = binfo;
02137 CLASSTYPE_INTERFACE_ONLY (t) = interface_only;
02138 SET_CLASSTYPE_INTERFACE_UNKNOWN_X (t, interface_unknown);
02139 TYPE_REDEFINED (t) = 1;
02140 CLASSTYPE_TEMPLATE_INFO (t) = template_info;
02141 CLASSTYPE_USE_TEMPLATE (t) = use_template;
02142 CLASSTYPE_DECL_LIST (t) = NULL_TREE;
02143 }
02144 TYPE_SIZE (t) = NULL_TREE;
02145 TYPE_MODE (t) = VOIDmode;
02146 TYPE_FIELDS (t) = NULL_TREE;
02147 TYPE_METHODS (t) = NULL_TREE;
02148 TYPE_VFIELD (t) = NULL_TREE;
02149 TYPE_CONTEXT (t) = NULL_TREE;
02150
02151
02152 TYPE_LANG_FLAG_0 (t) = 0;
02153 TYPE_LANG_FLAG_1 (t) = 0;
02154 TYPE_LANG_FLAG_2 (t) = 0;
02155 TYPE_LANG_FLAG_3 (t) = 0;
02156 TYPE_LANG_FLAG_4 (t) = 0;
02157 TYPE_LANG_FLAG_5 (t) = 0;
02158 TYPE_LANG_FLAG_6 (t) = 0;
02159
02160 SET_IS_AGGR_TYPE (t, 1);
02161 }
02162
02163
02164
02165
02166
02167 static void
02168 layout_vtable_decl (binfo, n)
02169 tree binfo;
02170 int n;
02171 {
02172 tree atype;
02173 tree vtable;
02174
02175 atype = build_cplus_array_type (vtable_entry_type,
02176 build_index_type (size_int (n - 1)));
02177 layout_type (atype);
02178
02179
02180 vtable = get_vtbl_decl_for_binfo (binfo);
02181 if (!same_type_p (TREE_TYPE (vtable), atype))
02182 {
02183 TREE_TYPE (vtable) = atype;
02184 DECL_SIZE (vtable) = DECL_SIZE_UNIT (vtable) = NULL_TREE;
02185 layout_decl (vtable, 0);
02186
02187
02188
02189 DECL_ALIGN (vtable) = MAX (TYPE_ALIGN (double_type_node),
02190 DECL_ALIGN (vtable));
02191 }
02192 }
02193
02194
02195
02196
02197 int
02198 same_signature_p (fndecl, base_fndecl)
02199 tree fndecl, base_fndecl;
02200 {
02201
02202
02203 if (DECL_DESTRUCTOR_P (base_fndecl) && DECL_DESTRUCTOR_P (fndecl)
02204 && special_function_p (base_fndecl) == special_function_p (fndecl))
02205 return 1;
02206
02207
02208
02209
02210 if (DECL_DESTRUCTOR_P (base_fndecl) || DECL_DESTRUCTOR_P (fndecl))
02211 return 0;
02212
02213 if (DECL_NAME (fndecl) == DECL_NAME (base_fndecl))
02214 {
02215 tree types, base_types;
02216 types = TYPE_ARG_TYPES (TREE_TYPE (fndecl));
02217 base_types = TYPE_ARG_TYPES (TREE_TYPE (base_fndecl));
02218 if ((TYPE_QUALS (TREE_TYPE (TREE_VALUE (base_types)))
02219 == TYPE_QUALS (TREE_TYPE (TREE_VALUE (types))))
02220 && compparms (TREE_CHAIN (base_types), TREE_CHAIN (types)))
02221 return 1;
02222 }
02223 return 0;
02224 }
02225
02226
02227
02228 static tree
02229 dfs_base_derived_from (tree binfo, void *data)
02230 {
02231 tree base = (tree) data;
02232
02233 if (same_type_p (TREE_TYPE (base), TREE_TYPE (binfo))
02234 && tree_int_cst_equal (BINFO_OFFSET (base), BINFO_OFFSET (binfo)))
02235 return error_mark_node;
02236
02237 return NULL_TREE;
02238 }
02239
02240
02241
02242
02243 static bool
02244 base_derived_from (tree derived, tree base)
02245 {
02246 return dfs_walk (derived, dfs_base_derived_from, NULL, base) != NULL_TREE;
02247 }
02248
02249 typedef struct find_final_overrider_data_s {
02250
02251 tree fn;
02252
02253 tree declaring_base;
02254
02255 tree most_derived_type;
02256
02257 tree candidates;
02258 } find_final_overrider_data;
02259
02260
02261
02262 static tree
02263 dfs_find_final_overrider (binfo, data)
02264 tree binfo;
02265 void *data;
02266 {
02267 find_final_overrider_data *ffod = (find_final_overrider_data *) data;
02268
02269 if (same_type_p (BINFO_TYPE (binfo),
02270 BINFO_TYPE (ffod->declaring_base))
02271 && tree_int_cst_equal (BINFO_OFFSET (binfo),
02272 BINFO_OFFSET (ffod->declaring_base)))
02273 {
02274 tree path;
02275 tree method;
02276
02277
02278 method = NULL_TREE;
02279
02280
02281 path = reverse_path (binfo);
02282 while (!same_type_p (BINFO_TYPE (TREE_VALUE (path)),
02283 ffod->most_derived_type))
02284 path = TREE_CHAIN (path);
02285 while (path)
02286 {
02287 method = look_for_overrides_here (BINFO_TYPE (TREE_VALUE (path)),
02288 ffod->fn);
02289 if (method)
02290 {
02291 path = TREE_VALUE (path);
02292 break;
02293 }
02294
02295 path = TREE_CHAIN (path);
02296 }
02297
02298
02299
02300 if (path)
02301 {
02302 tree *candidate;
02303
02304
02305 candidate = &ffod->candidates;
02306 while (*candidate)
02307 {
02308
02309
02310 if (base_derived_from (TREE_VALUE (*candidate), path))
02311 return NULL_TREE;
02312
02313 if (base_derived_from (path, TREE_VALUE (*candidate)))
02314 *candidate = TREE_CHAIN (*candidate);
02315 else
02316 candidate = &TREE_CHAIN (*candidate);
02317 }
02318
02319
02320 ffod->candidates = tree_cons (method, path, ffod->candidates);
02321 }
02322 }
02323
02324 return NULL_TREE;
02325 }
02326
02327
02328
02329
02330
02331
02332 static tree
02333 find_final_overrider (derived, binfo, fn)
02334 tree derived;
02335 tree binfo;
02336 tree fn;
02337 {
02338 find_final_overrider_data ffod;
02339
02340
02341
02342
02343
02344
02345
02346
02347
02348
02349
02350
02351
02352
02353
02354
02355
02356
02357
02358 ffod.fn = fn;
02359 ffod.declaring_base = binfo;
02360 ffod.most_derived_type = BINFO_TYPE (derived);
02361 ffod.candidates = NULL_TREE;
02362
02363 dfs_walk (derived,
02364 dfs_find_final_overrider,
02365 NULL,
02366 &ffod);
02367
02368
02369 if (!ffod.candidates || TREE_CHAIN (ffod.candidates))
02370 {
02371 error ("no unique final overrider for `%D' in `%T'", fn,
02372 BINFO_TYPE (derived));
02373 return error_mark_node;
02374 }
02375
02376 return ffod.candidates;
02377 }
02378
02379
02380
02381
02382 static tree
02383 get_vcall_index (tree fn, tree type)
02384 {
02385 tree v;
02386
02387 for (v = CLASSTYPE_VCALL_INDICES (type); v; v = TREE_CHAIN (v))
02388 if ((DECL_DESTRUCTOR_P (fn) && DECL_DESTRUCTOR_P (TREE_PURPOSE (v)))
02389 || same_signature_p (fn, TREE_PURPOSE (v)))
02390 break;
02391
02392
02393 my_friendly_assert (v, 20021103);
02394
02395 return TREE_VALUE (v);
02396 }
02397
02398
02399
02400
02401
02402 static void
02403 update_vtable_entry_for_fn (t, binfo, fn, virtuals)
02404 tree t;
02405 tree binfo;
02406 tree fn;
02407 tree *virtuals;
02408 {
02409 tree b;
02410 tree overrider;
02411 tree delta;
02412 tree virtual_base;
02413 tree first_defn;
02414 bool lost = false;
02415
02416
02417
02418
02419 for (b = binfo; ; b = get_primary_binfo (b))
02420 {
02421 if (look_for_overrides_here (BINFO_TYPE (b), fn))
02422 break;
02423
02424
02425 if (BINFO_LOST_PRIMARY_P (b))
02426 lost = true;
02427 }
02428 first_defn = b;
02429
02430
02431 overrider = find_final_overrider (TYPE_BINFO (t), b, fn);
02432 if (overrider == error_mark_node)
02433 return;
02434
02435
02436
02437 check_final_overrider (TREE_PURPOSE (overrider), fn);
02438
02439
02440
02441 virtual_base = NULL_TREE;
02442
02443
02444
02445 for (; b; b = BINFO_INHERITANCE_CHAIN (b))
02446 {
02447
02448
02449 if (same_type_p (BINFO_TYPE (b),
02450 BINFO_TYPE (TREE_VALUE (overrider))))
02451 break;
02452
02453
02454
02455
02456 if (!virtual_base && TREE_VIA_VIRTUAL (b))
02457 virtual_base = b;
02458 }
02459
02460
02461
02462
02463 if (virtual_base)
02464
02465
02466 delta = size_diffop (BINFO_OFFSET (virtual_base),
02467 BINFO_OFFSET (first_defn));
02468 else if (lost)
02469
02470
02471
02472
02473 delta = size_zero_node;
02474 else
02475
02476
02477
02478 delta = size_diffop (BINFO_OFFSET (TREE_VALUE (overrider)),
02479 BINFO_OFFSET (binfo));
02480
02481 modify_vtable_entry (t,
02482 binfo,
02483 TREE_PURPOSE (overrider),
02484 delta,
02485 virtuals);
02486
02487 if (virtual_base)
02488 BV_VCALL_INDEX (*virtuals)
02489 = get_vcall_index (TREE_PURPOSE (overrider),
02490 BINFO_TYPE (virtual_base));
02491 }
02492
02493
02494
02495 static tree
02496 dfs_modify_vtables (binfo, data)
02497 tree binfo;
02498 void *data;
02499 {
02500 if (
02501
02502
02503
02504 (!BINFO_PRIMARY_P (binfo) || TREE_VIA_VIRTUAL (binfo))
02505
02506 && CLASSTYPE_VFIELDS (BINFO_TYPE (binfo)))
02507 {
02508 tree t;
02509 tree virtuals;
02510 tree old_virtuals;
02511
02512 t = (tree) data;
02513
02514 make_new_vtable (t, binfo);
02515
02516
02517
02518
02519 for (virtuals = BINFO_VIRTUALS (binfo),
02520 old_virtuals = BINFO_VIRTUALS (TYPE_BINFO (BINFO_TYPE (binfo)));
02521 virtuals;
02522 virtuals = TREE_CHAIN (virtuals),
02523 old_virtuals = TREE_CHAIN (old_virtuals))
02524 update_vtable_entry_for_fn (t,
02525 binfo,
02526 BV_FN (old_virtuals),
02527 &virtuals);
02528 }
02529
02530 SET_BINFO_MARKED (binfo);
02531
02532 return NULL_TREE;
02533 }
02534
02535
02536
02537
02538
02539
02540
02541
02542
02543
02544 static tree
02545 modify_all_vtables (t, virtuals)
02546 tree t;
02547 tree virtuals;
02548 {
02549 tree binfo = TYPE_BINFO (t);
02550 tree *fnsp;
02551
02552
02553 dfs_walk (binfo,
02554 dfs_modify_vtables,
02555 dfs_unmarked_real_bases_queue_p,
02556 t);
02557 dfs_walk (binfo, dfs_unmark, dfs_marked_real_bases_queue_p, t);
02558
02559
02560
02561
02562
02563 for (fnsp = &virtuals; *fnsp; )
02564 {
02565 tree fn = TREE_VALUE (*fnsp);
02566
02567 if (!value_member (fn, BINFO_VIRTUALS (binfo))
02568 || DECL_VINDEX (fn) == error_mark_node)
02569 {
02570
02571
02572 BV_DELTA (*fnsp) = integer_zero_node;
02573 BV_VCALL_INDEX (*fnsp) = NULL_TREE;
02574
02575
02576 fnsp = &TREE_CHAIN (*fnsp);
02577 }
02578 else
02579
02580 *fnsp = TREE_CHAIN (*fnsp);
02581 }
02582
02583 return virtuals;
02584 }
02585
02586
02587
02588
02589 static tree
02590 get_basefndecls (name, t)
02591 tree name, t;
02592 {
02593 tree methods;
02594 tree base_fndecls = NULL_TREE;
02595 int n_baseclasses = CLASSTYPE_N_BASECLASSES (t);
02596 int i;
02597
02598
02599 i = lookup_fnfields_1 (t, name);
02600 if (i != -1)
02601 for (methods = TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (t), i);
02602 methods;
02603 methods = OVL_NEXT (methods))
02604 {
02605 tree method = OVL_CURRENT (methods);
02606
02607 if (TREE_CODE (method) == FUNCTION_DECL
02608 && DECL_VINDEX (method))
02609 base_fndecls = tree_cons (NULL_TREE, method, base_fndecls);
02610 }
02611
02612 if (base_fndecls)
02613 return base_fndecls;
02614
02615 for (i = 0; i < n_baseclasses; i++)
02616 {
02617 tree basetype = TYPE_BINFO_BASETYPE (t, i);
02618 base_fndecls = chainon (get_basefndecls (name, basetype),
02619 base_fndecls);
02620 }
02621
02622 return base_fndecls;
02623 }
02624
02625
02626
02627
02628
02629 static void
02630 check_for_override (decl, ctype)
02631 tree decl, ctype;
02632 {
02633 if (TREE_CODE (decl) == TEMPLATE_DECL)
02634
02635
02636
02637
02638 return;
02639 if ((DECL_DESTRUCTOR_P (decl)
02640 || IDENTIFIER_VIRTUAL_P (DECL_NAME (decl)))
02641 && look_for_overrides (ctype, decl)
02642 && !DECL_STATIC_FUNCTION_P (decl))
02643
02644
02645
02646 DECL_VINDEX (decl) = decl;
02647
02648 if (DECL_VIRTUAL_P (decl))
02649 {
02650 if (!DECL_VINDEX (decl))
02651 DECL_VINDEX (decl) = error_mark_node;
02652 IDENTIFIER_VIRTUAL_P (DECL_NAME (decl)) = 1;
02653 }
02654 }
02655
02656
02657
02658
02659 void
02660 warn_hidden (t)
02661 tree t;
02662 {
02663 tree method_vec = CLASSTYPE_METHOD_VEC (t);
02664 int n_methods = method_vec ? TREE_VEC_LENGTH (method_vec) : 0;
02665 int i;
02666
02667
02668 for (i = 2; i < n_methods && TREE_VEC_ELT (method_vec, i); ++i)
02669 {
02670 tree fns;
02671 tree name;
02672 tree fndecl;
02673 tree base_fndecls;
02674 int j;
02675
02676
02677
02678 name = DECL_NAME (OVL_CURRENT (TREE_VEC_ELT (method_vec, i)));
02679
02680 base_fndecls = NULL_TREE;
02681
02682
02683 for (j = 0; j < CLASSTYPE_N_BASECLASSES (t); j++)
02684 {
02685 tree basetype = TYPE_BINFO_BASETYPE (t, j);
02686 base_fndecls = chainon (get_basefndecls (name, basetype),
02687 base_fndecls);
02688 }
02689
02690
02691 if (!base_fndecls)
02692 continue;
02693
02694
02695 for (fns = TREE_VEC_ELT (method_vec, i); fns; fns = OVL_NEXT (fns))
02696 {
02697 fndecl = OVL_CURRENT (fns);
02698 if (DECL_VINDEX (fndecl))
02699 {
02700 tree *prev = &base_fndecls;
02701
02702 while (*prev)
02703
02704
02705
02706 if (same_signature_p (fndecl, TREE_VALUE (*prev)))
02707 *prev = TREE_CHAIN (*prev);
02708 else
02709 prev = &TREE_CHAIN (*prev);
02710 }
02711 }
02712
02713
02714
02715 while (base_fndecls)
02716 {
02717
02718 cp_warning_at ("`%D' was hidden", TREE_VALUE (base_fndecls));
02719 cp_warning_at (" by `%D'",
02720 OVL_CURRENT (TREE_VEC_ELT (method_vec, i)));
02721 base_fndecls = TREE_CHAIN (base_fndecls);
02722 }
02723 }
02724 }
02725
02726
02727
02728
02729 static void
02730 finish_struct_anon (t)
02731 tree t;
02732 {
02733 tree field;
02734
02735 for (field = TYPE_FIELDS (t); field; field = TREE_CHAIN (field))
02736 {
02737 if (TREE_STATIC (field))
02738 continue;
02739 if (TREE_CODE (field) != FIELD_DECL)
02740 continue;
02741
02742 if (DECL_NAME (field) == NULL_TREE
02743 && ANON_AGGR_TYPE_P (TREE_TYPE (field)))
02744 {
02745 tree elt = TYPE_FIELDS (TREE_TYPE (field));
02746 for (; elt; elt = TREE_CHAIN (elt))
02747 {
02748
02749
02750
02751
02752
02753
02754
02755 if (DECL_ARTIFICIAL (elt)
02756 && (!DECL_IMPLICIT_TYPEDEF_P (elt)
02757 || TYPE_ANONYMOUS_P (TREE_TYPE (elt))))
02758 continue;
02759
02760 if (DECL_NAME (elt) == constructor_name (t))
02761 cp_pedwarn_at ("ISO C++ forbids member `%D' with same name as enclosing class",
02762 elt);
02763
02764 if (TREE_CODE (elt) != FIELD_DECL)
02765 {
02766 cp_pedwarn_at ("`%#D' invalid; an anonymous union can only have non-static data members",
02767 elt);
02768 continue;
02769 }
02770
02771 if (TREE_PRIVATE (elt))
02772 cp_pedwarn_at ("private member `%#D' in anonymous union",
02773 elt);
02774 else if (TREE_PROTECTED (elt))
02775 cp_pedwarn_at ("protected member `%#D' in anonymous union",
02776 elt);
02777
02778 TREE_PRIVATE (elt) = TREE_PRIVATE (field);
02779 TREE_PROTECTED (elt) = TREE_PROTECTED (field);
02780 }
02781 }
02782 }
02783 }
02784
02785
02786
02787
02788
02789
02790
02791
02792
02793
02794
02795 void
02796 maybe_add_class_template_decl_list (type, t, friend_p)
02797 tree type;
02798 tree t;
02799 int friend_p;
02800 {
02801
02802 if (CLASSTYPE_TEMPLATE_INFO (type))
02803 CLASSTYPE_DECL_LIST (type)
02804 = tree_cons (friend_p ? NULL_TREE : type,
02805 t, CLASSTYPE_DECL_LIST (type));
02806 }
02807
02808
02809
02810
02811
02812
02813
02814
02815
02816
02817 static void
02818 add_implicitly_declared_members (t, cant_have_default_ctor,
02819 cant_have_const_cctor,
02820 cant_have_const_assignment)
02821 tree t;
02822 int cant_have_default_ctor;
02823 int cant_have_const_cctor;
02824 int cant_have_const_assignment;
02825 {
02826 tree default_fn;
02827 tree implicit_fns = NULL_TREE;
02828 tree virtual_dtor = NULL_TREE;
02829 tree *f;
02830
02831 ++adding_implicit_members;
02832
02833
02834 if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t) && !TYPE_HAS_DESTRUCTOR (t))
02835 {
02836 default_fn = implicitly_declare_fn (sfk_destructor, t, 0);
02837 check_for_override (default_fn, t);
02838
02839
02840 if (default_fn == void_type_node)
02841 TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t) = 0;
02842 else
02843 {
02844 TREE_CHAIN (default_fn) = implicit_fns;
02845 implicit_fns = default_fn;
02846
02847 if (DECL_VINDEX (default_fn))
02848 virtual_dtor = default_fn;
02849 }
02850 }
02851 else
02852
02853 TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t) |= TYPE_HAS_DESTRUCTOR (t);
02854
02855
02856 if (! TYPE_HAS_CONSTRUCTOR (t) && ! cant_have_default_ctor)
02857 {
02858 default_fn = implicitly_declare_fn (sfk_constructor, t, 0);
02859 TREE_CHAIN (default_fn) = implicit_fns;
02860 implicit_fns = default_fn;
02861 }
02862
02863
02864 if (! TYPE_HAS_INIT_REF (t) && ! TYPE_FOR_JAVA (t))
02865 {
02866
02867
02868 default_fn
02869 = implicitly_declare_fn (sfk_copy_constructor, t,
02870 !cant_have_const_cctor);
02871 TREE_CHAIN (default_fn) = implicit_fns;
02872 implicit_fns = default_fn;
02873 #ifdef KEY
02874 TYPE_HAS_IMPLICIT_COPY_CONSTRUCTOR (t) = 1;
02875 #endif
02876 }
02877
02878
02879 if (! TYPE_HAS_ASSIGN_REF (t) && ! TYPE_FOR_JAVA (t))
02880 {
02881 default_fn
02882 = implicitly_declare_fn (sfk_assignment_operator, t,
02883 !cant_have_const_assignment);
02884 TREE_CHAIN (default_fn) = implicit_fns;
02885 implicit_fns = default_fn;
02886 }
02887
02888
02889
02890 for (f = &implicit_fns; *f; f = &TREE_CHAIN (*f))
02891 {
02892 add_method (t, *f, 0);
02893 maybe_add_class_template_decl_list (current_class_type, *f, 0);
02894 }
02895 if (abi_version_at_least (2))
02896
02897
02898
02899 TYPE_METHODS (t) = chainon (TYPE_METHODS (t), implicit_fns);
02900 else
02901 {
02902 if (warn_abi && virtual_dtor)
02903 warning ("vtable layout for class `%T' may not be ABI-compliant "
02904 "and may change in a future version of GCC due to implicit "
02905 "virtual destructor",
02906 t);
02907 *f = TYPE_METHODS (t);
02908 TYPE_METHODS (t) = implicit_fns;
02909 }
02910
02911 --adding_implicit_members;
02912 }
02913
02914
02915
02916
02917 static int
02918 count_fields (fields)
02919 tree fields;
02920 {
02921 tree x;
02922 int n_fields = 0;
02923 for (x = fields; x; x = TREE_CHAIN (x))
02924 {
02925 if (TREE_CODE (x) == FIELD_DECL && ANON_AGGR_TYPE_P (TREE_TYPE (x)))
02926 n_fields += count_fields (TYPE_FIELDS (TREE_TYPE (x)));
02927 else
02928 n_fields += 1;
02929 }
02930 return n_fields;
02931 }
02932
02933
02934
02935
02936 static int
02937 add_fields_to_vec (fields, field_vec, idx)
02938 tree fields, field_vec;
02939 int idx;
02940 {
02941 tree x;
02942 for (x = fields; x; x = TREE_CHAIN (x))
02943 {
02944 if (TREE_CODE (x) == FIELD_DECL && ANON_AGGR_TYPE_P (TREE_TYPE (x)))
02945 idx = add_fields_to_vec (TYPE_FIELDS (TREE_TYPE (x)), field_vec, idx);
02946 else
02947 TREE_VEC_ELT (field_vec, idx++) = x;
02948 }
02949 return idx;
02950 }
02951
02952
02953
02954
02955
02956 static void
02957 check_bitfield_decl (field)
02958 tree field;
02959 {
02960 tree type = TREE_TYPE (field);
02961 tree w = NULL_TREE;
02962
02963
02964 if (DECL_INITIAL (field)
02965 && ! INTEGRAL_TYPE_P (TREE_TYPE (field)))
02966 {
02967 cp_error_at ("bit-field `%#D' with non-integral type", field);
02968 w = error_mark_node;
02969 }
02970
02971
02972 if (DECL_INITIAL (field))
02973 {
02974 w = DECL_INITIAL (field);
02975
02976
02977 STRIP_NOPS (w);
02978
02979
02980 if (TREE_CODE (w) == CONST_DECL)
02981 w = DECL_INITIAL (w);
02982 else
02983 w = decl_constant_value (w);
02984
02985 if (TREE_CODE (w) != INTEGER_CST)
02986 {
02987 cp_error_at ("bit-field `%D' width not an integer constant",
02988 field);
02989 w = error_mark_node;
02990 }
02991 else if (tree_int_cst_sgn (w) < 0)
02992 {
02993 cp_error_at ("negative width in bit-field `%D'", field);
02994 w = error_mark_node;
02995 }
02996 else if (integer_zerop (w) && DECL_NAME (field) != 0)
02997 {
02998 cp_error_at ("zero width for bit-field `%D'", field);
02999 w = error_mark_node;
03000 }
03001 else if (compare_tree_int (w, TYPE_PRECISION (type)) > 0
03002 && TREE_CODE (type) != ENUMERAL_TYPE
03003 && TREE_CODE (type) != BOOLEAN_TYPE)
03004 cp_warning_at ("width of `%D' exceeds its type", field);
03005 else if (TREE_CODE (type) == ENUMERAL_TYPE
03006 && (0 > compare_tree_int (w,
03007 min_precision (TYPE_MIN_VALUE (type),
03008 TREE_UNSIGNED (type)))
03009 || 0 > compare_tree_int (w,
03010 min_precision
03011 (TYPE_MAX_VALUE (type),
03012 TREE_UNSIGNED (type)))))
03013 cp_warning_at ("`%D' is too small to hold all values of `%#T'",
03014 field, type);
03015 }
03016
03017
03018
03019 DECL_INITIAL (field) = NULL_TREE;
03020
03021 if (w != error_mark_node)
03022 {
03023 DECL_SIZE (field) = convert (bitsizetype, w);
03024 DECL_BIT_FIELD (field) = 1;
03025
03026 if (integer_zerop (w)
03027 && ! (* targetm.ms_bitfield_layout_p) (DECL_FIELD_CONTEXT (field)))
03028 {
03029 #ifdef EMPTY_FIELD_BOUNDARY
03030 DECL_ALIGN (field) = MAX (DECL_ALIGN (field),
03031 EMPTY_FIELD_BOUNDARY);
03032 #endif
03033 #ifdef PCC_BITFIELD_TYPE_MATTERS
03034 if (PCC_BITFIELD_TYPE_MATTERS)
03035 {
03036 DECL_ALIGN (field) = MAX (DECL_ALIGN (field),
03037 TYPE_ALIGN (type));
03038 DECL_USER_ALIGN (field) |= TYPE_USER_ALIGN (type);
03039 }
03040 #endif
03041 }
03042 }
03043 else
03044 {
03045
03046 DECL_BIT_FIELD (field) = 0;
03047 CLEAR_DECL_C_BIT_FIELD (field);
03048 DECL_ALIGN (field) = MAX (DECL_ALIGN (field), TYPE_ALIGN (type));
03049 DECL_USER_ALIGN (field) |= TYPE_USER_ALIGN (type);
03050 }
03051 }
03052
03053
03054
03055
03056
03057 static void
03058 check_field_decl (field, t, cant_have_const_ctor,
03059 cant_have_default_ctor, no_const_asn_ref,
03060 any_default_members)
03061 tree field;
03062 tree t;
03063 int *cant_have_const_ctor;
03064 int *cant_have_default_ctor;
03065 int *no_const_asn_ref;
03066 int *any_default_members;
03067 {
03068 tree type = strip_array_types (TREE_TYPE (field));
03069
03070
03071
03072 if (ANON_UNION_TYPE_P (type))
03073 ;
03074
03075
03076 else if (ANON_AGGR_TYPE_P (type))
03077 {
03078 tree fields;
03079
03080 for (fields = TYPE_FIELDS (type); fields; fields = TREE_CHAIN (fields))
03081 if (TREE_CODE (fields) == FIELD_DECL && !DECL_C_BIT_FIELD (field))
03082 check_field_decl (fields, t, cant_have_const_ctor,
03083 cant_have_default_ctor, no_const_asn_ref,
03084 any_default_members);
03085 }
03086
03087
03088 else if (CLASS_TYPE_P (type))
03089 {
03090
03091
03092 abstract_virtuals_error (field, type);
03093
03094 if (TREE_CODE (t) == UNION_TYPE)
03095 {
03096 if (TYPE_NEEDS_CONSTRUCTING (type))
03097 cp_error_at ("member `%#D' with constructor not allowed in union",
03098 field);
03099 if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type))
03100 cp_error_at ("member `%#D' with destructor not allowed in union",
03101 field);
03102 if (TYPE_HAS_COMPLEX_ASSIGN_REF (type))
03103 cp_error_at ("member `%#D' with copy assignment operator not allowed in union",
03104 field);
03105 }
03106 else
03107 {
03108 TYPE_NEEDS_CONSTRUCTING (t) |= TYPE_NEEDS_CONSTRUCTING (type);
03109 TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)
03110 |= TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type);
03111 TYPE_HAS_COMPLEX_ASSIGN_REF (t) |= TYPE_HAS_COMPLEX_ASSIGN_REF (type);
03112 TYPE_HAS_COMPLEX_INIT_REF (t) |= TYPE_HAS_COMPLEX_INIT_REF (type);
03113 }
03114
03115 if (!TYPE_HAS_CONST_INIT_REF (type))
03116 *cant_have_const_ctor = 1;
03117
03118 if (!TYPE_HAS_CONST_ASSIGN_REF (type))
03119 *no_const_asn_ref = 1;
03120
03121 if (TYPE_HAS_CONSTRUCTOR (type)
03122 && ! TYPE_HAS_DEFAULT_CONSTRUCTOR (type))
03123 *cant_have_default_ctor = 1;
03124 }
03125 if (DECL_INITIAL (field) != NULL_TREE)
03126 {
03127
03128
03129 if (TREE_CODE (t) == UNION_TYPE && any_default_members != 0)
03130 cp_error_at ("multiple fields in union `%T' initialized");
03131 *any_default_members = 1;
03132 }
03133 }
03134
03135
03136
03137
03138
03139
03140
03141
03142
03143
03144
03145
03146
03147
03148
03149
03150
03151
03152
03153
03154
03155
03156
03157
03158
03159
03160
03161
03162
03163
03164 static void
03165 check_field_decls (tree t, tree *access_decls,
03166 int *cant_have_default_ctor_p,
03167 int *cant_have_const_ctor_p,
03168 int *no_const_asn_ref_p)
03169 {
03170 tree *field;
03171 tree *next;
03172 int has_pointers;
03173 int any_default_members;
03174
03175
03176 delete_duplicate_fields (TYPE_FIELDS (t));
03177
03178
03179 *access_decls = NULL_TREE;
03180
03181 has_pointers = 0;
03182
03183
03184 any_default_members = 0;
03185
03186 for (field = &TYPE_FIELDS (t); *field; field = next)
03187 {
03188 tree x = *field;
03189 tree type = TREE_TYPE (x);
03190
03191 next = &TREE_CHAIN (x);
03192
03193 if (TREE_CODE (x) == FIELD_DECL)
03194 {
03195 DECL_PACKED (x) |= TYPE_PACKED (t);
03196
03197 if (DECL_C_BIT_FIELD (x) && integer_zerop (DECL_INITIAL (x)))
03198
03199
03200 ;
03201 else
03202 {
03203 tree element_type;
03204
03205
03206 CLASSTYPE_EMPTY_P (t) = 0;
03207
03208 CLASSTYPE_NEARLY_EMPTY_P (t) = 0;
03209
03210
03211 element_type = strip_array_types (type);
03212 if (CLASS_TYPE_P (element_type)
03213 && CLASSTYPE_CONTAINS_EMPTY_CLASS_P (element_type))
03214 CLASSTYPE_CONTAINS_EMPTY_CLASS_P (t) = 1;
03215 }
03216 }
03217
03218 if (TREE_CODE (x) == USING_DECL)
03219 {
03220
03221 *field = TREE_CHAIN (x);
03222
03223
03224 *access_decls = tree_cons (NULL_TREE, x, *access_decls);
03225
03226
03227
03228 next = field;
03229 continue;
03230 }
03231
03232 if (TREE_CODE (x) == TYPE_DECL
03233 || TREE_CODE (x) == TEMPLATE_DECL)
03234 continue;
03235
03236
03237
03238
03239 DECL_CONTEXT (x) = t;
03240
03241
03242 if (current_function_decl && TREE_STATIC (x))
03243 cp_error_at ("field `%D' in local class cannot be static", x);
03244
03245
03246
03247 if (TREE_CODE (type) == FUNCTION_TYPE)
03248 {
03249 cp_error_at ("field `%D' invalidly declared function type",
03250 x);
03251 type = build_pointer_type (type);
03252 TREE_TYPE (x) = type;
03253 }
03254 else if (TREE_CODE (type) == METHOD_TYPE)
03255 {
03256 cp_error_at ("field `%D' invalidly declared method type", x);
03257 type = build_pointer_type (type);
03258 TREE_TYPE (x) = type;
03259 }
03260 else if (TREE_CODE (type) == OFFSET_TYPE)
03261 {
03262 cp_error_at ("field `%D' invalidly declared offset type", x);
03263 type = build_pointer_type (type);
03264 TREE_TYPE (x) = type;
03265 }
03266
03267 if (type == error_mark_node)
03268 continue;
03269
03270
03271 DECL_NONLOCAL (x) = 1;
03272
03273 if (TREE_CODE (x) == CONST_DECL)
03274 continue;
03275
03276 if (TREE_CODE (x) == VAR_DECL)
03277 {
03278 if (TREE_CODE (t) == UNION_TYPE)
03279
03280 cp_error_at ("field `%D' declared static in union", x);
03281
03282 continue;
03283 }
03284
03285
03286
03287 if (TREE_PRIVATE (x) || TREE_PROTECTED (x))
03288 CLASSTYPE_NON_AGGREGATE (t) = 1;
03289
03290
03291
03292 if (TREE_CODE (type) == REFERENCE_TYPE)
03293 {
03294 CLASSTYPE_NON_POD_P (t) = 1;
03295 if (DECL_INITIAL (x) == NULL_TREE)
03296 SET_CLASSTYPE_REF_FIELDS_NEED_INIT (t, 1);
03297
03298
03299
03300
03301
03302 *cant_have_default_ctor_p = 1;
03303 TYPE_HAS_COMPLEX_ASSIGN_REF (t) = 1;
03304
03305 if (! TYPE_HAS_CONSTRUCTOR (t) && CLASSTYPE_NON_AGGREGATE (t)
03306 && extra_warnings)
03307 cp_warning_at ("non-static reference `%#D' in class without a constructor", x);
03308 }
03309
03310 type = strip_array_types (type);
03311
03312 if (TREE_CODE (type) == POINTER_TYPE)
03313 has_pointers = 1;
03314
03315 if (DECL_MUTABLE_P (x) || TYPE_HAS_MUTABLE_P (type))
03316 CLASSTYPE_HAS_MUTABLE (t) = 1;
03317
03318 if (! pod_type_p (type))
03319
03320
03321 CLASSTYPE_NON_POD_P (t) = 1;
03322
03323 if (! zero_init_p (type))
03324 CLASSTYPE_NON_ZERO_INIT_P (t) = 1;
03325
03326
03327 if (CP_TYPE_CONST_P (type))
03328 {
03329 C_TYPE_FIELDS_READONLY (t) = 1;
03330 if (DECL_INITIAL (x) == NULL_TREE)
03331 SET_CLASSTYPE_READONLY_FIELDS_NEED_INIT (t, 1);
03332
03333
03334
03335
03336
03337 *cant_have_default_ctor_p = 1;
03338 TYPE_HAS_COMPLEX_ASSIGN_REF (t) = 1;
03339
03340 if (! TYPE_HAS_CONSTRUCTOR (t) && CLASSTYPE_NON_AGGREGATE (t)
03341 && extra_warnings)
03342 cp_warning_at ("non-static const member `%#D' in class without a constructor", x);
03343 }
03344
03345 else if (IS_AGGR_TYPE (type))
03346 {
03347 C_TYPE_FIELDS_READONLY (t) |= C_TYPE_FIELDS_READONLY (type);
03348 SET_CLASSTYPE_READONLY_FIELDS_NEED_INIT (t,
03349 CLASSTYPE_READONLY_FIELDS_NEED_INIT (t)
03350 | CLASSTYPE_READONLY_FIELDS_NEED_INIT (type));
03351 }
03352
03353
03354
03355
03356 if (DECL_NAME (x) == constructor_name (t)
03357 && TYPE_HAS_CONSTRUCTOR (t))
03358 cp_pedwarn_at ("field `%#D' with same name as class", x);
03359
03360
03361
03362 if (DECL_C_BIT_FIELD (x))
03363 check_bitfield_decl (x);
03364 else
03365 check_field_decl (x, t,
03366 cant_have_const_ctor_p,
03367 cant_have_default_ctor_p,
03368 no_const_asn_ref_p,
03369 &any_default_members);
03370 }
03371
03372
03373 if (has_pointers && warn_ecpp && TYPE_HAS_CONSTRUCTOR (t)
03374 && ! (TYPE_HAS_INIT_REF (t) && TYPE_HAS_ASSIGN_REF (t)))
03375 {
03376 warning ("`%#T' has pointer data members", t);
03377
03378 if (! TYPE_HAS_INIT_REF (t))
03379 {
03380 warning (" but does not override `%T(const %T&)'", t, t);
03381 if (! TYPE_HAS_ASSIGN_REF (t))
03382 warning (" or `operator=(const %T&)'", t);
03383 }
03384 else if (! TYPE_HAS_ASSIGN_REF (t))
03385 warning (" but does not override `operator=(const %T&)'", t);
03386 }
03387
03388
03389
03390 finish_struct_anon (t);
03391
03392
03393
03394 *access_decls = nreverse (*access_decls);
03395 }
03396
03397
03398
03399
03400 static int
03401 record_subobject_offset (type, offset, offsets)
03402 tree type;
03403 tree offset;
03404 splay_tree offsets;
03405 {
03406 splay_tree_node n;
03407
03408 if (!is_empty_class (type))
03409 return 0;
03410
03411
03412 n = splay_tree_lookup (offsets, (splay_tree_key) offset);
03413 if (!n)
03414 n = splay_tree_insert (offsets,
03415 (splay_tree_key) offset,
03416 (splay_tree_value) NULL_TREE);
03417 n->value = ((splay_tree_value)
03418 tree_cons (NULL_TREE,
03419 type,
03420 (tree) n->value));
03421
03422 return 0;
03423 }
03424
03425
03426
03427
03428 static int
03429 check_subobject_offset (type, offset, offsets)
03430 tree type;
03431 tree offset;
03432 splay_tree offsets;
03433 {
03434 splay_tree_node n;
03435 tree t;
03436
03437 if (!is_empty_class (type))
03438 return 0;
03439
03440
03441 n = splay_tree_lookup (offsets, (splay_tree_key) offset);
03442 if (!n)
03443 return 0;
03444
03445 for (t = (tree) n->value; t; t = TREE_CHAIN (t))
03446 if (same_type_p (TREE_VALUE (t), type))
03447 return 1;
03448
03449 return 0;
03450 }
03451
03452
03453
03454
03455
03456
03457
03458
03459
03460
03461
03462
03463 static int
03464 walk_subobject_offsets (type, f, offset, offsets, max_offset, vbases_p)
03465 tree type;
03466 subobject_offset_fn f;
03467 tree offset;
03468 splay_tree offsets;
03469 tree max_offset;
03470 int vbases_p;
03471 {
03472 int r = 0;
03473 tree type_binfo = NULL_TREE;
03474
03475
03476
03477 if (max_offset && INT_CST_LT (max_offset, offset))
03478 return 0;
03479
03480 if (!TYPE_P (type))
03481 {
03482 if (abi_version_at_least (2))
03483 type_binfo = type;
03484 type = BINFO_TYPE (type);
03485 }
03486
03487 if (CLASS_TYPE_P (type))
03488 {
03489 tree field;
03490 tree binfo;
03491 int i;
03492
03493
03494 if (!CLASSTYPE_CONTAINS_EMPTY_CLASS_P (type))
03495 return 0;
03496
03497
03498 r = (*f) (type, offset, offsets);
03499 if (r)
03500 return r;
03501
03502
03503 if (!type_binfo)
03504 type_binfo = TYPE_BINFO (type);
03505 for (i = 0; i < BINFO_N_BASETYPES (type_binfo); ++i)
03506 {
03507 tree binfo_offset;
03508
03509 binfo = BINFO_BASETYPE (type_binfo, i);
03510
03511 if (abi_version_at_least (2)
03512 && TREE_VIA_VIRTUAL (binfo))
03513 continue;
03514
03515 if (!vbases_p
03516 && TREE_VIA_VIRTUAL (binfo)
03517 && !BINFO_PRIMARY_P (binfo))
03518 continue;
03519
03520 if (!abi_version_at_least (2))
03521 binfo_offset = size_binop (PLUS_EXPR,
03522 offset,
03523 BINFO_OFFSET (binfo));
03524 else
03525 {
03526 tree orig_binfo;
03527
03528
03529
03530 orig_binfo = BINFO_BASETYPE (TYPE_BINFO (type), i);
03531 binfo_offset = size_binop (PLUS_EXPR,
03532 offset,
03533 BINFO_OFFSET (orig_binfo));
03534 }
03535
03536 r = walk_subobject_offsets (binfo,
03537 f,
03538 binfo_offset,
03539 offsets,
03540 max_offset,
03541 (abi_version_at_least (2)
03542 ? 0 : vbases_p));
03543 if (r)
03544 return r;
03545 }
03546
03547 if (abi_version_at_least (2))
03548 {
03549 tree vbase;
03550
03551
03552
03553
03554
03555
03556 if (vbases_p)
03557 for (vbase = CLASSTYPE_VBASECLASSES (type);
03558 vbase;
03559 vbase = TREE_CHAIN (vbase))
03560 {
03561 binfo = TREE_VALUE (vbase);
03562 r = walk_subobject_offsets (binfo,
03563 f,
03564 size_binop (PLUS_EXPR,
03565 offset,
03566 BINFO_OFFSET (binfo)),
03567 offsets,
03568 max_offset,
03569 0);
03570 if (r)
03571 return r;
03572 }
03573 else
03574 {
03575
03576
03577
03578 vbase = get_primary_binfo (type_binfo);
03579 if (vbase && TREE_VIA_VIRTUAL (vbase))
03580 {
03581 tree derived = type_binfo;
03582 while (BINFO_INHERITANCE_CHAIN (derived))
03583 derived = BINFO_INHERITANCE_CHAIN (derived);
03584 derived = TREE_TYPE (derived);
03585 vbase = binfo_for_vbase (TREE_TYPE (vbase), derived);
03586
03587 if (BINFO_PRIMARY_BASE_OF (vbase) == type_binfo)
03588 {
03589 r = (walk_subobject_offsets
03590 (vbase, f, offset,
03591 offsets, max_offset, 0));
03592 if (r)
03593 return r;
03594 }
03595 }
03596 }
03597 }
03598
03599
03600 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
03601 if (TREE_CODE (field) == FIELD_DECL && !DECL_ARTIFICIAL (field))
03602 {
03603 tree field_offset;
03604
03605 if (abi_version_at_least (2))
03606 field_offset = byte_position (field);
03607 else
03608
03609 field_offset = DECL_FIELD_OFFSET (field);
03610
03611 r = walk_subobject_offsets (TREE_TYPE (field),
03612 f,
03613 size_binop (PLUS_EXPR,
03614 offset,
03615 field_offset),
03616 offsets,
03617 max_offset,
03618 1);
03619 if (r)
03620 return r;
03621 }
03622 }
03623 else if (TREE_CODE (type) == ARRAY_TYPE)
03624 {
03625 tree element_type = strip_array_types (type);
03626 tree domain = TYPE_DOMAIN (type);
03627 tree index;
03628
03629
03630 if (!CLASS_TYPE_P (element_type)
03631 || !CLASSTYPE_CONTAINS_EMPTY_CLASS_P (element_type))
03632 return 0;
03633
03634
03635 for (index = size_zero_node;
03636
03637 (abi_version_at_least (2)
03638 ? !INT_CST_LT (TYPE_MAX_VALUE (domain), index)
03639 : INT_CST_LT (index, TYPE_MAX_VALUE (domain)));
03640 index = size_binop (PLUS_EXPR, index, size_one_node))
03641 {
03642 r = walk_subobject_offsets (TREE_TYPE (type),
03643 f,
03644 offset,
03645 offsets,
03646 max_offset,
03647 1);
03648 if (r)
03649 return r;
03650 offset = size_binop (PLUS_EXPR, offset,
03651 TYPE_SIZE_UNIT (TREE_TYPE (type)));
03652
03653
03654
03655 if (max_offset && INT_CST_LT (max_offset, offset))
03656 break;
03657 }
03658 }
03659
03660 return 0;
03661 }
03662
03663
03664
03665
03666
03667 static void
03668 record_subobject_offsets (type, offset, offsets, vbases_p)
03669 tree type;
03670 tree offset;
03671 splay_tree offsets;
03672 int vbases_p;
03673 {
03674 walk_subobject_offsets (type, record_subobject_offset, offset,
03675 offsets, NULL_TREE, vbases_p);
03676 }
03677
03678
03679
03680
03681
03682 static int
03683 layout_conflict_p (type, offset, offsets, vbases_p)
03684 tree type;
03685 tree offset;
03686 splay_tree offsets;
03687 int vbases_p;
03688 {
03689 splay_tree_node max_node;
03690
03691
03692
03693 max_node = splay_tree_max (offsets);
03694
03695
03696 if (!max_node)
03697 return 0;
03698
03699 return walk_subobject_offsets (type, check_subobject_offset, offset,
03700 offsets, (tree) (max_node->key),
03701 vbases_p);
03702 }
03703
03704
03705
03706
03707
03708
03709
03710 static void
03711 layout_nonempty_base_or_field (record_layout_info rli,
03712 tree decl,
03713 tree binfo,
03714 splay_tree offsets)
03715 {
03716 tree t = rli->t;
03717 tree offset = NULL_TREE;
03718 bool field_p;
03719 tree type;
03720
03721 if (binfo)
03722 {
03723
03724
03725
03726
03727 type = TREE_TYPE (binfo);
03728 field_p = false;
03729 }
03730 else
03731 {
03732 type = TREE_TYPE (decl);
03733 field_p = true;
03734 }
03735
03736
03737
03738
03739 while (1)
03740 {
03741 struct record_layout_info_s old_rli = *rli;
03742
03743
03744 place_field (rli, decl);
03745 offset = byte_position (decl);
03746
03747
03748
03749
03750
03751
03752
03753
03754
03755
03756
03757
03758
03759
03760
03761
03762
03763
03764 if (!abi_version_at_least (2) && binfo && TREE_VIA_VIRTUAL (binfo))
03765 break;
03766 if (layout_conflict_p (field_p ? type : binfo, offset,
03767 offsets, field_p))
03768 {
03769
03770
03771
03772 *rli = old_rli;
03773
03774
03775 rli->bitpos
03776 = size_binop (PLUS_EXPR, rli->bitpos,
03777 bitsize_int (binfo
03778 ? CLASSTYPE_ALIGN (type)
03779 : TYPE_ALIGN (type)));
03780 normalize_rli (rli);
03781 }
03782 else
03783
03784 break;
03785 }
03786
03787
03788
03789 if (binfo && CLASS_TYPE_P (BINFO_TYPE (binfo)))
03790
03791
03792
03793
03794 propagate_binfo_offsets (binfo,
03795 size_diffop (convert (ssizetype, offset),
03796 convert (ssizetype,
03797 BINFO_OFFSET (binfo))),
03798 t);
03799 }
03800
03801
03802
03803 static int
03804 empty_base_at_nonzero_offset_p (tree type,
03805 tree offset,
03806 splay_tree offsets ATTRIBUTE_UNUSED)
03807 {
03808 return is_empty_class (type) && !integer_zerop (offset);
03809 }
03810
03811
03812
03813
03814
03815
03816
03817 static bool
03818 layout_empty_base (binfo, eoc, offsets, t)
03819 tree binfo;
03820 tree eoc;
03821 splay_tree offsets;
03822 tree t;
03823 {
03824 tree alignment;
03825 tree basetype = BINFO_TYPE (binfo);
03826 bool atend = false;
03827
03828
03829 my_friendly_assert (is_empty_class (basetype), 20000321);
03830 alignment = ssize_int (CLASSTYPE_ALIGN_UNIT (basetype));
03831
03832 if (abi_version_at_least (2))
03833 BINFO_OFFSET (binfo) = size_zero_node;
03834 if (warn_abi && !integer_zerop (BINFO_OFFSET (binfo)))
03835 warning ("offset of empty base `%T' may not be ABI-compliant and may"
03836 "change in a future version of GCC",
03837 BINFO_TYPE (binfo));
03838
03839
03840
03841 if (layout_conflict_p (binfo,
03842 BINFO_OFFSET (binfo),
03843 offsets,
03844 0))
03845 {
03846
03847
03848 atend = true;
03849 propagate_binfo_offsets (binfo, convert (ssizetype, eoc), t);
03850 while (1)
03851 {
03852 if (!layout_conflict_p (binfo,
03853 BINFO_OFFSET (binfo),
03854 offsets,
03855 0))
03856
03857 break;
03858
03859
03860 propagate_binfo_offsets (binfo, alignment, t);
03861 }
03862 }
03863 return atend;
03864 }
03865
03866
03867
03868
03869
03870
03871
03872
03873
03874
03875 static tree *
03876 build_base_field (record_layout_info rli, tree binfo,
03877 splay_tree offsets, tree *next_field)
03878 {
03879 tree t = rli->t;
03880 tree basetype = BINFO_TYPE (binfo);
03881
03882 if (!COMPLETE_TYPE_P (basetype))
03883
03884
03885 return next_field;
03886
03887
03888 if (!is_empty_class (basetype))
03889 {
03890 tree decl;
03891
03892
03893
03894 CLASSTYPE_EMPTY_P (t) = 0;
03895
03896
03897 decl = build_decl (FIELD_DECL, NULL_TREE, CLASSTYPE_AS_BASE (basetype));
03898 DECL_ARTIFICIAL (decl) = 1;
03899 DECL_FIELD_CONTEXT (decl) = t;
03900 DECL_SIZE (decl) = CLASSTYPE_SIZE (basetype);
03901 DECL_SIZE_UNIT (decl) = CLASSTYPE_SIZE_UNIT (basetype);
03902 DECL_ALIGN (decl) = CLASSTYPE_ALIGN (basetype);
03903 DECL_USER_ALIGN (decl) = CLASSTYPE_USER_ALIGN (basetype);
03904 DECL_IGNORED_P (decl) = 1;
03905
03906
03907
03908
03909 layout_nonempty_base_or_field (rli, decl, binfo, offsets);
03910
03911 TREE_CHAIN (decl) = *next_field;
03912 *next_field = decl;
03913 next_field = &TREE_CHAIN (decl);
03914 }
03915 else
03916 {
03917 tree eoc;
03918 bool atend;
03919
03920
03921
03922 eoc = round_up (rli_size_unit_so_far (rli),
03923 CLASSTYPE_ALIGN_UNIT (basetype));
03924 atend = layout_empty_base (binfo, eoc, offsets, t);
03925
03926
03927 if (!TREE_VIA_VIRTUAL (binfo) && CLASSTYPE_NEARLY_EMPTY_P (t))
03928 {
03929 if (atend)
03930 CLASSTYPE_NEARLY_EMPTY_P (t) = 0;
03931
03932
03933
03934 else if (walk_subobject_offsets (basetype,
03935 empty_base_at_nonzero_offset_p,
03936 size_zero_node,
03937 NULL,
03938 NULL_TREE,
03939 true))
03940 {
03941 if (abi_version_at_least (2))
03942 CLASSTYPE_NEARLY_EMPTY_P (t) = 0;
03943 else if (warn_abi)
03944 warning ("class `%T' will be considered nearly empty in a "
03945 "future version of GCC", t);
03946 }
03947 }
03948
03949
03950
03951
03952
03953
03954
03955
03956
03957
03958
03959 }
03960
03961
03962 record_subobject_offsets (binfo,
03963 BINFO_OFFSET (binfo),
03964 offsets,
03965 0);
03966
03967 return next_field;
03968 }
03969
03970
03971
03972
03973
03974
03975
03976 static void
03977 build_base_fields (record_layout_info rli,
03978 splay_tree offsets, tree *next_field)
03979 {
03980
03981
03982 tree t = rli->t;
03983 int n_baseclasses = CLASSTYPE_N_BASECLASSES (t);
03984 int i;
03985
03986
03987 if (CLASSTYPE_HAS_PRIMARY_BASE_P (t))
03988 next_field = build_base_field (rli, CLASSTYPE_PRIMARY_BINFO (t),
03989 offsets, next_field);
03990
03991
03992 for (i = 0; i < n_baseclasses; ++i)
03993 {
03994 tree base_binfo;
03995
03996 base_binfo = BINFO_BASETYPE (TYPE_BINFO (t), i);
03997
03998
03999
04000 if (base_binfo == CLASSTYPE_PRIMARY_BINFO (t))
04001 continue;
04002
04003
04004
04005
04006 if (TREE_VIA_VIRTUAL (base_binfo)
04007 && !BINFO_PRIMARY_P (base_binfo))
04008 continue;
04009
04010 next_field = build_base_field (rli, base_binfo,
04011 offsets, next_field);
04012 }
04013 }
04014
04015
04016
04017
04018
04019 static void
04020 check_methods (t)
04021 tree t;
04022 {
04023 tree x;
04024
04025 for (x = TYPE_METHODS (t); x; x = TREE_CHAIN (x))
04026 {
04027
04028 if (DECL_ASSEMBLER_NAME_SET_P (x)
04029 && IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (x)))
04030 continue;
04031
04032 check_for_override (x, t);
04033 if (DECL_PURE_VIRTUAL_P (x) && ! DECL_VINDEX (x))
04034 cp_error_at ("initializer specified for non-virtual method `%D'", x);
04035
04036
04037
04038 if (DECL_VINDEX (x))
04039 {
04040 TYPE_POLYMORPHIC_P (t) = 1;
04041 if (DECL_PURE_VIRTUAL_P (x))
04042 CLASSTYPE_PURE_VIRTUALS (t)
04043 = tree_cons (NULL_TREE, x, CLASSTYPE_PURE_VIRTUALS (t));
04044 }
04045 }
04046 }
04047
04048
04049
04050
04051
04052 static tree
04053 build_clone (fn, name)
04054 tree fn;
04055 tree name;
04056 {
04057 tree parms;
04058 tree clone;
04059
04060
04061 clone = copy_decl (fn);
04062
04063 DECL_CLONED_FUNCTION (clone) = fn;
04064 DECL_ABSTRACT_ORIGIN (clone) = fn;
04065
04066 DECL_NAME (clone) = name;
04067 SET_DECL_ASSEMBLER_NAME (clone, NULL_TREE);
04068
04069 DECL_PENDING_INLINE_INFO (clone) = NULL;
04070 DECL_PENDING_INLINE_P (clone) = 0;
04071
04072 DECL_DEFERRED_FN (clone) = 0;
04073
04074
04075 if (name == base_dtor_identifier)
04076 {
04077 DECL_VIRTUAL_P (clone) = 0;
04078 if (TREE_CODE (clone) != TEMPLATE_DECL)
04079 DECL_VINDEX (clone) = NULL_TREE;
04080 }
04081
04082
04083
04084 if (DECL_HAS_IN_CHARGE_PARM_P (clone))
04085 {
04086 tree basetype;
04087 tree parmtypes;
04088 tree exceptions;
04089
04090 exceptions = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (clone));
04091 basetype = TYPE_METHOD_BASETYPE (TREE_TYPE (clone));
04092 parmtypes = TYPE_ARG_TYPES (TREE_TYPE (clone));
04093
04094 parmtypes = TREE_CHAIN (parmtypes);
04095
04096 parmtypes = TREE_CHAIN (parmtypes);
04097
04098 if (DECL_HAS_VTT_PARM_P (fn)
04099 && ! DECL_NEEDS_VTT_PARM_P (clone))
04100 parmtypes = TREE_CHAIN (parmtypes);
04101
04102
04103 TREE_TYPE (clone)
04104 = build_cplus_method_type (basetype,
04105 TREE_TYPE (TREE_TYPE (clone)),
04106 parmtypes);
04107 if (exceptions)
04108 TREE_TYPE (clone) = build_exception_variant (TREE_TYPE (clone),
04109 exceptions);
04110 }
04111
04112
04113
04114 if (TREE_CODE (clone) != TEMPLATE_DECL)
04115 {
04116 DECL_ARGUMENTS (clone) = copy_list (DECL_ARGUMENTS (clone));
04117
04118 if (DECL_HAS_IN_CHARGE_PARM_P (clone))
04119 {
04120 TREE_CHAIN (DECL_ARGUMENTS (clone))
04121 = TREE_CHAIN (TREE_CHAIN (DECL_ARGUMENTS (clone)));
04122 DECL_HAS_IN_CHARGE_PARM_P (clone) = 0;
04123 }
04124
04125 if (DECL_HAS_VTT_PARM_P (fn))
04126 {
04127 if (DECL_NEEDS_VTT_PARM_P (clone))
04128 DECL_HAS_VTT_PARM_P (clone) = 1;
04129 else
04130 {
04131 TREE_CHAIN (DECL_ARGUMENTS (clone))
04132 = TREE_CHAIN (TREE_CHAIN (DECL_ARGUMENTS (clone)));
04133 DECL_HAS_VTT_PARM_P (clone) = 0;
04134 }
04135 }
04136
04137 for (parms = DECL_ARGUMENTS (clone); parms; parms = TREE_CHAIN (parms))
04138 {
04139 DECL_CONTEXT (parms) = clone;
04140 cxx_dup_lang_specific_decl (parms);
04141 }
04142 }
04143
04144
04145 SET_DECL_RTL (clone, NULL_RTX);
04146 rest_of_decl_compilation (clone, NULL, 1, at_eof);
04147
04148
04149 TREE_CHAIN (clone) = TREE_CHAIN (fn);
04150 TREE_CHAIN (fn) = clone;
04151
04152
04153 if (TREE_CODE (clone) == TEMPLATE_DECL)
04154 {
04155 tree result;
04156
04157 DECL_TEMPLATE_RESULT (clone)
04158 = build_clone (DECL_TEMPLATE_RESULT (clone), name);
04159 result = DECL_TEMPLATE_RESULT (clone);
04160 DECL_TEMPLATE_INFO (result) = copy_node (DECL_TEMPLATE_INFO (result));
04161 DECL_TI_TEMPLATE (result) = clone;
04162 }
04163 else if (DECL_DEFERRED_FN (fn))
04164 defer_fn (clone);
04165
04166 return clone;
04167 }
04168
04169
04170
04171
04172
04173 void
04174 clone_function_decl (fn, update_method_vec_p)
04175 tree fn;
04176 int update_method_vec_p;
04177 {
04178 tree clone;
04179
04180
04181 if (TREE_CHAIN (fn)
04182 && DECL_CLONED_FUNCTION (TREE_CHAIN (fn)))
04183 return;
04184
04185 if (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (fn))
04186 {
04187
04188
04189 clone = build_clone (fn, complete_ctor_identifier);
04190 if (update_method_vec_p)
04191 add_method (DECL_CONTEXT (clone), clone, 0);
04192 #ifdef KEY
04193
04194
04195 {
04196 tree type = TYPE_METHOD_BASETYPE (TREE_TYPE (clone));
04197 if (!TYPE_HAS_IMPLICIT_COPY_CONSTRUCTOR (type) &&
04198 DECL_COPY_CONSTRUCTOR_P (clone)) {
04199 if (!DECL_COMPLETE_CONSTRUCTOR_P (clone))
04200 abort ();
04201 CLASSTYPE_COPY_CONSTRUCTOR (type) = clone;
04202 }
04203 }
04204 #endif
04205
04206 clone = build_clone (fn, base_ctor_identifier);
04207 if (update_method_vec_p)
04208 add_method (DECL_CONTEXT (clone), clone, 0);
04209 }
04210 else
04211 {
04212 my_friendly_assert (DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (fn), 20000411);
04213
04214
04215
04216
04217
04218
04219
04220
04221
04222
04223 if (DECL_VIRTUAL_P (fn))
04224 {
04225 clone = build_clone (fn, deleting_dtor_identifier);
04226 if (update_method_vec_p)
04227 add_method (DECL_CONTEXT (clone), clone, 0);
04228 }
04229 clone = build_clone (fn, complete_dtor_identifier);
04230 if (update_method_vec_p)
04231 add_method (DECL_CONTEXT (clone), clone, 0);
04232 clone = build_clone (fn, base_dtor_identifier);
04233 if (update_method_vec_p)
04234 add_method (DECL_CONTEXT (clone), clone, 0);
04235 }
04236
04237
04238 DECL_ABSTRACT (fn) = 1;
04239 }
04240
04241
04242
04243
04244
04245
04246
04247
04248 void
04249 adjust_clone_args (decl)
04250 tree decl;
04251 {
04252 tree clone;
04253
04254 for (clone = TREE_CHAIN (decl); clone && DECL_CLONED_FUNCTION (clone);
04255 clone = TREE_CHAIN (clone))
04256 {
04257 tree orig_clone_parms = TYPE_ARG_TYPES (TREE_TYPE (clone));
04258 tree orig_decl_parms = TYPE_ARG_TYPES (TREE_TYPE (decl));
04259 tree decl_parms, clone_parms;
04260
04261 clone_parms = orig_clone_parms;
04262
04263
04264 orig_clone_parms = TREE_CHAIN (orig_clone_parms);
04265 orig_decl_parms = TREE_CHAIN (orig_decl_parms);
04266
04267 if (DECL_HAS_IN_CHARGE_PARM_P (decl))
04268 orig_decl_parms = TREE_CHAIN (orig_decl_parms);
04269 if (DECL_HAS_VTT_PARM_P (decl))
04270 orig_decl_parms = TREE_CHAIN (orig_decl_parms);
04271
04272 clone_parms = orig_clone_parms;
04273 if (DECL_HAS_VTT_PARM_P (clone))
04274 clone_parms = TREE_CHAIN (clone_parms);
04275
04276 for (decl_parms = orig_decl_parms; decl_parms;
04277 decl_parms = TREE_CHAIN (decl_parms),
04278 clone_parms = TREE_CHAIN (clone_parms))
04279 {
04280 my_friendly_assert (same_type_p (TREE_TYPE (decl_parms),
04281 TREE_TYPE (clone_parms)), 20010424);
04282
04283 if (TREE_PURPOSE (decl_parms) && !TREE_PURPOSE (clone_parms))
04284 {
04285
04286
04287 tree exceptions = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (clone));
04288 tree basetype = TYPE_METHOD_BASETYPE (TREE_TYPE (clone));
04289 tree type;
04290
04291 clone_parms = orig_decl_parms;
04292
04293 if (DECL_HAS_VTT_PARM_P (clone))
04294 {
04295 clone_parms = tree_cons (TREE_PURPOSE (orig_clone_parms),
04296 TREE_VALUE (orig_clone_parms),
04297 clone_parms);
04298 TREE_TYPE (clone_parms) = TREE_TYPE (orig_clone_parms);
04299 }
04300 type = build_cplus_method_type (basetype,
04301 TREE_TYPE (TREE_TYPE (clone)),
04302 clone_parms);
04303 if (exceptions)
04304 type = build_exception_variant (type, exceptions);
04305 TREE_TYPE (clone) = type;
04306
04307 clone_parms = NULL_TREE;
04308 break;
04309 }
04310 }
04311 my_friendly_assert (!clone_parms, 20010424);
04312 }
04313 }
04314
04315
04316
04317
04318 static void
04319 clone_constructors_and_destructors (t)
04320 tree t;
04321 {
04322 tree fns;
04323
04324
04325
04326 if (!CLASSTYPE_METHOD_VEC (t))
04327 return;
04328
04329 for (fns = CLASSTYPE_CONSTRUCTORS (t); fns; fns = OVL_NEXT (fns))
04330 clone_function_decl (OVL_CURRENT (fns), 1);
04331 for (fns = CLASSTYPE_DESTRUCTORS (t); fns; fns = OVL_NEXT (fns))
04332 clone_function_decl (OVL_CURRENT (fns), 1);
04333 }
04334
04335
04336
04337 static void
04338 remove_zero_width_bit_fields (t)
04339 tree t;
04340 {
04341 tree *fieldsp;
04342
04343 fieldsp = &TYPE_FIELDS (t);
04344 while (*fieldsp)
04345 {
04346 if (TREE_CODE (*fieldsp) == FIELD_DECL
04347 && DECL_C_BIT_FIELD (*fieldsp)
04348 && DECL_INITIAL (*fieldsp))
04349 *fieldsp = TREE_CHAIN (*fieldsp);
04350 else
04351 fieldsp = &TREE_CHAIN (*fieldsp);
04352 }
04353 }
04354
04355
04356
04357
04358 static bool
04359 type_requires_array_cookie (type)
04360 tree type;
04361 {
04362 tree fns;
04363 bool has_two_argument_delete_p = false;
04364
04365 my_friendly_assert (CLASS_TYPE_P (type), 20010712);
04366
04367
04368
04369
04370 if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type))
04371 return true;
04372
04373
04374
04375
04376
04377 fns = lookup_fnfields (TYPE_BINFO (type),
04378 ansi_opname (VEC_DELETE_EXPR),
04379 0);
04380
04381
04382 if (!fns || fns == error_mark_node)
04383 return false;
04384
04385 for (fns = BASELINK_FUNCTIONS (fns); fns; fns = OVL_NEXT (fns))
04386 {
04387 tree fn;
04388 tree second_parm;
04389
04390
04391 fn = OVL_CURRENT (fns);
04392
04393
04394 second_parm = TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (fn)));
04395 if (second_parm == void_list_node)
04396 return false;
04397
04398
04399
04400 if (TREE_CHAIN (second_parm) == void_list_node
04401 && same_type_p (TREE_VALUE (second_parm), sizetype))
04402 has_two_argument_delete_p = true;
04403 }
04404
04405 return has_two_argument_delete_p;
04406 }
04407
04408
04409
04410
04411
04412
04413
04414 static void
04415 check_bases_and_members (tree t)
04416 {
04417
04418
04419 int cant_have_default_ctor;
04420
04421
04422 int cant_have_const_ctor;
04423
04424
04425 int no_const_asn_ref;
04426 tree access_decls;
04427
04428
04429
04430 cant_have_default_ctor = 0;
04431 cant_have_const_ctor = 0;
04432 no_const_asn_ref = 0;
04433
04434
04435 check_bases (t, &cant_have_default_ctor, &cant_have_const_ctor,
04436 &no_const_asn_ref);
04437
04438
04439 check_field_decls (t, &access_decls,
04440 &cant_have_default_ctor,
04441 &cant_have_const_ctor,
04442 &no_const_asn_ref);
04443
04444
04445 check_methods (t);
04446
04447
04448
04449 if (!TYPE_CONTAINS_VPTR_P (t))
04450 CLASSTYPE_NEARLY_EMPTY_P (t) = 0;
04451
04452
04453
04454 TYPE_HAS_COMPLEX_INIT_REF (t)
04455 |= (TYPE_HAS_INIT_REF (t)
04456 || TYPE_USES_VIRTUAL_BASECLASSES (t)
04457 || TYPE_POLYMORPHIC_P (t));
04458 TYPE_NEEDS_CONSTRUCTING (t)
04459 |= (TYPE_HAS_CONSTRUCTOR (t)
04460 || TYPE_USES_VIRTUAL_BASECLASSES (t)
04461 || TYPE_POLYMORPHIC_P (t));
04462 CLASSTYPE_NON_AGGREGATE (t) |= (TYPE_HAS_CONSTRUCTOR (t)
04463 || TYPE_POLYMORPHIC_P (t));
04464 CLASSTYPE_NON_POD_P (t)
04465 |= (CLASSTYPE_NON_AGGREGATE (t) || TYPE_HAS_DESTRUCTOR (t)
04466 || TYPE_HAS_ASSIGN_REF (t));
04467 TYPE_HAS_REAL_ASSIGN_REF (t) |= TYPE_HAS_ASSIGN_REF (t);
04468 TYPE_HAS_COMPLEX_ASSIGN_REF (t)
04469 |= TYPE_HAS_ASSIGN_REF (t) || TYPE_CONTAINS_VPTR_P (t);
04470
04471
04472
04473 add_implicitly_declared_members (t, cant_have_default_ctor,
04474 cant_have_const_ctor,
04475 no_const_asn_ref);
04476
04477
04478
04479 clone_constructors_and_destructors (t);
04480
04481
04482 for (; access_decls; access_decls = TREE_CHAIN (access_decls))
04483 handle_using_decl (TREE_VALUE (access_decls), t);
04484
04485
04486 finish_struct_methods (t);
04487
04488
04489
04490 TYPE_LANG_SPECIFIC (t)->u.c.vec_new_uses_cookie
04491 = type_requires_array_cookie (t);
04492 }
04493
04494
04495
04496
04497
04498
04499
04500
04501 static tree
04502 create_vtable_ptr (t, virtuals_p)
04503 tree t;
04504 tree *virtuals_p;
04505 {
04506 tree fn;
04507
04508
04509 for (fn = TYPE_METHODS (t); fn; fn = TREE_CHAIN (fn))
04510 if (DECL_VINDEX (fn) && !DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (fn)
04511 && TREE_CODE (DECL_VINDEX (fn)) != INTEGER_CST)
04512 {
04513 tree new_virtual = make_node (TREE_LIST);
04514
04515 BV_FN (new_virtual) = fn;
04516 BV_DELTA (new_virtual) = integer_zero_node;
04517
04518 TREE_CHAIN (new_virtual) = *virtuals_p;
04519 *virtuals_p = new_virtual;
04520 }
04521
04522
04523
04524
04525
04526 if (!TYPE_VFIELD (t) && (*virtuals_p || TYPE_CONTAINS_VPTR_P (t)))
04527 {
04528
04529
04530
04531
04532
04533
04534
04535
04536
04537
04538
04539
04540
04541
04542
04543
04544
04545
04546
04547 tree field;
04548
04549 field = build_decl (FIELD_DECL, get_vfield_name (t), vtbl_ptr_type_node);
04550 SET_DECL_ASSEMBLER_NAME (field, get_identifier (VFIELD_BASE));
04551 DECL_VIRTUAL_P (field) = 1;
04552 DECL_ARTIFICIAL (field) = 1;
04553 DECL_FIELD_CONTEXT (field) = t;
04554 DECL_FCONTEXT (field) = t;
04555 DECL_ALIGN (field) = TYPE_ALIGN (vtbl_ptr_type_node);
04556 DECL_USER_ALIGN (field) = TYPE_USER_ALIGN (vtbl_ptr_type_node);
04557
04558 TYPE_VFIELD (t) = field;
04559
04560
04561 CLASSTYPE_EMPTY_P (t) = 0;
04562
04563 if (CLASSTYPE_N_BASECLASSES (t))
04564
04565
04566
04567
04568 TYPE_BASE_CONVS_MAY_REQUIRE_CODE_P (t) = 1;
04569
04570 return field;
04571 }
04572
04573 return NULL_TREE;
04574 }
04575
04576
04577
04578
04579 static void
04580 fixup_pending_inline (fn)
04581 tree fn;
04582 {
04583 if (DECL_PENDING_INLINE_INFO (fn))
04584 {
04585 tree args = DECL_ARGUMENTS (fn);
04586 while (args)
04587 {
04588 DECL_CONTEXT (args) = fn;
04589 args = TREE_CHAIN (args);
04590 }
04591 }
04592 }
04593
04594
04595
04596
04597 static void
04598 fixup_inline_methods (type)
04599 tree type;
04600 {
04601 tree method = TYPE_METHODS (type);
04602
04603 if (method && TREE_CODE (method) == TREE_VEC)
04604 {
04605 if (TREE_VEC_ELT (method, 1))
04606 method = TREE_VEC_ELT (method, 1);
04607 else if (TREE_VEC_ELT (method, 0))
04608 method = TREE_VEC_ELT (method, 0);
04609 else
04610 method = TREE_VEC_ELT (method, 2);
04611 }
04612
04613
04614 for (; method; method = TREE_CHAIN (method))
04615 fixup_pending_inline (method);
04616
04617
04618 for (method = CLASSTYPE_INLINE_FRIENDS (type);
04619 method;
04620 method = TREE_CHAIN (method))
04621 fixup_pending_inline (TREE_VALUE (method));
04622 CLASSTYPE_INLINE_FRIENDS (type) = NULL_TREE;
04623 }
04624
04625
04626
04627
04628
04629
04630 static void
04631 propagate_binfo_offsets (binfo, offset, t)
04632 tree binfo;
04633 tree offset;
04634 tree t;
04635 {
04636 int i;
04637 tree primary_binfo;
04638
04639
04640 BINFO_OFFSET (binfo)
04641 = convert (sizetype,
04642 size_binop (PLUS_EXPR,
04643 convert (ssizetype, BINFO_OFFSET (binfo)),
04644 offset));
04645
04646
04647 primary_binfo = get_primary_binfo (binfo);
04648
04649
04650
04651 for (i = -1; i < BINFO_N_BASETYPES (binfo); ++i)
04652 {
04653 tree base_binfo;
04654
04655
04656
04657
04658 if (i == -1)
04659 {
04660 if (!primary_binfo)
04661 continue;
04662
04663 base_binfo = primary_binfo;
04664 }
04665 else
04666 {
04667 base_binfo = BINFO_BASETYPE (binfo, i);
04668
04669 if (base_binfo == primary_binfo)
04670 continue;
04671 }
04672
04673
04674 if (TREE_VIA_VIRTUAL (base_binfo)
04675 && (BINFO_PRIMARY_BASE_OF (base_binfo) != binfo
04676 || base_binfo != binfo_for_vbase (BINFO_TYPE (base_binfo), t)))
04677 continue;
04678
04679 propagate_binfo_offsets (base_binfo, offset, t);
04680 }
04681 }
04682
04683
04684
04685 static tree
04686 dfs_set_offset_for_unshared_vbases (binfo, data)
04687 tree binfo;
04688 void *data;
04689 {
04690
04691
04692
04693 if (TREE_VIA_VIRTUAL (binfo))
04694 {
04695 tree t = (tree) data;
04696 tree vbase;
04697 tree offset;
04698
04699 vbase = binfo_for_vbase (BINFO_TYPE (binfo), t);
04700 if (vbase != binfo)
04701 {
04702 offset = size_diffop (BINFO_OFFSET (vbase), BINFO_OFFSET (binfo));
04703 propagate_binfo_offsets (binfo, offset, t);
04704 }
04705 }
04706
04707 return NULL_TREE;
04708 }
04709
04710
04711
04712
04713
04714 static void
04715 layout_virtual_bases (record_layout_info rli, splay_tree offsets)
04716 {
04717 tree vbases;
04718 tree t = rli->t;
04719 bool first_vbase = true;
04720 tree *next_field;
04721
04722 if (CLASSTYPE_N_BASECLASSES (t) == 0)
04723 return;
04724
04725 if (!abi_version_at_least(2))
04726 {
04727
04728
04729 finish_record_layout (rli, false);
04730 #ifdef STRUCTURE_SIZE_BOUNDARY
04731
04732 if (! TYPE_PACKED (t))
04733 TYPE_ALIGN (t) = MAX (TYPE_ALIGN (t), STRUCTURE_SIZE_BOUNDARY);
04734 #endif
04735 rli->offset = TYPE_SIZE_UNIT (t);
04736 rli->bitpos = bitsize_zero_node;
04737 rli->record_align = TYPE_ALIGN (t);
04738 }
04739
04740
04741
04742 next_field = &TYPE_FIELDS (t);
04743 while (*next_field)
04744 next_field = &TREE_CHAIN (*next_field);
04745
04746
04747
04748
04749 for (vbases = TYPE_BINFO (t);
04750 vbases;
04751 vbases = TREE_CHAIN (vbases))
04752 {
04753 tree vbase;
04754
04755 if (!TREE_VIA_VIRTUAL (vbases))
04756 continue;
04757
04758 vbase = binfo_for_vbase (BINFO_TYPE (vbases), t);
04759
04760 if (!BINFO_PRIMARY_P (vbase))
04761 {
04762 tree basetype = TREE_TYPE (vbase);
04763
04764
04765
04766 next_field = build_base_field (rli, vbase,
04767 offsets, next_field);
04768
04769
04770
04771
04772
04773
04774
04775
04776 if (warn_abi
04777 && first_vbase
04778 && (tree_int_cst_lt
04779 (size_binop (CEIL_DIV_EXPR,
04780 round_up (CLASSTYPE_SIZE (t),
04781 CLASSTYPE_ALIGN (basetype)),
04782 bitsize_unit_node),
04783 BINFO_OFFSET (vbase))))
04784 warning ("offset of virtual base `%T' is not ABI-compliant and may change in a future version of GCC",
04785 basetype);
04786
04787 first_vbase = false;
04788 }
04789 }
04790
04791
04792
04793
04794
04795
04796 dfs_walk (TYPE_BINFO (t), dfs_set_offset_for_unshared_vbases, NULL, t);
04797 }
04798
04799
04800
04801
04802 static tree
04803 end_of_base (tree binfo)
04804 {
04805 tree size;
04806
04807 if (is_empty_class (BINFO_TYPE (binfo)))
04808
04809
04810
04811 size = TYPE_SIZE_UNIT (BINFO_TYPE (binfo));
04812 else
04813 size = CLASSTYPE_SIZE_UNIT (BINFO_TYPE (binfo));
04814
04815 return size_binop (PLUS_EXPR, BINFO_OFFSET (binfo), size);
04816 }
04817
04818
04819
04820
04821
04822 static tree
04823 end_of_class (t, include_virtuals_p)
04824 tree t;
04825 int include_virtuals_p;
04826 {
04827 tree result = size_zero_node;
04828 tree binfo;
04829 tree offset;
04830 int i;
04831
04832 for (i = 0; i < CLASSTYPE_N_BASECLASSES (t); ++i)
04833 {
04834 binfo = BINFO_BASETYPE (TYPE_BINFO (t), i);
04835
04836 if (!include_virtuals_p
04837 && TREE_VIA_VIRTUAL (binfo)
04838 && BINFO_PRIMARY_BASE_OF (binfo) != TYPE_BINFO (t))
04839 continue;
04840
04841 offset = end_of_base (binfo);
04842 if (INT_CST_LT_UNSIGNED (result, offset))
04843 result = offset;
04844 }
04845
04846
04847 if (abi_version_at_least (2) && include_virtuals_p)
04848 for (binfo = CLASSTYPE_VBASECLASSES (t);
04849 binfo;
04850 binfo = TREE_CHAIN (binfo))
04851 {
04852 offset = end_of_base (TREE_VALUE (binfo));
04853 if (INT_CST_LT_UNSIGNED (result, offset))
04854 result = offset;
04855 }
04856
04857 return result;
04858 }
04859
04860
04861
04862
04863
04864
04865
04866
04867
04868
04869
04870 static void
04871 warn_about_ambiguous_bases (t)
04872 tree t;
04873 {
04874 int i;
04875 tree vbases;
04876 tree basetype;
04877
04878
04879 for (i = 0; i < CLASSTYPE_N_BASECLASSES (t); ++i)
04880 {
04881 basetype = TYPE_BINFO_BASETYPE (t, i);
04882
04883 if (!lookup_base (t, basetype, ba_ignore | ba_quiet, NULL))
04884 warning ("direct base `%T' inaccessible in `%T' due to ambiguity",
04885 basetype, t);
04886 }
04887
04888
04889 if (extra_warnings)
04890 for (vbases = CLASSTYPE_VBASECLASSES (t);
04891 vbases;
04892 vbases = TREE_CHAIN (vbases))
04893 {
04894 basetype = BINFO_TYPE (TREE_VALUE (vbases));
04895
04896 if (!lookup_base (t, basetype, ba_ignore | ba_quiet, NULL))
04897 warning ("virtual base `%T' inaccessible in `%T' due to ambiguity",
04898 basetype, t);
04899 }
04900 }
04901
04902
04903
04904 static int
04905 splay_tree_compare_integer_csts (k1, k2)
04906 splay_tree_key k1;
04907 splay_tree_key k2;
04908 {
04909 return tree_int_cst_compare ((tree) k1, (tree) k2);
04910 }
04911
04912
04913
04914
04915 static void
04916 include_empty_classes (record_layout_info rli)
04917 {
04918 tree eoc;
04919 tree rli_size;
04920
04921
04922
04923
04924
04925
04926 eoc = end_of_class (rli->t,
04927 CLASSTYPE_AS_BASE (rli->t) != NULL_TREE);
04928 rli_size = rli_size_unit_so_far (rli);
04929 if (TREE_CODE (rli_size) == INTEGER_CST
04930 && INT_CST_LT_UNSIGNED (rli_size, eoc))
04931 {
04932 rli->bitpos = round_up (rli->bitpos, BITS_PER_UNIT);
04933 rli->bitpos
04934 = size_binop (PLUS_EXPR,
04935 rli->bitpos,
04936 size_binop (MULT_EXPR,
04937 convert (bitsizetype,
04938 size_binop (MINUS_EXPR,
04939 eoc, rli_size)),
04940 bitsize_int (BITS_PER_UNIT)));
04941 normalize_rli (rli);
04942 }
04943 }
04944
04945
04946
04947
04948
04949 static void
04950 layout_class_type (tree t, tree *virtuals_p)
04951 {
04952 tree non_static_data_members;
04953 tree field;
04954 tree vptr;
04955 record_layout_info rli;
04956
04957
04958 splay_tree empty_base_offsets;
04959
04960 bool last_field_was_bitfield = false;
04961
04962 tree *next_field;
04963
04964 tree base_t;
04965
04966
04967 non_static_data_members = TYPE_FIELDS (t);
04968
04969
04970 rli = start_record_layout (t);
04971
04972
04973
04974 determine_primary_base (t);
04975
04976
04977 vptr = create_vtable_ptr (t, virtuals_p);
04978
04979
04980 if (vptr)
04981 {
04982 TREE_CHAIN (vptr) = TYPE_FIELDS (t);
04983 TYPE_FIELDS (t) = vptr;
04984 next_field = &TREE_CHAIN (vptr);
04985 place_field (rli, vptr);
04986 }
04987 else
04988 next_field = &TYPE_FIELDS (t);
04989
04990
04991 empty_base_offsets = splay_tree_new (splay_tree_compare_integer_csts,
04992 NULL, NULL);
04993 build_base_fields (rli, empty_base_offsets, next_field);
04994
04995
04996 for (field = non_static_data_members; field; field = TREE_CHAIN (field))
04997 {
04998 tree type;
04999 tree padding;
05000
05001
05002
05003 if (TREE_CODE (field) != FIELD_DECL)
05004 {
05005 place_field (rli, field);
05006
05007
05008
05009
05010
05011
05012
05013
05014
05015
05016 if (TREE_CODE (field) == VAR_DECL)
05017 maybe_register_incomplete_var (field);
05018 continue;
05019 }
05020
05021 type = TREE_TYPE (field);
05022
05023
05024
05025
05026 if (DECL_C_BIT_FIELD (field)
05027 && INT_CST_LT (TYPE_SIZE (type), DECL_SIZE (field)))
05028 {
05029 integer_type_kind itk;
05030 tree integer_type;
05031
05032
05033
05034
05035
05036 for (itk = itk_char; itk != itk_none; ++itk)
05037 if (INT_CST_LT (DECL_SIZE (field),
05038 TYPE_SIZE (integer_types[itk])))
05039 break;
05040
05041
05042
05043
05044 integer_type = integer_types[itk - 1];
05045
05046 if (abi_version_at_least (2) && TREE_CODE (t) == UNION_TYPE)
05047
05048
05049 padding = DECL_SIZE (field);
05050 else
05051 {
05052 if (warn_abi && TREE_CODE (t) == UNION_TYPE)
05053 warning ("size assigned to `%T' may not be "
05054 "ABI-compliant and may change in a future "
05055 "version of GCC",
05056 t);
05057 padding = size_binop (MINUS_EXPR, DECL_SIZE (field),
05058 TYPE_SIZE (integer_type));
05059 }
05060 DECL_SIZE (field) = TYPE_SIZE (integer_type);
05061 DECL_ALIGN (field) = TYPE_ALIGN (integer_type);
05062 DECL_USER_ALIGN (field) = TYPE_USER_ALIGN (integer_type);
05063 layout_nonempty_base_or_field (rli, field, NULL_TREE,
05064 empty_base_offsets);
05065
05066
05067
05068 DECL_SIZE (field) = TYPE_SIZE (type);
05069
05070 if (abi_version_at_least (2))
05071 DECL_MODE (field) = TYPE_MODE (type);
05072 else if (warn_abi
05073 && DECL_MODE (field) != TYPE_MODE (type))
05074
05075
05076 warning ("the offset of `%D' may not be ABI-compliant and may "
05077 "change in a future version of GCC", field);
05078 }
05079 else
05080 {
05081 padding = NULL_TREE;
05082 layout_nonempty_base_or_field (rli, field, NULL_TREE,
05083 empty_base_offsets);
05084 }
05085
05086
05087 if (abi_version_at_least (2))
05088 record_subobject_offsets (TREE_TYPE (field),
05089 byte_position(field),
05090 empty_base_offsets,
05091 1);
05092
05093
05094
05095
05096 if (warn_abi
05097 && DECL_C_BIT_FIELD (field)
05098 && !last_field_was_bitfield
05099 && !integer_zerop (size_binop (TRUNC_MOD_EXPR,
05100 DECL_FIELD_BIT_OFFSET (field),
05101 bitsize_unit_node)))
05102 cp_warning_at ("offset of `%D' is not ABI-compliant and may change in a future version of GCC",
05103 field);
05104
05105
05106
05107 if (warn_abi
05108 && !tree_int_cst_equal (DECL_FIELD_OFFSET (field),
05109 byte_position (field))
05110 && contains_empty_class_p (TREE_TYPE (field)))
05111 cp_warning_at ("`%D' contains empty classes which may cause base "
05112 "classes to be placed at different locations in a "
05113 "future version of GCC",
05114 field);
05115
05116
05117
05118 if (padding)
05119 {
05120 tree padding_field;
05121
05122 padding_field = build_decl (FIELD_DECL,
05123 NULL_TREE,
05124 char_type_node);
05125 DECL_BIT_FIELD (padding_field) = 1;
05126 DECL_SIZE (padding_field) = padding;
05127 DECL_ALIGN (padding_field) = 1;
05128 DECL_USER_ALIGN (padding_field) = 0;
05129 layout_nonempty_base_or_field (rli, padding_field,
05130 NULL_TREE,
05131 empty_base_offsets);
05132 }
05133
05134 last_field_was_bitfield = DECL_C_BIT_FIELD (field);
05135 }
05136
05137 if (abi_version_at_least (2) && !integer_zerop (rli->bitpos))
05138 {
05139
05140
05141
05142 rli->bitpos = round_up (rli->bitpos, BITS_PER_UNIT);
05143 normalize_rli (rli);
05144 }
05145
05146
05147
05148 if (!abi_version_at_least (2))
05149 include_empty_classes(rli);
05150
05151
05152
05153 remove_zero_width_bit_fields (t);
05154
05155
05156
05157
05158 if (CLASSTYPE_NON_POD_P (t) || CLASSTYPE_EMPTY_P (t))
05159 {
05160 base_t = make_node (TREE_CODE (t));
05161
05162
05163
05164
05165 if (!abi_version_at_least (2) && CLASSTYPE_EMPTY_P (t))
05166 {
05167 TYPE_SIZE (base_t) = bitsize_zero_node;
05168 TYPE_SIZE_UNIT (base_t) = size_zero_node;
05169 if (warn_abi && !integer_zerop (rli_size_unit_so_far (rli)))
05170 warning ("layout of classes derived from empty class `%T' "
05171 "may change in a future version of GCC",
05172 t);
05173 }
05174 else
05175 {
05176 tree eoc;
05177
05178
05179
05180
05181
05182
05183
05184
05185 eoc = end_of_class (t, 0);
05186 TYPE_SIZE_UNIT (base_t)
05187 = size_binop (MAX_EXPR,
05188 convert (sizetype,
05189 size_binop (CEIL_DIV_EXPR,
05190 rli_size_so_far (rli),
05191 bitsize_int (BITS_PER_UNIT))),
05192 eoc);
05193 TYPE_SIZE (base_t)
05194 = size_binop (MAX_EXPR,
05195 rli_size_so_far (rli),
05196 size_binop (MULT_EXPR,
05197 convert (bitsizetype, eoc),
05198 bitsize_int (BITS_PER_UNIT)));
05199 }
05200 TYPE_ALIGN (base_t) = rli->record_align;
05201 TYPE_USER_ALIGN (base_t) = TYPE_USER_ALIGN (t);
05202
05203
05204 next_field = &TYPE_FIELDS (base_t);
05205 for (field = TYPE_FIELDS (t); field; field = TREE_CHAIN (field))
05206 if (TREE_CODE (field) == FIELD_DECL)
05207 {
05208 *next_field = build_decl (FIELD_DECL,
05209 DECL_NAME (field),
05210 TREE_TYPE (field));
05211 DECL_CONTEXT (*next_field) = base_t;
05212 DECL_FIELD_OFFSET (*next_field) = DECL_FIELD_OFFSET (field);
05213 DECL_FIELD_BIT_OFFSET (*next_field)
05214 = DECL_FIELD_BIT_OFFSET (field);
05215 DECL_BIT_FIELD (*next_field) = DECL_BIT_FIELD (field);
05216 #ifdef KEY
05217 DECL_SIZE (*next_field) = DECL_SIZE (field);
05218 DECL_SIZE_UNIT (*next_field) = DECL_SIZE_UNIT (field);
05219 #endif // KEY
05220 next_field = &TREE_CHAIN (*next_field);
05221 }
05222
05223
05224 CLASSTYPE_AS_BASE (t) = base_t;
05225 TYPE_CONTEXT (base_t) = t;
05226 }
05227 else
05228 CLASSTYPE_AS_BASE (t) = t;
05229
05230
05231 if (CLASSTYPE_EMPTY_P (t))
05232 CLASSTYPE_CONTAINS_EMPTY_CLASS_P (t) = 1;
05233
05234
05235
05236
05237 layout_decl (TYPE_MAIN_DECL (t), 0);
05238
05239
05240
05241
05242
05243 layout_virtual_bases (rli, empty_base_offsets);
05244
05245
05246
05247 include_empty_classes(rli);
05248
05249
05250 if (integer_zerop (rli_size_unit_so_far (rli)) && CLASSTYPE_EMPTY_P (t))
05251 place_field (rli,
05252 build_decl (FIELD_DECL, NULL_TREE, char_type_node));
05253
05254
05255 finish_record_layout (rli, true);
05256
05257
05258 warn_about_ambiguous_bases (t);
05259
05260
05261 splay_tree_delete (empty_base_offsets);
05262 }
05263
05264
05265
05266
05267 static tree
05268 key_method (tree type)
05269 {
05270 tree method;
05271
05272 if (TYPE_FOR_JAVA (type)
05273 || processing_template_decl
05274 || CLASSTYPE_TEMPLATE_INSTANTIATION (type)
05275 || CLASSTYPE_INTERFACE_KNOWN (type))
05276 return NULL_TREE;
05277
05278 for (method = TYPE_METHODS (type); method != NULL_TREE;
05279 method = TREE_CHAIN (method))
05280 if (DECL_VINDEX (method) != NULL_TREE
05281 && ! DECL_DECLARED_INLINE_P (method)
05282 && ! DECL_PURE_VIRTUAL_P (method))
05283 return method;
05284
05285 return NULL_TREE;
05286 }
05287
05288
05289
05290
05291 void
05292 finish_struct_1 (t)
05293 tree t;
05294 {
05295 tree x;
05296
05297 tree virtuals = NULL_TREE;
05298 int n_fields = 0;
05299 tree vfield;
05300
05301 if (COMPLETE_TYPE_P (t))
05302 {
05303 if (IS_AGGR_TYPE (t))
05304 error ("redefinition of `%#T'", t);
05305 else
05306 abort ();
05307 popclass ();
05308 return;
05309 }
05310
05311
05312
05313 TYPE_SIZE (t) = NULL_TREE;
05314 CLASSTYPE_GOT_SEMICOLON (t) = 0;
05315 CLASSTYPE_PRIMARY_BINFO (t) = NULL_TREE;
05316
05317 fixup_inline_methods (t);
05318
05319
05320
05321 CLASSTYPE_EMPTY_P (t) = 1;
05322 CLASSTYPE_NEARLY_EMPTY_P (t) = 1;
05323 CLASSTYPE_CONTAINS_EMPTY_CLASS_P (t) = 0;
05324
05325
05326
05327 check_bases_and_members (t);
05328
05329
05330 if (TYPE_CONTAINS_VPTR_P (t))
05331 {
05332 CLASSTYPE_KEY_METHOD (t) = key_method (t);
05333
05334
05335
05336 if (CLASSTYPE_KEY_METHOD (t) == NULL_TREE)
05337 keyed_classes = tree_cons (NULL_TREE, t, keyed_classes);
05338 }
05339
05340
05341 layout_class_type (t, &virtuals);
05342
05343
05344 vfield = TYPE_VFIELD (t);
05345 if (vfield && CLASSTYPE_HAS_PRIMARY_BASE_P (t))
05346 {
05347 tree primary = CLASSTYPE_PRIMARY_BINFO (t);
05348
05349 my_friendly_assert (same_type_p (DECL_FIELD_CONTEXT (vfield),
05350 BINFO_TYPE (primary)),
05351 20010726);
05352
05353 my_friendly_assert (integer_zerop (DECL_FIELD_OFFSET (vfield)),
05354 20010726);
05355 my_friendly_assert (integer_zerop (BINFO_OFFSET (primary)),
05356 20010726);
05357
05358 vfield = copy_decl (vfield);
05359 DECL_FIELD_CONTEXT (vfield) = t;
05360 TYPE_VFIELD (t) = vfield;
05361 }
05362 else
05363 my_friendly_assert (!vfield || DECL_FIELD_CONTEXT (vfield) == t, 20010726);
05364
05365 virtuals = modify_all_vtables (t, nreverse (virtuals));
05366
05367
05368
05369 if (TYPE_VFIELD (t) && !CLASSTYPE_HAS_PRIMARY_BASE_P (t))
05370 CLASSTYPE_VFIELDS (t)
05371 = chainon (CLASSTYPE_VFIELDS (t), build_tree_list (NULL_TREE, t));
05372
05373
05374 if (virtuals || TYPE_CONTAINS_VPTR_P (t))
05375 {
05376
05377 if (!CLASSTYPE_HAS_PRIMARY_BASE_P (t))
05378 build_primary_vtable (NULL_TREE, t);
05379 else if (! BINFO_NEW_VTABLE_MARKED (TYPE_BINFO (t), t))
05380
05381
05382 build_primary_vtable (CLASSTYPE_PRIMARY_BINFO (t), t);
05383 }
05384
05385 if (TYPE_CONTAINS_VPTR_P (t))
05386 {
05387 int vindex;
05388 tree fn;
05389
05390 if (TYPE_BINFO_VTABLE (t))
05391 my_friendly_assert (DECL_VIRTUAL_P (TYPE_BINFO_VTABLE (t)),
05392 20000116);
05393 if (!CLASSTYPE_HAS_PRIMARY_BASE_P (t))
05394 my_friendly_assert (TYPE_BINFO_VIRTUALS (t) == NULL_TREE,
05395 20000116);
05396
05397
05398 TYPE_BINFO_VIRTUALS (t) = chainon (TYPE_BINFO_VIRTUALS (t), virtuals);
05399
05400
05401 for (vindex = 0, fn = BINFO_VIRTUALS (TYPE_BINFO (t));
05402 fn;
05403 fn = TREE_CHAIN (fn),
05404 vindex += (TARGET_VTABLE_USES_DESCRIPTORS
05405 ? TARGET_VTABLE_USES_DESCRIPTORS : 1))
05406 if (TREE_CODE (DECL_VINDEX (BV_FN (fn))) != INTEGER_CST)
05407 DECL_VINDEX (BV_FN (fn)) = build_shared_int_cst (vindex);
05408 }
05409
05410 finish_struct_bits (t);
05411
05412
05413
05414 for (x = TYPE_FIELDS (t); x; x = TREE_CHAIN (x))
05415 if (TREE_CODE (x) == VAR_DECL && TREE_STATIC (x)
05416 && same_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (x)), t))
05417 DECL_MODE (x) = TYPE_MODE (t);
05418
05419
05420
05421
05422
05423
05424
05425
05426 n_fields = count_fields (TYPE_FIELDS (t));
05427 if (n_fields > 7)
05428 {
05429 tree field_vec = make_tree_vec (n_fields);
05430 add_fields_to_vec (TYPE_FIELDS (t), field_vec, 0);
05431 qsort (&TREE_VEC_ELT (field_vec, 0), n_fields, sizeof (tree),
05432 (int (*)(const void *, const void *))field_decl_cmp);
05433 if (! DECL_LANG_SPECIFIC (TYPE_MAIN_DECL (t)))
05434 retrofit_lang_decl (TYPE_MAIN_DECL (t));
05435 DECL_SORTED_FIELDS (TYPE_MAIN_DECL (t)) = field_vec;
05436 }
05437
05438 if (TYPE_HAS_CONSTRUCTOR (t))
05439 {
05440 tree vfields = CLASSTYPE_VFIELDS (t);
05441
05442 for (vfields = CLASSTYPE_VFIELDS (t);
05443 vfields; vfields = TREE_CHAIN (vfields))
05444
05445
05446
05447 if (VF_BINFO_VALUE (vfields))
05448 TREE_ADDRESSABLE (vfields) = 1;
05449 }
05450
05451
05452
05453 finish_vtbls (t);
05454
05455
05456 build_vtt (t);
05457
05458 if (warn_nonvdtor && TYPE_POLYMORPHIC_P (t) && TYPE_HAS_DESTRUCTOR (t)
05459 && DECL_VINDEX (TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (t), 1)) == NULL_TREE)
05460 warning ("`%#T' has virtual functions but non-virtual destructor", t);
05461
05462 complete_vars (t);
05463
05464 if (warn_overloaded_virtual)
05465 warn_hidden (t);
05466
05467 maybe_suppress_debug_info (t);
05468
05469 dump_class_hierarchy (t);
05470
05471
05472 rest_of_type_compilation (t, ! LOCAL_CLASS_P (t));
05473 }
05474
05475
05476
05477
05478 void
05479 unreverse_member_declarations (t)
05480 tree t;
05481 {
05482 tree next;
05483 tree prev;
05484 tree x;
05485
05486
05487
05488 TYPE_METHODS (t) = nreverse (TYPE_METHODS (t));
05489 CLASSTYPE_DECL_LIST (t) = nreverse (CLASSTYPE_DECL_LIST (t));
05490
05491
05492
05493 prev = NULL_TREE;
05494 for (x = TYPE_FIELDS (t);
05495 x && TREE_CODE (x) != TYPE_DECL;
05496 x = next)
05497 {
05498 next = TREE_CHAIN (x);
05499 TREE_CHAIN (x) = prev;
05500 prev = x;
05501 }
05502 if (prev)
05503 {
05504 TREE_CHAIN (TYPE_FIELDS (t)) = x;
05505 if (prev)
05506 TYPE_FIELDS (t) = prev;
05507 }
05508 }
05509
05510 tree
05511 finish_struct (t, attributes)
05512 tree t, attributes;
05513 {
05514 const char *saved_filename = input_filename;
05515 int saved_lineno = lineno;
05516
05517
05518
05519 unreverse_member_declarations (t);
05520
05521 cplus_decl_attributes (&t, attributes, (int) ATTR_FLAG_TYPE_IN_PLACE);
05522
05523
05524
05525 input_filename = DECL_SOURCE_FILE (TYPE_NAME (t));
05526 lineno = DECL_SOURCE_LINE (TYPE_NAME (t));
05527
05528 if (processing_template_decl)
05529 {
05530 finish_struct_methods (t);
05531 TYPE_SIZE (t) = bitsize_zero_node;
05532 }
05533 else
05534 finish_struct_1 (t);
05535
05536 input_filename = saved_filename;
05537 lineno = saved_lineno;
05538
05539 TYPE_BEING_DEFINED (t) = 0;
05540
05541 if (current_class_type)
05542 popclass ();
05543 else
05544 error ("trying to finish struct, but kicked out due to previous parse errors");
05545
05546 if (processing_template_decl && at_function_scope_p ())
05547 add_stmt (build_min (TAG_DEFN, t));
05548
05549 return t;
05550 }
05551
05552
05553
05554
05555
05556
05557
05558
05559
05560 static tree
05561 fixed_type_or_null (instance, nonnull, cdtorp)
05562 tree instance;
05563 int *nonnull;
05564 int *cdtorp;
05565 {
05566 switch (TREE_CODE (instance))
05567 {
05568 case INDIRECT_REF:
05569 if (POINTER_TYPE_P (TREE_TYPE (instance)))
05570 return NULL_TREE;
05571 else
05572 return fixed_type_or_null (TREE_OPERAND (instance, 0),
05573 nonnull, cdtorp);
05574
05575 case CALL_EXPR:
05576
05577 if (TREE_HAS_CONSTRUCTOR (instance))
05578 {
05579 if (nonnull)
05580 *nonnull = 1;
05581 return TREE_TYPE (instance);
05582 }
05583 return NULL_TREE;
05584
05585 case SAVE_EXPR:
05586
05587 if (TREE_HAS_CONSTRUCTOR (instance))
05588 {
05589 if (nonnull)
05590 *nonnull = 1;
05591 return TREE_TYPE (instance);
05592 }
05593 return fixed_type_or_null (TREE_OPERAND (instance, 0), nonnull, cdtorp);
05594
05595 case RTL_EXPR:
05596 return NULL_TREE;
05597
05598 case PLUS_EXPR:
05599 case MINUS_EXPR:
05600 if (TREE_CODE (TREE_OPERAND (instance, 0)) == ADDR_EXPR)
05601 return fixed_type_or_null (TREE_OPERAND (instance, 0), nonnull, cdtorp);
05602 if (TREE_CODE (TREE_OPERAND (instance, 1)) == INTEGER_CST)
05603
05604 return fixed_type_or_null (TREE_OPERAND (instance, 0), nonnull, cdtorp);
05605 return NULL_TREE;
05606
05607 case NOP_EXPR:
05608 case CONVERT_EXPR:
05609 return fixed_type_or_null (TREE_OPERAND (instance, 0), nonnull, cdtorp);
05610
05611 case ADDR_EXPR:
05612 if (nonnull)
05613 *nonnull = 1;
05614 return fixed_type_or_null (TREE_OPERAND (instance, 0), nonnull, cdtorp);
05615
05616 case COMPONENT_REF:
05617 return fixed_type_or_null (TREE_OPERAND (instance, 1), nonnull, cdtorp);
05618
05619 case VAR_DECL:
05620 case FIELD_DECL:
05621 if (TREE_CODE (TREE_TYPE (instance)) == ARRAY_TYPE
05622 && IS_AGGR_TYPE (TREE_TYPE (TREE_TYPE (instance))))
05623 {
05624 if (nonnull)
05625 *nonnull = 1;
05626 return TREE_TYPE (TREE_TYPE (instance));
05627 }
05628
05629 case TARGET_EXPR:
05630 case PARM_DECL:
05631 case RESULT_DECL:
05632 if (IS_AGGR_TYPE (TREE_TYPE (instance)))
05633 {
05634 if (nonnull)
05635 *nonnull = 1;
05636 return TREE_TYPE (instance);
05637 }
05638 else if (instance == current_class_ptr)
05639 {
05640 if (nonnull)
05641 *nonnull = 1;
05642
05643
05644 if (DECL_LANG_SPECIFIC (current_function_decl)
05645 && (DECL_CONSTRUCTOR_P (current_function_decl)
05646 || DECL_DESTRUCTOR_P (current_function_decl)))
05647 {
05648 if (cdtorp)
05649 *cdtorp = 1;
05650 return TREE_TYPE (TREE_TYPE (instance));
05651 }
05652 }
05653 else if (TREE_CODE (TREE_TYPE (instance)) == REFERENCE_TYPE)
05654 {
05655
05656 if (nonnull)
05657 *nonnull = 1;
05658
05659
05660
05661
05662 if (TREE_CODE (instance) == VAR_DECL
05663 && DECL_INITIAL (instance)
05664 && !DECL_VAR_MARKED_P (instance))
05665 {
05666 tree type;
05667 DECL_VAR_MARKED_P (instance) = 1;
05668 type = fixed_type_or_null (DECL_INITIAL (instance),
05669 nonnull, cdtorp);
05670 DECL_VAR_MARKED_P (instance) = 0;
05671 return type;
05672 }
05673 }
05674 return NULL_TREE;
05675
05676 default:
05677 return NULL_TREE;
05678 }
05679 }
05680
05681
05682
05683
05684
05685
05686
05687
05688
05689
05690
05691
05692
05693
05694
05695 int
05696 resolves_to_fixed_type_p (instance, nonnull)
05697 tree instance;
05698 int *nonnull;
05699 {
05700 tree t = TREE_TYPE (instance);
05701 int cdtorp = 0;
05702
05703 tree fixed = fixed_type_or_null (instance, nonnull, &cdtorp);
05704 if (fixed == NULL_TREE)
05705 return 0;
05706 if (POINTER_TYPE_P (t))
05707 t = TREE_TYPE (t);
05708 if (!same_type_ignoring_top_level_qualifiers_p (t, fixed))
05709 return 0;
05710 return cdtorp ? -1 : 1;
05711 }
05712
05713
05714 void
05715 init_class_processing ()
05716 {
05717 current_class_depth = 0;
05718 current_class_stack_size = 10;
05719 current_class_stack
05720 = (class_stack_node_t) xmalloc (current_class_stack_size
05721 * sizeof (struct class_stack_node));
05722 VARRAY_TREE_INIT (local_classes, 8, "local_classes");
05723
05724 access_default_node = build_int_2 (0, 0);
05725 access_public_node = build_int_2 (ak_public, 0);
05726 access_protected_node = build_int_2 (ak_protected, 0);
05727 access_private_node = build_int_2 (ak_private, 0);
05728 access_default_virtual_node = build_int_2 (4, 0);
05729 access_public_virtual_node = build_int_2 (4 | ak_public, 0);
05730 access_protected_virtual_node = build_int_2 (4 | ak_protected, 0);
05731 access_private_virtual_node = build_int_2 (4 | ak_private, 0);
05732
05733 ridpointers[(int) RID_PUBLIC] = access_public_node;
05734 ridpointers[(int) RID_PRIVATE] = access_private_node;
05735 ridpointers[(int) RID_PROTECTED] = access_protected_node;
05736 }
05737
05738
05739
05740
05741
05742
05743
05744
05745
05746
05747
05748
05749
05750
05751
05752
05753
05754
05755
05756
05757
05758
05759
05760
05761
05762
05763
05764
05765
05766
05767
05768
05769
05770
05771
05772 void
05773 pushclass (type, modify)
05774 tree type;
05775 int modify;
05776 {
05777 type = TYPE_MAIN_VARIANT (type);
05778
05779
05780 if (current_class_depth + 1 >= current_class_stack_size)
05781 {
05782 current_class_stack_size *= 2;
05783 current_class_stack
05784 = (class_stack_node_t) xrealloc (current_class_stack,
05785 current_class_stack_size
05786 * sizeof (struct class_stack_node));
05787 }
05788
05789
05790 current_class_stack[current_class_depth].name = current_class_name;
05791 current_class_stack[current_class_depth].type = current_class_type;
05792 current_class_stack[current_class_depth].access = current_access_specifier;
05793 current_class_stack[current_class_depth].names_used = 0;
05794 current_class_depth++;
05795
05796
05797 current_class_name = TYPE_NAME (type);
05798 if (TREE_CODE (current_class_name) == TYPE_DECL)
05799 current_class_name = DECL_NAME (current_class_name);
05800 current_class_type = type;
05801
05802
05803
05804 current_access_specifier = (CLASSTYPE_DECLARED_CLASS (type)
05805 ? access_private_node
05806 : access_public_node);
05807
05808 if (previous_class_type != NULL_TREE
05809 && (type != previous_class_type
05810 || !COMPLETE_TYPE_P (previous_class_type))
05811 && current_class_depth == 1)
05812 {
05813
05814 invalidate_class_lookup_cache ();
05815 }
05816
05817
05818
05819 if (modify && current_class_depth > 1)
05820 clear_identifier_class_values ();
05821
05822 pushlevel_class ();
05823
05824 if (modify)
05825 {
05826 if (type != previous_class_type || current_class_depth > 1)
05827 push_class_decls (type);
05828 else
05829 {
05830 tree item;
05831
05832
05833
05834
05835
05836
05837 set_class_shadows (previous_class_values);
05838 for (item = previous_class_values; item; item = TREE_CHAIN (item))
05839 {
05840 tree id = TREE_PURPOSE (item);
05841 tree decl = TREE_TYPE (item);
05842
05843 push_class_binding (id, decl);
05844 if (TREE_CODE (decl) == TYPE_DECL)
05845 set_identifier_type_value (id, TREE_TYPE (decl));
05846 }
05847 unuse_fields (type);
05848 }
05849
05850 cxx_remember_type_decls (CLASSTYPE_NESTED_UDTS (type));
05851 }
05852 }
05853
05854
05855
05856
05857
05858
05859 void
05860 invalidate_class_lookup_cache ()
05861 {
05862 tree t;
05863
05864
05865 for (t = previous_class_values; t; t = TREE_CHAIN (t))
05866 IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (t)) = NULL_TREE;
05867
05868 previous_class_values = NULL_TREE;
05869 previous_class_type = NULL_TREE;
05870 }
05871
05872
05873
05874
05875 void
05876 popclass ()
05877 {
05878 poplevel_class ();
05879 pop_class_decls ();
05880
05881 current_class_depth--;
05882 current_class_name = current_class_stack[current_class_depth].name;
05883 current_class_type = current_class_stack[current_class_depth].type;
05884 current_access_specifier = current_class_stack[current_class_depth].access;
05885 if (current_class_stack[current_class_depth].names_used)
05886 splay_tree_delete (current_class_stack[current_class_depth].names_used);
05887 }
05888
05889
05890
05891
05892
05893 int
05894 currently_open_class (t)
05895 tree t;
05896 {
05897 int i;
05898 if (t == current_class_type)
05899 return 1;
05900 for (i = 1; i < current_class_depth; ++i)
05901 if (current_class_stack [i].type == t)
05902 return 1;
05903 return 0;
05904 }
05905
05906
05907
05908
05909
05910 tree
05911 currently_open_derived_class (t)
05912 tree t;
05913 {
05914 int i;
05915
05916 if (DERIVED_FROM_P (t, current_class_type))
05917 return current_class_type;
05918
05919 for (i = current_class_depth - 1; i > 0; --i)
05920 if (DERIVED_FROM_P (t, current_class_stack[i].type))
05921 return current_class_stack[i].type;
05922
05923 return NULL_TREE;
05924 }
05925
05926
05927
05928
05929
05930
05931
05932
05933 void
05934 push_nested_class (type, modify)
05935 tree type;
05936 int modify;
05937 {
05938 tree context;
05939
05940
05941 if (type == NULL_TREE
05942 || type == error_mark_node
05943 || TREE_CODE (type) == NAMESPACE_DECL
05944 || ! IS_AGGR_TYPE (type)
05945 || TREE_CODE (type) == TEMPLATE_TYPE_PARM
05946 || TREE_CODE (type) == BOUND_TEMPLATE_TEMPLATE_PARM)
05947 return;
05948
05949 context = DECL_CONTEXT (TYPE_MAIN_DECL (type));
05950
05951 if (context && CLASS_TYPE_P (context))
05952 push_nested_class (context, 2);
05953 pushclass (type, modify);
05954 }
05955
05956
05957
05958 void
05959 pop_nested_class ()
05960 {
05961 tree context = DECL_CONTEXT (TYPE_MAIN_DECL (current_class_type));
05962
05963 popclass ();
05964 if (context && CLASS_TYPE_P (context))
05965 pop_nested_class ();
05966 }
05967
05968
05969
05970 int
05971 current_lang_depth ()
05972 {
05973 return VARRAY_ACTIVE_SIZE (current_lang_base);
05974 }
05975
05976
05977
05978
05979 void
05980 push_lang_context (name)
05981 tree name;
05982 {
05983 VARRAY_PUSH_TREE (current_lang_base, current_lang_name);
05984
05985 if (name == lang_name_cplusplus)
05986 {
05987 current_lang_name = name;
05988 }
05989 else if (name == lang_name_java)
05990 {
05991 current_lang_name = name;
05992
05993
05994
05995
05996 DECL_IGNORED_P (TYPE_NAME (java_byte_type_node)) = 0;
05997 DECL_IGNORED_P (TYPE_NAME (java_short_type_node)) = 0;
05998 DECL_IGNORED_P (TYPE_NAME (java_int_type_node)) = 0;
05999 DECL_IGNORED_P (TYPE_NAME (java_long_type_node)) = 0;
06000 DECL_IGNORED_P (TYPE_NAME (java_float_type_node)) = 0;
06001 DECL_IGNORED_P (TYPE_NAME (java_double_type_node)) = 0;
06002 DECL_IGNORED_P (TYPE_NAME (java_char_type_node)) = 0;
06003 DECL_IGNORED_P (TYPE_NAME (java_boolean_type_node)) = 0;
06004 }
06005 else if (name == lang_name_c)
06006 {
06007 current_lang_name = name;
06008 }
06009 else
06010 error ("language string `\"%s\"' not recognized", IDENTIFIER_POINTER (name));
06011 }
06012
06013
06014
06015 void
06016 pop_lang_context ()
06017 {
06018 current_lang_name = VARRAY_TOP_TREE (current_lang_base);
06019 VARRAY_POP (current_lang_base);
06020 }
06021
06022
06023
06024
06025
06026
06027
06028
06029
06030
06031
06032 static tree
06033 resolve_address_of_overloaded_function (target_type,
06034 overload,
06035 complain,
06036 ptrmem,
06037 template_only,
06038 explicit_targs)
06039 tree target_type;
06040 tree overload;
06041 int complain;
06042 int ptrmem;
06043 int template_only;
06044 tree explicit_targs;
06045 {
06046
06047
06048
06049
06050
06051
06052
06053
06054
06055
06056
06057
06058
06059
06060
06061
06062
06063
06064
06065
06066
06067
06068
06069
06070
06071
06072 int is_ptrmem = 0;
06073 int is_reference = 0;
06074
06075
06076
06077 tree matches = NULL_TREE;
06078 tree fn;
06079
06080
06081
06082
06083 my_friendly_assert (!(TREE_CODE (target_type) == POINTER_TYPE
06084 && (TREE_CODE (TREE_TYPE (target_type))
06085 == METHOD_TYPE)), 0);
06086
06087 if (TREE_CODE (overload) == COMPONENT_REF)
06088 overload = TREE_OPERAND (overload, 1);
06089
06090
06091 if (TYPE_PTRFN_P (target_type))
06092 ;
06093 else if (TYPE_PTRMEMFUNC_P (target_type))
06094
06095 is_ptrmem = 1;
06096 else if (TREE_CODE (target_type) == FUNCTION_TYPE)
06097 {
06098
06099
06100 target_type = build_reference_type (target_type);
06101 is_reference = 1;
06102 }
06103 else
06104 {
06105 if (complain)
06106 error ("\
06107 cannot resolve overloaded function `%D' based on conversion to type `%T'",
06108 DECL_NAME (OVL_FUNCTION (overload)), target_type);
06109 return error_mark_node;
06110 }
06111
06112
06113
06114
06115
06116 if (!template_only)
06117 {
06118 tree fns;
06119
06120 for (fns = overload; fns; fns = OVL_CHAIN (fns))
06121 {
06122 tree fn = OVL_FUNCTION (fns);
06123 tree fntype;
06124
06125 if (TREE_CODE (fn) == TEMPLATE_DECL)
06126
06127 continue;
06128
06129 if ((TREE_CODE (TREE_TYPE (fn)) == METHOD_TYPE)
06130 != is_ptrmem)
06131
06132
06133 continue;
06134
06135
06136 fntype = TREE_TYPE (fn);
06137 if (is_ptrmem)
06138 fntype = build_ptrmemfunc_type (build_pointer_type (fntype));
06139 else if (!is_reference)
06140 fntype = build_pointer_type (fntype);
06141
06142 if (can_convert_arg (target_type, fntype, fn))
06143 matches = tree_cons (fn, NULL_TREE, matches);
06144 }
06145 }
06146
06147
06148
06149
06150 if (!matches)
06151 {
06152 tree target_fn_type;
06153 tree target_arg_types;
06154 tree target_ret_type;
06155 tree fns;
06156
06157 if (is_ptrmem)
06158 target_fn_type
06159 = TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (target_type));
06160 else
06161 target_fn_type = TREE_TYPE (target_type);
06162 target_arg_types = TYPE_ARG_TYPES (target_fn_type);
06163 target_ret_type = TREE_TYPE (target_fn_type);
06164
06165
06166 if (TREE_CODE (target_fn_type) == METHOD_TYPE)
06167 target_arg_types = TREE_CHAIN (target_arg_types);
06168
06169 for (fns = overload; fns; fns = OVL_CHAIN (fns))
06170 {
06171 tree fn = OVL_FUNCTION (fns);
06172 tree instantiation;
06173 tree instantiation_type;
06174 tree targs;
06175
06176 if (TREE_CODE (fn) != TEMPLATE_DECL)
06177
06178 continue;
06179
06180 if ((TREE_CODE (TREE_TYPE (fn)) == METHOD_TYPE)
06181 != is_ptrmem)
06182
06183
06184 continue;
06185
06186
06187 targs = make_tree_vec (DECL_NTPARMS (fn));
06188 if (fn_type_unification (fn, explicit_targs, targs,
06189 target_arg_types, target_ret_type,
06190 DEDUCE_EXACT, -1) != 0)
06191
06192 continue;
06193
06194
06195 instantiation = instantiate_template (fn, targs);
06196 if (instantiation == error_mark_node)
06197
06198 continue;
06199
06200
06201 instantiation_type = TREE_TYPE (instantiation);
06202 if (is_ptrmem)
06203 instantiation_type =
06204 build_ptrmemfunc_type (build_pointer_type (instantiation_type));
06205 else if (!is_reference)
06206 instantiation_type = build_pointer_type (instantiation_type);
06207 if (can_convert_arg (target_type, instantiation_type, instantiation))
06208 matches = tree_cons (instantiation, fn, matches);
06209 }
06210
06211
06212 if (matches)
06213 {
06214 tree match = most_specialized_instantiation (matches);
06215
06216 if (match != error_mark_node)
06217 matches = tree_cons (match, NULL_TREE, NULL_TREE);
06218 }
06219 }
06220
06221
06222 if (matches == NULL_TREE)
06223 {
06224
06225 if (complain)
06226 {
06227 error ("no matches converting function `%D' to type `%#T'",
06228 DECL_NAME (OVL_FUNCTION (overload)),
06229 target_type);
06230
06231
06232
06233
06234 for (; overload; overload = OVL_NEXT (overload))
06235 matches = tree_cons (NULL_TREE, OVL_CURRENT (overload),
06236 matches);
06237
06238 print_candidates (matches);
06239 }
06240 return error_mark_node;
06241 }
06242 else if (TREE_CHAIN (matches))
06243 {
06244
06245
06246 if (complain)
06247 {
06248 tree match;
06249
06250 error ("converting overloaded function `%D' to type `%#T' is ambiguous",
06251 DECL_NAME (OVL_FUNCTION (overload)),
06252 target_type);
06253
06254
06255
06256 for (match = matches; match; match = TREE_CHAIN (match))
06257 TREE_VALUE (match) = TREE_PURPOSE (match);
06258
06259 print_candidates (matches);
06260 }
06261
06262 return error_mark_node;
06263 }
06264
06265
06266 fn = TREE_PURPOSE (matches);
06267
06268 if (DECL_NONSTATIC_MEMBER_FUNCTION_P (fn)
06269 && !ptrmem && !flag_ms_extensions)
06270 {
06271 static int explained;
06272
06273 if (!complain)
06274 return error_mark_node;
06275
06276 pedwarn ("assuming pointer to member `%D'", fn);
06277 if (!explained)
06278 {
06279 pedwarn ("(a pointer to member can only be formed with `&%E')", fn);
06280 explained = 1;
06281 }
06282 }
06283 mark_used (fn);
06284
06285 if (TYPE_PTRFN_P (target_type) || TYPE_PTRMEMFUNC_P (target_type))
06286 return build_unary_op (ADDR_EXPR, fn, 0);
06287 else
06288 {
06289
06290
06291
06292 cxx_mark_addressable (fn);
06293
06294 return fn;
06295 }
06296 }
06297
06298
06299
06300
06301
06302
06303
06304
06305
06306
06307
06308 tree
06309 instantiate_type (lhstype, rhs, flags)
06310 tree lhstype, rhs;
06311 tsubst_flags_t flags;
06312 {
06313 int complain = (flags & tf_error);
06314 int strict = (flags & tf_no_attributes)
06315 ? COMPARE_NO_ATTRIBUTES : COMPARE_STRICT;
06316 int allow_ptrmem = flags & tf_ptrmem_ok;
06317
06318 flags &= ~tf_ptrmem_ok;
06319
06320 if (TREE_CODE (lhstype) == UNKNOWN_TYPE)
06321 {
06322 if (complain)
06323 error ("not enough type information");
06324 return error_mark_node;
06325 }
06326
06327 if (TREE_TYPE (rhs) != NULL_TREE && ! (type_unknown_p (rhs)))
06328 {
06329 if (comptypes (lhstype, TREE_TYPE (rhs), strict))
06330 return rhs;
06331 if (complain)
06332 error ("argument of type `%T' does not match `%T'",
06333 TREE_TYPE (rhs), lhstype);
06334 return error_mark_node;
06335 }
06336
06337 if (TREE_CODE (rhs) == BASELINK)
06338 rhs = BASELINK_FUNCTIONS (rhs);
06339
06340
06341
06342 if (TREE_CODE (rhs) != OVERLOAD)
06343 rhs = copy_node (rhs);
06344
06345
06346
06347
06348
06349
06350 switch (TREE_CODE (rhs))
06351 {
06352 case TYPE_EXPR:
06353 case CONVERT_EXPR:
06354 case SAVE_EXPR:
06355 case CONSTRUCTOR:
06356 case BUFFER_REF:
06357 abort ();
06358 return error_mark_node;
06359
06360 case INDIRECT_REF:
06361 case ARRAY_REF:
06362 {
06363 tree new_rhs;
06364
06365 new_rhs = instantiate_type (build_pointer_type (lhstype),
06366 TREE_OPERAND (rhs, 0), flags);
06367 if (new_rhs == error_mark_node)
06368 return error_mark_node;
06369
06370 TREE_TYPE (rhs) = lhstype;
06371 TREE_OPERAND (rhs, 0) = new_rhs;
06372 return rhs;
06373 }
06374
06375 case NOP_EXPR:
06376 rhs = copy_node (TREE_OPERAND (rhs, 0));
06377 TREE_TYPE (rhs) = unknown_type_node;
06378 return instantiate_type (lhstype, rhs, flags);
06379
06380 case COMPONENT_REF:
06381 return instantiate_type (lhstype, TREE_OPERAND (rhs, 1), flags);
06382
06383 case OFFSET_REF:
06384 rhs = TREE_OPERAND (rhs, 1);
06385 if (BASELINK_P (rhs))
06386 return instantiate_type (lhstype, BASELINK_FUNCTIONS (rhs),
06387 flags | allow_ptrmem);
06388
06389
06390
06391 my_friendly_assert (TREE_CODE (rhs) == TEMPLATE_ID_EXPR, 0);
06392
06393
06394
06395 case TEMPLATE_ID_EXPR:
06396 {
06397 tree fns = TREE_OPERAND (rhs, 0);
06398 tree args = TREE_OPERAND (rhs, 1);
06399
06400 return
06401 resolve_address_of_overloaded_function (lhstype,
06402 fns,
06403 complain,
06404 allow_ptrmem,
06405 1,
06406 args);
06407 }
06408
06409 case OVERLOAD:
06410 return
06411 resolve_address_of_overloaded_function (lhstype,
06412 rhs,
06413 complain,
06414 allow_ptrmem,
06415 0,
06416 NULL_TREE);
06417
06418 case TREE_LIST:
06419
06420 my_friendly_assert (BASELINK_P (rhs), 990412);
06421
06422 return instantiate_type (lhstype, BASELINK_FUNCTIONS (rhs), flags);
06423
06424 case CALL_EXPR:
06425
06426 abort ();
06427 return error_mark_node;
06428
06429 case PLUS_EXPR:
06430 case MINUS_EXPR:
06431 case COMPOUND_EXPR:
06432 TREE_OPERAND (rhs, 0)
06433 = instantiate_type (lhstype, TREE_OPERAND (rhs, 0), flags);
06434 if (TREE_OPERAND (rhs, 0) == error_mark_node)
06435 return error_mark_node;
06436 TREE_OPERAND (rhs, 1)
06437 = instantiate_type (lhstype, TREE_OPERAND (rhs, 1), flags);
06438 if (TREE_OPERAND (rhs, 1) == error_mark_node)
06439 return error_mark_node;
06440
06441 TREE_TYPE (rhs) = lhstype;
06442 return rhs;
06443
06444 case MULT_EXPR:
06445 case TRUNC_DIV_EXPR:
06446 case FLOOR_DIV_EXPR:
06447 case CEIL_DIV_EXPR:
06448 case ROUND_DIV_EXPR:
06449 case RDIV_EXPR:
06450 case TRUNC_MOD_EXPR:
06451 case FLOOR_MOD_EXPR:
06452 case CEIL_MOD_EXPR:
06453 case ROUND_MOD_EXPR:
06454 case FIX_ROUND_EXPR:
06455 case FIX_FLOOR_EXPR:
06456 case FIX_CEIL_EXPR:
06457 case FIX_TRUNC_EXPR:
06458 case FLOAT_EXPR:
06459 case NEGATE_EXPR:
06460 case ABS_EXPR:
06461 case MAX_EXPR:
06462 case MIN_EXPR:
06463 case FFS_EXPR:
06464
06465 case BIT_AND_EXPR:
06466 case BIT_IOR_EXPR:
06467 case BIT_XOR_EXPR:
06468 case LSHIFT_EXPR:
06469 case RSHIFT_EXPR:
06470 case LROTATE_EXPR:
06471 case RROTATE_EXPR:
06472
06473 case PREINCREMENT_EXPR:
06474 case PREDECREMENT_EXPR:
06475 case POSTINCREMENT_EXPR:
06476 case POSTDECREMENT_EXPR:
06477 if (complain)
06478 error ("invalid operation on uninstantiated type");
06479 return error_mark_node;
06480
06481 case TRUTH_AND_EXPR:
06482 case TRUTH_OR_EXPR:
06483 case TRUTH_XOR_EXPR:
06484 case LT_EXPR:
06485 case LE_EXPR:
06486 case GT_EXPR:
06487 case GE_EXPR:
06488 case EQ_EXPR:
06489 case NE_EXPR:
06490 case TRUTH_ANDIF_EXPR:
06491 case TRUTH_ORIF_EXPR:
06492 case TRUTH_NOT_EXPR:
06493 if (complain)
06494 error ("not enough type information");
06495 return error_mark_node;
06496
06497 case COND_EXPR:
06498 if (type_unknown_p (TREE_OPERAND (rhs, 0)))
06499 {
06500 if (complain)
06501 error ("not enough type information");
06502 return error_mark_node;
06503 }
06504 TREE_OPERAND (rhs, 1)
06505 = instantiate_type (lhstype, TREE_OPERAND (rhs, 1), flags);
06506 if (TREE_OPERAND (rhs, 1) == error_mark_node)
06507 return error_mark_node;
06508 TREE_OPERAND (rhs, 2)
06509 = instantiate_type (lhstype, TREE_OPERAND (rhs, 2), flags);
06510 if (TREE_OPERAND (rhs, 2) == error_mark_node)
06511 return error_mark_node;
06512
06513 TREE_TYPE (rhs) = lhstype;
06514 return rhs;
06515
06516 case MODIFY_EXPR:
06517 TREE_OPERAND (rhs, 1)
06518 = instantiate_type (lhstype, TREE_OPERAND (rhs, 1), flags);
06519 if (TREE_OPERAND (rhs, 1) == error_mark_node)
06520 return error_mark_node;
06521
06522 TREE_TYPE (rhs) = lhstype;
06523 return rhs;
06524
06525 case ADDR_EXPR:
06526 {
06527 if (PTRMEM_OK_P (rhs))
06528 flags |= tf_ptrmem_ok;
06529
06530 return instantiate_type (lhstype, TREE_OPERAND (rhs, 0), flags);
06531 }
06532 case ENTRY_VALUE_EXPR:
06533 abort ();
06534 return error_mark_node;
06535
06536 case ERROR_MARK:
06537 return error_mark_node;
06538
06539 default:
06540 abort ();
06541 return error_mark_node;
06542 }
06543 }
06544
06545
06546
06547
06548
06549
06550
06551 static tree
06552 get_vfield_name (type)
06553 tree type;
06554 {
06555 tree binfo = TYPE_BINFO (type);
06556 char *buf;
06557
06558 while (BINFO_BASETYPES (binfo)
06559 && TYPE_CONTAINS_VPTR_P (BINFO_TYPE (BINFO_BASETYPE (binfo, 0)))
06560 && ! TREE_VIA_VIRTUAL (BINFO_BASETYPE (binfo, 0)))
06561 binfo = BINFO_BASETYPE (binfo, 0);
06562
06563 type = BINFO_TYPE (binfo);
06564 buf = (char *) alloca (sizeof (VFIELD_NAME_FORMAT)
06565 + TYPE_NAME_LENGTH (type) + 2);
06566 sprintf (buf, VFIELD_NAME_FORMAT,
06567 IDENTIFIER_POINTER (constructor_name (type)));
06568 return get_identifier (buf);
06569 }
06570
06571 void
06572 print_class_statistics ()
06573 {
06574 #ifdef GATHER_STATISTICS
06575 fprintf (stderr, "convert_harshness = %d\n", n_convert_harshness);
06576 fprintf (stderr, "compute_conversion_costs = %d\n", n_compute_conversion_costs);
06577 fprintf (stderr, "build_method_call = %d (inner = %d)\n",
06578 n_build_method_call, n_inner_fields_searched);
06579 if (n_vtables)
06580 {
06581 fprintf (stderr, "vtables = %d; vtable searches = %d\n",
06582 n_vtables, n_vtable_searches);
06583 fprintf (stderr, "vtable entries = %d; vtable elems = %d\n",
06584 n_vtable_entries, n_vtable_elems);
06585 }
06586 #endif
06587 }
06588
06589
06590
06591
06592
06593
06594
06595 void
06596 build_self_reference ()
06597 {
06598 tree name = constructor_name (current_class_type);
06599 tree value = build_lang_decl (TYPE_DECL, name, current_class_type);
06600 tree saved_cas;
06601
06602 DECL_NONLOCAL (value) = 1;
06603 DECL_CONTEXT (value) = current_class_type;
06604 DECL_ARTIFICIAL (value) = 1;
06605 SET_DECL_SELF_REFERENCE_P (value);
06606
06607 if (processing_template_decl)
06608 value = push_template_decl (value);
06609
06610 saved_cas = current_access_specifier;
06611 current_access_specifier = access_public_node;
06612 finish_member_declaration (value);
06613 current_access_specifier = saved_cas;
06614 }
06615
06616
06617
06618 int
06619 is_empty_class (type)
06620 tree type;
06621 {
06622 if (type == error_mark_node)
06623 return 0;
06624
06625 if (! IS_AGGR_TYPE (type))
06626 return 0;
06627
06628
06629
06630 if (abi_version_at_least (2))
06631 return CLASSTYPE_EMPTY_P (type);
06632 else
06633 return integer_zerop (CLASSTYPE_SIZE (type));
06634 }
06635
06636
06637
06638 static bool
06639 contains_empty_class_p (tree type)
06640 {
06641 if (is_empty_class (type))
06642 return true;
06643 if (CLASS_TYPE_P (type))
06644 {
06645 tree field;
06646 int i;
06647
06648 for (i = 0; i < CLASSTYPE_N_BASECLASSES (type); ++i)
06649 if (contains_empty_class_p (TYPE_BINFO_BASETYPE (type, i)))
06650 return true;
06651 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
06652 if (TREE_CODE (field) == FIELD_DECL
06653 && !DECL_ARTIFICIAL (field)
06654 && is_empty_class (TREE_TYPE (field)))
06655 return true;
06656 }
06657 else if (TREE_CODE (type) == ARRAY_TYPE)
06658 return contains_empty_class_p (TREE_TYPE (type));
06659 return false;
06660 }
06661
06662
06663
06664
06665 tree
06666 get_enclosing_class (type)
06667 tree type;
06668 {
06669 tree node = type;
06670
06671 while (node && TREE_CODE (node) != NAMESPACE_DECL)
06672 {
06673 switch (TREE_CODE_CLASS (TREE_CODE (node)))
06674 {
06675 case 'd':
06676 node = DECL_CONTEXT (node);
06677 break;
06678
06679 case 't':
06680 if (node != type)
06681 return node;
06682 node = TYPE_CONTEXT (node);
06683 break;
06684
06685 default:
06686 abort ();
06687 }
06688 }
06689 return NULL_TREE;
06690 }
06691
06692
06693
06694 int
06695 is_base_of_enclosing_class (base, type)
06696 tree base, type;
06697 {
06698 while (type)
06699 {
06700 if (lookup_base (type, base, ba_any, NULL))
06701 return 1;
06702
06703 type = get_enclosing_class (type);
06704 }
06705 return 0;
06706 }
06707
06708
06709
06710
06711 void
06712 maybe_note_name_used_in_class (name, decl)
06713 tree name;
06714 tree decl;
06715 {
06716 splay_tree names_used;
06717
06718
06719 if (!innermost_scope_is_class_p ())
06720 return;
06721
06722
06723
06724 if (IDENTIFIER_CLASS_VALUE (name))
06725 return;
06726
06727 if (!current_class_stack[current_class_depth - 1].names_used)
06728 current_class_stack[current_class_depth - 1].names_used
06729 = splay_tree_new (splay_tree_compare_pointers, 0, 0);
06730 names_used = current_class_stack[current_class_depth - 1].names_used;
06731
06732 splay_tree_insert (names_used,
06733 (splay_tree_key) name,
06734 (splay_tree_value) decl);
06735 }
06736
06737
06738
06739
06740 void
06741 note_name_declared_in_class (name, decl)
06742 tree name;
06743 tree decl;
06744 {
06745 splay_tree names_used;
06746 splay_tree_node n;
06747
06748
06749 names_used
06750 = current_class_stack[current_class_depth - 1].names_used;
06751 if (!names_used)
06752 return;
06753
06754 n = splay_tree_lookup (names_used, (splay_tree_key) name);
06755 if (n)
06756 {
06757
06758
06759
06760
06761
06762 error ("declaration of `%#D'", decl);
06763 cp_error_at ("changes meaning of `%D' from `%+#D'",
06764 DECL_NAME (OVL_CURRENT (decl)),
06765 (tree) n->value);
06766 }
06767 }
06768
06769
06770
06771
06772
06773 tree
06774 get_vtbl_decl_for_binfo (binfo)
06775 tree binfo;
06776 {
06777 tree decl;
06778
06779 decl = BINFO_VTABLE (binfo);
06780 if (decl && TREE_CODE (decl) == PLUS_EXPR)
06781 {
06782 my_friendly_assert (TREE_CODE (TREE_OPERAND (decl, 0)) == ADDR_EXPR,
06783 2000403);
06784 decl = TREE_OPERAND (TREE_OPERAND (decl, 0), 0);
06785 }
06786 if (decl)
06787 my_friendly_assert (TREE_CODE (decl) == VAR_DECL, 20000403);
06788 return decl;
06789 }
06790
06791
06792
06793
06794
06795 static tree
06796 dfs_get_primary_binfo (binfo, data)
06797 tree binfo;
06798 void *data;
06799 {
06800 tree cons = (tree) data;
06801 tree primary_base = TREE_PURPOSE (cons);
06802
06803 if (TREE_VIA_VIRTUAL (binfo)
06804 && same_type_p (BINFO_TYPE (binfo), primary_base))
06805
06806
06807
06808 TREE_VALUE (cons) = tree_cons (NULL, binfo, TREE_VALUE (cons));
06809
06810 return NULL_TREE;
06811 }
06812
06813
06814
06815
06816
06817
06818
06819
06820 tree
06821 get_primary_binfo (binfo)
06822 tree binfo;
06823 {
06824 tree primary_base;
06825 tree result = NULL_TREE;
06826 tree virtuals;
06827
06828 primary_base = CLASSTYPE_PRIMARY_BINFO (BINFO_TYPE (binfo));
06829 if (!primary_base)
06830 return NULL_TREE;
06831
06832
06833
06834 if (!TREE_VIA_VIRTUAL (primary_base))
06835 {
06836 int i;
06837
06838
06839
06840 for (i = 0; i < BINFO_N_BASETYPES (binfo); ++i)
06841 {
06842 tree base_binfo = BINFO_BASETYPE (binfo, i);
06843
06844 if (same_type_p (BINFO_TYPE (base_binfo),
06845 BINFO_TYPE (primary_base)))
06846 return base_binfo;
06847 }
06848
06849
06850 abort ();
06851 }
06852
06853
06854
06855
06856
06857
06858
06859 virtuals = build_tree_list (BINFO_TYPE (primary_base), NULL_TREE);
06860 dfs_walk (binfo, dfs_get_primary_binfo, NULL, virtuals);
06861 virtuals = TREE_VALUE (virtuals);
06862
06863
06864 my_friendly_assert (virtuals, 20010612);
06865
06866 if (TREE_CHAIN (virtuals))
06867 {
06868
06869
06870
06871
06872 tree complete_binfo;
06873 tree canonical;
06874
06875 for (complete_binfo = binfo;
06876 BINFO_INHERITANCE_CHAIN (complete_binfo);
06877 complete_binfo = BINFO_INHERITANCE_CHAIN (complete_binfo))
06878 continue;
06879 canonical = binfo_for_vbase (BINFO_TYPE (primary_base),
06880 BINFO_TYPE (complete_binfo));
06881
06882 for (; virtuals; virtuals = TREE_CHAIN (virtuals))
06883 {
06884 result = TREE_VALUE (virtuals);
06885
06886 if (canonical == result)
06887 {
06888
06889
06890 my_friendly_assert (!TREE_CHAIN (virtuals), 20010612);
06891 break;
06892 }
06893 }
06894 }
06895 else
06896 result = TREE_VALUE (virtuals);
06897 return result;
06898 }
06899
06900
06901
06902 static int
06903 maybe_indent_hierarchy (stream, indent, indented_p)
06904 FILE *stream;
06905 int indent;
06906 int indented_p;
06907 {
06908 if (!indented_p)
06909 fprintf (stream, "%*s", indent, "");
06910 return 1;
06911 }
06912
06913
06914
06915
06916
06917 static void
06918 dump_class_hierarchy_r (stream, flags, t, binfo, indent)
06919 FILE *stream;
06920 int flags;
06921 tree t;
06922 tree binfo;
06923 int indent;
06924 {
06925 int i;
06926 int indented = 0;
06927
06928 indented = maybe_indent_hierarchy (stream, indent, 0);
06929 fprintf (stream, "%s (0x%lx) ",
06930 type_as_string (binfo, TFF_PLAIN_IDENTIFIER),
06931 (unsigned long) binfo);
06932 fprintf (stream, HOST_WIDE_INT_PRINT_DEC,
06933 tree_low_cst (BINFO_OFFSET (binfo), 0));
06934 if (is_empty_class (BINFO_TYPE (binfo)))
06935 fprintf (stream, " empty");
06936 else if (CLASSTYPE_NEARLY_EMPTY_P (BINFO_TYPE (binfo)))
06937 fprintf (stream, " nearly-empty");
06938 if (TREE_VIA_VIRTUAL (binfo))
06939 {
06940 tree canonical = binfo_for_vbase (BINFO_TYPE (binfo), t);
06941
06942 fprintf (stream, " virtual");
06943 if (canonical == binfo)
06944 fprintf (stream, " canonical");
06945 else
06946 fprintf (stream, " non-canonical");
06947 }
06948 fprintf (stream, "\n");
06949
06950 indented = 0;
06951 if (BINFO_PRIMARY_BASE_OF (binfo))
06952 {
06953 indented = maybe_indent_hierarchy (stream, indent + 3, indented);
06954 fprintf (stream, " primary-for %s (0x%lx)",
06955 type_as_string (BINFO_PRIMARY_BASE_OF (binfo),
06956 TFF_PLAIN_IDENTIFIER),
06957 (unsigned long)BINFO_PRIMARY_BASE_OF (binfo));
06958 }
06959 if (BINFO_LOST_PRIMARY_P (binfo))
06960 {
06961 indented = maybe_indent_hierarchy (stream, indent + 3, indented);
06962 fprintf (stream, " lost-primary");
06963 }
06964 if (indented)
06965 fprintf (stream, "\n");
06966
06967 if (!(flags & TDF_SLIM))
06968 {
06969 int indented = 0;
06970
06971 if (BINFO_SUBVTT_INDEX (binfo))
06972 {
06973 indented = maybe_indent_hierarchy (stream, indent + 3, indented);
06974 fprintf (stream, " subvttidx=%s",
06975 expr_as_string (BINFO_SUBVTT_INDEX (binfo),
06976 TFF_PLAIN_IDENTIFIER));
06977 }
06978 if (BINFO_VPTR_INDEX (binfo))
06979 {
06980 indented = maybe_indent_hierarchy (stream, indent + 3, indented);
06981 fprintf (stream, " vptridx=%s",
06982 expr_as_string (BINFO_VPTR_INDEX (binfo),
06983 TFF_PLAIN_IDENTIFIER));
06984 }
06985 if (BINFO_VPTR_FIELD (binfo))
06986 {
06987 indented = maybe_indent_hierarchy (stream, indent + 3, indented);
06988 fprintf (stream, " vbaseoffset=%s",
06989 expr_as_string (BINFO_VPTR_FIELD (binfo),
06990 TFF_PLAIN_IDENTIFIER));
06991 }
06992 if (BINFO_VTABLE (binfo))
06993 {
06994 indented = maybe_indent_hierarchy (stream, indent + 3, indented);
06995 fprintf (stream, " vptr=%s",
06996 expr_as_string (BINFO_VTABLE (binfo),
06997 TFF_PLAIN_IDENTIFIER));
06998 }
06999
07000 if (indented)
07001 fprintf (stream, "\n");
07002 }
07003
07004
07005 for (i = 0; i < BINFO_N_BASETYPES (binfo); ++i)
07006 dump_class_hierarchy_r (stream, flags,
07007 t, BINFO_BASETYPE (binfo, i),
07008 indent + 2);
07009 }
07010
07011
07012
07013 static void
07014 dump_class_hierarchy (t)
07015 tree t;
07016 {
07017 int flags;
07018 FILE *stream = dump_begin (TDI_class, &flags);
07019
07020 if (!stream)
07021 return;
07022
07023 fprintf (stream, "Class %s\n", type_as_string (t, TFF_PLAIN_IDENTIFIER));
07024 fprintf (stream, " size=%lu align=%lu\n",
07025 (unsigned long)(tree_low_cst (TYPE_SIZE (t), 0) / BITS_PER_UNIT),
07026 (unsigned long)(TYPE_ALIGN (t) / BITS_PER_UNIT));
07027 dump_class_hierarchy_r (stream, flags, t, TYPE_BINFO (t), 0);
07028 fprintf (stream, "\n");
07029 dump_end (TDI_class, stream);
07030 }
07031
07032 static void
07033 dump_array (stream, decl)
07034 FILE *stream;
07035 tree decl;
07036 {
07037 tree inits;
07038 int ix;
07039 HOST_WIDE_INT elt;
07040 tree size = TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (decl)));
07041
07042 elt = (tree_low_cst (TYPE_SIZE (TREE_TYPE (TREE_TYPE (decl))), 0)
07043 / BITS_PER_UNIT);
07044 fprintf (stream, "%s:", decl_as_string (decl, TFF_PLAIN_IDENTIFIER));
07045 fprintf (stream, " %s entries",
07046 expr_as_string (size_binop (PLUS_EXPR, size, size_one_node),
07047 TFF_PLAIN_IDENTIFIER));
07048 fprintf (stream, "\n");
07049
07050 for (ix = 0, inits = TREE_OPERAND (DECL_INITIAL (decl), 1);
07051 inits; ix++, inits = TREE_CHAIN (inits))
07052 fprintf (stream, "%-4ld %s\n", (long)(ix * elt),
07053 expr_as_string (TREE_VALUE (inits), TFF_PLAIN_IDENTIFIER));
07054 }
07055
07056 static void
07057 dump_vtable (t, binfo, vtable)
07058 tree t;
07059 tree binfo;
07060 tree vtable;
07061 {
07062 int flags;
07063 FILE *stream = dump_begin (TDI_class, &flags);
07064
07065 if (!stream)
07066 return;
07067
07068 if (!(flags & TDF_SLIM))
07069 {
07070 int ctor_vtbl_p = TYPE_BINFO (t) != binfo;
07071
07072 fprintf (stream, "%s for %s",
07073 ctor_vtbl_p ? "Construction vtable" : "Vtable",
07074 type_as_string (binfo, TFF_PLAIN_IDENTIFIER));
07075 if (ctor_vtbl_p)
07076 {
07077 if (!TREE_VIA_VIRTUAL (binfo))
07078 fprintf (stream, " (0x%lx instance)", (unsigned long)binfo);
07079 fprintf (stream, " in %s", type_as_string (t, TFF_PLAIN_IDENTIFIER));
07080 }
07081 fprintf (stream, "\n");
07082 dump_array (stream, vtable);
07083 fprintf (stream, "\n");
07084 }
07085
07086 dump_end (TDI_class, stream);
07087 }
07088
07089 static void
07090 dump_vtt (t, vtt)
07091 tree t;
07092 tree vtt;
07093 {
07094 int flags;
07095 FILE *stream = dump_begin (TDI_class, &flags);
07096
07097 if (!stream)
07098 return;
07099
07100 if (!(flags & TDF_SLIM))
07101 {
07102 fprintf (stream, "VTT for %s\n",
07103 type_as_string (t, TFF_PLAIN_IDENTIFIER));
07104 dump_array (stream, vtt);
07105 fprintf (stream, "\n");
07106 }
07107
07108 dump_end (TDI_class, stream);
07109 }
07110
07111
07112
07113
07114
07115 static void
07116 finish_vtbls (t)
07117 tree t;
07118 {
07119 tree list;
07120 tree vbase;
07121 int i;
07122
07123
07124
07125
07126 list = build_tree_list (TYPE_BINFO_VTABLE (t), NULL_TREE);
07127 accumulate_vtbl_inits (TYPE_BINFO (t), TYPE_BINFO (t),
07128 TYPE_BINFO (t), t, list);
07129
07130
07131 for (vbase = TYPE_BINFO (t); vbase; vbase = TREE_CHAIN (vbase))
07132 {
07133 tree real_base;
07134
07135 if (!TREE_VIA_VIRTUAL (vbase))
07136 continue;
07137
07138
07139
07140 real_base = binfo_for_vbase (BINFO_TYPE (vbase), t);
07141
07142 accumulate_vtbl_inits (real_base, real_base,
07143 TYPE_BINFO (t), t, list);
07144 }
07145
07146
07147
07148 for (i = 0; i < BINFO_N_BASETYPES (TYPE_BINFO (t)); ++i)
07149 {
07150 tree base = BINFO_BASETYPE (TYPE_BINFO (t), i);
07151 if (TREE_VIA_VIRTUAL (base))
07152 {
07153 vbase = binfo_for_vbase (BINFO_TYPE (base), t);
07154 BINFO_VPTR_FIELD (base) = BINFO_VPTR_FIELD (vbase);
07155 }
07156 }
07157
07158 if (TYPE_BINFO_VTABLE (t))
07159 initialize_vtable (TYPE_BINFO (t), TREE_VALUE (list));
07160 }
07161
07162
07163
07164 static void
07165 initialize_vtable (binfo, inits)
07166 tree binfo;
07167 tree inits;
07168 {
07169 tree decl;
07170
07171 layout_vtable_decl (binfo, list_length (inits));
07172 decl = get_vtbl_decl_for_binfo (binfo);
07173 initialize_array (decl, inits);
07174 dump_vtable (BINFO_TYPE (binfo), binfo, decl);
07175 }
07176
07177
07178
07179
07180 static void
07181 initialize_array (decl, inits)
07182 tree decl;
07183 tree inits;
07184 {
07185 tree context;
07186
07187 context = DECL_CONTEXT (decl);
07188 DECL_CONTEXT (decl) = NULL_TREE;
07189 DECL_INITIAL (decl) = build_nt (CONSTRUCTOR, NULL_TREE, inits);
07190 TREE_HAS_CONSTRUCTOR (DECL_INITIAL (decl)) = 1;
07191 cp_finish_decl (decl, DECL_INITIAL (decl), NULL_TREE, 0);
07192 DECL_CONTEXT (decl) = context;
07193 }
07194
07195
07196
07197
07198
07199
07200
07201
07202
07203
07204
07205
07206
07207
07208 static void
07209 build_vtt (t)
07210 tree t;
07211 {
07212 tree inits;
07213 tree type;
07214 tree vtt;
07215 tree index;
07216
07217
07218 inits = NULL_TREE;
07219 index = size_zero_node;
07220 build_vtt_inits (TYPE_BINFO (t), t, &inits, &index);
07221
07222
07223 if (!inits)
07224 return;
07225
07226
07227 type = build_index_type (size_int (list_length (inits) - 1));
07228 type = build_cplus_array_type (const_ptr_type_node, type);
07229
07230
07231 vtt = build_vtable (t, get_vtt_name (t), type);
07232 initialize_array (vtt, inits);
07233
07234 TREE_CHAIN (vtt) = TREE_CHAIN (CLASSTYPE_VTABLES (t));
07235 TREE_CHAIN (CLASSTYPE_VTABLES (t)) = vtt;
07236
07237 dump_vtt (t, vtt);
07238 }
07239
07240
07241
07242
07243
07244
07245 static tree
07246 get_original_base (base_binfo, binfo)
07247 tree base_binfo;
07248 tree binfo;
07249 {
07250 tree derived;
07251 int ix;
07252
07253 if (same_type_p (BINFO_TYPE (base_binfo), BINFO_TYPE (binfo)))
07254 return binfo;
07255 if (TREE_VIA_VIRTUAL (base_binfo))
07256 return binfo_for_vbase (BINFO_TYPE (base_binfo), BINFO_TYPE (binfo));
07257 derived = get_original_base (BINFO_INHERITANCE_CHAIN (base_binfo), binfo);
07258
07259 for (ix = 0; ix != BINFO_N_BASETYPES (derived); ix++)
07260 if (same_type_p (BINFO_TYPE (base_binfo),
07261 BINFO_TYPE (BINFO_BASETYPE (derived, ix))))
07262 return BINFO_BASETYPE (derived, ix);
07263 abort ();
07264 return NULL;
07265 }
07266
07267
07268
07269
07270
07271
07272 static tree
07273 binfo_ctor_vtable (binfo)
07274 tree binfo;
07275 {
07276 tree vt;
07277
07278 while (1)
07279 {
07280 vt = BINFO_VTABLE (binfo);
07281 if (TREE_CODE (vt) == TREE_LIST)
07282 vt = TREE_VALUE (vt);
07283 if (TREE_CODE (vt) == TREE_VEC)
07284 binfo = vt;
07285 else
07286 break;
07287 }
07288
07289 return vt;
07290 }
07291
07292
07293
07294
07295
07296
07297
07298
07299
07300 static tree *
07301 build_vtt_inits (binfo, t, inits, index)
07302 tree binfo;
07303 tree t;
07304 tree *inits;
07305 tree *index;
07306 {
07307 int i;
07308 tree b;
07309 tree init;
07310 tree secondary_vptrs;
07311 int top_level_p = same_type_p (TREE_TYPE (binfo), t);
07312
07313
07314 if (!TYPE_USES_VIRTUAL_BASECLASSES (BINFO_TYPE (binfo)))
07315 return inits;
07316
07317
07318
07319 if (!top_level_p)
07320 {
07321 build_ctor_vtbl_group (binfo, t);
07322
07323
07324 BINFO_SUBVTT_INDEX (binfo) = *index;
07325 }
07326
07327
07328 init = binfo_ctor_vtable (binfo);
07329 *inits = build_tree_list (NULL_TREE, init);
07330 inits = &TREE_CHAIN (*inits);
07331 if (top_level_p)
07332 {
07333 my_friendly_assert (!BINFO_VPTR_INDEX (binfo), 20010129);
07334 BINFO_VPTR_INDEX (binfo) = *index;
07335 }
07336 *index = size_binop (PLUS_EXPR, *index, TYPE_SIZE_UNIT (ptr_type_node));
07337
07338
07339 for (i = 0; i < BINFO_N_BASETYPES (binfo); ++i)
07340 {
07341 b = BINFO_BASETYPE (binfo, i);
07342 if (!TREE_VIA_VIRTUAL (b))
07343 inits = build_vtt_inits (BINFO_BASETYPE (binfo, i), t,
07344 inits, index);
07345 }
07346
07347
07348
07349
07350 secondary_vptrs = tree_cons (t, NULL_TREE, BINFO_TYPE (binfo));
07351 TREE_TYPE (secondary_vptrs) = *index;
07352 VTT_TOP_LEVEL_P (secondary_vptrs) = top_level_p;
07353 VTT_MARKED_BINFO_P (secondary_vptrs) = 0;
07354
07355 dfs_walk_real (binfo,
07356 dfs_build_secondary_vptr_vtt_inits,
07357 NULL,
07358 dfs_ctor_vtable_bases_queue_p,
07359 secondary_vptrs);
07360 VTT_MARKED_BINFO_P (secondary_vptrs) = 1;
07361 dfs_walk (binfo, dfs_unmark, dfs_ctor_vtable_bases_queue_p,
07362 secondary_vptrs);
07363
07364 *index = TREE_TYPE (secondary_vptrs);
07365
07366
07367
07368
07369 secondary_vptrs = TREE_VALUE (secondary_vptrs);
07370 if (secondary_vptrs)
07371 {
07372 *inits = nreverse (secondary_vptrs);
07373 inits = &TREE_CHAIN (secondary_vptrs);
07374 my_friendly_assert (*inits == NULL_TREE, 20000517);
07375 }
07376
07377
07378 if (top_level_p)
07379 for (b = TYPE_BINFO (BINFO_TYPE (binfo)); b; b = TREE_CHAIN (b))
07380 {
07381 tree vbase;
07382
07383 if (!TREE_VIA_VIRTUAL (b))
07384 continue;
07385
07386 vbase = binfo_for_vbase (BINFO_TYPE (b), t);
07387 inits = build_vtt_inits (vbase, t, inits, index);
07388 }
07389
07390 if (!top_level_p)
07391 {
07392 tree data = tree_cons (t, binfo, NULL_TREE);
07393 VTT_TOP_LEVEL_P (data) = 0;
07394 VTT_MARKED_BINFO_P (data) = 0;
07395
07396 dfs_walk (binfo, dfs_fixup_binfo_vtbls,
07397 dfs_ctor_vtable_bases_queue_p,
07398 data);
07399 }
07400
07401 return inits;
07402 }
07403
07404
07405
07406
07407
07408
07409
07410
07411 static tree
07412 dfs_build_secondary_vptr_vtt_inits (binfo, data)
07413 tree binfo;
07414 void *data;
07415 {
07416 tree l;
07417 tree t;
07418 tree init;
07419 tree index;
07420 int top_level_p;
07421
07422 l = (tree) data;
07423 t = TREE_CHAIN (l);
07424 top_level_p = VTT_TOP_LEVEL_P (l);
07425
07426 SET_BINFO_MARKED (binfo);
07427
07428
07429 if (!TYPE_VFIELD (BINFO_TYPE (binfo)))
07430 return NULL_TREE;
07431
07432
07433 if (same_type_p (BINFO_TYPE (binfo), t))
07434 return NULL_TREE;
07435
07436
07437 if (!TREE_VIA_VIRTUAL (binfo) && BINFO_PRIMARY_P (binfo))
07438 return NULL_TREE;
07439
07440
07441
07442 if (!TYPE_USES_VIRTUAL_BASECLASSES (BINFO_TYPE (binfo))
07443 && !binfo_via_virtual (binfo, t))
07444 return NULL_TREE;
07445
07446
07447 index = TREE_TYPE (l);
07448 if (top_level_p)
07449 {
07450 my_friendly_assert (!BINFO_VPTR_INDEX (binfo), 20010129);
07451 BINFO_VPTR_INDEX (binfo) = index;
07452 }
07453 TREE_TYPE (l) = size_binop (PLUS_EXPR, index,
07454 TYPE_SIZE_UNIT (ptr_type_node));
07455
07456
07457 if (top_level_p && TREE_VIA_VIRTUAL (binfo))
07458 {
07459
07460
07461
07462 while (BINFO_PRIMARY_BASE_OF (binfo))
07463 binfo = BINFO_PRIMARY_BASE_OF (binfo);
07464 }
07465 init = binfo_ctor_vtable (binfo);
07466 TREE_VALUE (l) = tree_cons (NULL_TREE, init, TREE_VALUE (l));
07467
07468 return NULL_TREE;
07469 }
07470
07471
07472
07473
07474
07475
07476 static tree
07477 dfs_ctor_vtable_bases_queue_p (binfo, data)
07478 tree binfo;
07479 void *data;
07480 {
07481 if (TREE_VIA_VIRTUAL (binfo))
07482
07483 binfo = binfo_for_vbase (BINFO_TYPE (binfo), TREE_PURPOSE ((tree) data));
07484
07485 if (!BINFO_MARKED (binfo) == VTT_MARKED_BINFO_P ((tree) data))
07486 return NULL_TREE;
07487 return binfo;
07488 }
07489
07490
07491
07492
07493
07494
07495 static tree
07496 dfs_fixup_binfo_vtbls (binfo, data)
07497 tree binfo;
07498 void *data;
07499 {
07500 CLEAR_BINFO_MARKED (binfo);
07501
07502
07503 if (!TYPE_VFIELD (BINFO_TYPE (binfo)))
07504 return NULL_TREE;
07505
07506
07507
07508 if (BINFO_VTABLE (binfo)
07509 && TREE_CODE (BINFO_VTABLE (binfo)) == TREE_LIST
07510 && (TREE_PURPOSE (BINFO_VTABLE (binfo))
07511 == TREE_VALUE ((tree) data)))
07512 BINFO_VTABLE (binfo) = TREE_CHAIN (BINFO_VTABLE (binfo));
07513
07514 return NULL_TREE;
07515 }
07516
07517
07518
07519
07520 static void
07521 build_ctor_vtbl_group (binfo, t)
07522 tree binfo;
07523 tree t;
07524 {
07525 tree list;
07526 tree type;
07527 tree vtbl;
07528 tree inits;
07529 tree id;
07530 tree vbase;
07531
07532
07533 id = mangle_ctor_vtbl_for_type (t, binfo);
07534 if (IDENTIFIER_GLOBAL_VALUE (id))
07535 return;
07536
07537 my_friendly_assert (!same_type_p (BINFO_TYPE (binfo), t), 20010124);
07538
07539
07540
07541 vtbl = build_vtable (t, id, ptr_type_node);
07542 list = build_tree_list (vtbl, NULL_TREE);
07543 accumulate_vtbl_inits (binfo, TYPE_BINFO (TREE_TYPE (binfo)),
07544 binfo, t, list);
07545
07546
07547
07548 for (vbase = TYPE_BINFO (BINFO_TYPE (binfo));
07549 vbase;
07550 vbase = TREE_CHAIN (vbase))
07551 {
07552 tree b;
07553 tree orig_base;
07554
07555 if (!TREE_VIA_VIRTUAL (vbase))
07556 continue;
07557 b = binfo_for_vbase (BINFO_TYPE (vbase), t);
07558 orig_base = binfo_for_vbase (BINFO_TYPE (vbase), BINFO_TYPE (binfo));
07559
07560 accumulate_vtbl_inits (b, orig_base, binfo, t, list);
07561 }
07562 inits = TREE_VALUE (list);
07563
07564
07565 type = build_index_type (size_int (list_length (inits) - 1));
07566 type = build_cplus_array_type (vtable_entry_type, type);
07567 TREE_TYPE (vtbl) = type;
07568
07569
07570 CLASSTYPE_VTABLES (t) = chainon (CLASSTYPE_VTABLES (t), vtbl);
07571 initialize_array (vtbl, inits);
07572 dump_vtable (t, binfo, vtbl);
07573 }
07574
07575
07576
07577
07578
07579
07580
07581
07582
07583
07584
07585 static void
07586 accumulate_vtbl_inits (binfo, orig_binfo, rtti_binfo, t, inits)
07587 tree binfo;
07588 tree orig_binfo;
07589 tree rtti_binfo;
07590 tree t;
07591 tree inits;
07592 {
07593 int i;
07594 int ctor_vtbl_p = !same_type_p (BINFO_TYPE (rtti_binfo), t);
07595
07596 my_friendly_assert (same_type_p (BINFO_TYPE (binfo),
07597 BINFO_TYPE (orig_binfo)),
07598 20000517);
07599
07600
07601 if (!TYPE_CONTAINS_VPTR_P (BINFO_TYPE (binfo)))
07602 return;
07603
07604
07605
07606 if (ctor_vtbl_p
07607 && !TYPE_USES_VIRTUAL_BASECLASSES (BINFO_TYPE (binfo))
07608 && !binfo_via_virtual (orig_binfo, BINFO_TYPE (rtti_binfo)))
07609 return;
07610
07611
07612 TREE_VALUE (inits)
07613 = chainon (TREE_VALUE (inits),
07614 dfs_accumulate_vtbl_inits (binfo, orig_binfo,
07615 rtti_binfo, t, inits));
07616
07617
07618
07619
07620
07621
07622 for (i = 0; i < BINFO_N_BASETYPES (binfo); ++i)
07623 {
07624 tree base_binfo = BINFO_BASETYPE (binfo, i);
07625
07626
07627 if (TREE_VIA_VIRTUAL (base_binfo))
07628 continue;
07629 accumulate_vtbl_inits (base_binfo,
07630 BINFO_BASETYPE (orig_binfo, i),
07631 rtti_binfo, t,
07632 inits);
07633 }
07634 }
07635
07636
07637
07638
07639 static tree
07640 dfs_accumulate_vtbl_inits (binfo, orig_binfo, rtti_binfo, t, l)
07641 tree binfo;
07642 tree orig_binfo;
07643 tree rtti_binfo;
07644 tree t;
07645 tree l;
07646 {
07647 tree inits = NULL_TREE;
07648 tree vtbl = NULL_TREE;
07649 int ctor_vtbl_p = !same_type_p (BINFO_TYPE (rtti_binfo), t);
07650
07651 if (ctor_vtbl_p
07652 && TREE_VIA_VIRTUAL (orig_binfo) && BINFO_PRIMARY_P (orig_binfo))
07653 {
07654
07655
07656
07657
07658
07659
07660
07661
07662
07663
07664
07665
07666
07667
07668
07669 tree b = BINFO_PRIMARY_BASE_OF (binfo);
07670 tree last = NULL_TREE;
07671
07672
07673
07674 for (; b; b = BINFO_PRIMARY_BASE_OF (b))
07675 {
07676 last = b;
07677 if (TREE_VIA_VIRTUAL (b) || b == rtti_binfo)
07678 break;
07679 }
07680
07681
07682 if (b == NULL_TREE)
07683 for (b = last; b; b = BINFO_INHERITANCE_CHAIN (b))
07684 if (TREE_VIA_VIRTUAL (b) || b == rtti_binfo)
07685 break;
07686
07687
07688
07689
07690
07691 if (b == rtti_binfo
07692 || (b && binfo_for_vbase (BINFO_TYPE (b),
07693 BINFO_TYPE (rtti_binfo))))
07694
07695
07696
07697 vtbl = last;
07698
07699
07700 }
07701 else if (!BINFO_NEW_VTABLE_MARKED (orig_binfo, BINFO_TYPE (rtti_binfo)))
07702 return inits;
07703
07704 if (!vtbl)
07705 {
07706 tree index;
07707 int non_fn_entries;
07708
07709
07710 inits = build_vtbl_initializer (binfo, orig_binfo, t, rtti_binfo,
07711 &non_fn_entries);
07712
07713
07714 vtbl = TREE_PURPOSE (l);
07715 vtbl = build1 (ADDR_EXPR,
07716 vtbl_ptr_type_node,
07717 vtbl);
07718 TREE_CONSTANT (vtbl) = 1;
07719 index = size_binop (PLUS_EXPR,
07720 size_int (non_fn_entries),
07721 size_int (list_length (TREE_VALUE (l))));
07722 index = size_binop (MULT_EXPR,
07723 TYPE_SIZE_UNIT (vtable_entry_type),
07724 index);
07725 vtbl = build (PLUS_EXPR, TREE_TYPE (vtbl), vtbl, index);
07726 TREE_CONSTANT (vtbl) = 1;
07727 }
07728
07729 if (ctor_vtbl_p)
07730
07731
07732
07733 BINFO_VTABLE (binfo) = tree_cons (rtti_binfo, vtbl, BINFO_VTABLE (binfo));
07734 else if (BINFO_PRIMARY_P (binfo) && TREE_VIA_VIRTUAL (binfo))
07735 inits = NULL_TREE;
07736 else
07737
07738 BINFO_VTABLE (binfo) = vtbl;
07739
07740 return inits;
07741 }
07742
07743
07744
07745
07746
07747
07748
07749
07750
07751
07752
07753
07754
07755
07756
07757
07758
07759
07760
07761
07762
07763
07764
07765
07766 static tree
07767 build_vtbl_initializer (binfo, orig_binfo, t, rtti_binfo, non_fn_entries_p)
07768 tree binfo;
07769 tree orig_binfo;
07770 tree t;
07771 tree rtti_binfo;
07772 int *non_fn_entries_p;
07773 {
07774 tree v, b;
07775 tree vfun_inits;
07776 tree vbase;
07777 vtbl_init_data vid;
07778
07779
07780 memset (&vid, 0, sizeof (vid));
07781 vid.binfo = binfo;
07782 vid.derived = t;
07783 vid.rtti_binfo = rtti_binfo;
07784 vid.last_init = &vid.inits;
07785 vid.primary_vtbl_p = (binfo == TYPE_BINFO (t));
07786 vid.ctor_vtbl_p = !same_type_p (BINFO_TYPE (rtti_binfo), t);
07787 vid.generate_vcall_entries = true;
07788
07789 vid.index = ssize_int (-3 * TARGET_VTABLE_DATA_ENTRY_DISTANCE);
07790
07791
07792 build_rtti_vtbl_entries (binfo, &vid);
07793
07794
07795
07796
07797 VARRAY_TREE_INIT (vid.fns, 32, "fns");
07798
07799 build_vcall_and_vbase_vtbl_entries (binfo, &vid);
07800
07801
07802 for (vbase = CLASSTYPE_VBASECLASSES (t);
07803 vbase;
07804 vbase = TREE_CHAIN (vbase))
07805 CLEAR_BINFO_VTABLE_PATH_MARKED (TREE_VALUE (vbase));
07806
07807
07808 if (TARGET_VTABLE_DATA_ENTRY_DISTANCE > 1)
07809 {
07810 tree cur, *prev;
07811
07812 for (prev = &vid.inits; (cur = *prev); prev = &TREE_CHAIN (cur))
07813 {
07814 tree add = cur;
07815 int i;
07816
07817 for (i = 1; i < TARGET_VTABLE_DATA_ENTRY_DISTANCE; ++i)
07818 add = tree_cons (NULL_TREE,
07819 build1 (NOP_EXPR, vtable_entry_type,
07820 null_pointer_node),
07821 add);
07822 *prev = add;
07823 }
07824 }
07825
07826 if (non_fn_entries_p)
07827 *non_fn_entries_p = list_length (vid.inits);
07828
07829
07830
07831 vfun_inits = NULL_TREE;
07832 for (v = BINFO_VIRTUALS (orig_binfo); v; v = TREE_CHAIN (v))
07833 {
07834 tree delta;
07835 tree vcall_index;
07836 tree fn;
07837 tree init = NULL_TREE;
07838
07839 fn = BV_FN (v);
07840
07841
07842
07843
07844
07845
07846
07847
07848
07849
07850
07851 for (b = binfo; ; b = get_primary_binfo (b))
07852 {
07853
07854 if (look_for_overrides_here (BINFO_TYPE (b), fn))
07855 break;
07856
07857
07858
07859 if (BINFO_LOST_PRIMARY_P (b))
07860 {
07861 init = size_zero_node;
07862 break;
07863 }
07864 }
07865
07866 if (! init)
07867 {
07868
07869
07870 delta = BV_DELTA (v);
07871 vcall_index = BV_VCALL_INDEX (v);
07872
07873 my_friendly_assert (TREE_CODE (delta) == INTEGER_CST, 19990727);
07874 my_friendly_assert (TREE_CODE (fn) == FUNCTION_DECL, 19990727);
07875
07876
07877
07878 if (DECL_PURE_VIRTUAL_P (fn))
07879 fn = abort_fndecl;
07880 else if (!integer_zerop (delta) || vcall_index)
07881 fn = make_thunk (fn, delta, vcall_index);
07882
07883
07884 init = build1 (ADDR_EXPR, vfunc_ptr_type_node, fn);
07885
07886 TREE_CONSTANT (init) = 1;
07887 }
07888
07889
07890 if (TARGET_VTABLE_USES_DESCRIPTORS)
07891 {
07892 int i;
07893 if (init == size_zero_node)
07894 for (i = 0; i < TARGET_VTABLE_USES_DESCRIPTORS; ++i)
07895 vfun_inits = tree_cons (NULL_TREE, init, vfun_inits);
07896 else
07897 for (i = 0; i < TARGET_VTABLE_USES_DESCRIPTORS; ++i)
07898 {
07899 tree fdesc = build (FDESC_EXPR, vfunc_ptr_type_node,
07900 TREE_OPERAND (init, 0),
07901 build_int_2 (i, 0));
07902 TREE_CONSTANT (fdesc) = 1;
07903
07904 vfun_inits = tree_cons (NULL_TREE, fdesc, vfun_inits);
07905 }
07906 }
07907 else
07908 vfun_inits = tree_cons (NULL_TREE, init, vfun_inits);
07909 }
07910
07911
07912
07913 vfun_inits = nreverse (vfun_inits);
07914
07915
07916 vid.inits = nreverse (vid.inits);
07917
07918
07919 return chainon (vid.inits, vfun_inits);
07920 }
07921
07922
07923
07924
07925 static void
07926 build_vcall_and_vbase_vtbl_entries (binfo, vid)
07927 tree binfo;
07928 vtbl_init_data *vid;
07929 {
07930 tree b;
07931
07932
07933
07934 b = get_primary_binfo (binfo);
07935 if (b)
07936 build_vcall_and_vbase_vtbl_entries (b, vid);
07937
07938
07939 build_vbase_offset_vtbl_entries (binfo, vid);
07940
07941 build_vcall_offset_vtbl_entries (binfo, vid);
07942 }
07943
07944
07945
07946
07947
07948
07949 static void
07950 build_vbase_offset_vtbl_entries (binfo, vid)
07951 tree binfo;
07952 vtbl_init_data *vid;
07953 {
07954 tree vbase;
07955 tree t;
07956 tree non_primary_binfo;
07957
07958
07959
07960 if (!TYPE_USES_VIRTUAL_BASECLASSES (BINFO_TYPE (binfo)))
07961 return;
07962
07963 t = vid->derived;
07964
07965
07966
07967
07968 non_primary_binfo = binfo;
07969 while (BINFO_INHERITANCE_CHAIN (non_primary_binfo))
07970 {
07971 tree b;
07972
07973
07974
07975
07976
07977 if (TREE_VIA_VIRTUAL (non_primary_binfo))
07978 {
07979 non_primary_binfo = vid->binfo;
07980 break;
07981 }
07982
07983 b = BINFO_INHERITANCE_CHAIN (non_primary_binfo);
07984 if (get_primary_binfo (b) != non_primary_binfo)
07985 break;
07986 non_primary_binfo = b;
07987 }
07988
07989
07990 for (vbase = TYPE_BINFO (BINFO_TYPE (binfo));
07991 vbase;
07992 vbase = TREE_CHAIN (vbase))
07993 {
07994 tree b;
07995 tree delta;
07996
07997 if (!TREE_VIA_VIRTUAL (vbase))
07998 continue;
07999
08000
08001
08002 b = binfo_for_vbase (BINFO_TYPE (vbase), t);
08003
08004
08005
08006 if (BINFO_VTABLE_PATH_MARKED (b))
08007 continue;
08008 SET_BINFO_VTABLE_PATH_MARKED (b);
08009
08010
08011 delta = size_binop (MULT_EXPR,
08012 vid->index,
08013 convert (ssizetype,
08014 TYPE_SIZE_UNIT (vtable_entry_type)));
08015 if (vid->primary_vtbl_p)
08016 BINFO_VPTR_FIELD (b) = delta;
08017
08018 if (binfo != TYPE_BINFO (t))
08019 {
08020 tree orig_vbase;
08021
08022
08023 orig_vbase = binfo_for_vbase (BINFO_TYPE (vbase),
08024 BINFO_TYPE (binfo));
08025
08026
08027 if (!tree_int_cst_equal (delta,
08028 BINFO_VPTR_FIELD (orig_vbase)))
08029 abort ();
08030 }
08031
08032
08033 vid->index = size_binop (MINUS_EXPR, vid->index,
08034 ssize_int (TARGET_VTABLE_DATA_ENTRY_DISTANCE));
08035
08036
08037
08038
08039
08040 delta = size_diffop (BINFO_OFFSET (b), BINFO_OFFSET (non_primary_binfo));
08041
08042 *vid->last_init
08043 = build_tree_list (NULL_TREE,
08044 fold (build1 (NOP_EXPR,
08045 vtable_entry_type,
08046 delta)));
08047 vid->last_init = &TREE_CHAIN (*vid->last_init);
08048 }
08049 }
08050
08051
08052
08053
08054
08055 static void
08056 build_vcall_offset_vtbl_entries (binfo, vid)
08057 tree binfo;
08058 vtbl_init_data *vid;
08059 {
08060
08061
08062
08063 if (TREE_VIA_VIRTUAL (binfo) || binfo == TYPE_BINFO (vid->derived))
08064 {
08065
08066
08067
08068
08069
08070
08071
08072
08073
08074
08075
08076
08077
08078
08079
08080
08081
08082
08083 vid->vbase = binfo;
08084
08085
08086 if (!TREE_VIA_VIRTUAL (binfo))
08087 vid->generate_vcall_entries = false;
08088
08089 add_vcall_offset_vtbl_entries_r (binfo, vid);
08090 }
08091 }
08092
08093
08094
08095 static void
08096 add_vcall_offset_vtbl_entries_r (binfo, vid)
08097 tree binfo;
08098 vtbl_init_data *vid;
08099 {
08100 int i;
08101 tree primary_binfo;
08102
08103
08104
08105
08106
08107 if (TREE_VIA_VIRTUAL (binfo) && vid->vbase != binfo)
08108 return;
08109
08110
08111 primary_binfo = get_primary_binfo (binfo);
08112 if (primary_binfo)
08113 add_vcall_offset_vtbl_entries_r (primary_binfo, vid);
08114
08115
08116 add_vcall_offset_vtbl_entries_1 (binfo, vid);
08117
08118
08119 for (i = 0; i < BINFO_N_BASETYPES (binfo); ++i)
08120 {
08121 tree base_binfo;
08122
08123 base_binfo = BINFO_BASETYPE (binfo, i);
08124 if (base_binfo != primary_binfo)
08125 add_vcall_offset_vtbl_entries_r (base_binfo, vid);
08126 }
08127 }
08128
08129
08130
08131 static void
08132 add_vcall_offset_vtbl_entries_1 (binfo, vid)
08133 tree binfo;
08134 vtbl_init_data* vid;
08135 {
08136
08137 if (abi_version_at_least (2))
08138 {
08139 tree orig_fn;
08140
08141
08142
08143 for (orig_fn = TYPE_METHODS (BINFO_TYPE (binfo));
08144 orig_fn;
08145 orig_fn = TREE_CHAIN (orig_fn))
08146 if (DECL_VINDEX (orig_fn))
08147 add_vcall_offset (orig_fn, binfo, vid);
08148 }
08149 else
08150 {
08151 tree derived_virtuals;
08152 tree base_virtuals;
08153 tree orig_virtuals;
08154
08155
08156 tree non_primary_binfo;
08157
08158
08159
08160
08161 non_primary_binfo = binfo;
08162 while (BINFO_INHERITANCE_CHAIN (non_primary_binfo))
08163 {
08164 tree b;
08165
08166
08167
08168
08169
08170
08171
08172 if (TREE_VIA_VIRTUAL (non_primary_binfo))
08173 {
08174 if (non_primary_binfo != vid->vbase)
08175 abort ();