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