1 /* Language-dependent node constructors for parse phase of GNU compiler.
2 Copyright (C) 1987, 88, 92-98, 1999 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 static tree bot_manip
PROTO((tree
));
32 static tree perm_manip
PROTO((tree
));
33 static tree build_cplus_array_type_1
PROTO((tree
, tree
));
34 static void list_hash_add
PROTO((int, tree
));
35 static int list_hash
PROTO((tree
, tree
, tree
));
36 static tree list_hash_lookup
PROTO((int, tree
, tree
, tree
));
37 static void propagate_binfo_offsets
PROTO((tree
, tree
));
38 static int avoid_overlap
PROTO((tree
, tree
));
39 static cp_lvalue_kind lvalue_p_1
PROTO((tree
, int));
40 static tree no_linkage_helper
PROTO((tree
));
41 static tree build_srcloc
PROTO((char *, int));
43 #define CEIL(x,y) (((x) + (y) - 1) / (y))
45 /* If REF is an lvalue, returns the kind of lvalue that REF is.
46 Otherwise, returns clk_none. If TREAT_CLASS_RVALUES_AS_LVALUES is
47 non-zero, rvalues of class type are considered lvalues. */
50 lvalue_p_1 (ref
, treat_class_rvalues_as_lvalues
)
52 int treat_class_rvalues_as_lvalues
;
54 cp_lvalue_kind op1_lvalue_kind
= clk_none
;
55 cp_lvalue_kind op2_lvalue_kind
= clk_none
;
57 if (TREE_CODE (TREE_TYPE (ref
)) == REFERENCE_TYPE
)
60 if (ref
== current_class_ptr
&& flag_this_is_variable
<= 0)
63 switch (TREE_CODE (ref
))
65 /* preincrements and predecrements are valid lvals, provided
66 what they refer to are valid lvals. */
67 case PREINCREMENT_EXPR
:
68 case PREDECREMENT_EXPR
:
72 case WITH_CLEANUP_EXPR
:
76 return lvalue_p_1 (TREE_OPERAND (ref
, 0),
77 treat_class_rvalues_as_lvalues
);
80 op1_lvalue_kind
= lvalue_p_1 (TREE_OPERAND (ref
, 0),
81 treat_class_rvalues_as_lvalues
);
83 /* The "field" can be a FUNCTION_DECL or an OVERLOAD in some
85 && TREE_CODE (TREE_OPERAND (ref
, 1)) == FIELD_DECL
86 && DECL_BIT_FIELD (TREE_OPERAND (ref
, 1)))
88 /* Clear the ordinary bit. If this object was a class
89 rvalue we want to preserve that information. */
90 op1_lvalue_kind
&= ~clk_ordinary
;
91 /* The lvalue is for a btifield. */
92 op1_lvalue_kind
|= clk_bitfield
;
94 return op1_lvalue_kind
;
100 if (TREE_READONLY (ref
) && ! TREE_STATIC (ref
)
101 && DECL_LANG_SPECIFIC (ref
)
102 && DECL_IN_AGGR_P (ref
))
108 if (TREE_CODE (TREE_TYPE (ref
)) != METHOD_TYPE
)
112 /* A currently unresolved scope ref. */
114 my_friendly_abort (103);
116 if (TREE_CODE (TREE_OPERAND (ref
, 1)) == FUNCTION_DECL
)
121 op1_lvalue_kind
= lvalue_p_1 (TREE_OPERAND (ref
, 0),
122 treat_class_rvalues_as_lvalues
);
123 op2_lvalue_kind
= lvalue_p_1 (TREE_OPERAND (ref
, 1),
124 treat_class_rvalues_as_lvalues
);
128 op1_lvalue_kind
= lvalue_p_1 (TREE_OPERAND (ref
, 1),
129 treat_class_rvalues_as_lvalues
);
130 op2_lvalue_kind
= lvalue_p_1 (TREE_OPERAND (ref
, 2),
131 treat_class_rvalues_as_lvalues
);
138 return lvalue_p_1 (TREE_OPERAND (ref
, 1),
139 treat_class_rvalues_as_lvalues
);
142 return treat_class_rvalues_as_lvalues
? clk_class
: clk_none
;
145 return ((treat_class_rvalues_as_lvalues
146 && IS_AGGR_TYPE (TREE_TYPE (ref
)))
147 ? clk_class
: clk_none
);
150 /* All functions (except non-static-member functions) are
152 return (DECL_NONSTATIC_MEMBER_FUNCTION_P (ref
)
153 ? clk_none
: clk_ordinary
);
159 /* If one operand is not an lvalue at all, then this expression is
161 if (!op1_lvalue_kind
|| !op2_lvalue_kind
)
164 /* Otherwise, it's an lvalue, and it has all the odd properties
165 contributed by either operand. */
166 op1_lvalue_kind
= op1_lvalue_kind
| op2_lvalue_kind
;
167 /* It's not an ordinary lvalue if it involves either a bit-field or
169 if ((op1_lvalue_kind
& ~clk_ordinary
) != clk_none
)
170 op1_lvalue_kind
&= ~clk_ordinary
;
171 return op1_lvalue_kind
;
174 /* If REF is an lvalue, returns the kind of lvalue that REF is.
175 Otherwise, returns clk_none. Lvalues can be assigned, unless they
176 have TREE_READONLY, or unless they are FUNCTION_DECLs. Lvalues can
177 have their address taken, unless they have DECL_REGISTER. */
183 return lvalue_p_1 (ref
, /*treat_class_rvalues_as_lvalues=*/0);
186 /* This differs from real_lvalue_p in that class rvalues are
187 considered lvalues. */
194 (lvalue_p_1 (ref
, /*treat_class_rvalues_as_lvalues=*/1) != clk_none
);
197 /* Return nonzero if REF is an lvalue valid for this language;
198 otherwise, print an error message and return zero. */
201 lvalue_or_else (ref
, string
)
205 int win
= lvalue_p (ref
);
207 error ("non-lvalue in %s", string
);
211 /* INIT is a CALL_EXPR which needs info about its target.
212 TYPE is the type that this initialization should appear to have.
214 Build an encapsulation of the initialization to perform
215 and return it so that it can be processed by language-independent
216 and language-specific expression expanders. */
219 build_cplus_new (type
, init
)
227 /* Make sure that we're not trying to create an instance of an
229 abstract_virtuals_error (NULL_TREE
, type
);
231 if (TREE_CODE (init
) != CALL_EXPR
&& TREE_CODE (init
) != AGGR_INIT_EXPR
)
232 return convert (type
, init
);
234 slot
= build (VAR_DECL
, type
);
235 DECL_ARTIFICIAL (slot
) = 1;
236 layout_decl (slot
, 0);
238 /* We split the CALL_EXPR into its function and its arguments here.
239 Then, in expand_expr, we put them back together. The reason for
240 this is that this expression might be a default argument
241 expression. In that case, we need a new temporary every time the
242 expression is used. That's what break_out_target_exprs does; it
243 replaces every AGGR_INIT_EXPR with a copy that uses a fresh
244 temporary slot. Then, expand_expr builds up a call-expression
245 using the new slot. */
246 fn
= TREE_OPERAND (init
, 0);
247 rval
= build (AGGR_INIT_EXPR
, type
, fn
, TREE_OPERAND (init
, 1), slot
);
248 TREE_SIDE_EFFECTS (rval
) = 1;
249 AGGR_INIT_VIA_CTOR_P (rval
)
250 = (TREE_CODE (fn
) == ADDR_EXPR
251 && TREE_CODE (TREE_OPERAND (fn
, 0)) == FUNCTION_DECL
252 && DECL_CONSTRUCTOR_P (TREE_OPERAND (fn
, 0)));
253 rval
= build (TARGET_EXPR
, type
, slot
, rval
, NULL_TREE
, NULL_TREE
);
254 TREE_SIDE_EFFECTS (rval
) = 1;
259 /* Encapsulate the expression INIT in a TARGET_EXPR. */
262 get_target_expr (init
)
268 slot
= build (VAR_DECL
, TREE_TYPE (init
));
269 DECL_ARTIFICIAL (slot
) = 1;
270 layout_decl (slot
, 0);
271 rval
= build (TARGET_EXPR
, TREE_TYPE (init
), slot
, init
,
272 NULL_TREE
, NULL_TREE
);
273 TREE_SIDE_EFFECTS (rval
) = 1;
278 /* Recursively search EXP for CALL_EXPRs that need cleanups and replace
279 these CALL_EXPRs with tree nodes that will perform the cleanups. */
282 break_out_cleanups (exp
)
287 if (TREE_CODE (tmp
) == CALL_EXPR
288 && TYPE_NEEDS_DESTRUCTOR (TREE_TYPE (tmp
)))
289 return build_cplus_new (TREE_TYPE (tmp
), tmp
);
291 while (TREE_CODE (tmp
) == NOP_EXPR
292 || TREE_CODE (tmp
) == CONVERT_EXPR
293 || TREE_CODE (tmp
) == NON_LVALUE_EXPR
)
295 if (TREE_CODE (TREE_OPERAND (tmp
, 0)) == CALL_EXPR
296 && TYPE_NEEDS_DESTRUCTOR (TREE_TYPE (TREE_OPERAND (tmp
, 0))))
298 TREE_OPERAND (tmp
, 0)
299 = build_cplus_new (TREE_TYPE (TREE_OPERAND (tmp
, 0)),
300 TREE_OPERAND (tmp
, 0));
304 tmp
= TREE_OPERAND (tmp
, 0);
309 /* Recursively perform a preorder search EXP for CALL_EXPRs, making
310 copies where they are found. Returns a deep copy all nodes transitively
311 containing CALL_EXPRs. */
314 break_out_calls (exp
)
317 register tree t1
, t2
= NULL_TREE
;
318 register enum tree_code code
;
319 register int changed
= 0;
322 if (exp
== NULL_TREE
)
325 code
= TREE_CODE (exp
);
327 if (code
== CALL_EXPR
)
328 return copy_node (exp
);
330 /* Don't try and defeat a save_expr, as it should only be done once. */
331 if (code
== SAVE_EXPR
)
334 switch (TREE_CODE_CLASS (code
))
339 case 'c': /* a constant */
340 case 't': /* a type node */
341 case 'x': /* something random, like an identifier or an ERROR_MARK. */
344 case 'd': /* A decl node */
345 #if 0 /* This is bogus. jason 9/21/94 */
347 t1
= break_out_calls (DECL_INITIAL (exp
));
348 if (t1
!= DECL_INITIAL (exp
))
350 exp
= copy_node (exp
);
351 DECL_INITIAL (exp
) = t1
;
356 case 'b': /* A block node */
358 /* Don't know how to handle these correctly yet. Must do a
359 break_out_calls on all DECL_INITIAL values for local variables,
360 and also break_out_calls on all sub-blocks and sub-statements. */
365 case 'e': /* an expression */
366 case 'r': /* a reference */
367 case 's': /* an expression with side effects */
368 for (i
= tree_code_length
[(int) code
] - 1; i
>= 0; i
--)
370 t1
= break_out_calls (TREE_OPERAND (exp
, i
));
371 if (t1
!= TREE_OPERAND (exp
, i
))
373 exp
= copy_node (exp
);
374 TREE_OPERAND (exp
, i
) = t1
;
379 case '<': /* a comparison expression */
380 case '2': /* a binary arithmetic expression */
381 t2
= break_out_calls (TREE_OPERAND (exp
, 1));
382 if (t2
!= TREE_OPERAND (exp
, 1))
384 case '1': /* a unary arithmetic expression */
385 t1
= break_out_calls (TREE_OPERAND (exp
, 0));
386 if (t1
!= TREE_OPERAND (exp
, 0))
390 if (tree_code_length
[(int) code
] == 1)
391 return build1 (code
, TREE_TYPE (exp
), t1
);
393 return build (code
, TREE_TYPE (exp
), t1
, t2
);
400 extern struct obstack
*current_obstack
;
401 extern struct obstack permanent_obstack
, class_obstack
;
402 extern struct obstack
*saveable_obstack
;
403 extern struct obstack
*expression_obstack
;
405 /* Here is how primitive or already-canonicalized types' hash
406 codes are made. MUST BE CONSISTENT WITH tree.c !!! */
407 #define TYPE_HASH(TYPE) ((HOST_WIDE_INT) (TYPE) & 0777777)
409 /* Construct, lay out and return the type of methods belonging to class
410 BASETYPE and whose arguments are described by ARGTYPES and whose values
411 are described by RETTYPE. If each type exists already, reuse it. */
414 build_cplus_method_type (basetype
, rettype
, argtypes
)
415 tree basetype
, rettype
, argtypes
;
421 /* Make a node of the sort we want. */
422 t
= make_node (METHOD_TYPE
);
424 TYPE_METHOD_BASETYPE (t
) = TYPE_MAIN_VARIANT (basetype
);
425 TREE_TYPE (t
) = rettype
;
426 ptype
= build_pointer_type (basetype
);
428 /* The actual arglist for this function includes a "hidden" argument
429 which is "this". Put it into the list of argument types. Make
430 sure that the new argument list is allocated on the same obstack
432 push_obstacks (TYPE_OBSTACK (t
), TYPE_OBSTACK (t
));
433 argtypes
= tree_cons (NULL_TREE
, ptype
, argtypes
);
434 TYPE_ARG_TYPES (t
) = argtypes
;
435 TREE_SIDE_EFFECTS (argtypes
) = 1; /* Mark first argtype as "artificial". */
438 /* If we already have such a type, use the old one and free this one.
439 Note that it also frees up the above cons cell if found. */
440 hashcode
= TYPE_HASH (basetype
) + TYPE_HASH (rettype
) +
441 type_hash_list (argtypes
);
443 t
= type_hash_canon (hashcode
, t
);
445 if (TYPE_SIZE (t
) == 0)
452 build_cplus_array_type_1 (elt_type
, index_type
)
458 if (elt_type
== error_mark_node
|| index_type
== error_mark_node
)
459 return error_mark_node
;
461 push_obstacks_nochange ();
463 /* If both ELT_TYPE and INDEX_TYPE are permanent,
464 make this permanent too. */
465 if (TREE_PERMANENT (elt_type
)
466 && (index_type
== 0 || TREE_PERMANENT (index_type
)))
467 end_temporary_allocation ();
469 if (processing_template_decl
470 || uses_template_parms (elt_type
)
471 || uses_template_parms (index_type
))
473 t
= make_node (ARRAY_TYPE
);
474 TREE_TYPE (t
) = elt_type
;
475 TYPE_DOMAIN (t
) = index_type
;
478 t
= build_array_type (elt_type
, index_type
);
480 /* Push these needs up so that initialization takes place
482 TYPE_NEEDS_CONSTRUCTING (t
)
483 = TYPE_NEEDS_CONSTRUCTING (TYPE_MAIN_VARIANT (elt_type
));
484 TYPE_NEEDS_DESTRUCTOR (t
)
485 = TYPE_NEEDS_DESTRUCTOR (TYPE_MAIN_VARIANT (elt_type
));
491 build_cplus_array_type (elt_type
, index_type
)
496 int type_quals
= CP_TYPE_QUALS (elt_type
);
498 elt_type
= TYPE_MAIN_VARIANT (elt_type
);
500 t
= build_cplus_array_type_1 (elt_type
, index_type
);
502 if (type_quals
!= TYPE_UNQUALIFIED
)
503 t
= cp_build_qualified_type (t
, type_quals
);
508 /* Make a variant of TYPE, qualified with the TYPE_QUALS. Handles
509 arrays correctly. In particular, if TYPE is an array of T's, and
510 TYPE_QUALS is non-empty, returns an array of qualified T's. If
511 at attempt is made to qualify a type illegally, and COMPLAIN is
512 non-zero, an error is issued. If COMPLAIN is zero, error_mark_node
516 cp_build_qualified_type_real (type
, type_quals
, complain
)
523 if (type
== error_mark_node
)
526 if (type_quals
== TYPE_QUALS (type
))
529 /* A restrict-qualified pointer type must be a pointer (or reference)
530 to object or incomplete type. */
531 if ((type_quals
& TYPE_QUAL_RESTRICT
)
532 && TREE_CODE (type
) != TEMPLATE_TYPE_PARM
533 && (!POINTER_TYPE_P (type
)
534 || TYPE_PTRMEM_P (type
)
535 || TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
))
538 cp_error ("`%T' cannot be `restrict'-qualified", type
);
540 return error_mark_node
;
542 type_quals
&= ~TYPE_QUAL_RESTRICT
;
545 if (type_quals
!= TYPE_UNQUALIFIED
546 && TREE_CODE (type
) == FUNCTION_TYPE
)
549 cp_error ("`%T' cannot be `const'-, `volatile'-, or `restrict'-qualified", type
);
551 return error_mark_node
;
552 type_quals
= TYPE_UNQUALIFIED
;
554 else if (TREE_CODE (type
) == ARRAY_TYPE
)
556 /* In C++, the qualification really applies to the array element
557 type. Obtain the appropriately qualified element type. */
560 = cp_build_qualified_type_real (TREE_TYPE (type
),
564 if (element_type
== error_mark_node
)
565 return error_mark_node
;
567 /* See if we already have an identically qualified type. */
568 for (t
= TYPE_MAIN_VARIANT (type
); t
; t
= TYPE_NEXT_VARIANT (t
))
569 if (CP_TYPE_QUALS (t
) == type_quals
)
572 /* If we didn't already have it, create it now. */
575 /* Make a new array type, just like the old one, but with the
576 appropriately qualified element type. */
577 t
= build_type_copy (type
);
578 TREE_TYPE (t
) = element_type
;
581 /* Even if we already had this variant, we update
582 TYPE_NEEDS_CONSTRUCTING and TYPE_NEEDS_DESTRUCTOR in case
583 they changed since the variant was originally created.
585 This seems hokey; if there is some way to use a previous
586 variant *without* coming through here,
587 TYPE_NEEDS_CONSTRUCTING will never be updated. */
588 TYPE_NEEDS_CONSTRUCTING (t
)
589 = TYPE_NEEDS_CONSTRUCTING (TYPE_MAIN_VARIANT (element_type
));
590 TYPE_NEEDS_DESTRUCTOR (t
)
591 = TYPE_NEEDS_DESTRUCTOR (TYPE_MAIN_VARIANT (element_type
));
594 else if (TYPE_PTRMEMFUNC_P (type
))
596 /* For a pointer-to-member type, we can't just return a
597 cv-qualified version of the RECORD_TYPE. If we do, we
598 haven't change the field that contains the actual pointer to
599 a method, and so TYPE_PTRMEMFUNC_FN_TYPE will be wrong. */
602 t
= TYPE_PTRMEMFUNC_FN_TYPE (type
);
603 t
= cp_build_qualified_type_real (t
, type_quals
, complain
);
604 return build_ptrmemfunc_type (t
);
607 /* Retrieve (or create) the appropriately qualified variant. */
608 result
= build_qualified_type (type
, type_quals
);
610 /* If this was a pointer-to-method type, and we just made a copy,
611 then we need to clear the cached associated
612 pointer-to-member-function type; it is not valid for the new
615 && TREE_CODE (type
) == POINTER_TYPE
616 && TREE_CODE (TREE_TYPE (type
)) == METHOD_TYPE
)
617 TYPE_SET_PTRMEMFUNC_TYPE (result
, NULL_TREE
);
622 /* Returns the canonical version of TYPE. In other words, if TYPE is
623 a typedef, returns the underlying type. The cv-qualification of
624 the type returned matches the type input; they will always be
628 canonical_type_variant (t
)
631 return cp_build_qualified_type (TYPE_MAIN_VARIANT (t
), CP_TYPE_QUALS (t
));
634 /* Add OFFSET to all base types of T.
636 OFFSET, which is a type offset, is number of bytes.
638 Note that we don't have to worry about having two paths to the
639 same base type, since this type owns its association list. */
642 propagate_binfo_offsets (binfo
, offset
)
646 tree binfos
= BINFO_BASETYPES (binfo
);
647 int i
, n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
649 for (i
= 0; i
< n_baselinks
; /* note increment is done in the loop. */)
651 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
653 if (TREE_VIA_VIRTUAL (base_binfo
))
658 tree delta
= NULL_TREE
;
660 for (j
= i
+1; j
< n_baselinks
; j
++)
661 if (! TREE_VIA_VIRTUAL (TREE_VEC_ELT (binfos
, j
)))
663 /* The next basetype offset must take into account the space
664 between the classes, not just the size of each class. */
665 delta
= size_binop (MINUS_EXPR
,
666 BINFO_OFFSET (TREE_VEC_ELT (binfos
, j
)),
667 BINFO_OFFSET (base_binfo
));
672 if (BINFO_OFFSET_ZEROP (base_binfo
))
673 BINFO_OFFSET (base_binfo
) = offset
;
675 BINFO_OFFSET (base_binfo
)
676 = size_binop (PLUS_EXPR
, BINFO_OFFSET (base_binfo
), offset
);
678 BINFO_OFFSET (base_binfo
) = offset
;
681 propagate_binfo_offsets (base_binfo
, offset
);
683 /* Go to our next class that counts for offset propagation. */
686 offset
= size_binop (PLUS_EXPR
, offset
, delta
);
691 /* Makes new binfos for the indirect bases under BINFO, and updates
692 BINFO_OFFSET for them and their bases. */
695 unshare_base_binfos (binfo
)
698 tree binfos
= BINFO_BASETYPES (binfo
);
702 if (binfos
== NULL_TREE
)
705 /* Now unshare the structure beneath BINFO. */
706 for (j
= TREE_VEC_LENGTH (binfos
)-1;
709 tree base_binfo
= TREE_VEC_ELT (binfos
, j
);
710 new_binfo
= TREE_VEC_ELT (binfos
, j
)
711 = make_binfo (BINFO_OFFSET (base_binfo
),
713 BINFO_VTABLE (base_binfo
),
714 BINFO_VIRTUALS (base_binfo
));
715 TREE_VIA_PUBLIC (new_binfo
) = TREE_VIA_PUBLIC (base_binfo
);
716 TREE_VIA_PROTECTED (new_binfo
) = TREE_VIA_PROTECTED (base_binfo
);
717 TREE_VIA_VIRTUAL (new_binfo
) = TREE_VIA_VIRTUAL (base_binfo
);
718 BINFO_INHERITANCE_CHAIN (new_binfo
) = binfo
;
719 unshare_base_binfos (new_binfo
);
723 /* Finish the work of layout_record, now taking virtual bases into account.
724 Also compute the actual offsets that our base classes will have.
725 This must be performed after the fields are laid out, since virtual
726 baseclasses must lay down at the end of the record.
728 Returns the maximum number of virtual functions any of the
729 baseclasses provide. */
732 layout_basetypes (rec
, max
)
736 tree binfos
= TYPE_BINFO_BASETYPES (rec
);
737 int i
, n_baseclasses
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
741 unsigned int record_align
= MAX (BITS_PER_UNIT
, TYPE_ALIGN (rec
));
742 unsigned int desired_align
;
744 /* Record size so far is CONST_SIZE bits, where CONST_SIZE is an integer. */
745 register unsigned int const_size
= 0;
746 unsigned int nonvirtual_const_size
;
748 #ifdef STRUCTURE_SIZE_BOUNDARY
749 /* Packed structures don't need to have minimum size. */
750 if (! TYPE_PACKED (rec
))
751 record_align
= MAX (record_align
, STRUCTURE_SIZE_BOUNDARY
);
754 /* Get all the virtual base types that this type uses. The
755 TREE_VALUE slot holds the virtual baseclass type. Note that
756 get_vbase_types makes copies of the virtual base BINFOs, so that
757 the vbase_types are unshared. */
758 vbase_types
= CLASSTYPE_VBASECLASSES (rec
);
760 my_friendly_assert (TREE_CODE (TYPE_SIZE (rec
)) == INTEGER_CST
, 19970302);
761 const_size
= TREE_INT_CST_LOW (TYPE_SIZE (rec
));
763 nonvirtual_const_size
= const_size
;
767 tree basetype
= BINFO_TYPE (vbase_types
);
770 desired_align
= TYPE_ALIGN (basetype
);
771 record_align
= MAX (record_align
, desired_align
);
774 offset
= integer_zero_node
;
777 /* Give each virtual base type the alignment it wants. */
778 const_size
= CEIL (const_size
, desired_align
) * desired_align
;
779 offset
= size_int (CEIL (const_size
, BITS_PER_UNIT
));
782 if (CLASSTYPE_VSIZE (basetype
) > max
)
783 max
= CLASSTYPE_VSIZE (basetype
);
784 BINFO_OFFSET (vbase_types
) = offset
;
786 /* Every virtual baseclass takes a least a UNIT, so that we can
787 take it's address and get something different for each base. */
788 const_size
+= MAX (BITS_PER_UNIT
,
789 TREE_INT_CST_LOW (CLASSTYPE_SIZE (basetype
)));
791 vbase_types
= TREE_CHAIN (vbase_types
);
796 /* Because a virtual base might take a single byte above,
797 we have to re-adjust the total size to make sure it is
798 a multiple of the alignment. */
799 /* Give the whole object the alignment it wants. */
800 const_size
= CEIL (const_size
, record_align
) * record_align
;
803 /* Set the alignment in the complete type. We don't set CLASSTYPE_ALIGN
804 here, as that is for this class, without any virtual base classes. */
805 TYPE_ALIGN (rec
) = record_align
;
806 if (const_size
!= nonvirtual_const_size
)
808 TYPE_SIZE (rec
) = size_int (const_size
);
809 TYPE_SIZE_UNIT (rec
) = size_binop (FLOOR_DIV_EXPR
, TYPE_SIZE (rec
),
810 size_int (BITS_PER_UNIT
));
813 /* Now propagate offset information throughout the lattice. */
814 for (i
= 0; i
< n_baseclasses
; i
++)
816 register tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
817 register tree basetype
= BINFO_TYPE (base_binfo
);
818 tree field
= TYPE_FIELDS (rec
);
820 if (TREE_VIA_VIRTUAL (base_binfo
))
823 my_friendly_assert (TREE_TYPE (field
) == basetype
, 23897);
825 if (get_base_distance (basetype
, rec
, 0, (tree
*)0) == -2)
826 cp_warning ("direct base `%T' inaccessible in `%T' due to ambiguity",
829 BINFO_OFFSET (base_binfo
)
830 = size_int (CEIL (TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field
)),
832 propagate_binfo_offsets (base_binfo
, BINFO_OFFSET (base_binfo
));
833 TYPE_FIELDS (rec
) = TREE_CHAIN (field
);
836 for (vbase_types
= CLASSTYPE_VBASECLASSES (rec
); vbase_types
;
837 vbase_types
= TREE_CHAIN (vbase_types
))
839 BINFO_INHERITANCE_CHAIN (vbase_types
) = TYPE_BINFO (rec
);
840 unshare_base_binfos (vbase_types
);
841 propagate_binfo_offsets (vbase_types
, BINFO_OFFSET (vbase_types
));
845 tree basetype
= BINFO_TYPE (vbase_types
);
846 if (get_base_distance (basetype
, rec
, 0, (tree
*)0) == -2)
847 cp_warning ("virtual base `%T' inaccessible in `%T' due to ambiguity",
855 /* If the empty base field in DECL overlaps with a base of the same type in
856 NEWDECL, which is either another base field or the first data field of
857 the class, pad the base just before NEWDECL and return 1. Otherwise,
861 avoid_overlap (decl
, newdecl
)
866 if (newdecl
== NULL_TREE
867 || ! types_overlap_p (TREE_TYPE (decl
), TREE_TYPE (newdecl
)))
870 for (field
= decl
; TREE_CHAIN (field
) && TREE_CHAIN (field
) != newdecl
;
871 field
= TREE_CHAIN (field
))
874 DECL_SIZE (field
) = integer_one_node
;
879 /* Returns a list of fields to stand in for the base class subobjects
880 of REC. These fields are later removed by layout_basetypes. */
883 build_base_fields (rec
)
886 /* Chain to hold all the new FIELD_DECLs which stand in for base class
888 tree base_decls
= NULL_TREE
;
889 tree binfos
= TYPE_BINFO_BASETYPES (rec
);
890 int n_baseclasses
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
892 int i
, saw_empty
= 0;
893 unsigned int base_align
= 0;
895 for (i
= 0; i
< n_baseclasses
; ++i
)
897 register tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
898 register tree basetype
= BINFO_TYPE (base_binfo
);
900 if (TYPE_SIZE (basetype
) == 0)
901 /* This error is now reported in xref_tag, thus giving better
902 location information. */
905 if (TREE_VIA_VIRTUAL (base_binfo
))
908 decl
= build_lang_decl (FIELD_DECL
, NULL_TREE
, basetype
);
909 DECL_ARTIFICIAL (decl
) = 1;
910 DECL_FIELD_CONTEXT (decl
) = DECL_CLASS_CONTEXT (decl
) = rec
;
911 DECL_SIZE (decl
) = CLASSTYPE_SIZE (basetype
);
912 DECL_ALIGN (decl
) = CLASSTYPE_ALIGN (basetype
);
913 TREE_CHAIN (decl
) = base_decls
;
918 /* Brain damage for backwards compatibility. For no good reason,
919 the old layout_basetypes made every base at least as large as
920 the alignment for the bases up to that point, gratuitously
921 wasting space. So we do the same thing here. */
922 base_align
= MAX (base_align
, DECL_ALIGN (decl
));
924 = size_int (MAX (TREE_INT_CST_LOW (DECL_SIZE (decl
)),
927 else if (DECL_SIZE (decl
) == integer_zero_node
)
931 /* Reverse the list of fields so we allocate the bases in the proper
933 base_decls
= nreverse (base_decls
);
935 /* In the presence of empty base classes, we run the risk of allocating
936 two objects of the same class on top of one another. Avoid that. */
937 if (flag_new_abi
&& saw_empty
)
938 for (decl
= base_decls
; decl
; decl
= TREE_CHAIN (decl
))
940 if (DECL_SIZE (decl
) == integer_zero_node
)
942 /* First step through the following bases until we find
943 an overlap or a non-empty base. */
944 for (nextdecl
= TREE_CHAIN (decl
); nextdecl
;
945 nextdecl
= TREE_CHAIN (nextdecl
))
947 if (avoid_overlap (decl
, nextdecl
)
948 || DECL_SIZE (nextdecl
) != integer_zero_node
)
952 /* If we're still looking, also check against the first
954 for (nextdecl
= TYPE_FIELDS (rec
);
955 nextdecl
&& TREE_CODE (nextdecl
) != FIELD_DECL
;
956 nextdecl
= TREE_CHAIN (nextdecl
))
958 avoid_overlap (decl
, nextdecl
);
966 /* Returns list of virtual base class pointers in a FIELD_DECL chain. */
969 build_vbase_pointer_fields (rec
)
972 /* Chain to hold all the new FIELD_DECLs which point at virtual
974 tree vbase_decls
= NULL_TREE
;
975 tree binfos
= TYPE_BINFO_BASETYPES (rec
);
976 int n_baseclasses
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
980 /* Handle basetypes almost like fields, but record their
981 offsets differently. */
983 for (i
= 0; i
< n_baseclasses
; i
++)
985 register tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
986 register tree basetype
= BINFO_TYPE (base_binfo
);
988 if (TYPE_SIZE (basetype
) == 0)
989 /* This error is now reported in xref_tag, thus giving better
990 location information. */
993 /* All basetypes are recorded in the association list of the
996 if (TREE_VIA_VIRTUAL (base_binfo
))
1001 /* The offset for a virtual base class is only used in computing
1002 virtual function tables and for initializing virtual base
1003 pointers. It is built once `get_vbase_types' is called. */
1005 /* If this basetype can come from another vbase pointer
1006 without an additional indirection, we will share
1007 that pointer. If an indirection is involved, we
1008 make our own pointer. */
1009 for (j
= 0; j
< n_baseclasses
; j
++)
1011 tree other_base_binfo
= TREE_VEC_ELT (binfos
, j
);
1012 if (! TREE_VIA_VIRTUAL (other_base_binfo
)
1013 && binfo_member (basetype
,
1014 CLASSTYPE_VBASECLASSES (BINFO_TYPE
1019 FORMAT_VBASE_NAME (name
, basetype
);
1020 decl
= build_lang_decl (FIELD_DECL
, get_identifier (name
),
1021 build_pointer_type (basetype
));
1022 /* If you change any of the below, take a look at all the
1023 other VFIELD_BASEs and VTABLE_BASEs in the code, and change
1025 DECL_ASSEMBLER_NAME (decl
) = get_identifier (VTABLE_BASE
);
1026 DECL_VIRTUAL_P (decl
) = 1;
1027 DECL_ARTIFICIAL (decl
) = 1;
1028 DECL_FIELD_CONTEXT (decl
) = rec
;
1029 DECL_CLASS_CONTEXT (decl
) = rec
;
1030 DECL_FCONTEXT (decl
) = basetype
;
1031 DECL_SAVED_INSNS (decl
) = 0;
1032 DECL_FIELD_SIZE (decl
) = 0;
1033 DECL_ALIGN (decl
) = TYPE_ALIGN (ptr_type_node
);
1034 TREE_CHAIN (decl
) = vbase_decls
;
1035 BINFO_VPTR_FIELD (base_binfo
) = decl
;
1039 /* The space this decl occupies has already been accounted for. */
1047 /* Hashing of lists so that we don't make duplicates.
1048 The entry point is `list_hash_canon'. */
1050 /* Each hash table slot is a bucket containing a chain
1051 of these structures. */
1055 struct list_hash
*next
; /* Next structure in the bucket. */
1056 int hashcode
; /* Hash code of this list. */
1057 tree list
; /* The list recorded here. */
1060 /* Now here is the hash table. When recording a list, it is added
1061 to the slot whose index is the hash code mod the table size.
1062 Note that the hash table is used for several kinds of lists.
1063 While all these live in the same table, they are completely independent,
1064 and the hash code is computed differently for each of these. */
1066 #define TYPE_HASH_SIZE 59
1067 static struct list_hash
*list_hash_table
[TYPE_HASH_SIZE
];
1069 /* Compute a hash code for a list (chain of TREE_LIST nodes
1070 with goodies in the TREE_PURPOSE, TREE_VALUE, and bits of the
1071 TREE_COMMON slots), by adding the hash codes of the individual entries. */
1074 list_hash (purpose
, value
, chain
)
1075 tree purpose
, value
, chain
;
1077 register int hashcode
= 0;
1080 hashcode
+= TYPE_HASH (chain
);
1083 hashcode
+= TYPE_HASH (value
);
1087 hashcode
+= TYPE_HASH (purpose
);
1093 /* Look in the type hash table for a type isomorphic to TYPE.
1094 If one is found, return it. Otherwise return 0. */
1097 list_hash_lookup (hashcode
, purpose
, value
, chain
)
1099 tree purpose
, value
, chain
;
1101 register struct list_hash
*h
;
1103 for (h
= list_hash_table
[hashcode
% TYPE_HASH_SIZE
]; h
; h
= h
->next
)
1104 if (h
->hashcode
== hashcode
1105 && TREE_PURPOSE (h
->list
) == purpose
1106 && TREE_VALUE (h
->list
) == value
1107 && TREE_CHAIN (h
->list
) == chain
)
1112 /* Add an entry to the list-hash-table
1113 for a list TYPE whose hash code is HASHCODE. */
1116 list_hash_add (hashcode
, list
)
1120 register struct list_hash
*h
;
1122 h
= (struct list_hash
*) obstack_alloc (&class_obstack
, sizeof (struct list_hash
));
1123 h
->hashcode
= hashcode
;
1125 h
->next
= list_hash_table
[hashcode
% TYPE_HASH_SIZE
];
1126 list_hash_table
[hashcode
% TYPE_HASH_SIZE
] = h
;
1129 /* Given list components PURPOSE, VALUE, AND CHAIN, return the canonical
1130 object for an identical list if one already exists. Otherwise, build a
1131 new one, and record it as the canonical object. */
1133 /* Set to 1 to debug without canonicalization. Never set by program. */
1135 static int debug_no_list_hash
= 0;
1138 hash_tree_cons (purpose
, value
, chain
)
1139 tree purpose
, value
, chain
;
1141 struct obstack
*ambient_obstack
= current_obstack
;
1145 if (! debug_no_list_hash
)
1147 hashcode
= list_hash (purpose
, value
, chain
);
1148 t
= list_hash_lookup (hashcode
, purpose
, value
, chain
);
1153 current_obstack
= &class_obstack
;
1155 t
= tree_cons (purpose
, value
, chain
);
1157 /* If this is a new list, record it for later reuse. */
1158 if (! debug_no_list_hash
)
1159 list_hash_add (hashcode
, t
);
1161 current_obstack
= ambient_obstack
;
1165 /* Constructor for hashed lists. */
1168 hash_tree_chain (value
, chain
)
1171 return hash_tree_cons (NULL_TREE
, value
, chain
);
1174 /* Similar, but used for concatenating two lists. */
1177 hash_chainon (list1
, list2
)
1184 if (TREE_CHAIN (list1
) == NULL_TREE
)
1185 return hash_tree_chain (TREE_VALUE (list1
), list2
);
1186 return hash_tree_chain (TREE_VALUE (list1
),
1187 hash_chainon (TREE_CHAIN (list1
), list2
));
1190 /* Build an association between TYPE and some parameters:
1192 OFFSET is the offset added to `this' to convert it to a pointer
1195 BINFO is the base binfo to use, if we are deriving from one. This
1196 is necessary, as we want specialized parent binfos from base
1197 classes, so that the VTABLE_NAMEs of bases are for the most derived
1198 type, instead of the simple type.
1200 VTABLE is the virtual function table with which to initialize
1201 sub-objects of type TYPE.
1203 VIRTUALS are the virtual functions sitting in VTABLE. */
1206 make_binfo (offset
, binfo
, vtable
, virtuals
)
1208 tree vtable
, virtuals
;
1210 tree new_binfo
= make_tree_vec (7);
1213 if (TREE_CODE (binfo
) == TREE_VEC
)
1214 type
= BINFO_TYPE (binfo
);
1218 binfo
= CLASS_TYPE_P (type
) ? TYPE_BINFO (binfo
) : NULL_TREE
;
1221 TREE_TYPE (new_binfo
) = TYPE_MAIN_VARIANT (type
);
1222 BINFO_OFFSET (new_binfo
) = offset
;
1223 BINFO_VTABLE (new_binfo
) = vtable
;
1224 BINFO_VIRTUALS (new_binfo
) = virtuals
;
1225 BINFO_VPTR_FIELD (new_binfo
) = NULL_TREE
;
1227 if (binfo
&& BINFO_BASETYPES (binfo
) != NULL_TREE
)
1228 BINFO_BASETYPES (new_binfo
) = copy_node (BINFO_BASETYPES (binfo
));
1232 /* Return the binfo value for ELEM in TYPE. */
1235 binfo_value (elem
, type
)
1239 if (get_base_distance (elem
, type
, 0, (tree
*)0) == -2)
1240 compiler_error ("base class `%s' ambiguous in binfo_value",
1241 TYPE_NAME_STRING (elem
));
1243 return TYPE_BINFO (type
);
1244 if (TREE_CODE (elem
) == RECORD_TYPE
&& TYPE_BINFO (elem
) == type
)
1246 return get_binfo (elem
, type
, 0);
1249 /* Return a reversed copy of the BINFO-chain given by PATH. (If the
1250 BINFO_INHERITANCE_CHAIN points from base classes to derived
1251 classes, it will instead point from derived classes to base
1252 classes.) Returns the first node in the reversed chain. */
1258 register tree prev
= NULL_TREE
, cur
;
1259 push_expression_obstack ();
1260 for (cur
= path
; cur
; cur
= BINFO_INHERITANCE_CHAIN (cur
))
1262 tree r
= copy_node (cur
);
1263 BINFO_INHERITANCE_CHAIN (r
) = prev
;
1274 unsigned HOST_WIDE_INT n
;
1277 fprintf (stderr
, "type \"%s\"; offset = %ld\n",
1278 TYPE_NAME_STRING (BINFO_TYPE (elem
)),
1279 (long) TREE_INT_CST_LOW (BINFO_OFFSET (elem
)));
1280 fprintf (stderr
, "vtable type:\n");
1281 debug_tree (BINFO_TYPE (elem
));
1282 if (BINFO_VTABLE (elem
))
1283 fprintf (stderr
, "vtable decl \"%s\"\n", IDENTIFIER_POINTER (DECL_NAME (BINFO_VTABLE (elem
))));
1285 fprintf (stderr
, "no vtable decl yet\n");
1286 fprintf (stderr
, "virtuals:\n");
1287 virtuals
= BINFO_VIRTUALS (elem
);
1289 n
= skip_rtti_stuff (&virtuals
, BINFO_TYPE (elem
));
1293 tree fndecl
= TREE_VALUE (virtuals
);
1294 fprintf (stderr
, "%s [%ld =? %ld]\n",
1295 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (fndecl
)),
1296 (long) n
, (long) TREE_INT_CST_LOW (DECL_VINDEX (fndecl
)));
1298 virtuals
= TREE_CHAIN (virtuals
);
1302 /* Initialize an CPLUS_BINDING node that does not live on an obstack. */
1306 struct tree_binding
* node
;
1308 static struct tree_binding
* source
;
1311 extern struct obstack permanent_obstack
;
1312 push_obstacks (&permanent_obstack
, &permanent_obstack
);
1313 source
= (struct tree_binding
*)make_node (CPLUS_BINDING
);
1317 TREE_PERMANENT ((tree
)node
) = 0;
1326 if (TREE_CODE (t
) == FUNCTION_DECL
)
1328 else if (TREE_CODE (t
) == OVERLOAD
)
1330 for (i
=0; t
; t
= OVL_CHAIN (t
))
1335 my_friendly_abort (359);
1340 is_overloaded_fn (x
)
1343 /* A baselink is also considered an overloaded function. */
1344 if (TREE_CODE (x
) == OFFSET_REF
)
1345 x
= TREE_OPERAND (x
, 1);
1348 return (TREE_CODE (x
) == FUNCTION_DECL
1349 || TREE_CODE (x
) == TEMPLATE_ID_EXPR
1350 || DECL_FUNCTION_TEMPLATE_P (x
)
1351 || TREE_CODE (x
) == OVERLOAD
);
1355 really_overloaded_fn (x
)
1358 /* A baselink is also considered an overloaded function. */
1359 if (TREE_CODE (x
) == OFFSET_REF
)
1360 x
= TREE_OPERAND (x
, 1);
1363 return (TREE_CODE (x
) == OVERLOAD
1364 && (TREE_CHAIN (x
) != NULL_TREE
1365 || DECL_FUNCTION_TEMPLATE_P (OVL_FUNCTION (x
))));
1372 my_friendly_assert (is_overloaded_fn (from
), 9);
1373 /* A baselink is also considered an overloaded function. */
1374 if (BASELINK_P (from
))
1375 from
= TREE_VALUE (from
);
1376 return OVL_CURRENT (from
);
1379 /* Returns nonzero if T is a ->* or .* expression that refers to a
1386 return (TREE_CODE (t
) == OFFSET_REF
1387 && TYPE_PTRMEMFUNC_P (TREE_TYPE (TREE_OPERAND (t
, 1))));
1390 /* Return a new OVL node, concatenating it with the old one. */
1393 ovl_cons (decl
, chain
)
1397 tree result
= make_node (OVERLOAD
);
1398 TREE_TYPE (result
) = unknown_type_node
;
1399 OVL_FUNCTION (result
) = decl
;
1400 TREE_CHAIN (result
) = chain
;
1405 /* Same as ovl_cons, but on the scratch_obstack. */
1408 scratch_ovl_cons (value
, chain
)
1412 register struct obstack
*ambient_obstack
= current_obstack
;
1413 extern struct obstack
*expression_obstack
;
1414 current_obstack
= expression_obstack
;
1415 node
= ovl_cons (value
, chain
);
1416 current_obstack
= ambient_obstack
;
1420 /* Build a new overloaded function. If this is the first one,
1421 just return it; otherwise, ovl_cons the _DECLs */
1424 build_overload (decl
, chain
)
1428 if (! chain
&& TREE_CODE (decl
) != TEMPLATE_DECL
)
1430 if (chain
&& TREE_CODE (chain
) != OVERLOAD
)
1431 chain
= ovl_cons (chain
, NULL_TREE
);
1432 return ovl_cons (decl
, chain
);
1435 /* True if fn is in ovl. */
1438 ovl_member (fn
, ovl
)
1442 if (ovl
== NULL_TREE
)
1444 if (TREE_CODE (ovl
) != OVERLOAD
)
1446 for (; ovl
; ovl
= OVL_CHAIN (ovl
))
1447 if (OVL_FUNCTION (ovl
) == fn
)
1453 is_aggr_type_2 (t1
, t2
)
1456 if (TREE_CODE (t1
) != TREE_CODE (t2
))
1458 return IS_AGGR_TYPE (t1
) && IS_AGGR_TYPE (t2
);
1461 #define PRINT_RING_SIZE 4
1464 lang_printable_name (decl
, v
)
1468 static tree decl_ring
[PRINT_RING_SIZE
];
1469 static char *print_ring
[PRINT_RING_SIZE
];
1470 static int ring_counter
;
1473 /* Only cache functions. */
1475 || TREE_CODE (decl
) != FUNCTION_DECL
1476 || DECL_LANG_SPECIFIC (decl
) == 0)
1477 return lang_decl_name (decl
, v
);
1479 /* See if this print name is lying around. */
1480 for (i
= 0; i
< PRINT_RING_SIZE
; i
++)
1481 if (decl_ring
[i
] == decl
)
1482 /* yes, so return it. */
1483 return print_ring
[i
];
1485 if (++ring_counter
== PRINT_RING_SIZE
)
1488 if (current_function_decl
!= NULL_TREE
)
1490 if (decl_ring
[ring_counter
] == current_function_decl
)
1492 if (ring_counter
== PRINT_RING_SIZE
)
1494 if (decl_ring
[ring_counter
] == current_function_decl
)
1495 my_friendly_abort (106);
1498 if (print_ring
[ring_counter
])
1499 free (print_ring
[ring_counter
]);
1501 print_ring
[ring_counter
] = xstrdup (lang_decl_name (decl
, v
));
1502 decl_ring
[ring_counter
] = decl
;
1503 return print_ring
[ring_counter
];
1506 /* Build the FUNCTION_TYPE or METHOD_TYPE which may throw exceptions
1507 listed in RAISES. */
1510 build_exception_variant (type
, raises
)
1514 tree v
= TYPE_MAIN_VARIANT (type
);
1515 int type_quals
= TYPE_QUALS (type
);
1517 for (; v
; v
= TYPE_NEXT_VARIANT (v
))
1518 if (TYPE_QUALS (v
) == type_quals
1519 && comp_except_specs (raises
, TYPE_RAISES_EXCEPTIONS (v
), 1))
1522 /* Need to build a new variant. */
1523 v
= build_type_copy (type
);
1525 if (raises
&& ! TREE_PERMANENT (raises
))
1526 raises
= copy_to_permanent (raises
);
1528 TYPE_RAISES_EXCEPTIONS (v
) = raises
;
1532 /* Given a TEMPLATE_TEMPLATE_PARM node T, create a new one together with its
1533 lang_specific field and its corresponding TEMPLATE_DECL node */
1536 copy_template_template_parm (t
)
1539 tree
template = TYPE_NAME (t
);
1542 /* Make sure these end up on the permanent_obstack. */
1543 push_permanent_obstack ();
1545 t2
= make_lang_type (TEMPLATE_TEMPLATE_PARM
);
1546 template = copy_node (template);
1547 copy_lang_decl (template);
1551 TREE_TYPE (template) = t2
;
1552 TYPE_NAME (t2
) = template;
1553 TYPE_STUB_DECL (t2
) = template;
1555 /* No need to copy these */
1556 TYPE_FIELDS (t2
) = TYPE_FIELDS (t
);
1557 TEMPLATE_TEMPLATE_PARM_TEMPLATE_INFO (t2
)
1558 = TEMPLATE_TEMPLATE_PARM_TEMPLATE_INFO (t
);
1562 /* Walk through the tree structure T, applying func. If func ever returns
1563 non-null, return that value. */
1566 search_tree (t
, func
)
1568 tree (*func
) PROTO((tree
));
1570 #define TRY(ARG) if (tmp=search_tree (ARG, func), tmp != NULL_TREE) return tmp
1573 enum tree_code code
;
1582 /* Handle some common cases up front. */
1583 code
= TREE_CODE (t
);
1584 if (TREE_CODE_CLASS (code
) == '1')
1586 TRY (TREE_OPERAND (t
, 0));
1589 else if (TREE_CODE_CLASS (code
) == '2' || TREE_CODE_CLASS (code
) == '<')
1591 TRY (TREE_OPERAND (t
, 0));
1592 TRY (TREE_OPERAND (t
, 1));
1601 case IDENTIFIER_NODE
:
1608 case NAMESPACE_DECL
:
1612 TRY (TREE_TYPE (t
));
1616 TRY (TREE_TYPE (t
));
1617 TRY (TREE_CHAIN (t
));
1621 TRY (TREE_PURPOSE (t
));
1622 TRY (TREE_VALUE (t
));
1623 TRY (TREE_CHAIN (t
));
1627 TRY (OVL_FUNCTION (t
));
1628 TRY (OVL_CHAIN (t
));
1633 int len
= TREE_VEC_LENGTH (t
);
1637 TRY (TREE_VEC_ELT (t
, len
));
1648 TRY (TREE_TYPE (t
));
1653 case AGGR_INIT_EXPR
:
1655 TRY (TREE_OPERAND (t
, 0));
1656 TRY (TREE_OPERAND (t
, 1));
1657 TRY (TREE_OPERAND (t
, 2));
1660 case TRUTH_AND_EXPR
:
1662 case TRUTH_XOR_EXPR
:
1663 case TRUTH_ANDIF_EXPR
:
1664 case TRUTH_ORIF_EXPR
:
1665 case PREDECREMENT_EXPR
:
1666 case PREINCREMENT_EXPR
:
1667 case POSTDECREMENT_EXPR
:
1668 case POSTINCREMENT_EXPR
:
1671 case TRY_CATCH_EXPR
:
1672 case WITH_CLEANUP_EXPR
:
1677 TRY (TREE_OPERAND (t
, 0));
1678 TRY (TREE_OPERAND (t
, 1));
1684 case TRUTH_NOT_EXPR
:
1686 case CLEANUP_POINT_EXPR
:
1691 TRY (TREE_OPERAND (t
, 0));
1698 case PSEUDO_DTOR_EXPR
:
1702 TRY (TREE_REALPART (t
));
1703 TRY (TREE_IMAGPART (t
));
1707 TRY (CONSTRUCTOR_ELTS (t
));
1710 case TEMPLATE_TEMPLATE_PARM
:
1711 case TEMPLATE_PARM_INDEX
:
1712 case TEMPLATE_TYPE_PARM
:
1730 case REFERENCE_TYPE
:
1731 TRY (TREE_TYPE (t
));
1736 TRY (TREE_TYPE (t
));
1737 TRY (TYPE_ARG_TYPES (t
));
1741 TRY (TREE_TYPE (t
));
1742 TRY (TYPE_DOMAIN (t
));
1746 TRY (TYPE_MAX_VALUE (t
));
1750 TRY (TREE_TYPE (t
));
1751 TRY (TYPE_OFFSET_BASETYPE (t
));
1755 if (TYPE_PTRMEMFUNC_P (t
))
1756 TRY (TYPE_PTRMEMFUNC_FN_TYPE (t
));
1760 my_friendly_abort (19990803);
1768 /* Passed to search_tree. Checks for the use of types with no linkage. */
1771 no_linkage_helper (t
)
1775 && (IS_AGGR_TYPE (t
) || TREE_CODE (t
) == ENUMERAL_TYPE
)
1776 && (decl_function_context (TYPE_MAIN_DECL (t
))
1777 || ANON_AGGRNAME_P (TYPE_IDENTIFIER (t
))))
1782 /* Check if the type T depends on a type with no linkage and if so, return
1786 no_linkage_check (t
)
1789 /* There's no point in checking linkage on template functions; we
1790 can't know their complete types. */
1791 if (processing_template_decl
)
1794 t
= search_tree (t
, no_linkage_helper
);
1795 if (t
!= error_mark_node
)
1801 /* Make copies of all the nodes below T. If FUNC is non-NULL, call it
1807 tree (*func
) PROTO((tree
));
1810 enum tree_code code
;
1822 /* Handle some common cases up front. */
1823 code
= TREE_CODE (t
);
1824 if (TREE_CODE_CLASS (code
) == '1')
1827 TREE_TYPE (t
) = mapcar (TREE_TYPE (t
), func
);
1828 TREE_OPERAND (t
, 0) = mapcar (TREE_OPERAND (t
, 0), func
);
1831 else if (TREE_CODE_CLASS (code
) == '2' || TREE_CODE_CLASS (code
) == '<')
1834 TREE_TYPE (t
) = mapcar (TREE_TYPE (t
), func
);
1835 TREE_OPERAND (t
, 0) = mapcar (TREE_OPERAND (t
, 0), func
);
1836 TREE_OPERAND (t
, 1) = mapcar (TREE_OPERAND (t
, 1), func
);
1840 switch (TREE_CODE (t
))
1843 return error_mark_node
;
1848 /* Rather than aborting, return error_mark_node. This allows us
1849 to report a sensible error message on code like this:
1851 void g() { int i; f<i>(7); }
1855 void g() { const int i = 7; f<i>(7); }
1857 however, we must actually return the constant initializer. */
1858 if (TREE_READONLY_DECL_P (t
))
1860 tmp
= decl_constant_value (t
);
1862 return mapcar (tmp
, func
);
1864 return error_mark_node
;
1868 tree chain
= TREE_CHAIN (t
);
1870 TREE_CHAIN (t
) = mapcar (chain
, func
);
1871 TREE_TYPE (t
) = mapcar (TREE_TYPE (t
), func
);
1872 DECL_INITIAL (t
) = mapcar (DECL_INITIAL (t
), func
);
1873 DECL_SIZE (t
) = mapcar (DECL_SIZE (t
), func
);
1879 tree chain
= TREE_CHAIN (t
);
1881 TREE_PURPOSE (t
) = mapcar (TREE_PURPOSE (t
), func
);
1882 TREE_VALUE (t
) = mapcar (TREE_VALUE (t
), func
);
1883 TREE_CHAIN (t
) = mapcar (chain
, func
);
1889 tree chain
= OVL_CHAIN (t
);
1891 OVL_FUNCTION (t
) = mapcar (OVL_FUNCTION (t
), func
);
1892 OVL_CHAIN (t
) = mapcar (chain
, func
);
1898 int len
= TREE_VEC_LENGTH (t
);
1902 TREE_VEC_ELT (t
, len
) = mapcar (TREE_VEC_ELT (t
, len
), func
);
1909 return copy_node (t
);
1913 TREE_TYPE (t
) = mapcar (TREE_TYPE (t
), func
);
1914 PTRMEM_CST_MEMBER (t
) = mapcar (PTRMEM_CST_MEMBER (t
), func
);
1919 case AGGR_INIT_EXPR
:
1921 TREE_OPERAND (t
, 0) = mapcar (TREE_OPERAND (t
, 0), func
);
1922 TREE_OPERAND (t
, 1) = mapcar (TREE_OPERAND (t
, 1), func
);
1923 TREE_OPERAND (t
, 2) = mapcar (TREE_OPERAND (t
, 2), func
);
1926 case TRUTH_AND_EXPR
:
1928 case TRUTH_XOR_EXPR
:
1929 case TRUTH_ANDIF_EXPR
:
1930 case TRUTH_ORIF_EXPR
:
1931 case PREDECREMENT_EXPR
:
1932 case PREINCREMENT_EXPR
:
1933 case POSTDECREMENT_EXPR
:
1934 case POSTINCREMENT_EXPR
:
1937 case TRY_CATCH_EXPR
:
1938 case WITH_CLEANUP_EXPR
:
1943 TREE_OPERAND (t
, 0) = mapcar (TREE_OPERAND (t
, 0), func
);
1944 TREE_OPERAND (t
, 1) = mapcar (TREE_OPERAND (t
, 1), func
);
1949 TREE_TYPE (t
) = mapcar (TREE_TYPE (t
), func
);
1950 TREE_OPERAND (t
, 0) = mapcar (TREE_OPERAND (t
, 0), func
);
1951 TREE_OPERAND (t
, 1) = mapcar (TREE_OPERAND (t
, 1), func
);
1952 TREE_OPERAND (t
, 2) = NULL_TREE
;
1958 case TRUTH_NOT_EXPR
:
1960 case CLEANUP_POINT_EXPR
:
1964 TREE_TYPE (t
) = mapcar (TREE_TYPE (t
), func
);
1965 TREE_OPERAND (t
, 0) = mapcar (TREE_OPERAND (t
, 0), func
);
1969 tmp
= build_pointer_type (mapcar (TREE_TYPE (t
), func
));
1970 return cp_build_qualified_type (tmp
, TYPE_QUALS (t
));
1971 case REFERENCE_TYPE
:
1972 tmp
= build_reference_type (mapcar (TREE_TYPE (t
), func
));
1973 return cp_build_qualified_type (tmp
, TYPE_QUALS (t
));
1975 tmp
= build_function_type (mapcar (TREE_TYPE (t
), func
),
1976 mapcar (TYPE_ARG_TYPES (t
), func
));
1977 return cp_build_qualified_type (tmp
, TYPE_QUALS (t
));
1979 tmp
= build_cplus_array_type (mapcar (TREE_TYPE (t
), func
),
1980 mapcar (TYPE_DOMAIN (t
), func
));
1981 return cp_build_qualified_type (tmp
, CP_TYPE_QUALS (t
));
1983 tmp
= build_index_type (mapcar (TYPE_MAX_VALUE (t
), func
));
1984 return cp_build_qualified_type (tmp
, TYPE_QUALS (t
));
1986 tmp
= build_offset_type (mapcar (TYPE_OFFSET_BASETYPE (t
), func
),
1987 mapcar (TREE_TYPE (t
), func
));
1988 return cp_build_qualified_type (tmp
, TYPE_QUALS (t
));
1990 tmp
= build_cplus_method_type
1991 (mapcar (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (t
))), func
),
1992 mapcar (TREE_TYPE (t
), func
),
1993 mapcar (TREE_CHAIN (TYPE_ARG_TYPES (t
)), func
));
1994 return cp_build_qualified_type (tmp
, TYPE_QUALS (t
));
1998 TREE_REALPART (t
) = mapcar (TREE_REALPART (t
), func
);
1999 TREE_IMAGPART (t
) = mapcar (TREE_REALPART (t
), func
);
2004 CONSTRUCTOR_ELTS (t
) = mapcar (CONSTRUCTOR_ELTS (t
), func
);
2007 case TEMPLATE_TEMPLATE_PARM
:
2008 return copy_template_template_parm (t
);
2012 TREE_OPERAND (t
, 0) = mapcar (TREE_OPERAND (t
, 0), func
);
2013 TREE_OPERAND (t
, 1) = mapcar (TREE_OPERAND (t
, 1), func
);
2014 TREE_OPERAND (t
, 2) = NULL_TREE
;
2019 TREE_OPERAND (t
, 0) = mapcar (TREE_OPERAND (t
, 0), func
);
2020 TREE_OPERAND (t
, 1) = mapcar (TREE_OPERAND (t
, 1), func
);
2021 TREE_OPERAND (t
, 2) = mapcar (TREE_OPERAND (t
, 2), func
);
2028 TREE_OPERAND (t
, 0) = mapcar (TREE_OPERAND (t
, 0), func
);
2033 TREE_TYPE (t
) = mapcar (TREE_TYPE (t
), func
);
2037 if (TYPE_PTRMEMFUNC_P (t
))
2038 return build_ptrmemfunc_type
2039 (mapcar (TYPE_PTRMEMFUNC_FN_TYPE (t
), func
));
2040 /* else fall through */
2043 my_friendly_abort (19990815);
2045 my_friendly_abort (107);
2050 /* Returns T if T is allocated on the permanent obstack, NULL_TREE
2057 return TREE_PERMANENT (t
) ? t
: NULL_TREE
;
2064 if (TREE_PERMANENT (t
))
2067 /* Support `void f () { extern int i; A<&i> a; }' */
2068 if ((TREE_CODE (t
) == VAR_DECL
|| TREE_CODE (t
) == FUNCTION_DECL
)
2073 /* copy_rtx won't make a new SYMBOL_REF, so call make_decl_rtl again. */
2075 make_decl_rtl (t
, NULL_PTR
, 1);
2082 /* Assuming T is a node built bottom-up, make it all exist on
2083 permanent obstack, if it is not permanent already. */
2086 copy_to_permanent (t
)
2089 if (t
== NULL_TREE
|| TREE_PERMANENT (t
))
2092 push_permanent_obstack ();
2093 t
= mapcar (t
, perm_manip
);
2099 #ifdef GATHER_STATISTICS
2100 extern int depth_reached
;
2104 print_lang_statistics ()
2106 extern struct obstack decl_obstack
;
2107 print_obstack_statistics ("class_obstack", &class_obstack
);
2108 print_obstack_statistics ("decl_obstack", &decl_obstack
);
2109 print_search_statistics ();
2110 print_class_statistics ();
2111 #ifdef GATHER_STATISTICS
2112 fprintf (stderr
, "maximum template instantiation depth reached: %d\n",
2117 /* This is used by the `assert' macro. It is provided in libgcc.a,
2118 which `cc' doesn't know how to link. Note that the C++ front-end
2119 no longer actually uses the `assert' macro (instead, it calls
2120 my_friendly_assert). But all of the back-end files still need this. */
2123 __eprintf (string
, expression
, line
, filename
)
2125 const char *expression
;
2127 const char *filename
;
2129 fprintf (stderr
, string
, expression
, line
, filename
);
2134 /* Return, as an INTEGER_CST node, the number of elements for TYPE
2135 (which is an ARRAY_TYPE). This counts only elements of the top
2139 array_type_nelts_top (type
)
2142 return fold (build (PLUS_EXPR
, sizetype
,
2143 array_type_nelts (type
),
2147 /* Return, as an INTEGER_CST node, the number of elements for TYPE
2148 (which is an ARRAY_TYPE). This one is a recursive count of all
2149 ARRAY_TYPEs that are clumped together. */
2152 array_type_nelts_total (type
)
2155 tree sz
= array_type_nelts_top (type
);
2156 type
= TREE_TYPE (type
);
2157 while (TREE_CODE (type
) == ARRAY_TYPE
)
2159 tree n
= array_type_nelts_top (type
);
2160 sz
= fold (build (MULT_EXPR
, sizetype
, sz
, n
));
2161 type
= TREE_TYPE (type
);
2171 if (TREE_CODE (t
) != TREE_LIST
&& ! TREE_SIDE_EFFECTS (t
))
2173 else if (TREE_CODE (t
) == TARGET_EXPR
)
2175 if (TREE_CODE (TREE_OPERAND (t
, 1)) == AGGR_INIT_EXPR
)
2177 mark_used (TREE_OPERAND (TREE_OPERAND (TREE_OPERAND (t
, 1), 0), 0));
2178 return build_cplus_new
2179 (TREE_TYPE (t
), break_out_target_exprs (TREE_OPERAND (t
, 1)));
2182 TREE_OPERAND (t
, 0) = build (VAR_DECL
, TREE_TYPE (t
));
2183 layout_decl (TREE_OPERAND (t
, 0), 0);
2186 else if (TREE_CODE (t
) == CALL_EXPR
)
2187 mark_used (TREE_OPERAND (TREE_OPERAND (t
, 0), 0));
2192 /* Actually, we'll just clean out the target exprs for the moment. */
2195 break_out_target_exprs (t
)
2198 return mapcar (t
, bot_manip
);
2201 /* Obstack used for allocating nodes in template function and variable
2204 /* Similar to `build_nt', except we build
2205 on the permanent_obstack, regardless. */
2208 build_min_nt
VPROTO((enum tree_code code
, ...))
2210 #ifndef ANSI_PROTOTYPES
2211 enum tree_code code
;
2213 register struct obstack
*ambient_obstack
= expression_obstack
;
2216 register int length
;
2221 #ifndef ANSI_PROTOTYPES
2222 code
= va_arg (p
, enum tree_code
);
2225 expression_obstack
= &permanent_obstack
;
2227 t
= make_node (code
);
2228 length
= tree_code_length
[(int) code
];
2229 TREE_COMPLEXITY (t
) = lineno
;
2231 for (i
= 0; i
< length
; i
++)
2233 tree x
= va_arg (p
, tree
);
2234 TREE_OPERAND (t
, i
) = copy_to_permanent (x
);
2238 expression_obstack
= ambient_obstack
;
2242 /* Similar to `build', except we build
2243 on the permanent_obstack, regardless. */
2246 build_min
VPROTO((enum tree_code code
, tree tt
, ...))
2248 #ifndef ANSI_PROTOTYPES
2249 enum tree_code code
;
2252 register struct obstack
*ambient_obstack
= expression_obstack
;
2255 register int length
;
2260 #ifndef ANSI_PROTOTYPES
2261 code
= va_arg (p
, enum tree_code
);
2262 tt
= va_arg (p
, tree
);
2265 expression_obstack
= &permanent_obstack
;
2267 t
= make_node (code
);
2268 length
= tree_code_length
[(int) code
];
2269 TREE_TYPE (t
) = copy_to_permanent (tt
);
2270 TREE_COMPLEXITY (t
) = lineno
;
2272 for (i
= 0; i
< length
; i
++)
2274 tree x
= va_arg (p
, tree
);
2275 TREE_OPERAND (t
, i
) = copy_to_permanent (x
);
2279 expression_obstack
= ambient_obstack
;
2283 /* Same as `tree_cons' but make a permanent object. */
2286 min_tree_cons (purpose
, value
, chain
)
2287 tree purpose
, value
, chain
;
2290 register struct obstack
*ambient_obstack
= current_obstack
;
2291 current_obstack
= &permanent_obstack
;
2293 node
= tree_cons (copy_to_permanent (purpose
),
2294 copy_to_permanent (value
), chain
);
2295 current_obstack
= ambient_obstack
;
2303 if (TREE_CODE (t
) == TYPE_DECL
)
2305 if (TREE_CODE_CLASS (TREE_CODE (t
)) == 't')
2306 return TYPE_STUB_DECL (t
);
2308 my_friendly_abort (42);
2310 /* Stop compiler from complaining control reaches end of non-void function. */
2315 can_free (obstack
, t
)
2316 struct obstack
*obstack
;
2321 if (TREE_CODE (t
) == TREE_VEC
)
2322 size
= (TREE_VEC_LENGTH (t
)-1) * sizeof (tree
) + sizeof (struct tree_vec
);
2324 my_friendly_abort (42);
2326 #define ROUND(x) ((x + obstack_alignment_mask (obstack)) \
2327 & ~ obstack_alignment_mask (obstack))
2328 if ((char *)t
+ ROUND (size
) == obstack_next_free (obstack
))
2335 /* Return first vector element whose BINFO_TYPE is ELEM.
2336 Return 0 if ELEM is not in VEC. VEC may be NULL_TREE. */
2339 vec_binfo_member (elem
, vec
)
2345 for (i
= 0; i
< TREE_VEC_LENGTH (vec
); ++i
)
2346 if (same_type_p (elem
, BINFO_TYPE (TREE_VEC_ELT (vec
, i
))))
2347 return TREE_VEC_ELT (vec
, i
);
2352 /* Kludge around the fact that DECL_CONTEXT for virtual functions returns
2353 the wrong thing for decl_function_context. Hopefully the uses in the
2354 backend won't matter, since we don't need a static chain for local class
2358 hack_decl_function_context (decl
)
2361 if (TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_FUNCTION_MEMBER_P (decl
))
2362 return decl_function_context (TYPE_MAIN_DECL (DECL_CLASS_CONTEXT (decl
)));
2363 return decl_function_context (decl
);
2366 /* Returns the namespace that contains DECL, whether directly or
2370 decl_namespace_context (decl
)
2375 if (TREE_CODE (decl
) == NAMESPACE_DECL
)
2377 else if (TYPE_P (decl
))
2378 decl
= CP_DECL_CONTEXT (TYPE_MAIN_DECL (decl
));
2380 decl
= CP_DECL_CONTEXT (decl
);
2384 /* Return truthvalue of whether T1 is the same tree structure as T2.
2385 Return 1 if they are the same.
2386 Return 0 if they are understandably different.
2387 Return -1 if either contains tree structure not understood by
2391 cp_tree_equal (t1
, t2
)
2394 register enum tree_code code1
, code2
;
2399 if (t1
== 0 || t2
== 0)
2402 code1
= TREE_CODE (t1
);
2403 code2
= TREE_CODE (t2
);
2405 if (code1
== NOP_EXPR
|| code1
== CONVERT_EXPR
|| code1
== NON_LVALUE_EXPR
)
2407 if (code2
== NOP_EXPR
|| code2
== CONVERT_EXPR
|| code2
== NON_LVALUE_EXPR
)
2408 return cp_tree_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
2410 return cp_tree_equal (TREE_OPERAND (t1
, 0), t2
);
2412 else if (code2
== NOP_EXPR
|| code2
== CONVERT_EXPR
2413 || code2
== NON_LVALUE_EXPR
)
2414 return cp_tree_equal (t1
, TREE_OPERAND (t2
, 0));
2422 return TREE_INT_CST_LOW (t1
) == TREE_INT_CST_LOW (t2
)
2423 && TREE_INT_CST_HIGH (t1
) == TREE_INT_CST_HIGH (t2
);
2426 return REAL_VALUES_EQUAL (TREE_REAL_CST (t1
), TREE_REAL_CST (t2
));
2429 return TREE_STRING_LENGTH (t1
) == TREE_STRING_LENGTH (t2
)
2430 && !bcmp (TREE_STRING_POINTER (t1
), TREE_STRING_POINTER (t2
),
2431 TREE_STRING_LENGTH (t1
));
2434 /* We need to do this when determining whether or not two
2435 non-type pointer to member function template arguments
2437 if (!(same_type_p (TREE_TYPE (t1
), TREE_TYPE (t2
))
2438 /* The first operand is RTL. */
2439 && TREE_OPERAND (t1
, 0) == TREE_OPERAND (t2
, 0)))
2441 return cp_tree_equal (TREE_OPERAND (t1
, 1), TREE_OPERAND (t2
, 1));
2444 cmp
= cp_tree_equal (TREE_PURPOSE (t1
), TREE_PURPOSE (t2
));
2447 cmp
= cp_tree_equal (TREE_VALUE (t1
), TREE_VALUE (t2
));
2450 return cp_tree_equal (TREE_CHAIN (t1
), TREE_CHAIN (t2
));
2453 return cp_tree_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
2456 cmp
= cp_tree_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
2459 return simple_cst_list_equal (TREE_OPERAND (t1
, 1), TREE_OPERAND (t2
, 1));
2462 /* Special case: if either target is an unallocated VAR_DECL,
2463 it means that it's going to be unified with whatever the
2464 TARGET_EXPR is really supposed to initialize, so treat it
2465 as being equivalent to anything. */
2466 if ((TREE_CODE (TREE_OPERAND (t1
, 0)) == VAR_DECL
2467 && DECL_NAME (TREE_OPERAND (t1
, 0)) == NULL_TREE
2468 && DECL_RTL (TREE_OPERAND (t1
, 0)) == 0)
2469 || (TREE_CODE (TREE_OPERAND (t2
, 0)) == VAR_DECL
2470 && DECL_NAME (TREE_OPERAND (t2
, 0)) == NULL_TREE
2471 && DECL_RTL (TREE_OPERAND (t2
, 0)) == 0))
2474 cmp
= cp_tree_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
2477 return cp_tree_equal (TREE_OPERAND (t1
, 1), TREE_OPERAND (t2
, 1));
2479 case WITH_CLEANUP_EXPR
:
2480 cmp
= cp_tree_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
2483 return cp_tree_equal (TREE_OPERAND (t1
, 2), TREE_OPERAND (t1
, 2));
2486 if (TREE_OPERAND (t1
, 1) == TREE_OPERAND (t2
, 1))
2487 return cp_tree_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
2496 case TEMPLATE_PARM_INDEX
:
2497 return TEMPLATE_PARM_IDX (t1
) == TEMPLATE_PARM_IDX (t2
)
2498 && TEMPLATE_PARM_LEVEL (t1
) == TEMPLATE_PARM_LEVEL (t2
);
2502 if (TREE_CODE (TREE_OPERAND (t1
, 0)) != TREE_CODE (TREE_OPERAND (t2
, 0)))
2504 if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (t1
, 0))) == 't')
2505 return same_type_p (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
2509 /* Two pointer-to-members are the same if they point to the same
2510 field or function in the same class. */
2511 return (PTRMEM_CST_MEMBER (t1
) == PTRMEM_CST_MEMBER (t2
)
2512 && same_type_p (PTRMEM_CST_CLASS (t1
), PTRMEM_CST_CLASS (t2
)));
2518 switch (TREE_CODE_CLASS (code1
))
2528 for (i
=0; i
<tree_code_length
[(int) code1
]; ++i
)
2530 cmp
= cp_tree_equal (TREE_OPERAND (t1
, i
), TREE_OPERAND (t2
, i
));
2540 /* Similar to make_tree_vec, but build on the momentary_obstack.
2541 Thus, these vectors are really and truly temporary. */
2548 push_expression_obstack ();
2549 node
= make_tree_vec (len
);
2554 /* Build a wrapper around some pointer PTR so we can use it as a tree. */
2557 build_ptr_wrapper (ptr
)
2560 tree t
= make_node (WRAPPER
);
2561 WRAPPER_PTR (t
) = ptr
;
2565 /* Same, but on the expression_obstack. */
2568 build_expr_ptr_wrapper (ptr
)
2572 push_expression_obstack ();
2573 t
= build_ptr_wrapper (ptr
);
2578 /* Build a wrapper around some integer I so we can use it as a tree. */
2581 build_int_wrapper (i
)
2584 tree t
= make_node (WRAPPER
);
2585 WRAPPER_INT (t
) = i
;
2590 build_srcloc (file
, line
)
2596 /* Make sure that we put these on the permanent obstack; up in
2597 add_pending_template, we pass this return value into perm_tree_cons,
2598 which also puts it on the permanent_obstack. However, this wasn't
2599 explicitly doing the same. */
2600 register struct obstack
*ambient_obstack
= current_obstack
;
2601 current_obstack
= &permanent_obstack
;
2603 t
= make_node (SRCLOC
);
2604 SRCLOC_FILE (t
) = file
;
2605 SRCLOC_LINE (t
) = line
;
2607 current_obstack
= ambient_obstack
;
2613 build_srcloc_here ()
2615 return build_srcloc (input_filename
, lineno
);
2619 push_expression_obstack ()
2621 push_obstacks_nochange ();
2622 current_obstack
= expression_obstack
;
2625 /* Begin allocating on the permanent obstack. When you're done
2626 allocating there, call pop_obstacks to return to the previous set
2630 push_permanent_obstack ()
2632 push_obstacks_nochange ();
2633 end_temporary_allocation ();
2636 /* The type of ARG when used as an lvalue. */
2642 tree type
= TREE_TYPE (arg
);
2643 if (TREE_CODE (arg
) == OVERLOAD
)
2644 type
= unknown_type_node
;
2648 /* The type of ARG for printing error messages; denote lvalues with
2655 tree type
= TREE_TYPE (arg
);
2656 if (TREE_CODE (type
) == ARRAY_TYPE
)
2658 else if (real_lvalue_p (arg
))
2659 type
= build_reference_type (lvalue_type (arg
));
2660 else if (IS_AGGR_TYPE (type
))
2661 type
= lvalue_type (arg
);
2666 /* Does FUNCTION use a variable-length argument list? */
2669 varargs_function_p (function
)
2672 tree parm
= TYPE_ARG_TYPES (TREE_TYPE (function
));
2673 for (; parm
; parm
= TREE_CHAIN (parm
))
2674 if (TREE_VALUE (parm
) == void_type_node
)
2679 /* Returns 1 if decl is a member of a class. */
2685 tree ctx
= DECL_CONTEXT (decl
);
2686 return (ctx
&& TREE_CODE_CLASS (TREE_CODE (ctx
)) == 't');
2689 /* Create a placeholder for member access where we don't actually have an
2690 object that the access is against. */
2693 build_dummy_object (type
)
2696 tree decl
= build1 (NOP_EXPR
, build_pointer_type (type
), void_zero_node
);
2697 return build_indirect_ref (decl
, NULL_PTR
);
2700 /* We've gotten a reference to a member of TYPE. Return *this if appropriate,
2701 or a dummy object otherwise. If BINFOP is non-0, it is filled with the
2702 binfo path from current_class_type to TYPE, or 0. */
2705 maybe_dummy_object (type
, binfop
)
2711 if (current_class_type
2712 && get_base_distance (type
, current_class_type
, 0, binfop
) != -1)
2713 context
= current_class_type
;
2716 /* Reference from a nested class member function. */
2719 *binfop
= TYPE_BINFO (type
);
2722 if (current_class_ref
&& context
== current_class_type
)
2723 decl
= current_class_ref
;
2725 decl
= build_dummy_object (context
);
2730 /* Returns 1 if OB is a placeholder object, or a pointer to one. */
2733 is_dummy_object (ob
)
2736 if (TREE_CODE (ob
) == INDIRECT_REF
)
2737 ob
= TREE_OPERAND (ob
, 0);
2738 return (TREE_CODE (ob
) == NOP_EXPR
2739 && TREE_OPERAND (ob
, 0) == void_zero_node
);
2742 /* Returns 1 iff type T is a POD type, as defined in [basic.types]. */
2748 while (TREE_CODE (t
) == ARRAY_TYPE
)
2751 if (INTEGRAL_TYPE_P (t
))
2752 return 1; /* integral, character or enumeral type */
2753 if (FLOAT_TYPE_P (t
))
2756 return 1; /* pointer to non-member */
2757 if (TYPE_PTRMEM_P (t
))
2758 return 1; /* pointer to member object */
2759 if (TYPE_PTRMEMFUNC_P (t
))
2760 return 1; /* pointer to member function */
2762 if (! CLASS_TYPE_P (t
))
2763 return 0; /* other non-class type (reference or function) */
2764 if (CLASSTYPE_NON_POD_P (t
))
2769 /* Return a 1 if ATTR_NAME and ATTR_ARGS denote a valid C++-specific
2770 attribute for either declaration DECL or type TYPE and 0 otherwise.
2771 Plugged into valid_lang_attribute. */
2774 cp_valid_lang_attribute (attr_name
, attr_args
, decl
, type
)
2776 tree attr_args ATTRIBUTE_UNUSED
;
2777 tree decl ATTRIBUTE_UNUSED
;
2778 tree type ATTRIBUTE_UNUSED
;
2780 if (is_attribute_p ("com_interface", attr_name
))
2782 if (! flag_vtable_thunks
)
2784 error ("`com_interface' only supported with -fvtable-thunks");
2788 if (attr_args
!= NULL_TREE
2789 || decl
!= NULL_TREE
2790 || ! CLASS_TYPE_P (type
)
2791 || type
!= TYPE_MAIN_VARIANT (type
))
2793 warning ("`com_interface' attribute can only be applied to class definitions");
2797 CLASSTYPE_COM_INTERFACE (type
) = 1;
2800 else if (is_attribute_p ("init_priority", attr_name
))
2802 tree initp_expr
= (attr_args
? TREE_VALUE (attr_args
): NULL_TREE
);
2806 STRIP_NOPS (initp_expr
);
2808 if (!initp_expr
|| TREE_CODE (initp_expr
) != INTEGER_CST
)
2810 error ("requested init_priority is not an integer constant");
2814 pri
= TREE_INT_CST_LOW (initp_expr
);
2816 while (TREE_CODE (type
) == ARRAY_TYPE
)
2817 type
= TREE_TYPE (type
);
2819 if (decl
== NULL_TREE
2820 || TREE_CODE (decl
) != VAR_DECL
2821 || ! TREE_STATIC (decl
)
2822 || DECL_EXTERNAL (decl
)
2823 || (TREE_CODE (type
) != RECORD_TYPE
2824 && TREE_CODE (type
) != UNION_TYPE
)
2825 /* Static objects in functions are initialized the
2826 first time control passes through that
2827 function. This is not precise enough to pin down an
2828 init_priority value, so don't allow it. */
2829 || current_function_decl
)
2831 error ("can only use init_priority attribute on file-scope definitions of objects of class type");
2835 if (pri
> MAX_INIT_PRIORITY
|| pri
<= 0)
2837 error ("requested init_priority is out of range");
2841 /* Check for init_priorities that are reserved for
2842 language and runtime support implementations.*/
2843 if (pri
<= MAX_RESERVED_INIT_PRIORITY
)
2846 ("requested init_priority is reserved for internal use");
2849 DECL_INIT_PRIORITY (decl
) = pri
;
2856 /* Return a new PTRMEM_CST of the indicated TYPE. The MEMBER is the
2857 thing pointed to by the constant. */
2860 make_ptrmem_cst (type
, member
)
2864 tree ptrmem_cst
= make_node (PTRMEM_CST
);
2865 /* If would seem a great convenience if make_node would set
2866 TREE_CONSTANT for things of class `c', but it does not. */
2867 TREE_CONSTANT (ptrmem_cst
) = 1;
2868 TREE_TYPE (ptrmem_cst
) = type
;
2869 PTRMEM_CST_MEMBER (ptrmem_cst
) = member
;
2873 /* Initialize unsave for C++. */
2875 init_cplus_unsave ()
2877 lang_unsave_expr_now
= cplus_unsave_expr_now
;
2880 /* The C++ version of unsave_expr_now.
2881 See gcc/tree.c:unsave_expr_now for comments. */
2884 cplus_unsave_expr_now (expr
)
2890 else if (TREE_CODE (expr
) == AGGR_INIT_EXPR
)
2892 unsave_expr_now (TREE_OPERAND (expr
,0));
2893 if (TREE_OPERAND (expr
, 1)
2894 && TREE_CODE (TREE_OPERAND (expr
, 1)) == TREE_LIST
)
2896 tree exp
= TREE_OPERAND (expr
, 1);
2899 unsave_expr_now (TREE_VALUE (exp
));
2900 exp
= TREE_CHAIN (exp
);
2903 unsave_expr_now (TREE_OPERAND (expr
,2));