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