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