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