1 /* Language-dependent node constructors for parse phase of GNU compiler.
2 Copyright (C) 1987, 88, 92-98, 1999, 2000 Free Software Foundation, Inc.
3 Hacked by Michael Tiemann (tiemann@cygnus.com)
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
31 #include "insn-config.h"
32 #include "integrate.h"
34 static tree bot_manip
PARAMS ((tree
*, int *, void *));
35 static tree bot_replace
PARAMS ((tree
*, int *, void *));
36 static tree build_cplus_array_type_1
PARAMS ((tree
, tree
));
37 static void list_hash_add
PARAMS ((int, tree
));
38 static int list_hash
PARAMS ((tree
, tree
, tree
));
39 static tree list_hash_lookup
PARAMS ((int, tree
, tree
, tree
));
40 static cp_lvalue_kind lvalue_p_1
PARAMS ((tree
, int));
41 static tree no_linkage_helper
PARAMS ((tree
*, int *, void *));
42 static tree build_srcloc
PARAMS ((char *, int));
43 static void mark_list_hash
PARAMS ((void *));
44 static int statement_code_p
PARAMS ((enum tree_code
));
45 static tree mark_local_for_remap_r
PARAMS ((tree
*, int *, void *));
46 static tree cp_unsave_r
PARAMS ((tree
*, int *, void *));
47 static void cp_unsave
PARAMS ((tree
*));
48 static tree build_target_expr
PARAMS ((tree
, tree
));
50 /* If REF is an lvalue, returns the kind of lvalue that REF is.
51 Otherwise, returns clk_none. If TREAT_CLASS_RVALUES_AS_LVALUES is
52 non-zero, rvalues of class type are considered lvalues. */
55 lvalue_p_1 (ref
, treat_class_rvalues_as_lvalues
)
57 int treat_class_rvalues_as_lvalues
;
59 cp_lvalue_kind op1_lvalue_kind
= clk_none
;
60 cp_lvalue_kind op2_lvalue_kind
= clk_none
;
62 if (TREE_CODE (TREE_TYPE (ref
)) == REFERENCE_TYPE
)
65 if (ref
== current_class_ptr
&& flag_this_is_variable
<= 0)
68 switch (TREE_CODE (ref
))
70 /* preincrements and predecrements are valid lvals, provided
71 what they refer to are valid lvals. */
72 case PREINCREMENT_EXPR
:
73 case PREDECREMENT_EXPR
:
77 case WITH_CLEANUP_EXPR
:
81 return lvalue_p_1 (TREE_OPERAND (ref
, 0),
82 treat_class_rvalues_as_lvalues
);
85 op1_lvalue_kind
= lvalue_p_1 (TREE_OPERAND (ref
, 0),
86 treat_class_rvalues_as_lvalues
);
88 /* The "field" can be a FUNCTION_DECL or an OVERLOAD in some
90 && TREE_CODE (TREE_OPERAND (ref
, 1)) == FIELD_DECL
91 && DECL_C_BIT_FIELD (TREE_OPERAND (ref
, 1)))
93 /* Clear the ordinary bit. If this object was a class
94 rvalue we want to preserve that information. */
95 op1_lvalue_kind
&= ~clk_ordinary
;
96 /* The lvalue is for a btifield. */
97 op1_lvalue_kind
|= clk_bitfield
;
99 return op1_lvalue_kind
;
105 if (TREE_READONLY (ref
) && ! TREE_STATIC (ref
)
106 && DECL_LANG_SPECIFIC (ref
)
107 && DECL_IN_AGGR_P (ref
))
113 if (TREE_CODE (TREE_TYPE (ref
)) != METHOD_TYPE
)
117 /* A currently unresolved scope ref. */
119 my_friendly_abort (103);
121 if (TREE_CODE (TREE_OPERAND (ref
, 1)) == FUNCTION_DECL
)
126 op1_lvalue_kind
= lvalue_p_1 (TREE_OPERAND (ref
, 0),
127 treat_class_rvalues_as_lvalues
);
128 op2_lvalue_kind
= lvalue_p_1 (TREE_OPERAND (ref
, 1),
129 treat_class_rvalues_as_lvalues
);
133 op1_lvalue_kind
= lvalue_p_1 (TREE_OPERAND (ref
, 1),
134 treat_class_rvalues_as_lvalues
);
135 op2_lvalue_kind
= lvalue_p_1 (TREE_OPERAND (ref
, 2),
136 treat_class_rvalues_as_lvalues
);
143 return lvalue_p_1 (TREE_OPERAND (ref
, 1),
144 treat_class_rvalues_as_lvalues
);
147 return treat_class_rvalues_as_lvalues
? clk_class
: clk_none
;
151 return ((treat_class_rvalues_as_lvalues
152 && IS_AGGR_TYPE (TREE_TYPE (ref
)))
153 ? clk_class
: clk_none
);
156 /* All functions (except non-static-member functions) are
158 return (DECL_NONSTATIC_MEMBER_FUNCTION_P (ref
)
159 ? clk_none
: clk_ordinary
);
165 /* If one operand is not an lvalue at all, then this expression is
167 if (!op1_lvalue_kind
|| !op2_lvalue_kind
)
170 /* Otherwise, it's an lvalue, and it has all the odd properties
171 contributed by either operand. */
172 op1_lvalue_kind
= op1_lvalue_kind
| op2_lvalue_kind
;
173 /* It's not an ordinary lvalue if it involves either a bit-field or
175 if ((op1_lvalue_kind
& ~clk_ordinary
) != clk_none
)
176 op1_lvalue_kind
&= ~clk_ordinary
;
177 return op1_lvalue_kind
;
180 /* If REF is an lvalue, returns the kind of lvalue that REF is.
181 Otherwise, returns clk_none. Lvalues can be assigned, unless they
182 have TREE_READONLY, or unless they are FUNCTION_DECLs. Lvalues can
183 have their address taken, unless they have DECL_REGISTER. */
189 return lvalue_p_1 (ref
, /*treat_class_rvalues_as_lvalues=*/0);
192 /* This differs from real_lvalue_p in that class rvalues are
193 considered lvalues. */
200 (lvalue_p_1 (ref
, /*treat_class_rvalues_as_lvalues=*/1) != clk_none
);
203 /* Return nonzero if REF is an lvalue valid for this language;
204 otherwise, print an error message and return zero. */
207 lvalue_or_else (ref
, string
)
211 int win
= lvalue_p (ref
);
213 error ("non-lvalue in %s", string
);
217 /* Build a TARGET_EXPR, initializing the DECL with the VALUE. */
220 build_target_expr (decl
, value
)
226 t
= build (TARGET_EXPR
, TREE_TYPE (decl
), decl
, value
,
227 maybe_build_cleanup (decl
), NULL_TREE
);
228 /* We always set TREE_SIDE_EFFECTS so that expand_expr does not
229 ignore the TARGET_EXPR. If there really turn out to be no
230 side-effects, then the optimizer should be able to get rid of
231 whatever code is generated anyhow. */
232 TREE_SIDE_EFFECTS (t
) = 1;
237 /* INIT is a CALL_EXPR which needs info about its target.
238 TYPE is the type that this initialization should appear to have.
240 Build an encapsulation of the initialization to perform
241 and return it so that it can be processed by language-independent
242 and language-specific expression expanders. */
245 build_cplus_new (type
, init
)
253 /* Make sure that we're not trying to create an instance of an
255 abstract_virtuals_error (NULL_TREE
, type
);
257 if (TREE_CODE (init
) != CALL_EXPR
&& TREE_CODE (init
) != AGGR_INIT_EXPR
)
258 return convert (type
, init
);
260 slot
= build (VAR_DECL
, type
);
261 DECL_ARTIFICIAL (slot
) = 1;
262 DECL_CONTEXT (slot
) = current_function_decl
;
263 layout_decl (slot
, 0);
265 /* We split the CALL_EXPR into its function and its arguments here.
266 Then, in expand_expr, we put them back together. The reason for
267 this is that this expression might be a default argument
268 expression. In that case, we need a new temporary every time the
269 expression is used. That's what break_out_target_exprs does; it
270 replaces every AGGR_INIT_EXPR with a copy that uses a fresh
271 temporary slot. Then, expand_expr builds up a call-expression
272 using the new slot. */
273 fn
= TREE_OPERAND (init
, 0);
274 rval
= build (AGGR_INIT_EXPR
, type
, fn
, TREE_OPERAND (init
, 1), slot
);
275 TREE_SIDE_EFFECTS (rval
) = 1;
276 AGGR_INIT_VIA_CTOR_P (rval
)
277 = (TREE_CODE (fn
) == ADDR_EXPR
278 && TREE_CODE (TREE_OPERAND (fn
, 0)) == FUNCTION_DECL
279 && DECL_CONSTRUCTOR_P (TREE_OPERAND (fn
, 0)));
280 rval
= build_target_expr (slot
, rval
);
285 /* Buidl a TARGET_EXPR using INIT to initialize a new temporary of the
289 build_target_expr_with_type (init
, type
)
296 slot
= build (VAR_DECL
, type
);
297 DECL_ARTIFICIAL (slot
) = 1;
298 DECL_CONTEXT (slot
) = current_function_decl
;
299 layout_decl (slot
, 0);
300 rval
= build_target_expr (slot
, init
);
305 /* Like build_target_expr_with_type, but use the type of INIT. */
308 get_target_expr (init
)
311 return build_target_expr_with_type (init
, TREE_TYPE (init
));
314 /* Recursively search EXP for CALL_EXPRs that need cleanups and replace
315 these CALL_EXPRs with tree nodes that will perform the cleanups. */
318 break_out_cleanups (exp
)
323 if (TREE_CODE (tmp
) == CALL_EXPR
324 && TYPE_NEEDS_DESTRUCTOR (TREE_TYPE (tmp
)))
325 return build_cplus_new (TREE_TYPE (tmp
), tmp
);
327 while (TREE_CODE (tmp
) == NOP_EXPR
328 || TREE_CODE (tmp
) == CONVERT_EXPR
329 || TREE_CODE (tmp
) == NON_LVALUE_EXPR
)
331 if (TREE_CODE (TREE_OPERAND (tmp
, 0)) == CALL_EXPR
332 && TYPE_NEEDS_DESTRUCTOR (TREE_TYPE (TREE_OPERAND (tmp
, 0))))
334 TREE_OPERAND (tmp
, 0)
335 = build_cplus_new (TREE_TYPE (TREE_OPERAND (tmp
, 0)),
336 TREE_OPERAND (tmp
, 0));
340 tmp
= TREE_OPERAND (tmp
, 0);
345 /* Recursively perform a preorder search EXP for CALL_EXPRs, making
346 copies where they are found. Returns a deep copy all nodes transitively
347 containing CALL_EXPRs. */
350 break_out_calls (exp
)
353 register tree t1
, t2
= NULL_TREE
;
354 register enum tree_code code
;
355 register int changed
= 0;
358 if (exp
== NULL_TREE
)
361 code
= TREE_CODE (exp
);
363 if (code
== CALL_EXPR
)
364 return copy_node (exp
);
366 /* Don't try and defeat a save_expr, as it should only be done once. */
367 if (code
== SAVE_EXPR
)
370 switch (TREE_CODE_CLASS (code
))
375 case 'c': /* a constant */
376 case 't': /* a type node */
377 case 'x': /* something random, like an identifier or an ERROR_MARK. */
380 case 'd': /* A decl node */
381 #if 0 /* This is bogus. jason 9/21/94 */
383 t1
= break_out_calls (DECL_INITIAL (exp
));
384 if (t1
!= DECL_INITIAL (exp
))
386 exp
= copy_node (exp
);
387 DECL_INITIAL (exp
) = t1
;
392 case 'b': /* A block node */
394 /* Don't know how to handle these correctly yet. Must do a
395 break_out_calls on all DECL_INITIAL values for local variables,
396 and also break_out_calls on all sub-blocks and sub-statements. */
401 case 'e': /* an expression */
402 case 'r': /* a reference */
403 case 's': /* an expression with side effects */
404 for (i
= tree_code_length
[(int) code
] - 1; i
>= 0; i
--)
406 t1
= break_out_calls (TREE_OPERAND (exp
, i
));
407 if (t1
!= TREE_OPERAND (exp
, i
))
409 exp
= copy_node (exp
);
410 TREE_OPERAND (exp
, i
) = t1
;
415 case '<': /* a comparison expression */
416 case '2': /* a binary arithmetic expression */
417 t2
= break_out_calls (TREE_OPERAND (exp
, 1));
418 if (t2
!= TREE_OPERAND (exp
, 1))
420 case '1': /* a unary arithmetic expression */
421 t1
= break_out_calls (TREE_OPERAND (exp
, 0));
422 if (t1
!= TREE_OPERAND (exp
, 0))
426 if (tree_code_length
[(int) code
] == 1)
427 return build1 (code
, TREE_TYPE (exp
), t1
);
429 return build (code
, TREE_TYPE (exp
), t1
, t2
);
436 extern struct obstack permanent_obstack
;
438 /* Here is how primitive or already-canonicalized types' hash
439 codes are made. MUST BE CONSISTENT WITH tree.c !!! */
440 #define TYPE_HASH(TYPE) ((HOST_WIDE_INT) (TYPE) & 0777777)
442 /* Construct, lay out and return the type of methods belonging to class
443 BASETYPE and whose arguments are described by ARGTYPES and whose values
444 are described by RETTYPE. If each type exists already, reuse it. */
447 build_cplus_method_type (basetype
, rettype
, argtypes
)
448 tree basetype
, rettype
, argtypes
;
454 /* Make a node of the sort we want. */
455 t
= make_node (METHOD_TYPE
);
457 TYPE_METHOD_BASETYPE (t
) = TYPE_MAIN_VARIANT (basetype
);
458 TREE_TYPE (t
) = rettype
;
459 ptype
= build_pointer_type (basetype
);
461 /* The actual arglist for this function includes a "hidden" argument
462 which is "this". Put it into the list of argument types. Make
463 sure that the new argument list is allocated on the same obstack
465 argtypes
= tree_cons (NULL_TREE
, ptype
, argtypes
);
466 TYPE_ARG_TYPES (t
) = argtypes
;
467 TREE_SIDE_EFFECTS (argtypes
) = 1; /* Mark first argtype as "artificial". */
469 /* If we already have such a type, use the old one and free this one.
470 Note that it also frees up the above cons cell if found. */
471 hashcode
= TYPE_HASH (basetype
) + TYPE_HASH (rettype
) +
472 type_hash_list (argtypes
);
474 t
= type_hash_canon (hashcode
, t
);
476 if (TYPE_SIZE (t
) == 0)
483 build_cplus_array_type_1 (elt_type
, index_type
)
489 if (elt_type
== error_mark_node
|| index_type
== error_mark_node
)
490 return error_mark_node
;
492 if (processing_template_decl
493 || uses_template_parms (elt_type
)
494 || uses_template_parms (index_type
))
496 t
= make_node (ARRAY_TYPE
);
497 TREE_TYPE (t
) = elt_type
;
498 TYPE_DOMAIN (t
) = index_type
;
501 t
= build_array_type (elt_type
, index_type
);
503 /* Push these needs up so that initialization takes place
505 TYPE_NEEDS_CONSTRUCTING (t
)
506 = TYPE_NEEDS_CONSTRUCTING (TYPE_MAIN_VARIANT (elt_type
));
507 TYPE_NEEDS_DESTRUCTOR (t
)
508 = TYPE_NEEDS_DESTRUCTOR (TYPE_MAIN_VARIANT (elt_type
));
513 build_cplus_array_type (elt_type
, index_type
)
518 int type_quals
= CP_TYPE_QUALS (elt_type
);
520 elt_type
= TYPE_MAIN_VARIANT (elt_type
);
522 t
= build_cplus_array_type_1 (elt_type
, index_type
);
524 if (type_quals
!= TYPE_UNQUALIFIED
)
525 t
= cp_build_qualified_type (t
, type_quals
);
530 /* Make a variant of TYPE, qualified with the TYPE_QUALS. Handles
531 arrays correctly. In particular, if TYPE is an array of T's, and
532 TYPE_QUALS is non-empty, returns an array of qualified T's. If
533 at attempt is made to qualify a type illegally, and COMPLAIN is
534 non-zero, an error is issued. If COMPLAIN is zero, error_mark_node
538 cp_build_qualified_type_real (type
, type_quals
, complain
)
545 if (type
== error_mark_node
)
548 if (type_quals
== TYPE_QUALS (type
))
551 /* A restrict-qualified pointer type must be a pointer (or reference)
552 to object or incomplete type. */
553 if ((type_quals
& TYPE_QUAL_RESTRICT
)
554 && TREE_CODE (type
) != TEMPLATE_TYPE_PARM
555 && (!POINTER_TYPE_P (type
)
556 || TYPE_PTRMEM_P (type
)
557 || TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
))
560 cp_error ("`%T' cannot be `restrict'-qualified", type
);
562 return error_mark_node
;
564 type_quals
&= ~TYPE_QUAL_RESTRICT
;
567 if (type_quals
!= TYPE_UNQUALIFIED
568 && TREE_CODE (type
) == FUNCTION_TYPE
)
571 cp_error ("`%T' cannot be `const'-, `volatile'-, or `restrict'-qualified", type
);
573 return error_mark_node
;
574 type_quals
= TYPE_UNQUALIFIED
;
576 else if (TREE_CODE (type
) == ARRAY_TYPE
)
578 /* In C++, the qualification really applies to the array element
579 type. Obtain the appropriately qualified element type. */
582 = cp_build_qualified_type_real (TREE_TYPE (type
),
586 if (element_type
== error_mark_node
)
587 return error_mark_node
;
589 /* See if we already have an identically qualified type. */
590 for (t
= TYPE_MAIN_VARIANT (type
); t
; t
= TYPE_NEXT_VARIANT (t
))
591 if (CP_TYPE_QUALS (t
) == type_quals
)
594 /* If we didn't already have it, create it now. */
597 /* Make a new array type, just like the old one, but with the
598 appropriately qualified element type. */
599 t
= build_type_copy (type
);
600 TREE_TYPE (t
) = element_type
;
603 /* Even if we already had this variant, we update
604 TYPE_NEEDS_CONSTRUCTING and TYPE_NEEDS_DESTRUCTOR in case
605 they changed since the variant was originally created.
607 This seems hokey; if there is some way to use a previous
608 variant *without* coming through here,
609 TYPE_NEEDS_CONSTRUCTING will never be updated. */
610 TYPE_NEEDS_CONSTRUCTING (t
)
611 = TYPE_NEEDS_CONSTRUCTING (TYPE_MAIN_VARIANT (element_type
));
612 TYPE_NEEDS_DESTRUCTOR (t
)
613 = TYPE_NEEDS_DESTRUCTOR (TYPE_MAIN_VARIANT (element_type
));
616 else if (TYPE_PTRMEMFUNC_P (type
))
618 /* For a pointer-to-member type, we can't just return a
619 cv-qualified version of the RECORD_TYPE. If we do, we
620 haven't change the field that contains the actual pointer to
621 a method, and so TYPE_PTRMEMFUNC_FN_TYPE will be wrong. */
624 t
= TYPE_PTRMEMFUNC_FN_TYPE (type
);
625 t
= cp_build_qualified_type_real (t
, type_quals
, complain
);
626 return build_ptrmemfunc_type (t
);
629 /* Retrieve (or create) the appropriately qualified variant. */
630 result
= build_qualified_type (type
, type_quals
);
632 /* If this was a pointer-to-method type, and we just made a copy,
633 then we need to clear the cached associated
634 pointer-to-member-function type; it is not valid for the new
637 && TREE_CODE (type
) == POINTER_TYPE
638 && TREE_CODE (TREE_TYPE (type
)) == METHOD_TYPE
)
639 TYPE_SET_PTRMEMFUNC_TYPE (result
, NULL_TREE
);
644 /* Returns the canonical version of TYPE. In other words, if TYPE is
645 a typedef, returns the underlying type. The cv-qualification of
646 the type returned matches the type input; they will always be
650 canonical_type_variant (t
)
653 return cp_build_qualified_type (TYPE_MAIN_VARIANT (t
), CP_TYPE_QUALS (t
));
656 /* Makes new binfos for the indirect bases under BINFO, and updates
657 BINFO_OFFSET for them and their bases. */
660 unshare_base_binfos (binfo
)
663 tree binfos
= BINFO_BASETYPES (binfo
);
667 if (binfos
== NULL_TREE
)
670 /* Now unshare the structure beneath BINFO. */
671 for (j
= TREE_VEC_LENGTH (binfos
)-1;
674 tree base_binfo
= TREE_VEC_ELT (binfos
, j
);
675 new_binfo
= TREE_VEC_ELT (binfos
, j
)
676 = make_binfo (BINFO_OFFSET (base_binfo
),
678 BINFO_VTABLE (base_binfo
),
679 BINFO_VIRTUALS (base_binfo
));
680 TREE_VIA_PUBLIC (new_binfo
) = TREE_VIA_PUBLIC (base_binfo
);
681 TREE_VIA_PROTECTED (new_binfo
) = TREE_VIA_PROTECTED (base_binfo
);
682 TREE_VIA_VIRTUAL (new_binfo
) = TREE_VIA_VIRTUAL (base_binfo
);
683 BINFO_INHERITANCE_CHAIN (new_binfo
) = binfo
;
684 unshare_base_binfos (new_binfo
);
689 /* Hashing of lists so that we don't make duplicates.
690 The entry point is `list_hash_canon'. */
692 /* Each hash table slot is a bucket containing a chain
693 of these structures. */
697 struct list_hash
*next
; /* Next structure in the bucket. */
698 int hashcode
; /* Hash code of this list. */
699 tree list
; /* The list recorded here. */
702 /* Now here is the hash table. When recording a list, it is added
703 to the slot whose index is the hash code mod the table size.
704 Note that the hash table is used for several kinds of lists.
705 While all these live in the same table, they are completely independent,
706 and the hash code is computed differently for each of these. */
708 #define TYPE_HASH_SIZE 59
709 static struct list_hash
*list_hash_table
[TYPE_HASH_SIZE
];
711 /* Compute a hash code for a list (chain of TREE_LIST nodes
712 with goodies in the TREE_PURPOSE, TREE_VALUE, and bits of the
713 TREE_COMMON slots), by adding the hash codes of the individual entries. */
716 list_hash (purpose
, value
, chain
)
717 tree purpose
, value
, chain
;
719 register int hashcode
= 0;
722 hashcode
+= TYPE_HASH (chain
);
725 hashcode
+= TYPE_HASH (value
);
729 hashcode
+= TYPE_HASH (purpose
);
735 /* Look in the type hash table for a type isomorphic to TYPE.
736 If one is found, return it. Otherwise return 0. */
739 list_hash_lookup (hashcode
, purpose
, value
, chain
)
741 tree purpose
, value
, chain
;
743 register struct list_hash
*h
;
745 for (h
= list_hash_table
[hashcode
% TYPE_HASH_SIZE
]; h
; h
= h
->next
)
746 if (h
->hashcode
== hashcode
747 && TREE_PURPOSE (h
->list
) == purpose
748 && TREE_VALUE (h
->list
) == value
749 && TREE_CHAIN (h
->list
) == chain
)
754 /* Add an entry to the list-hash-table
755 for a list TYPE whose hash code is HASHCODE. */
758 list_hash_add (hashcode
, list
)
762 register struct list_hash
*h
;
764 h
= (struct list_hash
*) obstack_alloc (&permanent_obstack
, sizeof (struct list_hash
));
765 h
->hashcode
= hashcode
;
767 h
->next
= list_hash_table
[hashcode
% TYPE_HASH_SIZE
];
768 list_hash_table
[hashcode
% TYPE_HASH_SIZE
] = h
;
771 /* Given list components PURPOSE, VALUE, AND CHAIN, return the canonical
772 object for an identical list if one already exists. Otherwise, build a
773 new one, and record it as the canonical object. */
775 /* Set to 1 to debug without canonicalization. Never set by program. */
777 static int debug_no_list_hash
= 0;
780 hash_tree_cons (purpose
, value
, chain
)
781 tree purpose
, value
, chain
;
786 if (! debug_no_list_hash
)
788 hashcode
= list_hash (purpose
, value
, chain
);
789 t
= list_hash_lookup (hashcode
, purpose
, value
, chain
);
794 t
= tree_cons (purpose
, value
, chain
);
796 /* If this is a new list, record it for later reuse. */
797 if (! debug_no_list_hash
)
798 list_hash_add (hashcode
, t
);
803 /* Constructor for hashed lists. */
806 hash_tree_chain (value
, chain
)
809 return hash_tree_cons (NULL_TREE
, value
, chain
);
812 /* Similar, but used for concatenating two lists. */
815 hash_chainon (list1
, list2
)
822 if (TREE_CHAIN (list1
) == NULL_TREE
)
823 return hash_tree_chain (TREE_VALUE (list1
), list2
);
824 return hash_tree_chain (TREE_VALUE (list1
),
825 hash_chainon (TREE_CHAIN (list1
), list2
));
828 /* Build an association between TYPE and some parameters:
830 OFFSET is the offset added to `this' to convert it to a pointer
833 BINFO is the base binfo to use, if we are deriving from one. This
834 is necessary, as we want specialized parent binfos from base
835 classes, so that the VTABLE_NAMEs of bases are for the most derived
836 type, instead of the simple type.
838 VTABLE is the virtual function table with which to initialize
839 sub-objects of type TYPE.
841 VIRTUALS are the virtual functions sitting in VTABLE. */
844 make_binfo (offset
, binfo
, vtable
, virtuals
)
846 tree vtable
, virtuals
;
848 tree new_binfo
= make_tree_vec (7);
851 if (TREE_CODE (binfo
) == TREE_VEC
)
852 type
= BINFO_TYPE (binfo
);
856 binfo
= CLASS_TYPE_P (type
) ? TYPE_BINFO (binfo
) : NULL_TREE
;
859 TREE_TYPE (new_binfo
) = TYPE_MAIN_VARIANT (type
);
860 BINFO_OFFSET (new_binfo
) = offset
;
861 BINFO_VTABLE (new_binfo
) = vtable
;
862 BINFO_VIRTUALS (new_binfo
) = virtuals
;
864 if (binfo
&& BINFO_BASETYPES (binfo
) != NULL_TREE
)
865 BINFO_BASETYPES (new_binfo
) = copy_node (BINFO_BASETYPES (binfo
));
869 /* Return the binfo value for ELEM in TYPE. */
872 binfo_value (elem
, type
)
876 if (get_base_distance (elem
, type
, 0, (tree
*)0) == -2)
877 compiler_error ("base class `%s' ambiguous in binfo_value",
878 TYPE_NAME_STRING (elem
));
880 return TYPE_BINFO (type
);
881 if (TREE_CODE (elem
) == RECORD_TYPE
&& TYPE_BINFO (elem
) == type
)
883 return get_binfo (elem
, type
, 0);
886 /* Return a TREE_LIST whose TREE_VALUE nodes along the
887 BINFO_INHERITANCE_CHAIN for BINFO, but in the opposite order. In
888 other words, while the BINFO_INHERITANCE_CHAIN goes from base
889 classes to derived classes, the reversed path goes from derived
890 classes to base classes. */
898 reversed_path
= NULL_TREE
;
901 reversed_path
= tree_cons (NULL_TREE
, binfo
, reversed_path
);
902 binfo
= BINFO_INHERITANCE_CHAIN (binfo
);
905 return reversed_path
;
912 unsigned HOST_WIDE_INT n
;
915 fprintf (stderr
, "type \"%s\"; offset = %ld\n",
916 TYPE_NAME_STRING (BINFO_TYPE (elem
)),
917 (long) TREE_INT_CST_LOW (BINFO_OFFSET (elem
)));
918 fprintf (stderr
, "vtable type:\n");
919 debug_tree (BINFO_TYPE (elem
));
920 if (BINFO_VTABLE (elem
))
921 fprintf (stderr
, "vtable decl \"%s\"\n", IDENTIFIER_POINTER (DECL_NAME (BINFO_VTABLE (elem
))));
923 fprintf (stderr
, "no vtable decl yet\n");
924 fprintf (stderr
, "virtuals:\n");
925 virtuals
= skip_rtti_stuff (elem
, BINFO_TYPE (elem
), &n
);
929 tree fndecl
= TREE_VALUE (virtuals
);
930 fprintf (stderr
, "%s [%ld =? %ld]\n",
931 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (fndecl
)),
932 (long) n
, (long) TREE_INT_CST_LOW (DECL_VINDEX (fndecl
)));
934 virtuals
= TREE_CHAIN (virtuals
);
943 if (TREE_CODE (t
) == FUNCTION_DECL
)
945 else if (TREE_CODE (t
) == OVERLOAD
)
947 for (i
=0; t
; t
= OVL_CHAIN (t
))
952 my_friendly_abort (359);
960 /* A baselink is also considered an overloaded function. */
961 if (TREE_CODE (x
) == OFFSET_REF
)
962 x
= TREE_OPERAND (x
, 1);
965 return (TREE_CODE (x
) == FUNCTION_DECL
966 || TREE_CODE (x
) == TEMPLATE_ID_EXPR
967 || DECL_FUNCTION_TEMPLATE_P (x
)
968 || TREE_CODE (x
) == OVERLOAD
);
972 really_overloaded_fn (x
)
975 /* A baselink is also considered an overloaded function. */
976 if (TREE_CODE (x
) == OFFSET_REF
)
977 x
= TREE_OPERAND (x
, 1);
980 return (TREE_CODE (x
) == OVERLOAD
981 && (TREE_CHAIN (x
) != NULL_TREE
982 || DECL_FUNCTION_TEMPLATE_P (OVL_FUNCTION (x
))));
989 my_friendly_assert (is_overloaded_fn (from
), 9);
990 /* A baselink is also considered an overloaded function. */
991 if (BASELINK_P (from
))
992 from
= TREE_VALUE (from
);
993 return OVL_CURRENT (from
);
996 /* Returns nonzero if T is a ->* or .* expression that refers to a
1003 return (TREE_CODE (t
) == OFFSET_REF
1004 && TYPE_PTRMEMFUNC_P (TREE_TYPE (TREE_OPERAND (t
, 1))));
1007 /* Return a new OVL node, concatenating it with the old one. */
1010 ovl_cons (decl
, chain
)
1014 tree result
= make_node (OVERLOAD
);
1015 TREE_TYPE (result
) = unknown_type_node
;
1016 OVL_FUNCTION (result
) = decl
;
1017 TREE_CHAIN (result
) = chain
;
1022 /* Build a new overloaded function. If this is the first one,
1023 just return it; otherwise, ovl_cons the _DECLs */
1026 build_overload (decl
, chain
)
1030 if (! chain
&& TREE_CODE (decl
) != TEMPLATE_DECL
)
1032 if (chain
&& TREE_CODE (chain
) != OVERLOAD
)
1033 chain
= ovl_cons (chain
, NULL_TREE
);
1034 return ovl_cons (decl
, chain
);
1037 /* True if fn is in ovl. */
1040 ovl_member (fn
, ovl
)
1044 if (ovl
== NULL_TREE
)
1046 if (TREE_CODE (ovl
) != OVERLOAD
)
1048 for (; ovl
; ovl
= OVL_CHAIN (ovl
))
1049 if (OVL_FUNCTION (ovl
) == fn
)
1055 is_aggr_type_2 (t1
, t2
)
1058 if (TREE_CODE (t1
) != TREE_CODE (t2
))
1060 return IS_AGGR_TYPE (t1
) && IS_AGGR_TYPE (t2
);
1063 /* Returns non-zero if CODE is the code for a statement. */
1066 statement_code_p (code
)
1067 enum tree_code code
;
1087 case START_CATCH_STMT
:
1090 case CTOR_INITIALIZER
:
1102 #define PRINT_RING_SIZE 4
1105 lang_printable_name (decl
, v
)
1109 static tree decl_ring
[PRINT_RING_SIZE
];
1110 static char *print_ring
[PRINT_RING_SIZE
];
1111 static int ring_counter
;
1114 /* Only cache functions. */
1116 || TREE_CODE (decl
) != FUNCTION_DECL
1117 || DECL_LANG_SPECIFIC (decl
) == 0)
1118 return lang_decl_name (decl
, v
);
1120 /* See if this print name is lying around. */
1121 for (i
= 0; i
< PRINT_RING_SIZE
; i
++)
1122 if (decl_ring
[i
] == decl
)
1123 /* yes, so return it. */
1124 return print_ring
[i
];
1126 if (++ring_counter
== PRINT_RING_SIZE
)
1129 if (current_function_decl
!= NULL_TREE
)
1131 if (decl_ring
[ring_counter
] == current_function_decl
)
1133 if (ring_counter
== PRINT_RING_SIZE
)
1135 if (decl_ring
[ring_counter
] == current_function_decl
)
1136 my_friendly_abort (106);
1139 if (print_ring
[ring_counter
])
1140 free (print_ring
[ring_counter
]);
1142 print_ring
[ring_counter
] = xstrdup (lang_decl_name (decl
, v
));
1143 decl_ring
[ring_counter
] = decl
;
1144 return print_ring
[ring_counter
];
1147 /* Build the FUNCTION_TYPE or METHOD_TYPE which may throw exceptions
1148 listed in RAISES. */
1151 build_exception_variant (type
, raises
)
1155 tree v
= TYPE_MAIN_VARIANT (type
);
1156 int type_quals
= TYPE_QUALS (type
);
1158 for (; v
; v
= TYPE_NEXT_VARIANT (v
))
1159 if (TYPE_QUALS (v
) == type_quals
1160 && comp_except_specs (raises
, TYPE_RAISES_EXCEPTIONS (v
), 1))
1163 /* Need to build a new variant. */
1164 v
= build_type_copy (type
);
1165 TYPE_RAISES_EXCEPTIONS (v
) = raises
;
1169 /* Given a TEMPLATE_TEMPLATE_PARM node T, create a new one together with its
1170 lang_specific field and its corresponding TEMPLATE_DECL node */
1173 copy_template_template_parm (t
)
1176 tree
template = TYPE_NAME (t
);
1179 t2
= make_aggr_type (TEMPLATE_TEMPLATE_PARM
);
1180 template = copy_node (template);
1181 copy_lang_decl (template);
1183 TREE_TYPE (template) = t2
;
1184 TYPE_NAME (t2
) = template;
1185 TYPE_STUB_DECL (t2
) = template;
1187 /* No need to copy these */
1188 TYPE_FIELDS (t2
) = TYPE_FIELDS (t
);
1189 TEMPLATE_TEMPLATE_PARM_TEMPLATE_INFO (t2
)
1190 = TEMPLATE_TEMPLATE_PARM_TEMPLATE_INFO (t
);
1194 /* Apply FUNC to all the sub-trees of TP in a pre-order traversal.
1195 FUNC is called with the DATA and the address of each sub-tree. If
1196 FUNC returns a non-NULL value, the traversal is aborted, and the
1197 value returned by FUNC is returned. */
1200 walk_tree (tp
, func
, data
)
1205 enum tree_code code
;
1209 #define WALK_SUBTREE(NODE) \
1212 result = walk_tree (&(NODE), func, data); \
1218 /* Skip empty subtrees. */
1222 /* Call the function. */
1224 result
= (*func
) (tp
, &walk_subtrees
, data
);
1226 /* If we found something, return it. */
1230 /* Even if we didn't, FUNC may have decided that there was nothing
1231 interesting below this point in the tree. */
1235 code
= TREE_CODE (*tp
);
1237 /* Handle common cases up front. */
1238 if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (code
))
1239 || TREE_CODE_CLASS (code
) == 'r'
1240 || TREE_CODE_CLASS (code
) == 's')
1244 /* Walk over all the sub-trees of this operand. */
1245 len
= first_rtl_op (code
);
1246 /* TARGET_EXPRs are peculiar: operands 1 and 3 can be the same.
1247 But, we only want to walk once. */
1248 if (code
== TARGET_EXPR
1249 && TREE_OPERAND (*tp
, 3) == TREE_OPERAND (*tp
, 1))
1251 /* Go through the subtrees. We need to do this in forward order so
1252 that the scope of a FOR_EXPR is handled properly. */
1253 for (i
= 0; i
< len
; ++i
)
1254 WALK_SUBTREE (TREE_OPERAND (*tp
, i
));
1256 /* For statements, we also walk the chain so that we cover the
1257 entire statement tree. */
1258 if (statement_code_p (code
))
1260 if (code
== DECL_STMT
1261 && DECL_STMT_DECL (*tp
)
1262 && TREE_CODE_CLASS (TREE_CODE (DECL_STMT_DECL (*tp
))) == 'd')
1264 /* Walk the DECL_INITIAL and DECL_SIZE. We don't want to walk
1265 into declarations that are just mentioned, rather than
1266 declared; they don't really belong to this part of the tree.
1267 And, we can see cycles: the initializer for a declaration can
1268 refer to the declaration itself. */
1269 WALK_SUBTREE (DECL_INITIAL (DECL_STMT_DECL (*tp
)));
1270 WALK_SUBTREE (DECL_SIZE (DECL_STMT_DECL (*tp
)));
1273 WALK_SUBTREE (TREE_CHAIN (*tp
));
1276 /* We didn't find what we were looking for. */
1279 else if (TREE_CODE_CLASS (code
) == 'd')
1281 WALK_SUBTREE (TREE_TYPE (*tp
));
1283 /* We didn't find what we were looking for. */
1287 /* Not one of the easy cases. We must explicitly go through the
1292 case IDENTIFIER_NODE
:
1297 case TEMPLATE_TEMPLATE_PARM
:
1298 case TEMPLATE_PARM_INDEX
:
1299 case TEMPLATE_TYPE_PARM
:
1309 /* None of thse have subtrees other than those already walked
1314 WALK_SUBTREE (TREE_TYPE (*tp
));
1318 case REFERENCE_TYPE
:
1319 WALK_SUBTREE (TREE_TYPE (*tp
));
1323 WALK_SUBTREE (TREE_PURPOSE (*tp
));
1324 WALK_SUBTREE (TREE_VALUE (*tp
));
1325 WALK_SUBTREE (TREE_CHAIN (*tp
));
1329 WALK_SUBTREE (OVL_FUNCTION (*tp
));
1330 WALK_SUBTREE (OVL_CHAIN (*tp
));
1335 int len
= TREE_VEC_LENGTH (*tp
);
1337 WALK_SUBTREE (TREE_VEC_ELT (*tp
, len
));
1342 WALK_SUBTREE (TREE_REALPART (*tp
));
1343 WALK_SUBTREE (TREE_IMAGPART (*tp
));
1347 WALK_SUBTREE (CONSTRUCTOR_ELTS (*tp
));
1351 WALK_SUBTREE (TYPE_METHOD_BASETYPE (*tp
));
1355 WALK_SUBTREE (TREE_TYPE (*tp
));
1356 WALK_SUBTREE (TYPE_ARG_TYPES (*tp
));
1360 WALK_SUBTREE (TREE_TYPE (*tp
));
1361 WALK_SUBTREE (TYPE_DOMAIN (*tp
));
1365 WALK_SUBTREE (TYPE_MIN_VALUE (*tp
));
1366 WALK_SUBTREE (TYPE_MAX_VALUE (*tp
));
1370 WALK_SUBTREE (TREE_TYPE (*tp
));
1371 WALK_SUBTREE (TYPE_OFFSET_BASETYPE (*tp
));
1375 if (TYPE_PTRMEMFUNC_P (*tp
))
1376 WALK_SUBTREE (TYPE_PTRMEMFUNC_FN_TYPE (*tp
));
1380 my_friendly_abort (19990803);
1383 /* We didn't find what we were looking for. */
1389 /* Passed to walk_tree. Checks for the use of types with no linkage. */
1392 no_linkage_helper (tp
, walk_subtrees
, data
)
1394 int *walk_subtrees ATTRIBUTE_UNUSED
;
1395 void *data ATTRIBUTE_UNUSED
;
1400 && (IS_AGGR_TYPE (t
) || TREE_CODE (t
) == ENUMERAL_TYPE
)
1401 && (decl_function_context (TYPE_MAIN_DECL (t
))
1402 || ANON_AGGRNAME_P (TYPE_IDENTIFIER (t
))))
1407 /* Check if the type T depends on a type with no linkage and if so, return
1411 no_linkage_check (t
)
1414 /* There's no point in checking linkage on template functions; we
1415 can't know their complete types. */
1416 if (processing_template_decl
)
1419 t
= walk_tree (&t
, no_linkage_helper
, NULL
);
1420 if (t
!= error_mark_node
)
1425 /* Passed to walk_tree. Copies the node pointed to, if appropriate. */
1428 copy_tree_r (tp
, walk_subtrees
, data
)
1431 void *data ATTRIBUTE_UNUSED
;
1433 enum tree_code code
= TREE_CODE (*tp
);
1435 /* We make copies of most nodes. */
1436 if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (code
))
1437 || TREE_CODE_CLASS (code
) == 'r'
1438 || TREE_CODE_CLASS (code
) == 'c'
1439 || TREE_CODE_CLASS (code
) == 's'
1440 || code
== PARM_DECL
1441 || code
== TREE_LIST
1443 || code
== OVERLOAD
)
1445 /* Because the chain gets clobbered when we make a copy, we save it
1447 tree chain
= TREE_CHAIN (*tp
);
1449 /* Copy the node. */
1450 *tp
= copy_node (*tp
);
1452 /* Now, restore the chain, if appropriate. That will cause
1453 walk_tree to walk into the chain as well. */
1454 if (code
== PARM_DECL
|| code
== TREE_LIST
|| code
== OVERLOAD
1455 || statement_code_p (code
))
1456 TREE_CHAIN (*tp
) = chain
;
1458 /* For now, we don't update BLOCKs when we make copies. So, we
1459 have to nullify all scope-statements. */
1460 if (TREE_CODE (*tp
) == SCOPE_STMT
)
1461 SCOPE_STMT_BLOCK (*tp
) = NULL_TREE
;
1463 else if (code
== TEMPLATE_TEMPLATE_PARM
)
1464 /* These must be copied specially. */
1465 *tp
= copy_template_template_parm (*tp
);
1466 else if (TREE_CODE_CLASS (code
) == 't')
1467 /* There's no need to copy types, or anything beneath them. */
1473 #ifdef GATHER_STATISTICS
1474 extern int depth_reached
;
1478 print_lang_statistics ()
1480 print_search_statistics ();
1481 print_class_statistics ();
1482 #ifdef GATHER_STATISTICS
1483 fprintf (stderr
, "maximum template instantiation depth reached: %d\n",
1488 /* Return, as an INTEGER_CST node, the number of elements for TYPE
1489 (which is an ARRAY_TYPE). This counts only elements of the top
1493 array_type_nelts_top (type
)
1496 return fold (build (PLUS_EXPR
, sizetype
,
1497 array_type_nelts (type
),
1501 /* Return, as an INTEGER_CST node, the number of elements for TYPE
1502 (which is an ARRAY_TYPE). This one is a recursive count of all
1503 ARRAY_TYPEs that are clumped together. */
1506 array_type_nelts_total (type
)
1509 tree sz
= array_type_nelts_top (type
);
1510 type
= TREE_TYPE (type
);
1511 while (TREE_CODE (type
) == ARRAY_TYPE
)
1513 tree n
= array_type_nelts_top (type
);
1514 sz
= fold (build (MULT_EXPR
, sizetype
, sz
, n
));
1515 type
= TREE_TYPE (type
);
1520 /* Called from break_out_target_exprs via mapcar. */
1523 bot_manip (tp
, walk_subtrees
, data
)
1528 splay_tree target_remap
= ((splay_tree
) data
);
1531 if (TREE_CODE (t
) != TREE_LIST
&& ! TREE_SIDE_EFFECTS (t
))
1533 /* There can't be any TARGET_EXPRs below this point. */
1537 else if (TREE_CODE (t
) == TARGET_EXPR
)
1541 if (TREE_CODE (TREE_OPERAND (t
, 1)) == AGGR_INIT_EXPR
)
1543 mark_used (TREE_OPERAND (TREE_OPERAND (TREE_OPERAND (t
, 1), 0), 0));
1545 (TREE_TYPE (t
), break_out_target_exprs (TREE_OPERAND (t
, 1)));
1552 var
= build (VAR_DECL
, TREE_TYPE (t
));
1553 DECL_CONTEXT (var
) = current_function_decl
;
1554 layout_decl (var
, 0);
1555 TREE_OPERAND (u
, 0) = var
;
1558 /* Map the old variable to the new one. */
1559 splay_tree_insert (target_remap
,
1560 (splay_tree_key
) TREE_OPERAND (t
, 0),
1561 (splay_tree_value
) TREE_OPERAND (u
, 0));
1563 /* Replace the old expression with the new version. */
1565 /* We don't have to go below this point; the recursive call to
1566 break_out_target_exprs will have handled anything below this
1571 else if (TREE_CODE (t
) == CALL_EXPR
)
1572 mark_used (TREE_OPERAND (TREE_OPERAND (t
, 0), 0));
1574 /* Make a copy of this node. */
1575 return copy_tree_r (tp
, walk_subtrees
, NULL
);
1578 /* Replace all remapped VAR_DECLs in T with their new equivalents.
1579 DATA is really a splay-tree mapping old variables to new
1583 bot_replace (t
, walk_subtrees
, data
)
1585 int *walk_subtrees ATTRIBUTE_UNUSED
;
1588 splay_tree target_remap
= ((splay_tree
) data
);
1590 if (TREE_CODE (*t
) == VAR_DECL
)
1592 splay_tree_node n
= splay_tree_lookup (target_remap
,
1593 (splay_tree_key
) *t
);
1595 *t
= (tree
) n
->value
;
1601 /* When we parse a default argument expression, we may create
1602 temporary variables via TARGET_EXPRs. When we actually use the
1603 default-argument expression, we make a copy of the expression, but
1604 we must replace the temporaries with appropriate local versions. */
1607 break_out_target_exprs (t
)
1610 static int target_remap_count
;
1611 static splay_tree target_remap
;
1613 if (!target_remap_count
++)
1614 target_remap
= splay_tree_new (splay_tree_compare_pointers
,
1615 /*splay_tree_delete_key_fn=*/NULL
,
1616 /*splay_tree_delete_value_fn=*/NULL
);
1617 walk_tree (&t
, bot_manip
, target_remap
);
1618 walk_tree (&t
, bot_replace
, target_remap
);
1620 if (!--target_remap_count
)
1622 splay_tree_delete (target_remap
);
1623 target_remap
= NULL
;
1629 /* Obstack used for allocating nodes in template function and variable
1632 /* Similar to `build_nt', except that we set TREE_COMPLEXITY to be the
1633 current line number. */
1636 build_min_nt
VPARAMS ((enum tree_code code
, ...))
1638 #ifndef ANSI_PROTOTYPES
1639 enum tree_code code
;
1643 register int length
;
1648 #ifndef ANSI_PROTOTYPES
1649 code
= va_arg (p
, enum tree_code
);
1652 t
= make_node (code
);
1653 length
= tree_code_length
[(int) code
];
1654 TREE_COMPLEXITY (t
) = lineno
;
1656 for (i
= 0; i
< length
; i
++)
1658 tree x
= va_arg (p
, tree
);
1659 TREE_OPERAND (t
, i
) = x
;
1666 /* Similar to `build', except we set TREE_COMPLEXITY to the current
1670 build_min
VPARAMS ((enum tree_code code
, tree tt
, ...))
1672 #ifndef ANSI_PROTOTYPES
1673 enum tree_code code
;
1678 register int length
;
1683 #ifndef ANSI_PROTOTYPES
1684 code
= va_arg (p
, enum tree_code
);
1685 tt
= va_arg (p
, tree
);
1688 t
= make_node (code
);
1689 length
= tree_code_length
[(int) code
];
1691 TREE_COMPLEXITY (t
) = lineno
;
1693 for (i
= 0; i
< length
; i
++)
1695 tree x
= va_arg (p
, tree
);
1696 TREE_OPERAND (t
, i
) = x
;
1703 /* Returns an INTEGER_CST (of type `int') corresponding to I.
1704 Multiple calls with the same value of I may or may not yield the
1705 same node; therefore, callers should never modify the node
1709 build_shared_int_cst (i
)
1712 static tree cache
[256];
1715 return build_int_2 (i
, 0);
1718 cache
[i
] = build_int_2 (i
, 0);
1727 if (TREE_CODE (t
) == TYPE_DECL
)
1729 if (TREE_CODE_CLASS (TREE_CODE (t
)) == 't')
1730 return TYPE_STUB_DECL (t
);
1732 my_friendly_abort (42);
1734 /* Stop compiler from complaining control reaches end of non-void function. */
1739 can_free (obstack
, t
)
1740 struct obstack
*obstack
;
1745 if (TREE_CODE (t
) == TREE_VEC
)
1746 size
= (TREE_VEC_LENGTH (t
)-1) * sizeof (tree
) + sizeof (struct tree_vec
);
1748 my_friendly_abort (42);
1750 #define ROUND(x) ((x + obstack_alignment_mask (obstack)) \
1751 & ~ obstack_alignment_mask (obstack))
1752 if ((char *)t
+ ROUND (size
) == obstack_next_free (obstack
))
1759 /* Return first vector element whose BINFO_TYPE is ELEM.
1760 Return 0 if ELEM is not in VEC. VEC may be NULL_TREE. */
1763 vec_binfo_member (elem
, vec
)
1769 for (i
= 0; i
< TREE_VEC_LENGTH (vec
); ++i
)
1770 if (same_type_p (elem
, BINFO_TYPE (TREE_VEC_ELT (vec
, i
))))
1771 return TREE_VEC_ELT (vec
, i
);
1776 /* Returns the namespace that contains DECL, whether directly or
1780 decl_namespace_context (decl
)
1785 if (TREE_CODE (decl
) == NAMESPACE_DECL
)
1787 else if (TYPE_P (decl
))
1788 decl
= CP_DECL_CONTEXT (TYPE_MAIN_DECL (decl
));
1790 decl
= CP_DECL_CONTEXT (decl
);
1794 /* Return truthvalue of whether T1 is the same tree structure as T2.
1795 Return 1 if they are the same.
1796 Return 0 if they are understandably different.
1797 Return -1 if either contains tree structure not understood by
1801 cp_tree_equal (t1
, t2
)
1804 register enum tree_code code1
, code2
;
1809 if (t1
== 0 || t2
== 0)
1812 code1
= TREE_CODE (t1
);
1813 code2
= TREE_CODE (t2
);
1815 if (code1
== NOP_EXPR
|| code1
== CONVERT_EXPR
|| code1
== NON_LVALUE_EXPR
)
1817 if (code2
== NOP_EXPR
|| code2
== CONVERT_EXPR
|| code2
== NON_LVALUE_EXPR
)
1818 return cp_tree_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
1820 return cp_tree_equal (TREE_OPERAND (t1
, 0), t2
);
1822 else if (code2
== NOP_EXPR
|| code2
== CONVERT_EXPR
1823 || code2
== NON_LVALUE_EXPR
)
1824 return cp_tree_equal (t1
, TREE_OPERAND (t2
, 0));
1832 return TREE_INT_CST_LOW (t1
) == TREE_INT_CST_LOW (t2
)
1833 && TREE_INT_CST_HIGH (t1
) == TREE_INT_CST_HIGH (t2
);
1836 return REAL_VALUES_EQUAL (TREE_REAL_CST (t1
), TREE_REAL_CST (t2
));
1839 return TREE_STRING_LENGTH (t1
) == TREE_STRING_LENGTH (t2
)
1840 && !bcmp (TREE_STRING_POINTER (t1
), TREE_STRING_POINTER (t2
),
1841 TREE_STRING_LENGTH (t1
));
1844 /* We need to do this when determining whether or not two
1845 non-type pointer to member function template arguments
1847 if (!(same_type_p (TREE_TYPE (t1
), TREE_TYPE (t2
))
1848 /* The first operand is RTL. */
1849 && TREE_OPERAND (t1
, 0) == TREE_OPERAND (t2
, 0)))
1851 return cp_tree_equal (TREE_OPERAND (t1
, 1), TREE_OPERAND (t2
, 1));
1854 cmp
= cp_tree_equal (TREE_PURPOSE (t1
), TREE_PURPOSE (t2
));
1857 cmp
= cp_tree_equal (TREE_VALUE (t1
), TREE_VALUE (t2
));
1860 return cp_tree_equal (TREE_CHAIN (t1
), TREE_CHAIN (t2
));
1863 return cp_tree_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
1866 cmp
= cp_tree_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
1869 return simple_cst_list_equal (TREE_OPERAND (t1
, 1), TREE_OPERAND (t2
, 1));
1872 /* Special case: if either target is an unallocated VAR_DECL,
1873 it means that it's going to be unified with whatever the
1874 TARGET_EXPR is really supposed to initialize, so treat it
1875 as being equivalent to anything. */
1876 if ((TREE_CODE (TREE_OPERAND (t1
, 0)) == VAR_DECL
1877 && DECL_NAME (TREE_OPERAND (t1
, 0)) == NULL_TREE
1878 && DECL_RTL (TREE_OPERAND (t1
, 0)) == 0)
1879 || (TREE_CODE (TREE_OPERAND (t2
, 0)) == VAR_DECL
1880 && DECL_NAME (TREE_OPERAND (t2
, 0)) == NULL_TREE
1881 && DECL_RTL (TREE_OPERAND (t2
, 0)) == 0))
1884 cmp
= cp_tree_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
1887 return cp_tree_equal (TREE_OPERAND (t1
, 1), TREE_OPERAND (t2
, 1));
1889 case WITH_CLEANUP_EXPR
:
1890 cmp
= cp_tree_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
1893 return cp_tree_equal (TREE_OPERAND (t1
, 2), TREE_OPERAND (t1
, 2));
1896 if (TREE_OPERAND (t1
, 1) == TREE_OPERAND (t2
, 1))
1897 return cp_tree_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
1906 case TEMPLATE_PARM_INDEX
:
1907 return TEMPLATE_PARM_IDX (t1
) == TEMPLATE_PARM_IDX (t2
)
1908 && TEMPLATE_PARM_LEVEL (t1
) == TEMPLATE_PARM_LEVEL (t2
);
1912 if (TREE_CODE (TREE_OPERAND (t1
, 0)) != TREE_CODE (TREE_OPERAND (t2
, 0)))
1914 if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (t1
, 0))) == 't')
1915 return same_type_p (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
1919 /* Two pointer-to-members are the same if they point to the same
1920 field or function in the same class. */
1921 return (PTRMEM_CST_MEMBER (t1
) == PTRMEM_CST_MEMBER (t2
)
1922 && same_type_p (PTRMEM_CST_CLASS (t1
), PTRMEM_CST_CLASS (t2
)));
1928 switch (TREE_CODE_CLASS (code1
))
1938 for (i
=0; i
<tree_code_length
[(int) code1
]; ++i
)
1940 cmp
= cp_tree_equal (TREE_OPERAND (t1
, i
), TREE_OPERAND (t2
, i
));
1950 /* Build a wrapper around some pointer PTR so we can use it as a tree. */
1953 build_ptr_wrapper (ptr
)
1956 tree t
= make_node (WRAPPER
);
1957 WRAPPER_PTR (t
) = ptr
;
1961 /* Same, but on the expression_obstack. */
1964 build_expr_ptr_wrapper (ptr
)
1967 return build_ptr_wrapper (ptr
);
1970 /* Build a wrapper around some integer I so we can use it as a tree. */
1973 build_int_wrapper (i
)
1976 tree t
= make_node (WRAPPER
);
1977 WRAPPER_INT (t
) = i
;
1982 build_srcloc (file
, line
)
1988 t
= make_node (SRCLOC
);
1989 SRCLOC_FILE (t
) = file
;
1990 SRCLOC_LINE (t
) = line
;
1996 build_srcloc_here ()
1998 return build_srcloc (input_filename
, lineno
);
2001 /* The type of ARG when used as an lvalue. */
2007 tree type
= TREE_TYPE (arg
);
2008 if (TREE_CODE (arg
) == OVERLOAD
)
2009 type
= unknown_type_node
;
2013 /* The type of ARG for printing error messages; denote lvalues with
2020 tree type
= TREE_TYPE (arg
);
2021 if (TREE_CODE (type
) == ARRAY_TYPE
)
2023 else if (real_lvalue_p (arg
))
2024 type
= build_reference_type (lvalue_type (arg
));
2025 else if (IS_AGGR_TYPE (type
))
2026 type
= lvalue_type (arg
);
2031 /* Does FUNCTION use a variable-length argument list? */
2034 varargs_function_p (function
)
2037 tree parm
= TYPE_ARG_TYPES (TREE_TYPE (function
));
2038 for (; parm
; parm
= TREE_CHAIN (parm
))
2039 if (TREE_VALUE (parm
) == void_type_node
)
2044 /* Returns 1 if decl is a member of a class. */
2050 tree ctx
= DECL_CONTEXT (decl
);
2051 return (ctx
&& TREE_CODE_CLASS (TREE_CODE (ctx
)) == 't');
2054 /* Create a placeholder for member access where we don't actually have an
2055 object that the access is against. */
2058 build_dummy_object (type
)
2061 tree decl
= build1 (NOP_EXPR
, build_pointer_type (type
), void_zero_node
);
2062 return build_indirect_ref (decl
, NULL_PTR
);
2065 /* We've gotten a reference to a member of TYPE. Return *this if appropriate,
2066 or a dummy object otherwise. If BINFOP is non-0, it is filled with the
2067 binfo path from current_class_type to TYPE, or 0. */
2070 maybe_dummy_object (type
, binfop
)
2076 if (current_class_type
2077 && get_base_distance (type
, current_class_type
, 0, binfop
) != -1)
2078 context
= current_class_type
;
2081 /* Reference from a nested class member function. */
2084 *binfop
= TYPE_BINFO (type
);
2087 if (current_class_ref
&& context
== current_class_type
)
2088 decl
= current_class_ref
;
2090 decl
= build_dummy_object (context
);
2095 /* Returns 1 if OB is a placeholder object, or a pointer to one. */
2098 is_dummy_object (ob
)
2101 if (TREE_CODE (ob
) == INDIRECT_REF
)
2102 ob
= TREE_OPERAND (ob
, 0);
2103 return (TREE_CODE (ob
) == NOP_EXPR
2104 && TREE_OPERAND (ob
, 0) == void_zero_node
);
2107 /* Returns 1 iff type T is a POD type, as defined in [basic.types]. */
2113 while (TREE_CODE (t
) == ARRAY_TYPE
)
2116 if (INTEGRAL_TYPE_P (t
))
2117 return 1; /* integral, character or enumeral type */
2118 if (FLOAT_TYPE_P (t
))
2121 return 1; /* pointer to non-member */
2122 if (TYPE_PTRMEM_P (t
))
2123 return 1; /* pointer to member object */
2124 if (TYPE_PTRMEMFUNC_P (t
))
2125 return 1; /* pointer to member function */
2127 if (! CLASS_TYPE_P (t
))
2128 return 0; /* other non-class type (reference or function) */
2129 if (CLASSTYPE_NON_POD_P (t
))
2134 /* Return a 1 if ATTR_NAME and ATTR_ARGS denote a valid C++-specific
2135 attribute for either declaration DECL or type TYPE and 0 otherwise.
2136 Plugged into valid_lang_attribute. */
2139 cp_valid_lang_attribute (attr_name
, attr_args
, decl
, type
)
2141 tree attr_args ATTRIBUTE_UNUSED
;
2142 tree decl ATTRIBUTE_UNUSED
;
2143 tree type ATTRIBUTE_UNUSED
;
2145 if (is_attribute_p ("com_interface", attr_name
))
2147 if (! flag_vtable_thunks
)
2149 error ("`com_interface' only supported with -fvtable-thunks");
2153 if (attr_args
!= NULL_TREE
2154 || decl
!= NULL_TREE
2155 || ! CLASS_TYPE_P (type
)
2156 || type
!= TYPE_MAIN_VARIANT (type
))
2158 warning ("`com_interface' attribute can only be applied to class definitions");
2162 CLASSTYPE_COM_INTERFACE (type
) = 1;
2165 else if (is_attribute_p ("init_priority", attr_name
))
2167 tree initp_expr
= (attr_args
? TREE_VALUE (attr_args
): NULL_TREE
);
2171 STRIP_NOPS (initp_expr
);
2173 if (!initp_expr
|| TREE_CODE (initp_expr
) != INTEGER_CST
)
2175 error ("requested init_priority is not an integer constant");
2179 pri
= TREE_INT_CST_LOW (initp_expr
);
2181 while (TREE_CODE (type
) == ARRAY_TYPE
)
2182 type
= TREE_TYPE (type
);
2184 if (decl
== NULL_TREE
2185 || TREE_CODE (decl
) != VAR_DECL
2186 || ! TREE_STATIC (decl
)
2187 || DECL_EXTERNAL (decl
)
2188 || (TREE_CODE (type
) != RECORD_TYPE
2189 && TREE_CODE (type
) != UNION_TYPE
)
2190 /* Static objects in functions are initialized the
2191 first time control passes through that
2192 function. This is not precise enough to pin down an
2193 init_priority value, so don't allow it. */
2194 || current_function_decl
)
2196 error ("can only use init_priority attribute on file-scope definitions of objects of class type");
2200 if (pri
> MAX_INIT_PRIORITY
|| pri
<= 0)
2202 error ("requested init_priority is out of range");
2206 /* Check for init_priorities that are reserved for
2207 language and runtime support implementations.*/
2208 if (pri
<= MAX_RESERVED_INIT_PRIORITY
)
2211 ("requested init_priority is reserved for internal use");
2214 DECL_INIT_PRIORITY (decl
) = pri
;
2221 /* Return a new PTRMEM_CST of the indicated TYPE. The MEMBER is the
2222 thing pointed to by the constant. */
2225 make_ptrmem_cst (type
, member
)
2229 tree ptrmem_cst
= make_node (PTRMEM_CST
);
2230 /* If would seem a great convenience if make_node would set
2231 TREE_CONSTANT for things of class `c', but it does not. */
2232 TREE_CONSTANT (ptrmem_cst
) = 1;
2233 TREE_TYPE (ptrmem_cst
) = type
;
2234 PTRMEM_CST_MEMBER (ptrmem_cst
) = member
;
2238 /* Mark ARG (which is really a list_hash_table **) for GC. */
2241 mark_list_hash (arg
)
2244 struct list_hash
*lh
;
2246 for (lh
= * ((struct list_hash
**) arg
); lh
; lh
= lh
->next
)
2247 ggc_mark_tree (lh
->list
);
2250 /* Initialize tree.c. */
2255 make_lang_type_fn
= cp_make_lang_type
;
2256 lang_unsave
= cp_unsave
;
2257 ggc_add_root (list_hash_table
,
2258 sizeof (list_hash_table
) / sizeof (struct list_hash
*),
2259 sizeof (struct list_hash
*),
2263 /* The SAVE_EXPR pointed to by TP is being copied. If ST contains
2264 information indicating to what new SAVE_EXPR this one should be
2265 mapped, use that one. Otherwise, create a new node and enter it in
2266 ST. FN is the function into which the copy will be placed. */
2269 remap_save_expr (tp
, st
, fn
, walk_subtrees
)
2277 /* See if we already encountered this SAVE_EXPR. */
2278 n
= splay_tree_lookup (st
, (splay_tree_key
) *tp
);
2280 /* If we didn't already remap this SAVE_EXPR, do so now. */
2283 tree t
= copy_node (*tp
);
2285 /* The SAVE_EXPR is now part of the function into which we
2286 are inlining this body. */
2287 SAVE_EXPR_CONTEXT (t
) = fn
;
2288 /* And we haven't evaluated it yet. */
2289 SAVE_EXPR_RTL (t
) = NULL_RTX
;
2290 /* Remember this SAVE_EXPR. */
2291 n
= splay_tree_insert (st
,
2292 (splay_tree_key
) *tp
,
2293 (splay_tree_value
) t
);
2296 /* We've already walked into this SAVE_EXPR, so we needn't do it
2300 /* Replace this SAVE_EXPR with the copy. */
2301 *tp
= (tree
) n
->value
;
2304 /* Called via walk_tree. If *TP points to a DECL_STMT for a local
2305 declaration, copies the declaration and enters it in the splay_tree
2306 pointed to by DATA (which is really a `splay_tree *'). */
2309 mark_local_for_remap_r (tp
, walk_subtrees
, data
)
2311 int *walk_subtrees ATTRIBUTE_UNUSED
;
2315 splay_tree st
= (splay_tree
) data
;
2317 if ((TREE_CODE (t
) == DECL_STMT
2318 && nonstatic_local_decl_p (DECL_STMT_DECL (t
)))
2319 || TREE_CODE (t
) == LABEL_STMT
)
2324 /* Figure out what's being declared. */
2325 decl
= (TREE_CODE (t
) == DECL_STMT
2326 ? DECL_STMT_DECL (t
) : LABEL_STMT_LABEL (t
));
2329 copy
= copy_decl_for_inlining (decl
,
2330 DECL_CONTEXT (decl
),
2331 DECL_CONTEXT (decl
));
2333 /* Remember the copy. */
2334 splay_tree_insert (st
,
2335 (splay_tree_key
) decl
,
2336 (splay_tree_value
) copy
);
2342 /* Called via walk_tree when an expression is unsaved. Using the
2343 splay_tree pointed to by ST (which is really a `splay_tree *'),
2344 remaps all local declarations to appropriate replacements. */
2347 cp_unsave_r (tp
, walk_subtrees
, data
)
2352 splay_tree st
= (splay_tree
) data
;
2355 /* Only a local declaration (variable or label). */
2356 if (nonstatic_local_decl_p (*tp
))
2358 /* Lookup the declaration. */
2359 n
= splay_tree_lookup (st
, (splay_tree_key
) *tp
);
2361 /* If it's there, remap it. */
2363 *tp
= (tree
) n
->value
;
2365 else if (TREE_CODE (*tp
) == SAVE_EXPR
)
2366 remap_save_expr (tp
, st
, current_function_decl
, walk_subtrees
);
2369 copy_tree_r (tp
, walk_subtrees
, NULL
);
2371 /* Do whatever unsaving is required. */
2372 unsave_expr_1 (*tp
);
2375 /* Keep iterating. */
2379 /* Called by unsave_expr_now whenever an expression (*TP) needs to be
2388 /* Create a splay-tree to map old local variable declarations to new
2390 st
= splay_tree_new (splay_tree_compare_pointers
, NULL
, NULL
);
2392 /* Walk the tree once figuring out what needs to be remapped. */
2393 walk_tree (tp
, mark_local_for_remap_r
, st
);
2395 /* Walk the tree again, copying, remapping, and unsaving. */
2396 walk_tree (tp
, cp_unsave_r
, st
);
2399 splay_tree_delete (st
);