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