1 /* Language-depednent node constructors for parse phase of GNU compiler.
2 Copyright (C) 1987, 1988 Free Software Foundation, Inc.
3 Hacked by Michael Tiemann (tiemann@mcc.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 1, or (at your option)
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
25 #include "cplus-tree.h"
29 #define MAX(x,y) ((x) > (y) ? (x) : (y))
30 #define MIN(x,y) ((x) < (y) ? (x) : (y))
31 #define CEIL(x,y) (((x) + (y) - 1) / (y))
33 /* Return nonzero if REF is an lvalue valid for this language.
34 Lvalues can be assigned, unless they have TREE_READONLY.
35 Lvalues can have their address taken, unless they have TREE_REGDECL. */
41 register enum tree_code code
= TREE_CODE (ref
);
43 if (language_lvalue_valid (ref
))
47 return lvalue_p (TREE_OPERAND (ref
, 0));
53 if (TREE_READONLY (ref
) && ! TREE_STATIC (ref
)
54 && DECL_LANG_SPECIFIC (ref
)
55 && DECL_IN_AGGR_P (ref
))
62 if (TREE_CODE (TREE_TYPE (ref
)) != FUNCTION_TYPE
63 && TREE_CODE (TREE_TYPE (ref
)) != METHOD_TYPE
)
71 if (TREE_CODE (TREE_TYPE (ref
)) == REFERENCE_TYPE
72 /* unary_complex_lvalue knows how to deal with this case. */
73 || TREE_ADDRESSABLE (TREE_TYPE (ref
)))
77 /* A currently unresolved scope ref. */
81 if (TREE_CODE (TREE_OPERAND (ref
, 1)) == FUNCTION_DECL
)
83 if (TREE_CODE (TREE_OPERAND (ref
, 1)) == VAR_DECL
)
84 if (TREE_READONLY (ref
) && ! TREE_STATIC (ref
)
85 && DECL_LANG_SPECIFIC (ref
)
86 && DECL_IN_AGGR_P (ref
))
95 /* Return nonzero if REF is an lvalue valid for this language;
96 otherwise, print an error message and return zero. */
99 lvalue_or_else (ref
, string
)
103 int win
= lvalue_p (ref
);
105 error ("invalid lvalue in %s", string
);
109 /* INIT is a CALL_EXPR which needs info about its target.
110 TYPE is the type that this initialization should appear to have.
112 Build an encapsultation of the initialization to perfom
113 and return it so that it can be processed by language-independent
114 and language-specific expression expanders. */
116 build_cplus_new (type
, init
)
120 tree slot
= build (VAR_DECL
, type
);
121 tree rval
= build (CPLUS_NEW_EXPR
, type
,
122 TREE_OPERAND (init
, 0), TREE_OPERAND (init
, 1), slot
);
123 TREE_ADDRESSABLE (rval
) = 1;
124 rval
= build (NEW_EXPR
, type
, slot
, rval
, 0);
125 TREE_ADDRESSABLE (rval
) = 1;
129 extern struct obstack
*current_obstack
;
130 extern struct obstack permanent_obstack
, class_obstack
;
131 extern struct obstack
*saveable_obstack
;
133 /* Return a type like TYPE except that its CLASSTYPE_OFFSET
136 Such variant types already made are recorded so that duplicates
139 A variant types should never be used as the type of an expression.
140 Use TYPE_MAIN_VARIANT to find the main variant. */
143 build_classtype_variant (type
, offset
, virtualp
)
148 register tree t
, m
= CLASSTYPE_MAIN_VARIANT (type
);
149 register struct obstack
*ambient_obstack
= current_obstack
;
150 register struct obstack
*ambient_saveable_obstack
= saveable_obstack
;
151 register int lo
= TREE_INT_CST_LOW (offset
);
152 register int hi
= TREE_INT_CST_HIGH (offset
);
153 /* First search the chain variants for one that is what we want. */
155 if (hi
== 0 && lo
== 0)
156 offset
= integer_zero_node
;
158 for (t
= m
; t
; t
= CLASSTYPE_NEXT_VARIANT (t
))
159 if (virtualp
== TREE_VIA_VIRTUAL (t
)
160 && lo
== TREE_INT_CST_LOW (CLASSTYPE_OFFSET (t
))
161 && hi
== TREE_INT_CST_HIGH (CLASSTYPE_OFFSET (t
)))
164 /* We need a new one. */
165 if (TREE_PERMANENT (type
))
166 saveable_obstack
= &permanent_obstack
;
167 current_obstack
= saveable_obstack
;
169 t
= copy_node (type
);
170 copy_type_lang_specific (t
);
171 CLASSTYPE_AS_LIST (t
) = build_tree_list (NULL_TREE
, t
);
173 TYPE_POINTER_TO (t
) = 0;
174 TYPE_REFERENCE_TO (t
) = 0;
175 CLASSTYPE_OFFSET (t
) = offset
;
176 TREE_VIA_VIRTUAL (t
) = virtualp
;
178 /* Always promise to have TYPE_POINTER_TO filled in. */
179 build_pointer_type (t
);
181 /* Add this type to the chain of variants of TYPE. */
182 CLASSTYPE_NEXT_VARIANT (t
) = CLASSTYPE_NEXT_VARIANT (m
);
183 CLASSTYPE_NEXT_VARIANT (m
) = t
;
185 current_obstack
= ambient_obstack
;
186 saveable_obstack
= ambient_saveable_obstack
;
190 /* Here is how primitive or already-canonicalized types' hash
191 codes are made. MUST BE CONSISTENT WITH tree.c !!! */
192 #define TYPE_HASH(TYPE) TREE_UID (TYPE)
194 /* Construct, lay out and return the type of methods belonging to class
195 BASETYPE and whose arguments and values are described by TYPE.
196 If that type exists already, reuse it.
197 TYPE must be a FUNCTION_TYPE node. */
200 build_cplus_method_type (basetype
, rettype
, argtypes
)
201 tree basetype
, rettype
, argtypes
;
204 tree ptype
= build_pointer_type (basetype
);
207 /* Make a node of the sort we want. */
208 t
= make_node (METHOD_TYPE
);
210 TYPE_METHOD_BASETYPE (t
) = TYPE_MAIN_VARIANT (basetype
);
211 TREE_TYPE (t
) = rettype
;
212 ptype
= build_type_variant (ptype
, !flag_this_is_variable
, 0);
214 /* The actual arglist for this function includes a "hidden" argument
215 which is "this". Put it into the list of argument types. */
217 TYPE_ARG_TYPES (t
) = tree_cons (NULL
, ptype
, argtypes
);
219 /* If we already have such a type, use the old one and free this one.
220 Note that it also frees up the above cons cell if found. */
221 hashcode
= TYPE_HASH (basetype
) + TYPE_HASH (rettype
) + type_hash_list (argtypes
);
222 t
= type_hash_canon (hashcode
, t
);
224 if (TYPE_SIZE (t
) == 0)
231 build_cplus_array_type (elt_type
, index_type
)
235 register struct obstack
*ambient_obstack
= current_obstack
;
236 register struct obstack
*ambient_saveable_obstack
= saveable_obstack
;
239 /* We need a new one. If ELT_TYPE is permanent, make this permanent too. */
240 if (TREE_PERMANENT (elt_type
))
242 current_obstack
= &permanent_obstack
;
243 saveable_obstack
= &permanent_obstack
;
246 t
= build_array_type (elt_type
, index_type
);
248 /* Push these needs up so that initialization takes place
250 TYPE_NEEDS_CONSTRUCTING (t
) = TYPE_NEEDS_CONSTRUCTING (TYPE_MAIN_VARIANT (elt_type
));
251 TYPE_NEEDS_DESTRUCTOR (t
) = TYPE_NEEDS_DESTRUCTOR (TYPE_MAIN_VARIANT (elt_type
));
252 current_obstack
= ambient_obstack
;
253 saveable_obstack
= ambient_saveable_obstack
;
257 /* This is temporary until later. */
258 /* Construct, lay out and return the type of objects which are of type TYPE
259 as members of type BASETYPE. If that type exists already, reuse it. */
261 build_member_type (basetype
, type
)
267 assert (TREE_CODE (type
) != FUNCTION_TYPE
);
269 /* Make a node of the sort we want. */
270 t
= make_node (OFFSET_TYPE
);
271 TYPE_OFFSET_BASETYPE (t
) = basetype
;
272 TREE_TYPE (t
) = type
;
273 hashcode
= TREE_UID (basetype
) + TREE_UID (type
);
274 t
= type_hash_canon (hashcode
, t
);
279 /* Compute the actual offsets that our virtual base classes
280 will have *for this type*. This must be performed after
281 the fields are laid out, since virtual baseclasses must
282 lay down at the end of the record.
284 Returns the maximum number of virtual functions any of the virtual
285 baseclasses provide. */
287 layout_vbasetypes (rec
, max
)
291 /* Get all the virtual base types that this type uses.
292 The TREE_VALUE slot holds the virtual baseclass type. */
293 tree vbase_types
= get_vbase_types (rec
);
295 #ifdef STRUCTURE_SIZE_BOUNDARY
296 int record_align
= MAX (STRUCTURE_SIZE_BOUNDARY
, TYPE_ALIGN (rec
));
298 int record_align
= MAX (BITS_PER_UNIT
, TYPE_ALIGN (rec
));
301 /* Record size so far is CONST_SIZE + VAR_SIZE * SIZE_UNIT bits,
302 where CONST_SIZE is an integer
303 and VAR_SIZE is a tree expression.
304 If VAR_SIZE is null, the size is just CONST_SIZE.
305 Naturally we try to avoid using VAR_SIZE. */
306 register int const_size
= 0;
307 register tree var_size
= 0;
308 register int size_unit
= BITS_PER_UNIT
;
309 int nonvirtual_const_size
;
310 tree nonvirtual_var_size
;
312 CLASSTYPE_VBASECLASSES (rec
) = vbase_types
;
314 if (TREE_CODE (TYPE_SIZE (rec
)) == INTEGER_CST
)
315 const_size
= TREE_INT_CST_LOW (TYPE_SIZE (rec
)) * TYPE_SIZE_UNIT (rec
);
318 var_size
= TYPE_SIZE (rec
);
319 size_unit
= record_align
;
322 nonvirtual_const_size
= const_size
;
323 nonvirtual_var_size
= var_size
;
328 tree basetype
= ASSOC_TYPE (vbase_types
);
332 offset
= integer_zero_node
;
334 offset
= convert_units (build_int (const_size
), 1, BITS_PER_UNIT
);
336 if (CLASSTYPE_VSIZE (basetype
) > max
)
337 max
= CLASSTYPE_VSIZE (basetype
);
338 ASSOC_OFFSET (vbase_types
) = offset
;
340 inc
= MAX (record_align
,
341 (TREE_INT_CST_LOW (TYPE_SIZE (basetype
))
342 - TREE_INT_CST_LOW (CLASSTYPE_VBASE_SIZE (basetype
)))
343 * TYPE_SIZE_UNIT (basetype
));
346 vbase_types
= TREE_CHAIN (vbase_types
);
349 if (const_size
- nonvirtual_const_size
)
351 CLASSTYPE_VBASE_SIZE (rec
) = convert_units (build_int (const_size
- nonvirtual_const_size
),
353 TYPE_SIZE (rec
) = convert_units (build_int (const_size
), 1, BITS_PER_UNIT
);
356 CLASSTYPE_VBASE_SIZE (rec
) = integer_zero_node
;
361 /* This function should never be needed. */
363 fixup_vbase_offsets (type
)
366 tree virtuals
= TREE_CHAIN (CLASS_ASSOC_VIRTUALS (type
));
370 tree pfn
= FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (virtuals
));
371 tree decl
= TREE_OPERAND (pfn
, 0);
372 tree vcontext
= get_base_type (DECL_VCONTEXT (decl
), DECL_CONTEXT (decl
), 0);
373 if (vcontext
!= NULL_TREE
&& TREE_VIA_VIRTUAL (vcontext
))
376 tree vbase_offset_info
;
379 if (DECL_CONTEXT (decl
) == TYPE_MAIN_VARIANT (type
))
383 parent_type
= get_base_type (DECL_CONTEXT (decl
), type
, 0);
384 if (parent_type
== 0)
387 vbase_offset_info
= value_member (vcontext
,
388 CLASSTYPE_VBASECLASSES (parent_type
));
389 offset
= genop (MINUS_EXPR
, CLASSTYPE_OFFSET (parent_type
),
390 TREE_PURPOSE (vbase_offset_info
));
391 TREE_VALUE (virtuals
) = build_vtable_entry (offset
, pfn
);
393 virtuals
= TREE_CHAIN (virtuals
);
398 /* Lay out the base types of a record type, REC.
399 Tentatively set the size and alignment of REC
400 according to the base types alone.
402 Returns list of virtual base classes in a FIELD_DECL chain. */
404 layout_basetypes (rec
)
407 /* Chain to hold all the new FIELD_DECLs which point at virtual
409 tree vbase_decls
= NULL_TREE
;
411 #ifdef STRUCTURE_SIZE_BOUNDARY
412 int record_align
= MAX (STRUCTURE_SIZE_BOUNDARY
, TYPE_ALIGN (rec
));
414 int record_align
= MAX (BITS_PER_UNIT
, TYPE_ALIGN (rec
));
417 /* Record size so far is CONST_SIZE + VAR_SIZE * SIZE_UNIT bits,
418 where CONST_SIZE is an integer
419 and VAR_SIZE is a tree expression.
420 If VAR_SIZE is null, the size is just CONST_SIZE.
421 Naturally we try to avoid using VAR_SIZE. */
422 register int const_size
= 0;
423 register tree var_size
= 0;
424 register int size_unit
= BITS_PER_UNIT
;
425 int i
, n_baseclasses
= CLASSTYPE_N_BASECLASSES (rec
);
427 /* Handle basetypes almost like fields, but record their
428 offsets differently. */
430 for (i
= 1; i
<= n_baseclasses
; i
++)
432 int inc
, desired_align
;
433 register tree basetype
= CLASSTYPE_BASECLASS (rec
, i
);
436 if (TYPE_SIZE (basetype
) == 0)
438 error_with_aggr_type (basetype
, "base class `%s' has incomplete type");
439 SET_CLASSTYPE_VIAS (rec
, i
, 1, 0);
443 /* All basetypes are recorded in the association list of the
446 if (CLASSTYPE_VIA_VIRTUAL (rec
, i
))
449 char *name
= (char *)alloca (TYPE_NAME_LENGTH (basetype
)
450 + sizeof (VBASE_NAME
) + 1);
451 sprintf (name
, VBASE_NAME_FORMAT
, TYPE_NAME_STRING (basetype
));
453 /* The offset for a virtual base class is only
454 used in computing virtual function tables and
455 for initializing virtual base pointers. The assoc
456 for this base type is built once `get_vbase_types'
458 CLASSTYPE_BASECLASS (rec
, i
) = basetype
459 = build_classtype_variant (basetype
, integer_zero_node
, 1);
461 /* If this basetype can come from another vbase pointer
462 without an additional indirection, we will share
463 that pointer. If an indirection is involved, we
464 make our own pointer. */
465 for (j
= 1; j
<= n_baseclasses
; j
++)
466 if (! CLASSTYPE_VIA_VIRTUAL (rec
, j
)
467 && TYPE_USES_VIRTUAL_BASECLASSES (CLASSTYPE_BASECLASS (rec
, j
))
468 && value_member (TYPE_MAIN_VARIANT (basetype
),
469 CLASSTYPE_VBASECLASSES (CLASSTYPE_BASECLASS (rec
, j
))))
474 decl
= build_lang_decl (FIELD_DECL
, get_identifier (name
),
475 build_pointer_type (basetype
));
476 DECL_FIELD_CONTEXT (decl
) = rec
;
477 SET_DECL_FCONTEXT (decl
, TYPE_MAIN_VARIANT (basetype
));
478 DECL_VBASE_P (decl
) = 1;
479 TREE_CHAIN (decl
) = vbase_decls
;
483 /* The space this decl occupies has already been accounted for. */
492 class_offset
= integer_zero_node
;
495 /* Give each base type the alignment it wants. */
496 const_size
= CEIL (const_size
, TYPE_ALIGN (basetype
))
497 * TYPE_ALIGN (basetype
);
498 class_offset
= convert_units (build_int (const_size
), 1, BITS_PER_UNIT
);
499 CLASSTYPE_BASECLASS (rec
, i
) = basetype
500 = build_classtype_variant (basetype
, class_offset
, 0);
503 if (CLASSTYPE_VSIZE (basetype
))
504 assoc
= make_assoc (class_offset
, basetype
,
505 CLASS_ASSOC_VTABLE (basetype
),
506 CLASS_ASSOC_VIRTUALS (basetype
),
507 CLASSTYPE_ASSOC (rec
));
509 assoc
= make_assoc (class_offset
, basetype
, 0, 0,
510 CLASSTYPE_ASSOC (rec
));
511 CLASSTYPE_ASSOC (rec
) = assoc
;
514 TYPE_NAME (basetype
) = copy_node (TYPE_NAME (basetype
));
515 TREE_TYPE (TYPE_NAME (basetype
)) = basetype
;
516 DECL_OFFSET (TYPE_NAME (basetype
)) = const_size
;
520 /* Add only the amount of storage not present in
521 the virtual baseclasses. */
522 inc
= MAX (record_align
,
523 (TREE_INT_CST_LOW (TYPE_SIZE (basetype
))
524 - TREE_INT_CST_LOW (CLASSTYPE_VBASE_SIZE (basetype
)))
525 * TYPE_SIZE_UNIT (basetype
));
527 /* Record must have at least as much alignment as any field. */
528 desired_align
= TYPE_ALIGN (basetype
);
529 record_align
= MAX (record_align
, desired_align
);
535 CLASSTYPE_SIZE (rec
) = build_int_2 (const_size
, 0);
537 CLASSTYPE_SIZE (rec
) = integer_zero_node
;
538 CLASSTYPE_ALIGN (rec
) = record_align
;
543 /* Hashing of lists so that we don't make duplicates.
544 The entry point is `list_hash_canon'. */
546 /* Each hash table slot is a bucket containing a chain
547 of these structures. */
551 struct list_hash
*next
; /* Next structure in the bucket. */
552 int hashcode
; /* Hash code of this list. */
553 tree list
; /* The list recorded here. */
556 /* Now here is the hash table. When recording a list, it is added
557 to the slot whose index is the hash code mod the table size.
558 Note that the hash table is used for several kinds of lists.
559 While all these live in the same table, they are completely independent,
560 and the hash code is computed differently for each of these. */
562 #define TYPE_HASH_SIZE 59
563 struct list_hash
*list_hash_table
[TYPE_HASH_SIZE
];
565 /* Here is how primitive or already-canonicalized lists' hash
567 #define TYPE_HASH(TYPE) TREE_UID (TYPE)
569 /* Compute a hash code for a list (chain of TREE_LIST nodes
570 with goodies in the TREE_PURPOSE, TREE_VALUE, and bits of the
571 TREE_COMMON slots), by adding the hash codes of the individual entries. */
577 register int hashcode
= 0;
579 if (TREE_CHAIN (list
))
580 hashcode
= TYPE_HASH (TREE_CHAIN (list
));
583 if (TREE_VALUE (list
))
584 hashcode
+= TYPE_HASH (TREE_VALUE (list
));
587 if (TREE_PURPOSE (list
))
588 hashcode
+= TYPE_HASH (TREE_PURPOSE (list
));
594 /* Look in the type hash table for a type isomorphic to TYPE.
595 If one is found, return it. Otherwise return 0. */
598 list_hash_lookup (hashcode
, list
)
602 register struct list_hash
*h
;
603 for (h
= list_hash_table
[hashcode
% TYPE_HASH_SIZE
]; h
; h
= h
->next
)
604 if (h
->hashcode
== hashcode
605 && TREE_VIA_VIRTUAL (h
->list
) == TREE_VIA_VIRTUAL (list
)
606 && TREE_VIA_PUBLIC (h
->list
) == TREE_VIA_PUBLIC (list
)
607 && TREE_PURPOSE (h
->list
) == TREE_PURPOSE (list
)
608 && TREE_VALUE (h
->list
) == TREE_VALUE (list
))
610 assert (TREE_TYPE (h
->list
) == TREE_TYPE (list
));
611 assert (TREE_CHAIN (h
->list
) == TREE_CHAIN (list
));
617 /* Add an entry to the list-hash-table
618 for a list TYPE whose hash code is HASHCODE. */
621 list_hash_add (hashcode
, list
)
625 register struct list_hash
*h
;
627 h
= (struct list_hash
*) obstack_alloc (&class_obstack
, sizeof (struct list_hash
));
628 h
->hashcode
= hashcode
;
630 h
->next
= list_hash_table
[hashcode
% TYPE_HASH_SIZE
];
631 list_hash_table
[hashcode
% TYPE_HASH_SIZE
] = h
;
634 /* Given TYPE, and HASHCODE its hash code, return the canonical
635 object for an identical list if one already exists.
636 Otherwise, return TYPE, and record it as the canonical object
637 if it is a permanent object.
639 To use this function, first create a list of the sort you want.
640 Then compute its hash code from the fields of the list that
641 make it different from other similar lists.
642 Then call this function and use the value.
643 This function frees the list you pass in if it is a duplicate. */
645 /* Set to 1 to debug without canonicalization. Never set by program. */
646 int debug_no_list_hash
= 0;
649 list_hash_canon (hashcode
, list
)
655 if (debug_no_list_hash
)
658 t1
= list_hash_lookup (hashcode
, list
);
661 obstack_free (&class_obstack
, list
);
665 /* If this is a new list, record it for later reuse. */
666 list_hash_add (hashcode
, list
);
672 hash_tree_cons (via_public
, via_virtual
, purpose
, value
, chain
)
673 int via_public
, via_virtual
;
674 tree purpose
, value
, chain
;
676 struct obstack
*ambient_obstack
= current_obstack
;
680 current_obstack
= &class_obstack
;
681 t
= tree_cons (purpose
, value
, chain
);
682 TREE_VIA_PUBLIC (t
) = via_public
;
683 TREE_VIA_VIRTUAL (t
) = via_virtual
;
684 hashcode
= list_hash (t
);
685 t
= list_hash_canon (hashcode
, t
);
686 current_obstack
= ambient_obstack
;
690 /* Constructor for hashed lists. */
692 hash_tree_chain (value
, chain
)
695 struct obstack
*ambient_obstack
= current_obstack
;
699 current_obstack
= &class_obstack
;
700 t
= tree_cons (NULL_TREE
, value
, chain
);
701 hashcode
= list_hash (t
);
702 t
= list_hash_canon (hashcode
, t
);
703 current_obstack
= ambient_obstack
;
707 /* Similar, but used for concatenating two lists. */
709 hash_chainon (list1
, list2
)
716 if (TREE_CHAIN (list1
) == NULL_TREE
)
717 return hash_tree_chain (TREE_VALUE (list1
), list2
);
718 return hash_tree_chain (TREE_VALUE (list1
),
719 hash_chainon (TREE_CHAIN (list1
), list2
));
723 build_decl_list_1 (value
)
726 tree list
= NULL_TREE
;
728 if (TREE_CODE (value
) == IDENTIFIER_NODE
)
730 list
= IDENTIFIER_AS_LIST (value
);
731 if (list
!= NULL_TREE
732 && (TREE_CODE (list
) != TREE_LIST
733 || TREE_VALUE (list
) != value
))
735 else if (TREE_TYPE (value
) != NULL_TREE
736 && TREE_CODE (TREE_TYPE (TREE_TYPE (value
))) == RECORD_TYPE
)
738 tree type
= TREE_TYPE (TREE_TYPE (value
));
739 if (CLASSTYPE_AS_ID_LIST (type
) == NULL_TREE
)
740 CLASSTYPE_AS_ID_LIST (type
) = perm_tree_cons (NULL_TREE
, value
, NULL_TREE
);
741 list
= CLASSTYPE_AS_ID_LIST (type
);
744 else if (TREE_CODE (value
) == RECORD_TYPE
745 && TYPE_LANG_SPECIFIC (value
))
746 list
= CLASSTYPE_AS_LIST (value
);
748 if (list
!= NULL_TREE
)
750 assert (TREE_CHAIN (list
) == NULL_TREE
);
754 return build_decl_list (NULL_TREE
, value
);
757 /* Look in the type hash table for a type isomorphic to
758 `build_tree_list (NULL_TREE, VALUE)'.
759 If one is found, return it. Otherwise return 0. */
762 list_hash_lookup_or_cons (value
)
765 register int hashcode
= TYPE_HASH (value
);
766 register struct list_hash
*h
;
767 struct obstack
*ambient_obstack
;
768 tree list
= NULL_TREE
;
770 if (TREE_CODE (value
) == IDENTIFIER_NODE
)
772 list
= IDENTIFIER_AS_LIST (value
);
773 if (list
!= NULL_TREE
774 && (TREE_CODE (list
) != TREE_LIST
775 || TREE_VALUE (list
) != value
))
777 else if (TREE_TYPE (value
) != NULL_TREE
778 && TREE_CODE (TREE_TYPE (TREE_TYPE (value
))) == RECORD_TYPE
)
780 tree type
= TREE_TYPE (TREE_TYPE (value
));
781 if (CLASSTYPE_AS_ID_LIST (type
) == NULL_TREE
)
782 CLASSTYPE_AS_ID_LIST (type
) = perm_tree_cons (NULL_TREE
, value
, NULL_TREE
);
783 list
= CLASSTYPE_AS_ID_LIST (type
);
786 else if (TREE_CODE (value
) == TYPE_DECL
787 && TREE_CODE (TREE_TYPE (value
)) == RECORD_TYPE
788 && TYPE_LANG_SPECIFIC (TREE_TYPE (value
)))
789 list
= CLASSTYPE_AS_ID_LIST (TREE_TYPE (value
));
790 else if (TREE_CODE (value
) == RECORD_TYPE
791 && TYPE_LANG_SPECIFIC (value
))
792 list
= CLASSTYPE_AS_LIST (value
);
794 if (list
!= NULL_TREE
)
796 assert (TREE_CHAIN (list
) == NULL_TREE
);
800 if (debug_no_list_hash
)
801 return hash_tree_chain (value
, NULL_TREE
);
803 for (h
= list_hash_table
[hashcode
% TYPE_HASH_SIZE
]; h
; h
= h
->next
)
804 if (h
->hashcode
== hashcode
805 && TREE_VIA_VIRTUAL (h
->list
) == 0
806 && TREE_VIA_PUBLIC (h
->list
) == 0
807 && TREE_PURPOSE (h
->list
) == 0
808 && TREE_VALUE (h
->list
) == value
)
810 assert (TREE_TYPE (h
->list
) == 0);
811 assert (TREE_CHAIN (h
->list
) == 0);
815 ambient_obstack
= current_obstack
;
816 current_obstack
= &class_obstack
;
817 list
= build_tree_list (NULL_TREE
, value
);
818 list_hash_add (hashcode
, list
);
819 current_obstack
= ambient_obstack
;
823 /* Build an association between TYPE and some parameters:
825 OFFSET is the offset added to `this' to convert it to a pointer
828 VTABLE is the virtual function table with which to initialize
829 sub-objects of type TYPE.
831 VIRTUALS are the virtual functions sitting in VTABLE.
833 CHAIN are more associations we must retain. */
836 make_assoc (offset
, type
, vtable
, virtuals
, chain
)
838 tree vtable
, virtuals
;
841 tree assoc
= make_tree_vec (4);
843 TREE_TYPE (assoc
) = type
;
844 TREE_CHAIN (assoc
) = chain
;
846 TREE_USED (assoc
) = TREE_USED (chain
);
848 /* n.b.: TREE_VEC_ELT (assoc, 0) <=> TREE_VALUE (assoc). */
849 TREE_VEC_ELT (assoc
, 0) = TYPE_MAIN_VARIANT (type
);
850 TREE_VEC_ELT (assoc
, 1) = offset
;
851 TREE_VEC_ELT (assoc
, 2) = vtable
;
852 TREE_VEC_ELT (assoc
, 3) = virtuals
;
860 tree assoc
= copy_list (list
);
864 TREE_USED (assoc
) = 0;
865 assoc
= TREE_CHAIN (assoc
);
871 assoc_value (elem
, type
)
875 tree assoc
= CLASSTYPE_ASSOC (type
);
876 tree rval
= NULL_TREE
;
878 /* Dispose quickly of degenerate case. */
884 if (elem
== ASSOC_VALUE (assoc
))
885 /* If we find it on the main spine, then
886 there can be no ambiguity. */
889 if (ASSOC_VALUE (assoc
) != type
)
891 tree nval
= assoc_value (elem
, ASSOC_TYPE (assoc
));
894 if (rval
&& ASSOC_TYPE (rval
) != ASSOC_TYPE (nval
))
895 /* If we find it underneath, we must make sure that
896 there are no two ways to do it. */
897 compiler_error ("base class `%s' ambiguous in assoc_value",
898 TYPE_NAME_STRING (elem
));
902 assoc
= TREE_CHAIN (assoc
);
908 virtual_member (elem
, list
)
915 for (t
= list
; t
; t
= TREE_CHAIN (t
))
916 if (elem
== TREE_VALUE (t
))
919 for (t
= list
; t
; t
= TREE_CHAIN (t
))
922 for (i
= CLASSTYPE_N_BASECLASSES (TREE_TYPE (t
)); i
> 0; i
--)
924 nval
= assoc_value (elem
, CLASSTYPE_BASECLASS (TREE_TYPE (t
), i
));
927 if (rval
&& TREE_TYPE (nval
) != TREE_TYPE (rval
))
937 debug_dump_assoc (elem
)
943 fprintf (stderr
, "type \"%s\"; offset = %d\n",
944 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (ASSOC_VALUE (elem
)))),
945 TREE_INT_CST_LOW (ASSOC_OFFSET (elem
)));
946 fprintf (stderr
, "vtable type:\n");
947 dump_tree (stderr
, ASSOC_TYPE (elem
));
948 if (ASSOC_VTABLE (elem
))
949 fprintf (stderr
, "vtable decl \"%s\"\n", IDENTIFIER_POINTER (DECL_NAME (ASSOC_VTABLE (elem
))));
951 fprintf (stderr
, "no vtable decl yet\n");
952 fprintf (stderr
, "virtuals:\n");
953 virtuals
= ASSOC_VIRTUALS (elem
);
955 virtuals
= TREE_CHAIN (virtuals
);
959 tree fndecl
= TREE_OPERAND (FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (virtuals
)), 0);
960 fprintf (stderr
, "%s [%d =? %d]\n",
961 IDENTIFIER_POINTER (DECL_NAME (fndecl
)),
962 i
, TREE_INT_CST_LOW (DECL_VINDEX (fndecl
)));
963 virtuals
= TREE_CHAIN (virtuals
);
969 lang_printable_name (decl
)
972 if (TREE_CODE (decl
) != FUNCTION_DECL
973 || DECL_LANG_SPECIFIC (decl
) == 0)
975 if (DECL_NAME (decl
))
977 if (THIS_NAME_P (DECL_NAME (decl
)))
979 return IDENTIFIER_POINTER (DECL_NAME (decl
));
981 return "((anonymous))";
983 if (DECL_PRINT_NAME (decl
) == 0)
986 = (!DECL_CONSTRUCTOR_P (decl
)
987 && !DESTRUCTOR_NAME_P (DECL_NAME (decl
)));
988 int temp
= allocation_temporary_p ();
989 char *buf
= (char *)alloca (8192);
990 char *name
= (char *)fndecl_as_string (buf
, 0, decl
, print_ret_type_p
);
991 end_temporary_allocation ();
992 DECL_PRINT_NAME (decl
) = oballoc (strlen (name
) + 1);
993 strcpy (DECL_PRINT_NAME (decl
), name
);
995 resume_temporary_allocation ();
997 else if (DECL_NAME (decl
) == 0)
998 DECL_PRINT_NAME (decl
) = "((anonymous))";
1000 return DECL_PRINT_NAME (decl
);
1003 /* Return truthvalue about whether debugger should
1004 output full info about this type or not.
1006 Current strategy is to permit types which define
1007 no member functions to be output normally. For
1008 those which do define member functions, if no
1009 member functions have yet been output, then don't
1010 output the definition of the type. If member functions
1011 for the type are later seen, a full definition of the
1012 type will eventually be output. */
1014 lang_output_debug_info (type
)
1017 extern tree pending_vtables
;
1019 if (! IS_AGGR_TYPE (type
))
1021 if (TYPE_LANG_SPECIFIC (type
) == 0)
1023 if (CLASSTYPE_METHOD_VEC (type
) == 0)
1026 if (flag_minimal_debug
)
1028 /* Don't output full info about any type
1029 which does not have its implementation defined here. */
1030 if (TYPE_VIRTUAL_P (type
) && write_virtuals
== 2)
1031 return value_member (DECL_NAME (TYPE_NAME (type
)), pending_vtables
) != 0;
1032 if (CLASSTYPE_INTERFACE_ONLY (type
))
1035 return CLASSTYPE_ASM_WRITTEN (type
);
1038 /* Can't work until GDB is modified. */
1042 /* Comparison function for sorting identifiers in RAISES lists.
1043 Note that because IDENTIFIER_NODEs are unique, we can sort
1044 them by address, saving an indirection. */
1052 /* Build the FUNCTION_TYPE or METHOD_TYPE which may raise exceptions
1053 listed in RAISES. */
1055 build_exception_variant (ctype
, type
, raises
)
1060 tree v
= TYPE_MAIN_VARIANT (type
);
1062 tree
*a
= (tree
*)alloca ((list_length (raises
)+1) * sizeof (tree
));
1063 int constp
= TREE_READONLY (type
);
1064 int volatilep
= TREE_VOLATILE (type
);
1066 if (raises
&& TREE_CHAIN (raises
))
1068 for (i
= 0, t
= raises
; t
; t
= TREE_CHAIN (t
), i
++)
1070 /* NULL terminator for list. */
1072 qsort (a
, i
, sizeof (tree
), id_cmp
);
1074 TREE_CHAIN (a
[i
]) = a
[i
+1];
1080 return build_type_variant (v
, constp
, volatilep
);
1084 cname
= TYPE_NAME (ctype
);
1085 if (TREE_CODE (cname
) == TYPE_DECL
)
1086 cname
= DECL_NAME (cname
);
1091 for (t
= raises
; t
; t
= TREE_CHAIN (t
))
1093 /* See that all the exceptions we are thinking about
1094 raising have been declared. */
1095 tree this_cname
= lookup_exception_cname (ctype
, cname
, t
);
1096 tree decl
= lookup_exception_object (this_cname
, TREE_VALUE (t
), 1);
1098 if (decl
== NULL_TREE
)
1099 decl
= lookup_exception_object (this_cname
, TREE_VALUE (t
), 0);
1100 /* Place canonical exception decl into TREE_TYPE of RAISES list. */
1101 TREE_TYPE (t
) = decl
;
1104 for (v
= TYPE_NEXT_VARIANT (v
); v
; v
= TYPE_NEXT_VARIANT (v
))
1106 if (TREE_READONLY (v
) != constp
1107 || TREE_VOLATILE (v
) != volatilep
)
1111 t2
= TYPE_RAISES_EXCEPTIONS (v
);
1114 if (TREE_TYPE (t
) == TREE_TYPE (t2
))
1117 t2
= TREE_CHAIN (t2
);
1123 /* List of exceptions raised matches previously found list.
1125 @@ Nice to free up storage used in consing up the
1126 @@ list of exceptions raised. */
1130 /* Need to build a new variant. */
1131 v
= copy_node (type
);
1132 TYPE_NEXT_VARIANT (v
) = TYPE_NEXT_VARIANT (type
);
1133 TYPE_NEXT_VARIANT (type
) = v
;
1134 if (raises
&& ! TREE_PERMANENT (raises
))
1136 int temporary
= allocation_temporary_p ();
1138 end_temporary_allocation ();
1139 raises
= copy_list (raises
);
1141 resume_temporary_allocation ();
1143 TYPE_RAISES_EXCEPTIONS (v
) = raises
;
1147 /* Subroutine of make_permanent_node.
1149 Assuming T is a node build bottom-up, make it all exist on
1150 permanent obstack, if it is not permanent already. */
1155 enum tree_code code
;
1157 if (t
== NULL_TREE
|| TREE_PERMANENT (t
))
1160 switch (code
= TREE_CODE (t
))
1163 return error_mark_node
;
1173 tree chain
= TREE_CHAIN (t
);
1175 TREE_PURPOSE (t
) = make_deep_copy (TREE_PURPOSE (t
));
1176 TREE_VALUE (t
) = make_deep_copy (TREE_VALUE (t
));
1177 TREE_CHAIN (t
) = make_deep_copy (chain
);
1183 int len
= TREE_VEC_LENGTH (t
);
1187 TREE_VEC_ELT (t
, len
) = make_deep_copy (TREE_VEC_ELT (t
, len
));
1194 return copy_node (t
);
1199 TREE_OPERAND (t
, 0) = make_deep_copy (TREE_OPERAND (t
, 0));
1200 TREE_OPERAND (t
, 1) = make_deep_copy (TREE_OPERAND (t
, 1));
1201 TREE_OPERAND (t
, 2) = make_deep_copy (TREE_OPERAND (t
, 2));
1206 TREE_OPERAND (t
, 0) = make_deep_copy (TREE_OPERAND (t
, 0));
1213 case TRUNC_DIV_EXPR
:
1214 case TRUNC_MOD_EXPR
:
1222 case BIT_ANDTC_EXPR
:
1223 case TRUTH_ANDIF_EXPR
:
1224 case TRUTH_ORIF_EXPR
:
1232 case FLOOR_DIV_EXPR
:
1233 case ROUND_DIV_EXPR
:
1235 case FLOOR_MOD_EXPR
:
1236 case ROUND_MOD_EXPR
:
1238 case PREDECREMENT_EXPR
:
1239 case PREINCREMENT_EXPR
:
1240 case POSTDECREMENT_EXPR
:
1241 case POSTINCREMENT_EXPR
:
1244 TREE_OPERAND (t
, 0) = make_deep_copy (TREE_OPERAND (t
, 0));
1245 TREE_OPERAND (t
, 1) = make_deep_copy (TREE_OPERAND (t
, 1));
1253 case TRUTH_NOT_EXPR
:
1257 TREE_OPERAND (t
, 0) = make_deep_copy (TREE_OPERAND (t
, 0));
1260 /* This list is incomplete, but should suffice for now.
1261 It is very important that `sorry' does not call
1262 `report_error_function'. That could cause an infinite loop. */
1264 sorry ("initializer contains unrecognized tree code");
1265 return error_mark_node
;
1271 /* Assuming T is a node built bottom-up, make it all exist on
1272 permanent obstack, if it is not permanent already. */
1274 copy_to_permanent (t
)
1277 register struct obstack
*ambient_obstack
= current_obstack
;
1278 register struct obstack
*ambient_saveable_obstack
= saveable_obstack
;
1280 if (t
== NULL_TREE
|| TREE_PERMANENT (t
))
1283 saveable_obstack
= &permanent_obstack
;
1284 current_obstack
= saveable_obstack
;
1286 t
= make_deep_copy (t
);
1288 current_obstack
= ambient_obstack
;
1289 saveable_obstack
= ambient_saveable_obstack
;
1295 lang_simple_cst_equal (t1
, t2
)
1298 register enum tree_code code1
, code2
;
1303 if (t1
== 0 || t2
== 0)
1306 code1
= TREE_CODE (t1
);
1307 code2
= TREE_CODE (t2
);
1311 case CPLUS_NEW_EXPR
:
1312 cmp
= simple_cst_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
1315 return simple_cst_list_equal (TREE_OPERAND (t1
, 1), TREE_OPERAND (t2
, 1));