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 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 void list_hash_add
PARAMS ((int, tree
));
39 static int list_hash
PARAMS ((tree
, tree
, tree
));
40 static tree list_hash_lookup
PARAMS ((int, tree
, tree
, tree
));
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 ((char *, int));
44 static void mark_list_hash
PARAMS ((void *));
45 static int statement_code_p
PARAMS ((enum tree_code
));
46 static tree mark_local_for_remap_r
PARAMS ((tree
*, int *, void *));
47 static tree cp_unsave_r
PARAMS ((tree
*, int *, void *));
48 static void cp_unsave
PARAMS ((tree
*));
49 static tree build_target_expr
PARAMS ((tree
, tree
));
51 /* If REF is an lvalue, returns the kind of lvalue that REF is.
52 Otherwise, returns clk_none. If TREAT_CLASS_RVALUES_AS_LVALUES is
53 non-zero, rvalues of class type are considered lvalues. */
56 lvalue_p_1 (ref
, treat_class_rvalues_as_lvalues
)
58 int treat_class_rvalues_as_lvalues
;
60 cp_lvalue_kind op1_lvalue_kind
= clk_none
;
61 cp_lvalue_kind op2_lvalue_kind
= clk_none
;
63 if (TREE_CODE (TREE_TYPE (ref
)) == REFERENCE_TYPE
)
66 if (ref
== current_class_ptr
&& flag_this_is_variable
<= 0)
69 switch (TREE_CODE (ref
))
71 /* preincrements and predecrements are valid lvals, provided
72 what they refer to are valid lvals. */
73 case PREINCREMENT_EXPR
:
74 case PREDECREMENT_EXPR
:
78 case WITH_CLEANUP_EXPR
:
82 return lvalue_p_1 (TREE_OPERAND (ref
, 0),
83 treat_class_rvalues_as_lvalues
);
86 op1_lvalue_kind
= lvalue_p_1 (TREE_OPERAND (ref
, 0),
87 treat_class_rvalues_as_lvalues
);
89 /* The "field" can be a FUNCTION_DECL or an OVERLOAD in some
91 && TREE_CODE (TREE_OPERAND (ref
, 1)) == FIELD_DECL
92 && DECL_C_BIT_FIELD (TREE_OPERAND (ref
, 1)))
94 /* Clear the ordinary bit. If this object was a class
95 rvalue we want to preserve that information. */
96 op1_lvalue_kind
&= ~clk_ordinary
;
97 /* The lvalue is for a btifield. */
98 op1_lvalue_kind
|= clk_bitfield
;
100 return op1_lvalue_kind
;
106 if (TREE_READONLY (ref
) && ! TREE_STATIC (ref
)
107 && DECL_LANG_SPECIFIC (ref
)
108 && DECL_IN_AGGR_P (ref
))
114 if (TREE_CODE (TREE_TYPE (ref
)) != METHOD_TYPE
)
118 /* A currently unresolved scope ref. */
120 my_friendly_abort (103);
122 if (TREE_CODE (TREE_OPERAND (ref
, 1)) == FUNCTION_DECL
)
127 op1_lvalue_kind
= lvalue_p_1 (TREE_OPERAND (ref
, 0),
128 treat_class_rvalues_as_lvalues
);
129 op2_lvalue_kind
= lvalue_p_1 (TREE_OPERAND (ref
, 1),
130 treat_class_rvalues_as_lvalues
);
134 op1_lvalue_kind
= lvalue_p_1 (TREE_OPERAND (ref
, 1),
135 treat_class_rvalues_as_lvalues
);
136 op2_lvalue_kind
= lvalue_p_1 (TREE_OPERAND (ref
, 2),
137 treat_class_rvalues_as_lvalues
);
144 return lvalue_p_1 (TREE_OPERAND (ref
, 1),
145 treat_class_rvalues_as_lvalues
);
148 return treat_class_rvalues_as_lvalues
? clk_class
: clk_none
;
152 return ((treat_class_rvalues_as_lvalues
153 && IS_AGGR_TYPE (TREE_TYPE (ref
)))
154 ? clk_class
: clk_none
);
157 /* All functions (except non-static-member functions) are
159 return (DECL_NONSTATIC_MEMBER_FUNCTION_P (ref
)
160 ? clk_none
: clk_ordinary
);
166 /* If one operand is not an lvalue at all, then this expression is
168 if (!op1_lvalue_kind
|| !op2_lvalue_kind
)
171 /* Otherwise, it's an lvalue, and it has all the odd properties
172 contributed by either operand. */
173 op1_lvalue_kind
= op1_lvalue_kind
| op2_lvalue_kind
;
174 /* It's not an ordinary lvalue if it involves either a bit-field or
176 if ((op1_lvalue_kind
& ~clk_ordinary
) != clk_none
)
177 op1_lvalue_kind
&= ~clk_ordinary
;
178 return op1_lvalue_kind
;
181 /* If REF is an lvalue, returns the kind of lvalue that REF is.
182 Otherwise, returns clk_none. Lvalues can be assigned, unless they
183 have TREE_READONLY, or unless they are FUNCTION_DECLs. Lvalues can
184 have their address taken, unless they have DECL_REGISTER. */
190 return lvalue_p_1 (ref
, /*treat_class_rvalues_as_lvalues=*/0);
193 /* This differs from real_lvalue_p in that class rvalues are
194 considered lvalues. */
201 (lvalue_p_1 (ref
, /*treat_class_rvalues_as_lvalues=*/1) != clk_none
);
204 /* Return nonzero if REF is an lvalue valid for this language;
205 otherwise, print an error message and return zero. */
208 lvalue_or_else (ref
, string
)
212 int win
= lvalue_p (ref
);
214 error ("non-lvalue in %s", string
);
218 /* Build a TARGET_EXPR, initializing the DECL with the VALUE. */
221 build_target_expr (decl
, value
)
227 t
= build (TARGET_EXPR
, TREE_TYPE (decl
), decl
, value
,
228 maybe_build_cleanup (decl
), NULL_TREE
);
229 /* We always set TREE_SIDE_EFFECTS so that expand_expr does not
230 ignore the TARGET_EXPR. If there really turn out to be no
231 side-effects, then the optimizer should be able to get rid of
232 whatever code is generated anyhow. */
233 TREE_SIDE_EFFECTS (t
) = 1;
238 /* INIT is a CALL_EXPR which needs info about its target.
239 TYPE is the type that this initialization should appear to have.
241 Build an encapsulation of the initialization to perform
242 and return it so that it can be processed by language-independent
243 and language-specific expression expanders. */
246 build_cplus_new (type
, init
)
254 /* Make sure that we're not trying to create an instance of an
256 abstract_virtuals_error (NULL_TREE
, type
);
258 if (TREE_CODE (init
) != CALL_EXPR
&& TREE_CODE (init
) != AGGR_INIT_EXPR
)
259 return convert (type
, init
);
261 slot
= build (VAR_DECL
, type
);
262 DECL_ARTIFICIAL (slot
) = 1;
263 DECL_CONTEXT (slot
) = current_function_decl
;
264 layout_decl (slot
, 0);
266 /* We split the CALL_EXPR into its function and its arguments here.
267 Then, in expand_expr, we put them back together. The reason for
268 this is that this expression might be a default argument
269 expression. In that case, we need a new temporary every time the
270 expression is used. That's what break_out_target_exprs does; it
271 replaces every AGGR_INIT_EXPR with a copy that uses a fresh
272 temporary slot. Then, expand_expr builds up a call-expression
273 using the new slot. */
274 fn
= TREE_OPERAND (init
, 0);
275 rval
= build (AGGR_INIT_EXPR
, type
, fn
, TREE_OPERAND (init
, 1), slot
);
276 TREE_SIDE_EFFECTS (rval
) = 1;
277 AGGR_INIT_VIA_CTOR_P (rval
)
278 = (TREE_CODE (fn
) == ADDR_EXPR
279 && TREE_CODE (TREE_OPERAND (fn
, 0)) == FUNCTION_DECL
280 && DECL_CONSTRUCTOR_P (TREE_OPERAND (fn
, 0)));
281 rval
= build_target_expr (slot
, rval
);
286 /* Buidl a TARGET_EXPR using INIT to initialize a new temporary of the
290 build_target_expr_with_type (init
, type
)
297 slot
= build (VAR_DECL
, type
);
298 DECL_ARTIFICIAL (slot
) = 1;
299 DECL_CONTEXT (slot
) = current_function_decl
;
300 layout_decl (slot
, 0);
301 rval
= build_target_expr (slot
, init
);
306 /* Like build_target_expr_with_type, but use the type of INIT. */
309 get_target_expr (init
)
312 return build_target_expr_with_type (init
, TREE_TYPE (init
));
315 /* Recursively search EXP for CALL_EXPRs that need cleanups and replace
316 these CALL_EXPRs with tree nodes that will perform the cleanups. */
319 break_out_cleanups (exp
)
324 if (TREE_CODE (tmp
) == CALL_EXPR
325 && TYPE_NEEDS_DESTRUCTOR (TREE_TYPE (tmp
)))
326 return build_cplus_new (TREE_TYPE (tmp
), tmp
);
328 while (TREE_CODE (tmp
) == NOP_EXPR
329 || TREE_CODE (tmp
) == CONVERT_EXPR
330 || TREE_CODE (tmp
) == NON_LVALUE_EXPR
)
332 if (TREE_CODE (TREE_OPERAND (tmp
, 0)) == CALL_EXPR
333 && TYPE_NEEDS_DESTRUCTOR (TREE_TYPE (TREE_OPERAND (tmp
, 0))))
335 TREE_OPERAND (tmp
, 0)
336 = build_cplus_new (TREE_TYPE (TREE_OPERAND (tmp
, 0)),
337 TREE_OPERAND (tmp
, 0));
341 tmp
= TREE_OPERAND (tmp
, 0);
346 /* Recursively perform a preorder search EXP for CALL_EXPRs, making
347 copies where they are found. Returns a deep copy all nodes transitively
348 containing CALL_EXPRs. */
351 break_out_calls (exp
)
354 register tree t1
, t2
= NULL_TREE
;
355 register enum tree_code code
;
356 register int changed
= 0;
359 if (exp
== NULL_TREE
)
362 code
= TREE_CODE (exp
);
364 if (code
== CALL_EXPR
)
365 return copy_node (exp
);
367 /* Don't try and defeat a save_expr, as it should only be done once. */
368 if (code
== SAVE_EXPR
)
371 switch (TREE_CODE_CLASS (code
))
376 case 'c': /* a constant */
377 case 't': /* a type node */
378 case 'x': /* something random, like an identifier or an ERROR_MARK. */
381 case 'd': /* A decl node */
382 #if 0 /* This is bogus. jason 9/21/94 */
384 t1
= break_out_calls (DECL_INITIAL (exp
));
385 if (t1
!= DECL_INITIAL (exp
))
387 exp
= copy_node (exp
);
388 DECL_INITIAL (exp
) = t1
;
393 case 'b': /* A block node */
395 /* Don't know how to handle these correctly yet. Must do a
396 break_out_calls on all DECL_INITIAL values for local variables,
397 and also break_out_calls on all sub-blocks and sub-statements. */
402 case 'e': /* an expression */
403 case 'r': /* a reference */
404 case 's': /* an expression with side effects */
405 for (i
= tree_code_length
[(int) code
] - 1; i
>= 0; i
--)
407 t1
= break_out_calls (TREE_OPERAND (exp
, i
));
408 if (t1
!= TREE_OPERAND (exp
, i
))
410 exp
= copy_node (exp
);
411 TREE_OPERAND (exp
, i
) = t1
;
416 case '<': /* a comparison expression */
417 case '2': /* a binary arithmetic expression */
418 t2
= break_out_calls (TREE_OPERAND (exp
, 1));
419 if (t2
!= TREE_OPERAND (exp
, 1))
421 case '1': /* a unary arithmetic expression */
422 t1
= break_out_calls (TREE_OPERAND (exp
, 0));
423 if (t1
!= TREE_OPERAND (exp
, 0))
427 if (tree_code_length
[(int) code
] == 1)
428 return build1 (code
, TREE_TYPE (exp
), t1
);
430 return build (code
, TREE_TYPE (exp
), t1
, t2
);
437 extern struct obstack permanent_obstack
;
439 /* Here is how primitive or already-canonicalized types' hash
440 codes are made. MUST BE CONSISTENT WITH tree.c !!! */
441 #define TYPE_HASH(TYPE) ((HOST_WIDE_INT) (TYPE) & 0777777)
443 /* Construct, lay out and return the type of methods belonging to class
444 BASETYPE and whose arguments are described by ARGTYPES and whose values
445 are described by RETTYPE. If each type exists already, reuse it. */
448 build_cplus_method_type (basetype
, rettype
, argtypes
)
449 tree basetype
, rettype
, argtypes
;
455 /* Make a node of the sort we want. */
456 t
= make_node (METHOD_TYPE
);
458 TYPE_METHOD_BASETYPE (t
) = TYPE_MAIN_VARIANT (basetype
);
459 TREE_TYPE (t
) = rettype
;
460 ptype
= build_pointer_type (basetype
);
462 /* The actual arglist for this function includes a "hidden" argument
463 which is "this". Put it into the list of argument types. Make
464 sure that the new argument list is allocated on the same obstack
466 argtypes
= tree_cons (NULL_TREE
, ptype
, argtypes
);
467 TYPE_ARG_TYPES (t
) = argtypes
;
468 TREE_SIDE_EFFECTS (argtypes
) = 1; /* Mark first argtype as "artificial". */
470 /* If we already have such a type, use the old one and free this one.
471 Note that it also frees up the above cons cell if found. */
472 hashcode
= TYPE_HASH (basetype
) + TYPE_HASH (rettype
) +
473 type_hash_list (argtypes
);
475 t
= type_hash_canon (hashcode
, t
);
477 if (TYPE_SIZE (t
) == 0)
484 build_cplus_array_type_1 (elt_type
, index_type
)
490 if (elt_type
== error_mark_node
|| index_type
== error_mark_node
)
491 return error_mark_node
;
493 if (processing_template_decl
494 || uses_template_parms (elt_type
)
495 || uses_template_parms (index_type
))
497 t
= make_node (ARRAY_TYPE
);
498 TREE_TYPE (t
) = elt_type
;
499 TYPE_DOMAIN (t
) = index_type
;
502 t
= build_array_type (elt_type
, index_type
);
504 /* Push these needs up so that initialization takes place
506 TYPE_NEEDS_CONSTRUCTING (t
)
507 = TYPE_NEEDS_CONSTRUCTING (TYPE_MAIN_VARIANT (elt_type
));
508 TYPE_NEEDS_DESTRUCTOR (t
)
509 = TYPE_NEEDS_DESTRUCTOR (TYPE_MAIN_VARIANT (elt_type
));
514 build_cplus_array_type (elt_type
, index_type
)
519 int type_quals
= CP_TYPE_QUALS (elt_type
);
521 elt_type
= TYPE_MAIN_VARIANT (elt_type
);
523 t
= build_cplus_array_type_1 (elt_type
, index_type
);
525 if (type_quals
!= TYPE_UNQUALIFIED
)
526 t
= cp_build_qualified_type (t
, type_quals
);
531 /* Make a variant of TYPE, qualified with the TYPE_QUALS. Handles
532 arrays correctly. In particular, if TYPE is an array of T's, and
533 TYPE_QUALS is non-empty, returns an array of qualified T's. If
534 at attempt is made to qualify a type illegally, and COMPLAIN is
535 non-zero, an error is issued. If COMPLAIN is zero, error_mark_node
539 cp_build_qualified_type_real (type
, type_quals
, complain
)
546 if (type
== error_mark_node
)
549 if (type_quals
== TYPE_QUALS (type
))
552 /* A restrict-qualified pointer type must be a pointer (or reference)
553 to object or incomplete type. */
554 if ((type_quals
& TYPE_QUAL_RESTRICT
)
555 && TREE_CODE (type
) != TEMPLATE_TYPE_PARM
556 && (!POINTER_TYPE_P (type
)
557 || TYPE_PTRMEM_P (type
)
558 || TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
))
561 cp_error ("`%T' cannot be `restrict'-qualified", type
);
563 return error_mark_node
;
565 type_quals
&= ~TYPE_QUAL_RESTRICT
;
568 if (type_quals
!= TYPE_UNQUALIFIED
569 && TREE_CODE (type
) == FUNCTION_TYPE
)
572 cp_error ("`%T' cannot be `const'-, `volatile'-, or `restrict'-qualified", type
);
574 return error_mark_node
;
575 type_quals
= TYPE_UNQUALIFIED
;
577 else if (TREE_CODE (type
) == ARRAY_TYPE
)
579 /* In C++, the qualification really applies to the array element
580 type. Obtain the appropriately qualified element type. */
583 = cp_build_qualified_type_real (TREE_TYPE (type
),
587 if (element_type
== error_mark_node
)
588 return error_mark_node
;
590 /* See if we already have an identically qualified type. */
591 for (t
= TYPE_MAIN_VARIANT (type
); t
; t
= TYPE_NEXT_VARIANT (t
))
592 if (CP_TYPE_QUALS (t
) == type_quals
)
595 /* If we didn't already have it, create it now. */
598 /* Make a new array type, just like the old one, but with the
599 appropriately qualified element type. */
600 t
= build_type_copy (type
);
601 TREE_TYPE (t
) = element_type
;
604 /* Even if we already had this variant, we update
605 TYPE_NEEDS_CONSTRUCTING and TYPE_NEEDS_DESTRUCTOR in case
606 they changed since the variant was originally created.
608 This seems hokey; if there is some way to use a previous
609 variant *without* coming through here,
610 TYPE_NEEDS_CONSTRUCTING will never be updated. */
611 TYPE_NEEDS_CONSTRUCTING (t
)
612 = TYPE_NEEDS_CONSTRUCTING (TYPE_MAIN_VARIANT (element_type
));
613 TYPE_NEEDS_DESTRUCTOR (t
)
614 = TYPE_NEEDS_DESTRUCTOR (TYPE_MAIN_VARIANT (element_type
));
617 else if (TYPE_PTRMEMFUNC_P (type
))
619 /* For a pointer-to-member type, we can't just return a
620 cv-qualified version of the RECORD_TYPE. If we do, we
621 haven't change the field that contains the actual pointer to
622 a method, and so TYPE_PTRMEMFUNC_FN_TYPE will be wrong. */
625 t
= TYPE_PTRMEMFUNC_FN_TYPE (type
);
626 t
= cp_build_qualified_type_real (t
, type_quals
, complain
);
627 return build_ptrmemfunc_type (t
);
630 /* Retrieve (or create) the appropriately qualified variant. */
631 result
= build_qualified_type (type
, type_quals
);
633 /* If this was a pointer-to-method type, and we just made a copy,
634 then we need to clear the cached associated
635 pointer-to-member-function type; it is not valid for the new
638 && TREE_CODE (type
) == POINTER_TYPE
639 && TREE_CODE (TREE_TYPE (type
)) == METHOD_TYPE
)
640 TYPE_SET_PTRMEMFUNC_TYPE (result
, NULL_TREE
);
645 /* Returns the canonical version of TYPE. In other words, if TYPE is
646 a typedef, returns the underlying type. The cv-qualification of
647 the type returned matches the type input; they will always be
651 canonical_type_variant (t
)
654 return cp_build_qualified_type (TYPE_MAIN_VARIANT (t
), CP_TYPE_QUALS (t
));
657 /* Makes new binfos for the indirect bases under BINFO, and updates
658 BINFO_OFFSET for them and their bases. */
661 unshare_base_binfos (binfo
)
664 tree binfos
= BINFO_BASETYPES (binfo
);
668 if (binfos
== NULL_TREE
)
671 /* Now unshare the structure beneath BINFO. */
672 for (j
= TREE_VEC_LENGTH (binfos
)-1;
675 tree base_binfo
= TREE_VEC_ELT (binfos
, j
);
676 new_binfo
= TREE_VEC_ELT (binfos
, j
)
677 = make_binfo (BINFO_OFFSET (base_binfo
),
679 BINFO_VTABLE (base_binfo
),
680 BINFO_VIRTUALS (base_binfo
));
681 TREE_VIA_PUBLIC (new_binfo
) = TREE_VIA_PUBLIC (base_binfo
);
682 TREE_VIA_PROTECTED (new_binfo
) = TREE_VIA_PROTECTED (base_binfo
);
683 TREE_VIA_VIRTUAL (new_binfo
) = TREE_VIA_VIRTUAL (base_binfo
);
684 BINFO_INHERITANCE_CHAIN (new_binfo
) = binfo
;
685 unshare_base_binfos (new_binfo
);
690 /* Hashing of lists so that we don't make duplicates.
691 The entry point is `list_hash_canon'. */
693 /* Each hash table slot is a bucket containing a chain
694 of these structures. */
698 struct list_hash
*next
; /* Next structure in the bucket. */
699 int hashcode
; /* Hash code of this list. */
700 tree list
; /* The list recorded here. */
703 /* Now here is the hash table. When recording a list, it is added
704 to the slot whose index is the hash code mod the table size.
705 Note that the hash table is used for several kinds of lists.
706 While all these live in the same table, they are completely independent,
707 and the hash code is computed differently for each of these. */
709 #define TYPE_HASH_SIZE 59
710 static struct list_hash
*list_hash_table
[TYPE_HASH_SIZE
];
712 /* Compute a hash code for a list (chain of TREE_LIST nodes
713 with goodies in the TREE_PURPOSE, TREE_VALUE, and bits of the
714 TREE_COMMON slots), by adding the hash codes of the individual entries. */
717 list_hash (purpose
, value
, chain
)
718 tree purpose
, value
, chain
;
720 register int hashcode
= 0;
723 hashcode
+= TYPE_HASH (chain
);
726 hashcode
+= TYPE_HASH (value
);
730 hashcode
+= TYPE_HASH (purpose
);
736 /* Look in the type hash table for a type isomorphic to TYPE.
737 If one is found, return it. Otherwise return 0. */
740 list_hash_lookup (hashcode
, purpose
, value
, chain
)
742 tree purpose
, value
, chain
;
744 register struct list_hash
*h
;
746 for (h
= list_hash_table
[hashcode
% TYPE_HASH_SIZE
]; h
; h
= h
->next
)
747 if (h
->hashcode
== hashcode
748 && TREE_PURPOSE (h
->list
) == purpose
749 && TREE_VALUE (h
->list
) == value
750 && TREE_CHAIN (h
->list
) == chain
)
755 /* Add an entry to the list-hash-table
756 for a list TYPE whose hash code is HASHCODE. */
759 list_hash_add (hashcode
, list
)
763 register struct list_hash
*h
;
765 h
= (struct list_hash
*) obstack_alloc (&permanent_obstack
, sizeof (struct list_hash
));
766 h
->hashcode
= hashcode
;
768 h
->next
= list_hash_table
[hashcode
% TYPE_HASH_SIZE
];
769 list_hash_table
[hashcode
% TYPE_HASH_SIZE
] = h
;
772 /* Given list components PURPOSE, VALUE, AND CHAIN, return the canonical
773 object for an identical list if one already exists. Otherwise, build a
774 new one, and record it as the canonical object. */
776 /* Set to 1 to debug without canonicalization. Never set by program. */
778 static int debug_no_list_hash
= 0;
781 hash_tree_cons (purpose
, value
, chain
)
782 tree purpose
, value
, chain
;
787 if (! debug_no_list_hash
)
789 hashcode
= list_hash (purpose
, value
, chain
);
790 t
= list_hash_lookup (hashcode
, purpose
, value
, chain
);
795 t
= tree_cons (purpose
, value
, chain
);
797 /* If this is a new list, record it for later reuse. */
798 if (! debug_no_list_hash
)
799 list_hash_add (hashcode
, t
);
804 /* Constructor for hashed lists. */
807 hash_tree_chain (value
, chain
)
810 return hash_tree_cons (NULL_TREE
, value
, chain
);
813 /* Similar, but used for concatenating two lists. */
816 hash_chainon (list1
, list2
)
823 if (TREE_CHAIN (list1
) == NULL_TREE
)
824 return hash_tree_chain (TREE_VALUE (list1
), list2
);
825 return hash_tree_chain (TREE_VALUE (list1
),
826 hash_chainon (TREE_CHAIN (list1
), list2
));
829 /* Build an association between TYPE and some parameters:
831 OFFSET is the offset added to `this' to convert it to a pointer
834 BINFO is the base binfo to use, if we are deriving from one. This
835 is necessary, as we want specialized parent binfos from base
836 classes, so that the VTABLE_NAMEs of bases are for the most derived
837 type, instead of the simple type.
839 VTABLE is the virtual function table with which to initialize
840 sub-objects of type TYPE.
842 VIRTUALS are the virtual functions sitting in VTABLE. */
845 make_binfo (offset
, binfo
, vtable
, virtuals
)
847 tree vtable
, virtuals
;
849 tree new_binfo
= make_tree_vec (8);
852 if (TREE_CODE (binfo
) == TREE_VEC
)
853 type
= BINFO_TYPE (binfo
);
857 binfo
= CLASS_TYPE_P (type
) ? TYPE_BINFO (binfo
) : NULL_TREE
;
860 TREE_TYPE (new_binfo
) = TYPE_MAIN_VARIANT (type
);
861 BINFO_OFFSET (new_binfo
) = offset
;
862 BINFO_VTABLE (new_binfo
) = vtable
;
863 BINFO_VIRTUALS (new_binfo
) = virtuals
;
865 if (binfo
&& BINFO_BASETYPES (binfo
) != NULL_TREE
)
866 BINFO_BASETYPES (new_binfo
) = copy_node (BINFO_BASETYPES (binfo
));
870 /* Return the binfo value for ELEM in TYPE. */
873 binfo_value (elem
, type
)
877 if (get_base_distance (elem
, type
, 0, (tree
*)0) == -2)
878 compiler_error ("base class `%s' ambiguous in binfo_value",
879 TYPE_NAME_STRING (elem
));
881 return TYPE_BINFO (type
);
882 if (TREE_CODE (elem
) == RECORD_TYPE
&& TYPE_BINFO (elem
) == type
)
884 return get_binfo (elem
, type
, 0);
887 /* Return a TREE_LIST whose TREE_VALUE nodes along the
888 BINFO_INHERITANCE_CHAIN for BINFO, but in the opposite order. In
889 other words, while the BINFO_INHERITANCE_CHAIN goes from base
890 classes to derived classes, the reversed path goes from derived
891 classes to base classes. */
899 reversed_path
= NULL_TREE
;
902 reversed_path
= tree_cons (NULL_TREE
, binfo
, reversed_path
);
903 binfo
= BINFO_INHERITANCE_CHAIN (binfo
);
906 return reversed_path
;
916 fprintf (stderr
, "type \"%s\", offset = ",
917 TYPE_NAME_STRING (BINFO_TYPE (elem
)));
918 fprintf (stderr
, HOST_WIDE_INT_PRINT_DEC
,
919 TREE_INT_CST_LOW (BINFO_OFFSET (elem
)));
920 fprintf (stderr
, "\nvtable type:\n");
921 debug_tree (BINFO_TYPE (elem
));
922 if (BINFO_VTABLE (elem
))
923 fprintf (stderr
, "vtable decl \"%s\"\n",
924 IDENTIFIER_POINTER (DECL_NAME (BINFO_VTABLE (elem
))));
926 fprintf (stderr
, "no vtable decl yet\n");
927 fprintf (stderr
, "virtuals:\n");
928 virtuals
= skip_rtti_stuff (elem
, BINFO_TYPE (elem
), &n
);
932 tree fndecl
= TREE_VALUE (virtuals
);
933 fprintf (stderr
, "%s [%ld =? %ld]\n",
934 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (fndecl
)),
935 (long) n
, (long) TREE_INT_CST_LOW (DECL_VINDEX (fndecl
)));
937 virtuals
= TREE_CHAIN (virtuals
);
946 if (TREE_CODE (t
) == FUNCTION_DECL
)
948 else if (TREE_CODE (t
) == OVERLOAD
)
950 for (i
=0; t
; t
= OVL_CHAIN (t
))
955 my_friendly_abort (359);
963 /* A baselink is also considered an overloaded function. */
964 if (TREE_CODE (x
) == OFFSET_REF
)
965 x
= TREE_OPERAND (x
, 1);
968 return (TREE_CODE (x
) == FUNCTION_DECL
969 || TREE_CODE (x
) == TEMPLATE_ID_EXPR
970 || DECL_FUNCTION_TEMPLATE_P (x
)
971 || TREE_CODE (x
) == OVERLOAD
);
975 really_overloaded_fn (x
)
978 /* A baselink is also considered an overloaded function. */
979 if (TREE_CODE (x
) == OFFSET_REF
)
980 x
= TREE_OPERAND (x
, 1);
983 return (TREE_CODE (x
) == OVERLOAD
984 && (TREE_CHAIN (x
) != NULL_TREE
985 || DECL_FUNCTION_TEMPLATE_P (OVL_FUNCTION (x
))));
992 my_friendly_assert (is_overloaded_fn (from
), 9);
993 /* A baselink is also considered an overloaded function. */
994 if (BASELINK_P (from
))
995 from
= TREE_VALUE (from
);
996 return OVL_CURRENT (from
);
999 /* Returns nonzero if T is a ->* or .* expression that refers to a
1006 return (TREE_CODE (t
) == OFFSET_REF
1007 && TYPE_PTRMEMFUNC_P (TREE_TYPE (TREE_OPERAND (t
, 1))));
1010 /* Return a new OVL node, concatenating it with the old one. */
1013 ovl_cons (decl
, chain
)
1017 tree result
= make_node (OVERLOAD
);
1018 TREE_TYPE (result
) = unknown_type_node
;
1019 OVL_FUNCTION (result
) = decl
;
1020 TREE_CHAIN (result
) = chain
;
1025 /* Build a new overloaded function. If this is the first one,
1026 just return it; otherwise, ovl_cons the _DECLs */
1029 build_overload (decl
, chain
)
1033 if (! chain
&& TREE_CODE (decl
) != TEMPLATE_DECL
)
1035 if (chain
&& TREE_CODE (chain
) != OVERLOAD
)
1036 chain
= ovl_cons (chain
, NULL_TREE
);
1037 return ovl_cons (decl
, chain
);
1040 /* True if fn is in ovl. */
1043 ovl_member (fn
, ovl
)
1047 if (ovl
== NULL_TREE
)
1049 if (TREE_CODE (ovl
) != OVERLOAD
)
1051 for (; ovl
; ovl
= OVL_CHAIN (ovl
))
1052 if (OVL_FUNCTION (ovl
) == fn
)
1058 is_aggr_type_2 (t1
, t2
)
1061 if (TREE_CODE (t1
) != TREE_CODE (t2
))
1063 return IS_AGGR_TYPE (t1
) && IS_AGGR_TYPE (t2
);
1066 /* Returns non-zero if CODE is the code for a statement. */
1069 statement_code_p (code
)
1070 enum tree_code code
;
1090 case START_CATCH_STMT
:
1093 case CTOR_INITIALIZER
:
1105 #define PRINT_RING_SIZE 4
1108 lang_printable_name (decl
, v
)
1112 static tree decl_ring
[PRINT_RING_SIZE
];
1113 static char *print_ring
[PRINT_RING_SIZE
];
1114 static int ring_counter
;
1117 /* Only cache functions. */
1119 || TREE_CODE (decl
) != FUNCTION_DECL
1120 || DECL_LANG_SPECIFIC (decl
) == 0)
1121 return lang_decl_name (decl
, v
);
1123 /* See if this print name is lying around. */
1124 for (i
= 0; i
< PRINT_RING_SIZE
; i
++)
1125 if (decl_ring
[i
] == decl
)
1126 /* yes, so return it. */
1127 return print_ring
[i
];
1129 if (++ring_counter
== PRINT_RING_SIZE
)
1132 if (current_function_decl
!= NULL_TREE
)
1134 if (decl_ring
[ring_counter
] == current_function_decl
)
1136 if (ring_counter
== PRINT_RING_SIZE
)
1138 if (decl_ring
[ring_counter
] == current_function_decl
)
1139 my_friendly_abort (106);
1142 if (print_ring
[ring_counter
])
1143 free (print_ring
[ring_counter
]);
1145 print_ring
[ring_counter
] = xstrdup (lang_decl_name (decl
, v
));
1146 decl_ring
[ring_counter
] = decl
;
1147 return print_ring
[ring_counter
];
1150 /* Build the FUNCTION_TYPE or METHOD_TYPE which may throw exceptions
1151 listed in RAISES. */
1154 build_exception_variant (type
, raises
)
1158 tree v
= TYPE_MAIN_VARIANT (type
);
1159 int type_quals
= TYPE_QUALS (type
);
1161 for (; v
; v
= TYPE_NEXT_VARIANT (v
))
1162 if (TYPE_QUALS (v
) == type_quals
1163 && comp_except_specs (raises
, TYPE_RAISES_EXCEPTIONS (v
), 1))
1166 /* Need to build a new variant. */
1167 v
= build_type_copy (type
);
1168 TYPE_RAISES_EXCEPTIONS (v
) = raises
;
1172 /* Given a TEMPLATE_TEMPLATE_PARM node T, create a new one together with its
1173 lang_specific field and its corresponding TEMPLATE_DECL node */
1176 copy_template_template_parm (t
)
1179 tree
template = TYPE_NAME (t
);
1182 t2
= make_aggr_type (TEMPLATE_TEMPLATE_PARM
);
1183 template = copy_node (template);
1184 copy_lang_decl (template);
1186 TREE_TYPE (template) = t2
;
1187 TYPE_NAME (t2
) = template;
1188 TYPE_STUB_DECL (t2
) = template;
1190 /* No need to copy these */
1191 TYPE_FIELDS (t2
) = TYPE_FIELDS (t
);
1192 TEMPLATE_TEMPLATE_PARM_TEMPLATE_INFO (t2
)
1193 = TEMPLATE_TEMPLATE_PARM_TEMPLATE_INFO (t
);
1197 /* Apply FUNC to all the sub-trees of TP in a pre-order traversal.
1198 FUNC is called with the DATA and the address of each sub-tree. If
1199 FUNC returns a non-NULL value, the traversal is aborted, and the
1200 value returned by FUNC is returned. */
1203 walk_tree (tp
, func
, data
)
1208 enum tree_code code
;
1212 #define WALK_SUBTREE(NODE) \
1215 result = walk_tree (&(NODE), func, data); \
1221 /* Skip empty subtrees. */
1225 /* Call the function. */
1227 result
= (*func
) (tp
, &walk_subtrees
, data
);
1229 /* If we found something, return it. */
1233 /* Even if we didn't, FUNC may have decided that there was nothing
1234 interesting below this point in the tree. */
1238 code
= TREE_CODE (*tp
);
1240 /* Handle common cases up front. */
1241 if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (code
))
1242 || TREE_CODE_CLASS (code
) == 'r'
1243 || TREE_CODE_CLASS (code
) == 's')
1247 /* Walk over all the sub-trees of this operand. */
1248 len
= first_rtl_op (code
);
1249 /* TARGET_EXPRs are peculiar: operands 1 and 3 can be the same.
1250 But, we only want to walk once. */
1251 if (code
== TARGET_EXPR
1252 && TREE_OPERAND (*tp
, 3) == TREE_OPERAND (*tp
, 1))
1254 /* Go through the subtrees. We need to do this in forward order so
1255 that the scope of a FOR_EXPR is handled properly. */
1256 for (i
= 0; i
< len
; ++i
)
1257 WALK_SUBTREE (TREE_OPERAND (*tp
, i
));
1259 /* For statements, we also walk the chain so that we cover the
1260 entire statement tree. */
1261 if (statement_code_p (code
))
1263 if (code
== DECL_STMT
1264 && DECL_STMT_DECL (*tp
)
1265 && TREE_CODE_CLASS (TREE_CODE (DECL_STMT_DECL (*tp
))) == 'd')
1267 /* Walk the DECL_INITIAL and DECL_SIZE. We don't want to walk
1268 into declarations that are just mentioned, rather than
1269 declared; they don't really belong to this part of the tree.
1270 And, we can see cycles: the initializer for a declaration can
1271 refer to the declaration itself. */
1272 WALK_SUBTREE (DECL_INITIAL (DECL_STMT_DECL (*tp
)));
1273 WALK_SUBTREE (DECL_SIZE (DECL_STMT_DECL (*tp
)));
1274 WALK_SUBTREE (DECL_SIZE_UNIT (DECL_STMT_DECL (*tp
)));
1277 WALK_SUBTREE (TREE_CHAIN (*tp
));
1280 /* We didn't find what we were looking for. */
1283 else if (TREE_CODE_CLASS (code
) == 'd')
1285 WALK_SUBTREE (TREE_TYPE (*tp
));
1287 /* We didn't find what we were looking for. */
1291 /* Not one of the easy cases. We must explicitly go through the
1296 case IDENTIFIER_NODE
:
1301 case TEMPLATE_TEMPLATE_PARM
:
1302 case TEMPLATE_PARM_INDEX
:
1303 case TEMPLATE_TYPE_PARM
:
1313 /* None of thse have subtrees other than those already walked
1318 WALK_SUBTREE (TREE_TYPE (*tp
));
1322 case REFERENCE_TYPE
:
1323 WALK_SUBTREE (TREE_TYPE (*tp
));
1327 WALK_SUBTREE (TREE_PURPOSE (*tp
));
1328 WALK_SUBTREE (TREE_VALUE (*tp
));
1329 WALK_SUBTREE (TREE_CHAIN (*tp
));
1333 WALK_SUBTREE (OVL_FUNCTION (*tp
));
1334 WALK_SUBTREE (OVL_CHAIN (*tp
));
1339 int len
= TREE_VEC_LENGTH (*tp
);
1341 WALK_SUBTREE (TREE_VEC_ELT (*tp
, len
));
1346 WALK_SUBTREE (TREE_REALPART (*tp
));
1347 WALK_SUBTREE (TREE_IMAGPART (*tp
));
1351 WALK_SUBTREE (CONSTRUCTOR_ELTS (*tp
));
1355 WALK_SUBTREE (TYPE_METHOD_BASETYPE (*tp
));
1359 WALK_SUBTREE (TREE_TYPE (*tp
));
1360 WALK_SUBTREE (TYPE_ARG_TYPES (*tp
));
1364 WALK_SUBTREE (TREE_TYPE (*tp
));
1365 WALK_SUBTREE (TYPE_DOMAIN (*tp
));
1369 WALK_SUBTREE (TYPE_MIN_VALUE (*tp
));
1370 WALK_SUBTREE (TYPE_MAX_VALUE (*tp
));
1374 WALK_SUBTREE (TREE_TYPE (*tp
));
1375 WALK_SUBTREE (TYPE_OFFSET_BASETYPE (*tp
));
1379 if (TYPE_PTRMEMFUNC_P (*tp
))
1380 WALK_SUBTREE (TYPE_PTRMEMFUNC_FN_TYPE (*tp
));
1384 my_friendly_abort (19990803);
1387 /* We didn't find what we were looking for. */
1393 /* Passed to walk_tree. Checks for the use of types with no linkage. */
1396 no_linkage_helper (tp
, walk_subtrees
, data
)
1398 int *walk_subtrees ATTRIBUTE_UNUSED
;
1399 void *data ATTRIBUTE_UNUSED
;
1404 && (IS_AGGR_TYPE (t
) || TREE_CODE (t
) == ENUMERAL_TYPE
)
1405 && (decl_function_context (TYPE_MAIN_DECL (t
))
1406 || ANON_AGGRNAME_P (TYPE_IDENTIFIER (t
))))
1411 /* Check if the type T depends on a type with no linkage and if so, return
1415 no_linkage_check (t
)
1418 /* There's no point in checking linkage on template functions; we
1419 can't know their complete types. */
1420 if (processing_template_decl
)
1423 t
= walk_tree (&t
, no_linkage_helper
, NULL
);
1424 if (t
!= error_mark_node
)
1429 /* Passed to walk_tree. Copies the node pointed to, if appropriate. */
1432 copy_tree_r (tp
, walk_subtrees
, data
)
1435 void *data ATTRIBUTE_UNUSED
;
1437 enum tree_code code
= TREE_CODE (*tp
);
1439 /* We make copies of most nodes. */
1440 if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (code
))
1441 || TREE_CODE_CLASS (code
) == 'r'
1442 || TREE_CODE_CLASS (code
) == 'c'
1443 || TREE_CODE_CLASS (code
) == 's'
1444 || code
== PARM_DECL
1445 || code
== TREE_LIST
1447 || code
== OVERLOAD
)
1449 /* Because the chain gets clobbered when we make a copy, we save it
1451 tree chain
= TREE_CHAIN (*tp
);
1453 /* Copy the node. */
1454 *tp
= copy_node (*tp
);
1456 /* Now, restore the chain, if appropriate. That will cause
1457 walk_tree to walk into the chain as well. */
1458 if (code
== PARM_DECL
|| code
== TREE_LIST
|| code
== OVERLOAD
1459 || statement_code_p (code
))
1460 TREE_CHAIN (*tp
) = chain
;
1462 /* For now, we don't update BLOCKs when we make copies. So, we
1463 have to nullify all scope-statements. */
1464 if (TREE_CODE (*tp
) == SCOPE_STMT
)
1465 SCOPE_STMT_BLOCK (*tp
) = NULL_TREE
;
1467 else if (code
== TEMPLATE_TEMPLATE_PARM
)
1468 /* These must be copied specially. */
1469 *tp
= copy_template_template_parm (*tp
);
1470 else if (TREE_CODE_CLASS (code
) == 't')
1471 /* There's no need to copy types, or anything beneath them. */
1477 #ifdef GATHER_STATISTICS
1478 extern int depth_reached
;
1482 print_lang_statistics ()
1484 print_search_statistics ();
1485 print_class_statistics ();
1486 #ifdef GATHER_STATISTICS
1487 fprintf (stderr
, "maximum template instantiation depth reached: %d\n",
1492 /* Return, as an INTEGER_CST node, the number of elements for TYPE
1493 (which is an ARRAY_TYPE). This counts only elements of the top
1497 array_type_nelts_top (type
)
1500 return fold (build (PLUS_EXPR
, sizetype
,
1501 array_type_nelts (type
),
1505 /* Return, as an INTEGER_CST node, the number of elements for TYPE
1506 (which is an ARRAY_TYPE). This one is a recursive count of all
1507 ARRAY_TYPEs that are clumped together. */
1510 array_type_nelts_total (type
)
1513 tree sz
= array_type_nelts_top (type
);
1514 type
= TREE_TYPE (type
);
1515 while (TREE_CODE (type
) == ARRAY_TYPE
)
1517 tree n
= array_type_nelts_top (type
);
1518 sz
= fold (build (MULT_EXPR
, sizetype
, sz
, n
));
1519 type
= TREE_TYPE (type
);
1524 /* Called from break_out_target_exprs via mapcar. */
1527 bot_manip (tp
, walk_subtrees
, data
)
1532 splay_tree target_remap
= ((splay_tree
) data
);
1535 if (TREE_CODE (t
) != TREE_LIST
&& ! TREE_SIDE_EFFECTS (t
))
1537 /* There can't be any TARGET_EXPRs below this point. */
1541 else if (TREE_CODE (t
) == TARGET_EXPR
)
1545 if (TREE_CODE (TREE_OPERAND (t
, 1)) == AGGR_INIT_EXPR
)
1547 mark_used (TREE_OPERAND (TREE_OPERAND (TREE_OPERAND (t
, 1), 0), 0));
1549 (TREE_TYPE (t
), break_out_target_exprs (TREE_OPERAND (t
, 1)));
1556 var
= build (VAR_DECL
, TREE_TYPE (t
));
1557 DECL_CONTEXT (var
) = current_function_decl
;
1558 layout_decl (var
, 0);
1559 TREE_OPERAND (u
, 0) = var
;
1562 /* Map the old variable to the new one. */
1563 splay_tree_insert (target_remap
,
1564 (splay_tree_key
) TREE_OPERAND (t
, 0),
1565 (splay_tree_value
) TREE_OPERAND (u
, 0));
1567 /* Replace the old expression with the new version. */
1569 /* We don't have to go below this point; the recursive call to
1570 break_out_target_exprs will have handled anything below this
1575 else if (TREE_CODE (t
) == CALL_EXPR
)
1576 mark_used (TREE_OPERAND (TREE_OPERAND (t
, 0), 0));
1578 /* Make a copy of this node. */
1579 return copy_tree_r (tp
, walk_subtrees
, NULL
);
1582 /* Replace all remapped VAR_DECLs in T with their new equivalents.
1583 DATA is really a splay-tree mapping old variables to new
1587 bot_replace (t
, walk_subtrees
, data
)
1589 int *walk_subtrees ATTRIBUTE_UNUSED
;
1592 splay_tree target_remap
= ((splay_tree
) data
);
1594 if (TREE_CODE (*t
) == VAR_DECL
)
1596 splay_tree_node n
= splay_tree_lookup (target_remap
,
1597 (splay_tree_key
) *t
);
1599 *t
= (tree
) n
->value
;
1605 /* When we parse a default argument expression, we may create
1606 temporary variables via TARGET_EXPRs. When we actually use the
1607 default-argument expression, we make a copy of the expression, but
1608 we must replace the temporaries with appropriate local versions. */
1611 break_out_target_exprs (t
)
1614 static int target_remap_count
;
1615 static splay_tree target_remap
;
1617 if (!target_remap_count
++)
1618 target_remap
= splay_tree_new (splay_tree_compare_pointers
,
1619 /*splay_tree_delete_key_fn=*/NULL
,
1620 /*splay_tree_delete_value_fn=*/NULL
);
1621 walk_tree (&t
, bot_manip
, target_remap
);
1622 walk_tree (&t
, bot_replace
, target_remap
);
1624 if (!--target_remap_count
)
1626 splay_tree_delete (target_remap
);
1627 target_remap
= NULL
;
1633 /* Obstack used for allocating nodes in template function and variable
1636 /* Similar to `build_nt', except that we set TREE_COMPLEXITY to be the
1637 current line number. */
1640 build_min_nt
VPARAMS ((enum tree_code code
, ...))
1642 #ifndef ANSI_PROTOTYPES
1643 enum tree_code code
;
1647 register int length
;
1652 #ifndef ANSI_PROTOTYPES
1653 code
= va_arg (p
, enum tree_code
);
1656 t
= make_node (code
);
1657 length
= tree_code_length
[(int) code
];
1658 TREE_COMPLEXITY (t
) = lineno
;
1660 for (i
= 0; i
< length
; i
++)
1662 tree x
= va_arg (p
, tree
);
1663 TREE_OPERAND (t
, i
) = x
;
1670 /* Similar to `build', except we set TREE_COMPLEXITY to the current
1674 build_min
VPARAMS ((enum tree_code code
, tree tt
, ...))
1676 #ifndef ANSI_PROTOTYPES
1677 enum tree_code code
;
1682 register int length
;
1687 #ifndef ANSI_PROTOTYPES
1688 code
= va_arg (p
, enum tree_code
);
1689 tt
= va_arg (p
, tree
);
1692 t
= make_node (code
);
1693 length
= tree_code_length
[(int) code
];
1695 TREE_COMPLEXITY (t
) = lineno
;
1697 for (i
= 0; i
< length
; i
++)
1699 tree x
= va_arg (p
, tree
);
1700 TREE_OPERAND (t
, i
) = x
;
1707 /* Returns an INTEGER_CST (of type `int') corresponding to I.
1708 Multiple calls with the same value of I may or may not yield the
1709 same node; therefore, callers should never modify the node
1713 build_shared_int_cst (i
)
1716 static tree cache
[256];
1719 return build_int_2 (i
, 0);
1722 cache
[i
] = build_int_2 (i
, 0);
1731 if (TREE_CODE (t
) == TYPE_DECL
)
1733 if (TREE_CODE_CLASS (TREE_CODE (t
)) == 't')
1734 return TYPE_STUB_DECL (t
);
1736 my_friendly_abort (42);
1738 /* Stop compiler from complaining control reaches end of non-void function. */
1743 can_free (obstack
, t
)
1744 struct obstack
*obstack
;
1749 if (TREE_CODE (t
) == TREE_VEC
)
1750 size
= (TREE_VEC_LENGTH (t
)-1) * sizeof (tree
) + sizeof (struct tree_vec
);
1752 my_friendly_abort (42);
1754 #define ROUND(x) ((x + obstack_alignment_mask (obstack)) \
1755 & ~ obstack_alignment_mask (obstack))
1756 if ((char *)t
+ ROUND (size
) == obstack_next_free (obstack
))
1763 /* Return first vector element whose BINFO_TYPE is ELEM.
1764 Return 0 if ELEM is not in VEC. VEC may be NULL_TREE. */
1767 vec_binfo_member (elem
, vec
)
1773 for (i
= 0; i
< TREE_VEC_LENGTH (vec
); ++i
)
1774 if (same_type_p (elem
, BINFO_TYPE (TREE_VEC_ELT (vec
, i
))))
1775 return TREE_VEC_ELT (vec
, i
);
1780 /* Returns the namespace that contains DECL, whether directly or
1784 decl_namespace_context (decl
)
1789 if (TREE_CODE (decl
) == NAMESPACE_DECL
)
1791 else if (TYPE_P (decl
))
1792 decl
= CP_DECL_CONTEXT (TYPE_MAIN_DECL (decl
));
1794 decl
= CP_DECL_CONTEXT (decl
);
1798 /* Return truthvalue of whether T1 is the same tree structure as T2.
1799 Return 1 if they are the same.
1800 Return 0 if they are understandably different.
1801 Return -1 if either contains tree structure not understood by
1805 cp_tree_equal (t1
, t2
)
1808 register enum tree_code code1
, code2
;
1813 if (t1
== 0 || t2
== 0)
1816 code1
= TREE_CODE (t1
);
1817 code2
= TREE_CODE (t2
);
1819 if (code1
== NOP_EXPR
|| code1
== CONVERT_EXPR
|| code1
== NON_LVALUE_EXPR
)
1821 if (code2
== NOP_EXPR
|| code2
== CONVERT_EXPR
|| code2
== NON_LVALUE_EXPR
)
1822 return cp_tree_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
1824 return cp_tree_equal (TREE_OPERAND (t1
, 0), t2
);
1826 else if (code2
== NOP_EXPR
|| code2
== CONVERT_EXPR
1827 || code2
== NON_LVALUE_EXPR
)
1828 return cp_tree_equal (t1
, TREE_OPERAND (t2
, 0));
1836 return TREE_INT_CST_LOW (t1
) == TREE_INT_CST_LOW (t2
)
1837 && TREE_INT_CST_HIGH (t1
) == TREE_INT_CST_HIGH (t2
);
1840 return REAL_VALUES_EQUAL (TREE_REAL_CST (t1
), TREE_REAL_CST (t2
));
1843 return TREE_STRING_LENGTH (t1
) == TREE_STRING_LENGTH (t2
)
1844 && !bcmp (TREE_STRING_POINTER (t1
), TREE_STRING_POINTER (t2
),
1845 TREE_STRING_LENGTH (t1
));
1848 /* We need to do this when determining whether or not two
1849 non-type pointer to member function template arguments
1851 if (!(same_type_p (TREE_TYPE (t1
), TREE_TYPE (t2
))
1852 /* The first operand is RTL. */
1853 && TREE_OPERAND (t1
, 0) == TREE_OPERAND (t2
, 0)))
1855 return cp_tree_equal (TREE_OPERAND (t1
, 1), TREE_OPERAND (t2
, 1));
1858 cmp
= cp_tree_equal (TREE_PURPOSE (t1
), TREE_PURPOSE (t2
));
1861 cmp
= cp_tree_equal (TREE_VALUE (t1
), TREE_VALUE (t2
));
1864 return cp_tree_equal (TREE_CHAIN (t1
), TREE_CHAIN (t2
));
1867 return cp_tree_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
1870 cmp
= cp_tree_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
1873 return simple_cst_list_equal (TREE_OPERAND (t1
, 1), TREE_OPERAND (t2
, 1));
1876 /* Special case: if either target is an unallocated VAR_DECL,
1877 it means that it's going to be unified with whatever the
1878 TARGET_EXPR is really supposed to initialize, so treat it
1879 as being equivalent to anything. */
1880 if ((TREE_CODE (TREE_OPERAND (t1
, 0)) == VAR_DECL
1881 && DECL_NAME (TREE_OPERAND (t1
, 0)) == NULL_TREE
1882 && DECL_RTL (TREE_OPERAND (t1
, 0)) == 0)
1883 || (TREE_CODE (TREE_OPERAND (t2
, 0)) == VAR_DECL
1884 && DECL_NAME (TREE_OPERAND (t2
, 0)) == NULL_TREE
1885 && DECL_RTL (TREE_OPERAND (t2
, 0)) == 0))
1888 cmp
= cp_tree_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
1891 return cp_tree_equal (TREE_OPERAND (t1
, 1), TREE_OPERAND (t2
, 1));
1893 case WITH_CLEANUP_EXPR
:
1894 cmp
= cp_tree_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
1897 return cp_tree_equal (TREE_OPERAND (t1
, 2), TREE_OPERAND (t1
, 2));
1900 if (TREE_OPERAND (t1
, 1) == TREE_OPERAND (t2
, 1))
1901 return cp_tree_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
1910 case TEMPLATE_PARM_INDEX
:
1911 return TEMPLATE_PARM_IDX (t1
) == TEMPLATE_PARM_IDX (t2
)
1912 && TEMPLATE_PARM_LEVEL (t1
) == TEMPLATE_PARM_LEVEL (t2
);
1916 if (TREE_CODE (TREE_OPERAND (t1
, 0)) != TREE_CODE (TREE_OPERAND (t2
, 0)))
1918 if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (t1
, 0))) == 't')
1919 return same_type_p (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
1923 /* Two pointer-to-members are the same if they point to the same
1924 field or function in the same class. */
1925 return (PTRMEM_CST_MEMBER (t1
) == PTRMEM_CST_MEMBER (t2
)
1926 && same_type_p (PTRMEM_CST_CLASS (t1
), PTRMEM_CST_CLASS (t2
)));
1932 switch (TREE_CODE_CLASS (code1
))
1942 for (i
=0; i
<tree_code_length
[(int) code1
]; ++i
)
1944 cmp
= cp_tree_equal (TREE_OPERAND (t1
, i
), TREE_OPERAND (t2
, i
));
1954 /* Build a wrapper around some pointer PTR so we can use it as a tree. */
1957 build_ptr_wrapper (ptr
)
1960 tree t
= make_node (WRAPPER
);
1961 WRAPPER_PTR (t
) = ptr
;
1965 /* Same, but on the expression_obstack. */
1968 build_expr_ptr_wrapper (ptr
)
1971 return build_ptr_wrapper (ptr
);
1974 /* Build a wrapper around some integer I so we can use it as a tree. */
1977 build_int_wrapper (i
)
1980 tree t
= make_node (WRAPPER
);
1981 WRAPPER_INT (t
) = i
;
1986 build_srcloc (file
, line
)
1992 t
= make_node (SRCLOC
);
1993 SRCLOC_FILE (t
) = file
;
1994 SRCLOC_LINE (t
) = line
;
2000 build_srcloc_here ()
2002 return build_srcloc (input_filename
, lineno
);
2005 /* The type of ARG when used as an lvalue. */
2011 tree type
= TREE_TYPE (arg
);
2012 if (TREE_CODE (arg
) == OVERLOAD
)
2013 type
= unknown_type_node
;
2017 /* The type of ARG for printing error messages; denote lvalues with
2024 tree type
= TREE_TYPE (arg
);
2025 if (TREE_CODE (type
) == ARRAY_TYPE
)
2027 else if (real_lvalue_p (arg
))
2028 type
= build_reference_type (lvalue_type (arg
));
2029 else if (IS_AGGR_TYPE (type
))
2030 type
= lvalue_type (arg
);
2035 /* Does FUNCTION use a variable-length argument list? */
2038 varargs_function_p (function
)
2041 tree parm
= TYPE_ARG_TYPES (TREE_TYPE (function
));
2042 for (; parm
; parm
= TREE_CHAIN (parm
))
2043 if (TREE_VALUE (parm
) == void_type_node
)
2048 /* Returns 1 if decl is a member of a class. */
2054 tree ctx
= DECL_CONTEXT (decl
);
2055 return (ctx
&& TREE_CODE_CLASS (TREE_CODE (ctx
)) == 't');
2058 /* Create a placeholder for member access where we don't actually have an
2059 object that the access is against. */
2062 build_dummy_object (type
)
2065 tree decl
= build1 (NOP_EXPR
, build_pointer_type (type
), void_zero_node
);
2066 return build_indirect_ref (decl
, NULL_PTR
);
2069 /* We've gotten a reference to a member of TYPE. Return *this if appropriate,
2070 or a dummy object otherwise. If BINFOP is non-0, it is filled with the
2071 binfo path from current_class_type to TYPE, or 0. */
2074 maybe_dummy_object (type
, binfop
)
2080 if (current_class_type
2081 && get_base_distance (type
, current_class_type
, 0, binfop
) != -1)
2082 context
= current_class_type
;
2085 /* Reference from a nested class member function. */
2088 *binfop
= TYPE_BINFO (type
);
2091 if (current_class_ref
&& context
== current_class_type
)
2092 decl
= current_class_ref
;
2094 decl
= build_dummy_object (context
);
2099 /* Returns 1 if OB is a placeholder object, or a pointer to one. */
2102 is_dummy_object (ob
)
2105 if (TREE_CODE (ob
) == INDIRECT_REF
)
2106 ob
= TREE_OPERAND (ob
, 0);
2107 return (TREE_CODE (ob
) == NOP_EXPR
2108 && TREE_OPERAND (ob
, 0) == void_zero_node
);
2111 /* Returns 1 iff type T is a POD type, as defined in [basic.types]. */
2117 while (TREE_CODE (t
) == ARRAY_TYPE
)
2120 if (INTEGRAL_TYPE_P (t
))
2121 return 1; /* integral, character or enumeral type */
2122 if (FLOAT_TYPE_P (t
))
2125 return 1; /* pointer to non-member */
2126 if (TYPE_PTRMEM_P (t
))
2127 return 1; /* pointer to member object */
2128 if (TYPE_PTRMEMFUNC_P (t
))
2129 return 1; /* pointer to member function */
2131 if (! CLASS_TYPE_P (t
))
2132 return 0; /* other non-class type (reference or function) */
2133 if (CLASSTYPE_NON_POD_P (t
))
2138 /* Return a 1 if ATTR_NAME and ATTR_ARGS denote a valid C++-specific
2139 attribute for either declaration DECL or type TYPE and 0 otherwise.
2140 Plugged into valid_lang_attribute. */
2143 cp_valid_lang_attribute (attr_name
, attr_args
, decl
, type
)
2145 tree attr_args ATTRIBUTE_UNUSED
;
2146 tree decl ATTRIBUTE_UNUSED
;
2147 tree type ATTRIBUTE_UNUSED
;
2149 if (is_attribute_p ("com_interface", attr_name
))
2151 if (! flag_vtable_thunks
)
2153 error ("`com_interface' only supported with -fvtable-thunks");
2157 if (attr_args
!= NULL_TREE
2158 || decl
!= NULL_TREE
2159 || ! CLASS_TYPE_P (type
)
2160 || type
!= TYPE_MAIN_VARIANT (type
))
2162 warning ("`com_interface' attribute can only be applied to class definitions");
2166 CLASSTYPE_COM_INTERFACE (type
) = 1;
2169 else if (is_attribute_p ("init_priority", attr_name
))
2171 tree initp_expr
= (attr_args
? TREE_VALUE (attr_args
): NULL_TREE
);
2175 STRIP_NOPS (initp_expr
);
2177 if (!initp_expr
|| TREE_CODE (initp_expr
) != INTEGER_CST
)
2179 error ("requested init_priority is not an integer constant");
2183 pri
= TREE_INT_CST_LOW (initp_expr
);
2185 while (TREE_CODE (type
) == ARRAY_TYPE
)
2186 type
= TREE_TYPE (type
);
2188 if (decl
== NULL_TREE
2189 || TREE_CODE (decl
) != VAR_DECL
2190 || ! TREE_STATIC (decl
)
2191 || DECL_EXTERNAL (decl
)
2192 || (TREE_CODE (type
) != RECORD_TYPE
2193 && TREE_CODE (type
) != UNION_TYPE
)
2194 /* Static objects in functions are initialized the
2195 first time control passes through that
2196 function. This is not precise enough to pin down an
2197 init_priority value, so don't allow it. */
2198 || current_function_decl
)
2200 error ("can only use init_priority attribute on file-scope definitions of objects of class type");
2204 if (pri
> MAX_INIT_PRIORITY
|| pri
<= 0)
2206 error ("requested init_priority is out of range");
2210 /* Check for init_priorities that are reserved for
2211 language and runtime support implementations.*/
2212 if (pri
<= MAX_RESERVED_INIT_PRIORITY
)
2215 ("requested init_priority is reserved for internal use");
2218 DECL_INIT_PRIORITY (decl
) = pri
;
2225 /* Return a new PTRMEM_CST of the indicated TYPE. The MEMBER is the
2226 thing pointed to by the constant. */
2229 make_ptrmem_cst (type
, member
)
2233 tree ptrmem_cst
= make_node (PTRMEM_CST
);
2234 /* If would seem a great convenience if make_node would set
2235 TREE_CONSTANT for things of class `c', but it does not. */
2236 TREE_CONSTANT (ptrmem_cst
) = 1;
2237 TREE_TYPE (ptrmem_cst
) = type
;
2238 PTRMEM_CST_MEMBER (ptrmem_cst
) = member
;
2242 /* Mark ARG (which is really a list_hash_table **) for GC. */
2245 mark_list_hash (arg
)
2248 struct list_hash
*lh
;
2250 for (lh
= * ((struct list_hash
**) arg
); lh
; lh
= lh
->next
)
2251 ggc_mark_tree (lh
->list
);
2254 /* Initialize tree.c. */
2259 make_lang_type_fn
= cp_make_lang_type
;
2260 lang_unsave
= cp_unsave
;
2261 ggc_add_root (list_hash_table
,
2262 sizeof (list_hash_table
) / sizeof (struct list_hash
*),
2263 sizeof (struct list_hash
*),
2267 /* The SAVE_EXPR pointed to by TP is being copied. If ST contains
2268 information indicating to what new SAVE_EXPR this one should be
2269 mapped, use that one. Otherwise, create a new node and enter it in
2270 ST. FN is the function into which the copy will be placed. */
2273 remap_save_expr (tp
, st
, fn
, walk_subtrees
)
2281 /* See if we already encountered this SAVE_EXPR. */
2282 n
= splay_tree_lookup (st
, (splay_tree_key
) *tp
);
2284 /* If we didn't already remap this SAVE_EXPR, do so now. */
2287 tree t
= copy_node (*tp
);
2289 /* The SAVE_EXPR is now part of the function into which we
2290 are inlining this body. */
2291 SAVE_EXPR_CONTEXT (t
) = fn
;
2292 /* And we haven't evaluated it yet. */
2293 SAVE_EXPR_RTL (t
) = NULL_RTX
;
2294 /* Remember this SAVE_EXPR. */
2295 n
= splay_tree_insert (st
,
2296 (splay_tree_key
) *tp
,
2297 (splay_tree_value
) t
);
2300 /* We've already walked into this SAVE_EXPR, so we needn't do it
2304 /* Replace this SAVE_EXPR with the copy. */
2305 *tp
= (tree
) n
->value
;
2308 /* Called via walk_tree. If *TP points to a DECL_STMT for a local
2309 declaration, copies the declaration and enters it in the splay_tree
2310 pointed to by DATA (which is really a `splay_tree *'). */
2313 mark_local_for_remap_r (tp
, walk_subtrees
, data
)
2315 int *walk_subtrees ATTRIBUTE_UNUSED
;
2319 splay_tree st
= (splay_tree
) data
;
2321 if ((TREE_CODE (t
) == DECL_STMT
2322 && nonstatic_local_decl_p (DECL_STMT_DECL (t
)))
2323 || TREE_CODE (t
) == LABEL_STMT
)
2328 /* Figure out what's being declared. */
2329 decl
= (TREE_CODE (t
) == DECL_STMT
2330 ? DECL_STMT_DECL (t
) : LABEL_STMT_LABEL (t
));
2333 copy
= copy_decl_for_inlining (decl
,
2334 DECL_CONTEXT (decl
),
2335 DECL_CONTEXT (decl
));
2337 /* Remember the copy. */
2338 splay_tree_insert (st
,
2339 (splay_tree_key
) decl
,
2340 (splay_tree_value
) copy
);
2346 /* Called via walk_tree when an expression is unsaved. Using the
2347 splay_tree pointed to by ST (which is really a `splay_tree *'),
2348 remaps all local declarations to appropriate replacements. */
2351 cp_unsave_r (tp
, walk_subtrees
, data
)
2356 splay_tree st
= (splay_tree
) data
;
2359 /* Only a local declaration (variable or label). */
2360 if (nonstatic_local_decl_p (*tp
))
2362 /* Lookup the declaration. */
2363 n
= splay_tree_lookup (st
, (splay_tree_key
) *tp
);
2365 /* If it's there, remap it. */
2367 *tp
= (tree
) n
->value
;
2369 else if (TREE_CODE (*tp
) == SAVE_EXPR
)
2370 remap_save_expr (tp
, st
, current_function_decl
, walk_subtrees
);
2373 copy_tree_r (tp
, walk_subtrees
, NULL
);
2375 /* Do whatever unsaving is required. */
2376 unsave_expr_1 (*tp
);
2379 /* Keep iterating. */
2383 /* Called by unsave_expr_now whenever an expression (*TP) needs to be
2392 /* Create a splay-tree to map old local variable declarations to new
2394 st
= splay_tree_new (splay_tree_compare_pointers
, NULL
, NULL
);
2396 /* Walk the tree once figuring out what needs to be remapped. */
2397 walk_tree (tp
, mark_local_for_remap_r
, st
);
2399 /* Walk the tree again, copying, remapping, and unsaving. */
2400 walk_tree (tp
, cp_unsave_r
, st
);
2403 splay_tree_delete (st
);