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)
6 This file is part of GNU CC.
8 GNU CC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GNU CC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU CC; see the file COPYING. If not, write to
20 the Free Software Foundation, 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
32 #include "insn-config.h"
33 #include "integrate.h"
35 static tree bot_manip PARAMS ((tree *, int *, void *));
36 static tree bot_replace PARAMS ((tree *, int *, void *));
37 static tree build_cplus_array_type_1 PARAMS ((tree, tree));
38 static int list_hash_eq PARAMS ((const void *, const void *));
39 static hashval_t list_hash_pieces PARAMS ((tree, tree, tree));
40 static hashval_t list_hash PARAMS ((const void *));
41 static cp_lvalue_kind lvalue_p_1 PARAMS ((tree, int));
42 static tree no_linkage_helper PARAMS ((tree *, int *, void *));
43 static tree build_srcloc PARAMS ((const char *, int));
44 static tree mark_local_for_remap_r PARAMS ((tree *, int *, void *));
45 static tree cp_unsave_r PARAMS ((tree *, int *, void *));
46 static void cp_unsave PARAMS ((tree *));
47 static tree build_target_expr PARAMS ((tree, tree));
48 static tree count_trees_r PARAMS ((tree *, int *, void *));
49 static tree verify_stmt_tree_r PARAMS ((tree *, int *, void *));
50 static tree find_tree_r PARAMS ((tree *, int *, void *));
51 extern int cp_statement_code_p PARAMS ((enum tree_code));
53 /* If REF is an lvalue, returns the kind of lvalue that REF is.
54 Otherwise, returns clk_none. If TREAT_CLASS_RVALUES_AS_LVALUES is
55 non-zero, rvalues of class type are considered lvalues. */
58 lvalue_p_1 (ref, treat_class_rvalues_as_lvalues)
60 int treat_class_rvalues_as_lvalues;
62 cp_lvalue_kind op1_lvalue_kind = clk_none;
63 cp_lvalue_kind op2_lvalue_kind = clk_none;
65 if (TREE_CODE (TREE_TYPE (ref)) == REFERENCE_TYPE)
68 if (ref == current_class_ptr)
71 switch (TREE_CODE (ref))
73 /* preincrements and predecrements are valid lvals, provided
74 what they refer to are valid lvals. */
75 case PREINCREMENT_EXPR:
76 case PREDECREMENT_EXPR:
80 case WITH_CLEANUP_EXPR:
83 /* This shouldn't be here, but there are lots of places in the compiler
84 that are sloppy about tacking on NOP_EXPRs to the same type when
85 no actual conversion is happening. */
87 return lvalue_p_1 (TREE_OPERAND (ref, 0),
88 treat_class_rvalues_as_lvalues);
91 op1_lvalue_kind = lvalue_p_1 (TREE_OPERAND (ref, 0),
92 treat_class_rvalues_as_lvalues);
94 /* The "field" can be a FUNCTION_DECL or an OVERLOAD in some
96 && TREE_CODE (TREE_OPERAND (ref, 1)) == FIELD_DECL
97 && DECL_C_BIT_FIELD (TREE_OPERAND (ref, 1)))
99 /* Clear the ordinary bit. If this object was a class
100 rvalue we want to preserve that information. */
101 op1_lvalue_kind &= ~clk_ordinary;
102 /* The lvalue is for a btifield. */
103 op1_lvalue_kind |= clk_bitfield;
105 return op1_lvalue_kind;
111 if (TREE_READONLY (ref) && ! TREE_STATIC (ref)
112 && DECL_LANG_SPECIFIC (ref)
113 && DECL_IN_AGGR_P (ref))
119 if (TREE_CODE (TREE_TYPE (ref)) != METHOD_TYPE)
123 /* A currently unresolved scope ref. */
125 my_friendly_abort (103);
127 if (TREE_CODE (TREE_OPERAND (ref, 1)) == FUNCTION_DECL)
132 op1_lvalue_kind = lvalue_p_1 (TREE_OPERAND (ref, 0),
133 treat_class_rvalues_as_lvalues);
134 op2_lvalue_kind = lvalue_p_1 (TREE_OPERAND (ref, 1),
135 treat_class_rvalues_as_lvalues);
139 op1_lvalue_kind = lvalue_p_1 (TREE_OPERAND (ref, 1),
140 treat_class_rvalues_as_lvalues);
141 op2_lvalue_kind = lvalue_p_1 (TREE_OPERAND (ref, 2),
142 treat_class_rvalues_as_lvalues);
149 return lvalue_p_1 (TREE_OPERAND (ref, 1),
150 treat_class_rvalues_as_lvalues);
153 return treat_class_rvalues_as_lvalues ? clk_class : clk_none;
157 return ((treat_class_rvalues_as_lvalues
158 && IS_AGGR_TYPE (TREE_TYPE (ref)))
159 ? clk_class : clk_none);
162 /* All functions (except non-static-member functions) are
164 return (DECL_NONSTATIC_MEMBER_FUNCTION_P (ref)
165 ? clk_none : clk_ordinary);
171 /* If one operand is not an lvalue at all, then this expression is
173 if (!op1_lvalue_kind || !op2_lvalue_kind)
176 /* Otherwise, it's an lvalue, and it has all the odd properties
177 contributed by either operand. */
178 op1_lvalue_kind = op1_lvalue_kind | op2_lvalue_kind;
179 /* It's not an ordinary lvalue if it involves either a bit-field or
181 if ((op1_lvalue_kind & ~clk_ordinary) != clk_none)
182 op1_lvalue_kind &= ~clk_ordinary;
183 return op1_lvalue_kind;
186 /* If REF is an lvalue, returns the kind of lvalue that REF is.
187 Otherwise, returns clk_none. Lvalues can be assigned, unless they
188 have TREE_READONLY, or unless they are FUNCTION_DECLs. Lvalues can
189 have their address taken, unless they have DECL_REGISTER. */
195 return lvalue_p_1 (ref, /*treat_class_rvalues_as_lvalues=*/0);
198 /* This differs from real_lvalue_p in that class rvalues are
199 considered lvalues. */
206 (lvalue_p_1 (ref, /*treat_class_rvalues_as_lvalues=*/1) != clk_none);
209 /* Return nonzero if REF is an lvalue valid for this language;
210 otherwise, print an error message and return zero. */
213 lvalue_or_else (ref, string)
217 int win = lvalue_p (ref);
219 error ("non-lvalue in %s", string);
223 /* Build a TARGET_EXPR, initializing the DECL with the VALUE. */
226 build_target_expr (decl, value)
232 t = build (TARGET_EXPR, TREE_TYPE (decl), decl, value,
233 maybe_build_cleanup (decl), NULL_TREE);
234 /* We always set TREE_SIDE_EFFECTS so that expand_expr does not
235 ignore the TARGET_EXPR. If there really turn out to be no
236 side-effects, then the optimizer should be able to get rid of
237 whatever code is generated anyhow. */
238 TREE_SIDE_EFFECTS (t) = 1;
243 /* INIT is a CALL_EXPR which needs info about its target.
244 TYPE is the type that this initialization should appear to have.
246 Build an encapsulation of the initialization to perform
247 and return it so that it can be processed by language-independent
248 and language-specific expression expanders. */
251 build_cplus_new (type, init)
259 /* Make sure that we're not trying to create an instance of an
261 abstract_virtuals_error (NULL_TREE, type);
263 if (TREE_CODE (init) != CALL_EXPR && TREE_CODE (init) != AGGR_INIT_EXPR)
264 return convert (type, init);
266 slot = build (VAR_DECL, type);
267 DECL_ARTIFICIAL (slot) = 1;
268 DECL_CONTEXT (slot) = current_function_decl;
269 layout_decl (slot, 0);
271 /* We split the CALL_EXPR into its function and its arguments here.
272 Then, in expand_expr, we put them back together. The reason for
273 this is that this expression might be a default argument
274 expression. In that case, we need a new temporary every time the
275 expression is used. That's what break_out_target_exprs does; it
276 replaces every AGGR_INIT_EXPR with a copy that uses a fresh
277 temporary slot. Then, expand_expr builds up a call-expression
278 using the new slot. */
279 fn = TREE_OPERAND (init, 0);
280 rval = build (AGGR_INIT_EXPR, type, fn, TREE_OPERAND (init, 1), slot);
281 TREE_SIDE_EFFECTS (rval) = 1;
282 AGGR_INIT_VIA_CTOR_P (rval)
283 = (TREE_CODE (fn) == ADDR_EXPR
284 && TREE_CODE (TREE_OPERAND (fn, 0)) == FUNCTION_DECL
285 && DECL_CONSTRUCTOR_P (TREE_OPERAND (fn, 0)));
286 rval = build_target_expr (slot, rval);
291 /* Buidl a TARGET_EXPR using INIT to initialize a new temporary of the
295 build_target_expr_with_type (init, type)
302 if (TREE_CODE (init) == TARGET_EXPR)
305 slot = build (VAR_DECL, type);
306 DECL_ARTIFICIAL (slot) = 1;
307 DECL_CONTEXT (slot) = current_function_decl;
308 layout_decl (slot, 0);
309 rval = build_target_expr (slot, init);
314 /* Like build_target_expr_with_type, but use the type of INIT. */
317 get_target_expr (init)
320 return build_target_expr_with_type (init, TREE_TYPE (init));
323 /* Recursively perform a preorder search EXP for CALL_EXPRs, making
324 copies where they are found. Returns a deep copy all nodes transitively
325 containing CALL_EXPRs. */
328 break_out_calls (exp)
331 register tree t1, t2 = NULL_TREE;
332 register enum tree_code code;
333 register int changed = 0;
336 if (exp == NULL_TREE)
339 code = TREE_CODE (exp);
341 if (code == CALL_EXPR)
342 return copy_node (exp);
344 /* Don't try and defeat a save_expr, as it should only be done once. */
345 if (code == SAVE_EXPR)
348 switch (TREE_CODE_CLASS (code))
353 case 'c': /* a constant */
354 case 't': /* a type node */
355 case 'x': /* something random, like an identifier or an ERROR_MARK. */
358 case 'd': /* A decl node */
359 #if 0 /* This is bogus. jason 9/21/94 */
361 t1 = break_out_calls (DECL_INITIAL (exp));
362 if (t1 != DECL_INITIAL (exp))
364 exp = copy_node (exp);
365 DECL_INITIAL (exp) = t1;
370 case 'b': /* A block node */
372 /* Don't know how to handle these correctly yet. Must do a
373 break_out_calls on all DECL_INITIAL values for local variables,
374 and also break_out_calls on all sub-blocks and sub-statements. */
379 case 'e': /* an expression */
380 case 'r': /* a reference */
381 case 's': /* an expression with side effects */
382 for (i = TREE_CODE_LENGTH (code) - 1; i >= 0; i--)
384 t1 = break_out_calls (TREE_OPERAND (exp, i));
385 if (t1 != TREE_OPERAND (exp, i))
387 exp = copy_node (exp);
388 TREE_OPERAND (exp, i) = t1;
393 case '<': /* a comparison expression */
394 case '2': /* a binary arithmetic expression */
395 t2 = break_out_calls (TREE_OPERAND (exp, 1));
396 if (t2 != TREE_OPERAND (exp, 1))
398 case '1': /* a unary arithmetic expression */
399 t1 = break_out_calls (TREE_OPERAND (exp, 0));
400 if (t1 != TREE_OPERAND (exp, 0))
404 if (TREE_CODE_LENGTH (code) == 1)
405 return build1 (code, TREE_TYPE (exp), t1);
407 return build (code, TREE_TYPE (exp), t1, t2);
414 /* Here is how primitive or already-canonicalized types' hash
415 codes are made. MUST BE CONSISTENT WITH tree.c !!! */
416 #define TYPE_HASH(TYPE) ((HOST_WIDE_INT) (TYPE) & 0777777)
418 /* Construct, lay out and return the type of methods belonging to class
419 BASETYPE and whose arguments are described by ARGTYPES and whose values
420 are described by RETTYPE. If each type exists already, reuse it. */
423 build_cplus_method_type (basetype, rettype, argtypes)
424 tree basetype, rettype, argtypes;
430 /* Make a node of the sort we want. */
431 t = make_node (METHOD_TYPE);
433 TYPE_METHOD_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype);
434 TREE_TYPE (t) = rettype;
435 ptype = build_pointer_type (basetype);
437 /* The actual arglist for this function includes a "hidden" argument
438 which is "this". Put it into the list of argument types. */
439 argtypes = tree_cons (NULL_TREE, ptype, argtypes);
440 TYPE_ARG_TYPES (t) = argtypes;
441 TREE_SIDE_EFFECTS (argtypes) = 1; /* Mark first argtype as "artificial". */
443 /* If we already have such a type, use the old one and free this one.
444 Note that it also frees up the above cons cell if found. */
445 hashcode = TYPE_HASH (basetype) + TYPE_HASH (rettype) +
446 type_hash_list (argtypes);
448 t = type_hash_canon (hashcode, t);
450 if (!COMPLETE_TYPE_P (t))
457 build_cplus_array_type_1 (elt_type, index_type)
463 if (elt_type == error_mark_node || index_type == error_mark_node)
464 return error_mark_node;
466 if (processing_template_decl
467 || uses_template_parms (elt_type)
468 || uses_template_parms (index_type))
470 t = make_node (ARRAY_TYPE);
471 TREE_TYPE (t) = elt_type;
472 TYPE_DOMAIN (t) = index_type;
475 t = build_array_type (elt_type, index_type);
477 /* Push these needs up so that initialization takes place
479 TYPE_NEEDS_CONSTRUCTING (t)
480 = TYPE_NEEDS_CONSTRUCTING (TYPE_MAIN_VARIANT (elt_type));
481 TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)
482 = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TYPE_MAIN_VARIANT (elt_type));
487 build_cplus_array_type (elt_type, index_type)
492 int type_quals = CP_TYPE_QUALS (elt_type);
494 elt_type = TYPE_MAIN_VARIANT (elt_type);
496 t = build_cplus_array_type_1 (elt_type, index_type);
498 if (type_quals != TYPE_UNQUALIFIED)
499 t = cp_build_qualified_type (t, type_quals);
504 /* Make a variant of TYPE, qualified with the TYPE_QUALS. Handles
505 arrays correctly. In particular, if TYPE is an array of T's, and
506 TYPE_QUALS is non-empty, returns an array of qualified T's. If
507 at attempt is made to qualify a type illegally, and COMPLAIN is
508 non-zero, an error is issued. If COMPLAIN is zero, error_mark_node
512 cp_build_qualified_type_real (type, type_quals, complain)
519 if (type == error_mark_node)
522 if (type_quals == CP_TYPE_QUALS (type))
525 /* A restrict-qualified pointer type must be a pointer (or reference)
526 to object or incomplete type. */
527 if ((type_quals & TYPE_QUAL_RESTRICT)
528 && TREE_CODE (type) != TEMPLATE_TYPE_PARM
529 && (!POINTER_TYPE_P (type)
530 || TYPE_PTRMEM_P (type)
531 || TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE))
534 cp_error ("`%T' cannot be `restrict'-qualified", type);
536 return error_mark_node;
538 type_quals &= ~TYPE_QUAL_RESTRICT;
541 if (type_quals != TYPE_UNQUALIFIED
542 && TREE_CODE (type) == FUNCTION_TYPE)
545 cp_error ("`%T' cannot be `const'-, `volatile'-, or `restrict'-qualified", type);
547 return error_mark_node;
548 type_quals = TYPE_UNQUALIFIED;
550 else if (TREE_CODE (type) == ARRAY_TYPE)
552 /* In C++, the qualification really applies to the array element
553 type. Obtain the appropriately qualified element type. */
556 = cp_build_qualified_type_real (TREE_TYPE (type),
560 if (element_type == error_mark_node)
561 return error_mark_node;
563 /* See if we already have an identically qualified type. */
564 for (t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
565 if (CP_TYPE_QUALS (t) == type_quals)
568 /* If we didn't already have it, create it now. */
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;
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.
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));
590 else if (TYPE_PTRMEMFUNC_P (type))
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. */
598 t = TYPE_PTRMEMFUNC_FN_TYPE (type);
599 t = cp_build_qualified_type_real (t, type_quals, complain);
600 return build_ptrmemfunc_type (t);
603 /* Retrieve (or create) the appropriately qualified variant. */
604 result = build_qualified_type (type, type_quals);
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
611 && TREE_CODE (type) == POINTER_TYPE
612 && TREE_CODE (TREE_TYPE (type)) == METHOD_TYPE)
613 TYPE_SET_PTRMEMFUNC_TYPE (result, NULL_TREE);
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
624 canonical_type_variant (t)
627 return cp_build_qualified_type (TYPE_MAIN_VARIANT (t), CP_TYPE_QUALS (t));
630 /* Makes new binfos for the indirect bases under BINFO, and updates
631 BINFO_OFFSET for them and their bases. */
634 unshare_base_binfos (binfo)
637 tree binfos = BINFO_BASETYPES (binfo);
641 if (binfos == NULL_TREE)
644 /* Now unshare the structure beneath BINFO. */
645 for (j = TREE_VEC_LENGTH (binfos)-1;
648 tree base_binfo = TREE_VEC_ELT (binfos, j);
649 new_binfo = TREE_VEC_ELT (binfos, j)
650 = make_binfo (BINFO_OFFSET (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);
664 /* Hashing of lists so that we don't make duplicates.
665 The entry point is `list_hash_canon'. */
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. */
673 static htab_t list_hash_table;
682 /* Compare ENTRY (an entry in the hash table) with DATA (a list_proxy
683 for a node we are thinking about adding). */
686 list_hash_eq (entry, data)
690 tree t = (tree) entry;
691 struct list_proxy *proxy = (struct list_proxy *) data;
693 return (TREE_VALUE (t) == proxy->value
694 && TREE_PURPOSE (t) == proxy->purpose
695 && TREE_CHAIN (t) == proxy->chain);
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. */
703 list_hash_pieces (purpose, value, chain)
708 hashval_t hashcode = 0;
711 hashcode += TYPE_HASH (chain);
714 hashcode += TYPE_HASH (value);
718 hashcode += TYPE_HASH (purpose);
724 /* Hash an already existing TREE_LIST. */
731 return list_hash_pieces (TREE_PURPOSE (t),
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. */
741 hash_tree_cons (purpose, value, chain)
742 tree purpose, value, chain;
746 struct list_proxy proxy;
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;
755 /* See if it is already in the table. */
756 slot = htab_find_slot_with_hash (list_hash_table, &proxy, hashcode,
758 /* If not, create a new node. */
760 *slot = (PTR) tree_cons (purpose, value, chain);
764 /* Constructor for hashed lists. */
767 hash_tree_chain (value, chain)
770 return hash_tree_cons (NULL_TREE, value, chain);
773 /* Similar, but used for concatenating two lists. */
776 hash_chainon (list1, 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));
789 /* Build an association between TYPE and some parameters:
791 OFFSET is the offset added to `this' to convert it to a pointer
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.
799 VTABLE is the virtual function table with which to initialize
800 sub-objects of type TYPE.
802 VIRTUALS are the virtual functions sitting in VTABLE. */
805 make_binfo (offset, binfo, vtable, virtuals)
807 tree vtable, virtuals;
809 tree new_binfo = make_tree_vec (11);
812 if (TREE_CODE (binfo) == TREE_VEC)
813 type = BINFO_TYPE (binfo);
817 binfo = CLASS_TYPE_P (type) ? TYPE_BINFO (binfo) : NULL_TREE;
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;
825 if (binfo && BINFO_BASETYPES (binfo) != NULL_TREE)
826 BINFO_BASETYPES (new_binfo) = copy_node (BINFO_BASETYPES (binfo));
830 /* Return the binfo value for ELEM in TYPE. */
833 binfo_value (elem, type)
837 if (get_base_distance (elem, type, 0, (tree *)0) == -2)
838 compiler_error ("base class `%s' ambiguous in binfo_value",
839 TYPE_NAME_STRING (elem));
841 return TYPE_BINFO (type);
842 if (TREE_CODE (elem) == RECORD_TYPE && TYPE_BINFO (elem) == type)
844 return get_binfo (elem, type, 0);
847 /* Return a TREE_LIST whose TREE_VALUE nodes along the
848 BINFO_INHERITANCE_CHAIN for BINFO, but in the opposite order. In
849 other words, while the BINFO_INHERITANCE_CHAIN goes from base
850 classes to derived classes, the reversed path goes from derived
851 classes to base classes. */
859 reversed_path = NULL_TREE;
862 reversed_path = tree_cons (NULL_TREE, binfo, reversed_path);
863 binfo = BINFO_INHERITANCE_CHAIN (binfo);
866 return reversed_path;
876 fprintf (stderr, "type \"%s\", offset = ",
877 TYPE_NAME_STRING (BINFO_TYPE (elem)));
878 fprintf (stderr, HOST_WIDE_INT_PRINT_DEC,
879 TREE_INT_CST_LOW (BINFO_OFFSET (elem)));
880 fprintf (stderr, "\nvtable type:\n");
881 debug_tree (BINFO_TYPE (elem));
882 if (BINFO_VTABLE (elem))
883 fprintf (stderr, "vtable decl \"%s\"\n",
884 IDENTIFIER_POINTER (DECL_NAME (get_vtbl_decl_for_binfo (elem))));
886 fprintf (stderr, "no vtable decl yet\n");
887 fprintf (stderr, "virtuals:\n");
888 virtuals = BINFO_VIRTUALS (elem);
893 tree fndecl = TREE_VALUE (virtuals);
894 fprintf (stderr, "%s [%ld =? %ld]\n",
895 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (fndecl)),
896 (long) n, (long) TREE_INT_CST_LOW (DECL_VINDEX (fndecl)));
898 virtuals = TREE_CHAIN (virtuals);
907 if (TREE_CODE (t) == FUNCTION_DECL)
909 else if (TREE_CODE (t) == OVERLOAD)
911 for (i=0; t; t = OVL_CHAIN (t))
916 my_friendly_abort (359);
924 /* A baselink is also considered an overloaded function. */
925 if (TREE_CODE (x) == OFFSET_REF)
926 x = TREE_OPERAND (x, 1);
929 return (TREE_CODE (x) == FUNCTION_DECL
930 || TREE_CODE (x) == TEMPLATE_ID_EXPR
931 || DECL_FUNCTION_TEMPLATE_P (x)
932 || TREE_CODE (x) == OVERLOAD);
936 really_overloaded_fn (x)
939 /* A baselink is also considered an overloaded function. */
940 if (TREE_CODE (x) == OFFSET_REF)
941 x = TREE_OPERAND (x, 1);
944 return (TREE_CODE (x) == OVERLOAD
945 && (TREE_CHAIN (x) != NULL_TREE
946 || DECL_FUNCTION_TEMPLATE_P (OVL_FUNCTION (x))));
953 my_friendly_assert (is_overloaded_fn (from), 9);
954 /* A baselink is also considered an overloaded function. */
955 if (BASELINK_P (from))
956 from = TREE_VALUE (from);
957 return OVL_CURRENT (from);
960 /* Returns nonzero if T is a ->* or .* expression that refers to a
967 return (TREE_CODE (t) == OFFSET_REF
968 && TYPE_PTRMEMFUNC_P (TREE_TYPE (TREE_OPERAND (t, 1))));
971 /* Return a new OVL node, concatenating it with the old one. */
974 ovl_cons (decl, chain)
978 tree result = make_node (OVERLOAD);
979 TREE_TYPE (result) = unknown_type_node;
980 OVL_FUNCTION (result) = decl;
981 TREE_CHAIN (result) = chain;
986 /* Build a new overloaded function. If this is the first one,
987 just return it; otherwise, ovl_cons the _DECLs */
990 build_overload (decl, chain)
994 if (! chain && TREE_CODE (decl) != TEMPLATE_DECL)
996 if (chain && TREE_CODE (chain) != OVERLOAD)
997 chain = ovl_cons (chain, NULL_TREE);
998 return ovl_cons (decl, chain);
1001 /* True if fn is in ovl. */
1004 ovl_member (fn, ovl)
1008 if (ovl == NULL_TREE)
1010 if (TREE_CODE (ovl) != OVERLOAD)
1012 for (; ovl; ovl = OVL_CHAIN (ovl))
1013 if (OVL_FUNCTION (ovl) == fn)
1019 is_aggr_type_2 (t1, t2)
1022 if (TREE_CODE (t1) != TREE_CODE (t2))
1024 return IS_AGGR_TYPE (t1) && IS_AGGR_TYPE (t2);
1027 /* Returns non-zero if CODE is the code for a statement. */
1030 cp_statement_code_p (code)
1031 enum tree_code code;
1038 case CTOR_INITIALIZER:
1051 #define PRINT_RING_SIZE 4
1054 lang_printable_name (decl, v)
1058 static tree decl_ring[PRINT_RING_SIZE];
1059 static char *print_ring[PRINT_RING_SIZE];
1060 static int ring_counter;
1063 /* Only cache functions. */
1065 || TREE_CODE (decl) != FUNCTION_DECL
1066 || DECL_LANG_SPECIFIC (decl) == 0)
1067 return lang_decl_name (decl, v);
1069 /* See if this print name is lying around. */
1070 for (i = 0; i < PRINT_RING_SIZE; i++)
1071 if (decl_ring[i] == decl)
1072 /* yes, so return it. */
1073 return print_ring[i];
1075 if (++ring_counter == PRINT_RING_SIZE)
1078 if (current_function_decl != NULL_TREE)
1080 if (decl_ring[ring_counter] == current_function_decl)
1082 if (ring_counter == PRINT_RING_SIZE)
1084 if (decl_ring[ring_counter] == current_function_decl)
1085 my_friendly_abort (106);
1088 if (print_ring[ring_counter])
1089 free (print_ring[ring_counter]);
1091 print_ring[ring_counter] = xstrdup (lang_decl_name (decl, v));
1092 decl_ring[ring_counter] = decl;
1093 return print_ring[ring_counter];
1096 /* Build the FUNCTION_TYPE or METHOD_TYPE which may throw exceptions
1097 listed in RAISES. */
1100 build_exception_variant (type, raises)
1104 tree v = TYPE_MAIN_VARIANT (type);
1105 int type_quals = TYPE_QUALS (type);
1107 for (; v; v = TYPE_NEXT_VARIANT (v))
1108 if (TYPE_QUALS (v) == type_quals
1109 && comp_except_specs (raises, TYPE_RAISES_EXCEPTIONS (v), 1))
1112 /* Need to build a new variant. */
1113 v = build_type_copy (type);
1114 TYPE_RAISES_EXCEPTIONS (v) = raises;
1118 /* Given a TEMPLATE_TEMPLATE_PARM node T, create a new
1119 BOUND_TEMPLATE_TEMPLATE_PARM bound with NEWARGS as its template
1123 bind_template_template_parm (t, newargs)
1127 tree decl = TYPE_NAME (t);
1130 t2 = make_aggr_type (BOUND_TEMPLATE_TEMPLATE_PARM);
1131 decl = build_decl (TYPE_DECL, DECL_NAME (decl), NULL_TREE);
1133 /* These nodes have to be created to reflect new TYPE_DECL and template
1135 TEMPLATE_TYPE_PARM_INDEX (t2) = copy_node (TEMPLATE_TYPE_PARM_INDEX (t));
1136 TEMPLATE_PARM_DECL (TEMPLATE_TYPE_PARM_INDEX (t2)) = decl;
1137 TEMPLATE_TEMPLATE_PARM_TEMPLATE_INFO (t2)
1138 = tree_cons (TEMPLATE_TEMPLATE_PARM_TEMPLATE_DECL (t),
1139 newargs, NULL_TREE);
1141 TREE_TYPE (decl) = t2;
1142 TYPE_NAME (t2) = decl;
1143 TYPE_STUB_DECL (t2) = decl;
1149 /* Apply FUNC to all the sub-trees of TP in a pre-order traversal.
1150 FUNC is called with the DATA and the address of each sub-tree. If
1151 FUNC returns a non-NULL value, the traversal is aborted, and the
1152 value returned by FUNC is returned. If HTAB is non-NULL it is used
1153 to record the nodes visited, and to avoid visiting a node more than
1157 walk_tree (tp, func, data, htab)
1163 enum tree_code code;
1167 #define WALK_SUBTREE(NODE) \
1170 result = walk_tree (&(NODE), func, data, htab); \
1176 /* Skip empty subtrees. */
1184 /* Don't walk the same tree twice, if the user has requested
1185 that we avoid doing so. */
1186 if (htab_find (htab, *tp))
1188 /* If we haven't already seen this node, add it to the table. */
1189 slot = htab_find_slot (htab, *tp, INSERT);
1193 /* Call the function. */
1195 result = (*func) (tp, &walk_subtrees, data);
1197 /* If we found something, return it. */
1201 /* Even if we didn't, FUNC may have decided that there was nothing
1202 interesting below this point in the tree. */
1206 code = TREE_CODE (*tp);
1208 /* Handle common cases up front. */
1209 if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (code))
1210 || TREE_CODE_CLASS (code) == 'r'
1211 || TREE_CODE_CLASS (code) == 's')
1215 /* Set lineno here so we get the right instantiation context
1216 if we call instantiate_decl from inlinable_function_p. */
1217 if (statement_code_p (code) && !STMT_LINENO_FOR_FN_P (*tp))
1218 lineno = STMT_LINENO (*tp);
1220 /* Walk over all the sub-trees of this operand. */
1221 len = first_rtl_op (code);
1222 /* TARGET_EXPRs are peculiar: operands 1 and 3 can be the same.
1223 But, we only want to walk once. */
1224 if (code == TARGET_EXPR
1225 && TREE_OPERAND (*tp, 3) == TREE_OPERAND (*tp, 1))
1227 /* Go through the subtrees. We need to do this in forward order so
1228 that the scope of a FOR_EXPR is handled properly. */
1229 for (i = 0; i < len; ++i)
1230 WALK_SUBTREE (TREE_OPERAND (*tp, i));
1232 /* For statements, we also walk the chain so that we cover the
1233 entire statement tree. */
1234 if (statement_code_p (code))
1236 if (code == DECL_STMT
1237 && DECL_STMT_DECL (*tp)
1238 && DECL_P (DECL_STMT_DECL (*tp)))
1240 /* Walk the DECL_INITIAL and DECL_SIZE. We don't want to walk
1241 into declarations that are just mentioned, rather than
1242 declared; they don't really belong to this part of the tree.
1243 And, we can see cycles: the initializer for a declaration can
1244 refer to the declaration itself. */
1245 WALK_SUBTREE (DECL_INITIAL (DECL_STMT_DECL (*tp)));
1246 WALK_SUBTREE (DECL_SIZE (DECL_STMT_DECL (*tp)));
1247 WALK_SUBTREE (DECL_SIZE_UNIT (DECL_STMT_DECL (*tp)));
1250 /* This can be tail-recursion optimized if we write it this way. */
1251 return walk_tree (&TREE_CHAIN (*tp), func, data, htab);
1254 /* We didn't find what we were looking for. */
1257 else if (TREE_CODE_CLASS (code) == 'd')
1259 WALK_SUBTREE (TREE_TYPE (*tp));
1261 /* We didn't find what we were looking for. */
1265 /* Not one of the easy cases. We must explicitly go through the
1270 case IDENTIFIER_NODE:
1275 case TEMPLATE_TEMPLATE_PARM:
1276 case BOUND_TEMPLATE_TEMPLATE_PARM:
1277 case TEMPLATE_PARM_INDEX:
1278 case TEMPLATE_TYPE_PARM:
1289 /* None of thse have subtrees other than those already walked
1294 WALK_SUBTREE (TREE_TYPE (*tp));
1298 case REFERENCE_TYPE:
1299 WALK_SUBTREE (TREE_TYPE (*tp));
1303 /* A BASELINK_P's TREE_PURPOSE is a BINFO, and hence circular. */
1304 if (!BASELINK_P (*tp))
1305 WALK_SUBTREE (TREE_PURPOSE (*tp));
1306 WALK_SUBTREE (TREE_VALUE (*tp));
1307 WALK_SUBTREE (TREE_CHAIN (*tp));
1311 WALK_SUBTREE (OVL_FUNCTION (*tp));
1312 WALK_SUBTREE (OVL_CHAIN (*tp));
1317 int len = TREE_VEC_LENGTH (*tp);
1319 WALK_SUBTREE (TREE_VEC_ELT (*tp, len));
1324 WALK_SUBTREE (TREE_REALPART (*tp));
1325 WALK_SUBTREE (TREE_IMAGPART (*tp));
1329 WALK_SUBTREE (CONSTRUCTOR_ELTS (*tp));
1333 WALK_SUBTREE (TYPE_METHOD_BASETYPE (*tp));
1337 WALK_SUBTREE (TREE_TYPE (*tp));
1339 tree arg = TYPE_ARG_TYPES (*tp);
1341 /* We never want to walk into default arguments. */
1342 for (; arg; arg = TREE_CHAIN (arg))
1343 WALK_SUBTREE (TREE_VALUE (arg));
1348 WALK_SUBTREE (TREE_TYPE (*tp));
1349 WALK_SUBTREE (TYPE_DOMAIN (*tp));
1353 WALK_SUBTREE (TYPE_MIN_VALUE (*tp));
1354 WALK_SUBTREE (TYPE_MAX_VALUE (*tp));
1358 WALK_SUBTREE (TREE_TYPE (*tp));
1359 WALK_SUBTREE (TYPE_OFFSET_BASETYPE (*tp));
1363 if (TYPE_PTRMEMFUNC_P (*tp))
1364 WALK_SUBTREE (TYPE_PTRMEMFUNC_FN_TYPE (*tp));
1368 my_friendly_abort (19990803);
1371 /* We didn't find what we were looking for. */
1377 /* Like walk_tree, but does not walk duplicate nodes more than
1381 walk_tree_without_duplicates (tp, func, data)
1389 htab = htab_create (37, htab_hash_pointer, htab_eq_pointer, NULL);
1390 result = walk_tree (tp, func, data, htab);
1395 /* Called from count_trees via walk_tree. */
1398 count_trees_r (tp, walk_subtrees, data)
1399 tree *tp ATTRIBUTE_UNUSED;
1400 int *walk_subtrees ATTRIBUTE_UNUSED;
1407 /* Debugging function for measuring the rough complexity of a tree
1415 walk_tree_without_duplicates (&t, count_trees_r, &n_trees);
1419 /* Called from verify_stmt_tree via walk_tree. */
1422 verify_stmt_tree_r (tp, walk_subtrees, data)
1424 int *walk_subtrees ATTRIBUTE_UNUSED;
1428 htab_t *statements = (htab_t *) data;
1431 if (!statement_code_p (TREE_CODE (t)))
1434 /* If this statement is already present in the hash table, then
1435 there is a circularity in the statement tree. */
1436 if (htab_find (*statements, t))
1437 my_friendly_abort (20000727);
1439 slot = htab_find_slot (*statements, t, INSERT);
1445 /* Debugging function to check that the statement T has not been
1446 corrupted. For now, this function simply checks that T contains no
1450 verify_stmt_tree (t)
1454 statements = htab_create (37, htab_hash_pointer, htab_eq_pointer, NULL);
1455 walk_tree (&t, verify_stmt_tree_r, &statements, NULL);
1456 htab_delete (statements);
1459 /* Called from find_tree via walk_tree. */
1462 find_tree_r (tp, walk_subtrees, data)
1464 int *walk_subtrees ATTRIBUTE_UNUSED;
1467 if (*tp == (tree) data)
1473 /* Returns X if X appears in the tree structure rooted at T. */
1480 return walk_tree_without_duplicates (&t, find_tree_r, x);
1483 /* Passed to walk_tree. Checks for the use of types with no linkage. */
1486 no_linkage_helper (tp, walk_subtrees, data)
1488 int *walk_subtrees ATTRIBUTE_UNUSED;
1489 void *data ATTRIBUTE_UNUSED;
1494 && (CLASS_TYPE_P (t) || TREE_CODE (t) == ENUMERAL_TYPE)
1495 && (decl_function_context (TYPE_MAIN_DECL (t))
1496 || TYPE_ANONYMOUS_P (t)))
1501 /* Check if the type T depends on a type with no linkage and if so, return
1505 no_linkage_check (t)
1508 /* There's no point in checking linkage on template functions; we
1509 can't know their complete types. */
1510 if (processing_template_decl)
1513 t = walk_tree_without_duplicates (&t, no_linkage_helper, NULL);
1514 if (t != error_mark_node)
1519 /* Passed to walk_tree. Copies the node pointed to, if appropriate. */
1522 copy_tree_r (tp, walk_subtrees, data)
1525 void *data ATTRIBUTE_UNUSED;
1527 enum tree_code code = TREE_CODE (*tp);
1529 /* We make copies of most nodes. */
1530 if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (code))
1531 || TREE_CODE_CLASS (code) == 'r'
1532 || TREE_CODE_CLASS (code) == 'c'
1533 || TREE_CODE_CLASS (code) == 's'
1534 || code == TREE_LIST
1536 || code == OVERLOAD)
1538 /* Because the chain gets clobbered when we make a copy, we save it
1540 tree chain = TREE_CHAIN (*tp);
1542 /* Copy the node. */
1543 *tp = copy_node (*tp);
1545 /* Now, restore the chain, if appropriate. That will cause
1546 walk_tree to walk into the chain as well. */
1547 if (code == PARM_DECL || code == TREE_LIST || code == OVERLOAD
1548 || statement_code_p (code))
1549 TREE_CHAIN (*tp) = chain;
1551 /* For now, we don't update BLOCKs when we make copies. So, we
1552 have to nullify all scope-statements. */
1553 if (TREE_CODE (*tp) == SCOPE_STMT)
1554 SCOPE_STMT_BLOCK (*tp) = NULL_TREE;
1556 else if (TREE_CODE_CLASS (code) == 't')
1557 /* There's no need to copy types, or anything beneath them. */
1563 #ifdef GATHER_STATISTICS
1564 extern int depth_reached;
1568 print_lang_statistics ()
1570 print_search_statistics ();
1571 print_class_statistics ();
1572 #ifdef GATHER_STATISTICS
1573 fprintf (stderr, "maximum template instantiation depth reached: %d\n",
1578 /* Return, as an INTEGER_CST node, the number of elements for TYPE
1579 (which is an ARRAY_TYPE). This counts only elements of the top
1583 array_type_nelts_top (type)
1586 return fold (build (PLUS_EXPR, sizetype,
1587 array_type_nelts (type),
1591 /* Return, as an INTEGER_CST node, the number of elements for TYPE
1592 (which is an ARRAY_TYPE). This one is a recursive count of all
1593 ARRAY_TYPEs that are clumped together. */
1596 array_type_nelts_total (type)
1599 tree sz = array_type_nelts_top (type);
1600 type = TREE_TYPE (type);
1601 while (TREE_CODE (type) == ARRAY_TYPE)
1603 tree n = array_type_nelts_top (type);
1604 sz = fold (build (MULT_EXPR, sizetype, sz, n));
1605 type = TREE_TYPE (type);
1610 /* Called from break_out_target_exprs via mapcar. */
1613 bot_manip (tp, walk_subtrees, data)
1618 splay_tree target_remap = ((splay_tree) data);
1621 if (TREE_CONSTANT (t))
1623 /* There can't be any TARGET_EXPRs or their slot variables below
1624 this point. We used to check !TREE_SIDE_EFFECTS, but then we
1625 failed to copy an ADDR_EXPR of the slot VAR_DECL. */
1629 if (TREE_CODE (t) == TARGET_EXPR)
1633 if (TREE_CODE (TREE_OPERAND (t, 1)) == AGGR_INIT_EXPR)
1635 mark_used (TREE_OPERAND (TREE_OPERAND (TREE_OPERAND (t, 1), 0), 0));
1637 (TREE_TYPE (t), break_out_target_exprs (TREE_OPERAND (t, 1)));
1641 u = build_target_expr_with_type
1642 (break_out_target_exprs (TREE_OPERAND (t, 1)), TREE_TYPE (t));
1645 /* Map the old variable to the new one. */
1646 splay_tree_insert (target_remap,
1647 (splay_tree_key) TREE_OPERAND (t, 0),
1648 (splay_tree_value) TREE_OPERAND (u, 0));
1650 /* Replace the old expression with the new version. */
1652 /* We don't have to go below this point; the recursive call to
1653 break_out_target_exprs will have handled anything below this
1658 else if (TREE_CODE (t) == CALL_EXPR)
1659 mark_used (TREE_OPERAND (TREE_OPERAND (t, 0), 0));
1661 /* Make a copy of this node. */
1662 return copy_tree_r (tp, walk_subtrees, NULL);
1665 /* Replace all remapped VAR_DECLs in T with their new equivalents.
1666 DATA is really a splay-tree mapping old variables to new
1670 bot_replace (t, walk_subtrees, data)
1672 int *walk_subtrees ATTRIBUTE_UNUSED;
1675 splay_tree target_remap = ((splay_tree) data);
1677 if (TREE_CODE (*t) == VAR_DECL)
1679 splay_tree_node n = splay_tree_lookup (target_remap,
1680 (splay_tree_key) *t);
1682 *t = (tree) n->value;
1688 /* When we parse a default argument expression, we may create
1689 temporary variables via TARGET_EXPRs. When we actually use the
1690 default-argument expression, we make a copy of the expression, but
1691 we must replace the temporaries with appropriate local versions. */
1694 break_out_target_exprs (t)
1697 static int target_remap_count;
1698 static splay_tree target_remap;
1700 if (!target_remap_count++)
1701 target_remap = splay_tree_new (splay_tree_compare_pointers,
1702 /*splay_tree_delete_key_fn=*/NULL,
1703 /*splay_tree_delete_value_fn=*/NULL);
1704 walk_tree (&t, bot_manip, target_remap, NULL);
1705 walk_tree (&t, bot_replace, target_remap, NULL);
1707 if (!--target_remap_count)
1709 splay_tree_delete (target_remap);
1710 target_remap = NULL;
1716 /* Obstack used for allocating nodes in template function and variable
1719 /* Similar to `build_nt', except that we set TREE_COMPLEXITY to be the
1720 current line number. */
1723 build_min_nt VPARAMS ((enum tree_code code, ...))
1725 #ifndef ANSI_PROTOTYPES
1726 enum tree_code code;
1730 register int length;
1735 #ifndef ANSI_PROTOTYPES
1736 code = va_arg (p, enum tree_code);
1739 t = make_node (code);
1740 length = TREE_CODE_LENGTH (code);
1741 TREE_COMPLEXITY (t) = lineno;
1743 for (i = 0; i < length; i++)
1745 tree x = va_arg (p, tree);
1746 TREE_OPERAND (t, i) = x;
1753 /* Similar to `build', except we set TREE_COMPLEXITY to the current
1757 build_min VPARAMS ((enum tree_code code, tree tt, ...))
1759 #ifndef ANSI_PROTOTYPES
1760 enum tree_code code;
1765 register int length;
1770 #ifndef ANSI_PROTOTYPES
1771 code = va_arg (p, enum tree_code);
1772 tt = va_arg (p, tree);
1775 t = make_node (code);
1776 length = TREE_CODE_LENGTH (code);
1778 TREE_COMPLEXITY (t) = lineno;
1780 for (i = 0; i < length; i++)
1782 tree x = va_arg (p, tree);
1783 TREE_OPERAND (t, i) = x;
1790 /* Returns an INTEGER_CST (of type `int') corresponding to I.
1791 Multiple calls with the same value of I may or may not yield the
1792 same node; therefore, callers should never modify the node
1796 build_shared_int_cst (i)
1799 static tree cache[256];
1802 return build_int_2 (i, 0);
1805 cache[i] = build_int_2 (i, 0);
1814 if (TREE_CODE (t) == TYPE_DECL)
1817 return TYPE_STUB_DECL (t);
1818 if (t == error_mark_node)
1821 my_friendly_abort (42);
1823 /* Stop compiler from complaining control reaches end of non-void function. */
1827 /* Return first vector element whose BINFO_TYPE is ELEM.
1828 Return 0 if ELEM is not in VEC. VEC may be NULL_TREE. */
1831 vec_binfo_member (elem, vec)
1837 for (i = 0; i < TREE_VEC_LENGTH (vec); ++i)
1838 if (same_type_p (elem, BINFO_TYPE (TREE_VEC_ELT (vec, i))))
1839 return TREE_VEC_ELT (vec, i);
1844 /* Returns the namespace that contains DECL, whether directly or
1848 decl_namespace_context (decl)
1853 if (TREE_CODE (decl) == NAMESPACE_DECL)
1855 else if (TYPE_P (decl))
1856 decl = CP_DECL_CONTEXT (TYPE_MAIN_DECL (decl));
1858 decl = CP_DECL_CONTEXT (decl);
1862 /* Return truthvalue of whether T1 is the same tree structure as T2.
1863 Return 1 if they are the same.
1864 Return 0 if they are understandably different.
1865 Return -1 if either contains tree structure not understood by
1869 cp_tree_equal (t1, t2)
1872 register enum tree_code code1, code2;
1877 if (t1 == 0 || t2 == 0)
1880 code1 = TREE_CODE (t1);
1881 code2 = TREE_CODE (t2);
1883 if (code1 == NOP_EXPR || code1 == CONVERT_EXPR || code1 == NON_LVALUE_EXPR)
1885 if (code2 == NOP_EXPR || code2 == CONVERT_EXPR || code2 == NON_LVALUE_EXPR)
1886 return cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
1888 return cp_tree_equal (TREE_OPERAND (t1, 0), t2);
1890 else if (code2 == NOP_EXPR || code2 == CONVERT_EXPR
1891 || code2 == NON_LVALUE_EXPR)
1892 return cp_tree_equal (t1, TREE_OPERAND (t2, 0));
1900 return TREE_INT_CST_LOW (t1) == TREE_INT_CST_LOW (t2)
1901 && TREE_INT_CST_HIGH (t1) == TREE_INT_CST_HIGH (t2);
1904 return REAL_VALUES_EQUAL (TREE_REAL_CST (t1), TREE_REAL_CST (t2));
1907 return TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
1908 && !memcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
1909 TREE_STRING_LENGTH (t1));
1912 /* We need to do this when determining whether or not two
1913 non-type pointer to member function template arguments
1915 if (!(same_type_p (TREE_TYPE (t1), TREE_TYPE (t2))
1916 /* The first operand is RTL. */
1917 && TREE_OPERAND (t1, 0) == TREE_OPERAND (t2, 0)))
1919 return cp_tree_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
1922 cmp = cp_tree_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2));
1925 cmp = cp_tree_equal (TREE_VALUE (t1), TREE_VALUE (t2));
1928 return cp_tree_equal (TREE_CHAIN (t1), TREE_CHAIN (t2));
1931 return cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
1934 cmp = cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
1937 return simple_cst_list_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
1940 /* Special case: if either target is an unallocated VAR_DECL,
1941 it means that it's going to be unified with whatever the
1942 TARGET_EXPR is really supposed to initialize, so treat it
1943 as being equivalent to anything. */
1944 if ((TREE_CODE (TREE_OPERAND (t1, 0)) == VAR_DECL
1945 && DECL_NAME (TREE_OPERAND (t1, 0)) == NULL_TREE
1946 && !DECL_RTL_SET_P (TREE_OPERAND (t1, 0)))
1947 || (TREE_CODE (TREE_OPERAND (t2, 0)) == VAR_DECL
1948 && DECL_NAME (TREE_OPERAND (t2, 0)) == NULL_TREE
1949 && !DECL_RTL_SET_P (TREE_OPERAND (t2, 0))))
1952 cmp = cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
1955 return cp_tree_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
1957 case WITH_CLEANUP_EXPR:
1958 cmp = cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
1961 return cp_tree_equal (TREE_OPERAND (t1, 2), TREE_OPERAND (t1, 2));
1964 if (TREE_OPERAND (t1, 1) == TREE_OPERAND (t2, 1))
1965 return cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
1974 case TEMPLATE_PARM_INDEX:
1975 return TEMPLATE_PARM_IDX (t1) == TEMPLATE_PARM_IDX (t2)
1976 && TEMPLATE_PARM_LEVEL (t1) == TEMPLATE_PARM_LEVEL (t2);
1980 if (TREE_CODE (TREE_OPERAND (t1, 0)) != TREE_CODE (TREE_OPERAND (t2, 0)))
1982 if (TYPE_P (TREE_OPERAND (t1, 0)))
1983 return same_type_p (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
1987 /* Two pointer-to-members are the same if they point to the same
1988 field or function in the same class. */
1989 return (PTRMEM_CST_MEMBER (t1) == PTRMEM_CST_MEMBER (t2)
1990 && same_type_p (PTRMEM_CST_CLASS (t1), PTRMEM_CST_CLASS (t2)));
1996 switch (TREE_CODE_CLASS (code1))
2008 for (i = 0; i < TREE_CODE_LENGTH (code1); ++i)
2010 cmp = cp_tree_equal (TREE_OPERAND (t1, i), TREE_OPERAND (t2, i));
2018 return same_type_p (t1, t2) ? 1 : 0;
2024 /* Build a wrapper around some pointer PTR so we can use it as a tree. */
2027 build_ptr_wrapper (ptr)
2030 tree t = make_node (WRAPPER);
2031 WRAPPER_PTR (t) = ptr;
2035 /* Build a wrapper around some integer I so we can use it as a tree. */
2038 build_int_wrapper (i)
2041 tree t = make_node (WRAPPER);
2042 WRAPPER_INT (t) = i;
2047 build_srcloc (file, line)
2053 t = make_node (SRCLOC);
2054 SRCLOC_FILE (t) = file;
2055 SRCLOC_LINE (t) = line;
2061 build_srcloc_here ()
2063 return build_srcloc (input_filename, lineno);
2066 /* The type of ARG when used as an lvalue. */
2072 tree type = TREE_TYPE (arg);
2073 if (TREE_CODE (arg) == OVERLOAD)
2074 type = unknown_type_node;
2078 /* The type of ARG for printing error messages; denote lvalues with
2085 tree type = TREE_TYPE (arg);
2086 if (TREE_CODE (type) == ARRAY_TYPE)
2088 else if (real_lvalue_p (arg))
2089 type = build_reference_type (lvalue_type (arg));
2090 else if (IS_AGGR_TYPE (type))
2091 type = lvalue_type (arg);
2096 /* Does FUNCTION use a variable-length argument list? */
2099 varargs_function_p (function)
2102 tree parm = TYPE_ARG_TYPES (TREE_TYPE (function));
2103 for (; parm; parm = TREE_CHAIN (parm))
2104 if (TREE_VALUE (parm) == void_type_node)
2109 /* Returns 1 if decl is a member of a class. */
2115 const tree ctx = DECL_CONTEXT (decl);
2116 return (ctx && TYPE_P (ctx));
2119 /* Create a placeholder for member access where we don't actually have an
2120 object that the access is against. */
2123 build_dummy_object (type)
2126 tree decl = build1 (NOP_EXPR, build_pointer_type (type), void_zero_node);
2127 return build_indirect_ref (decl, NULL);
2130 /* We've gotten a reference to a member of TYPE. Return *this if appropriate,
2131 or a dummy object otherwise. If BINFOP is non-0, it is filled with the
2132 binfo path from current_class_type to TYPE, or 0. */
2135 maybe_dummy_object (type, binfop)
2141 if (current_class_type
2142 && get_base_distance (type, current_class_type, 0, binfop) != -1)
2143 context = current_class_type;
2146 /* Reference from a nested class member function. */
2149 *binfop = TYPE_BINFO (type);
2152 if (current_class_ref && context == current_class_type)
2153 decl = current_class_ref;
2155 decl = build_dummy_object (context);
2160 /* Returns 1 if OB is a placeholder object, or a pointer to one. */
2163 is_dummy_object (ob)
2166 if (TREE_CODE (ob) == INDIRECT_REF)
2167 ob = TREE_OPERAND (ob, 0);
2168 return (TREE_CODE (ob) == NOP_EXPR
2169 && TREE_OPERAND (ob, 0) == void_zero_node);
2172 /* Returns 1 iff type T is a POD type, as defined in [basic.types]. */
2178 t = strip_array_types (t);
2180 if (INTEGRAL_TYPE_P (t))
2181 return 1; /* integral, character or enumeral type */
2182 if (FLOAT_TYPE_P (t))
2185 return 1; /* pointer to non-member */
2186 if (TYPE_PTRMEM_P (t))
2187 return 1; /* pointer to member object */
2188 if (TYPE_PTRMEMFUNC_P (t))
2189 return 1; /* pointer to member function */
2191 if (! CLASS_TYPE_P (t))
2192 return 0; /* other non-class type (reference or function) */
2193 if (CLASSTYPE_NON_POD_P (t))
2198 /* Return a 1 if ATTR_NAME and ATTR_ARGS denote a valid C++-specific
2199 attribute for either declaration DECL or type TYPE and 0 otherwise.
2200 Plugged into valid_lang_attribute. */
2203 cp_valid_lang_attribute (attr_name, attr_args, decl, type)
2205 tree attr_args ATTRIBUTE_UNUSED;
2206 tree decl ATTRIBUTE_UNUSED;
2207 tree type ATTRIBUTE_UNUSED;
2209 if (is_attribute_p ("java_interface", attr_name))
2211 if (attr_args != NULL_TREE
2212 || decl != NULL_TREE
2213 || ! CLASS_TYPE_P (type)
2214 || ! TYPE_FOR_JAVA (type))
2216 error ("`java_interface' attribute can only be applied to Java class definitions");
2219 TYPE_JAVA_INTERFACE (type) = 1;
2222 if (is_attribute_p ("com_interface", attr_name))
2225 if (attr_args != NULL_TREE
2226 || decl != NULL_TREE
2227 || ! CLASS_TYPE_P (type)
2228 || type != TYPE_MAIN_VARIANT (type))
2230 warning ("`com_interface' attribute can only be applied to class definitions");
2236 `com_interface' is obsolete; g++ vtables are now COM-compatible by default");
2239 else if (is_attribute_p ("init_priority", attr_name))
2241 tree initp_expr = (attr_args ? TREE_VALUE (attr_args): NULL_TREE);
2245 STRIP_NOPS (initp_expr);
2247 if (!initp_expr || TREE_CODE (initp_expr) != INTEGER_CST)
2249 error ("requested init_priority is not an integer constant");
2253 pri = TREE_INT_CST_LOW (initp_expr);
2255 type = strip_array_types (type);
2257 if (decl == NULL_TREE
2258 || TREE_CODE (decl) != VAR_DECL
2259 || ! TREE_STATIC (decl)
2260 || DECL_EXTERNAL (decl)
2261 || (TREE_CODE (type) != RECORD_TYPE
2262 && TREE_CODE (type) != UNION_TYPE)
2263 /* Static objects in functions are initialized the
2264 first time control passes through that
2265 function. This is not precise enough to pin down an
2266 init_priority value, so don't allow it. */
2267 || current_function_decl)
2269 error ("can only use init_priority attribute on file-scope definitions of objects of class type");
2273 if (pri > MAX_INIT_PRIORITY || pri <= 0)
2275 error ("requested init_priority is out of range");
2279 /* Check for init_priorities that are reserved for
2280 language and runtime support implementations.*/
2281 if (pri <= MAX_RESERVED_INIT_PRIORITY)
2284 ("requested init_priority is reserved for internal use");
2287 if (SUPPORTS_INIT_PRIORITY)
2289 DECL_INIT_PRIORITY (decl) = pri;
2294 error ("init_priority attribute is not supported on this platform");
2302 /* Return a new PTRMEM_CST of the indicated TYPE. The MEMBER is the
2303 thing pointed to by the constant. */
2306 make_ptrmem_cst (type, member)
2310 tree ptrmem_cst = make_node (PTRMEM_CST);
2311 /* If would seem a great convenience if make_node would set
2312 TREE_CONSTANT for things of class `c', but it does not. */
2313 TREE_CONSTANT (ptrmem_cst) = 1;
2314 TREE_TYPE (ptrmem_cst) = type;
2315 PTRMEM_CST_MEMBER (ptrmem_cst) = member;
2319 /* Initialize tree.c. */
2324 make_lang_type_fn = cp_make_lang_type;
2325 lang_unsave = cp_unsave;
2326 lang_statement_code_p = cp_statement_code_p;
2327 lang_set_decl_assembler_name = mangle_decl;
2328 list_hash_table = htab_create (31, list_hash, list_hash_eq, NULL);
2329 ggc_add_root (&list_hash_table, 1,
2330 sizeof (list_hash_table),
2331 mark_tree_hashtable);
2334 /* The SAVE_EXPR pointed to by TP is being copied. If ST contains
2335 information indicating to what new SAVE_EXPR this one should be
2336 mapped, use that one. Otherwise, create a new node and enter it in
2337 ST. FN is the function into which the copy will be placed. */
2340 remap_save_expr (tp, st, fn, walk_subtrees)
2348 /* See if we already encountered this SAVE_EXPR. */
2349 n = splay_tree_lookup (st, (splay_tree_key) *tp);
2351 /* If we didn't already remap this SAVE_EXPR, do so now. */
2354 tree t = copy_node (*tp);
2356 /* The SAVE_EXPR is now part of the function into which we
2357 are inlining this body. */
2358 SAVE_EXPR_CONTEXT (t) = fn;
2359 /* And we haven't evaluated it yet. */
2360 SAVE_EXPR_RTL (t) = NULL_RTX;
2361 /* Remember this SAVE_EXPR. */
2362 n = splay_tree_insert (st,
2363 (splay_tree_key) *tp,
2364 (splay_tree_value) t);
2367 /* We've already walked into this SAVE_EXPR, so we needn't do it
2371 /* Replace this SAVE_EXPR with the copy. */
2372 *tp = (tree) n->value;
2375 /* Called via walk_tree. If *TP points to a DECL_STMT for a local
2376 declaration, copies the declaration and enters it in the splay_tree
2377 pointed to by DATA (which is really a `splay_tree *'). */
2380 mark_local_for_remap_r (tp, walk_subtrees, data)
2382 int *walk_subtrees ATTRIBUTE_UNUSED;
2386 splay_tree st = (splay_tree) data;
2390 if (TREE_CODE (t) == DECL_STMT
2391 && nonstatic_local_decl_p (DECL_STMT_DECL (t)))
2392 decl = DECL_STMT_DECL (t);
2393 else if (TREE_CODE (t) == LABEL_STMT)
2394 decl = LABEL_STMT_LABEL (t);
2395 else if (TREE_CODE (t) == TARGET_EXPR
2396 && nonstatic_local_decl_p (TREE_OPERAND (t, 0)))
2397 decl = TREE_OPERAND (t, 0);
2398 else if (TREE_CODE (t) == CASE_LABEL)
2399 decl = CASE_LABEL_DECL (t);
2408 copy = copy_decl_for_inlining (decl,
2409 DECL_CONTEXT (decl),
2410 DECL_CONTEXT (decl));
2412 /* Remember the copy. */
2413 splay_tree_insert (st,
2414 (splay_tree_key) decl,
2415 (splay_tree_value) copy);
2421 /* Called via walk_tree when an expression is unsaved. Using the
2422 splay_tree pointed to by ST (which is really a `splay_tree'),
2423 remaps all local declarations to appropriate replacements. */
2426 cp_unsave_r (tp, walk_subtrees, data)
2431 splay_tree st = (splay_tree) data;
2434 /* Only a local declaration (variable or label). */
2435 if (nonstatic_local_decl_p (*tp))
2437 /* Lookup the declaration. */
2438 n = splay_tree_lookup (st, (splay_tree_key) *tp);
2440 /* If it's there, remap it. */
2442 *tp = (tree) n->value;
2444 else if (TREE_CODE (*tp) == SAVE_EXPR)
2445 remap_save_expr (tp, st, current_function_decl, walk_subtrees);
2448 copy_tree_r (tp, walk_subtrees, NULL);
2450 /* Do whatever unsaving is required. */
2451 unsave_expr_1 (*tp);
2454 /* Keep iterating. */
2458 /* Called by unsave_expr_now whenever an expression (*TP) needs to be
2467 /* Create a splay-tree to map old local variable declarations to new
2469 st = splay_tree_new (splay_tree_compare_pointers, NULL, NULL);
2471 /* Walk the tree once figuring out what needs to be remapped. */
2472 walk_tree (tp, mark_local_for_remap_r, st, NULL);
2474 /* Walk the tree again, copying, remapping, and unsaving. */
2475 walk_tree (tp, cp_unsave_r, st, NULL);
2478 splay_tree_delete (st);
2481 /* Returns the kind of special function that DECL (a FUNCTION_DECL)
2482 is. Note that this sfk_none is zero, so this function can be used
2483 as a predicate to test whether or not DECL is a special function. */
2485 special_function_kind
2486 special_function_p (decl)
2489 /* Rather than doing all this stuff with magic names, we should
2490 probably have a field of type `special_function_kind' in
2491 DECL_LANG_SPECIFIC. */
2492 if (DECL_COPY_CONSTRUCTOR_P (decl))
2493 return sfk_copy_constructor;
2494 if (DECL_CONSTRUCTOR_P (decl))
2495 return sfk_constructor;
2496 if (DECL_OVERLOADED_OPERATOR_P (decl) == NOP_EXPR)
2497 return sfk_assignment_operator;
2498 if (DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (decl))
2499 return sfk_destructor;
2500 if (DECL_COMPLETE_DESTRUCTOR_P (decl))
2501 return sfk_complete_destructor;
2502 if (DECL_BASE_DESTRUCTOR_P (decl))
2503 return sfk_base_destructor;
2504 if (DECL_DELETING_DESTRUCTOR_P (decl))
2505 return sfk_deleting_destructor;
2506 if (DECL_CONV_FN_P (decl))
2507 return sfk_conversion;
2512 /* Returns non-zero if TYPE is a character type, including wchar_t. */
2518 return (same_type_p (type, char_type_node)
2519 || same_type_p (type, unsigned_char_type_node)
2520 || same_type_p (type, signed_char_type_node)
2521 || same_type_p (type, wchar_type_node));
2524 /* Returns the kind of linkage associated with the indicated DECL. Th
2525 value returned is as specified by the language standard; it is
2526 independent of implementation details regarding template
2527 instantiation, etc. For example, it is possible that a declaration
2528 to which this function assigns external linkage would not show up
2529 as a global symbol when you run `nm' on the resulting object file. */
2535 /* This function doesn't attempt to calculate the linkage from first
2536 principles as given in [basic.link]. Instead, it makes use of
2537 the fact that we have already set TREE_PUBLIC appropriately, and
2538 then handles a few special cases. Ideally, we would calculate
2539 linkage first, and then transform that into a concrete
2542 /* Things that don't have names have no linkage. */
2543 if (!DECL_NAME (decl))
2546 /* Things that are TREE_PUBLIC have external linkage. */
2547 if (TREE_PUBLIC (decl))
2550 /* Some things that are not TREE_PUBLIC have external linkage, too.
2551 For example, on targets that don't have weak symbols, we make all
2552 template instantiations have internal linkage (in the object
2553 file), but the symbols should still be treated as having external
2554 linkage from the point of view of the language. */
2555 if (DECL_LANG_SPECIFIC (decl) && DECL_COMDAT (decl))
2558 /* Things in local scope do not have linkage, if they don't have
2560 if (decl_function_context (decl))
2563 /* Everything else has internal linkage. */