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