1 /* Language-dependent node constructors for parse phase of GNU compiler.
2 Copyright (C) 1987, 1988, 1992, 1993 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, 675 Mass Ave, Cambridge, MA 02139, USA. */
29 #define CEIL(x,y) (((x) + (y) - 1) / (y))
31 /* Return nonzero if REF is an lvalue valid for this language.
32 Lvalues can be assigned, unless they have TREE_READONLY.
33 Lvalues can have their address taken, unless they have DECL_REGISTER. */
39 if (! language_lvalue_valid (ref
))
42 if (TREE_CODE (TREE_TYPE (ref
)) == REFERENCE_TYPE
)
45 if (ref
== current_class_decl
&& flag_this_is_variable
<= 0)
48 switch (TREE_CODE (ref
))
50 /* preincrements and predecrements are valid lvals, provided
51 what they refer to are valid lvals. */
52 case PREINCREMENT_EXPR
:
53 case PREDECREMENT_EXPR
:
56 return real_lvalue_p (TREE_OPERAND (ref
, 0));
62 if (TREE_READONLY (ref
) && ! TREE_STATIC (ref
)
63 && DECL_LANG_SPECIFIC (ref
)
64 && DECL_IN_AGGR_P (ref
))
71 if (TREE_CODE (TREE_TYPE (ref
)) != FUNCTION_TYPE
72 && TREE_CODE (TREE_TYPE (ref
)) != METHOD_TYPE
)
76 case WITH_CLEANUP_EXPR
:
77 return real_lvalue_p (TREE_OPERAND (ref
, 0));
79 /* A currently unresolved scope ref. */
81 my_friendly_abort (103);
83 if (TREE_CODE (TREE_OPERAND (ref
, 1)) == FUNCTION_DECL
)
85 return real_lvalue_p (TREE_OPERAND (ref
, 0))
86 && real_lvalue_p (TREE_OPERAND (ref
, 1));
90 return (real_lvalue_p (TREE_OPERAND (ref
, 1))
91 && real_lvalue_p (TREE_OPERAND (ref
, 2)));
97 return real_lvalue_p (TREE_OPERAND (ref
, 1));
101 return (real_lvalue_p (TREE_OPERAND (ref
, 0))
102 && real_lvalue_p (TREE_OPERAND (ref
, 1)));
112 if (! language_lvalue_valid (ref
))
115 if (TREE_CODE (TREE_TYPE (ref
)) == REFERENCE_TYPE
)
118 if (ref
== current_class_decl
&& flag_this_is_variable
<= 0)
121 switch (TREE_CODE (ref
))
123 /* preincrements and predecrements are valid lvals, provided
124 what they refer to are valid lvals. */
125 case PREINCREMENT_EXPR
:
126 case PREDECREMENT_EXPR
:
129 return lvalue_p (TREE_OPERAND (ref
, 0));
135 if (TREE_READONLY (ref
) && ! TREE_STATIC (ref
)
136 && DECL_LANG_SPECIFIC (ref
)
137 && DECL_IN_AGGR_P (ref
))
144 if (TREE_CODE (TREE_TYPE (ref
)) != FUNCTION_TYPE
145 && TREE_CODE (TREE_TYPE (ref
)) != METHOD_TYPE
)
149 case WITH_CLEANUP_EXPR
:
150 return lvalue_p (TREE_OPERAND (ref
, 0));
156 if (IS_AGGR_TYPE (TREE_TYPE (ref
)))
160 /* A currently unresolved scope ref. */
162 my_friendly_abort (103);
164 if (TREE_CODE (TREE_OPERAND (ref
, 1)) == FUNCTION_DECL
)
166 return lvalue_p (TREE_OPERAND (ref
, 0))
167 && lvalue_p (TREE_OPERAND (ref
, 1));
171 return (lvalue_p (TREE_OPERAND (ref
, 1))
172 && lvalue_p (TREE_OPERAND (ref
, 2)));
178 return lvalue_p (TREE_OPERAND (ref
, 1));
182 return (lvalue_p (TREE_OPERAND (ref
, 0))
183 && lvalue_p (TREE_OPERAND (ref
, 1)));
189 /* Return nonzero if REF is an lvalue valid for this language;
190 otherwise, print an error message and return zero. */
193 lvalue_or_else (ref
, string
)
197 int win
= lvalue_p (ref
);
199 error ("non-lvalue in %s", string
);
203 /* INIT is a CALL_EXPR which needs info about its target.
204 TYPE is the type that this initialization should appear to have.
206 Build an encapsulation of the initialization to perform
207 and return it so that it can be processed by language-independent
208 and language-specific expression expanders.
210 If WITH_CLEANUP_P is nonzero, we build a cleanup for this expression.
211 Otherwise, cleanups are not built here. For example, when building
212 an initialization for a stack slot, since the called function handles
213 the cleanup, we would not want to do it here. */
215 build_cplus_new (type
, init
, with_cleanup_p
)
223 slot
= build (VAR_DECL
, type
);
224 layout_decl (slot
, 0);
225 rval
= build (NEW_EXPR
, type
,
226 TREE_OPERAND (init
, 0), TREE_OPERAND (init
, 1), slot
);
227 TREE_SIDE_EFFECTS (rval
) = 1;
228 TREE_ADDRESSABLE (rval
) = 1;
229 rval
= build (TARGET_EXPR
, type
, slot
, rval
, 0);
230 TREE_SIDE_EFFECTS (rval
) = 1;
231 TREE_ADDRESSABLE (rval
) = 1;
234 if (with_cleanup_p
&& TYPE_NEEDS_DESTRUCTOR (type
))
236 TREE_OPERAND (rval
, 2) = error_mark_node
;
237 rval
= build (WITH_CLEANUP_EXPR
, type
, rval
, 0,
238 build_delete (TYPE_POINTER_TO (type
),
239 build_unary_op (ADDR_EXPR
, slot
, 0),
241 LOOKUP_NORMAL
|LOOKUP_DESTRUCTOR
, 0));
242 TREE_SIDE_EFFECTS (rval
) = 1;
243 TREE_ADDRESSABLE (rval
) = 1;
249 /* Recursively search EXP for CALL_EXPRs that need cleanups and replace
250 these CALL_EXPRs with tree nodes that will perform the cleanups. */
253 break_out_cleanups (exp
)
258 if (TREE_CODE (tmp
) == CALL_EXPR
259 && TYPE_NEEDS_DESTRUCTOR (TREE_TYPE (tmp
)))
260 return build_cplus_new (TREE_TYPE (tmp
), tmp
, 1);
262 while (TREE_CODE (tmp
) == NOP_EXPR
263 || TREE_CODE (tmp
) == CONVERT_EXPR
264 || TREE_CODE (tmp
) == NON_LVALUE_EXPR
)
266 if (TREE_CODE (TREE_OPERAND (tmp
, 0)) == CALL_EXPR
267 && TYPE_NEEDS_DESTRUCTOR (TREE_TYPE (TREE_OPERAND (tmp
, 0))))
269 TREE_OPERAND (tmp
, 0)
270 = build_cplus_new (TREE_TYPE (TREE_OPERAND (tmp
, 0)),
271 TREE_OPERAND (tmp
, 0), 1);
275 tmp
= TREE_OPERAND (tmp
, 0);
280 /* Recursively perform a preorder search EXP for CALL_EXPRs, making
281 copies where they are found. Returns a deep copy all nodes transitively
282 containing CALL_EXPRs. */
285 break_out_calls (exp
)
288 register tree t1
, t2
;
289 register enum tree_code code
;
290 register int changed
= 0;
293 if (exp
== NULL_TREE
)
296 code
= TREE_CODE (exp
);
298 if (code
== CALL_EXPR
)
299 return copy_node (exp
);
301 /* Don't try and defeat a save_expr, as it should only be done once. */
302 if (code
== SAVE_EXPR
)
305 switch (TREE_CODE_CLASS (code
))
310 case 'c': /* a constant */
311 case 't': /* a type node */
312 case 'x': /* something random, like an identifier or an ERROR_MARK. */
315 case 'd': /* A decl node */
316 #if 0 /* This is bogus. jason 9/21/94 */
318 t1
= break_out_calls (DECL_INITIAL (exp
));
319 if (t1
!= DECL_INITIAL (exp
))
321 exp
= copy_node (exp
);
322 DECL_INITIAL (exp
) = t1
;
327 case 'b': /* A block node */
329 /* Don't know how to handle these correctly yet. Must do a
330 break_out_calls on all DECL_INITIAL values for local variables,
331 and also break_out_calls on all sub-blocks and sub-statements. */
336 case 'e': /* an expression */
337 case 'r': /* a reference */
338 case 's': /* an expression with side effects */
339 for (i
= tree_code_length
[(int) code
] - 1; i
>= 0; i
--)
341 t1
= break_out_calls (TREE_OPERAND (exp
, i
));
342 if (t1
!= TREE_OPERAND (exp
, i
))
344 exp
= copy_node (exp
);
345 TREE_OPERAND (exp
, i
) = t1
;
350 case '<': /* a comparison expression */
351 case '2': /* a binary arithmetic expression */
352 t2
= break_out_calls (TREE_OPERAND (exp
, 1));
353 if (t2
!= TREE_OPERAND (exp
, 1))
355 case '1': /* a unary arithmetic expression */
356 t1
= break_out_calls (TREE_OPERAND (exp
, 0));
357 if (t1
!= TREE_OPERAND (exp
, 0))
361 if (tree_code_length
[(int) code
] == 1)
362 return build1 (code
, TREE_TYPE (exp
), t1
);
364 return build (code
, TREE_TYPE (exp
), t1
, t2
);
371 extern struct obstack
*current_obstack
;
372 extern struct obstack permanent_obstack
, class_obstack
;
373 extern struct obstack
*saveable_obstack
;
375 /* Here is how primitive or already-canonicalized types' hash
376 codes are made. MUST BE CONSISTENT WITH tree.c !!! */
377 #define TYPE_HASH(TYPE) ((HOST_WIDE_INT) (TYPE) & 0777777)
379 /* Construct, lay out and return the type of methods belonging to class
380 BASETYPE and whose arguments are described by ARGTYPES and whose values
381 are described by RETTYPE. If each type exists already, reuse it. */
383 build_cplus_method_type (basetype
, rettype
, argtypes
)
384 tree basetype
, rettype
, argtypes
;
390 /* Make a node of the sort we want. */
391 t
= make_node (METHOD_TYPE
);
393 TYPE_METHOD_BASETYPE (t
) = TYPE_MAIN_VARIANT (basetype
);
394 TREE_TYPE (t
) = rettype
;
395 if (IS_SIGNATURE (basetype
))
396 ptype
= build_signature_pointer_type (TYPE_MAIN_VARIANT (basetype
),
397 TYPE_READONLY (basetype
),
398 TYPE_VOLATILE (basetype
));
401 ptype
= build_pointer_type (basetype
);
402 ptype
= build_type_variant (ptype
, 1, 0);
404 /* The actual arglist for this function includes a "hidden" argument
405 which is "this". Put it into the list of argument types. */
407 argtypes
= tree_cons (NULL_TREE
, ptype
, argtypes
);
408 TYPE_ARG_TYPES (t
) = argtypes
;
409 TREE_SIDE_EFFECTS (argtypes
) = 1; /* Mark first argtype as "artificial". */
411 /* If we already have such a type, use the old one and free this one.
412 Note that it also frees up the above cons cell if found. */
413 hashcode
= TYPE_HASH (basetype
) + TYPE_HASH (rettype
) + type_hash_list (argtypes
);
414 t
= type_hash_canon (hashcode
, t
);
416 if (TYPE_SIZE (t
) == 0)
423 build_cplus_staticfn_type (basetype
, rettype
, argtypes
)
424 tree basetype
, rettype
, argtypes
;
429 /* Make a node of the sort we want. */
430 t
= make_node (FUNCTION_TYPE
);
432 TYPE_METHOD_BASETYPE (t
) = TYPE_MAIN_VARIANT (basetype
);
433 TREE_TYPE (t
) = rettype
;
435 TYPE_ARG_TYPES (t
) = argtypes
;
437 /* If we already have such a type, use the old one and free this one.
438 Note that it also frees up the above cons cell if found. */
439 hashcode
= TYPE_HASH (basetype
) + TYPE_HASH (rettype
) + type_hash_list (argtypes
);
440 t
= type_hash_canon (hashcode
, t
);
442 if (TYPE_SIZE (t
) == 0)
449 build_cplus_array_type (elt_type
, index_type
)
453 register struct obstack
*ambient_obstack
= current_obstack
;
454 register struct obstack
*ambient_saveable_obstack
= saveable_obstack
;
457 /* We need a new one. If both ELT_TYPE and INDEX_TYPE are permanent,
458 make this permanent too. */
459 if (TREE_PERMANENT (elt_type
)
460 && (index_type
== 0 || TREE_PERMANENT (index_type
)))
462 current_obstack
= &permanent_obstack
;
463 saveable_obstack
= &permanent_obstack
;
466 t
= build_array_type (elt_type
, index_type
);
468 /* Push these needs up so that initialization takes place
470 TYPE_NEEDS_CONSTRUCTING (t
) = TYPE_NEEDS_CONSTRUCTING (TYPE_MAIN_VARIANT (elt_type
));
471 TYPE_NEEDS_DESTRUCTOR (t
) = TYPE_NEEDS_DESTRUCTOR (TYPE_MAIN_VARIANT (elt_type
));
472 current_obstack
= ambient_obstack
;
473 saveable_obstack
= ambient_saveable_obstack
;
477 /* Make a variant type in the proper way for C/C++, propagating qualifiers
478 down to the element type of an array. */
481 cp_build_type_variant (type
, constp
, volatilep
)
483 int constp
, volatilep
;
485 if (TREE_CODE (type
) == ARRAY_TYPE
)
487 tree real_main_variant
= TYPE_MAIN_VARIANT (type
);
489 push_obstacks (TYPE_OBSTACK (real_main_variant
),
490 TYPE_OBSTACK (real_main_variant
));
491 type
= build_cplus_array_type (cp_build_type_variant (TREE_TYPE (type
),
495 /* TYPE must be on same obstack as REAL_MAIN_VARIANT. If not,
496 make a copy. (TYPE might have come from the hash table and
497 REAL_MAIN_VARIANT might be in some function's obstack.) */
499 if (TYPE_OBSTACK (type
) != TYPE_OBSTACK (real_main_variant
))
501 type
= copy_node (type
);
502 TYPE_POINTER_TO (type
) = TYPE_REFERENCE_TO (type
) = 0;
505 TYPE_MAIN_VARIANT (type
) = real_main_variant
;
508 return build_type_variant (type
, constp
, volatilep
);
511 /* Add OFFSET to all base types of T.
513 OFFSET, which is a type offset, is number of bytes.
515 Note that we don't have to worry about having two paths to the
516 same base type, since this type owns its association list. */
518 propagate_binfo_offsets (binfo
, offset
)
522 tree binfos
= BINFO_BASETYPES (binfo
);
523 int i
, n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
525 for (i
= 0; i
< n_baselinks
; /* note increment is done in the loop. */)
527 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
529 if (TREE_VIA_VIRTUAL (base_binfo
))
534 tree base_binfos
= BINFO_BASETYPES (base_binfo
);
537 for (j
= i
+1; j
< n_baselinks
; j
++)
538 if (! TREE_VIA_VIRTUAL (TREE_VEC_ELT (binfos
, j
)))
540 /* The next basetype offset must take into account the space
541 between the classes, not just the size of each class. */
542 delta
= size_binop (MINUS_EXPR
,
543 BINFO_OFFSET (TREE_VEC_ELT (binfos
, j
)),
544 BINFO_OFFSET (base_binfo
));
549 if (BINFO_OFFSET_ZEROP (base_binfo
))
550 BINFO_OFFSET (base_binfo
) = offset
;
552 BINFO_OFFSET (base_binfo
)
553 = size_binop (PLUS_EXPR
, BINFO_OFFSET (base_binfo
), offset
);
555 BINFO_OFFSET (base_binfo
) = offset
;
560 tree chain
= NULL_TREE
;
562 /* Now unshare the structure beneath BASE_BINFO. */
563 for (k
= TREE_VEC_LENGTH (base_binfos
)-1;
566 tree base_base_binfo
= TREE_VEC_ELT (base_binfos
, k
);
567 if (! TREE_VIA_VIRTUAL (base_base_binfo
))
568 TREE_VEC_ELT (base_binfos
, k
)
569 = make_binfo (BINFO_OFFSET (base_base_binfo
),
571 BINFO_VTABLE (base_base_binfo
),
572 BINFO_VIRTUALS (base_base_binfo
),
574 chain
= TREE_VEC_ELT (base_binfos
, k
);
575 TREE_VIA_PUBLIC (chain
) = TREE_VIA_PUBLIC (base_base_binfo
);
576 TREE_VIA_PROTECTED (chain
) = TREE_VIA_PROTECTED (base_base_binfo
);
577 BINFO_INHERITANCE_CHAIN (chain
) = base_binfo
;
579 /* Now propagate the offset to the base types. */
580 propagate_binfo_offsets (base_binfo
, offset
);
583 /* Go to our next class that counts for offset propagation. */
586 offset
= size_binop (PLUS_EXPR
, offset
, delta
);
591 /* Compute the actual offsets that our virtual base classes
592 will have *for this type*. This must be performed after
593 the fields are laid out, since virtual baseclasses must
594 lay down at the end of the record.
596 Returns the maximum number of virtual functions any of the virtual
597 baseclasses provide. */
599 layout_vbasetypes (rec
, max
)
603 /* Get all the virtual base types that this type uses.
604 The TREE_VALUE slot holds the virtual baseclass type. */
605 tree vbase_types
= get_vbase_types (rec
);
607 #ifdef STRUCTURE_SIZE_BOUNDARY
608 unsigned record_align
= MAX (STRUCTURE_SIZE_BOUNDARY
, TYPE_ALIGN (rec
));
610 unsigned record_align
= MAX (BITS_PER_UNIT
, TYPE_ALIGN (rec
));
614 /* Record size so far is CONST_SIZE + VAR_SIZE bits,
615 where CONST_SIZE is an integer
616 and VAR_SIZE is a tree expression.
617 If VAR_SIZE is null, the size is just CONST_SIZE.
618 Naturally we try to avoid using VAR_SIZE. */
619 register unsigned const_size
= 0;
620 register tree var_size
= 0;
621 int nonvirtual_const_size
;
622 tree nonvirtual_var_size
;
624 CLASSTYPE_VBASECLASSES (rec
) = vbase_types
;
626 if (TREE_CODE (TYPE_SIZE (rec
)) == INTEGER_CST
)
627 const_size
= TREE_INT_CST_LOW (TYPE_SIZE (rec
));
629 var_size
= TYPE_SIZE (rec
);
631 nonvirtual_const_size
= const_size
;
632 nonvirtual_var_size
= var_size
;
636 tree basetype
= BINFO_TYPE (vbase_types
);
639 desired_align
= TYPE_ALIGN (basetype
);
640 record_align
= MAX (record_align
, desired_align
);
643 offset
= integer_zero_node
;
646 /* Give each virtual base type the alignment it wants. */
647 const_size
= CEIL (const_size
, TYPE_ALIGN (basetype
))
648 * TYPE_ALIGN (basetype
);
649 offset
= size_int (CEIL (const_size
, BITS_PER_UNIT
));
652 if (CLASSTYPE_VSIZE (basetype
) > max
)
653 max
= CLASSTYPE_VSIZE (basetype
);
654 BINFO_OFFSET (vbase_types
) = offset
;
656 if (TREE_CODE (TYPE_SIZE (basetype
)) == INTEGER_CST
)
658 /* Every virtual baseclass takes a least a UNIT, so that we can
659 take it's address and get something different for each base. */
660 const_size
+= MAX (BITS_PER_UNIT
,
661 TREE_INT_CST_LOW (TYPE_SIZE (basetype
))
662 - TREE_INT_CST_LOW (CLASSTYPE_VBASE_SIZE (basetype
)));
664 else if (var_size
== 0)
665 var_size
= TYPE_SIZE (basetype
);
667 var_size
= size_binop (PLUS_EXPR
, var_size
, TYPE_SIZE (basetype
));
669 vbase_types
= TREE_CHAIN (vbase_types
);
674 /* Because a virtual base might take a single byte above,
675 we have to re-adjust the total size to make sure it it
676 a multiple of the alignment. */
677 /* Give the whole object the alignment it wants. */
678 const_size
= CEIL (const_size
, record_align
) * record_align
;
681 /* Set the alignment in the complete type. We don't set CLASSTYPE_ALIGN
682 here, as that is for this class, without any virtual base classes. */
683 TYPE_ALIGN (rec
) = record_align
;
684 if (const_size
!= nonvirtual_const_size
)
686 CLASSTYPE_VBASE_SIZE (rec
)
687 = size_int (const_size
- nonvirtual_const_size
);
688 TYPE_SIZE (rec
) = size_int (const_size
);
691 /* Now propagate offset information throughout the lattice
692 under the vbase type. */
693 for (vbase_types
= CLASSTYPE_VBASECLASSES (rec
); vbase_types
;
694 vbase_types
= TREE_CHAIN (vbase_types
))
696 tree base_binfos
= BINFO_BASETYPES (vbase_types
);
698 BINFO_INHERITANCE_CHAIN (vbase_types
) = TYPE_BINFO (rec
);
702 tree chain
= NULL_TREE
;
704 /* Now unshare the structure beneath BASE_BINFO. */
706 for (j
= TREE_VEC_LENGTH (base_binfos
)-1;
709 tree base_base_binfo
= TREE_VEC_ELT (base_binfos
, j
);
710 if (! TREE_VIA_VIRTUAL (base_base_binfo
))
711 TREE_VEC_ELT (base_binfos
, j
)
712 = make_binfo (BINFO_OFFSET (base_base_binfo
),
714 BINFO_VTABLE (base_base_binfo
),
715 BINFO_VIRTUALS (base_base_binfo
),
717 chain
= TREE_VEC_ELT (base_binfos
, j
);
718 TREE_VIA_PUBLIC (chain
) = TREE_VIA_PUBLIC (base_base_binfo
);
719 TREE_VIA_PROTECTED (chain
) = TREE_VIA_PROTECTED (base_base_binfo
);
720 BINFO_INHERITANCE_CHAIN (chain
) = vbase_types
;
723 propagate_binfo_offsets (vbase_types
, BINFO_OFFSET (vbase_types
));
730 /* Lay out the base types of a record type, REC.
731 Tentatively set the size and alignment of REC
732 according to the base types alone.
734 Offsets for immediate nonvirtual baseclasses are also computed here.
736 TYPE_BINFO (REC) should be NULL_TREE on entry, and this routine
737 creates a list of base_binfos in TYPE_BINFO (REC) from BINFOS.
739 Returns list of virtual base classes in a FIELD_DECL chain. */
741 layout_basetypes (rec
, binfos
)
744 /* Chain to hold all the new FIELD_DECLs which point at virtual
746 tree vbase_decls
= NULL_TREE
;
748 #ifdef STRUCTURE_SIZE_BOUNDARY
749 unsigned record_align
= MAX (STRUCTURE_SIZE_BOUNDARY
, TYPE_ALIGN (rec
));
751 unsigned record_align
= MAX (BITS_PER_UNIT
, TYPE_ALIGN (rec
));
754 /* Record size so far is CONST_SIZE + VAR_SIZE bits, where CONST_SIZE is
755 an integer and VAR_SIZE is a tree expression. If VAR_SIZE is null,
756 the size is just CONST_SIZE. Naturally we try to avoid using
757 VAR_SIZE. And so far, we've been sucessful. */
759 register tree var_size
= 0;
762 register unsigned const_size
= 0;
763 int i
, n_baseclasses
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
765 /* Handle basetypes almost like fields, but record their
766 offsets differently. */
768 for (i
= 0; i
< n_baseclasses
; i
++)
770 int inc
, desired_align
, int_vbase_size
;
771 register tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
772 register tree basetype
= BINFO_TYPE (base_binfo
);
775 if (TYPE_SIZE (basetype
) == 0)
778 /* This error is now reported in xref_tag, thus giving better
779 location information. */
780 error_with_aggr_type (base_binfo
,
781 "base class `%s' has incomplete type");
783 TREE_VIA_PUBLIC (base_binfo
) = 1;
784 TREE_VIA_PROTECTED (base_binfo
) = 0;
785 TREE_VIA_VIRTUAL (base_binfo
) = 0;
787 /* Should handle this better so that
790 class B: private A { virtual void F(); };
792 does not dump core when compiled. */
793 my_friendly_abort (121);
798 /* All basetypes are recorded in the association list of the
801 if (TREE_VIA_VIRTUAL (base_binfo
))
804 char *name
= (char *)alloca (TYPE_NAME_LENGTH (basetype
)
805 + sizeof (VBASE_NAME
) + 1);
807 /* The offset for a virtual base class is only used in computing
808 virtual function tables and for initializing virtual base
809 pointers. It is built once `get_vbase_types' is called. */
811 /* If this basetype can come from another vbase pointer
812 without an additional indirection, we will share
813 that pointer. If an indirection is involved, we
814 make our own pointer. */
815 for (j
= 0; j
< n_baseclasses
; j
++)
817 tree other_base_binfo
= TREE_VEC_ELT (binfos
, j
);
818 if (! TREE_VIA_VIRTUAL (other_base_binfo
)
819 && binfo_member (basetype
,
820 CLASSTYPE_VBASECLASSES (BINFO_TYPE (other_base_binfo
))))
823 sprintf (name
, VBASE_NAME_FORMAT
, TYPE_NAME_STRING (basetype
));
824 decl
= build_lang_decl (FIELD_DECL
, get_identifier (name
),
825 build_pointer_type (basetype
));
826 /* If you change any of the below, take a look at all the
827 other VFIELD_BASEs and VTABLE_BASEs in the code, and change
829 DECL_ASSEMBLER_NAME (decl
) = get_identifier (VTABLE_BASE
);
830 DECL_VIRTUAL_P (decl
) = 1;
831 DECL_FIELD_CONTEXT (decl
) = rec
;
832 DECL_CLASS_CONTEXT (decl
) = rec
;
833 DECL_FCONTEXT (decl
) = basetype
;
834 DECL_SAVED_INSNS (decl
) = NULL_RTX
;
835 DECL_FIELD_SIZE (decl
) = 0;
836 DECL_ALIGN (decl
) = TYPE_ALIGN (ptr_type_node
);
837 TREE_CHAIN (decl
) = vbase_decls
;
838 BINFO_VPTR_FIELD (base_binfo
) = decl
;
841 if (warn_nonvdtor
&& TYPE_HAS_DESTRUCTOR (basetype
)
842 && DECL_VINDEX (TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (basetype
), 0)) == NULL_TREE
)
844 warning_with_decl (TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (basetype
), 0),
845 "destructor `%s' non-virtual");
846 warning ("in inheritance relationship `%s: virtual %s'",
847 TYPE_NAME_STRING (rec
),
848 TYPE_NAME_STRING (basetype
));
851 /* The space this decl occupies has already been accounted for. */
856 offset
= integer_zero_node
;
859 /* Give each base type the alignment it wants. */
860 const_size
= CEIL (const_size
, TYPE_ALIGN (basetype
))
861 * TYPE_ALIGN (basetype
);
862 offset
= size_int ((const_size
+ BITS_PER_UNIT
- 1) / BITS_PER_UNIT
);
865 /* bpk: Disabled this check until someone is willing to
866 claim it as theirs and explain exactly what circumstances
867 warrant the warning. */
868 if (warn_nonvdtor
&& TYPE_HAS_DESTRUCTOR (basetype
)
869 && DECL_VINDEX (TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (basetype
), 0)) == NULL_TREE
)
871 warning_with_decl (TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (basetype
), 0),
872 "destructor `%s' non-virtual");
873 warning ("in inheritance relationship `%s:%s %s'",
874 TYPE_NAME_STRING (rec
),
875 TREE_VIA_VIRTUAL (base_binfo
) ? " virtual" : "",
876 TYPE_NAME_STRING (basetype
));
880 BINFO_OFFSET (base_binfo
) = offset
;
881 if (CLASSTYPE_VSIZE (basetype
))
883 BINFO_VTABLE (base_binfo
) = TYPE_BINFO_VTABLE (basetype
);
884 BINFO_VIRTUALS (base_binfo
) = TYPE_BINFO_VIRTUALS (basetype
);
886 TREE_CHAIN (base_binfo
) = TYPE_BINFO (rec
);
887 TYPE_BINFO (rec
) = base_binfo
;
889 /* Add only the amount of storage not present in
890 the virtual baseclasses. */
892 int_vbase_size
= TREE_INT_CST_LOW (CLASSTYPE_VBASE_SIZE (basetype
));
893 if (TREE_INT_CST_LOW (TYPE_SIZE (basetype
)) > int_vbase_size
)
895 inc
= MAX (record_align
,
896 (TREE_INT_CST_LOW (TYPE_SIZE (basetype
))
899 /* Record must have at least as much alignment as any field. */
900 desired_align
= TYPE_ALIGN (basetype
);
901 record_align
= MAX (record_align
, desired_align
);
908 CLASSTYPE_SIZE (rec
) = size_int (const_size
);
910 CLASSTYPE_SIZE (rec
) = integer_zero_node
;
911 CLASSTYPE_ALIGN (rec
) = record_align
;
916 /* Hashing of lists so that we don't make duplicates.
917 The entry point is `list_hash_canon'. */
919 /* Each hash table slot is a bucket containing a chain
920 of these structures. */
924 struct list_hash
*next
; /* Next structure in the bucket. */
925 int hashcode
; /* Hash code of this list. */
926 tree list
; /* The list recorded here. */
929 /* Now here is the hash table. When recording a list, it is added
930 to the slot whose index is the hash code mod the table size.
931 Note that the hash table is used for several kinds of lists.
932 While all these live in the same table, they are completely independent,
933 and the hash code is computed differently for each of these. */
935 #define TYPE_HASH_SIZE 59
936 struct list_hash
*list_hash_table
[TYPE_HASH_SIZE
];
938 /* Compute a hash code for a list (chain of TREE_LIST nodes
939 with goodies in the TREE_PURPOSE, TREE_VALUE, and bits of the
940 TREE_COMMON slots), by adding the hash codes of the individual entries. */
946 register int hashcode
= 0;
948 if (TREE_CHAIN (list
))
949 hashcode
+= TYPE_HASH (TREE_CHAIN (list
));
951 if (TREE_VALUE (list
))
952 hashcode
+= TYPE_HASH (TREE_VALUE (list
));
955 if (TREE_PURPOSE (list
))
956 hashcode
+= TYPE_HASH (TREE_PURPOSE (list
));
962 /* Look in the type hash table for a type isomorphic to TYPE.
963 If one is found, return it. Otherwise return 0. */
966 list_hash_lookup (hashcode
, list
)
970 register struct list_hash
*h
;
971 for (h
= list_hash_table
[hashcode
% TYPE_HASH_SIZE
]; h
; h
= h
->next
)
972 if (h
->hashcode
== hashcode
973 && TREE_VIA_VIRTUAL (h
->list
) == TREE_VIA_VIRTUAL (list
)
974 && TREE_VIA_PUBLIC (h
->list
) == TREE_VIA_PUBLIC (list
)
975 && TREE_VIA_PROTECTED (h
->list
) == TREE_VIA_PROTECTED (list
)
976 && TREE_PURPOSE (h
->list
) == TREE_PURPOSE (list
)
977 && TREE_VALUE (h
->list
) == TREE_VALUE (list
)
978 && TREE_CHAIN (h
->list
) == TREE_CHAIN (list
))
980 my_friendly_assert (TREE_TYPE (h
->list
) == TREE_TYPE (list
), 299);
986 /* Add an entry to the list-hash-table
987 for a list TYPE whose hash code is HASHCODE. */
990 list_hash_add (hashcode
, list
)
994 register struct list_hash
*h
;
996 h
= (struct list_hash
*) obstack_alloc (&class_obstack
, sizeof (struct list_hash
));
997 h
->hashcode
= hashcode
;
999 h
->next
= list_hash_table
[hashcode
% TYPE_HASH_SIZE
];
1000 list_hash_table
[hashcode
% TYPE_HASH_SIZE
] = h
;
1003 /* Given TYPE, and HASHCODE its hash code, return the canonical
1004 object for an identical list if one already exists.
1005 Otherwise, return TYPE, and record it as the canonical object
1006 if it is a permanent object.
1008 To use this function, first create a list of the sort you want.
1009 Then compute its hash code from the fields of the list that
1010 make it different from other similar lists.
1011 Then call this function and use the value.
1012 This function frees the list you pass in if it is a duplicate. */
1014 /* Set to 1 to debug without canonicalization. Never set by program. */
1015 static int debug_no_list_hash
= 0;
1018 list_hash_canon (hashcode
, list
)
1024 if (debug_no_list_hash
)
1027 t1
= list_hash_lookup (hashcode
, list
);
1030 obstack_free (&class_obstack
, list
);
1034 /* If this is a new list, record it for later reuse. */
1035 list_hash_add (hashcode
, list
);
1041 hash_tree_cons (via_public
, via_virtual
, via_protected
, purpose
, value
, chain
)
1042 int via_public
, via_virtual
, via_protected
;
1043 tree purpose
, value
, chain
;
1045 struct obstack
*ambient_obstack
= current_obstack
;
1049 current_obstack
= &class_obstack
;
1050 t
= tree_cons (purpose
, value
, chain
);
1051 TREE_VIA_PUBLIC (t
) = via_public
;
1052 TREE_VIA_PROTECTED (t
) = via_protected
;
1053 TREE_VIA_VIRTUAL (t
) = via_virtual
;
1054 hashcode
= list_hash (t
);
1055 t
= list_hash_canon (hashcode
, t
);
1056 current_obstack
= ambient_obstack
;
1060 /* Constructor for hashed lists. */
1062 hash_tree_chain (value
, chain
)
1065 struct obstack
*ambient_obstack
= current_obstack
;
1069 current_obstack
= &class_obstack
;
1070 t
= tree_cons (NULL_TREE
, value
, chain
);
1071 hashcode
= list_hash (t
);
1072 t
= list_hash_canon (hashcode
, t
);
1073 current_obstack
= ambient_obstack
;
1077 /* Similar, but used for concatenating two lists. */
1079 hash_chainon (list1
, list2
)
1086 if (TREE_CHAIN (list1
) == NULL_TREE
)
1087 return hash_tree_chain (TREE_VALUE (list1
), list2
);
1088 return hash_tree_chain (TREE_VALUE (list1
),
1089 hash_chainon (TREE_CHAIN (list1
), list2
));
1093 get_identifier_list (value
)
1096 tree list
= IDENTIFIER_AS_LIST (value
);
1097 if (list
!= NULL_TREE
1098 && (TREE_CODE (list
) != TREE_LIST
1099 || TREE_VALUE (list
) != value
))
1101 else if (IDENTIFIER_HAS_TYPE_VALUE (value
)
1102 && TREE_CODE (IDENTIFIER_TYPE_VALUE (value
)) == RECORD_TYPE
1103 && IDENTIFIER_TYPE_VALUE (value
)
1104 == TYPE_MAIN_VARIANT (IDENTIFIER_TYPE_VALUE (value
)))
1106 tree type
= IDENTIFIER_TYPE_VALUE (value
);
1108 if (TYPE_PTRMEMFUNC_P (type
))
1110 else if (type
== current_class_type
)
1111 /* Don't mess up the constructor name. */
1112 list
= tree_cons (NULL_TREE
, value
, NULL_TREE
);
1116 /* This will return the correct thing for regular types,
1117 nested types, and templates. Yay! */
1118 if (TYPE_NESTED_NAME (type
))
1119 id
= TYPE_NESTED_NAME (type
);
1121 id
= TYPE_IDENTIFIER (type
);
1123 if (CLASSTYPE_ID_AS_LIST (type
) == NULL_TREE
)
1124 CLASSTYPE_ID_AS_LIST (type
)
1125 = perm_tree_cons (NULL_TREE
, id
, NULL_TREE
);
1126 list
= CLASSTYPE_ID_AS_LIST (type
);
1133 get_decl_list (value
)
1136 tree list
= NULL_TREE
;
1138 if (TREE_CODE (value
) == IDENTIFIER_NODE
)
1139 list
= get_identifier_list (value
);
1140 else if (TREE_CODE (value
) == RECORD_TYPE
1141 && TYPE_LANG_SPECIFIC (value
))
1142 list
= CLASSTYPE_AS_LIST (value
);
1144 if (list
!= NULL_TREE
)
1146 my_friendly_assert (TREE_CHAIN (list
) == NULL_TREE
, 301);
1150 return build_decl_list (NULL_TREE
, value
);
1153 /* Look in the type hash table for a type isomorphic to
1154 `build_tree_list (NULL_TREE, VALUE)'.
1155 If one is found, return it. Otherwise return 0. */
1158 list_hash_lookup_or_cons (value
)
1161 register int hashcode
= TYPE_HASH (value
);
1162 register struct list_hash
*h
;
1163 struct obstack
*ambient_obstack
;
1164 tree list
= NULL_TREE
;
1166 if (TREE_CODE (value
) == IDENTIFIER_NODE
)
1167 list
= get_identifier_list (value
);
1168 else if (TREE_CODE (value
) == TYPE_DECL
1169 && TREE_CODE (TREE_TYPE (value
)) == RECORD_TYPE
1170 && TYPE_LANG_SPECIFIC (TREE_TYPE (value
)))
1171 list
= CLASSTYPE_ID_AS_LIST (TREE_TYPE (value
));
1172 else if (TREE_CODE (value
) == RECORD_TYPE
1173 && TYPE_LANG_SPECIFIC (value
))
1174 list
= CLASSTYPE_AS_LIST (value
);
1176 if (list
!= NULL_TREE
)
1178 my_friendly_assert (TREE_CHAIN (list
) == NULL_TREE
, 302);
1182 if (debug_no_list_hash
)
1183 return hash_tree_chain (value
, NULL_TREE
);
1185 for (h
= list_hash_table
[hashcode
% TYPE_HASH_SIZE
]; h
; h
= h
->next
)
1186 if (h
->hashcode
== hashcode
1187 && TREE_VIA_VIRTUAL (h
->list
) == 0
1188 && TREE_VIA_PUBLIC (h
->list
) == 0
1189 && TREE_VIA_PROTECTED (h
->list
) == 0
1190 && TREE_PURPOSE (h
->list
) == 0
1191 && TREE_VALUE (h
->list
) == value
)
1193 my_friendly_assert (TREE_TYPE (h
->list
) == 0, 303);
1194 my_friendly_assert (TREE_CHAIN (h
->list
) == 0, 304);
1198 ambient_obstack
= current_obstack
;
1199 current_obstack
= &class_obstack
;
1200 list
= build_tree_list (NULL_TREE
, value
);
1201 list_hash_add (hashcode
, list
);
1202 current_obstack
= ambient_obstack
;
1206 /* Build an association between TYPE and some parameters:
1208 OFFSET is the offset added to `this' to convert it to a pointer
1211 BINFO is the base binfo to use, if we are deriving from one. This
1212 is necessary, as we want specialized parent binfos from base
1213 classes, so that the VTABLE_NAMEs of bases are for the most derived
1214 type, instead of of the simple type.
1216 VTABLE is the virtual function table with which to initialize
1217 sub-objects of type TYPE.
1219 VIRTUALS are the virtual functions sitting in VTABLE.
1221 CHAIN are more associations we must retain. */
1224 make_binfo (offset
, binfo
, vtable
, virtuals
, chain
)
1226 tree vtable
, virtuals
;
1229 tree new_binfo
= make_tree_vec (6);
1232 if (TREE_CODE (binfo
) == TREE_VEC
)
1233 type
= BINFO_TYPE (binfo
);
1237 binfo
= TYPE_BINFO (binfo
);
1240 TREE_CHAIN (new_binfo
) = chain
;
1242 TREE_USED (new_binfo
) = TREE_USED (chain
);
1244 TREE_TYPE (new_binfo
) = TYPE_MAIN_VARIANT (type
);
1245 BINFO_OFFSET (new_binfo
) = offset
;
1246 BINFO_VTABLE (new_binfo
) = vtable
;
1247 BINFO_VIRTUALS (new_binfo
) = virtuals
;
1248 BINFO_VPTR_FIELD (new_binfo
) = NULL_TREE
;
1250 if (binfo
&& BINFO_BASETYPES (binfo
) != NULL_TREE
)
1251 BINFO_BASETYPES (new_binfo
) = copy_node (BINFO_BASETYPES (binfo
));
1255 /* Return the binfo value for ELEM in TYPE. */
1258 binfo_value (elem
, type
)
1262 if (get_base_distance (elem
, type
, 0, (tree
*)0) == -2)
1263 compiler_error ("base class `%s' ambiguous in binfo_value",
1264 TYPE_NAME_STRING (elem
));
1266 return TYPE_BINFO (type
);
1267 if (TREE_CODE (elem
) == RECORD_TYPE
&& TYPE_BINFO (elem
) == type
)
1269 return get_binfo (elem
, type
, 0);
1276 register tree prev
= 0, tmp
, next
;
1277 for (tmp
= path
; tmp
; tmp
= next
)
1279 next
= BINFO_INHERITANCE_CHAIN (tmp
);
1280 BINFO_INHERITANCE_CHAIN (tmp
) = prev
;
1287 virtual_member (elem
, list
)
1294 for (t
= list
; t
; t
= TREE_CHAIN (t
))
1295 if (elem
== BINFO_TYPE (t
))
1298 for (t
= list
; t
; t
= TREE_CHAIN (t
))
1300 tree binfos
= BINFO_BASETYPES (t
);
1303 if (binfos
!= NULL_TREE
)
1304 for (i
= TREE_VEC_LENGTH (binfos
)-1; i
>= 0; i
--)
1306 nval
= binfo_value (elem
, BINFO_TYPE (TREE_VEC_ELT (binfos
, i
)));
1309 if (rval
&& BINFO_OFFSET (nval
) != BINFO_OFFSET (rval
))
1310 my_friendly_abort (104);
1325 fprintf (stderr
, "type \"%s\"; offset = %d\n",
1326 TYPE_NAME_STRING (BINFO_TYPE (elem
)),
1327 TREE_INT_CST_LOW (BINFO_OFFSET (elem
)));
1328 fprintf (stderr
, "vtable type:\n");
1329 debug_tree (BINFO_TYPE (elem
));
1330 if (BINFO_VTABLE (elem
))
1331 fprintf (stderr
, "vtable decl \"%s\"\n", IDENTIFIER_POINTER (DECL_NAME (BINFO_VTABLE (elem
))));
1333 fprintf (stderr
, "no vtable decl yet\n");
1334 fprintf (stderr
, "virtuals:\n");
1335 virtuals
= BINFO_VIRTUALS (elem
);
1338 /* skip the rtti type descriptor entry */
1339 virtuals
= TREE_CHAIN (virtuals
);
1344 tree fndecl
= TREE_OPERAND (FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (virtuals
)), 0);
1345 fprintf (stderr
, "%s [%d =? %d]\n",
1346 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (fndecl
)),
1347 i
, TREE_INT_CST_LOW (DECL_VINDEX (fndecl
)));
1348 virtuals
= TREE_CHAIN (virtuals
);
1353 /* Return the length of a chain of nodes chained through DECL_CHAIN.
1354 We expect a null pointer to mark the end of the chain.
1355 This is the Lisp primitive `length'. */
1358 decl_list_length (t
)
1362 register int len
= 0;
1364 my_friendly_assert (TREE_CODE (t
) == FUNCTION_DECL
1365 || TREE_CODE (t
) == TEMPLATE_DECL
, 300);
1366 for (tail
= t
; tail
; tail
= DECL_CHAIN (tail
))
1376 if (TREE_CODE (t
) == FUNCTION_DECL
)
1378 else if (TREE_CODE (t
) == TREE_LIST
)
1379 return decl_list_length (TREE_VALUE (t
));
1381 my_friendly_abort (359);
1385 /* Like value_member, but for DECL_CHAINs. */
1387 decl_value_member (elem
, list
)
1394 list
= DECL_CHAIN (list
);
1400 is_overloaded_fn (x
)
1403 if (TREE_CODE (x
) == FUNCTION_DECL
)
1406 if (TREE_CODE (x
) == TREE_LIST
1407 && (TREE_CODE (TREE_VALUE (x
)) == FUNCTION_DECL
1408 || TREE_CODE (TREE_VALUE (x
)) == TEMPLATE_DECL
))
1415 really_overloaded_fn (x
)
1418 if (TREE_CODE (x
) == TREE_LIST
1419 && (TREE_CODE (TREE_VALUE (x
)) == FUNCTION_DECL
1420 || TREE_CODE (TREE_VALUE (x
)) == TEMPLATE_DECL
))
1430 if (TREE_CODE (from
) == FUNCTION_DECL
)
1433 my_friendly_assert (TREE_CODE (from
) == TREE_LIST
, 9);
1435 return TREE_VALUE (from
);
1439 fnaddr_from_vtable_entry (entry
)
1442 if (flag_vtable_thunks
)
1445 if (TREE_CODE (func
) == ADDR_EXPR
)
1446 func
= TREE_OPERAND (func
, 0);
1447 if (TREE_CODE (func
) == THUNK_DECL
)
1448 return DECL_INITIAL (func
);
1453 return TREE_VALUE (TREE_CHAIN (TREE_CHAIN (CONSTRUCTOR_ELTS (entry
))));
1457 set_fnaddr_from_vtable_entry (entry
, value
)
1460 if (flag_vtable_thunks
)
1463 TREE_VALUE (TREE_CHAIN (TREE_CHAIN (CONSTRUCTOR_ELTS (entry
)))) = value
;
1467 function_arg_chain (t
)
1470 return TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (t
)));
1474 promotes_to_aggr_type (t
, code
)
1476 enum tree_code code
;
1478 if (TREE_CODE (t
) == code
)
1480 return IS_AGGR_TYPE (t
);
1484 is_aggr_type_2 (t1
, t2
)
1487 if (TREE_CODE (t1
) != TREE_CODE (t2
))
1489 return IS_AGGR_TYPE (t1
) && IS_AGGR_TYPE (t2
);
1492 /* Give message using types TYPE1 and TYPE2 as arguments.
1493 PFN is the function which will print the message;
1494 S is the format string for PFN to use. */
1496 message_2_types (pfn
, s
, type1
, type2
)
1501 tree name1
= TYPE_NAME (type1
);
1502 tree name2
= TYPE_NAME (type2
);
1503 if (TREE_CODE (name1
) == TYPE_DECL
)
1504 name1
= DECL_NAME (name1
);
1505 if (TREE_CODE (name2
) == TYPE_DECL
)
1506 name2
= DECL_NAME (name2
);
1507 (*pfn
) (s
, IDENTIFIER_POINTER (name1
), IDENTIFIER_POINTER (name2
));
1510 #define PRINT_RING_SIZE 4
1513 lang_printable_name (decl
)
1516 static tree decl_ring
[PRINT_RING_SIZE
];
1517 static char *print_ring
[PRINT_RING_SIZE
];
1518 static int ring_counter
;
1521 /* Only cache functions. */
1522 if (TREE_CODE (decl
) != FUNCTION_DECL
1523 || DECL_LANG_SPECIFIC (decl
) == 0)
1524 return decl_as_string (decl
, 1);
1526 /* See if this print name is lying around. */
1527 for (i
= 0; i
< PRINT_RING_SIZE
; i
++)
1528 if (decl_ring
[i
] == decl
)
1529 /* yes, so return it. */
1530 return print_ring
[i
];
1532 if (++ring_counter
== PRINT_RING_SIZE
)
1535 if (current_function_decl
!= NULL_TREE
)
1537 if (decl_ring
[ring_counter
] == current_function_decl
)
1539 if (ring_counter
== PRINT_RING_SIZE
)
1541 if (decl_ring
[ring_counter
] == current_function_decl
)
1542 my_friendly_abort (106);
1545 if (print_ring
[ring_counter
])
1546 free (print_ring
[ring_counter
]);
1549 int print_ret_type_p
1550 = (!DECL_CONSTRUCTOR_P (decl
)
1551 && !DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (decl
)));
1553 char *name
= (char *)decl_as_string (decl
, print_ret_type_p
);
1554 print_ring
[ring_counter
] = (char *)malloc (strlen (name
) + 1);
1555 strcpy (print_ring
[ring_counter
], name
);
1556 decl_ring
[ring_counter
] = decl
;
1558 return print_ring
[ring_counter
];
1561 /* Comparison function for sorting identifiers in RAISES lists.
1562 Note that because IDENTIFIER_NODEs are unique, we can sort
1563 them by address, saving an indirection. */
1568 return (HOST_WIDE_INT
)TREE_VALUE (*p1
) - (HOST_WIDE_INT
)TREE_VALUE (*p2
);
1571 /* Build the FUNCTION_TYPE or METHOD_TYPE which may raise exceptions
1572 listed in RAISES. */
1574 build_exception_variant (ctype
, type
, raises
)
1579 tree v
= TYPE_MAIN_VARIANT (type
);
1581 tree
*a
= (tree
*)alloca ((list_length (raises
)+1) * sizeof (tree
));
1582 int constp
= TYPE_READONLY (type
);
1583 int volatilep
= TYPE_VOLATILE (type
);
1585 for (v
= TYPE_NEXT_VARIANT (v
); v
; v
= TYPE_NEXT_VARIANT (v
))
1587 if (TYPE_READONLY (v
) != constp
1588 || TYPE_VOLATILE (v
) != volatilep
)
1591 /* @@ This should do set equality, not exact match. */
1592 if (simple_cst_list_equal (TYPE_RAISES_EXCEPTIONS (v
), raises
))
1593 /* List of exceptions raised matches previously found list.
1595 @@ Nice to free up storage used in consing up the
1596 @@ list of exceptions raised. */
1600 /* Need to build a new variant. */
1601 v
= copy_node (type
);
1602 TYPE_NEXT_VARIANT (v
) = TYPE_NEXT_VARIANT (type
);
1603 TYPE_NEXT_VARIANT (type
) = v
;
1604 if (raises
&& ! TREE_PERMANENT (raises
))
1606 push_obstacks_nochange ();
1607 end_temporary_allocation ();
1608 raises
= copy_list (raises
);
1611 TYPE_RAISES_EXCEPTIONS (v
) = raises
;
1615 /* Subroutine of copy_to_permanent
1617 Assuming T is a node build bottom-up, make it all exist on
1618 permanent obstack, if it is not permanent already. */
1623 enum tree_code code
;
1625 if (t
== NULL_TREE
|| TREE_PERMANENT (t
))
1628 switch (code
= TREE_CODE (t
))
1631 return error_mark_node
;
1640 tree chain
= TREE_CHAIN (t
);
1642 TREE_CHAIN (t
) = make_deep_copy (chain
);
1643 TREE_TYPE (t
) = make_deep_copy (TREE_TYPE (t
));
1644 DECL_INITIAL (t
) = make_deep_copy (DECL_INITIAL (t
));
1645 DECL_SIZE (t
) = make_deep_copy (DECL_SIZE (t
));
1651 tree chain
= TREE_CHAIN (t
);
1653 TREE_PURPOSE (t
) = make_deep_copy (TREE_PURPOSE (t
));
1654 TREE_VALUE (t
) = make_deep_copy (TREE_VALUE (t
));
1655 TREE_CHAIN (t
) = make_deep_copy (chain
);
1661 int len
= TREE_VEC_LENGTH (t
);
1665 TREE_VEC_ELT (t
, len
) = make_deep_copy (TREE_VEC_ELT (t
, len
));
1672 return copy_node (t
);
1678 TREE_OPERAND (t
, 0) = make_deep_copy (TREE_OPERAND (t
, 0));
1679 TREE_OPERAND (t
, 1) = make_deep_copy (TREE_OPERAND (t
, 1));
1680 TREE_OPERAND (t
, 2) = make_deep_copy (TREE_OPERAND (t
, 2));
1685 TREE_OPERAND (t
, 0) = make_deep_copy (TREE_OPERAND (t
, 0));
1692 case TRUNC_DIV_EXPR
:
1693 case TRUNC_MOD_EXPR
:
1701 case BIT_ANDTC_EXPR
:
1702 case TRUTH_ANDIF_EXPR
:
1703 case TRUTH_ORIF_EXPR
:
1711 case FLOOR_DIV_EXPR
:
1712 case ROUND_DIV_EXPR
:
1714 case FLOOR_MOD_EXPR
:
1715 case ROUND_MOD_EXPR
:
1717 case PREDECREMENT_EXPR
:
1718 case PREINCREMENT_EXPR
:
1719 case POSTDECREMENT_EXPR
:
1720 case POSTINCREMENT_EXPR
:
1723 TREE_OPERAND (t
, 0) = make_deep_copy (TREE_OPERAND (t
, 0));
1724 TREE_OPERAND (t
, 1) = make_deep_copy (TREE_OPERAND (t
, 1));
1732 case TRUTH_NOT_EXPR
:
1736 TREE_OPERAND (t
, 0) = make_deep_copy (TREE_OPERAND (t
, 0));
1740 return build_pointer_type (make_deep_copy (TREE_TYPE (t
)));
1741 case REFERENCE_TYPE
:
1742 return build_reference_type (make_deep_copy (TREE_TYPE (t
)));
1744 return build_function_type (make_deep_copy (TREE_TYPE (t
)),
1745 make_deep_copy (TYPE_ARG_TYPES (t
)));
1747 return build_array_type (make_deep_copy (TREE_TYPE (t
)),
1748 make_deep_copy (TYPE_DOMAIN (t
)));
1750 return build_index_type (make_deep_copy (TYPE_MAX_VALUE (t
)));
1753 return build_offset_type (make_deep_copy (TYPE_OFFSET_BASETYPE (t
)),
1754 make_deep_copy (TREE_TYPE (t
)));
1756 return build_method_type
1757 (make_deep_copy (TYPE_METHOD_BASETYPE (t
)),
1759 (make_deep_copy (TREE_TYPE (t
)),
1760 make_deep_copy (TREE_CHAIN (TYPE_ARG_TYPES (t
)))));
1763 if (TYPE_PTRMEMFUNC_P (t
))
1764 return build_ptrmemfunc_type
1765 (make_deep_copy (TYPE_PTRMEMFUNC_FN_TYPE (t
)));
1766 /* else fall through */
1768 /* This list is incomplete, but should suffice for now.
1769 It is very important that `sorry' does not call
1770 `report_error_function'. That could cause an infinite loop. */
1772 sorry ("initializer contains unrecognized tree code");
1773 return error_mark_node
;
1776 my_friendly_abort (107);
1781 /* Assuming T is a node built bottom-up, make it all exist on
1782 permanent obstack, if it is not permanent already. */
1784 copy_to_permanent (t
)
1787 register struct obstack
*ambient_obstack
= current_obstack
;
1788 register struct obstack
*ambient_saveable_obstack
= saveable_obstack
;
1791 if (t
== NULL_TREE
|| TREE_PERMANENT (t
))
1794 saveable_obstack
= &permanent_obstack
;
1795 current_obstack
= saveable_obstack
;
1796 resume
= suspend_momentary ();
1798 t
= make_deep_copy (t
);
1800 resume_momentary (resume
);
1801 current_obstack
= ambient_obstack
;
1802 saveable_obstack
= ambient_saveable_obstack
;
1808 print_lang_statistics ()
1810 extern struct obstack maybepermanent_obstack
;
1811 print_obstack_statistics ("class_obstack", &class_obstack
);
1812 print_obstack_statistics ("permanent_obstack", &permanent_obstack
);
1813 print_obstack_statistics ("maybepermanent_obstack", &maybepermanent_obstack
);
1814 print_search_statistics ();
1815 print_class_statistics ();
1818 /* This is used by the `assert' macro. It is provided in libgcc.a,
1819 which `cc' doesn't know how to link. Note that the C++ front-end
1820 no longer actually uses the `assert' macro (instead, it calls
1821 my_friendly_assert). But all of the back-end files still need this. */
1823 __eprintf (string
, expression
, line
, filename
)
1826 const char *expression
;
1828 const char *filename
;
1836 fprintf (stderr
, string
, expression
, line
, filename
);
1841 /* Return, as an INTEGER_CST node, the number of elements for
1842 TYPE (which is an ARRAY_TYPE). This counts only elements of the top array. */
1845 array_type_nelts_top (type
)
1848 return fold (build (PLUS_EXPR
, sizetype
,
1849 array_type_nelts (type
),
1853 /* Return, as an INTEGER_CST node, the number of elements for
1854 TYPE (which is an ARRAY_TYPE). This one is a recursive count of all
1855 ARRAY_TYPEs that are clumped together. */
1858 array_type_nelts_total (type
)
1861 tree sz
= array_type_nelts_top (type
);
1862 type
= TREE_TYPE (type
);
1863 while (TREE_CODE (type
) == ARRAY_TYPE
)
1865 tree n
= array_type_nelts_top (type
);
1866 sz
= fold (build (MULT_EXPR
, sizetype
, sz
, n
));
1867 type
= TREE_TYPE (type
);