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