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. */
39 #ifdef NEED_DECLARATION_FREE
40 extern void free
PROTO((void *));
43 extern void compiler_error ();
45 static tree get_identifier_list
PROTO((tree
));
46 static tree bot_manip
PROTO((tree
));
47 static tree perm_manip
PROTO((tree
));
48 static tree build_cplus_array_type_1
PROTO((tree
, tree
));
49 static void list_hash_add
PROTO((int, tree
));
50 static int list_hash
PROTO((tree
, tree
, tree
));
51 static tree list_hash_lookup
PROTO((int, int, int, int, tree
, tree
,
54 #define CEIL(x,y) (((x) + (y) - 1) / (y))
56 /* Return nonzero if REF is an lvalue valid for this language.
57 Lvalues can be assigned, unless they have TREE_READONLY.
58 Lvalues can have their address taken, unless they have DECL_REGISTER. */
64 if (! language_lvalue_valid (ref
))
67 if (TREE_CODE (TREE_TYPE (ref
)) == REFERENCE_TYPE
)
70 if (ref
== current_class_ptr
&& flag_this_is_variable
<= 0)
73 switch (TREE_CODE (ref
))
75 /* preincrements and predecrements are valid lvals, provided
76 what they refer to are valid lvals. */
77 case PREINCREMENT_EXPR
:
78 case PREDECREMENT_EXPR
:
83 case WITH_CLEANUP_EXPR
:
84 return real_lvalue_p (TREE_OPERAND (ref
, 0));
90 if (TREE_READONLY (ref
) && ! TREE_STATIC (ref
)
91 && DECL_LANG_SPECIFIC (ref
)
92 && DECL_IN_AGGR_P (ref
))
99 if (TREE_CODE (TREE_TYPE (ref
)) != FUNCTION_TYPE
100 && TREE_CODE (TREE_TYPE (ref
)) != METHOD_TYPE
)
104 /* A currently unresolved scope ref. */
106 my_friendly_abort (103);
108 if (TREE_CODE (TREE_OPERAND (ref
, 1)) == FUNCTION_DECL
)
110 return real_lvalue_p (TREE_OPERAND (ref
, 0))
111 && real_lvalue_p (TREE_OPERAND (ref
, 1));
115 return (real_lvalue_p (TREE_OPERAND (ref
, 1))
116 && real_lvalue_p (TREE_OPERAND (ref
, 2)));
122 return real_lvalue_p (TREE_OPERAND (ref
, 1));
126 return (real_lvalue_p (TREE_OPERAND (ref
, 0))
127 && real_lvalue_p (TREE_OPERAND (ref
, 1)));
136 /* This differs from real_lvalue_p in that class rvalues are considered
142 if (! language_lvalue_valid (ref
))
145 if (TREE_CODE (TREE_TYPE (ref
)) == REFERENCE_TYPE
)
148 if (ref
== current_class_ptr
&& flag_this_is_variable
<= 0)
151 switch (TREE_CODE (ref
))
153 /* preincrements and predecrements are valid lvals, provided
154 what they refer to are valid lvals. */
155 case PREINCREMENT_EXPR
:
156 case PREDECREMENT_EXPR
:
163 case WITH_CLEANUP_EXPR
:
164 return lvalue_p (TREE_OPERAND (ref
, 0));
170 if (TREE_READONLY (ref
) && ! TREE_STATIC (ref
)
171 && DECL_LANG_SPECIFIC (ref
)
172 && DECL_IN_AGGR_P (ref
))
179 if (TREE_CODE (TREE_TYPE (ref
)) != FUNCTION_TYPE
180 && TREE_CODE (TREE_TYPE (ref
)) != METHOD_TYPE
)
188 if (IS_AGGR_TYPE (TREE_TYPE (ref
)))
192 /* A currently unresolved scope ref. */
194 my_friendly_abort (103);
196 if (TREE_CODE (TREE_OPERAND (ref
, 1)) == FUNCTION_DECL
)
198 return lvalue_p (TREE_OPERAND (ref
, 0))
199 && lvalue_p (TREE_OPERAND (ref
, 1));
203 return (lvalue_p (TREE_OPERAND (ref
, 1))
204 && lvalue_p (TREE_OPERAND (ref
, 2)));
210 return lvalue_p (TREE_OPERAND (ref
, 1));
214 return (lvalue_p (TREE_OPERAND (ref
, 0))
215 && lvalue_p (TREE_OPERAND (ref
, 1)));
224 /* Return nonzero if REF is an lvalue valid for this language;
225 otherwise, print an error message and return zero. */
228 lvalue_or_else (ref
, string
)
232 int win
= lvalue_p (ref
);
234 error ("non-lvalue in %s", string
);
238 /* INIT is a CALL_EXPR which needs info about its target.
239 TYPE is the type that this initialization should appear to have.
241 Build an encapsulation of the initialization to perform
242 and return it so that it can be processed by language-independent
243 and language-specific expression expanders. */
246 build_cplus_new (type
, init
)
253 if (TREE_CODE (init
) != CALL_EXPR
&& TREE_CODE (init
) != AGGR_INIT_EXPR
)
256 slot
= build (VAR_DECL
, type
);
257 DECL_ARTIFICIAL (slot
) = 1;
258 layout_decl (slot
, 0);
259 rval
= build (AGGR_INIT_EXPR
, type
,
260 TREE_OPERAND (init
, 0), TREE_OPERAND (init
, 1), slot
);
261 TREE_SIDE_EFFECTS (rval
) = 1;
262 rval
= build (TARGET_EXPR
, type
, slot
, rval
, NULL_TREE
, NULL_TREE
);
263 TREE_SIDE_EFFECTS (rval
) = 1;
268 /* Encapsulate the expression INIT in a TARGET_EXPR. */
271 get_target_expr (init
)
277 slot
= build (VAR_DECL
, TREE_TYPE (init
));
278 DECL_ARTIFICIAL (slot
) = 1;
279 layout_decl (slot
, 0);
280 rval
= build (TARGET_EXPR
, TREE_TYPE (init
), slot
, init
,
281 NULL_TREE
, NULL_TREE
);
282 TREE_SIDE_EFFECTS (rval
) = 1;
287 /* Recursively search EXP for CALL_EXPRs that need cleanups and replace
288 these CALL_EXPRs with tree nodes that will perform the cleanups. */
291 break_out_cleanups (exp
)
296 if (TREE_CODE (tmp
) == CALL_EXPR
297 && TYPE_NEEDS_DESTRUCTOR (TREE_TYPE (tmp
)))
298 return build_cplus_new (TREE_TYPE (tmp
), tmp
);
300 while (TREE_CODE (tmp
) == NOP_EXPR
301 || TREE_CODE (tmp
) == CONVERT_EXPR
302 || TREE_CODE (tmp
) == NON_LVALUE_EXPR
)
304 if (TREE_CODE (TREE_OPERAND (tmp
, 0)) == CALL_EXPR
305 && TYPE_NEEDS_DESTRUCTOR (TREE_TYPE (TREE_OPERAND (tmp
, 0))))
307 TREE_OPERAND (tmp
, 0)
308 = build_cplus_new (TREE_TYPE (TREE_OPERAND (tmp
, 0)),
309 TREE_OPERAND (tmp
, 0));
313 tmp
= TREE_OPERAND (tmp
, 0);
318 /* Recursively perform a preorder search EXP for CALL_EXPRs, making
319 copies where they are found. Returns a deep copy all nodes transitively
320 containing CALL_EXPRs. */
323 break_out_calls (exp
)
326 register tree t1
, t2
;
327 register enum tree_code code
;
328 register int changed
= 0;
331 if (exp
== NULL_TREE
)
334 code
= TREE_CODE (exp
);
336 if (code
== CALL_EXPR
)
337 return copy_node (exp
);
339 /* Don't try and defeat a save_expr, as it should only be done once. */
340 if (code
== SAVE_EXPR
)
343 switch (TREE_CODE_CLASS (code
))
348 case 'c': /* a constant */
349 case 't': /* a type node */
350 case 'x': /* something random, like an identifier or an ERROR_MARK. */
353 case 'd': /* A decl node */
354 #if 0 /* This is bogus. jason 9/21/94 */
356 t1
= break_out_calls (DECL_INITIAL (exp
));
357 if (t1
!= DECL_INITIAL (exp
))
359 exp
= copy_node (exp
);
360 DECL_INITIAL (exp
) = t1
;
365 case 'b': /* A block node */
367 /* Don't know how to handle these correctly yet. Must do a
368 break_out_calls on all DECL_INITIAL values for local variables,
369 and also break_out_calls on all sub-blocks and sub-statements. */
374 case 'e': /* an expression */
375 case 'r': /* a reference */
376 case 's': /* an expression with side effects */
377 for (i
= tree_code_length
[(int) code
] - 1; i
>= 0; i
--)
379 t1
= break_out_calls (TREE_OPERAND (exp
, i
));
380 if (t1
!= TREE_OPERAND (exp
, i
))
382 exp
= copy_node (exp
);
383 TREE_OPERAND (exp
, i
) = t1
;
388 case '<': /* a comparison expression */
389 case '2': /* a binary arithmetic expression */
390 t2
= break_out_calls (TREE_OPERAND (exp
, 1));
391 if (t2
!= TREE_OPERAND (exp
, 1))
393 case '1': /* a unary arithmetic expression */
394 t1
= break_out_calls (TREE_OPERAND (exp
, 0));
395 if (t1
!= TREE_OPERAND (exp
, 0))
399 if (tree_code_length
[(int) code
] == 1)
400 return build1 (code
, TREE_TYPE (exp
), t1
);
402 return build (code
, TREE_TYPE (exp
), t1
, t2
);
409 extern struct obstack
*current_obstack
;
410 extern struct obstack permanent_obstack
, class_obstack
;
411 extern struct obstack
*saveable_obstack
;
412 extern struct obstack
*expression_obstack
;
414 /* Here is how primitive or already-canonicalized types' hash
415 codes are made. MUST BE CONSISTENT WITH tree.c !!! */
416 #define TYPE_HASH(TYPE) ((HOST_WIDE_INT) (TYPE) & 0777777)
418 /* Construct, lay out and return the type of methods belonging to class
419 BASETYPE and whose arguments are described by ARGTYPES and whose values
420 are described by RETTYPE. If each type exists already, reuse it. */
423 build_cplus_method_type (basetype
, rettype
, argtypes
)
424 tree basetype
, rettype
, argtypes
;
430 /* Make a node of the sort we want. */
431 t
= make_node (METHOD_TYPE
);
433 TYPE_METHOD_BASETYPE (t
) = TYPE_MAIN_VARIANT (basetype
);
434 TREE_TYPE (t
) = rettype
;
435 if (IS_SIGNATURE (basetype
))
436 ptype
= build_signature_pointer_type (TYPE_MAIN_VARIANT (basetype
),
437 TYPE_READONLY (basetype
),
438 TYPE_VOLATILE (basetype
));
440 ptype
= build_pointer_type (basetype
);
442 /* The actual arglist for this function includes a "hidden" argument
443 which is "this". Put it into the list of argument types. */
445 argtypes
= tree_cons (NULL_TREE
, ptype
, argtypes
);
446 TYPE_ARG_TYPES (t
) = argtypes
;
447 TREE_SIDE_EFFECTS (argtypes
) = 1; /* Mark first argtype as "artificial". */
449 /* If we already have such a type, use the old one and free this one.
450 Note that it also frees up the above cons cell if found. */
451 hashcode
= TYPE_HASH (basetype
) + TYPE_HASH (rettype
) + type_hash_list (argtypes
);
452 t
= type_hash_canon (hashcode
, t
);
454 if (TYPE_SIZE (t
) == 0)
461 build_cplus_array_type_1 (elt_type
, index_type
)
465 register struct obstack
*ambient_obstack
= current_obstack
;
466 register struct obstack
*ambient_saveable_obstack
= saveable_obstack
;
469 /* We need a new one. If both ELT_TYPE and INDEX_TYPE are permanent,
470 make this permanent too. */
471 if (TREE_PERMANENT (elt_type
)
472 && (index_type
== 0 || TREE_PERMANENT (index_type
)))
474 current_obstack
= &permanent_obstack
;
475 saveable_obstack
= &permanent_obstack
;
478 if (processing_template_decl
)
480 t
= make_node (ARRAY_TYPE
);
481 TREE_TYPE (t
) = elt_type
;
482 TYPE_DOMAIN (t
) = index_type
;
485 t
= build_array_type (elt_type
, index_type
);
487 /* Push these needs up so that initialization takes place
489 TYPE_NEEDS_CONSTRUCTING (t
) = TYPE_NEEDS_CONSTRUCTING (TYPE_MAIN_VARIANT (elt_type
));
490 TYPE_NEEDS_DESTRUCTOR (t
) = TYPE_NEEDS_DESTRUCTOR (TYPE_MAIN_VARIANT (elt_type
));
491 current_obstack
= ambient_obstack
;
492 saveable_obstack
= ambient_saveable_obstack
;
497 build_cplus_array_type (elt_type
, index_type
)
502 int constp
= TYPE_READONLY (elt_type
);
503 int volatilep
= TYPE_VOLATILE (elt_type
);
504 elt_type
= TYPE_MAIN_VARIANT (elt_type
);
506 t
= build_cplus_array_type_1 (elt_type
, index_type
);
508 if (constp
|| volatilep
)
509 t
= cp_build_type_variant (t
, constp
, volatilep
);
514 /* Make a variant type in the proper way for C/C++, propagating qualifiers
515 down to the element type of an array. */
518 cp_build_type_variant (type
, constp
, volatilep
)
520 int constp
, volatilep
;
522 if (type
== error_mark_node
)
525 if (TREE_CODE (type
) == ARRAY_TYPE
)
527 tree real_main_variant
= TYPE_MAIN_VARIANT (type
);
529 push_obstacks (TYPE_OBSTACK (real_main_variant
),
530 TYPE_OBSTACK (real_main_variant
));
531 type
= build_cplus_array_type_1 (cp_build_type_variant
532 (TREE_TYPE (type
), constp
, volatilep
),
535 /* TYPE must be on same obstack as REAL_MAIN_VARIANT. If not,
536 make a copy. (TYPE might have come from the hash table and
537 REAL_MAIN_VARIANT might be in some function's obstack.) */
539 if (TYPE_OBSTACK (type
) != TYPE_OBSTACK (real_main_variant
))
541 type
= copy_node (type
);
542 TYPE_POINTER_TO (type
) = TYPE_REFERENCE_TO (type
) = 0;
545 TYPE_MAIN_VARIANT (type
) = real_main_variant
;
549 return build_type_variant (type
, constp
, volatilep
);
552 /* Add OFFSET to all base types of T.
554 OFFSET, which is a type offset, is number of bytes.
556 Note that we don't have to worry about having two paths to the
557 same base type, since this type owns its association list. */
560 propagate_binfo_offsets (binfo
, offset
)
564 tree binfos
= BINFO_BASETYPES (binfo
);
565 int i
, n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
567 for (i
= 0; i
< n_baselinks
; /* note increment is done in the loop. */)
569 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
571 if (TREE_VIA_VIRTUAL (base_binfo
))
576 tree base_binfos
= BINFO_BASETYPES (base_binfo
);
579 for (j
= i
+1; j
< n_baselinks
; j
++)
580 if (! TREE_VIA_VIRTUAL (TREE_VEC_ELT (binfos
, j
)))
582 /* The next basetype offset must take into account the space
583 between the classes, not just the size of each class. */
584 delta
= size_binop (MINUS_EXPR
,
585 BINFO_OFFSET (TREE_VEC_ELT (binfos
, j
)),
586 BINFO_OFFSET (base_binfo
));
591 if (BINFO_OFFSET_ZEROP (base_binfo
))
592 BINFO_OFFSET (base_binfo
) = offset
;
594 BINFO_OFFSET (base_binfo
)
595 = size_binop (PLUS_EXPR
, BINFO_OFFSET (base_binfo
), offset
);
597 BINFO_OFFSET (base_binfo
) = offset
;
602 tree chain
= NULL_TREE
;
604 /* Now unshare the structure beneath BASE_BINFO. */
605 for (k
= TREE_VEC_LENGTH (base_binfos
)-1;
608 tree base_base_binfo
= TREE_VEC_ELT (base_binfos
, k
);
609 if (! TREE_VIA_VIRTUAL (base_base_binfo
))
610 TREE_VEC_ELT (base_binfos
, k
)
611 = make_binfo (BINFO_OFFSET (base_base_binfo
),
613 BINFO_VTABLE (base_base_binfo
),
614 BINFO_VIRTUALS (base_base_binfo
),
616 chain
= TREE_VEC_ELT (base_binfos
, k
);
617 TREE_VIA_PUBLIC (chain
) = TREE_VIA_PUBLIC (base_base_binfo
);
618 TREE_VIA_PROTECTED (chain
) = TREE_VIA_PROTECTED (base_base_binfo
);
619 BINFO_INHERITANCE_CHAIN (chain
) = base_binfo
;
621 /* Now propagate the offset to the base types. */
622 propagate_binfo_offsets (base_binfo
, offset
);
625 /* Go to our next class that counts for offset propagation. */
628 offset
= size_binop (PLUS_EXPR
, offset
, delta
);
633 /* Compute the actual offsets that our virtual base classes
634 will have *for this type*. This must be performed after
635 the fields are laid out, since virtual baseclasses must
636 lay down at the end of the record.
638 Returns the maximum number of virtual functions any of the virtual
639 baseclasses provide. */
642 layout_vbasetypes (rec
, max
)
646 /* Get all the virtual base types that this type uses.
647 The TREE_VALUE slot holds the virtual baseclass type. */
648 tree vbase_types
= get_vbase_types (rec
);
650 #ifdef STRUCTURE_SIZE_BOUNDARY
651 unsigned record_align
= MAX (STRUCTURE_SIZE_BOUNDARY
, TYPE_ALIGN (rec
));
653 unsigned record_align
= MAX (BITS_PER_UNIT
, TYPE_ALIGN (rec
));
657 /* Record size so far is CONST_SIZE + VAR_SIZE bits,
658 where CONST_SIZE is an integer
659 and VAR_SIZE is a tree expression.
660 If VAR_SIZE is null, the size is just CONST_SIZE.
661 Naturally we try to avoid using VAR_SIZE. */
662 register unsigned const_size
= 0;
663 register tree var_size
= 0;
664 int nonvirtual_const_size
;
666 CLASSTYPE_VBASECLASSES (rec
) = vbase_types
;
668 if (TREE_CODE (TYPE_SIZE (rec
)) == INTEGER_CST
)
669 const_size
= TREE_INT_CST_LOW (TYPE_SIZE (rec
));
671 var_size
= TYPE_SIZE (rec
);
673 nonvirtual_const_size
= const_size
;
677 tree basetype
= BINFO_TYPE (vbase_types
);
680 desired_align
= TYPE_ALIGN (basetype
);
681 record_align
= MAX (record_align
, desired_align
);
684 offset
= integer_zero_node
;
687 /* Give each virtual base type the alignment it wants. */
688 const_size
= CEIL (const_size
, TYPE_ALIGN (basetype
))
689 * TYPE_ALIGN (basetype
);
690 offset
= size_int (CEIL (const_size
, BITS_PER_UNIT
));
693 if (CLASSTYPE_VSIZE (basetype
) > max
)
694 max
= CLASSTYPE_VSIZE (basetype
);
695 BINFO_OFFSET (vbase_types
) = offset
;
697 if (TREE_CODE (TYPE_SIZE (basetype
)) == INTEGER_CST
)
699 /* Every virtual baseclass takes a least a UNIT, so that we can
700 take it's address and get something different for each base. */
701 const_size
+= MAX (BITS_PER_UNIT
,
702 TREE_INT_CST_LOW (TYPE_SIZE (basetype
))
703 - TREE_INT_CST_LOW (CLASSTYPE_VBASE_SIZE (basetype
)));
705 else if (var_size
== 0)
706 var_size
= TYPE_SIZE (basetype
);
708 var_size
= size_binop (PLUS_EXPR
, var_size
, TYPE_SIZE (basetype
));
710 vbase_types
= TREE_CHAIN (vbase_types
);
715 /* Because a virtual base might take a single byte above,
716 we have to re-adjust the total size to make sure it it
717 a multiple of the alignment. */
718 /* Give the whole object the alignment it wants. */
719 const_size
= CEIL (const_size
, record_align
) * record_align
;
722 /* Set the alignment in the complete type. We don't set CLASSTYPE_ALIGN
723 here, as that is for this class, without any virtual base classes. */
724 TYPE_ALIGN (rec
) = record_align
;
725 if (const_size
!= nonvirtual_const_size
)
727 CLASSTYPE_VBASE_SIZE (rec
)
728 = size_int (const_size
- nonvirtual_const_size
);
729 TYPE_SIZE (rec
) = size_int (const_size
);
732 /* Now propagate offset information throughout the lattice
733 under the vbase type. */
734 for (vbase_types
= CLASSTYPE_VBASECLASSES (rec
); vbase_types
;
735 vbase_types
= TREE_CHAIN (vbase_types
))
737 tree base_binfos
= BINFO_BASETYPES (vbase_types
);
739 BINFO_INHERITANCE_CHAIN (vbase_types
) = TYPE_BINFO (rec
);
743 tree chain
= NULL_TREE
;
745 /* Now unshare the structure beneath BASE_BINFO. */
747 for (j
= TREE_VEC_LENGTH (base_binfos
)-1;
750 tree base_base_binfo
= TREE_VEC_ELT (base_binfos
, j
);
751 if (! TREE_VIA_VIRTUAL (base_base_binfo
))
752 TREE_VEC_ELT (base_binfos
, j
)
753 = make_binfo (BINFO_OFFSET (base_base_binfo
),
755 BINFO_VTABLE (base_base_binfo
),
756 BINFO_VIRTUALS (base_base_binfo
),
758 chain
= TREE_VEC_ELT (base_binfos
, j
);
759 TREE_VIA_PUBLIC (chain
) = TREE_VIA_PUBLIC (base_base_binfo
);
760 TREE_VIA_PROTECTED (chain
) = TREE_VIA_PROTECTED (base_base_binfo
);
761 BINFO_INHERITANCE_CHAIN (chain
) = vbase_types
;
764 propagate_binfo_offsets (vbase_types
, BINFO_OFFSET (vbase_types
));
771 /* Lay out the base types of a record type, REC.
772 Tentatively set the size and alignment of REC
773 according to the base types alone.
775 Offsets for immediate nonvirtual baseclasses are also computed here.
777 TYPE_BINFO (REC) should be NULL_TREE on entry, and this routine
778 creates a list of base_binfos in TYPE_BINFO (REC) from BINFOS.
780 Returns list of virtual base classes in a FIELD_DECL chain. */
783 layout_basetypes (rec
, binfos
)
786 /* Chain to hold all the new FIELD_DECLs which point at virtual
788 tree vbase_decls
= NULL_TREE
;
790 #ifdef STRUCTURE_SIZE_BOUNDARY
791 unsigned record_align
= MAX (STRUCTURE_SIZE_BOUNDARY
, TYPE_ALIGN (rec
));
793 unsigned record_align
= MAX (BITS_PER_UNIT
, TYPE_ALIGN (rec
));
796 /* Record size so far is CONST_SIZE + VAR_SIZE bits, where CONST_SIZE is
797 an integer and VAR_SIZE is a tree expression. If VAR_SIZE is null,
798 the size is just CONST_SIZE. Naturally we try to avoid using
799 VAR_SIZE. And so far, we've been successful. */
801 register tree var_size
= 0;
804 register unsigned const_size
= 0;
805 int i
, n_baseclasses
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
807 /* Handle basetypes almost like fields, but record their
808 offsets differently. */
810 for (i
= 0; i
< n_baseclasses
; i
++)
812 int inc
, desired_align
, int_vbase_size
;
813 register tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
814 register tree basetype
= BINFO_TYPE (base_binfo
);
817 if (TYPE_SIZE (basetype
) == 0)
820 /* This error is now reported in xref_tag, thus giving better
821 location information. */
822 error_with_aggr_type (base_binfo
,
823 "base class `%s' has incomplete type");
825 TREE_VIA_PUBLIC (base_binfo
) = 1;
826 TREE_VIA_PROTECTED (base_binfo
) = 0;
827 TREE_VIA_VIRTUAL (base_binfo
) = 0;
829 /* Should handle this better so that
832 class B: private A { virtual void F(); };
834 does not dump core when compiled. */
835 my_friendly_abort (121);
840 /* All basetypes are recorded in the association list of the
843 if (TREE_VIA_VIRTUAL (base_binfo
))
846 char *name
= (char *)alloca (TYPE_NAME_LENGTH (basetype
)
847 + sizeof (VBASE_NAME
) + 1);
849 /* The offset for a virtual base class is only used in computing
850 virtual function tables and for initializing virtual base
851 pointers. It is built once `get_vbase_types' is called. */
853 /* If this basetype can come from another vbase pointer
854 without an additional indirection, we will share
855 that pointer. If an indirection is involved, we
856 make our own pointer. */
857 for (j
= 0; j
< n_baseclasses
; j
++)
859 tree other_base_binfo
= TREE_VEC_ELT (binfos
, j
);
860 if (! TREE_VIA_VIRTUAL (other_base_binfo
)
861 && binfo_member (basetype
,
862 CLASSTYPE_VBASECLASSES (BINFO_TYPE (other_base_binfo
))))
865 sprintf (name
, VBASE_NAME_FORMAT
, TYPE_NAME_STRING (basetype
));
866 decl
= build_lang_field_decl (FIELD_DECL
, get_identifier (name
),
867 build_pointer_type (basetype
));
868 /* If you change any of the below, take a look at all the
869 other VFIELD_BASEs and VTABLE_BASEs in the code, and change
871 DECL_ASSEMBLER_NAME (decl
) = get_identifier (VTABLE_BASE
);
872 DECL_VIRTUAL_P (decl
) = 1;
873 DECL_ARTIFICIAL (decl
) = 1;
874 DECL_FIELD_CONTEXT (decl
) = rec
;
875 DECL_CLASS_CONTEXT (decl
) = rec
;
876 DECL_FCONTEXT (decl
) = basetype
;
877 DECL_SAVED_INSNS (decl
) = NULL_RTX
;
878 DECL_FIELD_SIZE (decl
) = 0;
879 DECL_ALIGN (decl
) = TYPE_ALIGN (ptr_type_node
);
880 TREE_CHAIN (decl
) = vbase_decls
;
881 BINFO_VPTR_FIELD (base_binfo
) = decl
;
885 /* The space this decl occupies has already been accounted for. */
889 /* Effective C++ rule 14. We only need to check TYPE_VIRTUAL_P
890 here because the case of virtual functions but non-virtual
891 dtor is handled in finish_struct_1. */
892 if (warn_ecpp
&& ! TYPE_VIRTUAL_P (basetype
)
893 && TYPE_HAS_DESTRUCTOR (basetype
))
894 cp_warning ("base class `%#T' has a non-virtual destructor", basetype
);
897 offset
= integer_zero_node
;
900 /* Give each base type the alignment it wants. */
901 const_size
= CEIL (const_size
, TYPE_ALIGN (basetype
))
902 * TYPE_ALIGN (basetype
);
903 offset
= size_int ((const_size
+ BITS_PER_UNIT
- 1) / BITS_PER_UNIT
);
905 BINFO_OFFSET (base_binfo
) = offset
;
906 if (CLASSTYPE_VSIZE (basetype
))
908 BINFO_VTABLE (base_binfo
) = TYPE_BINFO_VTABLE (basetype
);
909 BINFO_VIRTUALS (base_binfo
) = TYPE_BINFO_VIRTUALS (basetype
);
911 TREE_CHAIN (base_binfo
) = TYPE_BINFO (rec
);
912 TYPE_BINFO (rec
) = base_binfo
;
914 /* Add only the amount of storage not present in
915 the virtual baseclasses. */
917 int_vbase_size
= TREE_INT_CST_LOW (CLASSTYPE_VBASE_SIZE (basetype
));
918 if (TREE_INT_CST_LOW (TYPE_SIZE (basetype
)) > int_vbase_size
)
920 inc
= MAX (record_align
,
921 (TREE_INT_CST_LOW (TYPE_SIZE (basetype
))
924 /* Record must have at least as much alignment as any field. */
925 desired_align
= TYPE_ALIGN (basetype
);
926 record_align
= MAX (record_align
, desired_align
);
933 CLASSTYPE_SIZE (rec
) = size_int (const_size
);
935 CLASSTYPE_SIZE (rec
) = integer_zero_node
;
936 CLASSTYPE_ALIGN (rec
) = record_align
;
941 /* Hashing of lists so that we don't make duplicates.
942 The entry point is `list_hash_canon'. */
944 /* Each hash table slot is a bucket containing a chain
945 of these structures. */
949 struct list_hash
*next
; /* Next structure in the bucket. */
950 int hashcode
; /* Hash code of this list. */
951 tree list
; /* The list recorded here. */
954 /* Now here is the hash table. When recording a list, it is added
955 to the slot whose index is the hash code mod the table size.
956 Note that the hash table is used for several kinds of lists.
957 While all these live in the same table, they are completely independent,
958 and the hash code is computed differently for each of these. */
960 #define TYPE_HASH_SIZE 59
961 static struct list_hash
*list_hash_table
[TYPE_HASH_SIZE
];
963 /* Compute a hash code for a list (chain of TREE_LIST nodes
964 with goodies in the TREE_PURPOSE, TREE_VALUE, and bits of the
965 TREE_COMMON slots), by adding the hash codes of the individual entries. */
968 list_hash (purpose
, value
, chain
)
969 tree purpose
, value
, chain
;
971 register int hashcode
= 0;
974 hashcode
+= TYPE_HASH (chain
);
977 hashcode
+= TYPE_HASH (value
);
981 hashcode
+= TYPE_HASH (purpose
);
987 /* Look in the type hash table for a type isomorphic to TYPE.
988 If one is found, return it. Otherwise return 0. */
991 list_hash_lookup (hashcode
, via_public
, via_protected
, via_virtual
,
992 purpose
, value
, chain
)
993 int hashcode
, via_public
, via_virtual
, via_protected
;
994 tree purpose
, value
, chain
;
996 register struct list_hash
*h
;
998 for (h
= list_hash_table
[hashcode
% TYPE_HASH_SIZE
]; h
; h
= h
->next
)
999 if (h
->hashcode
== hashcode
1000 && TREE_VIA_VIRTUAL (h
->list
) == via_virtual
1001 && TREE_VIA_PUBLIC (h
->list
) == via_public
1002 && TREE_VIA_PROTECTED (h
->list
) == via_protected
1003 && TREE_PURPOSE (h
->list
) == purpose
1004 && TREE_VALUE (h
->list
) == value
1005 && TREE_CHAIN (h
->list
) == chain
)
1010 /* Add an entry to the list-hash-table
1011 for a list TYPE whose hash code is HASHCODE. */
1014 list_hash_add (hashcode
, list
)
1018 register struct list_hash
*h
;
1020 h
= (struct list_hash
*) obstack_alloc (&class_obstack
, sizeof (struct list_hash
));
1021 h
->hashcode
= hashcode
;
1023 h
->next
= list_hash_table
[hashcode
% TYPE_HASH_SIZE
];
1024 list_hash_table
[hashcode
% TYPE_HASH_SIZE
] = h
;
1027 /* Given TYPE, and HASHCODE its hash code, return the canonical
1028 object for an identical list if one already exists.
1029 Otherwise, return TYPE, and record it as the canonical object
1030 if it is a permanent object.
1032 To use this function, first create a list of the sort you want.
1033 Then compute its hash code from the fields of the list that
1034 make it different from other similar lists.
1035 Then call this function and use the value.
1036 This function frees the list you pass in if it is a duplicate. */
1038 /* Set to 1 to debug without canonicalization. Never set by program. */
1040 static int debug_no_list_hash
= 0;
1043 hash_tree_cons (via_public
, via_virtual
, via_protected
, purpose
, value
, chain
)
1044 int via_public
, via_virtual
, via_protected
;
1045 tree purpose
, value
, chain
;
1047 struct obstack
*ambient_obstack
= current_obstack
;
1051 if (! debug_no_list_hash
)
1053 hashcode
= list_hash (purpose
, value
, chain
);
1054 t
= list_hash_lookup (hashcode
, via_public
, via_protected
, via_virtual
,
1055 purpose
, value
, chain
);
1060 current_obstack
= &class_obstack
;
1062 t
= tree_cons (purpose
, value
, chain
);
1063 TREE_VIA_PUBLIC (t
) = via_public
;
1064 TREE_VIA_PROTECTED (t
) = via_protected
;
1065 TREE_VIA_VIRTUAL (t
) = via_virtual
;
1067 /* If this is a new list, record it for later reuse. */
1068 if (! debug_no_list_hash
)
1069 list_hash_add (hashcode
, t
);
1071 current_obstack
= ambient_obstack
;
1075 /* Constructor for hashed lists. */
1078 hash_tree_chain (value
, chain
)
1081 return hash_tree_cons (0, 0, 0, NULL_TREE
, value
, chain
);
1084 /* Similar, but used for concatenating two lists. */
1087 hash_chainon (list1
, list2
)
1094 if (TREE_CHAIN (list1
) == NULL_TREE
)
1095 return hash_tree_chain (TREE_VALUE (list1
), list2
);
1096 return hash_tree_chain (TREE_VALUE (list1
),
1097 hash_chainon (TREE_CHAIN (list1
), list2
));
1101 get_identifier_list (value
)
1104 tree list
= IDENTIFIER_AS_LIST (value
);
1105 if (list
!= NULL_TREE
1106 && (TREE_CODE (list
) != TREE_LIST
1107 || TREE_VALUE (list
) != value
))
1109 else if (IDENTIFIER_HAS_TYPE_VALUE (value
)
1110 && TREE_CODE (IDENTIFIER_TYPE_VALUE (value
)) == RECORD_TYPE
1111 && IDENTIFIER_TYPE_VALUE (value
)
1112 == TYPE_MAIN_VARIANT (IDENTIFIER_TYPE_VALUE (value
)))
1114 tree type
= IDENTIFIER_TYPE_VALUE (value
);
1116 if (TYPE_PTRMEMFUNC_P (type
))
1118 else if (type
== current_class_type
)
1119 /* Don't mess up the constructor name. */
1120 list
= tree_cons (NULL_TREE
, value
, NULL_TREE
);
1123 if (! CLASSTYPE_ID_AS_LIST (type
))
1124 CLASSTYPE_ID_AS_LIST (type
)
1125 = perm_tree_cons (NULL_TREE
, TYPE_IDENTIFIER (type
), 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 && value
== TYPE_MAIN_VARIANT (value
))
1143 list
= CLASSTYPE_AS_LIST (value
);
1145 if (list
!= NULL_TREE
)
1147 my_friendly_assert (TREE_CHAIN (list
) == NULL_TREE
, 301);
1151 return build_decl_list (NULL_TREE
, value
);
1154 /* Build an association between TYPE and some parameters:
1156 OFFSET is the offset added to `this' to convert it to a pointer
1159 BINFO is the base binfo to use, if we are deriving from one. This
1160 is necessary, as we want specialized parent binfos from base
1161 classes, so that the VTABLE_NAMEs of bases are for the most derived
1162 type, instead of of the simple type.
1164 VTABLE is the virtual function table with which to initialize
1165 sub-objects of type TYPE.
1167 VIRTUALS are the virtual functions sitting in VTABLE.
1169 CHAIN are more associations we must retain. */
1172 make_binfo (offset
, binfo
, vtable
, virtuals
, chain
)
1174 tree vtable
, virtuals
;
1177 tree new_binfo
= make_tree_vec (6);
1180 if (TREE_CODE (binfo
) == TREE_VEC
)
1181 type
= BINFO_TYPE (binfo
);
1185 binfo
= TYPE_BINFO (binfo
);
1188 TREE_CHAIN (new_binfo
) = chain
;
1190 TREE_USED (new_binfo
) = TREE_USED (chain
);
1192 TREE_TYPE (new_binfo
) = TYPE_MAIN_VARIANT (type
);
1193 BINFO_OFFSET (new_binfo
) = offset
;
1194 BINFO_VTABLE (new_binfo
) = vtable
;
1195 BINFO_VIRTUALS (new_binfo
) = virtuals
;
1196 BINFO_VPTR_FIELD (new_binfo
) = NULL_TREE
;
1198 if (binfo
&& BINFO_BASETYPES (binfo
) != NULL_TREE
)
1199 BINFO_BASETYPES (new_binfo
) = copy_node (BINFO_BASETYPES (binfo
));
1203 /* Return the binfo value for ELEM in TYPE. */
1206 binfo_value (elem
, type
)
1210 if (get_base_distance (elem
, type
, 0, (tree
*)0) == -2)
1211 compiler_error ("base class `%s' ambiguous in binfo_value",
1212 TYPE_NAME_STRING (elem
));
1214 return TYPE_BINFO (type
);
1215 if (TREE_CODE (elem
) == RECORD_TYPE
&& TYPE_BINFO (elem
) == type
)
1217 return get_binfo (elem
, type
, 0);
1224 register tree prev
= 0, tmp
, next
;
1225 for (tmp
= path
; tmp
; tmp
= next
)
1227 next
= BINFO_INHERITANCE_CHAIN (tmp
);
1228 BINFO_INHERITANCE_CHAIN (tmp
) = prev
;
1238 unsigned HOST_WIDE_INT n
;
1241 fprintf (stderr
, "type \"%s\"; offset = %d\n",
1242 TYPE_NAME_STRING (BINFO_TYPE (elem
)),
1243 TREE_INT_CST_LOW (BINFO_OFFSET (elem
)));
1244 fprintf (stderr
, "vtable type:\n");
1245 debug_tree (BINFO_TYPE (elem
));
1246 if (BINFO_VTABLE (elem
))
1247 fprintf (stderr
, "vtable decl \"%s\"\n", IDENTIFIER_POINTER (DECL_NAME (BINFO_VTABLE (elem
))));
1249 fprintf (stderr
, "no vtable decl yet\n");
1250 fprintf (stderr
, "virtuals:\n");
1251 virtuals
= BINFO_VIRTUALS (elem
);
1253 n
= skip_rtti_stuff (&virtuals
);
1257 tree fndecl
= TREE_OPERAND (FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (virtuals
)), 0);
1258 fprintf (stderr
, "%s [%d =? %d]\n",
1259 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (fndecl
)),
1260 n
, TREE_INT_CST_LOW (DECL_VINDEX (fndecl
)));
1262 virtuals
= TREE_CHAIN (virtuals
);
1266 /* Return the length of a chain of nodes chained through DECL_CHAIN.
1267 We expect a null pointer to mark the end of the chain.
1268 This is the Lisp primitive `length'. */
1271 decl_list_length (t
)
1275 register int len
= 0;
1277 my_friendly_assert (TREE_CODE (t
) == FUNCTION_DECL
1278 || TREE_CODE (t
) == TEMPLATE_DECL
, 300);
1279 for (tail
= t
; tail
; tail
= DECL_CHAIN (tail
))
1289 if (TREE_CODE (t
) == FUNCTION_DECL
)
1291 else if (TREE_CODE (t
) == TREE_LIST
)
1292 return decl_list_length (TREE_VALUE (t
));
1294 my_friendly_abort (359);
1299 is_overloaded_fn (x
)
1302 if (TREE_CODE (x
) == FUNCTION_DECL
1303 || TREE_CODE (x
) == TEMPLATE_ID_EXPR
1304 || DECL_FUNCTION_TEMPLATE_P (x
))
1307 if (TREE_CODE (x
) == TREE_LIST
1308 && (TREE_CODE (TREE_VALUE (x
)) == FUNCTION_DECL
1309 || DECL_FUNCTION_TEMPLATE_P (TREE_VALUE (x
))))
1316 really_overloaded_fn (x
)
1319 return TREE_CODE (x
) != FUNCTION_DECL
1320 && is_overloaded_fn (x
);
1327 if (TREE_CODE (from
) == FUNCTION_DECL
1328 || TREE_CODE (from
) == TEMPLATE_ID_EXPR
1329 || DECL_FUNCTION_TEMPLATE_P (from
))
1332 my_friendly_assert (TREE_CODE (from
) == TREE_LIST
, 9);
1334 return TREE_VALUE (from
);
1338 is_aggr_type_2 (t1
, t2
)
1341 if (TREE_CODE (t1
) != TREE_CODE (t2
))
1343 return IS_AGGR_TYPE (t1
) && IS_AGGR_TYPE (t2
);
1346 #define PRINT_RING_SIZE 4
1349 lang_printable_name (decl
, v
)
1353 static tree decl_ring
[PRINT_RING_SIZE
];
1354 static char *print_ring
[PRINT_RING_SIZE
];
1355 static int ring_counter
;
1358 /* Only cache functions. */
1360 || TREE_CODE (decl
) != FUNCTION_DECL
1361 || DECL_LANG_SPECIFIC (decl
) == 0)
1362 return lang_decl_name (decl
, v
);
1364 /* See if this print name is lying around. */
1365 for (i
= 0; i
< PRINT_RING_SIZE
; i
++)
1366 if (decl_ring
[i
] == decl
)
1367 /* yes, so return it. */
1368 return print_ring
[i
];
1370 if (++ring_counter
== PRINT_RING_SIZE
)
1373 if (current_function_decl
!= NULL_TREE
)
1375 if (decl_ring
[ring_counter
] == current_function_decl
)
1377 if (ring_counter
== PRINT_RING_SIZE
)
1379 if (decl_ring
[ring_counter
] == current_function_decl
)
1380 my_friendly_abort (106);
1383 if (print_ring
[ring_counter
])
1384 free (print_ring
[ring_counter
]);
1386 print_ring
[ring_counter
] = xstrdup (lang_decl_name (decl
, v
));
1387 decl_ring
[ring_counter
] = decl
;
1388 return print_ring
[ring_counter
];
1391 /* Build the FUNCTION_TYPE or METHOD_TYPE which may throw exceptions
1392 listed in RAISES. */
1395 build_exception_variant (type
, raises
)
1399 tree v
= TYPE_MAIN_VARIANT (type
);
1400 int constp
= TYPE_READONLY (type
);
1401 int volatilep
= TYPE_VOLATILE (type
);
1403 for (; v
; v
= TYPE_NEXT_VARIANT (v
))
1405 if (TYPE_READONLY (v
) != constp
1406 || TYPE_VOLATILE (v
) != volatilep
)
1409 /* @@ This should do set equality, not exact match. */
1410 if (simple_cst_list_equal (TYPE_RAISES_EXCEPTIONS (v
), raises
))
1411 /* List of exceptions raised matches previously found list.
1413 @@ Nice to free up storage used in consing up the
1414 @@ list of exceptions raised. */
1418 /* Need to build a new variant. */
1419 v
= build_type_copy (type
);
1421 if (raises
&& ! TREE_PERMANENT (raises
))
1423 push_obstacks_nochange ();
1424 end_temporary_allocation ();
1425 raises
= copy_list (raises
);
1429 TYPE_RAISES_EXCEPTIONS (v
) = raises
;
1433 /* Given a TEMPLATE_TEMPLATE_PARM node T, create a new one together with its
1434 lang_specific field and its corresponding TEMPLATE_DECL node */
1437 copy_template_template_parm (t
)
1440 tree
template = TYPE_NAME (t
);
1441 tree t2
= make_lang_type (TEMPLATE_TEMPLATE_PARM
);
1442 template = copy_node (template);
1443 copy_lang_decl (template);
1444 TREE_TYPE (template) = t2
;
1445 TYPE_NAME (t2
) = template;
1446 TYPE_STUB_DECL (t2
) = template;
1448 /* No need to copy these */
1449 TYPE_FIELDS (t2
) = TYPE_FIELDS (t
);
1450 CLASSTYPE_TEMPLATE_INFO (t2
) = CLASSTYPE_TEMPLATE_INFO (t
);
1454 /* Subroutine of copy_to_permanent
1456 Assuming T is a node build bottom-up, make it all exist on
1457 permanent obstack, if it is not permanent already. */
1462 tree (*func
) PROTO((tree
));
1469 if (tmp
= func (t
), tmp
!= NULL_TREE
)
1472 switch (TREE_CODE (t
))
1475 return error_mark_node
;
1480 /* Rather than aborting, return error_mark_node. This allows us
1481 to report a sensible error message on code like this:
1483 void g() { int i; f<i>(7); } */
1484 return error_mark_node
;
1488 tree chain
= TREE_CHAIN (t
);
1490 TREE_CHAIN (t
) = mapcar (chain
, func
);
1491 TREE_TYPE (t
) = mapcar (TREE_TYPE (t
), func
);
1492 DECL_INITIAL (t
) = mapcar (DECL_INITIAL (t
), func
);
1493 DECL_SIZE (t
) = mapcar (DECL_SIZE (t
), func
);
1499 tree chain
= TREE_CHAIN (t
);
1501 TREE_PURPOSE (t
) = mapcar (TREE_PURPOSE (t
), func
);
1502 TREE_VALUE (t
) = mapcar (TREE_VALUE (t
), func
);
1503 TREE_CHAIN (t
) = mapcar (chain
, func
);
1509 int len
= TREE_VEC_LENGTH (t
);
1513 TREE_VEC_ELT (t
, len
) = mapcar (TREE_VEC_ELT (t
, len
), func
);
1520 return copy_node (t
);
1524 case AGGR_INIT_EXPR
:
1526 TREE_OPERAND (t
, 0) = mapcar (TREE_OPERAND (t
, 0), func
);
1527 TREE_OPERAND (t
, 1) = mapcar (TREE_OPERAND (t
, 1), func
);
1528 TREE_OPERAND (t
, 2) = mapcar (TREE_OPERAND (t
, 2), func
);
1533 TREE_OPERAND (t
, 0) = mapcar (TREE_OPERAND (t
, 0), func
);
1540 case TRUNC_DIV_EXPR
:
1541 case TRUNC_MOD_EXPR
:
1549 case BIT_ANDTC_EXPR
:
1550 case TRUTH_ANDIF_EXPR
:
1551 case TRUTH_ORIF_EXPR
:
1559 case FLOOR_DIV_EXPR
:
1560 case ROUND_DIV_EXPR
:
1562 case FLOOR_MOD_EXPR
:
1563 case ROUND_MOD_EXPR
:
1565 case PREDECREMENT_EXPR
:
1566 case PREINCREMENT_EXPR
:
1567 case POSTDECREMENT_EXPR
:
1568 case POSTINCREMENT_EXPR
:
1571 case TRY_CATCH_EXPR
:
1572 case WITH_CLEANUP_EXPR
:
1574 TREE_OPERAND (t
, 0) = mapcar (TREE_OPERAND (t
, 0), func
);
1575 TREE_OPERAND (t
, 1) = mapcar (TREE_OPERAND (t
, 1), func
);
1580 TREE_TYPE (t
) = mapcar (TREE_TYPE (t
), func
);
1581 TREE_OPERAND (t
, 0) = mapcar (TREE_OPERAND (t
, 0), func
);
1582 TREE_OPERAND (t
, 1) = mapcar (TREE_OPERAND (t
, 1), func
);
1584 /* tree.def says that operand two is RTL, but
1585 build_call_declarator puts trees in there. */
1586 if (TREE_OPERAND (t
, 2)
1587 && TREE_CODE (TREE_OPERAND (t
, 2)) == TREE_LIST
)
1588 TREE_OPERAND (t
, 2) = mapcar (TREE_OPERAND (t
, 2), func
);
1590 TREE_OPERAND (t
, 2) = NULL_TREE
;
1598 case TRUTH_NOT_EXPR
:
1601 case CLEANUP_POINT_EXPR
:
1603 TREE_OPERAND (t
, 0) = mapcar (TREE_OPERAND (t
, 0), func
);
1607 tmp
= build_pointer_type (mapcar (TREE_TYPE (t
), func
));
1608 return cp_build_type_variant (tmp
, TYPE_READONLY (t
), TYPE_VOLATILE (t
));
1609 case REFERENCE_TYPE
:
1610 tmp
= build_reference_type (mapcar (TREE_TYPE (t
), func
));
1611 return cp_build_type_variant (tmp
, TYPE_READONLY (t
), TYPE_VOLATILE (t
));
1613 tmp
= build_function_type (mapcar (TREE_TYPE (t
), func
),
1614 mapcar (TYPE_ARG_TYPES (t
), func
));
1615 return cp_build_type_variant (tmp
, TYPE_READONLY (t
), TYPE_VOLATILE (t
));
1617 tmp
= build_cplus_array_type (mapcar (TREE_TYPE (t
), func
),
1618 mapcar (TYPE_DOMAIN (t
), func
));
1619 return cp_build_type_variant (tmp
, TYPE_READONLY (t
), TYPE_VOLATILE (t
));
1621 tmp
= build_index_type (mapcar (TYPE_MAX_VALUE (t
), func
));
1622 return cp_build_type_variant (tmp
, TYPE_READONLY (t
), TYPE_VOLATILE (t
));
1624 tmp
= build_offset_type (mapcar (TYPE_OFFSET_BASETYPE (t
), func
),
1625 mapcar (TREE_TYPE (t
), func
));
1626 return cp_build_type_variant (tmp
, TYPE_READONLY (t
), TYPE_VOLATILE (t
));
1628 tmp
= build_cplus_method_type
1629 (mapcar (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (t
))), func
),
1630 mapcar (TREE_TYPE (t
), func
),
1631 mapcar (TREE_CHAIN (TYPE_ARG_TYPES (t
)), func
));
1632 return cp_build_type_variant (tmp
, TYPE_READONLY (t
), TYPE_VOLATILE (t
));
1636 TREE_REALPART (t
) = mapcar (TREE_REALPART (t
), func
);
1637 TREE_IMAGPART (t
) = mapcar (TREE_REALPART (t
), func
);
1642 CONSTRUCTOR_ELTS (t
) = mapcar (CONSTRUCTOR_ELTS (t
), func
);
1645 case TEMPLATE_TEMPLATE_PARM
:
1646 return copy_template_template_parm (t
);
1649 if (TYPE_PTRMEMFUNC_P (t
))
1650 return build_ptrmemfunc_type
1651 (mapcar (TYPE_PTRMEMFUNC_FN_TYPE (t
), func
));
1652 /* else fall through */
1654 /* This list is incomplete, but should suffice for now.
1655 It is very important that `sorry' not call
1656 `report_error_function'. That could cause an infinite loop. */
1658 sorry ("initializer contains unrecognized tree code");
1659 return error_mark_node
;
1662 my_friendly_abort (107);
1671 if (TREE_PERMANENT (t
))
1673 /* Support `void f () { extern int i; A<&i> a; }' */
1674 if ((TREE_CODE (t
) == VAR_DECL
|| TREE_CODE (t
) == FUNCTION_DECL
)
1676 return copy_node (t
);
1680 /* Assuming T is a node built bottom-up, make it all exist on
1681 permanent obstack, if it is not permanent already. */
1684 copy_to_permanent (t
)
1687 register struct obstack
*ambient_obstack
= current_obstack
;
1688 register struct obstack
*ambient_saveable_obstack
= saveable_obstack
;
1689 register struct obstack
*ambient_expression_obstack
= expression_obstack
;
1691 if (t
== NULL_TREE
|| TREE_PERMANENT (t
))
1694 saveable_obstack
= &permanent_obstack
;
1695 current_obstack
= saveable_obstack
;
1696 expression_obstack
= saveable_obstack
;
1698 t
= mapcar (t
, perm_manip
);
1700 current_obstack
= ambient_obstack
;
1701 saveable_obstack
= ambient_saveable_obstack
;
1702 expression_obstack
= ambient_expression_obstack
;
1707 #ifdef GATHER_STATISTICS
1708 extern int depth_reached
;
1712 print_lang_statistics ()
1714 extern struct obstack decl_obstack
;
1715 print_obstack_statistics ("class_obstack", &class_obstack
);
1716 print_obstack_statistics ("decl_obstack", &decl_obstack
);
1717 print_search_statistics ();
1718 print_class_statistics ();
1719 #ifdef GATHER_STATISTICS
1720 fprintf (stderr
, "maximum template instantiation depth reached: %d\n",
1725 /* This is used by the `assert' macro. It is provided in libgcc.a,
1726 which `cc' doesn't know how to link. Note that the C++ front-end
1727 no longer actually uses the `assert' macro (instead, it calls
1728 my_friendly_assert). But all of the back-end files still need this. */
1731 __eprintf (string
, expression
, line
, filename
)
1734 const char *expression
;
1736 const char *filename
;
1744 fprintf (stderr
, string
, expression
, line
, filename
);
1749 /* Return, as an INTEGER_CST node, the number of elements for TYPE
1750 (which is an ARRAY_TYPE). This counts only elements of the top
1754 array_type_nelts_top (type
)
1757 return fold (build (PLUS_EXPR
, sizetype
,
1758 array_type_nelts (type
),
1762 /* Return, as an INTEGER_CST node, the number of elements for TYPE
1763 (which is an ARRAY_TYPE). This one is a recursive count of all
1764 ARRAY_TYPEs that are clumped together. */
1767 array_type_nelts_total (type
)
1770 tree sz
= array_type_nelts_top (type
);
1771 type
= TREE_TYPE (type
);
1772 while (TREE_CODE (type
) == ARRAY_TYPE
)
1774 tree n
= array_type_nelts_top (type
);
1775 sz
= fold (build (MULT_EXPR
, sizetype
, sz
, n
));
1776 type
= TREE_TYPE (type
);
1786 if (TREE_CODE (t
) != TREE_LIST
&& ! TREE_SIDE_EFFECTS (t
))
1788 else if (TREE_CODE (t
) == TARGET_EXPR
)
1790 if (TREE_CODE (TREE_OPERAND (t
, 1)) == AGGR_INIT_EXPR
)
1792 mark_used (TREE_OPERAND (TREE_OPERAND (TREE_OPERAND (t
, 1), 0), 0));
1793 return build_cplus_new
1794 (TREE_TYPE (t
), break_out_target_exprs (TREE_OPERAND (t
, 1)));
1797 TREE_OPERAND (t
, 0) = build (VAR_DECL
, TREE_TYPE (t
));
1798 layout_decl (TREE_OPERAND (t
, 0), 0);
1801 else if (TREE_CODE (t
) == CALL_EXPR
)
1802 mark_used (TREE_OPERAND (TREE_OPERAND (t
, 0), 0));
1807 /* Actually, we'll just clean out the target exprs for the moment. */
1810 break_out_target_exprs (t
)
1813 return mapcar (t
, bot_manip
);
1816 /* Obstack used for allocating nodes in template function and variable
1819 /* Similar to `build_nt', except we build
1820 on the permanent_obstack, regardless. */
1823 build_min_nt
VPROTO((enum tree_code code
, ...))
1826 enum tree_code code
;
1828 register struct obstack
*ambient_obstack
= expression_obstack
;
1831 register int length
;
1837 code
= va_arg (p
, enum tree_code
);
1840 expression_obstack
= &permanent_obstack
;
1842 t
= make_node (code
);
1843 length
= tree_code_length
[(int) code
];
1844 TREE_COMPLEXITY (t
) = lineno
;
1846 for (i
= 0; i
< length
; i
++)
1848 tree x
= va_arg (p
, tree
);
1849 TREE_OPERAND (t
, i
) = copy_to_permanent (x
);
1853 expression_obstack
= ambient_obstack
;
1857 /* Similar to `build', except we build
1858 on the permanent_obstack, regardless. */
1861 build_min
VPROTO((enum tree_code code
, tree tt
, ...))
1864 enum tree_code code
;
1867 register struct obstack
*ambient_obstack
= expression_obstack
;
1870 register int length
;
1876 code
= va_arg (p
, enum tree_code
);
1877 tt
= va_arg (p
, tree
);
1880 expression_obstack
= &permanent_obstack
;
1882 t
= make_node (code
);
1883 length
= tree_code_length
[(int) code
];
1885 TREE_COMPLEXITY (t
) = lineno
;
1887 for (i
= 0; i
< length
; i
++)
1889 tree x
= va_arg (p
, tree
);
1890 TREE_OPERAND (t
, i
) = copy_to_permanent (x
);
1894 expression_obstack
= ambient_obstack
;
1898 /* Same as `tree_cons' but make a permanent object. */
1901 min_tree_cons (purpose
, value
, chain
)
1902 tree purpose
, value
, chain
;
1905 register struct obstack
*ambient_obstack
= current_obstack
;
1906 current_obstack
= &permanent_obstack
;
1908 node
= tree_cons (copy_to_permanent (purpose
),
1909 copy_to_permanent (value
), chain
);
1910 current_obstack
= ambient_obstack
;
1918 if (TREE_CODE (t
) == TYPE_DECL
)
1920 if (TREE_CODE_CLASS (TREE_CODE (t
)) == 't')
1921 return TYPE_STUB_DECL (t
);
1923 my_friendly_abort (42);
1927 can_free (obstack
, t
)
1928 struct obstack
*obstack
;
1933 if (TREE_CODE (t
) == TREE_VEC
)
1934 size
= (TREE_VEC_LENGTH (t
)-1) * sizeof (tree
) + sizeof (struct tree_vec
);
1936 my_friendly_abort (42);
1938 #define ROUND(x) ((x + obstack_alignment_mask (obstack)) \
1939 & ~ obstack_alignment_mask (obstack))
1940 if ((char *)t
+ ROUND (size
) == obstack_next_free (obstack
))
1947 /* Return first vector element whose BINFO_TYPE is ELEM.
1948 Return 0 if ELEM is not in VEC. VEC may be NULL_TREE. */
1951 vec_binfo_member (elem
, vec
)
1957 for (i
= 0; i
< TREE_VEC_LENGTH (vec
); ++i
)
1958 if (comptypes (elem
, BINFO_TYPE (TREE_VEC_ELT (vec
, i
)), 1))
1959 return TREE_VEC_ELT (vec
, i
);
1964 /* Kludge around the fact that DECL_CONTEXT for virtual functions returns
1965 the wrong thing for decl_function_context. Hopefully the uses in the
1966 backend won't matter, since we don't need a static chain for local class
1970 hack_decl_function_context (decl
)
1973 if (TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_FUNCTION_MEMBER_P (decl
))
1974 return decl_function_context (TYPE_MAIN_DECL (DECL_CLASS_CONTEXT (decl
)));
1975 return decl_function_context (decl
);
1978 /* Return truthvalue of whether T1 is the same tree structure as T2.
1979 Return 1 if they are the same.
1980 Return 0 if they are understandably different.
1981 Return -1 if either contains tree structure not understood by
1985 cp_tree_equal (t1
, t2
)
1988 register enum tree_code code1
, code2
;
1993 if (t1
== 0 || t2
== 0)
1996 code1
= TREE_CODE (t1
);
1997 code2
= TREE_CODE (t2
);
1999 if (code1
== NOP_EXPR
|| code1
== CONVERT_EXPR
|| code1
== NON_LVALUE_EXPR
)
2000 if (code2
== NOP_EXPR
|| code2
== CONVERT_EXPR
|| code2
== NON_LVALUE_EXPR
)
2001 return cp_tree_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
2003 return cp_tree_equal (TREE_OPERAND (t1
, 0), t2
);
2004 else if (code2
== NOP_EXPR
|| code2
== CONVERT_EXPR
2005 || code2
== NON_LVALUE_EXPR
)
2006 return cp_tree_equal (t1
, TREE_OPERAND (t2
, 0));
2014 return TREE_INT_CST_LOW (t1
) == TREE_INT_CST_LOW (t2
)
2015 && TREE_INT_CST_HIGH (t1
) == TREE_INT_CST_HIGH (t2
);
2018 return REAL_VALUES_EQUAL (TREE_REAL_CST (t1
), TREE_REAL_CST (t2
));
2021 return TREE_STRING_LENGTH (t1
) == TREE_STRING_LENGTH (t2
)
2022 && !bcmp (TREE_STRING_POINTER (t1
), TREE_STRING_POINTER (t2
),
2023 TREE_STRING_LENGTH (t1
));
2029 return cp_tree_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
2032 cmp
= cp_tree_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
2035 return simple_cst_list_equal (TREE_OPERAND (t1
, 1), TREE_OPERAND (t2
, 1));
2038 /* Special case: if either target is an unallocated VAR_DECL,
2039 it means that it's going to be unified with whatever the
2040 TARGET_EXPR is really supposed to initialize, so treat it
2041 as being equivalent to anything. */
2042 if ((TREE_CODE (TREE_OPERAND (t1
, 0)) == VAR_DECL
2043 && DECL_NAME (TREE_OPERAND (t1
, 0)) == NULL_TREE
2044 && DECL_RTL (TREE_OPERAND (t1
, 0)) == 0)
2045 || (TREE_CODE (TREE_OPERAND (t2
, 0)) == VAR_DECL
2046 && DECL_NAME (TREE_OPERAND (t2
, 0)) == NULL_TREE
2047 && DECL_RTL (TREE_OPERAND (t2
, 0)) == 0))
2050 cmp
= cp_tree_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
2053 return cp_tree_equal (TREE_OPERAND (t1
, 1), TREE_OPERAND (t2
, 1));
2055 case WITH_CLEANUP_EXPR
:
2056 cmp
= cp_tree_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
2059 return cp_tree_equal (TREE_OPERAND (t1
, 2), TREE_OPERAND (t1
, 2));
2062 if (TREE_OPERAND (t1
, 1) == TREE_OPERAND (t2
, 1))
2063 return cp_tree_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
2072 case TEMPLATE_CONST_PARM
:
2073 return TEMPLATE_CONST_IDX (t1
) == TEMPLATE_CONST_IDX (t2
)
2074 && TEMPLATE_CONST_LEVEL (t1
) == TEMPLATE_CONST_LEVEL (t2
);
2077 if (TREE_CODE (TREE_OPERAND (t1
, 0)) != TREE_CODE (TREE_OPERAND (t2
, 0)))
2079 if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (t1
, 0))) == 't')
2080 return comptypes (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0), 1);
2087 switch (TREE_CODE_CLASS (code1
))
2097 for (i
=0; i
<tree_code_length
[(int) code1
]; ++i
)
2099 cmp
= cp_tree_equal (TREE_OPERAND (t1
, i
), TREE_OPERAND (t2
, i
));
2109 /* Similar to make_tree_vec, but build on a temporary obstack. */
2116 register struct obstack
*ambient_obstack
= current_obstack
;
2117 current_obstack
= expression_obstack
;
2118 node
= make_tree_vec (len
);
2119 current_obstack
= ambient_obstack
;
2124 push_expression_obstack ()
2126 push_obstacks_nochange ();
2127 current_obstack
= expression_obstack
;
2130 /* The type of ARG when used as an lvalue. */
2136 return cp_build_type_variant
2137 (TREE_TYPE (arg
), TREE_READONLY (arg
), TREE_THIS_VOLATILE (arg
));
2140 /* The type of ARG for printing error messages; denote lvalues with
2147 tree type
= TREE_TYPE (arg
);
2148 if (TREE_CODE (type
) == ARRAY_TYPE
)
2150 else if (real_lvalue_p (arg
))
2151 type
= build_reference_type (lvalue_type (arg
));
2152 else if (IS_AGGR_TYPE (type
))
2153 type
= lvalue_type (arg
);
2158 /* Does FUNCTION use a variable-length argument list? */
2161 varargs_function_p (function
)
2164 tree parm
= TYPE_ARG_TYPES (TREE_TYPE (function
));
2165 for (; parm
; parm
= TREE_CHAIN (parm
))
2166 if (TREE_VALUE (parm
) == void_type_node
)