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