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