1 /* Language-dependent node constructors for parse phase of GNU compiler.
2 Copyright (C) 1987, 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001 Free Software Foundation, Inc.
4 Hacked by Michael Tiemann (tiemann@cygnus.com)
6 This file is part of GNU CC.
8 GNU CC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GNU CC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU CC; see the file COPYING. If not, write to
20 the Free Software Foundation, 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
32 #include "insn-config.h"
33 #include "integrate.h"
34 #include "tree-inline.h"
36 static tree bot_manip
PARAMS ((tree
*, int *, void *));
37 static tree bot_replace
PARAMS ((tree
*, int *, void *));
38 static tree build_cplus_array_type_1
PARAMS ((tree
, tree
));
39 static int list_hash_eq
PARAMS ((const void *, const void *));
40 static hashval_t list_hash_pieces
PARAMS ((tree
, tree
, tree
));
41 static hashval_t list_hash
PARAMS ((const void *));
42 static cp_lvalue_kind lvalue_p_1
PARAMS ((tree
, int));
43 static tree no_linkage_helper
PARAMS ((tree
*, int *, void *));
44 static tree build_srcloc
PARAMS ((const char *, int));
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
));
49 static tree count_trees_r
PARAMS ((tree
*, int *, void *));
50 static tree verify_stmt_tree_r
PARAMS ((tree
*, int *, void *));
51 static tree find_tree_r
PARAMS ((tree
*, int *, void *));
52 extern int cp_statement_code_p
PARAMS ((enum tree_code
));
54 static tree handle_java_interface_attribute
PARAMS ((tree
*, tree
, tree
, int, bool *));
55 static tree handle_com_interface_attribute
PARAMS ((tree
*, tree
, tree
, int, bool *));
56 static tree handle_init_priority_attribute
PARAMS ((tree
*, tree
, tree
, int, bool *));
58 /* If REF is an lvalue, returns the kind of lvalue that REF is.
59 Otherwise, returns clk_none. If TREAT_CLASS_RVALUES_AS_LVALUES is
60 non-zero, rvalues of class type are considered lvalues. */
63 lvalue_p_1 (ref
, treat_class_rvalues_as_lvalues
)
65 int treat_class_rvalues_as_lvalues
;
67 cp_lvalue_kind op1_lvalue_kind
= clk_none
;
68 cp_lvalue_kind op2_lvalue_kind
= clk_none
;
70 if (TREE_CODE (TREE_TYPE (ref
)) == REFERENCE_TYPE
)
73 if (ref
== current_class_ptr
)
76 switch (TREE_CODE (ref
))
78 /* preincrements and predecrements are valid lvals, provided
79 what they refer to are valid lvals. */
80 case PREINCREMENT_EXPR
:
81 case PREDECREMENT_EXPR
:
85 case WITH_CLEANUP_EXPR
:
88 /* This shouldn't be here, but there are lots of places in the compiler
89 that are sloppy about tacking on NOP_EXPRs to the same type when
90 no actual conversion is happening. */
92 return lvalue_p_1 (TREE_OPERAND (ref
, 0),
93 treat_class_rvalues_as_lvalues
);
96 op1_lvalue_kind
= lvalue_p_1 (TREE_OPERAND (ref
, 0),
97 treat_class_rvalues_as_lvalues
);
99 /* The "field" can be a FUNCTION_DECL or an OVERLOAD in some
101 && TREE_CODE (TREE_OPERAND (ref
, 1)) == FIELD_DECL
102 && DECL_C_BIT_FIELD (TREE_OPERAND (ref
, 1)))
104 /* Clear the ordinary bit. If this object was a class
105 rvalue we want to preserve that information. */
106 op1_lvalue_kind
&= ~clk_ordinary
;
107 /* The lvalue is for a btifield. */
108 op1_lvalue_kind
|= clk_bitfield
;
110 return op1_lvalue_kind
;
116 if (TREE_READONLY (ref
) && ! TREE_STATIC (ref
)
117 && DECL_LANG_SPECIFIC (ref
)
118 && DECL_IN_AGGR_P (ref
))
124 if (TREE_CODE (TREE_TYPE (ref
)) != METHOD_TYPE
)
128 /* A currently unresolved scope ref. */
130 my_friendly_abort (103);
132 if (TREE_CODE (TREE_OPERAND (ref
, 1)) == FUNCTION_DECL
)
137 op1_lvalue_kind
= lvalue_p_1 (TREE_OPERAND (ref
, 0),
138 treat_class_rvalues_as_lvalues
);
139 op2_lvalue_kind
= lvalue_p_1 (TREE_OPERAND (ref
, 1),
140 treat_class_rvalues_as_lvalues
);
144 op1_lvalue_kind
= lvalue_p_1 (TREE_OPERAND (ref
, 1),
145 treat_class_rvalues_as_lvalues
);
146 op2_lvalue_kind
= lvalue_p_1 (TREE_OPERAND (ref
, 2),
147 treat_class_rvalues_as_lvalues
);
154 return lvalue_p_1 (TREE_OPERAND (ref
, 1),
155 treat_class_rvalues_as_lvalues
);
158 return treat_class_rvalues_as_lvalues
? clk_class
: clk_none
;
162 return ((treat_class_rvalues_as_lvalues
163 && IS_AGGR_TYPE (TREE_TYPE (ref
)))
164 ? clk_class
: clk_none
);
167 /* All functions (except non-static-member functions) are
169 return (DECL_NONSTATIC_MEMBER_FUNCTION_P (ref
)
170 ? clk_none
: clk_ordinary
);
176 /* If one operand is not an lvalue at all, then this expression is
178 if (!op1_lvalue_kind
|| !op2_lvalue_kind
)
181 /* Otherwise, it's an lvalue, and it has all the odd properties
182 contributed by either operand. */
183 op1_lvalue_kind
= op1_lvalue_kind
| op2_lvalue_kind
;
184 /* It's not an ordinary lvalue if it involves either a bit-field or
186 if ((op1_lvalue_kind
& ~clk_ordinary
) != clk_none
)
187 op1_lvalue_kind
&= ~clk_ordinary
;
188 return op1_lvalue_kind
;
191 /* If REF is an lvalue, returns the kind of lvalue that REF is.
192 Otherwise, returns clk_none. Lvalues can be assigned, unless they
193 have TREE_READONLY, or unless they are FUNCTION_DECLs. Lvalues can
194 have their address taken, unless they have DECL_REGISTER. */
200 return lvalue_p_1 (ref
, /*treat_class_rvalues_as_lvalues=*/0);
203 /* This differs from real_lvalue_p in that class rvalues are
204 considered lvalues. */
211 (lvalue_p_1 (ref
, /*treat_class_rvalues_as_lvalues=*/1) != clk_none
);
214 /* Return nonzero if REF is an lvalue valid for this language;
215 otherwise, print an error message and return zero. */
218 lvalue_or_else (ref
, string
)
222 int win
= lvalue_p (ref
);
224 error ("non-lvalue in %s", string
);
228 /* Build a TARGET_EXPR, initializing the DECL with the VALUE. */
231 build_target_expr (decl
, value
)
237 t
= build (TARGET_EXPR
, TREE_TYPE (decl
), decl
, value
,
238 maybe_build_cleanup (decl
), NULL_TREE
);
239 /* We always set TREE_SIDE_EFFECTS so that expand_expr does not
240 ignore the TARGET_EXPR. If there really turn out to be no
241 side-effects, then the optimizer should be able to get rid of
242 whatever code is generated anyhow. */
243 TREE_SIDE_EFFECTS (t
) = 1;
248 /* INIT is a CALL_EXPR which needs info about its target.
249 TYPE is the type that this initialization should appear to have.
251 Build an encapsulation of the initialization to perform
252 and return it so that it can be processed by language-independent
253 and language-specific expression expanders. */
256 build_cplus_new (type
, init
)
264 /* Make sure that we're not trying to create an instance of an
266 abstract_virtuals_error (NULL_TREE
, type
);
268 if (TREE_CODE (init
) != CALL_EXPR
&& TREE_CODE (init
) != AGGR_INIT_EXPR
)
269 return convert (type
, init
);
271 slot
= build (VAR_DECL
, type
);
272 DECL_ARTIFICIAL (slot
) = 1;
273 DECL_CONTEXT (slot
) = current_function_decl
;
274 layout_decl (slot
, 0);
276 /* We split the CALL_EXPR into its function and its arguments here.
277 Then, in expand_expr, we put them back together. The reason for
278 this is that this expression might be a default argument
279 expression. In that case, we need a new temporary every time the
280 expression is used. That's what break_out_target_exprs does; it
281 replaces every AGGR_INIT_EXPR with a copy that uses a fresh
282 temporary slot. Then, expand_expr builds up a call-expression
283 using the new slot. */
284 fn
= TREE_OPERAND (init
, 0);
285 rval
= build (AGGR_INIT_EXPR
, type
, fn
, TREE_OPERAND (init
, 1), slot
);
286 TREE_SIDE_EFFECTS (rval
) = 1;
287 AGGR_INIT_VIA_CTOR_P (rval
)
288 = (TREE_CODE (fn
) == ADDR_EXPR
289 && TREE_CODE (TREE_OPERAND (fn
, 0)) == FUNCTION_DECL
290 && DECL_CONSTRUCTOR_P (TREE_OPERAND (fn
, 0)));
291 rval
= build_target_expr (slot
, rval
);
296 /* Buidl a TARGET_EXPR using INIT to initialize a new temporary of the
300 build_target_expr_with_type (init
, type
)
307 if (TREE_CODE (init
) == TARGET_EXPR
)
310 slot
= build (VAR_DECL
, type
);
311 DECL_ARTIFICIAL (slot
) = 1;
312 DECL_CONTEXT (slot
) = current_function_decl
;
313 layout_decl (slot
, 0);
314 rval
= build_target_expr (slot
, init
);
319 /* Like build_target_expr_with_type, but use the type of INIT. */
322 get_target_expr (init
)
325 return build_target_expr_with_type (init
, TREE_TYPE (init
));
328 /* Recursively perform a preorder search EXP for CALL_EXPRs, making
329 copies where they are found. Returns a deep copy all nodes transitively
330 containing CALL_EXPRs. */
333 break_out_calls (exp
)
336 register tree t1
, t2
= NULL_TREE
;
337 register enum tree_code code
;
338 register int changed
= 0;
341 if (exp
== NULL_TREE
)
344 code
= TREE_CODE (exp
);
346 if (code
== CALL_EXPR
)
347 return copy_node (exp
);
349 /* Don't try and defeat a save_expr, as it should only be done once. */
350 if (code
== SAVE_EXPR
)
353 switch (TREE_CODE_CLASS (code
))
358 case 'c': /* a constant */
359 case 't': /* a type node */
360 case 'x': /* something random, like an identifier or an ERROR_MARK. */
363 case 'd': /* A decl node */
364 #if 0 /* This is bogus. jason 9/21/94 */
366 t1
= break_out_calls (DECL_INITIAL (exp
));
367 if (t1
!= DECL_INITIAL (exp
))
369 exp
= copy_node (exp
);
370 DECL_INITIAL (exp
) = t1
;
375 case 'b': /* A block node */
377 /* Don't know how to handle these correctly yet. Must do a
378 break_out_calls on all DECL_INITIAL values for local variables,
379 and also break_out_calls on all sub-blocks and sub-statements. */
384 case 'e': /* an expression */
385 case 'r': /* a reference */
386 case 's': /* an expression with side effects */
387 for (i
= TREE_CODE_LENGTH (code
) - 1; i
>= 0; i
--)
389 t1
= break_out_calls (TREE_OPERAND (exp
, i
));
390 if (t1
!= TREE_OPERAND (exp
, i
))
392 exp
= copy_node (exp
);
393 TREE_OPERAND (exp
, i
) = t1
;
398 case '<': /* a comparison expression */
399 case '2': /* a binary arithmetic expression */
400 t2
= break_out_calls (TREE_OPERAND (exp
, 1));
401 if (t2
!= TREE_OPERAND (exp
, 1))
403 case '1': /* a unary arithmetic expression */
404 t1
= break_out_calls (TREE_OPERAND (exp
, 0));
405 if (t1
!= TREE_OPERAND (exp
, 0))
409 if (TREE_CODE_LENGTH (code
) == 1)
410 return build1 (code
, TREE_TYPE (exp
), t1
);
412 return build (code
, TREE_TYPE (exp
), t1
, t2
);
419 /* Construct, lay out and return the type of methods belonging to class
420 BASETYPE and whose arguments are described by ARGTYPES and whose values
421 are described by RETTYPE. If each type exists already, reuse it. */
424 build_cplus_method_type (basetype
, rettype
, argtypes
)
425 tree basetype
, rettype
, argtypes
;
431 /* Make a node of the sort we want. */
432 t
= make_node (METHOD_TYPE
);
434 TYPE_METHOD_BASETYPE (t
) = TYPE_MAIN_VARIANT (basetype
);
435 TREE_TYPE (t
) = rettype
;
436 ptype
= build_pointer_type (basetype
);
438 /* The actual arglist for this function includes a "hidden" argument
439 which is "this". Put it into the list of argument types. */
440 argtypes
= tree_cons (NULL_TREE
, ptype
, argtypes
);
441 TYPE_ARG_TYPES (t
) = argtypes
;
442 TREE_SIDE_EFFECTS (argtypes
) = 1; /* Mark first argtype as "artificial". */
444 /* If we already have such a type, use the old one and free this one.
445 Note that it also frees up the above cons cell if found. */
446 hashcode
= TYPE_HASH (basetype
) + TYPE_HASH (rettype
) +
447 type_hash_list (argtypes
);
449 t
= type_hash_canon (hashcode
, t
);
451 if (!COMPLETE_TYPE_P (t
))
458 build_cplus_array_type_1 (elt_type
, index_type
)
464 if (elt_type
== error_mark_node
|| index_type
== error_mark_node
)
465 return error_mark_node
;
467 if (processing_template_decl
468 || uses_template_parms (elt_type
)
469 || uses_template_parms (index_type
))
471 t
= make_node (ARRAY_TYPE
);
472 TREE_TYPE (t
) = elt_type
;
473 TYPE_DOMAIN (t
) = index_type
;
476 t
= build_array_type (elt_type
, index_type
);
478 /* Push these needs up so that initialization takes place
480 TYPE_NEEDS_CONSTRUCTING (t
)
481 = TYPE_NEEDS_CONSTRUCTING (TYPE_MAIN_VARIANT (elt_type
));
482 TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t
)
483 = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TYPE_MAIN_VARIANT (elt_type
));
488 build_cplus_array_type (elt_type
, index_type
)
493 int type_quals
= CP_TYPE_QUALS (elt_type
);
495 if (type_quals
!= TYPE_UNQUALIFIED
)
496 elt_type
= cp_build_qualified_type (elt_type
, TYPE_UNQUALIFIED
);
498 t
= build_cplus_array_type_1 (elt_type
, index_type
);
500 if (type_quals
!= TYPE_UNQUALIFIED
)
501 t
= cp_build_qualified_type (t
, type_quals
);
506 /* Make a variant of TYPE, qualified with the TYPE_QUALS. Handles
507 arrays correctly. In particular, if TYPE is an array of T's, and
508 TYPE_QUALS is non-empty, returns an array of qualified T's. If
509 at attempt is made to qualify a type illegally, and COMPLAIN is
510 non-zero, an error is issued. If COMPLAIN is zero, error_mark_node
514 cp_build_qualified_type_real (type
, type_quals
, complain
)
521 if (type
== error_mark_node
)
524 if (type_quals
== CP_TYPE_QUALS (type
))
527 /* A restrict-qualified pointer type must be a pointer (or reference)
528 to object or incomplete type. */
529 if ((type_quals
& TYPE_QUAL_RESTRICT
)
530 && TREE_CODE (type
) != TEMPLATE_TYPE_PARM
531 && (!POINTER_TYPE_P (type
)
532 || TYPE_PTRMEM_P (type
)
533 || TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
))
536 cp_error ("`%T' cannot be `restrict'-qualified", type
);
538 return error_mark_node
;
540 type_quals
&= ~TYPE_QUAL_RESTRICT
;
543 if (type_quals
!= TYPE_UNQUALIFIED
544 && TREE_CODE (type
) == FUNCTION_TYPE
)
547 cp_error ("`%T' cannot be `const'-, `volatile'-, or `restrict'-qualified", type
);
549 return error_mark_node
;
550 type_quals
= TYPE_UNQUALIFIED
;
552 else if (TREE_CODE (type
) == ARRAY_TYPE
)
554 /* In C++, the qualification really applies to the array element
555 type. Obtain the appropriately qualified element type. */
558 = cp_build_qualified_type_real (TREE_TYPE (type
),
562 if (element_type
== error_mark_node
)
563 return error_mark_node
;
565 /* See if we already have an identically qualified type. */
566 t
= get_qualified_type (type
, type_quals
);
568 /* If we didn't already have it, create it now. */
571 /* Make a new array type, just like the old one, but with the
572 appropriately qualified element type. */
573 t
= build_type_copy (type
);
574 TREE_TYPE (t
) = element_type
;
577 /* Even if we already had this variant, we update
578 TYPE_NEEDS_CONSTRUCTING and TYPE_HAS_NONTRIVIAL_DESTRUCTOR in case
579 they changed since the variant was originally created.
581 This seems hokey; if there is some way to use a previous
582 variant *without* coming through here,
583 TYPE_NEEDS_CONSTRUCTING will never be updated. */
584 TYPE_NEEDS_CONSTRUCTING (t
)
585 = TYPE_NEEDS_CONSTRUCTING (TYPE_MAIN_VARIANT (element_type
));
586 TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t
)
587 = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TYPE_MAIN_VARIANT (element_type
));
590 else if (TYPE_PTRMEMFUNC_P (type
))
592 /* For a pointer-to-member type, we can't just return a
593 cv-qualified version of the RECORD_TYPE. If we do, we
594 haven't change the field that contains the actual pointer to
595 a method, and so TYPE_PTRMEMFUNC_FN_TYPE will be wrong. */
598 t
= TYPE_PTRMEMFUNC_FN_TYPE (type
);
599 t
= cp_build_qualified_type_real (t
, type_quals
, complain
);
600 return build_ptrmemfunc_type (t
);
603 /* Retrieve (or create) the appropriately qualified variant. */
604 result
= build_qualified_type (type
, type_quals
);
606 /* If this was a pointer-to-method type, and we just made a copy,
607 then we need to clear the cached associated
608 pointer-to-member-function type; it is not valid for the new
611 && TREE_CODE (type
) == POINTER_TYPE
612 && TREE_CODE (TREE_TYPE (type
)) == METHOD_TYPE
)
613 TYPE_SET_PTRMEMFUNC_TYPE (result
, NULL_TREE
);
618 /* Returns the canonical version of TYPE. In other words, if TYPE is
619 a typedef, returns the underlying type. The cv-qualification of
620 the type returned matches the type input; they will always be
624 canonical_type_variant (t
)
627 return cp_build_qualified_type (TYPE_MAIN_VARIANT (t
), CP_TYPE_QUALS (t
));
630 /* Makes new binfos for the indirect bases under BINFO, and updates
631 BINFO_OFFSET for them and their bases. */
634 unshare_base_binfos (binfo
)
637 tree binfos
= BINFO_BASETYPES (binfo
);
641 if (binfos
== NULL_TREE
)
644 /* Now unshare the structure beneath BINFO. */
645 for (j
= TREE_VEC_LENGTH (binfos
)-1;
648 tree base_binfo
= TREE_VEC_ELT (binfos
, j
);
649 new_binfo
= TREE_VEC_ELT (binfos
, j
)
650 = make_binfo (BINFO_OFFSET (base_binfo
),
652 BINFO_VTABLE (base_binfo
),
653 BINFO_VIRTUALS (base_binfo
));
654 TREE_VIA_PUBLIC (new_binfo
) = TREE_VIA_PUBLIC (base_binfo
);
655 TREE_VIA_PROTECTED (new_binfo
) = TREE_VIA_PROTECTED (base_binfo
);
656 TREE_VIA_VIRTUAL (new_binfo
) = TREE_VIA_VIRTUAL (base_binfo
);
657 BINFO_INHERITANCE_CHAIN (new_binfo
) = binfo
;
658 BINFO_PRIMARY_BASE_OF (new_binfo
) = NULL_TREE
;
659 unshare_base_binfos (new_binfo
);
664 /* Hashing of lists so that we don't make duplicates.
665 The entry point is `list_hash_canon'. */
667 /* Now here is the hash table. When recording a list, it is added
668 to the slot whose index is the hash code mod the table size.
669 Note that the hash table is used for several kinds of lists.
670 While all these live in the same table, they are completely independent,
671 and the hash code is computed differently for each of these. */
673 static htab_t list_hash_table
;
682 /* Compare ENTRY (an entry in the hash table) with DATA (a list_proxy
683 for a node we are thinking about adding). */
686 list_hash_eq (entry
, data
)
690 tree t
= (tree
) entry
;
691 struct list_proxy
*proxy
= (struct list_proxy
*) data
;
693 return (TREE_VALUE (t
) == proxy
->value
694 && TREE_PURPOSE (t
) == proxy
->purpose
695 && TREE_CHAIN (t
) == proxy
->chain
);
698 /* Compute a hash code for a list (chain of TREE_LIST nodes
699 with goodies in the TREE_PURPOSE, TREE_VALUE, and bits of the
700 TREE_COMMON slots), by adding the hash codes of the individual entries. */
703 list_hash_pieces (purpose
, value
, chain
)
708 hashval_t hashcode
= 0;
711 hashcode
+= TYPE_HASH (chain
);
714 hashcode
+= TYPE_HASH (value
);
718 hashcode
+= TYPE_HASH (purpose
);
724 /* Hash an already existing TREE_LIST. */
731 return list_hash_pieces (TREE_PURPOSE (t
),
736 /* Given list components PURPOSE, VALUE, AND CHAIN, return the canonical
737 object for an identical list if one already exists. Otherwise, build a
738 new one, and record it as the canonical object. */
741 hash_tree_cons (purpose
, value
, chain
)
742 tree purpose
, value
, chain
;
746 struct list_proxy proxy
;
748 /* Hash the list node. */
749 hashcode
= list_hash_pieces (purpose
, value
, chain
);
750 /* Create a proxy for the TREE_LIST we would like to create. We
751 don't actually create it so as to avoid creating garbage. */
752 proxy
.purpose
= purpose
;
755 /* See if it is already in the table. */
756 slot
= htab_find_slot_with_hash (list_hash_table
, &proxy
, hashcode
,
758 /* If not, create a new node. */
760 *slot
= (PTR
) tree_cons (purpose
, value
, chain
);
764 /* Constructor for hashed lists. */
767 hash_tree_chain (value
, chain
)
770 return hash_tree_cons (NULL_TREE
, value
, chain
);
773 /* Similar, but used for concatenating two lists. */
776 hash_chainon (list1
, list2
)
783 if (TREE_CHAIN (list1
) == NULL_TREE
)
784 return hash_tree_chain (TREE_VALUE (list1
), list2
);
785 return hash_tree_chain (TREE_VALUE (list1
),
786 hash_chainon (TREE_CHAIN (list1
), list2
));
789 /* Build an association between TYPE and some parameters:
791 OFFSET is the offset added to `this' to convert it to a pointer
794 BINFO is the base binfo to use, if we are deriving from one. This
795 is necessary, as we want specialized parent binfos from base
796 classes, so that the VTABLE_NAMEs of bases are for the most derived
797 type, instead of the simple type.
799 VTABLE is the virtual function table with which to initialize
800 sub-objects of type TYPE.
802 VIRTUALS are the virtual functions sitting in VTABLE. */
805 make_binfo (offset
, binfo
, vtable
, virtuals
)
807 tree vtable
, virtuals
;
809 tree new_binfo
= make_tree_vec (11);
812 if (TREE_CODE (binfo
) == TREE_VEC
)
813 type
= BINFO_TYPE (binfo
);
817 binfo
= CLASS_TYPE_P (type
) ? TYPE_BINFO (binfo
) : NULL_TREE
;
820 TREE_TYPE (new_binfo
) = TYPE_MAIN_VARIANT (type
);
821 BINFO_OFFSET (new_binfo
) = offset
;
822 BINFO_VTABLE (new_binfo
) = vtable
;
823 BINFO_VIRTUALS (new_binfo
) = virtuals
;
825 if (binfo
&& BINFO_BASETYPES (binfo
) != NULL_TREE
)
826 BINFO_BASETYPES (new_binfo
) = copy_node (BINFO_BASETYPES (binfo
));
830 /* Return the binfo value for ELEM in TYPE. */
833 binfo_value (elem
, type
)
837 if (get_base_distance (elem
, type
, 0, (tree
*)0) == -2)
838 compiler_error ("base class `%s' ambiguous in binfo_value",
839 TYPE_NAME_STRING (elem
));
841 return TYPE_BINFO (type
);
842 if (TREE_CODE (elem
) == RECORD_TYPE
&& TYPE_BINFO (elem
) == type
)
844 return get_binfo (elem
, type
, 0);
847 /* Return a TREE_LIST whose TREE_VALUE nodes along the
848 BINFO_INHERITANCE_CHAIN for BINFO, but in the opposite order. In
849 other words, while the BINFO_INHERITANCE_CHAIN goes from base
850 classes to derived classes, the reversed path goes from derived
851 classes to base classes. */
859 reversed_path
= NULL_TREE
;
862 reversed_path
= tree_cons (NULL_TREE
, binfo
, reversed_path
);
863 binfo
= BINFO_INHERITANCE_CHAIN (binfo
);
866 return reversed_path
;
876 fprintf (stderr
, "type \"%s\", offset = ",
877 TYPE_NAME_STRING (BINFO_TYPE (elem
)));
878 fprintf (stderr
, HOST_WIDE_INT_PRINT_DEC
,
879 TREE_INT_CST_LOW (BINFO_OFFSET (elem
)));
880 fprintf (stderr
, "\nvtable type:\n");
881 debug_tree (BINFO_TYPE (elem
));
882 if (BINFO_VTABLE (elem
))
883 fprintf (stderr
, "vtable decl \"%s\"\n",
884 IDENTIFIER_POINTER (DECL_NAME (get_vtbl_decl_for_binfo (elem
))));
886 fprintf (stderr
, "no vtable decl yet\n");
887 fprintf (stderr
, "virtuals:\n");
888 virtuals
= BINFO_VIRTUALS (elem
);
893 tree fndecl
= TREE_VALUE (virtuals
);
894 fprintf (stderr
, "%s [%ld =? %ld]\n",
895 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (fndecl
)),
896 (long) n
, (long) TREE_INT_CST_LOW (DECL_VINDEX (fndecl
)));
898 virtuals
= TREE_CHAIN (virtuals
);
907 if (TREE_CODE (t
) == FUNCTION_DECL
)
909 else if (TREE_CODE (t
) == OVERLOAD
)
911 for (i
=0; t
; t
= OVL_CHAIN (t
))
916 my_friendly_abort (359);
924 /* A baselink is also considered an overloaded function. */
925 if (TREE_CODE (x
) == OFFSET_REF
)
926 x
= TREE_OPERAND (x
, 1);
929 return (TREE_CODE (x
) == FUNCTION_DECL
930 || TREE_CODE (x
) == TEMPLATE_ID_EXPR
931 || DECL_FUNCTION_TEMPLATE_P (x
)
932 || TREE_CODE (x
) == OVERLOAD
);
936 really_overloaded_fn (x
)
939 /* A baselink is also considered an overloaded function. */
940 if (TREE_CODE (x
) == OFFSET_REF
)
941 x
= TREE_OPERAND (x
, 1);
944 return (TREE_CODE (x
) == OVERLOAD
945 && (TREE_CHAIN (x
) != NULL_TREE
946 || DECL_FUNCTION_TEMPLATE_P (OVL_FUNCTION (x
))));
953 my_friendly_assert (is_overloaded_fn (from
), 9);
954 /* A baselink is also considered an overloaded function. */
955 if (BASELINK_P (from
))
956 from
= TREE_VALUE (from
);
957 return OVL_CURRENT (from
);
960 /* Returns nonzero if T is a ->* or .* expression that refers to a
967 return (TREE_CODE (t
) == OFFSET_REF
968 && TYPE_PTRMEMFUNC_P (TREE_TYPE (TREE_OPERAND (t
, 1))));
971 /* Return a new OVL node, concatenating it with the old one. */
974 ovl_cons (decl
, chain
)
978 tree result
= make_node (OVERLOAD
);
979 TREE_TYPE (result
) = unknown_type_node
;
980 OVL_FUNCTION (result
) = decl
;
981 TREE_CHAIN (result
) = chain
;
986 /* Build a new overloaded function. If this is the first one,
987 just return it; otherwise, ovl_cons the _DECLs */
990 build_overload (decl
, chain
)
994 if (! chain
&& TREE_CODE (decl
) != TEMPLATE_DECL
)
996 if (chain
&& TREE_CODE (chain
) != OVERLOAD
)
997 chain
= ovl_cons (chain
, NULL_TREE
);
998 return ovl_cons (decl
, chain
);
1001 /* True if fn is in ovl. */
1004 ovl_member (fn
, ovl
)
1008 if (ovl
== NULL_TREE
)
1010 if (TREE_CODE (ovl
) != OVERLOAD
)
1012 for (; ovl
; ovl
= OVL_CHAIN (ovl
))
1013 if (OVL_FUNCTION (ovl
) == fn
)
1019 is_aggr_type_2 (t1
, t2
)
1022 if (TREE_CODE (t1
) != TREE_CODE (t2
))
1024 return IS_AGGR_TYPE (t1
) && IS_AGGR_TYPE (t2
);
1027 /* Returns non-zero if CODE is the code for a statement. */
1030 cp_statement_code_p (code
)
1031 enum tree_code code
;
1038 case CTOR_INITIALIZER
:
1052 #define PRINT_RING_SIZE 4
1055 lang_printable_name (decl
, v
)
1059 static tree decl_ring
[PRINT_RING_SIZE
];
1060 static char *print_ring
[PRINT_RING_SIZE
];
1061 static int ring_counter
;
1064 /* Only cache functions. */
1066 || TREE_CODE (decl
) != FUNCTION_DECL
1067 || DECL_LANG_SPECIFIC (decl
) == 0)
1068 return lang_decl_name (decl
, v
);
1070 /* See if this print name is lying around. */
1071 for (i
= 0; i
< PRINT_RING_SIZE
; i
++)
1072 if (decl_ring
[i
] == decl
)
1073 /* yes, so return it. */
1074 return print_ring
[i
];
1076 if (++ring_counter
== PRINT_RING_SIZE
)
1079 if (current_function_decl
!= NULL_TREE
)
1081 if (decl_ring
[ring_counter
] == current_function_decl
)
1083 if (ring_counter
== PRINT_RING_SIZE
)
1085 if (decl_ring
[ring_counter
] == current_function_decl
)
1086 my_friendly_abort (106);
1089 if (print_ring
[ring_counter
])
1090 free (print_ring
[ring_counter
]);
1092 print_ring
[ring_counter
] = xstrdup (lang_decl_name (decl
, v
));
1093 decl_ring
[ring_counter
] = decl
;
1094 return print_ring
[ring_counter
];
1097 /* Build the FUNCTION_TYPE or METHOD_TYPE which may throw exceptions
1098 listed in RAISES. */
1101 build_exception_variant (type
, raises
)
1105 tree v
= TYPE_MAIN_VARIANT (type
);
1106 int type_quals
= TYPE_QUALS (type
);
1108 for (; v
; v
= TYPE_NEXT_VARIANT (v
))
1109 if (TYPE_QUALS (v
) == type_quals
1110 && comp_except_specs (raises
, TYPE_RAISES_EXCEPTIONS (v
), 1))
1113 /* Need to build a new variant. */
1114 v
= build_type_copy (type
);
1115 TYPE_RAISES_EXCEPTIONS (v
) = raises
;
1119 /* Given a TEMPLATE_TEMPLATE_PARM node T, create a new
1120 BOUND_TEMPLATE_TEMPLATE_PARM bound with NEWARGS as its template
1124 bind_template_template_parm (t
, newargs
)
1128 tree decl
= TYPE_NAME (t
);
1131 t2
= make_aggr_type (BOUND_TEMPLATE_TEMPLATE_PARM
);
1132 decl
= build_decl (TYPE_DECL
, DECL_NAME (decl
), NULL_TREE
);
1134 /* These nodes have to be created to reflect new TYPE_DECL and template
1136 TEMPLATE_TYPE_PARM_INDEX (t2
) = copy_node (TEMPLATE_TYPE_PARM_INDEX (t
));
1137 TEMPLATE_PARM_DECL (TEMPLATE_TYPE_PARM_INDEX (t2
)) = decl
;
1138 TEMPLATE_TEMPLATE_PARM_TEMPLATE_INFO (t2
)
1139 = tree_cons (TEMPLATE_TEMPLATE_PARM_TEMPLATE_DECL (t
),
1140 newargs
, NULL_TREE
);
1142 TREE_TYPE (decl
) = t2
;
1143 TYPE_NAME (t2
) = decl
;
1144 TYPE_STUB_DECL (t2
) = decl
;
1150 /* Called from count_trees via walk_tree. */
1153 count_trees_r (tp
, walk_subtrees
, data
)
1154 tree
*tp ATTRIBUTE_UNUSED
;
1155 int *walk_subtrees ATTRIBUTE_UNUSED
;
1162 /* Debugging function for measuring the rough complexity of a tree
1170 walk_tree_without_duplicates (&t
, count_trees_r
, &n_trees
);
1174 /* Called from verify_stmt_tree via walk_tree. */
1177 verify_stmt_tree_r (tp
, walk_subtrees
, data
)
1179 int *walk_subtrees ATTRIBUTE_UNUSED
;
1183 htab_t
*statements
= (htab_t
*) data
;
1186 if (!statement_code_p (TREE_CODE (t
)))
1189 /* If this statement is already present in the hash table, then
1190 there is a circularity in the statement tree. */
1191 if (htab_find (*statements
, t
))
1192 my_friendly_abort (20000727);
1194 slot
= htab_find_slot (*statements
, t
, INSERT
);
1200 /* Debugging function to check that the statement T has not been
1201 corrupted. For now, this function simply checks that T contains no
1205 verify_stmt_tree (t
)
1209 statements
= htab_create (37, htab_hash_pointer
, htab_eq_pointer
, NULL
);
1210 walk_tree (&t
, verify_stmt_tree_r
, &statements
, NULL
);
1211 htab_delete (statements
);
1214 /* Called from find_tree via walk_tree. */
1217 find_tree_r (tp
, walk_subtrees
, data
)
1219 int *walk_subtrees ATTRIBUTE_UNUSED
;
1222 if (*tp
== (tree
) data
)
1228 /* Returns X if X appears in the tree structure rooted at T. */
1235 return walk_tree_without_duplicates (&t
, find_tree_r
, x
);
1238 /* Passed to walk_tree. Checks for the use of types with no linkage. */
1241 no_linkage_helper (tp
, walk_subtrees
, data
)
1243 int *walk_subtrees ATTRIBUTE_UNUSED
;
1244 void *data ATTRIBUTE_UNUSED
;
1249 && (CLASS_TYPE_P (t
) || TREE_CODE (t
) == ENUMERAL_TYPE
)
1250 && (decl_function_context (TYPE_MAIN_DECL (t
))
1251 || TYPE_ANONYMOUS_P (t
)))
1256 /* Check if the type T depends on a type with no linkage and if so, return
1260 no_linkage_check (t
)
1263 /* There's no point in checking linkage on template functions; we
1264 can't know their complete types. */
1265 if (processing_template_decl
)
1268 t
= walk_tree_without_duplicates (&t
, no_linkage_helper
, NULL
);
1269 if (t
!= error_mark_node
)
1274 #ifdef GATHER_STATISTICS
1275 extern int depth_reached
;
1279 cxx_print_statistics ()
1281 print_search_statistics ();
1282 print_class_statistics ();
1283 #ifdef GATHER_STATISTICS
1284 fprintf (stderr
, "maximum template instantiation depth reached: %d\n",
1289 /* Return, as an INTEGER_CST node, the number of elements for TYPE
1290 (which is an ARRAY_TYPE). This counts only elements of the top
1294 array_type_nelts_top (type
)
1297 return fold (build (PLUS_EXPR
, sizetype
,
1298 array_type_nelts (type
),
1302 /* Return, as an INTEGER_CST node, the number of elements for TYPE
1303 (which is an ARRAY_TYPE). This one is a recursive count of all
1304 ARRAY_TYPEs that are clumped together. */
1307 array_type_nelts_total (type
)
1310 tree sz
= array_type_nelts_top (type
);
1311 type
= TREE_TYPE (type
);
1312 while (TREE_CODE (type
) == ARRAY_TYPE
)
1314 tree n
= array_type_nelts_top (type
);
1315 sz
= fold (build (MULT_EXPR
, sizetype
, sz
, n
));
1316 type
= TREE_TYPE (type
);
1321 /* Called from break_out_target_exprs via mapcar. */
1324 bot_manip (tp
, walk_subtrees
, data
)
1329 splay_tree target_remap
= ((splay_tree
) data
);
1332 if (TREE_CONSTANT (t
))
1334 /* There can't be any TARGET_EXPRs or their slot variables below
1335 this point. We used to check !TREE_SIDE_EFFECTS, but then we
1336 failed to copy an ADDR_EXPR of the slot VAR_DECL. */
1340 if (TREE_CODE (t
) == TARGET_EXPR
)
1344 if (TREE_CODE (TREE_OPERAND (t
, 1)) == AGGR_INIT_EXPR
)
1346 mark_used (TREE_OPERAND (TREE_OPERAND (TREE_OPERAND (t
, 1), 0), 0));
1348 (TREE_TYPE (t
), break_out_target_exprs (TREE_OPERAND (t
, 1)));
1352 u
= build_target_expr_with_type
1353 (break_out_target_exprs (TREE_OPERAND (t
, 1)), TREE_TYPE (t
));
1356 /* Map the old variable to the new one. */
1357 splay_tree_insert (target_remap
,
1358 (splay_tree_key
) TREE_OPERAND (t
, 0),
1359 (splay_tree_value
) TREE_OPERAND (u
, 0));
1361 /* Replace the old expression with the new version. */
1363 /* We don't have to go below this point; the recursive call to
1364 break_out_target_exprs will have handled anything below this
1369 else if (TREE_CODE (t
) == CALL_EXPR
)
1370 mark_used (TREE_OPERAND (TREE_OPERAND (t
, 0), 0));
1372 /* Make a copy of this node. */
1373 return copy_tree_r (tp
, walk_subtrees
, NULL
);
1376 /* Replace all remapped VAR_DECLs in T with their new equivalents.
1377 DATA is really a splay-tree mapping old variables to new
1381 bot_replace (t
, walk_subtrees
, data
)
1383 int *walk_subtrees ATTRIBUTE_UNUSED
;
1386 splay_tree target_remap
= ((splay_tree
) data
);
1388 if (TREE_CODE (*t
) == VAR_DECL
)
1390 splay_tree_node n
= splay_tree_lookup (target_remap
,
1391 (splay_tree_key
) *t
);
1393 *t
= (tree
) n
->value
;
1399 /* When we parse a default argument expression, we may create
1400 temporary variables via TARGET_EXPRs. When we actually use the
1401 default-argument expression, we make a copy of the expression, but
1402 we must replace the temporaries with appropriate local versions. */
1405 break_out_target_exprs (t
)
1408 static int target_remap_count
;
1409 static splay_tree target_remap
;
1411 if (!target_remap_count
++)
1412 target_remap
= splay_tree_new (splay_tree_compare_pointers
,
1413 /*splay_tree_delete_key_fn=*/NULL
,
1414 /*splay_tree_delete_value_fn=*/NULL
);
1415 walk_tree (&t
, bot_manip
, target_remap
, NULL
);
1416 walk_tree (&t
, bot_replace
, target_remap
, NULL
);
1418 if (!--target_remap_count
)
1420 splay_tree_delete (target_remap
);
1421 target_remap
= NULL
;
1427 /* Obstack used for allocating nodes in template function and variable
1430 /* Similar to `build_nt', except that we set TREE_COMPLEXITY to be the
1431 current line number. */
1434 build_min_nt
VPARAMS ((enum tree_code code
, ...))
1437 register int length
;
1441 VA_FIXEDARG (p
, enum tree_code
, code
);
1443 t
= make_node (code
);
1444 length
= TREE_CODE_LENGTH (code
);
1445 TREE_COMPLEXITY (t
) = lineno
;
1447 for (i
= 0; i
< length
; i
++)
1449 tree x
= va_arg (p
, tree
);
1450 TREE_OPERAND (t
, i
) = x
;
1457 /* Similar to `build', except we set TREE_COMPLEXITY to the current
1461 build_min
VPARAMS ((enum tree_code code
, tree tt
, ...))
1464 register int length
;
1468 VA_FIXEDARG (p
, enum tree_code
, code
);
1469 VA_FIXEDARG (p
, tree
, tt
);
1471 t
= make_node (code
);
1472 length
= TREE_CODE_LENGTH (code
);
1474 TREE_COMPLEXITY (t
) = lineno
;
1476 for (i
= 0; i
< length
; i
++)
1478 tree x
= va_arg (p
, tree
);
1479 TREE_OPERAND (t
, i
) = x
;
1486 /* Returns an INTEGER_CST (of type `int') corresponding to I.
1487 Multiple calls with the same value of I may or may not yield the
1488 same node; therefore, callers should never modify the node
1492 build_shared_int_cst (i
)
1495 static tree cache
[256];
1498 return build_int_2 (i
, 0);
1501 cache
[i
] = build_int_2 (i
, 0);
1510 if (TREE_CODE (t
) == TYPE_DECL
)
1513 return TYPE_STUB_DECL (t
);
1514 if (t
== error_mark_node
)
1517 my_friendly_abort (42);
1519 /* Stop compiler from complaining control reaches end of non-void function. */
1523 /* Return first vector element whose BINFO_TYPE is ELEM.
1524 Return 0 if ELEM is not in VEC. VEC may be NULL_TREE. */
1527 vec_binfo_member (elem
, vec
)
1533 for (i
= 0; i
< TREE_VEC_LENGTH (vec
); ++i
)
1534 if (same_type_p (elem
, BINFO_TYPE (TREE_VEC_ELT (vec
, i
))))
1535 return TREE_VEC_ELT (vec
, i
);
1540 /* Returns the namespace that contains DECL, whether directly or
1544 decl_namespace_context (decl
)
1549 if (TREE_CODE (decl
) == NAMESPACE_DECL
)
1551 else if (TYPE_P (decl
))
1552 decl
= CP_DECL_CONTEXT (TYPE_MAIN_DECL (decl
));
1554 decl
= CP_DECL_CONTEXT (decl
);
1558 /* Return truthvalue of whether T1 is the same tree structure as T2.
1559 Return 1 if they are the same.
1560 Return 0 if they are understandably different.
1561 Return -1 if either contains tree structure not understood by
1565 cp_tree_equal (t1
, t2
)
1568 register enum tree_code code1
, code2
;
1573 if (t1
== 0 || t2
== 0)
1576 code1
= TREE_CODE (t1
);
1577 code2
= TREE_CODE (t2
);
1579 if (code1
== NOP_EXPR
|| code1
== CONVERT_EXPR
|| code1
== NON_LVALUE_EXPR
)
1581 if (code2
== NOP_EXPR
|| code2
== CONVERT_EXPR
|| code2
== NON_LVALUE_EXPR
)
1582 return cp_tree_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
1584 return cp_tree_equal (TREE_OPERAND (t1
, 0), t2
);
1586 else if (code2
== NOP_EXPR
|| code2
== CONVERT_EXPR
1587 || code2
== NON_LVALUE_EXPR
)
1588 return cp_tree_equal (t1
, TREE_OPERAND (t2
, 0));
1596 return TREE_INT_CST_LOW (t1
) == TREE_INT_CST_LOW (t2
)
1597 && TREE_INT_CST_HIGH (t1
) == TREE_INT_CST_HIGH (t2
);
1600 return REAL_VALUES_EQUAL (TREE_REAL_CST (t1
), TREE_REAL_CST (t2
));
1603 return TREE_STRING_LENGTH (t1
) == TREE_STRING_LENGTH (t2
)
1604 && !memcmp (TREE_STRING_POINTER (t1
), TREE_STRING_POINTER (t2
),
1605 TREE_STRING_LENGTH (t1
));
1608 /* We need to do this when determining whether or not two
1609 non-type pointer to member function template arguments
1611 if (!(same_type_p (TREE_TYPE (t1
), TREE_TYPE (t2
))
1612 /* The first operand is RTL. */
1613 && TREE_OPERAND (t1
, 0) == TREE_OPERAND (t2
, 0)))
1615 return cp_tree_equal (TREE_OPERAND (t1
, 1), TREE_OPERAND (t2
, 1));
1618 cmp
= cp_tree_equal (TREE_PURPOSE (t1
), TREE_PURPOSE (t2
));
1621 cmp
= cp_tree_equal (TREE_VALUE (t1
), TREE_VALUE (t2
));
1624 return cp_tree_equal (TREE_CHAIN (t1
), TREE_CHAIN (t2
));
1627 return cp_tree_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
1630 cmp
= cp_tree_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
1633 return simple_cst_list_equal (TREE_OPERAND (t1
, 1), TREE_OPERAND (t2
, 1));
1636 /* Special case: if either target is an unallocated VAR_DECL,
1637 it means that it's going to be unified with whatever the
1638 TARGET_EXPR is really supposed to initialize, so treat it
1639 as being equivalent to anything. */
1640 if ((TREE_CODE (TREE_OPERAND (t1
, 0)) == VAR_DECL
1641 && DECL_NAME (TREE_OPERAND (t1
, 0)) == NULL_TREE
1642 && !DECL_RTL_SET_P (TREE_OPERAND (t1
, 0)))
1643 || (TREE_CODE (TREE_OPERAND (t2
, 0)) == VAR_DECL
1644 && DECL_NAME (TREE_OPERAND (t2
, 0)) == NULL_TREE
1645 && !DECL_RTL_SET_P (TREE_OPERAND (t2
, 0))))
1648 cmp
= cp_tree_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
1651 return cp_tree_equal (TREE_OPERAND (t1
, 1), TREE_OPERAND (t2
, 1));
1653 case WITH_CLEANUP_EXPR
:
1654 cmp
= cp_tree_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
1657 return cp_tree_equal (TREE_OPERAND (t1
, 1), TREE_OPERAND (t1
, 1));
1660 if (TREE_OPERAND (t1
, 1) == TREE_OPERAND (t2
, 1))
1661 return cp_tree_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
1670 case TEMPLATE_PARM_INDEX
:
1671 return TEMPLATE_PARM_IDX (t1
) == TEMPLATE_PARM_IDX (t2
)
1672 && TEMPLATE_PARM_LEVEL (t1
) == TEMPLATE_PARM_LEVEL (t2
);
1676 if (TREE_CODE (TREE_OPERAND (t1
, 0)) != TREE_CODE (TREE_OPERAND (t2
, 0)))
1678 if (TYPE_P (TREE_OPERAND (t1
, 0)))
1679 return same_type_p (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
1683 /* Two pointer-to-members are the same if they point to the same
1684 field or function in the same class. */
1685 return (PTRMEM_CST_MEMBER (t1
) == PTRMEM_CST_MEMBER (t2
)
1686 && same_type_p (PTRMEM_CST_CLASS (t1
), PTRMEM_CST_CLASS (t2
)));
1692 switch (TREE_CODE_CLASS (code1
))
1704 for (i
= 0; i
< TREE_CODE_LENGTH (code1
); ++i
)
1706 cmp
= cp_tree_equal (TREE_OPERAND (t1
, i
), TREE_OPERAND (t2
, i
));
1714 return same_type_p (t1
, t2
) ? 1 : 0;
1720 /* Build a wrapper around some pointer PTR so we can use it as a tree. */
1723 build_ptr_wrapper (ptr
)
1726 tree t
= make_node (WRAPPER
);
1727 WRAPPER_PTR (t
) = ptr
;
1731 /* Build a wrapper around some integer I so we can use it as a tree. */
1734 build_int_wrapper (i
)
1737 tree t
= make_node (WRAPPER
);
1738 WRAPPER_INT (t
) = i
;
1743 build_srcloc (file
, line
)
1749 t
= make_node (SRCLOC
);
1750 SRCLOC_FILE (t
) = file
;
1751 SRCLOC_LINE (t
) = line
;
1757 build_srcloc_here ()
1759 return build_srcloc (input_filename
, lineno
);
1762 /* The type of ARG when used as an lvalue. */
1768 tree type
= TREE_TYPE (arg
);
1769 if (TREE_CODE (arg
) == OVERLOAD
)
1770 type
= unknown_type_node
;
1774 /* The type of ARG for printing error messages; denote lvalues with
1781 tree type
= TREE_TYPE (arg
);
1782 if (TREE_CODE (type
) == ARRAY_TYPE
)
1784 else if (real_lvalue_p (arg
))
1785 type
= build_reference_type (lvalue_type (arg
));
1786 else if (IS_AGGR_TYPE (type
))
1787 type
= lvalue_type (arg
);
1792 /* Does FUNCTION use a variable-length argument list? */
1795 varargs_function_p (function
)
1798 tree parm
= TYPE_ARG_TYPES (TREE_TYPE (function
));
1799 for (; parm
; parm
= TREE_CHAIN (parm
))
1800 if (TREE_VALUE (parm
) == void_type_node
)
1805 /* Returns 1 if decl is a member of a class. */
1811 const tree ctx
= DECL_CONTEXT (decl
);
1812 return (ctx
&& TYPE_P (ctx
));
1815 /* Create a placeholder for member access where we don't actually have an
1816 object that the access is against. */
1819 build_dummy_object (type
)
1822 tree decl
= build1 (NOP_EXPR
, build_pointer_type (type
), void_zero_node
);
1823 return build_indirect_ref (decl
, NULL
);
1826 /* We've gotten a reference to a member of TYPE. Return *this if appropriate,
1827 or a dummy object otherwise. If BINFOP is non-0, it is filled with the
1828 binfo path from current_class_type to TYPE, or 0. */
1831 maybe_dummy_object (type
, binfop
)
1837 if (current_class_type
1838 && get_base_distance (type
, current_class_type
, 0, binfop
) != -1)
1839 context
= current_class_type
;
1842 /* Reference from a nested class member function. */
1845 *binfop
= TYPE_BINFO (type
);
1848 if (current_class_ref
&& context
== current_class_type
)
1849 decl
= current_class_ref
;
1851 decl
= build_dummy_object (context
);
1856 /* Returns 1 if OB is a placeholder object, or a pointer to one. */
1859 is_dummy_object (ob
)
1862 if (TREE_CODE (ob
) == INDIRECT_REF
)
1863 ob
= TREE_OPERAND (ob
, 0);
1864 return (TREE_CODE (ob
) == NOP_EXPR
1865 && TREE_OPERAND (ob
, 0) == void_zero_node
);
1868 /* Returns 1 iff type T is a POD type, as defined in [basic.types]. */
1874 t
= strip_array_types (t
);
1876 if (INTEGRAL_TYPE_P (t
))
1877 return 1; /* integral, character or enumeral type */
1878 if (FLOAT_TYPE_P (t
))
1881 return 1; /* pointer to non-member */
1882 if (TYPE_PTRMEM_P (t
))
1883 return 1; /* pointer to member object */
1884 if (TYPE_PTRMEMFUNC_P (t
))
1885 return 1; /* pointer to member function */
1887 if (! CLASS_TYPE_P (t
))
1888 return 0; /* other non-class type (reference or function) */
1889 if (CLASSTYPE_NON_POD_P (t
))
1894 /* Table of valid C++ attributes. */
1895 const struct attribute_spec cp_attribute_table
[] =
1897 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
1898 { "java_interface", 0, 0, false, false, false, handle_java_interface_attribute
},
1899 { "com_interface", 0, 0, false, false, false, handle_com_interface_attribute
},
1900 { "init_priority", 1, 1, true, false, false, handle_init_priority_attribute
},
1901 { NULL
, 0, 0, false, false, false, NULL
}
1904 /* Handle a "java_interface" attribute; arguments as in
1905 struct attribute_spec.handler. */
1907 handle_java_interface_attribute (node
, name
, args
, flags
, no_add_attrs
)
1910 tree args ATTRIBUTE_UNUSED
;
1915 || !CLASS_TYPE_P (*node
)
1916 || !TYPE_FOR_JAVA (*node
))
1918 error ("`%s' attribute can only be applied to Java class definitions",
1919 IDENTIFIER_POINTER (name
));
1920 *no_add_attrs
= true;
1923 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
1924 *node
= build_type_copy (*node
);
1925 TYPE_JAVA_INTERFACE (*node
) = 1;
1930 /* Handle a "com_interface" attribute; arguments as in
1931 struct attribute_spec.handler. */
1933 handle_com_interface_attribute (node
, name
, args
, flags
, no_add_attrs
)
1936 tree args ATTRIBUTE_UNUSED
;
1937 int flags ATTRIBUTE_UNUSED
;
1942 *no_add_attrs
= true;
1945 || !CLASS_TYPE_P (*node
)
1946 || *node
!= TYPE_MAIN_VARIANT (*node
))
1948 warning ("`%s' attribute can only be applied to class definitions",
1949 IDENTIFIER_POINTER (name
));
1954 warning ("`%s' is obsolete; g++ vtables are now COM-compatible by default",
1955 IDENTIFIER_POINTER (name
));
1960 /* Handle an "init_priority" attribute; arguments as in
1961 struct attribute_spec.handler. */
1963 handle_init_priority_attribute (node
, name
, args
, flags
, no_add_attrs
)
1967 int flags ATTRIBUTE_UNUSED
;
1970 tree initp_expr
= TREE_VALUE (args
);
1972 tree type
= TREE_TYPE (decl
);
1975 STRIP_NOPS (initp_expr
);
1977 if (!initp_expr
|| TREE_CODE (initp_expr
) != INTEGER_CST
)
1979 error ("requested init_priority is not an integer constant");
1980 *no_add_attrs
= true;
1984 pri
= TREE_INT_CST_LOW (initp_expr
);
1986 type
= strip_array_types (type
);
1988 if (decl
== NULL_TREE
1989 || TREE_CODE (decl
) != VAR_DECL
1990 || !TREE_STATIC (decl
)
1991 || DECL_EXTERNAL (decl
)
1992 || (TREE_CODE (type
) != RECORD_TYPE
1993 && TREE_CODE (type
) != UNION_TYPE
)
1994 /* Static objects in functions are initialized the
1995 first time control passes through that
1996 function. This is not precise enough to pin down an
1997 init_priority value, so don't allow it. */
1998 || current_function_decl
)
2000 error ("can only use `%s' attribute on file-scope definitions of objects of class type",
2001 IDENTIFIER_POINTER (name
));
2002 *no_add_attrs
= true;
2006 if (pri
> MAX_INIT_PRIORITY
|| pri
<= 0)
2008 error ("requested init_priority is out of range");
2009 *no_add_attrs
= true;
2013 /* Check for init_priorities that are reserved for
2014 language and runtime support implementations.*/
2015 if (pri
<= MAX_RESERVED_INIT_PRIORITY
)
2018 ("requested init_priority is reserved for internal use");
2021 if (SUPPORTS_INIT_PRIORITY
)
2023 DECL_INIT_PRIORITY (decl
) = pri
;
2028 error ("`%s' attribute is not supported on this platform",
2029 IDENTIFIER_POINTER (name
));
2030 *no_add_attrs
= true;
2035 /* Return a new PTRMEM_CST of the indicated TYPE. The MEMBER is the
2036 thing pointed to by the constant. */
2039 make_ptrmem_cst (type
, member
)
2043 tree ptrmem_cst
= make_node (PTRMEM_CST
);
2044 /* If would seem a great convenience if make_node would set
2045 TREE_CONSTANT for things of class `c', but it does not. */
2046 TREE_CONSTANT (ptrmem_cst
) = 1;
2047 TREE_TYPE (ptrmem_cst
) = type
;
2048 PTRMEM_CST_MEMBER (ptrmem_cst
) = member
;
2052 /* Apply FUNC to all language-specific sub-trees of TP in a pre-order
2053 traversal. Called from walk_tree(). */
2056 cp_walk_subtrees (tp
, walk_subtrees_p
, func
, data
, htab
)
2058 int *walk_subtrees_p
;
2063 enum tree_code code
= TREE_CODE (*tp
);
2066 #define WALK_SUBTREE(NODE) \
2069 result = walk_tree (&(NODE), func, data, htab); \
2075 /* Not one of the easy cases. We must explicitly go through the
2080 case TEMPLATE_TEMPLATE_PARM
:
2081 case BOUND_TEMPLATE_TEMPLATE_PARM
:
2082 case UNBOUND_CLASS_TEMPLATE
:
2083 case TEMPLATE_PARM_INDEX
:
2084 case TEMPLATE_TYPE_PARM
:
2087 /* None of thse have subtrees other than those already walked
2089 *walk_subtrees_p
= 0;
2093 WALK_SUBTREE (TREE_TYPE (*tp
));
2094 *walk_subtrees_p
= 0;
2098 /* A BASELINK_P's TREE_PURPOSE is a BINFO, and hence circular. */
2099 if (!BASELINK_P (*tp
))
2100 WALK_SUBTREE (TREE_PURPOSE (*tp
));
2104 WALK_SUBTREE (OVL_FUNCTION (*tp
));
2105 WALK_SUBTREE (OVL_CHAIN (*tp
));
2106 *walk_subtrees_p
= 0;
2110 if (TYPE_PTRMEMFUNC_P (*tp
))
2111 WALK_SUBTREE (TYPE_PTRMEMFUNC_FN_TYPE (*tp
));
2118 /* We didn't find what we were looking for. */
2124 /* Decide whether there are language-specific reasons to not inline a
2125 function as a tree. */
2128 cp_cannot_inline_tree_fn (fnp
)
2133 /* We can inline a template instantiation only if it's fully
2135 if (DECL_TEMPLATE_INFO (fn
)
2136 && TI_PENDING_TEMPLATE_FLAG (DECL_TEMPLATE_INFO (fn
)))
2138 fn
= *fnp
= instantiate_decl (fn
, /*defer_ok=*/0);
2139 return TI_PENDING_TEMPLATE_FLAG (DECL_TEMPLATE_INFO (fn
));
2142 if (varargs_function_p (fn
))
2144 DECL_UNINLINABLE (fn
) = 1;
2148 if (! function_attribute_inlinable_p (fn
))
2150 DECL_UNINLINABLE (fn
) = 1;
2157 /* Add any pending functions other than the current function (already
2158 handled by the caller), that thus cannot be inlined, to FNS_P, then
2159 return the latest function added to the array, PREV_FN. */
2162 cp_add_pending_fn_decls (fns_p
, prev_fn
)
2166 varray_type
*fnsp
= (varray_type
*)fns_p
;
2167 struct saved_scope
*s
;
2169 for (s
= scope_chain
; s
; s
= s
->prev
)
2170 if (s
->function_decl
&& s
->function_decl
!= prev_fn
)
2172 VARRAY_PUSH_TREE (*fnsp
, s
->function_decl
);
2173 prev_fn
= s
->function_decl
;
2179 /* Determine whether a tree node is an OVERLOAD node. Used to decide
2180 whether to copy a node or to preserve its chain when inlining a
2184 cp_is_overload_p (t
)
2187 return TREE_CODE (t
) == OVERLOAD
;
2190 /* Determine whether VAR is a declaration of an automatic variable in
2194 cp_auto_var_in_fn_p (var
, fn
)
2197 return (DECL_P (var
) && DECL_CONTEXT (var
) == fn
2198 && nonstatic_local_decl_p (var
));
2201 /* Tell whether a declaration is needed for the RESULT of a function
2202 FN being inlined into CALLER or if the top node of target_exprs is
2206 cp_copy_res_decl_for_inlining (result
, fn
, caller
, decl_map_
,
2207 need_decl
, target_exprs
)
2208 tree result
, fn
, caller
;
2213 splay_tree decl_map
= (splay_tree
)decl_map_
;
2214 varray_type
*texps
= (varray_type
*)target_exprs
;
2216 int aggregate_return_p
;
2218 /* Figure out whether or not FN returns an aggregate. */
2219 aggregate_return_p
= IS_AGGR_TYPE (TREE_TYPE (result
));
2220 *need_decl
= ! aggregate_return_p
;
2222 /* If FN returns an aggregate then the caller will always create the
2223 temporary (using a TARGET_EXPR) and the call will be the
2224 initializing expression for the TARGET_EXPR. If we were just to
2225 create a new VAR_DECL here, then the result of this function
2226 would be copied (bitwise) into the variable initialized by the
2227 TARGET_EXPR. That's incorrect, so we must transform any
2228 references to the RESULT into references to the target. */
2229 if (aggregate_return_p
)
2231 if (VARRAY_ACTIVE_SIZE (*texps
) == 0)
2233 var
= TREE_OPERAND (VARRAY_TOP_TREE (*texps
), 0);
2234 if (! same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (var
),
2235 TREE_TYPE (result
)))
2238 /* Otherwise, make an appropriate copy. */
2240 var
= copy_decl_for_inlining (result
, fn
, caller
);
2242 if (DECL_SAVED_FUNCTION_DATA (fn
))
2244 tree nrv
= DECL_SAVED_FUNCTION_DATA (fn
)->x_return_value
;
2247 /* We have a named return value; copy the name and source
2248 position so we can get reasonable debugging information, and
2249 register the return variable as its equivalent. */
2250 DECL_NAME (var
) = DECL_NAME (nrv
);
2251 DECL_SOURCE_FILE (var
) = DECL_SOURCE_FILE (nrv
);
2252 DECL_SOURCE_LINE (var
) = DECL_SOURCE_LINE (nrv
);
2253 DECL_ABSTRACT_ORIGIN (var
) = DECL_ORIGIN (nrv
);
2254 splay_tree_insert (decl_map
,
2255 (splay_tree_key
) nrv
,
2256 (splay_tree_value
) var
);
2263 /* Initialize tree.c. */
2268 make_lang_type_fn
= cp_make_lang_type
;
2269 lang_unsave
= cp_unsave
;
2270 lang_statement_code_p
= cp_statement_code_p
;
2271 lang_set_decl_assembler_name
= mangle_decl
;
2272 list_hash_table
= htab_create (31, list_hash
, list_hash_eq
, NULL
);
2273 ggc_add_root (&list_hash_table
, 1,
2274 sizeof (list_hash_table
),
2275 mark_tree_hashtable
);
2278 /* Called via walk_tree. If *TP points to a DECL_STMT for a local
2279 declaration, copies the declaration and enters it in the splay_tree
2280 pointed to by DATA (which is really a `splay_tree *'). */
2283 mark_local_for_remap_r (tp
, walk_subtrees
, data
)
2285 int *walk_subtrees ATTRIBUTE_UNUSED
;
2289 splay_tree st
= (splay_tree
) data
;
2293 if (TREE_CODE (t
) == DECL_STMT
2294 && nonstatic_local_decl_p (DECL_STMT_DECL (t
)))
2295 decl
= DECL_STMT_DECL (t
);
2296 else if (TREE_CODE (t
) == LABEL_STMT
)
2297 decl
= LABEL_STMT_LABEL (t
);
2298 else if (TREE_CODE (t
) == TARGET_EXPR
2299 && nonstatic_local_decl_p (TREE_OPERAND (t
, 0)))
2300 decl
= TREE_OPERAND (t
, 0);
2301 else if (TREE_CODE (t
) == CASE_LABEL
)
2302 decl
= CASE_LABEL_DECL (t
);
2311 copy
= copy_decl_for_inlining (decl
,
2312 DECL_CONTEXT (decl
),
2313 DECL_CONTEXT (decl
));
2315 /* Remember the copy. */
2316 splay_tree_insert (st
,
2317 (splay_tree_key
) decl
,
2318 (splay_tree_value
) copy
);
2324 /* Called via walk_tree when an expression is unsaved. Using the
2325 splay_tree pointed to by ST (which is really a `splay_tree'),
2326 remaps all local declarations to appropriate replacements. */
2329 cp_unsave_r (tp
, walk_subtrees
, data
)
2334 splay_tree st
= (splay_tree
) data
;
2337 /* Only a local declaration (variable or label). */
2338 if (nonstatic_local_decl_p (*tp
))
2340 /* Lookup the declaration. */
2341 n
= splay_tree_lookup (st
, (splay_tree_key
) *tp
);
2343 /* If it's there, remap it. */
2345 *tp
= (tree
) n
->value
;
2347 else if (TREE_CODE (*tp
) == SAVE_EXPR
)
2348 remap_save_expr (tp
, st
, current_function_decl
, walk_subtrees
);
2351 copy_tree_r (tp
, walk_subtrees
, NULL
);
2353 /* Do whatever unsaving is required. */
2354 unsave_expr_1 (*tp
);
2357 /* Keep iterating. */
2361 /* Called by unsave_expr_now whenever an expression (*TP) needs to be
2370 /* Create a splay-tree to map old local variable declarations to new
2372 st
= splay_tree_new (splay_tree_compare_pointers
, NULL
, NULL
);
2374 /* Walk the tree once figuring out what needs to be remapped. */
2375 walk_tree (tp
, mark_local_for_remap_r
, st
, NULL
);
2377 /* Walk the tree again, copying, remapping, and unsaving. */
2378 walk_tree (tp
, cp_unsave_r
, st
, NULL
);
2381 splay_tree_delete (st
);
2384 /* Returns the kind of special function that DECL (a FUNCTION_DECL)
2385 is. Note that this sfk_none is zero, so this function can be used
2386 as a predicate to test whether or not DECL is a special function. */
2388 special_function_kind
2389 special_function_p (decl
)
2392 /* Rather than doing all this stuff with magic names, we should
2393 probably have a field of type `special_function_kind' in
2394 DECL_LANG_SPECIFIC. */
2395 if (DECL_COPY_CONSTRUCTOR_P (decl
))
2396 return sfk_copy_constructor
;
2397 if (DECL_CONSTRUCTOR_P (decl
))
2398 return sfk_constructor
;
2399 if (DECL_OVERLOADED_OPERATOR_P (decl
) == NOP_EXPR
)
2400 return sfk_assignment_operator
;
2401 if (DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (decl
))
2402 return sfk_destructor
;
2403 if (DECL_COMPLETE_DESTRUCTOR_P (decl
))
2404 return sfk_complete_destructor
;
2405 if (DECL_BASE_DESTRUCTOR_P (decl
))
2406 return sfk_base_destructor
;
2407 if (DECL_DELETING_DESTRUCTOR_P (decl
))
2408 return sfk_deleting_destructor
;
2409 if (DECL_CONV_FN_P (decl
))
2410 return sfk_conversion
;
2415 /* Returns non-zero if TYPE is a character type, including wchar_t. */
2421 return (same_type_p (type
, char_type_node
)
2422 || same_type_p (type
, unsigned_char_type_node
)
2423 || same_type_p (type
, signed_char_type_node
)
2424 || same_type_p (type
, wchar_type_node
));
2427 /* Returns the kind of linkage associated with the indicated DECL. Th
2428 value returned is as specified by the language standard; it is
2429 independent of implementation details regarding template
2430 instantiation, etc. For example, it is possible that a declaration
2431 to which this function assigns external linkage would not show up
2432 as a global symbol when you run `nm' on the resulting object file. */
2438 /* This function doesn't attempt to calculate the linkage from first
2439 principles as given in [basic.link]. Instead, it makes use of
2440 the fact that we have already set TREE_PUBLIC appropriately, and
2441 then handles a few special cases. Ideally, we would calculate
2442 linkage first, and then transform that into a concrete
2445 /* Things that don't have names have no linkage. */
2446 if (!DECL_NAME (decl
))
2449 /* Things that are TREE_PUBLIC have external linkage. */
2450 if (TREE_PUBLIC (decl
))
2453 /* Some things that are not TREE_PUBLIC have external linkage, too.
2454 For example, on targets that don't have weak symbols, we make all
2455 template instantiations have internal linkage (in the object
2456 file), but the symbols should still be treated as having external
2457 linkage from the point of view of the language. */
2458 if (DECL_LANG_SPECIFIC (decl
) && DECL_COMDAT (decl
))
2461 /* Things in local scope do not have linkage, if they don't have
2463 if (decl_function_context (decl
))
2466 /* Everything else has internal linkage. */