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)));
115 if (! language_lvalue_valid (ref
))
118 if (TREE_CODE (TREE_TYPE (ref
)) == REFERENCE_TYPE
)
121 if (ref
== current_class_ptr
&& flag_this_is_variable
<= 0)
124 switch (TREE_CODE (ref
))
126 /* preincrements and predecrements are valid lvals, provided
127 what they refer to are valid lvals. */
128 case PREINCREMENT_EXPR
:
129 case PREDECREMENT_EXPR
:
132 return lvalue_p (TREE_OPERAND (ref
, 0));
138 if (TREE_READONLY (ref
) && ! TREE_STATIC (ref
)
139 && DECL_LANG_SPECIFIC (ref
)
140 && DECL_IN_AGGR_P (ref
))
147 if (TREE_CODE (TREE_TYPE (ref
)) != FUNCTION_TYPE
148 && TREE_CODE (TREE_TYPE (ref
)) != METHOD_TYPE
)
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. */
211 build_cplus_new (type
, init
)
218 if (TREE_CODE (init
) == TARGET_EXPR
|| init
== error_mark_node
)
221 slot
= build (VAR_DECL
, type
);
222 layout_decl (slot
, 0);
223 rval
= build (NEW_EXPR
, type
,
224 TREE_OPERAND (init
, 0), TREE_OPERAND (init
, 1), slot
);
225 TREE_SIDE_EFFECTS (rval
) = 1;
226 TREE_ADDRESSABLE (rval
) = 1;
227 rval
= build (TARGET_EXPR
, type
, slot
, rval
, NULL_TREE
, NULL_TREE
);
228 TREE_SIDE_EFFECTS (rval
) = 1;
229 TREE_ADDRESSABLE (rval
) = 1;
234 /* Recursively search EXP for CALL_EXPRs that need cleanups and replace
235 these CALL_EXPRs with tree nodes that will perform the cleanups. */
238 break_out_cleanups (exp
)
243 if (TREE_CODE (tmp
) == CALL_EXPR
244 && TYPE_NEEDS_DESTRUCTOR (TREE_TYPE (tmp
)))
245 return build_cplus_new (TREE_TYPE (tmp
), tmp
);
247 while (TREE_CODE (tmp
) == NOP_EXPR
248 || TREE_CODE (tmp
) == CONVERT_EXPR
249 || TREE_CODE (tmp
) == NON_LVALUE_EXPR
)
251 if (TREE_CODE (TREE_OPERAND (tmp
, 0)) == CALL_EXPR
252 && TYPE_NEEDS_DESTRUCTOR (TREE_TYPE (TREE_OPERAND (tmp
, 0))))
254 TREE_OPERAND (tmp
, 0)
255 = build_cplus_new (TREE_TYPE (TREE_OPERAND (tmp
, 0)),
256 TREE_OPERAND (tmp
, 0));
260 tmp
= TREE_OPERAND (tmp
, 0);
265 /* Recursively perform a preorder search EXP for CALL_EXPRs, making
266 copies where they are found. Returns a deep copy all nodes transitively
267 containing CALL_EXPRs. */
270 break_out_calls (exp
)
273 register tree t1
, t2
;
274 register enum tree_code code
;
275 register int changed
= 0;
278 if (exp
== NULL_TREE
)
281 code
= TREE_CODE (exp
);
283 if (code
== CALL_EXPR
)
284 return copy_node (exp
);
286 /* Don't try and defeat a save_expr, as it should only be done once. */
287 if (code
== SAVE_EXPR
)
290 switch (TREE_CODE_CLASS (code
))
295 case 'c': /* a constant */
296 case 't': /* a type node */
297 case 'x': /* something random, like an identifier or an ERROR_MARK. */
300 case 'd': /* A decl node */
301 #if 0 /* This is bogus. jason 9/21/94 */
303 t1
= break_out_calls (DECL_INITIAL (exp
));
304 if (t1
!= DECL_INITIAL (exp
))
306 exp
= copy_node (exp
);
307 DECL_INITIAL (exp
) = t1
;
312 case 'b': /* A block node */
314 /* Don't know how to handle these correctly yet. Must do a
315 break_out_calls on all DECL_INITIAL values for local variables,
316 and also break_out_calls on all sub-blocks and sub-statements. */
321 case 'e': /* an expression */
322 case 'r': /* a reference */
323 case 's': /* an expression with side effects */
324 for (i
= tree_code_length
[(int) code
] - 1; i
>= 0; i
--)
326 t1
= break_out_calls (TREE_OPERAND (exp
, i
));
327 if (t1
!= TREE_OPERAND (exp
, i
))
329 exp
= copy_node (exp
);
330 TREE_OPERAND (exp
, i
) = t1
;
335 case '<': /* a comparison expression */
336 case '2': /* a binary arithmetic expression */
337 t2
= break_out_calls (TREE_OPERAND (exp
, 1));
338 if (t2
!= TREE_OPERAND (exp
, 1))
340 case '1': /* a unary arithmetic expression */
341 t1
= break_out_calls (TREE_OPERAND (exp
, 0));
342 if (t1
!= TREE_OPERAND (exp
, 0))
346 if (tree_code_length
[(int) code
] == 1)
347 return build1 (code
, TREE_TYPE (exp
), t1
);
349 return build (code
, TREE_TYPE (exp
), t1
, t2
);
356 extern struct obstack
*current_obstack
;
357 extern struct obstack permanent_obstack
, class_obstack
;
358 extern struct obstack
*saveable_obstack
;
359 extern struct obstack
*expression_obstack
;
361 /* Here is how primitive or already-canonicalized types' hash
362 codes are made. MUST BE CONSISTENT WITH tree.c !!! */
363 #define TYPE_HASH(TYPE) ((HOST_WIDE_INT) (TYPE) & 0777777)
365 /* Construct, lay out and return the type of methods belonging to class
366 BASETYPE and whose arguments are described by ARGTYPES and whose values
367 are described by RETTYPE. If each type exists already, reuse it. */
370 build_cplus_method_type (basetype
, rettype
, argtypes
)
371 tree basetype
, rettype
, argtypes
;
377 /* Make a node of the sort we want. */
378 t
= make_node (METHOD_TYPE
);
380 TYPE_METHOD_BASETYPE (t
) = TYPE_MAIN_VARIANT (basetype
);
381 TREE_TYPE (t
) = rettype
;
382 if (IS_SIGNATURE (basetype
))
383 ptype
= build_signature_pointer_type (TYPE_MAIN_VARIANT (basetype
),
384 TYPE_READONLY (basetype
),
385 TYPE_VOLATILE (basetype
));
387 ptype
= build_pointer_type (basetype
);
389 /* The actual arglist for this function includes a "hidden" argument
390 which is "this". Put it into the list of argument types. */
392 argtypes
= tree_cons (NULL_TREE
, ptype
, argtypes
);
393 TYPE_ARG_TYPES (t
) = argtypes
;
394 TREE_SIDE_EFFECTS (argtypes
) = 1; /* Mark first argtype as "artificial". */
396 /* If we already have such a type, use the old one and free this one.
397 Note that it also frees up the above cons cell if found. */
398 hashcode
= TYPE_HASH (basetype
) + TYPE_HASH (rettype
) + type_hash_list (argtypes
);
399 t
= type_hash_canon (hashcode
, t
);
401 if (TYPE_SIZE (t
) == 0)
408 build_cplus_array_type_1 (elt_type
, index_type
)
412 register struct obstack
*ambient_obstack
= current_obstack
;
413 register struct obstack
*ambient_saveable_obstack
= saveable_obstack
;
416 /* We need a new one. If both ELT_TYPE and INDEX_TYPE are permanent,
417 make this permanent too. */
418 if (TREE_PERMANENT (elt_type
)
419 && (index_type
== 0 || TREE_PERMANENT (index_type
)))
421 current_obstack
= &permanent_obstack
;
422 saveable_obstack
= &permanent_obstack
;
425 if (processing_template_decl
)
427 t
= make_node (ARRAY_TYPE
);
428 TREE_TYPE (t
) = elt_type
;
429 TYPE_DOMAIN (t
) = index_type
;
432 t
= build_array_type (elt_type
, index_type
);
434 /* Push these needs up so that initialization takes place
436 TYPE_NEEDS_CONSTRUCTING (t
) = TYPE_NEEDS_CONSTRUCTING (TYPE_MAIN_VARIANT (elt_type
));
437 TYPE_NEEDS_DESTRUCTOR (t
) = TYPE_NEEDS_DESTRUCTOR (TYPE_MAIN_VARIANT (elt_type
));
438 current_obstack
= ambient_obstack
;
439 saveable_obstack
= ambient_saveable_obstack
;
444 build_cplus_array_type (elt_type
, index_type
)
449 int constp
= TYPE_READONLY (elt_type
);
450 int volatilep
= TYPE_VOLATILE (elt_type
);
451 elt_type
= TYPE_MAIN_VARIANT (elt_type
);
453 t
= build_cplus_array_type_1 (elt_type
, index_type
);
455 if (constp
|| volatilep
)
456 t
= cp_build_type_variant (t
, constp
, volatilep
);
461 /* Make a variant type in the proper way for C/C++, propagating qualifiers
462 down to the element type of an array. */
465 cp_build_type_variant (type
, constp
, volatilep
)
467 int constp
, volatilep
;
469 if (type
== error_mark_node
)
472 if (TREE_CODE (type
) == ARRAY_TYPE
)
474 tree real_main_variant
= TYPE_MAIN_VARIANT (type
);
476 push_obstacks (TYPE_OBSTACK (real_main_variant
),
477 TYPE_OBSTACK (real_main_variant
));
478 type
= build_cplus_array_type_1 (cp_build_type_variant
479 (TREE_TYPE (type
), constp
, volatilep
),
482 /* TYPE must be on same obstack as REAL_MAIN_VARIANT. If not,
483 make a copy. (TYPE might have come from the hash table and
484 REAL_MAIN_VARIANT might be in some function's obstack.) */
486 if (TYPE_OBSTACK (type
) != TYPE_OBSTACK (real_main_variant
))
488 type
= copy_node (type
);
489 TYPE_POINTER_TO (type
) = TYPE_REFERENCE_TO (type
) = 0;
492 TYPE_MAIN_VARIANT (type
) = real_main_variant
;
496 return build_type_variant (type
, constp
, volatilep
);
499 /* Add OFFSET to all base types of T.
501 OFFSET, which is a type offset, is number of bytes.
503 Note that we don't have to worry about having two paths to the
504 same base type, since this type owns its association list. */
507 propagate_binfo_offsets (binfo
, offset
)
511 tree binfos
= BINFO_BASETYPES (binfo
);
512 int i
, n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
514 for (i
= 0; i
< n_baselinks
; /* note increment is done in the loop. */)
516 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
518 if (TREE_VIA_VIRTUAL (base_binfo
))
523 tree base_binfos
= BINFO_BASETYPES (base_binfo
);
526 for (j
= i
+1; j
< n_baselinks
; j
++)
527 if (! TREE_VIA_VIRTUAL (TREE_VEC_ELT (binfos
, j
)))
529 /* The next basetype offset must take into account the space
530 between the classes, not just the size of each class. */
531 delta
= size_binop (MINUS_EXPR
,
532 BINFO_OFFSET (TREE_VEC_ELT (binfos
, j
)),
533 BINFO_OFFSET (base_binfo
));
538 if (BINFO_OFFSET_ZEROP (base_binfo
))
539 BINFO_OFFSET (base_binfo
) = offset
;
541 BINFO_OFFSET (base_binfo
)
542 = size_binop (PLUS_EXPR
, BINFO_OFFSET (base_binfo
), offset
);
544 BINFO_OFFSET (base_binfo
) = offset
;
549 tree chain
= NULL_TREE
;
551 /* Now unshare the structure beneath BASE_BINFO. */
552 for (k
= TREE_VEC_LENGTH (base_binfos
)-1;
555 tree base_base_binfo
= TREE_VEC_ELT (base_binfos
, k
);
556 if (! TREE_VIA_VIRTUAL (base_base_binfo
))
557 TREE_VEC_ELT (base_binfos
, k
)
558 = make_binfo (BINFO_OFFSET (base_base_binfo
),
560 BINFO_VTABLE (base_base_binfo
),
561 BINFO_VIRTUALS (base_base_binfo
),
563 chain
= TREE_VEC_ELT (base_binfos
, k
);
564 TREE_VIA_PUBLIC (chain
) = TREE_VIA_PUBLIC (base_base_binfo
);
565 TREE_VIA_PROTECTED (chain
) = TREE_VIA_PROTECTED (base_base_binfo
);
566 BINFO_INHERITANCE_CHAIN (chain
) = base_binfo
;
568 /* Now propagate the offset to the base types. */
569 propagate_binfo_offsets (base_binfo
, offset
);
572 /* Go to our next class that counts for offset propagation. */
575 offset
= size_binop (PLUS_EXPR
, offset
, delta
);
580 /* Compute the actual offsets that our virtual base classes
581 will have *for this type*. This must be performed after
582 the fields are laid out, since virtual baseclasses must
583 lay down at the end of the record.
585 Returns the maximum number of virtual functions any of the virtual
586 baseclasses provide. */
589 layout_vbasetypes (rec
, max
)
593 /* Get all the virtual base types that this type uses.
594 The TREE_VALUE slot holds the virtual baseclass type. */
595 tree vbase_types
= get_vbase_types (rec
);
597 #ifdef STRUCTURE_SIZE_BOUNDARY
598 unsigned record_align
= MAX (STRUCTURE_SIZE_BOUNDARY
, TYPE_ALIGN (rec
));
600 unsigned record_align
= MAX (BITS_PER_UNIT
, TYPE_ALIGN (rec
));
604 /* Record size so far is CONST_SIZE + VAR_SIZE bits,
605 where CONST_SIZE is an integer
606 and VAR_SIZE is a tree expression.
607 If VAR_SIZE is null, the size is just CONST_SIZE.
608 Naturally we try to avoid using VAR_SIZE. */
609 register unsigned const_size
= 0;
610 register tree var_size
= 0;
611 int nonvirtual_const_size
;
613 CLASSTYPE_VBASECLASSES (rec
) = vbase_types
;
615 if (TREE_CODE (TYPE_SIZE (rec
)) == INTEGER_CST
)
616 const_size
= TREE_INT_CST_LOW (TYPE_SIZE (rec
));
618 var_size
= TYPE_SIZE (rec
);
620 nonvirtual_const_size
= const_size
;
624 tree basetype
= BINFO_TYPE (vbase_types
);
627 desired_align
= TYPE_ALIGN (basetype
);
628 record_align
= MAX (record_align
, desired_align
);
631 offset
= integer_zero_node
;
634 /* Give each virtual base type the alignment it wants. */
635 const_size
= CEIL (const_size
, TYPE_ALIGN (basetype
))
636 * TYPE_ALIGN (basetype
);
637 offset
= size_int (CEIL (const_size
, BITS_PER_UNIT
));
640 if (CLASSTYPE_VSIZE (basetype
) > max
)
641 max
= CLASSTYPE_VSIZE (basetype
);
642 BINFO_OFFSET (vbase_types
) = offset
;
644 if (TREE_CODE (TYPE_SIZE (basetype
)) == INTEGER_CST
)
646 /* Every virtual baseclass takes a least a UNIT, so that we can
647 take it's address and get something different for each base. */
648 const_size
+= MAX (BITS_PER_UNIT
,
649 TREE_INT_CST_LOW (TYPE_SIZE (basetype
))
650 - TREE_INT_CST_LOW (CLASSTYPE_VBASE_SIZE (basetype
)));
652 else if (var_size
== 0)
653 var_size
= TYPE_SIZE (basetype
);
655 var_size
= size_binop (PLUS_EXPR
, var_size
, TYPE_SIZE (basetype
));
657 vbase_types
= TREE_CHAIN (vbase_types
);
662 /* Because a virtual base might take a single byte above,
663 we have to re-adjust the total size to make sure it it
664 a multiple of the alignment. */
665 /* Give the whole object the alignment it wants. */
666 const_size
= CEIL (const_size
, record_align
) * record_align
;
669 /* Set the alignment in the complete type. We don't set CLASSTYPE_ALIGN
670 here, as that is for this class, without any virtual base classes. */
671 TYPE_ALIGN (rec
) = record_align
;
672 if (const_size
!= nonvirtual_const_size
)
674 CLASSTYPE_VBASE_SIZE (rec
)
675 = size_int (const_size
- nonvirtual_const_size
);
676 TYPE_SIZE (rec
) = size_int (const_size
);
679 /* Now propagate offset information throughout the lattice
680 under the vbase type. */
681 for (vbase_types
= CLASSTYPE_VBASECLASSES (rec
); vbase_types
;
682 vbase_types
= TREE_CHAIN (vbase_types
))
684 tree base_binfos
= BINFO_BASETYPES (vbase_types
);
686 BINFO_INHERITANCE_CHAIN (vbase_types
) = TYPE_BINFO (rec
);
690 tree chain
= NULL_TREE
;
692 /* Now unshare the structure beneath BASE_BINFO. */
694 for (j
= TREE_VEC_LENGTH (base_binfos
)-1;
697 tree base_base_binfo
= TREE_VEC_ELT (base_binfos
, j
);
698 if (! TREE_VIA_VIRTUAL (base_base_binfo
))
699 TREE_VEC_ELT (base_binfos
, j
)
700 = make_binfo (BINFO_OFFSET (base_base_binfo
),
702 BINFO_VTABLE (base_base_binfo
),
703 BINFO_VIRTUALS (base_base_binfo
),
705 chain
= TREE_VEC_ELT (base_binfos
, j
);
706 TREE_VIA_PUBLIC (chain
) = TREE_VIA_PUBLIC (base_base_binfo
);
707 TREE_VIA_PROTECTED (chain
) = TREE_VIA_PROTECTED (base_base_binfo
);
708 BINFO_INHERITANCE_CHAIN (chain
) = vbase_types
;
711 propagate_binfo_offsets (vbase_types
, BINFO_OFFSET (vbase_types
));
718 /* Lay out the base types of a record type, REC.
719 Tentatively set the size and alignment of REC
720 according to the base types alone.
722 Offsets for immediate nonvirtual baseclasses are also computed here.
724 TYPE_BINFO (REC) should be NULL_TREE on entry, and this routine
725 creates a list of base_binfos in TYPE_BINFO (REC) from BINFOS.
727 Returns list of virtual base classes in a FIELD_DECL chain. */
730 layout_basetypes (rec
, binfos
)
733 /* Chain to hold all the new FIELD_DECLs which point at virtual
735 tree vbase_decls
= NULL_TREE
;
737 #ifdef STRUCTURE_SIZE_BOUNDARY
738 unsigned record_align
= MAX (STRUCTURE_SIZE_BOUNDARY
, TYPE_ALIGN (rec
));
740 unsigned record_align
= MAX (BITS_PER_UNIT
, TYPE_ALIGN (rec
));
743 /* Record size so far is CONST_SIZE + VAR_SIZE bits, where CONST_SIZE is
744 an integer and VAR_SIZE is a tree expression. If VAR_SIZE is null,
745 the size is just CONST_SIZE. Naturally we try to avoid using
746 VAR_SIZE. And so far, we've been successful. */
748 register tree var_size
= 0;
751 register unsigned const_size
= 0;
752 int i
, n_baseclasses
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
754 /* Handle basetypes almost like fields, but record their
755 offsets differently. */
757 for (i
= 0; i
< n_baseclasses
; i
++)
759 int inc
, desired_align
, int_vbase_size
;
760 register tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
761 register tree basetype
= BINFO_TYPE (base_binfo
);
764 if (TYPE_SIZE (basetype
) == 0)
767 /* This error is now reported in xref_tag, thus giving better
768 location information. */
769 error_with_aggr_type (base_binfo
,
770 "base class `%s' has incomplete type");
772 TREE_VIA_PUBLIC (base_binfo
) = 1;
773 TREE_VIA_PROTECTED (base_binfo
) = 0;
774 TREE_VIA_VIRTUAL (base_binfo
) = 0;
776 /* Should handle this better so that
779 class B: private A { virtual void F(); };
781 does not dump core when compiled. */
782 my_friendly_abort (121);
787 /* All basetypes are recorded in the association list of the
790 if (TREE_VIA_VIRTUAL (base_binfo
))
793 char *name
= (char *)alloca (TYPE_NAME_LENGTH (basetype
)
794 + sizeof (VBASE_NAME
) + 1);
796 /* The offset for a virtual base class is only used in computing
797 virtual function tables and for initializing virtual base
798 pointers. It is built once `get_vbase_types' is called. */
800 /* If this basetype can come from another vbase pointer
801 without an additional indirection, we will share
802 that pointer. If an indirection is involved, we
803 make our own pointer. */
804 for (j
= 0; j
< n_baseclasses
; j
++)
806 tree other_base_binfo
= TREE_VEC_ELT (binfos
, j
);
807 if (! TREE_VIA_VIRTUAL (other_base_binfo
)
808 && binfo_member (basetype
,
809 CLASSTYPE_VBASECLASSES (BINFO_TYPE (other_base_binfo
))))
812 sprintf (name
, VBASE_NAME_FORMAT
, TYPE_NAME_STRING (basetype
));
813 decl
= build_lang_field_decl (FIELD_DECL
, get_identifier (name
),
814 build_pointer_type (basetype
));
815 /* If you change any of the below, take a look at all the
816 other VFIELD_BASEs and VTABLE_BASEs in the code, and change
818 DECL_ASSEMBLER_NAME (decl
) = get_identifier (VTABLE_BASE
);
819 DECL_VIRTUAL_P (decl
) = 1;
820 DECL_FIELD_CONTEXT (decl
) = rec
;
821 DECL_CLASS_CONTEXT (decl
) = rec
;
822 DECL_FCONTEXT (decl
) = basetype
;
823 DECL_SAVED_INSNS (decl
) = NULL_RTX
;
824 DECL_FIELD_SIZE (decl
) = 0;
825 DECL_ALIGN (decl
) = TYPE_ALIGN (ptr_type_node
);
826 TREE_CHAIN (decl
) = vbase_decls
;
827 BINFO_VPTR_FIELD (base_binfo
) = decl
;
830 if (warn_nonvdtor
&& TYPE_HAS_DESTRUCTOR (basetype
)
831 && DECL_VINDEX (TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (basetype
), 1)) == NULL_TREE
)
833 warning_with_decl (TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (basetype
), 1),
834 "destructor `%s' non-virtual");
835 warning ("in inheritance relationship `%s: virtual %s'",
836 TYPE_NAME_STRING (rec
),
837 TYPE_NAME_STRING (basetype
));
840 /* The space this decl occupies has already been accounted for. */
845 offset
= integer_zero_node
;
848 /* Give each base type the alignment it wants. */
849 const_size
= CEIL (const_size
, TYPE_ALIGN (basetype
))
850 * TYPE_ALIGN (basetype
);
851 offset
= size_int ((const_size
+ BITS_PER_UNIT
- 1) / BITS_PER_UNIT
);
854 /* bpk: Disabled this check until someone is willing to
855 claim it as theirs and explain exactly what circumstances
856 warrant the warning. */
857 if (warn_nonvdtor
&& TYPE_HAS_DESTRUCTOR (basetype
)
858 && DECL_VINDEX (TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (basetype
), 1)) == NULL_TREE
)
860 warning_with_decl (TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (basetype
), 1),
861 "destructor `%s' non-virtual");
862 warning ("in inheritance relationship `%s:%s %s'",
863 TYPE_NAME_STRING (rec
),
864 TREE_VIA_VIRTUAL (base_binfo
) ? " virtual" : "",
865 TYPE_NAME_STRING (basetype
));
869 BINFO_OFFSET (base_binfo
) = offset
;
870 if (CLASSTYPE_VSIZE (basetype
))
872 BINFO_VTABLE (base_binfo
) = TYPE_BINFO_VTABLE (basetype
);
873 BINFO_VIRTUALS (base_binfo
) = TYPE_BINFO_VIRTUALS (basetype
);
875 TREE_CHAIN (base_binfo
) = TYPE_BINFO (rec
);
876 TYPE_BINFO (rec
) = base_binfo
;
878 /* Add only the amount of storage not present in
879 the virtual baseclasses. */
881 int_vbase_size
= TREE_INT_CST_LOW (CLASSTYPE_VBASE_SIZE (basetype
));
882 if (TREE_INT_CST_LOW (TYPE_SIZE (basetype
)) > int_vbase_size
)
884 inc
= MAX (record_align
,
885 (TREE_INT_CST_LOW (TYPE_SIZE (basetype
))
888 /* Record must have at least as much alignment as any field. */
889 desired_align
= TYPE_ALIGN (basetype
);
890 record_align
= MAX (record_align
, desired_align
);
897 CLASSTYPE_SIZE (rec
) = size_int (const_size
);
899 CLASSTYPE_SIZE (rec
) = integer_zero_node
;
900 CLASSTYPE_ALIGN (rec
) = record_align
;
905 /* Hashing of lists so that we don't make duplicates.
906 The entry point is `list_hash_canon'. */
908 /* Each hash table slot is a bucket containing a chain
909 of these structures. */
913 struct list_hash
*next
; /* Next structure in the bucket. */
914 int hashcode
; /* Hash code of this list. */
915 tree list
; /* The list recorded here. */
918 /* Now here is the hash table. When recording a list, it is added
919 to the slot whose index is the hash code mod the table size.
920 Note that the hash table is used for several kinds of lists.
921 While all these live in the same table, they are completely independent,
922 and the hash code is computed differently for each of these. */
924 #define TYPE_HASH_SIZE 59
925 struct list_hash
*list_hash_table
[TYPE_HASH_SIZE
];
927 /* Compute a hash code for a list (chain of TREE_LIST nodes
928 with goodies in the TREE_PURPOSE, TREE_VALUE, and bits of the
929 TREE_COMMON slots), by adding the hash codes of the individual entries. */
935 register int hashcode
= 0;
937 if (TREE_CHAIN (list
))
938 hashcode
+= TYPE_HASH (TREE_CHAIN (list
));
940 if (TREE_VALUE (list
))
941 hashcode
+= TYPE_HASH (TREE_VALUE (list
));
944 if (TREE_PURPOSE (list
))
945 hashcode
+= TYPE_HASH (TREE_PURPOSE (list
));
951 /* Look in the type hash table for a type isomorphic to TYPE.
952 If one is found, return it. Otherwise return 0. */
955 list_hash_lookup (hashcode
, list
)
959 register struct list_hash
*h
;
960 for (h
= list_hash_table
[hashcode
% TYPE_HASH_SIZE
]; h
; h
= h
->next
)
961 if (h
->hashcode
== hashcode
962 && TREE_VIA_VIRTUAL (h
->list
) == TREE_VIA_VIRTUAL (list
)
963 && TREE_VIA_PUBLIC (h
->list
) == TREE_VIA_PUBLIC (list
)
964 && TREE_VIA_PROTECTED (h
->list
) == TREE_VIA_PROTECTED (list
)
965 && TREE_PURPOSE (h
->list
) == TREE_PURPOSE (list
)
966 && TREE_VALUE (h
->list
) == TREE_VALUE (list
)
967 && TREE_CHAIN (h
->list
) == TREE_CHAIN (list
))
969 my_friendly_assert (TREE_TYPE (h
->list
) == TREE_TYPE (list
), 299);
975 /* Add an entry to the list-hash-table
976 for a list TYPE whose hash code is HASHCODE. */
979 list_hash_add (hashcode
, list
)
983 register struct list_hash
*h
;
985 h
= (struct list_hash
*) obstack_alloc (&class_obstack
, sizeof (struct list_hash
));
986 h
->hashcode
= hashcode
;
988 h
->next
= list_hash_table
[hashcode
% TYPE_HASH_SIZE
];
989 list_hash_table
[hashcode
% TYPE_HASH_SIZE
] = h
;
992 /* Given TYPE, and HASHCODE its hash code, return the canonical
993 object for an identical list if one already exists.
994 Otherwise, return TYPE, and record it as the canonical object
995 if it is a permanent object.
997 To use this function, first create a list of the sort you want.
998 Then compute its hash code from the fields of the list that
999 make it different from other similar lists.
1000 Then call this function and use the value.
1001 This function frees the list you pass in if it is a duplicate. */
1003 /* Set to 1 to debug without canonicalization. Never set by program. */
1005 static int debug_no_list_hash
= 0;
1008 list_hash_canon (hashcode
, list
)
1014 if (debug_no_list_hash
)
1017 t1
= list_hash_lookup (hashcode
, list
);
1020 obstack_free (&class_obstack
, list
);
1024 /* If this is a new list, record it for later reuse. */
1025 list_hash_add (hashcode
, list
);
1031 hash_tree_cons (via_public
, via_virtual
, via_protected
, purpose
, value
, chain
)
1032 int via_public
, via_virtual
, via_protected
;
1033 tree purpose
, value
, chain
;
1035 struct obstack
*ambient_obstack
= current_obstack
;
1039 current_obstack
= &class_obstack
;
1040 t
= tree_cons (purpose
, value
, chain
);
1041 TREE_VIA_PUBLIC (t
) = via_public
;
1042 TREE_VIA_PROTECTED (t
) = via_protected
;
1043 TREE_VIA_VIRTUAL (t
) = via_virtual
;
1044 hashcode
= list_hash (t
);
1045 t
= list_hash_canon (hashcode
, t
);
1046 current_obstack
= ambient_obstack
;
1050 /* Constructor for hashed lists. */
1053 hash_tree_chain (value
, chain
)
1056 struct obstack
*ambient_obstack
= current_obstack
;
1060 current_obstack
= &class_obstack
;
1061 t
= tree_cons (NULL_TREE
, value
, chain
);
1062 hashcode
= list_hash (t
);
1063 t
= list_hash_canon (hashcode
, t
);
1064 current_obstack
= ambient_obstack
;
1068 /* Similar, but used for concatenating two lists. */
1071 hash_chainon (list1
, list2
)
1078 if (TREE_CHAIN (list1
) == NULL_TREE
)
1079 return hash_tree_chain (TREE_VALUE (list1
), list2
);
1080 return hash_tree_chain (TREE_VALUE (list1
),
1081 hash_chainon (TREE_CHAIN (list1
), list2
));
1085 get_identifier_list (value
)
1088 tree list
= IDENTIFIER_AS_LIST (value
);
1089 if (list
!= NULL_TREE
1090 && (TREE_CODE (list
) != TREE_LIST
1091 || TREE_VALUE (list
) != value
))
1093 else if (IDENTIFIER_HAS_TYPE_VALUE (value
)
1094 && TREE_CODE (IDENTIFIER_TYPE_VALUE (value
)) == RECORD_TYPE
1095 && IDENTIFIER_TYPE_VALUE (value
)
1096 == TYPE_MAIN_VARIANT (IDENTIFIER_TYPE_VALUE (value
)))
1098 tree type
= IDENTIFIER_TYPE_VALUE (value
);
1100 if (TYPE_PTRMEMFUNC_P (type
))
1102 else if (type
== current_class_type
)
1103 /* Don't mess up the constructor name. */
1104 list
= tree_cons (NULL_TREE
, value
, NULL_TREE
);
1107 if (! CLASSTYPE_ID_AS_LIST (type
))
1108 CLASSTYPE_ID_AS_LIST (type
)
1109 = perm_tree_cons (NULL_TREE
, TYPE_IDENTIFIER (type
), NULL_TREE
);
1110 list
= CLASSTYPE_ID_AS_LIST (type
);
1117 get_decl_list (value
)
1120 tree list
= NULL_TREE
;
1122 if (TREE_CODE (value
) == IDENTIFIER_NODE
)
1123 list
= get_identifier_list (value
);
1124 else if (TREE_CODE (value
) == RECORD_TYPE
1125 && TYPE_LANG_SPECIFIC (value
)
1126 && value
== TYPE_MAIN_VARIANT (value
))
1127 list
= CLASSTYPE_AS_LIST (value
);
1129 if (list
!= NULL_TREE
)
1131 my_friendly_assert (TREE_CHAIN (list
) == NULL_TREE
, 301);
1135 return build_decl_list (NULL_TREE
, value
);
1138 /* Build an association between TYPE and some parameters:
1140 OFFSET is the offset added to `this' to convert it to a pointer
1143 BINFO is the base binfo to use, if we are deriving from one. This
1144 is necessary, as we want specialized parent binfos from base
1145 classes, so that the VTABLE_NAMEs of bases are for the most derived
1146 type, instead of of the simple type.
1148 VTABLE is the virtual function table with which to initialize
1149 sub-objects of type TYPE.
1151 VIRTUALS are the virtual functions sitting in VTABLE.
1153 CHAIN are more associations we must retain. */
1156 make_binfo (offset
, binfo
, vtable
, virtuals
, chain
)
1158 tree vtable
, virtuals
;
1161 tree new_binfo
= make_tree_vec (6);
1164 if (TREE_CODE (binfo
) == TREE_VEC
)
1165 type
= BINFO_TYPE (binfo
);
1169 binfo
= TYPE_BINFO (binfo
);
1172 TREE_CHAIN (new_binfo
) = chain
;
1174 TREE_USED (new_binfo
) = TREE_USED (chain
);
1176 TREE_TYPE (new_binfo
) = TYPE_MAIN_VARIANT (type
);
1177 BINFO_OFFSET (new_binfo
) = offset
;
1178 BINFO_VTABLE (new_binfo
) = vtable
;
1179 BINFO_VIRTUALS (new_binfo
) = virtuals
;
1180 BINFO_VPTR_FIELD (new_binfo
) = NULL_TREE
;
1182 if (binfo
&& BINFO_BASETYPES (binfo
) != NULL_TREE
)
1183 BINFO_BASETYPES (new_binfo
) = copy_node (BINFO_BASETYPES (binfo
));
1187 /* Return the binfo value for ELEM in TYPE. */
1190 binfo_value (elem
, type
)
1194 if (get_base_distance (elem
, type
, 0, (tree
*)0) == -2)
1195 compiler_error ("base class `%s' ambiguous in binfo_value",
1196 TYPE_NAME_STRING (elem
));
1198 return TYPE_BINFO (type
);
1199 if (TREE_CODE (elem
) == RECORD_TYPE
&& TYPE_BINFO (elem
) == type
)
1201 return get_binfo (elem
, type
, 0);
1208 register tree prev
= 0, tmp
, next
;
1209 for (tmp
= path
; tmp
; tmp
= next
)
1211 next
= BINFO_INHERITANCE_CHAIN (tmp
);
1212 BINFO_INHERITANCE_CHAIN (tmp
) = prev
;
1222 unsigned HOST_WIDE_INT n
;
1225 fprintf (stderr
, "type \"%s\"; offset = %d\n",
1226 TYPE_NAME_STRING (BINFO_TYPE (elem
)),
1227 TREE_INT_CST_LOW (BINFO_OFFSET (elem
)));
1228 fprintf (stderr
, "vtable type:\n");
1229 debug_tree (BINFO_TYPE (elem
));
1230 if (BINFO_VTABLE (elem
))
1231 fprintf (stderr
, "vtable decl \"%s\"\n", IDENTIFIER_POINTER (DECL_NAME (BINFO_VTABLE (elem
))));
1233 fprintf (stderr
, "no vtable decl yet\n");
1234 fprintf (stderr
, "virtuals:\n");
1235 virtuals
= BINFO_VIRTUALS (elem
);
1237 n
= skip_rtti_stuff (&virtuals
);
1241 tree fndecl
= TREE_OPERAND (FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (virtuals
)), 0);
1242 fprintf (stderr
, "%s [%d =? %d]\n",
1243 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (fndecl
)),
1244 n
, TREE_INT_CST_LOW (DECL_VINDEX (fndecl
)));
1246 virtuals
= TREE_CHAIN (virtuals
);
1250 /* Return the length of a chain of nodes chained through DECL_CHAIN.
1251 We expect a null pointer to mark the end of the chain.
1252 This is the Lisp primitive `length'. */
1255 decl_list_length (t
)
1259 register int len
= 0;
1261 my_friendly_assert (TREE_CODE (t
) == FUNCTION_DECL
1262 || TREE_CODE (t
) == TEMPLATE_DECL
, 300);
1263 for (tail
= t
; tail
; tail
= DECL_CHAIN (tail
))
1273 if (TREE_CODE (t
) == FUNCTION_DECL
)
1275 else if (TREE_CODE (t
) == TREE_LIST
)
1276 return decl_list_length (TREE_VALUE (t
));
1278 my_friendly_abort (359);
1283 is_overloaded_fn (x
)
1286 if (TREE_CODE (x
) == FUNCTION_DECL
)
1289 if (TREE_CODE (x
) == TREE_LIST
1290 && (TREE_CODE (TREE_VALUE (x
)) == FUNCTION_DECL
1291 || TREE_CODE (TREE_VALUE (x
)) == TEMPLATE_DECL
))
1298 really_overloaded_fn (x
)
1301 if (TREE_CODE (x
) == TREE_LIST
1302 && (TREE_CODE (TREE_VALUE (x
)) == FUNCTION_DECL
1303 || TREE_CODE (TREE_VALUE (x
)) == TEMPLATE_DECL
))
1313 if (TREE_CODE (from
) == FUNCTION_DECL
)
1316 my_friendly_assert (TREE_CODE (from
) == TREE_LIST
, 9);
1318 return TREE_VALUE (from
);
1322 fnaddr_from_vtable_entry (entry
)
1325 if (flag_vtable_thunks
)
1328 if (TREE_CODE (func
) == ADDR_EXPR
)
1329 func
= TREE_OPERAND (func
, 0);
1330 if (TREE_CODE (func
) == THUNK_DECL
)
1331 return DECL_INITIAL (func
);
1336 return TREE_VALUE (TREE_CHAIN (TREE_CHAIN (CONSTRUCTOR_ELTS (entry
))));
1340 function_arg_chain (t
)
1343 return TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (t
)));
1347 promotes_to_aggr_type (t
, code
)
1349 enum tree_code code
;
1351 if (TREE_CODE (t
) == code
)
1353 return IS_AGGR_TYPE (t
);
1357 is_aggr_type_2 (t1
, t2
)
1360 if (TREE_CODE (t1
) != TREE_CODE (t2
))
1362 return IS_AGGR_TYPE (t1
) && IS_AGGR_TYPE (t2
);
1365 /* Give message using types TYPE1 and TYPE2 as arguments.
1366 PFN is the function which will print the message;
1367 S is the format string for PFN to use. */
1370 message_2_types (pfn
, s
, type1
, type2
)
1375 tree name1
= TYPE_NAME (type1
);
1376 tree name2
= TYPE_NAME (type2
);
1377 if (TREE_CODE (name1
) == TYPE_DECL
)
1378 name1
= DECL_NAME (name1
);
1379 if (TREE_CODE (name2
) == TYPE_DECL
)
1380 name2
= DECL_NAME (name2
);
1381 (*pfn
) (s
, IDENTIFIER_POINTER (name1
), IDENTIFIER_POINTER (name2
));
1384 #define PRINT_RING_SIZE 4
1387 lang_printable_name (decl
)
1390 static tree decl_ring
[PRINT_RING_SIZE
];
1391 static char *print_ring
[PRINT_RING_SIZE
];
1392 static int ring_counter
;
1395 /* Only cache functions. */
1396 if (TREE_CODE (decl
) != FUNCTION_DECL
1397 || DECL_LANG_SPECIFIC (decl
) == 0)
1398 return decl_as_string (decl
, 1);
1400 /* See if this print name is lying around. */
1401 for (i
= 0; i
< PRINT_RING_SIZE
; i
++)
1402 if (decl_ring
[i
] == decl
)
1403 /* yes, so return it. */
1404 return print_ring
[i
];
1406 if (++ring_counter
== PRINT_RING_SIZE
)
1409 if (current_function_decl
!= NULL_TREE
)
1411 if (decl_ring
[ring_counter
] == current_function_decl
)
1413 if (ring_counter
== PRINT_RING_SIZE
)
1415 if (decl_ring
[ring_counter
] == current_function_decl
)
1416 my_friendly_abort (106);
1419 if (print_ring
[ring_counter
])
1420 free (print_ring
[ring_counter
]);
1423 int print_ret_type_p
1424 = (!DECL_CONSTRUCTOR_P (decl
)
1425 && !DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (decl
)));
1427 char *name
= (char *)decl_as_string (decl
, print_ret_type_p
);
1428 print_ring
[ring_counter
] = (char *)malloc (strlen (name
) + 1);
1429 strcpy (print_ring
[ring_counter
], name
);
1430 decl_ring
[ring_counter
] = decl
;
1432 return print_ring
[ring_counter
];
1435 /* Build the FUNCTION_TYPE or METHOD_TYPE which may throw exceptions
1436 listed in RAISES. */
1439 build_exception_variant (type
, raises
)
1443 tree v
= TYPE_MAIN_VARIANT (type
);
1444 int constp
= TYPE_READONLY (type
);
1445 int volatilep
= TYPE_VOLATILE (type
);
1447 for (; v
; v
= TYPE_NEXT_VARIANT (v
))
1449 if (TYPE_READONLY (v
) != constp
1450 || TYPE_VOLATILE (v
) != volatilep
)
1453 /* @@ This should do set equality, not exact match. */
1454 if (simple_cst_list_equal (TYPE_RAISES_EXCEPTIONS (v
), raises
))
1455 /* List of exceptions raised matches previously found list.
1457 @@ Nice to free up storage used in consing up the
1458 @@ list of exceptions raised. */
1462 /* Need to build a new variant. */
1463 v
= build_type_copy (type
);
1465 if (raises
&& ! TREE_PERMANENT (raises
))
1467 push_obstacks_nochange ();
1468 end_temporary_allocation ();
1469 raises
= copy_list (raises
);
1473 TYPE_RAISES_EXCEPTIONS (v
) = raises
;
1477 /* Subroutine of copy_to_permanent
1479 Assuming T is a node build bottom-up, make it all exist on
1480 permanent obstack, if it is not permanent already. */
1492 if (tmp
= func (t
), tmp
!= NULL_TREE
)
1495 switch (TREE_CODE (t
))
1498 return error_mark_node
;
1507 tree chain
= TREE_CHAIN (t
);
1509 TREE_CHAIN (t
) = mapcar (chain
, func
);
1510 TREE_TYPE (t
) = mapcar (TREE_TYPE (t
), func
);
1511 DECL_INITIAL (t
) = mapcar (DECL_INITIAL (t
), func
);
1512 DECL_SIZE (t
) = mapcar (DECL_SIZE (t
), func
);
1518 tree chain
= TREE_CHAIN (t
);
1520 TREE_PURPOSE (t
) = mapcar (TREE_PURPOSE (t
), func
);
1521 TREE_VALUE (t
) = mapcar (TREE_VALUE (t
), func
);
1522 TREE_CHAIN (t
) = mapcar (chain
, func
);
1528 int len
= TREE_VEC_LENGTH (t
);
1532 TREE_VEC_ELT (t
, len
) = mapcar (TREE_VEC_ELT (t
, len
), func
);
1539 return copy_node (t
);
1545 TREE_OPERAND (t
, 0) = mapcar (TREE_OPERAND (t
, 0), func
);
1546 TREE_OPERAND (t
, 1) = mapcar (TREE_OPERAND (t
, 1), func
);
1547 TREE_OPERAND (t
, 2) = mapcar (TREE_OPERAND (t
, 2), func
);
1552 TREE_OPERAND (t
, 0) = mapcar (TREE_OPERAND (t
, 0), func
);
1559 case TRUNC_DIV_EXPR
:
1560 case TRUNC_MOD_EXPR
:
1568 case BIT_ANDTC_EXPR
:
1569 case TRUTH_ANDIF_EXPR
:
1570 case TRUTH_ORIF_EXPR
:
1578 case FLOOR_DIV_EXPR
:
1579 case ROUND_DIV_EXPR
:
1581 case FLOOR_MOD_EXPR
:
1582 case ROUND_MOD_EXPR
:
1584 case PREDECREMENT_EXPR
:
1585 case PREINCREMENT_EXPR
:
1586 case POSTDECREMENT_EXPR
:
1587 case POSTINCREMENT_EXPR
:
1592 TREE_OPERAND (t
, 0) = mapcar (TREE_OPERAND (t
, 0), func
);
1593 TREE_OPERAND (t
, 1) = mapcar (TREE_OPERAND (t
, 1), func
);
1601 case TRUTH_NOT_EXPR
:
1605 TREE_OPERAND (t
, 0) = mapcar (TREE_OPERAND (t
, 0), func
);
1609 tmp
= build_pointer_type (mapcar (TREE_TYPE (t
), func
));
1610 return cp_build_type_variant (tmp
, TYPE_READONLY (t
), TYPE_VOLATILE (t
));
1611 case REFERENCE_TYPE
:
1612 tmp
= build_reference_type (mapcar (TREE_TYPE (t
), func
));
1613 return cp_build_type_variant (tmp
, TYPE_READONLY (t
), TYPE_VOLATILE (t
));
1615 tmp
= build_function_type (mapcar (TREE_TYPE (t
), func
),
1616 mapcar (TYPE_ARG_TYPES (t
), func
));
1617 return cp_build_type_variant (tmp
, TYPE_READONLY (t
), TYPE_VOLATILE (t
));
1619 tmp
= build_cplus_array_type (mapcar (TREE_TYPE (t
), func
),
1620 mapcar (TYPE_DOMAIN (t
), func
));
1621 return cp_build_type_variant (tmp
, TYPE_READONLY (t
), TYPE_VOLATILE (t
));
1623 tmp
= build_index_type (mapcar (TYPE_MAX_VALUE (t
), func
));
1624 return cp_build_type_variant (tmp
, TYPE_READONLY (t
), TYPE_VOLATILE (t
));
1626 tmp
= build_offset_type (mapcar (TYPE_OFFSET_BASETYPE (t
), func
),
1627 mapcar (TREE_TYPE (t
), func
));
1628 return cp_build_type_variant (tmp
, TYPE_READONLY (t
), TYPE_VOLATILE (t
));
1630 tmp
= build_cplus_method_type
1631 (mapcar (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (t
))), func
),
1632 mapcar (TREE_TYPE (t
), func
),
1633 mapcar (TREE_CHAIN (TYPE_ARG_TYPES (t
)), func
));
1634 return cp_build_type_variant (tmp
, TYPE_READONLY (t
), TYPE_VOLATILE (t
));
1638 CONSTRUCTOR_ELTS (t
) = mapcar (CONSTRUCTOR_ELTS (t
), func
);
1642 if (TYPE_PTRMEMFUNC_P (t
))
1643 return build_ptrmemfunc_type
1644 (mapcar (TYPE_PTRMEMFUNC_FN_TYPE (t
), func
));
1645 /* else fall through */
1647 /* This list is incomplete, but should suffice for now.
1648 It is very important that `sorry' not call
1649 `report_error_function'. That could cause an infinite loop. */
1651 sorry ("initializer contains unrecognized tree code");
1652 return error_mark_node
;
1655 my_friendly_abort (107);
1664 if (TREE_PERMANENT (t
))
1666 /* Support `void f () { extern int i; A<&i> a; }' */
1667 if ((TREE_CODE (t
) == VAR_DECL
|| TREE_CODE (t
) == FUNCTION_DECL
)
1669 return copy_node (t
);
1673 /* Assuming T is a node built bottom-up, make it all exist on
1674 permanent obstack, if it is not permanent already. */
1677 copy_to_permanent (t
)
1680 register struct obstack
*ambient_obstack
= current_obstack
;
1681 register struct obstack
*ambient_saveable_obstack
= saveable_obstack
;
1682 register struct obstack
*ambient_expression_obstack
= expression_obstack
;
1684 if (t
== NULL_TREE
|| TREE_PERMANENT (t
))
1687 saveable_obstack
= &permanent_obstack
;
1688 current_obstack
= saveable_obstack
;
1689 expression_obstack
= saveable_obstack
;
1691 t
= mapcar (t
, perm_manip
);
1693 current_obstack
= ambient_obstack
;
1694 saveable_obstack
= ambient_saveable_obstack
;
1695 expression_obstack
= ambient_expression_obstack
;
1700 #ifdef GATHER_STATISTICS
1701 extern int depth_reached
;
1705 print_lang_statistics ()
1707 extern struct obstack maybepermanent_obstack
, decl_obstack
;
1708 print_obstack_statistics ("class_obstack", &class_obstack
);
1709 print_obstack_statistics ("decl_obstack", &decl_obstack
);
1710 print_obstack_statistics ("permanent_obstack", &permanent_obstack
);
1711 print_obstack_statistics ("maybepermanent_obstack", &maybepermanent_obstack
);
1712 print_search_statistics ();
1713 print_class_statistics ();
1714 #ifdef GATHER_STATISTICS
1715 fprintf (stderr
, "maximum template instantiation depth reached: %d\n",
1720 /* This is used by the `assert' macro. It is provided in libgcc.a,
1721 which `cc' doesn't know how to link. Note that the C++ front-end
1722 no longer actually uses the `assert' macro (instead, it calls
1723 my_friendly_assert). But all of the back-end files still need this. */
1726 __eprintf (string
, expression
, line
, filename
)
1729 const char *expression
;
1731 const char *filename
;
1739 fprintf (stderr
, string
, expression
, line
, filename
);
1744 /* Return, as an INTEGER_CST node, the number of elements for TYPE
1745 (which is an ARRAY_TYPE). This counts only elements of the top
1749 array_type_nelts_top (type
)
1752 return fold (build (PLUS_EXPR
, sizetype
,
1753 array_type_nelts (type
),
1757 /* Return, as an INTEGER_CST node, the number of elements for TYPE
1758 (which is an ARRAY_TYPE). This one is a recursive count of all
1759 ARRAY_TYPEs that are clumped together. */
1762 array_type_nelts_total (type
)
1765 tree sz
= array_type_nelts_top (type
);
1766 type
= TREE_TYPE (type
);
1767 while (TREE_CODE (type
) == ARRAY_TYPE
)
1769 tree n
= array_type_nelts_top (type
);
1770 sz
= fold (build (MULT_EXPR
, sizetype
, sz
, n
));
1771 type
= TREE_TYPE (type
);
1781 if (TREE_CODE (t
) != TREE_LIST
&& ! TREE_SIDE_EFFECTS (t
))
1783 else if (TREE_CODE (t
) == TARGET_EXPR
)
1785 if (TREE_CODE (TREE_OPERAND (t
, 1)) == NEW_EXPR
)
1787 mark_used (TREE_OPERAND (TREE_OPERAND (TREE_OPERAND (t
, 1), 0), 0));
1788 return build_cplus_new
1789 (TREE_TYPE (t
), break_out_target_exprs (TREE_OPERAND (t
, 1)));
1792 TREE_OPERAND (t
, 0) = build (VAR_DECL
, TREE_TYPE (t
));
1793 layout_decl (TREE_OPERAND (t
, 0), 0);
1796 else if (TREE_CODE (t
) == CALL_EXPR
)
1797 mark_used (TREE_OPERAND (TREE_OPERAND (t
, 0), 0));
1802 /* Actually, we'll just clean out the target exprs for the moment. */
1805 break_out_target_exprs (t
)
1808 return mapcar (t
, bot_manip
);
1811 /* Obstack used for allocating nodes in template function and variable
1814 extern struct obstack
*expression_obstack
;
1816 /* Similar to `build_nt', except we build
1817 on the permanent_obstack, regardless. */
1820 build_min_nt
VPROTO((enum tree_code code
, ...))
1823 enum tree_code code
;
1825 register struct obstack
*ambient_obstack
= expression_obstack
;
1828 register int length
;
1834 code
= va_arg (p
, enum tree_code
);
1837 expression_obstack
= &permanent_obstack
;
1839 t
= make_node (code
);
1840 length
= tree_code_length
[(int) code
];
1841 TREE_COMPLEXITY (t
) = lineno
;
1843 for (i
= 0; i
< length
; i
++)
1845 tree x
= va_arg (p
, tree
);
1846 TREE_OPERAND (t
, i
) = copy_to_permanent (x
);
1850 expression_obstack
= ambient_obstack
;
1854 /* Similar to `build', except we build
1855 on the permanent_obstack, regardless. */
1858 build_min
VPROTO((enum tree_code code
, tree tt
, ...))
1861 enum tree_code code
;
1864 register struct obstack
*ambient_obstack
= expression_obstack
;
1867 register int length
;
1873 code
= va_arg (p
, enum tree_code
);
1874 tt
= va_arg (p
, tree
);
1877 expression_obstack
= &permanent_obstack
;
1879 t
= make_node (code
);
1880 length
= tree_code_length
[(int) code
];
1882 TREE_COMPLEXITY (t
) = lineno
;
1884 for (i
= 0; i
< length
; i
++)
1886 tree x
= va_arg (p
, tree
);
1887 TREE_OPERAND (t
, i
) = copy_to_permanent (x
);
1891 expression_obstack
= ambient_obstack
;
1895 /* Same as `tree_cons' but make a permanent object. */
1898 min_tree_cons (purpose
, value
, chain
)
1899 tree purpose
, value
, chain
;
1902 register struct obstack
*ambient_obstack
= current_obstack
;
1903 current_obstack
= &permanent_obstack
;
1905 node
= tree_cons (copy_to_permanent (purpose
),
1906 copy_to_permanent (value
), chain
);
1907 current_obstack
= ambient_obstack
;
1915 if (TREE_CODE (t
) == IDENTIFIER_NODE
)
1916 return identifier_typedecl_value (t
);
1917 if (TREE_CODE (t
) == TYPE_DECL
)
1919 if (TREE_CODE_CLASS (TREE_CODE (t
)) == 't')
1920 return TYPE_STUB_DECL (t
);
1922 my_friendly_abort (42);
1926 can_free (obstack
, t
)
1927 struct obstack
*obstack
;
1932 if (TREE_CODE (t
) == TREE_VEC
)
1933 size
= (TREE_VEC_LENGTH (t
)-1) * sizeof (tree
) + sizeof (struct tree_vec
);
1935 my_friendly_abort (42);
1937 #define ROUND(x) ((x + obstack_alignment_mask (obstack)) \
1938 & ~ obstack_alignment_mask (obstack))
1939 if ((char *)t
+ ROUND (size
) == obstack_next_free (obstack
))
1946 /* Return first vector element whose BINFO_TYPE is ELEM.
1947 Return 0 if ELEM is not in VEC. VEC may be NULL_TREE. */
1950 vec_binfo_member (elem
, vec
)
1956 for (i
= 0; i
< TREE_VEC_LENGTH (vec
); ++i
)
1957 if (comptypes (elem
, BINFO_TYPE (TREE_VEC_ELT (vec
, i
)), 1))
1958 return TREE_VEC_ELT (vec
, i
);
1963 /* Kludge around the fact that DECL_CONTEXT for virtual functions returns
1964 the wrong thing for decl_function_context. Hopefully the uses in the
1965 backend won't matter, since we don't need a static chain for local class
1969 hack_decl_function_context (decl
)
1972 if (TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_FUNCTION_MEMBER_P (decl
))
1973 return decl_function_context (TYPE_MAIN_DECL (DECL_CLASS_CONTEXT (decl
)));
1974 return decl_function_context (decl
);
1977 /* Return truthvalue of whether T1 is the same tree structure as T2.
1978 Return 1 if they are the same.
1979 Return 0 if they are understandably different.
1980 Return -1 if either contains tree structure not understood by
1984 cp_tree_equal (t1
, t2
)
1987 register enum tree_code code1
, code2
;
1992 if (t1
== 0 || t2
== 0)
1995 code1
= TREE_CODE (t1
);
1996 code2
= TREE_CODE (t2
);
1998 if (code1
== NOP_EXPR
|| code1
== CONVERT_EXPR
|| code1
== NON_LVALUE_EXPR
)
1999 if (code2
== NOP_EXPR
|| code2
== CONVERT_EXPR
|| code2
== NON_LVALUE_EXPR
)
2000 return cp_tree_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
2002 return cp_tree_equal (TREE_OPERAND (t1
, 0), t2
);
2003 else if (code2
== NOP_EXPR
|| code2
== CONVERT_EXPR
2004 || code2
== NON_LVALUE_EXPR
)
2005 return cp_tree_equal (t1
, TREE_OPERAND (t2
, 0));
2013 return TREE_INT_CST_LOW (t1
) == TREE_INT_CST_LOW (t2
)
2014 && TREE_INT_CST_HIGH (t1
) == TREE_INT_CST_HIGH (t2
);
2017 return REAL_VALUES_EQUAL (TREE_REAL_CST (t1
), TREE_REAL_CST (t2
));
2020 return TREE_STRING_LENGTH (t1
) == TREE_STRING_LENGTH (t2
)
2021 && !bcmp (TREE_STRING_POINTER (t1
), TREE_STRING_POINTER (t2
),
2022 TREE_STRING_LENGTH (t1
));
2028 return cp_tree_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
2031 cmp
= cp_tree_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
2034 return simple_cst_list_equal (TREE_OPERAND (t1
, 1), TREE_OPERAND (t2
, 1));
2037 /* Special case: if either target is an unallocated VAR_DECL,
2038 it means that it's going to be unified with whatever the
2039 TARGET_EXPR is really supposed to initialize, so treat it
2040 as being equivalent to anything. */
2041 if ((TREE_CODE (TREE_OPERAND (t1
, 0)) == VAR_DECL
2042 && DECL_NAME (TREE_OPERAND (t1
, 0)) == NULL_TREE
2043 && DECL_RTL (TREE_OPERAND (t1
, 0)) == 0)
2044 || (TREE_CODE (TREE_OPERAND (t2
, 0)) == VAR_DECL
2045 && DECL_NAME (TREE_OPERAND (t2
, 0)) == NULL_TREE
2046 && DECL_RTL (TREE_OPERAND (t2
, 0)) == 0))
2049 cmp
= cp_tree_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
2052 return cp_tree_equal (TREE_OPERAND (t1
, 1), TREE_OPERAND (t2
, 1));
2054 case WITH_CLEANUP_EXPR
:
2055 cmp
= cp_tree_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
2058 return cp_tree_equal (TREE_OPERAND (t1
, 2), TREE_OPERAND (t1
, 2));
2061 if (TREE_OPERAND (t1
, 1) == TREE_OPERAND (t2
, 1))
2062 return cp_tree_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
2071 case TEMPLATE_CONST_PARM
:
2072 return TEMPLATE_CONST_IDX (t1
) == TEMPLATE_CONST_IDX (t2
);
2075 if (TREE_CODE (TREE_OPERAND (t1
, 0)) != TREE_CODE (TREE_OPERAND (t2
, 0)))
2077 if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (t1
, 0))) == 't')
2078 return comptypes (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0), 1);
2082 switch (TREE_CODE_CLASS (code1
))
2092 for (i
=0; i
<tree_code_length
[(int) code1
]; ++i
)
2094 cmp
= cp_tree_equal (TREE_OPERAND (t1
, i
), TREE_OPERAND (t2
, i
));
2104 /* Similar to make_tree_vec, but build on a temporary obstack. */
2111 push_obstacks_nochange ();
2112 resume_temporary_allocation ();
2113 node
= make_tree_vec (len
);
2118 /* The type of ARG when used as an lvalue. */
2124 return cp_build_type_variant
2125 (TREE_TYPE (arg
), TREE_READONLY (arg
), TREE_THIS_VOLATILE (arg
));
2128 /* The type of ARG for printing error messages; denote lvalues with
2135 tree type
= TREE_TYPE (arg
);
2136 if (TREE_CODE (type
) == ARRAY_TYPE
)
2138 else if (real_lvalue_p (arg
))
2139 type
= build_reference_type (lvalue_type (arg
));
2140 else if (IS_AGGR_TYPE (type
))
2141 type
= lvalue_type (arg
);