1 /* Language-dependent node constructors for parse phase of GNU compiler.
2 Copyright (C) 1987, 88, 92, 93, 94, 95, 1996 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. */
35 #define CEIL(x,y) (((x) + (y) - 1) / (y))
37 /* Return nonzero if REF is an lvalue valid for this language.
38 Lvalues can be assigned, unless they have TREE_READONLY.
39 Lvalues can have their address taken, unless they have DECL_REGISTER. */
45 if (! language_lvalue_valid (ref
))
48 if (TREE_CODE (TREE_TYPE (ref
)) == REFERENCE_TYPE
)
51 if (ref
== current_class_ptr
&& flag_this_is_variable
<= 0)
54 switch (TREE_CODE (ref
))
56 /* preincrements and predecrements are valid lvals, provided
57 what they refer to are valid lvals. */
58 case PREINCREMENT_EXPR
:
59 case PREDECREMENT_EXPR
:
62 return real_lvalue_p (TREE_OPERAND (ref
, 0));
68 if (TREE_READONLY (ref
) && ! TREE_STATIC (ref
)
69 && DECL_LANG_SPECIFIC (ref
)
70 && DECL_IN_AGGR_P (ref
))
77 if (TREE_CODE (TREE_TYPE (ref
)) != FUNCTION_TYPE
78 && TREE_CODE (TREE_TYPE (ref
)) != METHOD_TYPE
)
82 /* A currently unresolved scope ref. */
84 my_friendly_abort (103);
86 if (TREE_CODE (TREE_OPERAND (ref
, 1)) == FUNCTION_DECL
)
88 return real_lvalue_p (TREE_OPERAND (ref
, 0))
89 && real_lvalue_p (TREE_OPERAND (ref
, 1));
93 return (real_lvalue_p (TREE_OPERAND (ref
, 1))
94 && real_lvalue_p (TREE_OPERAND (ref
, 2)));
100 return real_lvalue_p (TREE_OPERAND (ref
, 1));
104 return (real_lvalue_p (TREE_OPERAND (ref
, 0))
105 && real_lvalue_p (TREE_OPERAND (ref
, 1)));
111 /* This differs from real_lvalue_p in that class rvalues are considered
117 if (! language_lvalue_valid (ref
))
120 if (TREE_CODE (TREE_TYPE (ref
)) == REFERENCE_TYPE
)
123 if (ref
== current_class_ptr
&& flag_this_is_variable
<= 0)
126 switch (TREE_CODE (ref
))
128 /* preincrements and predecrements are valid lvals, provided
129 what they refer to are valid lvals. */
130 case PREINCREMENT_EXPR
:
131 case PREDECREMENT_EXPR
:
136 return lvalue_p (TREE_OPERAND (ref
, 0));
142 if (TREE_READONLY (ref
) && ! TREE_STATIC (ref
)
143 && DECL_LANG_SPECIFIC (ref
)
144 && DECL_IN_AGGR_P (ref
))
151 if (TREE_CODE (TREE_TYPE (ref
)) != FUNCTION_TYPE
152 && TREE_CODE (TREE_TYPE (ref
)) != METHOD_TYPE
)
160 if (IS_AGGR_TYPE (TREE_TYPE (ref
)))
164 /* A currently unresolved scope ref. */
166 my_friendly_abort (103);
168 if (TREE_CODE (TREE_OPERAND (ref
, 1)) == FUNCTION_DECL
)
170 return lvalue_p (TREE_OPERAND (ref
, 0))
171 && lvalue_p (TREE_OPERAND (ref
, 1));
175 return (lvalue_p (TREE_OPERAND (ref
, 1))
176 && lvalue_p (TREE_OPERAND (ref
, 2)));
182 return lvalue_p (TREE_OPERAND (ref
, 1));
186 return (lvalue_p (TREE_OPERAND (ref
, 0))
187 && lvalue_p (TREE_OPERAND (ref
, 1)));
193 /* Return nonzero if REF is an lvalue valid for this language;
194 otherwise, print an error message and return zero. */
197 lvalue_or_else (ref
, string
)
201 int win
= lvalue_p (ref
);
203 error ("non-lvalue in %s", string
);
207 /* INIT is a CALL_EXPR which needs info about its target.
208 TYPE is the type that this initialization should appear to have.
210 Build an encapsulation of the initialization to perform
211 and return it so that it can be processed by language-independent
212 and language-specific expression expanders. */
215 build_cplus_new (type
, init
)
222 if (TREE_CODE (init
) == TARGET_EXPR
|| init
== error_mark_node
)
225 slot
= build (VAR_DECL
, type
);
226 layout_decl (slot
, 0);
227 rval
= build (NEW_EXPR
, type
,
228 TREE_OPERAND (init
, 0), TREE_OPERAND (init
, 1), slot
);
229 TREE_SIDE_EFFECTS (rval
) = 1;
230 TREE_ADDRESSABLE (rval
) = 1;
231 rval
= build (TARGET_EXPR
, type
, slot
, rval
, NULL_TREE
, NULL_TREE
);
232 TREE_SIDE_EFFECTS (rval
) = 1;
233 TREE_ADDRESSABLE (rval
) = 1;
238 /* Recursively search EXP for CALL_EXPRs that need cleanups and replace
239 these CALL_EXPRs with tree nodes that will perform the cleanups. */
242 break_out_cleanups (exp
)
247 if (TREE_CODE (tmp
) == CALL_EXPR
248 && TYPE_NEEDS_DESTRUCTOR (TREE_TYPE (tmp
)))
249 return build_cplus_new (TREE_TYPE (tmp
), tmp
);
251 while (TREE_CODE (tmp
) == NOP_EXPR
252 || TREE_CODE (tmp
) == CONVERT_EXPR
253 || TREE_CODE (tmp
) == NON_LVALUE_EXPR
)
255 if (TREE_CODE (TREE_OPERAND (tmp
, 0)) == CALL_EXPR
256 && TYPE_NEEDS_DESTRUCTOR (TREE_TYPE (TREE_OPERAND (tmp
, 0))))
258 TREE_OPERAND (tmp
, 0)
259 = build_cplus_new (TREE_TYPE (TREE_OPERAND (tmp
, 0)),
260 TREE_OPERAND (tmp
, 0));
264 tmp
= TREE_OPERAND (tmp
, 0);
269 /* Recursively perform a preorder search EXP for CALL_EXPRs, making
270 copies where they are found. Returns a deep copy all nodes transitively
271 containing CALL_EXPRs. */
274 break_out_calls (exp
)
277 register tree t1
, t2
;
278 register enum tree_code code
;
279 register int changed
= 0;
282 if (exp
== NULL_TREE
)
285 code
= TREE_CODE (exp
);
287 if (code
== CALL_EXPR
)
288 return copy_node (exp
);
290 /* Don't try and defeat a save_expr, as it should only be done once. */
291 if (code
== SAVE_EXPR
)
294 switch (TREE_CODE_CLASS (code
))
299 case 'c': /* a constant */
300 case 't': /* a type node */
301 case 'x': /* something random, like an identifier or an ERROR_MARK. */
304 case 'd': /* A decl node */
305 #if 0 /* This is bogus. jason 9/21/94 */
307 t1
= break_out_calls (DECL_INITIAL (exp
));
308 if (t1
!= DECL_INITIAL (exp
))
310 exp
= copy_node (exp
);
311 DECL_INITIAL (exp
) = t1
;
316 case 'b': /* A block node */
318 /* Don't know how to handle these correctly yet. Must do a
319 break_out_calls on all DECL_INITIAL values for local variables,
320 and also break_out_calls on all sub-blocks and sub-statements. */
325 case 'e': /* an expression */
326 case 'r': /* a reference */
327 case 's': /* an expression with side effects */
328 for (i
= tree_code_length
[(int) code
] - 1; i
>= 0; i
--)
330 t1
= break_out_calls (TREE_OPERAND (exp
, i
));
331 if (t1
!= TREE_OPERAND (exp
, i
))
333 exp
= copy_node (exp
);
334 TREE_OPERAND (exp
, i
) = t1
;
339 case '<': /* a comparison expression */
340 case '2': /* a binary arithmetic expression */
341 t2
= break_out_calls (TREE_OPERAND (exp
, 1));
342 if (t2
!= TREE_OPERAND (exp
, 1))
344 case '1': /* a unary arithmetic expression */
345 t1
= break_out_calls (TREE_OPERAND (exp
, 0));
346 if (t1
!= TREE_OPERAND (exp
, 0))
350 if (tree_code_length
[(int) code
] == 1)
351 return build1 (code
, TREE_TYPE (exp
), t1
);
353 return build (code
, TREE_TYPE (exp
), t1
, t2
);
360 extern struct obstack
*current_obstack
;
361 extern struct obstack permanent_obstack
, class_obstack
;
362 extern struct obstack
*saveable_obstack
;
363 extern struct obstack
*expression_obstack
;
365 /* Here is how primitive or already-canonicalized types' hash
366 codes are made. MUST BE CONSISTENT WITH tree.c !!! */
367 #define TYPE_HASH(TYPE) ((HOST_WIDE_INT) (TYPE) & 0777777)
369 /* Construct, lay out and return the type of methods belonging to class
370 BASETYPE and whose arguments are described by ARGTYPES and whose values
371 are described by RETTYPE. If each type exists already, reuse it. */
374 build_cplus_method_type (basetype
, rettype
, argtypes
)
375 tree basetype
, rettype
, argtypes
;
381 /* Make a node of the sort we want. */
382 t
= make_node (METHOD_TYPE
);
384 TYPE_METHOD_BASETYPE (t
) = TYPE_MAIN_VARIANT (basetype
);
385 TREE_TYPE (t
) = rettype
;
386 if (IS_SIGNATURE (basetype
))
387 ptype
= build_signature_pointer_type (TYPE_MAIN_VARIANT (basetype
),
388 TYPE_READONLY (basetype
),
389 TYPE_VOLATILE (basetype
));
391 ptype
= build_pointer_type (basetype
);
393 /* The actual arglist for this function includes a "hidden" argument
394 which is "this". Put it into the list of argument types. */
396 argtypes
= tree_cons (NULL_TREE
, ptype
, argtypes
);
397 TYPE_ARG_TYPES (t
) = argtypes
;
398 TREE_SIDE_EFFECTS (argtypes
) = 1; /* Mark first argtype as "artificial". */
400 /* If we already have such a type, use the old one and free this one.
401 Note that it also frees up the above cons cell if found. */
402 hashcode
= TYPE_HASH (basetype
) + TYPE_HASH (rettype
) + type_hash_list (argtypes
);
403 t
= type_hash_canon (hashcode
, t
);
405 if (TYPE_SIZE (t
) == 0)
412 build_cplus_array_type_1 (elt_type
, index_type
)
416 register struct obstack
*ambient_obstack
= current_obstack
;
417 register struct obstack
*ambient_saveable_obstack
= saveable_obstack
;
420 /* We need a new one. If both ELT_TYPE and INDEX_TYPE are permanent,
421 make this permanent too. */
422 if (TREE_PERMANENT (elt_type
)
423 && (index_type
== 0 || TREE_PERMANENT (index_type
)))
425 current_obstack
= &permanent_obstack
;
426 saveable_obstack
= &permanent_obstack
;
429 if (processing_template_decl
)
431 t
= make_node (ARRAY_TYPE
);
432 TREE_TYPE (t
) = elt_type
;
433 TYPE_DOMAIN (t
) = index_type
;
436 t
= build_array_type (elt_type
, index_type
);
438 /* Push these needs up so that initialization takes place
440 TYPE_NEEDS_CONSTRUCTING (t
) = TYPE_NEEDS_CONSTRUCTING (TYPE_MAIN_VARIANT (elt_type
));
441 TYPE_NEEDS_DESTRUCTOR (t
) = TYPE_NEEDS_DESTRUCTOR (TYPE_MAIN_VARIANT (elt_type
));
442 current_obstack
= ambient_obstack
;
443 saveable_obstack
= ambient_saveable_obstack
;
448 build_cplus_array_type (elt_type
, index_type
)
453 int constp
= TYPE_READONLY (elt_type
);
454 int volatilep
= TYPE_VOLATILE (elt_type
);
455 elt_type
= TYPE_MAIN_VARIANT (elt_type
);
457 t
= build_cplus_array_type_1 (elt_type
, index_type
);
459 if (constp
|| volatilep
)
460 t
= cp_build_type_variant (t
, constp
, volatilep
);
465 /* Make a variant type in the proper way for C/C++, propagating qualifiers
466 down to the element type of an array. */
469 cp_build_type_variant (type
, constp
, volatilep
)
471 int constp
, volatilep
;
473 if (type
== error_mark_node
)
476 if (TREE_CODE (type
) == ARRAY_TYPE
)
478 tree real_main_variant
= TYPE_MAIN_VARIANT (type
);
480 push_obstacks (TYPE_OBSTACK (real_main_variant
),
481 TYPE_OBSTACK (real_main_variant
));
482 type
= build_cplus_array_type_1 (cp_build_type_variant
483 (TREE_TYPE (type
), constp
, volatilep
),
486 /* TYPE must be on same obstack as REAL_MAIN_VARIANT. If not,
487 make a copy. (TYPE might have come from the hash table and
488 REAL_MAIN_VARIANT might be in some function's obstack.) */
490 if (TYPE_OBSTACK (type
) != TYPE_OBSTACK (real_main_variant
))
492 type
= copy_node (type
);
493 TYPE_POINTER_TO (type
) = TYPE_REFERENCE_TO (type
) = 0;
496 TYPE_MAIN_VARIANT (type
) = real_main_variant
;
500 return build_type_variant (type
, constp
, volatilep
);
503 /* Add OFFSET to all base types of T.
505 OFFSET, which is a type offset, is number of bytes.
507 Note that we don't have to worry about having two paths to the
508 same base type, since this type owns its association list. */
511 propagate_binfo_offsets (binfo
, offset
)
515 tree binfos
= BINFO_BASETYPES (binfo
);
516 int i
, n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
518 for (i
= 0; i
< n_baselinks
; /* note increment is done in the loop. */)
520 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
522 if (TREE_VIA_VIRTUAL (base_binfo
))
527 tree base_binfos
= BINFO_BASETYPES (base_binfo
);
530 for (j
= i
+1; j
< n_baselinks
; j
++)
531 if (! TREE_VIA_VIRTUAL (TREE_VEC_ELT (binfos
, j
)))
533 /* The next basetype offset must take into account the space
534 between the classes, not just the size of each class. */
535 delta
= size_binop (MINUS_EXPR
,
536 BINFO_OFFSET (TREE_VEC_ELT (binfos
, j
)),
537 BINFO_OFFSET (base_binfo
));
542 if (BINFO_OFFSET_ZEROP (base_binfo
))
543 BINFO_OFFSET (base_binfo
) = offset
;
545 BINFO_OFFSET (base_binfo
)
546 = size_binop (PLUS_EXPR
, BINFO_OFFSET (base_binfo
), offset
);
548 BINFO_OFFSET (base_binfo
) = offset
;
553 tree chain
= NULL_TREE
;
555 /* Now unshare the structure beneath BASE_BINFO. */
556 for (k
= TREE_VEC_LENGTH (base_binfos
)-1;
559 tree base_base_binfo
= TREE_VEC_ELT (base_binfos
, k
);
560 if (! TREE_VIA_VIRTUAL (base_base_binfo
))
561 TREE_VEC_ELT (base_binfos
, k
)
562 = make_binfo (BINFO_OFFSET (base_base_binfo
),
564 BINFO_VTABLE (base_base_binfo
),
565 BINFO_VIRTUALS (base_base_binfo
),
567 chain
= TREE_VEC_ELT (base_binfos
, k
);
568 TREE_VIA_PUBLIC (chain
) = TREE_VIA_PUBLIC (base_base_binfo
);
569 TREE_VIA_PROTECTED (chain
) = TREE_VIA_PROTECTED (base_base_binfo
);
570 BINFO_INHERITANCE_CHAIN (chain
) = base_binfo
;
572 /* Now propagate the offset to the base types. */
573 propagate_binfo_offsets (base_binfo
, offset
);
576 /* Go to our next class that counts for offset propagation. */
579 offset
= size_binop (PLUS_EXPR
, offset
, delta
);
584 /* Compute the actual offsets that our virtual base classes
585 will have *for this type*. This must be performed after
586 the fields are laid out, since virtual baseclasses must
587 lay down at the end of the record.
589 Returns the maximum number of virtual functions any of the virtual
590 baseclasses provide. */
593 layout_vbasetypes (rec
, max
)
597 /* Get all the virtual base types that this type uses.
598 The TREE_VALUE slot holds the virtual baseclass type. */
599 tree vbase_types
= get_vbase_types (rec
);
601 #ifdef STRUCTURE_SIZE_BOUNDARY
602 unsigned record_align
= MAX (STRUCTURE_SIZE_BOUNDARY
, TYPE_ALIGN (rec
));
604 unsigned record_align
= MAX (BITS_PER_UNIT
, TYPE_ALIGN (rec
));
608 /* Record size so far is CONST_SIZE + VAR_SIZE bits,
609 where CONST_SIZE is an integer
610 and VAR_SIZE is a tree expression.
611 If VAR_SIZE is null, the size is just CONST_SIZE.
612 Naturally we try to avoid using VAR_SIZE. */
613 register unsigned const_size
= 0;
614 register tree var_size
= 0;
615 int nonvirtual_const_size
;
617 CLASSTYPE_VBASECLASSES (rec
) = vbase_types
;
619 if (TREE_CODE (TYPE_SIZE (rec
)) == INTEGER_CST
)
620 const_size
= TREE_INT_CST_LOW (TYPE_SIZE (rec
));
622 var_size
= TYPE_SIZE (rec
);
624 nonvirtual_const_size
= const_size
;
628 tree basetype
= BINFO_TYPE (vbase_types
);
631 desired_align
= TYPE_ALIGN (basetype
);
632 record_align
= MAX (record_align
, desired_align
);
635 offset
= integer_zero_node
;
638 /* Give each virtual base type the alignment it wants. */
639 const_size
= CEIL (const_size
, TYPE_ALIGN (basetype
))
640 * TYPE_ALIGN (basetype
);
641 offset
= size_int (CEIL (const_size
, BITS_PER_UNIT
));
644 if (CLASSTYPE_VSIZE (basetype
) > max
)
645 max
= CLASSTYPE_VSIZE (basetype
);
646 BINFO_OFFSET (vbase_types
) = offset
;
648 if (TREE_CODE (TYPE_SIZE (basetype
)) == INTEGER_CST
)
650 /* Every virtual baseclass takes a least a UNIT, so that we can
651 take it's address and get something different for each base. */
652 const_size
+= MAX (BITS_PER_UNIT
,
653 TREE_INT_CST_LOW (TYPE_SIZE (basetype
))
654 - TREE_INT_CST_LOW (CLASSTYPE_VBASE_SIZE (basetype
)));
656 else if (var_size
== 0)
657 var_size
= TYPE_SIZE (basetype
);
659 var_size
= size_binop (PLUS_EXPR
, var_size
, TYPE_SIZE (basetype
));
661 vbase_types
= TREE_CHAIN (vbase_types
);
666 /* Because a virtual base might take a single byte above,
667 we have to re-adjust the total size to make sure it it
668 a multiple of the alignment. */
669 /* Give the whole object the alignment it wants. */
670 const_size
= CEIL (const_size
, record_align
) * record_align
;
673 /* Set the alignment in the complete type. We don't set CLASSTYPE_ALIGN
674 here, as that is for this class, without any virtual base classes. */
675 TYPE_ALIGN (rec
) = record_align
;
676 if (const_size
!= nonvirtual_const_size
)
678 CLASSTYPE_VBASE_SIZE (rec
)
679 = size_int (const_size
- nonvirtual_const_size
);
680 TYPE_SIZE (rec
) = size_int (const_size
);
683 /* Now propagate offset information throughout the lattice
684 under the vbase type. */
685 for (vbase_types
= CLASSTYPE_VBASECLASSES (rec
); vbase_types
;
686 vbase_types
= TREE_CHAIN (vbase_types
))
688 tree base_binfos
= BINFO_BASETYPES (vbase_types
);
690 BINFO_INHERITANCE_CHAIN (vbase_types
) = TYPE_BINFO (rec
);
694 tree chain
= NULL_TREE
;
696 /* Now unshare the structure beneath BASE_BINFO. */
698 for (j
= TREE_VEC_LENGTH (base_binfos
)-1;
701 tree base_base_binfo
= TREE_VEC_ELT (base_binfos
, j
);
702 if (! TREE_VIA_VIRTUAL (base_base_binfo
))
703 TREE_VEC_ELT (base_binfos
, j
)
704 = make_binfo (BINFO_OFFSET (base_base_binfo
),
706 BINFO_VTABLE (base_base_binfo
),
707 BINFO_VIRTUALS (base_base_binfo
),
709 chain
= TREE_VEC_ELT (base_binfos
, j
);
710 TREE_VIA_PUBLIC (chain
) = TREE_VIA_PUBLIC (base_base_binfo
);
711 TREE_VIA_PROTECTED (chain
) = TREE_VIA_PROTECTED (base_base_binfo
);
712 BINFO_INHERITANCE_CHAIN (chain
) = vbase_types
;
715 propagate_binfo_offsets (vbase_types
, BINFO_OFFSET (vbase_types
));
722 /* Lay out the base types of a record type, REC.
723 Tentatively set the size and alignment of REC
724 according to the base types alone.
726 Offsets for immediate nonvirtual baseclasses are also computed here.
728 TYPE_BINFO (REC) should be NULL_TREE on entry, and this routine
729 creates a list of base_binfos in TYPE_BINFO (REC) from BINFOS.
731 Returns list of virtual base classes in a FIELD_DECL chain. */
734 layout_basetypes (rec
, binfos
)
737 /* Chain to hold all the new FIELD_DECLs which point at virtual
739 tree vbase_decls
= NULL_TREE
;
741 #ifdef STRUCTURE_SIZE_BOUNDARY
742 unsigned record_align
= MAX (STRUCTURE_SIZE_BOUNDARY
, TYPE_ALIGN (rec
));
744 unsigned record_align
= MAX (BITS_PER_UNIT
, TYPE_ALIGN (rec
));
747 /* Record size so far is CONST_SIZE + VAR_SIZE bits, where CONST_SIZE is
748 an integer and VAR_SIZE is a tree expression. If VAR_SIZE is null,
749 the size is just CONST_SIZE. Naturally we try to avoid using
750 VAR_SIZE. And so far, we've been successful. */
752 register tree var_size
= 0;
755 register unsigned const_size
= 0;
756 int i
, n_baseclasses
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
758 /* Handle basetypes almost like fields, but record their
759 offsets differently. */
761 for (i
= 0; i
< n_baseclasses
; i
++)
763 int inc
, desired_align
, int_vbase_size
;
764 register tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
765 register tree basetype
= BINFO_TYPE (base_binfo
);
768 if (TYPE_SIZE (basetype
) == 0)
771 /* This error is now reported in xref_tag, thus giving better
772 location information. */
773 error_with_aggr_type (base_binfo
,
774 "base class `%s' has incomplete type");
776 TREE_VIA_PUBLIC (base_binfo
) = 1;
777 TREE_VIA_PROTECTED (base_binfo
) = 0;
778 TREE_VIA_VIRTUAL (base_binfo
) = 0;
780 /* Should handle this better so that
783 class B: private A { virtual void F(); };
785 does not dump core when compiled. */
786 my_friendly_abort (121);
791 /* All basetypes are recorded in the association list of the
794 if (TREE_VIA_VIRTUAL (base_binfo
))
797 char *name
= (char *)alloca (TYPE_NAME_LENGTH (basetype
)
798 + sizeof (VBASE_NAME
) + 1);
800 /* The offset for a virtual base class is only used in computing
801 virtual function tables and for initializing virtual base
802 pointers. It is built once `get_vbase_types' is called. */
804 /* If this basetype can come from another vbase pointer
805 without an additional indirection, we will share
806 that pointer. If an indirection is involved, we
807 make our own pointer. */
808 for (j
= 0; j
< n_baseclasses
; j
++)
810 tree other_base_binfo
= TREE_VEC_ELT (binfos
, j
);
811 if (! TREE_VIA_VIRTUAL (other_base_binfo
)
812 && binfo_member (basetype
,
813 CLASSTYPE_VBASECLASSES (BINFO_TYPE (other_base_binfo
))))
816 sprintf (name
, VBASE_NAME_FORMAT
, TYPE_NAME_STRING (basetype
));
817 decl
= build_lang_field_decl (FIELD_DECL
, get_identifier (name
),
818 build_pointer_type (basetype
));
819 /* If you change any of the below, take a look at all the
820 other VFIELD_BASEs and VTABLE_BASEs in the code, and change
822 DECL_ASSEMBLER_NAME (decl
) = get_identifier (VTABLE_BASE
);
823 DECL_VIRTUAL_P (decl
) = 1;
824 DECL_ARTIFICIAL (decl
) = 1;
825 DECL_FIELD_CONTEXT (decl
) = rec
;
826 DECL_CLASS_CONTEXT (decl
) = rec
;
827 DECL_FCONTEXT (decl
) = basetype
;
828 DECL_SAVED_INSNS (decl
) = NULL_RTX
;
829 DECL_FIELD_SIZE (decl
) = 0;
830 DECL_ALIGN (decl
) = TYPE_ALIGN (ptr_type_node
);
831 TREE_CHAIN (decl
) = vbase_decls
;
832 BINFO_VPTR_FIELD (base_binfo
) = decl
;
835 if (warn_nonvdtor
&& TYPE_HAS_DESTRUCTOR (basetype
)
836 && DECL_VINDEX (TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (basetype
), 1)) == NULL_TREE
)
838 warning_with_decl (TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (basetype
), 1),
839 "destructor `%s' non-virtual");
840 warning ("in inheritance relationship `%s: virtual %s'",
841 TYPE_NAME_STRING (rec
),
842 TYPE_NAME_STRING (basetype
));
845 /* The space this decl occupies has already been accounted for. */
850 offset
= integer_zero_node
;
853 /* Give each base type the alignment it wants. */
854 const_size
= CEIL (const_size
, TYPE_ALIGN (basetype
))
855 * TYPE_ALIGN (basetype
);
856 offset
= size_int ((const_size
+ BITS_PER_UNIT
- 1) / BITS_PER_UNIT
);
859 /* bpk: Disabled this check until someone is willing to
860 claim it as theirs and explain exactly what circumstances
861 warrant the warning. */
862 if (warn_nonvdtor
&& TYPE_HAS_DESTRUCTOR (basetype
)
863 && DECL_VINDEX (TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (basetype
), 1)) == NULL_TREE
)
865 warning_with_decl (TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (basetype
), 1),
866 "destructor `%s' non-virtual");
867 warning ("in inheritance relationship `%s:%s %s'",
868 TYPE_NAME_STRING (rec
),
869 TREE_VIA_VIRTUAL (base_binfo
) ? " virtual" : "",
870 TYPE_NAME_STRING (basetype
));
874 BINFO_OFFSET (base_binfo
) = offset
;
875 if (CLASSTYPE_VSIZE (basetype
))
877 BINFO_VTABLE (base_binfo
) = TYPE_BINFO_VTABLE (basetype
);
878 BINFO_VIRTUALS (base_binfo
) = TYPE_BINFO_VIRTUALS (basetype
);
880 TREE_CHAIN (base_binfo
) = TYPE_BINFO (rec
);
881 TYPE_BINFO (rec
) = base_binfo
;
883 /* Add only the amount of storage not present in
884 the virtual baseclasses. */
886 int_vbase_size
= TREE_INT_CST_LOW (CLASSTYPE_VBASE_SIZE (basetype
));
887 if (TREE_INT_CST_LOW (TYPE_SIZE (basetype
)) > int_vbase_size
)
889 inc
= MAX (record_align
,
890 (TREE_INT_CST_LOW (TYPE_SIZE (basetype
))
893 /* Record must have at least as much alignment as any field. */
894 desired_align
= TYPE_ALIGN (basetype
);
895 record_align
= MAX (record_align
, desired_align
);
902 CLASSTYPE_SIZE (rec
) = size_int (const_size
);
904 CLASSTYPE_SIZE (rec
) = integer_zero_node
;
905 CLASSTYPE_ALIGN (rec
) = record_align
;
910 /* Hashing of lists so that we don't make duplicates.
911 The entry point is `list_hash_canon'. */
913 /* Each hash table slot is a bucket containing a chain
914 of these structures. */
918 struct list_hash
*next
; /* Next structure in the bucket. */
919 int hashcode
; /* Hash code of this list. */
920 tree list
; /* The list recorded here. */
923 /* Now here is the hash table. When recording a list, it is added
924 to the slot whose index is the hash code mod the table size.
925 Note that the hash table is used for several kinds of lists.
926 While all these live in the same table, they are completely independent,
927 and the hash code is computed differently for each of these. */
929 #define TYPE_HASH_SIZE 59
930 static struct list_hash
*list_hash_table
[TYPE_HASH_SIZE
];
932 /* Compute a hash code for a list (chain of TREE_LIST nodes
933 with goodies in the TREE_PURPOSE, TREE_VALUE, and bits of the
934 TREE_COMMON slots), by adding the hash codes of the individual entries. */
937 list_hash (purpose
, value
, chain
)
938 tree purpose
, value
, chain
;
940 register int hashcode
= 0;
943 hashcode
+= TYPE_HASH (chain
);
946 hashcode
+= TYPE_HASH (value
);
950 hashcode
+= TYPE_HASH (purpose
);
956 /* Look in the type hash table for a type isomorphic to TYPE.
957 If one is found, return it. Otherwise return 0. */
960 list_hash_lookup (hashcode
, via_public
, via_protected
, via_virtual
,
961 purpose
, value
, chain
)
962 int hashcode
, via_public
, via_virtual
, via_protected
;
963 tree purpose
, value
, chain
;
965 register struct list_hash
*h
;
967 for (h
= list_hash_table
[hashcode
% TYPE_HASH_SIZE
]; h
; h
= h
->next
)
968 if (h
->hashcode
== hashcode
969 && TREE_VIA_VIRTUAL (h
->list
) == via_virtual
970 && TREE_VIA_PUBLIC (h
->list
) == via_public
971 && TREE_VIA_PROTECTED (h
->list
) == via_protected
972 && TREE_PURPOSE (h
->list
) == purpose
973 && TREE_VALUE (h
->list
) == value
974 && TREE_CHAIN (h
->list
) == chain
)
979 /* Add an entry to the list-hash-table
980 for a list TYPE whose hash code is HASHCODE. */
983 list_hash_add (hashcode
, list
)
987 register struct list_hash
*h
;
989 h
= (struct list_hash
*) obstack_alloc (&class_obstack
, sizeof (struct list_hash
));
990 h
->hashcode
= hashcode
;
992 h
->next
= list_hash_table
[hashcode
% TYPE_HASH_SIZE
];
993 list_hash_table
[hashcode
% TYPE_HASH_SIZE
] = h
;
996 /* Given TYPE, and HASHCODE its hash code, return the canonical
997 object for an identical list if one already exists.
998 Otherwise, return TYPE, and record it as the canonical object
999 if it is a permanent object.
1001 To use this function, first create a list of the sort you want.
1002 Then compute its hash code from the fields of the list that
1003 make it different from other similar lists.
1004 Then call this function and use the value.
1005 This function frees the list you pass in if it is a duplicate. */
1007 /* Set to 1 to debug without canonicalization. Never set by program. */
1009 static int debug_no_list_hash
= 0;
1012 hash_tree_cons (via_public
, via_virtual
, via_protected
, purpose
, value
, chain
)
1013 int via_public
, via_virtual
, via_protected
;
1014 tree purpose
, value
, chain
;
1016 struct obstack
*ambient_obstack
= current_obstack
;
1020 if (! debug_no_list_hash
)
1022 hashcode
= list_hash (purpose
, value
, chain
);
1023 t
= list_hash_lookup (hashcode
, via_public
, via_protected
, via_virtual
,
1024 purpose
, value
, chain
);
1029 current_obstack
= &class_obstack
;
1031 t
= tree_cons (purpose
, value
, chain
);
1032 TREE_VIA_PUBLIC (t
) = via_public
;
1033 TREE_VIA_PROTECTED (t
) = via_protected
;
1034 TREE_VIA_VIRTUAL (t
) = via_virtual
;
1036 /* If this is a new list, record it for later reuse. */
1037 if (! debug_no_list_hash
)
1038 list_hash_add (hashcode
, t
);
1040 current_obstack
= ambient_obstack
;
1044 /* Constructor for hashed lists. */
1047 hash_tree_chain (value
, chain
)
1050 return hash_tree_cons (0, 0, 0, NULL_TREE
, value
, chain
);
1053 /* Similar, but used for concatenating two lists. */
1056 hash_chainon (list1
, list2
)
1063 if (TREE_CHAIN (list1
) == NULL_TREE
)
1064 return hash_tree_chain (TREE_VALUE (list1
), list2
);
1065 return hash_tree_chain (TREE_VALUE (list1
),
1066 hash_chainon (TREE_CHAIN (list1
), list2
));
1070 get_identifier_list (value
)
1073 tree list
= IDENTIFIER_AS_LIST (value
);
1074 if (list
!= NULL_TREE
1075 && (TREE_CODE (list
) != TREE_LIST
1076 || TREE_VALUE (list
) != value
))
1078 else if (IDENTIFIER_HAS_TYPE_VALUE (value
)
1079 && TREE_CODE (IDENTIFIER_TYPE_VALUE (value
)) == RECORD_TYPE
1080 && IDENTIFIER_TYPE_VALUE (value
)
1081 == TYPE_MAIN_VARIANT (IDENTIFIER_TYPE_VALUE (value
)))
1083 tree type
= IDENTIFIER_TYPE_VALUE (value
);
1085 if (TYPE_PTRMEMFUNC_P (type
))
1087 else if (type
== current_class_type
)
1088 /* Don't mess up the constructor name. */
1089 list
= tree_cons (NULL_TREE
, value
, NULL_TREE
);
1092 if (! CLASSTYPE_ID_AS_LIST (type
))
1093 CLASSTYPE_ID_AS_LIST (type
)
1094 = perm_tree_cons (NULL_TREE
, TYPE_IDENTIFIER (type
), NULL_TREE
);
1095 list
= CLASSTYPE_ID_AS_LIST (type
);
1102 get_decl_list (value
)
1105 tree list
= NULL_TREE
;
1107 if (TREE_CODE (value
) == IDENTIFIER_NODE
)
1108 list
= get_identifier_list (value
);
1109 else if (TREE_CODE (value
) == RECORD_TYPE
1110 && TYPE_LANG_SPECIFIC (value
)
1111 && value
== TYPE_MAIN_VARIANT (value
))
1112 list
= CLASSTYPE_AS_LIST (value
);
1114 if (list
!= NULL_TREE
)
1116 my_friendly_assert (TREE_CHAIN (list
) == NULL_TREE
, 301);
1120 return build_decl_list (NULL_TREE
, value
);
1123 /* Build an association between TYPE and some parameters:
1125 OFFSET is the offset added to `this' to convert it to a pointer
1128 BINFO is the base binfo to use, if we are deriving from one. This
1129 is necessary, as we want specialized parent binfos from base
1130 classes, so that the VTABLE_NAMEs of bases are for the most derived
1131 type, instead of of the simple type.
1133 VTABLE is the virtual function table with which to initialize
1134 sub-objects of type TYPE.
1136 VIRTUALS are the virtual functions sitting in VTABLE.
1138 CHAIN are more associations we must retain. */
1141 make_binfo (offset
, binfo
, vtable
, virtuals
, chain
)
1143 tree vtable
, virtuals
;
1146 tree new_binfo
= make_tree_vec (6);
1149 if (TREE_CODE (binfo
) == TREE_VEC
)
1150 type
= BINFO_TYPE (binfo
);
1154 binfo
= TYPE_BINFO (binfo
);
1157 TREE_CHAIN (new_binfo
) = chain
;
1159 TREE_USED (new_binfo
) = TREE_USED (chain
);
1161 TREE_TYPE (new_binfo
) = TYPE_MAIN_VARIANT (type
);
1162 BINFO_OFFSET (new_binfo
) = offset
;
1163 BINFO_VTABLE (new_binfo
) = vtable
;
1164 BINFO_VIRTUALS (new_binfo
) = virtuals
;
1165 BINFO_VPTR_FIELD (new_binfo
) = NULL_TREE
;
1167 if (binfo
&& BINFO_BASETYPES (binfo
) != NULL_TREE
)
1168 BINFO_BASETYPES (new_binfo
) = copy_node (BINFO_BASETYPES (binfo
));
1172 /* Return the binfo value for ELEM in TYPE. */
1175 binfo_value (elem
, type
)
1179 if (get_base_distance (elem
, type
, 0, (tree
*)0) == -2)
1180 compiler_error ("base class `%s' ambiguous in binfo_value",
1181 TYPE_NAME_STRING (elem
));
1183 return TYPE_BINFO (type
);
1184 if (TREE_CODE (elem
) == RECORD_TYPE
&& TYPE_BINFO (elem
) == type
)
1186 return get_binfo (elem
, type
, 0);
1193 register tree prev
= 0, tmp
, next
;
1194 for (tmp
= path
; tmp
; tmp
= next
)
1196 next
= BINFO_INHERITANCE_CHAIN (tmp
);
1197 BINFO_INHERITANCE_CHAIN (tmp
) = prev
;
1207 unsigned HOST_WIDE_INT n
;
1210 fprintf (stderr
, "type \"%s\"; offset = %d\n",
1211 TYPE_NAME_STRING (BINFO_TYPE (elem
)),
1212 TREE_INT_CST_LOW (BINFO_OFFSET (elem
)));
1213 fprintf (stderr
, "vtable type:\n");
1214 debug_tree (BINFO_TYPE (elem
));
1215 if (BINFO_VTABLE (elem
))
1216 fprintf (stderr
, "vtable decl \"%s\"\n", IDENTIFIER_POINTER (DECL_NAME (BINFO_VTABLE (elem
))));
1218 fprintf (stderr
, "no vtable decl yet\n");
1219 fprintf (stderr
, "virtuals:\n");
1220 virtuals
= BINFO_VIRTUALS (elem
);
1222 n
= skip_rtti_stuff (&virtuals
);
1226 tree fndecl
= TREE_OPERAND (FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (virtuals
)), 0);
1227 fprintf (stderr
, "%s [%d =? %d]\n",
1228 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (fndecl
)),
1229 n
, TREE_INT_CST_LOW (DECL_VINDEX (fndecl
)));
1231 virtuals
= TREE_CHAIN (virtuals
);
1235 /* Return the length of a chain of nodes chained through DECL_CHAIN.
1236 We expect a null pointer to mark the end of the chain.
1237 This is the Lisp primitive `length'. */
1240 decl_list_length (t
)
1244 register int len
= 0;
1246 my_friendly_assert (TREE_CODE (t
) == FUNCTION_DECL
1247 || TREE_CODE (t
) == TEMPLATE_DECL
, 300);
1248 for (tail
= t
; tail
; tail
= DECL_CHAIN (tail
))
1258 if (TREE_CODE (t
) == FUNCTION_DECL
)
1260 else if (TREE_CODE (t
) == TREE_LIST
)
1261 return decl_list_length (TREE_VALUE (t
));
1263 my_friendly_abort (359);
1268 is_overloaded_fn (x
)
1271 if (TREE_CODE (x
) == FUNCTION_DECL
)
1274 if (TREE_CODE (x
) == TREE_LIST
1275 && (TREE_CODE (TREE_VALUE (x
)) == FUNCTION_DECL
1276 || TREE_CODE (TREE_VALUE (x
)) == TEMPLATE_DECL
))
1283 really_overloaded_fn (x
)
1286 if (TREE_CODE (x
) == TREE_LIST
1287 && (TREE_CODE (TREE_VALUE (x
)) == FUNCTION_DECL
1288 || TREE_CODE (TREE_VALUE (x
)) == TEMPLATE_DECL
))
1298 if (TREE_CODE (from
) == FUNCTION_DECL
)
1301 my_friendly_assert (TREE_CODE (from
) == TREE_LIST
, 9);
1303 return TREE_VALUE (from
);
1307 is_aggr_type_2 (t1
, t2
)
1310 if (TREE_CODE (t1
) != TREE_CODE (t2
))
1312 return IS_AGGR_TYPE (t1
) && IS_AGGR_TYPE (t2
);
1315 /* Give message using types TYPE1 and TYPE2 as arguments.
1316 PFN is the function which will print the message;
1317 S is the format string for PFN to use. */
1320 message_2_types (pfn
, s
, type1
, type2
)
1325 tree name1
= TYPE_NAME (type1
);
1326 tree name2
= TYPE_NAME (type2
);
1327 if (TREE_CODE (name1
) == TYPE_DECL
)
1328 name1
= DECL_NAME (name1
);
1329 if (TREE_CODE (name2
) == TYPE_DECL
)
1330 name2
= DECL_NAME (name2
);
1331 (*pfn
) (s
, IDENTIFIER_POINTER (name1
), IDENTIFIER_POINTER (name2
));
1334 #define PRINT_RING_SIZE 4
1337 lang_printable_name (decl
, v
)
1341 static tree decl_ring
[PRINT_RING_SIZE
];
1342 static char *print_ring
[PRINT_RING_SIZE
];
1343 static int ring_counter
;
1346 /* Only cache functions. */
1348 || TREE_CODE (decl
) != FUNCTION_DECL
1349 || DECL_LANG_SPECIFIC (decl
) == 0)
1350 return lang_decl_name (decl
, v
);
1352 /* See if this print name is lying around. */
1353 for (i
= 0; i
< PRINT_RING_SIZE
; i
++)
1354 if (decl_ring
[i
] == decl
)
1355 /* yes, so return it. */
1356 return print_ring
[i
];
1358 if (++ring_counter
== PRINT_RING_SIZE
)
1361 if (current_function_decl
!= NULL_TREE
)
1363 if (decl_ring
[ring_counter
] == current_function_decl
)
1365 if (ring_counter
== PRINT_RING_SIZE
)
1367 if (decl_ring
[ring_counter
] == current_function_decl
)
1368 my_friendly_abort (106);
1371 if (print_ring
[ring_counter
])
1372 free (print_ring
[ring_counter
]);
1374 print_ring
[ring_counter
] = xstrdup (lang_decl_name (decl
, v
));
1375 decl_ring
[ring_counter
] = decl
;
1376 return print_ring
[ring_counter
];
1379 /* Build the FUNCTION_TYPE or METHOD_TYPE which may throw exceptions
1380 listed in RAISES. */
1383 build_exception_variant (type
, raises
)
1387 tree v
= TYPE_MAIN_VARIANT (type
);
1388 int constp
= TYPE_READONLY (type
);
1389 int volatilep
= TYPE_VOLATILE (type
);
1391 for (; v
; v
= TYPE_NEXT_VARIANT (v
))
1393 if (TYPE_READONLY (v
) != constp
1394 || TYPE_VOLATILE (v
) != volatilep
)
1397 /* @@ This should do set equality, not exact match. */
1398 if (simple_cst_list_equal (TYPE_RAISES_EXCEPTIONS (v
), raises
))
1399 /* List of exceptions raised matches previously found list.
1401 @@ Nice to free up storage used in consing up the
1402 @@ list of exceptions raised. */
1406 /* Need to build a new variant. */
1407 v
= build_type_copy (type
);
1409 if (raises
&& ! TREE_PERMANENT (raises
))
1411 push_obstacks_nochange ();
1412 end_temporary_allocation ();
1413 raises
= copy_list (raises
);
1417 TYPE_RAISES_EXCEPTIONS (v
) = raises
;
1421 /* Subroutine of copy_to_permanent
1423 Assuming T is a node build bottom-up, make it all exist on
1424 permanent obstack, if it is not permanent already. */
1436 if (tmp
= func (t
), tmp
!= NULL_TREE
)
1439 switch (TREE_CODE (t
))
1442 return error_mark_node
;
1451 tree chain
= TREE_CHAIN (t
);
1453 TREE_CHAIN (t
) = mapcar (chain
, func
);
1454 TREE_TYPE (t
) = mapcar (TREE_TYPE (t
), func
);
1455 DECL_INITIAL (t
) = mapcar (DECL_INITIAL (t
), func
);
1456 DECL_SIZE (t
) = mapcar (DECL_SIZE (t
), func
);
1462 tree chain
= TREE_CHAIN (t
);
1464 TREE_PURPOSE (t
) = mapcar (TREE_PURPOSE (t
), func
);
1465 TREE_VALUE (t
) = mapcar (TREE_VALUE (t
), func
);
1466 TREE_CHAIN (t
) = mapcar (chain
, func
);
1472 int len
= TREE_VEC_LENGTH (t
);
1476 TREE_VEC_ELT (t
, len
) = mapcar (TREE_VEC_ELT (t
, len
), func
);
1483 return copy_node (t
);
1489 TREE_OPERAND (t
, 0) = mapcar (TREE_OPERAND (t
, 0), func
);
1490 TREE_OPERAND (t
, 1) = mapcar (TREE_OPERAND (t
, 1), func
);
1491 TREE_OPERAND (t
, 2) = mapcar (TREE_OPERAND (t
, 2), func
);
1496 TREE_OPERAND (t
, 0) = mapcar (TREE_OPERAND (t
, 0), func
);
1503 case TRUNC_DIV_EXPR
:
1504 case TRUNC_MOD_EXPR
:
1512 case BIT_ANDTC_EXPR
:
1513 case TRUTH_ANDIF_EXPR
:
1514 case TRUTH_ORIF_EXPR
:
1522 case FLOOR_DIV_EXPR
:
1523 case ROUND_DIV_EXPR
:
1525 case FLOOR_MOD_EXPR
:
1526 case ROUND_MOD_EXPR
:
1528 case PREDECREMENT_EXPR
:
1529 case PREINCREMENT_EXPR
:
1530 case POSTDECREMENT_EXPR
:
1531 case POSTINCREMENT_EXPR
:
1535 TREE_OPERAND (t
, 0) = mapcar (TREE_OPERAND (t
, 0), func
);
1536 TREE_OPERAND (t
, 1) = mapcar (TREE_OPERAND (t
, 1), func
);
1541 TREE_TYPE (t
) = mapcar (TREE_TYPE (t
), func
);
1542 TREE_OPERAND (t
, 0) = mapcar (TREE_OPERAND (t
, 0), func
);
1543 TREE_OPERAND (t
, 1) = mapcar (TREE_OPERAND (t
, 1), func
);
1545 /* tree.def says that operand two is RTL, but
1546 build_call_declarator puts trees in there. */
1547 if (TREE_OPERAND (t
, 2)
1548 && TREE_CODE (TREE_OPERAND (t
, 2)) == TREE_LIST
)
1549 TREE_OPERAND (t
, 2) = mapcar (TREE_OPERAND (t
, 2), func
);
1551 TREE_OPERAND (t
, 2) = NULL_TREE
;
1559 case TRUTH_NOT_EXPR
:
1563 TREE_OPERAND (t
, 0) = mapcar (TREE_OPERAND (t
, 0), func
);
1567 tmp
= build_pointer_type (mapcar (TREE_TYPE (t
), func
));
1568 return cp_build_type_variant (tmp
, TYPE_READONLY (t
), TYPE_VOLATILE (t
));
1569 case REFERENCE_TYPE
:
1570 tmp
= build_reference_type (mapcar (TREE_TYPE (t
), func
));
1571 return cp_build_type_variant (tmp
, TYPE_READONLY (t
), TYPE_VOLATILE (t
));
1573 tmp
= build_function_type (mapcar (TREE_TYPE (t
), func
),
1574 mapcar (TYPE_ARG_TYPES (t
), func
));
1575 return cp_build_type_variant (tmp
, TYPE_READONLY (t
), TYPE_VOLATILE (t
));
1577 tmp
= build_cplus_array_type (mapcar (TREE_TYPE (t
), func
),
1578 mapcar (TYPE_DOMAIN (t
), func
));
1579 return cp_build_type_variant (tmp
, TYPE_READONLY (t
), TYPE_VOLATILE (t
));
1581 tmp
= build_index_type (mapcar (TYPE_MAX_VALUE (t
), func
));
1582 return cp_build_type_variant (tmp
, TYPE_READONLY (t
), TYPE_VOLATILE (t
));
1584 tmp
= build_offset_type (mapcar (TYPE_OFFSET_BASETYPE (t
), func
),
1585 mapcar (TREE_TYPE (t
), func
));
1586 return cp_build_type_variant (tmp
, TYPE_READONLY (t
), TYPE_VOLATILE (t
));
1588 tmp
= build_cplus_method_type
1589 (mapcar (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (t
))), func
),
1590 mapcar (TREE_TYPE (t
), func
),
1591 mapcar (TREE_CHAIN (TYPE_ARG_TYPES (t
)), func
));
1592 return cp_build_type_variant (tmp
, TYPE_READONLY (t
), TYPE_VOLATILE (t
));
1596 TREE_REALPART (t
) = mapcar (TREE_REALPART (t
), func
);
1597 TREE_IMAGPART (t
) = mapcar (TREE_REALPART (t
), func
);
1602 CONSTRUCTOR_ELTS (t
) = mapcar (CONSTRUCTOR_ELTS (t
), func
);
1606 if (TYPE_PTRMEMFUNC_P (t
))
1607 return build_ptrmemfunc_type
1608 (mapcar (TYPE_PTRMEMFUNC_FN_TYPE (t
), func
));
1609 /* else fall through */
1611 /* This list is incomplete, but should suffice for now.
1612 It is very important that `sorry' not call
1613 `report_error_function'. That could cause an infinite loop. */
1615 sorry ("initializer contains unrecognized tree code");
1616 return error_mark_node
;
1619 my_friendly_abort (107);
1628 if (TREE_PERMANENT (t
))
1630 /* Support `void f () { extern int i; A<&i> a; }' */
1631 if ((TREE_CODE (t
) == VAR_DECL
|| TREE_CODE (t
) == FUNCTION_DECL
)
1633 return copy_node (t
);
1637 /* Assuming T is a node built bottom-up, make it all exist on
1638 permanent obstack, if it is not permanent already. */
1641 copy_to_permanent (t
)
1644 register struct obstack
*ambient_obstack
= current_obstack
;
1645 register struct obstack
*ambient_saveable_obstack
= saveable_obstack
;
1646 register struct obstack
*ambient_expression_obstack
= expression_obstack
;
1648 if (t
== NULL_TREE
|| TREE_PERMANENT (t
))
1651 saveable_obstack
= &permanent_obstack
;
1652 current_obstack
= saveable_obstack
;
1653 expression_obstack
= saveable_obstack
;
1655 t
= mapcar (t
, perm_manip
);
1657 current_obstack
= ambient_obstack
;
1658 saveable_obstack
= ambient_saveable_obstack
;
1659 expression_obstack
= ambient_expression_obstack
;
1664 #ifdef GATHER_STATISTICS
1665 extern int depth_reached
;
1669 print_lang_statistics ()
1671 extern struct obstack maybepermanent_obstack
, decl_obstack
;
1672 print_obstack_statistics ("class_obstack", &class_obstack
);
1673 print_obstack_statistics ("decl_obstack", &decl_obstack
);
1674 print_obstack_statistics ("permanent_obstack", &permanent_obstack
);
1675 print_obstack_statistics ("maybepermanent_obstack", &maybepermanent_obstack
);
1676 print_search_statistics ();
1677 print_class_statistics ();
1678 #ifdef GATHER_STATISTICS
1679 fprintf (stderr
, "maximum template instantiation depth reached: %d\n",
1684 /* This is used by the `assert' macro. It is provided in libgcc.a,
1685 which `cc' doesn't know how to link. Note that the C++ front-end
1686 no longer actually uses the `assert' macro (instead, it calls
1687 my_friendly_assert). But all of the back-end files still need this. */
1690 __eprintf (string
, expression
, line
, filename
)
1693 const char *expression
;
1695 const char *filename
;
1703 fprintf (stderr
, string
, expression
, line
, filename
);
1708 /* Return, as an INTEGER_CST node, the number of elements for TYPE
1709 (which is an ARRAY_TYPE). This counts only elements of the top
1713 array_type_nelts_top (type
)
1716 return fold (build (PLUS_EXPR
, sizetype
,
1717 array_type_nelts (type
),
1721 /* Return, as an INTEGER_CST node, the number of elements for TYPE
1722 (which is an ARRAY_TYPE). This one is a recursive count of all
1723 ARRAY_TYPEs that are clumped together. */
1726 array_type_nelts_total (type
)
1729 tree sz
= array_type_nelts_top (type
);
1730 type
= TREE_TYPE (type
);
1731 while (TREE_CODE (type
) == ARRAY_TYPE
)
1733 tree n
= array_type_nelts_top (type
);
1734 sz
= fold (build (MULT_EXPR
, sizetype
, sz
, n
));
1735 type
= TREE_TYPE (type
);
1745 if (TREE_CODE (t
) != TREE_LIST
&& ! TREE_SIDE_EFFECTS (t
))
1747 else if (TREE_CODE (t
) == TARGET_EXPR
)
1749 if (TREE_CODE (TREE_OPERAND (t
, 1)) == NEW_EXPR
)
1751 mark_used (TREE_OPERAND (TREE_OPERAND (TREE_OPERAND (t
, 1), 0), 0));
1752 return build_cplus_new
1753 (TREE_TYPE (t
), break_out_target_exprs (TREE_OPERAND (t
, 1)));
1756 TREE_OPERAND (t
, 0) = build (VAR_DECL
, TREE_TYPE (t
));
1757 layout_decl (TREE_OPERAND (t
, 0), 0);
1760 else if (TREE_CODE (t
) == CALL_EXPR
)
1761 mark_used (TREE_OPERAND (TREE_OPERAND (t
, 0), 0));
1766 /* Actually, we'll just clean out the target exprs for the moment. */
1769 break_out_target_exprs (t
)
1772 return mapcar (t
, bot_manip
);
1775 /* Obstack used for allocating nodes in template function and variable
1778 extern struct obstack
*expression_obstack
;
1780 /* Similar to `build_nt', except we build
1781 on the permanent_obstack, regardless. */
1784 build_min_nt
VPROTO((enum tree_code code
, ...))
1787 enum tree_code code
;
1789 register struct obstack
*ambient_obstack
= expression_obstack
;
1792 register int length
;
1798 code
= va_arg (p
, enum tree_code
);
1801 expression_obstack
= &permanent_obstack
;
1803 t
= make_node (code
);
1804 length
= tree_code_length
[(int) code
];
1805 TREE_COMPLEXITY (t
) = lineno
;
1807 for (i
= 0; i
< length
; i
++)
1809 tree x
= va_arg (p
, tree
);
1810 TREE_OPERAND (t
, i
) = copy_to_permanent (x
);
1814 expression_obstack
= ambient_obstack
;
1818 /* Similar to `build', except we build
1819 on the permanent_obstack, regardless. */
1822 build_min
VPROTO((enum tree_code code
, tree tt
, ...))
1825 enum tree_code code
;
1828 register struct obstack
*ambient_obstack
= expression_obstack
;
1831 register int length
;
1837 code
= va_arg (p
, enum tree_code
);
1838 tt
= va_arg (p
, tree
);
1841 expression_obstack
= &permanent_obstack
;
1843 t
= make_node (code
);
1844 length
= tree_code_length
[(int) code
];
1846 TREE_COMPLEXITY (t
) = lineno
;
1848 for (i
= 0; i
< length
; i
++)
1850 tree x
= va_arg (p
, tree
);
1851 TREE_OPERAND (t
, i
) = copy_to_permanent (x
);
1855 expression_obstack
= ambient_obstack
;
1859 /* Same as `tree_cons' but make a permanent object. */
1862 min_tree_cons (purpose
, value
, chain
)
1863 tree purpose
, value
, chain
;
1866 register struct obstack
*ambient_obstack
= current_obstack
;
1867 current_obstack
= &permanent_obstack
;
1869 node
= tree_cons (copy_to_permanent (purpose
),
1870 copy_to_permanent (value
), chain
);
1871 current_obstack
= ambient_obstack
;
1879 if (TREE_CODE (t
) == IDENTIFIER_NODE
)
1880 return identifier_typedecl_value (t
);
1881 if (TREE_CODE (t
) == TYPE_DECL
)
1883 if (TREE_CODE_CLASS (TREE_CODE (t
)) == 't')
1884 return TYPE_STUB_DECL (t
);
1886 my_friendly_abort (42);
1890 can_free (obstack
, t
)
1891 struct obstack
*obstack
;
1896 if (TREE_CODE (t
) == TREE_VEC
)
1897 size
= (TREE_VEC_LENGTH (t
)-1) * sizeof (tree
) + sizeof (struct tree_vec
);
1899 my_friendly_abort (42);
1901 #define ROUND(x) ((x + obstack_alignment_mask (obstack)) \
1902 & ~ obstack_alignment_mask (obstack))
1903 if ((char *)t
+ ROUND (size
) == obstack_next_free (obstack
))
1910 /* Return first vector element whose BINFO_TYPE is ELEM.
1911 Return 0 if ELEM is not in VEC. VEC may be NULL_TREE. */
1914 vec_binfo_member (elem
, vec
)
1920 for (i
= 0; i
< TREE_VEC_LENGTH (vec
); ++i
)
1921 if (comptypes (elem
, BINFO_TYPE (TREE_VEC_ELT (vec
, i
)), 1))
1922 return TREE_VEC_ELT (vec
, i
);
1927 /* Kludge around the fact that DECL_CONTEXT for virtual functions returns
1928 the wrong thing for decl_function_context. Hopefully the uses in the
1929 backend won't matter, since we don't need a static chain for local class
1933 hack_decl_function_context (decl
)
1936 if (TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_FUNCTION_MEMBER_P (decl
))
1937 return decl_function_context (TYPE_MAIN_DECL (DECL_CLASS_CONTEXT (decl
)));
1938 return decl_function_context (decl
);
1941 /* Return truthvalue of whether T1 is the same tree structure as T2.
1942 Return 1 if they are the same.
1943 Return 0 if they are understandably different.
1944 Return -1 if either contains tree structure not understood by
1948 cp_tree_equal (t1
, t2
)
1951 register enum tree_code code1
, code2
;
1956 if (t1
== 0 || t2
== 0)
1959 code1
= TREE_CODE (t1
);
1960 code2
= TREE_CODE (t2
);
1962 if (code1
== NOP_EXPR
|| code1
== CONVERT_EXPR
|| code1
== NON_LVALUE_EXPR
)
1963 if (code2
== NOP_EXPR
|| code2
== CONVERT_EXPR
|| code2
== NON_LVALUE_EXPR
)
1964 return cp_tree_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
1966 return cp_tree_equal (TREE_OPERAND (t1
, 0), t2
);
1967 else if (code2
== NOP_EXPR
|| code2
== CONVERT_EXPR
1968 || code2
== NON_LVALUE_EXPR
)
1969 return cp_tree_equal (t1
, TREE_OPERAND (t2
, 0));
1977 return TREE_INT_CST_LOW (t1
) == TREE_INT_CST_LOW (t2
)
1978 && TREE_INT_CST_HIGH (t1
) == TREE_INT_CST_HIGH (t2
);
1981 return REAL_VALUES_EQUAL (TREE_REAL_CST (t1
), TREE_REAL_CST (t2
));
1984 return TREE_STRING_LENGTH (t1
) == TREE_STRING_LENGTH (t2
)
1985 && !bcmp (TREE_STRING_POINTER (t1
), TREE_STRING_POINTER (t2
),
1986 TREE_STRING_LENGTH (t1
));
1992 return cp_tree_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
1995 cmp
= cp_tree_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
1998 return simple_cst_list_equal (TREE_OPERAND (t1
, 1), TREE_OPERAND (t2
, 1));
2001 /* Special case: if either target is an unallocated VAR_DECL,
2002 it means that it's going to be unified with whatever the
2003 TARGET_EXPR is really supposed to initialize, so treat it
2004 as being equivalent to anything. */
2005 if ((TREE_CODE (TREE_OPERAND (t1
, 0)) == VAR_DECL
2006 && DECL_NAME (TREE_OPERAND (t1
, 0)) == NULL_TREE
2007 && DECL_RTL (TREE_OPERAND (t1
, 0)) == 0)
2008 || (TREE_CODE (TREE_OPERAND (t2
, 0)) == VAR_DECL
2009 && DECL_NAME (TREE_OPERAND (t2
, 0)) == NULL_TREE
2010 && DECL_RTL (TREE_OPERAND (t2
, 0)) == 0))
2013 cmp
= cp_tree_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
2016 return cp_tree_equal (TREE_OPERAND (t1
, 1), TREE_OPERAND (t2
, 1));
2018 case WITH_CLEANUP_EXPR
:
2019 cmp
= cp_tree_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
2022 return cp_tree_equal (TREE_OPERAND (t1
, 2), TREE_OPERAND (t1
, 2));
2025 if (TREE_OPERAND (t1
, 1) == TREE_OPERAND (t2
, 1))
2026 return cp_tree_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
2035 case TEMPLATE_CONST_PARM
:
2036 return TEMPLATE_CONST_IDX (t1
) == TEMPLATE_CONST_IDX (t2
);
2039 if (TREE_CODE (TREE_OPERAND (t1
, 0)) != TREE_CODE (TREE_OPERAND (t2
, 0)))
2041 if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (t1
, 0))) == 't')
2042 return comptypes (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0), 1);
2046 switch (TREE_CODE_CLASS (code1
))
2056 for (i
=0; i
<tree_code_length
[(int) code1
]; ++i
)
2058 cmp
= cp_tree_equal (TREE_OPERAND (t1
, i
), TREE_OPERAND (t2
, i
));
2068 /* Similar to make_tree_vec, but build on a temporary obstack. */
2075 push_obstacks_nochange ();
2076 resume_temporary_allocation ();
2077 node
= make_tree_vec (len
);
2082 /* The type of ARG when used as an lvalue. */
2088 return cp_build_type_variant
2089 (TREE_TYPE (arg
), TREE_READONLY (arg
), TREE_THIS_VOLATILE (arg
));
2092 /* The type of ARG for printing error messages; denote lvalues with
2099 tree type
= TREE_TYPE (arg
);
2100 if (TREE_CODE (type
) == ARRAY_TYPE
)
2102 else if (real_lvalue_p (arg
))
2103 type
= build_reference_type (lvalue_type (arg
));
2104 else if (IS_AGGR_TYPE (type
))
2105 type
= lvalue_type (arg
);
2110 /* Does FUNCTION use a variable-length argument list? */
2113 varargs_function_p (function
)
2116 tree parm
= TYPE_ARG_TYPES (TREE_TYPE (function
));
2117 for (; parm
; parm
= TREE_CHAIN (parm
))
2118 if (TREE_VALUE (parm
) == void_type_node
)