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