]> gcc.gnu.org Git - gcc.git/blame - gcc/cp/tree.c
except.c: Remove register_exception_table{,_p}.
[gcc.git] / gcc / cp / tree.c
CommitLineData
8d08fdba 1/* Language-dependent node constructors for parse phase of GNU compiler.
357a4089 2 Copyright (C) 1987, 88, 92, 93, 94, 95, 1996 Free Software Foundation, Inc.
8d08fdba
MS
3 Hacked by Michael Tiemann (tiemann@cygnus.com)
4
5This file is part of GNU CC.
6
7GNU CC is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2, or (at your option)
10any later version.
11
12GNU CC is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GNU CC; see the file COPYING. If not, write to
e9fa0c7c
RK
19the Free Software Foundation, 59 Temple Place - Suite 330,
20Boston, MA 02111-1307, USA. */
8d08fdba
MS
21
22#include "config.h"
23#include <stdio.h>
24#include "obstack.h"
25#include "tree.h"
26#include "cp-tree.h"
27#include "flags.h"
28cbf42c 28#include "rtl.h"
5566b478
MS
29#ifdef __STDC__
30#include <stdarg.h>
31#else
32#include <varargs.h>
33#endif
8d08fdba 34
9f617717
L
35#ifdef HAVE_STDLIB_H
36#include <stdlib.h>
37#endif
38
39#ifdef NEED_DECLARATION_FREE
40extern void free PROTO((void *));
41#endif
42
49c249e1
JM
43extern void compiler_error ();
44
45static tree get_identifier_list PROTO((tree));
46static tree bot_manip PROTO((tree));
47static tree perm_manip PROTO((tree));
48static tree build_cplus_array_type_1 PROTO((tree, tree));
49static void list_hash_add PROTO((int, tree));
50static int list_hash PROTO((tree, tree, tree));
51static tree list_hash_lookup PROTO((int, int, int, int, tree, tree,
52 tree));
53
8d08fdba
MS
54#define CEIL(x,y) (((x) + (y) - 1) / (y))
55
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. */
59
8ccc31eb
MS
60int
61real_lvalue_p (ref)
62 tree ref;
63{
64 if (! language_lvalue_valid (ref))
65 return 0;
66
67 if (TREE_CODE (TREE_TYPE (ref)) == REFERENCE_TYPE)
68 return 1;
69
4ac14744 70 if (ref == current_class_ptr && flag_this_is_variable <= 0)
8ccc31eb
MS
71 return 0;
72
73 switch (TREE_CODE (ref))
74 {
75 /* preincrements and predecrements are valid lvals, provided
e92cc029 76 what they refer to are valid lvals. */
8ccc31eb
MS
77 case PREINCREMENT_EXPR:
78 case PREDECREMENT_EXPR:
79 case COMPONENT_REF:
80 case SAVE_EXPR:
c7ae64f2
JM
81 case UNSAVE_EXPR:
82 case TRY_CATCH_EXPR:
83 case WITH_CLEANUP_EXPR:
8ccc31eb
MS
84 return real_lvalue_p (TREE_OPERAND (ref, 0));
85
86 case STRING_CST:
87 return 1;
88
89 case VAR_DECL:
90 if (TREE_READONLY (ref) && ! TREE_STATIC (ref)
91 && DECL_LANG_SPECIFIC (ref)
92 && DECL_IN_AGGR_P (ref))
93 return 0;
94 case INDIRECT_REF:
95 case ARRAY_REF:
96 case PARM_DECL:
97 case RESULT_DECL:
98 case ERROR_MARK:
99 if (TREE_CODE (TREE_TYPE (ref)) != FUNCTION_TYPE
100 && TREE_CODE (TREE_TYPE (ref)) != METHOD_TYPE)
101 return 1;
102 break;
103
8ccc31eb
MS
104 /* A currently unresolved scope ref. */
105 case SCOPE_REF:
106 my_friendly_abort (103);
107 case OFFSET_REF:
108 if (TREE_CODE (TREE_OPERAND (ref, 1)) == FUNCTION_DECL)
109 return 1;
110 return real_lvalue_p (TREE_OPERAND (ref, 0))
111 && real_lvalue_p (TREE_OPERAND (ref, 1));
112 break;
113
114 case COND_EXPR:
115 return (real_lvalue_p (TREE_OPERAND (ref, 1))
116 && real_lvalue_p (TREE_OPERAND (ref, 2)));
117
118 case MODIFY_EXPR:
119 return 1;
120
121 case COMPOUND_EXPR:
122 return real_lvalue_p (TREE_OPERAND (ref, 1));
123
124 case MAX_EXPR:
125 case MIN_EXPR:
126 return (real_lvalue_p (TREE_OPERAND (ref, 0))
127 && real_lvalue_p (TREE_OPERAND (ref, 1)));
128 }
129
130 return 0;
131}
132
eb66be0e
MS
133/* This differs from real_lvalue_p in that class rvalues are considered
134 lvalues. */
8d08fdba
MS
135int
136lvalue_p (ref)
137 tree ref;
138{
a292b002
MS
139 if (! language_lvalue_valid (ref))
140 return 0;
141
142 if (TREE_CODE (TREE_TYPE (ref)) == REFERENCE_TYPE)
143 return 1;
8d08fdba 144
4ac14744 145 if (ref == current_class_ptr && flag_this_is_variable <= 0)
a292b002
MS
146 return 0;
147
148 switch (TREE_CODE (ref))
39211cd5 149 {
a292b002 150 /* preincrements and predecrements are valid lvals, provided
e92cc029 151 what they refer to are valid lvals. */
a292b002
MS
152 case PREINCREMENT_EXPR:
153 case PREDECREMENT_EXPR:
37c46b43
MS
154 case REALPART_EXPR:
155 case IMAGPART_EXPR:
a292b002
MS
156 case COMPONENT_REF:
157 case SAVE_EXPR:
c7ae64f2
JM
158 case UNSAVE_EXPR:
159 case TRY_CATCH_EXPR:
160 case WITH_CLEANUP_EXPR:
a292b002
MS
161 return lvalue_p (TREE_OPERAND (ref, 0));
162
163 case STRING_CST:
164 return 1;
165
166 case VAR_DECL:
167 if (TREE_READONLY (ref) && ! TREE_STATIC (ref)
168 && DECL_LANG_SPECIFIC (ref)
169 && DECL_IN_AGGR_P (ref))
170 return 0;
171 case INDIRECT_REF:
172 case ARRAY_REF:
173 case PARM_DECL:
174 case RESULT_DECL:
175 case ERROR_MARK:
176 if (TREE_CODE (TREE_TYPE (ref)) != FUNCTION_TYPE
177 && TREE_CODE (TREE_TYPE (ref)) != METHOD_TYPE)
8d08fdba 178 return 1;
a292b002 179 break;
39211cd5 180
a292b002
MS
181 case TARGET_EXPR:
182 return 1;
39211cd5 183
a292b002 184 case CALL_EXPR:
e8abc66f 185 if (IS_AGGR_TYPE (TREE_TYPE (ref)))
a292b002
MS
186 return 1;
187 break;
2986ae00 188
a292b002
MS
189 /* A currently unresolved scope ref. */
190 case SCOPE_REF:
191 my_friendly_abort (103);
192 case OFFSET_REF:
193 if (TREE_CODE (TREE_OPERAND (ref, 1)) == FUNCTION_DECL)
194 return 1;
195 return lvalue_p (TREE_OPERAND (ref, 0))
196 && lvalue_p (TREE_OPERAND (ref, 1));
197 break;
198
199 case COND_EXPR:
200 return (lvalue_p (TREE_OPERAND (ref, 1))
201 && lvalue_p (TREE_OPERAND (ref, 2)));
202
203 case MODIFY_EXPR:
204 return 1;
205
206 case COMPOUND_EXPR:
207 return lvalue_p (TREE_OPERAND (ref, 1));
e1cd6e56
MS
208
209 case MAX_EXPR:
210 case MIN_EXPR:
211 return (lvalue_p (TREE_OPERAND (ref, 0))
212 && lvalue_p (TREE_OPERAND (ref, 1)));
39211cd5 213 }
a292b002 214
8d08fdba
MS
215 return 0;
216}
217
218/* Return nonzero if REF is an lvalue valid for this language;
219 otherwise, print an error message and return zero. */
220
221int
222lvalue_or_else (ref, string)
223 tree ref;
224 char *string;
225{
226 int win = lvalue_p (ref);
227 if (! win)
2986ae00 228 error ("non-lvalue in %s", string);
8d08fdba
MS
229 return win;
230}
231
232/* INIT is a CALL_EXPR which needs info about its target.
233 TYPE is the type that this initialization should appear to have.
234
235 Build an encapsulation of the initialization to perform
236 and return it so that it can be processed by language-independent
2ee887f2 237 and language-specific expression expanders. */
e92cc029 238
8d08fdba 239tree
5566b478 240build_cplus_new (type, init)
8d08fdba
MS
241 tree type;
242 tree init;
8d08fdba 243{
e8abc66f
MS
244 tree slot;
245 tree rval;
246
02531345 247 if (TREE_CODE (init) != CALL_EXPR && TREE_CODE (init) != AGGR_INIT_EXPR)
c11b6f21
MS
248 return init;
249
e8abc66f 250 slot = build (VAR_DECL, type);
aa36c081 251 DECL_ARTIFICIAL (slot) = 1;
e8abc66f 252 layout_decl (slot, 0);
02531345 253 rval = build (AGGR_INIT_EXPR, type,
e8abc66f 254 TREE_OPERAND (init, 0), TREE_OPERAND (init, 1), slot);
8d08fdba 255 TREE_SIDE_EFFECTS (rval) = 1;
e349ee73 256 rval = build (TARGET_EXPR, type, slot, rval, NULL_TREE, NULL_TREE);
8d08fdba 257 TREE_SIDE_EFFECTS (rval) = 1;
8d08fdba 258
8d08fdba
MS
259 return rval;
260}
261
aa36c081
JM
262/* Encapsulate the expression INIT in a TARGET_EXPR. */
263
264tree
265get_target_expr (init)
266 tree init;
267{
268 tree slot;
269 tree rval;
270
271 slot = build (VAR_DECL, TREE_TYPE (init));
272 DECL_ARTIFICIAL (slot) = 1;
273 layout_decl (slot, 0);
274 rval = build (TARGET_EXPR, TREE_TYPE (init), slot, init,
275 NULL_TREE, NULL_TREE);
276 TREE_SIDE_EFFECTS (rval) = 1;
277
278 return rval;
279}
280
8d08fdba
MS
281/* Recursively search EXP for CALL_EXPRs that need cleanups and replace
282 these CALL_EXPRs with tree nodes that will perform the cleanups. */
283
284tree
285break_out_cleanups (exp)
286 tree exp;
287{
288 tree tmp = exp;
289
290 if (TREE_CODE (tmp) == CALL_EXPR
291 && TYPE_NEEDS_DESTRUCTOR (TREE_TYPE (tmp)))
5566b478 292 return build_cplus_new (TREE_TYPE (tmp), tmp);
8d08fdba
MS
293
294 while (TREE_CODE (tmp) == NOP_EXPR
295 || TREE_CODE (tmp) == CONVERT_EXPR
296 || TREE_CODE (tmp) == NON_LVALUE_EXPR)
297 {
298 if (TREE_CODE (TREE_OPERAND (tmp, 0)) == CALL_EXPR
299 && TYPE_NEEDS_DESTRUCTOR (TREE_TYPE (TREE_OPERAND (tmp, 0))))
300 {
301 TREE_OPERAND (tmp, 0)
302 = build_cplus_new (TREE_TYPE (TREE_OPERAND (tmp, 0)),
5566b478 303 TREE_OPERAND (tmp, 0));
8d08fdba
MS
304 break;
305 }
306 else
307 tmp = TREE_OPERAND (tmp, 0);
308 }
309 return exp;
310}
311
312/* Recursively perform a preorder search EXP for CALL_EXPRs, making
313 copies where they are found. Returns a deep copy all nodes transitively
314 containing CALL_EXPRs. */
315
316tree
317break_out_calls (exp)
318 tree exp;
319{
320 register tree t1, t2;
321 register enum tree_code code;
322 register int changed = 0;
323 register int i;
324
325 if (exp == NULL_TREE)
326 return exp;
327
328 code = TREE_CODE (exp);
329
330 if (code == CALL_EXPR)
331 return copy_node (exp);
332
e92cc029 333 /* Don't try and defeat a save_expr, as it should only be done once. */
8d08fdba
MS
334 if (code == SAVE_EXPR)
335 return exp;
336
337 switch (TREE_CODE_CLASS (code))
338 {
339 default:
340 abort ();
341
342 case 'c': /* a constant */
343 case 't': /* a type node */
344 case 'x': /* something random, like an identifier or an ERROR_MARK. */
345 return exp;
346
347 case 'd': /* A decl node */
f376e137
MS
348#if 0 /* This is bogus. jason 9/21/94 */
349
8d08fdba
MS
350 t1 = break_out_calls (DECL_INITIAL (exp));
351 if (t1 != DECL_INITIAL (exp))
352 {
353 exp = copy_node (exp);
354 DECL_INITIAL (exp) = t1;
355 }
f376e137 356#endif
8d08fdba
MS
357 return exp;
358
359 case 'b': /* A block node */
360 {
361 /* Don't know how to handle these correctly yet. Must do a
362 break_out_calls on all DECL_INITIAL values for local variables,
363 and also break_out_calls on all sub-blocks and sub-statements. */
364 abort ();
365 }
366 return exp;
367
368 case 'e': /* an expression */
369 case 'r': /* a reference */
370 case 's': /* an expression with side effects */
371 for (i = tree_code_length[(int) code] - 1; i >= 0; i--)
372 {
373 t1 = break_out_calls (TREE_OPERAND (exp, i));
374 if (t1 != TREE_OPERAND (exp, i))
375 {
376 exp = copy_node (exp);
377 TREE_OPERAND (exp, i) = t1;
378 }
379 }
380 return exp;
381
382 case '<': /* a comparison expression */
383 case '2': /* a binary arithmetic expression */
384 t2 = break_out_calls (TREE_OPERAND (exp, 1));
385 if (t2 != TREE_OPERAND (exp, 1))
386 changed = 1;
387 case '1': /* a unary arithmetic expression */
388 t1 = break_out_calls (TREE_OPERAND (exp, 0));
389 if (t1 != TREE_OPERAND (exp, 0))
390 changed = 1;
391 if (changed)
392 {
393 if (tree_code_length[(int) code] == 1)
394 return build1 (code, TREE_TYPE (exp), t1);
395 else
396 return build (code, TREE_TYPE (exp), t1, t2);
397 }
398 return exp;
399 }
400
401}
402\f
403extern struct obstack *current_obstack;
404extern struct obstack permanent_obstack, class_obstack;
405extern struct obstack *saveable_obstack;
5156628f 406extern struct obstack *expression_obstack;
8d08fdba
MS
407
408/* Here is how primitive or already-canonicalized types' hash
409 codes are made. MUST BE CONSISTENT WITH tree.c !!! */
410#define TYPE_HASH(TYPE) ((HOST_WIDE_INT) (TYPE) & 0777777)
411
412/* Construct, lay out and return the type of methods belonging to class
413 BASETYPE and whose arguments are described by ARGTYPES and whose values
414 are described by RETTYPE. If each type exists already, reuse it. */
e92cc029 415
8d08fdba
MS
416tree
417build_cplus_method_type (basetype, rettype, argtypes)
418 tree basetype, rettype, argtypes;
419{
420 register tree t;
421 tree ptype;
422 int hashcode;
423
424 /* Make a node of the sort we want. */
425 t = make_node (METHOD_TYPE);
426
427 TYPE_METHOD_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype);
428 TREE_TYPE (t) = rettype;
429 if (IS_SIGNATURE (basetype))
430 ptype = build_signature_pointer_type (TYPE_MAIN_VARIANT (basetype),
431 TYPE_READONLY (basetype),
432 TYPE_VOLATILE (basetype));
433 else
863adfc0
MS
434 ptype = build_pointer_type (basetype);
435
8d08fdba
MS
436 /* The actual arglist for this function includes a "hidden" argument
437 which is "this". Put it into the list of argument types. */
438
439 argtypes = tree_cons (NULL_TREE, ptype, argtypes);
440 TYPE_ARG_TYPES (t) = argtypes;
441 TREE_SIDE_EFFECTS (argtypes) = 1; /* Mark first argtype as "artificial". */
442
443 /* If we already have such a type, use the old one and free this one.
444 Note that it also frees up the above cons cell if found. */
445 hashcode = TYPE_HASH (basetype) + TYPE_HASH (rettype) + type_hash_list (argtypes);
446 t = type_hash_canon (hashcode, t);
447
448 if (TYPE_SIZE (t) == 0)
449 layout_type (t);
450
451 return t;
452}
453
bd6dd845 454static tree
e349ee73 455build_cplus_array_type_1 (elt_type, index_type)
8d08fdba
MS
456 tree elt_type;
457 tree index_type;
458{
459 register struct obstack *ambient_obstack = current_obstack;
460 register struct obstack *ambient_saveable_obstack = saveable_obstack;
461 tree t;
462
463 /* We need a new one. If both ELT_TYPE and INDEX_TYPE are permanent,
464 make this permanent too. */
465 if (TREE_PERMANENT (elt_type)
466 && (index_type == 0 || TREE_PERMANENT (index_type)))
467 {
468 current_obstack = &permanent_obstack;
469 saveable_obstack = &permanent_obstack;
470 }
471
5156628f 472 if (processing_template_decl)
5566b478
MS
473 {
474 t = make_node (ARRAY_TYPE);
475 TREE_TYPE (t) = elt_type;
476 TYPE_DOMAIN (t) = index_type;
477 }
478 else
479 t = build_array_type (elt_type, index_type);
8d08fdba
MS
480
481 /* Push these needs up so that initialization takes place
482 more easily. */
483 TYPE_NEEDS_CONSTRUCTING (t) = TYPE_NEEDS_CONSTRUCTING (TYPE_MAIN_VARIANT (elt_type));
484 TYPE_NEEDS_DESTRUCTOR (t) = TYPE_NEEDS_DESTRUCTOR (TYPE_MAIN_VARIANT (elt_type));
485 current_obstack = ambient_obstack;
486 saveable_obstack = ambient_saveable_obstack;
487 return t;
488}
e349ee73
MS
489
490tree
491build_cplus_array_type (elt_type, index_type)
492 tree elt_type;
493 tree index_type;
494{
495 tree t;
496 int constp = TYPE_READONLY (elt_type);
497 int volatilep = TYPE_VOLATILE (elt_type);
498 elt_type = TYPE_MAIN_VARIANT (elt_type);
499
500 t = build_cplus_array_type_1 (elt_type, index_type);
501
502 if (constp || volatilep)
503 t = cp_build_type_variant (t, constp, volatilep);
504
505 return t;
506}
8d08fdba 507\f
f376e137
MS
508/* Make a variant type in the proper way for C/C++, propagating qualifiers
509 down to the element type of an array. */
510
511tree
512cp_build_type_variant (type, constp, volatilep)
513 tree type;
514 int constp, volatilep;
515{
e76a2646
MS
516 if (type == error_mark_node)
517 return type;
518
f376e137
MS
519 if (TREE_CODE (type) == ARRAY_TYPE)
520 {
521 tree real_main_variant = TYPE_MAIN_VARIANT (type);
522
523 push_obstacks (TYPE_OBSTACK (real_main_variant),
524 TYPE_OBSTACK (real_main_variant));
e349ee73
MS
525 type = build_cplus_array_type_1 (cp_build_type_variant
526 (TREE_TYPE (type), constp, volatilep),
527 TYPE_DOMAIN (type));
f376e137
MS
528
529 /* TYPE must be on same obstack as REAL_MAIN_VARIANT. If not,
530 make a copy. (TYPE might have come from the hash table and
531 REAL_MAIN_VARIANT might be in some function's obstack.) */
532
533 if (TYPE_OBSTACK (type) != TYPE_OBSTACK (real_main_variant))
534 {
535 type = copy_node (type);
536 TYPE_POINTER_TO (type) = TYPE_REFERENCE_TO (type) = 0;
537 }
538
539 TYPE_MAIN_VARIANT (type) = real_main_variant;
540 pop_obstacks ();
e349ee73 541 return type;
f376e137
MS
542 }
543 return build_type_variant (type, constp, volatilep);
544}
545\f
8d08fdba
MS
546/* Add OFFSET to all base types of T.
547
548 OFFSET, which is a type offset, is number of bytes.
549
550 Note that we don't have to worry about having two paths to the
551 same base type, since this type owns its association list. */
e92cc029 552
8d08fdba
MS
553void
554propagate_binfo_offsets (binfo, offset)
555 tree binfo;
556 tree offset;
557{
558 tree binfos = BINFO_BASETYPES (binfo);
559 int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
560
561 for (i = 0; i < n_baselinks; /* note increment is done in the loop. */)
562 {
563 tree base_binfo = TREE_VEC_ELT (binfos, i);
564
565 if (TREE_VIA_VIRTUAL (base_binfo))
566 i += 1;
567 else
568 {
569 int j;
570 tree base_binfos = BINFO_BASETYPES (base_binfo);
571 tree delta;
572
573 for (j = i+1; j < n_baselinks; j++)
574 if (! TREE_VIA_VIRTUAL (TREE_VEC_ELT (binfos, j)))
575 {
576 /* The next basetype offset must take into account the space
577 between the classes, not just the size of each class. */
578 delta = size_binop (MINUS_EXPR,
579 BINFO_OFFSET (TREE_VEC_ELT (binfos, j)),
580 BINFO_OFFSET (base_binfo));
581 break;
582 }
583
584#if 0
585 if (BINFO_OFFSET_ZEROP (base_binfo))
586 BINFO_OFFSET (base_binfo) = offset;
587 else
588 BINFO_OFFSET (base_binfo)
589 = size_binop (PLUS_EXPR, BINFO_OFFSET (base_binfo), offset);
590#else
591 BINFO_OFFSET (base_binfo) = offset;
592#endif
593 if (base_binfos)
594 {
595 int k;
596 tree chain = NULL_TREE;
597
598 /* Now unshare the structure beneath BASE_BINFO. */
599 for (k = TREE_VEC_LENGTH (base_binfos)-1;
600 k >= 0; k--)
601 {
602 tree base_base_binfo = TREE_VEC_ELT (base_binfos, k);
603 if (! TREE_VIA_VIRTUAL (base_base_binfo))
604 TREE_VEC_ELT (base_binfos, k)
605 = make_binfo (BINFO_OFFSET (base_base_binfo),
8926095f 606 base_base_binfo,
8d08fdba
MS
607 BINFO_VTABLE (base_base_binfo),
608 BINFO_VIRTUALS (base_base_binfo),
609 chain);
610 chain = TREE_VEC_ELT (base_binfos, k);
611 TREE_VIA_PUBLIC (chain) = TREE_VIA_PUBLIC (base_base_binfo);
612 TREE_VIA_PROTECTED (chain) = TREE_VIA_PROTECTED (base_base_binfo);
8ccc31eb 613 BINFO_INHERITANCE_CHAIN (chain) = base_binfo;
8d08fdba
MS
614 }
615 /* Now propagate the offset to the base types. */
616 propagate_binfo_offsets (base_binfo, offset);
617 }
618
619 /* Go to our next class that counts for offset propagation. */
620 i = j;
621 if (i < n_baselinks)
622 offset = size_binop (PLUS_EXPR, offset, delta);
623 }
624 }
625}
626
627/* Compute the actual offsets that our virtual base classes
628 will have *for this type*. This must be performed after
629 the fields are laid out, since virtual baseclasses must
630 lay down at the end of the record.
631
632 Returns the maximum number of virtual functions any of the virtual
633 baseclasses provide. */
e92cc029 634
8d08fdba
MS
635int
636layout_vbasetypes (rec, max)
637 tree rec;
638 int max;
639{
640 /* Get all the virtual base types that this type uses.
641 The TREE_VALUE slot holds the virtual baseclass type. */
642 tree vbase_types = get_vbase_types (rec);
643
644#ifdef STRUCTURE_SIZE_BOUNDARY
645 unsigned record_align = MAX (STRUCTURE_SIZE_BOUNDARY, TYPE_ALIGN (rec));
646#else
647 unsigned record_align = MAX (BITS_PER_UNIT, TYPE_ALIGN (rec));
648#endif
f0e01782 649 int desired_align;
8d08fdba
MS
650
651 /* Record size so far is CONST_SIZE + VAR_SIZE bits,
652 where CONST_SIZE is an integer
653 and VAR_SIZE is a tree expression.
654 If VAR_SIZE is null, the size is just CONST_SIZE.
655 Naturally we try to avoid using VAR_SIZE. */
656 register unsigned const_size = 0;
657 register tree var_size = 0;
658 int nonvirtual_const_size;
8d08fdba
MS
659
660 CLASSTYPE_VBASECLASSES (rec) = vbase_types;
661
662 if (TREE_CODE (TYPE_SIZE (rec)) == INTEGER_CST)
663 const_size = TREE_INT_CST_LOW (TYPE_SIZE (rec));
664 else
665 var_size = TYPE_SIZE (rec);
666
667 nonvirtual_const_size = const_size;
8d08fdba
MS
668
669 while (vbase_types)
670 {
671 tree basetype = BINFO_TYPE (vbase_types);
672 tree offset;
673
f0e01782
MS
674 desired_align = TYPE_ALIGN (basetype);
675 record_align = MAX (record_align, desired_align);
676
8d08fdba
MS
677 if (const_size == 0)
678 offset = integer_zero_node;
679 else
f0e01782
MS
680 {
681 /* Give each virtual base type the alignment it wants. */
682 const_size = CEIL (const_size, TYPE_ALIGN (basetype))
683 * TYPE_ALIGN (basetype);
684 offset = size_int (CEIL (const_size, BITS_PER_UNIT));
685 }
8d08fdba
MS
686
687 if (CLASSTYPE_VSIZE (basetype) > max)
688 max = CLASSTYPE_VSIZE (basetype);
689 BINFO_OFFSET (vbase_types) = offset;
690
691 if (TREE_CODE (TYPE_SIZE (basetype)) == INTEGER_CST)
e1cd6e56
MS
692 {
693 /* Every virtual baseclass takes a least a UNIT, so that we can
694 take it's address and get something different for each base. */
695 const_size += MAX (BITS_PER_UNIT,
696 TREE_INT_CST_LOW (TYPE_SIZE (basetype))
697 - TREE_INT_CST_LOW (CLASSTYPE_VBASE_SIZE (basetype)));
698 }
8d08fdba
MS
699 else if (var_size == 0)
700 var_size = TYPE_SIZE (basetype);
701 else
702 var_size = size_binop (PLUS_EXPR, var_size, TYPE_SIZE (basetype));
703
704 vbase_types = TREE_CHAIN (vbase_types);
705 }
706
e1cd6e56
MS
707 if (const_size)
708 {
709 /* Because a virtual base might take a single byte above,
710 we have to re-adjust the total size to make sure it it
711 a multiple of the alignment. */
712 /* Give the whole object the alignment it wants. */
713 const_size = CEIL (const_size, record_align) * record_align;
714 }
715
f0e01782
MS
716 /* Set the alignment in the complete type. We don't set CLASSTYPE_ALIGN
717 here, as that is for this class, without any virtual base classes. */
718 TYPE_ALIGN (rec) = record_align;
8d08fdba
MS
719 if (const_size != nonvirtual_const_size)
720 {
721 CLASSTYPE_VBASE_SIZE (rec)
722 = size_int (const_size - nonvirtual_const_size);
723 TYPE_SIZE (rec) = size_int (const_size);
724 }
725
726 /* Now propagate offset information throughout the lattice
727 under the vbase type. */
728 for (vbase_types = CLASSTYPE_VBASECLASSES (rec); vbase_types;
729 vbase_types = TREE_CHAIN (vbase_types))
730 {
731 tree base_binfos = BINFO_BASETYPES (vbase_types);
732
8ccc31eb
MS
733 BINFO_INHERITANCE_CHAIN (vbase_types) = TYPE_BINFO (rec);
734
8d08fdba
MS
735 if (base_binfos)
736 {
737 tree chain = NULL_TREE;
738 int j;
739 /* Now unshare the structure beneath BASE_BINFO. */
740
741 for (j = TREE_VEC_LENGTH (base_binfos)-1;
742 j >= 0; j--)
743 {
744 tree base_base_binfo = TREE_VEC_ELT (base_binfos, j);
745 if (! TREE_VIA_VIRTUAL (base_base_binfo))
746 TREE_VEC_ELT (base_binfos, j)
747 = make_binfo (BINFO_OFFSET (base_base_binfo),
8926095f 748 base_base_binfo,
8d08fdba
MS
749 BINFO_VTABLE (base_base_binfo),
750 BINFO_VIRTUALS (base_base_binfo),
751 chain);
752 chain = TREE_VEC_ELT (base_binfos, j);
753 TREE_VIA_PUBLIC (chain) = TREE_VIA_PUBLIC (base_base_binfo);
754 TREE_VIA_PROTECTED (chain) = TREE_VIA_PROTECTED (base_base_binfo);
8ccc31eb 755 BINFO_INHERITANCE_CHAIN (chain) = vbase_types;
8d08fdba
MS
756 }
757
758 propagate_binfo_offsets (vbase_types, BINFO_OFFSET (vbase_types));
759 }
760 }
761
762 return max;
763}
764
765/* Lay out the base types of a record type, REC.
766 Tentatively set the size and alignment of REC
767 according to the base types alone.
768
769 Offsets for immediate nonvirtual baseclasses are also computed here.
770
7177d104
MS
771 TYPE_BINFO (REC) should be NULL_TREE on entry, and this routine
772 creates a list of base_binfos in TYPE_BINFO (REC) from BINFOS.
773
8d08fdba 774 Returns list of virtual base classes in a FIELD_DECL chain. */
e92cc029 775
8d08fdba
MS
776tree
777layout_basetypes (rec, binfos)
778 tree rec, binfos;
779{
780 /* Chain to hold all the new FIELD_DECLs which point at virtual
781 base classes. */
782 tree vbase_decls = NULL_TREE;
783
784#ifdef STRUCTURE_SIZE_BOUNDARY
785 unsigned record_align = MAX (STRUCTURE_SIZE_BOUNDARY, TYPE_ALIGN (rec));
786#else
787 unsigned record_align = MAX (BITS_PER_UNIT, TYPE_ALIGN (rec));
788#endif
789
8926095f
MS
790 /* Record size so far is CONST_SIZE + VAR_SIZE bits, where CONST_SIZE is
791 an integer and VAR_SIZE is a tree expression. If VAR_SIZE is null,
792 the size is just CONST_SIZE. Naturally we try to avoid using
e92cc029 793 VAR_SIZE. And so far, we've been successful. */
8926095f 794#if 0
8d08fdba 795 register tree var_size = 0;
8926095f
MS
796#endif
797
798 register unsigned const_size = 0;
8d08fdba
MS
799 int i, n_baseclasses = binfos ? TREE_VEC_LENGTH (binfos) : 0;
800
801 /* Handle basetypes almost like fields, but record their
802 offsets differently. */
803
804 for (i = 0; i < n_baseclasses; i++)
805 {
806 int inc, desired_align, int_vbase_size;
807 register tree base_binfo = TREE_VEC_ELT (binfos, i);
808 register tree basetype = BINFO_TYPE (base_binfo);
809 tree decl, offset;
810
811 if (TYPE_SIZE (basetype) == 0)
812 {
813#if 0
814 /* This error is now reported in xref_tag, thus giving better
815 location information. */
816 error_with_aggr_type (base_binfo,
817 "base class `%s' has incomplete type");
818
819 TREE_VIA_PUBLIC (base_binfo) = 1;
820 TREE_VIA_PROTECTED (base_binfo) = 0;
821 TREE_VIA_VIRTUAL (base_binfo) = 0;
822
823 /* Should handle this better so that
824
825 class A;
826 class B: private A { virtual void F(); };
827
e92cc029 828 does not dump core when compiled. */
8d08fdba
MS
829 my_friendly_abort (121);
830#endif
831 continue;
832 }
833
834 /* All basetypes are recorded in the association list of the
835 derived type. */
836
837 if (TREE_VIA_VIRTUAL (base_binfo))
838 {
839 int j;
840 char *name = (char *)alloca (TYPE_NAME_LENGTH (basetype)
841 + sizeof (VBASE_NAME) + 1);
842
843 /* The offset for a virtual base class is only used in computing
844 virtual function tables and for initializing virtual base
845 pointers. It is built once `get_vbase_types' is called. */
846
847 /* If this basetype can come from another vbase pointer
848 without an additional indirection, we will share
849 that pointer. If an indirection is involved, we
850 make our own pointer. */
851 for (j = 0; j < n_baseclasses; j++)
852 {
853 tree other_base_binfo = TREE_VEC_ELT (binfos, j);
854 if (! TREE_VIA_VIRTUAL (other_base_binfo)
855 && binfo_member (basetype,
856 CLASSTYPE_VBASECLASSES (BINFO_TYPE (other_base_binfo))))
857 goto got_it;
858 }
859 sprintf (name, VBASE_NAME_FORMAT, TYPE_NAME_STRING (basetype));
be99da77
MS
860 decl = build_lang_field_decl (FIELD_DECL, get_identifier (name),
861 build_pointer_type (basetype));
8d08fdba
MS
862 /* If you change any of the below, take a look at all the
863 other VFIELD_BASEs and VTABLE_BASEs in the code, and change
e92cc029 864 them too. */
8d08fdba
MS
865 DECL_ASSEMBLER_NAME (decl) = get_identifier (VTABLE_BASE);
866 DECL_VIRTUAL_P (decl) = 1;
d2e5ee5c 867 DECL_ARTIFICIAL (decl) = 1;
8d08fdba
MS
868 DECL_FIELD_CONTEXT (decl) = rec;
869 DECL_CLASS_CONTEXT (decl) = rec;
870 DECL_FCONTEXT (decl) = basetype;
28cbf42c 871 DECL_SAVED_INSNS (decl) = NULL_RTX;
8d08fdba
MS
872 DECL_FIELD_SIZE (decl) = 0;
873 DECL_ALIGN (decl) = TYPE_ALIGN (ptr_type_node);
874 TREE_CHAIN (decl) = vbase_decls;
875 BINFO_VPTR_FIELD (base_binfo) = decl;
876 vbase_decls = decl;
877
8d08fdba
MS
878 got_it:
879 /* The space this decl occupies has already been accounted for. */
880 continue;
881 }
882
42976354
BK
883 /* Effective C++ rule 14. We only need to check TYPE_VIRTUAL_P
884 here because the case of virtual functions but non-virtual
885 dtor is handled in finish_struct_1. */
886 if (warn_ecpp && ! TYPE_VIRTUAL_P (basetype)
887 && TYPE_HAS_DESTRUCTOR (basetype))
888 cp_warning ("base class `%#T' has a non-virtual destructor", basetype);
889
8d08fdba
MS
890 if (const_size == 0)
891 offset = integer_zero_node;
892 else
893 {
894 /* Give each base type the alignment it wants. */
895 const_size = CEIL (const_size, TYPE_ALIGN (basetype))
896 * TYPE_ALIGN (basetype);
897 offset = size_int ((const_size + BITS_PER_UNIT - 1) / BITS_PER_UNIT);
8d08fdba
MS
898 }
899 BINFO_OFFSET (base_binfo) = offset;
900 if (CLASSTYPE_VSIZE (basetype))
901 {
902 BINFO_VTABLE (base_binfo) = TYPE_BINFO_VTABLE (basetype);
903 BINFO_VIRTUALS (base_binfo) = TYPE_BINFO_VIRTUALS (basetype);
904 }
905 TREE_CHAIN (base_binfo) = TYPE_BINFO (rec);
906 TYPE_BINFO (rec) = base_binfo;
907
908 /* Add only the amount of storage not present in
909 the virtual baseclasses. */
910
911 int_vbase_size = TREE_INT_CST_LOW (CLASSTYPE_VBASE_SIZE (basetype));
912 if (TREE_INT_CST_LOW (TYPE_SIZE (basetype)) > int_vbase_size)
913 {
914 inc = MAX (record_align,
915 (TREE_INT_CST_LOW (TYPE_SIZE (basetype))
916 - int_vbase_size));
917
918 /* Record must have at least as much alignment as any field. */
919 desired_align = TYPE_ALIGN (basetype);
920 record_align = MAX (record_align, desired_align);
921
922 const_size += inc;
923 }
924 }
925
926 if (const_size)
927 CLASSTYPE_SIZE (rec) = size_int (const_size);
928 else
929 CLASSTYPE_SIZE (rec) = integer_zero_node;
930 CLASSTYPE_ALIGN (rec) = record_align;
931
932 return vbase_decls;
933}
934\f
935/* Hashing of lists so that we don't make duplicates.
936 The entry point is `list_hash_canon'. */
937
938/* Each hash table slot is a bucket containing a chain
939 of these structures. */
940
941struct list_hash
942{
943 struct list_hash *next; /* Next structure in the bucket. */
944 int hashcode; /* Hash code of this list. */
945 tree list; /* The list recorded here. */
946};
947
948/* Now here is the hash table. When recording a list, it is added
949 to the slot whose index is the hash code mod the table size.
950 Note that the hash table is used for several kinds of lists.
951 While all these live in the same table, they are completely independent,
952 and the hash code is computed differently for each of these. */
953
954#define TYPE_HASH_SIZE 59
37c46b43 955static struct list_hash *list_hash_table[TYPE_HASH_SIZE];
8d08fdba
MS
956
957/* Compute a hash code for a list (chain of TREE_LIST nodes
958 with goodies in the TREE_PURPOSE, TREE_VALUE, and bits of the
959 TREE_COMMON slots), by adding the hash codes of the individual entries. */
960
37c46b43
MS
961static int
962list_hash (purpose, value, chain)
963 tree purpose, value, chain;
8d08fdba
MS
964{
965 register int hashcode = 0;
966
37c46b43
MS
967 if (chain)
968 hashcode += TYPE_HASH (chain);
8d08fdba 969
37c46b43
MS
970 if (value)
971 hashcode += TYPE_HASH (value);
8d08fdba
MS
972 else
973 hashcode += 1007;
37c46b43
MS
974 if (purpose)
975 hashcode += TYPE_HASH (purpose);
8d08fdba
MS
976 else
977 hashcode += 1009;
978 return hashcode;
979}
980
981/* Look in the type hash table for a type isomorphic to TYPE.
982 If one is found, return it. Otherwise return 0. */
983
37c46b43
MS
984static tree
985list_hash_lookup (hashcode, via_public, via_protected, via_virtual,
986 purpose, value, chain)
987 int hashcode, via_public, via_virtual, via_protected;
988 tree purpose, value, chain;
8d08fdba
MS
989{
990 register struct list_hash *h;
37c46b43 991
8d08fdba
MS
992 for (h = list_hash_table[hashcode % TYPE_HASH_SIZE]; h; h = h->next)
993 if (h->hashcode == hashcode
37c46b43
MS
994 && TREE_VIA_VIRTUAL (h->list) == via_virtual
995 && TREE_VIA_PUBLIC (h->list) == via_public
996 && TREE_VIA_PROTECTED (h->list) == via_protected
997 && TREE_PURPOSE (h->list) == purpose
998 && TREE_VALUE (h->list) == value
999 && TREE_CHAIN (h->list) == chain)
1000 return h->list;
8d08fdba
MS
1001 return 0;
1002}
1003
1004/* Add an entry to the list-hash-table
1005 for a list TYPE whose hash code is HASHCODE. */
1006
37c46b43 1007static void
8d08fdba
MS
1008list_hash_add (hashcode, list)
1009 int hashcode;
1010 tree list;
1011{
1012 register struct list_hash *h;
1013
1014 h = (struct list_hash *) obstack_alloc (&class_obstack, sizeof (struct list_hash));
1015 h->hashcode = hashcode;
1016 h->list = list;
1017 h->next = list_hash_table[hashcode % TYPE_HASH_SIZE];
1018 list_hash_table[hashcode % TYPE_HASH_SIZE] = h;
1019}
1020
1021/* Given TYPE, and HASHCODE its hash code, return the canonical
1022 object for an identical list if one already exists.
1023 Otherwise, return TYPE, and record it as the canonical object
1024 if it is a permanent object.
1025
1026 To use this function, first create a list of the sort you want.
1027 Then compute its hash code from the fields of the list that
1028 make it different from other similar lists.
1029 Then call this function and use the value.
1030 This function frees the list you pass in if it is a duplicate. */
1031
1032/* Set to 1 to debug without canonicalization. Never set by program. */
e92cc029 1033
a0a33927 1034static int debug_no_list_hash = 0;
8d08fdba 1035
8d08fdba
MS
1036tree
1037hash_tree_cons (via_public, via_virtual, via_protected, purpose, value, chain)
1038 int via_public, via_virtual, via_protected;
1039 tree purpose, value, chain;
1040{
1041 struct obstack *ambient_obstack = current_obstack;
1042 tree t;
1043 int hashcode;
1044
37c46b43
MS
1045 if (! debug_no_list_hash)
1046 {
1047 hashcode = list_hash (purpose, value, chain);
1048 t = list_hash_lookup (hashcode, via_public, via_protected, via_virtual,
1049 purpose, value, chain);
1050 if (t)
1051 return t;
1052 }
1053
8d08fdba 1054 current_obstack = &class_obstack;
37c46b43 1055
8d08fdba
MS
1056 t = tree_cons (purpose, value, chain);
1057 TREE_VIA_PUBLIC (t) = via_public;
1058 TREE_VIA_PROTECTED (t) = via_protected;
1059 TREE_VIA_VIRTUAL (t) = via_virtual;
37c46b43
MS
1060
1061 /* If this is a new list, record it for later reuse. */
1062 if (! debug_no_list_hash)
1063 list_hash_add (hashcode, t);
1064
8d08fdba
MS
1065 current_obstack = ambient_obstack;
1066 return t;
1067}
1068
1069/* Constructor for hashed lists. */
e92cc029 1070
8d08fdba
MS
1071tree
1072hash_tree_chain (value, chain)
1073 tree value, chain;
1074{
37c46b43 1075 return hash_tree_cons (0, 0, 0, NULL_TREE, value, chain);
8d08fdba
MS
1076}
1077
1078/* Similar, but used for concatenating two lists. */
e92cc029 1079
8d08fdba
MS
1080tree
1081hash_chainon (list1, list2)
1082 tree list1, list2;
1083{
1084 if (list2 == 0)
1085 return list1;
1086 if (list1 == 0)
1087 return list2;
1088 if (TREE_CHAIN (list1) == NULL_TREE)
1089 return hash_tree_chain (TREE_VALUE (list1), list2);
1090 return hash_tree_chain (TREE_VALUE (list1),
1091 hash_chainon (TREE_CHAIN (list1), list2));
1092}
1093
51c184be
MS
1094static tree
1095get_identifier_list (value)
8d08fdba
MS
1096 tree value;
1097{
51c184be
MS
1098 tree list = IDENTIFIER_AS_LIST (value);
1099 if (list != NULL_TREE
1100 && (TREE_CODE (list) != TREE_LIST
1101 || TREE_VALUE (list) != value))
1102 list = NULL_TREE;
1103 else if (IDENTIFIER_HAS_TYPE_VALUE (value)
8926095f
MS
1104 && TREE_CODE (IDENTIFIER_TYPE_VALUE (value)) == RECORD_TYPE
1105 && IDENTIFIER_TYPE_VALUE (value)
1106 == TYPE_MAIN_VARIANT (IDENTIFIER_TYPE_VALUE (value)))
8d08fdba 1107 {
51c184be
MS
1108 tree type = IDENTIFIER_TYPE_VALUE (value);
1109
1110 if (TYPE_PTRMEMFUNC_P (type))
8d08fdba 1111 list = NULL_TREE;
51c184be
MS
1112 else if (type == current_class_type)
1113 /* Don't mess up the constructor name. */
1114 list = tree_cons (NULL_TREE, value, NULL_TREE);
1115 else
8d08fdba 1116 {
a80e4195 1117 if (! CLASSTYPE_ID_AS_LIST (type))
51c184be 1118 CLASSTYPE_ID_AS_LIST (type)
a80e4195 1119 = perm_tree_cons (NULL_TREE, TYPE_IDENTIFIER (type), NULL_TREE);
51c184be 1120 list = CLASSTYPE_ID_AS_LIST (type);
8d08fdba
MS
1121 }
1122 }
51c184be
MS
1123 return list;
1124}
1125
1126tree
1127get_decl_list (value)
1128 tree value;
1129{
1130 tree list = NULL_TREE;
1131
1132 if (TREE_CODE (value) == IDENTIFIER_NODE)
1133 list = get_identifier_list (value);
8d08fdba 1134 else if (TREE_CODE (value) == RECORD_TYPE
be99da77
MS
1135 && TYPE_LANG_SPECIFIC (value)
1136 && value == TYPE_MAIN_VARIANT (value))
8d08fdba
MS
1137 list = CLASSTYPE_AS_LIST (value);
1138
1139 if (list != NULL_TREE)
1140 {
1141 my_friendly_assert (TREE_CHAIN (list) == NULL_TREE, 301);
1142 return list;
1143 }
1144
1145 return build_decl_list (NULL_TREE, value);
1146}
8d08fdba
MS
1147\f
1148/* Build an association between TYPE and some parameters:
1149
1150 OFFSET is the offset added to `this' to convert it to a pointer
1151 of type `TYPE *'
1152
8926095f
MS
1153 BINFO is the base binfo to use, if we are deriving from one. This
1154 is necessary, as we want specialized parent binfos from base
1155 classes, so that the VTABLE_NAMEs of bases are for the most derived
1156 type, instead of of the simple type.
1157
8d08fdba
MS
1158 VTABLE is the virtual function table with which to initialize
1159 sub-objects of type TYPE.
1160
1161 VIRTUALS are the virtual functions sitting in VTABLE.
1162
1163 CHAIN are more associations we must retain. */
1164
1165tree
8926095f
MS
1166make_binfo (offset, binfo, vtable, virtuals, chain)
1167 tree offset, binfo;
8d08fdba
MS
1168 tree vtable, virtuals;
1169 tree chain;
1170{
8926095f
MS
1171 tree new_binfo = make_tree_vec (6);
1172 tree type;
8d08fdba 1173
8926095f
MS
1174 if (TREE_CODE (binfo) == TREE_VEC)
1175 type = BINFO_TYPE (binfo);
1176 else
1177 {
1178 type = binfo;
1179 binfo = TYPE_BINFO (binfo);
1180 }
8d08fdba 1181
8926095f
MS
1182 TREE_CHAIN (new_binfo) = chain;
1183 if (chain)
1184 TREE_USED (new_binfo) = TREE_USED (chain);
8d08fdba 1185
8926095f
MS
1186 TREE_TYPE (new_binfo) = TYPE_MAIN_VARIANT (type);
1187 BINFO_OFFSET (new_binfo) = offset;
1188 BINFO_VTABLE (new_binfo) = vtable;
1189 BINFO_VIRTUALS (new_binfo) = virtuals;
1190 BINFO_VPTR_FIELD (new_binfo) = NULL_TREE;
8d08fdba 1191
8926095f
MS
1192 if (binfo && BINFO_BASETYPES (binfo) != NULL_TREE)
1193 BINFO_BASETYPES (new_binfo) = copy_node (BINFO_BASETYPES (binfo));
1194 return new_binfo;
8d08fdba
MS
1195}
1196
8d08fdba
MS
1197/* Return the binfo value for ELEM in TYPE. */
1198
1199tree
1200binfo_value (elem, type)
1201 tree elem;
1202 tree type;
1203{
1204 if (get_base_distance (elem, type, 0, (tree *)0) == -2)
1205 compiler_error ("base class `%s' ambiguous in binfo_value",
1206 TYPE_NAME_STRING (elem));
1207 if (elem == type)
1208 return TYPE_BINFO (type);
1209 if (TREE_CODE (elem) == RECORD_TYPE && TYPE_BINFO (elem) == type)
1210 return type;
1211 return get_binfo (elem, type, 0);
1212}
1213
1214tree
1215reverse_path (path)
1216 tree path;
1217{
1218 register tree prev = 0, tmp, next;
1219 for (tmp = path; tmp; tmp = next)
1220 {
1221 next = BINFO_INHERITANCE_CHAIN (tmp);
1222 BINFO_INHERITANCE_CHAIN (tmp) = prev;
1223 prev = tmp;
1224 }
1225 return prev;
1226}
1227
8d08fdba
MS
1228void
1229debug_binfo (elem)
1230 tree elem;
1231{
f30432d7 1232 unsigned HOST_WIDE_INT n;
8d08fdba
MS
1233 tree virtuals;
1234
1235 fprintf (stderr, "type \"%s\"; offset = %d\n",
1236 TYPE_NAME_STRING (BINFO_TYPE (elem)),
1237 TREE_INT_CST_LOW (BINFO_OFFSET (elem)));
1238 fprintf (stderr, "vtable type:\n");
1239 debug_tree (BINFO_TYPE (elem));
1240 if (BINFO_VTABLE (elem))
1241 fprintf (stderr, "vtable decl \"%s\"\n", IDENTIFIER_POINTER (DECL_NAME (BINFO_VTABLE (elem))));
1242 else
1243 fprintf (stderr, "no vtable decl yet\n");
1244 fprintf (stderr, "virtuals:\n");
1245 virtuals = BINFO_VIRTUALS (elem);
f30432d7
MS
1246
1247 n = skip_rtti_stuff (&virtuals);
1248
8d08fdba
MS
1249 while (virtuals)
1250 {
1251 tree fndecl = TREE_OPERAND (FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (virtuals)), 0);
1252 fprintf (stderr, "%s [%d =? %d]\n",
1253 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (fndecl)),
f30432d7
MS
1254 n, TREE_INT_CST_LOW (DECL_VINDEX (fndecl)));
1255 ++n;
8d08fdba 1256 virtuals = TREE_CHAIN (virtuals);
8d08fdba
MS
1257 }
1258}
1259
1260/* Return the length of a chain of nodes chained through DECL_CHAIN.
1261 We expect a null pointer to mark the end of the chain.
1262 This is the Lisp primitive `length'. */
1263
1264int
1265decl_list_length (t)
1266 tree t;
1267{
1268 register tree tail;
1269 register int len = 0;
1270
1271 my_friendly_assert (TREE_CODE (t) == FUNCTION_DECL
1272 || TREE_CODE (t) == TEMPLATE_DECL, 300);
1273 for (tail = t; tail; tail = DECL_CHAIN (tail))
1274 len++;
1275
1276 return len;
1277}
1278
1279int
1280count_functions (t)
1281 tree t;
1282{
1283 if (TREE_CODE (t) == FUNCTION_DECL)
1284 return 1;
5b605f68
MS
1285 else if (TREE_CODE (t) == TREE_LIST)
1286 return decl_list_length (TREE_VALUE (t));
8d08fdba 1287
5b605f68 1288 my_friendly_abort (359);
0d16d68e 1289 return 0;
8d08fdba
MS
1290}
1291
8d08fdba
MS
1292int
1293is_overloaded_fn (x)
1294 tree x;
1295{
aa36c081
JM
1296 if (TREE_CODE (x) == FUNCTION_DECL
1297 || TREE_CODE (x) == TEMPLATE_ID_EXPR
1298 || DECL_FUNCTION_TEMPLATE_P (x))
386b8a85
JM
1299 return 1;
1300
8d08fdba
MS
1301 if (TREE_CODE (x) == TREE_LIST
1302 && (TREE_CODE (TREE_VALUE (x)) == FUNCTION_DECL
aa36c081 1303 || DECL_FUNCTION_TEMPLATE_P (TREE_VALUE (x))))
8d08fdba
MS
1304 return 1;
1305
1306 return 0;
1307}
1308
8926095f
MS
1309int
1310really_overloaded_fn (x)
1311 tree x;
1312{
aa36c081
JM
1313 if (TREE_CODE (x) == TEMPLATE_ID_EXPR
1314 || DECL_FUNCTION_TEMPLATE_P (x))
386b8a85
JM
1315 return 1;
1316
8926095f
MS
1317 if (TREE_CODE (x) == TREE_LIST
1318 && (TREE_CODE (TREE_VALUE (x)) == FUNCTION_DECL
386b8a85 1319 || DECL_FUNCTION_TEMPLATE_P (TREE_VALUE (x))))
8926095f
MS
1320 return 1;
1321
1322 return 0;
1323}
1324
8d08fdba
MS
1325tree
1326get_first_fn (from)
1327 tree from;
1328{
00d3396f
JM
1329 if (TREE_CODE (from) == FUNCTION_DECL
1330 || TREE_CODE (from) == TEMPLATE_ID_EXPR
386b8a85 1331 || DECL_FUNCTION_TEMPLATE_P (from))
8d08fdba
MS
1332 return from;
1333
1334 my_friendly_assert (TREE_CODE (from) == TREE_LIST, 9);
1335
1336 return TREE_VALUE (from);
1337}
1338
8d08fdba
MS
1339int
1340is_aggr_type_2 (t1, t2)
1341 tree t1, t2;
1342{
1343 if (TREE_CODE (t1) != TREE_CODE (t2))
1344 return 0;
1345 return IS_AGGR_TYPE (t1) && IS_AGGR_TYPE (t2);
1346}
8d08fdba
MS
1347\f
1348#define PRINT_RING_SIZE 4
1349
1350char *
2ba25f50 1351lang_printable_name (decl, v)
8d08fdba 1352 tree decl;
2ba25f50 1353 int v;
8d08fdba
MS
1354{
1355 static tree decl_ring[PRINT_RING_SIZE];
1356 static char *print_ring[PRINT_RING_SIZE];
1357 static int ring_counter;
1358 int i;
1359
1360 /* Only cache functions. */
2ba25f50
MS
1361 if (v < 2
1362 || TREE_CODE (decl) != FUNCTION_DECL
8d08fdba 1363 || DECL_LANG_SPECIFIC (decl) == 0)
2ba25f50 1364 return lang_decl_name (decl, v);
8d08fdba
MS
1365
1366 /* See if this print name is lying around. */
1367 for (i = 0; i < PRINT_RING_SIZE; i++)
1368 if (decl_ring[i] == decl)
1369 /* yes, so return it. */
1370 return print_ring[i];
1371
1372 if (++ring_counter == PRINT_RING_SIZE)
1373 ring_counter = 0;
1374
1375 if (current_function_decl != NULL_TREE)
1376 {
1377 if (decl_ring[ring_counter] == current_function_decl)
1378 ring_counter += 1;
1379 if (ring_counter == PRINT_RING_SIZE)
1380 ring_counter = 0;
1381 if (decl_ring[ring_counter] == current_function_decl)
1382 my_friendly_abort (106);
1383 }
1384
1385 if (print_ring[ring_counter])
1386 free (print_ring[ring_counter]);
1387
2ba25f50
MS
1388 print_ring[ring_counter] = xstrdup (lang_decl_name (decl, v));
1389 decl_ring[ring_counter] = decl;
8d08fdba
MS
1390 return print_ring[ring_counter];
1391}
1392\f
f30432d7 1393/* Build the FUNCTION_TYPE or METHOD_TYPE which may throw exceptions
8d08fdba 1394 listed in RAISES. */
e92cc029 1395
8d08fdba 1396tree
f30432d7
MS
1397build_exception_variant (type, raises)
1398 tree type;
8d08fdba
MS
1399 tree raises;
1400{
8d08fdba 1401 tree v = TYPE_MAIN_VARIANT (type);
8d08fdba
MS
1402 int constp = TYPE_READONLY (type);
1403 int volatilep = TYPE_VOLATILE (type);
1404
45537677 1405 for (; v; v = TYPE_NEXT_VARIANT (v))
8d08fdba
MS
1406 {
1407 if (TYPE_READONLY (v) != constp
1408 || TYPE_VOLATILE (v) != volatilep)
1409 continue;
1410
e92cc029 1411 /* @@ This should do set equality, not exact match. */
6060a796
MS
1412 if (simple_cst_list_equal (TYPE_RAISES_EXCEPTIONS (v), raises))
1413 /* List of exceptions raised matches previously found list.
8d08fdba 1414
6060a796
MS
1415 @@ Nice to free up storage used in consing up the
1416 @@ list of exceptions raised. */
1417 return v;
8d08fdba
MS
1418 }
1419
1420 /* Need to build a new variant. */
45537677
MS
1421 v = build_type_copy (type);
1422
8d08fdba
MS
1423 if (raises && ! TREE_PERMANENT (raises))
1424 {
1425 push_obstacks_nochange ();
1426 end_temporary_allocation ();
1427 raises = copy_list (raises);
1428 pop_obstacks ();
1429 }
5566b478 1430
8d08fdba
MS
1431 TYPE_RAISES_EXCEPTIONS (v) = raises;
1432 return v;
1433}
1434
1435/* Subroutine of copy_to_permanent
1436
1437 Assuming T is a node build bottom-up, make it all exist on
1438 permanent obstack, if it is not permanent already. */
878cd289
MS
1439
1440tree
1441mapcar (t, func)
8d08fdba 1442 tree t;
49c249e1 1443 tree (*func) PROTO((tree));
8d08fdba 1444{
878cd289 1445 tree tmp;
8d08fdba 1446
878cd289 1447 if (t == NULL_TREE)
8d08fdba
MS
1448 return t;
1449
878cd289
MS
1450 if (tmp = func (t), tmp != NULL_TREE)
1451 return tmp;
1452
5566b478 1453 switch (TREE_CODE (t))
8d08fdba
MS
1454 {
1455 case ERROR_MARK:
1456 return error_mark_node;
1457
1458 case VAR_DECL:
1459 case FUNCTION_DECL:
1460 case CONST_DECL:
1461 break;
1462
1463 case PARM_DECL:
1464 {
1465 tree chain = TREE_CHAIN (t);
1466 t = copy_node (t);
878cd289
MS
1467 TREE_CHAIN (t) = mapcar (chain, func);
1468 TREE_TYPE (t) = mapcar (TREE_TYPE (t), func);
1469 DECL_INITIAL (t) = mapcar (DECL_INITIAL (t), func);
1470 DECL_SIZE (t) = mapcar (DECL_SIZE (t), func);
8d08fdba
MS
1471 return t;
1472 }
1473
1474 case TREE_LIST:
1475 {
1476 tree chain = TREE_CHAIN (t);
1477 t = copy_node (t);
878cd289
MS
1478 TREE_PURPOSE (t) = mapcar (TREE_PURPOSE (t), func);
1479 TREE_VALUE (t) = mapcar (TREE_VALUE (t), func);
1480 TREE_CHAIN (t) = mapcar (chain, func);
8d08fdba
MS
1481 return t;
1482 }
1483
1484 case TREE_VEC:
1485 {
1486 int len = TREE_VEC_LENGTH (t);
1487
1488 t = copy_node (t);
1489 while (len--)
878cd289 1490 TREE_VEC_ELT (t, len) = mapcar (TREE_VEC_ELT (t, len), func);
8d08fdba
MS
1491 return t;
1492 }
1493
1494 case INTEGER_CST:
1495 case REAL_CST:
1496 case STRING_CST:
1497 return copy_node (t);
1498
1499 case COND_EXPR:
1500 case TARGET_EXPR:
02531345 1501 case AGGR_INIT_EXPR:
8d08fdba 1502 t = copy_node (t);
878cd289
MS
1503 TREE_OPERAND (t, 0) = mapcar (TREE_OPERAND (t, 0), func);
1504 TREE_OPERAND (t, 1) = mapcar (TREE_OPERAND (t, 1), func);
1505 TREE_OPERAND (t, 2) = mapcar (TREE_OPERAND (t, 2), func);
8d08fdba
MS
1506 return t;
1507
1508 case SAVE_EXPR:
1509 t = copy_node (t);
878cd289 1510 TREE_OPERAND (t, 0) = mapcar (TREE_OPERAND (t, 0), func);
8d08fdba
MS
1511 return t;
1512
1513 case MODIFY_EXPR:
1514 case PLUS_EXPR:
1515 case MINUS_EXPR:
1516 case MULT_EXPR:
1517 case TRUNC_DIV_EXPR:
1518 case TRUNC_MOD_EXPR:
1519 case MIN_EXPR:
1520 case MAX_EXPR:
1521 case LSHIFT_EXPR:
1522 case RSHIFT_EXPR:
1523 case BIT_IOR_EXPR:
1524 case BIT_XOR_EXPR:
1525 case BIT_AND_EXPR:
1526 case BIT_ANDTC_EXPR:
1527 case TRUTH_ANDIF_EXPR:
1528 case TRUTH_ORIF_EXPR:
1529 case LT_EXPR:
1530 case LE_EXPR:
1531 case GT_EXPR:
1532 case GE_EXPR:
1533 case EQ_EXPR:
1534 case NE_EXPR:
1535 case CEIL_DIV_EXPR:
1536 case FLOOR_DIV_EXPR:
1537 case ROUND_DIV_EXPR:
1538 case CEIL_MOD_EXPR:
1539 case FLOOR_MOD_EXPR:
1540 case ROUND_MOD_EXPR:
1541 case COMPOUND_EXPR:
1542 case PREDECREMENT_EXPR:
1543 case PREINCREMENT_EXPR:
1544 case POSTDECREMENT_EXPR:
1545 case POSTINCREMENT_EXPR:
5566b478
MS
1546 case ARRAY_REF:
1547 case SCOPE_REF:
6748b643
JM
1548 case TRY_CATCH_EXPR:
1549 case WITH_CLEANUP_EXPR:
8d08fdba 1550 t = copy_node (t);
878cd289
MS
1551 TREE_OPERAND (t, 0) = mapcar (TREE_OPERAND (t, 0), func);
1552 TREE_OPERAND (t, 1) = mapcar (TREE_OPERAND (t, 1), func);
8d08fdba
MS
1553 return t;
1554
7834ab39
MS
1555 case CALL_EXPR:
1556 t = copy_node (t);
1557 TREE_TYPE (t) = mapcar (TREE_TYPE (t), func);
1558 TREE_OPERAND (t, 0) = mapcar (TREE_OPERAND (t, 0), func);
1559 TREE_OPERAND (t, 1) = mapcar (TREE_OPERAND (t, 1), func);
1560
1561 /* tree.def says that operand two is RTL, but
1562 build_call_declarator puts trees in there. */
1563 if (TREE_OPERAND (t, 2)
1564 && TREE_CODE (TREE_OPERAND (t, 2)) == TREE_LIST)
1565 TREE_OPERAND (t, 2) = mapcar (TREE_OPERAND (t, 2), func);
1566 else
1567 TREE_OPERAND (t, 2) = NULL_TREE;
1568 return t;
1569
8d08fdba
MS
1570 case CONVERT_EXPR:
1571 case ADDR_EXPR:
1572 case INDIRECT_REF:
1573 case NEGATE_EXPR:
1574 case BIT_NOT_EXPR:
1575 case TRUTH_NOT_EXPR:
1576 case NOP_EXPR:
1577 case COMPONENT_REF:
6748b643 1578 case CLEANUP_POINT_EXPR:
8d08fdba 1579 t = copy_node (t);
878cd289 1580 TREE_OPERAND (t, 0) = mapcar (TREE_OPERAND (t, 0), func);
8d08fdba
MS
1581 return t;
1582
00595019 1583 case POINTER_TYPE:
e76a2646
MS
1584 tmp = build_pointer_type (mapcar (TREE_TYPE (t), func));
1585 return cp_build_type_variant (tmp, TYPE_READONLY (t), TYPE_VOLATILE (t));
00595019 1586 case REFERENCE_TYPE:
e76a2646
MS
1587 tmp = build_reference_type (mapcar (TREE_TYPE (t), func));
1588 return cp_build_type_variant (tmp, TYPE_READONLY (t), TYPE_VOLATILE (t));
00595019 1589 case FUNCTION_TYPE:
e76a2646
MS
1590 tmp = build_function_type (mapcar (TREE_TYPE (t), func),
1591 mapcar (TYPE_ARG_TYPES (t), func));
1592 return cp_build_type_variant (tmp, TYPE_READONLY (t), TYPE_VOLATILE (t));
00595019 1593 case ARRAY_TYPE:
5156628f
MS
1594 tmp = build_cplus_array_type (mapcar (TREE_TYPE (t), func),
1595 mapcar (TYPE_DOMAIN (t), func));
e76a2646 1596 return cp_build_type_variant (tmp, TYPE_READONLY (t), TYPE_VOLATILE (t));
b7484fbe 1597 case INTEGER_TYPE:
e76a2646
MS
1598 tmp = build_index_type (mapcar (TYPE_MAX_VALUE (t), func));
1599 return cp_build_type_variant (tmp, TYPE_READONLY (t), TYPE_VOLATILE (t));
00595019 1600 case OFFSET_TYPE:
e76a2646
MS
1601 tmp = build_offset_type (mapcar (TYPE_OFFSET_BASETYPE (t), func),
1602 mapcar (TREE_TYPE (t), func));
1603 return cp_build_type_variant (tmp, TYPE_READONLY (t), TYPE_VOLATILE (t));
00595019 1604 case METHOD_TYPE:
e76a2646
MS
1605 tmp = build_cplus_method_type
1606 (mapcar (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (t))), func),
1607 mapcar (TREE_TYPE (t), func),
1608 mapcar (TREE_CHAIN (TYPE_ARG_TYPES (t)), func));
1609 return cp_build_type_variant (tmp, TYPE_READONLY (t), TYPE_VOLATILE (t));
b7484fbe 1610
37c46b43
MS
1611 case COMPLEX_CST:
1612 t = copy_node (t);
1613 TREE_REALPART (t) = mapcar (TREE_REALPART (t), func);
1614 TREE_IMAGPART (t) = mapcar (TREE_REALPART (t), func);
1615 return t;
1616
5156628f
MS
1617 case CONSTRUCTOR:
1618 t = copy_node (t);
1619 CONSTRUCTOR_ELTS (t) = mapcar (CONSTRUCTOR_ELTS (t), func);
1620 return t;
1621
00595019
MS
1622 case RECORD_TYPE:
1623 if (TYPE_PTRMEMFUNC_P (t))
1624 return build_ptrmemfunc_type
878cd289 1625 (mapcar (TYPE_PTRMEMFUNC_FN_TYPE (t), func));
00595019
MS
1626 /* else fall through */
1627
8d08fdba 1628 /* This list is incomplete, but should suffice for now.
e76a2646 1629 It is very important that `sorry' not call
8d08fdba
MS
1630 `report_error_function'. That could cause an infinite loop. */
1631 default:
1632 sorry ("initializer contains unrecognized tree code");
1633 return error_mark_node;
1634
1635 }
1636 my_friendly_abort (107);
1637 /* NOTREACHED */
1638 return NULL_TREE;
1639}
1640
878cd289
MS
1641static tree
1642perm_manip (t)
1643 tree t;
1644{
1645 if (TREE_PERMANENT (t))
1646 return t;
ec255269
MS
1647 /* Support `void f () { extern int i; A<&i> a; }' */
1648 if ((TREE_CODE (t) == VAR_DECL || TREE_CODE (t) == FUNCTION_DECL)
1649 && TREE_PUBLIC (t))
1650 return copy_node (t);
878cd289
MS
1651 return NULL_TREE;
1652}
1653
8d08fdba
MS
1654/* Assuming T is a node built bottom-up, make it all exist on
1655 permanent obstack, if it is not permanent already. */
e92cc029 1656
8d08fdba
MS
1657tree
1658copy_to_permanent (t)
1659 tree t;
1660{
1661 register struct obstack *ambient_obstack = current_obstack;
1662 register struct obstack *ambient_saveable_obstack = saveable_obstack;
5156628f 1663 register struct obstack *ambient_expression_obstack = expression_obstack;
8d08fdba
MS
1664
1665 if (t == NULL_TREE || TREE_PERMANENT (t))
1666 return t;
1667
1668 saveable_obstack = &permanent_obstack;
1669 current_obstack = saveable_obstack;
5156628f 1670 expression_obstack = saveable_obstack;
8d08fdba 1671
878cd289 1672 t = mapcar (t, perm_manip);
8d08fdba
MS
1673
1674 current_obstack = ambient_obstack;
1675 saveable_obstack = ambient_saveable_obstack;
5156628f 1676 expression_obstack = ambient_expression_obstack;
8d08fdba
MS
1677
1678 return t;
1679}
1680
5566b478
MS
1681#ifdef GATHER_STATISTICS
1682extern int depth_reached;
1683#endif
1684
8d08fdba
MS
1685void
1686print_lang_statistics ()
1687{
e66d884e 1688 extern struct obstack decl_obstack;
8d08fdba 1689 print_obstack_statistics ("class_obstack", &class_obstack);
5566b478 1690 print_obstack_statistics ("decl_obstack", &decl_obstack);
8d08fdba
MS
1691 print_search_statistics ();
1692 print_class_statistics ();
5566b478
MS
1693#ifdef GATHER_STATISTICS
1694 fprintf (stderr, "maximum template instantiation depth reached: %d\n",
1695 depth_reached);
1696#endif
8d08fdba
MS
1697}
1698
1699/* This is used by the `assert' macro. It is provided in libgcc.a,
1700 which `cc' doesn't know how to link. Note that the C++ front-end
1701 no longer actually uses the `assert' macro (instead, it calls
1702 my_friendly_assert). But all of the back-end files still need this. */
e92cc029 1703
8d08fdba
MS
1704void
1705__eprintf (string, expression, line, filename)
1706#ifdef __STDC__
1707 const char *string;
1708 const char *expression;
1709 unsigned line;
1710 const char *filename;
1711#else
1712 char *string;
1713 char *expression;
1714 unsigned line;
1715 char *filename;
1716#endif
1717{
1718 fprintf (stderr, string, expression, line, filename);
1719 fflush (stderr);
1720 abort ();
1721}
1722
e92cc029
MS
1723/* Return, as an INTEGER_CST node, the number of elements for TYPE
1724 (which is an ARRAY_TYPE). This counts only elements of the top
1725 array. */
8d08fdba
MS
1726
1727tree
1728array_type_nelts_top (type)
1729 tree type;
1730{
eae89e04 1731 return fold (build (PLUS_EXPR, sizetype,
8d08fdba
MS
1732 array_type_nelts (type),
1733 integer_one_node));
1734}
1735
e92cc029
MS
1736/* Return, as an INTEGER_CST node, the number of elements for TYPE
1737 (which is an ARRAY_TYPE). This one is a recursive count of all
1738 ARRAY_TYPEs that are clumped together. */
8d08fdba
MS
1739
1740tree
1741array_type_nelts_total (type)
1742 tree type;
1743{
1744 tree sz = array_type_nelts_top (type);
1745 type = TREE_TYPE (type);
1746 while (TREE_CODE (type) == ARRAY_TYPE)
1747 {
1748 tree n = array_type_nelts_top (type);
eae89e04 1749 sz = fold (build (MULT_EXPR, sizetype, sz, n));
8d08fdba
MS
1750 type = TREE_TYPE (type);
1751 }
1752 return sz;
1753}
878cd289
MS
1754
1755static
1756tree
1757bot_manip (t)
1758 tree t;
1759{
1760 if (TREE_CODE (t) != TREE_LIST && ! TREE_SIDE_EFFECTS (t))
1761 return t;
1762 else if (TREE_CODE (t) == TARGET_EXPR)
73aad9b9 1763 {
02531345 1764 if (TREE_CODE (TREE_OPERAND (t, 1)) == AGGR_INIT_EXPR)
73aad9b9
JM
1765 {
1766 mark_used (TREE_OPERAND (TREE_OPERAND (TREE_OPERAND (t, 1), 0), 0));
1767 return build_cplus_new
1768 (TREE_TYPE (t), break_out_target_exprs (TREE_OPERAND (t, 1)));
1769 }
1770 t = copy_node (t);
1771 TREE_OPERAND (t, 0) = build (VAR_DECL, TREE_TYPE (t));
1772 layout_decl (TREE_OPERAND (t, 0), 0);
1773 return t;
1774 }
1775 else if (TREE_CODE (t) == CALL_EXPR)
1776 mark_used (TREE_OPERAND (TREE_OPERAND (t, 0), 0));
1777
878cd289
MS
1778 return NULL_TREE;
1779}
1780
1781/* Actually, we'll just clean out the target exprs for the moment. */
e92cc029 1782
878cd289
MS
1783tree
1784break_out_target_exprs (t)
1785 tree t;
1786{
1787 return mapcar (t, bot_manip);
1788}
f30432d7 1789
5566b478
MS
1790/* Obstack used for allocating nodes in template function and variable
1791 definitions. */
1792
5566b478
MS
1793/* Similar to `build_nt', except we build
1794 on the permanent_obstack, regardless. */
1795
1796tree
1797build_min_nt VPROTO((enum tree_code code, ...))
1798{
1799#ifndef __STDC__
1800 enum tree_code code;
1801#endif
1802 register struct obstack *ambient_obstack = expression_obstack;
1803 va_list p;
1804 register tree t;
1805 register int length;
1806 register int i;
1807
1808 VA_START (p, code);
1809
1810#ifndef __STDC__
1811 code = va_arg (p, enum tree_code);
1812#endif
1813
1814 expression_obstack = &permanent_obstack;
1815
1816 t = make_node (code);
1817 length = tree_code_length[(int) code];
1818 TREE_COMPLEXITY (t) = lineno;
1819
1820 for (i = 0; i < length; i++)
1821 {
1822 tree x = va_arg (p, tree);
1823 TREE_OPERAND (t, i) = copy_to_permanent (x);
1824 }
1825
1826 va_end (p);
1827 expression_obstack = ambient_obstack;
1828 return t;
1829}
1830
1831/* Similar to `build', except we build
1832 on the permanent_obstack, regardless. */
1833
1834tree
1835build_min VPROTO((enum tree_code code, tree tt, ...))
1836{
1837#ifndef __STDC__
1838 enum tree_code code;
1839 tree tt;
1840#endif
1841 register struct obstack *ambient_obstack = expression_obstack;
1842 va_list p;
1843 register tree t;
1844 register int length;
1845 register int i;
1846
1847 VA_START (p, tt);
1848
1849#ifndef __STDC__
1850 code = va_arg (p, enum tree_code);
1851 tt = va_arg (p, tree);
1852#endif
1853
1854 expression_obstack = &permanent_obstack;
1855
1856 t = make_node (code);
1857 length = tree_code_length[(int) code];
1858 TREE_TYPE (t) = tt;
1859 TREE_COMPLEXITY (t) = lineno;
1860
1861 for (i = 0; i < length; i++)
1862 {
1863 tree x = va_arg (p, tree);
1864 TREE_OPERAND (t, i) = copy_to_permanent (x);
1865 }
1866
1867 va_end (p);
1868 expression_obstack = ambient_obstack;
1869 return t;
1870}
1871
1872/* Same as `tree_cons' but make a permanent object. */
1873
1874tree
1875min_tree_cons (purpose, value, chain)
1876 tree purpose, value, chain;
1877{
1878 register tree node;
1879 register struct obstack *ambient_obstack = current_obstack;
1880 current_obstack = &permanent_obstack;
1881
fc378698
MS
1882 node = tree_cons (copy_to_permanent (purpose),
1883 copy_to_permanent (value), chain);
5566b478
MS
1884 current_obstack = ambient_obstack;
1885 return node;
1886}
1887
1888tree
1889get_type_decl (t)
1890 tree t;
1891{
5566b478
MS
1892 if (TREE_CODE (t) == TYPE_DECL)
1893 return t;
1894 if (TREE_CODE_CLASS (TREE_CODE (t)) == 't')
1895 return TYPE_STUB_DECL (t);
1896
1897 my_friendly_abort (42);
1898}
1899
1900int
1901can_free (obstack, t)
1902 struct obstack *obstack;
1903 tree t;
1904{
1905 int size;
1906
1907 if (TREE_CODE (t) == TREE_VEC)
1908 size = (TREE_VEC_LENGTH (t)-1) * sizeof (tree) + sizeof (struct tree_vec);
1909 else
1910 my_friendly_abort (42);
1911
1912#define ROUND(x) ((x + obstack_alignment_mask (obstack)) \
1913 & ~ obstack_alignment_mask (obstack))
1914 if ((char *)t + ROUND (size) == obstack_next_free (obstack))
1915 return 1;
1916#undef ROUND
1917
1918 return 0;
1919}
1920
1921/* Return first vector element whose BINFO_TYPE is ELEM.
934c6b13 1922 Return 0 if ELEM is not in VEC. VEC may be NULL_TREE. */
5566b478
MS
1923
1924tree
1925vec_binfo_member (elem, vec)
1926 tree elem, vec;
1927{
1928 int i;
934c6b13
MS
1929
1930 if (vec)
1931 for (i = 0; i < TREE_VEC_LENGTH (vec); ++i)
e92cc029 1932 if (comptypes (elem, BINFO_TYPE (TREE_VEC_ELT (vec, i)), 1))
934c6b13
MS
1933 return TREE_VEC_ELT (vec, i);
1934
5566b478
MS
1935 return NULL_TREE;
1936}
e76a2646
MS
1937
1938/* Kludge around the fact that DECL_CONTEXT for virtual functions returns
1939 the wrong thing for decl_function_context. Hopefully the uses in the
1940 backend won't matter, since we don't need a static chain for local class
1941 methods. FIXME! */
1942
1943tree
1944hack_decl_function_context (decl)
1945 tree decl;
1946{
1947 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_FUNCTION_MEMBER_P (decl))
1948 return decl_function_context (TYPE_MAIN_DECL (DECL_CLASS_CONTEXT (decl)));
1949 return decl_function_context (decl);
1950}
67d743fe
MS
1951
1952/* Return truthvalue of whether T1 is the same tree structure as T2.
1953 Return 1 if they are the same.
1954 Return 0 if they are understandably different.
1955 Return -1 if either contains tree structure not understood by
1956 this function. */
1957
1958int
1959cp_tree_equal (t1, t2)
1960 tree t1, t2;
1961{
1962 register enum tree_code code1, code2;
1963 int cmp;
1964
1965 if (t1 == t2)
1966 return 1;
1967 if (t1 == 0 || t2 == 0)
1968 return 0;
1969
1970 code1 = TREE_CODE (t1);
1971 code2 = TREE_CODE (t2);
1972
1973 if (code1 == NOP_EXPR || code1 == CONVERT_EXPR || code1 == NON_LVALUE_EXPR)
1974 if (code2 == NOP_EXPR || code2 == CONVERT_EXPR || code2 == NON_LVALUE_EXPR)
1975 return cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
1976 else
1977 return cp_tree_equal (TREE_OPERAND (t1, 0), t2);
1978 else if (code2 == NOP_EXPR || code2 == CONVERT_EXPR
1979 || code2 == NON_LVALUE_EXPR)
1980 return cp_tree_equal (t1, TREE_OPERAND (t2, 0));
1981
1982 if (code1 != code2)
1983 return 0;
1984
1985 switch (code1)
1986 {
1987 case INTEGER_CST:
1988 return TREE_INT_CST_LOW (t1) == TREE_INT_CST_LOW (t2)
1989 && TREE_INT_CST_HIGH (t1) == TREE_INT_CST_HIGH (t2);
1990
1991 case REAL_CST:
1992 return REAL_VALUES_EQUAL (TREE_REAL_CST (t1), TREE_REAL_CST (t2));
1993
1994 case STRING_CST:
1995 return TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
1996 && !bcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
1997 TREE_STRING_LENGTH (t1));
1998
1999 case CONSTRUCTOR:
2000 abort ();
2001
2002 case SAVE_EXPR:
2003 return cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
2004
2005 case CALL_EXPR:
2006 cmp = cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
2007 if (cmp <= 0)
2008 return cmp;
2009 return simple_cst_list_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
2010
2011 case TARGET_EXPR:
2012 /* Special case: if either target is an unallocated VAR_DECL,
2013 it means that it's going to be unified with whatever the
2014 TARGET_EXPR is really supposed to initialize, so treat it
2015 as being equivalent to anything. */
2016 if ((TREE_CODE (TREE_OPERAND (t1, 0)) == VAR_DECL
2017 && DECL_NAME (TREE_OPERAND (t1, 0)) == NULL_TREE
2018 && DECL_RTL (TREE_OPERAND (t1, 0)) == 0)
2019 || (TREE_CODE (TREE_OPERAND (t2, 0)) == VAR_DECL
2020 && DECL_NAME (TREE_OPERAND (t2, 0)) == NULL_TREE
2021 && DECL_RTL (TREE_OPERAND (t2, 0)) == 0))
2022 cmp = 1;
2023 else
2024 cmp = cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
2025 if (cmp <= 0)
2026 return cmp;
2027 return cp_tree_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
2028
2029 case WITH_CLEANUP_EXPR:
2030 cmp = cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
2031 if (cmp <= 0)
2032 return cmp;
2033 return cp_tree_equal (TREE_OPERAND (t1, 2), TREE_OPERAND (t1, 2));
2034
2035 case COMPONENT_REF:
2036 if (TREE_OPERAND (t1, 1) == TREE_OPERAND (t2, 1))
2037 return cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
2038 return 0;
2039
2040 case VAR_DECL:
2041 case PARM_DECL:
2042 case CONST_DECL:
2043 case FUNCTION_DECL:
2044 return 0;
2045
2046 case TEMPLATE_CONST_PARM:
98c1c668
JM
2047 return TEMPLATE_CONST_IDX (t1) == TEMPLATE_CONST_IDX (t2)
2048 && TEMPLATE_CONST_LEVEL (t1) == TEMPLATE_CONST_LEVEL (t2);
67d743fe
MS
2049
2050 case SIZEOF_EXPR:
2051 if (TREE_CODE (TREE_OPERAND (t1, 0)) != TREE_CODE (TREE_OPERAND (t2, 0)))
2052 return 0;
2053 if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (t1, 0))) == 't')
2054 return comptypes (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0), 1);
2055 break;
2056 }
2057
2058 switch (TREE_CODE_CLASS (code1))
2059 {
2060 int i;
2061 case '1':
2062 case '2':
2063 case '<':
2064 case 'e':
2065 case 'r':
2066 case 's':
2067 cmp = 1;
2068 for (i=0; i<tree_code_length[(int) code1]; ++i)
2069 {
2070 cmp = cp_tree_equal (TREE_OPERAND (t1, i), TREE_OPERAND (t2, i));
2071 if (cmp <= 0)
2072 return cmp;
2073 }
2074 return cmp;
2075 }
2076
2077 return -1;
2078}
73aad9b9
JM
2079
2080/* Similar to make_tree_vec, but build on a temporary obstack. */
2081
2082tree
2083make_temp_vec (len)
2084 int len;
2085{
2086 register tree node;
e66d884e
JM
2087 register struct obstack *ambient_obstack = current_obstack;
2088 current_obstack = expression_obstack;
73aad9b9 2089 node = make_tree_vec (len);
e66d884e 2090 current_obstack = ambient_obstack;
73aad9b9
JM
2091 return node;
2092}
d11ad92e 2093
e66d884e
JM
2094void
2095push_expression_obstack ()
2096{
2097 push_obstacks_nochange ();
2098 current_obstack = expression_obstack;
2099}
2100
d11ad92e
MS
2101/* The type of ARG when used as an lvalue. */
2102
2103tree
2104lvalue_type (arg)
2105 tree arg;
2106{
2107 return cp_build_type_variant
2108 (TREE_TYPE (arg), TREE_READONLY (arg), TREE_THIS_VOLATILE (arg));
2109}
2110
2111/* The type of ARG for printing error messages; denote lvalues with
2112 reference types. */
2113
2114tree
2115error_type (arg)
2116 tree arg;
2117{
2118 tree type = TREE_TYPE (arg);
2119 if (TREE_CODE (type) == ARRAY_TYPE)
2120 ;
2121 else if (real_lvalue_p (arg))
2122 type = build_reference_type (lvalue_type (arg));
2123 else if (IS_AGGR_TYPE (type))
2124 type = lvalue_type (arg);
2125
2126 return type;
2127}
eb66be0e
MS
2128
2129/* Does FUNCTION use a variable-length argument list? */
2130
2131int
2132varargs_function_p (function)
2133 tree function;
2134{
2135 tree parm = TYPE_ARG_TYPES (TREE_TYPE (function));
2136 for (; parm; parm = TREE_CHAIN (parm))
2137 if (TREE_VALUE (parm) == void_type_node)
2138 return 0;
2139 return 1;
2140}
This page took 0.516951 seconds and 5 git commands to generate.