00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "config.h"
00024 #include "system.h"
00025 #include "coretypes.h"
00026 #include "tm.h"
00027 #include "tree.h"
00028 #include "cp-tree.h"
00029 #include "flags.h"
00030 #include "real.h"
00031 #include "rtl.h"
00032 #include "toplev.h"
00033 #include "insn-config.h"
00034 #include "integrate.h"
00035 #include "tree-inline.h"
00036 #include "target.h"
00037
00038 static tree bot_manip (tree *, int *, void *);
00039 static tree bot_replace (tree *, int *, void *);
00040 static tree build_cplus_array_type_1 (tree, tree);
00041 static int list_hash_eq (const void *, const void *);
00042 static hashval_t list_hash_pieces (tree, tree, tree);
00043 static hashval_t list_hash (const void *);
00044 static cp_lvalue_kind lvalue_p_1 (tree, int);
00045 static tree build_target_expr (tree, tree);
00046 static tree count_trees_r (tree *, int *, void *);
00047 static tree verify_stmt_tree_r (tree *, int *, void *);
00048 static tree find_tree_r (tree *, int *, void *);
00049 static tree build_local_temp (tree);
00050
00051 static tree handle_java_interface_attribute (tree *, tree, tree, int, bool *);
00052 static tree handle_com_interface_attribute (tree *, tree, tree, int, bool *);
00053 static tree handle_init_priority_attribute (tree *, tree, tree, int, bool *);
00054
00055
00056
00057
00058
00059 static cp_lvalue_kind
00060 lvalue_p_1 (tree ref,
00061 int treat_class_rvalues_as_lvalues)
00062 {
00063 cp_lvalue_kind op1_lvalue_kind = clk_none;
00064 cp_lvalue_kind op2_lvalue_kind = clk_none;
00065
00066 if (TREE_CODE (TREE_TYPE (ref)) == REFERENCE_TYPE)
00067 return clk_ordinary;
00068
00069 if (ref == current_class_ptr)
00070 return clk_none;
00071
00072 switch (TREE_CODE (ref))
00073 {
00074
00075
00076 case PREINCREMENT_EXPR:
00077 case PREDECREMENT_EXPR:
00078 case SAVE_EXPR:
00079 case TRY_CATCH_EXPR:
00080 case WITH_CLEANUP_EXPR:
00081 case REALPART_EXPR:
00082 case IMAGPART_EXPR:
00083 return lvalue_p_1 (TREE_OPERAND (ref, 0),
00084 treat_class_rvalues_as_lvalues);
00085
00086 case COMPONENT_REF:
00087 op1_lvalue_kind = lvalue_p_1 (TREE_OPERAND (ref, 0),
00088 treat_class_rvalues_as_lvalues);
00089
00090
00091 op1_lvalue_kind &= ~clk_packed;
00092
00093 if (!op1_lvalue_kind
00094
00095
00096 || TREE_CODE (TREE_OPERAND (ref, 1)) != FIELD_DECL)
00097 ;
00098 else if (DECL_C_BIT_FIELD (TREE_OPERAND (ref, 1)))
00099 {
00100
00101
00102 op1_lvalue_kind &= ~clk_ordinary;
00103
00104 op1_lvalue_kind |= clk_bitfield;
00105 }
00106 else if (DECL_PACKED (TREE_OPERAND (ref, 1)))
00107 op1_lvalue_kind |= clk_packed;
00108
00109 return op1_lvalue_kind;
00110
00111 case STRING_CST:
00112 return clk_ordinary;
00113
00114 case VAR_DECL:
00115 if (TREE_READONLY (ref) && ! TREE_STATIC (ref)
00116 && DECL_LANG_SPECIFIC (ref)
00117 && DECL_IN_AGGR_P (ref))
00118 return clk_none;
00119 case INDIRECT_REF:
00120 case ARRAY_REF:
00121 case PARM_DECL:
00122 case RESULT_DECL:
00123 if (TREE_CODE (TREE_TYPE (ref)) != METHOD_TYPE)
00124 return clk_ordinary;
00125 break;
00126
00127
00128 case SCOPE_REF:
00129 gcc_unreachable ();
00130 case MAX_EXPR:
00131 case MIN_EXPR:
00132
00133 if (TREE_SIDE_EFFECTS (TREE_OPERAND (ref, 0))
00134 || TREE_SIDE_EFFECTS (TREE_OPERAND (ref, 1)))
00135 return clk_none;
00136 op1_lvalue_kind = lvalue_p_1 (TREE_OPERAND (ref, 0),
00137 treat_class_rvalues_as_lvalues);
00138 op2_lvalue_kind = lvalue_p_1 (TREE_OPERAND (ref, 1),
00139 treat_class_rvalues_as_lvalues);
00140 break;
00141
00142 case COND_EXPR:
00143 op1_lvalue_kind = lvalue_p_1 (TREE_OPERAND (ref, 1),
00144 treat_class_rvalues_as_lvalues);
00145 op2_lvalue_kind = lvalue_p_1 (TREE_OPERAND (ref, 2),
00146 treat_class_rvalues_as_lvalues);
00147 break;
00148
00149 case MODIFY_EXPR:
00150 return clk_ordinary;
00151
00152 case COMPOUND_EXPR:
00153 return lvalue_p_1 (TREE_OPERAND (ref, 1),
00154 treat_class_rvalues_as_lvalues);
00155
00156 case TARGET_EXPR:
00157 return treat_class_rvalues_as_lvalues ? clk_class : clk_none;
00158
00159 case CALL_EXPR:
00160 case VA_ARG_EXPR:
00161
00162 return clk_none;
00163
00164 case FUNCTION_DECL:
00165
00166
00167 return (DECL_NONSTATIC_MEMBER_FUNCTION_P (ref)
00168 ? clk_none : clk_ordinary);
00169
00170 case NON_DEPENDENT_EXPR:
00171
00172
00173
00174
00175
00176 return clk_ordinary;
00177
00178 default:
00179 break;
00180 }
00181
00182
00183
00184 if (!op1_lvalue_kind || !op2_lvalue_kind)
00185 return clk_none;
00186
00187
00188
00189 op1_lvalue_kind = op1_lvalue_kind | op2_lvalue_kind;
00190
00191
00192 if ((op1_lvalue_kind & ~clk_ordinary) != clk_none)
00193 op1_lvalue_kind &= ~clk_ordinary;
00194 return op1_lvalue_kind;
00195 }
00196
00197
00198
00199
00200
00201 cp_lvalue_kind
00202 real_lvalue_p (tree ref)
00203 {
00204 return lvalue_p_1 (ref,
00205 0);
00206 }
00207
00208
00209
00210
00211 int
00212 lvalue_p (tree ref)
00213 {
00214 return
00215 (lvalue_p_1 (ref, 1) != clk_none);
00216 }
00217
00218
00219
00220
00221 bool
00222 builtin_valid_in_constant_expr_p (tree decl)
00223 {
00224
00225
00226 return DECL_IS_BUILTIN_CONSTANT_P (decl);
00227 }
00228
00229
00230
00231 static tree
00232 build_target_expr (tree decl, tree value)
00233 {
00234 tree t;
00235
00236 t = build4 (TARGET_EXPR, TREE_TYPE (decl), decl, value,
00237 cxx_maybe_build_cleanup (decl), NULL_TREE);
00238
00239
00240
00241
00242 TREE_SIDE_EFFECTS (t) = 1;
00243
00244 return t;
00245 }
00246
00247
00248
00249
00250 static tree
00251 build_local_temp (tree type)
00252 {
00253 tree slot = build_decl (VAR_DECL, NULL_TREE, type);
00254 DECL_ARTIFICIAL (slot) = 1;
00255 DECL_IGNORED_P (slot) = 1;
00256 DECL_CONTEXT (slot) = current_function_decl;
00257 layout_decl (slot, 0);
00258 return slot;
00259 }
00260
00261
00262
00263
00264
00265
00266
00267
00268 tree
00269 build_cplus_new (tree type, tree init)
00270 {
00271 tree fn;
00272 tree slot;
00273 tree rval;
00274 int is_ctor;
00275
00276
00277
00278 abstract_virtuals_error (NULL_TREE, type);
00279
00280 if (TREE_CODE (init) != CALL_EXPR && TREE_CODE (init) != AGGR_INIT_EXPR)
00281 return convert (type, init);
00282
00283 fn = TREE_OPERAND (init, 0);
00284 is_ctor = (TREE_CODE (fn) == ADDR_EXPR
00285 && TREE_CODE (TREE_OPERAND (fn, 0)) == FUNCTION_DECL
00286 && DECL_CONSTRUCTOR_P (TREE_OPERAND (fn, 0)));
00287
00288 slot = build_local_temp (type);
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301 if (is_ctor || TREE_ADDRESSABLE (type))
00302 {
00303 rval = build3 (AGGR_INIT_EXPR, void_type_node, fn,
00304 TREE_OPERAND (init, 1), slot);
00305 TREE_SIDE_EFFECTS (rval) = 1;
00306 AGGR_INIT_VIA_CTOR_P (rval) = is_ctor;
00307 }
00308 else
00309 rval = init;
00310
00311 rval = build_target_expr (slot, rval);
00312
00313 return rval;
00314 }
00315
00316
00317
00318
00319 tree
00320 build_target_expr_with_type (tree init, tree type)
00321 {
00322 tree slot;
00323
00324 gcc_assert (!VOID_TYPE_P (type));
00325
00326 if (TREE_CODE (init) == TARGET_EXPR)
00327 return init;
00328 else if (CLASS_TYPE_P (type) && !TYPE_HAS_TRIVIAL_INIT_REF (type)
00329 && TREE_CODE (init) != COND_EXPR
00330 && TREE_CODE (init) != CONSTRUCTOR
00331 && TREE_CODE (init) != VA_ARG_EXPR)
00332
00333
00334
00335
00336
00337 return force_rvalue (init);
00338
00339 slot = build_local_temp (type);
00340 return build_target_expr (slot, init);
00341 }
00342
00343
00344
00345
00346
00347 tree
00348 force_target_expr (tree type, tree init)
00349 {
00350 tree slot;
00351
00352 gcc_assert (!VOID_TYPE_P (type));
00353
00354 slot = build_local_temp (type);
00355 return build_target_expr (slot, init);
00356 }
00357
00358
00359
00360 tree
00361 get_target_expr (tree init)
00362 {
00363 return build_target_expr_with_type (init, TREE_TYPE (init));
00364 }
00365
00366
00367
00368
00369 tree
00370 rvalue (tree expr)
00371 {
00372 tree type;
00373 if (real_lvalue_p (expr))
00374 {
00375 type = TREE_TYPE (expr);
00376
00377
00378
00379 if (!CLASS_TYPE_P (type))
00380 type = TYPE_MAIN_VARIANT (type);
00381 expr = build1 (NON_LVALUE_EXPR, type, expr);
00382 }
00383 return expr;
00384 }
00385
00386
00387 static tree
00388 build_cplus_array_type_1 (tree elt_type, tree index_type)
00389 {
00390 tree t;
00391
00392 if (elt_type == error_mark_node || index_type == error_mark_node)
00393 return error_mark_node;
00394
00395 if (dependent_type_p (elt_type)
00396 || (index_type
00397 && value_dependent_expression_p (TYPE_MAX_VALUE (index_type))))
00398 {
00399 t = make_node (ARRAY_TYPE);
00400 TREE_TYPE (t) = elt_type;
00401 TYPE_DOMAIN (t) = index_type;
00402 }
00403 else
00404 t = build_array_type (elt_type, index_type);
00405
00406
00407
00408 TYPE_NEEDS_CONSTRUCTING (t)
00409 = TYPE_NEEDS_CONSTRUCTING (TYPE_MAIN_VARIANT (elt_type));
00410 TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)
00411 = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TYPE_MAIN_VARIANT (elt_type));
00412 return t;
00413 }
00414
00415 tree
00416 build_cplus_array_type (tree elt_type, tree index_type)
00417 {
00418 tree t;
00419 int type_quals = cp_type_quals (elt_type);
00420
00421 if (type_quals != TYPE_UNQUALIFIED)
00422 elt_type = cp_build_qualified_type (elt_type, TYPE_UNQUALIFIED);
00423
00424 t = build_cplus_array_type_1 (elt_type, index_type);
00425
00426 if (type_quals != TYPE_UNQUALIFIED)
00427 t = cp_build_qualified_type (t, type_quals);
00428
00429 return t;
00430 }
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452 tree
00453 cp_build_qualified_type_real (tree type,
00454 int type_quals,
00455 tsubst_flags_t complain)
00456 {
00457 tree result;
00458 int bad_quals = TYPE_UNQUALIFIED;
00459
00460 if (type == error_mark_node)
00461 return type;
00462
00463 if (type_quals == cp_type_quals (type))
00464 return type;
00465
00466 if (TREE_CODE (type) == ARRAY_TYPE)
00467 {
00468
00469
00470 tree t;
00471 tree element_type
00472 = cp_build_qualified_type_real (TREE_TYPE (type),
00473 type_quals,
00474 complain);
00475
00476 if (element_type == error_mark_node)
00477 return error_mark_node;
00478
00479
00480 for (t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
00481 if (cp_type_quals (t) == type_quals
00482 && TYPE_NAME (t) == TYPE_NAME (type)
00483 && TYPE_CONTEXT (t) == TYPE_CONTEXT (type))
00484 break;
00485
00486 if (!t)
00487 {
00488
00489
00490 t = build_variant_type_copy (type);
00491 TREE_TYPE (t) = element_type;
00492 }
00493
00494
00495
00496
00497
00498
00499
00500
00501 TYPE_NEEDS_CONSTRUCTING (t)
00502 = TYPE_NEEDS_CONSTRUCTING (TYPE_MAIN_VARIANT (element_type));
00503 TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)
00504 = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TYPE_MAIN_VARIANT (element_type));
00505 return t;
00506 }
00507 else if (TYPE_PTRMEMFUNC_P (type))
00508 {
00509
00510
00511
00512
00513 tree t;
00514
00515 t = TYPE_PTRMEMFUNC_FN_TYPE (type);
00516 t = cp_build_qualified_type_real (t, type_quals, complain);
00517 return build_ptrmemfunc_type (t);
00518 }
00519
00520
00521
00522 if (type_quals & (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE)
00523 && (TREE_CODE (type) == REFERENCE_TYPE
00524 || TREE_CODE (type) == METHOD_TYPE))
00525 {
00526 bad_quals |= type_quals & (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE);
00527 type_quals &= ~(TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE);
00528 }
00529
00530
00531
00532 if ((type_quals & TYPE_QUAL_RESTRICT)
00533 && TREE_CODE (type) != TEMPLATE_TYPE_PARM
00534 && TREE_CODE (type) != TYPENAME_TYPE
00535 && TREE_CODE (type) != FUNCTION_TYPE
00536 && !POINTER_TYPE_P (type))
00537 {
00538 bad_quals |= TYPE_QUAL_RESTRICT;
00539 type_quals &= ~TYPE_QUAL_RESTRICT;
00540 }
00541
00542 if (bad_quals == TYPE_UNQUALIFIED)
00543 ;
00544 else if (!(complain & (tf_error | tf_ignore_bad_quals)))
00545 return error_mark_node;
00546 else
00547 {
00548 if (complain & tf_ignore_bad_quals)
00549
00550
00551 bad_quals &= ~TYPE_QUAL_CONST;
00552 if (bad_quals)
00553 {
00554 tree bad_type = build_qualified_type (ptr_type_node, bad_quals);
00555
00556 if (!(complain & tf_ignore_bad_quals))
00557 error ("%qV qualifiers cannot be applied to %qT",
00558 bad_type, type);
00559 }
00560 }
00561
00562
00563 result = build_qualified_type (type, type_quals);
00564
00565
00566
00567
00568
00569 if (result != type
00570 && TREE_CODE (type) == POINTER_TYPE
00571 && TREE_CODE (TREE_TYPE (type)) == METHOD_TYPE)
00572 TYPE_LANG_SPECIFIC (result) = NULL;
00573
00574 return result;
00575 }
00576
00577
00578
00579
00580
00581
00582 tree
00583 canonical_type_variant (tree t)
00584 {
00585 return cp_build_qualified_type (TYPE_MAIN_VARIANT (t), cp_type_quals (t));
00586 }
00587
00588
00589
00590
00591
00592
00593
00594
00595
00596
00597
00598
00599
00600
00601
00602
00603
00604
00605
00606 tree
00607 copy_binfo (tree binfo, tree type, tree t, tree *igo_prev, int virt)
00608 {
00609 tree new_binfo;
00610
00611 if (virt)
00612 {
00613
00614 new_binfo = binfo_for_vbase (type, t);
00615 if (new_binfo)
00616 return new_binfo;
00617 }
00618
00619 new_binfo = make_tree_binfo (binfo ? BINFO_N_BASE_BINFOS (binfo) : 0);
00620 BINFO_TYPE (new_binfo) = type;
00621
00622
00623 TREE_CHAIN (*igo_prev) = new_binfo;
00624 *igo_prev = new_binfo;
00625
00626 if (binfo)
00627 {
00628 int ix;
00629 tree base_binfo;
00630
00631 gcc_assert (!BINFO_DEPENDENT_BASE_P (binfo));
00632 gcc_assert (SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), type));
00633
00634 BINFO_OFFSET (new_binfo) = BINFO_OFFSET (binfo);
00635 BINFO_VIRTUALS (new_binfo) = BINFO_VIRTUALS (binfo);
00636
00637
00638 BINFO_BASE_ACCESSES (new_binfo) = BINFO_BASE_ACCESSES (binfo);
00639
00640
00641 for (ix = 0; BINFO_BASE_ITERATE (binfo, ix, base_binfo); ix++)
00642 {
00643 tree new_base_binfo;
00644
00645 gcc_assert (!BINFO_DEPENDENT_BASE_P (base_binfo));
00646 new_base_binfo = copy_binfo (base_binfo, BINFO_TYPE (base_binfo),
00647 t, igo_prev,
00648 BINFO_VIRTUAL_P (base_binfo));
00649
00650 if (!BINFO_INHERITANCE_CHAIN (new_base_binfo))
00651 BINFO_INHERITANCE_CHAIN (new_base_binfo) = new_binfo;
00652 BINFO_BASE_APPEND (new_binfo, new_base_binfo);
00653 }
00654 }
00655 else
00656 BINFO_DEPENDENT_BASE_P (new_binfo) = 1;
00657
00658 if (virt)
00659 {
00660
00661
00662 VEC_quick_push (tree, CLASSTYPE_VBASECLASSES (t), new_binfo);
00663 BINFO_VIRTUAL_P (new_binfo) = 1;
00664 BINFO_INHERITANCE_CHAIN (new_binfo) = TYPE_BINFO (t);
00665 }
00666
00667 return new_binfo;
00668 }
00669
00670
00671
00672
00673
00674
00675
00676
00677
00678
00679 static GTY ((param_is (union tree_node))) htab_t list_hash_table;
00680
00681 struct list_proxy
00682 {
00683 tree purpose;
00684 tree value;
00685 tree chain;
00686 };
00687
00688
00689
00690
00691 static int
00692 list_hash_eq (const void* entry, const void* data)
00693 {
00694 tree t = (tree) entry;
00695 struct list_proxy *proxy = (struct list_proxy *) data;
00696
00697 return (TREE_VALUE (t) == proxy->value
00698 && TREE_PURPOSE (t) == proxy->purpose
00699 && TREE_CHAIN (t) == proxy->chain);
00700 }
00701
00702
00703
00704
00705
00706 static hashval_t
00707 list_hash_pieces (tree purpose, tree value, tree chain)
00708 {
00709 hashval_t hashcode = 0;
00710
00711 if (chain)
00712 hashcode += TREE_HASH (chain);
00713
00714 if (value)
00715 hashcode += TREE_HASH (value);
00716 else
00717 hashcode += 1007;
00718 if (purpose)
00719 hashcode += TREE_HASH (purpose);
00720 else
00721 hashcode += 1009;
00722 return hashcode;
00723 }
00724
00725
00726
00727 static hashval_t
00728 list_hash (const void* p)
00729 {
00730 tree t = (tree) p;
00731 return list_hash_pieces (TREE_PURPOSE (t),
00732 TREE_VALUE (t),
00733 TREE_CHAIN (t));
00734 }
00735
00736
00737
00738
00739
00740 tree
00741 hash_tree_cons (tree purpose, tree value, tree chain)
00742 {
00743 int hashcode = 0;
00744 void **slot;
00745 struct list_proxy proxy;
00746
00747
00748 hashcode = list_hash_pieces (purpose, value, chain);
00749
00750
00751 proxy.purpose = purpose;
00752 proxy.value = value;
00753 proxy.chain = chain;
00754
00755 slot = htab_find_slot_with_hash (list_hash_table, &proxy, hashcode,
00756 INSERT);
00757
00758 if (!*slot)
00759 *slot = tree_cons (purpose, value, chain);
00760 return *slot;
00761 }
00762
00763
00764
00765 tree
00766 hash_tree_chain (tree value, tree chain)
00767 {
00768 return hash_tree_cons (NULL_TREE, value, chain);
00769 }
00770
00771 void
00772 debug_binfo (tree elem)
00773 {
00774 HOST_WIDE_INT n;
00775 tree virtuals;
00776
00777 fprintf (stderr, "type \"%s\", offset = " HOST_WIDE_INT_PRINT_DEC
00778 "\nvtable type:\n",
00779 TYPE_NAME_STRING (BINFO_TYPE (elem)),
00780 TREE_INT_CST_LOW (BINFO_OFFSET (elem)));
00781 debug_tree (BINFO_TYPE (elem));
00782 if (BINFO_VTABLE (elem))
00783 fprintf (stderr, "vtable decl \"%s\"\n",
00784 IDENTIFIER_POINTER (DECL_NAME (get_vtbl_decl_for_binfo (elem))));
00785 else
00786 fprintf (stderr, "no vtable decl yet\n");
00787 fprintf (stderr, "virtuals:\n");
00788 virtuals = BINFO_VIRTUALS (elem);
00789 n = 0;
00790
00791 while (virtuals)
00792 {
00793 tree fndecl = TREE_VALUE (virtuals);
00794 fprintf (stderr, "%s [%ld =? %ld]\n",
00795 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (fndecl)),
00796 (long) n, (long) TREE_INT_CST_LOW (DECL_VINDEX (fndecl)));
00797 ++n;
00798 virtuals = TREE_CHAIN (virtuals);
00799 }
00800 }
00801
00802 int
00803 is_overloaded_fn (tree x)
00804 {
00805
00806 if (TREE_CODE (x) == OFFSET_REF)
00807 x = TREE_OPERAND (x, 1);
00808 if (BASELINK_P (x))
00809 x = BASELINK_FUNCTIONS (x);
00810 return (TREE_CODE (x) == FUNCTION_DECL
00811 || TREE_CODE (x) == TEMPLATE_ID_EXPR
00812 || DECL_FUNCTION_TEMPLATE_P (x)
00813 || TREE_CODE (x) == OVERLOAD);
00814 }
00815
00816 int
00817 really_overloaded_fn (tree x)
00818 {
00819
00820 if (TREE_CODE (x) == OFFSET_REF)
00821 x = TREE_OPERAND (x, 1);
00822 if (BASELINK_P (x))
00823 x = BASELINK_FUNCTIONS (x);
00824
00825 return ((TREE_CODE (x) == OVERLOAD && OVL_CHAIN (x))
00826 || DECL_FUNCTION_TEMPLATE_P (OVL_CURRENT (x))
00827 || TREE_CODE (x) == TEMPLATE_ID_EXPR);
00828 }
00829
00830 tree
00831 get_first_fn (tree from)
00832 {
00833 gcc_assert (is_overloaded_fn (from));
00834
00835 if (BASELINK_P (from))
00836 from = BASELINK_FUNCTIONS (from);
00837 return OVL_CURRENT (from);
00838 }
00839
00840
00841
00842 tree
00843 ovl_cons (tree decl, tree chain)
00844 {
00845 tree result = make_node (OVERLOAD);
00846 TREE_TYPE (result) = unknown_type_node;
00847 OVL_FUNCTION (result) = decl;
00848 TREE_CHAIN (result) = chain;
00849
00850 return result;
00851 }
00852
00853
00854
00855
00856 tree
00857 build_overload (tree decl, tree chain)
00858 {
00859 if (! chain && TREE_CODE (decl) != TEMPLATE_DECL)
00860 return decl;
00861 if (chain && TREE_CODE (chain) != OVERLOAD)
00862 chain = ovl_cons (chain, NULL_TREE);
00863 return ovl_cons (decl, chain);
00864 }
00865
00866
00867 #define PRINT_RING_SIZE 4
00868
00869 const char *
00870 cxx_printable_name (tree decl, int v)
00871 {
00872 static tree decl_ring[PRINT_RING_SIZE];
00873 static char *print_ring[PRINT_RING_SIZE];
00874 static int ring_counter;
00875 int i;
00876
00877
00878 if (v < 2
00879 || TREE_CODE (decl) != FUNCTION_DECL
00880 || DECL_LANG_SPECIFIC (decl) == 0)
00881 return lang_decl_name (decl, v);
00882
00883
00884 for (i = 0; i < PRINT_RING_SIZE; i++)
00885 if (decl_ring[i] == decl)
00886
00887 return print_ring[i];
00888
00889 if (++ring_counter == PRINT_RING_SIZE)
00890 ring_counter = 0;
00891
00892 if (current_function_decl != NULL_TREE)
00893 {
00894 if (decl_ring[ring_counter] == current_function_decl)
00895 ring_counter += 1;
00896 if (ring_counter == PRINT_RING_SIZE)
00897 ring_counter = 0;
00898 gcc_assert (decl_ring[ring_counter] != current_function_decl);
00899 }
00900
00901 if (print_ring[ring_counter])
00902 free (print_ring[ring_counter]);
00903
00904 print_ring[ring_counter] = xstrdup (lang_decl_name (decl, v));
00905 decl_ring[ring_counter] = decl;
00906 return print_ring[ring_counter];
00907 }
00908
00909
00910
00911
00912 tree
00913 build_exception_variant (tree type, tree raises)
00914 {
00915 tree v = TYPE_MAIN_VARIANT (type);
00916 int type_quals = TYPE_QUALS (type);
00917
00918 for (; v; v = TYPE_NEXT_VARIANT (v))
00919 if (check_qualified_type (v, type, type_quals)
00920 && comp_except_specs (raises, TYPE_RAISES_EXCEPTIONS (v), 1))
00921 return v;
00922
00923
00924 v = build_variant_type_copy (type);
00925 TYPE_RAISES_EXCEPTIONS (v) = raises;
00926 return v;
00927 }
00928
00929
00930
00931
00932
00933 tree
00934 bind_template_template_parm (tree t, tree newargs)
00935 {
00936 tree decl = TYPE_NAME (t);
00937 tree t2;
00938
00939 t2 = make_aggr_type (BOUND_TEMPLATE_TEMPLATE_PARM);
00940 decl = build_decl (TYPE_DECL, DECL_NAME (decl), NULL_TREE);
00941
00942
00943
00944 TEMPLATE_TYPE_PARM_INDEX (t2) = copy_node (TEMPLATE_TYPE_PARM_INDEX (t));
00945 TEMPLATE_PARM_DECL (TEMPLATE_TYPE_PARM_INDEX (t2)) = decl;
00946 TEMPLATE_TEMPLATE_PARM_TEMPLATE_INFO (t2)
00947 = tree_cons (TEMPLATE_TEMPLATE_PARM_TEMPLATE_DECL (t),
00948 newargs, NULL_TREE);
00949
00950 TREE_TYPE (decl) = t2;
00951 TYPE_NAME (t2) = decl;
00952 TYPE_STUB_DECL (t2) = decl;
00953 TYPE_SIZE (t2) = 0;
00954
00955 return t2;
00956 }
00957
00958
00959
00960 static tree
00961 count_trees_r (tree *tp, int *walk_subtrees, void *data)
00962 {
00963 ++*((int *) data);
00964
00965 if (TYPE_P (*tp))
00966 *walk_subtrees = 0;
00967
00968 return NULL_TREE;
00969 }
00970
00971
00972
00973
00974 int
00975 count_trees (tree t)
00976 {
00977 int n_trees = 0;
00978 walk_tree_without_duplicates (&t, count_trees_r, &n_trees);
00979 return n_trees;
00980 }
00981
00982
00983
00984 static tree
00985 verify_stmt_tree_r (tree* tp,
00986 int* walk_subtrees ATTRIBUTE_UNUSED ,
00987 void* data)
00988 {
00989 tree t = *tp;
00990 htab_t *statements = (htab_t *) data;
00991 void **slot;
00992
00993 if (!STATEMENT_CODE_P (TREE_CODE (t)))
00994 return NULL_TREE;
00995
00996
00997
00998 gcc_assert (!htab_find (*statements, t));
00999
01000 slot = htab_find_slot (*statements, t, INSERT);
01001 *slot = t;
01002
01003 return NULL_TREE;
01004 }
01005
01006
01007
01008
01009
01010 void
01011 verify_stmt_tree (tree t)
01012 {
01013 htab_t statements;
01014 statements = htab_create (37, htab_hash_pointer, htab_eq_pointer, NULL);
01015 walk_tree (&t, verify_stmt_tree_r, &statements, NULL);
01016 htab_delete (statements);
01017 }
01018
01019
01020
01021 static tree
01022 find_tree_r (tree* tp,
01023 int* walk_subtrees ATTRIBUTE_UNUSED ,
01024 void* data)
01025 {
01026 if (*tp == (tree) data)
01027 return (tree) data;
01028
01029 return NULL_TREE;
01030 }
01031
01032
01033
01034 tree
01035 find_tree (tree t, tree x)
01036 {
01037 return walk_tree_without_duplicates (&t, find_tree_r, x);
01038 }
01039
01040
01041
01042
01043
01044 tree
01045 no_linkage_check (tree t, bool relaxed_p)
01046 {
01047 tree r;
01048
01049
01050
01051 if (processing_template_decl)
01052 return NULL_TREE;
01053
01054 switch (TREE_CODE (t))
01055 {
01056 tree fn;
01057
01058 case RECORD_TYPE:
01059 if (TYPE_PTRMEMFUNC_P (t))
01060 goto ptrmem;
01061
01062 case UNION_TYPE:
01063 if (!CLASS_TYPE_P (t))
01064 return NULL_TREE;
01065
01066 case ENUMERAL_TYPE:
01067 if (TYPE_ANONYMOUS_P (t))
01068 return t;
01069 fn = decl_function_context (TYPE_MAIN_DECL (t));
01070 if (fn && (!relaxed_p || !TREE_PUBLIC (fn)))
01071 return t;
01072 return NULL_TREE;
01073
01074 case ARRAY_TYPE:
01075 case POINTER_TYPE:
01076 case REFERENCE_TYPE:
01077 return no_linkage_check (TREE_TYPE (t), relaxed_p);
01078
01079 case OFFSET_TYPE:
01080 ptrmem:
01081 r = no_linkage_check (TYPE_PTRMEM_POINTED_TO_TYPE (t),
01082 relaxed_p);
01083 if (r)
01084 return r;
01085 return no_linkage_check (TYPE_PTRMEM_CLASS_TYPE (t), relaxed_p);
01086
01087 case METHOD_TYPE:
01088 r = no_linkage_check (TYPE_METHOD_BASETYPE (t), relaxed_p);
01089 if (r)
01090 return r;
01091
01092 case FUNCTION_TYPE:
01093 {
01094 tree parm;
01095 for (parm = TYPE_ARG_TYPES (t);
01096 parm && parm != void_list_node;
01097 parm = TREE_CHAIN (parm))
01098 {
01099 r = no_linkage_check (TREE_VALUE (parm), relaxed_p);
01100 if (r)
01101 return r;
01102 }
01103 return no_linkage_check (TREE_TYPE (t), relaxed_p);
01104 }
01105
01106 default:
01107 return NULL_TREE;
01108 }
01109 }
01110
01111 #ifdef GATHER_STATISTICS
01112 extern int depth_reached;
01113 #endif
01114
01115 void
01116 cxx_print_statistics (void)
01117 {
01118 print_search_statistics ();
01119 print_class_statistics ();
01120 #ifdef GATHER_STATISTICS
01121 fprintf (stderr, "maximum template instantiation depth reached: %d\n",
01122 depth_reached);
01123 #endif
01124 }
01125
01126
01127
01128
01129
01130 tree
01131 array_type_nelts_top (tree type)
01132 {
01133 return fold (build2 (PLUS_EXPR, sizetype,
01134 array_type_nelts (type),
01135 integer_one_node));
01136 }
01137
01138
01139
01140
01141
01142 tree
01143 array_type_nelts_total (tree type)
01144 {
01145 tree sz = array_type_nelts_top (type);
01146 type = TREE_TYPE (type);
01147 while (TREE_CODE (type) == ARRAY_TYPE)
01148 {
01149 tree n = array_type_nelts_top (type);
01150 sz = fold (build2 (MULT_EXPR, sizetype, sz, n));
01151 type = TREE_TYPE (type);
01152 }
01153 return sz;
01154 }
01155
01156
01157
01158 static tree
01159 bot_manip (tree* tp, int* walk_subtrees, void* data)
01160 {
01161 splay_tree target_remap = ((splay_tree) data);
01162 tree t = *tp;
01163
01164 if (!TYPE_P (t) && TREE_CONSTANT (t))
01165 {
01166
01167
01168
01169 *walk_subtrees = 0;
01170 return NULL_TREE;
01171 }
01172 if (TREE_CODE (t) == TARGET_EXPR)
01173 {
01174 tree u;
01175
01176 if (TREE_CODE (TREE_OPERAND (t, 1)) == AGGR_INIT_EXPR)
01177 {
01178 mark_used (TREE_OPERAND (TREE_OPERAND (TREE_OPERAND (t, 1), 0), 0));
01179 u = build_cplus_new
01180 (TREE_TYPE (t), break_out_target_exprs (TREE_OPERAND (t, 1)));
01181 }
01182 else
01183 {
01184 u = build_target_expr_with_type
01185 (break_out_target_exprs (TREE_OPERAND (t, 1)), TREE_TYPE (t));
01186 }
01187
01188
01189 splay_tree_insert (target_remap,
01190 (splay_tree_key) TREE_OPERAND (t, 0),
01191 (splay_tree_value) TREE_OPERAND (u, 0));
01192
01193
01194 *tp = u;
01195
01196
01197
01198 *walk_subtrees = 0;
01199 return NULL_TREE;
01200 }
01201 else if (TREE_CODE (t) == CALL_EXPR)
01202 mark_used (TREE_OPERAND (TREE_OPERAND (t, 0), 0));
01203
01204
01205 return copy_tree_r (tp, walk_subtrees, NULL);
01206 }
01207
01208
01209
01210
01211
01212 static tree
01213 bot_replace (tree* t,
01214 int* walk_subtrees ATTRIBUTE_UNUSED ,
01215 void* data)
01216 {
01217 splay_tree target_remap = ((splay_tree) data);
01218
01219 if (TREE_CODE (*t) == VAR_DECL)
01220 {
01221 splay_tree_node n = splay_tree_lookup (target_remap,
01222 (splay_tree_key) *t);
01223 if (n)
01224 *t = (tree) n->value;
01225 }
01226
01227 return NULL_TREE;
01228 }
01229
01230
01231
01232
01233
01234
01235 tree
01236 break_out_target_exprs (tree t)
01237 {
01238 static int target_remap_count;
01239 static splay_tree target_remap;
01240
01241 if (!target_remap_count++)
01242 target_remap = splay_tree_new (splay_tree_compare_pointers,
01243 NULL,
01244 NULL);
01245 walk_tree (&t, bot_manip, target_remap, NULL);
01246 walk_tree (&t, bot_replace, target_remap, NULL);
01247
01248 if (!--target_remap_count)
01249 {
01250 splay_tree_delete (target_remap);
01251 target_remap = NULL;
01252 }
01253
01254 return t;
01255 }
01256
01257
01258
01259
01260 tree
01261 build_min_nt (enum tree_code code, ...)
01262 {
01263 tree t;
01264 int length;
01265 int i;
01266 va_list p;
01267
01268 va_start (p, code);
01269
01270 t = make_node (code);
01271 length = TREE_CODE_LENGTH (code);
01272
01273 for (i = 0; i < length; i++)
01274 {
01275 tree x = va_arg (p, tree);
01276 TREE_OPERAND (t, i) = x;
01277 }
01278
01279 va_end (p);
01280 return t;
01281 }
01282
01283
01284
01285 tree
01286 build_min (enum tree_code code, tree tt, ...)
01287 {
01288 tree t;
01289 int length;
01290 int i;
01291 va_list p;
01292
01293 va_start (p, tt);
01294
01295 t = make_node (code);
01296 length = TREE_CODE_LENGTH (code);
01297 TREE_TYPE (t) = tt;
01298
01299 for (i = 0; i < length; i++)
01300 {
01301 tree x = va_arg (p, tree);
01302 TREE_OPERAND (t, i) = x;
01303 if (x && !TYPE_P (x) && TREE_SIDE_EFFECTS (x))
01304 TREE_SIDE_EFFECTS (t) = 1;
01305 }
01306
01307 va_end (p);
01308 return t;
01309 }
01310
01311
01312
01313
01314
01315 tree
01316 build_min_non_dep (enum tree_code code, tree non_dep, ...)
01317 {
01318 tree t;
01319 int length;
01320 int i;
01321 va_list p;
01322
01323 va_start (p, non_dep);
01324
01325 t = make_node (code);
01326 length = TREE_CODE_LENGTH (code);
01327 TREE_TYPE (t) = TREE_TYPE (non_dep);
01328 TREE_SIDE_EFFECTS (t) = TREE_SIDE_EFFECTS (non_dep);
01329
01330 for (i = 0; i < length; i++)
01331 {
01332 tree x = va_arg (p, tree);
01333 TREE_OPERAND (t, i) = x;
01334 }
01335
01336 if (code == COMPOUND_EXPR && TREE_CODE (non_dep) != COMPOUND_EXPR)
01337
01338
01339 COMPOUND_EXPR_OVERLOADED (t) = 1;
01340
01341 va_end (p);
01342 return t;
01343 }
01344
01345 tree
01346 get_type_decl (tree t)
01347 {
01348 if (TREE_CODE (t) == TYPE_DECL)
01349 return t;
01350 if (TYPE_P (t))
01351 return TYPE_STUB_DECL (t);
01352 gcc_assert (t == error_mark_node);
01353 return t;
01354 }
01355
01356
01357
01358
01359 tree
01360 decl_namespace_context (tree decl)
01361 {
01362 while (1)
01363 {
01364 if (TREE_CODE (decl) == NAMESPACE_DECL)
01365 return decl;
01366 else if (TYPE_P (decl))
01367 decl = CP_DECL_CONTEXT (TYPE_MAIN_DECL (decl));
01368 else
01369 decl = CP_DECL_CONTEXT (decl);
01370 }
01371 }
01372
01373
01374
01375
01376 bool
01377 cp_tree_equal (tree t1, tree t2)
01378 {
01379 enum tree_code code1, code2;
01380
01381 if (t1 == t2)
01382 return true;
01383 if (!t1 || !t2)
01384 return false;
01385
01386 for (code1 = TREE_CODE (t1);
01387 code1 == NOP_EXPR || code1 == CONVERT_EXPR
01388 || code1 == NON_LVALUE_EXPR;
01389 code1 = TREE_CODE (t1))
01390 t1 = TREE_OPERAND (t1, 0);
01391 for (code2 = TREE_CODE (t2);
01392 code2 == NOP_EXPR || code2 == CONVERT_EXPR
01393 || code1 == NON_LVALUE_EXPR;
01394 code2 = TREE_CODE (t2))
01395 t2 = TREE_OPERAND (t2, 0);
01396
01397
01398 if (t1 == t2)
01399 return true;
01400
01401 if (code1 != code2)
01402 return false;
01403
01404 switch (code1)
01405 {
01406 case INTEGER_CST:
01407 return TREE_INT_CST_LOW (t1) == TREE_INT_CST_LOW (t2)
01408 && TREE_INT_CST_HIGH (t1) == TREE_INT_CST_HIGH (t2);
01409
01410 case REAL_CST:
01411 return REAL_VALUES_EQUAL (TREE_REAL_CST (t1), TREE_REAL_CST (t2));
01412
01413 case STRING_CST:
01414 return TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
01415 && !memcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
01416 TREE_STRING_LENGTH (t1));
01417
01418 case CONSTRUCTOR:
01419
01420
01421
01422 if (!(same_type_p (TREE_TYPE (t1), TREE_TYPE (t2))
01423
01424 && TREE_OPERAND (t1, 0) == TREE_OPERAND (t2, 0)))
01425 return false;
01426 return cp_tree_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
01427
01428 case TREE_LIST:
01429 if (!cp_tree_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2)))
01430 return false;
01431 if (!cp_tree_equal (TREE_VALUE (t1), TREE_VALUE (t2)))
01432 return false;
01433 return cp_tree_equal (TREE_CHAIN (t1), TREE_CHAIN (t2));
01434
01435 case SAVE_EXPR:
01436 return cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
01437
01438 case CALL_EXPR:
01439 if (!cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0)))
01440 return false;
01441 return cp_tree_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
01442
01443 case TARGET_EXPR:
01444 {
01445 tree o1 = TREE_OPERAND (t1, 0);
01446 tree o2 = TREE_OPERAND (t2, 0);
01447
01448
01449
01450
01451
01452 if (TREE_CODE (o1) == VAR_DECL && DECL_NAME (o1) == NULL_TREE
01453 && !DECL_RTL_SET_P (o1))
01454 ;
01455 else if (TREE_CODE (o2) == VAR_DECL && DECL_NAME (o2) == NULL_TREE
01456 && !DECL_RTL_SET_P (o2))
01457 ;
01458 else if (!cp_tree_equal (o1, o2))
01459 return false;
01460
01461 return cp_tree_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
01462 }
01463
01464 case WITH_CLEANUP_EXPR:
01465 if (!cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0)))
01466 return false;
01467 return cp_tree_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t1, 1));
01468
01469 case COMPONENT_REF:
01470 if (TREE_OPERAND (t1, 1) != TREE_OPERAND (t2, 1))
01471 return false;
01472 return cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
01473
01474 case VAR_DECL:
01475 case PARM_DECL:
01476 case CONST_DECL:
01477 case FUNCTION_DECL:
01478 case TEMPLATE_DECL:
01479 case IDENTIFIER_NODE:
01480 case SSA_NAME:
01481 return false;
01482
01483 case BASELINK:
01484 return (BASELINK_BINFO (t1) == BASELINK_BINFO (t2)
01485 && BASELINK_ACCESS_BINFO (t1) == BASELINK_ACCESS_BINFO (t2)
01486 && cp_tree_equal (BASELINK_FUNCTIONS (t1),
01487 BASELINK_FUNCTIONS (t2)));
01488
01489 case TEMPLATE_PARM_INDEX:
01490 return (TEMPLATE_PARM_IDX (t1) == TEMPLATE_PARM_IDX (t2)
01491 && TEMPLATE_PARM_LEVEL (t1) == TEMPLATE_PARM_LEVEL (t2)
01492 && same_type_p (TREE_TYPE (TEMPLATE_PARM_DECL (t1)),
01493 TREE_TYPE (TEMPLATE_PARM_DECL (t2))));
01494
01495 case TEMPLATE_ID_EXPR:
01496 {
01497 unsigned ix;
01498 tree vec1, vec2;
01499
01500 if (!cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0)))
01501 return false;
01502 vec1 = TREE_OPERAND (t1, 1);
01503 vec2 = TREE_OPERAND (t2, 1);
01504
01505 if (!vec1 || !vec2)
01506 return !vec1 && !vec2;
01507
01508 if (TREE_VEC_LENGTH (vec1) != TREE_VEC_LENGTH (vec2))
01509 return false;
01510
01511 for (ix = TREE_VEC_LENGTH (vec1); ix--;)
01512 if (!cp_tree_equal (TREE_VEC_ELT (vec1, ix),
01513 TREE_VEC_ELT (vec2, ix)))
01514 return false;
01515
01516 return true;
01517 }
01518
01519 case SIZEOF_EXPR:
01520 case ALIGNOF_EXPR:
01521 {
01522 tree o1 = TREE_OPERAND (t1, 0);
01523 tree o2 = TREE_OPERAND (t2, 0);
01524
01525 if (TREE_CODE (o1) != TREE_CODE (o2))
01526 return false;
01527 if (TYPE_P (o1))
01528 return same_type_p (o1, o2);
01529 else
01530 return cp_tree_equal (o1, o2);
01531 }
01532
01533 case PTRMEM_CST:
01534
01535
01536 if (PTRMEM_CST_MEMBER (t1) != PTRMEM_CST_MEMBER (t2))
01537 return false;
01538
01539 return same_type_p (PTRMEM_CST_CLASS (t1), PTRMEM_CST_CLASS (t2));
01540
01541 case OVERLOAD:
01542 if (OVL_FUNCTION (t1) != OVL_FUNCTION (t2))
01543 return false;
01544 return cp_tree_equal (OVL_CHAIN (t1), OVL_CHAIN (t2));
01545
01546 default:
01547 break;
01548 }
01549
01550 switch (TREE_CODE_CLASS (code1))
01551 {
01552 case tcc_unary:
01553 case tcc_binary:
01554 case tcc_comparison:
01555 case tcc_expression:
01556 case tcc_reference:
01557 case tcc_statement:
01558 {
01559 int i;
01560
01561 for (i = 0; i < TREE_CODE_LENGTH (code1); ++i)
01562 if (!cp_tree_equal (TREE_OPERAND (t1, i), TREE_OPERAND (t2, i)))
01563 return false;
01564
01565 return true;
01566 }
01567
01568 case tcc_type:
01569 return same_type_p (t1, t2);
01570 default:
01571 gcc_unreachable ();
01572 }
01573
01574 return false;
01575 }
01576
01577
01578
01579 tree
01580 lvalue_type (tree arg)
01581 {
01582 tree type = TREE_TYPE (arg);
01583 return type;
01584 }
01585
01586
01587
01588
01589 tree
01590 error_type (tree arg)
01591 {
01592 tree type = TREE_TYPE (arg);
01593
01594 if (TREE_CODE (type) == ARRAY_TYPE)
01595 ;
01596 else if (TREE_CODE (type) == ERROR_MARK)
01597 ;
01598 else if (real_lvalue_p (arg))
01599 type = build_reference_type (lvalue_type (arg));
01600 else if (IS_AGGR_TYPE (type))
01601 type = lvalue_type (arg);
01602
01603 return type;
01604 }
01605
01606
01607
01608 int
01609 varargs_function_p (tree function)
01610 {
01611 tree parm = TYPE_ARG_TYPES (TREE_TYPE (function));
01612 for (; parm; parm = TREE_CHAIN (parm))
01613 if (TREE_VALUE (parm) == void_type_node)
01614 return 0;
01615 return 1;
01616 }
01617
01618
01619
01620 int
01621 member_p (tree decl)
01622 {
01623 const tree ctx = DECL_CONTEXT (decl);
01624 return (ctx && TYPE_P (ctx));
01625 }
01626
01627
01628
01629
01630 tree
01631 build_dummy_object (tree type)
01632 {
01633 tree decl = build1 (NOP_EXPR, build_pointer_type (type), void_zero_node);
01634 return build_indirect_ref (decl, NULL);
01635 }
01636
01637
01638
01639
01640
01641 tree
01642 maybe_dummy_object (tree type, tree* binfop)
01643 {
01644 tree decl, context;
01645 tree binfo;
01646
01647 if (current_class_type
01648 && (binfo = lookup_base (current_class_type, type,
01649 ba_unique | ba_quiet, NULL)))
01650 context = current_class_type;
01651 else
01652 {
01653
01654 context = type;
01655 binfo = TYPE_BINFO (type);
01656 }
01657
01658 if (binfop)
01659 *binfop = binfo;
01660
01661 if (current_class_ref && context == current_class_type
01662
01663
01664
01665 && same_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (current_class_ref)),
01666 current_class_type))
01667 decl = current_class_ref;
01668 else
01669 decl = build_dummy_object (context);
01670
01671 return decl;
01672 }
01673
01674
01675
01676 int
01677 is_dummy_object (tree ob)
01678 {
01679 if (TREE_CODE (ob) == INDIRECT_REF)
01680 ob = TREE_OPERAND (ob, 0);
01681 return (TREE_CODE (ob) == NOP_EXPR
01682 && TREE_OPERAND (ob, 0) == void_zero_node);
01683 }
01684
01685
01686
01687 int
01688 pod_type_p (tree t)
01689 {
01690 t = strip_array_types (t);
01691
01692 if (t == error_mark_node)
01693 return 1;
01694 if (INTEGRAL_TYPE_P (t))
01695 return 1;
01696 if (FLOAT_TYPE_P (t))
01697 return 1;
01698 if (TYPE_PTR_P (t))
01699 return 1;
01700 if (TYPE_PTR_TO_MEMBER_P (t))
01701 return 1;
01702
01703 if (TREE_CODE (t) == VECTOR_TYPE)
01704 return 1;
01705
01706 if (! CLASS_TYPE_P (t))
01707 return 0;
01708 if (CLASSTYPE_NON_POD_P (t))
01709 return 0;
01710 return 1;
01711 }
01712
01713
01714
01715
01716 int
01717 zero_init_p (tree t)
01718 {
01719 t = strip_array_types (t);
01720
01721 if (t == error_mark_node)
01722 return 1;
01723
01724
01725 if (TYPE_PTRMEM_P (t))
01726 return 0;
01727
01728
01729
01730 if (CLASS_TYPE_P (t) && CLASSTYPE_NON_ZERO_INIT_P (t))
01731 return 0;
01732
01733 return 1;
01734 }
01735
01736
01737 const struct attribute_spec cxx_attribute_table[] =
01738 {
01739
01740 { "java_interface", 0, 0, false, false, false, handle_java_interface_attribute },
01741 { "com_interface", 0, 0, false, false, false, handle_com_interface_attribute },
01742 { "init_priority", 1, 1, true, false, false, handle_init_priority_attribute },
01743 { NULL, 0, 0, false, false, false, NULL }
01744 };
01745
01746
01747
01748 static tree
01749 handle_java_interface_attribute (tree* node,
01750 tree name,
01751 tree args ATTRIBUTE_UNUSED ,
01752 int flags,
01753 bool* no_add_attrs)
01754 {
01755 if (DECL_P (*node)
01756 || !CLASS_TYPE_P (*node)
01757 || !TYPE_FOR_JAVA (*node))
01758 {
01759 error ("%qE attribute can only be applied to Java class definitions",
01760 name);
01761 *no_add_attrs = true;
01762 return NULL_TREE;
01763 }
01764 if (!(flags & (int) ATTR_FLAG_TYPE_IN_PLACE))
01765 *node = build_variant_type_copy (*node);
01766 TYPE_JAVA_INTERFACE (*node) = 1;
01767
01768 return NULL_TREE;
01769 }
01770
01771
01772
01773 static tree
01774 handle_com_interface_attribute (tree* node,
01775 tree name,
01776 tree args ATTRIBUTE_UNUSED ,
01777 int flags ATTRIBUTE_UNUSED ,
01778 bool* no_add_attrs)
01779 {
01780 static int warned;
01781
01782 *no_add_attrs = true;
01783
01784 if (DECL_P (*node)
01785 || !CLASS_TYPE_P (*node)
01786 || *node != TYPE_MAIN_VARIANT (*node))
01787 {
01788 warning ("%qE attribute can only be applied to class definitions", name);
01789 return NULL_TREE;
01790 }
01791
01792 if (!warned++)
01793 warning ("%qE is obsolete; g++ vtables are now COM-compatible by default",
01794 name);
01795
01796 return NULL_TREE;
01797 }
01798
01799
01800
01801 static tree
01802 handle_init_priority_attribute (tree* node,
01803 tree name,
01804 tree args,
01805 int flags ATTRIBUTE_UNUSED ,
01806 bool* no_add_attrs)
01807 {
01808 tree initp_expr = TREE_VALUE (args);
01809 tree decl = *node;
01810 tree type = TREE_TYPE (decl);
01811 int pri;
01812
01813 STRIP_NOPS (initp_expr);
01814
01815 if (!initp_expr || TREE_CODE (initp_expr) != INTEGER_CST)
01816 {
01817 error ("requested init_priority is not an integer constant");
01818 *no_add_attrs = true;
01819 return NULL_TREE;
01820 }
01821
01822 pri = TREE_INT_CST_LOW (initp_expr);
01823
01824 type = strip_array_types (type);
01825
01826 if (decl == NULL_TREE
01827 || TREE_CODE (decl) != VAR_DECL
01828 || !TREE_STATIC (decl)
01829 || DECL_EXTERNAL (decl)
01830 || (TREE_CODE (type) != RECORD_TYPE
01831 && TREE_CODE (type) != UNION_TYPE)
01832
01833
01834
01835
01836 || current_function_decl)
01837 {
01838 error ("can only use %qE attribute on file-scope definitions "
01839 "of objects of class type", name);
01840 *no_add_attrs = true;
01841 return NULL_TREE;
01842 }
01843
01844 if (pri > MAX_INIT_PRIORITY || pri <= 0)
01845 {
01846 error ("requested init_priority is out of range");
01847 *no_add_attrs = true;
01848 return NULL_TREE;
01849 }
01850
01851
01852
01853 if (pri <= MAX_RESERVED_INIT_PRIORITY)
01854 {
01855 warning
01856 ("requested init_priority is reserved for internal use");
01857 }
01858
01859 if (SUPPORTS_INIT_PRIORITY)
01860 {
01861 DECL_INIT_PRIORITY (decl) = pri;
01862 return NULL_TREE;
01863 }
01864 else
01865 {
01866 error ("%qE attribute is not supported on this platform", name);
01867 *no_add_attrs = true;
01868 return NULL_TREE;
01869 }
01870 }
01871
01872
01873
01874
01875 tree
01876 make_ptrmem_cst (tree type, tree member)
01877 {
01878 tree ptrmem_cst = make_node (PTRMEM_CST);
01879 TREE_TYPE (ptrmem_cst) = type;
01880 PTRMEM_CST_MEMBER (ptrmem_cst) = member;
01881 return ptrmem_cst;
01882 }
01883
01884
01885
01886
01887 tree
01888 cp_build_type_attribute_variant (tree type, tree attributes)
01889 {
01890 tree new_type;
01891
01892 new_type = build_type_attribute_variant (type, attributes);
01893 if (TREE_CODE (new_type) == FUNCTION_TYPE
01894 && (TYPE_RAISES_EXCEPTIONS (new_type)
01895 != TYPE_RAISES_EXCEPTIONS (type)))
01896 new_type = build_exception_variant (new_type,
01897 TYPE_RAISES_EXCEPTIONS (type));
01898 return new_type;
01899 }
01900
01901
01902
01903
01904 tree
01905 cp_walk_subtrees (tree *tp, int *walk_subtrees_p, walk_tree_fn func,
01906 void *data, struct pointer_set_t *pset)
01907 {
01908 enum tree_code code = TREE_CODE (*tp);
01909 location_t save_locus;
01910 tree result;
01911
01912 #define WALK_SUBTREE(NODE) \
01913 do \
01914 { \
01915 result = walk_tree (&(NODE), func, data, pset); \
01916 if (result) goto out; \
01917 } \
01918 while (0)
01919
01920
01921
01922 save_locus = input_location;
01923 if (EXPR_HAS_LOCATION (*tp))
01924 input_location = EXPR_LOCATION (*tp);
01925
01926
01927
01928 result = NULL_TREE;
01929 switch (code)
01930 {
01931 case DEFAULT_ARG:
01932 case TEMPLATE_TEMPLATE_PARM:
01933 case BOUND_TEMPLATE_TEMPLATE_PARM:
01934 case UNBOUND_CLASS_TEMPLATE:
01935 case TEMPLATE_PARM_INDEX:
01936 case TEMPLATE_TYPE_PARM:
01937 case TYPENAME_TYPE:
01938 case TYPEOF_TYPE:
01939 case BASELINK:
01940
01941
01942 *walk_subtrees_p = 0;
01943 break;
01944
01945 case TINST_LEVEL:
01946 WALK_SUBTREE (TINST_DECL (*tp));
01947 *walk_subtrees_p = 0;
01948 break;
01949
01950 case PTRMEM_CST:
01951 WALK_SUBTREE (TREE_TYPE (*tp));
01952 *walk_subtrees_p = 0;
01953 break;
01954
01955 case TREE_LIST:
01956 WALK_SUBTREE (TREE_PURPOSE (*tp));
01957 break;
01958
01959 case OVERLOAD:
01960 WALK_SUBTREE (OVL_FUNCTION (*tp));
01961 WALK_SUBTREE (OVL_CHAIN (*tp));
01962 *walk_subtrees_p = 0;
01963 break;
01964
01965 case RECORD_TYPE:
01966 if (TYPE_PTRMEMFUNC_P (*tp))
01967 WALK_SUBTREE (TYPE_PTRMEMFUNC_FN_TYPE (*tp));
01968 break;
01969
01970 default:
01971 input_location = save_locus;
01972 return NULL_TREE;
01973 }
01974
01975
01976 out:
01977 input_location = save_locus;
01978 return result;
01979
01980 #undef WALK_SUBTREE
01981 }
01982
01983
01984
01985
01986 int
01987 cp_cannot_inline_tree_fn (tree* fnp)
01988 {
01989 tree fn = *fnp;
01990
01991
01992
01993 if (DECL_TEMPLATE_INFO (fn)
01994 && TI_PENDING_TEMPLATE_FLAG (DECL_TEMPLATE_INFO (fn)))
01995 {
01996
01997
01998 if (!DECL_INLINE (DECL_TEMPLATE_RESULT
01999 (template_for_substitution (fn))))
02000 return 1;
02001
02002 fn = *fnp = instantiate_decl (fn, 0, 0);
02003
02004 if (TI_PENDING_TEMPLATE_FLAG (DECL_TEMPLATE_INFO (fn)))
02005 return 1;
02006 }
02007
02008 if (flag_really_no_inline
02009 && (
02010 #ifdef KEY
02011
02012 flag_spin_file ||
02013 #endif
02014 lookup_attribute ("always_inline", DECL_ATTRIBUTES (fn)) == NULL))
02015 return 1;
02016
02017
02018
02019
02020
02021
02022 if (!DECL_DECLARED_INLINE_P (fn) && !(*targetm.binds_local_p) (fn)
02023 && !DECL_COMDAT (fn))
02024 {
02025 DECL_UNINLINABLE (fn) = 1;
02026 return 1;
02027 }
02028
02029 if (varargs_function_p (fn))
02030 {
02031 DECL_UNINLINABLE (fn) = 1;
02032 return 1;
02033 }
02034
02035 if (! function_attribute_inlinable_p (fn))
02036 {
02037 DECL_UNINLINABLE (fn) = 1;
02038 return 1;
02039 }
02040
02041 return 0;
02042 }
02043
02044
02045
02046
02047
02048 tree
02049 cp_add_pending_fn_decls (void* fns_p, tree prev_fn)
02050 {
02051 varray_type *fnsp = (varray_type *)fns_p;
02052 struct saved_scope *s;
02053
02054 for (s = scope_chain; s; s = s->prev)
02055 if (s->function_decl && s->function_decl != prev_fn)
02056 {
02057 VARRAY_PUSH_TREE (*fnsp, s->function_decl);
02058 prev_fn = s->function_decl;
02059 }
02060
02061 return prev_fn;
02062 }
02063
02064
02065
02066
02067 int
02068 cp_auto_var_in_fn_p (tree var, tree fn)
02069 {
02070 return (DECL_P (var) && DECL_CONTEXT (var) == fn
02071 && nonstatic_local_decl_p (var));
02072 }
02073
02074
02075
02076 void
02077 init_tree (void)
02078 {
02079 list_hash_table = htab_create_ggc (31, list_hash, list_hash_eq, NULL);
02080 }
02081
02082
02083
02084
02085
02086 special_function_kind
02087 special_function_p (tree decl)
02088 {
02089
02090
02091
02092 if (DECL_COPY_CONSTRUCTOR_P (decl))
02093 return sfk_copy_constructor;
02094 if (DECL_CONSTRUCTOR_P (decl))
02095 return sfk_constructor;
02096 if (DECL_OVERLOADED_OPERATOR_P (decl) == NOP_EXPR)
02097 return sfk_assignment_operator;
02098 if (DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (decl))
02099 return sfk_destructor;
02100 if (DECL_COMPLETE_DESTRUCTOR_P (decl))
02101 return sfk_complete_destructor;
02102 if (DECL_BASE_DESTRUCTOR_P (decl))
02103 return sfk_base_destructor;
02104 if (DECL_DELETING_DESTRUCTOR_P (decl))
02105 return sfk_deleting_destructor;
02106 if (DECL_CONV_FN_P (decl))
02107 return sfk_conversion;
02108
02109 return sfk_none;
02110 }
02111
02112
02113
02114 int
02115 char_type_p (tree type)
02116 {
02117 return (same_type_p (type, char_type_node)
02118 || same_type_p (type, unsigned_char_type_node)
02119 || same_type_p (type, signed_char_type_node)
02120 || same_type_p (type, wchar_type_node));
02121 }
02122
02123
02124
02125
02126
02127
02128
02129
02130 linkage_kind
02131 decl_linkage (tree decl)
02132 {
02133
02134
02135
02136
02137
02138
02139
02140
02141 if (!DECL_NAME (decl))
02142 return lk_none;
02143
02144
02145 if (TREE_PUBLIC (decl))
02146 return lk_external;
02147
02148
02149
02150
02151
02152
02153 if (DECL_LANG_SPECIFIC (decl) && DECL_COMDAT (decl))
02154 return lk_external;
02155
02156
02157
02158 if (decl_function_context (decl))
02159 return lk_none;
02160
02161
02162 return lk_internal;
02163 }
02164
02165
02166
02167
02168
02169 tree
02170 stabilize_expr (tree exp, tree* initp)
02171 {
02172 tree init_expr;
02173
02174 if (!TREE_SIDE_EFFECTS (exp))
02175 {
02176 init_expr = NULL_TREE;
02177 }
02178 else if (!real_lvalue_p (exp)
02179 || !TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (exp)))
02180 {
02181 init_expr = get_target_expr (exp);
02182 exp = TARGET_EXPR_SLOT (init_expr);
02183 }
02184 else
02185 {
02186 exp = build_unary_op (ADDR_EXPR, exp, 1);
02187 init_expr = get_target_expr (exp);
02188 exp = TARGET_EXPR_SLOT (init_expr);
02189 exp = build_indirect_ref (exp, 0);
02190 }
02191
02192 *initp = init_expr;
02193 return exp;
02194 }
02195
02196
02197
02198
02199 tree
02200 add_stmt_to_compound (tree orig, tree new)
02201 {
02202 if (!new || !TREE_SIDE_EFFECTS (new))
02203 return orig;
02204 if (!orig || !TREE_SIDE_EFFECTS (orig))
02205 return new;
02206 return build2 (COMPOUND_EXPR, void_type_node, orig, new);
02207 }
02208
02209
02210
02211
02212 void
02213 stabilize_call (tree call, tree *initp)
02214 {
02215 tree inits = NULL_TREE;
02216 tree t;
02217
02218 if (call == error_mark_node)
02219 return;
02220
02221 gcc_assert (TREE_CODE (call) == CALL_EXPR
02222 || TREE_CODE (call) == AGGR_INIT_EXPR);
02223
02224 for (t = TREE_OPERAND (call, 1); t; t = TREE_CHAIN (t))
02225 if (TREE_SIDE_EFFECTS (TREE_VALUE (t)))
02226 {
02227 tree init;
02228 TREE_VALUE (t) = stabilize_expr (TREE_VALUE (t), &init);
02229 inits = add_stmt_to_compound (inits, init);
02230 }
02231
02232 *initp = inits;
02233 }
02234
02235
02236
02237
02238
02239
02240 bool
02241 stabilize_init (tree init, tree *initp)
02242 {
02243 tree t = init;
02244
02245 if (t == error_mark_node)
02246 return true;
02247
02248 if (TREE_CODE (t) == INIT_EXPR
02249 && TREE_CODE (TREE_OPERAND (t, 1)) != TARGET_EXPR)
02250 TREE_OPERAND (t, 1) = stabilize_expr (TREE_OPERAND (t, 1), initp);
02251 else
02252 {
02253 if (TREE_CODE (t) == INIT_EXPR)
02254 t = TREE_OPERAND (t, 1);
02255 if (TREE_CODE (t) == TARGET_EXPR)
02256 t = TARGET_EXPR_INITIAL (t);
02257 if (TREE_CODE (t) == COMPOUND_EXPR)
02258 t = expr_last (t);
02259 if (TREE_CODE (t) == CONSTRUCTOR
02260 && CONSTRUCTOR_ELTS (t) == NULL_TREE)
02261 {
02262
02263 *initp = NULL_TREE;
02264 return true;
02265 }
02266
02267
02268
02269 if (TREE_CODE (t) == COND_EXPR)
02270 return false;
02271
02272
02273
02274 if (TREE_SIDE_EFFECTS (t))
02275 stabilize_call (t, initp);
02276 }
02277
02278 return true;
02279 }
02280
02281
02282
02283
02284 tree
02285 fold_if_not_in_template (tree expr)
02286 {
02287
02288
02289
02290
02291 return (processing_template_decl ? expr : fold (expr));
02292 }
02293
02294
02295 #if defined ENABLE_TREE_CHECKING && (GCC_VERSION >= 2007)
02296
02297
02298
02299 void
02300 lang_check_failed (const char* file, int line, const char* function)
02301 {
02302 internal_error ("lang_* check: failed in %s, at %s:%d",
02303 function, trim_filename (file), line);
02304 }
02305 #endif
02306
02307 #include "gt-cp-tree.h"