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