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