]>
Commit | Line | Data |
---|---|---|
8d08fdba | 1 | /* Language-dependent node constructors for parse phase of GNU compiler. |
06ceef4e RK |
2 | Copyright (C) 1987, 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998, |
3 | 1999, 2000 Free Software Foundation, Inc. | |
8d08fdba MS |
4 | Hacked by Michael Tiemann (tiemann@cygnus.com) |
5 | ||
6 | This file is part of GNU CC. | |
7 | ||
8 | GNU CC is free software; you can redistribute it and/or modify | |
9 | it under the terms of the GNU General Public License as published by | |
10 | the Free Software Foundation; either version 2, or (at your option) | |
11 | any later version. | |
12 | ||
13 | GNU CC is distributed in the hope that it will be useful, | |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
19 | along with GNU CC; see the file COPYING. If not, write to | |
e9fa0c7c RK |
20 | the Free Software Foundation, 59 Temple Place - Suite 330, |
21 | Boston, MA 02111-1307, USA. */ | |
8d08fdba MS |
22 | |
23 | #include "config.h" | |
8d052bc7 | 24 | #include "system.h" |
8d08fdba MS |
25 | #include "obstack.h" |
26 | #include "tree.h" | |
27 | #include "cp-tree.h" | |
28 | #include "flags.h" | |
28cbf42c | 29 | #include "rtl.h" |
12027a89 | 30 | #include "toplev.h" |
87e3dbc9 | 31 | #include "ggc.h" |
46e8c075 MM |
32 | #include "insn-config.h" |
33 | #include "integrate.h" | |
12027a89 | 34 | |
158991b7 KG |
35 | static tree bot_manip PARAMS ((tree *, int *, void *)); |
36 | static tree bot_replace PARAMS ((tree *, int *, void *)); | |
37 | static tree build_cplus_array_type_1 PARAMS ((tree, tree)); | |
38 | static void list_hash_add PARAMS ((int, tree)); | |
39 | static int list_hash PARAMS ((tree, tree, tree)); | |
40 | static tree list_hash_lookup PARAMS ((int, tree, tree, tree)); | |
41 | static cp_lvalue_kind lvalue_p_1 PARAMS ((tree, int)); | |
42 | static tree no_linkage_helper PARAMS ((tree *, int *, void *)); | |
3b304f5b | 43 | static tree build_srcloc PARAMS ((const char *, int)); |
158991b7 KG |
44 | static void mark_list_hash PARAMS ((void *)); |
45 | static int statement_code_p PARAMS ((enum tree_code)); | |
46 | static tree mark_local_for_remap_r PARAMS ((tree *, int *, void *)); | |
47 | static tree cp_unsave_r PARAMS ((tree *, int *, void *)); | |
48 | static void cp_unsave PARAMS ((tree *)); | |
49 | static tree build_target_expr PARAMS ((tree, tree)); | |
49c249e1 | 50 | |
27b8d0cd MM |
51 | /* If REF is an lvalue, returns the kind of lvalue that REF is. |
52 | Otherwise, returns clk_none. If TREAT_CLASS_RVALUES_AS_LVALUES is | |
53 | non-zero, rvalues of class type are considered lvalues. */ | |
8d08fdba | 54 | |
27b8d0cd | 55 | static cp_lvalue_kind |
69851283 | 56 | lvalue_p_1 (ref, treat_class_rvalues_as_lvalues) |
8ccc31eb | 57 | tree ref; |
69851283 | 58 | int treat_class_rvalues_as_lvalues; |
8ccc31eb | 59 | { |
27b8d0cd MM |
60 | cp_lvalue_kind op1_lvalue_kind = clk_none; |
61 | cp_lvalue_kind op2_lvalue_kind = clk_none; | |
62 | ||
8ccc31eb | 63 | if (TREE_CODE (TREE_TYPE (ref)) == REFERENCE_TYPE) |
27b8d0cd | 64 | return clk_ordinary; |
8ccc31eb | 65 | |
4ac14744 | 66 | if (ref == current_class_ptr && flag_this_is_variable <= 0) |
27b8d0cd | 67 | return clk_none; |
8ccc31eb MS |
68 | |
69 | switch (TREE_CODE (ref)) | |
70 | { | |
71 | /* preincrements and predecrements are valid lvals, provided | |
e92cc029 | 72 | what they refer to are valid lvals. */ |
8ccc31eb MS |
73 | case PREINCREMENT_EXPR: |
74 | case PREDECREMENT_EXPR: | |
8ccc31eb | 75 | case SAVE_EXPR: |
c7ae64f2 JM |
76 | case UNSAVE_EXPR: |
77 | case TRY_CATCH_EXPR: | |
78 | case WITH_CLEANUP_EXPR: | |
69851283 MM |
79 | case REALPART_EXPR: |
80 | case IMAGPART_EXPR: | |
06126ca2 | 81 | case NOP_EXPR: |
69851283 MM |
82 | return lvalue_p_1 (TREE_OPERAND (ref, 0), |
83 | treat_class_rvalues_as_lvalues); | |
8ccc31eb | 84 | |
27b8d0cd MM |
85 | case COMPONENT_REF: |
86 | op1_lvalue_kind = lvalue_p_1 (TREE_OPERAND (ref, 0), | |
87 | treat_class_rvalues_as_lvalues); | |
88 | if (op1_lvalue_kind | |
89 | /* The "field" can be a FUNCTION_DECL or an OVERLOAD in some | |
90 | situations. */ | |
91 | && TREE_CODE (TREE_OPERAND (ref, 1)) == FIELD_DECL | |
807625cf | 92 | && DECL_C_BIT_FIELD (TREE_OPERAND (ref, 1))) |
27b8d0cd MM |
93 | { |
94 | /* Clear the ordinary bit. If this object was a class | |
95 | rvalue we want to preserve that information. */ | |
96 | op1_lvalue_kind &= ~clk_ordinary; | |
97 | /* The lvalue is for a btifield. */ | |
98 | op1_lvalue_kind |= clk_bitfield; | |
99 | } | |
100 | return op1_lvalue_kind; | |
101 | ||
8ccc31eb | 102 | case STRING_CST: |
27b8d0cd | 103 | return clk_ordinary; |
8ccc31eb MS |
104 | |
105 | case VAR_DECL: | |
106 | if (TREE_READONLY (ref) && ! TREE_STATIC (ref) | |
107 | && DECL_LANG_SPECIFIC (ref) | |
108 | && DECL_IN_AGGR_P (ref)) | |
27b8d0cd | 109 | return clk_none; |
8ccc31eb MS |
110 | case INDIRECT_REF: |
111 | case ARRAY_REF: | |
112 | case PARM_DECL: | |
113 | case RESULT_DECL: | |
59e76fc6 | 114 | if (TREE_CODE (TREE_TYPE (ref)) != METHOD_TYPE) |
27b8d0cd | 115 | return clk_ordinary; |
8ccc31eb MS |
116 | break; |
117 | ||
8ccc31eb MS |
118 | /* A currently unresolved scope ref. */ |
119 | case SCOPE_REF: | |
120 | my_friendly_abort (103); | |
121 | case OFFSET_REF: | |
122 | if (TREE_CODE (TREE_OPERAND (ref, 1)) == FUNCTION_DECL) | |
27b8d0cd MM |
123 | return clk_ordinary; |
124 | /* Fall through. */ | |
125 | case MAX_EXPR: | |
126 | case MIN_EXPR: | |
127 | op1_lvalue_kind = lvalue_p_1 (TREE_OPERAND (ref, 0), | |
128 | treat_class_rvalues_as_lvalues); | |
129 | op2_lvalue_kind = lvalue_p_1 (TREE_OPERAND (ref, 1), | |
130 | treat_class_rvalues_as_lvalues); | |
8ccc31eb MS |
131 | break; |
132 | ||
133 | case COND_EXPR: | |
27b8d0cd MM |
134 | op1_lvalue_kind = lvalue_p_1 (TREE_OPERAND (ref, 1), |
135 | treat_class_rvalues_as_lvalues); | |
136 | op2_lvalue_kind = lvalue_p_1 (TREE_OPERAND (ref, 2), | |
137 | treat_class_rvalues_as_lvalues); | |
138 | break; | |
8ccc31eb MS |
139 | |
140 | case MODIFY_EXPR: | |
27b8d0cd | 141 | return clk_ordinary; |
8ccc31eb MS |
142 | |
143 | case COMPOUND_EXPR: | |
69851283 | 144 | return lvalue_p_1 (TREE_OPERAND (ref, 1), |
27b8d0cd | 145 | treat_class_rvalues_as_lvalues); |
69851283 MM |
146 | |
147 | case TARGET_EXPR: | |
27b8d0cd | 148 | return treat_class_rvalues_as_lvalues ? clk_class : clk_none; |
69851283 MM |
149 | |
150 | case CALL_EXPR: | |
356955cf | 151 | case VA_ARG_EXPR: |
27b8d0cd MM |
152 | return ((treat_class_rvalues_as_lvalues |
153 | && IS_AGGR_TYPE (TREE_TYPE (ref))) | |
154 | ? clk_class : clk_none); | |
69851283 MM |
155 | |
156 | case FUNCTION_DECL: | |
157 | /* All functions (except non-static-member functions) are | |
158 | lvalues. */ | |
27b8d0cd MM |
159 | return (DECL_NONSTATIC_MEMBER_FUNCTION_P (ref) |
160 | ? clk_none : clk_ordinary); | |
7f85441b KG |
161 | |
162 | default: | |
163 | break; | |
8ccc31eb MS |
164 | } |
165 | ||
27b8d0cd MM |
166 | /* If one operand is not an lvalue at all, then this expression is |
167 | not an lvalue. */ | |
168 | if (!op1_lvalue_kind || !op2_lvalue_kind) | |
169 | return clk_none; | |
170 | ||
171 | /* Otherwise, it's an lvalue, and it has all the odd properties | |
172 | contributed by either operand. */ | |
173 | op1_lvalue_kind = op1_lvalue_kind | op2_lvalue_kind; | |
174 | /* It's not an ordinary lvalue if it involves either a bit-field or | |
175 | a class rvalue. */ | |
176 | if ((op1_lvalue_kind & ~clk_ordinary) != clk_none) | |
177 | op1_lvalue_kind &= ~clk_ordinary; | |
178 | return op1_lvalue_kind; | |
8ccc31eb MS |
179 | } |
180 | ||
27b8d0cd MM |
181 | /* If REF is an lvalue, returns the kind of lvalue that REF is. |
182 | Otherwise, returns clk_none. Lvalues can be assigned, unless they | |
183 | have TREE_READONLY, or unless they are FUNCTION_DECLs. Lvalues can | |
184 | have their address taken, unless they have DECL_REGISTER. */ | |
69851283 | 185 | |
27b8d0cd | 186 | cp_lvalue_kind |
69851283 MM |
187 | real_lvalue_p (ref) |
188 | tree ref; | |
189 | { | |
190 | return lvalue_p_1 (ref, /*treat_class_rvalues_as_lvalues=*/0); | |
191 | } | |
192 | ||
27b8d0cd MM |
193 | /* This differs from real_lvalue_p in that class rvalues are |
194 | considered lvalues. */ | |
69851283 | 195 | |
8d08fdba MS |
196 | int |
197 | lvalue_p (ref) | |
198 | tree ref; | |
199 | { | |
27b8d0cd MM |
200 | return |
201 | (lvalue_p_1 (ref, /*treat_class_rvalues_as_lvalues=*/1) != clk_none); | |
8d08fdba MS |
202 | } |
203 | ||
204 | /* Return nonzero if REF is an lvalue valid for this language; | |
205 | otherwise, print an error message and return zero. */ | |
206 | ||
207 | int | |
208 | lvalue_or_else (ref, string) | |
209 | tree ref; | |
834003f4 | 210 | const char *string; |
8d08fdba MS |
211 | { |
212 | int win = lvalue_p (ref); | |
213 | if (! win) | |
8251199e | 214 | error ("non-lvalue in %s", string); |
8d08fdba MS |
215 | return win; |
216 | } | |
217 | ||
c506ca22 MM |
218 | /* Build a TARGET_EXPR, initializing the DECL with the VALUE. */ |
219 | ||
220 | static tree | |
221 | build_target_expr (decl, value) | |
222 | tree decl; | |
223 | tree value; | |
224 | { | |
225 | tree t; | |
226 | ||
227 | t = build (TARGET_EXPR, TREE_TYPE (decl), decl, value, | |
228 | maybe_build_cleanup (decl), NULL_TREE); | |
229 | /* We always set TREE_SIDE_EFFECTS so that expand_expr does not | |
230 | ignore the TARGET_EXPR. If there really turn out to be no | |
231 | side-effects, then the optimizer should be able to get rid of | |
232 | whatever code is generated anyhow. */ | |
233 | TREE_SIDE_EFFECTS (t) = 1; | |
234 | ||
235 | return t; | |
236 | } | |
237 | ||
8d08fdba MS |
238 | /* INIT is a CALL_EXPR which needs info about its target. |
239 | TYPE is the type that this initialization should appear to have. | |
240 | ||
241 | Build an encapsulation of the initialization to perform | |
242 | and return it so that it can be processed by language-independent | |
2ee887f2 | 243 | and language-specific expression expanders. */ |
e92cc029 | 244 | |
8d08fdba | 245 | tree |
5566b478 | 246 | build_cplus_new (type, init) |
8d08fdba MS |
247 | tree type; |
248 | tree init; | |
8d08fdba | 249 | { |
e1376b00 | 250 | tree fn; |
e8abc66f MS |
251 | tree slot; |
252 | tree rval; | |
253 | ||
27b8d0cd MM |
254 | /* Make sure that we're not trying to create an instance of an |
255 | abstract class. */ | |
5bb2f1e7 | 256 | abstract_virtuals_error (NULL_TREE, type); |
27b8d0cd | 257 | |
02531345 | 258 | if (TREE_CODE (init) != CALL_EXPR && TREE_CODE (init) != AGGR_INIT_EXPR) |
06126ca2 | 259 | return convert (type, init); |
c11b6f21 | 260 | |
e8abc66f | 261 | slot = build (VAR_DECL, type); |
aa36c081 | 262 | DECL_ARTIFICIAL (slot) = 1; |
46e8c075 | 263 | DECL_CONTEXT (slot) = current_function_decl; |
e8abc66f | 264 | layout_decl (slot, 0); |
e1376b00 MM |
265 | |
266 | /* We split the CALL_EXPR into its function and its arguments here. | |
267 | Then, in expand_expr, we put them back together. The reason for | |
268 | this is that this expression might be a default argument | |
269 | expression. In that case, we need a new temporary every time the | |
270 | expression is used. That's what break_out_target_exprs does; it | |
271 | replaces every AGGR_INIT_EXPR with a copy that uses a fresh | |
272 | temporary slot. Then, expand_expr builds up a call-expression | |
273 | using the new slot. */ | |
274 | fn = TREE_OPERAND (init, 0); | |
275 | rval = build (AGGR_INIT_EXPR, type, fn, TREE_OPERAND (init, 1), slot); | |
8d08fdba | 276 | TREE_SIDE_EFFECTS (rval) = 1; |
e1376b00 MM |
277 | AGGR_INIT_VIA_CTOR_P (rval) |
278 | = (TREE_CODE (fn) == ADDR_EXPR | |
279 | && TREE_CODE (TREE_OPERAND (fn, 0)) == FUNCTION_DECL | |
280 | && DECL_CONSTRUCTOR_P (TREE_OPERAND (fn, 0))); | |
9d85d30c | 281 | rval = build_target_expr (slot, rval); |
8d08fdba | 282 | |
8d08fdba MS |
283 | return rval; |
284 | } | |
285 | ||
c506ca22 MM |
286 | /* Buidl a TARGET_EXPR using INIT to initialize a new temporary of the |
287 | indicated TYPE. */ | |
aa36c081 JM |
288 | |
289 | tree | |
c506ca22 | 290 | build_target_expr_with_type (init, type) |
aa36c081 | 291 | tree init; |
c506ca22 | 292 | tree type; |
aa36c081 JM |
293 | { |
294 | tree slot; | |
295 | tree rval; | |
296 | ||
5062dbd5 JM |
297 | if (TREE_CODE (init) == TARGET_EXPR) |
298 | return init; | |
299 | ||
c506ca22 | 300 | slot = build (VAR_DECL, type); |
aa36c081 | 301 | DECL_ARTIFICIAL (slot) = 1; |
c506ca22 | 302 | DECL_CONTEXT (slot) = current_function_decl; |
aa36c081 | 303 | layout_decl (slot, 0); |
9d85d30c | 304 | rval = build_target_expr (slot, init); |
aa36c081 JM |
305 | |
306 | return rval; | |
307 | } | |
308 | ||
c506ca22 MM |
309 | /* Like build_target_expr_with_type, but use the type of INIT. */ |
310 | ||
311 | tree | |
312 | get_target_expr (init) | |
313 | tree init; | |
314 | { | |
315 | return build_target_expr_with_type (init, TREE_TYPE (init)); | |
316 | } | |
317 | ||
8d08fdba MS |
318 | /* Recursively search EXP for CALL_EXPRs that need cleanups and replace |
319 | these CALL_EXPRs with tree nodes that will perform the cleanups. */ | |
320 | ||
321 | tree | |
322 | break_out_cleanups (exp) | |
323 | tree exp; | |
324 | { | |
325 | tree tmp = exp; | |
326 | ||
327 | if (TREE_CODE (tmp) == CALL_EXPR | |
834c6dff | 328 | && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TREE_TYPE (tmp))) |
5566b478 | 329 | return build_cplus_new (TREE_TYPE (tmp), tmp); |
8d08fdba MS |
330 | |
331 | while (TREE_CODE (tmp) == NOP_EXPR | |
332 | || TREE_CODE (tmp) == CONVERT_EXPR | |
333 | || TREE_CODE (tmp) == NON_LVALUE_EXPR) | |
334 | { | |
335 | if (TREE_CODE (TREE_OPERAND (tmp, 0)) == CALL_EXPR | |
834c6dff | 336 | && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TREE_TYPE (TREE_OPERAND (tmp, 0)))) |
8d08fdba MS |
337 | { |
338 | TREE_OPERAND (tmp, 0) | |
339 | = build_cplus_new (TREE_TYPE (TREE_OPERAND (tmp, 0)), | |
5566b478 | 340 | TREE_OPERAND (tmp, 0)); |
8d08fdba MS |
341 | break; |
342 | } | |
343 | else | |
344 | tmp = TREE_OPERAND (tmp, 0); | |
345 | } | |
346 | return exp; | |
347 | } | |
348 | ||
349 | /* Recursively perform a preorder search EXP for CALL_EXPRs, making | |
350 | copies where they are found. Returns a deep copy all nodes transitively | |
351 | containing CALL_EXPRs. */ | |
352 | ||
353 | tree | |
354 | break_out_calls (exp) | |
355 | tree exp; | |
356 | { | |
a703fb38 | 357 | register tree t1, t2 = NULL_TREE; |
8d08fdba MS |
358 | register enum tree_code code; |
359 | register int changed = 0; | |
360 | register int i; | |
361 | ||
362 | if (exp == NULL_TREE) | |
363 | return exp; | |
364 | ||
365 | code = TREE_CODE (exp); | |
366 | ||
367 | if (code == CALL_EXPR) | |
368 | return copy_node (exp); | |
369 | ||
e92cc029 | 370 | /* Don't try and defeat a save_expr, as it should only be done once. */ |
8d08fdba MS |
371 | if (code == SAVE_EXPR) |
372 | return exp; | |
373 | ||
374 | switch (TREE_CODE_CLASS (code)) | |
375 | { | |
376 | default: | |
377 | abort (); | |
378 | ||
379 | case 'c': /* a constant */ | |
380 | case 't': /* a type node */ | |
381 | case 'x': /* something random, like an identifier or an ERROR_MARK. */ | |
382 | return exp; | |
383 | ||
384 | case 'd': /* A decl node */ | |
f376e137 MS |
385 | #if 0 /* This is bogus. jason 9/21/94 */ |
386 | ||
8d08fdba MS |
387 | t1 = break_out_calls (DECL_INITIAL (exp)); |
388 | if (t1 != DECL_INITIAL (exp)) | |
389 | { | |
390 | exp = copy_node (exp); | |
391 | DECL_INITIAL (exp) = t1; | |
392 | } | |
f376e137 | 393 | #endif |
8d08fdba MS |
394 | return exp; |
395 | ||
396 | case 'b': /* A block node */ | |
397 | { | |
398 | /* Don't know how to handle these correctly yet. Must do a | |
399 | break_out_calls on all DECL_INITIAL values for local variables, | |
400 | and also break_out_calls on all sub-blocks and sub-statements. */ | |
401 | abort (); | |
402 | } | |
403 | return exp; | |
404 | ||
405 | case 'e': /* an expression */ | |
406 | case 'r': /* a reference */ | |
407 | case 's': /* an expression with side effects */ | |
8d5e6e25 | 408 | for (i = TREE_CODE_LENGTH (code) - 1; i >= 0; i--) |
8d08fdba MS |
409 | { |
410 | t1 = break_out_calls (TREE_OPERAND (exp, i)); | |
411 | if (t1 != TREE_OPERAND (exp, i)) | |
412 | { | |
413 | exp = copy_node (exp); | |
414 | TREE_OPERAND (exp, i) = t1; | |
415 | } | |
416 | } | |
417 | return exp; | |
418 | ||
419 | case '<': /* a comparison expression */ | |
420 | case '2': /* a binary arithmetic expression */ | |
421 | t2 = break_out_calls (TREE_OPERAND (exp, 1)); | |
422 | if (t2 != TREE_OPERAND (exp, 1)) | |
423 | changed = 1; | |
424 | case '1': /* a unary arithmetic expression */ | |
425 | t1 = break_out_calls (TREE_OPERAND (exp, 0)); | |
426 | if (t1 != TREE_OPERAND (exp, 0)) | |
427 | changed = 1; | |
428 | if (changed) | |
429 | { | |
8d5e6e25 | 430 | if (TREE_CODE_LENGTH (code) == 1) |
8d08fdba MS |
431 | return build1 (code, TREE_TYPE (exp), t1); |
432 | else | |
433 | return build (code, TREE_TYPE (exp), t1, t2); | |
434 | } | |
435 | return exp; | |
436 | } | |
437 | ||
438 | } | |
439 | \f | |
0a2c2fd1 | 440 | extern struct obstack permanent_obstack; |
8d08fdba MS |
441 | |
442 | /* Here is how primitive or already-canonicalized types' hash | |
443 | codes are made. MUST BE CONSISTENT WITH tree.c !!! */ | |
444 | #define TYPE_HASH(TYPE) ((HOST_WIDE_INT) (TYPE) & 0777777) | |
445 | ||
446 | /* Construct, lay out and return the type of methods belonging to class | |
447 | BASETYPE and whose arguments are described by ARGTYPES and whose values | |
448 | are described by RETTYPE. If each type exists already, reuse it. */ | |
e92cc029 | 449 | |
8d08fdba MS |
450 | tree |
451 | build_cplus_method_type (basetype, rettype, argtypes) | |
452 | tree basetype, rettype, argtypes; | |
453 | { | |
454 | register tree t; | |
455 | tree ptype; | |
456 | int hashcode; | |
457 | ||
458 | /* Make a node of the sort we want. */ | |
459 | t = make_node (METHOD_TYPE); | |
460 | ||
461 | TYPE_METHOD_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype); | |
462 | TREE_TYPE (t) = rettype; | |
6eabb241 | 463 | ptype = build_pointer_type (basetype); |
863adfc0 | 464 | |
8d08fdba | 465 | /* The actual arglist for this function includes a "hidden" argument |
454fa7a7 | 466 | which is "this". Put it into the list of argument types. */ |
8d08fdba MS |
467 | argtypes = tree_cons (NULL_TREE, ptype, argtypes); |
468 | TYPE_ARG_TYPES (t) = argtypes; | |
469 | TREE_SIDE_EFFECTS (argtypes) = 1; /* Mark first argtype as "artificial". */ | |
470 | ||
471 | /* If we already have such a type, use the old one and free this one. | |
472 | Note that it also frees up the above cons cell if found. */ | |
558475f0 MM |
473 | hashcode = TYPE_HASH (basetype) + TYPE_HASH (rettype) + |
474 | type_hash_list (argtypes); | |
475 | ||
8d08fdba MS |
476 | t = type_hash_canon (hashcode, t); |
477 | ||
d0f062fb | 478 | if (!COMPLETE_TYPE_P (t)) |
8d08fdba MS |
479 | layout_type (t); |
480 | ||
481 | return t; | |
482 | } | |
483 | ||
bd6dd845 | 484 | static tree |
e349ee73 | 485 | build_cplus_array_type_1 (elt_type, index_type) |
8d08fdba MS |
486 | tree elt_type; |
487 | tree index_type; | |
488 | { | |
8d08fdba MS |
489 | tree t; |
490 | ||
adecb3f4 MM |
491 | if (elt_type == error_mark_node || index_type == error_mark_node) |
492 | return error_mark_node; | |
493 | ||
7bdbfa05 MM |
494 | if (processing_template_decl |
495 | || uses_template_parms (elt_type) | |
496 | || uses_template_parms (index_type)) | |
5566b478 MS |
497 | { |
498 | t = make_node (ARRAY_TYPE); | |
499 | TREE_TYPE (t) = elt_type; | |
500 | TYPE_DOMAIN (t) = index_type; | |
501 | } | |
502 | else | |
80661759 | 503 | t = build_array_type (elt_type, index_type); |
8d08fdba MS |
504 | |
505 | /* Push these needs up so that initialization takes place | |
506 | more easily. */ | |
db3626d1 MM |
507 | TYPE_NEEDS_CONSTRUCTING (t) |
508 | = TYPE_NEEDS_CONSTRUCTING (TYPE_MAIN_VARIANT (elt_type)); | |
834c6dff MM |
509 | TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t) |
510 | = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TYPE_MAIN_VARIANT (elt_type)); | |
8d08fdba MS |
511 | return t; |
512 | } | |
e349ee73 MS |
513 | |
514 | tree | |
515 | build_cplus_array_type (elt_type, index_type) | |
516 | tree elt_type; | |
517 | tree index_type; | |
518 | { | |
519 | tree t; | |
91063b51 MM |
520 | int type_quals = CP_TYPE_QUALS (elt_type); |
521 | ||
e349ee73 MS |
522 | elt_type = TYPE_MAIN_VARIANT (elt_type); |
523 | ||
524 | t = build_cplus_array_type_1 (elt_type, index_type); | |
525 | ||
91063b51 MM |
526 | if (type_quals != TYPE_UNQUALIFIED) |
527 | t = cp_build_qualified_type (t, type_quals); | |
e349ee73 MS |
528 | |
529 | return t; | |
530 | } | |
8d08fdba | 531 | \f |
adecb3f4 MM |
532 | /* Make a variant of TYPE, qualified with the TYPE_QUALS. Handles |
533 | arrays correctly. In particular, if TYPE is an array of T's, and | |
534 | TYPE_QUALS is non-empty, returns an array of qualified T's. If | |
535 | at attempt is made to qualify a type illegally, and COMPLAIN is | |
536 | non-zero, an error is issued. If COMPLAIN is zero, error_mark_node | |
537 | is returned. */ | |
f376e137 MS |
538 | |
539 | tree | |
adecb3f4 | 540 | cp_build_qualified_type_real (type, type_quals, complain) |
f376e137 | 541 | tree type; |
91063b51 | 542 | int type_quals; |
adecb3f4 | 543 | int complain; |
f376e137 | 544 | { |
2adeacc9 MM |
545 | tree result; |
546 | ||
e76a2646 MS |
547 | if (type == error_mark_node) |
548 | return type; | |
e271912d JM |
549 | |
550 | if (type_quals == TYPE_QUALS (type)) | |
551 | return type; | |
552 | ||
91063b51 MM |
553 | /* A restrict-qualified pointer type must be a pointer (or reference) |
554 | to object or incomplete type. */ | |
555 | if ((type_quals & TYPE_QUAL_RESTRICT) | |
adecb3f4 | 556 | && TREE_CODE (type) != TEMPLATE_TYPE_PARM |
91063b51 MM |
557 | && (!POINTER_TYPE_P (type) |
558 | || TYPE_PTRMEM_P (type) | |
559 | || TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE)) | |
560 | { | |
adecb3f4 MM |
561 | if (complain) |
562 | cp_error ("`%T' cannot be `restrict'-qualified", type); | |
563 | else | |
564 | return error_mark_node; | |
565 | ||
91063b51 MM |
566 | type_quals &= ~TYPE_QUAL_RESTRICT; |
567 | } | |
568 | ||
77700469 MM |
569 | if (type_quals != TYPE_UNQUALIFIED |
570 | && TREE_CODE (type) == FUNCTION_TYPE) | |
571 | { | |
adecb3f4 MM |
572 | if (complain) |
573 | cp_error ("`%T' cannot be `const'-, `volatile'-, or `restrict'-qualified", type); | |
574 | else | |
575 | return error_mark_node; | |
77700469 MM |
576 | type_quals = TYPE_UNQUALIFIED; |
577 | } | |
578 | else if (TREE_CODE (type) == ARRAY_TYPE) | |
f376e137 | 579 | { |
db3626d1 MM |
580 | /* In C++, the qualification really applies to the array element |
581 | type. Obtain the appropriately qualified element type. */ | |
582 | tree t; | |
583 | tree element_type | |
584 | = cp_build_qualified_type_real (TREE_TYPE (type), | |
585 | type_quals, | |
586 | complain); | |
587 | ||
588 | if (element_type == error_mark_node) | |
adecb3f4 | 589 | return error_mark_node; |
f376e137 | 590 | |
db3626d1 MM |
591 | /* See if we already have an identically qualified type. */ |
592 | for (t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t)) | |
593 | if (CP_TYPE_QUALS (t) == type_quals) | |
594 | break; | |
f376e137 | 595 | |
db3626d1 MM |
596 | /* If we didn't already have it, create it now. */ |
597 | if (!t) | |
f376e137 | 598 | { |
db3626d1 MM |
599 | /* Make a new array type, just like the old one, but with the |
600 | appropriately qualified element type. */ | |
601 | t = build_type_copy (type); | |
602 | TREE_TYPE (t) = element_type; | |
f376e137 MS |
603 | } |
604 | ||
db3626d1 | 605 | /* Even if we already had this variant, we update |
834c6dff | 606 | TYPE_NEEDS_CONSTRUCTING and TYPE_HAS_NONTRIVIAL_DESTRUCTOR in case |
db3626d1 MM |
607 | they changed since the variant was originally created. |
608 | ||
609 | This seems hokey; if there is some way to use a previous | |
610 | variant *without* coming through here, | |
611 | TYPE_NEEDS_CONSTRUCTING will never be updated. */ | |
612 | TYPE_NEEDS_CONSTRUCTING (t) | |
613 | = TYPE_NEEDS_CONSTRUCTING (TYPE_MAIN_VARIANT (element_type)); | |
834c6dff MM |
614 | TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t) |
615 | = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TYPE_MAIN_VARIANT (element_type)); | |
db3626d1 | 616 | return t; |
f376e137 | 617 | } |
2adeacc9 MM |
618 | else if (TYPE_PTRMEMFUNC_P (type)) |
619 | { | |
620 | /* For a pointer-to-member type, we can't just return a | |
621 | cv-qualified version of the RECORD_TYPE. If we do, we | |
622 | haven't change the field that contains the actual pointer to | |
623 | a method, and so TYPE_PTRMEMFUNC_FN_TYPE will be wrong. */ | |
624 | tree t; | |
625 | ||
626 | t = TYPE_PTRMEMFUNC_FN_TYPE (type); | |
627 | t = cp_build_qualified_type_real (t, type_quals, complain); | |
46cbda4a | 628 | return build_ptrmemfunc_type (t); |
2adeacc9 MM |
629 | } |
630 | ||
631 | /* Retrieve (or create) the appropriately qualified variant. */ | |
632 | result = build_qualified_type (type, type_quals); | |
633 | ||
634 | /* If this was a pointer-to-method type, and we just made a copy, | |
635 | then we need to clear the cached associated | |
636 | pointer-to-member-function type; it is not valid for the new | |
637 | type. */ | |
638 | if (result != type | |
639 | && TREE_CODE (type) == POINTER_TYPE | |
640 | && TREE_CODE (TREE_TYPE (type)) == METHOD_TYPE) | |
641 | TYPE_SET_PTRMEMFUNC_TYPE (result, NULL_TREE); | |
642 | ||
643 | return result; | |
f376e137 | 644 | } |
53929c47 JM |
645 | |
646 | /* Returns the canonical version of TYPE. In other words, if TYPE is | |
647 | a typedef, returns the underlying type. The cv-qualification of | |
648 | the type returned matches the type input; they will always be | |
649 | compatible types. */ | |
650 | ||
651 | tree | |
652 | canonical_type_variant (t) | |
653 | tree t; | |
654 | { | |
91063b51 | 655 | return cp_build_qualified_type (TYPE_MAIN_VARIANT (t), CP_TYPE_QUALS (t)); |
53929c47 | 656 | } |
f376e137 | 657 | \f |
dfbcd65a | 658 | /* Makes new binfos for the indirect bases under BINFO, and updates |
9a71c18b JM |
659 | BINFO_OFFSET for them and their bases. */ |
660 | ||
dfbcd65a JM |
661 | void |
662 | unshare_base_binfos (binfo) | |
663 | tree binfo; | |
9a71c18b | 664 | { |
dfbcd65a JM |
665 | tree binfos = BINFO_BASETYPES (binfo); |
666 | tree new_binfo; | |
667 | int j; | |
9a71c18b | 668 | |
dfbcd65a JM |
669 | if (binfos == NULL_TREE) |
670 | return; | |
9a71c18b | 671 | |
dfbcd65a JM |
672 | /* Now unshare the structure beneath BINFO. */ |
673 | for (j = TREE_VEC_LENGTH (binfos)-1; | |
674 | j >= 0; j--) | |
675 | { | |
676 | tree base_binfo = TREE_VEC_ELT (binfos, j); | |
677 | new_binfo = TREE_VEC_ELT (binfos, j) | |
678 | = make_binfo (BINFO_OFFSET (base_binfo), | |
679 | base_binfo, | |
680 | BINFO_VTABLE (base_binfo), | |
681 | BINFO_VIRTUALS (base_binfo)); | |
682 | TREE_VIA_PUBLIC (new_binfo) = TREE_VIA_PUBLIC (base_binfo); | |
683 | TREE_VIA_PROTECTED (new_binfo) = TREE_VIA_PROTECTED (base_binfo); | |
684 | TREE_VIA_VIRTUAL (new_binfo) = TREE_VIA_VIRTUAL (base_binfo); | |
685 | BINFO_INHERITANCE_CHAIN (new_binfo) = binfo; | |
686 | unshare_base_binfos (new_binfo); | |
9a71c18b JM |
687 | } |
688 | } | |
689 | ||
8d08fdba MS |
690 | \f |
691 | /* Hashing of lists so that we don't make duplicates. | |
692 | The entry point is `list_hash_canon'. */ | |
693 | ||
694 | /* Each hash table slot is a bucket containing a chain | |
695 | of these structures. */ | |
696 | ||
697 | struct list_hash | |
698 | { | |
699 | struct list_hash *next; /* Next structure in the bucket. */ | |
700 | int hashcode; /* Hash code of this list. */ | |
701 | tree list; /* The list recorded here. */ | |
702 | }; | |
703 | ||
704 | /* Now here is the hash table. When recording a list, it is added | |
705 | to the slot whose index is the hash code mod the table size. | |
706 | Note that the hash table is used for several kinds of lists. | |
707 | While all these live in the same table, they are completely independent, | |
708 | and the hash code is computed differently for each of these. */ | |
709 | ||
710 | #define TYPE_HASH_SIZE 59 | |
37c46b43 | 711 | static struct list_hash *list_hash_table[TYPE_HASH_SIZE]; |
8d08fdba MS |
712 | |
713 | /* Compute a hash code for a list (chain of TREE_LIST nodes | |
714 | with goodies in the TREE_PURPOSE, TREE_VALUE, and bits of the | |
715 | TREE_COMMON slots), by adding the hash codes of the individual entries. */ | |
716 | ||
37c46b43 MS |
717 | static int |
718 | list_hash (purpose, value, chain) | |
719 | tree purpose, value, chain; | |
8d08fdba MS |
720 | { |
721 | register int hashcode = 0; | |
722 | ||
37c46b43 MS |
723 | if (chain) |
724 | hashcode += TYPE_HASH (chain); | |
8d08fdba | 725 | |
37c46b43 MS |
726 | if (value) |
727 | hashcode += TYPE_HASH (value); | |
8d08fdba MS |
728 | else |
729 | hashcode += 1007; | |
37c46b43 MS |
730 | if (purpose) |
731 | hashcode += TYPE_HASH (purpose); | |
8d08fdba MS |
732 | else |
733 | hashcode += 1009; | |
734 | return hashcode; | |
735 | } | |
736 | ||
737 | /* Look in the type hash table for a type isomorphic to TYPE. | |
738 | If one is found, return it. Otherwise return 0. */ | |
739 | ||
37c46b43 | 740 | static tree |
51632249 JM |
741 | list_hash_lookup (hashcode, purpose, value, chain) |
742 | int hashcode; | |
37c46b43 | 743 | tree purpose, value, chain; |
8d08fdba MS |
744 | { |
745 | register struct list_hash *h; | |
37c46b43 | 746 | |
8d08fdba MS |
747 | for (h = list_hash_table[hashcode % TYPE_HASH_SIZE]; h; h = h->next) |
748 | if (h->hashcode == hashcode | |
37c46b43 MS |
749 | && TREE_PURPOSE (h->list) == purpose |
750 | && TREE_VALUE (h->list) == value | |
751 | && TREE_CHAIN (h->list) == chain) | |
752 | return h->list; | |
8d08fdba MS |
753 | return 0; |
754 | } | |
755 | ||
756 | /* Add an entry to the list-hash-table | |
757 | for a list TYPE whose hash code is HASHCODE. */ | |
758 | ||
37c46b43 | 759 | static void |
8d08fdba MS |
760 | list_hash_add (hashcode, list) |
761 | int hashcode; | |
762 | tree list; | |
763 | { | |
764 | register struct list_hash *h; | |
765 | ||
0a2c2fd1 | 766 | h = (struct list_hash *) obstack_alloc (&permanent_obstack, sizeof (struct list_hash)); |
8d08fdba MS |
767 | h->hashcode = hashcode; |
768 | h->list = list; | |
769 | h->next = list_hash_table[hashcode % TYPE_HASH_SIZE]; | |
770 | list_hash_table[hashcode % TYPE_HASH_SIZE] = h; | |
771 | } | |
772 | ||
51632249 JM |
773 | /* Given list components PURPOSE, VALUE, AND CHAIN, return the canonical |
774 | object for an identical list if one already exists. Otherwise, build a | |
775 | new one, and record it as the canonical object. */ | |
8d08fdba MS |
776 | |
777 | /* Set to 1 to debug without canonicalization. Never set by program. */ | |
e92cc029 | 778 | |
a0a33927 | 779 | static int debug_no_list_hash = 0; |
8d08fdba | 780 | |
8d08fdba | 781 | tree |
51632249 | 782 | hash_tree_cons (purpose, value, chain) |
8d08fdba MS |
783 | tree purpose, value, chain; |
784 | { | |
8d08fdba | 785 | tree t; |
a703fb38 | 786 | int hashcode = 0; |
8d08fdba | 787 | |
37c46b43 MS |
788 | if (! debug_no_list_hash) |
789 | { | |
790 | hashcode = list_hash (purpose, value, chain); | |
51632249 | 791 | t = list_hash_lookup (hashcode, purpose, value, chain); |
37c46b43 MS |
792 | if (t) |
793 | return t; | |
794 | } | |
795 | ||
8d08fdba | 796 | t = tree_cons (purpose, value, chain); |
37c46b43 MS |
797 | |
798 | /* If this is a new list, record it for later reuse. */ | |
799 | if (! debug_no_list_hash) | |
800 | list_hash_add (hashcode, t); | |
801 | ||
8d08fdba MS |
802 | return t; |
803 | } | |
804 | ||
805 | /* Constructor for hashed lists. */ | |
e92cc029 | 806 | |
8d08fdba MS |
807 | tree |
808 | hash_tree_chain (value, chain) | |
809 | tree value, chain; | |
810 | { | |
51632249 | 811 | return hash_tree_cons (NULL_TREE, value, chain); |
8d08fdba MS |
812 | } |
813 | ||
814 | /* Similar, but used for concatenating two lists. */ | |
e92cc029 | 815 | |
8d08fdba MS |
816 | tree |
817 | hash_chainon (list1, list2) | |
818 | tree list1, list2; | |
819 | { | |
820 | if (list2 == 0) | |
821 | return list1; | |
822 | if (list1 == 0) | |
823 | return list2; | |
824 | if (TREE_CHAIN (list1) == NULL_TREE) | |
825 | return hash_tree_chain (TREE_VALUE (list1), list2); | |
826 | return hash_tree_chain (TREE_VALUE (list1), | |
827 | hash_chainon (TREE_CHAIN (list1), list2)); | |
828 | } | |
8d08fdba MS |
829 | \f |
830 | /* Build an association between TYPE and some parameters: | |
831 | ||
832 | OFFSET is the offset added to `this' to convert it to a pointer | |
833 | of type `TYPE *' | |
834 | ||
8926095f MS |
835 | BINFO is the base binfo to use, if we are deriving from one. This |
836 | is necessary, as we want specialized parent binfos from base | |
837 | classes, so that the VTABLE_NAMEs of bases are for the most derived | |
38e01259 | 838 | type, instead of the simple type. |
8926095f | 839 | |
8d08fdba MS |
840 | VTABLE is the virtual function table with which to initialize |
841 | sub-objects of type TYPE. | |
842 | ||
ca107ded | 843 | VIRTUALS are the virtual functions sitting in VTABLE. */ |
8d08fdba MS |
844 | |
845 | tree | |
ca107ded | 846 | make_binfo (offset, binfo, vtable, virtuals) |
8926095f | 847 | tree offset, binfo; |
8d08fdba | 848 | tree vtable, virtuals; |
8d08fdba | 849 | { |
3ec6bad3 | 850 | tree new_binfo = make_tree_vec (10); |
8926095f | 851 | tree type; |
8d08fdba | 852 | |
8926095f MS |
853 | if (TREE_CODE (binfo) == TREE_VEC) |
854 | type = BINFO_TYPE (binfo); | |
855 | else | |
856 | { | |
857 | type = binfo; | |
7ddedda4 | 858 | binfo = CLASS_TYPE_P (type) ? TYPE_BINFO (binfo) : NULL_TREE; |
8926095f | 859 | } |
8d08fdba | 860 | |
8926095f MS |
861 | TREE_TYPE (new_binfo) = TYPE_MAIN_VARIANT (type); |
862 | BINFO_OFFSET (new_binfo) = offset; | |
863 | BINFO_VTABLE (new_binfo) = vtable; | |
864 | BINFO_VIRTUALS (new_binfo) = virtuals; | |
8d08fdba | 865 | |
8926095f MS |
866 | if (binfo && BINFO_BASETYPES (binfo) != NULL_TREE) |
867 | BINFO_BASETYPES (new_binfo) = copy_node (BINFO_BASETYPES (binfo)); | |
868 | return new_binfo; | |
8d08fdba MS |
869 | } |
870 | ||
8d08fdba MS |
871 | /* Return the binfo value for ELEM in TYPE. */ |
872 | ||
873 | tree | |
874 | binfo_value (elem, type) | |
875 | tree elem; | |
876 | tree type; | |
877 | { | |
878 | if (get_base_distance (elem, type, 0, (tree *)0) == -2) | |
8251199e | 879 | compiler_error ("base class `%s' ambiguous in binfo_value", |
8d08fdba MS |
880 | TYPE_NAME_STRING (elem)); |
881 | if (elem == type) | |
882 | return TYPE_BINFO (type); | |
883 | if (TREE_CODE (elem) == RECORD_TYPE && TYPE_BINFO (elem) == type) | |
884 | return type; | |
885 | return get_binfo (elem, type, 0); | |
886 | } | |
887 | ||
5e19c053 MM |
888 | /* Return a TREE_LIST whose TREE_VALUE nodes along the |
889 | BINFO_INHERITANCE_CHAIN for BINFO, but in the opposite order. In | |
890 | other words, while the BINFO_INHERITANCE_CHAIN goes from base | |
891 | classes to derived classes, the reversed path goes from derived | |
892 | classes to base classes. */ | |
ca107ded | 893 | |
8d08fdba | 894 | tree |
5e19c053 MM |
895 | reverse_path (binfo) |
896 | tree binfo; | |
8d08fdba | 897 | { |
5e19c053 MM |
898 | tree reversed_path; |
899 | ||
900 | reversed_path = NULL_TREE; | |
901 | while (binfo) | |
8d08fdba | 902 | { |
5e19c053 MM |
903 | reversed_path = tree_cons (NULL_TREE, binfo, reversed_path); |
904 | binfo = BINFO_INHERITANCE_CHAIN (binfo); | |
8d08fdba | 905 | } |
5e19c053 MM |
906 | |
907 | return reversed_path; | |
8d08fdba MS |
908 | } |
909 | ||
8d08fdba MS |
910 | void |
911 | debug_binfo (elem) | |
912 | tree elem; | |
913 | { | |
fed3cef0 | 914 | HOST_WIDE_INT n; |
8d08fdba MS |
915 | tree virtuals; |
916 | ||
fed3cef0 RK |
917 | fprintf (stderr, "type \"%s\", offset = ", |
918 | TYPE_NAME_STRING (BINFO_TYPE (elem))); | |
919 | fprintf (stderr, HOST_WIDE_INT_PRINT_DEC, | |
920 | TREE_INT_CST_LOW (BINFO_OFFSET (elem))); | |
921 | fprintf (stderr, "\nvtable type:\n"); | |
8d08fdba MS |
922 | debug_tree (BINFO_TYPE (elem)); |
923 | if (BINFO_VTABLE (elem)) | |
fed3cef0 | 924 | fprintf (stderr, "vtable decl \"%s\"\n", |
c35cce41 | 925 | IDENTIFIER_POINTER (DECL_NAME (get_vtbl_decl_for_binfo (elem)))); |
8d08fdba MS |
926 | else |
927 | fprintf (stderr, "no vtable decl yet\n"); | |
928 | fprintf (stderr, "virtuals:\n"); | |
da3d4dfa MM |
929 | virtuals = BINFO_VIRTUALS (elem); |
930 | n = first_vfun_index (BINFO_TYPE (elem)); | |
f30432d7 | 931 | |
8d08fdba MS |
932 | while (virtuals) |
933 | { | |
83f2ccf4 | 934 | tree fndecl = TREE_VALUE (virtuals); |
71e89f27 | 935 | fprintf (stderr, "%s [%ld =? %ld]\n", |
8d08fdba | 936 | IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (fndecl)), |
71e89f27 | 937 | (long) n, (long) TREE_INT_CST_LOW (DECL_VINDEX (fndecl))); |
f30432d7 | 938 | ++n; |
8d08fdba | 939 | virtuals = TREE_CHAIN (virtuals); |
8d08fdba MS |
940 | } |
941 | } | |
942 | ||
8d08fdba MS |
943 | int |
944 | count_functions (t) | |
945 | tree t; | |
946 | { | |
2c73f9f5 | 947 | int i; |
8d08fdba MS |
948 | if (TREE_CODE (t) == FUNCTION_DECL) |
949 | return 1; | |
2c73f9f5 ML |
950 | else if (TREE_CODE (t) == OVERLOAD) |
951 | { | |
952 | for (i=0; t; t = OVL_CHAIN (t)) | |
953 | i++; | |
954 | return i; | |
955 | } | |
8d08fdba | 956 | |
5b605f68 | 957 | my_friendly_abort (359); |
0d16d68e | 958 | return 0; |
8d08fdba MS |
959 | } |
960 | ||
8d08fdba MS |
961 | int |
962 | is_overloaded_fn (x) | |
963 | tree x; | |
964 | { | |
4bb0968f | 965 | /* A baselink is also considered an overloaded function. */ |
05e0b2f4 JM |
966 | if (TREE_CODE (x) == OFFSET_REF) |
967 | x = TREE_OPERAND (x, 1); | |
4bb0968f MM |
968 | if (BASELINK_P (x)) |
969 | x = TREE_VALUE (x); | |
06ab59df MM |
970 | return (TREE_CODE (x) == FUNCTION_DECL |
971 | || TREE_CODE (x) == TEMPLATE_ID_EXPR | |
972 | || DECL_FUNCTION_TEMPLATE_P (x) | |
2c73f9f5 | 973 | || TREE_CODE (x) == OVERLOAD); |
8d08fdba MS |
974 | } |
975 | ||
8926095f MS |
976 | int |
977 | really_overloaded_fn (x) | |
978 | tree x; | |
979 | { | |
4bb0968f | 980 | /* A baselink is also considered an overloaded function. */ |
05e0b2f4 JM |
981 | if (TREE_CODE (x) == OFFSET_REF) |
982 | x = TREE_OPERAND (x, 1); | |
4bb0968f | 983 | if (BASELINK_P (x)) |
2c73f9f5 ML |
984 | x = TREE_VALUE (x); |
985 | return (TREE_CODE (x) == OVERLOAD | |
986 | && (TREE_CHAIN (x) != NULL_TREE | |
987 | || DECL_FUNCTION_TEMPLATE_P (OVL_FUNCTION (x)))); | |
8926095f MS |
988 | } |
989 | ||
8d08fdba MS |
990 | tree |
991 | get_first_fn (from) | |
992 | tree from; | |
993 | { | |
06ab59df | 994 | my_friendly_assert (is_overloaded_fn (from), 9); |
2c73f9f5 | 995 | /* A baselink is also considered an overloaded function. */ |
4bb0968f | 996 | if (BASELINK_P (from)) |
2c73f9f5 ML |
997 | from = TREE_VALUE (from); |
998 | return OVL_CURRENT (from); | |
999 | } | |
8d08fdba | 1000 | |
8d7f862c JM |
1001 | /* Returns nonzero if T is a ->* or .* expression that refers to a |
1002 | member function. */ | |
1003 | ||
1004 | int | |
1005 | bound_pmf_p (t) | |
1006 | tree t; | |
1007 | { | |
1008 | return (TREE_CODE (t) == OFFSET_REF | |
1009 | && TYPE_PTRMEMFUNC_P (TREE_TYPE (TREE_OPERAND (t, 1)))); | |
1010 | } | |
1011 | ||
2c73f9f5 ML |
1012 | /* Return a new OVL node, concatenating it with the old one. */ |
1013 | ||
1014 | tree | |
1015 | ovl_cons (decl, chain) | |
1016 | tree decl; | |
1017 | tree chain; | |
1018 | { | |
1019 | tree result = make_node (OVERLOAD); | |
1020 | TREE_TYPE (result) = unknown_type_node; | |
1021 | OVL_FUNCTION (result) = decl; | |
1022 | TREE_CHAIN (result) = chain; | |
1023 | ||
1024 | return result; | |
1025 | } | |
1026 | ||
2c73f9f5 ML |
1027 | /* Build a new overloaded function. If this is the first one, |
1028 | just return it; otherwise, ovl_cons the _DECLs */ | |
1029 | ||
1030 | tree | |
1031 | build_overload (decl, chain) | |
1032 | tree decl; | |
1033 | tree chain; | |
1034 | { | |
161c12b0 | 1035 | if (! chain && TREE_CODE (decl) != TEMPLATE_DECL) |
2c73f9f5 | 1036 | return decl; |
161c12b0 | 1037 | if (chain && TREE_CODE (chain) != OVERLOAD) |
2c73f9f5 ML |
1038 | chain = ovl_cons (chain, NULL_TREE); |
1039 | return ovl_cons (decl, chain); | |
1040 | } | |
1041 | ||
1042 | /* True if fn is in ovl. */ | |
1043 | ||
1044 | int | |
1045 | ovl_member (fn, ovl) | |
1046 | tree fn; | |
1047 | tree ovl; | |
1048 | { | |
92ac31f1 | 1049 | if (ovl == NULL_TREE) |
2c73f9f5 | 1050 | return 0; |
92ac31f1 | 1051 | if (TREE_CODE (ovl) != OVERLOAD) |
2c169bab | 1052 | return ovl == fn; |
2c73f9f5 | 1053 | for (; ovl; ovl = OVL_CHAIN (ovl)) |
2c169bab | 1054 | if (OVL_FUNCTION (ovl) == fn) |
2c73f9f5 ML |
1055 | return 1; |
1056 | return 0; | |
8d08fdba MS |
1057 | } |
1058 | ||
8d08fdba MS |
1059 | int |
1060 | is_aggr_type_2 (t1, t2) | |
1061 | tree t1, t2; | |
1062 | { | |
1063 | if (TREE_CODE (t1) != TREE_CODE (t2)) | |
1064 | return 0; | |
1065 | return IS_AGGR_TYPE (t1) && IS_AGGR_TYPE (t2); | |
1066 | } | |
46e8c075 MM |
1067 | |
1068 | /* Returns non-zero if CODE is the code for a statement. */ | |
1069 | ||
1070 | static int | |
1071 | statement_code_p (code) | |
1072 | enum tree_code code; | |
1073 | { | |
1074 | switch (code) | |
1075 | { | |
1076 | case EXPR_STMT: | |
1077 | case COMPOUND_STMT: | |
1078 | case DECL_STMT: | |
1079 | case IF_STMT: | |
1080 | case FOR_STMT: | |
1081 | case WHILE_STMT: | |
1082 | case DO_STMT: | |
1083 | case RETURN_STMT: | |
1084 | case BREAK_STMT: | |
1085 | case CONTINUE_STMT: | |
1086 | case SWITCH_STMT: | |
1087 | case GOTO_STMT: | |
1088 | case LABEL_STMT: | |
1089 | case ASM_STMT: | |
1090 | case SUBOBJECT: | |
1091 | case CLEANUP_STMT: | |
1092 | case START_CATCH_STMT: | |
1093 | case CTOR_STMT: | |
1094 | case SCOPE_STMT: | |
1095 | case CTOR_INITIALIZER: | |
1096 | case CASE_LABEL: | |
1097 | case RETURN_INIT: | |
1098 | case TRY_BLOCK: | |
1099 | case HANDLER: | |
1100 | return 1; | |
1101 | ||
1102 | default: | |
1103 | return 0; | |
1104 | } | |
1105 | } | |
8d08fdba MS |
1106 | \f |
1107 | #define PRINT_RING_SIZE 4 | |
1108 | ||
e1def31b | 1109 | const char * |
2ba25f50 | 1110 | lang_printable_name (decl, v) |
8d08fdba | 1111 | tree decl; |
2ba25f50 | 1112 | int v; |
8d08fdba MS |
1113 | { |
1114 | static tree decl_ring[PRINT_RING_SIZE]; | |
1115 | static char *print_ring[PRINT_RING_SIZE]; | |
1116 | static int ring_counter; | |
1117 | int i; | |
1118 | ||
1119 | /* Only cache functions. */ | |
2ba25f50 MS |
1120 | if (v < 2 |
1121 | || TREE_CODE (decl) != FUNCTION_DECL | |
8d08fdba | 1122 | || DECL_LANG_SPECIFIC (decl) == 0) |
2ba25f50 | 1123 | return lang_decl_name (decl, v); |
8d08fdba MS |
1124 | |
1125 | /* See if this print name is lying around. */ | |
1126 | for (i = 0; i < PRINT_RING_SIZE; i++) | |
1127 | if (decl_ring[i] == decl) | |
1128 | /* yes, so return it. */ | |
1129 | return print_ring[i]; | |
1130 | ||
1131 | if (++ring_counter == PRINT_RING_SIZE) | |
1132 | ring_counter = 0; | |
1133 | ||
1134 | if (current_function_decl != NULL_TREE) | |
1135 | { | |
1136 | if (decl_ring[ring_counter] == current_function_decl) | |
1137 | ring_counter += 1; | |
1138 | if (ring_counter == PRINT_RING_SIZE) | |
1139 | ring_counter = 0; | |
1140 | if (decl_ring[ring_counter] == current_function_decl) | |
1141 | my_friendly_abort (106); | |
1142 | } | |
1143 | ||
1144 | if (print_ring[ring_counter]) | |
1145 | free (print_ring[ring_counter]); | |
1146 | ||
2ba25f50 MS |
1147 | print_ring[ring_counter] = xstrdup (lang_decl_name (decl, v)); |
1148 | decl_ring[ring_counter] = decl; | |
8d08fdba MS |
1149 | return print_ring[ring_counter]; |
1150 | } | |
1151 | \f | |
f30432d7 | 1152 | /* Build the FUNCTION_TYPE or METHOD_TYPE which may throw exceptions |
8d08fdba | 1153 | listed in RAISES. */ |
e92cc029 | 1154 | |
8d08fdba | 1155 | tree |
f30432d7 MS |
1156 | build_exception_variant (type, raises) |
1157 | tree type; | |
8d08fdba MS |
1158 | tree raises; |
1159 | { | |
8d08fdba | 1160 | tree v = TYPE_MAIN_VARIANT (type); |
91063b51 | 1161 | int type_quals = TYPE_QUALS (type); |
8d08fdba | 1162 | |
45537677 | 1163 | for (; v; v = TYPE_NEXT_VARIANT (v)) |
4cc1d462 NS |
1164 | if (TYPE_QUALS (v) == type_quals |
1165 | && comp_except_specs (raises, TYPE_RAISES_EXCEPTIONS (v), 1)) | |
1166 | return v; | |
8d08fdba MS |
1167 | |
1168 | /* Need to build a new variant. */ | |
45537677 | 1169 | v = build_type_copy (type); |
8d08fdba MS |
1170 | TYPE_RAISES_EXCEPTIONS (v) = raises; |
1171 | return v; | |
1172 | } | |
1173 | ||
73b0fce8 KL |
1174 | /* Given a TEMPLATE_TEMPLATE_PARM node T, create a new one together with its |
1175 | lang_specific field and its corresponding TEMPLATE_DECL node */ | |
1176 | ||
1177 | tree | |
1178 | copy_template_template_parm (t) | |
1179 | tree t; | |
1180 | { | |
1181 | tree template = TYPE_NAME (t); | |
6b9b6b15 JM |
1182 | tree t2; |
1183 | ||
33848bb0 | 1184 | t2 = make_aggr_type (TEMPLATE_TEMPLATE_PARM); |
0acf7199 | 1185 | template = copy_decl (template); |
6b9b6b15 | 1186 | |
73b0fce8 KL |
1187 | TREE_TYPE (template) = t2; |
1188 | TYPE_NAME (t2) = template; | |
1189 | TYPE_STUB_DECL (t2) = template; | |
1190 | ||
1191 | /* No need to copy these */ | |
1192 | TYPE_FIELDS (t2) = TYPE_FIELDS (t); | |
7ddedda4 MM |
1193 | TEMPLATE_TEMPLATE_PARM_TEMPLATE_INFO (t2) |
1194 | = TEMPLATE_TEMPLATE_PARM_TEMPLATE_INFO (t); | |
73b0fce8 KL |
1195 | return t2; |
1196 | } | |
1197 | ||
8dfaeb63 MM |
1198 | /* Apply FUNC to all the sub-trees of TP in a pre-order traversal. |
1199 | FUNC is called with the DATA and the address of each sub-tree. If | |
1200 | FUNC returns a non-NULL value, the traversal is aborted, and the | |
1201 | value returned by FUNC is returned. */ | |
50a6dbd7 | 1202 | |
8dfaeb63 MM |
1203 | tree |
1204 | walk_tree (tp, func, data) | |
b3ab27f3 | 1205 | tree *tp; |
8dfaeb63 MM |
1206 | walk_tree_fn func; |
1207 | void *data; | |
50a6dbd7 | 1208 | { |
8dfaeb63 MM |
1209 | enum tree_code code; |
1210 | int walk_subtrees; | |
1211 | tree result; | |
b3ab27f3 | 1212 | |
8dfaeb63 MM |
1213 | #define WALK_SUBTREE(NODE) \ |
1214 | do \ | |
1215 | { \ | |
1216 | result = walk_tree (&(NODE), func, data); \ | |
1217 | if (result) \ | |
1218 | return result; \ | |
1219 | } \ | |
1220 | while (0) | |
1221 | ||
1222 | /* Skip empty subtrees. */ | |
1223 | if (!*tp) | |
b3ab27f3 | 1224 | return NULL_TREE; |
50a6dbd7 | 1225 | |
8dfaeb63 MM |
1226 | /* Call the function. */ |
1227 | walk_subtrees = 1; | |
1228 | result = (*func) (tp, &walk_subtrees, data); | |
1229 | ||
1230 | /* If we found something, return it. */ | |
1231 | if (result) | |
1232 | return result; | |
1233 | ||
1234 | /* Even if we didn't, FUNC may have decided that there was nothing | |
1235 | interesting below this point in the tree. */ | |
1236 | if (!walk_subtrees) | |
1237 | return NULL_TREE; | |
1238 | ||
1239 | code = TREE_CODE (*tp); | |
1240 | ||
b3a44a4c | 1241 | /* Handle common cases up front. */ |
8dfaeb63 | 1242 | if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (code)) |
46e8c075 MM |
1243 | || TREE_CODE_CLASS (code) == 'r' |
1244 | || TREE_CODE_CLASS (code) == 's') | |
2adeacc9 | 1245 | { |
5afb79e7 | 1246 | int i, len; |
8dfaeb63 | 1247 | |
3b54e10b JM |
1248 | /* Set lineno here so we get the right instantiation context |
1249 | if we call instantiate_decl from inlinable_function_p. */ | |
1250 | if (statement_code_p (code) && !STMT_LINENO_FOR_FN_P (*tp)) | |
1251 | lineno = STMT_LINENO (*tp); | |
1252 | ||
8dfaeb63 | 1253 | /* Walk over all the sub-trees of this operand. */ |
5afb79e7 | 1254 | len = first_rtl_op (code); |
3eb24f73 MM |
1255 | /* TARGET_EXPRs are peculiar: operands 1 and 3 can be the same. |
1256 | But, we only want to walk once. */ | |
1257 | if (code == TARGET_EXPR | |
1258 | && TREE_OPERAND (*tp, 3) == TREE_OPERAND (*tp, 1)) | |
5afb79e7 JM |
1259 | --len; |
1260 | /* Go through the subtrees. We need to do this in forward order so | |
1261 | that the scope of a FOR_EXPR is handled properly. */ | |
1262 | for (i = 0; i < len; ++i) | |
1263 | WALK_SUBTREE (TREE_OPERAND (*tp, i)); | |
8dfaeb63 | 1264 | |
46e8c075 MM |
1265 | /* For statements, we also walk the chain so that we cover the |
1266 | entire statement tree. */ | |
1267 | if (statement_code_p (code)) | |
b3a44a4c MM |
1268 | { |
1269 | if (code == DECL_STMT | |
1270 | && DECL_STMT_DECL (*tp) | |
2f939d94 | 1271 | && DECL_P (DECL_STMT_DECL (*tp))) |
b3a44a4c MM |
1272 | { |
1273 | /* Walk the DECL_INITIAL and DECL_SIZE. We don't want to walk | |
1274 | into declarations that are just mentioned, rather than | |
1275 | declared; they don't really belong to this part of the tree. | |
1276 | And, we can see cycles: the initializer for a declaration can | |
1277 | refer to the declaration itself. */ | |
1278 | WALK_SUBTREE (DECL_INITIAL (DECL_STMT_DECL (*tp))); | |
1279 | WALK_SUBTREE (DECL_SIZE (DECL_STMT_DECL (*tp))); | |
06ceef4e | 1280 | WALK_SUBTREE (DECL_SIZE_UNIT (DECL_STMT_DECL (*tp))); |
b3a44a4c MM |
1281 | } |
1282 | ||
1283 | WALK_SUBTREE (TREE_CHAIN (*tp)); | |
1284 | } | |
46e8c075 | 1285 | |
8dfaeb63 | 1286 | /* We didn't find what we were looking for. */ |
2adeacc9 MM |
1287 | return NULL_TREE; |
1288 | } | |
8dfaeb63 | 1289 | else if (TREE_CODE_CLASS (code) == 'd') |
2adeacc9 | 1290 | { |
8dfaeb63 | 1291 | WALK_SUBTREE (TREE_TYPE (*tp)); |
8dfaeb63 MM |
1292 | |
1293 | /* We didn't find what we were looking for. */ | |
2adeacc9 MM |
1294 | return NULL_TREE; |
1295 | } | |
1296 | ||
8dfaeb63 MM |
1297 | /* Not one of the easy cases. We must explicitly go through the |
1298 | children. */ | |
2adeacc9 | 1299 | switch (code) |
50a6dbd7 JM |
1300 | { |
1301 | case ERROR_MARK: | |
50a6dbd7 | 1302 | case IDENTIFIER_NODE: |
8dfaeb63 MM |
1303 | case INTEGER_CST: |
1304 | case REAL_CST: | |
1305 | case STRING_CST: | |
1306 | case DEFAULT_ARG: | |
1307 | case TEMPLATE_TEMPLATE_PARM: | |
1308 | case TEMPLATE_PARM_INDEX: | |
1309 | case TEMPLATE_TYPE_PARM: | |
1310 | case REAL_TYPE: | |
1311 | case COMPLEX_TYPE: | |
1312 | case VOID_TYPE: | |
1313 | case BOOLEAN_TYPE: | |
1314 | case TYPENAME_TYPE: | |
1315 | case UNION_TYPE: | |
1316 | case ENUMERAL_TYPE: | |
1317 | case TYPEOF_TYPE: | |
1318 | case BLOCK: | |
1319 | /* None of thse have subtrees other than those already walked | |
1320 | above. */ | |
50a6dbd7 JM |
1321 | break; |
1322 | ||
8dfaeb63 MM |
1323 | case PTRMEM_CST: |
1324 | WALK_SUBTREE (TREE_TYPE (*tp)); | |
50a6dbd7 JM |
1325 | break; |
1326 | ||
8dfaeb63 MM |
1327 | case POINTER_TYPE: |
1328 | case REFERENCE_TYPE: | |
1329 | WALK_SUBTREE (TREE_TYPE (*tp)); | |
50a6dbd7 JM |
1330 | break; |
1331 | ||
1332 | case TREE_LIST: | |
8dfaeb63 MM |
1333 | WALK_SUBTREE (TREE_PURPOSE (*tp)); |
1334 | WALK_SUBTREE (TREE_VALUE (*tp)); | |
1335 | WALK_SUBTREE (TREE_CHAIN (*tp)); | |
50a6dbd7 JM |
1336 | break; |
1337 | ||
1338 | case OVERLOAD: | |
8dfaeb63 MM |
1339 | WALK_SUBTREE (OVL_FUNCTION (*tp)); |
1340 | WALK_SUBTREE (OVL_CHAIN (*tp)); | |
50a6dbd7 JM |
1341 | break; |
1342 | ||
1343 | case TREE_VEC: | |
1344 | { | |
8dfaeb63 | 1345 | int len = TREE_VEC_LENGTH (*tp); |
50a6dbd7 | 1346 | while (len--) |
8dfaeb63 | 1347 | WALK_SUBTREE (TREE_VEC_ELT (*tp, len)); |
50a6dbd7 JM |
1348 | } |
1349 | break; | |
1350 | ||
50a6dbd7 | 1351 | case COMPLEX_CST: |
8dfaeb63 MM |
1352 | WALK_SUBTREE (TREE_REALPART (*tp)); |
1353 | WALK_SUBTREE (TREE_IMAGPART (*tp)); | |
50a6dbd7 JM |
1354 | break; |
1355 | ||
1356 | case CONSTRUCTOR: | |
8dfaeb63 | 1357 | WALK_SUBTREE (CONSTRUCTOR_ELTS (*tp)); |
50a6dbd7 JM |
1358 | break; |
1359 | ||
8dfaeb63 MM |
1360 | case METHOD_TYPE: |
1361 | WALK_SUBTREE (TYPE_METHOD_BASETYPE (*tp)); | |
1362 | /* Fall through. */ | |
50a6dbd7 JM |
1363 | |
1364 | case FUNCTION_TYPE: | |
8dfaeb63 MM |
1365 | WALK_SUBTREE (TREE_TYPE (*tp)); |
1366 | WALK_SUBTREE (TYPE_ARG_TYPES (*tp)); | |
50a6dbd7 JM |
1367 | break; |
1368 | ||
1369 | case ARRAY_TYPE: | |
8dfaeb63 MM |
1370 | WALK_SUBTREE (TREE_TYPE (*tp)); |
1371 | WALK_SUBTREE (TYPE_DOMAIN (*tp)); | |
50a6dbd7 JM |
1372 | break; |
1373 | ||
1374 | case INTEGER_TYPE: | |
8dfaeb63 MM |
1375 | WALK_SUBTREE (TYPE_MIN_VALUE (*tp)); |
1376 | WALK_SUBTREE (TYPE_MAX_VALUE (*tp)); | |
50a6dbd7 JM |
1377 | break; |
1378 | ||
1379 | case OFFSET_TYPE: | |
8dfaeb63 MM |
1380 | WALK_SUBTREE (TREE_TYPE (*tp)); |
1381 | WALK_SUBTREE (TYPE_OFFSET_BASETYPE (*tp)); | |
50a6dbd7 JM |
1382 | break; |
1383 | ||
1384 | case RECORD_TYPE: | |
8dfaeb63 MM |
1385 | if (TYPE_PTRMEMFUNC_P (*tp)) |
1386 | WALK_SUBTREE (TYPE_PTRMEMFUNC_FN_TYPE (*tp)); | |
50a6dbd7 | 1387 | break; |
46e8c075 | 1388 | |
50a6dbd7 | 1389 | default: |
2adeacc9 | 1390 | my_friendly_abort (19990803); |
50a6dbd7 JM |
1391 | } |
1392 | ||
8dfaeb63 | 1393 | /* We didn't find what we were looking for. */ |
50a6dbd7 JM |
1394 | return NULL_TREE; |
1395 | ||
8dfaeb63 | 1396 | #undef WALK_SUBTREE |
50a6dbd7 JM |
1397 | } |
1398 | ||
8dfaeb63 | 1399 | /* Passed to walk_tree. Checks for the use of types with no linkage. */ |
50a6dbd7 JM |
1400 | |
1401 | static tree | |
8dfaeb63 | 1402 | no_linkage_helper (tp, walk_subtrees, data) |
b3ab27f3 | 1403 | tree *tp; |
8dfaeb63 MM |
1404 | int *walk_subtrees ATTRIBUTE_UNUSED; |
1405 | void *data ATTRIBUTE_UNUSED; | |
50a6dbd7 | 1406 | { |
b3ab27f3 MM |
1407 | tree t = *tp; |
1408 | ||
50a6dbd7 JM |
1409 | if (TYPE_P (t) |
1410 | && (IS_AGGR_TYPE (t) || TREE_CODE (t) == ENUMERAL_TYPE) | |
1411 | && (decl_function_context (TYPE_MAIN_DECL (t)) | |
1412 | || ANON_AGGRNAME_P (TYPE_IDENTIFIER (t)))) | |
1413 | return t; | |
1414 | return NULL_TREE; | |
1415 | } | |
1416 | ||
1417 | /* Check if the type T depends on a type with no linkage and if so, return | |
1418 | it. */ | |
1419 | ||
1420 | tree | |
1421 | no_linkage_check (t) | |
1422 | tree t; | |
1423 | { | |
2adeacc9 MM |
1424 | /* There's no point in checking linkage on template functions; we |
1425 | can't know their complete types. */ | |
1426 | if (processing_template_decl) | |
1427 | return NULL_TREE; | |
1428 | ||
8dfaeb63 | 1429 | t = walk_tree (&t, no_linkage_helper, NULL); |
50a6dbd7 JM |
1430 | if (t != error_mark_node) |
1431 | return t; | |
1432 | return NULL_TREE; | |
1433 | } | |
1434 | ||
8dfaeb63 | 1435 | /* Passed to walk_tree. Copies the node pointed to, if appropriate. */ |
50a6dbd7 | 1436 | |
46e8c075 | 1437 | tree |
8dfaeb63 MM |
1438 | copy_tree_r (tp, walk_subtrees, data) |
1439 | tree *tp; | |
46e8c075 | 1440 | int *walk_subtrees; |
8dfaeb63 | 1441 | void *data ATTRIBUTE_UNUSED; |
8d08fdba | 1442 | { |
8dfaeb63 MM |
1443 | enum tree_code code = TREE_CODE (*tp); |
1444 | ||
1445 | /* We make copies of most nodes. */ | |
1446 | if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (code)) | |
1447 | || TREE_CODE_CLASS (code) == 'r' | |
1448 | || TREE_CODE_CLASS (code) == 'c' | |
46e8c075 | 1449 | || TREE_CODE_CLASS (code) == 's' |
8dfaeb63 MM |
1450 | || code == TREE_LIST |
1451 | || code == TREE_VEC | |
1452 | || code == OVERLOAD) | |
558475f0 | 1453 | { |
8dfaeb63 MM |
1454 | /* Because the chain gets clobbered when we make a copy, we save it |
1455 | here. */ | |
1456 | tree chain = TREE_CHAIN (*tp); | |
558475f0 | 1457 | |
8dfaeb63 MM |
1458 | /* Copy the node. */ |
1459 | *tp = copy_node (*tp); | |
8d08fdba | 1460 | |
8dfaeb63 MM |
1461 | /* Now, restore the chain, if appropriate. That will cause |
1462 | walk_tree to walk into the chain as well. */ | |
46e8c075 MM |
1463 | if (code == PARM_DECL || code == TREE_LIST || code == OVERLOAD |
1464 | || statement_code_p (code)) | |
8dfaeb63 | 1465 | TREE_CHAIN (*tp) = chain; |
46e8c075 MM |
1466 | |
1467 | /* For now, we don't update BLOCKs when we make copies. So, we | |
1468 | have to nullify all scope-statements. */ | |
1469 | if (TREE_CODE (*tp) == SCOPE_STMT) | |
d9b2d9da | 1470 | SCOPE_STMT_BLOCK (*tp) = NULL_TREE; |
8d08fdba | 1471 | } |
8dfaeb63 MM |
1472 | else if (code == TEMPLATE_TEMPLATE_PARM) |
1473 | /* These must be copied specially. */ | |
1474 | *tp = copy_template_template_parm (*tp); | |
46e8c075 MM |
1475 | else if (TREE_CODE_CLASS (code) == 't') |
1476 | /* There's no need to copy types, or anything beneath them. */ | |
1477 | *walk_subtrees = 0; | |
8dfaeb63 | 1478 | |
8d08fdba MS |
1479 | return NULL_TREE; |
1480 | } | |
1481 | ||
5566b478 MS |
1482 | #ifdef GATHER_STATISTICS |
1483 | extern int depth_reached; | |
1484 | #endif | |
1485 | ||
8d08fdba MS |
1486 | void |
1487 | print_lang_statistics () | |
1488 | { | |
8d08fdba MS |
1489 | print_search_statistics (); |
1490 | print_class_statistics (); | |
5566b478 MS |
1491 | #ifdef GATHER_STATISTICS |
1492 | fprintf (stderr, "maximum template instantiation depth reached: %d\n", | |
1493 | depth_reached); | |
1494 | #endif | |
8d08fdba MS |
1495 | } |
1496 | ||
e92cc029 MS |
1497 | /* Return, as an INTEGER_CST node, the number of elements for TYPE |
1498 | (which is an ARRAY_TYPE). This counts only elements of the top | |
1499 | array. */ | |
8d08fdba MS |
1500 | |
1501 | tree | |
1502 | array_type_nelts_top (type) | |
1503 | tree type; | |
1504 | { | |
eae89e04 | 1505 | return fold (build (PLUS_EXPR, sizetype, |
8d08fdba MS |
1506 | array_type_nelts (type), |
1507 | integer_one_node)); | |
1508 | } | |
1509 | ||
e92cc029 MS |
1510 | /* Return, as an INTEGER_CST node, the number of elements for TYPE |
1511 | (which is an ARRAY_TYPE). This one is a recursive count of all | |
1512 | ARRAY_TYPEs that are clumped together. */ | |
8d08fdba MS |
1513 | |
1514 | tree | |
1515 | array_type_nelts_total (type) | |
1516 | tree type; | |
1517 | { | |
1518 | tree sz = array_type_nelts_top (type); | |
1519 | type = TREE_TYPE (type); | |
1520 | while (TREE_CODE (type) == ARRAY_TYPE) | |
1521 | { | |
1522 | tree n = array_type_nelts_top (type); | |
eae89e04 | 1523 | sz = fold (build (MULT_EXPR, sizetype, sz, n)); |
8d08fdba MS |
1524 | type = TREE_TYPE (type); |
1525 | } | |
1526 | return sz; | |
1527 | } | |
878cd289 | 1528 | |
b3ab27f3 MM |
1529 | /* Called from break_out_target_exprs via mapcar. */ |
1530 | ||
1531 | static tree | |
8dfaeb63 MM |
1532 | bot_manip (tp, walk_subtrees, data) |
1533 | tree *tp; | |
1534 | int *walk_subtrees; | |
1535 | void *data; | |
878cd289 | 1536 | { |
8dfaeb63 MM |
1537 | splay_tree target_remap = ((splay_tree) data); |
1538 | tree t = *tp; | |
1539 | ||
878cd289 | 1540 | if (TREE_CODE (t) != TREE_LIST && ! TREE_SIDE_EFFECTS (t)) |
8dfaeb63 MM |
1541 | { |
1542 | /* There can't be any TARGET_EXPRs below this point. */ | |
1543 | *walk_subtrees = 0; | |
1544 | return NULL_TREE; | |
1545 | } | |
878cd289 | 1546 | else if (TREE_CODE (t) == TARGET_EXPR) |
73aad9b9 | 1547 | { |
b3ab27f3 MM |
1548 | tree u; |
1549 | ||
02531345 | 1550 | if (TREE_CODE (TREE_OPERAND (t, 1)) == AGGR_INIT_EXPR) |
73aad9b9 JM |
1551 | { |
1552 | mark_used (TREE_OPERAND (TREE_OPERAND (TREE_OPERAND (t, 1), 0), 0)); | |
b3ab27f3 | 1553 | u = build_cplus_new |
73aad9b9 JM |
1554 | (TREE_TYPE (t), break_out_target_exprs (TREE_OPERAND (t, 1))); |
1555 | } | |
b3ab27f3 MM |
1556 | else |
1557 | { | |
301e21af MM |
1558 | tree var; |
1559 | ||
b3ab27f3 | 1560 | u = copy_node (t); |
301e21af MM |
1561 | var = build (VAR_DECL, TREE_TYPE (t)); |
1562 | DECL_CONTEXT (var) = current_function_decl; | |
1563 | layout_decl (var, 0); | |
1564 | TREE_OPERAND (u, 0) = var; | |
b3ab27f3 MM |
1565 | } |
1566 | ||
1567 | /* Map the old variable to the new one. */ | |
1568 | splay_tree_insert (target_remap, | |
1569 | (splay_tree_key) TREE_OPERAND (t, 0), | |
1570 | (splay_tree_value) TREE_OPERAND (u, 0)); | |
8dfaeb63 MM |
1571 | |
1572 | /* Replace the old expression with the new version. */ | |
1573 | *tp = u; | |
1574 | /* We don't have to go below this point; the recursive call to | |
1575 | break_out_target_exprs will have handled anything below this | |
1576 | point. */ | |
1577 | *walk_subtrees = 0; | |
1578 | return NULL_TREE; | |
73aad9b9 JM |
1579 | } |
1580 | else if (TREE_CODE (t) == CALL_EXPR) | |
1581 | mark_used (TREE_OPERAND (TREE_OPERAND (t, 0), 0)); | |
1582 | ||
8dfaeb63 MM |
1583 | /* Make a copy of this node. */ |
1584 | return copy_tree_r (tp, walk_subtrees, NULL); | |
878cd289 MS |
1585 | } |
1586 | ||
8dfaeb63 MM |
1587 | /* Replace all remapped VAR_DECLs in T with their new equivalents. |
1588 | DATA is really a splay-tree mapping old variables to new | |
1589 | variables. */ | |
b3ab27f3 MM |
1590 | |
1591 | static tree | |
8dfaeb63 | 1592 | bot_replace (t, walk_subtrees, data) |
b3ab27f3 | 1593 | tree *t; |
8dfaeb63 MM |
1594 | int *walk_subtrees ATTRIBUTE_UNUSED; |
1595 | void *data; | |
b3ab27f3 | 1596 | { |
8dfaeb63 MM |
1597 | splay_tree target_remap = ((splay_tree) data); |
1598 | ||
b3ab27f3 MM |
1599 | if (TREE_CODE (*t) == VAR_DECL) |
1600 | { | |
1601 | splay_tree_node n = splay_tree_lookup (target_remap, | |
1602 | (splay_tree_key) *t); | |
1603 | if (n) | |
1604 | *t = (tree) n->value; | |
1605 | } | |
1606 | ||
1607 | return NULL_TREE; | |
1608 | } | |
1609 | ||
8dfaeb63 MM |
1610 | /* When we parse a default argument expression, we may create |
1611 | temporary variables via TARGET_EXPRs. When we actually use the | |
1612 | default-argument expression, we make a copy of the expression, but | |
1613 | we must replace the temporaries with appropriate local versions. */ | |
e92cc029 | 1614 | |
878cd289 MS |
1615 | tree |
1616 | break_out_target_exprs (t) | |
1617 | tree t; | |
1618 | { | |
8dfaeb63 MM |
1619 | static int target_remap_count; |
1620 | static splay_tree target_remap; | |
1621 | ||
b3ab27f3 MM |
1622 | if (!target_remap_count++) |
1623 | target_remap = splay_tree_new (splay_tree_compare_pointers, | |
1624 | /*splay_tree_delete_key_fn=*/NULL, | |
1625 | /*splay_tree_delete_value_fn=*/NULL); | |
8dfaeb63 MM |
1626 | walk_tree (&t, bot_manip, target_remap); |
1627 | walk_tree (&t, bot_replace, target_remap); | |
b3ab27f3 MM |
1628 | |
1629 | if (!--target_remap_count) | |
1630 | { | |
1631 | splay_tree_delete (target_remap); | |
1632 | target_remap = NULL; | |
1633 | } | |
1634 | ||
1635 | return t; | |
878cd289 | 1636 | } |
f30432d7 | 1637 | |
5566b478 MS |
1638 | /* Obstack used for allocating nodes in template function and variable |
1639 | definitions. */ | |
1640 | ||
a09ba2e0 MM |
1641 | /* Similar to `build_nt', except that we set TREE_COMPLEXITY to be the |
1642 | current line number. */ | |
5566b478 MS |
1643 | |
1644 | tree | |
158991b7 | 1645 | build_min_nt VPARAMS ((enum tree_code code, ...)) |
5566b478 | 1646 | { |
c5c76735 | 1647 | #ifndef ANSI_PROTOTYPES |
5566b478 MS |
1648 | enum tree_code code; |
1649 | #endif | |
5566b478 MS |
1650 | va_list p; |
1651 | register tree t; | |
1652 | register int length; | |
1653 | register int i; | |
1654 | ||
1655 | VA_START (p, code); | |
1656 | ||
c5c76735 | 1657 | #ifndef ANSI_PROTOTYPES |
5566b478 MS |
1658 | code = va_arg (p, enum tree_code); |
1659 | #endif | |
1660 | ||
5566b478 | 1661 | t = make_node (code); |
8d5e6e25 | 1662 | length = TREE_CODE_LENGTH (code); |
5566b478 MS |
1663 | TREE_COMPLEXITY (t) = lineno; |
1664 | ||
1665 | for (i = 0; i < length; i++) | |
1666 | { | |
1667 | tree x = va_arg (p, tree); | |
2a1e9fdd | 1668 | TREE_OPERAND (t, i) = x; |
5566b478 MS |
1669 | } |
1670 | ||
1671 | va_end (p); | |
5566b478 MS |
1672 | return t; |
1673 | } | |
1674 | ||
a09ba2e0 MM |
1675 | /* Similar to `build', except we set TREE_COMPLEXITY to the current |
1676 | line-number. */ | |
5566b478 MS |
1677 | |
1678 | tree | |
158991b7 | 1679 | build_min VPARAMS ((enum tree_code code, tree tt, ...)) |
5566b478 | 1680 | { |
c5c76735 | 1681 | #ifndef ANSI_PROTOTYPES |
5566b478 MS |
1682 | enum tree_code code; |
1683 | tree tt; | |
1684 | #endif | |
5566b478 MS |
1685 | va_list p; |
1686 | register tree t; | |
1687 | register int length; | |
1688 | register int i; | |
1689 | ||
1690 | VA_START (p, tt); | |
1691 | ||
c5c76735 | 1692 | #ifndef ANSI_PROTOTYPES |
5566b478 MS |
1693 | code = va_arg (p, enum tree_code); |
1694 | tt = va_arg (p, tree); | |
1695 | #endif | |
1696 | ||
5566b478 | 1697 | t = make_node (code); |
8d5e6e25 | 1698 | length = TREE_CODE_LENGTH (code); |
2a1e9fdd | 1699 | TREE_TYPE (t) = tt; |
5566b478 MS |
1700 | TREE_COMPLEXITY (t) = lineno; |
1701 | ||
1702 | for (i = 0; i < length; i++) | |
1703 | { | |
1704 | tree x = va_arg (p, tree); | |
2a1e9fdd | 1705 | TREE_OPERAND (t, i) = x; |
5566b478 MS |
1706 | } |
1707 | ||
1708 | va_end (p); | |
5566b478 MS |
1709 | return t; |
1710 | } | |
1711 | ||
a68ad5bd MM |
1712 | /* Returns an INTEGER_CST (of type `int') corresponding to I. |
1713 | Multiple calls with the same value of I may or may not yield the | |
1714 | same node; therefore, callers should never modify the node | |
1715 | returned. */ | |
1716 | ||
1717 | tree | |
1718 | build_shared_int_cst (i) | |
1719 | int i; | |
1720 | { | |
1721 | static tree cache[256]; | |
1722 | ||
1723 | if (i >= 256) | |
1724 | return build_int_2 (i, 0); | |
1725 | ||
1726 | if (!cache[i]) | |
1727 | cache[i] = build_int_2 (i, 0); | |
1728 | ||
1729 | return cache[i]; | |
1730 | } | |
1731 | ||
5566b478 MS |
1732 | tree |
1733 | get_type_decl (t) | |
1734 | tree t; | |
1735 | { | |
5566b478 MS |
1736 | if (TREE_CODE (t) == TYPE_DECL) |
1737 | return t; | |
2f939d94 | 1738 | if (TYPE_P (t)) |
5566b478 MS |
1739 | return TYPE_STUB_DECL (t); |
1740 | ||
1741 | my_friendly_abort (42); | |
4e1e2064 MH |
1742 | |
1743 | /* Stop compiler from complaining control reaches end of non-void function. */ | |
1744 | return 0; | |
5566b478 MS |
1745 | } |
1746 | ||
1747 | int | |
1748 | can_free (obstack, t) | |
1749 | struct obstack *obstack; | |
1750 | tree t; | |
1751 | { | |
a703fb38 | 1752 | int size = 0; |
5566b478 MS |
1753 | |
1754 | if (TREE_CODE (t) == TREE_VEC) | |
1755 | size = (TREE_VEC_LENGTH (t)-1) * sizeof (tree) + sizeof (struct tree_vec); | |
1756 | else | |
1757 | my_friendly_abort (42); | |
1758 | ||
1759 | #define ROUND(x) ((x + obstack_alignment_mask (obstack)) \ | |
1760 | & ~ obstack_alignment_mask (obstack)) | |
1761 | if ((char *)t + ROUND (size) == obstack_next_free (obstack)) | |
1762 | return 1; | |
1763 | #undef ROUND | |
1764 | ||
1765 | return 0; | |
1766 | } | |
1767 | ||
1768 | /* Return first vector element whose BINFO_TYPE is ELEM. | |
934c6b13 | 1769 | Return 0 if ELEM is not in VEC. VEC may be NULL_TREE. */ |
5566b478 MS |
1770 | |
1771 | tree | |
1772 | vec_binfo_member (elem, vec) | |
1773 | tree elem, vec; | |
1774 | { | |
1775 | int i; | |
934c6b13 MS |
1776 | |
1777 | if (vec) | |
1778 | for (i = 0; i < TREE_VEC_LENGTH (vec); ++i) | |
3bfdc719 | 1779 | if (same_type_p (elem, BINFO_TYPE (TREE_VEC_ELT (vec, i)))) |
934c6b13 MS |
1780 | return TREE_VEC_ELT (vec, i); |
1781 | ||
5566b478 MS |
1782 | return NULL_TREE; |
1783 | } | |
e76a2646 | 1784 | |
700466c2 JM |
1785 | /* Returns the namespace that contains DECL, whether directly or |
1786 | indirectly. */ | |
1787 | ||
1788 | tree | |
1789 | decl_namespace_context (decl) | |
1790 | tree decl; | |
1791 | { | |
1792 | while (1) | |
1793 | { | |
1794 | if (TREE_CODE (decl) == NAMESPACE_DECL) | |
1795 | return decl; | |
1796 | else if (TYPE_P (decl)) | |
1797 | decl = CP_DECL_CONTEXT (TYPE_MAIN_DECL (decl)); | |
1798 | else | |
1799 | decl = CP_DECL_CONTEXT (decl); | |
1800 | } | |
1801 | } | |
1802 | ||
67d743fe MS |
1803 | /* Return truthvalue of whether T1 is the same tree structure as T2. |
1804 | Return 1 if they are the same. | |
1805 | Return 0 if they are understandably different. | |
1806 | Return -1 if either contains tree structure not understood by | |
1807 | this function. */ | |
1808 | ||
1809 | int | |
1810 | cp_tree_equal (t1, t2) | |
1811 | tree t1, t2; | |
1812 | { | |
1813 | register enum tree_code code1, code2; | |
1814 | int cmp; | |
1815 | ||
1816 | if (t1 == t2) | |
1817 | return 1; | |
1818 | if (t1 == 0 || t2 == 0) | |
1819 | return 0; | |
1820 | ||
1821 | code1 = TREE_CODE (t1); | |
1822 | code2 = TREE_CODE (t2); | |
1823 | ||
1824 | if (code1 == NOP_EXPR || code1 == CONVERT_EXPR || code1 == NON_LVALUE_EXPR) | |
a703fb38 KG |
1825 | { |
1826 | if (code2 == NOP_EXPR || code2 == CONVERT_EXPR || code2 == NON_LVALUE_EXPR) | |
1827 | return cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0)); | |
1828 | else | |
1829 | return cp_tree_equal (TREE_OPERAND (t1, 0), t2); | |
1830 | } | |
67d743fe MS |
1831 | else if (code2 == NOP_EXPR || code2 == CONVERT_EXPR |
1832 | || code2 == NON_LVALUE_EXPR) | |
1833 | return cp_tree_equal (t1, TREE_OPERAND (t2, 0)); | |
1834 | ||
1835 | if (code1 != code2) | |
1836 | return 0; | |
1837 | ||
1838 | switch (code1) | |
1839 | { | |
1840 | case INTEGER_CST: | |
1841 | return TREE_INT_CST_LOW (t1) == TREE_INT_CST_LOW (t2) | |
1842 | && TREE_INT_CST_HIGH (t1) == TREE_INT_CST_HIGH (t2); | |
1843 | ||
1844 | case REAL_CST: | |
1845 | return REAL_VALUES_EQUAL (TREE_REAL_CST (t1), TREE_REAL_CST (t2)); | |
1846 | ||
1847 | case STRING_CST: | |
1848 | return TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2) | |
1849 | && !bcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2), | |
1850 | TREE_STRING_LENGTH (t1)); | |
1851 | ||
1852 | case CONSTRUCTOR: | |
7dd4bdf5 MM |
1853 | /* We need to do this when determining whether or not two |
1854 | non-type pointer to member function template arguments | |
1855 | are the same. */ | |
3bfdc719 | 1856 | if (!(same_type_p (TREE_TYPE (t1), TREE_TYPE (t2)) |
7dd4bdf5 MM |
1857 | /* The first operand is RTL. */ |
1858 | && TREE_OPERAND (t1, 0) == TREE_OPERAND (t2, 0))) | |
1859 | return 0; | |
1860 | return cp_tree_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1)); | |
1861 | ||
1862 | case TREE_LIST: | |
1863 | cmp = cp_tree_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2)); | |
1864 | if (cmp <= 0) | |
1865 | return cmp; | |
1866 | cmp = cp_tree_equal (TREE_VALUE (t1), TREE_VALUE (t2)); | |
1867 | if (cmp <= 0) | |
1868 | return cmp; | |
1869 | return cp_tree_equal (TREE_CHAIN (t1), TREE_CHAIN (t2)); | |
67d743fe MS |
1870 | |
1871 | case SAVE_EXPR: | |
1872 | return cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0)); | |
1873 | ||
1874 | case CALL_EXPR: | |
1875 | cmp = cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0)); | |
1876 | if (cmp <= 0) | |
1877 | return cmp; | |
1878 | return simple_cst_list_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1)); | |
1879 | ||
1880 | case TARGET_EXPR: | |
1881 | /* Special case: if either target is an unallocated VAR_DECL, | |
1882 | it means that it's going to be unified with whatever the | |
1883 | TARGET_EXPR is really supposed to initialize, so treat it | |
1884 | as being equivalent to anything. */ | |
1885 | if ((TREE_CODE (TREE_OPERAND (t1, 0)) == VAR_DECL | |
1886 | && DECL_NAME (TREE_OPERAND (t1, 0)) == NULL_TREE | |
1887 | && DECL_RTL (TREE_OPERAND (t1, 0)) == 0) | |
1888 | || (TREE_CODE (TREE_OPERAND (t2, 0)) == VAR_DECL | |
1889 | && DECL_NAME (TREE_OPERAND (t2, 0)) == NULL_TREE | |
1890 | && DECL_RTL (TREE_OPERAND (t2, 0)) == 0)) | |
1891 | cmp = 1; | |
1892 | else | |
1893 | cmp = cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0)); | |
1894 | if (cmp <= 0) | |
1895 | return cmp; | |
1896 | return cp_tree_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1)); | |
1897 | ||
1898 | case WITH_CLEANUP_EXPR: | |
1899 | cmp = cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0)); | |
1900 | if (cmp <= 0) | |
1901 | return cmp; | |
1902 | return cp_tree_equal (TREE_OPERAND (t1, 2), TREE_OPERAND (t1, 2)); | |
1903 | ||
1904 | case COMPONENT_REF: | |
1905 | if (TREE_OPERAND (t1, 1) == TREE_OPERAND (t2, 1)) | |
1906 | return cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0)); | |
1907 | return 0; | |
1908 | ||
1909 | case VAR_DECL: | |
1910 | case PARM_DECL: | |
1911 | case CONST_DECL: | |
1912 | case FUNCTION_DECL: | |
1913 | return 0; | |
1914 | ||
f84b4be9 JM |
1915 | case TEMPLATE_PARM_INDEX: |
1916 | return TEMPLATE_PARM_IDX (t1) == TEMPLATE_PARM_IDX (t2) | |
1917 | && TEMPLATE_PARM_LEVEL (t1) == TEMPLATE_PARM_LEVEL (t2); | |
67d743fe MS |
1918 | |
1919 | case SIZEOF_EXPR: | |
abff8e06 | 1920 | case ALIGNOF_EXPR: |
67d743fe MS |
1921 | if (TREE_CODE (TREE_OPERAND (t1, 0)) != TREE_CODE (TREE_OPERAND (t2, 0))) |
1922 | return 0; | |
2f939d94 | 1923 | if (TYPE_P (TREE_OPERAND (t1, 0))) |
3bfdc719 | 1924 | return same_type_p (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0)); |
67d743fe | 1925 | break; |
7f85441b | 1926 | |
61a127b3 MM |
1927 | case PTRMEM_CST: |
1928 | /* Two pointer-to-members are the same if they point to the same | |
1929 | field or function in the same class. */ | |
1930 | return (PTRMEM_CST_MEMBER (t1) == PTRMEM_CST_MEMBER (t2) | |
3bfdc719 | 1931 | && same_type_p (PTRMEM_CST_CLASS (t1), PTRMEM_CST_CLASS (t2))); |
61a127b3 | 1932 | |
7f85441b KG |
1933 | default: |
1934 | break; | |
67d743fe MS |
1935 | } |
1936 | ||
1937 | switch (TREE_CODE_CLASS (code1)) | |
1938 | { | |
1939 | int i; | |
1940 | case '1': | |
1941 | case '2': | |
1942 | case '<': | |
1943 | case 'e': | |
1944 | case 'r': | |
1945 | case 's': | |
1946 | cmp = 1; | |
8d5e6e25 | 1947 | for (i = 0; i < TREE_CODE_LENGTH (code1); ++i) |
67d743fe MS |
1948 | { |
1949 | cmp = cp_tree_equal (TREE_OPERAND (t1, i), TREE_OPERAND (t2, i)); | |
1950 | if (cmp <= 0) | |
1951 | return cmp; | |
1952 | } | |
1953 | return cmp; | |
1954 | } | |
1955 | ||
1956 | return -1; | |
1957 | } | |
73aad9b9 | 1958 | |
5ffe581d JM |
1959 | /* Build a wrapper around some pointer PTR so we can use it as a tree. */ |
1960 | ||
1961 | tree | |
1962 | build_ptr_wrapper (ptr) | |
1963 | void *ptr; | |
1964 | { | |
1965 | tree t = make_node (WRAPPER); | |
1966 | WRAPPER_PTR (t) = ptr; | |
1967 | return t; | |
1968 | } | |
1969 | ||
1970 | /* Same, but on the expression_obstack. */ | |
1971 | ||
1972 | tree | |
1973 | build_expr_ptr_wrapper (ptr) | |
1974 | void *ptr; | |
1975 | { | |
cd9f6678 | 1976 | return build_ptr_wrapper (ptr); |
5ffe581d JM |
1977 | } |
1978 | ||
1979 | /* Build a wrapper around some integer I so we can use it as a tree. */ | |
1980 | ||
1981 | tree | |
1982 | build_int_wrapper (i) | |
1983 | int i; | |
1984 | { | |
1985 | tree t = make_node (WRAPPER); | |
1986 | WRAPPER_INT (t) = i; | |
1987 | return t; | |
1988 | } | |
1989 | ||
d8e178a0 | 1990 | static tree |
1139b3d8 | 1991 | build_srcloc (file, line) |
3b304f5b | 1992 | const char *file; |
1139b3d8 JM |
1993 | int line; |
1994 | { | |
a48ebb56 BK |
1995 | tree t; |
1996 | ||
a48ebb56 | 1997 | t = make_node (SRCLOC); |
1139b3d8 JM |
1998 | SRCLOC_FILE (t) = file; |
1999 | SRCLOC_LINE (t) = line; | |
a48ebb56 | 2000 | |
1139b3d8 JM |
2001 | return t; |
2002 | } | |
2003 | ||
2004 | tree | |
2005 | build_srcloc_here () | |
2006 | { | |
2007 | return build_srcloc (input_filename, lineno); | |
2008 | } | |
2009 | ||
d11ad92e MS |
2010 | /* The type of ARG when used as an lvalue. */ |
2011 | ||
2012 | tree | |
2013 | lvalue_type (arg) | |
2014 | tree arg; | |
2015 | { | |
2c73f9f5 ML |
2016 | tree type = TREE_TYPE (arg); |
2017 | if (TREE_CODE (arg) == OVERLOAD) | |
2018 | type = unknown_type_node; | |
8cd4c175 | 2019 | return type; |
d11ad92e MS |
2020 | } |
2021 | ||
2022 | /* The type of ARG for printing error messages; denote lvalues with | |
2023 | reference types. */ | |
2024 | ||
2025 | tree | |
2026 | error_type (arg) | |
2027 | tree arg; | |
2028 | { | |
2029 | tree type = TREE_TYPE (arg); | |
2030 | if (TREE_CODE (type) == ARRAY_TYPE) | |
2031 | ; | |
2032 | else if (real_lvalue_p (arg)) | |
2033 | type = build_reference_type (lvalue_type (arg)); | |
2034 | else if (IS_AGGR_TYPE (type)) | |
2035 | type = lvalue_type (arg); | |
2036 | ||
2037 | return type; | |
2038 | } | |
eb66be0e MS |
2039 | |
2040 | /* Does FUNCTION use a variable-length argument list? */ | |
2041 | ||
2042 | int | |
2043 | varargs_function_p (function) | |
2044 | tree function; | |
2045 | { | |
2046 | tree parm = TYPE_ARG_TYPES (TREE_TYPE (function)); | |
2047 | for (; parm; parm = TREE_CHAIN (parm)) | |
2048 | if (TREE_VALUE (parm) == void_type_node) | |
2049 | return 0; | |
2050 | return 1; | |
2051 | } | |
f94ae2f5 JM |
2052 | |
2053 | /* Returns 1 if decl is a member of a class. */ | |
2054 | ||
2055 | int | |
2056 | member_p (decl) | |
2057 | tree decl; | |
2058 | { | |
2f939d94 TP |
2059 | const tree ctx = DECL_CONTEXT (decl); |
2060 | return (ctx && TYPE_P (ctx)); | |
f94ae2f5 | 2061 | } |
51924768 JM |
2062 | |
2063 | /* Create a placeholder for member access where we don't actually have an | |
2064 | object that the access is against. */ | |
2065 | ||
2066 | tree | |
2067 | build_dummy_object (type) | |
2068 | tree type; | |
2069 | { | |
44689c12 | 2070 | tree decl = build1 (NOP_EXPR, build_pointer_type (type), void_zero_node); |
51924768 JM |
2071 | return build_indirect_ref (decl, NULL_PTR); |
2072 | } | |
2073 | ||
2074 | /* We've gotten a reference to a member of TYPE. Return *this if appropriate, | |
2075 | or a dummy object otherwise. If BINFOP is non-0, it is filled with the | |
2076 | binfo path from current_class_type to TYPE, or 0. */ | |
2077 | ||
2078 | tree | |
2079 | maybe_dummy_object (type, binfop) | |
2080 | tree type; | |
2081 | tree *binfop; | |
2082 | { | |
2083 | tree decl, context; | |
2084 | ||
2085 | if (current_class_type | |
2086 | && get_base_distance (type, current_class_type, 0, binfop) != -1) | |
2087 | context = current_class_type; | |
2088 | else | |
2089 | { | |
2090 | /* Reference from a nested class member function. */ | |
2091 | context = type; | |
2092 | if (binfop) | |
2093 | *binfop = TYPE_BINFO (type); | |
2094 | } | |
2095 | ||
2096 | if (current_class_ref && context == current_class_type) | |
2097 | decl = current_class_ref; | |
2098 | else | |
2099 | decl = build_dummy_object (context); | |
2100 | ||
2101 | return decl; | |
2102 | } | |
2103 | ||
2104 | /* Returns 1 if OB is a placeholder object, or a pointer to one. */ | |
2105 | ||
2106 | int | |
2107 | is_dummy_object (ob) | |
2108 | tree ob; | |
2109 | { | |
2110 | if (TREE_CODE (ob) == INDIRECT_REF) | |
2111 | ob = TREE_OPERAND (ob, 0); | |
2112 | return (TREE_CODE (ob) == NOP_EXPR | |
44689c12 | 2113 | && TREE_OPERAND (ob, 0) == void_zero_node); |
51924768 | 2114 | } |
5524676d JM |
2115 | |
2116 | /* Returns 1 iff type T is a POD type, as defined in [basic.types]. */ | |
2117 | ||
2118 | int | |
2119 | pod_type_p (t) | |
2120 | tree t; | |
2121 | { | |
5524676d JM |
2122 | while (TREE_CODE (t) == ARRAY_TYPE) |
2123 | t = TREE_TYPE (t); | |
2124 | ||
52fb2769 NS |
2125 | if (INTEGRAL_TYPE_P (t)) |
2126 | return 1; /* integral, character or enumeral type */ | |
2127 | if (FLOAT_TYPE_P (t)) | |
5524676d | 2128 | return 1; |
52fb2769 NS |
2129 | if (TYPE_PTR_P (t)) |
2130 | return 1; /* pointer to non-member */ | |
2131 | if (TYPE_PTRMEM_P (t)) | |
2132 | return 1; /* pointer to member object */ | |
2133 | if (TYPE_PTRMEMFUNC_P (t)) | |
2134 | return 1; /* pointer to member function */ | |
2135 | ||
2136 | if (! CLASS_TYPE_P (t)) | |
2137 | return 0; /* other non-class type (reference or function) */ | |
2138 | if (CLASSTYPE_NON_POD_P (t)) | |
5524676d | 2139 | return 0; |
5524676d JM |
2140 | return 1; |
2141 | } | |
e5dc5fb2 | 2142 | |
e5dc5fb2 JM |
2143 | /* Return a 1 if ATTR_NAME and ATTR_ARGS denote a valid C++-specific |
2144 | attribute for either declaration DECL or type TYPE and 0 otherwise. | |
2145 | Plugged into valid_lang_attribute. */ | |
2146 | ||
2147 | int | |
2148 | cp_valid_lang_attribute (attr_name, attr_args, decl, type) | |
2149 | tree attr_name; | |
2150 | tree attr_args ATTRIBUTE_UNUSED; | |
2151 | tree decl ATTRIBUTE_UNUSED; | |
2152 | tree type ATTRIBUTE_UNUSED; | |
2153 | { | |
9db83085 | 2154 | if (is_attribute_p ("com_interface", attr_name)) |
e5dc5fb2 JM |
2155 | { |
2156 | if (! flag_vtable_thunks) | |
2157 | { | |
2158 | error ("`com_interface' only supported with -fvtable-thunks"); | |
2159 | return 0; | |
2160 | } | |
2161 | ||
2162 | if (attr_args != NULL_TREE | |
2163 | || decl != NULL_TREE | |
2164 | || ! CLASS_TYPE_P (type) | |
2165 | || type != TYPE_MAIN_VARIANT (type)) | |
2166 | { | |
2167 | warning ("`com_interface' attribute can only be applied to class definitions"); | |
2168 | return 0; | |
2169 | } | |
2170 | ||
2171 | CLASSTYPE_COM_INTERFACE (type) = 1; | |
2172 | return 1; | |
2173 | } | |
9db83085 | 2174 | else if (is_attribute_p ("init_priority", attr_name)) |
e5dc5fb2 JM |
2175 | { |
2176 | tree initp_expr = (attr_args ? TREE_VALUE (attr_args): NULL_TREE); | |
2177 | int pri; | |
2178 | ||
2179 | if (initp_expr) | |
2180 | STRIP_NOPS (initp_expr); | |
2181 | ||
2182 | if (!initp_expr || TREE_CODE (initp_expr) != INTEGER_CST) | |
2183 | { | |
2184 | error ("requested init_priority is not an integer constant"); | |
2185 | return 0; | |
2186 | } | |
2187 | ||
2188 | pri = TREE_INT_CST_LOW (initp_expr); | |
2189 | ||
2190 | while (TREE_CODE (type) == ARRAY_TYPE) | |
2191 | type = TREE_TYPE (type); | |
2192 | ||
2193 | if (decl == NULL_TREE | |
2194 | || TREE_CODE (decl) != VAR_DECL | |
2195 | || ! TREE_STATIC (decl) | |
2196 | || DECL_EXTERNAL (decl) | |
2197 | || (TREE_CODE (type) != RECORD_TYPE | |
2198 | && TREE_CODE (type) != UNION_TYPE) | |
2199 | /* Static objects in functions are initialized the | |
2200 | first time control passes through that | |
2201 | function. This is not precise enough to pin down an | |
2202 | init_priority value, so don't allow it. */ | |
2203 | || current_function_decl) | |
2204 | { | |
2205 | error ("can only use init_priority attribute on file-scope definitions of objects of class type"); | |
2206 | return 0; | |
2207 | } | |
2208 | ||
2209 | if (pri > MAX_INIT_PRIORITY || pri <= 0) | |
2210 | { | |
2211 | error ("requested init_priority is out of range"); | |
2212 | return 0; | |
2213 | } | |
2214 | ||
2215 | /* Check for init_priorities that are reserved for | |
2216 | language and runtime support implementations.*/ | |
2217 | if (pri <= MAX_RESERVED_INIT_PRIORITY) | |
2218 | { | |
2219 | warning | |
2220 | ("requested init_priority is reserved for internal use"); | |
2221 | } | |
2222 | ||
0aafb128 | 2223 | DECL_INIT_PRIORITY (decl) = pri; |
e5dc5fb2 JM |
2224 | return 1; |
2225 | } | |
2226 | ||
2227 | return 0; | |
2228 | } | |
87533b37 MM |
2229 | |
2230 | /* Return a new PTRMEM_CST of the indicated TYPE. The MEMBER is the | |
2231 | thing pointed to by the constant. */ | |
2232 | ||
2233 | tree | |
2234 | make_ptrmem_cst (type, member) | |
2235 | tree type; | |
2236 | tree member; | |
2237 | { | |
2238 | tree ptrmem_cst = make_node (PTRMEM_CST); | |
2239 | /* If would seem a great convenience if make_node would set | |
2240 | TREE_CONSTANT for things of class `c', but it does not. */ | |
2241 | TREE_CONSTANT (ptrmem_cst) = 1; | |
2242 | TREE_TYPE (ptrmem_cst) = type; | |
2243 | PTRMEM_CST_MEMBER (ptrmem_cst) = member; | |
2244 | return ptrmem_cst; | |
2245 | } | |
2246 | ||
87e3dbc9 MM |
2247 | /* Mark ARG (which is really a list_hash_table **) for GC. */ |
2248 | ||
2249 | static void | |
2250 | mark_list_hash (arg) | |
2251 | void *arg; | |
2252 | { | |
2253 | struct list_hash *lh; | |
2254 | ||
2255 | for (lh = * ((struct list_hash **) arg); lh; lh = lh->next) | |
2256 | ggc_mark_tree (lh->list); | |
2257 | } | |
2258 | ||
2259 | /* Initialize tree.c. */ | |
2260 | ||
0a818f84 | 2261 | void |
87e3dbc9 | 2262 | init_tree () |
0a818f84 | 2263 | { |
266f2faa | 2264 | make_lang_type_fn = cp_make_lang_type; |
46e8c075 | 2265 | lang_unsave = cp_unsave; |
87e3dbc9 MM |
2266 | ggc_add_root (list_hash_table, |
2267 | sizeof (list_hash_table) / sizeof (struct list_hash *), | |
2268 | sizeof (struct list_hash *), | |
2269 | mark_list_hash); | |
0a818f84 GRK |
2270 | } |
2271 | ||
46e8c075 MM |
2272 | /* The SAVE_EXPR pointed to by TP is being copied. If ST contains |
2273 | information indicating to what new SAVE_EXPR this one should be | |
2274 | mapped, use that one. Otherwise, create a new node and enter it in | |
2275 | ST. FN is the function into which the copy will be placed. */ | |
0a818f84 | 2276 | |
4ef8e8f5 | 2277 | void |
d7d5e42f | 2278 | remap_save_expr (tp, st, fn, walk_subtrees) |
46e8c075 MM |
2279 | tree *tp; |
2280 | splay_tree st; | |
2281 | tree fn; | |
d7d5e42f | 2282 | int *walk_subtrees; |
0a818f84 | 2283 | { |
46e8c075 | 2284 | splay_tree_node n; |
0a818f84 | 2285 | |
46e8c075 MM |
2286 | /* See if we already encountered this SAVE_EXPR. */ |
2287 | n = splay_tree_lookup (st, (splay_tree_key) *tp); | |
2288 | ||
2289 | /* If we didn't already remap this SAVE_EXPR, do so now. */ | |
2290 | if (!n) | |
0a818f84 | 2291 | { |
46e8c075 MM |
2292 | tree t = copy_node (*tp); |
2293 | ||
2294 | /* The SAVE_EXPR is now part of the function into which we | |
2295 | are inlining this body. */ | |
2296 | SAVE_EXPR_CONTEXT (t) = fn; | |
2297 | /* And we haven't evaluated it yet. */ | |
2298 | SAVE_EXPR_RTL (t) = NULL_RTX; | |
2299 | /* Remember this SAVE_EXPR. */ | |
2300 | n = splay_tree_insert (st, | |
2301 | (splay_tree_key) *tp, | |
2302 | (splay_tree_value) t); | |
2303 | } | |
d7d5e42f MM |
2304 | else |
2305 | /* We've already walked into this SAVE_EXPR, so we needn't do it | |
2306 | again. */ | |
2307 | *walk_subtrees = 0; | |
46e8c075 MM |
2308 | |
2309 | /* Replace this SAVE_EXPR with the copy. */ | |
2310 | *tp = (tree) n->value; | |
2311 | } | |
2312 | ||
2313 | /* Called via walk_tree. If *TP points to a DECL_STMT for a local | |
2314 | declaration, copies the declaration and enters it in the splay_tree | |
2315 | pointed to by DATA (which is really a `splay_tree *'). */ | |
2316 | ||
2317 | static tree | |
2318 | mark_local_for_remap_r (tp, walk_subtrees, data) | |
2319 | tree *tp; | |
2320 | int *walk_subtrees ATTRIBUTE_UNUSED; | |
2321 | void *data; | |
2322 | { | |
2323 | tree t = *tp; | |
2324 | splay_tree st = (splay_tree) data; | |
ec47ccca | 2325 | tree decl; |
46e8c075 | 2326 | |
ec47ccca MM |
2327 | |
2328 | if (TREE_CODE (t) == DECL_STMT | |
2329 | && nonstatic_local_decl_p (DECL_STMT_DECL (t))) | |
2330 | decl = DECL_STMT_DECL (t); | |
2331 | else if (TREE_CODE (t) == LABEL_STMT) | |
2332 | decl = LABEL_STMT_LABEL (t); | |
2333 | else if (TREE_CODE (t) == TARGET_EXPR | |
2334 | && nonstatic_local_decl_p (TREE_OPERAND (t, 0))) | |
2335 | decl = TREE_OPERAND (t, 0); | |
2336 | else | |
2337 | decl = NULL_TREE; | |
2338 | ||
2339 | if (decl) | |
46e8c075 | 2340 | { |
46e8c075 MM |
2341 | tree copy; |
2342 | ||
46e8c075 MM |
2343 | /* Make a copy. */ |
2344 | copy = copy_decl_for_inlining (decl, | |
2345 | DECL_CONTEXT (decl), | |
2346 | DECL_CONTEXT (decl)); | |
2347 | ||
2348 | /* Remember the copy. */ | |
2349 | splay_tree_insert (st, | |
2350 | (splay_tree_key) decl, | |
2351 | (splay_tree_value) copy); | |
0a818f84 GRK |
2352 | } |
2353 | ||
46e8c075 MM |
2354 | return NULL_TREE; |
2355 | } | |
2356 | ||
2357 | /* Called via walk_tree when an expression is unsaved. Using the | |
ec47ccca | 2358 | splay_tree pointed to by ST (which is really a `splay_tree'), |
46e8c075 MM |
2359 | remaps all local declarations to appropriate replacements. */ |
2360 | ||
2361 | static tree | |
2362 | cp_unsave_r (tp, walk_subtrees, data) | |
2363 | tree *tp; | |
2364 | int *walk_subtrees; | |
2365 | void *data; | |
2366 | { | |
2367 | splay_tree st = (splay_tree) data; | |
2368 | splay_tree_node n; | |
2369 | ||
2370 | /* Only a local declaration (variable or label). */ | |
2371 | if (nonstatic_local_decl_p (*tp)) | |
2372 | { | |
2373 | /* Lookup the declaration. */ | |
2374 | n = splay_tree_lookup (st, (splay_tree_key) *tp); | |
2375 | ||
2376 | /* If it's there, remap it. */ | |
2377 | if (n) | |
2378 | *tp = (tree) n->value; | |
2379 | } | |
2380 | else if (TREE_CODE (*tp) == SAVE_EXPR) | |
d7d5e42f | 2381 | remap_save_expr (tp, st, current_function_decl, walk_subtrees); |
0a818f84 | 2382 | else |
46e8c075 MM |
2383 | { |
2384 | copy_tree_r (tp, walk_subtrees, NULL); | |
2385 | ||
2386 | /* Do whatever unsaving is required. */ | |
2387 | unsave_expr_1 (*tp); | |
2388 | } | |
2389 | ||
2390 | /* Keep iterating. */ | |
2391 | return NULL_TREE; | |
0a818f84 GRK |
2392 | } |
2393 | ||
46e8c075 MM |
2394 | /* Called by unsave_expr_now whenever an expression (*TP) needs to be |
2395 | unsaved. */ | |
2396 | ||
2397 | static void | |
2398 | cp_unsave (tp) | |
2399 | tree *tp; | |
2400 | { | |
2401 | splay_tree st; | |
2402 | ||
2403 | /* Create a splay-tree to map old local variable declarations to new | |
2404 | ones. */ | |
2405 | st = splay_tree_new (splay_tree_compare_pointers, NULL, NULL); | |
2406 | ||
2407 | /* Walk the tree once figuring out what needs to be remapped. */ | |
2408 | walk_tree (tp, mark_local_for_remap_r, st); | |
2409 | ||
2410 | /* Walk the tree again, copying, remapping, and unsaving. */ | |
2411 | walk_tree (tp, cp_unsave_r, st); | |
2412 | ||
2413 | /* Clean up. */ | |
2414 | splay_tree_delete (st); | |
2415 | } | |
872f37f9 MM |
2416 | |
2417 | /* Returns the kind of special function that DECL (a FUNCTION_DECL) | |
2418 | is. Note that this sfk_none is zero, so this function can be used | |
2419 | as a predicate to test whether or not DECL is a special function. */ | |
2420 | ||
2421 | special_function_kind | |
2422 | special_function_p (decl) | |
2423 | tree decl; | |
2424 | { | |
2425 | /* Rather than doing all this stuff with magic names, we should | |
2426 | probably have a field of type `special_function_kind' in | |
2427 | DECL_LANG_SPECIFIC. */ | |
2428 | if (DECL_COPY_CONSTRUCTOR_P (decl)) | |
2429 | return sfk_copy_constructor; | |
2430 | if (DECL_CONSTRUCTOR_P (decl)) | |
2431 | return sfk_constructor; | |
596ea4e5 | 2432 | if (DECL_OVERLOADED_OPERATOR_P (decl) == NOP_EXPR) |
872f37f9 MM |
2433 | return sfk_assignment_operator; |
2434 | if (DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (decl)) | |
2435 | return sfk_destructor; | |
2436 | if (DECL_COMPLETE_DESTRUCTOR_P (decl)) | |
2437 | return sfk_complete_destructor; | |
2438 | if (DECL_BASE_DESTRUCTOR_P (decl)) | |
2439 | return sfk_base_destructor; | |
2440 | if (DECL_DELETING_DESTRUCTOR_P (decl)) | |
2441 | return sfk_deleting_destructor; | |
2442 | if (DECL_CONV_FN_P (decl)) | |
2443 | return sfk_conversion; | |
2444 | ||
2445 | return sfk_none; | |
2446 | } |