tree.c revision 90075
1/* Language-dependent node constructors for parse phase of GNU compiler. 2 Copyright (C) 1987, 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 3 1999, 2000, 2001 Free Software Foundation, Inc. 4 Hacked by Michael Tiemann (tiemann@cygnus.com) 5 6This file is part of GNU CC. 7 8GNU CC is free software; you can redistribute it and/or modify 9it under the terms of the GNU General Public License as published by 10the Free Software Foundation; either version 2, or (at your option) 11any later version. 12 13GNU CC is distributed in the hope that it will be useful, 14but WITHOUT ANY WARRANTY; without even the implied warranty of 15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16GNU General Public License for more details. 17 18You should have received a copy of the GNU General Public License 19along with GNU CC; see the file COPYING. If not, write to 20the Free Software Foundation, 59 Temple Place - Suite 330, 21Boston, MA 02111-1307, USA. */ 22 23#include "config.h" 24#include "system.h" 25#include "obstack.h" 26#include "tree.h" 27#include "cp-tree.h" 28#include "flags.h" 29#include "rtl.h" 30#include "toplev.h" 31#include "ggc.h" 32#include "insn-config.h" 33#include "integrate.h" 34#include "tree-inline.h" 35 36static tree bot_manip PARAMS ((tree *, int *, void *)); 37static tree bot_replace PARAMS ((tree *, int *, void *)); 38static tree build_cplus_array_type_1 PARAMS ((tree, tree)); 39static int list_hash_eq PARAMS ((const void *, const void *)); 40static hashval_t list_hash_pieces PARAMS ((tree, tree, tree)); 41static hashval_t list_hash PARAMS ((const void *)); 42static cp_lvalue_kind lvalue_p_1 PARAMS ((tree, int)); 43static tree no_linkage_helper PARAMS ((tree *, int *, void *)); 44static tree build_srcloc PARAMS ((const char *, int)); 45static tree mark_local_for_remap_r PARAMS ((tree *, int *, void *)); 46static tree cp_unsave_r PARAMS ((tree *, int *, void *)); 47static void cp_unsave PARAMS ((tree *)); 48static tree build_target_expr PARAMS ((tree, tree)); 49static tree count_trees_r PARAMS ((tree *, int *, void *)); 50static tree verify_stmt_tree_r PARAMS ((tree *, int *, void *)); 51static tree find_tree_r PARAMS ((tree *, int *, void *)); 52extern int cp_statement_code_p PARAMS ((enum tree_code)); 53 54static tree handle_java_interface_attribute PARAMS ((tree *, tree, tree, int, bool *)); 55static tree handle_com_interface_attribute PARAMS ((tree *, tree, tree, int, bool *)); 56static tree handle_init_priority_attribute PARAMS ((tree *, tree, tree, int, bool *)); 57 58/* If REF is an lvalue, returns the kind of lvalue that REF is. 59 Otherwise, returns clk_none. If TREAT_CLASS_RVALUES_AS_LVALUES is 60 non-zero, rvalues of class type are considered lvalues. */ 61 62static cp_lvalue_kind 63lvalue_p_1 (ref, treat_class_rvalues_as_lvalues) 64 tree ref; 65 int treat_class_rvalues_as_lvalues; 66{ 67 cp_lvalue_kind op1_lvalue_kind = clk_none; 68 cp_lvalue_kind op2_lvalue_kind = clk_none; 69 70 if (TREE_CODE (TREE_TYPE (ref)) == REFERENCE_TYPE) 71 return clk_ordinary; 72 73 if (ref == current_class_ptr) 74 return clk_none; 75 76 switch (TREE_CODE (ref)) 77 { 78 /* preincrements and predecrements are valid lvals, provided 79 what they refer to are valid lvals. */ 80 case PREINCREMENT_EXPR: 81 case PREDECREMENT_EXPR: 82 case SAVE_EXPR: 83 case UNSAVE_EXPR: 84 case TRY_CATCH_EXPR: 85 case WITH_CLEANUP_EXPR: 86 case REALPART_EXPR: 87 case IMAGPART_EXPR: 88 /* This shouldn't be here, but there are lots of places in the compiler 89 that are sloppy about tacking on NOP_EXPRs to the same type when 90 no actual conversion is happening. */ 91 case NOP_EXPR: 92 return lvalue_p_1 (TREE_OPERAND (ref, 0), 93 treat_class_rvalues_as_lvalues); 94 95 case COMPONENT_REF: 96 op1_lvalue_kind = lvalue_p_1 (TREE_OPERAND (ref, 0), 97 treat_class_rvalues_as_lvalues); 98 if (op1_lvalue_kind 99 /* The "field" can be a FUNCTION_DECL or an OVERLOAD in some 100 situations. */ 101 && TREE_CODE (TREE_OPERAND (ref, 1)) == FIELD_DECL 102 && DECL_C_BIT_FIELD (TREE_OPERAND (ref, 1))) 103 { 104 /* Clear the ordinary bit. If this object was a class 105 rvalue we want to preserve that information. */ 106 op1_lvalue_kind &= ~clk_ordinary; 107 /* The lvalue is for a btifield. */ 108 op1_lvalue_kind |= clk_bitfield; 109 } 110 return op1_lvalue_kind; 111 112 case STRING_CST: 113 return clk_ordinary; 114 115 case VAR_DECL: 116 if (TREE_READONLY (ref) && ! TREE_STATIC (ref) 117 && DECL_LANG_SPECIFIC (ref) 118 && DECL_IN_AGGR_P (ref)) 119 return clk_none; 120 case INDIRECT_REF: 121 case ARRAY_REF: 122 case PARM_DECL: 123 case RESULT_DECL: 124 if (TREE_CODE (TREE_TYPE (ref)) != METHOD_TYPE) 125 return clk_ordinary; 126 break; 127 128 /* A currently unresolved scope ref. */ 129 case SCOPE_REF: 130 abort (); 131 case OFFSET_REF: 132 if (TREE_CODE (TREE_OPERAND (ref, 1)) == FUNCTION_DECL) 133 return clk_ordinary; 134 /* Fall through. */ 135 case MAX_EXPR: 136 case MIN_EXPR: 137 op1_lvalue_kind = lvalue_p_1 (TREE_OPERAND (ref, 0), 138 treat_class_rvalues_as_lvalues); 139 op2_lvalue_kind = lvalue_p_1 (TREE_OPERAND (ref, 1), 140 treat_class_rvalues_as_lvalues); 141 break; 142 143 case COND_EXPR: 144 op1_lvalue_kind = lvalue_p_1 (TREE_OPERAND (ref, 1), 145 treat_class_rvalues_as_lvalues); 146 op2_lvalue_kind = lvalue_p_1 (TREE_OPERAND (ref, 2), 147 treat_class_rvalues_as_lvalues); 148 break; 149 150 case MODIFY_EXPR: 151 return clk_ordinary; 152 153 case COMPOUND_EXPR: 154 return lvalue_p_1 (TREE_OPERAND (ref, 1), 155 treat_class_rvalues_as_lvalues); 156 157 case TARGET_EXPR: 158 return treat_class_rvalues_as_lvalues ? clk_class : clk_none; 159 160 case CALL_EXPR: 161 case VA_ARG_EXPR: 162 return ((treat_class_rvalues_as_lvalues 163 && IS_AGGR_TYPE (TREE_TYPE (ref))) 164 ? clk_class : clk_none); 165 166 case FUNCTION_DECL: 167 /* All functions (except non-static-member functions) are 168 lvalues. */ 169 return (DECL_NONSTATIC_MEMBER_FUNCTION_P (ref) 170 ? clk_none : clk_ordinary); 171 172 default: 173 break; 174 } 175 176 /* If one operand is not an lvalue at all, then this expression is 177 not an lvalue. */ 178 if (!op1_lvalue_kind || !op2_lvalue_kind) 179 return clk_none; 180 181 /* Otherwise, it's an lvalue, and it has all the odd properties 182 contributed by either operand. */ 183 op1_lvalue_kind = op1_lvalue_kind | op2_lvalue_kind; 184 /* It's not an ordinary lvalue if it involves either a bit-field or 185 a class rvalue. */ 186 if ((op1_lvalue_kind & ~clk_ordinary) != clk_none) 187 op1_lvalue_kind &= ~clk_ordinary; 188 return op1_lvalue_kind; 189} 190 191/* If REF is an lvalue, returns the kind of lvalue that REF is. 192 Otherwise, returns clk_none. Lvalues can be assigned, unless they 193 have TREE_READONLY, or unless they are FUNCTION_DECLs. Lvalues can 194 have their address taken, unless they have DECL_REGISTER. */ 195 196cp_lvalue_kind 197real_lvalue_p (ref) 198 tree ref; 199{ 200 return lvalue_p_1 (ref, /*treat_class_rvalues_as_lvalues=*/0); 201} 202 203/* This differs from real_lvalue_p in that class rvalues are 204 considered lvalues. */ 205 206int 207lvalue_p (ref) 208 tree ref; 209{ 210 return 211 (lvalue_p_1 (ref, /*treat_class_rvalues_as_lvalues=*/1) != clk_none); 212} 213 214/* Return nonzero if REF is an lvalue valid for this language; 215 otherwise, print an error message and return zero. */ 216 217int 218lvalue_or_else (ref, string) 219 tree ref; 220 const char *string; 221{ 222 int win = lvalue_p (ref); 223 if (! win) 224 error ("non-lvalue in %s", string); 225 return win; 226} 227 228/* Build a TARGET_EXPR, initializing the DECL with the VALUE. */ 229 230static tree 231build_target_expr (decl, value) 232 tree decl; 233 tree value; 234{ 235 tree t; 236 237 t = build (TARGET_EXPR, TREE_TYPE (decl), decl, value, 238 maybe_build_cleanup (decl), NULL_TREE); 239 /* We always set TREE_SIDE_EFFECTS so that expand_expr does not 240 ignore the TARGET_EXPR. If there really turn out to be no 241 side-effects, then the optimizer should be able to get rid of 242 whatever code is generated anyhow. */ 243 TREE_SIDE_EFFECTS (t) = 1; 244 245 return t; 246} 247 248/* INIT is a CALL_EXPR which needs info about its target. 249 TYPE is the type that this initialization should appear to have. 250 251 Build an encapsulation of the initialization to perform 252 and return it so that it can be processed by language-independent 253 and language-specific expression expanders. */ 254 255tree 256build_cplus_new (type, init) 257 tree type; 258 tree init; 259{ 260 tree fn; 261 tree slot; 262 tree rval; 263 264 /* Make sure that we're not trying to create an instance of an 265 abstract class. */ 266 abstract_virtuals_error (NULL_TREE, type); 267 268 if (TREE_CODE (init) != CALL_EXPR && TREE_CODE (init) != AGGR_INIT_EXPR) 269 return convert (type, init); 270 271 slot = build (VAR_DECL, type); 272 DECL_ARTIFICIAL (slot) = 1; 273 DECL_CONTEXT (slot) = current_function_decl; 274 layout_decl (slot, 0); 275 276 /* We split the CALL_EXPR into its function and its arguments here. 277 Then, in expand_expr, we put them back together. The reason for 278 this is that this expression might be a default argument 279 expression. In that case, we need a new temporary every time the 280 expression is used. That's what break_out_target_exprs does; it 281 replaces every AGGR_INIT_EXPR with a copy that uses a fresh 282 temporary slot. Then, expand_expr builds up a call-expression 283 using the new slot. */ 284 fn = TREE_OPERAND (init, 0); 285 rval = build (AGGR_INIT_EXPR, type, fn, TREE_OPERAND (init, 1), slot); 286 TREE_SIDE_EFFECTS (rval) = 1; 287 AGGR_INIT_VIA_CTOR_P (rval) 288 = (TREE_CODE (fn) == ADDR_EXPR 289 && TREE_CODE (TREE_OPERAND (fn, 0)) == FUNCTION_DECL 290 && DECL_CONSTRUCTOR_P (TREE_OPERAND (fn, 0))); 291 rval = build_target_expr (slot, rval); 292 293 return rval; 294} 295 296/* Buidl a TARGET_EXPR using INIT to initialize a new temporary of the 297 indicated TYPE. */ 298 299tree 300build_target_expr_with_type (init, type) 301 tree init; 302 tree type; 303{ 304 tree slot; 305 tree rval; 306 307 if (TREE_CODE (init) == TARGET_EXPR) 308 return init; 309 310 slot = build (VAR_DECL, type); 311 DECL_ARTIFICIAL (slot) = 1; 312 DECL_CONTEXT (slot) = current_function_decl; 313 layout_decl (slot, 0); 314 rval = build_target_expr (slot, init); 315 316 return rval; 317} 318 319/* Like build_target_expr_with_type, but use the type of INIT. */ 320 321tree 322get_target_expr (init) 323 tree init; 324{ 325 return build_target_expr_with_type (init, TREE_TYPE (init)); 326} 327 328/* Recursively perform a preorder search EXP for CALL_EXPRs, making 329 copies where they are found. Returns a deep copy all nodes transitively 330 containing CALL_EXPRs. */ 331 332tree 333break_out_calls (exp) 334 tree exp; 335{ 336 register tree t1, t2 = NULL_TREE; 337 register enum tree_code code; 338 register int changed = 0; 339 register int i; 340 341 if (exp == NULL_TREE) 342 return exp; 343 344 code = TREE_CODE (exp); 345 346 if (code == CALL_EXPR) 347 return copy_node (exp); 348 349 /* Don't try and defeat a save_expr, as it should only be done once. */ 350 if (code == SAVE_EXPR) 351 return exp; 352 353 switch (TREE_CODE_CLASS (code)) 354 { 355 default: 356 abort (); 357 358 case 'c': /* a constant */ 359 case 't': /* a type node */ 360 case 'x': /* something random, like an identifier or an ERROR_MARK. */ 361 return exp; 362 363 case 'd': /* A decl node */ 364#if 0 /* This is bogus. jason 9/21/94 */ 365 366 t1 = break_out_calls (DECL_INITIAL (exp)); 367 if (t1 != DECL_INITIAL (exp)) 368 { 369 exp = copy_node (exp); 370 DECL_INITIAL (exp) = t1; 371 } 372#endif 373 return exp; 374 375 case 'b': /* A block node */ 376 { 377 /* Don't know how to handle these correctly yet. Must do a 378 break_out_calls on all DECL_INITIAL values for local variables, 379 and also break_out_calls on all sub-blocks and sub-statements. */ 380 abort (); 381 } 382 return exp; 383 384 case 'e': /* an expression */ 385 case 'r': /* a reference */ 386 case 's': /* an expression with side effects */ 387 for (i = TREE_CODE_LENGTH (code) - 1; i >= 0; i--) 388 { 389 t1 = break_out_calls (TREE_OPERAND (exp, i)); 390 if (t1 != TREE_OPERAND (exp, i)) 391 { 392 exp = copy_node (exp); 393 TREE_OPERAND (exp, i) = t1; 394 } 395 } 396 return exp; 397 398 case '<': /* a comparison expression */ 399 case '2': /* a binary arithmetic expression */ 400 t2 = break_out_calls (TREE_OPERAND (exp, 1)); 401 if (t2 != TREE_OPERAND (exp, 1)) 402 changed = 1; 403 case '1': /* a unary arithmetic expression */ 404 t1 = break_out_calls (TREE_OPERAND (exp, 0)); 405 if (t1 != TREE_OPERAND (exp, 0)) 406 changed = 1; 407 if (changed) 408 { 409 if (TREE_CODE_LENGTH (code) == 1) 410 return build1 (code, TREE_TYPE (exp), t1); 411 else 412 return build (code, TREE_TYPE (exp), t1, t2); 413 } 414 return exp; 415 } 416 417} 418 419/* Construct, lay out and return the type of methods belonging to class 420 BASETYPE and whose arguments are described by ARGTYPES and whose values 421 are described by RETTYPE. If each type exists already, reuse it. */ 422 423tree 424build_cplus_method_type (basetype, rettype, argtypes) 425 tree basetype, rettype, argtypes; 426{ 427 register tree t; 428 tree ptype; 429 int hashcode; 430 431 /* Make a node of the sort we want. */ 432 t = make_node (METHOD_TYPE); 433 434 TYPE_METHOD_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype); 435 TREE_TYPE (t) = rettype; 436 ptype = build_pointer_type (basetype); 437 438 /* The actual arglist for this function includes a "hidden" argument 439 which is "this". Put it into the list of argument types. */ 440 argtypes = tree_cons (NULL_TREE, ptype, argtypes); 441 TYPE_ARG_TYPES (t) = argtypes; 442 TREE_SIDE_EFFECTS (argtypes) = 1; /* Mark first argtype as "artificial". */ 443 444 /* If we already have such a type, use the old one and free this one. 445 Note that it also frees up the above cons cell if found. */ 446 hashcode = TYPE_HASH (basetype) + TYPE_HASH (rettype) + 447 type_hash_list (argtypes); 448 449 t = type_hash_canon (hashcode, t); 450 451 if (!COMPLETE_TYPE_P (t)) 452 layout_type (t); 453 454 return t; 455} 456 457static tree 458build_cplus_array_type_1 (elt_type, index_type) 459 tree elt_type; 460 tree index_type; 461{ 462 tree t; 463 464 if (elt_type == error_mark_node || index_type == error_mark_node) 465 return error_mark_node; 466 467 if (processing_template_decl 468 || uses_template_parms (elt_type) 469 || uses_template_parms (index_type)) 470 { 471 t = make_node (ARRAY_TYPE); 472 TREE_TYPE (t) = elt_type; 473 TYPE_DOMAIN (t) = index_type; 474 } 475 else 476 t = build_array_type (elt_type, index_type); 477 478 /* Push these needs up so that initialization takes place 479 more easily. */ 480 TYPE_NEEDS_CONSTRUCTING (t) 481 = TYPE_NEEDS_CONSTRUCTING (TYPE_MAIN_VARIANT (elt_type)); 482 TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t) 483 = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TYPE_MAIN_VARIANT (elt_type)); 484 return t; 485} 486 487tree 488build_cplus_array_type (elt_type, index_type) 489 tree elt_type; 490 tree index_type; 491{ 492 tree t; 493 int type_quals = cp_type_quals (elt_type); 494 495 if (type_quals != TYPE_UNQUALIFIED) 496 elt_type = cp_build_qualified_type (elt_type, TYPE_UNQUALIFIED); 497 498 t = build_cplus_array_type_1 (elt_type, index_type); 499 500 if (type_quals != TYPE_UNQUALIFIED) 501 t = cp_build_qualified_type (t, type_quals); 502 503 return t; 504} 505 506/* Make a variant of TYPE, qualified with the TYPE_QUALS. Handles 507 arrays correctly. In particular, if TYPE is an array of T's, and 508 TYPE_QUALS is non-empty, returns an array of qualified T's. If 509 at attempt is made to qualify a type illegally, and COMPLAIN is 510 non-zero, an error is issued. If COMPLAIN is zero, error_mark_node 511 is returned. */ 512 513tree 514cp_build_qualified_type_real (type, type_quals, complain) 515 tree type; 516 int type_quals; 517 int complain; 518{ 519 tree result; 520 521 if (type == error_mark_node) 522 return type; 523 524 if (type_quals == cp_type_quals (type)) 525 return type; 526 527 /* A restrict-qualified pointer type must be a pointer (or reference) 528 to object or incomplete type. */ 529 if ((type_quals & TYPE_QUAL_RESTRICT) 530 && TREE_CODE (type) != TEMPLATE_TYPE_PARM 531 && (!POINTER_TYPE_P (type) 532 || TYPE_PTRMEM_P (type) 533 || TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE)) 534 { 535 if (complain) 536 error ("`%T' cannot be `restrict'-qualified", type); 537 else 538 return error_mark_node; 539 540 type_quals &= ~TYPE_QUAL_RESTRICT; 541 } 542 543 if (type_quals != TYPE_UNQUALIFIED 544 && TREE_CODE (type) == FUNCTION_TYPE) 545 { 546 if (complain) 547 error ("`%T' cannot be `const'-, `volatile'-, or `restrict'-qualified", type); 548 else 549 return error_mark_node; 550 type_quals = TYPE_UNQUALIFIED; 551 } 552 else if (TREE_CODE (type) == ARRAY_TYPE) 553 { 554 /* In C++, the qualification really applies to the array element 555 type. Obtain the appropriately qualified element type. */ 556 tree t; 557 tree element_type 558 = cp_build_qualified_type_real (TREE_TYPE (type), 559 type_quals, 560 complain); 561 562 if (element_type == error_mark_node) 563 return error_mark_node; 564 565 /* See if we already have an identically qualified type. */ 566 t = get_qualified_type (type, type_quals); 567 568 /* If we didn't already have it, create it now. */ 569 if (!t) 570 { 571 /* Make a new array type, just like the old one, but with the 572 appropriately qualified element type. */ 573 t = build_type_copy (type); 574 TREE_TYPE (t) = element_type; 575 } 576 577 /* Even if we already had this variant, we update 578 TYPE_NEEDS_CONSTRUCTING and TYPE_HAS_NONTRIVIAL_DESTRUCTOR in case 579 they changed since the variant was originally created. 580 581 This seems hokey; if there is some way to use a previous 582 variant *without* coming through here, 583 TYPE_NEEDS_CONSTRUCTING will never be updated. */ 584 TYPE_NEEDS_CONSTRUCTING (t) 585 = TYPE_NEEDS_CONSTRUCTING (TYPE_MAIN_VARIANT (element_type)); 586 TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t) 587 = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TYPE_MAIN_VARIANT (element_type)); 588 return t; 589 } 590 else if (TYPE_PTRMEMFUNC_P (type)) 591 { 592 /* For a pointer-to-member type, we can't just return a 593 cv-qualified version of the RECORD_TYPE. If we do, we 594 haven't change the field that contains the actual pointer to 595 a method, and so TYPE_PTRMEMFUNC_FN_TYPE will be wrong. */ 596 tree t; 597 598 t = TYPE_PTRMEMFUNC_FN_TYPE (type); 599 t = cp_build_qualified_type_real (t, type_quals, complain); 600 return build_ptrmemfunc_type (t); 601 } 602 603 /* Retrieve (or create) the appropriately qualified variant. */ 604 result = build_qualified_type (type, type_quals); 605 606 /* If this was a pointer-to-method type, and we just made a copy, 607 then we need to clear the cached associated 608 pointer-to-member-function type; it is not valid for the new 609 type. */ 610 if (result != type 611 && TREE_CODE (type) == POINTER_TYPE 612 && TREE_CODE (TREE_TYPE (type)) == METHOD_TYPE) 613 TYPE_SET_PTRMEMFUNC_TYPE (result, NULL_TREE); 614 615 return result; 616} 617 618/* Returns the canonical version of TYPE. In other words, if TYPE is 619 a typedef, returns the underlying type. The cv-qualification of 620 the type returned matches the type input; they will always be 621 compatible types. */ 622 623tree 624canonical_type_variant (t) 625 tree t; 626{ 627 return cp_build_qualified_type (TYPE_MAIN_VARIANT (t), cp_type_quals (t)); 628} 629 630/* Makes new binfos for the indirect bases under BINFO, and updates 631 BINFO_OFFSET for them and their bases. */ 632 633void 634unshare_base_binfos (binfo) 635 tree binfo; 636{ 637 tree binfos = BINFO_BASETYPES (binfo); 638 tree new_binfo; 639 int j; 640 641 if (binfos == NULL_TREE) 642 return; 643 644 /* Now unshare the structure beneath BINFO. */ 645 for (j = TREE_VEC_LENGTH (binfos)-1; 646 j >= 0; j--) 647 { 648 tree base_binfo = TREE_VEC_ELT (binfos, j); 649 new_binfo = TREE_VEC_ELT (binfos, j) 650 = make_binfo (BINFO_OFFSET (base_binfo), 651 base_binfo, 652 BINFO_VTABLE (base_binfo), 653 BINFO_VIRTUALS (base_binfo)); 654 TREE_VIA_PUBLIC (new_binfo) = TREE_VIA_PUBLIC (base_binfo); 655 TREE_VIA_PROTECTED (new_binfo) = TREE_VIA_PROTECTED (base_binfo); 656 TREE_VIA_VIRTUAL (new_binfo) = TREE_VIA_VIRTUAL (base_binfo); 657 BINFO_INHERITANCE_CHAIN (new_binfo) = binfo; 658 BINFO_PRIMARY_BASE_OF (new_binfo) = NULL_TREE; 659 unshare_base_binfos (new_binfo); 660 } 661} 662 663 664/* Hashing of lists so that we don't make duplicates. 665 The entry point is `list_hash_canon'. */ 666 667/* Now here is the hash table. When recording a list, it is added 668 to the slot whose index is the hash code mod the table size. 669 Note that the hash table is used for several kinds of lists. 670 While all these live in the same table, they are completely independent, 671 and the hash code is computed differently for each of these. */ 672 673static htab_t list_hash_table; 674 675struct list_proxy 676{ 677 tree purpose; 678 tree value; 679 tree chain; 680}; 681 682/* Compare ENTRY (an entry in the hash table) with DATA (a list_proxy 683 for a node we are thinking about adding). */ 684 685static int 686list_hash_eq (entry, data) 687 const void *entry; 688 const void *data; 689{ 690 tree t = (tree) entry; 691 struct list_proxy *proxy = (struct list_proxy *) data; 692 693 return (TREE_VALUE (t) == proxy->value 694 && TREE_PURPOSE (t) == proxy->purpose 695 && TREE_CHAIN (t) == proxy->chain); 696} 697 698/* Compute a hash code for a list (chain of TREE_LIST nodes 699 with goodies in the TREE_PURPOSE, TREE_VALUE, and bits of the 700 TREE_COMMON slots), by adding the hash codes of the individual entries. */ 701 702static hashval_t 703list_hash_pieces (purpose, value, chain) 704 tree purpose; 705 tree value; 706 tree chain; 707{ 708 hashval_t hashcode = 0; 709 710 if (chain) 711 hashcode += TYPE_HASH (chain); 712 713 if (value) 714 hashcode += TYPE_HASH (value); 715 else 716 hashcode += 1007; 717 if (purpose) 718 hashcode += TYPE_HASH (purpose); 719 else 720 hashcode += 1009; 721 return hashcode; 722} 723 724/* Hash an already existing TREE_LIST. */ 725 726static hashval_t 727list_hash (p) 728 const void *p; 729{ 730 tree t = (tree) p; 731 return list_hash_pieces (TREE_PURPOSE (t), 732 TREE_VALUE (t), 733 TREE_CHAIN (t)); 734} 735 736/* Given list components PURPOSE, VALUE, AND CHAIN, return the canonical 737 object for an identical list if one already exists. Otherwise, build a 738 new one, and record it as the canonical object. */ 739 740tree 741hash_tree_cons (purpose, value, chain) 742 tree purpose, value, chain; 743{ 744 int hashcode = 0; 745 PTR* slot; 746 struct list_proxy proxy; 747 748 /* Hash the list node. */ 749 hashcode = list_hash_pieces (purpose, value, chain); 750 /* Create a proxy for the TREE_LIST we would like to create. We 751 don't actually create it so as to avoid creating garbage. */ 752 proxy.purpose = purpose; 753 proxy.value = value; 754 proxy.chain = chain; 755 /* See if it is already in the table. */ 756 slot = htab_find_slot_with_hash (list_hash_table, &proxy, hashcode, 757 INSERT); 758 /* If not, create a new node. */ 759 if (!*slot) 760 *slot = (PTR) tree_cons (purpose, value, chain); 761 return *slot; 762} 763 764/* Constructor for hashed lists. */ 765 766tree 767hash_tree_chain (value, chain) 768 tree value, chain; 769{ 770 return hash_tree_cons (NULL_TREE, value, chain); 771} 772 773/* Similar, but used for concatenating two lists. */ 774 775tree 776hash_chainon (list1, list2) 777 tree list1, list2; 778{ 779 if (list2 == 0) 780 return list1; 781 if (list1 == 0) 782 return list2; 783 if (TREE_CHAIN (list1) == NULL_TREE) 784 return hash_tree_chain (TREE_VALUE (list1), list2); 785 return hash_tree_chain (TREE_VALUE (list1), 786 hash_chainon (TREE_CHAIN (list1), list2)); 787} 788 789/* Build an association between TYPE and some parameters: 790 791 OFFSET is the offset added to `this' to convert it to a pointer 792 of type `TYPE *' 793 794 BINFO is the base binfo to use, if we are deriving from one. This 795 is necessary, as we want specialized parent binfos from base 796 classes, so that the VTABLE_NAMEs of bases are for the most derived 797 type, instead of the simple type. 798 799 VTABLE is the virtual function table with which to initialize 800 sub-objects of type TYPE. 801 802 VIRTUALS are the virtual functions sitting in VTABLE. */ 803 804tree 805make_binfo (offset, binfo, vtable, virtuals) 806 tree offset, binfo; 807 tree vtable, virtuals; 808{ 809 tree new_binfo = make_tree_vec (11); 810 tree type; 811 812 if (TREE_CODE (binfo) == TREE_VEC) 813 type = BINFO_TYPE (binfo); 814 else 815 { 816 type = binfo; 817 binfo = CLASS_TYPE_P (type) ? TYPE_BINFO (binfo) : NULL_TREE; 818 } 819 820 TREE_TYPE (new_binfo) = TYPE_MAIN_VARIANT (type); 821 BINFO_OFFSET (new_binfo) = offset; 822 BINFO_VTABLE (new_binfo) = vtable; 823 BINFO_VIRTUALS (new_binfo) = virtuals; 824 825 if (binfo && BINFO_BASETYPES (binfo) != NULL_TREE) 826 BINFO_BASETYPES (new_binfo) = copy_node (BINFO_BASETYPES (binfo)); 827 return new_binfo; 828} 829 830/* Return a TREE_LIST whose TREE_VALUE nodes along the 831 BINFO_INHERITANCE_CHAIN for BINFO, but in the opposite order. In 832 other words, while the BINFO_INHERITANCE_CHAIN goes from base 833 classes to derived classes, the reversed path goes from derived 834 classes to base classes. */ 835 836tree 837reverse_path (binfo) 838 tree binfo; 839{ 840 tree reversed_path; 841 842 reversed_path = NULL_TREE; 843 while (binfo) 844 { 845 reversed_path = tree_cons (NULL_TREE, binfo, reversed_path); 846 binfo = BINFO_INHERITANCE_CHAIN (binfo); 847 } 848 849 return reversed_path; 850} 851 852void 853debug_binfo (elem) 854 tree elem; 855{ 856 HOST_WIDE_INT n; 857 tree virtuals; 858 859 fprintf (stderr, "type \"%s\", offset = ", 860 TYPE_NAME_STRING (BINFO_TYPE (elem))); 861 fprintf (stderr, HOST_WIDE_INT_PRINT_DEC, 862 TREE_INT_CST_LOW (BINFO_OFFSET (elem))); 863 fprintf (stderr, "\nvtable type:\n"); 864 debug_tree (BINFO_TYPE (elem)); 865 if (BINFO_VTABLE (elem)) 866 fprintf (stderr, "vtable decl \"%s\"\n", 867 IDENTIFIER_POINTER (DECL_NAME (get_vtbl_decl_for_binfo (elem)))); 868 else 869 fprintf (stderr, "no vtable decl yet\n"); 870 fprintf (stderr, "virtuals:\n"); 871 virtuals = BINFO_VIRTUALS (elem); 872 n = 0; 873 874 while (virtuals) 875 { 876 tree fndecl = TREE_VALUE (virtuals); 877 fprintf (stderr, "%s [%ld =? %ld]\n", 878 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (fndecl)), 879 (long) n, (long) TREE_INT_CST_LOW (DECL_VINDEX (fndecl))); 880 ++n; 881 virtuals = TREE_CHAIN (virtuals); 882 } 883} 884 885int 886count_functions (t) 887 tree t; 888{ 889 int i; 890 if (TREE_CODE (t) == FUNCTION_DECL) 891 return 1; 892 else if (TREE_CODE (t) == OVERLOAD) 893 { 894 for (i=0; t; t = OVL_CHAIN (t)) 895 i++; 896 return i; 897 } 898 899 abort (); 900 return 0; 901} 902 903int 904is_overloaded_fn (x) 905 tree x; 906{ 907 /* A baselink is also considered an overloaded function. */ 908 if (TREE_CODE (x) == OFFSET_REF) 909 x = TREE_OPERAND (x, 1); 910 if (BASELINK_P (x)) 911 x = TREE_VALUE (x); 912 return (TREE_CODE (x) == FUNCTION_DECL 913 || TREE_CODE (x) == TEMPLATE_ID_EXPR 914 || DECL_FUNCTION_TEMPLATE_P (x) 915 || TREE_CODE (x) == OVERLOAD); 916} 917 918int 919really_overloaded_fn (x) 920 tree x; 921{ 922 /* A baselink is also considered an overloaded function. */ 923 if (TREE_CODE (x) == OFFSET_REF) 924 x = TREE_OPERAND (x, 1); 925 if (BASELINK_P (x)) 926 x = TREE_VALUE (x); 927 return (TREE_CODE (x) == OVERLOAD 928 && (TREE_CHAIN (x) != NULL_TREE 929 || DECL_FUNCTION_TEMPLATE_P (OVL_FUNCTION (x)))); 930} 931 932tree 933get_first_fn (from) 934 tree from; 935{ 936 my_friendly_assert (is_overloaded_fn (from), 9); 937 /* A baselink is also considered an overloaded function. */ 938 if (BASELINK_P (from)) 939 from = TREE_VALUE (from); 940 return OVL_CURRENT (from); 941} 942 943/* Returns nonzero if T is a ->* or .* expression that refers to a 944 member function. */ 945 946int 947bound_pmf_p (t) 948 tree t; 949{ 950 return (TREE_CODE (t) == OFFSET_REF 951 && TYPE_PTRMEMFUNC_P (TREE_TYPE (TREE_OPERAND (t, 1)))); 952} 953 954/* Return a new OVL node, concatenating it with the old one. */ 955 956tree 957ovl_cons (decl, chain) 958 tree decl; 959 tree chain; 960{ 961 tree result = make_node (OVERLOAD); 962 TREE_TYPE (result) = unknown_type_node; 963 OVL_FUNCTION (result) = decl; 964 TREE_CHAIN (result) = chain; 965 966 return result; 967} 968 969/* Build a new overloaded function. If this is the first one, 970 just return it; otherwise, ovl_cons the _DECLs */ 971 972tree 973build_overload (decl, chain) 974 tree decl; 975 tree chain; 976{ 977 if (! chain && TREE_CODE (decl) != TEMPLATE_DECL) 978 return decl; 979 if (chain && TREE_CODE (chain) != OVERLOAD) 980 chain = ovl_cons (chain, NULL_TREE); 981 return ovl_cons (decl, chain); 982} 983 984int 985is_aggr_type_2 (t1, t2) 986 tree t1, t2; 987{ 988 if (TREE_CODE (t1) != TREE_CODE (t2)) 989 return 0; 990 return IS_AGGR_TYPE (t1) && IS_AGGR_TYPE (t2); 991} 992 993/* Returns non-zero if CODE is the code for a statement. */ 994 995int 996cp_statement_code_p (code) 997 enum tree_code code; 998{ 999 switch (code) 1000 { 1001 case SUBOBJECT: 1002 case CLEANUP_STMT: 1003 case CTOR_STMT: 1004 case CTOR_INITIALIZER: 1005 case RETURN_INIT: 1006 case TRY_BLOCK: 1007 case HANDLER: 1008 case EH_SPEC_BLOCK: 1009 case USING_STMT: 1010 case TAG_DEFN: 1011 return 1; 1012 1013 default: 1014 return 0; 1015 } 1016} 1017 1018#define PRINT_RING_SIZE 4 1019 1020const char * 1021lang_printable_name (decl, v) 1022 tree decl; 1023 int v; 1024{ 1025 static tree decl_ring[PRINT_RING_SIZE]; 1026 static char *print_ring[PRINT_RING_SIZE]; 1027 static int ring_counter; 1028 int i; 1029 1030 /* Only cache functions. */ 1031 if (v < 2 1032 || TREE_CODE (decl) != FUNCTION_DECL 1033 || DECL_LANG_SPECIFIC (decl) == 0) 1034 return lang_decl_name (decl, v); 1035 1036 /* See if this print name is lying around. */ 1037 for (i = 0; i < PRINT_RING_SIZE; i++) 1038 if (decl_ring[i] == decl) 1039 /* yes, so return it. */ 1040 return print_ring[i]; 1041 1042 if (++ring_counter == PRINT_RING_SIZE) 1043 ring_counter = 0; 1044 1045 if (current_function_decl != NULL_TREE) 1046 { 1047 if (decl_ring[ring_counter] == current_function_decl) 1048 ring_counter += 1; 1049 if (ring_counter == PRINT_RING_SIZE) 1050 ring_counter = 0; 1051 if (decl_ring[ring_counter] == current_function_decl) 1052 abort (); 1053 } 1054 1055 if (print_ring[ring_counter]) 1056 free (print_ring[ring_counter]); 1057 1058 print_ring[ring_counter] = xstrdup (lang_decl_name (decl, v)); 1059 decl_ring[ring_counter] = decl; 1060 return print_ring[ring_counter]; 1061} 1062 1063/* Build the FUNCTION_TYPE or METHOD_TYPE which may throw exceptions 1064 listed in RAISES. */ 1065 1066tree 1067build_exception_variant (type, raises) 1068 tree type; 1069 tree raises; 1070{ 1071 tree v = TYPE_MAIN_VARIANT (type); 1072 int type_quals = TYPE_QUALS (type); 1073 1074 for (; v; v = TYPE_NEXT_VARIANT (v)) 1075 if (TYPE_QUALS (v) == type_quals 1076 && comp_except_specs (raises, TYPE_RAISES_EXCEPTIONS (v), 1)) 1077 return v; 1078 1079 /* Need to build a new variant. */ 1080 v = build_type_copy (type); 1081 TYPE_RAISES_EXCEPTIONS (v) = raises; 1082 return v; 1083} 1084 1085/* Given a TEMPLATE_TEMPLATE_PARM node T, create a new 1086 BOUND_TEMPLATE_TEMPLATE_PARM bound with NEWARGS as its template 1087 arguments. */ 1088 1089tree 1090bind_template_template_parm (t, newargs) 1091 tree t; 1092 tree newargs; 1093{ 1094 tree decl = TYPE_NAME (t); 1095 tree t2; 1096 1097 t2 = make_aggr_type (BOUND_TEMPLATE_TEMPLATE_PARM); 1098 decl = build_decl (TYPE_DECL, DECL_NAME (decl), NULL_TREE); 1099 1100 /* These nodes have to be created to reflect new TYPE_DECL and template 1101 arguments. */ 1102 TEMPLATE_TYPE_PARM_INDEX (t2) = copy_node (TEMPLATE_TYPE_PARM_INDEX (t)); 1103 TEMPLATE_PARM_DECL (TEMPLATE_TYPE_PARM_INDEX (t2)) = decl; 1104 TEMPLATE_TEMPLATE_PARM_TEMPLATE_INFO (t2) 1105 = tree_cons (TEMPLATE_TEMPLATE_PARM_TEMPLATE_DECL (t), 1106 newargs, NULL_TREE); 1107 1108 TREE_TYPE (decl) = t2; 1109 TYPE_NAME (t2) = decl; 1110 TYPE_STUB_DECL (t2) = decl; 1111 TYPE_SIZE (t2) = 0; 1112 1113 return t2; 1114} 1115 1116/* Called from count_trees via walk_tree. */ 1117 1118static tree 1119count_trees_r (tp, walk_subtrees, data) 1120 tree *tp ATTRIBUTE_UNUSED; 1121 int *walk_subtrees ATTRIBUTE_UNUSED; 1122 void *data; 1123{ 1124 ++ *((int*) data); 1125 return NULL_TREE; 1126} 1127 1128/* Debugging function for measuring the rough complexity of a tree 1129 representation. */ 1130 1131int 1132count_trees (t) 1133 tree t; 1134{ 1135 int n_trees = 0; 1136 walk_tree_without_duplicates (&t, count_trees_r, &n_trees); 1137 return n_trees; 1138} 1139 1140/* Called from verify_stmt_tree via walk_tree. */ 1141 1142static tree 1143verify_stmt_tree_r (tp, walk_subtrees, data) 1144 tree *tp; 1145 int *walk_subtrees ATTRIBUTE_UNUSED; 1146 void *data; 1147{ 1148 tree t = *tp; 1149 htab_t *statements = (htab_t *) data; 1150 void **slot; 1151 1152 if (!statement_code_p (TREE_CODE (t))) 1153 return NULL_TREE; 1154 1155 /* If this statement is already present in the hash table, then 1156 there is a circularity in the statement tree. */ 1157 if (htab_find (*statements, t)) 1158 abort (); 1159 1160 slot = htab_find_slot (*statements, t, INSERT); 1161 *slot = t; 1162 1163 return NULL_TREE; 1164} 1165 1166/* Debugging function to check that the statement T has not been 1167 corrupted. For now, this function simply checks that T contains no 1168 circularities. */ 1169 1170void 1171verify_stmt_tree (t) 1172 tree t; 1173{ 1174 htab_t statements; 1175 statements = htab_create (37, htab_hash_pointer, htab_eq_pointer, NULL); 1176 walk_tree (&t, verify_stmt_tree_r, &statements, NULL); 1177 htab_delete (statements); 1178} 1179 1180/* Called from find_tree via walk_tree. */ 1181 1182static tree 1183find_tree_r (tp, walk_subtrees, data) 1184 tree *tp; 1185 int *walk_subtrees ATTRIBUTE_UNUSED; 1186 void *data; 1187{ 1188 if (*tp == (tree) data) 1189 return (tree) data; 1190 1191 return NULL_TREE; 1192} 1193 1194/* Returns X if X appears in the tree structure rooted at T. */ 1195 1196tree 1197find_tree (t, x) 1198 tree t; 1199 tree x; 1200{ 1201 return walk_tree_without_duplicates (&t, find_tree_r, x); 1202} 1203 1204/* Passed to walk_tree. Checks for the use of types with no linkage. */ 1205 1206static tree 1207no_linkage_helper (tp, walk_subtrees, data) 1208 tree *tp; 1209 int *walk_subtrees ATTRIBUTE_UNUSED; 1210 void *data ATTRIBUTE_UNUSED; 1211{ 1212 tree t = *tp; 1213 1214 if (TYPE_P (t) 1215 && (CLASS_TYPE_P (t) || TREE_CODE (t) == ENUMERAL_TYPE) 1216 && (decl_function_context (TYPE_MAIN_DECL (t)) 1217 || TYPE_ANONYMOUS_P (t))) 1218 return t; 1219 return NULL_TREE; 1220} 1221 1222/* Check if the type T depends on a type with no linkage and if so, return 1223 it. */ 1224 1225tree 1226no_linkage_check (t) 1227 tree t; 1228{ 1229 /* There's no point in checking linkage on template functions; we 1230 can't know their complete types. */ 1231 if (processing_template_decl) 1232 return NULL_TREE; 1233 1234 t = walk_tree_without_duplicates (&t, no_linkage_helper, NULL); 1235 if (t != error_mark_node) 1236 return t; 1237 return NULL_TREE; 1238} 1239 1240#ifdef GATHER_STATISTICS 1241extern int depth_reached; 1242#endif 1243 1244void 1245cxx_print_statistics () 1246{ 1247 print_search_statistics (); 1248 print_class_statistics (); 1249#ifdef GATHER_STATISTICS 1250 fprintf (stderr, "maximum template instantiation depth reached: %d\n", 1251 depth_reached); 1252#endif 1253} 1254 1255/* Return, as an INTEGER_CST node, the number of elements for TYPE 1256 (which is an ARRAY_TYPE). This counts only elements of the top 1257 array. */ 1258 1259tree 1260array_type_nelts_top (type) 1261 tree type; 1262{ 1263 return fold (build (PLUS_EXPR, sizetype, 1264 array_type_nelts (type), 1265 integer_one_node)); 1266} 1267 1268/* Return, as an INTEGER_CST node, the number of elements for TYPE 1269 (which is an ARRAY_TYPE). This one is a recursive count of all 1270 ARRAY_TYPEs that are clumped together. */ 1271 1272tree 1273array_type_nelts_total (type) 1274 tree type; 1275{ 1276 tree sz = array_type_nelts_top (type); 1277 type = TREE_TYPE (type); 1278 while (TREE_CODE (type) == ARRAY_TYPE) 1279 { 1280 tree n = array_type_nelts_top (type); 1281 sz = fold (build (MULT_EXPR, sizetype, sz, n)); 1282 type = TREE_TYPE (type); 1283 } 1284 return sz; 1285} 1286 1287/* Called from break_out_target_exprs via mapcar. */ 1288 1289static tree 1290bot_manip (tp, walk_subtrees, data) 1291 tree *tp; 1292 int *walk_subtrees; 1293 void *data; 1294{ 1295 splay_tree target_remap = ((splay_tree) data); 1296 tree t = *tp; 1297 1298 if (TREE_CONSTANT (t)) 1299 { 1300 /* There can't be any TARGET_EXPRs or their slot variables below 1301 this point. We used to check !TREE_SIDE_EFFECTS, but then we 1302 failed to copy an ADDR_EXPR of the slot VAR_DECL. */ 1303 *walk_subtrees = 0; 1304 return NULL_TREE; 1305 } 1306 if (TREE_CODE (t) == TARGET_EXPR) 1307 { 1308 tree u; 1309 1310 if (TREE_CODE (TREE_OPERAND (t, 1)) == AGGR_INIT_EXPR) 1311 { 1312 mark_used (TREE_OPERAND (TREE_OPERAND (TREE_OPERAND (t, 1), 0), 0)); 1313 u = build_cplus_new 1314 (TREE_TYPE (t), break_out_target_exprs (TREE_OPERAND (t, 1))); 1315 } 1316 else 1317 { 1318 u = build_target_expr_with_type 1319 (break_out_target_exprs (TREE_OPERAND (t, 1)), TREE_TYPE (t)); 1320 } 1321 1322 /* Map the old variable to the new one. */ 1323 splay_tree_insert (target_remap, 1324 (splay_tree_key) TREE_OPERAND (t, 0), 1325 (splay_tree_value) TREE_OPERAND (u, 0)); 1326 1327 /* Replace the old expression with the new version. */ 1328 *tp = u; 1329 /* We don't have to go below this point; the recursive call to 1330 break_out_target_exprs will have handled anything below this 1331 point. */ 1332 *walk_subtrees = 0; 1333 return NULL_TREE; 1334 } 1335 else if (TREE_CODE (t) == CALL_EXPR) 1336 mark_used (TREE_OPERAND (TREE_OPERAND (t, 0), 0)); 1337 1338 /* Make a copy of this node. */ 1339 return copy_tree_r (tp, walk_subtrees, NULL); 1340} 1341 1342/* Replace all remapped VAR_DECLs in T with their new equivalents. 1343 DATA is really a splay-tree mapping old variables to new 1344 variables. */ 1345 1346static tree 1347bot_replace (t, walk_subtrees, data) 1348 tree *t; 1349 int *walk_subtrees ATTRIBUTE_UNUSED; 1350 void *data; 1351{ 1352 splay_tree target_remap = ((splay_tree) data); 1353 1354 if (TREE_CODE (*t) == VAR_DECL) 1355 { 1356 splay_tree_node n = splay_tree_lookup (target_remap, 1357 (splay_tree_key) *t); 1358 if (n) 1359 *t = (tree) n->value; 1360 } 1361 1362 return NULL_TREE; 1363} 1364 1365/* When we parse a default argument expression, we may create 1366 temporary variables via TARGET_EXPRs. When we actually use the 1367 default-argument expression, we make a copy of the expression, but 1368 we must replace the temporaries with appropriate local versions. */ 1369 1370tree 1371break_out_target_exprs (t) 1372 tree t; 1373{ 1374 static int target_remap_count; 1375 static splay_tree target_remap; 1376 1377 if (!target_remap_count++) 1378 target_remap = splay_tree_new (splay_tree_compare_pointers, 1379 /*splay_tree_delete_key_fn=*/NULL, 1380 /*splay_tree_delete_value_fn=*/NULL); 1381 walk_tree (&t, bot_manip, target_remap, NULL); 1382 walk_tree (&t, bot_replace, target_remap, NULL); 1383 1384 if (!--target_remap_count) 1385 { 1386 splay_tree_delete (target_remap); 1387 target_remap = NULL; 1388 } 1389 1390 return t; 1391} 1392 1393/* Obstack used for allocating nodes in template function and variable 1394 definitions. */ 1395 1396/* Similar to `build_nt', except that we set TREE_COMPLEXITY to be the 1397 current line number. */ 1398 1399tree 1400build_min_nt VPARAMS ((enum tree_code code, ...)) 1401{ 1402 register tree t; 1403 register int length; 1404 register int i; 1405 1406 VA_OPEN (p, code); 1407 VA_FIXEDARG (p, enum tree_code, code); 1408 1409 t = make_node (code); 1410 length = TREE_CODE_LENGTH (code); 1411 TREE_COMPLEXITY (t) = lineno; 1412 1413 for (i = 0; i < length; i++) 1414 { 1415 tree x = va_arg (p, tree); 1416 TREE_OPERAND (t, i) = x; 1417 } 1418 1419 VA_CLOSE (p); 1420 return t; 1421} 1422 1423/* Similar to `build', except we set TREE_COMPLEXITY to the current 1424 line-number. */ 1425 1426tree 1427build_min VPARAMS ((enum tree_code code, tree tt, ...)) 1428{ 1429 register tree t; 1430 register int length; 1431 register int i; 1432 1433 VA_OPEN (p, tt); 1434 VA_FIXEDARG (p, enum tree_code, code); 1435 VA_FIXEDARG (p, tree, tt); 1436 1437 t = make_node (code); 1438 length = TREE_CODE_LENGTH (code); 1439 TREE_TYPE (t) = tt; 1440 TREE_COMPLEXITY (t) = lineno; 1441 1442 for (i = 0; i < length; i++) 1443 { 1444 tree x = va_arg (p, tree); 1445 TREE_OPERAND (t, i) = x; 1446 } 1447 1448 VA_CLOSE (p); 1449 return t; 1450} 1451 1452/* Returns an INTEGER_CST (of type `int') corresponding to I. 1453 Multiple calls with the same value of I may or may not yield the 1454 same node; therefore, callers should never modify the node 1455 returned. */ 1456 1457tree 1458build_shared_int_cst (i) 1459 int i; 1460{ 1461 static tree cache[256]; 1462 1463 if (i >= 256) 1464 return build_int_2 (i, 0); 1465 1466 if (!cache[i]) 1467 cache[i] = build_int_2 (i, 0); 1468 1469 return cache[i]; 1470} 1471 1472tree 1473get_type_decl (t) 1474 tree t; 1475{ 1476 if (TREE_CODE (t) == TYPE_DECL) 1477 return t; 1478 if (TYPE_P (t)) 1479 return TYPE_STUB_DECL (t); 1480 if (t == error_mark_node) 1481 return t; 1482 1483 abort (); 1484 1485 /* Stop compiler from complaining control reaches end of non-void function. */ 1486 return 0; 1487} 1488 1489/* Return first vector element whose BINFO_TYPE is ELEM. 1490 Return 0 if ELEM is not in VEC. VEC may be NULL_TREE. */ 1491 1492tree 1493vec_binfo_member (elem, vec) 1494 tree elem, vec; 1495{ 1496 int i; 1497 1498 if (vec) 1499 for (i = 0; i < TREE_VEC_LENGTH (vec); ++i) 1500 if (same_type_p (elem, BINFO_TYPE (TREE_VEC_ELT (vec, i)))) 1501 return TREE_VEC_ELT (vec, i); 1502 1503 return NULL_TREE; 1504} 1505 1506/* Returns the namespace that contains DECL, whether directly or 1507 indirectly. */ 1508 1509tree 1510decl_namespace_context (decl) 1511 tree decl; 1512{ 1513 while (1) 1514 { 1515 if (TREE_CODE (decl) == NAMESPACE_DECL) 1516 return decl; 1517 else if (TYPE_P (decl)) 1518 decl = CP_DECL_CONTEXT (TYPE_MAIN_DECL (decl)); 1519 else 1520 decl = CP_DECL_CONTEXT (decl); 1521 } 1522} 1523 1524/* Return truthvalue of whether T1 is the same tree structure as T2. 1525 Return 1 if they are the same. 1526 Return 0 if they are understandably different. 1527 Return -1 if either contains tree structure not understood by 1528 this function. */ 1529 1530int 1531cp_tree_equal (t1, t2) 1532 tree t1, t2; 1533{ 1534 register enum tree_code code1, code2; 1535 int cmp; 1536 1537 if (t1 == t2) 1538 return 1; 1539 if (t1 == 0 || t2 == 0) 1540 return 0; 1541 1542 code1 = TREE_CODE (t1); 1543 code2 = TREE_CODE (t2); 1544 1545 if (code1 == NOP_EXPR || code1 == CONVERT_EXPR || code1 == NON_LVALUE_EXPR) 1546 { 1547 if (code2 == NOP_EXPR || code2 == CONVERT_EXPR || code2 == NON_LVALUE_EXPR) 1548 return cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0)); 1549 else 1550 return cp_tree_equal (TREE_OPERAND (t1, 0), t2); 1551 } 1552 else if (code2 == NOP_EXPR || code2 == CONVERT_EXPR 1553 || code2 == NON_LVALUE_EXPR) 1554 return cp_tree_equal (t1, TREE_OPERAND (t2, 0)); 1555 1556 if (code1 != code2) 1557 return 0; 1558 1559 switch (code1) 1560 { 1561 case INTEGER_CST: 1562 return TREE_INT_CST_LOW (t1) == TREE_INT_CST_LOW (t2) 1563 && TREE_INT_CST_HIGH (t1) == TREE_INT_CST_HIGH (t2); 1564 1565 case REAL_CST: 1566 return REAL_VALUES_EQUAL (TREE_REAL_CST (t1), TREE_REAL_CST (t2)); 1567 1568 case STRING_CST: 1569 return TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2) 1570 && !memcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2), 1571 TREE_STRING_LENGTH (t1)); 1572 1573 case CONSTRUCTOR: 1574 /* We need to do this when determining whether or not two 1575 non-type pointer to member function template arguments 1576 are the same. */ 1577 if (!(same_type_p (TREE_TYPE (t1), TREE_TYPE (t2)) 1578 /* The first operand is RTL. */ 1579 && TREE_OPERAND (t1, 0) == TREE_OPERAND (t2, 0))) 1580 return 0; 1581 return cp_tree_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1)); 1582 1583 case TREE_LIST: 1584 cmp = cp_tree_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2)); 1585 if (cmp <= 0) 1586 return cmp; 1587 cmp = cp_tree_equal (TREE_VALUE (t1), TREE_VALUE (t2)); 1588 if (cmp <= 0) 1589 return cmp; 1590 return cp_tree_equal (TREE_CHAIN (t1), TREE_CHAIN (t2)); 1591 1592 case SAVE_EXPR: 1593 return cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0)); 1594 1595 case CALL_EXPR: 1596 cmp = cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0)); 1597 if (cmp <= 0) 1598 return cmp; 1599 return simple_cst_list_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1)); 1600 1601 case TARGET_EXPR: 1602 /* Special case: if either target is an unallocated VAR_DECL, 1603 it means that it's going to be unified with whatever the 1604 TARGET_EXPR is really supposed to initialize, so treat it 1605 as being equivalent to anything. */ 1606 if ((TREE_CODE (TREE_OPERAND (t1, 0)) == VAR_DECL 1607 && DECL_NAME (TREE_OPERAND (t1, 0)) == NULL_TREE 1608 && !DECL_RTL_SET_P (TREE_OPERAND (t1, 0))) 1609 || (TREE_CODE (TREE_OPERAND (t2, 0)) == VAR_DECL 1610 && DECL_NAME (TREE_OPERAND (t2, 0)) == NULL_TREE 1611 && !DECL_RTL_SET_P (TREE_OPERAND (t2, 0)))) 1612 cmp = 1; 1613 else 1614 cmp = cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0)); 1615 if (cmp <= 0) 1616 return cmp; 1617 return cp_tree_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1)); 1618 1619 case WITH_CLEANUP_EXPR: 1620 cmp = cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0)); 1621 if (cmp <= 0) 1622 return cmp; 1623 return cp_tree_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t1, 1)); 1624 1625 case COMPONENT_REF: 1626 if (TREE_OPERAND (t1, 1) == TREE_OPERAND (t2, 1)) 1627 return cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0)); 1628 return 0; 1629 1630 case VAR_DECL: 1631 case PARM_DECL: 1632 case CONST_DECL: 1633 case FUNCTION_DECL: 1634 return 0; 1635 1636 case TEMPLATE_PARM_INDEX: 1637 return TEMPLATE_PARM_IDX (t1) == TEMPLATE_PARM_IDX (t2) 1638 && TEMPLATE_PARM_LEVEL (t1) == TEMPLATE_PARM_LEVEL (t2); 1639 1640 case SIZEOF_EXPR: 1641 case ALIGNOF_EXPR: 1642 if (TREE_CODE (TREE_OPERAND (t1, 0)) != TREE_CODE (TREE_OPERAND (t2, 0))) 1643 return 0; 1644 if (TYPE_P (TREE_OPERAND (t1, 0))) 1645 return same_type_p (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0)); 1646 break; 1647 1648 case PTRMEM_CST: 1649 /* Two pointer-to-members are the same if they point to the same 1650 field or function in the same class. */ 1651 return (PTRMEM_CST_MEMBER (t1) == PTRMEM_CST_MEMBER (t2) 1652 && same_type_p (PTRMEM_CST_CLASS (t1), PTRMEM_CST_CLASS (t2))); 1653 1654 default: 1655 break; 1656 } 1657 1658 switch (TREE_CODE_CLASS (code1)) 1659 { 1660 case '1': 1661 case '2': 1662 case '<': 1663 case 'e': 1664 case 'r': 1665 case 's': 1666 { 1667 int i; 1668 1669 cmp = 1; 1670 for (i = 0; i < TREE_CODE_LENGTH (code1); ++i) 1671 { 1672 cmp = cp_tree_equal (TREE_OPERAND (t1, i), TREE_OPERAND (t2, i)); 1673 if (cmp <= 0) 1674 return cmp; 1675 } 1676 return cmp; 1677 } 1678 1679 case 't': 1680 return same_type_p (t1, t2) ? 1 : 0; 1681 } 1682 1683 return -1; 1684} 1685 1686/* Build a wrapper around some pointer PTR so we can use it as a tree. */ 1687 1688tree 1689build_ptr_wrapper (ptr) 1690 void *ptr; 1691{ 1692 tree t = make_node (WRAPPER); 1693 WRAPPER_PTR (t) = ptr; 1694 return t; 1695} 1696 1697/* Build a wrapper around some integer I so we can use it as a tree. */ 1698 1699tree 1700build_int_wrapper (i) 1701 int i; 1702{ 1703 tree t = make_node (WRAPPER); 1704 WRAPPER_INT (t) = i; 1705 return t; 1706} 1707 1708static tree 1709build_srcloc (file, line) 1710 const char *file; 1711 int line; 1712{ 1713 tree t; 1714 1715 t = make_node (SRCLOC); 1716 SRCLOC_FILE (t) = file; 1717 SRCLOC_LINE (t) = line; 1718 1719 return t; 1720} 1721 1722tree 1723build_srcloc_here () 1724{ 1725 return build_srcloc (input_filename, lineno); 1726} 1727 1728/* The type of ARG when used as an lvalue. */ 1729 1730tree 1731lvalue_type (arg) 1732 tree arg; 1733{ 1734 tree type = TREE_TYPE (arg); 1735 if (TREE_CODE (arg) == OVERLOAD) 1736 type = unknown_type_node; 1737 return type; 1738} 1739 1740/* The type of ARG for printing error messages; denote lvalues with 1741 reference types. */ 1742 1743tree 1744error_type (arg) 1745 tree arg; 1746{ 1747 tree type = TREE_TYPE (arg); 1748 if (TREE_CODE (type) == ARRAY_TYPE) 1749 ; 1750 else if (real_lvalue_p (arg)) 1751 type = build_reference_type (lvalue_type (arg)); 1752 else if (IS_AGGR_TYPE (type)) 1753 type = lvalue_type (arg); 1754 1755 return type; 1756} 1757 1758/* Does FUNCTION use a variable-length argument list? */ 1759 1760int 1761varargs_function_p (function) 1762 tree function; 1763{ 1764 tree parm = TYPE_ARG_TYPES (TREE_TYPE (function)); 1765 for (; parm; parm = TREE_CHAIN (parm)) 1766 if (TREE_VALUE (parm) == void_type_node) 1767 return 0; 1768 return 1; 1769} 1770 1771/* Returns 1 if decl is a member of a class. */ 1772 1773int 1774member_p (decl) 1775 tree decl; 1776{ 1777 const tree ctx = DECL_CONTEXT (decl); 1778 return (ctx && TYPE_P (ctx)); 1779} 1780 1781/* Create a placeholder for member access where we don't actually have an 1782 object that the access is against. */ 1783 1784tree 1785build_dummy_object (type) 1786 tree type; 1787{ 1788 tree decl = build1 (NOP_EXPR, build_pointer_type (type), void_zero_node); 1789 return build_indirect_ref (decl, NULL); 1790} 1791 1792/* We've gotten a reference to a member of TYPE. Return *this if appropriate, 1793 or a dummy object otherwise. If BINFOP is non-0, it is filled with the 1794 binfo path from current_class_type to TYPE, or 0. */ 1795 1796tree 1797maybe_dummy_object (type, binfop) 1798 tree type; 1799 tree *binfop; 1800{ 1801 tree decl, context; 1802 tree binfo; 1803 1804 if (current_class_type 1805 && (binfo = lookup_base (current_class_type, type, 1806 ba_ignore | ba_quiet, NULL))) 1807 context = current_class_type; 1808 else 1809 { 1810 /* Reference from a nested class member function. */ 1811 context = type; 1812 binfo = TYPE_BINFO (type); 1813 } 1814 1815 if (binfop) 1816 *binfop = binfo; 1817 1818 if (current_class_ref && context == current_class_type) 1819 decl = current_class_ref; 1820 else 1821 decl = build_dummy_object (context); 1822 1823 return decl; 1824} 1825 1826/* Returns 1 if OB is a placeholder object, or a pointer to one. */ 1827 1828int 1829is_dummy_object (ob) 1830 tree ob; 1831{ 1832 if (TREE_CODE (ob) == INDIRECT_REF) 1833 ob = TREE_OPERAND (ob, 0); 1834 return (TREE_CODE (ob) == NOP_EXPR 1835 && TREE_OPERAND (ob, 0) == void_zero_node); 1836} 1837 1838/* Returns 1 iff type T is a POD type, as defined in [basic.types]. */ 1839 1840int 1841pod_type_p (t) 1842 tree t; 1843{ 1844 t = strip_array_types (t); 1845 1846 if (INTEGRAL_TYPE_P (t)) 1847 return 1; /* integral, character or enumeral type */ 1848 if (FLOAT_TYPE_P (t)) 1849 return 1; 1850 if (TYPE_PTR_P (t)) 1851 return 1; /* pointer to non-member */ 1852 if (TYPE_PTRMEM_P (t)) 1853 return 1; /* pointer to member object */ 1854 if (TYPE_PTRMEMFUNC_P (t)) 1855 return 1; /* pointer to member function */ 1856 1857 if (! CLASS_TYPE_P (t)) 1858 return 0; /* other non-class type (reference or function) */ 1859 if (CLASSTYPE_NON_POD_P (t)) 1860 return 0; 1861 return 1; 1862} 1863 1864/* Table of valid C++ attributes. */ 1865const struct attribute_spec cp_attribute_table[] = 1866{ 1867 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */ 1868 { "java_interface", 0, 0, false, false, false, handle_java_interface_attribute }, 1869 { "com_interface", 0, 0, false, false, false, handle_com_interface_attribute }, 1870 { "init_priority", 1, 1, true, false, false, handle_init_priority_attribute }, 1871 { NULL, 0, 0, false, false, false, NULL } 1872}; 1873 1874/* Handle a "java_interface" attribute; arguments as in 1875 struct attribute_spec.handler. */ 1876static tree 1877handle_java_interface_attribute (node, name, args, flags, no_add_attrs) 1878 tree *node; 1879 tree name; 1880 tree args ATTRIBUTE_UNUSED; 1881 int flags; 1882 bool *no_add_attrs; 1883{ 1884 if (DECL_P (*node) 1885 || !CLASS_TYPE_P (*node) 1886 || !TYPE_FOR_JAVA (*node)) 1887 { 1888 error ("`%s' attribute can only be applied to Java class definitions", 1889 IDENTIFIER_POINTER (name)); 1890 *no_add_attrs = true; 1891 return NULL_TREE; 1892 } 1893 if (!(flags & (int) ATTR_FLAG_TYPE_IN_PLACE)) 1894 *node = build_type_copy (*node); 1895 TYPE_JAVA_INTERFACE (*node) = 1; 1896 1897 return NULL_TREE; 1898} 1899 1900/* Handle a "com_interface" attribute; arguments as in 1901 struct attribute_spec.handler. */ 1902static tree 1903handle_com_interface_attribute (node, name, args, flags, no_add_attrs) 1904 tree *node; 1905 tree name; 1906 tree args ATTRIBUTE_UNUSED; 1907 int flags ATTRIBUTE_UNUSED; 1908 bool *no_add_attrs; 1909{ 1910 static int warned; 1911 1912 *no_add_attrs = true; 1913 1914 if (DECL_P (*node) 1915 || !CLASS_TYPE_P (*node) 1916 || *node != TYPE_MAIN_VARIANT (*node)) 1917 { 1918 warning ("`%s' attribute can only be applied to class definitions", 1919 IDENTIFIER_POINTER (name)); 1920 return NULL_TREE; 1921 } 1922 1923 if (!warned++) 1924 warning ("`%s' is obsolete; g++ vtables are now COM-compatible by default", 1925 IDENTIFIER_POINTER (name)); 1926 1927 return NULL_TREE; 1928} 1929 1930/* Handle an "init_priority" attribute; arguments as in 1931 struct attribute_spec.handler. */ 1932static tree 1933handle_init_priority_attribute (node, name, args, flags, no_add_attrs) 1934 tree *node; 1935 tree name; 1936 tree args; 1937 int flags ATTRIBUTE_UNUSED; 1938 bool *no_add_attrs; 1939{ 1940 tree initp_expr = TREE_VALUE (args); 1941 tree decl = *node; 1942 tree type = TREE_TYPE (decl); 1943 int pri; 1944 1945 STRIP_NOPS (initp_expr); 1946 1947 if (!initp_expr || TREE_CODE (initp_expr) != INTEGER_CST) 1948 { 1949 error ("requested init_priority is not an integer constant"); 1950 *no_add_attrs = true; 1951 return NULL_TREE; 1952 } 1953 1954 pri = TREE_INT_CST_LOW (initp_expr); 1955 1956 type = strip_array_types (type); 1957 1958 if (decl == NULL_TREE 1959 || TREE_CODE (decl) != VAR_DECL 1960 || !TREE_STATIC (decl) 1961 || DECL_EXTERNAL (decl) 1962 || (TREE_CODE (type) != RECORD_TYPE 1963 && TREE_CODE (type) != UNION_TYPE) 1964 /* Static objects in functions are initialized the 1965 first time control passes through that 1966 function. This is not precise enough to pin down an 1967 init_priority value, so don't allow it. */ 1968 || current_function_decl) 1969 { 1970 error ("can only use `%s' attribute on file-scope definitions of objects of class type", 1971 IDENTIFIER_POINTER (name)); 1972 *no_add_attrs = true; 1973 return NULL_TREE; 1974 } 1975 1976 if (pri > MAX_INIT_PRIORITY || pri <= 0) 1977 { 1978 error ("requested init_priority is out of range"); 1979 *no_add_attrs = true; 1980 return NULL_TREE; 1981 } 1982 1983 /* Check for init_priorities that are reserved for 1984 language and runtime support implementations.*/ 1985 if (pri <= MAX_RESERVED_INIT_PRIORITY) 1986 { 1987 warning 1988 ("requested init_priority is reserved for internal use"); 1989 } 1990 1991 if (SUPPORTS_INIT_PRIORITY) 1992 { 1993 DECL_INIT_PRIORITY (decl) = pri; 1994 return NULL_TREE; 1995 } 1996 else 1997 { 1998 error ("`%s' attribute is not supported on this platform", 1999 IDENTIFIER_POINTER (name)); 2000 *no_add_attrs = true; 2001 return NULL_TREE; 2002 } 2003} 2004 2005/* Return a new PTRMEM_CST of the indicated TYPE. The MEMBER is the 2006 thing pointed to by the constant. */ 2007 2008tree 2009make_ptrmem_cst (type, member) 2010 tree type; 2011 tree member; 2012{ 2013 tree ptrmem_cst = make_node (PTRMEM_CST); 2014 /* If would seem a great convenience if make_node would set 2015 TREE_CONSTANT for things of class `c', but it does not. */ 2016 TREE_CONSTANT (ptrmem_cst) = 1; 2017 TREE_TYPE (ptrmem_cst) = type; 2018 PTRMEM_CST_MEMBER (ptrmem_cst) = member; 2019 return ptrmem_cst; 2020} 2021 2022/* Apply FUNC to all language-specific sub-trees of TP in a pre-order 2023 traversal. Called from walk_tree(). */ 2024 2025tree 2026cp_walk_subtrees (tp, walk_subtrees_p, func, data, htab) 2027 tree *tp; 2028 int *walk_subtrees_p; 2029 walk_tree_fn func; 2030 void *data; 2031 void *htab; 2032{ 2033 enum tree_code code = TREE_CODE (*tp); 2034 tree result; 2035 2036#define WALK_SUBTREE(NODE) \ 2037 do \ 2038 { \ 2039 result = walk_tree (&(NODE), func, data, htab); \ 2040 if (result) \ 2041 return result; \ 2042 } \ 2043 while (0) 2044 2045 /* Not one of the easy cases. We must explicitly go through the 2046 children. */ 2047 switch (code) 2048 { 2049 case DEFAULT_ARG: 2050 case TEMPLATE_TEMPLATE_PARM: 2051 case BOUND_TEMPLATE_TEMPLATE_PARM: 2052 case UNBOUND_CLASS_TEMPLATE: 2053 case TEMPLATE_PARM_INDEX: 2054 case TEMPLATE_TYPE_PARM: 2055 case TYPENAME_TYPE: 2056 case TYPEOF_TYPE: 2057 /* None of thse have subtrees other than those already walked 2058 above. */ 2059 *walk_subtrees_p = 0; 2060 break; 2061 2062 case PTRMEM_CST: 2063 WALK_SUBTREE (TREE_TYPE (*tp)); 2064 *walk_subtrees_p = 0; 2065 break; 2066 2067 case TREE_LIST: 2068 /* A BASELINK_P's TREE_PURPOSE is a BINFO, and hence circular. */ 2069 if (!BASELINK_P (*tp)) 2070 WALK_SUBTREE (TREE_PURPOSE (*tp)); 2071 break; 2072 2073 case OVERLOAD: 2074 WALK_SUBTREE (OVL_FUNCTION (*tp)); 2075 WALK_SUBTREE (OVL_CHAIN (*tp)); 2076 *walk_subtrees_p = 0; 2077 break; 2078 2079 case RECORD_TYPE: 2080 if (TYPE_PTRMEMFUNC_P (*tp)) 2081 WALK_SUBTREE (TYPE_PTRMEMFUNC_FN_TYPE (*tp)); 2082 break; 2083 2084 default: 2085 break; 2086 } 2087 2088 /* We didn't find what we were looking for. */ 2089 return NULL_TREE; 2090 2091#undef WALK_SUBTREE 2092} 2093 2094/* Decide whether there are language-specific reasons to not inline a 2095 function as a tree. */ 2096 2097int 2098cp_cannot_inline_tree_fn (fnp) 2099 tree *fnp; 2100{ 2101 tree fn = *fnp; 2102 2103 /* We can inline a template instantiation only if it's fully 2104 instantiated. */ 2105 if (DECL_TEMPLATE_INFO (fn) 2106 && TI_PENDING_TEMPLATE_FLAG (DECL_TEMPLATE_INFO (fn))) 2107 { 2108 fn = *fnp = instantiate_decl (fn, /*defer_ok=*/0); 2109 return TI_PENDING_TEMPLATE_FLAG (DECL_TEMPLATE_INFO (fn)); 2110 } 2111 2112 if (varargs_function_p (fn)) 2113 { 2114 DECL_UNINLINABLE (fn) = 1; 2115 return 1; 2116 } 2117 2118 if (! function_attribute_inlinable_p (fn)) 2119 { 2120 DECL_UNINLINABLE (fn) = 1; 2121 return 1; 2122 } 2123 2124 return 0; 2125} 2126 2127/* Add any pending functions other than the current function (already 2128 handled by the caller), that thus cannot be inlined, to FNS_P, then 2129 return the latest function added to the array, PREV_FN. */ 2130 2131tree 2132cp_add_pending_fn_decls (fns_p, prev_fn) 2133 void *fns_p; 2134 tree prev_fn; 2135{ 2136 varray_type *fnsp = (varray_type *)fns_p; 2137 struct saved_scope *s; 2138 2139 for (s = scope_chain; s; s = s->prev) 2140 if (s->function_decl && s->function_decl != prev_fn) 2141 { 2142 VARRAY_PUSH_TREE (*fnsp, s->function_decl); 2143 prev_fn = s->function_decl; 2144 } 2145 2146 return prev_fn; 2147} 2148 2149/* Determine whether a tree node is an OVERLOAD node. Used to decide 2150 whether to copy a node or to preserve its chain when inlining a 2151 function. */ 2152 2153int 2154cp_is_overload_p (t) 2155 tree t; 2156{ 2157 return TREE_CODE (t) == OVERLOAD; 2158} 2159 2160/* Determine whether VAR is a declaration of an automatic variable in 2161 function FN. */ 2162 2163int 2164cp_auto_var_in_fn_p (var, fn) 2165 tree var, fn; 2166{ 2167 return (DECL_P (var) && DECL_CONTEXT (var) == fn 2168 && nonstatic_local_decl_p (var)); 2169} 2170 2171/* Tell whether a declaration is needed for the RESULT of a function 2172 FN being inlined into CALLER or if the top node of target_exprs is 2173 to be used. */ 2174 2175tree 2176cp_copy_res_decl_for_inlining (result, fn, caller, decl_map_, 2177 need_decl, target_exprs) 2178 tree result, fn, caller; 2179 void *decl_map_; 2180 int *need_decl; 2181 void *target_exprs; 2182{ 2183 splay_tree decl_map = (splay_tree)decl_map_; 2184 varray_type *texps = (varray_type *)target_exprs; 2185 tree var; 2186 int aggregate_return_p; 2187 2188 /* Figure out whether or not FN returns an aggregate. */ 2189 aggregate_return_p = IS_AGGR_TYPE (TREE_TYPE (result)); 2190 *need_decl = ! aggregate_return_p; 2191 2192 /* If FN returns an aggregate then the caller will always create the 2193 temporary (using a TARGET_EXPR) and the call will be the 2194 initializing expression for the TARGET_EXPR. If we were just to 2195 create a new VAR_DECL here, then the result of this function 2196 would be copied (bitwise) into the variable initialized by the 2197 TARGET_EXPR. That's incorrect, so we must transform any 2198 references to the RESULT into references to the target. */ 2199 if (aggregate_return_p) 2200 { 2201 if (VARRAY_ACTIVE_SIZE (*texps) == 0) 2202 abort (); 2203 var = TREE_OPERAND (VARRAY_TOP_TREE (*texps), 0); 2204 if (! same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (var), 2205 TREE_TYPE (result))) 2206 abort (); 2207 } 2208 /* Otherwise, make an appropriate copy. */ 2209 else 2210 var = copy_decl_for_inlining (result, fn, caller); 2211 2212 if (DECL_SAVED_FUNCTION_DATA (fn)) 2213 { 2214 tree nrv = DECL_SAVED_FUNCTION_DATA (fn)->x_return_value; 2215 if (nrv) 2216 { 2217 /* We have a named return value; copy the name and source 2218 position so we can get reasonable debugging information, and 2219 register the return variable as its equivalent. */ 2220 DECL_NAME (var) = DECL_NAME (nrv); 2221 DECL_SOURCE_FILE (var) = DECL_SOURCE_FILE (nrv); 2222 DECL_SOURCE_LINE (var) = DECL_SOURCE_LINE (nrv); 2223 DECL_ABSTRACT_ORIGIN (var) = DECL_ORIGIN (nrv); 2224 splay_tree_insert (decl_map, 2225 (splay_tree_key) nrv, 2226 (splay_tree_value) var); 2227 } 2228 } 2229 2230 return var; 2231} 2232 2233/* Record that we're about to start inlining FN, and return non-zero if 2234 that's OK. Used for lang_hooks.tree_inlining.start_inlining. */ 2235 2236int 2237cp_start_inlining (fn) 2238 tree fn; 2239{ 2240 if (DECL_TEMPLATE_INSTANTIATION (fn)) 2241 return push_tinst_level (fn); 2242 else 2243 return 1; 2244} 2245 2246/* Record that we're done inlining FN. Used for 2247 lang_hooks.tree_inlining.end_inlining. */ 2248 2249void 2250cp_end_inlining (fn) 2251 tree fn ATTRIBUTE_UNUSED; 2252{ 2253 if (DECL_TEMPLATE_INSTANTIATION (fn)) 2254 pop_tinst_level (); 2255} 2256 2257/* Initialize tree.c. */ 2258 2259void 2260init_tree () 2261{ 2262 make_lang_type_fn = cp_make_lang_type; 2263 lang_unsave = cp_unsave; 2264 lang_statement_code_p = cp_statement_code_p; 2265 lang_set_decl_assembler_name = mangle_decl; 2266 list_hash_table = htab_create (31, list_hash, list_hash_eq, NULL); 2267 ggc_add_root (&list_hash_table, 1, 2268 sizeof (list_hash_table), 2269 mark_tree_hashtable); 2270} 2271 2272/* Called via walk_tree. If *TP points to a DECL_STMT for a local 2273 declaration, copies the declaration and enters it in the splay_tree 2274 pointed to by DATA (which is really a `splay_tree *'). */ 2275 2276static tree 2277mark_local_for_remap_r (tp, walk_subtrees, data) 2278 tree *tp; 2279 int *walk_subtrees ATTRIBUTE_UNUSED; 2280 void *data; 2281{ 2282 tree t = *tp; 2283 splay_tree st = (splay_tree) data; 2284 tree decl; 2285 2286 2287 if (TREE_CODE (t) == DECL_STMT 2288 && nonstatic_local_decl_p (DECL_STMT_DECL (t))) 2289 decl = DECL_STMT_DECL (t); 2290 else if (TREE_CODE (t) == LABEL_STMT) 2291 decl = LABEL_STMT_LABEL (t); 2292 else if (TREE_CODE (t) == TARGET_EXPR 2293 && nonstatic_local_decl_p (TREE_OPERAND (t, 0))) 2294 decl = TREE_OPERAND (t, 0); 2295 else if (TREE_CODE (t) == CASE_LABEL) 2296 decl = CASE_LABEL_DECL (t); 2297 else 2298 decl = NULL_TREE; 2299 2300 if (decl) 2301 { 2302 tree copy; 2303 2304 /* Make a copy. */ 2305 copy = copy_decl_for_inlining (decl, 2306 DECL_CONTEXT (decl), 2307 DECL_CONTEXT (decl)); 2308 2309 /* Remember the copy. */ 2310 splay_tree_insert (st, 2311 (splay_tree_key) decl, 2312 (splay_tree_value) copy); 2313 } 2314 2315 return NULL_TREE; 2316} 2317 2318/* Called via walk_tree when an expression is unsaved. Using the 2319 splay_tree pointed to by ST (which is really a `splay_tree'), 2320 remaps all local declarations to appropriate replacements. */ 2321 2322static tree 2323cp_unsave_r (tp, walk_subtrees, data) 2324 tree *tp; 2325 int *walk_subtrees; 2326 void *data; 2327{ 2328 splay_tree st = (splay_tree) data; 2329 splay_tree_node n; 2330 2331 /* Only a local declaration (variable or label). */ 2332 if (nonstatic_local_decl_p (*tp)) 2333 { 2334 /* Lookup the declaration. */ 2335 n = splay_tree_lookup (st, (splay_tree_key) *tp); 2336 2337 /* If it's there, remap it. */ 2338 if (n) 2339 *tp = (tree) n->value; 2340 } 2341 else if (TREE_CODE (*tp) == SAVE_EXPR) 2342 remap_save_expr (tp, st, current_function_decl, walk_subtrees); 2343 else 2344 { 2345 copy_tree_r (tp, walk_subtrees, NULL); 2346 2347 /* Do whatever unsaving is required. */ 2348 unsave_expr_1 (*tp); 2349 } 2350 2351 /* Keep iterating. */ 2352 return NULL_TREE; 2353} 2354 2355/* Called by unsave_expr_now whenever an expression (*TP) needs to be 2356 unsaved. */ 2357 2358static void 2359cp_unsave (tp) 2360 tree *tp; 2361{ 2362 splay_tree st; 2363 2364 /* Create a splay-tree to map old local variable declarations to new 2365 ones. */ 2366 st = splay_tree_new (splay_tree_compare_pointers, NULL, NULL); 2367 2368 /* Walk the tree once figuring out what needs to be remapped. */ 2369 walk_tree (tp, mark_local_for_remap_r, st, NULL); 2370 2371 /* Walk the tree again, copying, remapping, and unsaving. */ 2372 walk_tree (tp, cp_unsave_r, st, NULL); 2373 2374 /* Clean up. */ 2375 splay_tree_delete (st); 2376} 2377 2378/* Returns the kind of special function that DECL (a FUNCTION_DECL) 2379 is. Note that this sfk_none is zero, so this function can be used 2380 as a predicate to test whether or not DECL is a special function. */ 2381 2382special_function_kind 2383special_function_p (decl) 2384 tree decl; 2385{ 2386 /* Rather than doing all this stuff with magic names, we should 2387 probably have a field of type `special_function_kind' in 2388 DECL_LANG_SPECIFIC. */ 2389 if (DECL_COPY_CONSTRUCTOR_P (decl)) 2390 return sfk_copy_constructor; 2391 if (DECL_CONSTRUCTOR_P (decl)) 2392 return sfk_constructor; 2393 if (DECL_OVERLOADED_OPERATOR_P (decl) == NOP_EXPR) 2394 return sfk_assignment_operator; 2395 if (DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (decl)) 2396 return sfk_destructor; 2397 if (DECL_COMPLETE_DESTRUCTOR_P (decl)) 2398 return sfk_complete_destructor; 2399 if (DECL_BASE_DESTRUCTOR_P (decl)) 2400 return sfk_base_destructor; 2401 if (DECL_DELETING_DESTRUCTOR_P (decl)) 2402 return sfk_deleting_destructor; 2403 if (DECL_CONV_FN_P (decl)) 2404 return sfk_conversion; 2405 2406 return sfk_none; 2407} 2408 2409/* Returns non-zero if TYPE is a character type, including wchar_t. */ 2410 2411int 2412char_type_p (type) 2413 tree type; 2414{ 2415 return (same_type_p (type, char_type_node) 2416 || same_type_p (type, unsigned_char_type_node) 2417 || same_type_p (type, signed_char_type_node) 2418 || same_type_p (type, wchar_type_node)); 2419} 2420 2421/* Returns the kind of linkage associated with the indicated DECL. Th 2422 value returned is as specified by the language standard; it is 2423 independent of implementation details regarding template 2424 instantiation, etc. For example, it is possible that a declaration 2425 to which this function assigns external linkage would not show up 2426 as a global symbol when you run `nm' on the resulting object file. */ 2427 2428linkage_kind 2429decl_linkage (decl) 2430 tree decl; 2431{ 2432 /* This function doesn't attempt to calculate the linkage from first 2433 principles as given in [basic.link]. Instead, it makes use of 2434 the fact that we have already set TREE_PUBLIC appropriately, and 2435 then handles a few special cases. Ideally, we would calculate 2436 linkage first, and then transform that into a concrete 2437 implementation. */ 2438 2439 /* Things that don't have names have no linkage. */ 2440 if (!DECL_NAME (decl)) 2441 return lk_none; 2442 2443 /* Things that are TREE_PUBLIC have external linkage. */ 2444 if (TREE_PUBLIC (decl)) 2445 return lk_external; 2446 2447 /* Some things that are not TREE_PUBLIC have external linkage, too. 2448 For example, on targets that don't have weak symbols, we make all 2449 template instantiations have internal linkage (in the object 2450 file), but the symbols should still be treated as having external 2451 linkage from the point of view of the language. */ 2452 if (DECL_LANG_SPECIFIC (decl) && DECL_COMDAT (decl)) 2453 return lk_external; 2454 2455 /* Things in local scope do not have linkage, if they don't have 2456 TREE_PUBLIC set. */ 2457 if (decl_function_context (decl)) 2458 return lk_none; 2459 2460 /* Everything else has internal linkage. */ 2461 return lk_internal; 2462} 2463