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 "coretypes.h"
00029 #include "tm.h"
00030 #include "tree.h"
00031 #include "cp-tree.h"
00032 #include "obstack.h"
00033 #include "flags.h"
00034 #include "rtl.h"
00035 #include "output.h"
00036 #include "toplev.h"
00037
00038 static int is_subobject_of_p (tree, tree);
00039 static tree dfs_lookup_base (tree, void *);
00040 static tree dfs_dcast_hint_pre (tree, void *);
00041 static tree dfs_dcast_hint_post (tree, void *);
00042 static tree dfs_debug_mark (tree, void *);
00043 static tree dfs_walk_once_r (tree, tree (*pre_fn) (tree, void *),
00044 tree (*post_fn) (tree, void *), void *data);
00045 static void dfs_unmark_r (tree);
00046 static int check_hidden_convs (tree, int, int, tree, tree, tree);
00047 static tree split_conversions (tree, tree, tree, tree);
00048 static int lookup_conversions_r (tree, int, int,
00049 tree, tree, tree, tree, tree *, tree *);
00050 static int look_for_overrides_r (tree, tree);
00051 static tree lookup_field_r (tree, void *);
00052 static tree dfs_accessible_post (tree, void *);
00053 static tree dfs_walk_once_accessible_r (tree, bool, bool,
00054 tree (*pre_fn) (tree, void *),
00055 tree (*post_fn) (tree, void *),
00056 void *data);
00057 static tree dfs_walk_once_accessible (tree, bool,
00058 tree (*pre_fn) (tree, void *),
00059 tree (*post_fn) (tree, void *),
00060 void *data);
00061 static tree dfs_access_in_type (tree, void *);
00062 static access_kind access_in_type (tree, tree);
00063 static int protected_accessible_p (tree, tree, tree);
00064 static int friend_accessible_p (tree, tree, tree);
00065 static int template_self_reference_p (tree, tree);
00066 static tree dfs_get_pure_virtuals (tree, void *);
00067
00068
00069
00070 #ifdef GATHER_STATISTICS
00071 static int n_fields_searched;
00072 static int n_calls_lookup_field, n_calls_lookup_field_1;
00073 static int n_calls_lookup_fnfields, n_calls_lookup_fnfields_1;
00074 static int n_calls_get_base_type;
00075 static int n_outer_fields_searched;
00076 static int n_contexts_saved;
00077 #endif
00078
00079
00080
00081
00082 struct lookup_base_data_s
00083 {
00084 tree t;
00085 tree base;
00086 tree binfo;
00087 bool via_virtual;
00088 bool ambiguous;
00089 bool repeated_base;
00090
00091 bool want_any;
00092 };
00093
00094
00095
00096
00097 static tree
00098 dfs_lookup_base (tree binfo, void *data_)
00099 {
00100 struct lookup_base_data_s *data = (struct lookup_base_data_s *) data_;
00101
00102 if (SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), data->base))
00103 {
00104 if (!data->binfo)
00105 {
00106 data->binfo = binfo;
00107 data->via_virtual
00108 = binfo_via_virtual (data->binfo, data->t) != NULL_TREE;
00109
00110 if (!data->repeated_base)
00111
00112 return binfo;
00113
00114 if (data->want_any && !data->via_virtual)
00115
00116
00117 return binfo;
00118
00119 return dfs_skip_bases;
00120 }
00121 else
00122 {
00123 gcc_assert (binfo != data->binfo);
00124
00125
00126 if (!data->want_any)
00127 {
00128
00129 data->binfo = NULL_TREE;
00130 data->ambiguous = true;
00131 return error_mark_node;
00132 }
00133
00134
00135 if (!binfo_via_virtual (binfo, data->t))
00136 {
00137 data->binfo = binfo;
00138 data->via_virtual = false;
00139 return binfo;
00140 }
00141
00142
00143
00144 return dfs_skip_bases;
00145 }
00146 }
00147
00148 return NULL_TREE;
00149 }
00150
00151
00152
00153
00154
00155
00156 bool
00157 accessible_base_p (tree t, tree base, bool consider_local_p)
00158 {
00159 tree decl;
00160
00161
00162
00163
00164
00165
00166
00167
00168 if (same_type_p (t, base))
00169 return true;
00170
00171
00172 decl = TYPE_FIELDS (base);
00173 while (!DECL_SELF_REFERENCE_P (decl))
00174 decl = TREE_CHAIN (decl);
00175 while (ANON_AGGR_TYPE_P (t))
00176 t = TYPE_CONTEXT (t);
00177 return accessible_p (t, decl, consider_local_p);
00178 }
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190 tree
00191 lookup_base (tree t, tree base, base_access access, base_kind *kind_ptr)
00192 {
00193 tree binfo;
00194 tree t_binfo;
00195 base_kind bk;
00196
00197 if (t == error_mark_node || base == error_mark_node)
00198 {
00199 if (kind_ptr)
00200 *kind_ptr = bk_not_base;
00201 return error_mark_node;
00202 }
00203 gcc_assert (TYPE_P (base));
00204
00205 if (!TYPE_P (t))
00206 {
00207 t_binfo = t;
00208 t = BINFO_TYPE (t);
00209 }
00210 else
00211 {
00212 t = complete_type (TYPE_MAIN_VARIANT (t));
00213 t_binfo = TYPE_BINFO (t);
00214 }
00215
00216 base = complete_type (TYPE_MAIN_VARIANT (base));
00217
00218 if (t_binfo)
00219 {
00220 struct lookup_base_data_s data;
00221
00222 data.t = t;
00223 data.base = base;
00224 data.binfo = NULL_TREE;
00225 data.ambiguous = data.via_virtual = false;
00226 data.repeated_base = CLASSTYPE_REPEATED_BASE_P (t);
00227 data.want_any = access == ba_any;
00228
00229 dfs_walk_once (t_binfo, dfs_lookup_base, NULL, &data);
00230 binfo = data.binfo;
00231
00232 if (!binfo)
00233 bk = data.ambiguous ? bk_ambig : bk_not_base;
00234 else if (binfo == t_binfo)
00235 bk = bk_same_type;
00236 else if (data.via_virtual)
00237 bk = bk_via_virtual;
00238 else
00239 bk = bk_proper_base;
00240 }
00241 else
00242 {
00243 binfo = NULL_TREE;
00244 bk = bk_not_base;
00245 }
00246
00247
00248 if (access != ba_any)
00249 switch (bk)
00250 {
00251 case bk_not_base:
00252 break;
00253
00254 case bk_ambig:
00255 if (!(access & ba_quiet))
00256 {
00257 error ("%qT is an ambiguous base of %qT", base, t);
00258 binfo = error_mark_node;
00259 }
00260 break;
00261
00262 default:
00263 if ((access & ba_check_bit)
00264
00265
00266
00267
00268
00269
00270 && COMPLETE_TYPE_P (base)
00271 && !accessible_base_p (t, base, !(access & ba_ignore_scope)))
00272 {
00273 if (!(access & ba_quiet))
00274 {
00275 error ("%qT is an inaccessible base of %qT", base, t);
00276 binfo = error_mark_node;
00277 }
00278 else
00279 binfo = NULL_TREE;
00280 bk = bk_inaccessible;
00281 }
00282 break;
00283 }
00284
00285 if (kind_ptr)
00286 *kind_ptr = bk;
00287
00288 return binfo;
00289 }
00290
00291
00292
00293 struct dcast_data_s
00294 {
00295 tree subtype;
00296 int virt_depth;
00297
00298 tree offset;
00299 bool repeated_base;
00300
00301 };
00302
00303
00304
00305
00306 static tree
00307 dfs_dcast_hint_pre (tree binfo, void *data_)
00308 {
00309 struct dcast_data_s *data = (struct dcast_data_s *) data_;
00310
00311 if (BINFO_VIRTUAL_P (binfo))
00312 data->virt_depth++;
00313
00314 if (SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), data->subtype))
00315 {
00316 if (data->virt_depth)
00317 {
00318 data->offset = ssize_int (-1);
00319 return data->offset;
00320 }
00321 if (data->offset)
00322 data->offset = ssize_int (-3);
00323 else
00324 data->offset = BINFO_OFFSET (binfo);
00325
00326 return data->repeated_base ? dfs_skip_bases : data->offset;
00327 }
00328
00329 return NULL_TREE;
00330 }
00331
00332
00333
00334 static tree
00335 dfs_dcast_hint_post (tree binfo, void *data_)
00336 {
00337 struct dcast_data_s *data = (struct dcast_data_s *) data_;
00338
00339 if (BINFO_VIRTUAL_P (binfo))
00340 data->virt_depth--;
00341
00342 return NULL_TREE;
00343 }
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356 tree
00357 dcast_base_hint (tree subtype, tree target)
00358 {
00359 struct dcast_data_s data;
00360
00361 data.subtype = subtype;
00362 data.virt_depth = 0;
00363 data.offset = NULL_TREE;
00364 data.repeated_base = CLASSTYPE_REPEATED_BASE_P (target);
00365
00366 dfs_walk_once_accessible (TYPE_BINFO (target), false,
00367 dfs_dcast_hint_pre, dfs_dcast_hint_post, &data);
00368 return data.offset ? data.offset : ssize_int (-2);
00369 }
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381 tree
00382 lookup_field_1 (tree type, tree name, bool want_type)
00383 {
00384 tree field;
00385
00386 if (TREE_CODE (type) == TEMPLATE_TYPE_PARM
00387 || TREE_CODE (type) == BOUND_TEMPLATE_TEMPLATE_PARM
00388 || TREE_CODE (type) == TYPENAME_TYPE)
00389
00390
00391
00392
00393
00394
00395 return NULL_TREE;
00396
00397 if (TYPE_NAME (type)
00398 && DECL_LANG_SPECIFIC (TYPE_NAME (type))
00399 && DECL_SORTED_FIELDS (TYPE_NAME (type)))
00400 {
00401 tree *fields = &DECL_SORTED_FIELDS (TYPE_NAME (type))->elts[0];
00402 int lo = 0, hi = DECL_SORTED_FIELDS (TYPE_NAME (type))->len;
00403 int i;
00404
00405 while (lo < hi)
00406 {
00407 i = (lo + hi) / 2;
00408
00409 #ifdef GATHER_STATISTICS
00410 n_fields_searched++;
00411 #endif
00412
00413 if (DECL_NAME (fields[i]) > name)
00414 hi = i;
00415 else if (DECL_NAME (fields[i]) < name)
00416 lo = i + 1;
00417 else
00418 {
00419 field = NULL_TREE;
00420
00421
00422
00423
00424
00425 if (want_type)
00426 {
00427 do
00428 field = fields[i--];
00429 while (i >= lo && DECL_NAME (fields[i]) == name);
00430 if (TREE_CODE (field) != TYPE_DECL
00431 && !DECL_CLASS_TEMPLATE_P (field))
00432 field = NULL_TREE;
00433 }
00434 else
00435 {
00436 do
00437 field = fields[i++];
00438 while (i < hi && DECL_NAME (fields[i]) == name);
00439 }
00440 return field;
00441 }
00442 }
00443 return NULL_TREE;
00444 }
00445
00446 field = TYPE_FIELDS (type);
00447
00448 #ifdef GATHER_STATISTICS
00449 n_calls_lookup_field_1++;
00450 #endif
00451 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
00452 {
00453 #ifdef GATHER_STATISTICS
00454 n_fields_searched++;
00455 #endif
00456 gcc_assert (DECL_P (field));
00457 if (DECL_NAME (field) == NULL_TREE
00458 && ANON_AGGR_TYPE_P (TREE_TYPE (field)))
00459 {
00460 tree temp = lookup_field_1 (TREE_TYPE (field), name, want_type);
00461 if (temp)
00462 return temp;
00463 }
00464 if (TREE_CODE (field) == USING_DECL)
00465 {
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475 if (!DECL_DEPENDENT_P (field))
00476 continue;
00477 }
00478
00479 if (DECL_NAME (field) == name
00480 && (!want_type
00481 || TREE_CODE (field) == TYPE_DECL
00482 || DECL_CLASS_TEMPLATE_P (field)))
00483 return field;
00484 }
00485
00486 if (name == vptr_identifier)
00487 {
00488
00489 if (TYPE_POLYMORPHIC_P (type))
00490 return TYPE_VFIELD (type);
00491 }
00492 return NULL_TREE;
00493 }
00494
00495
00496
00497
00498 tree
00499 current_scope (void)
00500 {
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516 if (current_function_decl && current_class_type
00517 && ((DECL_FUNCTION_MEMBER_P (current_function_decl)
00518 && same_type_p (DECL_CONTEXT (current_function_decl),
00519 current_class_type))
00520 || (DECL_FRIEND_CONTEXT (current_function_decl)
00521 && same_type_p (DECL_FRIEND_CONTEXT (current_function_decl),
00522 current_class_type))))
00523 return current_function_decl;
00524 if (current_class_type)
00525 return current_class_type;
00526 if (current_function_decl)
00527 return current_function_decl;
00528 return current_namespace;
00529 }
00530
00531
00532
00533
00534
00535 int
00536 at_function_scope_p (void)
00537 {
00538 tree cs = current_scope ();
00539 return cs && TREE_CODE (cs) == FUNCTION_DECL;
00540 }
00541
00542
00543
00544 bool
00545 at_class_scope_p (void)
00546 {
00547 tree cs = current_scope ();
00548 return cs && TYPE_P (cs);
00549 }
00550
00551
00552
00553 bool
00554 at_namespace_scope_p (void)
00555 {
00556 tree cs = current_scope ();
00557 return cs && TREE_CODE (cs) == NAMESPACE_DECL;
00558 }
00559
00560
00561
00562 tree
00563 context_for_name_lookup (tree decl)
00564 {
00565
00566
00567
00568
00569
00570
00571 tree context = DECL_CONTEXT (decl);
00572
00573 while (context && TYPE_P (context) && ANON_AGGR_TYPE_P (context))
00574 context = TYPE_CONTEXT (context);
00575 if (!context)
00576 context = global_namespace;
00577
00578 return context;
00579 }
00580
00581
00582
00583
00584 #define BINFO_ACCESS(NODE) \
00585 ((access_kind) ((TREE_PUBLIC (NODE) << 1) | TREE_PRIVATE (NODE)))
00586
00587
00588
00589 #define SET_BINFO_ACCESS(NODE, ACCESS) \
00590 ((TREE_PUBLIC (NODE) = ((ACCESS) & 2) != 0), \
00591 (TREE_PRIVATE (NODE) = ((ACCESS) & 1) != 0))
00592
00593
00594
00595
00596 static tree
00597 dfs_access_in_type (tree binfo, void *data)
00598 {
00599 tree decl = (tree) data;
00600 tree type = BINFO_TYPE (binfo);
00601 access_kind access = ak_none;
00602
00603 if (context_for_name_lookup (decl) == type)
00604 {
00605
00606
00607 if (TREE_PRIVATE (decl))
00608 access = ak_private;
00609 else if (TREE_PROTECTED (decl))
00610 access = ak_protected;
00611 else
00612 access = ak_public;
00613 }
00614 else
00615 {
00616
00617
00618
00619
00620 if (DECL_LANG_SPECIFIC (decl) && !DECL_DISCRIMINATOR_P (decl))
00621 {
00622 tree decl_access = purpose_member (type, DECL_ACCESS (decl));
00623
00624 if (decl_access)
00625 {
00626 decl_access = TREE_VALUE (decl_access);
00627
00628 if (decl_access == access_public_node)
00629 access = ak_public;
00630 else if (decl_access == access_protected_node)
00631 access = ak_protected;
00632 else if (decl_access == access_private_node)
00633 access = ak_private;
00634 else
00635 gcc_unreachable ();
00636 }
00637 }
00638
00639 if (!access)
00640 {
00641 int i;
00642 tree base_binfo;
00643 VEC(tree,gc) *accesses;
00644
00645
00646
00647 accesses = BINFO_BASE_ACCESSES (binfo);
00648 for (i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
00649 {
00650 tree base_access = VEC_index (tree, accesses, i);
00651 access_kind base_access_now = BINFO_ACCESS (base_binfo);
00652
00653 if (base_access_now == ak_none || base_access_now == ak_private)
00654
00655
00656
00657 base_access_now = ak_none;
00658 else if (base_access == access_protected_node)
00659
00660
00661 base_access_now = ak_protected;
00662 else if (base_access == access_private_node)
00663
00664
00665 base_access_now = ak_private;
00666
00667
00668
00669 if (base_access_now != ak_none
00670 && (access == ak_none || base_access_now < access))
00671 {
00672 access = base_access_now;
00673
00674
00675 if (access == ak_public)
00676 break;
00677 }
00678 }
00679 }
00680 }
00681
00682
00683 SET_BINFO_ACCESS (binfo, access);
00684
00685 return NULL_TREE;
00686 }
00687
00688
00689
00690 static access_kind
00691 access_in_type (tree type, tree decl)
00692 {
00693 tree binfo = TYPE_BINFO (type);
00694
00695
00696
00697
00698
00699
00700
00701
00702
00703
00704
00705
00706 dfs_walk_once (binfo, NULL, dfs_access_in_type, decl);
00707
00708 return BINFO_ACCESS (binfo);
00709 }
00710
00711
00712
00713
00714 static int
00715 protected_accessible_p (tree decl, tree derived, tree binfo)
00716 {
00717 access_kind access;
00718
00719
00720
00721
00722
00723
00724
00725
00726
00727
00728
00729
00730
00731
00732
00733
00734
00735
00736 if (!DERIVED_FROM_P (context_for_name_lookup (decl), derived))
00737 return 0;
00738
00739 access = access_in_type (derived, decl);
00740
00741
00742 if (access == ak_none)
00743 return 0;
00744
00745
00746
00747
00748
00749
00750
00751
00752
00753
00754
00755
00756 if (DECL_NONSTATIC_MEMBER_P (decl))
00757 {
00758
00759
00760 tree t = binfo;
00761 while (BINFO_INHERITANCE_CHAIN (t))
00762 t = BINFO_INHERITANCE_CHAIN (t);
00763
00764 if (!DERIVED_FROM_P (derived, BINFO_TYPE (t)))
00765 return 0;
00766 }
00767
00768 return 1;
00769 }
00770
00771
00772
00773
00774 static int
00775 friend_accessible_p (tree scope, tree decl, tree binfo)
00776 {
00777 tree befriending_classes;
00778 tree t;
00779
00780 if (!scope)
00781 return 0;
00782
00783 if (TREE_CODE (scope) == FUNCTION_DECL
00784 || DECL_FUNCTION_TEMPLATE_P (scope))
00785 befriending_classes = DECL_BEFRIENDING_CLASSES (scope);
00786 else if (TYPE_P (scope))
00787 befriending_classes = CLASSTYPE_BEFRIENDING_CLASSES (scope);
00788 else
00789 return 0;
00790
00791 for (t = befriending_classes; t; t = TREE_CHAIN (t))
00792 if (protected_accessible_p (decl, TREE_VALUE (t), binfo))
00793 return 1;
00794
00795
00796
00797 if (TYPE_P (scope))
00798 for (t = TYPE_CONTEXT (scope); t && TYPE_P (t); t = TYPE_CONTEXT (t))
00799 if (protected_accessible_p (decl, t, binfo))
00800 return 1;
00801
00802 if (TREE_CODE (scope) == FUNCTION_DECL
00803 || DECL_FUNCTION_TEMPLATE_P (scope))
00804 {
00805
00806
00807 if (DECL_CLASS_SCOPE_P (scope)
00808 && friend_accessible_p (DECL_CONTEXT (scope), decl, binfo))
00809 return 1;
00810
00811
00812 if (DECL_TEMPLATE_INFO (scope))
00813 {
00814 int ret;
00815
00816
00817 ++processing_template_decl;
00818 ret = friend_accessible_p (DECL_TI_TEMPLATE (scope), decl, binfo);
00819 --processing_template_decl;
00820 return ret;
00821 }
00822 }
00823
00824 return 0;
00825 }
00826
00827
00828
00829 static tree
00830 dfs_accessible_post (tree binfo, void *data ATTRIBUTE_UNUSED)
00831 {
00832 if (BINFO_ACCESS (binfo) != ak_none)
00833 {
00834 tree scope = current_scope ();
00835 if (scope && TREE_CODE (scope) != NAMESPACE_DECL
00836 && is_friend (BINFO_TYPE (binfo), scope))
00837 return binfo;
00838 }
00839
00840 return NULL_TREE;
00841 }
00842
00843
00844
00845
00846
00847
00848
00849
00850
00851 int
00852 accessible_p (tree type, tree decl, bool consider_local_p)
00853 {
00854 tree binfo;
00855 tree scope;
00856 access_kind access;
00857
00858
00859
00860 int protected_ok = 0;
00861
00862
00863
00864 if (!TYPE_P (context_for_name_lookup (decl)))
00865 return 1;
00866
00867
00868 scope = current_scope ();
00869 if (scope && DECL_THUNK_P (scope))
00870 return 1;
00871
00872
00873
00874
00875
00876
00877
00878
00879 if (processing_template_decl
00880 && (!processing_template_parmlist || processing_template_decl > 1))
00881 return 1;
00882
00883 if (!TYPE_P (type))
00884 {
00885 binfo = type;
00886 type = BINFO_TYPE (type);
00887 }
00888 else
00889 binfo = TYPE_BINFO (type);
00890
00891
00892
00893
00894
00895
00896
00897
00898
00899
00900
00901
00902
00903
00904
00905
00906
00907
00908
00909
00910 if (consider_local_p)
00911 {
00912
00913
00914
00915 if (current_class_type)
00916 protected_ok = protected_accessible_p (decl,
00917 current_class_type, binfo);
00918
00919
00920 if (!protected_ok)
00921 protected_ok = friend_accessible_p (scope, decl, binfo);
00922 }
00923
00924
00925
00926 binfo = TYPE_BINFO (type);
00927
00928
00929
00930 access = access_in_type (type, decl);
00931 if (access == ak_public
00932 || (access == ak_protected && protected_ok))
00933 return 1;
00934
00935 if (!consider_local_p)
00936 return 0;
00937
00938
00939
00940 return dfs_walk_once_accessible (binfo, true,
00941 NULL, dfs_accessible_post, NULL)
00942 != NULL_TREE;
00943 }
00944
00945 struct lookup_field_info {
00946
00947 tree type;
00948
00949 tree name;
00950
00951 tree rval;
00952
00953 tree rval_binfo;
00954
00955
00956 tree ambiguous;
00957
00958 int want_type;
00959
00960 const char *errstr;
00961 };
00962
00963
00964
00965
00966
00967
00968
00969
00970
00971 static int
00972 template_self_reference_p (tree type, tree decl)
00973 {
00974 return (CLASSTYPE_USE_TEMPLATE (type)
00975 && PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (type))
00976 && TREE_CODE (decl) == TYPE_DECL
00977 && DECL_ARTIFICIAL (decl)
00978 && DECL_NAME (decl) == constructor_name (type));
00979 }
00980
00981
00982
00983
00984
00985
00986
00987
00988
00989
00990
00991 int
00992 shared_member_p (tree t)
00993 {
00994 if (TREE_CODE (t) == VAR_DECL || TREE_CODE (t) == TYPE_DECL \
00995 || TREE_CODE (t) == CONST_DECL)
00996 return 1;
00997 if (is_overloaded_fn (t))
00998 {
00999 for (; t; t = OVL_NEXT (t))
01000 {
01001 tree fn = OVL_CURRENT (t);
01002 if (DECL_NONSTATIC_MEMBER_FUNCTION_P (fn))
01003 return 0;
01004 }
01005 return 1;
01006 }
01007 return 0;
01008 }
01009
01010
01011
01012
01013
01014 static int
01015 is_subobject_of_p (tree parent, tree binfo)
01016 {
01017 tree probe;
01018
01019 for (probe = parent; probe; probe = BINFO_INHERITANCE_CHAIN (probe))
01020 {
01021 if (probe == binfo)
01022 return 1;
01023 if (BINFO_VIRTUAL_P (probe))
01024 return (binfo_for_vbase (BINFO_TYPE (probe), BINFO_TYPE (binfo))
01025 != NULL_TREE);
01026 }
01027 return 0;
01028 }
01029
01030
01031
01032
01033
01034
01035 static tree
01036 lookup_field_r (tree binfo, void *data)
01037 {
01038 struct lookup_field_info *lfi = (struct lookup_field_info *) data;
01039 tree type = BINFO_TYPE (binfo);
01040 tree nval = NULL_TREE;
01041
01042
01043 if (BINFO_DEPENDENT_BASE_P (binfo))
01044 return NULL_TREE;
01045
01046
01047
01048 if (lfi->rval_binfo && BINFO_INHERITANCE_CHAIN (binfo) == lfi->rval_binfo
01049 && !BINFO_VIRTUAL_P (binfo))
01050 return dfs_skip_bases;
01051
01052
01053
01054
01055 if (!lfi->want_type)
01056 {
01057 int idx = lookup_fnfields_1 (type, lfi->name);
01058 if (idx >= 0)
01059 nval = VEC_index (tree, CLASSTYPE_METHOD_VEC (type), idx);
01060 }
01061
01062 if (!nval)
01063
01064 nval = lookup_field_1 (type, lfi->name, lfi->want_type);
01065
01066
01067
01068 if (!nval)
01069 goto done;
01070
01071
01072
01073 if (lfi->want_type && TREE_CODE (nval) != TYPE_DECL
01074 && !DECL_CLASS_TEMPLATE_P (nval))
01075 {
01076 if (lfi->name == TYPE_IDENTIFIER (type))
01077 {
01078
01079
01080
01081
01082 for (nval = TREE_CHAIN (nval); nval; nval = TREE_CHAIN (nval))
01083 if (DECL_NAME (nval) == lfi->name
01084 && TREE_CODE (nval) == TYPE_DECL)
01085 break;
01086 }
01087 else
01088 nval = NULL_TREE;
01089 if (!nval && CLASSTYPE_NESTED_UTDS (type) != NULL)
01090 {
01091 binding_entry e = binding_table_find (CLASSTYPE_NESTED_UTDS (type),
01092 lfi->name);
01093 if (e != NULL)
01094 nval = TYPE_MAIN_DECL (e->type);
01095 else
01096 goto done;
01097 }
01098 }
01099
01100
01101 if (!same_type_p (type, lfi->type)
01102 && template_self_reference_p (type, nval))
01103 goto done;
01104
01105
01106
01107 if (lfi->rval_binfo
01108 && !is_subobject_of_p (lfi->rval_binfo, binfo))
01109
01110 {
01111 if (nval == lfi->rval && shared_member_p (nval))
01112
01113 ;
01114 else if (is_subobject_of_p (binfo, lfi->rval_binfo))
01115
01116 ;
01117 else
01118 {
01119
01120
01121 if (!lfi->ambiguous && lfi->rval)
01122 {
01123
01124
01125
01126 lfi->ambiguous = tree_cons (NULL_TREE, lfi->rval, NULL_TREE);
01127 TREE_TYPE (lfi->ambiguous) = error_mark_node;
01128 }
01129
01130
01131 lfi->ambiguous = tree_cons (NULL_TREE, nval, lfi->ambiguous);
01132 TREE_TYPE (lfi->ambiguous) = error_mark_node;
01133 lfi->errstr = "request for member %qD is ambiguous";
01134 }
01135 }
01136 else
01137 {
01138 lfi->rval = nval;
01139 lfi->rval_binfo = binfo;
01140 }
01141
01142 done:
01143
01144 if (IDENTIFIER_CTOR_OR_DTOR_P (lfi->name))
01145 return dfs_skip_bases;
01146 return NULL_TREE;
01147 }
01148
01149
01150
01151
01152
01153 tree
01154 build_baselink (tree binfo, tree access_binfo, tree functions, tree optype)
01155 {
01156 tree baselink;
01157
01158 gcc_assert (TREE_CODE (functions) == FUNCTION_DECL
01159 || TREE_CODE (functions) == TEMPLATE_DECL
01160 || TREE_CODE (functions) == TEMPLATE_ID_EXPR
01161 || TREE_CODE (functions) == OVERLOAD);
01162 gcc_assert (!optype || TYPE_P (optype));
01163 gcc_assert (TREE_TYPE (functions));
01164
01165 baselink = make_node (BASELINK);
01166 TREE_TYPE (baselink) = TREE_TYPE (functions);
01167 BASELINK_BINFO (baselink) = binfo;
01168 BASELINK_ACCESS_BINFO (baselink) = access_binfo;
01169 BASELINK_FUNCTIONS (baselink) = functions;
01170 BASELINK_OPTYPE (baselink) = optype;
01171
01172 return baselink;
01173 }
01174
01175
01176
01177
01178
01179
01180
01181
01182
01183
01184
01185
01186
01187 tree
01188 lookup_member (tree xbasetype, tree name, int protect, bool want_type)
01189 {
01190 tree rval, rval_binfo = NULL_TREE;
01191 tree type = NULL_TREE, basetype_path = NULL_TREE;
01192 struct lookup_field_info lfi;
01193
01194
01195
01196
01197
01198
01199
01200
01201 const char *errstr = 0;
01202
01203 gcc_assert (TREE_CODE (name) == IDENTIFIER_NODE);
01204
01205 if (TREE_CODE (xbasetype) == TREE_BINFO)
01206 {
01207 type = BINFO_TYPE (xbasetype);
01208 basetype_path = xbasetype;
01209 }
01210 else
01211 {
01212 if (!IS_AGGR_TYPE_CODE (TREE_CODE (xbasetype)))
01213 return NULL_TREE;
01214 type = xbasetype;
01215 xbasetype = NULL_TREE;
01216 }
01217
01218 type = complete_type (type);
01219 if (!basetype_path)
01220 basetype_path = TYPE_BINFO (type);
01221
01222 if (!basetype_path)
01223 return NULL_TREE;
01224
01225 #ifdef GATHER_STATISTICS
01226 n_calls_lookup_field++;
01227 #endif
01228
01229 memset (&lfi, 0, sizeof (lfi));
01230 lfi.type = type;
01231 lfi.name = name;
01232 lfi.want_type = want_type;
01233 dfs_walk_all (basetype_path, &lookup_field_r, NULL, &lfi);
01234 rval = lfi.rval;
01235 rval_binfo = lfi.rval_binfo;
01236 if (rval_binfo)
01237 type = BINFO_TYPE (rval_binfo);
01238 errstr = lfi.errstr;
01239
01240
01241
01242 if (!protect && lfi.ambiguous)
01243 return NULL_TREE;
01244
01245 if (protect == 2)
01246 {
01247 if (lfi.ambiguous)
01248 return lfi.ambiguous;
01249 else
01250 protect = 0;
01251 }
01252
01253
01254
01255
01256
01257
01258
01259
01260
01261
01262
01263
01264
01265
01266
01267
01268
01269
01270
01271
01272 if (rval && protect
01273 && !really_overloaded_fn (rval)
01274 && !(TREE_CODE (rval) == FUNCTION_DECL
01275 && DECL_NONSTATIC_MEMBER_FUNCTION_P (rval)))
01276 perform_or_defer_access_check (basetype_path, rval, rval);
01277
01278 if (errstr && protect)
01279 {
01280 error (errstr, name, type);
01281 if (lfi.ambiguous)
01282 print_candidates (lfi.ambiguous);
01283 rval = error_mark_node;
01284 }
01285
01286 if (rval && is_overloaded_fn (rval))
01287 rval = build_baselink (rval_binfo, basetype_path, rval,
01288 (IDENTIFIER_TYPENAME_P (name)
01289 ? TREE_TYPE (name): NULL_TREE));
01290 return rval;
01291 }
01292
01293
01294
01295
01296 tree
01297 lookup_field (tree xbasetype, tree name, int protect, bool want_type)
01298 {
01299 tree rval = lookup_member (xbasetype, name, protect, want_type);
01300
01301
01302 if (!error_operand_p (rval)
01303 && (rval && BASELINK_P (rval)))
01304 return NULL_TREE;
01305
01306 return rval;
01307 }
01308
01309
01310
01311
01312 tree
01313 lookup_fnfields (tree xbasetype, tree name, int protect)
01314 {
01315 tree rval = lookup_member (xbasetype, name, protect, false);
01316
01317
01318 if (!error_operand_p (rval)
01319 && (rval && !BASELINK_P (rval)))
01320 return NULL_TREE;
01321
01322 return rval;
01323 }
01324
01325
01326
01327
01328
01329
01330 static int
01331 lookup_conversion_operator (tree class_type, tree type)
01332 {
01333 int tpl_slot = -1;
01334
01335 if (TYPE_HAS_CONVERSION (class_type))
01336 {
01337 int i;
01338 tree fn;
01339 VEC(tree,gc) *methods = CLASSTYPE_METHOD_VEC (class_type);
01340
01341 for (i = CLASSTYPE_FIRST_CONVERSION_SLOT;
01342 VEC_iterate (tree, methods, i, fn); ++i)
01343 {
01344
01345
01346
01347
01348 fn = OVL_CURRENT (fn);
01349 if (!DECL_CONV_FN_P (fn))
01350 break;
01351
01352 if (TREE_CODE (fn) == TEMPLATE_DECL)
01353
01354
01355 tpl_slot = i;
01356 else if (same_type_p (DECL_CONV_FN_TYPE (fn), type))
01357 return i;
01358 }
01359 }
01360
01361 return tpl_slot;
01362 }
01363
01364
01365
01366
01367 int
01368 lookup_fnfields_1 (tree type, tree name)
01369 {
01370 VEC(tree,gc) *method_vec;
01371 tree fn;
01372 tree tmp;
01373 size_t i;
01374
01375 if (!CLASS_TYPE_P (type))
01376 return -1;
01377
01378 if (COMPLETE_TYPE_P (type))
01379 {
01380 if ((name == ctor_identifier
01381 || name == base_ctor_identifier
01382 || name == complete_ctor_identifier))
01383 {
01384 if (CLASSTYPE_LAZY_DEFAULT_CTOR (type))
01385 lazily_declare_fn (sfk_constructor, type);
01386 if (CLASSTYPE_LAZY_COPY_CTOR (type))
01387 lazily_declare_fn (sfk_copy_constructor, type);
01388 }
01389 else if (name == ansi_assopname(NOP_EXPR)
01390 && CLASSTYPE_LAZY_ASSIGNMENT_OP (type))
01391 lazily_declare_fn (sfk_assignment_operator, type);
01392 else if ((name == dtor_identifier
01393 || name == base_dtor_identifier
01394 || name == complete_dtor_identifier
01395 || name == deleting_dtor_identifier)
01396 && CLASSTYPE_LAZY_DESTRUCTOR (type))
01397 lazily_declare_fn (sfk_destructor, type);
01398 }
01399
01400 method_vec = CLASSTYPE_METHOD_VEC (type);
01401 if (!method_vec)
01402 return -1;
01403
01404 #ifdef GATHER_STATISTICS
01405 n_calls_lookup_fnfields_1++;
01406 #endif
01407
01408
01409 if (name == ctor_identifier)
01410 {
01411 fn = CLASSTYPE_CONSTRUCTORS (type);
01412 return fn ? CLASSTYPE_CONSTRUCTOR_SLOT : -1;
01413 }
01414
01415 if (name == dtor_identifier)
01416 {
01417 fn = CLASSTYPE_DESTRUCTORS (type);
01418 return fn ? CLASSTYPE_DESTRUCTOR_SLOT : -1;
01419 }
01420 if (IDENTIFIER_TYPENAME_P (name))
01421 return lookup_conversion_operator (type, TREE_TYPE (name));
01422
01423
01424 for (i = CLASSTYPE_FIRST_CONVERSION_SLOT;
01425 VEC_iterate (tree, method_vec, i, fn);
01426 ++i)
01427 if (!DECL_CONV_FN_P (OVL_CURRENT (fn)))
01428 break;
01429
01430
01431 if (COMPLETE_TYPE_P (type))
01432 {
01433 int lo;
01434 int hi;
01435
01436 lo = i;
01437 hi = VEC_length (tree, method_vec);
01438 while (lo < hi)
01439 {
01440 i = (lo + hi) / 2;
01441
01442 #ifdef GATHER_STATISTICS
01443 n_outer_fields_searched++;
01444 #endif
01445
01446 tmp = VEC_index (tree, method_vec, i);
01447 tmp = DECL_NAME (OVL_CURRENT (tmp));
01448 if (tmp > name)
01449 hi = i;
01450 else if (tmp < name)
01451 lo = i + 1;
01452 else
01453 return i;
01454 }
01455 }
01456 else
01457 for (; VEC_iterate (tree, method_vec, i, fn); ++i)
01458 {
01459 #ifdef GATHER_STATISTICS
01460 n_outer_fields_searched++;
01461 #endif
01462 if (DECL_NAME (OVL_CURRENT (fn)) == name)
01463 return i;
01464 }
01465
01466 return -1;
01467 }
01468
01469
01470
01471
01472 int
01473 class_method_index_for_fn (tree class_type, tree function)
01474 {
01475 gcc_assert (TREE_CODE (function) == FUNCTION_DECL
01476 || DECL_FUNCTION_TEMPLATE_P (function));
01477
01478 return lookup_fnfields_1 (class_type,
01479 DECL_CONSTRUCTOR_P (function) ? ctor_identifier :
01480 DECL_DESTRUCTOR_P (function) ? dtor_identifier :
01481 DECL_NAME (function));
01482 }
01483
01484
01485
01486
01487
01488
01489
01490
01491
01492
01493
01494
01495
01496 tree
01497 adjust_result_of_qualified_name_lookup (tree decl,
01498 tree qualifying_scope,
01499 tree context_class)
01500 {
01501 if (context_class && context_class != error_mark_node
01502 && CLASS_TYPE_P (context_class)
01503 && CLASS_TYPE_P (qualifying_scope)
01504 && DERIVED_FROM_P (qualifying_scope, context_class)
01505 && BASELINK_P (decl))
01506 {
01507 tree base;
01508
01509
01510
01511
01512
01513
01514 base = lookup_base (context_class, qualifying_scope,
01515 ba_unique | ba_quiet, NULL);
01516 if (base)
01517 {
01518 BASELINK_ACCESS_BINFO (decl) = base;
01519 BASELINK_BINFO (decl)
01520 = lookup_base (base, BINFO_TYPE (BASELINK_BINFO (decl)),
01521 ba_unique | ba_quiet,
01522 NULL);
01523 }
01524 }
01525
01526 return decl;
01527 }
01528
01529
01530
01531
01532
01533
01534
01535
01536
01537
01538
01539
01540 tree
01541 dfs_walk_all (tree binfo, tree (*pre_fn) (tree, void *),
01542 tree (*post_fn) (tree, void *), void *data)
01543 {
01544 tree rval;
01545 unsigned ix;
01546 tree base_binfo;
01547
01548
01549 if (pre_fn)
01550 {
01551 rval = pre_fn (binfo, data);
01552 if (rval)
01553 {
01554 if (rval == dfs_skip_bases)
01555 goto skip_bases;
01556 return rval;
01557 }
01558 }
01559
01560
01561 for (ix = 0; BINFO_BASE_ITERATE (binfo, ix, base_binfo); ix++)
01562 {
01563 rval = dfs_walk_all (base_binfo, pre_fn, post_fn, data);
01564 if (rval)
01565 return rval;
01566 }
01567
01568 skip_bases:
01569
01570 if (post_fn)
01571 {
01572 rval = post_fn (binfo, data);
01573 gcc_assert (rval != dfs_skip_bases);
01574 return rval;
01575 }
01576
01577 return NULL_TREE;
01578 }
01579
01580
01581
01582
01583 static tree
01584 dfs_walk_once_r (tree binfo, tree (*pre_fn) (tree, void *),
01585 tree (*post_fn) (tree, void *), void *data)
01586 {
01587 tree rval;
01588 unsigned ix;
01589 tree base_binfo;
01590
01591
01592 if (pre_fn)
01593 {
01594 rval = pre_fn (binfo, data);
01595 if (rval)
01596 {
01597 if (rval == dfs_skip_bases)
01598 goto skip_bases;
01599
01600 return rval;
01601 }
01602 }
01603
01604
01605 for (ix = 0; BINFO_BASE_ITERATE (binfo, ix, base_binfo); ix++)
01606 {
01607 if (BINFO_VIRTUAL_P (base_binfo))
01608 {
01609 if (BINFO_MARKED (base_binfo))
01610 continue;
01611 BINFO_MARKED (base_binfo) = 1;
01612 }
01613
01614 rval = dfs_walk_once_r (base_binfo, pre_fn, post_fn, data);
01615 if (rval)
01616 return rval;
01617 }
01618
01619 skip_bases:
01620
01621 if (post_fn)
01622 {
01623 rval = post_fn (binfo, data);
01624 gcc_assert (rval != dfs_skip_bases);
01625 return rval;
01626 }
01627
01628 return NULL_TREE;
01629 }
01630
01631
01632
01633
01634 static void
01635 dfs_unmark_r (tree binfo)
01636 {
01637 unsigned ix;
01638 tree base_binfo;
01639
01640
01641 for (ix = 0; BINFO_BASE_ITERATE (binfo, ix, base_binfo); ix++)
01642 {
01643 if (BINFO_VIRTUAL_P (base_binfo))
01644 {
01645 if (!BINFO_MARKED (base_binfo))
01646 continue;
01647 BINFO_MARKED (base_binfo) = 0;
01648 }
01649
01650 if (CLASSTYPE_VBASECLASSES (BINFO_TYPE (base_binfo)))
01651 dfs_unmark_r (base_binfo);
01652 }
01653 }
01654
01655
01656
01657
01658
01659
01660 tree
01661 dfs_walk_once (tree binfo, tree (*pre_fn) (tree, void *),
01662 tree (*post_fn) (tree, void *), void *data)
01663 {
01664 static int active = 0;
01665 tree rval;
01666
01667 gcc_assert (pre_fn || post_fn);
01668 gcc_assert (!active);
01669 active++;
01670
01671 if (!CLASSTYPE_DIAMOND_SHAPED_P (BINFO_TYPE (binfo)))
01672
01673
01674 rval = dfs_walk_all (binfo, pre_fn, post_fn, data);
01675 else
01676 {
01677 rval = dfs_walk_once_r (binfo, pre_fn, post_fn, data);
01678 if (!BINFO_INHERITANCE_CHAIN (binfo))
01679 {
01680
01681
01682
01683 VEC(tree,gc) *vbases;
01684 unsigned ix;
01685 tree base_binfo;
01686
01687 for (vbases = CLASSTYPE_VBASECLASSES (BINFO_TYPE (binfo)), ix = 0;
01688 VEC_iterate (tree, vbases, ix, base_binfo); ix++)
01689 BINFO_MARKED (base_binfo) = 0;
01690 }
01691 else
01692 dfs_unmark_r (binfo);
01693 }
01694
01695 active--;
01696
01697 return rval;
01698 }
01699
01700
01701
01702
01703
01704
01705 static tree
01706 dfs_walk_once_accessible_r (tree binfo, bool friends_p, bool once,
01707 tree (*pre_fn) (tree, void *),
01708 tree (*post_fn) (tree, void *), void *data)
01709 {
01710 tree rval = NULL_TREE;
01711 unsigned ix;
01712 tree base_binfo;
01713
01714
01715 if (pre_fn)
01716 {
01717 rval = pre_fn (binfo, data);
01718 if (rval)
01719 {
01720 if (rval == dfs_skip_bases)
01721 goto skip_bases;
01722
01723 return rval;
01724 }
01725 }
01726
01727
01728 for (ix = 0; BINFO_BASE_ITERATE (binfo, ix, base_binfo); ix++)
01729 {
01730 bool mark = once && BINFO_VIRTUAL_P (base_binfo);
01731
01732 if (mark && BINFO_MARKED (base_binfo))
01733 continue;
01734
01735
01736
01737
01738 if (BINFO_BASE_ACCESS (binfo, ix) != access_public_node)
01739 {
01740 tree scope;
01741 if (!friends_p)
01742 continue;
01743 scope = current_scope ();
01744 if (!scope
01745 || TREE_CODE (scope) == NAMESPACE_DECL
01746 || !is_friend (BINFO_TYPE (binfo), scope))
01747 continue;
01748 }
01749
01750 if (mark)
01751 BINFO_MARKED (base_binfo) = 1;
01752
01753 rval = dfs_walk_once_accessible_r (base_binfo, friends_p, once,
01754 pre_fn, post_fn, data);
01755 if (rval)
01756 return rval;
01757 }
01758
01759 skip_bases:
01760
01761 if (post_fn)
01762 {
01763 rval = post_fn (binfo, data);
01764 gcc_assert (rval != dfs_skip_bases);
01765 return rval;
01766 }
01767
01768 return NULL_TREE;
01769 }
01770
01771
01772
01773
01774
01775 static tree
01776 dfs_walk_once_accessible (tree binfo, bool friends_p,
01777 tree (*pre_fn) (tree, void *),
01778 tree (*post_fn) (tree, void *), void *data)
01779 {
01780 bool diamond_shaped = CLASSTYPE_DIAMOND_SHAPED_P (BINFO_TYPE (binfo));
01781 tree rval = dfs_walk_once_accessible_r (binfo, friends_p, diamond_shaped,
01782 pre_fn, post_fn, data);
01783
01784 if (diamond_shaped)
01785 {
01786 if (!BINFO_INHERITANCE_CHAIN (binfo))
01787 {
01788
01789
01790
01791 VEC(tree,gc) *vbases;
01792 unsigned ix;
01793 tree base_binfo;
01794
01795 for (vbases = CLASSTYPE_VBASECLASSES (BINFO_TYPE (binfo)), ix = 0;
01796 VEC_iterate (tree, vbases, ix, base_binfo); ix++)
01797 BINFO_MARKED (base_binfo) = 0;
01798 }
01799 else
01800 dfs_unmark_r (binfo);
01801 }
01802 return rval;
01803 }
01804
01805
01806
01807
01808 static int
01809 check_final_overrider (tree overrider, tree basefn)
01810 {
01811 tree over_type = TREE_TYPE (overrider);
01812 tree base_type = TREE_TYPE (basefn);
01813 tree over_return = TREE_TYPE (over_type);
01814 tree base_return = TREE_TYPE (base_type);
01815 tree over_throw = TYPE_RAISES_EXCEPTIONS (over_type);
01816 tree base_throw = TYPE_RAISES_EXCEPTIONS (base_type);
01817 int fail = 0;
01818
01819 if (DECL_INVALID_OVERRIDER_P (overrider))
01820 return 0;
01821
01822 if (same_type_p (base_return, over_return))
01823 ;
01824 else if ((CLASS_TYPE_P (over_return) && CLASS_TYPE_P (base_return))
01825 || (TREE_CODE (base_return) == TREE_CODE (over_return)
01826 && POINTER_TYPE_P (base_return)))
01827 {
01828
01829 unsigned base_quals, over_quals;
01830
01831 fail = !POINTER_TYPE_P (base_return);
01832 if (!fail)
01833 {
01834 fail = cp_type_quals (base_return) != cp_type_quals (over_return);
01835
01836 base_return = TREE_TYPE (base_return);
01837 over_return = TREE_TYPE (over_return);
01838 }
01839 base_quals = cp_type_quals (base_return);
01840 over_quals = cp_type_quals (over_return);
01841
01842 if ((base_quals & over_quals) != over_quals)
01843 fail = 1;
01844
01845 if (CLASS_TYPE_P (base_return) && CLASS_TYPE_P (over_return))
01846 {
01847 tree binfo = lookup_base (over_return, base_return,
01848 ba_check | ba_quiet, NULL);
01849
01850 if (!binfo)
01851 fail = 1;
01852 }
01853 else if (!pedantic
01854 && can_convert (TREE_TYPE (base_type), TREE_TYPE (over_type)))
01855
01856
01857 {
01858
01859
01860 over_return = non_reference (TREE_TYPE (over_type));
01861 if (CLASS_TYPE_P (over_return))
01862 fail = 2;
01863 else
01864 {
01865 warning (0, "deprecated covariant return type for %q+#D",
01866 overrider);
01867 warning (0, " overriding %q+#D", basefn);
01868 }
01869 }
01870 else
01871 fail = 2;
01872 }
01873 else
01874 fail = 2;
01875 if (!fail)
01876 ;
01877 else
01878 {
01879 if (fail == 1)
01880 {
01881 error ("invalid covariant return type for %q+#D", overrider);
01882 error (" overriding %q+#D", basefn);
01883 }
01884 else
01885 {
01886 error ("conflicting return type specified for %q+#D", overrider);
01887 error (" overriding %q+#D", basefn);
01888 }
01889 DECL_INVALID_OVERRIDER_P (overrider) = 1;
01890 return 0;
01891 }
01892
01893
01894 if (!comp_except_specs (base_throw, over_throw, 0))
01895 {
01896 error ("looser throw specifier for %q+#F", overrider);
01897 error (" overriding %q+#F", basefn);
01898 DECL_INVALID_OVERRIDER_P (overrider) = 1;
01899 return 0;
01900 }
01901
01902 return 1;
01903 }
01904
01905
01906
01907
01908
01909
01910
01911
01912
01913
01914
01915 int
01916 look_for_overrides (tree type, tree fndecl)
01917 {
01918 tree binfo = TYPE_BINFO (type);
01919 tree base_binfo;
01920 int ix;
01921 int found = 0;
01922
01923 for (ix = 0; BINFO_BASE_ITERATE (binfo, ix, base_binfo); ix++)
01924 {
01925 tree basetype = BINFO_TYPE (base_binfo);
01926
01927 if (TYPE_POLYMORPHIC_P (basetype))
01928 found += look_for_overrides_r (basetype, fndecl);
01929 }
01930 return found;
01931 }
01932
01933
01934
01935
01936 tree
01937 look_for_overrides_here (tree type, tree fndecl)
01938 {
01939 int ix;
01940
01941
01942
01943
01944 if (!CLASSTYPE_METHOD_VEC (type))
01945 return NULL_TREE;
01946
01947 if (DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (fndecl))
01948 ix = CLASSTYPE_DESTRUCTOR_SLOT;
01949 else
01950 ix = lookup_fnfields_1 (type, DECL_NAME (fndecl));
01951 if (ix >= 0)
01952 {
01953 tree fns = VEC_index (tree, CLASSTYPE_METHOD_VEC (type), ix);
01954
01955 for (; fns; fns = OVL_NEXT (fns))
01956 {
01957 tree fn = OVL_CURRENT (fns);
01958
01959 if (!DECL_VIRTUAL_P (fn))
01960 ;
01961 else if (DECL_CONTEXT (fn) != type)
01962 ;
01963 else if (DECL_STATIC_FUNCTION_P (fndecl))
01964 {
01965 tree btypes = TYPE_ARG_TYPES (TREE_TYPE (fn));
01966 tree dtypes = TYPE_ARG_TYPES (TREE_TYPE (fndecl));
01967 if (compparms (TREE_CHAIN (btypes), dtypes))
01968 return fn;
01969 }
01970 else if (same_signature_p (fndecl, fn))
01971 return fn;
01972 }
01973 }
01974 return NULL_TREE;
01975 }
01976
01977
01978
01979
01980 static int
01981 look_for_overrides_r (tree type, tree fndecl)
01982 {
01983 tree fn = look_for_overrides_here (type, fndecl);
01984 if (fn)
01985 {
01986 if (DECL_STATIC_FUNCTION_P (fndecl))
01987 {
01988
01989
01990 error ("%q+#D cannot be declared", fndecl);
01991 error (" since %q+#D declared in base class", fn);
01992 }
01993 else
01994 {
01995
01996 DECL_VIRTUAL_P (fndecl) = 1;
01997 check_final_overrider (fndecl, fn);
01998 }
01999 return 1;
02000 }
02001
02002
02003 return look_for_overrides (type, fndecl);
02004 }
02005
02006
02007
02008 static tree
02009 dfs_get_pure_virtuals (tree binfo, void *data)
02010 {
02011 tree type = (tree) data;
02012
02013
02014
02015
02016 if (!BINFO_PRIMARY_P (binfo))
02017 {
02018 tree virtuals;
02019
02020 for (virtuals = BINFO_VIRTUALS (binfo);
02021 virtuals;
02022 virtuals = TREE_CHAIN (virtuals))
02023 if (DECL_PURE_VIRTUAL_P (BV_FN (virtuals)))
02024 VEC_safe_push (tree, gc, CLASSTYPE_PURE_VIRTUALS (type),
02025 BV_FN (virtuals));
02026 }
02027
02028 return NULL_TREE;
02029 }
02030
02031
02032
02033 void
02034 get_pure_virtuals (tree type)
02035 {
02036
02037
02038 CLASSTYPE_PURE_VIRTUALS (type) = NULL;
02039
02040
02041
02042
02043
02044
02045 dfs_walk_once (TYPE_BINFO (type), NULL, dfs_get_pure_virtuals, type);
02046 }
02047
02048
02049
02050
02051
02052
02053
02054
02055 void
02056 maybe_suppress_debug_info (tree t)
02057 {
02058 if (write_symbols == NO_DEBUG)
02059 return;
02060
02061
02062 TYPE_DECL_SUPPRESS_DEBUG (TYPE_MAIN_DECL (t)) = 0;
02063
02064
02065 if (flag_emit_class_debug_always)
02066 return;
02067
02068
02069
02070 if (CLASSTYPE_INTERFACE_KNOWN (t))
02071 {
02072 if (CLASSTYPE_INTERFACE_ONLY (t))
02073 TYPE_DECL_SUPPRESS_DEBUG (TYPE_MAIN_DECL (t)) = 1;
02074
02075 }
02076
02077
02078 else if (TYPE_CONTAINS_VPTR_P (t))
02079 TYPE_DECL_SUPPRESS_DEBUG (TYPE_MAIN_DECL (t)) = 1;
02080
02081
02082 }
02083
02084
02085
02086
02087
02088
02089
02090
02091
02092
02093 static tree
02094 dfs_debug_mark (tree binfo, void *data ATTRIBUTE_UNUSED)
02095 {
02096 tree t = BINFO_TYPE (binfo);
02097
02098 if (CLASSTYPE_DEBUG_REQUESTED (t))
02099 return dfs_skip_bases;
02100
02101 CLASSTYPE_DEBUG_REQUESTED (t) = 1;
02102
02103 return NULL_TREE;
02104 }
02105
02106
02107
02108
02109
02110
02111
02112
02113 void
02114 note_debug_info_needed (tree type)
02115 {
02116 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_NAME (type)))
02117 {
02118 TYPE_DECL_SUPPRESS_DEBUG (TYPE_NAME (type)) = 0;
02119 rest_of_type_compilation (type, toplevel_bindings_p ());
02120 }
02121
02122 dfs_walk_all (TYPE_BINFO (type), dfs_debug_mark, NULL, 0);
02123 }
02124
02125 void
02126 print_search_statistics (void)
02127 {
02128 #ifdef GATHER_STATISTICS
02129 fprintf (stderr, "%d fields searched in %d[%d] calls to lookup_field[_1]\n",
02130 n_fields_searched, n_calls_lookup_field, n_calls_lookup_field_1);
02131 fprintf (stderr, "%d fnfields searched in %d calls to lookup_fnfields\n",
02132 n_outer_fields_searched, n_calls_lookup_fnfields);
02133 fprintf (stderr, "%d calls to get_base_type\n", n_calls_get_base_type);
02134 #else
02135 fprintf (stderr, "no search statistics\n");
02136 #endif
02137 }
02138
02139 void
02140 reinit_search_statistics (void)
02141 {
02142 #ifdef GATHER_STATISTICS
02143 n_fields_searched = 0;
02144 n_calls_lookup_field = 0, n_calls_lookup_field_1 = 0;
02145 n_calls_lookup_fnfields = 0, n_calls_lookup_fnfields_1 = 0;
02146 n_calls_get_base_type = 0;
02147 n_outer_fields_searched = 0;
02148 n_contexts_saved = 0;
02149 #endif
02150 }
02151
02152
02153
02154
02155
02156
02157
02158
02159
02160
02161
02162
02163 static int
02164 check_hidden_convs (tree binfo, int virtual_depth, int virtualness,
02165 tree to_type, tree parent_convs, tree other_convs)
02166 {
02167 tree level, probe;
02168
02169
02170 for (level = parent_convs; level; level = TREE_CHAIN (level))
02171 for (probe = TREE_VALUE (level); probe; probe = TREE_CHAIN (probe))
02172 if (same_type_p (to_type, TREE_TYPE (probe)))
02173 return 0;
02174
02175 if (virtual_depth || virtualness)
02176 {
02177
02178
02179 for (level = other_convs; level; level = TREE_CHAIN (level))
02180 {
02181 int we_hide_them;
02182 int they_hide_us;
02183 tree *prev, other;
02184
02185 if (!(virtual_depth || TREE_STATIC (level)))
02186
02187 continue;
02188
02189 if (!TREE_VALUE (level))
02190
02191 continue;
02192
02193 they_hide_us = (virtual_depth
02194 && original_binfo (binfo, TREE_PURPOSE (level)));
02195 we_hide_them = (!they_hide_us && TREE_STATIC (level)
02196 && original_binfo (TREE_PURPOSE (level), binfo));
02197
02198 if (!(we_hide_them || they_hide_us))
02199
02200 continue;
02201
02202 for (prev = &TREE_VALUE (level), other = *prev; other;)
02203 {
02204 if (same_type_p (to_type, TREE_TYPE (other)))
02205 {
02206 if (they_hide_us)
02207
02208 return 0;
02209
02210 if (we_hide_them)
02211 {
02212
02213 other = TREE_CHAIN (other);
02214 *prev = other;
02215 continue;
02216 }
02217 }
02218 prev = &TREE_CHAIN (other);
02219 other = *prev;
02220 }
02221 }
02222 }
02223 return 1;
02224 }
02225
02226
02227
02228
02229
02230
02231
02232
02233
02234
02235 static tree
02236 split_conversions (tree my_convs, tree parent_convs,
02237 tree child_convs, tree other_convs)
02238 {
02239 tree t;
02240 tree prev;
02241
02242
02243 for (prev = NULL, t = child_convs;
02244 t != other_convs; prev = t, t = TREE_CHAIN (t))
02245 continue;
02246
02247 if (prev)
02248 TREE_CHAIN (prev) = NULL_TREE;
02249 else
02250 child_convs = NULL_TREE;
02251
02252
02253 if (my_convs)
02254 {
02255 my_convs = parent_convs;
02256 TREE_CHAIN (my_convs) = child_convs;
02257 }
02258 else
02259 my_convs = child_convs;
02260
02261 return my_convs;
02262 }
02263
02264
02265
02266
02267
02268
02269
02270
02271
02272
02273
02274
02275
02276
02277
02278
02279
02280
02281
02282
02283
02284 static int
02285 lookup_conversions_r (tree binfo,
02286 int virtual_depth, int virtualness,
02287 tree parent_convs, tree parent_tpl_convs,
02288 tree other_convs, tree other_tpl_convs,
02289 tree *convs, tree *tpl_convs)
02290 {
02291 int my_virtualness = 0;
02292 tree my_convs = NULL_TREE;
02293 tree my_tpl_convs = NULL_TREE;
02294 tree child_convs = NULL_TREE;
02295 tree child_tpl_convs = NULL_TREE;
02296 unsigned i;
02297 tree base_binfo;
02298 VEC(tree,gc) *method_vec = CLASSTYPE_METHOD_VEC (BINFO_TYPE (binfo));
02299 tree conv;
02300
02301
02302 if (!TYPE_HAS_CONVERSION (BINFO_TYPE (binfo)))
02303 {
02304 *convs = *tpl_convs = NULL_TREE;
02305
02306 return 0;
02307 }
02308
02309 if (BINFO_VIRTUAL_P (binfo))
02310 virtual_depth++;
02311
02312
02313 for (i = CLASSTYPE_FIRST_CONVERSION_SLOT;
02314 VEC_iterate (tree, method_vec, i, conv);
02315 ++i)
02316 {
02317 tree cur = OVL_CURRENT (conv);
02318
02319 if (!DECL_CONV_FN_P (cur))
02320 break;
02321
02322 if (TREE_CODE (cur) == TEMPLATE_DECL)
02323 {
02324
02325
02326 tree tpls;
02327
02328 for (tpls = conv; tpls; tpls = OVL_NEXT (tpls))
02329 {
02330 tree tpl = OVL_CURRENT (tpls);
02331 tree type = DECL_CONV_FN_TYPE (tpl);
02332
02333 if (check_hidden_convs (binfo, virtual_depth, virtualness,
02334 type, parent_tpl_convs, other_tpl_convs))
02335 {
02336 my_tpl_convs = tree_cons (binfo, tpl, my_tpl_convs);
02337 TREE_TYPE (my_tpl_convs) = type;
02338 if (virtual_depth)
02339 {
02340 TREE_STATIC (my_tpl_convs) = 1;
02341 my_virtualness = 1;
02342 }
02343 }
02344 }
02345 }
02346 else
02347 {
02348 tree name = DECL_NAME (cur);
02349
02350 if (!IDENTIFIER_MARKED (name))
02351 {
02352 tree type = DECL_CONV_FN_TYPE (cur);
02353
02354 if (check_hidden_convs (binfo, virtual_depth, virtualness,
02355 type, parent_convs, other_convs))
02356 {
02357 my_convs = tree_cons (binfo, conv, my_convs);
02358 TREE_TYPE (my_convs) = type;
02359 if (virtual_depth)
02360 {
02361 TREE_STATIC (my_convs) = 1;
02362 my_virtualness = 1;
02363 }
02364 IDENTIFIER_MARKED (name) = 1;
02365 }
02366 }
02367 }
02368 }
02369
02370 if (my_convs)
02371 {
02372 parent_convs = tree_cons (binfo, my_convs, parent_convs);
02373 if (virtual_depth)
02374 TREE_STATIC (parent_convs) = 1;
02375 }
02376
02377 if (my_tpl_convs)
02378 {
02379 parent_tpl_convs = tree_cons (binfo, my_tpl_convs, parent_tpl_convs);
02380 if (virtual_depth)
02381 TREE_STATIC (parent_tpl_convs) = 1;
02382 }
02383
02384 child_convs = other_convs;
02385 child_tpl_convs = other_tpl_convs;
02386
02387
02388 for (i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
02389 {
02390 tree base_convs, base_tpl_convs;
02391 unsigned base_virtualness;
02392
02393 base_virtualness = lookup_conversions_r (base_binfo,
02394 virtual_depth, virtualness,
02395 parent_convs, parent_tpl_convs,
02396 child_convs, child_tpl_convs,
02397 &base_convs, &base_tpl_convs);
02398 if (base_virtualness)
02399 my_virtualness = virtualness = 1;
02400 child_convs = chainon (base_convs, child_convs);
02401 child_tpl_convs = chainon (base_tpl_convs, child_tpl_convs);
02402 }
02403
02404
02405 for (conv = my_convs; conv; conv = TREE_CHAIN (conv))
02406 IDENTIFIER_MARKED (DECL_NAME (OVL_CURRENT (TREE_VALUE (conv)))) = 0;
02407
02408 *convs = split_conversions (my_convs, parent_convs,
02409 child_convs, other_convs);
02410 *tpl_convs = split_conversions (my_tpl_convs, parent_tpl_convs,
02411 child_tpl_convs, other_tpl_convs);
02412
02413 return my_virtualness;
02414 }
02415
02416
02417
02418
02419
02420
02421
02422
02423
02424
02425 tree
02426 lookup_conversions (tree type)
02427 {
02428 tree convs, tpl_convs;
02429 tree list = NULL_TREE;
02430
02431 complete_type (type);
02432 if (!TYPE_BINFO (type))
02433 return NULL_TREE;
02434
02435 lookup_conversions_r (TYPE_BINFO (type), 0, 0,
02436 NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE,
02437 &convs, &tpl_convs);
02438
02439
02440 for (; convs; convs = TREE_CHAIN (convs))
02441 {
02442 tree probe, next;
02443
02444 for (probe = TREE_VALUE (convs); probe; probe = next)
02445 {
02446 next = TREE_CHAIN (probe);
02447
02448 TREE_CHAIN (probe) = list;
02449 list = probe;
02450 }
02451 }
02452
02453 for (; tpl_convs; tpl_convs = TREE_CHAIN (tpl_convs))
02454 {
02455 tree probe, next;
02456
02457 for (probe = TREE_VALUE (tpl_convs); probe; probe = next)
02458 {
02459 next = TREE_CHAIN (probe);
02460
02461 TREE_CHAIN (probe) = list;
02462 list = probe;
02463 }
02464 }
02465
02466 return list;
02467 }
02468
02469
02470
02471
02472 tree
02473 binfo_from_vbase (tree binfo)
02474 {
02475 for (; binfo; binfo = BINFO_INHERITANCE_CHAIN (binfo))
02476 {
02477 if (BINFO_VIRTUAL_P (binfo))
02478 return binfo;
02479 }
02480 return NULL_TREE;
02481 }
02482
02483
02484
02485
02486
02487 tree
02488 binfo_via_virtual (tree binfo, tree limit)
02489 {
02490 if (limit && !CLASSTYPE_VBASECLASSES (limit))
02491
02492 return NULL_TREE;
02493
02494 for (; binfo && !SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), limit);
02495 binfo = BINFO_INHERITANCE_CHAIN (binfo))
02496 {
02497 if (BINFO_VIRTUAL_P (binfo))
02498 return binfo;
02499 }
02500 return NULL_TREE;
02501 }
02502
02503
02504
02505
02506
02507 tree
02508 copied_binfo (tree binfo, tree here)
02509 {
02510 tree result = NULL_TREE;
02511
02512 if (BINFO_VIRTUAL_P (binfo))
02513 {
02514 tree t;
02515
02516 for (t = here; BINFO_INHERITANCE_CHAIN (t);
02517 t = BINFO_INHERITANCE_CHAIN (t))
02518 continue;
02519
02520 result = binfo_for_vbase (BINFO_TYPE (binfo), BINFO_TYPE (t));
02521 }
02522 else if (BINFO_INHERITANCE_CHAIN (binfo))
02523 {
02524 tree cbinfo;
02525 tree base_binfo;
02526 int ix;
02527
02528 cbinfo = copied_binfo (BINFO_INHERITANCE_CHAIN (binfo), here);
02529 for (ix = 0; BINFO_BASE_ITERATE (cbinfo, ix, base_binfo); ix++)
02530 if (SAME_BINFO_TYPE_P (BINFO_TYPE (base_binfo), BINFO_TYPE (binfo)))
02531 {
02532 result = base_binfo;
02533 break;
02534 }
02535 }
02536 else
02537 {
02538 gcc_assert (SAME_BINFO_TYPE_P (BINFO_TYPE (here), BINFO_TYPE (binfo)));
02539 result = here;
02540 }
02541
02542 gcc_assert (result);
02543 return result;
02544 }
02545
02546 tree
02547 binfo_for_vbase (tree base, tree t)
02548 {
02549 unsigned ix;
02550 tree binfo;
02551 VEC(tree,gc) *vbases;
02552
02553 for (vbases = CLASSTYPE_VBASECLASSES (t), ix = 0;
02554 VEC_iterate (tree, vbases, ix, binfo); ix++)
02555 if (SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), base))
02556 return binfo;
02557 return NULL;
02558 }
02559
02560
02561
02562
02563
02564
02565 tree
02566 original_binfo (tree binfo, tree here)
02567 {
02568 tree result = NULL;
02569
02570 if (SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), BINFO_TYPE (here)))
02571 result = here;
02572 else if (BINFO_VIRTUAL_P (binfo))
02573 result = (CLASSTYPE_VBASECLASSES (BINFO_TYPE (here))
02574 ? binfo_for_vbase (BINFO_TYPE (binfo), BINFO_TYPE (here))
02575 : NULL_TREE);
02576 else if (BINFO_INHERITANCE_CHAIN (binfo))
02577 {
02578 tree base_binfos;
02579
02580 base_binfos = original_binfo (BINFO_INHERITANCE_CHAIN (binfo), here);
02581 if (base_binfos)
02582 {
02583 int ix;
02584 tree base_binfo;
02585
02586 for (ix = 0; (base_binfo = BINFO_BASE_BINFO (base_binfos, ix)); ix++)
02587 if (SAME_BINFO_TYPE_P (BINFO_TYPE (base_binfo),
02588 BINFO_TYPE (binfo)))
02589 {
02590 result = base_binfo;
02591 break;
02592 }
02593 }
02594 }
02595
02596 return result;
02597 }
02598