]>
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, |
a7cbc517 | 3 | 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009 |
e77f031d | 4 | Free Software Foundation, Inc. |
8d08fdba MS |
5 | Hacked by Michael Tiemann (tiemann@cygnus.com) |
6 | ||
f5adbb8d | 7 | This file is part of GCC. |
8d08fdba | 8 | |
f5adbb8d | 9 | GCC is free software; you can redistribute it and/or modify |
8d08fdba | 10 | it under the terms of the GNU General Public License as published by |
e77f031d | 11 | the Free Software Foundation; either version 3, or (at your option) |
8d08fdba MS |
12 | any later version. |
13 | ||
f5adbb8d | 14 | GCC is distributed in the hope that it will be useful, |
8d08fdba MS |
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | GNU General Public License for more details. | |
18 | ||
19 | You should have received a copy of the GNU General Public License | |
e77f031d NC |
20 | along with GCC; see the file COPYING3. If not see |
21 | <http://www.gnu.org/licenses/>. */ | |
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" | |
12027a89 | 30 | #include "toplev.h" |
25af8512 | 31 | #include "tree-inline.h" |
e58a9aa1 | 32 | #include "debug.h" |
41990f96 | 33 | #include "convert.h" |
87501227 | 34 | #include "cgraph.h" |
245763e3 | 35 | #include "splay-tree.h" |
6662d794 | 36 | #include "gimple.h" /* gimple_has_body_p */ |
12027a89 | 37 | |
b57b79f7 NN |
38 | static tree bot_manip (tree *, int *, void *); |
39 | static tree bot_replace (tree *, int *, void *); | |
b57b79f7 NN |
40 | static int list_hash_eq (const void *, const void *); |
41 | static hashval_t list_hash_pieces (tree, tree, tree); | |
42 | static hashval_t list_hash (const void *); | |
df5c89cb | 43 | static cp_lvalue_kind lvalue_p_1 (const_tree); |
b57b79f7 NN |
44 | static tree build_target_expr (tree, tree); |
45 | static tree count_trees_r (tree *, int *, void *); | |
46 | static tree verify_stmt_tree_r (tree *, int *, void *); | |
a6f86b51 | 47 | static tree build_local_temp (tree); |
b57b79f7 NN |
48 | |
49 | static tree handle_java_interface_attribute (tree *, tree, tree, int, bool *); | |
50 | static tree handle_com_interface_attribute (tree *, tree, tree, int, bool *); | |
51 | static tree handle_init_priority_attribute (tree *, tree, tree, int, bool *); | |
91d231cb | 52 | |
27b8d0cd | 53 | /* If REF is an lvalue, returns the kind of lvalue that REF is. |
df5c89cb | 54 | Otherwise, returns clk_none. */ |
8d08fdba | 55 | |
27b8d0cd | 56 | static cp_lvalue_kind |
df5c89cb | 57 | lvalue_p_1 (const_tree ref) |
8ccc31eb | 58 | { |
27b8d0cd MM |
59 | cp_lvalue_kind op1_lvalue_kind = clk_none; |
60 | cp_lvalue_kind op2_lvalue_kind = clk_none; | |
61 | ||
8af2fec4 RY |
62 | /* Expressions of reference type are sometimes wrapped in |
63 | INDIRECT_REFs. INDIRECT_REFs are just internal compiler | |
64 | representation, not part of the language, so we have to look | |
65 | through them. */ | |
66 | if (TREE_CODE (ref) == INDIRECT_REF | |
67 | && TREE_CODE (TREE_TYPE (TREE_OPERAND (ref, 0))) | |
68 | == REFERENCE_TYPE) | |
df5c89cb | 69 | return lvalue_p_1 (TREE_OPERAND (ref, 0)); |
8af2fec4 | 70 | |
8ccc31eb | 71 | if (TREE_CODE (TREE_TYPE (ref)) == REFERENCE_TYPE) |
8af2fec4 RY |
72 | { |
73 | /* unnamed rvalue references are rvalues */ | |
74 | if (TYPE_REF_IS_RVALUE (TREE_TYPE (ref)) | |
75 | && TREE_CODE (ref) != PARM_DECL | |
76 | && TREE_CODE (ref) != VAR_DECL | |
77 | && TREE_CODE (ref) != COMPONENT_REF) | |
df5c89cb | 78 | return clk_rvalueref; |
8af2fec4 | 79 | |
d732e98f | 80 | /* lvalue references and named rvalue references are lvalues. */ |
8af2fec4 RY |
81 | return clk_ordinary; |
82 | } | |
8ccc31eb | 83 | |
394fd776 | 84 | if (ref == current_class_ptr) |
27b8d0cd | 85 | return clk_none; |
8ccc31eb MS |
86 | |
87 | switch (TREE_CODE (ref)) | |
88 | { | |
8f4361eb AP |
89 | case SAVE_EXPR: |
90 | return clk_none; | |
8ccc31eb | 91 | /* preincrements and predecrements are valid lvals, provided |
e92cc029 | 92 | what they refer to are valid lvals. */ |
8ccc31eb MS |
93 | case PREINCREMENT_EXPR: |
94 | case PREDECREMENT_EXPR: | |
c7ae64f2 JM |
95 | case TRY_CATCH_EXPR: |
96 | case WITH_CLEANUP_EXPR: | |
69851283 MM |
97 | case REALPART_EXPR: |
98 | case IMAGPART_EXPR: | |
df5c89cb | 99 | return lvalue_p_1 (TREE_OPERAND (ref, 0)); |
8ccc31eb | 100 | |
27b8d0cd | 101 | case COMPONENT_REF: |
df5c89cb | 102 | op1_lvalue_kind = lvalue_p_1 (TREE_OPERAND (ref, 0)); |
c8b2e872 | 103 | /* Look at the member designator. */ |
4af9e878 | 104 | if (!op1_lvalue_kind) |
0cbd7506 | 105 | ; |
4af9e878 JM |
106 | else if (is_overloaded_fn (TREE_OPERAND (ref, 1))) |
107 | /* The "field" can be a FUNCTION_DECL or an OVERLOAD in some | |
b7da27c2 JM |
108 | situations. If we're seeing a COMPONENT_REF, it's a non-static |
109 | member, so it isn't an lvalue. */ | |
110 | op1_lvalue_kind = clk_none; | |
111 | else if (TREE_CODE (TREE_OPERAND (ref, 1)) != FIELD_DECL) | |
112 | /* This can be IDENTIFIER_NODE in a template. */; | |
e0d1297c | 113 | else if (DECL_C_BIT_FIELD (TREE_OPERAND (ref, 1))) |
27b8d0cd MM |
114 | { |
115 | /* Clear the ordinary bit. If this object was a class | |
116 | rvalue we want to preserve that information. */ | |
117 | op1_lvalue_kind &= ~clk_ordinary; | |
cd0be382 | 118 | /* The lvalue is for a bitfield. */ |
27b8d0cd MM |
119 | op1_lvalue_kind |= clk_bitfield; |
120 | } | |
e0d1297c NS |
121 | else if (DECL_PACKED (TREE_OPERAND (ref, 1))) |
122 | op1_lvalue_kind |= clk_packed; | |
9f63daea | 123 | |
27b8d0cd MM |
124 | return op1_lvalue_kind; |
125 | ||
8ccc31eb | 126 | case STRING_CST: |
266b4890 | 127 | case COMPOUND_LITERAL_EXPR: |
27b8d0cd | 128 | return clk_ordinary; |
8ccc31eb | 129 | |
e58a9aa1 | 130 | case CONST_DECL: |
4b8c1a92 JJ |
131 | /* CONST_DECL without TREE_STATIC are enumeration values and |
132 | thus not lvalues. With TREE_STATIC they are used by ObjC++ | |
133 | in objc_build_string_object and need to be considered as | |
134 | lvalues. */ | |
135 | if (! TREE_STATIC (ref)) | |
136 | return clk_none; | |
8ccc31eb MS |
137 | case VAR_DECL: |
138 | if (TREE_READONLY (ref) && ! TREE_STATIC (ref) | |
139 | && DECL_LANG_SPECIFIC (ref) | |
140 | && DECL_IN_AGGR_P (ref)) | |
27b8d0cd | 141 | return clk_none; |
8ccc31eb MS |
142 | case INDIRECT_REF: |
143 | case ARRAY_REF: | |
144 | case PARM_DECL: | |
145 | case RESULT_DECL: | |
59e76fc6 | 146 | if (TREE_CODE (TREE_TYPE (ref)) != METHOD_TYPE) |
27b8d0cd | 147 | return clk_ordinary; |
8ccc31eb MS |
148 | break; |
149 | ||
8ccc31eb MS |
150 | /* A currently unresolved scope ref. */ |
151 | case SCOPE_REF: | |
315fb5db | 152 | gcc_unreachable (); |
27b8d0cd MM |
153 | case MAX_EXPR: |
154 | case MIN_EXPR: | |
d211a298 RS |
155 | /* Disallow <? and >? as lvalues if either argument side-effects. */ |
156 | if (TREE_SIDE_EFFECTS (TREE_OPERAND (ref, 0)) | |
157 | || TREE_SIDE_EFFECTS (TREE_OPERAND (ref, 1))) | |
158 | return clk_none; | |
df5c89cb JM |
159 | op1_lvalue_kind = lvalue_p_1 (TREE_OPERAND (ref, 0)); |
160 | op2_lvalue_kind = lvalue_p_1 (TREE_OPERAND (ref, 1)); | |
8ccc31eb MS |
161 | break; |
162 | ||
163 | case COND_EXPR: | |
42924ed7 JJ |
164 | op1_lvalue_kind = lvalue_p_1 (TREE_OPERAND (ref, 1) |
165 | ? TREE_OPERAND (ref, 1) | |
df5c89cb JM |
166 | : TREE_OPERAND (ref, 0)); |
167 | op2_lvalue_kind = lvalue_p_1 (TREE_OPERAND (ref, 2)); | |
27b8d0cd | 168 | break; |
8ccc31eb MS |
169 | |
170 | case MODIFY_EXPR: | |
27b8d0cd | 171 | return clk_ordinary; |
8ccc31eb MS |
172 | |
173 | case COMPOUND_EXPR: | |
df5c89cb | 174 | return lvalue_p_1 (TREE_OPERAND (ref, 1)); |
69851283 MM |
175 | |
176 | case TARGET_EXPR: | |
df5c89cb | 177 | return clk_class; |
69851283 | 178 | |
356955cf | 179 | case VA_ARG_EXPR: |
df5c89cb | 180 | return (CLASS_TYPE_P (TREE_TYPE (ref)) ? clk_class : clk_none); |
c0ad5a31 MM |
181 | |
182 | case CALL_EXPR: | |
4e8dca1c JM |
183 | /* Any class-valued call would be wrapped in a TARGET_EXPR. */ |
184 | return clk_none; | |
69851283 MM |
185 | |
186 | case FUNCTION_DECL: | |
187 | /* All functions (except non-static-member functions) are | |
188 | lvalues. */ | |
9f63daea | 189 | return (DECL_NONSTATIC_MEMBER_FUNCTION_P (ref) |
27b8d0cd | 190 | ? clk_none : clk_ordinary); |
7f85441b | 191 | |
4af9e878 JM |
192 | case BASELINK: |
193 | /* We now represent a reference to a single static member function | |
194 | with a BASELINK. */ | |
1e4ae551 MLI |
195 | /* This CONST_CAST is okay because BASELINK_FUNCTIONS returns |
196 | its argument unmodified and we assign it to a const_tree. */ | |
df5c89cb | 197 | return lvalue_p_1 (BASELINK_FUNCTIONS (CONST_CAST_TREE (ref))); |
4af9e878 | 198 | |
d17811fd MM |
199 | case NON_DEPENDENT_EXPR: |
200 | /* We must consider NON_DEPENDENT_EXPRs to be lvalues so that | |
201 | things like "&E" where "E" is an expression with a | |
202 | non-dependent type work. It is safe to be lenient because an | |
203 | error will be issued when the template is instantiated if "E" | |
204 | is not an lvalue. */ | |
205 | return clk_ordinary; | |
206 | ||
7f85441b KG |
207 | default: |
208 | break; | |
8ccc31eb MS |
209 | } |
210 | ||
27b8d0cd MM |
211 | /* If one operand is not an lvalue at all, then this expression is |
212 | not an lvalue. */ | |
213 | if (!op1_lvalue_kind || !op2_lvalue_kind) | |
214 | return clk_none; | |
215 | ||
216 | /* Otherwise, it's an lvalue, and it has all the odd properties | |
217 | contributed by either operand. */ | |
218 | op1_lvalue_kind = op1_lvalue_kind | op2_lvalue_kind; | |
9771799c | 219 | /* It's not an ordinary lvalue if it involves any other kind. */ |
27b8d0cd MM |
220 | if ((op1_lvalue_kind & ~clk_ordinary) != clk_none) |
221 | op1_lvalue_kind &= ~clk_ordinary; | |
9771799c JM |
222 | /* It can't be both a pseudo-lvalue and a non-addressable lvalue. |
223 | A COND_EXPR of those should be wrapped in a TARGET_EXPR. */ | |
224 | if ((op1_lvalue_kind & (clk_rvalueref|clk_class)) | |
225 | && (op1_lvalue_kind & (clk_bitfield|clk_packed))) | |
226 | op1_lvalue_kind = clk_none; | |
27b8d0cd | 227 | return op1_lvalue_kind; |
8ccc31eb MS |
228 | } |
229 | ||
aa6e8ed3 MM |
230 | /* Returns the kind of lvalue that REF is, in the sense of |
231 | [basic.lval]. This function should really be named lvalue_p; it | |
232 | computes the C++ definition of lvalue. */ | |
233 | ||
234 | cp_lvalue_kind | |
4af9e878 | 235 | real_lvalue_p (tree ref) |
aa6e8ed3 | 236 | { |
df5c89cb JM |
237 | cp_lvalue_kind kind = lvalue_p_1 (ref); |
238 | if (kind & (clk_rvalueref|clk_class)) | |
239 | return clk_none; | |
240 | else | |
241 | return kind; | |
aa6e8ed3 MM |
242 | } |
243 | ||
df5c89cb JM |
244 | /* This differs from real_lvalue_p in that class rvalues are considered |
245 | lvalues. */ | |
69851283 | 246 | |
1e4ae551 MLI |
247 | bool |
248 | lvalue_p (const_tree ref) | |
8d08fdba | 249 | { |
df5c89cb JM |
250 | return (lvalue_p_1 (ref) != clk_none); |
251 | } | |
252 | ||
253 | /* This differs from real_lvalue_p in that rvalues formed by dereferencing | |
254 | rvalue references are considered rvalues. */ | |
255 | ||
256 | bool | |
257 | lvalue_or_rvalue_with_address_p (const_tree ref) | |
258 | { | |
259 | cp_lvalue_kind kind = lvalue_p_1 (ref); | |
260 | if (kind & clk_class) | |
261 | return false; | |
262 | else | |
263 | return (kind != clk_none); | |
6c6e776d MA |
264 | } |
265 | ||
100d337a MA |
266 | /* Test whether DECL is a builtin that may appear in a |
267 | constant-expression. */ | |
268 | ||
269 | bool | |
58f9752a | 270 | builtin_valid_in_constant_expr_p (const_tree decl) |
100d337a MA |
271 | { |
272 | /* At present BUILT_IN_CONSTANT_P is the only builtin we're allowing | |
273 | in constant-expressions. We may want to add other builtins later. */ | |
88a7beb7 | 274 | return DECL_IS_BUILTIN_CONSTANT_P (decl); |
100d337a MA |
275 | } |
276 | ||
c506ca22 MM |
277 | /* Build a TARGET_EXPR, initializing the DECL with the VALUE. */ |
278 | ||
279 | static tree | |
b57b79f7 | 280 | build_target_expr (tree decl, tree value) |
c506ca22 MM |
281 | { |
282 | tree t; | |
04941f76 AO |
283 | |
284 | #ifdef ENABLE_CHECKING | |
285 | gcc_assert (VOID_TYPE_P (TREE_TYPE (value)) | |
286 | || TREE_TYPE (decl) == TREE_TYPE (value) | |
287 | || useless_type_conversion_p (TREE_TYPE (decl), | |
288 | TREE_TYPE (value))); | |
289 | #endif | |
c506ca22 | 290 | |
f293ce4b RS |
291 | t = build4 (TARGET_EXPR, TREE_TYPE (decl), decl, value, |
292 | cxx_maybe_build_cleanup (decl), NULL_TREE); | |
c506ca22 MM |
293 | /* We always set TREE_SIDE_EFFECTS so that expand_expr does not |
294 | ignore the TARGET_EXPR. If there really turn out to be no | |
295 | side-effects, then the optimizer should be able to get rid of | |
296 | whatever code is generated anyhow. */ | |
297 | TREE_SIDE_EFFECTS (t) = 1; | |
298 | ||
299 | return t; | |
300 | } | |
301 | ||
a6f86b51 JM |
302 | /* Return an undeclared local temporary of type TYPE for use in building a |
303 | TARGET_EXPR. */ | |
304 | ||
305 | static tree | |
306 | build_local_temp (tree type) | |
307 | { | |
c2255bc4 AH |
308 | tree slot = build_decl (input_location, |
309 | VAR_DECL, NULL_TREE, type); | |
a6f86b51 | 310 | DECL_ARTIFICIAL (slot) = 1; |
78e0d62b | 311 | DECL_IGNORED_P (slot) = 1; |
a6f86b51 JM |
312 | DECL_CONTEXT (slot) = current_function_decl; |
313 | layout_decl (slot, 0); | |
314 | return slot; | |
315 | } | |
316 | ||
5039610b SL |
317 | /* Set various status flags when building an AGGR_INIT_EXPR object T. */ |
318 | ||
319 | static void | |
320 | process_aggr_init_operands (tree t) | |
321 | { | |
322 | bool side_effects; | |
323 | ||
324 | side_effects = TREE_SIDE_EFFECTS (t); | |
325 | if (!side_effects) | |
326 | { | |
327 | int i, n; | |
328 | n = TREE_OPERAND_LENGTH (t); | |
329 | for (i = 1; i < n; i++) | |
330 | { | |
331 | tree op = TREE_OPERAND (t, i); | |
332 | if (op && TREE_SIDE_EFFECTS (op)) | |
333 | { | |
334 | side_effects = 1; | |
335 | break; | |
336 | } | |
337 | } | |
338 | } | |
339 | TREE_SIDE_EFFECTS (t) = side_effects; | |
340 | } | |
341 | ||
342 | /* Build an AGGR_INIT_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE, | |
343 | FN, and SLOT. NARGS is the number of call arguments which are specified | |
344 | as a tree array ARGS. */ | |
345 | ||
346 | static tree | |
347 | build_aggr_init_array (tree return_type, tree fn, tree slot, int nargs, | |
348 | tree *args) | |
349 | { | |
350 | tree t; | |
351 | int i; | |
352 | ||
353 | t = build_vl_exp (AGGR_INIT_EXPR, nargs + 3); | |
354 | TREE_TYPE (t) = return_type; | |
355 | AGGR_INIT_EXPR_FN (t) = fn; | |
356 | AGGR_INIT_EXPR_SLOT (t) = slot; | |
357 | for (i = 0; i < nargs; i++) | |
358 | AGGR_INIT_EXPR_ARG (t, i) = args[i]; | |
359 | process_aggr_init_operands (t); | |
360 | return t; | |
361 | } | |
362 | ||
363 | /* INIT is a CALL_EXPR or AGGR_INIT_EXPR which needs info about its | |
844ae01d | 364 | target. TYPE is the type to be initialized. |
8d08fdba | 365 | |
844ae01d JM |
366 | Build an AGGR_INIT_EXPR to represent the initialization. This function |
367 | differs from build_cplus_new in that an AGGR_INIT_EXPR can only be used | |
368 | to initialize another object, whereas a TARGET_EXPR can either | |
369 | initialize another object or create its own temporary object, and as a | |
370 | result building up a TARGET_EXPR requires that the type's destructor be | |
371 | callable. */ | |
e92cc029 | 372 | |
8d08fdba | 373 | tree |
844ae01d | 374 | build_aggr_init_expr (tree type, tree init) |
8d08fdba | 375 | { |
e1376b00 | 376 | tree fn; |
e8abc66f MS |
377 | tree slot; |
378 | tree rval; | |
4977bab6 | 379 | int is_ctor; |
e8abc66f | 380 | |
27b8d0cd MM |
381 | /* Make sure that we're not trying to create an instance of an |
382 | abstract class. */ | |
5bb2f1e7 | 383 | abstract_virtuals_error (NULL_TREE, type); |
27b8d0cd | 384 | |
5039610b SL |
385 | if (TREE_CODE (init) == CALL_EXPR) |
386 | fn = CALL_EXPR_FN (init); | |
387 | else if (TREE_CODE (init) == AGGR_INIT_EXPR) | |
388 | fn = AGGR_INIT_EXPR_FN (init); | |
389 | else | |
06126ca2 | 390 | return convert (type, init); |
c11b6f21 | 391 | |
4977bab6 ZW |
392 | is_ctor = (TREE_CODE (fn) == ADDR_EXPR |
393 | && TREE_CODE (TREE_OPERAND (fn, 0)) == FUNCTION_DECL | |
394 | && DECL_CONSTRUCTOR_P (TREE_OPERAND (fn, 0))); | |
395 | ||
e1376b00 MM |
396 | /* We split the CALL_EXPR into its function and its arguments here. |
397 | Then, in expand_expr, we put them back together. The reason for | |
398 | this is that this expression might be a default argument | |
399 | expression. In that case, we need a new temporary every time the | |
400 | expression is used. That's what break_out_target_exprs does; it | |
401 | replaces every AGGR_INIT_EXPR with a copy that uses a fresh | |
402 | temporary slot. Then, expand_expr builds up a call-expression | |
403 | using the new slot. */ | |
4977bab6 ZW |
404 | |
405 | /* If we don't need to use a constructor to create an object of this | |
406 | type, don't mess with AGGR_INIT_EXPR. */ | |
407 | if (is_ctor || TREE_ADDRESSABLE (type)) | |
408 | { | |
844ae01d JM |
409 | slot = build_local_temp (type); |
410 | ||
5039610b SL |
411 | if (TREE_CODE(init) == CALL_EXPR) |
412 | rval = build_aggr_init_array (void_type_node, fn, slot, | |
413 | call_expr_nargs (init), | |
414 | CALL_EXPR_ARGP (init)); | |
415 | else | |
416 | rval = build_aggr_init_array (void_type_node, fn, slot, | |
417 | aggr_init_expr_nargs (init), | |
418 | AGGR_INIT_EXPR_ARGP (init)); | |
4977bab6 ZW |
419 | TREE_SIDE_EFFECTS (rval) = 1; |
420 | AGGR_INIT_VIA_CTOR_P (rval) = is_ctor; | |
d8a0d13e | 421 | TREE_NOTHROW (rval) = TREE_NOTHROW (init); |
4977bab6 ZW |
422 | } |
423 | else | |
424 | rval = init; | |
425 | ||
844ae01d JM |
426 | return rval; |
427 | } | |
428 | ||
429 | /* INIT is a CALL_EXPR or AGGR_INIT_EXPR which needs info about its | |
430 | target. TYPE is the type that this initialization should appear to | |
431 | have. | |
432 | ||
433 | Build an encapsulation of the initialization to perform | |
434 | and return it so that it can be processed by language-independent | |
435 | and language-specific expression expanders. */ | |
436 | ||
437 | tree | |
438 | build_cplus_new (tree type, tree init) | |
439 | { | |
440 | tree rval = build_aggr_init_expr (type, init); | |
441 | tree slot; | |
442 | ||
443 | if (TREE_CODE (rval) == AGGR_INIT_EXPR) | |
444 | slot = AGGR_INIT_EXPR_SLOT (rval); | |
445 | else if (TREE_CODE (rval) == CALL_EXPR) | |
446 | slot = build_local_temp (type); | |
447 | else | |
448 | return rval; | |
449 | ||
9d85d30c | 450 | rval = build_target_expr (slot, rval); |
c08cd4c1 | 451 | TARGET_EXPR_IMPLICIT_P (rval) = 1; |
8d08fdba | 452 | |
8d08fdba MS |
453 | return rval; |
454 | } | |
455 | ||
d5f4eddd JM |
456 | /* Return a TARGET_EXPR which expresses the direct-initialization of one |
457 | array from another. */ | |
458 | ||
459 | tree | |
460 | build_array_copy (tree init) | |
461 | { | |
462 | tree type = TREE_TYPE (init); | |
463 | tree slot = build_local_temp (type); | |
464 | init = build2 (VEC_INIT_EXPR, type, slot, init); | |
465 | SET_EXPR_LOCATION (init, input_location); | |
466 | init = build_target_expr (slot, init); | |
467 | TARGET_EXPR_IMPLICIT_P (init) = 1; | |
468 | ||
469 | return init; | |
470 | } | |
471 | ||
ab93b543 | 472 | /* Build a TARGET_EXPR using INIT to initialize a new temporary of the |
c506ca22 | 473 | indicated TYPE. */ |
aa36c081 JM |
474 | |
475 | tree | |
b57b79f7 | 476 | build_target_expr_with_type (tree init, tree type) |
aa36c081 | 477 | { |
50bc768d | 478 | gcc_assert (!VOID_TYPE_P (type)); |
59445d74 | 479 | |
309714d4 JM |
480 | if (TREE_CODE (init) == TARGET_EXPR |
481 | || init == error_mark_node) | |
5062dbd5 | 482 | return init; |
d758e847 | 483 | else if (CLASS_TYPE_P (type) && type_has_nontrivial_copy_init (type) |
7efc22ea | 484 | && !VOID_TYPE_P (TREE_TYPE (init)) |
4b5aa881 | 485 | && TREE_CODE (init) != COND_EXPR |
662eceda MM |
486 | && TREE_CODE (init) != CONSTRUCTOR |
487 | && TREE_CODE (init) != VA_ARG_EXPR) | |
7efc22ea JM |
488 | /* We need to build up a copy constructor call. A void initializer |
489 | means we're being called from bot_manip. COND_EXPR is a special | |
182609b5 | 490 | case because we already have copies on the arms and we don't want |
4b5aa881 | 491 | another one here. A CONSTRUCTOR is aggregate initialization, which |
662eceda MM |
492 | is handled separately. A VA_ARG_EXPR is magic creation of an |
493 | aggregate; there's no additional work to be done. */ | |
182609b5 | 494 | return force_rvalue (init); |
5062dbd5 | 495 | |
357d956e | 496 | return force_target_expr (type, init); |
a6f86b51 | 497 | } |
aa36c081 | 498 | |
a6f86b51 JM |
499 | /* Like the above function, but without the checking. This function should |
500 | only be used by code which is deliberately trying to subvert the type | |
d758e847 JM |
501 | system, such as call_builtin_trap. Or build_over_call, to avoid |
502 | infinite recursion. */ | |
a6f86b51 JM |
503 | |
504 | tree | |
505 | force_target_expr (tree type, tree init) | |
506 | { | |
59445d74 RH |
507 | tree slot; |
508 | ||
50bc768d | 509 | gcc_assert (!VOID_TYPE_P (type)); |
59445d74 RH |
510 | |
511 | slot = build_local_temp (type); | |
a6f86b51 | 512 | return build_target_expr (slot, init); |
aa36c081 JM |
513 | } |
514 | ||
c506ca22 MM |
515 | /* Like build_target_expr_with_type, but use the type of INIT. */ |
516 | ||
517 | tree | |
b57b79f7 | 518 | get_target_expr (tree init) |
c506ca22 | 519 | { |
450a927a JM |
520 | if (TREE_CODE (init) == AGGR_INIT_EXPR) |
521 | return build_target_expr (AGGR_INIT_EXPR_SLOT (init), init); | |
522 | else | |
523 | return build_target_expr_with_type (init, TREE_TYPE (init)); | |
c506ca22 MM |
524 | } |
525 | ||
e1039697 MM |
526 | /* If EXPR is a bitfield reference, convert it to the declared type of |
527 | the bitfield, and return the resulting expression. Otherwise, | |
528 | return EXPR itself. */ | |
529 | ||
530 | tree | |
531 | convert_bitfield_to_declared_type (tree expr) | |
532 | { | |
533 | tree bitfield_type; | |
534 | ||
535 | bitfield_type = is_bitfield_expr_with_lowered_type (expr); | |
536 | if (bitfield_type) | |
41990f96 MM |
537 | expr = convert_to_integer (TYPE_MAIN_VARIANT (bitfield_type), |
538 | expr); | |
e1039697 MM |
539 | return expr; |
540 | } | |
541 | ||
5cc53d4e MM |
542 | /* EXPR is being used in an rvalue context. Return a version of EXPR |
543 | that is marked as an rvalue. */ | |
544 | ||
545 | tree | |
546 | rvalue (tree expr) | |
547 | { | |
41990f96 MM |
548 | tree type; |
549 | ||
550 | if (error_operand_p (expr)) | |
551 | return expr; | |
552 | ||
03a904b5 JJ |
553 | expr = mark_rvalue_use (expr); |
554 | ||
41990f96 MM |
555 | /* [basic.lval] |
556 | ||
557 | Non-class rvalues always have cv-unqualified types. */ | |
558 | type = TREE_TYPE (expr); | |
36c37128 JM |
559 | if (!CLASS_TYPE_P (type) && cv_qualified_p (type)) |
560 | type = cv_unqualified (type); | |
41990f96 | 561 | |
b9c6b842 JM |
562 | /* We need to do this for rvalue refs as well to get the right answer |
563 | from decltype; see c++/36628. */ | |
564 | if (!processing_template_decl && lvalue_or_rvalue_with_address_p (expr)) | |
41990f96 MM |
565 | expr = build1 (NON_LVALUE_EXPR, type, expr); |
566 | else if (type != TREE_TYPE (expr)) | |
567 | expr = build_nop (type, expr); | |
568 | ||
5cc53d4e MM |
569 | return expr; |
570 | } | |
571 | ||
8d08fdba | 572 | \f |
06d40de8 DG |
573 | /* Hash an ARRAY_TYPE. K is really of type `tree'. */ |
574 | ||
575 | static hashval_t | |
576 | cplus_array_hash (const void* k) | |
577 | { | |
578 | hashval_t hash; | |
741ac903 | 579 | const_tree const t = (const_tree) k; |
06d40de8 | 580 | |
eb9c434c JJ |
581 | hash = TYPE_UID (TREE_TYPE (t)); |
582 | if (TYPE_DOMAIN (t)) | |
583 | hash ^= TYPE_UID (TYPE_DOMAIN (t)); | |
06d40de8 DG |
584 | return hash; |
585 | } | |
586 | ||
587 | typedef struct cplus_array_info { | |
588 | tree type; | |
589 | tree domain; | |
590 | } cplus_array_info; | |
591 | ||
592 | /* Compare two ARRAY_TYPEs. K1 is really of type `tree', K2 is really | |
593 | of type `cplus_array_info*'. */ | |
594 | ||
595 | static int | |
596 | cplus_array_compare (const void * k1, const void * k2) | |
597 | { | |
741ac903 KG |
598 | const_tree const t1 = (const_tree) k1; |
599 | const cplus_array_info *const t2 = (const cplus_array_info*) k2; | |
06d40de8 | 600 | |
714f2304 | 601 | return (TREE_TYPE (t1) == t2->type && TYPE_DOMAIN (t1) == t2->domain); |
06d40de8 DG |
602 | } |
603 | ||
38e40fcd JM |
604 | /* Hash table containing dependent array types, which are unsuitable for |
605 | the language-independent type hash table. */ | |
06d40de8 DG |
606 | static GTY ((param_is (union tree_node))) htab_t cplus_array_htab; |
607 | ||
38e40fcd | 608 | /* Like build_array_type, but handle special C++ semantics. */ |
06d40de8 | 609 | |
38e40fcd JM |
610 | tree |
611 | build_cplus_array_type (tree elt_type, tree index_type) | |
8d08fdba | 612 | { |
8d08fdba MS |
613 | tree t; |
614 | ||
adecb3f4 MM |
615 | if (elt_type == error_mark_node || index_type == error_mark_node) |
616 | return error_mark_node; | |
617 | ||
6da06848 JJ |
618 | if (processing_template_decl |
619 | && (dependent_type_p (elt_type) | |
620 | || (index_type && !TREE_CONSTANT (TYPE_MAX_VALUE (index_type))))) | |
5566b478 | 621 | { |
06d40de8 DG |
622 | void **e; |
623 | cplus_array_info cai; | |
624 | hashval_t hash; | |
714f2304 | 625 | |
06d40de8 DG |
626 | if (cplus_array_htab == NULL) |
627 | cplus_array_htab = htab_create_ggc (61, &cplus_array_hash, | |
628 | &cplus_array_compare, NULL); | |
629 | ||
eb9c434c JJ |
630 | hash = TYPE_UID (elt_type); |
631 | if (index_type) | |
632 | hash ^= TYPE_UID (index_type); | |
06d40de8 DG |
633 | cai.type = elt_type; |
634 | cai.domain = index_type; | |
635 | ||
636 | e = htab_find_slot_with_hash (cplus_array_htab, &cai, hash, INSERT); | |
637 | if (*e) | |
714f2304 | 638 | /* We have found the type: we're done. */ |
06d40de8 DG |
639 | return (tree) *e; |
640 | else | |
641 | { | |
714f2304 | 642 | /* Build a new array type. */ |
7ecbca9d | 643 | t = cxx_make_type (ARRAY_TYPE); |
06d40de8 DG |
644 | TREE_TYPE (t) = elt_type; |
645 | TYPE_DOMAIN (t) = index_type; | |
646 | ||
714f2304 DG |
647 | /* Store it in the hash table. */ |
648 | *e = t; | |
649 | ||
650 | /* Set the canonical type for this new node. */ | |
06d40de8 DG |
651 | if (TYPE_STRUCTURAL_EQUALITY_P (elt_type) |
652 | || (index_type && TYPE_STRUCTURAL_EQUALITY_P (index_type))) | |
653 | SET_TYPE_STRUCTURAL_EQUALITY (t); | |
654 | else if (TYPE_CANONICAL (elt_type) != elt_type | |
655 | || (index_type | |
656 | && TYPE_CANONICAL (index_type) != index_type)) | |
714f2304 DG |
657 | TYPE_CANONICAL (t) |
658 | = build_cplus_array_type | |
659 | (TYPE_CANONICAL (elt_type), | |
6da06848 | 660 | index_type ? TYPE_CANONICAL (index_type) : index_type); |
714f2304 DG |
661 | else |
662 | TYPE_CANONICAL (t) = t; | |
06d40de8 | 663 | } |
5566b478 MS |
664 | } |
665 | else | |
80661759 | 666 | t = build_array_type (elt_type, index_type); |
8d08fdba | 667 | |
38e40fcd JM |
668 | /* We want TYPE_MAIN_VARIANT of an array to strip cv-quals from the |
669 | element type as well, so fix it up if needed. */ | |
670 | if (elt_type != TYPE_MAIN_VARIANT (elt_type)) | |
671 | { | |
672 | tree m = build_cplus_array_type (TYPE_MAIN_VARIANT (elt_type), | |
673 | index_type); | |
674 | if (TYPE_MAIN_VARIANT (t) != m) | |
675 | { | |
676 | TYPE_MAIN_VARIANT (t) = m; | |
677 | TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (m); | |
678 | TYPE_NEXT_VARIANT (m) = t; | |
679 | } | |
680 | } | |
681 | ||
8d08fdba MS |
682 | /* Push these needs up so that initialization takes place |
683 | more easily. */ | |
9f63daea | 684 | TYPE_NEEDS_CONSTRUCTING (t) |
db3626d1 | 685 | = TYPE_NEEDS_CONSTRUCTING (TYPE_MAIN_VARIANT (elt_type)); |
9f63daea | 686 | TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t) |
834c6dff | 687 | = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TYPE_MAIN_VARIANT (elt_type)); |
8d08fdba MS |
688 | return t; |
689 | } | |
e349ee73 | 690 | |
09357846 JM |
691 | /* Return an ARRAY_TYPE with element type ELT and length N. */ |
692 | ||
693 | tree | |
694 | build_array_of_n_type (tree elt, int n) | |
695 | { | |
696 | return build_cplus_array_type (elt, build_index_type (size_int (n - 1))); | |
697 | } | |
698 | ||
8af2fec4 RY |
699 | /* Return a reference type node referring to TO_TYPE. If RVAL is |
700 | true, return an rvalue reference type, otherwise return an lvalue | |
701 | reference type. If a type node exists, reuse it, otherwise create | |
702 | a new one. */ | |
703 | tree | |
704 | cp_build_reference_type (tree to_type, bool rval) | |
705 | { | |
706 | tree lvalue_ref, t; | |
707 | lvalue_ref = build_reference_type (to_type); | |
708 | if (!rval) | |
709 | return lvalue_ref; | |
710 | ||
711 | /* This code to create rvalue reference types is based on and tied | |
712 | to the code creating lvalue reference types in the middle-end | |
713 | functions build_reference_type_for_mode and build_reference_type. | |
714 | ||
715 | It works by putting the rvalue reference type nodes after the | |
716 | lvalue reference nodes in the TYPE_NEXT_REF_TO linked list, so | |
717 | they will effectively be ignored by the middle end. */ | |
718 | ||
719 | for (t = lvalue_ref; (t = TYPE_NEXT_REF_TO (t)); ) | |
720 | if (TYPE_REF_IS_RVALUE (t)) | |
721 | return t; | |
722 | ||
22521c89 | 723 | t = build_distinct_type_copy (lvalue_ref); |
8af2fec4 RY |
724 | |
725 | TYPE_REF_IS_RVALUE (t) = true; | |
726 | TYPE_NEXT_REF_TO (t) = TYPE_NEXT_REF_TO (lvalue_ref); | |
727 | TYPE_NEXT_REF_TO (lvalue_ref) = t; | |
8af2fec4 RY |
728 | |
729 | if (TYPE_STRUCTURAL_EQUALITY_P (to_type)) | |
730 | SET_TYPE_STRUCTURAL_EQUALITY (t); | |
731 | else if (TYPE_CANONICAL (to_type) != to_type) | |
732 | TYPE_CANONICAL (t) | |
733 | = cp_build_reference_type (TYPE_CANONICAL (to_type), rval); | |
734 | else | |
735 | TYPE_CANONICAL (t) = t; | |
736 | ||
737 | layout_type (t); | |
738 | ||
739 | return t; | |
740 | ||
741 | } | |
742 | ||
d5f4eddd JM |
743 | /* Returns EXPR cast to rvalue reference type, like std::move. */ |
744 | ||
745 | tree | |
746 | move (tree expr) | |
747 | { | |
748 | tree type = TREE_TYPE (expr); | |
749 | gcc_assert (TREE_CODE (type) != REFERENCE_TYPE); | |
750 | type = cp_build_reference_type (type, /*rval*/true); | |
751 | return build_static_cast (type, expr, tf_warning_or_error); | |
752 | } | |
753 | ||
9ae165a0 DG |
754 | /* Used by the C++ front end to build qualified array types. However, |
755 | the C version of this function does not properly maintain canonical | |
756 | types (which are not used in C). */ | |
757 | tree | |
758 | c_build_qualified_type (tree type, int type_quals) | |
759 | { | |
760 | return cp_build_qualified_type (type, type_quals); | |
761 | } | |
8af2fec4 | 762 | |
8d08fdba | 763 | \f |
adecb3f4 MM |
764 | /* Make a variant of TYPE, qualified with the TYPE_QUALS. Handles |
765 | arrays correctly. In particular, if TYPE is an array of T's, and | |
c2ea3a40 | 766 | TYPE_QUALS is non-empty, returns an array of qualified T's. |
9f63daea | 767 | |
39a13be5 | 768 | FLAGS determines how to deal with ill-formed qualifications. If |
4f2b0fb2 NS |
769 | tf_ignore_bad_quals is set, then bad qualifications are dropped |
770 | (this is permitted if TYPE was introduced via a typedef or template | |
771 | type parameter). If bad qualifications are dropped and tf_warning | |
772 | is set, then a warning is issued for non-const qualifications. If | |
773 | tf_ignore_bad_quals is not set and tf_error is not set, we | |
774 | return error_mark_node. Otherwise, we issue an error, and ignore | |
775 | the qualifications. | |
776 | ||
777 | Qualification of a reference type is valid when the reference came | |
778 | via a typedef or template type argument. [dcl.ref] No such | |
779 | dispensation is provided for qualifying a function type. [dcl.fct] | |
780 | DR 295 queries this and the proposed resolution brings it into line | |
34cd5ae7 | 781 | with qualifying a reference. We implement the DR. We also behave |
4f2b0fb2 | 782 | in a similar manner for restricting non-pointer types. */ |
9f63daea | 783 | |
f376e137 | 784 | tree |
9f63daea | 785 | cp_build_qualified_type_real (tree type, |
0cbd7506 MS |
786 | int type_quals, |
787 | tsubst_flags_t complain) | |
f376e137 | 788 | { |
2adeacc9 | 789 | tree result; |
4f2b0fb2 | 790 | int bad_quals = TYPE_UNQUALIFIED; |
2adeacc9 | 791 | |
e76a2646 MS |
792 | if (type == error_mark_node) |
793 | return type; | |
e271912d | 794 | |
89d684bb | 795 | if (type_quals == cp_type_quals (type)) |
e271912d JM |
796 | return type; |
797 | ||
4f2b0fb2 | 798 | if (TREE_CODE (type) == ARRAY_TYPE) |
f376e137 | 799 | { |
db3626d1 MM |
800 | /* In C++, the qualification really applies to the array element |
801 | type. Obtain the appropriately qualified element type. */ | |
802 | tree t; | |
9f63daea EC |
803 | tree element_type |
804 | = cp_build_qualified_type_real (TREE_TYPE (type), | |
db3626d1 MM |
805 | type_quals, |
806 | complain); | |
807 | ||
808 | if (element_type == error_mark_node) | |
adecb3f4 | 809 | return error_mark_node; |
f376e137 | 810 | |
38e40fcd JM |
811 | /* See if we already have an identically qualified type. Tests |
812 | should be equivalent to those in check_qualified_type. */ | |
29fae15c | 813 | for (t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t)) |
9f63daea | 814 | if (cp_type_quals (t) == type_quals |
29fae15c | 815 | && TYPE_NAME (t) == TYPE_NAME (type) |
38e40fcd JM |
816 | && TYPE_CONTEXT (t) == TYPE_CONTEXT (type) |
817 | && attribute_list_equal (TYPE_ATTRIBUTES (t), | |
818 | TYPE_ATTRIBUTES (type))) | |
29fae15c | 819 | break; |
9f63daea | 820 | |
29fae15c | 821 | if (!t) |
38e40fcd JM |
822 | { |
823 | t = build_cplus_array_type (element_type, TYPE_DOMAIN (type)); | |
824 | ||
825 | /* Keep the typedef name. */ | |
826 | if (TYPE_NAME (t) != TYPE_NAME (type)) | |
827 | { | |
828 | t = build_variant_type_copy (t); | |
829 | TYPE_NAME (t) = TYPE_NAME (type); | |
830 | } | |
831 | } | |
f376e137 | 832 | |
db3626d1 | 833 | /* Even if we already had this variant, we update |
834c6dff | 834 | TYPE_NEEDS_CONSTRUCTING and TYPE_HAS_NONTRIVIAL_DESTRUCTOR in case |
9f63daea EC |
835 | they changed since the variant was originally created. |
836 | ||
db3626d1 MM |
837 | This seems hokey; if there is some way to use a previous |
838 | variant *without* coming through here, | |
839 | TYPE_NEEDS_CONSTRUCTING will never be updated. */ | |
9f63daea | 840 | TYPE_NEEDS_CONSTRUCTING (t) |
db3626d1 | 841 | = TYPE_NEEDS_CONSTRUCTING (TYPE_MAIN_VARIANT (element_type)); |
9f63daea | 842 | TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t) |
834c6dff | 843 | = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TYPE_MAIN_VARIANT (element_type)); |
db3626d1 | 844 | return t; |
f376e137 | 845 | } |
2adeacc9 MM |
846 | else if (TYPE_PTRMEMFUNC_P (type)) |
847 | { | |
848 | /* For a pointer-to-member type, we can't just return a | |
849 | cv-qualified version of the RECORD_TYPE. If we do, we | |
4f2b0fb2 | 850 | haven't changed the field that contains the actual pointer to |
2adeacc9 MM |
851 | a method, and so TYPE_PTRMEMFUNC_FN_TYPE will be wrong. */ |
852 | tree t; | |
853 | ||
854 | t = TYPE_PTRMEMFUNC_FN_TYPE (type); | |
855 | t = cp_build_qualified_type_real (t, type_quals, complain); | |
46cbda4a | 856 | return build_ptrmemfunc_type (t); |
2adeacc9 | 857 | } |
9a3c2683 JJ |
858 | else if (TREE_CODE (type) == TYPE_PACK_EXPANSION) |
859 | { | |
860 | tree t = PACK_EXPANSION_PATTERN (type); | |
861 | ||
862 | t = cp_build_qualified_type_real (t, type_quals, complain); | |
863 | return make_pack_expansion (t); | |
864 | } | |
9f63daea | 865 | |
39a13be5 | 866 | /* A reference or method type shall not be cv-qualified. |
93e1ddcf JM |
867 | [dcl.ref], [dcl.fct]. This used to be an error, but as of DR 295 |
868 | (in CD1) we always ignore extra cv-quals on functions. */ | |
4b011bbf JM |
869 | if (type_quals & (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE) |
870 | && (TREE_CODE (type) == REFERENCE_TYPE | |
2872152c | 871 | || TREE_CODE (type) == FUNCTION_TYPE |
4b011bbf JM |
872 | || TREE_CODE (type) == METHOD_TYPE)) |
873 | { | |
93e1ddcf JM |
874 | if (TREE_CODE (type) == REFERENCE_TYPE) |
875 | bad_quals |= type_quals & (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE); | |
4b011bbf JM |
876 | type_quals &= ~(TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE); |
877 | } | |
9f63daea | 878 | |
2872152c JM |
879 | /* But preserve any function-cv-quals on a FUNCTION_TYPE. */ |
880 | if (TREE_CODE (type) == FUNCTION_TYPE) | |
881 | type_quals |= type_memfn_quals (type); | |
882 | ||
4b011bbf | 883 | /* A restrict-qualified type must be a pointer (or reference) |
0d9c0892 | 884 | to object or incomplete type. */ |
4b011bbf JM |
885 | if ((type_quals & TYPE_QUAL_RESTRICT) |
886 | && TREE_CODE (type) != TEMPLATE_TYPE_PARM | |
887 | && TREE_CODE (type) != TYPENAME_TYPE | |
888 | && !POINTER_TYPE_P (type)) | |
889 | { | |
890 | bad_quals |= TYPE_QUAL_RESTRICT; | |
891 | type_quals &= ~TYPE_QUAL_RESTRICT; | |
892 | } | |
893 | ||
93e1ddcf JM |
894 | if (bad_quals == TYPE_UNQUALIFIED |
895 | || (complain & tf_ignore_bad_quals)) | |
4b011bbf | 896 | /*OK*/; |
93e1ddcf | 897 | else if (!(complain & tf_error)) |
4b011bbf | 898 | return error_mark_node; |
4b011bbf JM |
899 | else |
900 | { | |
93e1ddcf JM |
901 | tree bad_type = build_qualified_type (ptr_type_node, bad_quals); |
902 | error ("%qV qualifiers cannot be applied to %qT", | |
903 | bad_type, type); | |
4b011bbf | 904 | } |
9f63daea | 905 | |
2adeacc9 MM |
906 | /* Retrieve (or create) the appropriately qualified variant. */ |
907 | result = build_qualified_type (type, type_quals); | |
908 | ||
909 | /* If this was a pointer-to-method type, and we just made a copy, | |
3cfab7ec GK |
910 | then we need to unshare the record that holds the cached |
911 | pointer-to-member-function type, because these will be distinct | |
912 | between the unqualified and qualified types. */ | |
9f63daea | 913 | if (result != type |
2adeacc9 | 914 | && TREE_CODE (type) == POINTER_TYPE |
0f67bdf1 JM |
915 | && TREE_CODE (TREE_TYPE (type)) == METHOD_TYPE |
916 | && TYPE_LANG_SPECIFIC (result) == TYPE_LANG_SPECIFIC (type)) | |
3cfab7ec | 917 | TYPE_LANG_SPECIFIC (result) = NULL; |
2adeacc9 | 918 | |
7aa4a1df DG |
919 | /* We may also have ended up building a new copy of the canonical |
920 | type of a pointer-to-method type, which could have the same | |
921 | sharing problem described above. */ | |
922 | if (TYPE_CANONICAL (result) != TYPE_CANONICAL (type) | |
923 | && TREE_CODE (type) == POINTER_TYPE | |
924 | && TREE_CODE (TREE_TYPE (type)) == METHOD_TYPE | |
925 | && (TYPE_LANG_SPECIFIC (TYPE_CANONICAL (result)) | |
926 | == TYPE_LANG_SPECIFIC (TYPE_CANONICAL (type)))) | |
927 | TYPE_LANG_SPECIFIC (TYPE_CANONICAL (result)) = NULL; | |
7aa4a1df | 928 | |
2adeacc9 | 929 | return result; |
f376e137 | 930 | } |
53929c47 | 931 | |
164247b0 JM |
932 | /* Return TYPE with const and volatile removed. */ |
933 | ||
934 | tree | |
935 | cv_unqualified (tree type) | |
936 | { | |
ea8b8aa0 JM |
937 | int quals; |
938 | ||
939 | if (type == error_mark_node) | |
940 | return type; | |
941 | ||
a3360e77 | 942 | quals = cp_type_quals (type); |
164247b0 JM |
943 | quals &= ~(TYPE_QUAL_CONST|TYPE_QUAL_VOLATILE); |
944 | return cp_build_qualified_type (type, quals); | |
945 | } | |
946 | ||
cd41d410 DS |
947 | /* Builds a qualified variant of T that is not a typedef variant. |
948 | E.g. consider the following declarations: | |
949 | typedef const int ConstInt; | |
950 | typedef ConstInt* PtrConstInt; | |
951 | If T is PtrConstInt, this function returns a type representing | |
952 | const int*. | |
953 | In other words, if T is a typedef, the function returns the underlying type. | |
954 | The cv-qualification and attributes of the type returned match the | |
955 | input type. | |
956 | They will always be compatible types. | |
957 | The returned type is built so that all of its subtypes | |
958 | recursively have their typedefs stripped as well. | |
959 | ||
960 | This is different from just returning TYPE_CANONICAL (T) | |
961 | Because of several reasons: | |
962 | * If T is a type that needs structural equality | |
963 | its TYPE_CANONICAL (T) will be NULL. | |
964 | * TYPE_CANONICAL (T) desn't carry type attributes | |
965 | and looses template parameter names. */ | |
53929c47 JM |
966 | |
967 | tree | |
cd41d410 | 968 | strip_typedefs (tree t) |
53929c47 | 969 | { |
cd41d410 DS |
970 | tree result = NULL, type = NULL, t0 = NULL; |
971 | ||
972 | if (!t || t == error_mark_node || t == TYPE_CANONICAL (t)) | |
973 | return t; | |
974 | ||
975 | gcc_assert (TYPE_P (t)); | |
976 | ||
977 | switch (TREE_CODE (t)) | |
978 | { | |
979 | case POINTER_TYPE: | |
980 | type = strip_typedefs (TREE_TYPE (t)); | |
981 | result = build_pointer_type (type); | |
982 | break; | |
983 | case REFERENCE_TYPE: | |
984 | type = strip_typedefs (TREE_TYPE (t)); | |
985 | result = cp_build_reference_type (type, TYPE_REF_IS_RVALUE (t)); | |
986 | break; | |
987 | case OFFSET_TYPE: | |
988 | t0 = strip_typedefs (TYPE_OFFSET_BASETYPE (t)); | |
989 | type = strip_typedefs (TREE_TYPE (t)); | |
990 | result = build_offset_type (t0, type); | |
991 | break; | |
992 | case RECORD_TYPE: | |
993 | if (TYPE_PTRMEMFUNC_P (t)) | |
994 | { | |
995 | t0 = strip_typedefs (TYPE_PTRMEMFUNC_FN_TYPE (t)); | |
996 | result = build_ptrmemfunc_type (t0); | |
997 | } | |
998 | break; | |
999 | case ARRAY_TYPE: | |
1000 | type = strip_typedefs (TREE_TYPE (t)); | |
1001 | t0 = strip_typedefs (TYPE_DOMAIN (t));; | |
1002 | result = build_cplus_array_type (type, t0); | |
1003 | break; | |
1004 | case FUNCTION_TYPE: | |
1005 | case METHOD_TYPE: | |
1006 | { | |
1007 | tree arg_types = NULL, arg_node, arg_type; | |
1008 | for (arg_node = TYPE_ARG_TYPES (t); | |
1009 | arg_node; | |
1010 | arg_node = TREE_CHAIN (arg_node)) | |
1011 | { | |
1012 | if (arg_node == void_list_node) | |
1013 | break; | |
1014 | arg_type = strip_typedefs (TREE_VALUE (arg_node)); | |
1015 | gcc_assert (arg_type); | |
1016 | ||
1017 | arg_types = | |
1018 | tree_cons (TREE_PURPOSE (arg_node), arg_type, arg_types); | |
1019 | } | |
1020 | ||
1021 | if (arg_types) | |
1022 | arg_types = nreverse (arg_types); | |
1023 | ||
1024 | /* A list of parameters not ending with an ellipsis | |
1025 | must end with void_list_node. */ | |
1026 | if (arg_node) | |
1027 | arg_types = chainon (arg_types, void_list_node); | |
1028 | ||
1029 | type = strip_typedefs (TREE_TYPE (t)); | |
1030 | if (TREE_CODE (t) == METHOD_TYPE) | |
1031 | { | |
1032 | tree class_type = TREE_TYPE (TREE_VALUE (arg_types)); | |
1033 | gcc_assert (class_type); | |
1034 | result = | |
1035 | build_method_type_directly (class_type, type, | |
1036 | TREE_CHAIN (arg_types)); | |
1037 | } | |
1038 | else | |
2872152c | 1039 | { |
cd41d410 DS |
1040 | result = build_function_type (type, |
1041 | arg_types); | |
2872152c JM |
1042 | result = apply_memfn_quals (result, type_memfn_quals (t)); |
1043 | } | |
3c3905fc JM |
1044 | |
1045 | if (TYPE_RAISES_EXCEPTIONS (t)) | |
1046 | result = build_exception_variant (result, | |
1047 | TYPE_RAISES_EXCEPTIONS (t)); | |
cd41d410 DS |
1048 | } |
1049 | break; | |
1050 | default: | |
1051 | break; | |
1052 | } | |
1ad8aeeb | 1053 | |
cd41d410 DS |
1054 | if (!result) |
1055 | result = TYPE_MAIN_VARIANT (t); | |
3c3905fc JM |
1056 | if (TYPE_ATTRIBUTES (t)) |
1057 | result = cp_build_type_attribute_variant (result, TYPE_ATTRIBUTES (t)); | |
cd41d410 | 1058 | return cp_build_qualified_type (result, cp_type_quals (t)); |
53929c47 | 1059 | } |
cd41d410 | 1060 | |
9cf10655 DS |
1061 | /* Setup a TYPE_DECL node as a typedef representation. |
1062 | See comments of set_underlying_type in c-common.c. */ | |
1063 | ||
1064 | void | |
1065 | cp_set_underlying_type (tree t) | |
1066 | { | |
1067 | set_underlying_type (t); | |
e96ce650 DS |
1068 | /* If T is a template type parm, make it require structural equality. |
1069 | This is useful when comparing two template type parms, | |
9cf10655 | 1070 | because it forces the comparison of the template parameters of their |
e96ce650 DS |
1071 | decls. */ |
1072 | if (TREE_CODE (TREE_TYPE (t)) == TEMPLATE_TYPE_PARM) | |
9cf10655 DS |
1073 | SET_TYPE_STRUCTURAL_EQUALITY (TREE_TYPE (t)); |
1074 | } | |
1075 | ||
f376e137 | 1076 | \f |
48b45647 NS |
1077 | /* Makes a copy of BINFO and TYPE, which is to be inherited into a |
1078 | graph dominated by T. If BINFO is NULL, TYPE is a dependent base, | |
1079 | and we do a shallow copy. If BINFO is non-NULL, we do a deep copy. | |
1080 | VIRT indicates whether TYPE is inherited virtually or not. | |
1081 | IGO_PREV points at the previous binfo of the inheritance graph | |
1082 | order chain. The newly copied binfo's TREE_CHAIN forms this | |
1083 | ordering. | |
1084 | ||
1085 | The CLASSTYPE_VBASECLASSES vector of T is constructed in the | |
1086 | correct order. That is in the order the bases themselves should be | |
1087 | constructed in. | |
dbbf88d1 NS |
1088 | |
1089 | The BINFO_INHERITANCE of a virtual base class points to the binfo | |
48b45647 NS |
1090 | of the most derived type. ??? We could probably change this so that |
1091 | BINFO_INHERITANCE becomes synonymous with BINFO_PRIMARY, and hence | |
1092 | remove a field. They currently can only differ for primary virtual | |
1093 | virtual bases. */ | |
dbbf88d1 NS |
1094 | |
1095 | tree | |
48b45647 | 1096 | copy_binfo (tree binfo, tree type, tree t, tree *igo_prev, int virt) |
9a71c18b | 1097 | { |
48b45647 | 1098 | tree new_binfo; |
9a71c18b | 1099 | |
48b45647 NS |
1100 | if (virt) |
1101 | { | |
1102 | /* See if we've already made this virtual base. */ | |
1103 | new_binfo = binfo_for_vbase (type, t); | |
1104 | if (new_binfo) | |
1105 | return new_binfo; | |
1106 | } | |
9f63daea | 1107 | |
fa743e8c | 1108 | new_binfo = make_tree_binfo (binfo ? BINFO_N_BASE_BINFOS (binfo) : 0); |
48b45647 | 1109 | BINFO_TYPE (new_binfo) = type; |
9a71c18b | 1110 | |
48b45647 NS |
1111 | /* Chain it into the inheritance graph. */ |
1112 | TREE_CHAIN (*igo_prev) = new_binfo; | |
1113 | *igo_prev = new_binfo; | |
9f63daea | 1114 | |
48b45647 | 1115 | if (binfo) |
dfbcd65a | 1116 | { |
fa743e8c NS |
1117 | int ix; |
1118 | tree base_binfo; | |
9f63daea | 1119 | |
50bc768d | 1120 | gcc_assert (!BINFO_DEPENDENT_BASE_P (binfo)); |
539ed333 | 1121 | gcc_assert (SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), type)); |
9f63daea | 1122 | |
48b45647 NS |
1123 | BINFO_OFFSET (new_binfo) = BINFO_OFFSET (binfo); |
1124 | BINFO_VIRTUALS (new_binfo) = BINFO_VIRTUALS (binfo); | |
9f63daea | 1125 | |
fa743e8c NS |
1126 | /* We do not need to copy the accesses, as they are read only. */ |
1127 | BINFO_BASE_ACCESSES (new_binfo) = BINFO_BASE_ACCESSES (binfo); | |
9f63daea | 1128 | |
48b45647 | 1129 | /* Recursively copy base binfos of BINFO. */ |
fa743e8c | 1130 | for (ix = 0; BINFO_BASE_ITERATE (binfo, ix, base_binfo); ix++) |
dbbf88d1 | 1131 | { |
48b45647 | 1132 | tree new_base_binfo; |
9f63daea | 1133 | |
50bc768d | 1134 | gcc_assert (!BINFO_DEPENDENT_BASE_P (base_binfo)); |
48b45647 NS |
1135 | new_base_binfo = copy_binfo (base_binfo, BINFO_TYPE (base_binfo), |
1136 | t, igo_prev, | |
1137 | BINFO_VIRTUAL_P (base_binfo)); | |
9f63daea | 1138 | |
48b45647 NS |
1139 | if (!BINFO_INHERITANCE_CHAIN (new_base_binfo)) |
1140 | BINFO_INHERITANCE_CHAIN (new_base_binfo) = new_binfo; | |
fa743e8c | 1141 | BINFO_BASE_APPEND (new_binfo, new_base_binfo); |
dbbf88d1 | 1142 | } |
9a71c18b | 1143 | } |
48b45647 NS |
1144 | else |
1145 | BINFO_DEPENDENT_BASE_P (new_binfo) = 1; | |
9f63daea | 1146 | |
48b45647 NS |
1147 | if (virt) |
1148 | { | |
1149 | /* Push it onto the list after any virtual bases it contains | |
1150 | will have been pushed. */ | |
1151 | VEC_quick_push (tree, CLASSTYPE_VBASECLASSES (t), new_binfo); | |
1152 | BINFO_VIRTUAL_P (new_binfo) = 1; | |
1153 | BINFO_INHERITANCE_CHAIN (new_binfo) = TYPE_BINFO (t); | |
1154 | } | |
9f63daea | 1155 | |
48b45647 | 1156 | return new_binfo; |
9a71c18b | 1157 | } |
8d08fdba MS |
1158 | \f |
1159 | /* Hashing of lists so that we don't make duplicates. | |
1160 | The entry point is `list_hash_canon'. */ | |
1161 | ||
8d08fdba MS |
1162 | /* Now here is the hash table. When recording a list, it is added |
1163 | to the slot whose index is the hash code mod the table size. | |
1164 | Note that the hash table is used for several kinds of lists. | |
1165 | While all these live in the same table, they are completely independent, | |
1166 | and the hash code is computed differently for each of these. */ | |
1167 | ||
e2500fed | 1168 | static GTY ((param_is (union tree_node))) htab_t list_hash_table; |
9ccb25d5 | 1169 | |
9f63daea | 1170 | struct list_proxy |
9ccb25d5 MM |
1171 | { |
1172 | tree purpose; | |
1173 | tree value; | |
1174 | tree chain; | |
1175 | }; | |
1176 | ||
1177 | /* Compare ENTRY (an entry in the hash table) with DATA (a list_proxy | |
1178 | for a node we are thinking about adding). */ | |
1179 | ||
1180 | static int | |
b57b79f7 | 1181 | list_hash_eq (const void* entry, const void* data) |
9ccb25d5 | 1182 | { |
741ac903 KG |
1183 | const_tree const t = (const_tree) entry; |
1184 | const struct list_proxy *const proxy = (const struct list_proxy *) data; | |
9ccb25d5 MM |
1185 | |
1186 | return (TREE_VALUE (t) == proxy->value | |
1187 | && TREE_PURPOSE (t) == proxy->purpose | |
1188 | && TREE_CHAIN (t) == proxy->chain); | |
1189 | } | |
8d08fdba MS |
1190 | |
1191 | /* Compute a hash code for a list (chain of TREE_LIST nodes | |
1192 | with goodies in the TREE_PURPOSE, TREE_VALUE, and bits of the | |
1193 | TREE_COMMON slots), by adding the hash codes of the individual entries. */ | |
1194 | ||
9ccb25d5 | 1195 | static hashval_t |
b57b79f7 | 1196 | list_hash_pieces (tree purpose, tree value, tree chain) |
8d08fdba | 1197 | { |
9ccb25d5 | 1198 | hashval_t hashcode = 0; |
9f63daea | 1199 | |
37c46b43 | 1200 | if (chain) |
fd917e0d | 1201 | hashcode += TREE_HASH (chain); |
9f63daea | 1202 | |
37c46b43 | 1203 | if (value) |
fd917e0d | 1204 | hashcode += TREE_HASH (value); |
8d08fdba MS |
1205 | else |
1206 | hashcode += 1007; | |
37c46b43 | 1207 | if (purpose) |
fd917e0d | 1208 | hashcode += TREE_HASH (purpose); |
8d08fdba MS |
1209 | else |
1210 | hashcode += 1009; | |
1211 | return hashcode; | |
1212 | } | |
1213 | ||
9ccb25d5 | 1214 | /* Hash an already existing TREE_LIST. */ |
8d08fdba | 1215 | |
9ccb25d5 | 1216 | static hashval_t |
b57b79f7 | 1217 | list_hash (const void* p) |
8d08fdba | 1218 | { |
741ac903 | 1219 | const_tree const t = (const_tree) p; |
9f63daea EC |
1220 | return list_hash_pieces (TREE_PURPOSE (t), |
1221 | TREE_VALUE (t), | |
9ccb25d5 | 1222 | TREE_CHAIN (t)); |
8d08fdba MS |
1223 | } |
1224 | ||
51632249 JM |
1225 | /* Given list components PURPOSE, VALUE, AND CHAIN, return the canonical |
1226 | object for an identical list if one already exists. Otherwise, build a | |
1227 | new one, and record it as the canonical object. */ | |
8d08fdba | 1228 | |
8d08fdba | 1229 | tree |
b57b79f7 | 1230 | hash_tree_cons (tree purpose, tree value, tree chain) |
8d08fdba | 1231 | { |
a703fb38 | 1232 | int hashcode = 0; |
fad205ff | 1233 | void **slot; |
9ccb25d5 MM |
1234 | struct list_proxy proxy; |
1235 | ||
1236 | /* Hash the list node. */ | |
1237 | hashcode = list_hash_pieces (purpose, value, chain); | |
1238 | /* Create a proxy for the TREE_LIST we would like to create. We | |
1239 | don't actually create it so as to avoid creating garbage. */ | |
1240 | proxy.purpose = purpose; | |
1241 | proxy.value = value; | |
1242 | proxy.chain = chain; | |
1243 | /* See if it is already in the table. */ | |
1244 | slot = htab_find_slot_with_hash (list_hash_table, &proxy, hashcode, | |
1245 | INSERT); | |
1246 | /* If not, create a new node. */ | |
1247 | if (!*slot) | |
fad205ff | 1248 | *slot = tree_cons (purpose, value, chain); |
67f5655f | 1249 | return (tree) *slot; |
8d08fdba MS |
1250 | } |
1251 | ||
1252 | /* Constructor for hashed lists. */ | |
e92cc029 | 1253 | |
8d08fdba | 1254 | tree |
b57b79f7 | 1255 | hash_tree_chain (tree value, tree chain) |
8d08fdba | 1256 | { |
51632249 | 1257 | return hash_tree_cons (NULL_TREE, value, chain); |
8d08fdba | 1258 | } |
8d08fdba | 1259 | \f |
8d08fdba | 1260 | void |
b57b79f7 | 1261 | debug_binfo (tree elem) |
8d08fdba | 1262 | { |
fed3cef0 | 1263 | HOST_WIDE_INT n; |
8d08fdba MS |
1264 | tree virtuals; |
1265 | ||
90ff44cf KG |
1266 | fprintf (stderr, "type \"%s\", offset = " HOST_WIDE_INT_PRINT_DEC |
1267 | "\nvtable type:\n", | |
1268 | TYPE_NAME_STRING (BINFO_TYPE (elem)), | |
fed3cef0 | 1269 | TREE_INT_CST_LOW (BINFO_OFFSET (elem))); |
8d08fdba MS |
1270 | debug_tree (BINFO_TYPE (elem)); |
1271 | if (BINFO_VTABLE (elem)) | |
fed3cef0 | 1272 | fprintf (stderr, "vtable decl \"%s\"\n", |
c35cce41 | 1273 | IDENTIFIER_POINTER (DECL_NAME (get_vtbl_decl_for_binfo (elem)))); |
8d08fdba MS |
1274 | else |
1275 | fprintf (stderr, "no vtable decl yet\n"); | |
1276 | fprintf (stderr, "virtuals:\n"); | |
da3d4dfa | 1277 | virtuals = BINFO_VIRTUALS (elem); |
1f84ec23 | 1278 | n = 0; |
f30432d7 | 1279 | |
8d08fdba MS |
1280 | while (virtuals) |
1281 | { | |
83f2ccf4 | 1282 | tree fndecl = TREE_VALUE (virtuals); |
71e89f27 | 1283 | fprintf (stderr, "%s [%ld =? %ld]\n", |
8d08fdba | 1284 | IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (fndecl)), |
71e89f27 | 1285 | (long) n, (long) TREE_INT_CST_LOW (DECL_VINDEX (fndecl))); |
f30432d7 | 1286 | ++n; |
8d08fdba | 1287 | virtuals = TREE_CHAIN (virtuals); |
8d08fdba MS |
1288 | } |
1289 | } | |
1290 | ||
02ed62dd MM |
1291 | /* Build a representation for the qualified name SCOPE::NAME. TYPE is |
1292 | the type of the result expression, if known, or NULL_TREE if the | |
1293 | resulting expression is type-dependent. If TEMPLATE_P is true, | |
1294 | NAME is known to be a template because the user explicitly used the | |
3db45ab5 | 1295 | "template" keyword after the "::". |
02ed62dd MM |
1296 | |
1297 | All SCOPE_REFs should be built by use of this function. */ | |
1298 | ||
1299 | tree | |
1300 | build_qualified_name (tree type, tree scope, tree name, bool template_p) | |
1301 | { | |
1302 | tree t; | |
36569397 MM |
1303 | if (type == error_mark_node |
1304 | || scope == error_mark_node | |
1305 | || name == error_mark_node) | |
1306 | return error_mark_node; | |
02ed62dd MM |
1307 | t = build2 (SCOPE_REF, type, scope, name); |
1308 | QUALIFIED_NAME_IS_TEMPLATE (t) = template_p; | |
7097b3ac JM |
1309 | if (type) |
1310 | t = convert_from_reference (t); | |
02ed62dd MM |
1311 | return t; |
1312 | } | |
1313 | ||
3b426391 | 1314 | /* Returns nonzero if X is an expression for a (possibly overloaded) |
eff3a276 MM |
1315 | function. If "f" is a function or function template, "f", "c->f", |
1316 | "c.f", "C::f", and "f<int>" will all be considered possibly | |
1317 | overloaded functions. Returns 2 if the function is actually | |
b9704fc5 | 1318 | overloaded, i.e., if it is impossible to know the type of the |
eff3a276 MM |
1319 | function without performing overload resolution. */ |
1320 | ||
8d08fdba | 1321 | int |
b57b79f7 | 1322 | is_overloaded_fn (tree x) |
8d08fdba | 1323 | { |
4bb0968f | 1324 | /* A baselink is also considered an overloaded function. */ |
ccbe00a4 JM |
1325 | if (TREE_CODE (x) == OFFSET_REF |
1326 | || TREE_CODE (x) == COMPONENT_REF) | |
05e0b2f4 | 1327 | x = TREE_OPERAND (x, 1); |
4bb0968f | 1328 | if (BASELINK_P (x)) |
da15dae6 | 1329 | x = BASELINK_FUNCTIONS (x); |
d095e03c JM |
1330 | if (TREE_CODE (x) == TEMPLATE_ID_EXPR) |
1331 | x = TREE_OPERAND (x, 0); | |
1332 | if (DECL_FUNCTION_TEMPLATE_P (OVL_CURRENT (x)) | |
eff3a276 MM |
1333 | || (TREE_CODE (x) == OVERLOAD && OVL_CHAIN (x))) |
1334 | return 2; | |
1335 | return (TREE_CODE (x) == FUNCTION_DECL | |
1336 | || TREE_CODE (x) == OVERLOAD); | |
8d08fdba MS |
1337 | } |
1338 | ||
eff3a276 MM |
1339 | /* Returns true iff X is an expression for an overloaded function |
1340 | whose type cannot be known without performing overload | |
1341 | resolution. */ | |
1342 | ||
1343 | bool | |
b57b79f7 | 1344 | really_overloaded_fn (tree x) |
9f63daea | 1345 | { |
eff3a276 | 1346 | return is_overloaded_fn (x) == 2; |
8926095f MS |
1347 | } |
1348 | ||
8d08fdba | 1349 | tree |
294e855f | 1350 | get_fns (tree from) |
8d08fdba | 1351 | { |
50bc768d | 1352 | gcc_assert (is_overloaded_fn (from)); |
c6002625 | 1353 | /* A baselink is also considered an overloaded function. */ |
7e361ae6 JM |
1354 | if (TREE_CODE (from) == OFFSET_REF |
1355 | || TREE_CODE (from) == COMPONENT_REF) | |
ccbe00a4 | 1356 | from = TREE_OPERAND (from, 1); |
4bb0968f | 1357 | if (BASELINK_P (from)) |
da15dae6 | 1358 | from = BASELINK_FUNCTIONS (from); |
d095e03c JM |
1359 | if (TREE_CODE (from) == TEMPLATE_ID_EXPR) |
1360 | from = TREE_OPERAND (from, 0); | |
294e855f JM |
1361 | return from; |
1362 | } | |
1363 | ||
1364 | tree | |
1365 | get_first_fn (tree from) | |
1366 | { | |
1367 | return OVL_CURRENT (get_fns (from)); | |
2c73f9f5 | 1368 | } |
8d08fdba | 1369 | |
c6002625 | 1370 | /* Return a new OVL node, concatenating it with the old one. */ |
2c73f9f5 ML |
1371 | |
1372 | tree | |
b57b79f7 | 1373 | ovl_cons (tree decl, tree chain) |
2c73f9f5 ML |
1374 | { |
1375 | tree result = make_node (OVERLOAD); | |
1376 | TREE_TYPE (result) = unknown_type_node; | |
1377 | OVL_FUNCTION (result) = decl; | |
1378 | TREE_CHAIN (result) = chain; | |
9f63daea | 1379 | |
2c73f9f5 ML |
1380 | return result; |
1381 | } | |
1382 | ||
2c73f9f5 ML |
1383 | /* Build a new overloaded function. If this is the first one, |
1384 | just return it; otherwise, ovl_cons the _DECLs */ | |
1385 | ||
1386 | tree | |
b57b79f7 | 1387 | build_overload (tree decl, tree chain) |
2c73f9f5 | 1388 | { |
161c12b0 | 1389 | if (! chain && TREE_CODE (decl) != TEMPLATE_DECL) |
2c73f9f5 | 1390 | return decl; |
161c12b0 | 1391 | if (chain && TREE_CODE (chain) != OVERLOAD) |
2c73f9f5 ML |
1392 | chain = ovl_cons (chain, NULL_TREE); |
1393 | return ovl_cons (decl, chain); | |
1394 | } | |
1395 | ||
8d08fdba MS |
1396 | \f |
1397 | #define PRINT_RING_SIZE 4 | |
1398 | ||
f41c4af3 JM |
1399 | static const char * |
1400 | cxx_printable_name_internal (tree decl, int v, bool translate) | |
8d08fdba | 1401 | { |
1bde0042 | 1402 | static unsigned int uid_ring[PRINT_RING_SIZE]; |
8d08fdba | 1403 | static char *print_ring[PRINT_RING_SIZE]; |
f41c4af3 | 1404 | static bool trans_ring[PRINT_RING_SIZE]; |
8d08fdba MS |
1405 | static int ring_counter; |
1406 | int i; | |
1407 | ||
1408 | /* Only cache functions. */ | |
2ba25f50 MS |
1409 | if (v < 2 |
1410 | || TREE_CODE (decl) != FUNCTION_DECL | |
8d08fdba | 1411 | || DECL_LANG_SPECIFIC (decl) == 0) |
f41c4af3 | 1412 | return lang_decl_name (decl, v, translate); |
8d08fdba MS |
1413 | |
1414 | /* See if this print name is lying around. */ | |
1415 | for (i = 0; i < PRINT_RING_SIZE; i++) | |
f41c4af3 | 1416 | if (uid_ring[i] == DECL_UID (decl) && translate == trans_ring[i]) |
8d08fdba MS |
1417 | /* yes, so return it. */ |
1418 | return print_ring[i]; | |
1419 | ||
1420 | if (++ring_counter == PRINT_RING_SIZE) | |
1421 | ring_counter = 0; | |
1422 | ||
1423 | if (current_function_decl != NULL_TREE) | |
1424 | { | |
8fa6fa79 JM |
1425 | /* There may be both translated and untranslated versions of the |
1426 | name cached. */ | |
1427 | for (i = 0; i < 2; i++) | |
1428 | { | |
1429 | if (uid_ring[ring_counter] == DECL_UID (current_function_decl)) | |
1430 | ring_counter += 1; | |
1431 | if (ring_counter == PRINT_RING_SIZE) | |
1432 | ring_counter = 0; | |
1433 | } | |
1bde0042 | 1434 | gcc_assert (uid_ring[ring_counter] != DECL_UID (current_function_decl)); |
8d08fdba MS |
1435 | } |
1436 | ||
1437 | if (print_ring[ring_counter]) | |
1438 | free (print_ring[ring_counter]); | |
1439 | ||
f41c4af3 | 1440 | print_ring[ring_counter] = xstrdup (lang_decl_name (decl, v, translate)); |
1bde0042 | 1441 | uid_ring[ring_counter] = DECL_UID (decl); |
f41c4af3 | 1442 | trans_ring[ring_counter] = translate; |
8d08fdba MS |
1443 | return print_ring[ring_counter]; |
1444 | } | |
f41c4af3 JM |
1445 | |
1446 | const char * | |
1447 | cxx_printable_name (tree decl, int v) | |
1448 | { | |
1449 | return cxx_printable_name_internal (decl, v, false); | |
1450 | } | |
1451 | ||
1452 | const char * | |
1453 | cxx_printable_name_translate (tree decl, int v) | |
1454 | { | |
1455 | return cxx_printable_name_internal (decl, v, true); | |
1456 | } | |
8d08fdba | 1457 | \f |
f30432d7 | 1458 | /* Build the FUNCTION_TYPE or METHOD_TYPE which may throw exceptions |
8d08fdba | 1459 | listed in RAISES. */ |
e92cc029 | 1460 | |
8d08fdba | 1461 | tree |
b57b79f7 | 1462 | build_exception_variant (tree type, tree raises) |
8d08fdba | 1463 | { |
3a55fb4c JM |
1464 | tree v; |
1465 | int type_quals; | |
8d08fdba | 1466 | |
3a55fb4c JM |
1467 | if (comp_except_specs (raises, TYPE_RAISES_EXCEPTIONS (type), ce_exact)) |
1468 | return type; | |
1469 | ||
1470 | type_quals = TYPE_QUALS (type); | |
1471 | for (v = TYPE_MAIN_VARIANT (type); v; v = TYPE_NEXT_VARIANT (v)) | |
896c3aa3 | 1472 | if (check_qualified_type (v, type, type_quals) |
3a55fb4c | 1473 | && comp_except_specs (raises, TYPE_RAISES_EXCEPTIONS (v), ce_exact)) |
4cc1d462 | 1474 | return v; |
8d08fdba MS |
1475 | |
1476 | /* Need to build a new variant. */ | |
8dd16ecc | 1477 | v = build_variant_type_copy (type); |
8d08fdba MS |
1478 | TYPE_RAISES_EXCEPTIONS (v) = raises; |
1479 | return v; | |
1480 | } | |
1481 | ||
dac65501 KL |
1482 | /* Given a TEMPLATE_TEMPLATE_PARM node T, create a new |
1483 | BOUND_TEMPLATE_TEMPLATE_PARM bound with NEWARGS as its template | |
1899c3a4 | 1484 | arguments. */ |
73b0fce8 KL |
1485 | |
1486 | tree | |
b57b79f7 | 1487 | bind_template_template_parm (tree t, tree newargs) |
73b0fce8 | 1488 | { |
1899c3a4 | 1489 | tree decl = TYPE_NAME (t); |
6b9b6b15 JM |
1490 | tree t2; |
1491 | ||
9e1e64ec | 1492 | t2 = cxx_make_type (BOUND_TEMPLATE_TEMPLATE_PARM); |
c2255bc4 AH |
1493 | decl = build_decl (input_location, |
1494 | TYPE_DECL, DECL_NAME (decl), NULL_TREE); | |
1899c3a4 | 1495 | |
dac65501 KL |
1496 | /* These nodes have to be created to reflect new TYPE_DECL and template |
1497 | arguments. */ | |
1498 | TEMPLATE_TYPE_PARM_INDEX (t2) = copy_node (TEMPLATE_TYPE_PARM_INDEX (t)); | |
1499 | TEMPLATE_PARM_DECL (TEMPLATE_TYPE_PARM_INDEX (t2)) = decl; | |
1500 | TEMPLATE_TEMPLATE_PARM_TEMPLATE_INFO (t2) | |
aa373032 | 1501 | = build_template_info (TEMPLATE_TEMPLATE_PARM_TEMPLATE_DECL (t), newargs); |
6b9b6b15 | 1502 | |
1899c3a4 KL |
1503 | TREE_TYPE (decl) = t2; |
1504 | TYPE_NAME (t2) = decl; | |
1505 | TYPE_STUB_DECL (t2) = decl; | |
dac65501 | 1506 | TYPE_SIZE (t2) = 0; |
06d40de8 | 1507 | SET_TYPE_STRUCTURAL_EQUALITY (t2); |
73b0fce8 | 1508 | |
73b0fce8 KL |
1509 | return t2; |
1510 | } | |
1511 | ||
bf3428d0 | 1512 | /* Called from count_trees via walk_tree. */ |
297a5329 JM |
1513 | |
1514 | static tree | |
44de5aeb | 1515 | count_trees_r (tree *tp, int *walk_subtrees, void *data) |
297a5329 | 1516 | { |
44de5aeb RK |
1517 | ++*((int *) data); |
1518 | ||
1519 | if (TYPE_P (*tp)) | |
1520 | *walk_subtrees = 0; | |
1521 | ||
297a5329 JM |
1522 | return NULL_TREE; |
1523 | } | |
1524 | ||
1525 | /* Debugging function for measuring the rough complexity of a tree | |
1526 | representation. */ | |
1527 | ||
1528 | int | |
b57b79f7 | 1529 | count_trees (tree t) |
297a5329 | 1530 | { |
bf3428d0 | 1531 | int n_trees = 0; |
14588106 | 1532 | cp_walk_tree_without_duplicates (&t, count_trees_r, &n_trees); |
297a5329 | 1533 | return n_trees; |
9f63daea | 1534 | } |
297a5329 | 1535 | |
b2244c65 MM |
1536 | /* Called from verify_stmt_tree via walk_tree. */ |
1537 | ||
1538 | static tree | |
9f63daea | 1539 | verify_stmt_tree_r (tree* tp, |
0cbd7506 MS |
1540 | int* walk_subtrees ATTRIBUTE_UNUSED , |
1541 | void* data) | |
b2244c65 MM |
1542 | { |
1543 | tree t = *tp; | |
1544 | htab_t *statements = (htab_t *) data; | |
1545 | void **slot; | |
1546 | ||
009ed910 | 1547 | if (!STATEMENT_CODE_P (TREE_CODE (t))) |
b2244c65 MM |
1548 | return NULL_TREE; |
1549 | ||
1550 | /* If this statement is already present in the hash table, then | |
1551 | there is a circularity in the statement tree. */ | |
315fb5db | 1552 | gcc_assert (!htab_find (*statements, t)); |
9f63daea | 1553 | |
b2244c65 MM |
1554 | slot = htab_find_slot (*statements, t, INSERT); |
1555 | *slot = t; | |
1556 | ||
1557 | return NULL_TREE; | |
1558 | } | |
1559 | ||
1560 | /* Debugging function to check that the statement T has not been | |
1561 | corrupted. For now, this function simply checks that T contains no | |
1562 | circularities. */ | |
1563 | ||
1564 | void | |
b57b79f7 | 1565 | verify_stmt_tree (tree t) |
b2244c65 MM |
1566 | { |
1567 | htab_t statements; | |
1568 | statements = htab_create (37, htab_hash_pointer, htab_eq_pointer, NULL); | |
14588106 | 1569 | cp_walk_tree (&t, verify_stmt_tree_r, &statements, NULL); |
b2244c65 MM |
1570 | htab_delete (statements); |
1571 | } | |
1572 | ||
50a6dbd7 | 1573 | /* Check if the type T depends on a type with no linkage and if so, return |
4684cd27 | 1574 | it. If RELAXED_P then do not consider a class type declared within |
ecc607fc | 1575 | a vague-linkage function to have no linkage. */ |
50a6dbd7 JM |
1576 | |
1577 | tree | |
4684cd27 | 1578 | no_linkage_check (tree t, bool relaxed_p) |
50a6dbd7 | 1579 | { |
caf43ca4 MM |
1580 | tree r; |
1581 | ||
2adeacc9 MM |
1582 | /* There's no point in checking linkage on template functions; we |
1583 | can't know their complete types. */ | |
1584 | if (processing_template_decl) | |
1585 | return NULL_TREE; | |
1586 | ||
caf43ca4 MM |
1587 | switch (TREE_CODE (t)) |
1588 | { | |
1589 | case RECORD_TYPE: | |
1590 | if (TYPE_PTRMEMFUNC_P (t)) | |
1591 | goto ptrmem; | |
e6d92cec JM |
1592 | /* Lambda types that don't have mangling scope have no linkage. We |
1593 | check CLASSTYPE_LAMBDA_EXPR here rather than LAMBDA_TYPE_P because | |
1594 | when we get here from pushtag none of the lambda information is | |
1595 | set up yet, so we want to assume that the lambda has linkage and | |
1596 | fix it up later if not. */ | |
1597 | if (CLASSTYPE_LAMBDA_EXPR (t) | |
1598 | && LAMBDA_TYPE_EXTRA_SCOPE (t) == NULL_TREE) | |
1599 | return t; | |
caf43ca4 MM |
1600 | /* Fall through. */ |
1601 | case UNION_TYPE: | |
1602 | if (!CLASS_TYPE_P (t)) | |
1603 | return NULL_TREE; | |
1604 | /* Fall through. */ | |
1605 | case ENUMERAL_TYPE: | |
ecc607fc | 1606 | /* Only treat anonymous types as having no linkage if they're at |
2f59d9e0 | 1607 | namespace scope. This is core issue 966. */ |
ecc607fc | 1608 | if (TYPE_ANONYMOUS_P (t) && TYPE_NAMESPACE_SCOPE_P (t)) |
caf43ca4 | 1609 | return t; |
ecc607fc | 1610 | |
e6d92cec | 1611 | for (r = CP_TYPE_CONTEXT (t); ; ) |
ecc607fc | 1612 | { |
e6d92cec JM |
1613 | /* If we're a nested type of a !TREE_PUBLIC class, we might not |
1614 | have linkage, or we might just be in an anonymous namespace. | |
1615 | If we're in a TREE_PUBLIC class, we have linkage. */ | |
1616 | if (TYPE_P (r) && !TREE_PUBLIC (TYPE_NAME (r))) | |
1617 | return no_linkage_check (TYPE_CONTEXT (t), relaxed_p); | |
1618 | else if (TREE_CODE (r) == FUNCTION_DECL) | |
1619 | { | |
d6dcdbd5 | 1620 | if (!relaxed_p || !vague_linkage_p (r)) |
e6d92cec JM |
1621 | return t; |
1622 | else | |
1623 | r = CP_DECL_CONTEXT (r); | |
1624 | } | |
ecc607fc | 1625 | else |
e6d92cec | 1626 | break; |
ecc607fc JM |
1627 | } |
1628 | ||
caf43ca4 MM |
1629 | return NULL_TREE; |
1630 | ||
1631 | case ARRAY_TYPE: | |
1632 | case POINTER_TYPE: | |
1633 | case REFERENCE_TYPE: | |
4684cd27 | 1634 | return no_linkage_check (TREE_TYPE (t), relaxed_p); |
caf43ca4 MM |
1635 | |
1636 | case OFFSET_TYPE: | |
1637 | ptrmem: | |
4684cd27 MM |
1638 | r = no_linkage_check (TYPE_PTRMEM_POINTED_TO_TYPE (t), |
1639 | relaxed_p); | |
caf43ca4 MM |
1640 | if (r) |
1641 | return r; | |
4684cd27 | 1642 | return no_linkage_check (TYPE_PTRMEM_CLASS_TYPE (t), relaxed_p); |
caf43ca4 MM |
1643 | |
1644 | case METHOD_TYPE: | |
4684cd27 | 1645 | r = no_linkage_check (TYPE_METHOD_BASETYPE (t), relaxed_p); |
caf43ca4 MM |
1646 | if (r) |
1647 | return r; | |
1648 | /* Fall through. */ | |
1649 | case FUNCTION_TYPE: | |
1650 | { | |
1651 | tree parm; | |
9f63daea EC |
1652 | for (parm = TYPE_ARG_TYPES (t); |
1653 | parm && parm != void_list_node; | |
caf43ca4 MM |
1654 | parm = TREE_CHAIN (parm)) |
1655 | { | |
4684cd27 | 1656 | r = no_linkage_check (TREE_VALUE (parm), relaxed_p); |
caf43ca4 MM |
1657 | if (r) |
1658 | return r; | |
1659 | } | |
4684cd27 | 1660 | return no_linkage_check (TREE_TYPE (t), relaxed_p); |
caf43ca4 MM |
1661 | } |
1662 | ||
1663 | default: | |
1664 | return NULL_TREE; | |
1665 | } | |
50a6dbd7 JM |
1666 | } |
1667 | ||
5566b478 MS |
1668 | #ifdef GATHER_STATISTICS |
1669 | extern int depth_reached; | |
1670 | #endif | |
1671 | ||
8d08fdba | 1672 | void |
b57b79f7 | 1673 | cxx_print_statistics (void) |
8d08fdba | 1674 | { |
8d08fdba MS |
1675 | print_search_statistics (); |
1676 | print_class_statistics (); | |
7dcfe861 | 1677 | print_template_statistics (); |
5566b478 MS |
1678 | #ifdef GATHER_STATISTICS |
1679 | fprintf (stderr, "maximum template instantiation depth reached: %d\n", | |
1680 | depth_reached); | |
1681 | #endif | |
8d08fdba MS |
1682 | } |
1683 | ||
e92cc029 MS |
1684 | /* Return, as an INTEGER_CST node, the number of elements for TYPE |
1685 | (which is an ARRAY_TYPE). This counts only elements of the top | |
1686 | array. */ | |
8d08fdba MS |
1687 | |
1688 | tree | |
b57b79f7 | 1689 | array_type_nelts_top (tree type) |
8d08fdba | 1690 | { |
db3927fb AH |
1691 | return fold_build2_loc (input_location, |
1692 | PLUS_EXPR, sizetype, | |
7866705a | 1693 | array_type_nelts (type), |
701e903a | 1694 | size_one_node); |
8d08fdba MS |
1695 | } |
1696 | ||
e92cc029 MS |
1697 | /* Return, as an INTEGER_CST node, the number of elements for TYPE |
1698 | (which is an ARRAY_TYPE). This one is a recursive count of all | |
1699 | ARRAY_TYPEs that are clumped together. */ | |
8d08fdba MS |
1700 | |
1701 | tree | |
b57b79f7 | 1702 | array_type_nelts_total (tree type) |
8d08fdba MS |
1703 | { |
1704 | tree sz = array_type_nelts_top (type); | |
1705 | type = TREE_TYPE (type); | |
1706 | while (TREE_CODE (type) == ARRAY_TYPE) | |
1707 | { | |
1708 | tree n = array_type_nelts_top (type); | |
db3927fb AH |
1709 | sz = fold_build2_loc (input_location, |
1710 | MULT_EXPR, sizetype, sz, n); | |
8d08fdba MS |
1711 | type = TREE_TYPE (type); |
1712 | } | |
1713 | return sz; | |
1714 | } | |
878cd289 | 1715 | |
b3ab27f3 MM |
1716 | /* Called from break_out_target_exprs via mapcar. */ |
1717 | ||
1718 | static tree | |
b57b79f7 | 1719 | bot_manip (tree* tp, int* walk_subtrees, void* data) |
878cd289 | 1720 | { |
8dfaeb63 MM |
1721 | splay_tree target_remap = ((splay_tree) data); |
1722 | tree t = *tp; | |
1723 | ||
4f976745 | 1724 | if (!TYPE_P (t) && TREE_CONSTANT (t)) |
8dfaeb63 | 1725 | { |
495d26d6 | 1726 | /* There can't be any TARGET_EXPRs or their slot variables below |
0cbd7506 MS |
1727 | this point. We used to check !TREE_SIDE_EFFECTS, but then we |
1728 | failed to copy an ADDR_EXPR of the slot VAR_DECL. */ | |
8dfaeb63 MM |
1729 | *walk_subtrees = 0; |
1730 | return NULL_TREE; | |
1731 | } | |
495d26d6 | 1732 | if (TREE_CODE (t) == TARGET_EXPR) |
73aad9b9 | 1733 | { |
b3ab27f3 MM |
1734 | tree u; |
1735 | ||
02531345 | 1736 | if (TREE_CODE (TREE_OPERAND (t, 1)) == AGGR_INIT_EXPR) |
7efc22ea | 1737 | u = build_cplus_new (TREE_TYPE (t), TREE_OPERAND (t, 1)); |
9f63daea | 1738 | else |
7efc22ea | 1739 | u = build_target_expr_with_type (TREE_OPERAND (t, 1), TREE_TYPE (t)); |
b3ab27f3 MM |
1740 | |
1741 | /* Map the old variable to the new one. */ | |
9f63daea EC |
1742 | splay_tree_insert (target_remap, |
1743 | (splay_tree_key) TREE_OPERAND (t, 0), | |
b3ab27f3 | 1744 | (splay_tree_value) TREE_OPERAND (u, 0)); |
8dfaeb63 | 1745 | |
7efc22ea JM |
1746 | TREE_OPERAND (u, 1) = break_out_target_exprs (TREE_OPERAND (u, 1)); |
1747 | ||
8dfaeb63 MM |
1748 | /* Replace the old expression with the new version. */ |
1749 | *tp = u; | |
1750 | /* We don't have to go below this point; the recursive call to | |
1751 | break_out_target_exprs will have handled anything below this | |
1752 | point. */ | |
1753 | *walk_subtrees = 0; | |
1754 | return NULL_TREE; | |
73aad9b9 | 1755 | } |
73aad9b9 | 1756 | |
8dfaeb63 MM |
1757 | /* Make a copy of this node. */ |
1758 | return copy_tree_r (tp, walk_subtrees, NULL); | |
878cd289 | 1759 | } |
9f63daea | 1760 | |
8dfaeb63 MM |
1761 | /* Replace all remapped VAR_DECLs in T with their new equivalents. |
1762 | DATA is really a splay-tree mapping old variables to new | |
1763 | variables. */ | |
b3ab27f3 MM |
1764 | |
1765 | static tree | |
9f63daea | 1766 | bot_replace (tree* t, |
0cbd7506 MS |
1767 | int* walk_subtrees ATTRIBUTE_UNUSED , |
1768 | void* data) | |
b3ab27f3 | 1769 | { |
8dfaeb63 MM |
1770 | splay_tree target_remap = ((splay_tree) data); |
1771 | ||
b3ab27f3 MM |
1772 | if (TREE_CODE (*t) == VAR_DECL) |
1773 | { | |
1774 | splay_tree_node n = splay_tree_lookup (target_remap, | |
1775 | (splay_tree_key) *t); | |
1776 | if (n) | |
1777 | *t = (tree) n->value; | |
1778 | } | |
1779 | ||
1780 | return NULL_TREE; | |
1781 | } | |
9f63daea | 1782 | |
8dfaeb63 MM |
1783 | /* When we parse a default argument expression, we may create |
1784 | temporary variables via TARGET_EXPRs. When we actually use the | |
1785 | default-argument expression, we make a copy of the expression, but | |
1786 | we must replace the temporaries with appropriate local versions. */ | |
e92cc029 | 1787 | |
878cd289 | 1788 | tree |
b57b79f7 | 1789 | break_out_target_exprs (tree t) |
878cd289 | 1790 | { |
8dfaeb63 MM |
1791 | static int target_remap_count; |
1792 | static splay_tree target_remap; | |
1793 | ||
b3ab27f3 | 1794 | if (!target_remap_count++) |
9f63daea EC |
1795 | target_remap = splay_tree_new (splay_tree_compare_pointers, |
1796 | /*splay_tree_delete_key_fn=*/NULL, | |
b3ab27f3 | 1797 | /*splay_tree_delete_value_fn=*/NULL); |
14588106 RG |
1798 | cp_walk_tree (&t, bot_manip, target_remap, NULL); |
1799 | cp_walk_tree (&t, bot_replace, target_remap, NULL); | |
b3ab27f3 MM |
1800 | |
1801 | if (!--target_remap_count) | |
1802 | { | |
1803 | splay_tree_delete (target_remap); | |
1804 | target_remap = NULL; | |
1805 | } | |
1806 | ||
1807 | return t; | |
878cd289 | 1808 | } |
f30432d7 | 1809 | |
8e1daa34 NS |
1810 | /* Similar to `build_nt', but for template definitions of dependent |
1811 | expressions */ | |
5566b478 MS |
1812 | |
1813 | tree | |
e34d07f2 | 1814 | build_min_nt (enum tree_code code, ...) |
5566b478 | 1815 | { |
926ce8bd KH |
1816 | tree t; |
1817 | int length; | |
1818 | int i; | |
e34d07f2 | 1819 | va_list p; |
5566b478 | 1820 | |
5039610b SL |
1821 | gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp); |
1822 | ||
e34d07f2 | 1823 | va_start (p, code); |
5566b478 | 1824 | |
5566b478 | 1825 | t = make_node (code); |
8d5e6e25 | 1826 | length = TREE_CODE_LENGTH (code); |
5566b478 MS |
1827 | |
1828 | for (i = 0; i < length; i++) | |
1829 | { | |
1830 | tree x = va_arg (p, tree); | |
2a1e9fdd | 1831 | TREE_OPERAND (t, i) = x; |
5566b478 MS |
1832 | } |
1833 | ||
e34d07f2 | 1834 | va_end (p); |
5566b478 MS |
1835 | return t; |
1836 | } | |
1837 | ||
5039610b | 1838 | |
8e1daa34 | 1839 | /* Similar to `build', but for template definitions. */ |
5566b478 MS |
1840 | |
1841 | tree | |
e34d07f2 | 1842 | build_min (enum tree_code code, tree tt, ...) |
5566b478 | 1843 | { |
926ce8bd KH |
1844 | tree t; |
1845 | int length; | |
1846 | int i; | |
e34d07f2 | 1847 | va_list p; |
5566b478 | 1848 | |
5039610b SL |
1849 | gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp); |
1850 | ||
e34d07f2 | 1851 | va_start (p, tt); |
5566b478 | 1852 | |
5566b478 | 1853 | t = make_node (code); |
8d5e6e25 | 1854 | length = TREE_CODE_LENGTH (code); |
2a1e9fdd | 1855 | TREE_TYPE (t) = tt; |
5566b478 MS |
1856 | |
1857 | for (i = 0; i < length; i++) | |
1858 | { | |
1859 | tree x = va_arg (p, tree); | |
2a1e9fdd | 1860 | TREE_OPERAND (t, i) = x; |
4f976745 | 1861 | if (x && !TYPE_P (x) && TREE_SIDE_EFFECTS (x)) |
8e1daa34 | 1862 | TREE_SIDE_EFFECTS (t) = 1; |
5566b478 MS |
1863 | } |
1864 | ||
e34d07f2 | 1865 | va_end (p); |
5566b478 MS |
1866 | return t; |
1867 | } | |
1868 | ||
8e1daa34 NS |
1869 | /* Similar to `build', but for template definitions of non-dependent |
1870 | expressions. NON_DEP is the non-dependent expression that has been | |
1871 | built. */ | |
1872 | ||
1873 | tree | |
1874 | build_min_non_dep (enum tree_code code, tree non_dep, ...) | |
1875 | { | |
926ce8bd KH |
1876 | tree t; |
1877 | int length; | |
1878 | int i; | |
8e1daa34 NS |
1879 | va_list p; |
1880 | ||
5039610b SL |
1881 | gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp); |
1882 | ||
8e1daa34 NS |
1883 | va_start (p, non_dep); |
1884 | ||
1885 | t = make_node (code); | |
1886 | length = TREE_CODE_LENGTH (code); | |
1887 | TREE_TYPE (t) = TREE_TYPE (non_dep); | |
8e1daa34 NS |
1888 | TREE_SIDE_EFFECTS (t) = TREE_SIDE_EFFECTS (non_dep); |
1889 | ||
1890 | for (i = 0; i < length; i++) | |
1891 | { | |
1892 | tree x = va_arg (p, tree); | |
1893 | TREE_OPERAND (t, i) = x; | |
1894 | } | |
1895 | ||
1896 | if (code == COMPOUND_EXPR && TREE_CODE (non_dep) != COMPOUND_EXPR) | |
1897 | /* This should not be considered a COMPOUND_EXPR, because it | |
04c06002 | 1898 | resolves to an overload. */ |
8e1daa34 | 1899 | COMPOUND_EXPR_OVERLOADED (t) = 1; |
9f63daea | 1900 | |
8e1daa34 NS |
1901 | va_end (p); |
1902 | return t; | |
1903 | } | |
1904 | ||
3fcb9d1b NF |
1905 | /* Similar to `build_nt_call_vec', but for template definitions of |
1906 | non-dependent expressions. NON_DEP is the non-dependent expression | |
1907 | that has been built. */ | |
5039610b SL |
1908 | |
1909 | tree | |
c166b898 | 1910 | build_min_non_dep_call_vec (tree non_dep, tree fn, VEC(tree,gc) *argvec) |
5039610b | 1911 | { |
c166b898 | 1912 | tree t = build_nt_call_vec (fn, argvec); |
5039610b SL |
1913 | TREE_TYPE (t) = TREE_TYPE (non_dep); |
1914 | TREE_SIDE_EFFECTS (t) = TREE_SIDE_EFFECTS (non_dep); | |
1915 | return t; | |
1916 | } | |
1917 | ||
5566b478 | 1918 | tree |
b57b79f7 | 1919 | get_type_decl (tree t) |
5566b478 | 1920 | { |
5566b478 MS |
1921 | if (TREE_CODE (t) == TYPE_DECL) |
1922 | return t; | |
2f939d94 | 1923 | if (TYPE_P (t)) |
5566b478 | 1924 | return TYPE_STUB_DECL (t); |
315fb5db NS |
1925 | gcc_assert (t == error_mark_node); |
1926 | return t; | |
5566b478 MS |
1927 | } |
1928 | ||
700466c2 JM |
1929 | /* Returns the namespace that contains DECL, whether directly or |
1930 | indirectly. */ | |
1931 | ||
1932 | tree | |
b57b79f7 | 1933 | decl_namespace_context (tree decl) |
700466c2 JM |
1934 | { |
1935 | while (1) | |
1936 | { | |
1937 | if (TREE_CODE (decl) == NAMESPACE_DECL) | |
1938 | return decl; | |
1939 | else if (TYPE_P (decl)) | |
1940 | decl = CP_DECL_CONTEXT (TYPE_MAIN_DECL (decl)); | |
1941 | else | |
1942 | decl = CP_DECL_CONTEXT (decl); | |
1943 | } | |
1944 | } | |
1945 | ||
b9e75696 JM |
1946 | /* Returns true if decl is within an anonymous namespace, however deeply |
1947 | nested, or false otherwise. */ | |
1948 | ||
1949 | bool | |
58f9752a | 1950 | decl_anon_ns_mem_p (const_tree decl) |
b9e75696 JM |
1951 | { |
1952 | while (1) | |
1953 | { | |
653109bd | 1954 | if (decl == NULL_TREE || decl == error_mark_node) |
b9e75696 JM |
1955 | return false; |
1956 | if (TREE_CODE (decl) == NAMESPACE_DECL | |
1957 | && DECL_NAME (decl) == NULL_TREE) | |
1958 | return true; | |
1959 | /* Classes and namespaces inside anonymous namespaces have | |
1960 | TREE_PUBLIC == 0, so we can shortcut the search. */ | |
1961 | else if (TYPE_P (decl)) | |
1962 | return (TREE_PUBLIC (TYPE_NAME (decl)) == 0); | |
1963 | else if (TREE_CODE (decl) == NAMESPACE_DECL) | |
1964 | return (TREE_PUBLIC (decl) == 0); | |
1965 | else | |
1966 | decl = DECL_CONTEXT (decl); | |
1967 | } | |
1968 | } | |
1969 | ||
67d743fe | 1970 | /* Return truthvalue of whether T1 is the same tree structure as T2. |
c8a209ca | 1971 | Return 1 if they are the same. Return 0 if they are different. */ |
67d743fe | 1972 | |
c8a209ca | 1973 | bool |
b57b79f7 | 1974 | cp_tree_equal (tree t1, tree t2) |
67d743fe | 1975 | { |
926ce8bd | 1976 | enum tree_code code1, code2; |
67d743fe MS |
1977 | |
1978 | if (t1 == t2) | |
c8a209ca NS |
1979 | return true; |
1980 | if (!t1 || !t2) | |
1981 | return false; | |
1982 | ||
1983 | for (code1 = TREE_CODE (t1); | |
1a87cf0c | 1984 | CONVERT_EXPR_CODE_P (code1) |
c8a209ca NS |
1985 | || code1 == NON_LVALUE_EXPR; |
1986 | code1 = TREE_CODE (t1)) | |
1987 | t1 = TREE_OPERAND (t1, 0); | |
1988 | for (code2 = TREE_CODE (t2); | |
1a87cf0c | 1989 | CONVERT_EXPR_CODE_P (code2) |
c8a209ca NS |
1990 | || code1 == NON_LVALUE_EXPR; |
1991 | code2 = TREE_CODE (t2)) | |
1992 | t2 = TREE_OPERAND (t2, 0); | |
1993 | ||
1994 | /* They might have become equal now. */ | |
1995 | if (t1 == t2) | |
1996 | return true; | |
9f63daea | 1997 | |
67d743fe | 1998 | if (code1 != code2) |
c8a209ca | 1999 | return false; |
67d743fe MS |
2000 | |
2001 | switch (code1) | |
2002 | { | |
2003 | case INTEGER_CST: | |
2004 | return TREE_INT_CST_LOW (t1) == TREE_INT_CST_LOW (t2) | |
2005 | && TREE_INT_CST_HIGH (t1) == TREE_INT_CST_HIGH (t2); | |
2006 | ||
2007 | case REAL_CST: | |
2008 | return REAL_VALUES_EQUAL (TREE_REAL_CST (t1), TREE_REAL_CST (t2)); | |
2009 | ||
2010 | case STRING_CST: | |
2011 | return TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2) | |
da61dec9 | 2012 | && !memcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2), |
c8a209ca | 2013 | TREE_STRING_LENGTH (t1)); |
67d743fe | 2014 | |
d05739f8 JM |
2015 | case FIXED_CST: |
2016 | return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1), | |
2017 | TREE_FIXED_CST (t2)); | |
2018 | ||
2a2193e0 SM |
2019 | case COMPLEX_CST: |
2020 | return cp_tree_equal (TREE_REALPART (t1), TREE_REALPART (t2)) | |
2021 | && cp_tree_equal (TREE_IMAGPART (t1), TREE_IMAGPART (t2)); | |
2022 | ||
67d743fe | 2023 | case CONSTRUCTOR: |
7dd4bdf5 MM |
2024 | /* We need to do this when determining whether or not two |
2025 | non-type pointer to member function template arguments | |
2026 | are the same. */ | |
31d06664 JM |
2027 | if (!same_type_p (TREE_TYPE (t1), TREE_TYPE (t2)) |
2028 | || CONSTRUCTOR_NELTS (t1) != CONSTRUCTOR_NELTS (t2)) | |
c8a209ca | 2029 | return false; |
31d06664 JM |
2030 | { |
2031 | tree field, value; | |
2032 | unsigned int i; | |
2033 | FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (t1), i, field, value) | |
2034 | { | |
2035 | constructor_elt *elt2 = CONSTRUCTOR_ELT (t2, i); | |
2036 | if (!cp_tree_equal (field, elt2->index) | |
2037 | || !cp_tree_equal (value, elt2->value)) | |
2038 | return false; | |
2039 | } | |
2040 | } | |
2041 | return true; | |
7dd4bdf5 MM |
2042 | |
2043 | case TREE_LIST: | |
c8a209ca NS |
2044 | if (!cp_tree_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2))) |
2045 | return false; | |
2046 | if (!cp_tree_equal (TREE_VALUE (t1), TREE_VALUE (t2))) | |
2047 | return false; | |
7dd4bdf5 | 2048 | return cp_tree_equal (TREE_CHAIN (t1), TREE_CHAIN (t2)); |
67d743fe MS |
2049 | |
2050 | case SAVE_EXPR: | |
2051 | return cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0)); | |
2052 | ||
2053 | case CALL_EXPR: | |
5039610b SL |
2054 | { |
2055 | tree arg1, arg2; | |
2056 | call_expr_arg_iterator iter1, iter2; | |
2057 | if (!cp_tree_equal (CALL_EXPR_FN (t1), CALL_EXPR_FN (t2))) | |
2058 | return false; | |
2059 | for (arg1 = first_call_expr_arg (t1, &iter1), | |
2060 | arg2 = first_call_expr_arg (t2, &iter2); | |
2061 | arg1 && arg2; | |
2062 | arg1 = next_call_expr_arg (&iter1), | |
2063 | arg2 = next_call_expr_arg (&iter2)) | |
2064 | if (!cp_tree_equal (arg1, arg2)) | |
2065 | return false; | |
96b4a0b5 JM |
2066 | if (arg1 || arg2) |
2067 | return false; | |
2068 | return true; | |
5039610b | 2069 | } |
67d743fe | 2070 | |
c8a209ca NS |
2071 | case TARGET_EXPR: |
2072 | { | |
2073 | tree o1 = TREE_OPERAND (t1, 0); | |
2074 | tree o2 = TREE_OPERAND (t2, 0); | |
9f63daea | 2075 | |
c8a209ca NS |
2076 | /* Special case: if either target is an unallocated VAR_DECL, |
2077 | it means that it's going to be unified with whatever the | |
2078 | TARGET_EXPR is really supposed to initialize, so treat it | |
2079 | as being equivalent to anything. */ | |
2080 | if (TREE_CODE (o1) == VAR_DECL && DECL_NAME (o1) == NULL_TREE | |
2081 | && !DECL_RTL_SET_P (o1)) | |
2082 | /*Nop*/; | |
2083 | else if (TREE_CODE (o2) == VAR_DECL && DECL_NAME (o2) == NULL_TREE | |
2084 | && !DECL_RTL_SET_P (o2)) | |
2085 | /*Nop*/; | |
2086 | else if (!cp_tree_equal (o1, o2)) | |
2087 | return false; | |
9f63daea | 2088 | |
c8a209ca NS |
2089 | return cp_tree_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1)); |
2090 | } | |
9f63daea | 2091 | |
67d743fe | 2092 | case WITH_CLEANUP_EXPR: |
c8a209ca NS |
2093 | if (!cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0))) |
2094 | return false; | |
6ad7895a | 2095 | return cp_tree_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t1, 1)); |
67d743fe MS |
2096 | |
2097 | case COMPONENT_REF: | |
c8a209ca NS |
2098 | if (TREE_OPERAND (t1, 1) != TREE_OPERAND (t2, 1)) |
2099 | return false; | |
2100 | return cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0)); | |
67d743fe | 2101 | |
67d743fe | 2102 | case PARM_DECL: |
a77f94e2 JM |
2103 | /* For comparing uses of parameters in late-specified return types |
2104 | with an out-of-class definition of the function. */ | |
448545cb | 2105 | if (same_type_p (TREE_TYPE (t1), TREE_TYPE (t2)) |
ad909c97 | 2106 | && DECL_PARM_INDEX (t1) == DECL_PARM_INDEX (t2)) |
a77f94e2 JM |
2107 | return true; |
2108 | else | |
2109 | return false; | |
2110 | ||
2111 | case VAR_DECL: | |
67d743fe MS |
2112 | case CONST_DECL: |
2113 | case FUNCTION_DECL: | |
c8a209ca NS |
2114 | case TEMPLATE_DECL: |
2115 | case IDENTIFIER_NODE: | |
47c0c7d7 | 2116 | case SSA_NAME: |
c8a209ca | 2117 | return false; |
67d743fe | 2118 | |
17a27b4f MM |
2119 | case BASELINK: |
2120 | return (BASELINK_BINFO (t1) == BASELINK_BINFO (t2) | |
2121 | && BASELINK_ACCESS_BINFO (t1) == BASELINK_ACCESS_BINFO (t2) | |
2122 | && cp_tree_equal (BASELINK_FUNCTIONS (t1), | |
2123 | BASELINK_FUNCTIONS (t2))); | |
2124 | ||
f84b4be9 | 2125 | case TEMPLATE_PARM_INDEX: |
31758337 NS |
2126 | return (TEMPLATE_PARM_IDX (t1) == TEMPLATE_PARM_IDX (t2) |
2127 | && TEMPLATE_PARM_LEVEL (t1) == TEMPLATE_PARM_LEVEL (t2) | |
9524f710 LE |
2128 | && (TEMPLATE_PARM_PARAMETER_PACK (t1) |
2129 | == TEMPLATE_PARM_PARAMETER_PACK (t2)) | |
31758337 NS |
2130 | && same_type_p (TREE_TYPE (TEMPLATE_PARM_DECL (t1)), |
2131 | TREE_TYPE (TEMPLATE_PARM_DECL (t2)))); | |
67d743fe | 2132 | |
bf12d54d NS |
2133 | case TEMPLATE_ID_EXPR: |
2134 | { | |
2135 | unsigned ix; | |
2136 | tree vec1, vec2; | |
9f63daea | 2137 | |
bf12d54d NS |
2138 | if (!cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0))) |
2139 | return false; | |
2140 | vec1 = TREE_OPERAND (t1, 1); | |
2141 | vec2 = TREE_OPERAND (t2, 1); | |
2142 | ||
2143 | if (!vec1 || !vec2) | |
2144 | return !vec1 && !vec2; | |
9f63daea | 2145 | |
bf12d54d NS |
2146 | if (TREE_VEC_LENGTH (vec1) != TREE_VEC_LENGTH (vec2)) |
2147 | return false; | |
2148 | ||
2149 | for (ix = TREE_VEC_LENGTH (vec1); ix--;) | |
2150 | if (!cp_tree_equal (TREE_VEC_ELT (vec1, ix), | |
2151 | TREE_VEC_ELT (vec2, ix))) | |
2152 | return false; | |
9f63daea | 2153 | |
bf12d54d NS |
2154 | return true; |
2155 | } | |
9f63daea | 2156 | |
67d743fe | 2157 | case SIZEOF_EXPR: |
abff8e06 | 2158 | case ALIGNOF_EXPR: |
c8a209ca NS |
2159 | { |
2160 | tree o1 = TREE_OPERAND (t1, 0); | |
2161 | tree o2 = TREE_OPERAND (t2, 0); | |
9f63daea | 2162 | |
c8a209ca NS |
2163 | if (TREE_CODE (o1) != TREE_CODE (o2)) |
2164 | return false; | |
2165 | if (TYPE_P (o1)) | |
2166 | return same_type_p (o1, o2); | |
2167 | else | |
2168 | return cp_tree_equal (o1, o2); | |
2169 | } | |
9f63daea | 2170 | |
6f9f76e3 SM |
2171 | case MODOP_EXPR: |
2172 | { | |
2173 | tree t1_op1, t2_op1; | |
2174 | ||
2175 | if (!cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0))) | |
2176 | return false; | |
2177 | ||
2178 | t1_op1 = TREE_OPERAND (t1, 1); | |
2179 | t2_op1 = TREE_OPERAND (t2, 1); | |
2180 | if (TREE_CODE (t1_op1) != TREE_CODE (t2_op1)) | |
2181 | return false; | |
2182 | ||
2183 | return cp_tree_equal (TREE_OPERAND (t1, 2), TREE_OPERAND (t2, 2)); | |
2184 | } | |
2185 | ||
61a127b3 MM |
2186 | case PTRMEM_CST: |
2187 | /* Two pointer-to-members are the same if they point to the same | |
2188 | field or function in the same class. */ | |
c8a209ca NS |
2189 | if (PTRMEM_CST_MEMBER (t1) != PTRMEM_CST_MEMBER (t2)) |
2190 | return false; | |
2191 | ||
2192 | return same_type_p (PTRMEM_CST_CLASS (t1), PTRMEM_CST_CLASS (t2)); | |
61a127b3 | 2193 | |
943e3ede MM |
2194 | case OVERLOAD: |
2195 | if (OVL_FUNCTION (t1) != OVL_FUNCTION (t2)) | |
2196 | return false; | |
2197 | return cp_tree_equal (OVL_CHAIN (t1), OVL_CHAIN (t2)); | |
2198 | ||
ea798d0f PC |
2199 | case TRAIT_EXPR: |
2200 | if (TRAIT_EXPR_KIND (t1) != TRAIT_EXPR_KIND (t2)) | |
2201 | return false; | |
2202 | return same_type_p (TRAIT_EXPR_TYPE1 (t1), TRAIT_EXPR_TYPE1 (t2)) | |
2203 | && same_type_p (TRAIT_EXPR_TYPE2 (t1), TRAIT_EXPR_TYPE2 (t2)); | |
2204 | ||
ab73eba8 JM |
2205 | case CAST_EXPR: |
2206 | case STATIC_CAST_EXPR: | |
2207 | case REINTERPRET_CAST_EXPR: | |
2208 | case CONST_CAST_EXPR: | |
2209 | case DYNAMIC_CAST_EXPR: | |
2210 | case NEW_EXPR: | |
2211 | if (!same_type_p (TREE_TYPE (t1), TREE_TYPE (t2))) | |
2212 | return false; | |
2213 | /* Now compare operands as usual. */ | |
2214 | break; | |
2215 | ||
7f85441b KG |
2216 | default: |
2217 | break; | |
67d743fe MS |
2218 | } |
2219 | ||
2220 | switch (TREE_CODE_CLASS (code1)) | |
2221 | { | |
6615c446 JO |
2222 | case tcc_unary: |
2223 | case tcc_binary: | |
2224 | case tcc_comparison: | |
2225 | case tcc_expression: | |
5039610b | 2226 | case tcc_vl_exp: |
6615c446 JO |
2227 | case tcc_reference: |
2228 | case tcc_statement: | |
aa1826e2 | 2229 | { |
5039610b SL |
2230 | int i, n; |
2231 | ||
2232 | n = TREE_OPERAND_LENGTH (t1); | |
2233 | if (TREE_CODE_CLASS (code1) == tcc_vl_exp | |
2234 | && n != TREE_OPERAND_LENGTH (t2)) | |
2235 | return false; | |
9f63daea | 2236 | |
5039610b | 2237 | for (i = 0; i < n; ++i) |
c8a209ca NS |
2238 | if (!cp_tree_equal (TREE_OPERAND (t1, i), TREE_OPERAND (t2, i))) |
2239 | return false; | |
9f63daea | 2240 | |
c8a209ca | 2241 | return true; |
aa1826e2 | 2242 | } |
9f63daea | 2243 | |
6615c446 | 2244 | case tcc_type: |
c8a209ca | 2245 | return same_type_p (t1, t2); |
6615c446 JO |
2246 | default: |
2247 | gcc_unreachable (); | |
67d743fe | 2248 | } |
6615c446 | 2249 | /* We can get here with --disable-checking. */ |
c8a209ca | 2250 | return false; |
67d743fe | 2251 | } |
73aad9b9 | 2252 | |
d11ad92e MS |
2253 | /* The type of ARG when used as an lvalue. */ |
2254 | ||
2255 | tree | |
b57b79f7 | 2256 | lvalue_type (tree arg) |
d11ad92e | 2257 | { |
2c73f9f5 | 2258 | tree type = TREE_TYPE (arg); |
8cd4c175 | 2259 | return type; |
d11ad92e MS |
2260 | } |
2261 | ||
2262 | /* The type of ARG for printing error messages; denote lvalues with | |
2263 | reference types. */ | |
2264 | ||
2265 | tree | |
b57b79f7 | 2266 | error_type (tree arg) |
d11ad92e MS |
2267 | { |
2268 | tree type = TREE_TYPE (arg); | |
9f63daea | 2269 | |
d11ad92e MS |
2270 | if (TREE_CODE (type) == ARRAY_TYPE) |
2271 | ; | |
08476342 NS |
2272 | else if (TREE_CODE (type) == ERROR_MARK) |
2273 | ; | |
d11ad92e MS |
2274 | else if (real_lvalue_p (arg)) |
2275 | type = build_reference_type (lvalue_type (arg)); | |
9e1e64ec | 2276 | else if (MAYBE_CLASS_TYPE_P (type)) |
d11ad92e MS |
2277 | type = lvalue_type (arg); |
2278 | ||
2279 | return type; | |
2280 | } | |
eb66be0e MS |
2281 | |
2282 | /* Does FUNCTION use a variable-length argument list? */ | |
2283 | ||
2284 | int | |
58f9752a | 2285 | varargs_function_p (const_tree function) |
eb66be0e | 2286 | { |
f38958e8 | 2287 | return stdarg_p (TREE_TYPE (function)); |
eb66be0e | 2288 | } |
f94ae2f5 JM |
2289 | |
2290 | /* Returns 1 if decl is a member of a class. */ | |
2291 | ||
2292 | int | |
58f9752a | 2293 | member_p (const_tree decl) |
f94ae2f5 | 2294 | { |
58f9752a | 2295 | const_tree const ctx = DECL_CONTEXT (decl); |
2f939d94 | 2296 | return (ctx && TYPE_P (ctx)); |
f94ae2f5 | 2297 | } |
51924768 JM |
2298 | |
2299 | /* Create a placeholder for member access where we don't actually have an | |
2300 | object that the access is against. */ | |
2301 | ||
2302 | tree | |
b57b79f7 | 2303 | build_dummy_object (tree type) |
51924768 | 2304 | { |
44689c12 | 2305 | tree decl = build1 (NOP_EXPR, build_pointer_type (type), void_zero_node); |
dd865ef6 | 2306 | return cp_build_indirect_ref (decl, RO_NULL, tf_warning_or_error); |
51924768 JM |
2307 | } |
2308 | ||
2309 | /* We've gotten a reference to a member of TYPE. Return *this if appropriate, | |
2310 | or a dummy object otherwise. If BINFOP is non-0, it is filled with the | |
2311 | binfo path from current_class_type to TYPE, or 0. */ | |
2312 | ||
2313 | tree | |
b57b79f7 | 2314 | maybe_dummy_object (tree type, tree* binfop) |
51924768 JM |
2315 | { |
2316 | tree decl, context; | |
2db1ab2d | 2317 | tree binfo; |
a6846853 | 2318 | tree current = current_nonlambda_class_type (); |
9f63daea | 2319 | |
a6846853 JM |
2320 | if (current |
2321 | && (binfo = lookup_base (current, type, ba_any, NULL))) | |
2322 | context = current; | |
51924768 JM |
2323 | else |
2324 | { | |
2325 | /* Reference from a nested class member function. */ | |
2326 | context = type; | |
2db1ab2d | 2327 | binfo = TYPE_BINFO (type); |
51924768 JM |
2328 | } |
2329 | ||
2db1ab2d NS |
2330 | if (binfop) |
2331 | *binfop = binfo; | |
9f63daea | 2332 | |
a29e1034 | 2333 | if (current_class_ref && context == current_class_type |
3ebf5204 | 2334 | /* Kludge: Make sure that current_class_type is actually |
0cbd7506 MS |
2335 | correct. It might not be if we're in the middle of |
2336 | tsubst_default_argument. */ | |
a29e1034 JM |
2337 | && same_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (current_class_ref)), |
2338 | current_class_type)) | |
51924768 | 2339 | decl = current_class_ref; |
a6846853 JM |
2340 | else if (current != current_class_type |
2341 | && context == nonlambda_method_basetype ()) | |
2342 | /* In a lambda, need to go through 'this' capture. */ | |
2343 | decl = (cp_build_indirect_ref | |
2344 | ((lambda_expr_this_capture | |
2345 | (CLASSTYPE_LAMBDA_EXPR (current_class_type))), | |
2346 | RO_NULL, tf_warning_or_error)); | |
51924768 JM |
2347 | else |
2348 | decl = build_dummy_object (context); | |
2349 | ||
2350 | return decl; | |
2351 | } | |
2352 | ||
2353 | /* Returns 1 if OB is a placeholder object, or a pointer to one. */ | |
2354 | ||
2355 | int | |
58f9752a | 2356 | is_dummy_object (const_tree ob) |
51924768 JM |
2357 | { |
2358 | if (TREE_CODE (ob) == INDIRECT_REF) | |
2359 | ob = TREE_OPERAND (ob, 0); | |
2360 | return (TREE_CODE (ob) == NOP_EXPR | |
44689c12 | 2361 | && TREE_OPERAND (ob, 0) == void_zero_node); |
51924768 | 2362 | } |
5524676d | 2363 | |
c32097d8 JM |
2364 | /* Returns 1 iff type T is something we want to treat as a scalar type for |
2365 | the purpose of deciding whether it is trivial/POD/standard-layout. */ | |
2366 | ||
2367 | static bool | |
2368 | scalarish_type_p (const_tree t) | |
2369 | { | |
2370 | if (t == error_mark_node) | |
2371 | return 1; | |
2372 | ||
2373 | return (SCALAR_TYPE_P (t) | |
2374 | || TREE_CODE (t) == VECTOR_TYPE); | |
2375 | } | |
2376 | ||
2377 | /* Returns true iff T requires non-trivial default initialization. */ | |
2378 | ||
2379 | bool | |
2380 | type_has_nontrivial_default_init (const_tree t) | |
2381 | { | |
2382 | t = strip_array_types (CONST_CAST_TREE (t)); | |
2383 | ||
2384 | if (CLASS_TYPE_P (t)) | |
2385 | return TYPE_HAS_COMPLEX_DFLT (t); | |
2386 | else | |
2387 | return 0; | |
2388 | } | |
2389 | ||
d758e847 JM |
2390 | /* Returns true iff copying an object of type T (including via move |
2391 | constructor) is non-trivial. That is, T has no non-trivial copy | |
2392 | constructors and no non-trivial move constructors. */ | |
c32097d8 JM |
2393 | |
2394 | bool | |
2395 | type_has_nontrivial_copy_init (const_tree t) | |
2396 | { | |
2397 | t = strip_array_types (CONST_CAST_TREE (t)); | |
2398 | ||
2399 | if (CLASS_TYPE_P (t)) | |
d758e847 JM |
2400 | { |
2401 | gcc_assert (COMPLETE_TYPE_P (t)); | |
2402 | return ((TYPE_HAS_COPY_CTOR (t) | |
2403 | && TYPE_HAS_COMPLEX_COPY_CTOR (t)) | |
2404 | || TYPE_HAS_COMPLEX_MOVE_CTOR (t)); | |
2405 | } | |
c32097d8 JM |
2406 | else |
2407 | return 0; | |
2408 | } | |
2409 | ||
46408846 JM |
2410 | /* Returns 1 iff type T is a trivially copyable type, as defined in |
2411 | [basic.types] and [class]. */ | |
c32097d8 JM |
2412 | |
2413 | bool | |
46408846 | 2414 | trivially_copyable_p (const_tree t) |
c32097d8 JM |
2415 | { |
2416 | t = strip_array_types (CONST_CAST_TREE (t)); | |
2417 | ||
2418 | if (CLASS_TYPE_P (t)) | |
d758e847 JM |
2419 | return ((!TYPE_HAS_COPY_CTOR (t) |
2420 | || !TYPE_HAS_COMPLEX_COPY_CTOR (t)) | |
2421 | && !TYPE_HAS_COMPLEX_MOVE_CTOR (t) | |
2422 | && (!TYPE_HAS_COPY_ASSIGN (t) | |
2423 | || !TYPE_HAS_COMPLEX_COPY_ASSIGN (t)) | |
2424 | && !TYPE_HAS_COMPLEX_MOVE_ASSIGN (t) | |
334738b4 | 2425 | && TYPE_HAS_TRIVIAL_DESTRUCTOR (t)); |
c32097d8 JM |
2426 | else |
2427 | return scalarish_type_p (t); | |
2428 | } | |
2429 | ||
46408846 JM |
2430 | /* Returns 1 iff type T is a trivial type, as defined in [basic.types] and |
2431 | [class]. */ | |
2432 | ||
2433 | bool | |
2434 | trivial_type_p (const_tree t) | |
2435 | { | |
2436 | t = strip_array_types (CONST_CAST_TREE (t)); | |
2437 | ||
2438 | if (CLASS_TYPE_P (t)) | |
2439 | return (TYPE_HAS_TRIVIAL_DFLT (t) | |
2440 | && trivially_copyable_p (t)); | |
2441 | else | |
2442 | return scalarish_type_p (t); | |
2443 | } | |
2444 | ||
5524676d JM |
2445 | /* Returns 1 iff type T is a POD type, as defined in [basic.types]. */ |
2446 | ||
c32097d8 | 2447 | bool |
58f9752a | 2448 | pod_type_p (const_tree t) |
5524676d | 2449 | { |
4e9b57fa | 2450 | /* This CONST_CAST is okay because strip_array_types returns its |
75547801 | 2451 | argument unmodified and we assign it to a const_tree. */ |
b1d5455a | 2452 | t = strip_array_types (CONST_CAST_TREE(t)); |
5524676d | 2453 | |
cc72bbaa JM |
2454 | if (!CLASS_TYPE_P (t)) |
2455 | return scalarish_type_p (t); | |
2456 | else if (cxx_dialect > cxx98) | |
c32097d8 JM |
2457 | /* [class]/10: A POD struct is a class that is both a trivial class and a |
2458 | standard-layout class, and has no non-static data members of type | |
2459 | non-POD struct, non-POD union (or array of such types). | |
2460 | ||
2461 | We don't need to check individual members because if a member is | |
2462 | non-std-layout or non-trivial, the class will be too. */ | |
2463 | return (std_layout_type_p (t) && trivial_type_p (t)); | |
2464 | else | |
cc72bbaa JM |
2465 | /* The C++98 definition of POD is different. */ |
2466 | return !CLASSTYPE_NON_LAYOUT_POD_P (t); | |
c32097d8 JM |
2467 | } |
2468 | ||
2469 | /* Returns true iff T is POD for the purpose of layout, as defined in the | |
2470 | C++ ABI. */ | |
2471 | ||
2472 | bool | |
2473 | layout_pod_type_p (const_tree t) | |
2474 | { | |
2475 | t = strip_array_types (CONST_CAST_TREE (t)); | |
2476 | ||
2477 | if (CLASS_TYPE_P (t)) | |
2478 | return !CLASSTYPE_NON_LAYOUT_POD_P (t); | |
2479 | else | |
2480 | return scalarish_type_p (t); | |
2481 | } | |
2482 | ||
2483 | /* Returns true iff T is a standard-layout type, as defined in | |
2484 | [basic.types]. */ | |
2485 | ||
2486 | bool | |
2487 | std_layout_type_p (const_tree t) | |
2488 | { | |
2489 | t = strip_array_types (CONST_CAST_TREE (t)); | |
2490 | ||
2491 | if (CLASS_TYPE_P (t)) | |
2492 | return !CLASSTYPE_NON_STD_LAYOUT (t); | |
2493 | else | |
2494 | return scalarish_type_p (t); | |
5524676d | 2495 | } |
e5dc5fb2 | 2496 | |
39ef6592 LC |
2497 | /* Nonzero iff type T is a class template implicit specialization. */ |
2498 | ||
2499 | bool | |
ac7d7749 | 2500 | class_tmpl_impl_spec_p (const_tree t) |
39ef6592 LC |
2501 | { |
2502 | return CLASS_TYPE_P (t) && CLASSTYPE_TEMPLATE_INSTANTIATION (t); | |
2503 | } | |
2504 | ||
94e6e4c4 AO |
2505 | /* Returns 1 iff zero initialization of type T means actually storing |
2506 | zeros in it. */ | |
2507 | ||
2508 | int | |
58f9752a | 2509 | zero_init_p (const_tree t) |
94e6e4c4 | 2510 | { |
4e9b57fa | 2511 | /* This CONST_CAST is okay because strip_array_types returns its |
75547801 | 2512 | argument unmodified and we assign it to a const_tree. */ |
b1d5455a | 2513 | t = strip_array_types (CONST_CAST_TREE(t)); |
94e6e4c4 | 2514 | |
17bbb839 MM |
2515 | if (t == error_mark_node) |
2516 | return 1; | |
2517 | ||
94e6e4c4 AO |
2518 | /* NULL pointers to data members are initialized with -1. */ |
2519 | if (TYPE_PTRMEM_P (t)) | |
2520 | return 0; | |
2521 | ||
2522 | /* Classes that contain types that can't be zero-initialized, cannot | |
2523 | be zero-initialized themselves. */ | |
2524 | if (CLASS_TYPE_P (t) && CLASSTYPE_NON_ZERO_INIT_P (t)) | |
2525 | return 0; | |
2526 | ||
2527 | return 1; | |
2528 | } | |
2529 | ||
91d231cb | 2530 | /* Table of valid C++ attributes. */ |
349ae713 | 2531 | const struct attribute_spec cxx_attribute_table[] = |
e5dc5fb2 | 2532 | { |
91d231cb JM |
2533 | /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */ |
2534 | { "java_interface", 0, 0, false, false, false, handle_java_interface_attribute }, | |
2535 | { "com_interface", 0, 0, false, false, false, handle_com_interface_attribute }, | |
2536 | { "init_priority", 1, 1, true, false, false, handle_init_priority_attribute }, | |
0cbd7506 | 2537 | { NULL, 0, 0, false, false, false, NULL } |
91d231cb JM |
2538 | }; |
2539 | ||
2540 | /* Handle a "java_interface" attribute; arguments as in | |
2541 | struct attribute_spec.handler. */ | |
2542 | static tree | |
9f63daea | 2543 | handle_java_interface_attribute (tree* node, |
0cbd7506 MS |
2544 | tree name, |
2545 | tree args ATTRIBUTE_UNUSED , | |
2546 | int flags, | |
2547 | bool* no_add_attrs) | |
91d231cb JM |
2548 | { |
2549 | if (DECL_P (*node) | |
2550 | || !CLASS_TYPE_P (*node) | |
2551 | || !TYPE_FOR_JAVA (*node)) | |
60c87482 | 2552 | { |
a82e1a7d | 2553 | error ("%qE attribute can only be applied to Java class definitions", |
4460cef2 | 2554 | name); |
91d231cb JM |
2555 | *no_add_attrs = true; |
2556 | return NULL_TREE; | |
60c87482 | 2557 | } |
91d231cb | 2558 | if (!(flags & (int) ATTR_FLAG_TYPE_IN_PLACE)) |
8dd16ecc | 2559 | *node = build_variant_type_copy (*node); |
91d231cb | 2560 | TYPE_JAVA_INTERFACE (*node) = 1; |
e5dc5fb2 | 2561 | |
91d231cb JM |
2562 | return NULL_TREE; |
2563 | } | |
2564 | ||
2565 | /* Handle a "com_interface" attribute; arguments as in | |
2566 | struct attribute_spec.handler. */ | |
2567 | static tree | |
9f63daea | 2568 | handle_com_interface_attribute (tree* node, |
0cbd7506 MS |
2569 | tree name, |
2570 | tree args ATTRIBUTE_UNUSED , | |
2571 | int flags ATTRIBUTE_UNUSED , | |
2572 | bool* no_add_attrs) | |
91d231cb JM |
2573 | { |
2574 | static int warned; | |
2575 | ||
2576 | *no_add_attrs = true; | |
2577 | ||
2578 | if (DECL_P (*node) | |
2579 | || !CLASS_TYPE_P (*node) | |
2580 | || *node != TYPE_MAIN_VARIANT (*node)) | |
e5dc5fb2 | 2581 | { |
5c498b10 DD |
2582 | warning (OPT_Wattributes, "%qE attribute can only be applied " |
2583 | "to class definitions", name); | |
91d231cb JM |
2584 | return NULL_TREE; |
2585 | } | |
e5dc5fb2 | 2586 | |
91d231cb | 2587 | if (!warned++) |
d4ee4d25 | 2588 | warning (0, "%qE is obsolete; g++ vtables are now COM-compatible by default", |
4460cef2 | 2589 | name); |
91d231cb JM |
2590 | |
2591 | return NULL_TREE; | |
2592 | } | |
2593 | ||
2594 | /* Handle an "init_priority" attribute; arguments as in | |
2595 | struct attribute_spec.handler. */ | |
2596 | static tree | |
9f63daea | 2597 | handle_init_priority_attribute (tree* node, |
0cbd7506 MS |
2598 | tree name, |
2599 | tree args, | |
2600 | int flags ATTRIBUTE_UNUSED , | |
2601 | bool* no_add_attrs) | |
91d231cb JM |
2602 | { |
2603 | tree initp_expr = TREE_VALUE (args); | |
2604 | tree decl = *node; | |
2605 | tree type = TREE_TYPE (decl); | |
2606 | int pri; | |
2607 | ||
2608 | STRIP_NOPS (initp_expr); | |
9f63daea | 2609 | |
91d231cb JM |
2610 | if (!initp_expr || TREE_CODE (initp_expr) != INTEGER_CST) |
2611 | { | |
2612 | error ("requested init_priority is not an integer constant"); | |
2613 | *no_add_attrs = true; | |
2614 | return NULL_TREE; | |
2615 | } | |
e5dc5fb2 | 2616 | |
91d231cb | 2617 | pri = TREE_INT_CST_LOW (initp_expr); |
9f63daea | 2618 | |
91d231cb JM |
2619 | type = strip_array_types (type); |
2620 | ||
2621 | if (decl == NULL_TREE | |
2622 | || TREE_CODE (decl) != VAR_DECL | |
2623 | || !TREE_STATIC (decl) | |
2624 | || DECL_EXTERNAL (decl) | |
2625 | || (TREE_CODE (type) != RECORD_TYPE | |
2626 | && TREE_CODE (type) != UNION_TYPE) | |
2627 | /* Static objects in functions are initialized the | |
2628 | first time control passes through that | |
2629 | function. This is not precise enough to pin down an | |
c6002625 | 2630 | init_priority value, so don't allow it. */ |
9f63daea | 2631 | || current_function_decl) |
91d231cb | 2632 | { |
a82e1a7d | 2633 | error ("can only use %qE attribute on file-scope definitions " |
0cbd7506 | 2634 | "of objects of class type", name); |
91d231cb JM |
2635 | *no_add_attrs = true; |
2636 | return NULL_TREE; | |
2637 | } | |
e5dc5fb2 | 2638 | |
91d231cb JM |
2639 | if (pri > MAX_INIT_PRIORITY || pri <= 0) |
2640 | { | |
2641 | error ("requested init_priority is out of range"); | |
2642 | *no_add_attrs = true; | |
2643 | return NULL_TREE; | |
2644 | } | |
e5dc5fb2 | 2645 | |
91d231cb JM |
2646 | /* Check for init_priorities that are reserved for |
2647 | language and runtime support implementations.*/ | |
2648 | if (pri <= MAX_RESERVED_INIT_PRIORITY) | |
2649 | { | |
9f63daea | 2650 | warning |
d4ee4d25 | 2651 | (0, "requested init_priority is reserved for internal use"); |
e5dc5fb2 JM |
2652 | } |
2653 | ||
91d231cb JM |
2654 | if (SUPPORTS_INIT_PRIORITY) |
2655 | { | |
820cc88f DB |
2656 | SET_DECL_INIT_PRIORITY (decl, pri); |
2657 | DECL_HAS_INIT_PRIORITY_P (decl) = 1; | |
91d231cb JM |
2658 | return NULL_TREE; |
2659 | } | |
2660 | else | |
2661 | { | |
a82e1a7d | 2662 | error ("%qE attribute is not supported on this platform", name); |
91d231cb JM |
2663 | *no_add_attrs = true; |
2664 | return NULL_TREE; | |
2665 | } | |
e5dc5fb2 | 2666 | } |
87533b37 MM |
2667 | |
2668 | /* Return a new PTRMEM_CST of the indicated TYPE. The MEMBER is the | |
2669 | thing pointed to by the constant. */ | |
2670 | ||
2671 | tree | |
b57b79f7 | 2672 | make_ptrmem_cst (tree type, tree member) |
87533b37 MM |
2673 | { |
2674 | tree ptrmem_cst = make_node (PTRMEM_CST); | |
87533b37 MM |
2675 | TREE_TYPE (ptrmem_cst) = type; |
2676 | PTRMEM_CST_MEMBER (ptrmem_cst) = member; | |
2677 | return ptrmem_cst; | |
2678 | } | |
2679 | ||
e9525111 | 2680 | /* Build a variant of TYPE that has the indicated ATTRIBUTES. May |
51035976 | 2681 | return an existing type if an appropriate type already exists. */ |
e9525111 MM |
2682 | |
2683 | tree | |
2684 | cp_build_type_attribute_variant (tree type, tree attributes) | |
2685 | { | |
2686 | tree new_type; | |
2687 | ||
2688 | new_type = build_type_attribute_variant (type, attributes); | |
3a55fb4c JM |
2689 | if (TREE_CODE (new_type) == FUNCTION_TYPE |
2690 | || TREE_CODE (new_type) == METHOD_TYPE) | |
e9525111 MM |
2691 | new_type = build_exception_variant (new_type, |
2692 | TYPE_RAISES_EXCEPTIONS (type)); | |
8e30dcf3 JM |
2693 | |
2694 | /* Making a new main variant of a class type is broken. */ | |
2695 | gcc_assert (!CLASS_TYPE_P (type) || new_type == type); | |
2696 | ||
e9525111 MM |
2697 | return new_type; |
2698 | } | |
2699 | ||
2dff8956 JJ |
2700 | /* Return TRUE if TYPE1 and TYPE2 are identical for type hashing purposes. |
2701 | Called only after doing all language independent checks. Only | |
2702 | to check TYPE_RAISES_EXCEPTIONS for FUNCTION_TYPE, the rest is already | |
2703 | compared in type_hash_eq. */ | |
2704 | ||
2705 | bool | |
2706 | cxx_type_hash_eq (const_tree typea, const_tree typeb) | |
2707 | { | |
2708 | gcc_assert (TREE_CODE (typea) == FUNCTION_TYPE); | |
2709 | ||
2710 | return comp_except_specs (TYPE_RAISES_EXCEPTIONS (typea), | |
3a55fb4c | 2711 | TYPE_RAISES_EXCEPTIONS (typeb), ce_exact); |
2dff8956 JJ |
2712 | } |
2713 | ||
25af8512 | 2714 | /* Apply FUNC to all language-specific sub-trees of TP in a pre-order |
350fae66 | 2715 | traversal. Called from walk_tree. */ |
25af8512 | 2716 | |
9f63daea | 2717 | tree |
350fae66 | 2718 | cp_walk_subtrees (tree *tp, int *walk_subtrees_p, walk_tree_fn func, |
0c58f841 | 2719 | void *data, struct pointer_set_t *pset) |
25af8512 AO |
2720 | { |
2721 | enum tree_code code = TREE_CODE (*tp); | |
2722 | tree result; | |
9f63daea | 2723 | |
25af8512 AO |
2724 | #define WALK_SUBTREE(NODE) \ |
2725 | do \ | |
2726 | { \ | |
14588106 | 2727 | result = cp_walk_tree (&(NODE), func, data, pset); \ |
6de9cd9a | 2728 | if (result) goto out; \ |
25af8512 AO |
2729 | } \ |
2730 | while (0) | |
2731 | ||
2732 | /* Not one of the easy cases. We must explicitly go through the | |
2733 | children. */ | |
6de9cd9a | 2734 | result = NULL_TREE; |
25af8512 AO |
2735 | switch (code) |
2736 | { | |
2737 | case DEFAULT_ARG: | |
2738 | case TEMPLATE_TEMPLATE_PARM: | |
2739 | case BOUND_TEMPLATE_TEMPLATE_PARM: | |
b8c6534b | 2740 | case UNBOUND_CLASS_TEMPLATE: |
25af8512 AO |
2741 | case TEMPLATE_PARM_INDEX: |
2742 | case TEMPLATE_TYPE_PARM: | |
2743 | case TYPENAME_TYPE: | |
2744 | case TYPEOF_TYPE: | |
da1d7781 | 2745 | /* None of these have subtrees other than those already walked |
0cbd7506 | 2746 | above. */ |
25af8512 AO |
2747 | *walk_subtrees_p = 0; |
2748 | break; | |
2749 | ||
5d80a306 DG |
2750 | case BASELINK: |
2751 | WALK_SUBTREE (BASELINK_FUNCTIONS (*tp)); | |
2752 | *walk_subtrees_p = 0; | |
2753 | break; | |
2754 | ||
25af8512 AO |
2755 | case PTRMEM_CST: |
2756 | WALK_SUBTREE (TREE_TYPE (*tp)); | |
2757 | *walk_subtrees_p = 0; | |
2758 | break; | |
2759 | ||
2760 | case TREE_LIST: | |
5dae1114 | 2761 | WALK_SUBTREE (TREE_PURPOSE (*tp)); |
25af8512 AO |
2762 | break; |
2763 | ||
2764 | case OVERLOAD: | |
2765 | WALK_SUBTREE (OVL_FUNCTION (*tp)); | |
2766 | WALK_SUBTREE (OVL_CHAIN (*tp)); | |
2767 | *walk_subtrees_p = 0; | |
4439d02f DG |
2768 | break; |
2769 | ||
2770 | case USING_DECL: | |
2771 | WALK_SUBTREE (DECL_NAME (*tp)); | |
2772 | WALK_SUBTREE (USING_DECL_SCOPE (*tp)); | |
2773 | WALK_SUBTREE (USING_DECL_DECLS (*tp)); | |
2774 | *walk_subtrees_p = 0; | |
25af8512 AO |
2775 | break; |
2776 | ||
2777 | case RECORD_TYPE: | |
2778 | if (TYPE_PTRMEMFUNC_P (*tp)) | |
2779 | WALK_SUBTREE (TYPE_PTRMEMFUNC_FN_TYPE (*tp)); | |
2780 | break; | |
2781 | ||
5d80a306 DG |
2782 | case TYPE_ARGUMENT_PACK: |
2783 | case NONTYPE_ARGUMENT_PACK: | |
2784 | { | |
2785 | tree args = ARGUMENT_PACK_ARGS (*tp); | |
2786 | int i, len = TREE_VEC_LENGTH (args); | |
2787 | for (i = 0; i < len; i++) | |
2788 | WALK_SUBTREE (TREE_VEC_ELT (args, i)); | |
2789 | } | |
2790 | break; | |
2791 | ||
2792 | case TYPE_PACK_EXPANSION: | |
2793 | WALK_SUBTREE (TREE_TYPE (*tp)); | |
2794 | *walk_subtrees_p = 0; | |
2795 | break; | |
2796 | ||
2797 | case EXPR_PACK_EXPANSION: | |
2798 | WALK_SUBTREE (TREE_OPERAND (*tp, 0)); | |
2799 | *walk_subtrees_p = 0; | |
2800 | break; | |
2801 | ||
2802 | case CAST_EXPR: | |
a7cbc517 JJ |
2803 | case REINTERPRET_CAST_EXPR: |
2804 | case STATIC_CAST_EXPR: | |
2805 | case CONST_CAST_EXPR: | |
2806 | case DYNAMIC_CAST_EXPR: | |
5d80a306 DG |
2807 | if (TREE_TYPE (*tp)) |
2808 | WALK_SUBTREE (TREE_TYPE (*tp)); | |
2809 | ||
2810 | { | |
2811 | int i; | |
2812 | for (i = 0; i < TREE_CODE_LENGTH (TREE_CODE (*tp)); ++i) | |
2813 | WALK_SUBTREE (TREE_OPERAND (*tp, i)); | |
2814 | } | |
2815 | *walk_subtrees_p = 0; | |
2816 | break; | |
2817 | ||
cb68ec50 PC |
2818 | case TRAIT_EXPR: |
2819 | WALK_SUBTREE (TRAIT_EXPR_TYPE1 (*tp)); | |
2820 | WALK_SUBTREE (TRAIT_EXPR_TYPE2 (*tp)); | |
2821 | *walk_subtrees_p = 0; | |
2822 | break; | |
2823 | ||
3ad6a8e1 DG |
2824 | case DECLTYPE_TYPE: |
2825 | WALK_SUBTREE (DECLTYPE_TYPE_EXPR (*tp)); | |
2826 | *walk_subtrees_p = 0; | |
2827 | break; | |
2828 | ||
2829 | ||
25af8512 | 2830 | default: |
350fae66 | 2831 | return NULL_TREE; |
25af8512 AO |
2832 | } |
2833 | ||
2834 | /* We didn't find what we were looking for. */ | |
6de9cd9a | 2835 | out: |
6de9cd9a | 2836 | return result; |
25af8512 AO |
2837 | |
2838 | #undef WALK_SUBTREE | |
2839 | } | |
2840 | ||
b655f214 MM |
2841 | /* Like save_expr, but for C++. */ |
2842 | ||
2843 | tree | |
2844 | cp_save_expr (tree expr) | |
2845 | { | |
2846 | /* There is no reason to create a SAVE_EXPR within a template; if | |
2847 | needed, we can create the SAVE_EXPR when instantiating the | |
2848 | template. Furthermore, the middle-end cannot handle C++-specific | |
2849 | tree codes. */ | |
2850 | if (processing_template_decl) | |
2851 | return expr; | |
2852 | return save_expr (expr); | |
2853 | } | |
2854 | ||
87e3dbc9 MM |
2855 | /* Initialize tree.c. */ |
2856 | ||
0a818f84 | 2857 | void |
b57b79f7 | 2858 | init_tree (void) |
0a818f84 | 2859 | { |
e2500fed | 2860 | list_hash_table = htab_create_ggc (31, list_hash, list_hash_eq, NULL); |
0a818f84 GRK |
2861 | } |
2862 | ||
872f37f9 | 2863 | /* Returns the kind of special function that DECL (a FUNCTION_DECL) |
50ad9642 MM |
2864 | is. Note that sfk_none is zero, so this function can be used as a |
2865 | predicate to test whether or not DECL is a special function. */ | |
872f37f9 MM |
2866 | |
2867 | special_function_kind | |
58f9752a | 2868 | special_function_p (const_tree decl) |
872f37f9 MM |
2869 | { |
2870 | /* Rather than doing all this stuff with magic names, we should | |
2871 | probably have a field of type `special_function_kind' in | |
2872 | DECL_LANG_SPECIFIC. */ | |
2873 | if (DECL_COPY_CONSTRUCTOR_P (decl)) | |
2874 | return sfk_copy_constructor; | |
d5f4eddd JM |
2875 | if (DECL_MOVE_CONSTRUCTOR_P (decl)) |
2876 | return sfk_move_constructor; | |
872f37f9 MM |
2877 | if (DECL_CONSTRUCTOR_P (decl)) |
2878 | return sfk_constructor; | |
596ea4e5 | 2879 | if (DECL_OVERLOADED_OPERATOR_P (decl) == NOP_EXPR) |
ac177431 JM |
2880 | { |
2881 | if (copy_fn_p (decl)) | |
2882 | return sfk_copy_assignment; | |
2883 | if (move_fn_p (decl)) | |
2884 | return sfk_move_assignment; | |
2885 | } | |
872f37f9 MM |
2886 | if (DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (decl)) |
2887 | return sfk_destructor; | |
2888 | if (DECL_COMPLETE_DESTRUCTOR_P (decl)) | |
2889 | return sfk_complete_destructor; | |
2890 | if (DECL_BASE_DESTRUCTOR_P (decl)) | |
2891 | return sfk_base_destructor; | |
2892 | if (DECL_DELETING_DESTRUCTOR_P (decl)) | |
2893 | return sfk_deleting_destructor; | |
2894 | if (DECL_CONV_FN_P (decl)) | |
2895 | return sfk_conversion; | |
2896 | ||
2897 | return sfk_none; | |
2898 | } | |
7b019c19 | 2899 | |
838dfd8a | 2900 | /* Returns nonzero if TYPE is a character type, including wchar_t. */ |
7b019c19 MM |
2901 | |
2902 | int | |
b57b79f7 | 2903 | char_type_p (tree type) |
7b019c19 MM |
2904 | { |
2905 | return (same_type_p (type, char_type_node) | |
2906 | || same_type_p (type, unsigned_char_type_node) | |
2907 | || same_type_p (type, signed_char_type_node) | |
b6baa67d KVH |
2908 | || same_type_p (type, char16_type_node) |
2909 | || same_type_p (type, char32_type_node) | |
7b019c19 MM |
2910 | || same_type_p (type, wchar_type_node)); |
2911 | } | |
ad50e811 MM |
2912 | |
2913 | /* Returns the kind of linkage associated with the indicated DECL. Th | |
2914 | value returned is as specified by the language standard; it is | |
2915 | independent of implementation details regarding template | |
2916 | instantiation, etc. For example, it is possible that a declaration | |
2917 | to which this function assigns external linkage would not show up | |
2918 | as a global symbol when you run `nm' on the resulting object file. */ | |
2919 | ||
2920 | linkage_kind | |
b57b79f7 | 2921 | decl_linkage (tree decl) |
ad50e811 MM |
2922 | { |
2923 | /* This function doesn't attempt to calculate the linkage from first | |
2924 | principles as given in [basic.link]. Instead, it makes use of | |
2925 | the fact that we have already set TREE_PUBLIC appropriately, and | |
2926 | then handles a few special cases. Ideally, we would calculate | |
2927 | linkage first, and then transform that into a concrete | |
2928 | implementation. */ | |
2929 | ||
2930 | /* Things that don't have names have no linkage. */ | |
2931 | if (!DECL_NAME (decl)) | |
2932 | return lk_none; | |
2933 | ||
c02cdc25 TT |
2934 | /* Fields have no linkage. */ |
2935 | if (TREE_CODE (decl) == FIELD_DECL) | |
2936 | return lk_none; | |
2937 | ||
ad50e811 MM |
2938 | /* Things that are TREE_PUBLIC have external linkage. */ |
2939 | if (TREE_PUBLIC (decl)) | |
2940 | return lk_external; | |
3db45ab5 | 2941 | |
b70f0f48 JM |
2942 | if (TREE_CODE (decl) == NAMESPACE_DECL) |
2943 | return lk_external; | |
2944 | ||
3db45ab5 | 2945 | /* Linkage of a CONST_DECL depends on the linkage of the enumeration |
3f774254 DB |
2946 | type. */ |
2947 | if (TREE_CODE (decl) == CONST_DECL) | |
2948 | return decl_linkage (TYPE_NAME (TREE_TYPE (decl))); | |
ad50e811 MM |
2949 | |
2950 | /* Some things that are not TREE_PUBLIC have external linkage, too. | |
2951 | For example, on targets that don't have weak symbols, we make all | |
2952 | template instantiations have internal linkage (in the object | |
2953 | file), but the symbols should still be treated as having external | |
2954 | linkage from the point of view of the language. */ | |
ad909c97 JM |
2955 | if ((TREE_CODE (decl) == FUNCTION_DECL |
2956 | || TREE_CODE (decl) == VAR_DECL) | |
b9e75696 | 2957 | && DECL_COMDAT (decl)) |
ad50e811 MM |
2958 | return lk_external; |
2959 | ||
2960 | /* Things in local scope do not have linkage, if they don't have | |
2961 | TREE_PUBLIC set. */ | |
2962 | if (decl_function_context (decl)) | |
2963 | return lk_none; | |
2964 | ||
b70f0f48 JM |
2965 | /* Members of the anonymous namespace also have TREE_PUBLIC unset, but |
2966 | are considered to have external linkage for language purposes. DECLs | |
2967 | really meant to have internal linkage have DECL_THIS_STATIC set. */ | |
ce41114b | 2968 | if (TREE_CODE (decl) == TYPE_DECL) |
b70f0f48 | 2969 | return lk_external; |
ce41114b JJ |
2970 | if (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == FUNCTION_DECL) |
2971 | { | |
2972 | if (!DECL_THIS_STATIC (decl)) | |
2973 | return lk_external; | |
2974 | ||
2975 | /* Static data members and static member functions from classes | |
2976 | in anonymous namespace also don't have TREE_PUBLIC set. */ | |
2977 | if (DECL_CLASS_CONTEXT (decl)) | |
2978 | return lk_external; | |
2979 | } | |
b70f0f48 | 2980 | |
ad50e811 MM |
2981 | /* Everything else has internal linkage. */ |
2982 | return lk_internal; | |
2983 | } | |
6f30f1f1 | 2984 | \f |
9beafc83 MM |
2985 | /* EXP is an expression that we want to pre-evaluate. Returns (in |
2986 | *INITP) an expression that will perform the pre-evaluation. The | |
2987 | value returned by this function is a side-effect free expression | |
2988 | equivalent to the pre-evaluated expression. Callers must ensure | |
2989 | that *INITP is evaluated before EXP. */ | |
6f30f1f1 JM |
2990 | |
2991 | tree | |
b57b79f7 | 2992 | stabilize_expr (tree exp, tree* initp) |
6f30f1f1 JM |
2993 | { |
2994 | tree init_expr; | |
2995 | ||
2996 | if (!TREE_SIDE_EFFECTS (exp)) | |
9beafc83 | 2997 | init_expr = NULL_TREE; |
6f30f1f1 JM |
2998 | else if (!real_lvalue_p (exp) |
2999 | || !TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (exp))) | |
3000 | { | |
3001 | init_expr = get_target_expr (exp); | |
3002 | exp = TARGET_EXPR_SLOT (init_expr); | |
3003 | } | |
3004 | else | |
3005 | { | |
5ade1ed2 | 3006 | exp = cp_build_unary_op (ADDR_EXPR, exp, 1, tf_warning_or_error); |
6f30f1f1 JM |
3007 | init_expr = get_target_expr (exp); |
3008 | exp = TARGET_EXPR_SLOT (init_expr); | |
dd865ef6 | 3009 | exp = cp_build_indirect_ref (exp, RO_NULL, tf_warning_or_error); |
6f30f1f1 | 3010 | } |
6f30f1f1 | 3011 | *initp = init_expr; |
9beafc83 MM |
3012 | |
3013 | gcc_assert (!TREE_SIDE_EFFECTS (exp)); | |
6f30f1f1 JM |
3014 | return exp; |
3015 | } | |
6de9cd9a | 3016 | |
be93747e | 3017 | /* Add NEW_EXPR, an expression whose value we don't care about, after the |
40aac948 JM |
3018 | similar expression ORIG. */ |
3019 | ||
3020 | tree | |
be93747e | 3021 | add_stmt_to_compound (tree orig, tree new_expr) |
40aac948 | 3022 | { |
be93747e | 3023 | if (!new_expr || !TREE_SIDE_EFFECTS (new_expr)) |
40aac948 JM |
3024 | return orig; |
3025 | if (!orig || !TREE_SIDE_EFFECTS (orig)) | |
be93747e KG |
3026 | return new_expr; |
3027 | return build2 (COMPOUND_EXPR, void_type_node, orig, new_expr); | |
40aac948 JM |
3028 | } |
3029 | ||
9beafc83 MM |
3030 | /* Like stabilize_expr, but for a call whose arguments we want to |
3031 | pre-evaluate. CALL is modified in place to use the pre-evaluated | |
3032 | arguments, while, upon return, *INITP contains an expression to | |
3033 | compute the arguments. */ | |
6de9cd9a DN |
3034 | |
3035 | void | |
3036 | stabilize_call (tree call, tree *initp) | |
3037 | { | |
3038 | tree inits = NULL_TREE; | |
5039610b SL |
3039 | int i; |
3040 | int nargs = call_expr_nargs (call); | |
6de9cd9a | 3041 | |
28267cfc JJ |
3042 | if (call == error_mark_node || processing_template_decl) |
3043 | { | |
3044 | *initp = NULL_TREE; | |
3045 | return; | |
3046 | } | |
6de9cd9a | 3047 | |
5039610b | 3048 | gcc_assert (TREE_CODE (call) == CALL_EXPR); |
6de9cd9a | 3049 | |
5039610b SL |
3050 | for (i = 0; i < nargs; i++) |
3051 | { | |
3052 | tree init; | |
3053 | CALL_EXPR_ARG (call, i) = | |
3054 | stabilize_expr (CALL_EXPR_ARG (call, i), &init); | |
3055 | inits = add_stmt_to_compound (inits, init); | |
3056 | } | |
3057 | ||
3058 | *initp = inits; | |
3059 | } | |
3060 | ||
3061 | /* Like stabilize_expr, but for an AGGR_INIT_EXPR whose arguments we want | |
3062 | to pre-evaluate. CALL is modified in place to use the pre-evaluated | |
3063 | arguments, while, upon return, *INITP contains an expression to | |
3064 | compute the arguments. */ | |
3065 | ||
3066 | void | |
3067 | stabilize_aggr_init (tree call, tree *initp) | |
3068 | { | |
3069 | tree inits = NULL_TREE; | |
3070 | int i; | |
3071 | int nargs = aggr_init_expr_nargs (call); | |
3072 | ||
3073 | if (call == error_mark_node) | |
3074 | return; | |
3075 | ||
3076 | gcc_assert (TREE_CODE (call) == AGGR_INIT_EXPR); | |
3077 | ||
3078 | for (i = 0; i < nargs; i++) | |
3079 | { | |
3080 | tree init; | |
3081 | AGGR_INIT_EXPR_ARG (call, i) = | |
3082 | stabilize_expr (AGGR_INIT_EXPR_ARG (call, i), &init); | |
3083 | inits = add_stmt_to_compound (inits, init); | |
3084 | } | |
6de9cd9a DN |
3085 | |
3086 | *initp = inits; | |
3087 | } | |
3088 | ||
9beafc83 MM |
3089 | /* Like stabilize_expr, but for an initialization. |
3090 | ||
3091 | If the initialization is for an object of class type, this function | |
3092 | takes care not to introduce additional temporaries. | |
3093 | ||
3094 | Returns TRUE iff the expression was successfully pre-evaluated, | |
3095 | i.e., if INIT is now side-effect free, except for, possible, a | |
3096 | single call to a constructor. */ | |
6de9cd9a DN |
3097 | |
3098 | bool | |
3099 | stabilize_init (tree init, tree *initp) | |
3100 | { | |
3101 | tree t = init; | |
3102 | ||
9beafc83 MM |
3103 | *initp = NULL_TREE; |
3104 | ||
28267cfc | 3105 | if (t == error_mark_node || processing_template_decl) |
6de9cd9a DN |
3106 | return true; |
3107 | ||
3108 | if (TREE_CODE (t) == INIT_EXPR | |
844ae01d JM |
3109 | && TREE_CODE (TREE_OPERAND (t, 1)) != TARGET_EXPR |
3110 | && TREE_CODE (TREE_OPERAND (t, 1)) != AGGR_INIT_EXPR) | |
6de9cd9a | 3111 | { |
9beafc83 MM |
3112 | TREE_OPERAND (t, 1) = stabilize_expr (TREE_OPERAND (t, 1), initp); |
3113 | return true; | |
3114 | } | |
6de9cd9a | 3115 | |
9beafc83 MM |
3116 | if (TREE_CODE (t) == INIT_EXPR) |
3117 | t = TREE_OPERAND (t, 1); | |
3118 | if (TREE_CODE (t) == TARGET_EXPR) | |
3119 | t = TARGET_EXPR_INITIAL (t); | |
3120 | if (TREE_CODE (t) == COMPOUND_EXPR) | |
3121 | t = expr_last (t); | |
3122 | if (TREE_CODE (t) == CONSTRUCTOR | |
3123 | && EMPTY_CONSTRUCTOR_P (t)) | |
3124 | /* Default-initialization. */ | |
3125 | return true; | |
3126 | ||
3127 | /* If the initializer is a COND_EXPR, we can't preevaluate | |
3128 | anything. */ | |
3129 | if (TREE_CODE (t) == COND_EXPR) | |
3130 | return false; | |
6de9cd9a | 3131 | |
5039610b | 3132 | if (TREE_CODE (t) == CALL_EXPR) |
9beafc83 MM |
3133 | { |
3134 | stabilize_call (t, initp); | |
3135 | return true; | |
6de9cd9a DN |
3136 | } |
3137 | ||
5039610b SL |
3138 | if (TREE_CODE (t) == AGGR_INIT_EXPR) |
3139 | { | |
3140 | stabilize_aggr_init (t, initp); | |
3141 | return true; | |
3142 | } | |
3143 | ||
9beafc83 MM |
3144 | /* The initialization is being performed via a bitwise copy -- and |
3145 | the item copied may have side effects. */ | |
3146 | return TREE_SIDE_EFFECTS (init); | |
6de9cd9a DN |
3147 | } |
3148 | ||
455f19cb MM |
3149 | /* Like "fold", but should be used whenever we might be processing the |
3150 | body of a template. */ | |
3151 | ||
3152 | tree | |
3153 | fold_if_not_in_template (tree expr) | |
3154 | { | |
3155 | /* In the body of a template, there is never any need to call | |
3156 | "fold". We will call fold later when actually instantiating the | |
3157 | template. Integral constant expressions in templates will be | |
f9f1c24e | 3158 | evaluated via fold_non_dependent_expr, as necessary. */ |
392e3d51 RS |
3159 | if (processing_template_decl) |
3160 | return expr; | |
3161 | ||
3162 | /* Fold C++ front-end specific tree codes. */ | |
3163 | if (TREE_CODE (expr) == UNARY_PLUS_EXPR) | |
3164 | return fold_convert (TREE_TYPE (expr), TREE_OPERAND (expr, 0)); | |
3165 | ||
3166 | return fold (expr); | |
455f19cb MM |
3167 | } |
3168 | ||
015c2c66 MM |
3169 | /* Returns true if a cast to TYPE may appear in an integral constant |
3170 | expression. */ | |
3171 | ||
3172 | bool | |
3173 | cast_valid_in_integral_constant_expression_p (tree type) | |
3174 | { | |
3175 | return (INTEGRAL_OR_ENUMERATION_TYPE_P (type) | |
3176 | || dependent_type_p (type) | |
3177 | || type == error_mark_node); | |
3178 | } | |
3179 | ||
4537ec0c DN |
3180 | /* Return true if we need to fix linkage information of DECL. */ |
3181 | ||
3182 | static bool | |
3183 | cp_fix_function_decl_p (tree decl) | |
3184 | { | |
3185 | /* Skip if DECL is not externally visible. */ | |
3186 | if (!TREE_PUBLIC (decl)) | |
3187 | return false; | |
3188 | ||
3189 | /* We need to fix DECL if it a appears to be exported but with no | |
3190 | function body. Thunks do not have CFGs and we may need to | |
3191 | handle them specially later. */ | |
3192 | if (!gimple_has_body_p (decl) | |
3193 | && !DECL_THUNK_P (decl) | |
3194 | && !DECL_EXTERNAL (decl)) | |
87501227 JJ |
3195 | { |
3196 | struct cgraph_node *node = cgraph_get_node (decl); | |
3197 | ||
3198 | /* Don't fix same_body aliases. Although they don't have their own | |
3199 | CFG, they share it with what they alias to. */ | |
3200 | if (!node | |
3201 | || node->decl == decl | |
3202 | || !node->same_body) | |
3203 | return true; | |
3204 | } | |
4537ec0c DN |
3205 | |
3206 | return false; | |
3207 | } | |
3208 | ||
3209 | /* Clean the C++ specific parts of the tree T. */ | |
3210 | ||
3211 | void | |
3212 | cp_free_lang_data (tree t) | |
3213 | { | |
3214 | if (TREE_CODE (t) == METHOD_TYPE | |
3215 | || TREE_CODE (t) == FUNCTION_TYPE) | |
3216 | { | |
3217 | /* Default args are not interesting anymore. */ | |
3218 | tree argtypes = TYPE_ARG_TYPES (t); | |
3219 | while (argtypes) | |
3220 | { | |
3221 | TREE_PURPOSE (argtypes) = 0; | |
3222 | argtypes = TREE_CHAIN (argtypes); | |
3223 | } | |
3224 | } | |
3225 | else if (TREE_CODE (t) == FUNCTION_DECL | |
3226 | && cp_fix_function_decl_p (t)) | |
3227 | { | |
3228 | /* If T is used in this translation unit at all, the definition | |
3229 | must exist somewhere else since we have decided to not emit it | |
3230 | in this TU. So make it an external reference. */ | |
3231 | DECL_EXTERNAL (t) = 1; | |
3232 | TREE_STATIC (t) = 0; | |
3233 | } | |
652a8c1c RG |
3234 | if (CP_AGGREGATE_TYPE_P (t) |
3235 | && TYPE_NAME (t)) | |
3236 | { | |
3237 | tree name = TYPE_NAME (t); | |
3238 | if (TREE_CODE (name) == TYPE_DECL) | |
3239 | name = DECL_NAME (name); | |
3240 | /* Drop anonymous names. */ | |
3241 | if (name != NULL_TREE | |
3242 | && ANON_AGGRNAME_P (name)) | |
3243 | TYPE_NAME (t) = NULL_TREE; | |
3244 | } | |
4537ec0c DN |
3245 | } |
3246 | ||
bffad7f1 SB |
3247 | /* Stub for c-common. Please keep in sync with c-decl.c. |
3248 | FIXME: If address space support is target specific, then this | |
3249 | should be a C target hook. But currently this is not possible, | |
3250 | because this function is called via REGISTER_TARGET_PRAGMAS. */ | |
3251 | void | |
3252 | c_register_addr_space (const char *word ATTRIBUTE_UNUSED, | |
3253 | addr_space_t as ATTRIBUTE_UNUSED) | |
3254 | { | |
3255 | } | |
3256 | ||
e2500fed GK |
3257 | \f |
3258 | #if defined ENABLE_TREE_CHECKING && (GCC_VERSION >= 2007) | |
3259 | /* Complain that some language-specific thing hanging off a tree | |
3260 | node has been accessed improperly. */ | |
3261 | ||
3262 | void | |
b57b79f7 | 3263 | lang_check_failed (const char* file, int line, const char* function) |
e2500fed GK |
3264 | { |
3265 | internal_error ("lang_* check: failed in %s, at %s:%d", | |
3266 | function, trim_filename (file), line); | |
3267 | } | |
3268 | #endif /* ENABLE_TREE_CHECKING */ | |
3269 | ||
3270 | #include "gt-cp-tree.h" |