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 #include "config.h"
00027 #include "system.h"
00028 #include "tree.h"
00029 #include "cp-tree.h"
00030 #include "obstack.h"
00031 #include "flags.h"
00032 #include "rtl.h"
00033 #include "output.h"
00034 #include "ggc.h"
00035 #include "toplev.h"
00036 #include "stack.h"
00037
00038
00039
00040 static struct obstack search_obstack;
00041
00042
00043
00044 struct stack_level *
00045 push_stack_level (obstack, tp, size)
00046 struct obstack *obstack;
00047 char *tp;
00048 int size;
00049 {
00050 struct stack_level *stack;
00051 obstack_grow (obstack, tp, size);
00052 stack = (struct stack_level *) ((char*)obstack_next_free (obstack) - size);
00053 obstack_finish (obstack);
00054 stack->obstack = obstack;
00055 stack->first = (tree *) obstack_base (obstack);
00056 stack->limit = obstack_room (obstack) / sizeof (tree *);
00057 return stack;
00058 }
00059
00060 struct stack_level *
00061 pop_stack_level (stack)
00062 struct stack_level *stack;
00063 {
00064 struct stack_level *tem = stack;
00065 struct obstack *obstack = tem->obstack;
00066 stack = tem->prev;
00067 obstack_free (obstack, tem);
00068 return stack;
00069 }
00070
00071 #define search_level stack_level
00072 static struct search_level *search_stack;
00073
00074 struct vbase_info
00075 {
00076
00077 tree type;
00078
00079 tree decl_ptr;
00080 tree inits;
00081 };
00082
00083 static int is_subobject_of_p PARAMS ((tree, tree, tree));
00084 static int is_subobject_of_p_1 PARAMS ((tree, tree, tree));
00085 static tree dfs_check_overlap PARAMS ((tree, void *));
00086 static tree dfs_no_overlap_yet PARAMS ((tree, void *));
00087 static base_kind lookup_base_r
00088 PARAMS ((tree, tree, base_access, int, tree *));
00089 static int dynamic_cast_base_recurse PARAMS ((tree, tree, int, tree *));
00090 static tree marked_pushdecls_p PARAMS ((tree, void *));
00091 static tree unmarked_pushdecls_p PARAMS ((tree, void *));
00092 static tree dfs_debug_unmarkedp PARAMS ((tree, void *));
00093 static tree dfs_debug_mark PARAMS ((tree, void *));
00094 static tree dfs_get_vbase_types PARAMS ((tree, void *));
00095 static tree dfs_push_type_decls PARAMS ((tree, void *));
00096 static tree dfs_push_decls PARAMS ((tree, void *));
00097 static tree dfs_unuse_fields PARAMS ((tree, void *));
00098 static tree add_conversions PARAMS ((tree, void *));
00099 static int covariant_return_p PARAMS ((tree, tree));
00100 static int look_for_overrides_r PARAMS ((tree, tree));
00101 static struct search_level *push_search_level
00102 PARAMS ((struct stack_level *, struct obstack *));
00103 static struct search_level *pop_search_level
00104 PARAMS ((struct stack_level *));
00105 static tree bfs_walk
00106 PARAMS ((tree, tree (*) (tree, void *), tree (*) (tree, void *),
00107 void *));
00108 static tree lookup_field_queue_p PARAMS ((tree, void *));
00109 static int shared_member_p PARAMS ((tree));
00110 static tree lookup_field_r PARAMS ((tree, void *));
00111 static tree canonical_binfo PARAMS ((tree));
00112 static tree shared_marked_p PARAMS ((tree, void *));
00113 static tree shared_unmarked_p PARAMS ((tree, void *));
00114 static int dependent_base_p PARAMS ((tree));
00115 static tree dfs_accessible_queue_p PARAMS ((tree, void *));
00116 static tree dfs_accessible_p PARAMS ((tree, void *));
00117 static tree dfs_access_in_type PARAMS ((tree, void *));
00118 static access_kind access_in_type PARAMS ((tree, tree));
00119 static tree dfs_canonical_queue PARAMS ((tree, void *));
00120 static tree dfs_assert_unmarked_p PARAMS ((tree, void *));
00121 static void assert_canonical_unmarked PARAMS ((tree));
00122 static int protected_accessible_p PARAMS ((tree, tree, tree));
00123 static int friend_accessible_p PARAMS ((tree, tree, tree));
00124 static void setup_class_bindings PARAMS ((tree, int));
00125 static int template_self_reference_p PARAMS ((tree, tree));
00126 static tree dfs_find_vbase_instance PARAMS ((tree, void *));
00127 static tree dfs_get_pure_virtuals PARAMS ((tree, void *));
00128 static tree dfs_build_inheritance_graph_order PARAMS ((tree, void *));
00129
00130
00131
00132 static struct search_level *
00133 push_search_level (stack, obstack)
00134 struct stack_level *stack;
00135 struct obstack *obstack;
00136 {
00137 struct search_level tem;
00138
00139 tem.prev = stack;
00140 return push_stack_level (obstack, (char *)&tem, sizeof (tem));
00141 }
00142
00143
00144
00145 static struct search_level *
00146 pop_search_level (obstack)
00147 struct stack_level *obstack;
00148 {
00149 register struct search_level *stack = pop_stack_level (obstack);
00150
00151 return stack;
00152 }
00153
00154
00155 #ifdef GATHER_STATISTICS
00156 static int n_fields_searched;
00157 static int n_calls_lookup_field, n_calls_lookup_field_1;
00158 static int n_calls_lookup_fnfields, n_calls_lookup_fnfields_1;
00159 static int n_calls_get_base_type;
00160 static int n_outer_fields_searched;
00161 static int n_contexts_saved;
00162 #endif
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177 static base_kind
00178 lookup_base_r (binfo, base, access, is_virtual, binfo_ptr)
00179 tree binfo, base;
00180 base_access access;
00181 int is_virtual;
00182 tree *binfo_ptr;
00183 {
00184 int i;
00185 tree bases;
00186 base_kind found = bk_not_base;
00187
00188 if (same_type_p (BINFO_TYPE (binfo), base))
00189 {
00190
00191
00192 found = bk_same_type;
00193 if (is_virtual)
00194 found = bk_via_virtual;
00195
00196 if (!*binfo_ptr)
00197 *binfo_ptr = binfo;
00198 else if (!is_virtual || !tree_int_cst_equal (BINFO_OFFSET (binfo),
00199 BINFO_OFFSET (*binfo_ptr)))
00200 {
00201 if (access != ba_any)
00202 *binfo_ptr = NULL;
00203 else if (!is_virtual)
00204
00205 *binfo_ptr = binfo;
00206 found = bk_ambig;
00207 }
00208
00209 return found;
00210 }
00211
00212 bases = BINFO_BASETYPES (binfo);
00213 if (!bases)
00214 return bk_not_base;
00215
00216 for (i = TREE_VEC_LENGTH (bases); i--;)
00217 {
00218 tree base_binfo = TREE_VEC_ELT (bases, i);
00219 base_kind bk;
00220
00221 bk = lookup_base_r (base_binfo, base,
00222 access,
00223 is_virtual || TREE_VIA_VIRTUAL (base_binfo),
00224 binfo_ptr);
00225
00226 switch (bk)
00227 {
00228 case bk_ambig:
00229 if (access != ba_any)
00230 return bk;
00231 found = bk;
00232 break;
00233
00234 case bk_same_type:
00235 bk = bk_proper_base;
00236
00237 case bk_proper_base:
00238 my_friendly_assert (found == bk_not_base, 20010723);
00239 found = bk;
00240 break;
00241
00242 case bk_via_virtual:
00243 if (found != bk_ambig)
00244 found = bk;
00245 break;
00246
00247 case bk_not_base:
00248 break;
00249
00250 default:
00251 abort ();
00252 }
00253 }
00254 return found;
00255 }
00256
00257
00258
00259
00260 bool
00261 accessible_base_p (tree t, tree base)
00262 {
00263 tree decl;
00264
00265
00266
00267
00268
00269
00270
00271 decl = TYPE_FIELDS (base);
00272 while (!DECL_SELF_REFERENCE_P (decl))
00273 decl = TREE_CHAIN (decl);
00274 while (ANON_AGGR_TYPE_P (t))
00275 t = TYPE_CONTEXT (t);
00276 return accessible_p (t, decl);
00277 }
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289 tree
00290 lookup_base (t, base, access, kind_ptr)
00291 tree t, base;
00292 base_access access;
00293 base_kind *kind_ptr;
00294 {
00295 tree binfo = NULL;
00296 tree t_binfo = NULL;
00297 base_kind bk;
00298
00299 if (t == error_mark_node || base == error_mark_node)
00300 {
00301 if (kind_ptr)
00302 *kind_ptr = bk_not_base;
00303 return error_mark_node;
00304 }
00305 my_friendly_assert (TYPE_P (base), 20011127);
00306
00307 if (!TYPE_P (t))
00308 {
00309 t_binfo = t;
00310 t = BINFO_TYPE (t);
00311 }
00312 else
00313 t_binfo = TYPE_BINFO (t);
00314
00315
00316 t = complete_type (TYPE_MAIN_VARIANT (t));
00317 base = complete_type (TYPE_MAIN_VARIANT (base));
00318
00319 bk = lookup_base_r (t_binfo, base, access, 0, &binfo);
00320
00321
00322 if (access != ba_any)
00323 switch (bk)
00324 {
00325 case bk_not_base:
00326 break;
00327
00328 case bk_ambig:
00329 binfo = NULL_TREE;
00330 if (!(access & ba_quiet))
00331 {
00332 error ("`%T' is an ambiguous base of `%T'", base, t);
00333 binfo = error_mark_node;
00334 }
00335 break;
00336
00337 default:
00338 if ((access & ~ba_quiet) != ba_ignore
00339
00340
00341
00342
00343
00344
00345 && COMPLETE_TYPE_P (base)
00346 && !accessible_base_p (t, base))
00347 {
00348 if (!(access & ba_quiet))
00349 {
00350 error ("`%T' is an inaccessible base of `%T'", base, t);
00351 binfo = error_mark_node;
00352 }
00353 else
00354 binfo = NULL_TREE;
00355 bk = bk_inaccessible;
00356 }
00357 break;
00358 }
00359
00360 if (kind_ptr)
00361 *kind_ptr = bk;
00362
00363 return binfo;
00364 }
00365
00366
00367
00368 static int
00369 dynamic_cast_base_recurse (subtype, binfo, via_virtual, offset_ptr)
00370 tree subtype;
00371 tree binfo;
00372 int via_virtual;
00373 tree *offset_ptr;
00374 {
00375 tree binfos;
00376 int i, n_baselinks;
00377 int worst = -2;
00378
00379 if (BINFO_TYPE (binfo) == subtype)
00380 {
00381 if (via_virtual)
00382 return -1;
00383 else
00384 {
00385 *offset_ptr = BINFO_OFFSET (binfo);
00386 return 0;
00387 }
00388 }
00389
00390 binfos = BINFO_BASETYPES (binfo);
00391 n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
00392 for (i = 0; i < n_baselinks; i++)
00393 {
00394 tree base_binfo = TREE_VEC_ELT (binfos, i);
00395 int rval;
00396
00397 if (!TREE_VIA_PUBLIC (base_binfo))
00398 continue;
00399 rval = dynamic_cast_base_recurse
00400 (subtype, base_binfo,
00401 via_virtual || TREE_VIA_VIRTUAL (base_binfo), offset_ptr);
00402 if (worst == -2)
00403 worst = rval;
00404 else if (rval >= 0)
00405 worst = worst >= 0 ? -3 : worst;
00406 else if (rval == -1)
00407 worst = -1;
00408 else if (rval == -3 && worst != -1)
00409 worst = -3;
00410 }
00411 return worst;
00412 }
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425 tree
00426 get_dynamic_cast_base_type (subtype, target)
00427 tree subtype;
00428 tree target;
00429 {
00430 tree offset = NULL_TREE;
00431 int boff = dynamic_cast_base_recurse (subtype, TYPE_BINFO (target),
00432 0, &offset);
00433
00434 if (!boff)
00435 return offset;
00436 offset = build_int_2 (boff, -1);
00437 TREE_TYPE (offset) = ssizetype;
00438 return offset;
00439 }
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450 tree
00451 lookup_field_1 (tree type, tree name, bool want_type)
00452 {
00453 register tree field;
00454
00455 if (TREE_CODE (type) == TEMPLATE_TYPE_PARM
00456 || TREE_CODE (type) == BOUND_TEMPLATE_TEMPLATE_PARM
00457 || TREE_CODE (type) == TYPENAME_TYPE)
00458
00459
00460
00461
00462
00463
00464 return NULL_TREE;
00465
00466 if (TYPE_NAME (type)
00467 && DECL_LANG_SPECIFIC (TYPE_NAME (type))
00468 && DECL_SORTED_FIELDS (TYPE_NAME (type)))
00469 {
00470 tree *fields = &TREE_VEC_ELT (DECL_SORTED_FIELDS (TYPE_NAME (type)), 0);
00471 int lo = 0, hi = TREE_VEC_LENGTH (DECL_SORTED_FIELDS (TYPE_NAME (type)));
00472 int i;
00473
00474 while (lo < hi)
00475 {
00476 i = (lo + hi) / 2;
00477
00478 #ifdef GATHER_STATISTICS
00479 n_fields_searched++;
00480 #endif
00481
00482 if (DECL_NAME (fields[i]) > name)
00483 hi = i;
00484 else if (DECL_NAME (fields[i]) < name)
00485 lo = i + 1;
00486 else
00487 {
00488 field = NULL_TREE;
00489
00490
00491
00492
00493
00494 if (want_type)
00495 {
00496 do
00497 field = fields[i--];
00498 while (i >= lo && DECL_NAME (fields[i]) == name);
00499 if (TREE_CODE (field) != TYPE_DECL
00500 && !DECL_CLASS_TEMPLATE_P (field))
00501 field = NULL_TREE;
00502 }
00503 else
00504 {
00505 do
00506 field = fields[i++];
00507 while (i < hi && DECL_NAME (fields[i]) == name);
00508 }
00509 return field;
00510 }
00511 }
00512 return NULL_TREE;
00513 }
00514
00515 field = TYPE_FIELDS (type);
00516
00517 #ifdef GATHER_STATISTICS
00518 n_calls_lookup_field_1++;
00519 #endif
00520 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
00521 {
00522 #ifdef GATHER_STATISTICS
00523 n_fields_searched++;
00524 #endif
00525 my_friendly_assert (DECL_P (field), 0);
00526 if (DECL_NAME (field) == NULL_TREE
00527 && ANON_AGGR_TYPE_P (TREE_TYPE (field)))
00528 {
00529 tree temp = lookup_field_1 (TREE_TYPE (field), name, want_type);
00530 if (temp)
00531 return temp;
00532 }
00533 if (TREE_CODE (field) == USING_DECL)
00534
00535
00536
00537
00538
00539 continue;
00540
00541 if (DECL_NAME (field) == name
00542 && (!want_type
00543 || TREE_CODE (field) == TYPE_DECL
00544 || DECL_CLASS_TEMPLATE_P (field)))
00545 return field;
00546 }
00547
00548 if (name == vptr_identifier)
00549 {
00550
00551 if (TYPE_POLYMORPHIC_P (type))
00552 return TYPE_VFIELD (type);
00553 }
00554 return NULL_TREE;
00555 }
00556
00557
00558
00559
00560
00561
00562
00563
00564
00565
00566
00567
00568
00569
00570
00571
00572
00573 tree
00574 current_scope ()
00575 {
00576 if (current_function_decl == NULL_TREE)
00577 return current_class_type;
00578 if (current_class_type == NULL_TREE)
00579 return current_function_decl;
00580 if ((DECL_FUNCTION_MEMBER_P (current_function_decl)
00581 && same_type_p (DECL_CONTEXT (current_function_decl),
00582 current_class_type))
00583 || (DECL_FRIEND_CONTEXT (current_function_decl)
00584 && same_type_p (DECL_FRIEND_CONTEXT (current_function_decl),
00585 current_class_type)))
00586 return current_function_decl;
00587
00588 return current_class_type;
00589 }
00590
00591
00592
00593
00594
00595 int
00596 at_function_scope_p ()
00597 {
00598 tree cs = current_scope ();
00599 return cs && TREE_CODE (cs) == FUNCTION_DECL;
00600 }
00601
00602
00603
00604 bool
00605 at_class_scope_p ()
00606 {
00607 tree cs = current_scope ();
00608 return cs && TYPE_P (cs);
00609 }
00610
00611
00612
00613 tree
00614 context_for_name_lookup (decl)
00615 tree decl;
00616 {
00617
00618
00619
00620
00621
00622
00623 tree context = DECL_CONTEXT (decl);
00624
00625 while (context && TYPE_P (context) && ANON_AGGR_TYPE_P (context))
00626 context = TYPE_CONTEXT (context);
00627 if (!context)
00628 context = global_namespace;
00629
00630 return context;
00631 }
00632
00633
00634
00635
00636 static tree
00637 canonical_binfo (binfo)
00638 tree binfo;
00639 {
00640 return (TREE_VIA_VIRTUAL (binfo)
00641 ? TYPE_BINFO (BINFO_TYPE (binfo)) : binfo);
00642 }
00643
00644
00645
00646
00647 static tree
00648 dfs_canonical_queue (binfo, data)
00649 tree binfo;
00650 void *data ATTRIBUTE_UNUSED;
00651 {
00652 return canonical_binfo (binfo);
00653 }
00654
00655
00656
00657 static tree
00658 dfs_assert_unmarked_p (binfo, data)
00659 tree binfo;
00660 void *data ATTRIBUTE_UNUSED;
00661 {
00662 my_friendly_assert (!BINFO_MARKED (binfo), 0);
00663 return NULL_TREE;
00664 }
00665
00666
00667
00668
00669 static void
00670 assert_canonical_unmarked (binfo)
00671 tree binfo;
00672 {
00673 dfs_walk (binfo, dfs_assert_unmarked_p, dfs_canonical_queue, 0);
00674 }
00675
00676
00677
00678
00679 static tree
00680 shared_marked_p (binfo, data)
00681 tree binfo;
00682 void *data;
00683 {
00684 binfo = canonical_binfo (binfo);
00685 return markedp (binfo, data);
00686 }
00687
00688
00689
00690
00691 static tree
00692 shared_unmarked_p (binfo, data)
00693 tree binfo;
00694 void *data;
00695 {
00696 binfo = canonical_binfo (binfo);
00697 return unmarkedp (binfo, data);
00698 }
00699
00700
00701
00702
00703 #define BINFO_ACCESS(NODE) \
00704 ((access_kind) ((TREE_LANG_FLAG_1 (NODE) << 1) | TREE_LANG_FLAG_6 (NODE)))
00705
00706
00707
00708 #define SET_BINFO_ACCESS(NODE, ACCESS) \
00709 ((TREE_LANG_FLAG_1 (NODE) = ((ACCESS) & 2) != 0), \
00710 (TREE_LANG_FLAG_6 (NODE) = ((ACCESS) & 1) != 0))
00711
00712
00713
00714
00715 static tree
00716 dfs_access_in_type (binfo, data)
00717 tree binfo;
00718 void *data;
00719 {
00720 tree decl = (tree) data;
00721 tree type = BINFO_TYPE (binfo);
00722 access_kind access = ak_none;
00723
00724 if (context_for_name_lookup (decl) == type)
00725 {
00726
00727
00728 if (TREE_PRIVATE (decl))
00729 access = ak_private;
00730 else if (TREE_PROTECTED (decl))
00731 access = ak_protected;
00732 else
00733 access = ak_public;
00734 }
00735 else
00736 {
00737
00738
00739
00740
00741 if (DECL_LANG_SPECIFIC (decl) && !DECL_DISCRIMINATOR_P (decl))
00742 {
00743 tree decl_access = purpose_member (type, DECL_ACCESS (decl));
00744 if (decl_access)
00745 access = ((access_kind)
00746 TREE_INT_CST_LOW (TREE_VALUE (decl_access)));
00747 }
00748
00749 if (!access)
00750 {
00751 int i;
00752 int n_baselinks;
00753 tree binfos;
00754
00755
00756
00757 binfos = BINFO_BASETYPES (binfo);
00758 n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
00759 for (i = 0; i < n_baselinks; ++i)
00760 {
00761 tree base_binfo = TREE_VEC_ELT (binfos, i);
00762 access_kind base_access
00763 = BINFO_ACCESS (canonical_binfo (base_binfo));
00764
00765 if (base_access == ak_none || base_access == ak_private)
00766
00767
00768
00769 base_access = ak_none;
00770 else if (TREE_VIA_PROTECTED (base_binfo))
00771
00772
00773 base_access = ak_protected;
00774 else if (!TREE_VIA_PUBLIC (base_binfo))
00775
00776
00777 base_access = ak_private;
00778
00779
00780
00781 if (base_access != ak_none
00782 && (base_access == ak_public
00783 || (base_access == ak_protected
00784 && access != ak_public)
00785 || (base_access == ak_private
00786 && access == ak_none)))
00787 {
00788 access = base_access;
00789
00790
00791 if (access == ak_public)
00792 break;
00793 }
00794 }
00795 }
00796 }
00797
00798
00799 SET_BINFO_ACCESS (binfo, access);
00800
00801
00802
00803 SET_BINFO_MARKED (binfo);
00804
00805 return NULL_TREE;
00806 }
00807
00808
00809
00810 static access_kind
00811 access_in_type (type, decl)
00812 tree type;
00813 tree decl;
00814 {
00815 tree binfo = TYPE_BINFO (type);
00816
00817
00818
00819
00820
00821
00822
00823
00824
00825
00826
00827
00828 dfs_walk_real (binfo, 0, dfs_access_in_type, shared_unmarked_p, decl);
00829 dfs_walk (binfo, dfs_unmark, shared_marked_p, 0);
00830 assert_canonical_unmarked (binfo);
00831
00832 return BINFO_ACCESS (binfo);
00833 }
00834
00835
00836
00837 static tree
00838 dfs_accessible_queue_p (binfo, data)
00839 tree binfo;
00840 void *data ATTRIBUTE_UNUSED;
00841 {
00842 if (BINFO_MARKED (binfo))
00843 return NULL_TREE;
00844
00845
00846
00847 if (!TREE_VIA_PUBLIC (binfo)
00848 && !is_friend (BINFO_TYPE (BINFO_INHERITANCE_CHAIN (binfo)),
00849 current_scope ()))
00850 return NULL_TREE;
00851
00852 return canonical_binfo (binfo);
00853 }
00854
00855
00856
00857 static tree
00858 dfs_accessible_p (binfo, data)
00859 tree binfo;
00860 void *data;
00861 {
00862 int protected_ok = data != 0;
00863 access_kind access;
00864
00865 SET_BINFO_MARKED (binfo);
00866 access = BINFO_ACCESS (binfo);
00867 if (access == ak_public || (access == ak_protected && protected_ok))
00868 return binfo;
00869 else if (access != ak_none
00870 && is_friend (BINFO_TYPE (binfo), current_scope ()))
00871 return binfo;
00872
00873 return NULL_TREE;
00874 }
00875
00876
00877
00878
00879 static int
00880 protected_accessible_p (decl, derived, binfo)
00881 tree decl;
00882 tree derived;
00883 tree binfo;
00884 {
00885 access_kind access;
00886
00887
00888
00889
00890
00891
00892
00893
00894
00895
00896
00897
00898
00899
00900
00901
00902
00903
00904 if (!DERIVED_FROM_P (context_for_name_lookup (decl), derived))
00905 return 0;
00906
00907 access = access_in_type (derived, decl);
00908
00909
00910 if (access == ak_none)
00911 return 0;
00912
00913
00914
00915
00916
00917
00918
00919
00920
00921
00922
00923
00924 if (DECL_NONSTATIC_MEMBER_P (decl))
00925 {
00926
00927
00928 tree t = binfo;
00929 while (BINFO_INHERITANCE_CHAIN (t))
00930 t = BINFO_INHERITANCE_CHAIN (t);
00931
00932 if (!DERIVED_FROM_P (derived, BINFO_TYPE (t)))
00933 return 0;
00934 }
00935
00936 return 1;
00937 }
00938
00939
00940
00941
00942 static int
00943 friend_accessible_p (scope, decl, binfo)
00944 tree scope;
00945 tree decl;
00946 tree binfo;
00947 {
00948 tree befriending_classes;
00949 tree t;
00950
00951 if (!scope)
00952 return 0;
00953
00954 if (TREE_CODE (scope) == FUNCTION_DECL
00955 || DECL_FUNCTION_TEMPLATE_P (scope))
00956 befriending_classes = DECL_BEFRIENDING_CLASSES (scope);
00957 else if (TYPE_P (scope))
00958 befriending_classes = CLASSTYPE_BEFRIENDING_CLASSES (scope);
00959 else
00960 return 0;
00961
00962 for (t = befriending_classes; t; t = TREE_CHAIN (t))
00963 if (protected_accessible_p (decl, TREE_VALUE (t), binfo))
00964 return 1;
00965
00966
00967
00968 if (TYPE_P (scope))
00969 for (t = TYPE_CONTEXT (scope); t && TYPE_P (t); t = TYPE_CONTEXT (t))
00970 if (protected_accessible_p (decl, t, binfo))
00971 return 1;
00972
00973 if (TREE_CODE (scope) == FUNCTION_DECL
00974 || DECL_FUNCTION_TEMPLATE_P (scope))
00975 {
00976
00977
00978 if (DECL_CLASS_SCOPE_P (decl)
00979 && friend_accessible_p (DECL_CONTEXT (scope), decl, binfo))
00980 return 1;
00981
00982
00983 if (DECL_TEMPLATE_INFO (scope))
00984 return friend_accessible_p (DECL_TI_TEMPLATE (scope), decl, binfo);
00985 }
00986 else if (CLASSTYPE_TEMPLATE_INFO (scope))
00987 return friend_accessible_p (CLASSTYPE_TI_TEMPLATE (scope), decl, binfo);
00988
00989 return 0;
00990 }
00991
00992
00993
00994
00995
00996
00997
00998
00999
01000
01001
01002
01003
01004
01005
01006
01007
01008
01009
01010
01011
01012 void
01013 type_access_control (type, val)
01014 tree type, val;
01015 {
01016 if (val == NULL_TREE
01017 || (TREE_CODE (val) != TEMPLATE_DECL && TREE_CODE (val) != TYPE_DECL)
01018 || ! DECL_CLASS_SCOPE_P (val))
01019 return;
01020
01021 if (type_lookups == error_mark_node)
01022 enforce_access (type, val);
01023 else if (! accessible_p (type, val))
01024 type_lookups = tree_cons (type, val, type_lookups);
01025 }
01026
01027
01028
01029
01030
01031
01032
01033 int
01034 accessible_p (type, decl)
01035 tree type;
01036 tree decl;
01037
01038 {
01039 tree binfo;
01040 tree t;
01041
01042
01043
01044 int protected_ok = 0;
01045
01046
01047 if (!flag_access_control)
01048 return 1;
01049
01050
01051
01052 if (!TYPE_P (context_for_name_lookup (decl)))
01053 return 1;
01054
01055 if (!TYPE_P (type))
01056 {
01057 binfo = type;
01058 type = BINFO_TYPE (type);
01059 }
01060 else
01061 binfo = TYPE_BINFO (type);
01062
01063
01064
01065
01066
01067
01068
01069
01070
01071
01072
01073
01074
01075
01076
01077
01078
01079
01080
01081
01082
01083
01084
01085 if (current_class_type)
01086 protected_ok = protected_accessible_p (decl, current_class_type, binfo);
01087
01088
01089 if (!protected_ok)
01090 protected_ok = friend_accessible_p (current_scope (), decl, binfo);
01091
01092
01093
01094 binfo = TYPE_BINFO (type);
01095
01096
01097
01098 access_in_type (type, decl);
01099
01100
01101 t = dfs_walk (binfo, dfs_accessible_p,
01102 dfs_accessible_queue_p,
01103 protected_ok ? &protected_ok : 0);
01104
01105
01106
01107 dfs_walk (binfo, dfs_unmark, dfs_canonical_queue, 0);
01108 assert_canonical_unmarked (binfo);
01109
01110 return t != NULL_TREE;
01111 }
01112
01113
01114
01115
01116 static int
01117 is_subobject_of_p_1 (parent, binfo, most_derived)
01118 tree parent, binfo, most_derived;
01119 {
01120 tree binfos;
01121 int i, n_baselinks;
01122
01123 if (parent == binfo)
01124 return 1;
01125
01126 binfos = BINFO_BASETYPES (binfo);
01127 n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
01128
01129
01130 for (i = 0; i < n_baselinks; i++)
01131 {
01132 tree base_binfo = TREE_VEC_ELT (binfos, i);
01133 tree base_type;
01134
01135 base_type = TREE_TYPE (base_binfo);
01136 if (!CLASS_TYPE_P (base_type))
01137
01138
01139 continue;
01140
01141
01142 if (TREE_VIA_VIRTUAL (base_binfo))
01143 {
01144 if (CLASSTYPE_MARKED4 (base_type))
01145 continue;
01146 SET_CLASSTYPE_MARKED4 (base_type);
01147 base_binfo = binfo_for_vbase (base_type, most_derived);
01148 }
01149
01150 if (is_subobject_of_p_1 (parent, base_binfo, most_derived))
01151 return 1;
01152 }
01153 return 0;
01154 }
01155
01156
01157
01158
01159
01160
01161 static int
01162 is_subobject_of_p (tree parent, tree binfo, tree most_derived)
01163 {
01164 int result;
01165 tree vbase;
01166
01167 result = is_subobject_of_p_1 (parent, binfo, most_derived);
01168
01169 for (vbase = CLASSTYPE_VBASECLASSES (most_derived);
01170 vbase;
01171 vbase = TREE_CHAIN (vbase))
01172 CLEAR_CLASSTYPE_MARKED4 (TREE_TYPE (TREE_VALUE (vbase)));
01173
01174 return result;
01175 }
01176
01177 struct lookup_field_info {
01178
01179 tree type;
01180
01181 tree name;
01182
01183 tree rval;
01184
01185 tree rval_binfo;
01186
01187
01188 tree ambiguous;
01189
01190 int want_type;
01191
01192 int from_dep_base_p;
01193
01194 const char *errstr;
01195 };
01196
01197
01198
01199
01200
01201
01202 static tree
01203 lookup_field_queue_p (binfo, data)
01204 tree binfo;
01205 void *data;
01206 {
01207 struct lookup_field_info *lfi = (struct lookup_field_info *) data;
01208
01209
01210 if (IDENTIFIER_CTOR_OR_DTOR_P (lfi->name))
01211 return NULL_TREE;
01212
01213
01214
01215 binfo = CANONICAL_BINFO (binfo, lfi->type);
01216 if (!lfi->from_dep_base_p && lfi->rval_binfo
01217 && is_subobject_of_p (binfo, lfi->rval_binfo, lfi->type))
01218 return NULL_TREE;
01219
01220 return binfo;
01221 }
01222
01223
01224
01225
01226
01227
01228
01229
01230
01231 static int
01232 template_self_reference_p (type, decl)
01233 tree type;
01234 tree decl;
01235 {
01236 return (CLASSTYPE_USE_TEMPLATE (type)
01237 && PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (type))
01238 && TREE_CODE (decl) == TYPE_DECL
01239 && DECL_ARTIFICIAL (decl)
01240 && DECL_NAME (decl) == constructor_name (type));
01241 }
01242
01243
01244
01245
01246
01247
01248
01249
01250
01251
01252
01253
01254 static int
01255 shared_member_p (t)
01256 tree t;
01257 {
01258 if (TREE_CODE (t) == VAR_DECL || TREE_CODE (t) == TYPE_DECL \
01259 || TREE_CODE (t) == CONST_DECL)
01260 return 1;
01261 if (is_overloaded_fn (t))
01262 {
01263 for (; t; t = OVL_NEXT (t))
01264 {
01265 tree fn = OVL_CURRENT (t);
01266 if (DECL_NONSTATIC_MEMBER_FUNCTION_P (fn))
01267 return 0;
01268 }
01269 return 1;
01270 }
01271 return 0;
01272 }
01273
01274
01275
01276
01277
01278
01279 static tree
01280 lookup_field_r (binfo, data)
01281 tree binfo;
01282 void *data;
01283 {
01284 struct lookup_field_info *lfi = (struct lookup_field_info *) data;
01285 tree type = BINFO_TYPE (binfo);
01286 tree nval = NULL_TREE;
01287 int from_dep_base_p;
01288
01289
01290
01291
01292 if (!lfi->want_type)
01293 {
01294 int idx = lookup_fnfields_1 (type, lfi->name);
01295 if (idx >= 0)
01296 nval = TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type), idx);
01297 }
01298
01299 if (!nval)
01300
01301 nval = lookup_field_1 (type, lfi->name, lfi->want_type);
01302
01303
01304
01305 if (!nval)
01306 return NULL_TREE;
01307
01308
01309
01310 if (lfi->want_type && TREE_CODE (nval) != TYPE_DECL
01311 && !DECL_CLASS_TEMPLATE_P (nval))
01312 {
01313 if (lfi->name == TYPE_IDENTIFIER (type))
01314 {
01315
01316
01317
01318
01319 for (nval = TREE_CHAIN (nval); nval; nval = TREE_CHAIN (nval))
01320 if (DECL_NAME (nval) == lfi->name
01321 && TREE_CODE (nval) == TYPE_DECL)
01322 break;
01323 }
01324 else
01325 nval = NULL_TREE;
01326 if (!nval && CLASSTYPE_NESTED_UDTS (type) != NULL)
01327 {
01328 binding_entry e = binding_table_find (CLASSTYPE_NESTED_UDTS (type),
01329 lfi->name);
01330 if (e != NULL)
01331 nval = TYPE_MAIN_DECL (e->type);
01332 else
01333 return NULL_TREE;
01334 }
01335 }
01336
01337
01338 if (!same_type_p (type, lfi->type)
01339 && template_self_reference_p (type, nval))
01340 return NULL_TREE;
01341
01342 from_dep_base_p = dependent_base_p (binfo);
01343 if (lfi->from_dep_base_p && !from_dep_base_p)
01344 {
01345
01346
01347
01348
01349
01350
01351
01352
01353
01354
01355
01356
01357 lfi->from_dep_base_p = 0;
01358 lfi->rval = NULL_TREE;
01359 lfi->rval_binfo = NULL_TREE;
01360 lfi->ambiguous = NULL_TREE;
01361 lfi->errstr = 0;
01362 }
01363 else if (lfi->rval_binfo && !lfi->from_dep_base_p && from_dep_base_p)
01364
01365
01366 return NULL_TREE;
01367
01368
01369
01370 if (lfi->rval_binfo && !is_subobject_of_p (lfi->rval_binfo, binfo, lfi->type))
01371 {
01372 if (nval == lfi->rval && shared_member_p (nval))
01373
01374 ;
01375 else if (is_subobject_of_p (binfo, lfi->rval_binfo, lfi->type))
01376
01377 ;
01378 else
01379 {
01380
01381
01382 if (!lfi->ambiguous && lfi->rval)
01383 {
01384
01385
01386
01387 lfi->ambiguous = tree_cons (NULL_TREE, lfi->rval, NULL_TREE);
01388 TREE_TYPE (lfi->ambiguous) = error_mark_node;
01389 }
01390
01391
01392 lfi->ambiguous = tree_cons (NULL_TREE, nval, lfi->ambiguous);
01393 TREE_TYPE (lfi->ambiguous) = error_mark_node;
01394 lfi->errstr = "request for member `%D' is ambiguous";
01395 }
01396 }
01397 else
01398 {
01399 if (from_dep_base_p && TREE_CODE (nval) != TYPE_DECL
01400
01401
01402
01403 && !DECL_CLASS_TEMPLATE_P (nval))
01404
01405
01406
01407 return NULL_TREE;
01408
01409 lfi->rval = nval;
01410 lfi->from_dep_base_p = from_dep_base_p;
01411 lfi->rval_binfo = binfo;
01412 }
01413
01414 return NULL_TREE;
01415 }
01416
01417
01418
01419
01420
01421 tree
01422 build_baselink (tree binfo, tree access_binfo, tree functions, tree optype)
01423 {
01424 tree baselink;
01425
01426 my_friendly_assert (TREE_CODE (functions) == FUNCTION_DECL
01427 || TREE_CODE (functions) == TEMPLATE_DECL
01428 || TREE_CODE (functions) == TEMPLATE_ID_EXPR
01429 || TREE_CODE (functions) == OVERLOAD,
01430 20020730);
01431 my_friendly_assert (!optype || TYPE_P (optype), 20020730);
01432 my_friendly_assert (TREE_TYPE (functions), 20020805);
01433
01434 baselink = build (BASELINK, TREE_TYPE (functions), NULL_TREE,
01435 NULL_TREE, NULL_TREE);
01436 BASELINK_BINFO (baselink) = binfo;
01437 BASELINK_ACCESS_BINFO (baselink) = access_binfo;
01438 BASELINK_FUNCTIONS (baselink) = functions;
01439 BASELINK_OPTYPE (baselink) = optype;
01440
01441 return baselink;
01442 }
01443
01444
01445
01446
01447
01448
01449
01450
01451
01452
01453
01454
01455
01456 tree
01457 lookup_member (xbasetype, name, protect, want_type)
01458 register tree xbasetype, name;
01459 int protect, want_type;
01460 {
01461 tree rval, rval_binfo = NULL_TREE;
01462 tree type = NULL_TREE, basetype_path = NULL_TREE;
01463 struct lookup_field_info lfi;
01464
01465
01466
01467
01468
01469
01470
01471
01472 const char *errstr = 0;
01473
01474 if (xbasetype == current_class_type && TYPE_BEING_DEFINED (xbasetype)
01475 && IDENTIFIER_CLASS_VALUE (name))
01476 {
01477 tree field = IDENTIFIER_CLASS_VALUE (name);
01478 if (! is_overloaded_fn (field)
01479 && ! (want_type && TREE_CODE (field) != TYPE_DECL))
01480
01481
01482 return field;
01483 }
01484
01485 if (TREE_CODE (xbasetype) == TREE_VEC)
01486 {
01487 type = BINFO_TYPE (xbasetype);
01488 basetype_path = xbasetype;
01489 }
01490 else if (IS_AGGR_TYPE_CODE (TREE_CODE (xbasetype)))
01491 {
01492 type = xbasetype;
01493 basetype_path = TYPE_BINFO (type);
01494 my_friendly_assert (BINFO_INHERITANCE_CHAIN (basetype_path) == NULL_TREE,
01495 980827);
01496 }
01497 else
01498 abort ();
01499
01500 complete_type (type);
01501
01502 #ifdef GATHER_STATISTICS
01503 n_calls_lookup_field++;
01504 #endif
01505
01506 memset ((PTR) &lfi, 0, sizeof (lfi));
01507 lfi.type = type;
01508 lfi.name = name;
01509 lfi.want_type = want_type;
01510 bfs_walk (basetype_path, &lookup_field_r, &lookup_field_queue_p, &lfi);
01511 rval = lfi.rval;
01512 rval_binfo = lfi.rval_binfo;
01513 if (rval_binfo)
01514 type = BINFO_TYPE (rval_binfo);
01515 errstr = lfi.errstr;
01516
01517
01518
01519 if (!protect && lfi.ambiguous)
01520 return NULL_TREE;
01521
01522 if (protect == 2)
01523 {
01524 if (lfi.ambiguous)
01525 return lfi.ambiguous;
01526 else
01527 protect = 0;
01528 }
01529
01530
01531
01532
01533
01534 if (rval && protect && !is_overloaded_fn (rval)
01535 && !enforce_access (xbasetype, rval))
01536 return error_mark_node;
01537
01538 if (errstr && protect)
01539 {
01540 error (errstr, name, type);
01541 if (lfi.ambiguous)
01542 print_candidates (lfi.ambiguous);
01543 rval = error_mark_node;
01544 }
01545
01546
01547
01548 if (rval && lfi.from_dep_base_p && !DECL_CLASS_TEMPLATE_P (rval))
01549 rval = TYPE_STUB_DECL (build_typename_type (BINFO_TYPE (basetype_path),
01550 name, name,
01551 TREE_TYPE (rval)));
01552
01553 if (rval && is_overloaded_fn (rval))
01554 rval = build_baselink (rval_binfo, basetype_path, rval,
01555 (IDENTIFIER_TYPENAME_P (name)
01556 ? TREE_TYPE (name): NULL_TREE));
01557 return rval;
01558 }
01559
01560
01561
01562
01563 tree
01564 lookup_field (xbasetype, name, protect, want_type)
01565 register tree xbasetype, name;
01566 int protect, want_type;
01567 {
01568 tree rval = lookup_member (xbasetype, name, protect, want_type);
01569
01570
01571 if (rval && BASELINK_P (rval))
01572 return NULL_TREE;
01573
01574 return rval;
01575 }
01576
01577
01578
01579
01580 tree
01581 lookup_fnfields (xbasetype, name, protect)
01582 register tree xbasetype, name;
01583 int protect;
01584 {
01585 tree rval = lookup_member (xbasetype, name, protect, 0);
01586
01587
01588 if (rval && !BASELINK_P (rval))
01589 return NULL_TREE;
01590
01591 return rval;
01592 }
01593
01594
01595
01596 tree
01597 lookup_nested_field (name, complain)
01598 tree name;
01599 int complain;
01600 {
01601 register tree t;
01602
01603 tree id = NULL_TREE;
01604 if (TYPE_MAIN_DECL (current_class_type))
01605 {
01606
01607
01608
01609 for (t = TYPE_MAIN_DECL (current_class_type);
01610 t && DECL_CONTEXT (t);
01611 t = TYPE_MAIN_DECL (DECL_CONTEXT (t)))
01612 {
01613 if (TREE_CODE (DECL_CONTEXT (t)) != RECORD_TYPE)
01614 break;
01615
01616
01617 id = lookup_field (DECL_CONTEXT (t), name, complain, 0);
01618 if (id == error_mark_node)
01619 {
01620 id = NULL_TREE;
01621 continue;
01622 }
01623
01624 if (id != NULL_TREE)
01625 {
01626 if (TREE_CODE (id) == FIELD_DECL
01627 && ! TREE_STATIC (id)
01628 && TREE_TYPE (id) != error_mark_node)
01629 {
01630 if (complain)
01631 {
01632
01633
01634
01635
01636
01637
01638 error ("assignment to non-static member `%D' of enclosing class `%T'",
01639 id, DECL_CONTEXT (t));
01640
01641
01642 TREE_TYPE (id) = error_mark_node;
01643 }
01644 else
01645 {
01646 id = NULL_TREE;
01647 continue;
01648 }
01649 }
01650 break;
01651 }
01652 }
01653 }
01654
01655 return id;
01656 }
01657
01658
01659
01660
01661
01662
01663 static int
01664 lookup_conversion_operator (tree class_type, tree type)
01665 {
01666 int pass;
01667 int i;
01668
01669 tree methods = CLASSTYPE_METHOD_VEC (class_type);
01670
01671 for (pass = 0; pass < 2; ++pass)
01672 for (i = CLASSTYPE_FIRST_CONVERSION_SLOT;
01673 i < TREE_VEC_LENGTH (methods);
01674 ++i)
01675 {
01676 tree fn = TREE_VEC_ELT (methods, i);
01677
01678
01679 if (!fn)
01680 break;
01681
01682
01683
01684
01685 fn = OVL_CURRENT (fn);
01686 if (!DECL_CONV_FN_P (fn))
01687 break;
01688
01689 if (pass == 0)
01690 {
01691
01692
01693
01694 if (TREE_CODE (fn) != TEMPLATE_DECL
01695 && same_type_p (DECL_CONV_FN_TYPE (fn), type))
01696 return i;
01697 }
01698 else
01699 {
01700
01701
01702
01703
01704
01705
01706 if (TREE_CODE (fn) == TEMPLATE_DECL)
01707 return i;
01708 }
01709 }
01710
01711 return -1;
01712 }
01713
01714
01715
01716
01717 int
01718 lookup_fnfields_1 (tree type, tree name)
01719 {
01720 tree method_vec;
01721 tree *methods;
01722 tree tmp;
01723 int i;
01724 int len;
01725
01726 if (!CLASS_TYPE_P (type))
01727 return -1;
01728
01729 method_vec = CLASSTYPE_METHOD_VEC (type);
01730
01731 if (!method_vec)
01732 return -1;
01733
01734 methods = &TREE_VEC_ELT (method_vec, 0);
01735 len = TREE_VEC_LENGTH (method_vec);
01736
01737 #ifdef GATHER_STATISTICS
01738 n_calls_lookup_fnfields_1++;
01739 #endif
01740
01741
01742 if (name == ctor_identifier)
01743 return (methods[CLASSTYPE_CONSTRUCTOR_SLOT]
01744 ? CLASSTYPE_CONSTRUCTOR_SLOT : -1);
01745
01746 if (name == dtor_identifier)
01747 return (methods[CLASSTYPE_DESTRUCTOR_SLOT]
01748 ? CLASSTYPE_DESTRUCTOR_SLOT : -1);
01749 if (IDENTIFIER_TYPENAME_P (name))
01750 return lookup_conversion_operator (type, TREE_TYPE (name));
01751
01752
01753 i = CLASSTYPE_FIRST_CONVERSION_SLOT;
01754 while (i < len && methods[i] && DECL_CONV_FN_P (OVL_CURRENT (methods[i])))
01755 i++;
01756
01757
01758 if (COMPLETE_TYPE_P (type))
01759 {
01760 int lo = i;
01761 int hi = len;
01762
01763 while (lo < hi)
01764 {
01765 i = (lo + hi) / 2;
01766
01767 #ifdef GATHER_STATISTICS
01768 n_outer_fields_searched++;
01769 #endif
01770
01771 tmp = methods[i];
01772
01773
01774
01775 if (tmp)
01776 tmp = DECL_NAME (OVL_CURRENT (tmp));
01777 if (!tmp || tmp > name)
01778 hi = i;
01779 else if (tmp < name)
01780 lo = i + 1;
01781 else
01782 return i;
01783 }
01784 }
01785 else
01786 for (; i < len && methods[i]; ++i)
01787 {
01788 #ifdef GATHER_STATISTICS
01789 n_outer_fields_searched++;
01790 #endif
01791
01792 tmp = OVL_CURRENT (methods[i]);
01793 if (DECL_NAME (tmp) == name)
01794 return i;
01795 }
01796
01797 return -1;
01798 }
01799
01800
01801
01802
01803
01804
01805
01806
01807
01808
01809
01810
01811 tree
01812 adjust_result_of_qualified_name_lookup (tree decl,
01813 tree qualifying_class,
01814 tree context_class)
01815 {
01816 my_friendly_assert (CLASS_TYPE_P (qualifying_class), 20020808);
01817 my_friendly_assert (CLASS_TYPE_P (context_class), 20020808);
01818
01819 if (BASELINK_P (decl)
01820 && DERIVED_FROM_P (qualifying_class, context_class))
01821 {
01822 tree base;
01823
01824
01825
01826
01827
01828
01829 base = lookup_base (context_class, qualifying_class,
01830 ba_ignore | ba_quiet, NULL);
01831 if (base)
01832 {
01833 BASELINK_ACCESS_BINFO (decl) = base;
01834 BASELINK_BINFO (decl)
01835 = lookup_base (base, BINFO_TYPE (BASELINK_BINFO (decl)),
01836 ba_ignore | ba_quiet,
01837 NULL);
01838 }
01839 }
01840
01841 return decl;
01842 }
01843
01844
01845
01846
01847
01848
01849
01850
01851
01852
01853
01854
01855
01856 static tree
01857 bfs_walk (binfo, fn, qfn, data)
01858 tree binfo;
01859 tree (*fn) PARAMS ((tree, void *));
01860 tree (*qfn) PARAMS ((tree, void *));
01861 void *data;
01862 {
01863 size_t head;
01864 size_t tail;
01865 tree rval = NULL_TREE;
01866
01867
01868 varray_type bfs_bases;
01869
01870
01871
01872 VARRAY_TREE_INIT (bfs_bases, 10, "search_stack");
01873
01874
01875 VARRAY_TREE (bfs_bases, 0) = binfo;
01876 tail = 1;
01877
01878 for (head = 0; head < tail; ++head)
01879 {
01880 int i;
01881 int n_baselinks;
01882 tree binfos;
01883
01884
01885 binfo = VARRAY_TREE (bfs_bases, head);
01886
01887
01888 rval = (*fn) (binfo, data);
01889 if (rval)
01890 break;
01891
01892
01893 binfos = BINFO_BASETYPES (binfo);
01894 n_baselinks = binfos ? TREE_VEC_LENGTH (binfos): 0;
01895 for (i = 0; i < n_baselinks; i++)
01896 {
01897 tree base_binfo = TREE_VEC_ELT (binfos, i);
01898
01899 if (qfn)
01900 base_binfo = (*qfn) (base_binfo, data);
01901
01902 if (base_binfo)
01903 {
01904 if (tail == VARRAY_SIZE (bfs_bases))
01905 VARRAY_GROW (bfs_bases, 2 * VARRAY_SIZE (bfs_bases));
01906 VARRAY_TREE (bfs_bases, tail) = base_binfo;
01907 ++tail;
01908 }
01909 }
01910 }
01911
01912 return rval;
01913 }
01914
01915
01916
01917
01918
01919 tree
01920 dfs_walk_real (binfo, prefn, postfn, qfn, data)
01921 tree binfo;
01922 tree (*prefn) PARAMS ((tree, void *));
01923 tree (*postfn) PARAMS ((tree, void *));
01924 tree (*qfn) PARAMS ((tree, void *));
01925 void *data;
01926 {
01927 int i;
01928 int n_baselinks;
01929 tree binfos;
01930 tree rval = NULL_TREE;
01931
01932
01933 if (prefn)
01934 {
01935 rval = (*prefn) (binfo, data);
01936 if (rval)
01937 return rval;
01938 }
01939
01940
01941 binfos = BINFO_BASETYPES (binfo);
01942 n_baselinks = BINFO_N_BASETYPES (binfo);
01943 for (i = 0; i < n_baselinks; i++)
01944 {
01945 tree base_binfo = TREE_VEC_ELT (binfos, i);
01946
01947 if (qfn)
01948 base_binfo = (*qfn) (base_binfo, data);
01949
01950 if (base_binfo)
01951 {
01952 rval = dfs_walk_real (base_binfo, prefn, postfn, qfn, data);
01953 if (rval)
01954 return rval;
01955 }
01956 }
01957
01958
01959 if (postfn)
01960 rval = (*postfn) (binfo, data);
01961
01962 return rval;
01963 }
01964
01965
01966
01967
01968 tree
01969 dfs_walk (binfo, fn, qfn, data)
01970 tree binfo;
01971 tree (*fn) PARAMS ((tree, void *));
01972 tree (*qfn) PARAMS ((tree, void *));
01973 void *data;
01974 {
01975 return dfs_walk_real (binfo, 0, fn, qfn, data);
01976 }
01977
01978
01979
01980
01981
01982
01983
01984 static int
01985 covariant_return_p (brettype, drettype)
01986 tree brettype, drettype;
01987 {
01988 tree binfo;
01989 base_kind kind;
01990
01991 if (TREE_CODE (brettype) == FUNCTION_DECL)
01992 {
01993 brettype = TREE_TYPE (TREE_TYPE (brettype));
01994 drettype = TREE_TYPE (TREE_TYPE (drettype));
01995 }
01996 else if (TREE_CODE (brettype) == METHOD_TYPE)
01997 {
01998 brettype = TREE_TYPE (brettype);
01999 drettype = TREE_TYPE (drettype);
02000 }
02001
02002 if (same_type_p (brettype, drettype))
02003 return 0;
02004
02005 if (! (TREE_CODE (brettype) == TREE_CODE (drettype)
02006 && (TREE_CODE (brettype) == POINTER_TYPE
02007 || TREE_CODE (brettype) == REFERENCE_TYPE)
02008 && TYPE_QUALS (brettype) == TYPE_QUALS (drettype)))
02009 return 0;
02010
02011 if (! can_convert (brettype, drettype))
02012 return 0;
02013
02014 brettype = TREE_TYPE (brettype);
02015 drettype = TREE_TYPE (drettype);
02016
02017
02018 if (! IS_AGGR_TYPE (drettype) || ! IS_AGGR_TYPE (brettype))
02019 return -1;
02020
02021 binfo = lookup_base (drettype, brettype, ba_check | ba_quiet, &kind);
02022
02023 if (!binfo)
02024 return 0;
02025 if (BINFO_OFFSET_ZEROP (binfo) && kind != bk_via_virtual)
02026 return 1;
02027 return 2;
02028 }
02029
02030
02031
02032
02033 int
02034 check_final_overrider (overrider, basefn)
02035 tree overrider, basefn;
02036 {
02037 tree over_type = TREE_TYPE (overrider);
02038 tree base_type = TREE_TYPE (basefn);
02039 tree over_return = TREE_TYPE (over_type);
02040 tree base_return = TREE_TYPE (base_type);
02041 tree over_throw = TYPE_RAISES_EXCEPTIONS (over_type);
02042 tree base_throw = TYPE_RAISES_EXCEPTIONS (base_type);
02043 int i;
02044
02045 if (same_type_p (base_return, over_return))
02046 ;
02047 else if ((i = covariant_return_p (base_return, over_return)))
02048 {
02049 if (i == 2)
02050 sorry ("adjusting pointers for covariant returns");
02051
02052 if (pedantic && i == -1)
02053 {
02054 cp_pedwarn_at ("invalid covariant return type for `%#D'", overrider);
02055 cp_pedwarn_at (" overriding `%#D' (must be pointer or reference to class)", basefn);
02056 }
02057 }
02058 else if (IS_AGGR_TYPE_2 (base_return, over_return)
02059 && same_or_base_type_p (base_return, over_return))
02060 {
02061 cp_error_at ("invalid covariant return type for `%#D'", overrider);
02062 cp_error_at (" overriding `%#D' (must use pointer or reference)", basefn);
02063 return 0;
02064 }
02065 else if (IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (overrider)) == NULL_TREE)
02066 {
02067 cp_error_at ("conflicting return type specified for `%#D'", overrider);
02068 cp_error_at (" overriding `%#D'", basefn);
02069 SET_IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (overrider),
02070 DECL_CONTEXT (overrider));
02071 return 0;
02072 }
02073
02074
02075 if (!comp_except_specs (base_throw, over_throw, 0))
02076 {
02077 cp_error_at ("looser throw specifier for `%#F'", overrider);
02078 cp_error_at (" overriding `%#F'", basefn);
02079 return 0;
02080 }
02081 return 1;
02082 }
02083
02084
02085
02086
02087
02088
02089
02090
02091
02092
02093
02094 int
02095 look_for_overrides (type, fndecl)
02096 tree type, fndecl;
02097 {
02098 tree binfo = TYPE_BINFO (type);
02099 tree basebinfos = BINFO_BASETYPES (binfo);
02100 int nbasebinfos = basebinfos ? TREE_VEC_LENGTH (basebinfos) : 0;
02101 int ix;
02102 int found = 0;
02103
02104 for (ix = 0; ix != nbasebinfos; ix++)
02105 {
02106 tree basetype = BINFO_TYPE (TREE_VEC_ELT (basebinfos, ix));
02107
02108 if (TYPE_POLYMORPHIC_P (basetype))
02109 found += look_for_overrides_r (basetype, fndecl);
02110 }
02111 return found;
02112 }
02113
02114
02115
02116
02117 tree
02118 look_for_overrides_here (type, fndecl)
02119 tree type, fndecl;
02120 {
02121 int ix;
02122
02123 if (DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (fndecl))
02124 ix = CLASSTYPE_DESTRUCTOR_SLOT;
02125 else
02126 ix = lookup_fnfields_1 (type, DECL_NAME (fndecl));
02127 if (ix >= 0)
02128 {
02129 tree fns = TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type), ix);
02130
02131 for (; fns; fns = OVL_NEXT (fns))
02132 {
02133 tree fn = OVL_CURRENT (fns);
02134
02135 if (!DECL_VIRTUAL_P (fn))
02136 ;
02137 else if (DECL_CONTEXT (fn) != type)
02138 ;
02139 else if (DECL_STATIC_FUNCTION_P (fndecl))
02140 {
02141 tree btypes = TYPE_ARG_TYPES (TREE_TYPE (fn));
02142 tree dtypes = TYPE_ARG_TYPES (TREE_TYPE (fndecl));
02143 if (compparms (TREE_CHAIN (btypes), dtypes))
02144 return fn;
02145 }
02146 else if (same_signature_p (fndecl, fn))
02147 return fn;
02148 }
02149 }
02150 return NULL_TREE;
02151 }
02152
02153
02154
02155
02156 static int
02157 look_for_overrides_r (type, fndecl)
02158 tree type, fndecl;
02159 {
02160 tree fn = look_for_overrides_here (type, fndecl);
02161 if (fn)
02162 {
02163 if (DECL_STATIC_FUNCTION_P (fndecl))
02164 {
02165
02166
02167 cp_error_at ("`%#D' cannot be declared", fndecl);
02168 cp_error_at (" since `%#D' declared in base class", fn);
02169 }
02170 else
02171 {
02172
02173 DECL_VIRTUAL_P (fndecl) = 1;
02174 check_final_overrider (fndecl, fn);
02175 }
02176 return 1;
02177 }
02178
02179
02180 return look_for_overrides (type, fndecl);
02181 }
02182
02183
02184
02185
02186
02187
02188
02189
02190
02191
02192
02193 tree
02194 dfs_unmarked_real_bases_queue_p (binfo, data)
02195 tree binfo;
02196 void *data;
02197 {
02198 if (TREE_VIA_VIRTUAL (binfo))
02199 {
02200 tree type = (tree) data;
02201
02202 if (TREE_CODE (type) == TREE_LIST)
02203 type = TREE_PURPOSE (type);
02204 binfo = binfo_for_vbase (BINFO_TYPE (binfo), type);
02205 }
02206 return unmarkedp (binfo, NULL);
02207 }
02208
02209
02210
02211
02212 tree
02213 dfs_marked_real_bases_queue_p (binfo, data)
02214 tree binfo;
02215 void *data;
02216 {
02217 if (TREE_VIA_VIRTUAL (binfo))
02218 {
02219 tree type = (tree) data;
02220
02221 if (TREE_CODE (type) == TREE_LIST)
02222 type = TREE_PURPOSE (type);
02223 binfo = binfo_for_vbase (BINFO_TYPE (binfo), type);
02224 }
02225 return markedp (binfo, NULL);
02226 }
02227
02228
02229
02230
02231 tree
02232 dfs_skip_vbases (binfo, data)
02233 tree binfo;
02234 void *data ATTRIBUTE_UNUSED;
02235 {
02236 if (TREE_VIA_VIRTUAL (binfo))
02237 return NULL_TREE;
02238
02239 return binfo;
02240 }
02241
02242
02243
02244 static tree
02245 dfs_get_pure_virtuals (binfo, data)
02246 tree binfo;
02247 void *data;
02248 {
02249 tree type = (tree) data;
02250
02251
02252
02253
02254 if (!BINFO_PRIMARY_P (binfo))
02255 {
02256 tree virtuals;
02257
02258 for (virtuals = BINFO_VIRTUALS (binfo);
02259 virtuals;
02260 virtuals = TREE_CHAIN (virtuals))
02261 if (DECL_PURE_VIRTUAL_P (BV_FN (virtuals)))
02262 CLASSTYPE_PURE_VIRTUALS (type)
02263 = tree_cons (NULL_TREE, BV_FN (virtuals),
02264 CLASSTYPE_PURE_VIRTUALS (type));
02265 }
02266
02267 SET_BINFO_MARKED (binfo);
02268
02269 return NULL_TREE;
02270 }
02271
02272
02273
02274 void
02275 get_pure_virtuals (type)
02276 tree type;
02277 {
02278 tree vbases;
02279
02280
02281
02282 CLASSTYPE_PURE_VIRTUALS (type) = NULL_TREE;
02283
02284
02285
02286
02287
02288
02289 dfs_walk (TYPE_BINFO (type), dfs_get_pure_virtuals,
02290 dfs_unmarked_real_bases_queue_p, type);
02291 dfs_walk (TYPE_BINFO (type), dfs_unmark,
02292 dfs_marked_real_bases_queue_p, type);
02293
02294
02295 CLASSTYPE_PURE_VIRTUALS (type) = nreverse (CLASSTYPE_PURE_VIRTUALS (type));
02296
02297 for (vbases = CLASSTYPE_VBASECLASSES (type);
02298 vbases;
02299 vbases = TREE_CHAIN (vbases))
02300 {
02301 tree virtuals;
02302
02303 for (virtuals = BINFO_VIRTUALS (TREE_VALUE (vbases));
02304 virtuals;
02305 virtuals = TREE_CHAIN (virtuals))
02306 {
02307 tree base_fndecl = BV_FN (virtuals);
02308 if (DECL_NEEDS_FINAL_OVERRIDER_P (base_fndecl))
02309 error ("`%#D' needs a final overrider", base_fndecl);
02310 }
02311 }
02312 }
02313
02314
02315
02316 tree
02317 markedp (binfo, data)
02318 tree binfo;
02319 void *data ATTRIBUTE_UNUSED;
02320 {
02321 return BINFO_MARKED (binfo) ? binfo : NULL_TREE;
02322 }
02323
02324 tree
02325 unmarkedp (binfo, data)
02326 tree binfo;
02327 void *data ATTRIBUTE_UNUSED;
02328 {
02329 return !BINFO_MARKED (binfo) ? binfo : NULL_TREE;
02330 }
02331
02332 tree
02333 marked_vtable_pathp (binfo, data)
02334 tree binfo;
02335 void *data ATTRIBUTE_UNUSED;
02336 {
02337 return BINFO_VTABLE_PATH_MARKED (binfo) ? binfo : NULL_TREE;
02338 }
02339
02340 tree
02341 unmarked_vtable_pathp (binfo, data)
02342 tree binfo;
02343 void *data ATTRIBUTE_UNUSED;
02344 {
02345 return !BINFO_VTABLE_PATH_MARKED (binfo) ? binfo : NULL_TREE;
02346 }
02347
02348 static tree
02349 marked_pushdecls_p (binfo, data)
02350 tree binfo;
02351 void *data ATTRIBUTE_UNUSED;
02352 {
02353 return (CLASS_TYPE_P (BINFO_TYPE (binfo))
02354 && BINFO_PUSHDECLS_MARKED (binfo)) ? binfo : NULL_TREE;
02355 }
02356
02357 static tree
02358 unmarked_pushdecls_p (binfo, data)
02359 tree binfo;
02360 void *data ATTRIBUTE_UNUSED;
02361 {
02362 return (CLASS_TYPE_P (BINFO_TYPE (binfo))
02363 && !BINFO_PUSHDECLS_MARKED (binfo)) ? binfo : NULL_TREE;
02364 }
02365
02366
02367
02368
02369
02370 tree
02371 dfs_unmark (binfo, data)
02372 tree binfo;
02373 void *data ATTRIBUTE_UNUSED;
02374 {
02375 CLEAR_BINFO_MARKED (binfo);
02376 return NULL_TREE;
02377 }
02378
02379
02380
02381
02382
02383 static tree
02384 dfs_get_vbase_types (binfo, data)
02385 tree binfo;
02386 void *data;
02387 {
02388 tree type = (tree) data;
02389
02390 if (TREE_VIA_VIRTUAL (binfo))
02391 CLASSTYPE_VBASECLASSES (type)
02392 = tree_cons (BINFO_TYPE (binfo),
02393 binfo,
02394 CLASSTYPE_VBASECLASSES (type));
02395 SET_BINFO_MARKED (binfo);
02396 return NULL_TREE;
02397 }
02398
02399
02400
02401
02402 static tree
02403 dfs_build_inheritance_graph_order (binfo, data)
02404 tree binfo;
02405 void *data;
02406 {
02407 tree *last_binfo = (tree *) data;
02408
02409 if (*last_binfo)
02410 TREE_CHAIN (*last_binfo) = binfo;
02411 *last_binfo = binfo;
02412 SET_BINFO_MARKED (binfo);
02413 return NULL_TREE;
02414 }
02415
02416
02417
02418 void
02419 get_vbase_types (type)
02420 tree type;
02421 {
02422 tree last_binfo;
02423
02424 CLASSTYPE_VBASECLASSES (type) = NULL_TREE;
02425 dfs_walk (TYPE_BINFO (type), dfs_get_vbase_types, unmarkedp, type);
02426
02427
02428 CLASSTYPE_VBASECLASSES (type) = nreverse (CLASSTYPE_VBASECLASSES (type));
02429 dfs_walk (TYPE_BINFO (type), dfs_unmark, markedp, 0);
02430
02431 last_binfo = NULL;
02432 dfs_walk_real (TYPE_BINFO (type),
02433 dfs_build_inheritance_graph_order,
02434 NULL,
02435 unmarkedp,
02436 &last_binfo);
02437 dfs_walk (TYPE_BINFO (type), dfs_unmark, markedp, NULL);
02438 }
02439
02440
02441
02442 static tree
02443 dfs_find_vbase_instance (binfo, data)
02444 tree binfo;
02445 void *data;
02446 {
02447 tree base = TREE_VALUE ((tree) data);
02448
02449 if (BINFO_PRIMARY_P (binfo)
02450 && same_type_p (BINFO_TYPE (binfo), base))
02451 return binfo;
02452
02453 return NULL_TREE;
02454 }
02455
02456
02457
02458
02459 tree
02460 find_vbase_instance (base, type)
02461 tree base;
02462 tree type;
02463 {
02464 tree instance;
02465
02466 instance = binfo_for_vbase (base, type);
02467 if (!BINFO_PRIMARY_P (instance))
02468 return instance;
02469
02470 return dfs_walk (TYPE_BINFO (type),
02471 dfs_find_vbase_instance,
02472 NULL,
02473 build_tree_list (type, base));
02474 }
02475
02476
02477
02478
02479
02480
02481
02482
02483
02484 void
02485 maybe_suppress_debug_info (t)
02486 tree t;
02487 {
02488
02489
02490
02491
02492
02493
02494
02495
02496 if (write_symbols == DWARF_DEBUG || write_symbols == NO_DEBUG)
02497 return;
02498
02499
02500 TYPE_DECL_SUPPRESS_DEBUG (TYPE_MAIN_DECL (t)) = 0;
02501
02502
02503
02504 if (CLASSTYPE_INTERFACE_KNOWN (t))
02505 {
02506 if (CLASSTYPE_INTERFACE_ONLY (t))
02507 TYPE_DECL_SUPPRESS_DEBUG (TYPE_MAIN_DECL (t)) = 1;
02508
02509 }
02510
02511
02512 else if (TYPE_CONTAINS_VPTR_P (t))
02513 TYPE_DECL_SUPPRESS_DEBUG (TYPE_MAIN_DECL (t)) = 1;
02514
02515
02516 }
02517
02518
02519
02520
02521
02522
02523
02524
02525
02526
02527 static tree
02528 dfs_debug_mark (binfo, data)
02529 tree binfo;
02530 void *data ATTRIBUTE_UNUSED;
02531 {
02532 tree t = BINFO_TYPE (binfo);
02533
02534 CLASSTYPE_DEBUG_REQUESTED (t) = 1;
02535
02536 return NULL_TREE;
02537 }
02538
02539
02540
02541
02542 static tree
02543 dfs_debug_unmarkedp (binfo, data)
02544 tree binfo;
02545 void *data ATTRIBUTE_UNUSED;
02546 {
02547 return (!CLASSTYPE_DEBUG_REQUESTED (BINFO_TYPE (binfo))
02548 ? binfo : NULL_TREE);
02549 }
02550
02551
02552
02553
02554
02555
02556
02557
02558 void
02559 note_debug_info_needed (type)
02560 tree type;
02561 {
02562 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_NAME (type)))
02563 {
02564 TYPE_DECL_SUPPRESS_DEBUG (TYPE_NAME (type)) = 0;
02565 rest_of_type_compilation (type, toplevel_bindings_p ());
02566 }
02567
02568 dfs_walk (TYPE_BINFO (type), dfs_debug_mark, dfs_debug_unmarkedp, 0);
02569 }
02570
02571
02572
02573
02574
02575
02576 static int
02577 dependent_base_p (binfo)
02578 tree binfo;
02579 {
02580 for (; binfo; binfo = BINFO_INHERITANCE_CHAIN (binfo))
02581 {
02582 if (currently_open_class (TREE_TYPE (binfo)))
02583 break;
02584 if (uses_template_parms (TREE_TYPE (binfo)))
02585 return 1;
02586 }
02587 return 0;
02588 }
02589
02590 static void
02591 setup_class_bindings (name, type_binding_p)
02592 tree name;
02593 int type_binding_p;
02594 {
02595 tree type_binding = NULL_TREE;
02596 tree value_binding;
02597
02598
02599
02600 if (IDENTIFIER_CLASS_VALUE (name))
02601 return;
02602
02603
02604 if (type_binding_p)
02605 {
02606 type_binding = lookup_member (current_class_type, name,
02607 2,
02608 1);
02609 if (TREE_CODE (type_binding) == TREE_LIST
02610 && TREE_TYPE (type_binding) == error_mark_node)
02611
02612 push_class_level_binding (name, type_binding);
02613 else
02614 pushdecl_class_level (type_binding);
02615 }
02616
02617
02618 value_binding = lookup_member (current_class_type, name,
02619 2,
02620 0);
02621
02622 if (type_binding_p
02623 && (TREE_CODE (value_binding) == TYPE_DECL
02624 || DECL_CLASS_TEMPLATE_P (value_binding)
02625 || (TREE_CODE (value_binding) == TREE_LIST
02626 && TREE_TYPE (value_binding) == error_mark_node
02627 && (TREE_CODE (TREE_VALUE (value_binding))
02628 == TYPE_DECL))))
02629
02630
02631 ;
02632 else if (value_binding)
02633 {
02634 if (TREE_CODE (value_binding) == TREE_LIST
02635 && TREE_TYPE (value_binding) == error_mark_node)
02636
02637 push_class_level_binding (name, value_binding);
02638 else
02639 {
02640 if (BASELINK_P (value_binding))
02641
02642 value_binding = BASELINK_FUNCTIONS (value_binding);
02643
02644
02645
02646
02647
02648
02649 if (IDENTIFIER_TYPENAME_P (name)
02650 && is_overloaded_fn (value_binding))
02651 {
02652 tree fns;
02653 for (fns = value_binding; fns; fns = OVL_NEXT (fns))
02654 if (IDENTIFIER_CLASS_VALUE (DECL_NAME (OVL_CURRENT (fns))))
02655 return;
02656 }
02657 pushdecl_class_level (value_binding);
02658 }
02659 }
02660 }
02661
02662
02663
02664
02665 static tree
02666 dfs_push_type_decls (binfo, data)
02667 tree binfo;
02668 void *data ATTRIBUTE_UNUSED;
02669 {
02670 tree type;
02671 tree fields;
02672
02673 type = BINFO_TYPE (binfo);
02674 for (fields = TYPE_FIELDS (type); fields; fields = TREE_CHAIN (fields))
02675 if (DECL_NAME (fields) && TREE_CODE (fields) == TYPE_DECL
02676 && !(!same_type_p (type, current_class_type)
02677 && template_self_reference_p (type, fields)))
02678 setup_class_bindings (DECL_NAME (fields), 1);
02679
02680
02681
02682 SET_BINFO_PUSHDECLS_MARKED (binfo);
02683
02684 return NULL_TREE;
02685 }
02686
02687
02688
02689
02690 static tree
02691 dfs_push_decls (binfo, data)
02692 tree binfo;
02693 void *data;
02694 {
02695 tree type;
02696 tree method_vec;
02697 int dep_base_p;
02698
02699 type = BINFO_TYPE (binfo);
02700 dep_base_p = (processing_template_decl && type != current_class_type
02701 && dependent_base_p (binfo));
02702 if (!dep_base_p)
02703 {
02704 tree fields;
02705 for (fields = TYPE_FIELDS (type); fields; fields = TREE_CHAIN (fields))
02706 if (DECL_NAME (fields)
02707 && TREE_CODE (fields) != TYPE_DECL
02708 && TREE_CODE (fields) != USING_DECL
02709 && !DECL_ARTIFICIAL (fields))
02710 setup_class_bindings (DECL_NAME (fields), 0);
02711 else if (TREE_CODE (fields) == FIELD_DECL
02712 && ANON_AGGR_TYPE_P (TREE_TYPE (fields)))
02713 dfs_push_decls (TYPE_BINFO (TREE_TYPE (fields)), data);
02714
02715 method_vec = (CLASS_TYPE_P (type)
02716 ? CLASSTYPE_METHOD_VEC (type) : NULL_TREE);
02717
02718 if (method_vec && TREE_VEC_LENGTH (method_vec) >= 3)
02719 {
02720 tree *methods;
02721 tree *end;
02722
02723
02724 end = TREE_VEC_END (method_vec);
02725
02726 for (methods = &TREE_VEC_ELT (method_vec, 2);
02727 methods < end && *methods;
02728 methods++)
02729 setup_class_bindings (DECL_NAME (OVL_CURRENT (*methods)),
02730 0);
02731 }
02732 }
02733
02734 CLEAR_BINFO_PUSHDECLS_MARKED (binfo);
02735
02736 return NULL_TREE;
02737 }
02738
02739
02740
02741
02742
02743
02744
02745
02746 void
02747 push_class_decls (type)
02748 tree type;
02749 {
02750 search_stack = push_search_level (search_stack, &search_obstack);
02751
02752
02753 dfs_walk (TYPE_BINFO (type), dfs_push_type_decls, unmarked_pushdecls_p, 0);
02754
02755
02756 dfs_walk (TYPE_BINFO (type), dfs_push_decls, marked_pushdecls_p, 0);
02757 }
02758
02759
02760
02761 static tree
02762 dfs_unuse_fields (binfo, data)
02763 tree binfo;
02764 void *data ATTRIBUTE_UNUSED;
02765 {
02766 tree type = TREE_TYPE (binfo);
02767 tree fields;
02768
02769 for (fields = TYPE_FIELDS (type); fields; fields = TREE_CHAIN (fields))
02770 {
02771 if (TREE_CODE (fields) != FIELD_DECL || DECL_ARTIFICIAL (fields))
02772 continue;
02773
02774 TREE_USED (fields) = 0;
02775 if (DECL_NAME (fields) == NULL_TREE
02776 && ANON_AGGR_TYPE_P (TREE_TYPE (fields)))
02777 unuse_fields (TREE_TYPE (fields));
02778 }
02779
02780 return NULL_TREE;
02781 }
02782
02783 void
02784 unuse_fields (type)
02785 tree type;
02786 {
02787 dfs_walk (TYPE_BINFO (type), dfs_unuse_fields, unmarkedp, 0);
02788 }
02789
02790 void
02791 pop_class_decls ()
02792 {
02793
02794
02795 if (search_stack)
02796 search_stack = pop_search_level (search_stack);
02797 }
02798
02799 void
02800 print_search_statistics ()
02801 {
02802 #ifdef GATHER_STATISTICS
02803 fprintf (stderr, "%d fields searched in %d[%d] calls to lookup_field[_1]\n",
02804 n_fields_searched, n_calls_lookup_field, n_calls_lookup_field_1);
02805 fprintf (stderr, "%d fnfields searched in %d calls to lookup_fnfields\n",
02806 n_outer_fields_searched, n_calls_lookup_fnfields);
02807 fprintf (stderr, "%d calls to get_base_type\n", n_calls_get_base_type);
02808 #else
02809 fprintf (stderr, "no search statistics\n");
02810 #endif
02811 }
02812
02813 void
02814 init_search_processing ()
02815 {
02816 gcc_obstack_init (&search_obstack);
02817 }
02818
02819 void
02820 reinit_search_statistics ()
02821 {
02822 #ifdef GATHER_STATISTICS
02823 n_fields_searched = 0;
02824 n_calls_lookup_field = 0, n_calls_lookup_field_1 = 0;
02825 n_calls_lookup_fnfields = 0, n_calls_lookup_fnfields_1 = 0;
02826 n_calls_get_base_type = 0;
02827 n_outer_fields_searched = 0;
02828 n_contexts_saved = 0;
02829 #endif
02830 }
02831
02832 static tree
02833 add_conversions (binfo, data)
02834 tree binfo;
02835 void *data;
02836 {
02837 int i;
02838 tree method_vec = CLASSTYPE_METHOD_VEC (BINFO_TYPE (binfo));
02839 tree *conversions = (tree *) data;
02840
02841
02842 if (!method_vec)
02843 return NULL_TREE;
02844
02845 for (i = 2; i < TREE_VEC_LENGTH (method_vec); ++i)
02846 {
02847 tree tmp = TREE_VEC_ELT (method_vec, i);
02848 tree name;
02849
02850 if (!tmp || ! DECL_CONV_FN_P (OVL_CURRENT (tmp)))
02851 break;
02852
02853 name = DECL_NAME (OVL_CURRENT (tmp));
02854
02855
02856 if (! IDENTIFIER_MARKED (name))
02857 {
02858 tree t;
02859
02860
02861
02862
02863
02864 for (t = *conversions; t; t = TREE_CHAIN (t))
02865 {
02866 tree fn;
02867 for (fn = TREE_VALUE (t); fn; fn = OVL_NEXT (fn))
02868 if (same_type_p (TREE_TYPE (name),
02869 DECL_CONV_FN_TYPE (OVL_CURRENT (fn))))
02870 break;
02871 if (fn)
02872 break;
02873 }
02874 if (!t)
02875 {
02876 *conversions = tree_cons (binfo, tmp, *conversions);
02877 IDENTIFIER_MARKED (name) = 1;
02878 }
02879 }
02880 }
02881 return NULL_TREE;
02882 }
02883
02884
02885
02886
02887
02888
02889
02890 tree
02891 lookup_conversions (type)
02892 tree type;
02893 {
02894 tree t;
02895 tree conversions = NULL_TREE;
02896
02897 complete_type (type);
02898 bfs_walk (TYPE_BINFO (type), add_conversions, 0, &conversions);
02899
02900 for (t = conversions; t; t = TREE_CHAIN (t))
02901 IDENTIFIER_MARKED (DECL_NAME (OVL_CURRENT (TREE_VALUE (t)))) = 0;
02902
02903 return conversions;
02904 }
02905
02906 struct overlap_info
02907 {
02908 tree compare_type;
02909 int found_overlap;
02910 };
02911
02912
02913
02914
02915 static tree
02916 dfs_check_overlap (empty_binfo, data)
02917 tree empty_binfo;
02918 void *data;
02919 {
02920 struct overlap_info *oi = (struct overlap_info *) data;
02921 tree binfo;
02922 for (binfo = TYPE_BINFO (oi->compare_type);
02923 ;
02924 binfo = BINFO_BASETYPE (binfo, 0))
02925 {
02926 if (BINFO_TYPE (binfo) == BINFO_TYPE (empty_binfo))
02927 {
02928 oi->found_overlap = 1;
02929 break;
02930 }
02931 else if (BINFO_BASETYPES (binfo) == NULL_TREE)
02932 break;
02933 }
02934
02935 return NULL_TREE;
02936 }
02937
02938
02939
02940 static tree
02941 dfs_no_overlap_yet (binfo, data)
02942 tree binfo;
02943 void *data;
02944 {
02945 struct overlap_info *oi = (struct overlap_info *) data;
02946 return !oi->found_overlap ? binfo : NULL_TREE;
02947 }
02948
02949
02950
02951
02952 int
02953 types_overlap_p (empty_type, next_type)
02954 tree empty_type, next_type;
02955 {
02956 struct overlap_info oi;
02957
02958 if (! IS_AGGR_TYPE (next_type))
02959 return 0;
02960 oi.compare_type = next_type;
02961 oi.found_overlap = 0;
02962 dfs_walk (TYPE_BINFO (empty_type), dfs_check_overlap,
02963 dfs_no_overlap_yet, &oi);
02964 return oi.found_overlap;
02965 }
02966
02967
02968
02969
02970
02971
02972 tree
02973 binfo_for_vtable (var)
02974 tree var;
02975 {
02976 tree main_binfo = TYPE_BINFO (DECL_CONTEXT (var));
02977 tree binfos = TYPE_BINFO_BASETYPES (BINFO_TYPE (main_binfo));
02978 int n_baseclasses = CLASSTYPE_N_BASECLASSES (BINFO_TYPE (main_binfo));
02979 int i;
02980
02981 for (i = 0; i < n_baseclasses; i++)
02982 {
02983 tree base_binfo = TREE_VEC_ELT (binfos, i);
02984 if (base_binfo != NULL_TREE && BINFO_VTABLE (base_binfo) == var)
02985 return base_binfo;
02986 }
02987
02988
02989
02990 if (CLASSTYPE_HAS_PRIMARY_BASE_P (BINFO_TYPE (main_binfo)))
02991 return get_primary_binfo (main_binfo);
02992
02993 return main_binfo;
02994 }
02995
02996
02997
02998
02999 tree
03000 binfo_from_vbase (binfo)
03001 tree binfo;
03002 {
03003 for (; binfo; binfo = BINFO_INHERITANCE_CHAIN (binfo))
03004 {
03005 if (TREE_VIA_VIRTUAL (binfo))
03006 return binfo;
03007 }
03008 return NULL_TREE;
03009 }
03010
03011
03012
03013
03014
03015 tree
03016 binfo_via_virtual (binfo, limit)
03017 tree binfo;
03018 tree limit;
03019 {
03020 for (; binfo && (!limit || !same_type_p (BINFO_TYPE (binfo), limit));
03021 binfo = BINFO_INHERITANCE_CHAIN (binfo))
03022 {
03023 if (TREE_VIA_VIRTUAL (binfo))
03024 return binfo;
03025 }
03026 return NULL_TREE;
03027 }
03028
03029
03030
03031
03032 tree
03033 binfo_for_vbase (basetype, classtype)
03034 tree basetype;
03035 tree classtype;
03036 {
03037 tree binfo;
03038
03039 binfo = purpose_member (basetype, CLASSTYPE_VBASECLASSES (classtype));
03040 return binfo ? TREE_VALUE (binfo) : NULL_TREE;
03041 }