1e4b17023SJohn Marino /* Language-dependent node constructors for parse phase of GNU compiler.
2e4b17023SJohn Marino Copyright (C) 1987, 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
35ce9237cSJohn Marino 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010, 2011,
45ce9237cSJohn Marino 2012 Free Software Foundation, Inc.
5e4b17023SJohn Marino Hacked by Michael Tiemann (tiemann@cygnus.com)
6e4b17023SJohn Marino
7e4b17023SJohn Marino This file is part of GCC.
8e4b17023SJohn Marino
9e4b17023SJohn Marino GCC is free software; you can redistribute it and/or modify
10e4b17023SJohn Marino it under the terms of the GNU General Public License as published by
11e4b17023SJohn Marino the Free Software Foundation; either version 3, or (at your option)
12e4b17023SJohn Marino any later version.
13e4b17023SJohn Marino
14e4b17023SJohn Marino GCC is distributed in the hope that it will be useful,
15e4b17023SJohn Marino but WITHOUT ANY WARRANTY; without even the implied warranty of
16e4b17023SJohn Marino MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17e4b17023SJohn Marino GNU General Public License for more details.
18e4b17023SJohn Marino
19e4b17023SJohn Marino You should have received a copy of the GNU General Public License
20e4b17023SJohn Marino along with GCC; see the file COPYING3. If not see
21e4b17023SJohn Marino <http://www.gnu.org/licenses/>. */
22e4b17023SJohn Marino
23e4b17023SJohn Marino #include "config.h"
24e4b17023SJohn Marino #include "system.h"
25e4b17023SJohn Marino #include "coretypes.h"
26e4b17023SJohn Marino #include "tm.h"
27e4b17023SJohn Marino #include "tree.h"
28e4b17023SJohn Marino #include "cp-tree.h"
29e4b17023SJohn Marino #include "flags.h"
30e4b17023SJohn Marino #include "tree-inline.h"
31e4b17023SJohn Marino #include "debug.h"
32e4b17023SJohn Marino #include "convert.h"
33e4b17023SJohn Marino #include "cgraph.h"
34e4b17023SJohn Marino #include "splay-tree.h"
35e4b17023SJohn Marino #include "gimple.h" /* gimple_has_body_p */
36e4b17023SJohn Marino
37e4b17023SJohn Marino static tree bot_manip (tree *, int *, void *);
38e4b17023SJohn Marino static tree bot_replace (tree *, int *, void *);
39e4b17023SJohn Marino static int list_hash_eq (const void *, const void *);
40e4b17023SJohn Marino static hashval_t list_hash_pieces (tree, tree, tree);
41e4b17023SJohn Marino static hashval_t list_hash (const void *);
42e4b17023SJohn Marino static tree build_target_expr (tree, tree, tsubst_flags_t);
43e4b17023SJohn Marino static tree count_trees_r (tree *, int *, void *);
44e4b17023SJohn Marino static tree verify_stmt_tree_r (tree *, int *, void *);
45e4b17023SJohn Marino static tree build_local_temp (tree);
46e4b17023SJohn Marino
47e4b17023SJohn Marino static tree handle_java_interface_attribute (tree *, tree, tree, int, bool *);
48e4b17023SJohn Marino static tree handle_com_interface_attribute (tree *, tree, tree, int, bool *);
49e4b17023SJohn Marino static tree handle_init_priority_attribute (tree *, tree, tree, int, bool *);
50e4b17023SJohn Marino
51e4b17023SJohn Marino /* If REF is an lvalue, returns the kind of lvalue that REF is.
52e4b17023SJohn Marino Otherwise, returns clk_none. */
53e4b17023SJohn Marino
54e4b17023SJohn Marino cp_lvalue_kind
lvalue_kind(const_tree ref)55e4b17023SJohn Marino lvalue_kind (const_tree ref)
56e4b17023SJohn Marino {
57e4b17023SJohn Marino cp_lvalue_kind op1_lvalue_kind = clk_none;
58e4b17023SJohn Marino cp_lvalue_kind op2_lvalue_kind = clk_none;
59e4b17023SJohn Marino
60e4b17023SJohn Marino /* Expressions of reference type are sometimes wrapped in
61e4b17023SJohn Marino INDIRECT_REFs. INDIRECT_REFs are just internal compiler
62e4b17023SJohn Marino representation, not part of the language, so we have to look
63e4b17023SJohn Marino through them. */
64e4b17023SJohn Marino if (REFERENCE_REF_P (ref))
65e4b17023SJohn Marino return lvalue_kind (TREE_OPERAND (ref, 0));
66e4b17023SJohn Marino
67e4b17023SJohn Marino if (TREE_TYPE (ref)
68e4b17023SJohn Marino && TREE_CODE (TREE_TYPE (ref)) == REFERENCE_TYPE)
69e4b17023SJohn Marino {
70e4b17023SJohn Marino /* unnamed rvalue references are rvalues */
71e4b17023SJohn Marino if (TYPE_REF_IS_RVALUE (TREE_TYPE (ref))
72e4b17023SJohn Marino && TREE_CODE (ref) != PARM_DECL
73e4b17023SJohn Marino && TREE_CODE (ref) != VAR_DECL
74e4b17023SJohn Marino && TREE_CODE (ref) != COMPONENT_REF
75e4b17023SJohn Marino /* Functions are always lvalues. */
76e4b17023SJohn Marino && TREE_CODE (TREE_TYPE (TREE_TYPE (ref))) != FUNCTION_TYPE)
77e4b17023SJohn Marino return clk_rvalueref;
78e4b17023SJohn Marino
79e4b17023SJohn Marino /* lvalue references and named rvalue references are lvalues. */
80e4b17023SJohn Marino return clk_ordinary;
81e4b17023SJohn Marino }
82e4b17023SJohn Marino
83e4b17023SJohn Marino if (ref == current_class_ptr)
84e4b17023SJohn Marino return clk_none;
85e4b17023SJohn Marino
86e4b17023SJohn Marino switch (TREE_CODE (ref))
87e4b17023SJohn Marino {
88e4b17023SJohn Marino case SAVE_EXPR:
89e4b17023SJohn Marino return clk_none;
90e4b17023SJohn Marino /* preincrements and predecrements are valid lvals, provided
91e4b17023SJohn Marino what they refer to are valid lvals. */
92e4b17023SJohn Marino case PREINCREMENT_EXPR:
93e4b17023SJohn Marino case PREDECREMENT_EXPR:
94e4b17023SJohn Marino case TRY_CATCH_EXPR:
95e4b17023SJohn Marino case WITH_CLEANUP_EXPR:
96e4b17023SJohn Marino case REALPART_EXPR:
97e4b17023SJohn Marino case IMAGPART_EXPR:
98e4b17023SJohn Marino return lvalue_kind (TREE_OPERAND (ref, 0));
99e4b17023SJohn Marino
100e4b17023SJohn Marino case COMPONENT_REF:
101e4b17023SJohn Marino op1_lvalue_kind = lvalue_kind (TREE_OPERAND (ref, 0));
102e4b17023SJohn Marino /* Look at the member designator. */
103e4b17023SJohn Marino if (!op1_lvalue_kind)
104e4b17023SJohn Marino ;
105e4b17023SJohn Marino else if (is_overloaded_fn (TREE_OPERAND (ref, 1)))
106e4b17023SJohn Marino /* The "field" can be a FUNCTION_DECL or an OVERLOAD in some
107e4b17023SJohn Marino situations. If we're seeing a COMPONENT_REF, it's a non-static
108e4b17023SJohn Marino member, so it isn't an lvalue. */
109e4b17023SJohn Marino op1_lvalue_kind = clk_none;
110e4b17023SJohn Marino else if (TREE_CODE (TREE_OPERAND (ref, 1)) != FIELD_DECL)
111e4b17023SJohn Marino /* This can be IDENTIFIER_NODE in a template. */;
112e4b17023SJohn Marino else if (DECL_C_BIT_FIELD (TREE_OPERAND (ref, 1)))
113e4b17023SJohn Marino {
114e4b17023SJohn Marino /* Clear the ordinary bit. If this object was a class
115e4b17023SJohn Marino rvalue we want to preserve that information. */
116e4b17023SJohn Marino op1_lvalue_kind &= ~clk_ordinary;
117e4b17023SJohn Marino /* The lvalue is for a bitfield. */
118e4b17023SJohn Marino op1_lvalue_kind |= clk_bitfield;
119e4b17023SJohn Marino }
120e4b17023SJohn Marino else if (DECL_PACKED (TREE_OPERAND (ref, 1)))
121e4b17023SJohn Marino op1_lvalue_kind |= clk_packed;
122e4b17023SJohn Marino
123e4b17023SJohn Marino return op1_lvalue_kind;
124e4b17023SJohn Marino
125e4b17023SJohn Marino case STRING_CST:
126e4b17023SJohn Marino case COMPOUND_LITERAL_EXPR:
127e4b17023SJohn Marino return clk_ordinary;
128e4b17023SJohn Marino
129e4b17023SJohn Marino case CONST_DECL:
130e4b17023SJohn Marino /* CONST_DECL without TREE_STATIC are enumeration values and
131e4b17023SJohn Marino thus not lvalues. With TREE_STATIC they are used by ObjC++
132e4b17023SJohn Marino in objc_build_string_object and need to be considered as
133e4b17023SJohn Marino lvalues. */
134e4b17023SJohn Marino if (! TREE_STATIC (ref))
135e4b17023SJohn Marino return clk_none;
136e4b17023SJohn Marino case VAR_DECL:
137e4b17023SJohn Marino if (TREE_READONLY (ref) && ! TREE_STATIC (ref)
138e4b17023SJohn Marino && DECL_LANG_SPECIFIC (ref)
139e4b17023SJohn Marino && DECL_IN_AGGR_P (ref))
140e4b17023SJohn Marino return clk_none;
141e4b17023SJohn Marino case INDIRECT_REF:
142e4b17023SJohn Marino case ARROW_EXPR:
143e4b17023SJohn Marino case ARRAY_REF:
144e4b17023SJohn Marino case PARM_DECL:
145e4b17023SJohn Marino case RESULT_DECL:
146e4b17023SJohn Marino return clk_ordinary;
147e4b17023SJohn Marino
148e4b17023SJohn Marino /* A scope ref in a template, left as SCOPE_REF to support later
149e4b17023SJohn Marino access checking. */
150e4b17023SJohn Marino case SCOPE_REF:
151e4b17023SJohn Marino {
152e4b17023SJohn Marino tree op = TREE_OPERAND (ref, 1);
153e4b17023SJohn Marino /* The member must be an lvalue; assume it isn't a bit-field. */
154e4b17023SJohn Marino if (TREE_CODE (op) == IDENTIFIER_NODE)
155e4b17023SJohn Marino return clk_ordinary;
156e4b17023SJohn Marino gcc_assert (!type_dependent_expression_p (CONST_CAST_TREE (ref)));
157e4b17023SJohn Marino return lvalue_kind (op);
158e4b17023SJohn Marino }
159e4b17023SJohn Marino
160e4b17023SJohn Marino case MAX_EXPR:
161e4b17023SJohn Marino case MIN_EXPR:
162e4b17023SJohn Marino /* Disallow <? and >? as lvalues if either argument side-effects. */
163e4b17023SJohn Marino if (TREE_SIDE_EFFECTS (TREE_OPERAND (ref, 0))
164e4b17023SJohn Marino || TREE_SIDE_EFFECTS (TREE_OPERAND (ref, 1)))
165e4b17023SJohn Marino return clk_none;
166e4b17023SJohn Marino op1_lvalue_kind = lvalue_kind (TREE_OPERAND (ref, 0));
167e4b17023SJohn Marino op2_lvalue_kind = lvalue_kind (TREE_OPERAND (ref, 1));
168e4b17023SJohn Marino break;
169e4b17023SJohn Marino
170e4b17023SJohn Marino case COND_EXPR:
171e4b17023SJohn Marino op1_lvalue_kind = lvalue_kind (TREE_OPERAND (ref, 1)
172e4b17023SJohn Marino ? TREE_OPERAND (ref, 1)
173e4b17023SJohn Marino : TREE_OPERAND (ref, 0));
174e4b17023SJohn Marino op2_lvalue_kind = lvalue_kind (TREE_OPERAND (ref, 2));
175e4b17023SJohn Marino break;
176e4b17023SJohn Marino
177e4b17023SJohn Marino case MODIFY_EXPR:
178e4b17023SJohn Marino case TYPEID_EXPR:
179e4b17023SJohn Marino return clk_ordinary;
180e4b17023SJohn Marino
181e4b17023SJohn Marino case COMPOUND_EXPR:
182e4b17023SJohn Marino return lvalue_kind (TREE_OPERAND (ref, 1));
183e4b17023SJohn Marino
184e4b17023SJohn Marino case TARGET_EXPR:
185e4b17023SJohn Marino return clk_class;
186e4b17023SJohn Marino
187e4b17023SJohn Marino case VA_ARG_EXPR:
188e4b17023SJohn Marino return (CLASS_TYPE_P (TREE_TYPE (ref)) ? clk_class : clk_none);
189e4b17023SJohn Marino
190e4b17023SJohn Marino case CALL_EXPR:
191e4b17023SJohn Marino /* We can see calls outside of TARGET_EXPR in templates. */
192e4b17023SJohn Marino if (CLASS_TYPE_P (TREE_TYPE (ref)))
193e4b17023SJohn Marino return clk_class;
194e4b17023SJohn Marino return clk_none;
195e4b17023SJohn Marino
196e4b17023SJohn Marino case FUNCTION_DECL:
197e4b17023SJohn Marino /* All functions (except non-static-member functions) are
198e4b17023SJohn Marino lvalues. */
199e4b17023SJohn Marino return (DECL_NONSTATIC_MEMBER_FUNCTION_P (ref)
200e4b17023SJohn Marino ? clk_none : clk_ordinary);
201e4b17023SJohn Marino
202e4b17023SJohn Marino case BASELINK:
203e4b17023SJohn Marino /* We now represent a reference to a single static member function
204e4b17023SJohn Marino with a BASELINK. */
205e4b17023SJohn Marino /* This CONST_CAST is okay because BASELINK_FUNCTIONS returns
206e4b17023SJohn Marino its argument unmodified and we assign it to a const_tree. */
207e4b17023SJohn Marino return lvalue_kind (BASELINK_FUNCTIONS (CONST_CAST_TREE (ref)));
208e4b17023SJohn Marino
209e4b17023SJohn Marino case NON_DEPENDENT_EXPR:
210e4b17023SJohn Marino /* We just return clk_ordinary for NON_DEPENDENT_EXPR in C++98, but
211e4b17023SJohn Marino in C++11 lvalues don't bind to rvalue references, so we need to
212e4b17023SJohn Marino work harder to avoid bogus errors (c++/44870). */
213e4b17023SJohn Marino if (cxx_dialect < cxx0x)
214e4b17023SJohn Marino return clk_ordinary;
215e4b17023SJohn Marino else
216e4b17023SJohn Marino return lvalue_kind (TREE_OPERAND (ref, 0));
217e4b17023SJohn Marino
218e4b17023SJohn Marino default:
219e4b17023SJohn Marino if (!TREE_TYPE (ref))
220e4b17023SJohn Marino return clk_none;
221e4b17023SJohn Marino if (CLASS_TYPE_P (TREE_TYPE (ref)))
222e4b17023SJohn Marino return clk_class;
223e4b17023SJohn Marino break;
224e4b17023SJohn Marino }
225e4b17023SJohn Marino
226e4b17023SJohn Marino /* If one operand is not an lvalue at all, then this expression is
227e4b17023SJohn Marino not an lvalue. */
228e4b17023SJohn Marino if (!op1_lvalue_kind || !op2_lvalue_kind)
229e4b17023SJohn Marino return clk_none;
230e4b17023SJohn Marino
231e4b17023SJohn Marino /* Otherwise, it's an lvalue, and it has all the odd properties
232e4b17023SJohn Marino contributed by either operand. */
233e4b17023SJohn Marino op1_lvalue_kind = op1_lvalue_kind | op2_lvalue_kind;
234e4b17023SJohn Marino /* It's not an ordinary lvalue if it involves any other kind. */
235e4b17023SJohn Marino if ((op1_lvalue_kind & ~clk_ordinary) != clk_none)
236e4b17023SJohn Marino op1_lvalue_kind &= ~clk_ordinary;
237e4b17023SJohn Marino /* It can't be both a pseudo-lvalue and a non-addressable lvalue.
238e4b17023SJohn Marino A COND_EXPR of those should be wrapped in a TARGET_EXPR. */
239e4b17023SJohn Marino if ((op1_lvalue_kind & (clk_rvalueref|clk_class))
240e4b17023SJohn Marino && (op1_lvalue_kind & (clk_bitfield|clk_packed)))
241e4b17023SJohn Marino op1_lvalue_kind = clk_none;
242e4b17023SJohn Marino return op1_lvalue_kind;
243e4b17023SJohn Marino }
244e4b17023SJohn Marino
245e4b17023SJohn Marino /* Returns the kind of lvalue that REF is, in the sense of
246e4b17023SJohn Marino [basic.lval]. This function should really be named lvalue_p; it
247e4b17023SJohn Marino computes the C++ definition of lvalue. */
248e4b17023SJohn Marino
249e4b17023SJohn Marino cp_lvalue_kind
real_lvalue_p(const_tree ref)250e4b17023SJohn Marino real_lvalue_p (const_tree ref)
251e4b17023SJohn Marino {
252e4b17023SJohn Marino cp_lvalue_kind kind = lvalue_kind (ref);
253e4b17023SJohn Marino if (kind & (clk_rvalueref|clk_class))
254e4b17023SJohn Marino return clk_none;
255e4b17023SJohn Marino else
256e4b17023SJohn Marino return kind;
257e4b17023SJohn Marino }
258e4b17023SJohn Marino
259e4b17023SJohn Marino /* This differs from real_lvalue_p in that class rvalues are considered
260e4b17023SJohn Marino lvalues. */
261e4b17023SJohn Marino
262e4b17023SJohn Marino bool
lvalue_p(const_tree ref)263e4b17023SJohn Marino lvalue_p (const_tree ref)
264e4b17023SJohn Marino {
265e4b17023SJohn Marino return (lvalue_kind (ref) != clk_none);
266e4b17023SJohn Marino }
267e4b17023SJohn Marino
268e4b17023SJohn Marino /* This differs from real_lvalue_p in that rvalues formed by dereferencing
269e4b17023SJohn Marino rvalue references are considered rvalues. */
270e4b17023SJohn Marino
271e4b17023SJohn Marino bool
lvalue_or_rvalue_with_address_p(const_tree ref)272e4b17023SJohn Marino lvalue_or_rvalue_with_address_p (const_tree ref)
273e4b17023SJohn Marino {
274e4b17023SJohn Marino cp_lvalue_kind kind = lvalue_kind (ref);
275e4b17023SJohn Marino if (kind & clk_class)
276e4b17023SJohn Marino return false;
277e4b17023SJohn Marino else
278e4b17023SJohn Marino return (kind != clk_none);
279e4b17023SJohn Marino }
280e4b17023SJohn Marino
281e4b17023SJohn Marino /* Test whether DECL is a builtin that may appear in a
282e4b17023SJohn Marino constant-expression. */
283e4b17023SJohn Marino
284e4b17023SJohn Marino bool
builtin_valid_in_constant_expr_p(const_tree decl)285e4b17023SJohn Marino builtin_valid_in_constant_expr_p (const_tree decl)
286e4b17023SJohn Marino {
287e4b17023SJohn Marino /* At present BUILT_IN_CONSTANT_P is the only builtin we're allowing
288e4b17023SJohn Marino in constant-expressions. We may want to add other builtins later. */
289e4b17023SJohn Marino return DECL_IS_BUILTIN_CONSTANT_P (decl);
290e4b17023SJohn Marino }
291e4b17023SJohn Marino
292e4b17023SJohn Marino /* Build a TARGET_EXPR, initializing the DECL with the VALUE. */
293e4b17023SJohn Marino
294e4b17023SJohn Marino static tree
build_target_expr(tree decl,tree value,tsubst_flags_t complain)295e4b17023SJohn Marino build_target_expr (tree decl, tree value, tsubst_flags_t complain)
296e4b17023SJohn Marino {
297e4b17023SJohn Marino tree t;
298e4b17023SJohn Marino tree type = TREE_TYPE (decl);
299e4b17023SJohn Marino
300e4b17023SJohn Marino #ifdef ENABLE_CHECKING
301e4b17023SJohn Marino gcc_assert (VOID_TYPE_P (TREE_TYPE (value))
302e4b17023SJohn Marino || TREE_TYPE (decl) == TREE_TYPE (value)
303e4b17023SJohn Marino /* On ARM ctors return 'this'. */
304e4b17023SJohn Marino || (TREE_CODE (TREE_TYPE (value)) == POINTER_TYPE
305e4b17023SJohn Marino && TREE_CODE (value) == CALL_EXPR)
306e4b17023SJohn Marino || useless_type_conversion_p (TREE_TYPE (decl),
307e4b17023SJohn Marino TREE_TYPE (value)));
308e4b17023SJohn Marino #endif
309e4b17023SJohn Marino
310e4b17023SJohn Marino t = cxx_maybe_build_cleanup (decl, complain);
311e4b17023SJohn Marino if (t == error_mark_node)
312e4b17023SJohn Marino return error_mark_node;
313e4b17023SJohn Marino t = build4 (TARGET_EXPR, type, decl, value, t, NULL_TREE);
314e4b17023SJohn Marino /* We always set TREE_SIDE_EFFECTS so that expand_expr does not
315e4b17023SJohn Marino ignore the TARGET_EXPR. If there really turn out to be no
316e4b17023SJohn Marino side-effects, then the optimizer should be able to get rid of
317e4b17023SJohn Marino whatever code is generated anyhow. */
318e4b17023SJohn Marino TREE_SIDE_EFFECTS (t) = 1;
319e4b17023SJohn Marino
320e4b17023SJohn Marino return t;
321e4b17023SJohn Marino }
322e4b17023SJohn Marino
323e4b17023SJohn Marino /* Return an undeclared local temporary of type TYPE for use in building a
324e4b17023SJohn Marino TARGET_EXPR. */
325e4b17023SJohn Marino
326e4b17023SJohn Marino static tree
build_local_temp(tree type)327e4b17023SJohn Marino build_local_temp (tree type)
328e4b17023SJohn Marino {
329e4b17023SJohn Marino tree slot = build_decl (input_location,
330e4b17023SJohn Marino VAR_DECL, NULL_TREE, type);
331e4b17023SJohn Marino DECL_ARTIFICIAL (slot) = 1;
332e4b17023SJohn Marino DECL_IGNORED_P (slot) = 1;
333e4b17023SJohn Marino DECL_CONTEXT (slot) = current_function_decl;
334e4b17023SJohn Marino layout_decl (slot, 0);
335e4b17023SJohn Marino return slot;
336e4b17023SJohn Marino }
337e4b17023SJohn Marino
338e4b17023SJohn Marino /* Set various status flags when building an AGGR_INIT_EXPR object T. */
339e4b17023SJohn Marino
340e4b17023SJohn Marino static void
process_aggr_init_operands(tree t)341e4b17023SJohn Marino process_aggr_init_operands (tree t)
342e4b17023SJohn Marino {
343e4b17023SJohn Marino bool side_effects;
344e4b17023SJohn Marino
345e4b17023SJohn Marino side_effects = TREE_SIDE_EFFECTS (t);
346e4b17023SJohn Marino if (!side_effects)
347e4b17023SJohn Marino {
348e4b17023SJohn Marino int i, n;
349e4b17023SJohn Marino n = TREE_OPERAND_LENGTH (t);
350e4b17023SJohn Marino for (i = 1; i < n; i++)
351e4b17023SJohn Marino {
352e4b17023SJohn Marino tree op = TREE_OPERAND (t, i);
353e4b17023SJohn Marino if (op && TREE_SIDE_EFFECTS (op))
354e4b17023SJohn Marino {
355e4b17023SJohn Marino side_effects = 1;
356e4b17023SJohn Marino break;
357e4b17023SJohn Marino }
358e4b17023SJohn Marino }
359e4b17023SJohn Marino }
360e4b17023SJohn Marino TREE_SIDE_EFFECTS (t) = side_effects;
361e4b17023SJohn Marino }
362e4b17023SJohn Marino
363e4b17023SJohn Marino /* Build an AGGR_INIT_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE,
364e4b17023SJohn Marino FN, and SLOT. NARGS is the number of call arguments which are specified
365e4b17023SJohn Marino as a tree array ARGS. */
366e4b17023SJohn Marino
367e4b17023SJohn Marino static tree
build_aggr_init_array(tree return_type,tree fn,tree slot,int nargs,tree * args)368e4b17023SJohn Marino build_aggr_init_array (tree return_type, tree fn, tree slot, int nargs,
369e4b17023SJohn Marino tree *args)
370e4b17023SJohn Marino {
371e4b17023SJohn Marino tree t;
372e4b17023SJohn Marino int i;
373e4b17023SJohn Marino
374e4b17023SJohn Marino t = build_vl_exp (AGGR_INIT_EXPR, nargs + 3);
375e4b17023SJohn Marino TREE_TYPE (t) = return_type;
376e4b17023SJohn Marino AGGR_INIT_EXPR_FN (t) = fn;
377e4b17023SJohn Marino AGGR_INIT_EXPR_SLOT (t) = slot;
378e4b17023SJohn Marino for (i = 0; i < nargs; i++)
379e4b17023SJohn Marino AGGR_INIT_EXPR_ARG (t, i) = args[i];
380e4b17023SJohn Marino process_aggr_init_operands (t);
381e4b17023SJohn Marino return t;
382e4b17023SJohn Marino }
383e4b17023SJohn Marino
384e4b17023SJohn Marino /* INIT is a CALL_EXPR or AGGR_INIT_EXPR which needs info about its
385e4b17023SJohn Marino target. TYPE is the type to be initialized.
386e4b17023SJohn Marino
387e4b17023SJohn Marino Build an AGGR_INIT_EXPR to represent the initialization. This function
388e4b17023SJohn Marino differs from build_cplus_new in that an AGGR_INIT_EXPR can only be used
389e4b17023SJohn Marino to initialize another object, whereas a TARGET_EXPR can either
390e4b17023SJohn Marino initialize another object or create its own temporary object, and as a
391e4b17023SJohn Marino result building up a TARGET_EXPR requires that the type's destructor be
392e4b17023SJohn Marino callable. */
393e4b17023SJohn Marino
394e4b17023SJohn Marino tree
build_aggr_init_expr(tree type,tree init,tsubst_flags_t complain ATTRIBUTE_UNUSED)3955ce9237cSJohn Marino build_aggr_init_expr (tree type, tree init,
3965ce9237cSJohn Marino tsubst_flags_t complain ATTRIBUTE_UNUSED)
397e4b17023SJohn Marino {
398e4b17023SJohn Marino tree fn;
399e4b17023SJohn Marino tree slot;
400e4b17023SJohn Marino tree rval;
401e4b17023SJohn Marino int is_ctor;
402e4b17023SJohn Marino
403e4b17023SJohn Marino if (TREE_CODE (init) == CALL_EXPR)
404e4b17023SJohn Marino fn = CALL_EXPR_FN (init);
405e4b17023SJohn Marino else if (TREE_CODE (init) == AGGR_INIT_EXPR)
406e4b17023SJohn Marino fn = AGGR_INIT_EXPR_FN (init);
407e4b17023SJohn Marino else
408e4b17023SJohn Marino return convert (type, init);
409e4b17023SJohn Marino
410e4b17023SJohn Marino is_ctor = (TREE_CODE (fn) == ADDR_EXPR
411e4b17023SJohn Marino && TREE_CODE (TREE_OPERAND (fn, 0)) == FUNCTION_DECL
412e4b17023SJohn Marino && DECL_CONSTRUCTOR_P (TREE_OPERAND (fn, 0)));
413e4b17023SJohn Marino
414e4b17023SJohn Marino /* We split the CALL_EXPR into its function and its arguments here.
415e4b17023SJohn Marino Then, in expand_expr, we put them back together. The reason for
416e4b17023SJohn Marino this is that this expression might be a default argument
417e4b17023SJohn Marino expression. In that case, we need a new temporary every time the
418e4b17023SJohn Marino expression is used. That's what break_out_target_exprs does; it
419e4b17023SJohn Marino replaces every AGGR_INIT_EXPR with a copy that uses a fresh
420e4b17023SJohn Marino temporary slot. Then, expand_expr builds up a call-expression
421e4b17023SJohn Marino using the new slot. */
422e4b17023SJohn Marino
423e4b17023SJohn Marino /* If we don't need to use a constructor to create an object of this
424e4b17023SJohn Marino type, don't mess with AGGR_INIT_EXPR. */
425e4b17023SJohn Marino if (is_ctor || TREE_ADDRESSABLE (type))
426e4b17023SJohn Marino {
427e4b17023SJohn Marino slot = build_local_temp (type);
428e4b17023SJohn Marino
429e4b17023SJohn Marino if (TREE_CODE(init) == CALL_EXPR)
430e4b17023SJohn Marino rval = build_aggr_init_array (void_type_node, fn, slot,
431e4b17023SJohn Marino call_expr_nargs (init),
432e4b17023SJohn Marino CALL_EXPR_ARGP (init));
433e4b17023SJohn Marino else
434e4b17023SJohn Marino rval = build_aggr_init_array (void_type_node, fn, slot,
435e4b17023SJohn Marino aggr_init_expr_nargs (init),
436e4b17023SJohn Marino AGGR_INIT_EXPR_ARGP (init));
437e4b17023SJohn Marino TREE_SIDE_EFFECTS (rval) = 1;
438e4b17023SJohn Marino AGGR_INIT_VIA_CTOR_P (rval) = is_ctor;
439e4b17023SJohn Marino TREE_NOTHROW (rval) = TREE_NOTHROW (init);
440e4b17023SJohn Marino }
441e4b17023SJohn Marino else
442e4b17023SJohn Marino rval = init;
443e4b17023SJohn Marino
444e4b17023SJohn Marino return rval;
445e4b17023SJohn Marino }
446e4b17023SJohn Marino
447e4b17023SJohn Marino /* INIT is a CALL_EXPR or AGGR_INIT_EXPR which needs info about its
448e4b17023SJohn Marino target. TYPE is the type that this initialization should appear to
449e4b17023SJohn Marino have.
450e4b17023SJohn Marino
451e4b17023SJohn Marino Build an encapsulation of the initialization to perform
452e4b17023SJohn Marino and return it so that it can be processed by language-independent
453e4b17023SJohn Marino and language-specific expression expanders. */
454e4b17023SJohn Marino
455e4b17023SJohn Marino tree
build_cplus_new(tree type,tree init,tsubst_flags_t complain)456e4b17023SJohn Marino build_cplus_new (tree type, tree init, tsubst_flags_t complain)
457e4b17023SJohn Marino {
458e4b17023SJohn Marino tree rval = build_aggr_init_expr (type, init, complain);
459e4b17023SJohn Marino tree slot;
460e4b17023SJohn Marino
4615ce9237cSJohn Marino /* Make sure that we're not trying to create an instance of an
4625ce9237cSJohn Marino abstract class. */
4635ce9237cSJohn Marino if (abstract_virtuals_error_sfinae (NULL_TREE, type, complain))
4645ce9237cSJohn Marino return error_mark_node;
4655ce9237cSJohn Marino
466e4b17023SJohn Marino if (TREE_CODE (rval) == AGGR_INIT_EXPR)
467e4b17023SJohn Marino slot = AGGR_INIT_EXPR_SLOT (rval);
468e4b17023SJohn Marino else if (TREE_CODE (rval) == CALL_EXPR
469e4b17023SJohn Marino || TREE_CODE (rval) == CONSTRUCTOR)
470e4b17023SJohn Marino slot = build_local_temp (type);
471e4b17023SJohn Marino else
472e4b17023SJohn Marino return rval;
473e4b17023SJohn Marino
474e4b17023SJohn Marino rval = build_target_expr (slot, rval, complain);
475e4b17023SJohn Marino
476e4b17023SJohn Marino if (rval != error_mark_node)
477e4b17023SJohn Marino TARGET_EXPR_IMPLICIT_P (rval) = 1;
478e4b17023SJohn Marino
479e4b17023SJohn Marino return rval;
480e4b17023SJohn Marino }
481e4b17023SJohn Marino
482e4b17023SJohn Marino /* Subroutine of build_vec_init_expr: Build up a single element
483e4b17023SJohn Marino intialization as a proxy for the full array initialization to get things
484e4b17023SJohn Marino marked as used and any appropriate diagnostics.
485e4b17023SJohn Marino
486e4b17023SJohn Marino Since we're deferring building the actual constructor calls until
487e4b17023SJohn Marino gimplification time, we need to build one now and throw it away so
488e4b17023SJohn Marino that the relevant constructor gets mark_used before cgraph decides
489e4b17023SJohn Marino what functions are needed. Here we assume that init is either
490e4b17023SJohn Marino NULL_TREE, void_type_node (indicating value-initialization), or
491e4b17023SJohn Marino another array to copy. */
492e4b17023SJohn Marino
493e4b17023SJohn Marino static tree
build_vec_init_elt(tree type,tree init,tsubst_flags_t complain)494e4b17023SJohn Marino build_vec_init_elt (tree type, tree init, tsubst_flags_t complain)
495e4b17023SJohn Marino {
496e4b17023SJohn Marino tree inner_type = strip_array_types (type);
497e4b17023SJohn Marino VEC(tree,gc) *argvec;
498e4b17023SJohn Marino
499e4b17023SJohn Marino if (integer_zerop (array_type_nelts_total (type))
500e4b17023SJohn Marino || !CLASS_TYPE_P (inner_type))
501e4b17023SJohn Marino /* No interesting initialization to do. */
502e4b17023SJohn Marino return integer_zero_node;
503e4b17023SJohn Marino else if (init == void_type_node)
504e4b17023SJohn Marino return build_value_init (inner_type, complain);
505e4b17023SJohn Marino
506e4b17023SJohn Marino gcc_assert (init == NULL_TREE
507e4b17023SJohn Marino || (same_type_ignoring_top_level_qualifiers_p
508e4b17023SJohn Marino (type, TREE_TYPE (init))));
509e4b17023SJohn Marino
510e4b17023SJohn Marino argvec = make_tree_vector ();
511e4b17023SJohn Marino if (init)
512e4b17023SJohn Marino {
5135ce9237cSJohn Marino tree init_type = strip_array_types (TREE_TYPE (init));
5145ce9237cSJohn Marino tree dummy = build_dummy_object (init_type);
515e4b17023SJohn Marino if (!real_lvalue_p (init))
516e4b17023SJohn Marino dummy = move (dummy);
517e4b17023SJohn Marino VEC_quick_push (tree, argvec, dummy);
518e4b17023SJohn Marino }
519e4b17023SJohn Marino init = build_special_member_call (NULL_TREE, complete_ctor_identifier,
520e4b17023SJohn Marino &argvec, inner_type, LOOKUP_NORMAL,
521e4b17023SJohn Marino complain);
522e4b17023SJohn Marino release_tree_vector (argvec);
523e4b17023SJohn Marino
524e4b17023SJohn Marino /* For a trivial constructor, build_over_call creates a TARGET_EXPR. But
525e4b17023SJohn Marino we don't want one here because we aren't creating a temporary. */
526e4b17023SJohn Marino if (TREE_CODE (init) == TARGET_EXPR)
527e4b17023SJohn Marino init = TARGET_EXPR_INITIAL (init);
528e4b17023SJohn Marino
529e4b17023SJohn Marino return init;
530e4b17023SJohn Marino }
531e4b17023SJohn Marino
532e4b17023SJohn Marino /* Return a TARGET_EXPR which expresses the initialization of an array to
533e4b17023SJohn Marino be named later, either default-initialization or copy-initialization
534e4b17023SJohn Marino from another array of the same type. */
535e4b17023SJohn Marino
536e4b17023SJohn Marino tree
build_vec_init_expr(tree type,tree init,tsubst_flags_t complain)537e4b17023SJohn Marino build_vec_init_expr (tree type, tree init, tsubst_flags_t complain)
538e4b17023SJohn Marino {
539e4b17023SJohn Marino tree slot;
540e4b17023SJohn Marino bool value_init = false;
541e4b17023SJohn Marino tree elt_init = build_vec_init_elt (type, init, complain);
542e4b17023SJohn Marino
543e4b17023SJohn Marino if (init == void_type_node)
544e4b17023SJohn Marino {
545e4b17023SJohn Marino value_init = true;
546e4b17023SJohn Marino init = NULL_TREE;
547e4b17023SJohn Marino }
548e4b17023SJohn Marino
549e4b17023SJohn Marino slot = build_local_temp (type);
550e4b17023SJohn Marino init = build2 (VEC_INIT_EXPR, type, slot, init);
551e4b17023SJohn Marino TREE_SIDE_EFFECTS (init) = true;
552e4b17023SJohn Marino SET_EXPR_LOCATION (init, input_location);
553e4b17023SJohn Marino
554e4b17023SJohn Marino if (cxx_dialect >= cxx0x
555e4b17023SJohn Marino && potential_constant_expression (elt_init))
556e4b17023SJohn Marino VEC_INIT_EXPR_IS_CONSTEXPR (init) = true;
557e4b17023SJohn Marino VEC_INIT_EXPR_VALUE_INIT (init) = value_init;
558e4b17023SJohn Marino
559e4b17023SJohn Marino return init;
560e4b17023SJohn Marino }
561e4b17023SJohn Marino
562e4b17023SJohn Marino /* Give a helpful diagnostic for a non-constexpr VEC_INIT_EXPR in a context
563e4b17023SJohn Marino that requires a constant expression. */
564e4b17023SJohn Marino
565e4b17023SJohn Marino void
diagnose_non_constexpr_vec_init(tree expr)566e4b17023SJohn Marino diagnose_non_constexpr_vec_init (tree expr)
567e4b17023SJohn Marino {
568e4b17023SJohn Marino tree type = TREE_TYPE (VEC_INIT_EXPR_SLOT (expr));
569e4b17023SJohn Marino tree init, elt_init;
570e4b17023SJohn Marino if (VEC_INIT_EXPR_VALUE_INIT (expr))
571e4b17023SJohn Marino init = void_type_node;
572e4b17023SJohn Marino else
573e4b17023SJohn Marino init = VEC_INIT_EXPR_INIT (expr);
574e4b17023SJohn Marino
575e4b17023SJohn Marino elt_init = build_vec_init_elt (type, init, tf_warning_or_error);
576e4b17023SJohn Marino require_potential_constant_expression (elt_init);
577e4b17023SJohn Marino }
578e4b17023SJohn Marino
579e4b17023SJohn Marino tree
build_array_copy(tree init)580e4b17023SJohn Marino build_array_copy (tree init)
581e4b17023SJohn Marino {
582e4b17023SJohn Marino return build_vec_init_expr (TREE_TYPE (init), init, tf_warning_or_error);
583e4b17023SJohn Marino }
584e4b17023SJohn Marino
585e4b17023SJohn Marino /* Build a TARGET_EXPR using INIT to initialize a new temporary of the
586e4b17023SJohn Marino indicated TYPE. */
587e4b17023SJohn Marino
588e4b17023SJohn Marino tree
build_target_expr_with_type(tree init,tree type,tsubst_flags_t complain)589e4b17023SJohn Marino build_target_expr_with_type (tree init, tree type, tsubst_flags_t complain)
590e4b17023SJohn Marino {
591e4b17023SJohn Marino gcc_assert (!VOID_TYPE_P (type));
592e4b17023SJohn Marino
593e4b17023SJohn Marino if (TREE_CODE (init) == TARGET_EXPR
594e4b17023SJohn Marino || init == error_mark_node)
595e4b17023SJohn Marino return init;
596e4b17023SJohn Marino else if (CLASS_TYPE_P (type) && type_has_nontrivial_copy_init (type)
597e4b17023SJohn Marino && !VOID_TYPE_P (TREE_TYPE (init))
598e4b17023SJohn Marino && TREE_CODE (init) != COND_EXPR
599e4b17023SJohn Marino && TREE_CODE (init) != CONSTRUCTOR
600e4b17023SJohn Marino && TREE_CODE (init) != VA_ARG_EXPR)
601e4b17023SJohn Marino /* We need to build up a copy constructor call. A void initializer
602e4b17023SJohn Marino means we're being called from bot_manip. COND_EXPR is a special
603e4b17023SJohn Marino case because we already have copies on the arms and we don't want
604e4b17023SJohn Marino another one here. A CONSTRUCTOR is aggregate initialization, which
605e4b17023SJohn Marino is handled separately. A VA_ARG_EXPR is magic creation of an
606e4b17023SJohn Marino aggregate; there's no additional work to be done. */
607e4b17023SJohn Marino return force_rvalue (init, complain);
608e4b17023SJohn Marino
609e4b17023SJohn Marino return force_target_expr (type, init, complain);
610e4b17023SJohn Marino }
611e4b17023SJohn Marino
612e4b17023SJohn Marino /* Like the above function, but without the checking. This function should
613e4b17023SJohn Marino only be used by code which is deliberately trying to subvert the type
614e4b17023SJohn Marino system, such as call_builtin_trap. Or build_over_call, to avoid
615e4b17023SJohn Marino infinite recursion. */
616e4b17023SJohn Marino
617e4b17023SJohn Marino tree
force_target_expr(tree type,tree init,tsubst_flags_t complain)618e4b17023SJohn Marino force_target_expr (tree type, tree init, tsubst_flags_t complain)
619e4b17023SJohn Marino {
620e4b17023SJohn Marino tree slot;
621e4b17023SJohn Marino
622e4b17023SJohn Marino gcc_assert (!VOID_TYPE_P (type));
623e4b17023SJohn Marino
624e4b17023SJohn Marino slot = build_local_temp (type);
625e4b17023SJohn Marino return build_target_expr (slot, init, complain);
626e4b17023SJohn Marino }
627e4b17023SJohn Marino
628e4b17023SJohn Marino /* Like build_target_expr_with_type, but use the type of INIT. */
629e4b17023SJohn Marino
630e4b17023SJohn Marino tree
get_target_expr_sfinae(tree init,tsubst_flags_t complain)631e4b17023SJohn Marino get_target_expr_sfinae (tree init, tsubst_flags_t complain)
632e4b17023SJohn Marino {
633e4b17023SJohn Marino if (TREE_CODE (init) == AGGR_INIT_EXPR)
634e4b17023SJohn Marino return build_target_expr (AGGR_INIT_EXPR_SLOT (init), init, complain);
635e4b17023SJohn Marino else if (TREE_CODE (init) == VEC_INIT_EXPR)
636e4b17023SJohn Marino return build_target_expr (VEC_INIT_EXPR_SLOT (init), init, complain);
637e4b17023SJohn Marino else
638e4b17023SJohn Marino return build_target_expr_with_type (init, TREE_TYPE (init), complain);
639e4b17023SJohn Marino }
640e4b17023SJohn Marino
641e4b17023SJohn Marino tree
get_target_expr(tree init)642e4b17023SJohn Marino get_target_expr (tree init)
643e4b17023SJohn Marino {
644e4b17023SJohn Marino return get_target_expr_sfinae (init, tf_warning_or_error);
645e4b17023SJohn Marino }
646e4b17023SJohn Marino
647e4b17023SJohn Marino /* If EXPR is a bitfield reference, convert it to the declared type of
648e4b17023SJohn Marino the bitfield, and return the resulting expression. Otherwise,
649e4b17023SJohn Marino return EXPR itself. */
650e4b17023SJohn Marino
651e4b17023SJohn Marino tree
convert_bitfield_to_declared_type(tree expr)652e4b17023SJohn Marino convert_bitfield_to_declared_type (tree expr)
653e4b17023SJohn Marino {
654e4b17023SJohn Marino tree bitfield_type;
655e4b17023SJohn Marino
656e4b17023SJohn Marino bitfield_type = is_bitfield_expr_with_lowered_type (expr);
657e4b17023SJohn Marino if (bitfield_type)
658e4b17023SJohn Marino expr = convert_to_integer (TYPE_MAIN_VARIANT (bitfield_type),
659e4b17023SJohn Marino expr);
660e4b17023SJohn Marino return expr;
661e4b17023SJohn Marino }
662e4b17023SJohn Marino
663e4b17023SJohn Marino /* EXPR is being used in an rvalue context. Return a version of EXPR
664e4b17023SJohn Marino that is marked as an rvalue. */
665e4b17023SJohn Marino
666e4b17023SJohn Marino tree
rvalue(tree expr)667e4b17023SJohn Marino rvalue (tree expr)
668e4b17023SJohn Marino {
669e4b17023SJohn Marino tree type;
670e4b17023SJohn Marino
671e4b17023SJohn Marino if (error_operand_p (expr))
672e4b17023SJohn Marino return expr;
673e4b17023SJohn Marino
674e4b17023SJohn Marino expr = mark_rvalue_use (expr);
675e4b17023SJohn Marino
676e4b17023SJohn Marino /* [basic.lval]
677e4b17023SJohn Marino
678e4b17023SJohn Marino Non-class rvalues always have cv-unqualified types. */
679e4b17023SJohn Marino type = TREE_TYPE (expr);
680e4b17023SJohn Marino if (!CLASS_TYPE_P (type) && cv_qualified_p (type))
681e4b17023SJohn Marino type = cv_unqualified (type);
682e4b17023SJohn Marino
683e4b17023SJohn Marino /* We need to do this for rvalue refs as well to get the right answer
684e4b17023SJohn Marino from decltype; see c++/36628. */
685e4b17023SJohn Marino if (!processing_template_decl && lvalue_or_rvalue_with_address_p (expr))
686e4b17023SJohn Marino expr = build1 (NON_LVALUE_EXPR, type, expr);
687e4b17023SJohn Marino else if (type != TREE_TYPE (expr))
688e4b17023SJohn Marino expr = build_nop (type, expr);
689e4b17023SJohn Marino
690e4b17023SJohn Marino return expr;
691e4b17023SJohn Marino }
692e4b17023SJohn Marino
693e4b17023SJohn Marino
694e4b17023SJohn Marino /* Hash an ARRAY_TYPE. K is really of type `tree'. */
695e4b17023SJohn Marino
696e4b17023SJohn Marino static hashval_t
cplus_array_hash(const void * k)697e4b17023SJohn Marino cplus_array_hash (const void* k)
698e4b17023SJohn Marino {
699e4b17023SJohn Marino hashval_t hash;
700e4b17023SJohn Marino const_tree const t = (const_tree) k;
701e4b17023SJohn Marino
702e4b17023SJohn Marino hash = TYPE_UID (TREE_TYPE (t));
703e4b17023SJohn Marino if (TYPE_DOMAIN (t))
704e4b17023SJohn Marino hash ^= TYPE_UID (TYPE_DOMAIN (t));
705e4b17023SJohn Marino return hash;
706e4b17023SJohn Marino }
707e4b17023SJohn Marino
708e4b17023SJohn Marino typedef struct cplus_array_info {
709e4b17023SJohn Marino tree type;
710e4b17023SJohn Marino tree domain;
711e4b17023SJohn Marino } cplus_array_info;
712e4b17023SJohn Marino
713e4b17023SJohn Marino /* Compare two ARRAY_TYPEs. K1 is really of type `tree', K2 is really
714e4b17023SJohn Marino of type `cplus_array_info*'. */
715e4b17023SJohn Marino
716e4b17023SJohn Marino static int
cplus_array_compare(const void * k1,const void * k2)717e4b17023SJohn Marino cplus_array_compare (const void * k1, const void * k2)
718e4b17023SJohn Marino {
719e4b17023SJohn Marino const_tree const t1 = (const_tree) k1;
720e4b17023SJohn Marino const cplus_array_info *const t2 = (const cplus_array_info*) k2;
721e4b17023SJohn Marino
722e4b17023SJohn Marino return (TREE_TYPE (t1) == t2->type && TYPE_DOMAIN (t1) == t2->domain);
723e4b17023SJohn Marino }
724e4b17023SJohn Marino
725e4b17023SJohn Marino /* Hash table containing dependent array types, which are unsuitable for
726e4b17023SJohn Marino the language-independent type hash table. */
727e4b17023SJohn Marino static GTY ((param_is (union tree_node))) htab_t cplus_array_htab;
728e4b17023SJohn Marino
729e4b17023SJohn Marino /* Like build_array_type, but handle special C++ semantics. */
730e4b17023SJohn Marino
731e4b17023SJohn Marino tree
build_cplus_array_type(tree elt_type,tree index_type)732e4b17023SJohn Marino build_cplus_array_type (tree elt_type, tree index_type)
733e4b17023SJohn Marino {
734e4b17023SJohn Marino tree t;
7355ce9237cSJohn Marino bool needs_ctor, needs_dtor;
736e4b17023SJohn Marino
737e4b17023SJohn Marino if (elt_type == error_mark_node || index_type == error_mark_node)
738e4b17023SJohn Marino return error_mark_node;
739e4b17023SJohn Marino
740e4b17023SJohn Marino if (processing_template_decl
741e4b17023SJohn Marino && (dependent_type_p (elt_type)
742e4b17023SJohn Marino || (index_type && !TREE_CONSTANT (TYPE_MAX_VALUE (index_type)))))
743e4b17023SJohn Marino {
744e4b17023SJohn Marino void **e;
745e4b17023SJohn Marino cplus_array_info cai;
746e4b17023SJohn Marino hashval_t hash;
747e4b17023SJohn Marino
748e4b17023SJohn Marino if (cplus_array_htab == NULL)
749e4b17023SJohn Marino cplus_array_htab = htab_create_ggc (61, &cplus_array_hash,
750e4b17023SJohn Marino &cplus_array_compare, NULL);
751e4b17023SJohn Marino
752e4b17023SJohn Marino hash = TYPE_UID (elt_type);
753e4b17023SJohn Marino if (index_type)
754e4b17023SJohn Marino hash ^= TYPE_UID (index_type);
755e4b17023SJohn Marino cai.type = elt_type;
756e4b17023SJohn Marino cai.domain = index_type;
757e4b17023SJohn Marino
758e4b17023SJohn Marino e = htab_find_slot_with_hash (cplus_array_htab, &cai, hash, INSERT);
759e4b17023SJohn Marino if (*e)
760e4b17023SJohn Marino /* We have found the type: we're done. */
761e4b17023SJohn Marino return (tree) *e;
762e4b17023SJohn Marino else
763e4b17023SJohn Marino {
764e4b17023SJohn Marino /* Build a new array type. */
765e4b17023SJohn Marino t = cxx_make_type (ARRAY_TYPE);
766e4b17023SJohn Marino TREE_TYPE (t) = elt_type;
767e4b17023SJohn Marino TYPE_DOMAIN (t) = index_type;
768e4b17023SJohn Marino
769e4b17023SJohn Marino /* Store it in the hash table. */
770e4b17023SJohn Marino *e = t;
771e4b17023SJohn Marino
772e4b17023SJohn Marino /* Set the canonical type for this new node. */
773e4b17023SJohn Marino if (TYPE_STRUCTURAL_EQUALITY_P (elt_type)
774e4b17023SJohn Marino || (index_type && TYPE_STRUCTURAL_EQUALITY_P (index_type)))
775e4b17023SJohn Marino SET_TYPE_STRUCTURAL_EQUALITY (t);
776e4b17023SJohn Marino else if (TYPE_CANONICAL (elt_type) != elt_type
777e4b17023SJohn Marino || (index_type
778e4b17023SJohn Marino && TYPE_CANONICAL (index_type) != index_type))
779e4b17023SJohn Marino TYPE_CANONICAL (t)
780e4b17023SJohn Marino = build_cplus_array_type
781e4b17023SJohn Marino (TYPE_CANONICAL (elt_type),
782e4b17023SJohn Marino index_type ? TYPE_CANONICAL (index_type) : index_type);
783e4b17023SJohn Marino else
784e4b17023SJohn Marino TYPE_CANONICAL (t) = t;
785e4b17023SJohn Marino }
786e4b17023SJohn Marino }
787e4b17023SJohn Marino else
788e4b17023SJohn Marino {
789e4b17023SJohn Marino if (!TYPE_STRUCTURAL_EQUALITY_P (elt_type)
790e4b17023SJohn Marino && !(index_type && TYPE_STRUCTURAL_EQUALITY_P (index_type))
791e4b17023SJohn Marino && (TYPE_CANONICAL (elt_type) != elt_type
792e4b17023SJohn Marino || (index_type && TYPE_CANONICAL (index_type) != index_type)))
793e4b17023SJohn Marino /* Make sure that the canonical type is on the appropriate
794e4b17023SJohn Marino variants list. */
795e4b17023SJohn Marino build_cplus_array_type
796e4b17023SJohn Marino (TYPE_CANONICAL (elt_type),
797e4b17023SJohn Marino index_type ? TYPE_CANONICAL (index_type) : index_type);
798e4b17023SJohn Marino t = build_array_type (elt_type, index_type);
799e4b17023SJohn Marino }
800e4b17023SJohn Marino
8015ce9237cSJohn Marino /* Push these needs up so that initialization takes place
8025ce9237cSJohn Marino more easily. */
8035ce9237cSJohn Marino needs_ctor
8045ce9237cSJohn Marino = TYPE_NEEDS_CONSTRUCTING (TYPE_MAIN_VARIANT (elt_type));
8055ce9237cSJohn Marino TYPE_NEEDS_CONSTRUCTING (t) = needs_ctor;
8065ce9237cSJohn Marino needs_dtor
8075ce9237cSJohn Marino = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TYPE_MAIN_VARIANT (elt_type));
8085ce9237cSJohn Marino TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t) = needs_dtor;
8095ce9237cSJohn Marino
810e4b17023SJohn Marino /* We want TYPE_MAIN_VARIANT of an array to strip cv-quals from the
811e4b17023SJohn Marino element type as well, so fix it up if needed. */
812e4b17023SJohn Marino if (elt_type != TYPE_MAIN_VARIANT (elt_type))
813e4b17023SJohn Marino {
814e4b17023SJohn Marino tree m = build_cplus_array_type (TYPE_MAIN_VARIANT (elt_type),
815e4b17023SJohn Marino index_type);
816e4b17023SJohn Marino
817e4b17023SJohn Marino if (TYPE_MAIN_VARIANT (t) != m)
818e4b17023SJohn Marino {
819*95d28233SJohn Marino if (COMPLETE_TYPE_P (TREE_TYPE (t)) && !COMPLETE_TYPE_P (m))
8205ce9237cSJohn Marino {
8215ce9237cSJohn Marino /* m was built before the element type was complete, so we
822*95d28233SJohn Marino also need to copy the layout info from t. We might
823*95d28233SJohn Marino end up doing this multiple times if t is an array of
824*95d28233SJohn Marino unknown bound. */
8255ce9237cSJohn Marino tree size = TYPE_SIZE (t);
8265ce9237cSJohn Marino tree size_unit = TYPE_SIZE_UNIT (t);
8275ce9237cSJohn Marino unsigned int align = TYPE_ALIGN (t);
8285ce9237cSJohn Marino unsigned int user_align = TYPE_USER_ALIGN (t);
8295ce9237cSJohn Marino enum machine_mode mode = TYPE_MODE (t);
8305ce9237cSJohn Marino tree var;
8315ce9237cSJohn Marino for (var = m; var; var = TYPE_NEXT_VARIANT (var))
8325ce9237cSJohn Marino {
8335ce9237cSJohn Marino TYPE_SIZE (var) = size;
8345ce9237cSJohn Marino TYPE_SIZE_UNIT (var) = size_unit;
8355ce9237cSJohn Marino TYPE_ALIGN (var) = align;
8365ce9237cSJohn Marino TYPE_USER_ALIGN (var) = user_align;
8375ce9237cSJohn Marino SET_TYPE_MODE (var, mode);
8385ce9237cSJohn Marino TYPE_NEEDS_CONSTRUCTING (var) = needs_ctor;
8395ce9237cSJohn Marino TYPE_HAS_NONTRIVIAL_DESTRUCTOR (var) = needs_dtor;
8405ce9237cSJohn Marino }
8415ce9237cSJohn Marino }
8425ce9237cSJohn Marino
843e4b17023SJohn Marino TYPE_MAIN_VARIANT (t) = m;
844e4b17023SJohn Marino TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (m);
845e4b17023SJohn Marino TYPE_NEXT_VARIANT (m) = t;
846e4b17023SJohn Marino }
847e4b17023SJohn Marino }
848e4b17023SJohn Marino
849e4b17023SJohn Marino return t;
850e4b17023SJohn Marino }
851e4b17023SJohn Marino
852e4b17023SJohn Marino /* Return an ARRAY_TYPE with element type ELT and length N. */
853e4b17023SJohn Marino
854e4b17023SJohn Marino tree
build_array_of_n_type(tree elt,int n)855e4b17023SJohn Marino build_array_of_n_type (tree elt, int n)
856e4b17023SJohn Marino {
857e4b17023SJohn Marino return build_cplus_array_type (elt, build_index_type (size_int (n - 1)));
858e4b17023SJohn Marino }
859e4b17023SJohn Marino
860e4b17023SJohn Marino /* Return a reference type node referring to TO_TYPE. If RVAL is
861e4b17023SJohn Marino true, return an rvalue reference type, otherwise return an lvalue
862e4b17023SJohn Marino reference type. If a type node exists, reuse it, otherwise create
863e4b17023SJohn Marino a new one. */
864e4b17023SJohn Marino tree
cp_build_reference_type(tree to_type,bool rval)865e4b17023SJohn Marino cp_build_reference_type (tree to_type, bool rval)
866e4b17023SJohn Marino {
867e4b17023SJohn Marino tree lvalue_ref, t;
868e4b17023SJohn Marino lvalue_ref = build_reference_type (to_type);
869e4b17023SJohn Marino if (!rval)
870e4b17023SJohn Marino return lvalue_ref;
871e4b17023SJohn Marino
872e4b17023SJohn Marino /* This code to create rvalue reference types is based on and tied
873e4b17023SJohn Marino to the code creating lvalue reference types in the middle-end
874e4b17023SJohn Marino functions build_reference_type_for_mode and build_reference_type.
875e4b17023SJohn Marino
876e4b17023SJohn Marino It works by putting the rvalue reference type nodes after the
877e4b17023SJohn Marino lvalue reference nodes in the TYPE_NEXT_REF_TO linked list, so
878e4b17023SJohn Marino they will effectively be ignored by the middle end. */
879e4b17023SJohn Marino
880e4b17023SJohn Marino for (t = lvalue_ref; (t = TYPE_NEXT_REF_TO (t)); )
881e4b17023SJohn Marino if (TYPE_REF_IS_RVALUE (t))
882e4b17023SJohn Marino return t;
883e4b17023SJohn Marino
884e4b17023SJohn Marino t = build_distinct_type_copy (lvalue_ref);
885e4b17023SJohn Marino
886e4b17023SJohn Marino TYPE_REF_IS_RVALUE (t) = true;
887e4b17023SJohn Marino TYPE_NEXT_REF_TO (t) = TYPE_NEXT_REF_TO (lvalue_ref);
888e4b17023SJohn Marino TYPE_NEXT_REF_TO (lvalue_ref) = t;
889e4b17023SJohn Marino
890e4b17023SJohn Marino if (TYPE_STRUCTURAL_EQUALITY_P (to_type))
891e4b17023SJohn Marino SET_TYPE_STRUCTURAL_EQUALITY (t);
892e4b17023SJohn Marino else if (TYPE_CANONICAL (to_type) != to_type)
893e4b17023SJohn Marino TYPE_CANONICAL (t)
894e4b17023SJohn Marino = cp_build_reference_type (TYPE_CANONICAL (to_type), rval);
895e4b17023SJohn Marino else
896e4b17023SJohn Marino TYPE_CANONICAL (t) = t;
897e4b17023SJohn Marino
898e4b17023SJohn Marino layout_type (t);
899e4b17023SJohn Marino
900e4b17023SJohn Marino return t;
901e4b17023SJohn Marino
902e4b17023SJohn Marino }
903e4b17023SJohn Marino
904e4b17023SJohn Marino /* Returns EXPR cast to rvalue reference type, like std::move. */
905e4b17023SJohn Marino
906e4b17023SJohn Marino tree
move(tree expr)907e4b17023SJohn Marino move (tree expr)
908e4b17023SJohn Marino {
909e4b17023SJohn Marino tree type = TREE_TYPE (expr);
910e4b17023SJohn Marino gcc_assert (TREE_CODE (type) != REFERENCE_TYPE);
911e4b17023SJohn Marino type = cp_build_reference_type (type, /*rval*/true);
912e4b17023SJohn Marino return build_static_cast (type, expr, tf_warning_or_error);
913e4b17023SJohn Marino }
914e4b17023SJohn Marino
915e4b17023SJohn Marino /* Used by the C++ front end to build qualified array types. However,
916e4b17023SJohn Marino the C version of this function does not properly maintain canonical
917e4b17023SJohn Marino types (which are not used in C). */
918e4b17023SJohn Marino tree
c_build_qualified_type(tree type,int type_quals)919e4b17023SJohn Marino c_build_qualified_type (tree type, int type_quals)
920e4b17023SJohn Marino {
921e4b17023SJohn Marino return cp_build_qualified_type (type, type_quals);
922e4b17023SJohn Marino }
923e4b17023SJohn Marino
924e4b17023SJohn Marino
925e4b17023SJohn Marino /* Make a variant of TYPE, qualified with the TYPE_QUALS. Handles
926e4b17023SJohn Marino arrays correctly. In particular, if TYPE is an array of T's, and
927e4b17023SJohn Marino TYPE_QUALS is non-empty, returns an array of qualified T's.
928e4b17023SJohn Marino
929e4b17023SJohn Marino FLAGS determines how to deal with ill-formed qualifications. If
930e4b17023SJohn Marino tf_ignore_bad_quals is set, then bad qualifications are dropped
931e4b17023SJohn Marino (this is permitted if TYPE was introduced via a typedef or template
932e4b17023SJohn Marino type parameter). If bad qualifications are dropped and tf_warning
933e4b17023SJohn Marino is set, then a warning is issued for non-const qualifications. If
934e4b17023SJohn Marino tf_ignore_bad_quals is not set and tf_error is not set, we
935e4b17023SJohn Marino return error_mark_node. Otherwise, we issue an error, and ignore
936e4b17023SJohn Marino the qualifications.
937e4b17023SJohn Marino
938e4b17023SJohn Marino Qualification of a reference type is valid when the reference came
939e4b17023SJohn Marino via a typedef or template type argument. [dcl.ref] No such
940e4b17023SJohn Marino dispensation is provided for qualifying a function type. [dcl.fct]
941e4b17023SJohn Marino DR 295 queries this and the proposed resolution brings it into line
942e4b17023SJohn Marino with qualifying a reference. We implement the DR. We also behave
943e4b17023SJohn Marino in a similar manner for restricting non-pointer types. */
944e4b17023SJohn Marino
945e4b17023SJohn Marino tree
cp_build_qualified_type_real(tree type,int type_quals,tsubst_flags_t complain)946e4b17023SJohn Marino cp_build_qualified_type_real (tree type,
947e4b17023SJohn Marino int type_quals,
948e4b17023SJohn Marino tsubst_flags_t complain)
949e4b17023SJohn Marino {
950e4b17023SJohn Marino tree result;
951e4b17023SJohn Marino int bad_quals = TYPE_UNQUALIFIED;
952e4b17023SJohn Marino
953e4b17023SJohn Marino if (type == error_mark_node)
954e4b17023SJohn Marino return type;
955e4b17023SJohn Marino
956e4b17023SJohn Marino if (type_quals == cp_type_quals (type))
957e4b17023SJohn Marino return type;
958e4b17023SJohn Marino
959e4b17023SJohn Marino if (TREE_CODE (type) == ARRAY_TYPE)
960e4b17023SJohn Marino {
961e4b17023SJohn Marino /* In C++, the qualification really applies to the array element
962e4b17023SJohn Marino type. Obtain the appropriately qualified element type. */
963e4b17023SJohn Marino tree t;
964e4b17023SJohn Marino tree element_type
965e4b17023SJohn Marino = cp_build_qualified_type_real (TREE_TYPE (type),
966e4b17023SJohn Marino type_quals,
967e4b17023SJohn Marino complain);
968e4b17023SJohn Marino
969e4b17023SJohn Marino if (element_type == error_mark_node)
970e4b17023SJohn Marino return error_mark_node;
971e4b17023SJohn Marino
972e4b17023SJohn Marino /* See if we already have an identically qualified type. Tests
973e4b17023SJohn Marino should be equivalent to those in check_qualified_type. */
974e4b17023SJohn Marino for (t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
975e4b17023SJohn Marino if (TREE_TYPE (t) == element_type
976e4b17023SJohn Marino && TYPE_NAME (t) == TYPE_NAME (type)
977e4b17023SJohn Marino && TYPE_CONTEXT (t) == TYPE_CONTEXT (type)
978e4b17023SJohn Marino && attribute_list_equal (TYPE_ATTRIBUTES (t),
979e4b17023SJohn Marino TYPE_ATTRIBUTES (type)))
980e4b17023SJohn Marino break;
981e4b17023SJohn Marino
982e4b17023SJohn Marino if (!t)
983e4b17023SJohn Marino {
984e4b17023SJohn Marino t = build_cplus_array_type (element_type, TYPE_DOMAIN (type));
985e4b17023SJohn Marino
986e4b17023SJohn Marino /* Keep the typedef name. */
987e4b17023SJohn Marino if (TYPE_NAME (t) != TYPE_NAME (type))
988e4b17023SJohn Marino {
989e4b17023SJohn Marino t = build_variant_type_copy (t);
990e4b17023SJohn Marino TYPE_NAME (t) = TYPE_NAME (type);
991e4b17023SJohn Marino }
992e4b17023SJohn Marino }
993e4b17023SJohn Marino
994e4b17023SJohn Marino /* Even if we already had this variant, we update
995e4b17023SJohn Marino TYPE_NEEDS_CONSTRUCTING and TYPE_HAS_NONTRIVIAL_DESTRUCTOR in case
996e4b17023SJohn Marino they changed since the variant was originally created.
997e4b17023SJohn Marino
998e4b17023SJohn Marino This seems hokey; if there is some way to use a previous
999e4b17023SJohn Marino variant *without* coming through here,
1000e4b17023SJohn Marino TYPE_NEEDS_CONSTRUCTING will never be updated. */
1001e4b17023SJohn Marino TYPE_NEEDS_CONSTRUCTING (t)
1002e4b17023SJohn Marino = TYPE_NEEDS_CONSTRUCTING (TYPE_MAIN_VARIANT (element_type));
1003e4b17023SJohn Marino TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)
1004e4b17023SJohn Marino = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TYPE_MAIN_VARIANT (element_type));
1005e4b17023SJohn Marino return t;
1006e4b17023SJohn Marino }
1007e4b17023SJohn Marino else if (TYPE_PTRMEMFUNC_P (type))
1008e4b17023SJohn Marino {
1009e4b17023SJohn Marino /* For a pointer-to-member type, we can't just return a
1010e4b17023SJohn Marino cv-qualified version of the RECORD_TYPE. If we do, we
1011e4b17023SJohn Marino haven't changed the field that contains the actual pointer to
1012e4b17023SJohn Marino a method, and so TYPE_PTRMEMFUNC_FN_TYPE will be wrong. */
1013e4b17023SJohn Marino tree t;
1014e4b17023SJohn Marino
1015e4b17023SJohn Marino t = TYPE_PTRMEMFUNC_FN_TYPE (type);
1016e4b17023SJohn Marino t = cp_build_qualified_type_real (t, type_quals, complain);
1017e4b17023SJohn Marino return build_ptrmemfunc_type (t);
1018e4b17023SJohn Marino }
1019e4b17023SJohn Marino else if (TREE_CODE (type) == TYPE_PACK_EXPANSION)
1020e4b17023SJohn Marino {
1021e4b17023SJohn Marino tree t = PACK_EXPANSION_PATTERN (type);
1022e4b17023SJohn Marino
1023e4b17023SJohn Marino t = cp_build_qualified_type_real (t, type_quals, complain);
1024e4b17023SJohn Marino return make_pack_expansion (t);
1025e4b17023SJohn Marino }
1026e4b17023SJohn Marino
1027e4b17023SJohn Marino /* A reference or method type shall not be cv-qualified.
1028e4b17023SJohn Marino [dcl.ref], [dcl.fct]. This used to be an error, but as of DR 295
1029e4b17023SJohn Marino (in CD1) we always ignore extra cv-quals on functions. */
1030e4b17023SJohn Marino if (type_quals & (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE)
1031e4b17023SJohn Marino && (TREE_CODE (type) == REFERENCE_TYPE
1032e4b17023SJohn Marino || TREE_CODE (type) == FUNCTION_TYPE
1033e4b17023SJohn Marino || TREE_CODE (type) == METHOD_TYPE))
1034e4b17023SJohn Marino {
1035e4b17023SJohn Marino if (TREE_CODE (type) == REFERENCE_TYPE)
1036e4b17023SJohn Marino bad_quals |= type_quals & (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE);
1037e4b17023SJohn Marino type_quals &= ~(TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE);
1038e4b17023SJohn Marino }
1039e4b17023SJohn Marino
1040e4b17023SJohn Marino /* But preserve any function-cv-quals on a FUNCTION_TYPE. */
1041e4b17023SJohn Marino if (TREE_CODE (type) == FUNCTION_TYPE)
1042e4b17023SJohn Marino type_quals |= type_memfn_quals (type);
1043e4b17023SJohn Marino
1044e4b17023SJohn Marino /* A restrict-qualified type must be a pointer (or reference)
1045e4b17023SJohn Marino to object or incomplete type. */
1046e4b17023SJohn Marino if ((type_quals & TYPE_QUAL_RESTRICT)
1047e4b17023SJohn Marino && TREE_CODE (type) != TEMPLATE_TYPE_PARM
1048e4b17023SJohn Marino && TREE_CODE (type) != TYPENAME_TYPE
1049e4b17023SJohn Marino && !POINTER_TYPE_P (type))
1050e4b17023SJohn Marino {
1051e4b17023SJohn Marino bad_quals |= TYPE_QUAL_RESTRICT;
1052e4b17023SJohn Marino type_quals &= ~TYPE_QUAL_RESTRICT;
1053e4b17023SJohn Marino }
1054e4b17023SJohn Marino
1055e4b17023SJohn Marino if (bad_quals == TYPE_UNQUALIFIED
1056e4b17023SJohn Marino || (complain & tf_ignore_bad_quals))
1057e4b17023SJohn Marino /*OK*/;
1058e4b17023SJohn Marino else if (!(complain & tf_error))
1059e4b17023SJohn Marino return error_mark_node;
1060e4b17023SJohn Marino else
1061e4b17023SJohn Marino {
1062e4b17023SJohn Marino tree bad_type = build_qualified_type (ptr_type_node, bad_quals);
1063e4b17023SJohn Marino error ("%qV qualifiers cannot be applied to %qT",
1064e4b17023SJohn Marino bad_type, type);
1065e4b17023SJohn Marino }
1066e4b17023SJohn Marino
1067e4b17023SJohn Marino /* Retrieve (or create) the appropriately qualified variant. */
1068e4b17023SJohn Marino result = build_qualified_type (type, type_quals);
1069e4b17023SJohn Marino
1070e4b17023SJohn Marino /* If this was a pointer-to-method type, and we just made a copy,
1071e4b17023SJohn Marino then we need to unshare the record that holds the cached
1072e4b17023SJohn Marino pointer-to-member-function type, because these will be distinct
1073e4b17023SJohn Marino between the unqualified and qualified types. */
1074e4b17023SJohn Marino if (result != type
1075e4b17023SJohn Marino && TREE_CODE (type) == POINTER_TYPE
1076e4b17023SJohn Marino && TREE_CODE (TREE_TYPE (type)) == METHOD_TYPE
1077e4b17023SJohn Marino && TYPE_LANG_SPECIFIC (result) == TYPE_LANG_SPECIFIC (type))
1078e4b17023SJohn Marino TYPE_LANG_SPECIFIC (result) = NULL;
1079e4b17023SJohn Marino
1080e4b17023SJohn Marino /* We may also have ended up building a new copy of the canonical
1081e4b17023SJohn Marino type of a pointer-to-method type, which could have the same
1082e4b17023SJohn Marino sharing problem described above. */
1083e4b17023SJohn Marino if (TYPE_CANONICAL (result) != TYPE_CANONICAL (type)
1084e4b17023SJohn Marino && TREE_CODE (type) == POINTER_TYPE
1085e4b17023SJohn Marino && TREE_CODE (TREE_TYPE (type)) == METHOD_TYPE
1086e4b17023SJohn Marino && (TYPE_LANG_SPECIFIC (TYPE_CANONICAL (result))
1087e4b17023SJohn Marino == TYPE_LANG_SPECIFIC (TYPE_CANONICAL (type))))
1088e4b17023SJohn Marino TYPE_LANG_SPECIFIC (TYPE_CANONICAL (result)) = NULL;
1089e4b17023SJohn Marino
1090e4b17023SJohn Marino return result;
1091e4b17023SJohn Marino }
1092e4b17023SJohn Marino
1093e4b17023SJohn Marino /* Return TYPE with const and volatile removed. */
1094e4b17023SJohn Marino
1095e4b17023SJohn Marino tree
cv_unqualified(tree type)1096e4b17023SJohn Marino cv_unqualified (tree type)
1097e4b17023SJohn Marino {
1098e4b17023SJohn Marino int quals;
1099e4b17023SJohn Marino
1100e4b17023SJohn Marino if (type == error_mark_node)
1101e4b17023SJohn Marino return type;
1102e4b17023SJohn Marino
1103e4b17023SJohn Marino quals = cp_type_quals (type);
1104e4b17023SJohn Marino quals &= ~(TYPE_QUAL_CONST|TYPE_QUAL_VOLATILE);
1105e4b17023SJohn Marino return cp_build_qualified_type (type, quals);
1106e4b17023SJohn Marino }
1107e4b17023SJohn Marino
1108e4b17023SJohn Marino /* Builds a qualified variant of T that is not a typedef variant.
1109e4b17023SJohn Marino E.g. consider the following declarations:
1110e4b17023SJohn Marino typedef const int ConstInt;
1111e4b17023SJohn Marino typedef ConstInt* PtrConstInt;
1112e4b17023SJohn Marino If T is PtrConstInt, this function returns a type representing
1113e4b17023SJohn Marino const int*.
1114e4b17023SJohn Marino In other words, if T is a typedef, the function returns the underlying type.
1115e4b17023SJohn Marino The cv-qualification and attributes of the type returned match the
1116e4b17023SJohn Marino input type.
1117e4b17023SJohn Marino They will always be compatible types.
1118e4b17023SJohn Marino The returned type is built so that all of its subtypes
1119e4b17023SJohn Marino recursively have their typedefs stripped as well.
1120e4b17023SJohn Marino
1121e4b17023SJohn Marino This is different from just returning TYPE_CANONICAL (T)
1122e4b17023SJohn Marino Because of several reasons:
1123e4b17023SJohn Marino * If T is a type that needs structural equality
1124e4b17023SJohn Marino its TYPE_CANONICAL (T) will be NULL.
1125e4b17023SJohn Marino * TYPE_CANONICAL (T) desn't carry type attributes
11265ce9237cSJohn Marino and loses template parameter names. */
1127e4b17023SJohn Marino
1128e4b17023SJohn Marino tree
strip_typedefs(tree t)1129e4b17023SJohn Marino strip_typedefs (tree t)
1130e4b17023SJohn Marino {
1131e4b17023SJohn Marino tree result = NULL, type = NULL, t0 = NULL;
1132e4b17023SJohn Marino
1133e4b17023SJohn Marino if (!t || t == error_mark_node || t == TYPE_CANONICAL (t))
1134e4b17023SJohn Marino return t;
1135e4b17023SJohn Marino
1136e4b17023SJohn Marino gcc_assert (TYPE_P (t));
1137e4b17023SJohn Marino
1138e4b17023SJohn Marino switch (TREE_CODE (t))
1139e4b17023SJohn Marino {
1140e4b17023SJohn Marino case POINTER_TYPE:
1141e4b17023SJohn Marino type = strip_typedefs (TREE_TYPE (t));
1142e4b17023SJohn Marino result = build_pointer_type (type);
1143e4b17023SJohn Marino break;
1144e4b17023SJohn Marino case REFERENCE_TYPE:
1145e4b17023SJohn Marino type = strip_typedefs (TREE_TYPE (t));
1146e4b17023SJohn Marino result = cp_build_reference_type (type, TYPE_REF_IS_RVALUE (t));
1147e4b17023SJohn Marino break;
1148e4b17023SJohn Marino case OFFSET_TYPE:
1149e4b17023SJohn Marino t0 = strip_typedefs (TYPE_OFFSET_BASETYPE (t));
1150e4b17023SJohn Marino type = strip_typedefs (TREE_TYPE (t));
1151e4b17023SJohn Marino result = build_offset_type (t0, type);
1152e4b17023SJohn Marino break;
1153e4b17023SJohn Marino case RECORD_TYPE:
1154e4b17023SJohn Marino if (TYPE_PTRMEMFUNC_P (t))
1155e4b17023SJohn Marino {
1156e4b17023SJohn Marino t0 = strip_typedefs (TYPE_PTRMEMFUNC_FN_TYPE (t));
1157e4b17023SJohn Marino result = build_ptrmemfunc_type (t0);
1158e4b17023SJohn Marino }
1159e4b17023SJohn Marino break;
1160e4b17023SJohn Marino case ARRAY_TYPE:
1161e4b17023SJohn Marino type = strip_typedefs (TREE_TYPE (t));
1162e4b17023SJohn Marino t0 = strip_typedefs (TYPE_DOMAIN (t));;
1163e4b17023SJohn Marino result = build_cplus_array_type (type, t0);
1164e4b17023SJohn Marino break;
1165e4b17023SJohn Marino case FUNCTION_TYPE:
1166e4b17023SJohn Marino case METHOD_TYPE:
1167e4b17023SJohn Marino {
1168e4b17023SJohn Marino tree arg_types = NULL, arg_node, arg_type;
1169e4b17023SJohn Marino for (arg_node = TYPE_ARG_TYPES (t);
1170e4b17023SJohn Marino arg_node;
1171e4b17023SJohn Marino arg_node = TREE_CHAIN (arg_node))
1172e4b17023SJohn Marino {
1173e4b17023SJohn Marino if (arg_node == void_list_node)
1174e4b17023SJohn Marino break;
1175e4b17023SJohn Marino arg_type = strip_typedefs (TREE_VALUE (arg_node));
1176e4b17023SJohn Marino gcc_assert (arg_type);
1177e4b17023SJohn Marino
1178e4b17023SJohn Marino arg_types =
1179e4b17023SJohn Marino tree_cons (TREE_PURPOSE (arg_node), arg_type, arg_types);
1180e4b17023SJohn Marino }
1181e4b17023SJohn Marino
1182e4b17023SJohn Marino if (arg_types)
1183e4b17023SJohn Marino arg_types = nreverse (arg_types);
1184e4b17023SJohn Marino
1185e4b17023SJohn Marino /* A list of parameters not ending with an ellipsis
1186e4b17023SJohn Marino must end with void_list_node. */
1187e4b17023SJohn Marino if (arg_node)
1188e4b17023SJohn Marino arg_types = chainon (arg_types, void_list_node);
1189e4b17023SJohn Marino
1190e4b17023SJohn Marino type = strip_typedefs (TREE_TYPE (t));
1191e4b17023SJohn Marino if (TREE_CODE (t) == METHOD_TYPE)
1192e4b17023SJohn Marino {
1193e4b17023SJohn Marino tree class_type = TREE_TYPE (TREE_VALUE (arg_types));
1194e4b17023SJohn Marino gcc_assert (class_type);
1195e4b17023SJohn Marino result =
1196e4b17023SJohn Marino build_method_type_directly (class_type, type,
1197e4b17023SJohn Marino TREE_CHAIN (arg_types));
1198e4b17023SJohn Marino }
1199e4b17023SJohn Marino else
1200e4b17023SJohn Marino {
1201e4b17023SJohn Marino result = build_function_type (type,
1202e4b17023SJohn Marino arg_types);
1203e4b17023SJohn Marino result = apply_memfn_quals (result, type_memfn_quals (t));
1204e4b17023SJohn Marino }
1205e4b17023SJohn Marino
1206e4b17023SJohn Marino if (TYPE_RAISES_EXCEPTIONS (t))
1207e4b17023SJohn Marino result = build_exception_variant (result,
1208e4b17023SJohn Marino TYPE_RAISES_EXCEPTIONS (t));
1209e4b17023SJohn Marino }
1210e4b17023SJohn Marino break;
1211e4b17023SJohn Marino case TYPENAME_TYPE:
12125ce9237cSJohn Marino {
12135ce9237cSJohn Marino tree fullname = TYPENAME_TYPE_FULLNAME (t);
12145ce9237cSJohn Marino if (TREE_CODE (fullname) == TEMPLATE_ID_EXPR
12155ce9237cSJohn Marino && TREE_OPERAND (fullname, 1))
12165ce9237cSJohn Marino {
12175ce9237cSJohn Marino tree args = TREE_OPERAND (fullname, 1);
12185ce9237cSJohn Marino tree new_args = copy_node (args);
12195ce9237cSJohn Marino bool changed = false;
12205ce9237cSJohn Marino int i;
12215ce9237cSJohn Marino for (i = 0; i < TREE_VEC_LENGTH (args); ++i)
12225ce9237cSJohn Marino {
12235ce9237cSJohn Marino tree arg = TREE_VEC_ELT (args, i);
12245ce9237cSJohn Marino tree strip_arg;
12255ce9237cSJohn Marino if (TYPE_P (arg))
12265ce9237cSJohn Marino strip_arg = strip_typedefs (arg);
12275ce9237cSJohn Marino else
12285ce9237cSJohn Marino strip_arg = strip_typedefs_expr (arg);
12295ce9237cSJohn Marino TREE_VEC_ELT (new_args, i) = strip_arg;
12305ce9237cSJohn Marino if (strip_arg != arg)
12315ce9237cSJohn Marino changed = true;
12325ce9237cSJohn Marino }
12335ce9237cSJohn Marino if (changed)
12345ce9237cSJohn Marino {
12355ce9237cSJohn Marino NON_DEFAULT_TEMPLATE_ARGS_COUNT (new_args)
12365ce9237cSJohn Marino = NON_DEFAULT_TEMPLATE_ARGS_COUNT (args);
12375ce9237cSJohn Marino fullname
12385ce9237cSJohn Marino = lookup_template_function (TREE_OPERAND (fullname, 0),
12395ce9237cSJohn Marino new_args);
12405ce9237cSJohn Marino }
12415ce9237cSJohn Marino else
12425ce9237cSJohn Marino ggc_free (new_args);
12435ce9237cSJohn Marino }
1244e4b17023SJohn Marino result = make_typename_type (strip_typedefs (TYPE_CONTEXT (t)),
12455ce9237cSJohn Marino fullname, typename_type, tf_none);
12465ce9237cSJohn Marino }
12475ce9237cSJohn Marino break;
12485ce9237cSJohn Marino case DECLTYPE_TYPE:
12495ce9237cSJohn Marino result = strip_typedefs_expr (DECLTYPE_TYPE_EXPR (t));
12505ce9237cSJohn Marino if (result == DECLTYPE_TYPE_EXPR (t))
12515ce9237cSJohn Marino return t;
12525ce9237cSJohn Marino else
12535ce9237cSJohn Marino result = (finish_decltype_type
12545ce9237cSJohn Marino (result,
12555ce9237cSJohn Marino DECLTYPE_TYPE_ID_EXPR_OR_MEMBER_ACCESS_P (t),
12565ce9237cSJohn Marino tf_none));
1257e4b17023SJohn Marino break;
1258e4b17023SJohn Marino default:
1259e4b17023SJohn Marino break;
1260e4b17023SJohn Marino }
1261e4b17023SJohn Marino
1262e4b17023SJohn Marino if (!result)
1263e4b17023SJohn Marino result = TYPE_MAIN_VARIANT (t);
1264e4b17023SJohn Marino if (TYPE_USER_ALIGN (t) != TYPE_USER_ALIGN (result)
1265e4b17023SJohn Marino || TYPE_ALIGN (t) != TYPE_ALIGN (result))
1266e4b17023SJohn Marino {
1267e4b17023SJohn Marino gcc_assert (TYPE_USER_ALIGN (t));
1268e4b17023SJohn Marino if (TYPE_ALIGN (t) == TYPE_ALIGN (result))
1269e4b17023SJohn Marino result = build_variant_type_copy (result);
1270e4b17023SJohn Marino else
1271e4b17023SJohn Marino result = build_aligned_type (result, TYPE_ALIGN (t));
1272e4b17023SJohn Marino TYPE_USER_ALIGN (result) = true;
1273e4b17023SJohn Marino }
1274e4b17023SJohn Marino if (TYPE_ATTRIBUTES (t))
1275e4b17023SJohn Marino result = cp_build_type_attribute_variant (result, TYPE_ATTRIBUTES (t));
1276e4b17023SJohn Marino return cp_build_qualified_type (result, cp_type_quals (t));
1277e4b17023SJohn Marino }
1278e4b17023SJohn Marino
12795ce9237cSJohn Marino /* Like strip_typedefs above, but works on expressions, so that in
12805ce9237cSJohn Marino
12815ce9237cSJohn Marino template<class T> struct A
12825ce9237cSJohn Marino {
12835ce9237cSJohn Marino typedef T TT;
12845ce9237cSJohn Marino B<sizeof(TT)> b;
12855ce9237cSJohn Marino };
12865ce9237cSJohn Marino
12875ce9237cSJohn Marino sizeof(TT) is replaced by sizeof(T). */
12885ce9237cSJohn Marino
12895ce9237cSJohn Marino tree
strip_typedefs_expr(tree t)12905ce9237cSJohn Marino strip_typedefs_expr (tree t)
12915ce9237cSJohn Marino {
12925ce9237cSJohn Marino unsigned i,n;
12935ce9237cSJohn Marino tree r, type, *ops;
12945ce9237cSJohn Marino enum tree_code code;
12955ce9237cSJohn Marino
12965ce9237cSJohn Marino if (t == NULL_TREE || t == error_mark_node)
12975ce9237cSJohn Marino return t;
12985ce9237cSJohn Marino
12995ce9237cSJohn Marino if (DECL_P (t) || CONSTANT_CLASS_P (t))
13005ce9237cSJohn Marino return t;
13015ce9237cSJohn Marino
13025ce9237cSJohn Marino /* Some expressions have type operands, so let's handle types here rather
13035ce9237cSJohn Marino than check TYPE_P in multiple places below. */
13045ce9237cSJohn Marino if (TYPE_P (t))
13055ce9237cSJohn Marino return strip_typedefs (t);
13065ce9237cSJohn Marino
13075ce9237cSJohn Marino code = TREE_CODE (t);
13085ce9237cSJohn Marino switch (code)
13095ce9237cSJohn Marino {
13105ce9237cSJohn Marino case IDENTIFIER_NODE:
13115ce9237cSJohn Marino case TEMPLATE_PARM_INDEX:
13125ce9237cSJohn Marino case OVERLOAD:
13135ce9237cSJohn Marino case BASELINK:
13145ce9237cSJohn Marino case ARGUMENT_PACK_SELECT:
13155ce9237cSJohn Marino return t;
13165ce9237cSJohn Marino
13175ce9237cSJohn Marino case TRAIT_EXPR:
13185ce9237cSJohn Marino {
13195ce9237cSJohn Marino tree type1 = strip_typedefs (TRAIT_EXPR_TYPE1 (t));
13205ce9237cSJohn Marino tree type2 = strip_typedefs (TRAIT_EXPR_TYPE2 (t));
13215ce9237cSJohn Marino if (type1 == TRAIT_EXPR_TYPE1 (t)
13225ce9237cSJohn Marino && type2 == TRAIT_EXPR_TYPE2 (t))
13235ce9237cSJohn Marino return t;
13245ce9237cSJohn Marino r = copy_node (t);
13255ce9237cSJohn Marino TRAIT_EXPR_TYPE1 (t) = type1;
13265ce9237cSJohn Marino TRAIT_EXPR_TYPE2 (t) = type2;
13275ce9237cSJohn Marino return r;
13285ce9237cSJohn Marino }
13295ce9237cSJohn Marino
13305ce9237cSJohn Marino case TREE_LIST:
13315ce9237cSJohn Marino {
13325ce9237cSJohn Marino VEC(tree,gc) *vec = make_tree_vector ();
13335ce9237cSJohn Marino bool changed = false;
13345ce9237cSJohn Marino tree it;
13355ce9237cSJohn Marino for (it = t; it; it = TREE_CHAIN (it))
13365ce9237cSJohn Marino {
13375ce9237cSJohn Marino tree val = strip_typedefs_expr (TREE_VALUE (t));
13385ce9237cSJohn Marino VEC_safe_push (tree, gc, vec, val);
13395ce9237cSJohn Marino if (val != TREE_VALUE (t))
13405ce9237cSJohn Marino changed = true;
13415ce9237cSJohn Marino gcc_assert (TREE_PURPOSE (it) == NULL_TREE);
13425ce9237cSJohn Marino }
13435ce9237cSJohn Marino if (changed)
13445ce9237cSJohn Marino {
13455ce9237cSJohn Marino r = NULL_TREE;
13465ce9237cSJohn Marino FOR_EACH_VEC_ELT_REVERSE (tree, vec, i, it)
13475ce9237cSJohn Marino r = tree_cons (NULL_TREE, it, r);
13485ce9237cSJohn Marino }
13495ce9237cSJohn Marino else
13505ce9237cSJohn Marino r = t;
13515ce9237cSJohn Marino release_tree_vector (vec);
13525ce9237cSJohn Marino return r;
13535ce9237cSJohn Marino }
13545ce9237cSJohn Marino
13555ce9237cSJohn Marino case TREE_VEC:
13565ce9237cSJohn Marino {
13575ce9237cSJohn Marino bool changed = false;
13585ce9237cSJohn Marino VEC(tree,gc)* vec = make_tree_vector ();
13595ce9237cSJohn Marino n = TREE_VEC_LENGTH (t);
13605ce9237cSJohn Marino VEC_reserve (tree, gc, vec, n);
13615ce9237cSJohn Marino for (i = 0; i < n; ++i)
13625ce9237cSJohn Marino {
13635ce9237cSJohn Marino tree op = strip_typedefs_expr (TREE_VEC_ELT (t, i));
13645ce9237cSJohn Marino VEC_quick_push (tree, vec, op);
13655ce9237cSJohn Marino if (op != TREE_VEC_ELT (t, i))
13665ce9237cSJohn Marino changed = true;
13675ce9237cSJohn Marino }
13685ce9237cSJohn Marino if (changed)
13695ce9237cSJohn Marino {
13705ce9237cSJohn Marino r = copy_node (t);
13715ce9237cSJohn Marino for (i = 0; i < n; ++i)
13725ce9237cSJohn Marino TREE_VEC_ELT (r, i) = VEC_index (tree, vec, i);
13735ce9237cSJohn Marino NON_DEFAULT_TEMPLATE_ARGS_COUNT (r)
13745ce9237cSJohn Marino = NON_DEFAULT_TEMPLATE_ARGS_COUNT (t);
13755ce9237cSJohn Marino }
13765ce9237cSJohn Marino else
13775ce9237cSJohn Marino r = t;
13785ce9237cSJohn Marino release_tree_vector (vec);
13795ce9237cSJohn Marino return r;
13805ce9237cSJohn Marino }
13815ce9237cSJohn Marino
13825ce9237cSJohn Marino case CONSTRUCTOR:
13835ce9237cSJohn Marino {
13845ce9237cSJohn Marino bool changed = false;
13855ce9237cSJohn Marino VEC(constructor_elt,gc) *vec
13865ce9237cSJohn Marino = VEC_copy (constructor_elt, gc, CONSTRUCTOR_ELTS (t));
13875ce9237cSJohn Marino n = CONSTRUCTOR_NELTS (t);
13885ce9237cSJohn Marino type = strip_typedefs (TREE_TYPE (t));
13895ce9237cSJohn Marino for (i = 0; i < n; ++i)
13905ce9237cSJohn Marino {
13915ce9237cSJohn Marino constructor_elt *e = VEC_index (constructor_elt, vec, i);
13925ce9237cSJohn Marino tree op = strip_typedefs_expr (e->value);
13935ce9237cSJohn Marino if (op != e->value)
13945ce9237cSJohn Marino {
13955ce9237cSJohn Marino changed = true;
13965ce9237cSJohn Marino e->value = op;
13975ce9237cSJohn Marino }
13985ce9237cSJohn Marino gcc_checking_assert (e->index == strip_typedefs_expr (e->index));
13995ce9237cSJohn Marino }
14005ce9237cSJohn Marino
14015ce9237cSJohn Marino if (!changed && type == TREE_TYPE (t))
14025ce9237cSJohn Marino {
14035ce9237cSJohn Marino VEC_free (constructor_elt, gc, vec);
14045ce9237cSJohn Marino return t;
14055ce9237cSJohn Marino }
14065ce9237cSJohn Marino else
14075ce9237cSJohn Marino {
14085ce9237cSJohn Marino r = copy_node (t);
14095ce9237cSJohn Marino TREE_TYPE (r) = type;
14105ce9237cSJohn Marino CONSTRUCTOR_ELTS (r) = vec;
14115ce9237cSJohn Marino return r;
14125ce9237cSJohn Marino }
14135ce9237cSJohn Marino }
14145ce9237cSJohn Marino
14155ce9237cSJohn Marino case LAMBDA_EXPR:
14165ce9237cSJohn Marino gcc_unreachable ();
14175ce9237cSJohn Marino
14185ce9237cSJohn Marino default:
14195ce9237cSJohn Marino break;
14205ce9237cSJohn Marino }
14215ce9237cSJohn Marino
14225ce9237cSJohn Marino gcc_assert (EXPR_P (t));
14235ce9237cSJohn Marino
14245ce9237cSJohn Marino n = TREE_OPERAND_LENGTH (t);
14255ce9237cSJohn Marino ops = XALLOCAVEC (tree, n);
14265ce9237cSJohn Marino type = TREE_TYPE (t);
14275ce9237cSJohn Marino
14285ce9237cSJohn Marino switch (code)
14295ce9237cSJohn Marino {
14305ce9237cSJohn Marino CASE_CONVERT:
14315ce9237cSJohn Marino case IMPLICIT_CONV_EXPR:
14325ce9237cSJohn Marino case DYNAMIC_CAST_EXPR:
14335ce9237cSJohn Marino case STATIC_CAST_EXPR:
14345ce9237cSJohn Marino case CONST_CAST_EXPR:
14355ce9237cSJohn Marino case REINTERPRET_CAST_EXPR:
14365ce9237cSJohn Marino case CAST_EXPR:
14375ce9237cSJohn Marino case NEW_EXPR:
14385ce9237cSJohn Marino type = strip_typedefs (type);
14395ce9237cSJohn Marino /* fallthrough */
14405ce9237cSJohn Marino
14415ce9237cSJohn Marino default:
14425ce9237cSJohn Marino for (i = 0; i < n; ++i)
14435ce9237cSJohn Marino ops[i] = strip_typedefs_expr (TREE_OPERAND (t, i));
14445ce9237cSJohn Marino break;
14455ce9237cSJohn Marino }
14465ce9237cSJohn Marino
14475ce9237cSJohn Marino /* If nothing changed, return t. */
14485ce9237cSJohn Marino for (i = 0; i < n; ++i)
14495ce9237cSJohn Marino if (ops[i] != TREE_OPERAND (t, i))
14505ce9237cSJohn Marino break;
14515ce9237cSJohn Marino if (i == n && type == TREE_TYPE (t))
14525ce9237cSJohn Marino return t;
14535ce9237cSJohn Marino
14545ce9237cSJohn Marino r = copy_node (t);
14555ce9237cSJohn Marino TREE_TYPE (r) = type;
14565ce9237cSJohn Marino for (i = 0; i < n; ++i)
14575ce9237cSJohn Marino TREE_OPERAND (r, i) = ops[i];
14585ce9237cSJohn Marino return r;
14595ce9237cSJohn Marino }
14605ce9237cSJohn Marino
1461e4b17023SJohn Marino /* Makes a copy of BINFO and TYPE, which is to be inherited into a
1462e4b17023SJohn Marino graph dominated by T. If BINFO is NULL, TYPE is a dependent base,
1463e4b17023SJohn Marino and we do a shallow copy. If BINFO is non-NULL, we do a deep copy.
1464e4b17023SJohn Marino VIRT indicates whether TYPE is inherited virtually or not.
1465e4b17023SJohn Marino IGO_PREV points at the previous binfo of the inheritance graph
1466e4b17023SJohn Marino order chain. The newly copied binfo's TREE_CHAIN forms this
1467e4b17023SJohn Marino ordering.
1468e4b17023SJohn Marino
1469e4b17023SJohn Marino The CLASSTYPE_VBASECLASSES vector of T is constructed in the
1470e4b17023SJohn Marino correct order. That is in the order the bases themselves should be
1471e4b17023SJohn Marino constructed in.
1472e4b17023SJohn Marino
1473e4b17023SJohn Marino The BINFO_INHERITANCE of a virtual base class points to the binfo
1474e4b17023SJohn Marino of the most derived type. ??? We could probably change this so that
1475e4b17023SJohn Marino BINFO_INHERITANCE becomes synonymous with BINFO_PRIMARY, and hence
1476e4b17023SJohn Marino remove a field. They currently can only differ for primary virtual
1477e4b17023SJohn Marino virtual bases. */
1478e4b17023SJohn Marino
1479e4b17023SJohn Marino tree
copy_binfo(tree binfo,tree type,tree t,tree * igo_prev,int virt)1480e4b17023SJohn Marino copy_binfo (tree binfo, tree type, tree t, tree *igo_prev, int virt)
1481e4b17023SJohn Marino {
1482e4b17023SJohn Marino tree new_binfo;
1483e4b17023SJohn Marino
1484e4b17023SJohn Marino if (virt)
1485e4b17023SJohn Marino {
1486e4b17023SJohn Marino /* See if we've already made this virtual base. */
1487e4b17023SJohn Marino new_binfo = binfo_for_vbase (type, t);
1488e4b17023SJohn Marino if (new_binfo)
1489e4b17023SJohn Marino return new_binfo;
1490e4b17023SJohn Marino }
1491e4b17023SJohn Marino
1492e4b17023SJohn Marino new_binfo = make_tree_binfo (binfo ? BINFO_N_BASE_BINFOS (binfo) : 0);
1493e4b17023SJohn Marino BINFO_TYPE (new_binfo) = type;
1494e4b17023SJohn Marino
1495e4b17023SJohn Marino /* Chain it into the inheritance graph. */
1496e4b17023SJohn Marino TREE_CHAIN (*igo_prev) = new_binfo;
1497e4b17023SJohn Marino *igo_prev = new_binfo;
1498e4b17023SJohn Marino
1499e4b17023SJohn Marino if (binfo && !BINFO_DEPENDENT_BASE_P (binfo))
1500e4b17023SJohn Marino {
1501e4b17023SJohn Marino int ix;
1502e4b17023SJohn Marino tree base_binfo;
1503e4b17023SJohn Marino
1504e4b17023SJohn Marino gcc_assert (SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), type));
1505e4b17023SJohn Marino
1506e4b17023SJohn Marino BINFO_OFFSET (new_binfo) = BINFO_OFFSET (binfo);
1507e4b17023SJohn Marino BINFO_VIRTUALS (new_binfo) = BINFO_VIRTUALS (binfo);
1508e4b17023SJohn Marino
1509e4b17023SJohn Marino /* We do not need to copy the accesses, as they are read only. */
1510e4b17023SJohn Marino BINFO_BASE_ACCESSES (new_binfo) = BINFO_BASE_ACCESSES (binfo);
1511e4b17023SJohn Marino
1512e4b17023SJohn Marino /* Recursively copy base binfos of BINFO. */
1513e4b17023SJohn Marino for (ix = 0; BINFO_BASE_ITERATE (binfo, ix, base_binfo); ix++)
1514e4b17023SJohn Marino {
1515e4b17023SJohn Marino tree new_base_binfo;
1516e4b17023SJohn Marino new_base_binfo = copy_binfo (base_binfo, BINFO_TYPE (base_binfo),
1517e4b17023SJohn Marino t, igo_prev,
1518e4b17023SJohn Marino BINFO_VIRTUAL_P (base_binfo));
1519e4b17023SJohn Marino
1520e4b17023SJohn Marino if (!BINFO_INHERITANCE_CHAIN (new_base_binfo))
1521e4b17023SJohn Marino BINFO_INHERITANCE_CHAIN (new_base_binfo) = new_binfo;
1522e4b17023SJohn Marino BINFO_BASE_APPEND (new_binfo, new_base_binfo);
1523e4b17023SJohn Marino }
1524e4b17023SJohn Marino }
1525e4b17023SJohn Marino else
1526e4b17023SJohn Marino BINFO_DEPENDENT_BASE_P (new_binfo) = 1;
1527e4b17023SJohn Marino
1528e4b17023SJohn Marino if (virt)
1529e4b17023SJohn Marino {
1530e4b17023SJohn Marino /* Push it onto the list after any virtual bases it contains
1531e4b17023SJohn Marino will have been pushed. */
1532e4b17023SJohn Marino VEC_quick_push (tree, CLASSTYPE_VBASECLASSES (t), new_binfo);
1533e4b17023SJohn Marino BINFO_VIRTUAL_P (new_binfo) = 1;
1534e4b17023SJohn Marino BINFO_INHERITANCE_CHAIN (new_binfo) = TYPE_BINFO (t);
1535e4b17023SJohn Marino }
1536e4b17023SJohn Marino
1537e4b17023SJohn Marino return new_binfo;
1538e4b17023SJohn Marino }
1539e4b17023SJohn Marino
1540e4b17023SJohn Marino /* Hashing of lists so that we don't make duplicates.
1541e4b17023SJohn Marino The entry point is `list_hash_canon'. */
1542e4b17023SJohn Marino
1543e4b17023SJohn Marino /* Now here is the hash table. When recording a list, it is added
1544e4b17023SJohn Marino to the slot whose index is the hash code mod the table size.
1545e4b17023SJohn Marino Note that the hash table is used for several kinds of lists.
1546e4b17023SJohn Marino While all these live in the same table, they are completely independent,
1547e4b17023SJohn Marino and the hash code is computed differently for each of these. */
1548e4b17023SJohn Marino
1549e4b17023SJohn Marino static GTY ((param_is (union tree_node))) htab_t list_hash_table;
1550e4b17023SJohn Marino
1551e4b17023SJohn Marino struct list_proxy
1552e4b17023SJohn Marino {
1553e4b17023SJohn Marino tree purpose;
1554e4b17023SJohn Marino tree value;
1555e4b17023SJohn Marino tree chain;
1556e4b17023SJohn Marino };
1557e4b17023SJohn Marino
1558e4b17023SJohn Marino /* Compare ENTRY (an entry in the hash table) with DATA (a list_proxy
1559e4b17023SJohn Marino for a node we are thinking about adding). */
1560e4b17023SJohn Marino
1561e4b17023SJohn Marino static int
list_hash_eq(const void * entry,const void * data)1562e4b17023SJohn Marino list_hash_eq (const void* entry, const void* data)
1563e4b17023SJohn Marino {
1564e4b17023SJohn Marino const_tree const t = (const_tree) entry;
1565e4b17023SJohn Marino const struct list_proxy *const proxy = (const struct list_proxy *) data;
1566e4b17023SJohn Marino
1567e4b17023SJohn Marino return (TREE_VALUE (t) == proxy->value
1568e4b17023SJohn Marino && TREE_PURPOSE (t) == proxy->purpose
1569e4b17023SJohn Marino && TREE_CHAIN (t) == proxy->chain);
1570e4b17023SJohn Marino }
1571e4b17023SJohn Marino
1572e4b17023SJohn Marino /* Compute a hash code for a list (chain of TREE_LIST nodes
1573e4b17023SJohn Marino with goodies in the TREE_PURPOSE, TREE_VALUE, and bits of the
1574e4b17023SJohn Marino TREE_COMMON slots), by adding the hash codes of the individual entries. */
1575e4b17023SJohn Marino
1576e4b17023SJohn Marino static hashval_t
list_hash_pieces(tree purpose,tree value,tree chain)1577e4b17023SJohn Marino list_hash_pieces (tree purpose, tree value, tree chain)
1578e4b17023SJohn Marino {
1579e4b17023SJohn Marino hashval_t hashcode = 0;
1580e4b17023SJohn Marino
1581e4b17023SJohn Marino if (chain)
1582e4b17023SJohn Marino hashcode += TREE_HASH (chain);
1583e4b17023SJohn Marino
1584e4b17023SJohn Marino if (value)
1585e4b17023SJohn Marino hashcode += TREE_HASH (value);
1586e4b17023SJohn Marino else
1587e4b17023SJohn Marino hashcode += 1007;
1588e4b17023SJohn Marino if (purpose)
1589e4b17023SJohn Marino hashcode += TREE_HASH (purpose);
1590e4b17023SJohn Marino else
1591e4b17023SJohn Marino hashcode += 1009;
1592e4b17023SJohn Marino return hashcode;
1593e4b17023SJohn Marino }
1594e4b17023SJohn Marino
1595e4b17023SJohn Marino /* Hash an already existing TREE_LIST. */
1596e4b17023SJohn Marino
1597e4b17023SJohn Marino static hashval_t
list_hash(const void * p)1598e4b17023SJohn Marino list_hash (const void* p)
1599e4b17023SJohn Marino {
1600e4b17023SJohn Marino const_tree const t = (const_tree) p;
1601e4b17023SJohn Marino return list_hash_pieces (TREE_PURPOSE (t),
1602e4b17023SJohn Marino TREE_VALUE (t),
1603e4b17023SJohn Marino TREE_CHAIN (t));
1604e4b17023SJohn Marino }
1605e4b17023SJohn Marino
1606e4b17023SJohn Marino /* Given list components PURPOSE, VALUE, AND CHAIN, return the canonical
1607e4b17023SJohn Marino object for an identical list if one already exists. Otherwise, build a
1608e4b17023SJohn Marino new one, and record it as the canonical object. */
1609e4b17023SJohn Marino
1610e4b17023SJohn Marino tree
hash_tree_cons(tree purpose,tree value,tree chain)1611e4b17023SJohn Marino hash_tree_cons (tree purpose, tree value, tree chain)
1612e4b17023SJohn Marino {
1613e4b17023SJohn Marino int hashcode = 0;
1614e4b17023SJohn Marino void **slot;
1615e4b17023SJohn Marino struct list_proxy proxy;
1616e4b17023SJohn Marino
1617e4b17023SJohn Marino /* Hash the list node. */
1618e4b17023SJohn Marino hashcode = list_hash_pieces (purpose, value, chain);
1619e4b17023SJohn Marino /* Create a proxy for the TREE_LIST we would like to create. We
1620e4b17023SJohn Marino don't actually create it so as to avoid creating garbage. */
1621e4b17023SJohn Marino proxy.purpose = purpose;
1622e4b17023SJohn Marino proxy.value = value;
1623e4b17023SJohn Marino proxy.chain = chain;
1624e4b17023SJohn Marino /* See if it is already in the table. */
1625e4b17023SJohn Marino slot = htab_find_slot_with_hash (list_hash_table, &proxy, hashcode,
1626e4b17023SJohn Marino INSERT);
1627e4b17023SJohn Marino /* If not, create a new node. */
1628e4b17023SJohn Marino if (!*slot)
1629e4b17023SJohn Marino *slot = tree_cons (purpose, value, chain);
1630e4b17023SJohn Marino return (tree) *slot;
1631e4b17023SJohn Marino }
1632e4b17023SJohn Marino
1633e4b17023SJohn Marino /* Constructor for hashed lists. */
1634e4b17023SJohn Marino
1635e4b17023SJohn Marino tree
hash_tree_chain(tree value,tree chain)1636e4b17023SJohn Marino hash_tree_chain (tree value, tree chain)
1637e4b17023SJohn Marino {
1638e4b17023SJohn Marino return hash_tree_cons (NULL_TREE, value, chain);
1639e4b17023SJohn Marino }
1640e4b17023SJohn Marino
1641e4b17023SJohn Marino void
debug_binfo(tree elem)1642e4b17023SJohn Marino debug_binfo (tree elem)
1643e4b17023SJohn Marino {
1644e4b17023SJohn Marino HOST_WIDE_INT n;
1645e4b17023SJohn Marino tree virtuals;
1646e4b17023SJohn Marino
1647e4b17023SJohn Marino fprintf (stderr, "type \"%s\", offset = " HOST_WIDE_INT_PRINT_DEC
1648e4b17023SJohn Marino "\nvtable type:\n",
1649e4b17023SJohn Marino TYPE_NAME_STRING (BINFO_TYPE (elem)),
1650e4b17023SJohn Marino TREE_INT_CST_LOW (BINFO_OFFSET (elem)));
1651e4b17023SJohn Marino debug_tree (BINFO_TYPE (elem));
1652e4b17023SJohn Marino if (BINFO_VTABLE (elem))
1653e4b17023SJohn Marino fprintf (stderr, "vtable decl \"%s\"\n",
1654e4b17023SJohn Marino IDENTIFIER_POINTER (DECL_NAME (get_vtbl_decl_for_binfo (elem))));
1655e4b17023SJohn Marino else
1656e4b17023SJohn Marino fprintf (stderr, "no vtable decl yet\n");
1657e4b17023SJohn Marino fprintf (stderr, "virtuals:\n");
1658e4b17023SJohn Marino virtuals = BINFO_VIRTUALS (elem);
1659e4b17023SJohn Marino n = 0;
1660e4b17023SJohn Marino
1661e4b17023SJohn Marino while (virtuals)
1662e4b17023SJohn Marino {
1663e4b17023SJohn Marino tree fndecl = TREE_VALUE (virtuals);
1664e4b17023SJohn Marino fprintf (stderr, "%s [%ld =? %ld]\n",
1665e4b17023SJohn Marino IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (fndecl)),
1666e4b17023SJohn Marino (long) n, (long) TREE_INT_CST_LOW (DECL_VINDEX (fndecl)));
1667e4b17023SJohn Marino ++n;
1668e4b17023SJohn Marino virtuals = TREE_CHAIN (virtuals);
1669e4b17023SJohn Marino }
1670e4b17023SJohn Marino }
1671e4b17023SJohn Marino
1672e4b17023SJohn Marino /* Build a representation for the qualified name SCOPE::NAME. TYPE is
1673e4b17023SJohn Marino the type of the result expression, if known, or NULL_TREE if the
1674e4b17023SJohn Marino resulting expression is type-dependent. If TEMPLATE_P is true,
1675e4b17023SJohn Marino NAME is known to be a template because the user explicitly used the
1676e4b17023SJohn Marino "template" keyword after the "::".
1677e4b17023SJohn Marino
1678e4b17023SJohn Marino All SCOPE_REFs should be built by use of this function. */
1679e4b17023SJohn Marino
1680e4b17023SJohn Marino tree
build_qualified_name(tree type,tree scope,tree name,bool template_p)1681e4b17023SJohn Marino build_qualified_name (tree type, tree scope, tree name, bool template_p)
1682e4b17023SJohn Marino {
1683e4b17023SJohn Marino tree t;
1684e4b17023SJohn Marino if (type == error_mark_node
1685e4b17023SJohn Marino || scope == error_mark_node
1686e4b17023SJohn Marino || name == error_mark_node)
1687e4b17023SJohn Marino return error_mark_node;
1688e4b17023SJohn Marino t = build2 (SCOPE_REF, type, scope, name);
1689e4b17023SJohn Marino QUALIFIED_NAME_IS_TEMPLATE (t) = template_p;
1690e4b17023SJohn Marino PTRMEM_OK_P (t) = true;
1691e4b17023SJohn Marino if (type)
1692e4b17023SJohn Marino t = convert_from_reference (t);
1693e4b17023SJohn Marino return t;
1694e4b17023SJohn Marino }
1695e4b17023SJohn Marino
1696e4b17023SJohn Marino /* Returns nonzero if X is an expression for a (possibly overloaded)
1697e4b17023SJohn Marino function. If "f" is a function or function template, "f", "c->f",
1698e4b17023SJohn Marino "c.f", "C::f", and "f<int>" will all be considered possibly
1699e4b17023SJohn Marino overloaded functions. Returns 2 if the function is actually
1700e4b17023SJohn Marino overloaded, i.e., if it is impossible to know the type of the
1701e4b17023SJohn Marino function without performing overload resolution. */
1702e4b17023SJohn Marino
1703e4b17023SJohn Marino int
is_overloaded_fn(tree x)1704e4b17023SJohn Marino is_overloaded_fn (tree x)
1705e4b17023SJohn Marino {
1706e4b17023SJohn Marino /* A baselink is also considered an overloaded function. */
1707e4b17023SJohn Marino if (TREE_CODE (x) == OFFSET_REF
1708e4b17023SJohn Marino || TREE_CODE (x) == COMPONENT_REF)
1709e4b17023SJohn Marino x = TREE_OPERAND (x, 1);
1710e4b17023SJohn Marino if (BASELINK_P (x))
1711e4b17023SJohn Marino x = BASELINK_FUNCTIONS (x);
1712e4b17023SJohn Marino if (TREE_CODE (x) == TEMPLATE_ID_EXPR)
1713e4b17023SJohn Marino x = TREE_OPERAND (x, 0);
1714e4b17023SJohn Marino if (DECL_FUNCTION_TEMPLATE_P (OVL_CURRENT (x))
1715e4b17023SJohn Marino || (TREE_CODE (x) == OVERLOAD && OVL_CHAIN (x)))
1716e4b17023SJohn Marino return 2;
1717e4b17023SJohn Marino return (TREE_CODE (x) == FUNCTION_DECL
1718e4b17023SJohn Marino || TREE_CODE (x) == OVERLOAD);
1719e4b17023SJohn Marino }
1720e4b17023SJohn Marino
1721e4b17023SJohn Marino /* X is the CALL_EXPR_FN of a CALL_EXPR. If X represents a dependent name
1722e4b17023SJohn Marino (14.6.2), return the IDENTIFIER_NODE for that name. Otherwise, return
1723e4b17023SJohn Marino NULL_TREE. */
1724e4b17023SJohn Marino
1725e4b17023SJohn Marino tree
dependent_name(tree x)1726e4b17023SJohn Marino dependent_name (tree x)
1727e4b17023SJohn Marino {
1728e4b17023SJohn Marino if (TREE_CODE (x) == IDENTIFIER_NODE)
1729e4b17023SJohn Marino return x;
1730e4b17023SJohn Marino if (TREE_CODE (x) != COMPONENT_REF
1731e4b17023SJohn Marino && TREE_CODE (x) != OFFSET_REF
1732e4b17023SJohn Marino && TREE_CODE (x) != BASELINK
1733e4b17023SJohn Marino && is_overloaded_fn (x))
1734e4b17023SJohn Marino return DECL_NAME (get_first_fn (x));
1735e4b17023SJohn Marino return NULL_TREE;
1736e4b17023SJohn Marino }
1737e4b17023SJohn Marino
1738e4b17023SJohn Marino /* Returns true iff X is an expression for an overloaded function
1739e4b17023SJohn Marino whose type cannot be known without performing overload
1740e4b17023SJohn Marino resolution. */
1741e4b17023SJohn Marino
1742e4b17023SJohn Marino bool
really_overloaded_fn(tree x)1743e4b17023SJohn Marino really_overloaded_fn (tree x)
1744e4b17023SJohn Marino {
1745e4b17023SJohn Marino return is_overloaded_fn (x) == 2;
1746e4b17023SJohn Marino }
1747e4b17023SJohn Marino
1748e4b17023SJohn Marino tree
get_fns(tree from)1749e4b17023SJohn Marino get_fns (tree from)
1750e4b17023SJohn Marino {
1751e4b17023SJohn Marino gcc_assert (is_overloaded_fn (from));
1752e4b17023SJohn Marino /* A baselink is also considered an overloaded function. */
1753e4b17023SJohn Marino if (TREE_CODE (from) == OFFSET_REF
1754e4b17023SJohn Marino || TREE_CODE (from) == COMPONENT_REF)
1755e4b17023SJohn Marino from = TREE_OPERAND (from, 1);
1756e4b17023SJohn Marino if (BASELINK_P (from))
1757e4b17023SJohn Marino from = BASELINK_FUNCTIONS (from);
1758e4b17023SJohn Marino if (TREE_CODE (from) == TEMPLATE_ID_EXPR)
1759e4b17023SJohn Marino from = TREE_OPERAND (from, 0);
1760e4b17023SJohn Marino return from;
1761e4b17023SJohn Marino }
1762e4b17023SJohn Marino
1763e4b17023SJohn Marino tree
get_first_fn(tree from)1764e4b17023SJohn Marino get_first_fn (tree from)
1765e4b17023SJohn Marino {
1766e4b17023SJohn Marino return OVL_CURRENT (get_fns (from));
1767e4b17023SJohn Marino }
1768e4b17023SJohn Marino
1769e4b17023SJohn Marino /* Return a new OVL node, concatenating it with the old one. */
1770e4b17023SJohn Marino
1771e4b17023SJohn Marino tree
ovl_cons(tree decl,tree chain)1772e4b17023SJohn Marino ovl_cons (tree decl, tree chain)
1773e4b17023SJohn Marino {
1774e4b17023SJohn Marino tree result = make_node (OVERLOAD);
1775e4b17023SJohn Marino TREE_TYPE (result) = unknown_type_node;
1776e4b17023SJohn Marino OVL_FUNCTION (result) = decl;
1777e4b17023SJohn Marino TREE_CHAIN (result) = chain;
1778e4b17023SJohn Marino
1779e4b17023SJohn Marino return result;
1780e4b17023SJohn Marino }
1781e4b17023SJohn Marino
1782e4b17023SJohn Marino /* Build a new overloaded function. If this is the first one,
1783e4b17023SJohn Marino just return it; otherwise, ovl_cons the _DECLs */
1784e4b17023SJohn Marino
1785e4b17023SJohn Marino tree
build_overload(tree decl,tree chain)1786e4b17023SJohn Marino build_overload (tree decl, tree chain)
1787e4b17023SJohn Marino {
1788e4b17023SJohn Marino if (! chain && TREE_CODE (decl) != TEMPLATE_DECL)
1789e4b17023SJohn Marino return decl;
1790e4b17023SJohn Marino return ovl_cons (decl, chain);
1791e4b17023SJohn Marino }
1792e4b17023SJohn Marino
1793e4b17023SJohn Marino /* Return the scope where the overloaded functions OVL were found. */
1794e4b17023SJohn Marino
1795e4b17023SJohn Marino tree
ovl_scope(tree ovl)1796e4b17023SJohn Marino ovl_scope (tree ovl)
1797e4b17023SJohn Marino {
1798e4b17023SJohn Marino if (TREE_CODE (ovl) == OFFSET_REF
1799e4b17023SJohn Marino || TREE_CODE (ovl) == COMPONENT_REF)
1800e4b17023SJohn Marino ovl = TREE_OPERAND (ovl, 1);
1801e4b17023SJohn Marino if (TREE_CODE (ovl) == BASELINK)
1802e4b17023SJohn Marino return BINFO_TYPE (BASELINK_BINFO (ovl));
1803e4b17023SJohn Marino if (TREE_CODE (ovl) == TEMPLATE_ID_EXPR)
1804e4b17023SJohn Marino ovl = TREE_OPERAND (ovl, 0);
1805e4b17023SJohn Marino /* Skip using-declarations. */
1806e4b17023SJohn Marino while (TREE_CODE (ovl) == OVERLOAD && OVL_USED (ovl) && OVL_CHAIN (ovl))
1807e4b17023SJohn Marino ovl = OVL_CHAIN (ovl);
1808e4b17023SJohn Marino return CP_DECL_CONTEXT (OVL_CURRENT (ovl));
1809e4b17023SJohn Marino }
1810e4b17023SJohn Marino
1811e4b17023SJohn Marino /* Return TRUE if FN is a non-static member function, FALSE otherwise.
1812e4b17023SJohn Marino This function looks into BASELINK and OVERLOAD nodes. */
1813e4b17023SJohn Marino
1814e4b17023SJohn Marino bool
non_static_member_function_p(tree fn)1815e4b17023SJohn Marino non_static_member_function_p (tree fn)
1816e4b17023SJohn Marino {
1817e4b17023SJohn Marino if (fn == NULL_TREE)
1818e4b17023SJohn Marino return false;
1819e4b17023SJohn Marino
1820e4b17023SJohn Marino if (is_overloaded_fn (fn))
1821e4b17023SJohn Marino fn = get_first_fn (fn);
1822e4b17023SJohn Marino
1823e4b17023SJohn Marino return (DECL_P (fn)
1824e4b17023SJohn Marino && DECL_NONSTATIC_MEMBER_FUNCTION_P (fn));
1825e4b17023SJohn Marino }
1826e4b17023SJohn Marino
1827e4b17023SJohn Marino
1828e4b17023SJohn Marino #define PRINT_RING_SIZE 4
1829e4b17023SJohn Marino
1830e4b17023SJohn Marino static const char *
cxx_printable_name_internal(tree decl,int v,bool translate)1831e4b17023SJohn Marino cxx_printable_name_internal (tree decl, int v, bool translate)
1832e4b17023SJohn Marino {
1833e4b17023SJohn Marino static unsigned int uid_ring[PRINT_RING_SIZE];
1834e4b17023SJohn Marino static char *print_ring[PRINT_RING_SIZE];
1835e4b17023SJohn Marino static bool trans_ring[PRINT_RING_SIZE];
1836e4b17023SJohn Marino static int ring_counter;
1837e4b17023SJohn Marino int i;
1838e4b17023SJohn Marino
1839e4b17023SJohn Marino /* Only cache functions. */
1840e4b17023SJohn Marino if (v < 2
1841e4b17023SJohn Marino || TREE_CODE (decl) != FUNCTION_DECL
1842e4b17023SJohn Marino || DECL_LANG_SPECIFIC (decl) == 0)
1843e4b17023SJohn Marino return lang_decl_name (decl, v, translate);
1844e4b17023SJohn Marino
1845e4b17023SJohn Marino /* See if this print name is lying around. */
1846e4b17023SJohn Marino for (i = 0; i < PRINT_RING_SIZE; i++)
1847e4b17023SJohn Marino if (uid_ring[i] == DECL_UID (decl) && translate == trans_ring[i])
1848e4b17023SJohn Marino /* yes, so return it. */
1849e4b17023SJohn Marino return print_ring[i];
1850e4b17023SJohn Marino
1851e4b17023SJohn Marino if (++ring_counter == PRINT_RING_SIZE)
1852e4b17023SJohn Marino ring_counter = 0;
1853e4b17023SJohn Marino
1854e4b17023SJohn Marino if (current_function_decl != NULL_TREE)
1855e4b17023SJohn Marino {
1856e4b17023SJohn Marino /* There may be both translated and untranslated versions of the
1857e4b17023SJohn Marino name cached. */
1858e4b17023SJohn Marino for (i = 0; i < 2; i++)
1859e4b17023SJohn Marino {
1860e4b17023SJohn Marino if (uid_ring[ring_counter] == DECL_UID (current_function_decl))
1861e4b17023SJohn Marino ring_counter += 1;
1862e4b17023SJohn Marino if (ring_counter == PRINT_RING_SIZE)
1863e4b17023SJohn Marino ring_counter = 0;
1864e4b17023SJohn Marino }
1865e4b17023SJohn Marino gcc_assert (uid_ring[ring_counter] != DECL_UID (current_function_decl));
1866e4b17023SJohn Marino }
1867e4b17023SJohn Marino
1868e4b17023SJohn Marino free (print_ring[ring_counter]);
1869e4b17023SJohn Marino
1870e4b17023SJohn Marino print_ring[ring_counter] = xstrdup (lang_decl_name (decl, v, translate));
1871e4b17023SJohn Marino uid_ring[ring_counter] = DECL_UID (decl);
1872e4b17023SJohn Marino trans_ring[ring_counter] = translate;
1873e4b17023SJohn Marino return print_ring[ring_counter];
1874e4b17023SJohn Marino }
1875e4b17023SJohn Marino
1876e4b17023SJohn Marino const char *
cxx_printable_name(tree decl,int v)1877e4b17023SJohn Marino cxx_printable_name (tree decl, int v)
1878e4b17023SJohn Marino {
1879e4b17023SJohn Marino return cxx_printable_name_internal (decl, v, false);
1880e4b17023SJohn Marino }
1881e4b17023SJohn Marino
1882e4b17023SJohn Marino const char *
cxx_printable_name_translate(tree decl,int v)1883e4b17023SJohn Marino cxx_printable_name_translate (tree decl, int v)
1884e4b17023SJohn Marino {
1885e4b17023SJohn Marino return cxx_printable_name_internal (decl, v, true);
1886e4b17023SJohn Marino }
1887e4b17023SJohn Marino
1888e4b17023SJohn Marino /* Build the FUNCTION_TYPE or METHOD_TYPE which may throw exceptions
1889e4b17023SJohn Marino listed in RAISES. */
1890e4b17023SJohn Marino
1891e4b17023SJohn Marino tree
build_exception_variant(tree type,tree raises)1892e4b17023SJohn Marino build_exception_variant (tree type, tree raises)
1893e4b17023SJohn Marino {
1894e4b17023SJohn Marino tree v;
1895e4b17023SJohn Marino int type_quals;
1896e4b17023SJohn Marino
1897e4b17023SJohn Marino if (comp_except_specs (raises, TYPE_RAISES_EXCEPTIONS (type), ce_exact))
1898e4b17023SJohn Marino return type;
1899e4b17023SJohn Marino
1900e4b17023SJohn Marino type_quals = TYPE_QUALS (type);
1901e4b17023SJohn Marino for (v = TYPE_MAIN_VARIANT (type); v; v = TYPE_NEXT_VARIANT (v))
1902e4b17023SJohn Marino if (check_qualified_type (v, type, type_quals)
1903e4b17023SJohn Marino && comp_except_specs (raises, TYPE_RAISES_EXCEPTIONS (v), ce_exact))
1904e4b17023SJohn Marino return v;
1905e4b17023SJohn Marino
1906e4b17023SJohn Marino /* Need to build a new variant. */
1907e4b17023SJohn Marino v = build_variant_type_copy (type);
1908e4b17023SJohn Marino TYPE_RAISES_EXCEPTIONS (v) = raises;
1909e4b17023SJohn Marino return v;
1910e4b17023SJohn Marino }
1911e4b17023SJohn Marino
1912e4b17023SJohn Marino /* Given a TEMPLATE_TEMPLATE_PARM node T, create a new
1913e4b17023SJohn Marino BOUND_TEMPLATE_TEMPLATE_PARM bound with NEWARGS as its template
1914e4b17023SJohn Marino arguments. */
1915e4b17023SJohn Marino
1916e4b17023SJohn Marino tree
bind_template_template_parm(tree t,tree newargs)1917e4b17023SJohn Marino bind_template_template_parm (tree t, tree newargs)
1918e4b17023SJohn Marino {
1919e4b17023SJohn Marino tree decl = TYPE_NAME (t);
1920e4b17023SJohn Marino tree t2;
1921e4b17023SJohn Marino
1922e4b17023SJohn Marino t2 = cxx_make_type (BOUND_TEMPLATE_TEMPLATE_PARM);
1923e4b17023SJohn Marino decl = build_decl (input_location,
1924e4b17023SJohn Marino TYPE_DECL, DECL_NAME (decl), NULL_TREE);
1925e4b17023SJohn Marino
1926e4b17023SJohn Marino /* These nodes have to be created to reflect new TYPE_DECL and template
1927e4b17023SJohn Marino arguments. */
1928e4b17023SJohn Marino TEMPLATE_TYPE_PARM_INDEX (t2) = copy_node (TEMPLATE_TYPE_PARM_INDEX (t));
1929e4b17023SJohn Marino TEMPLATE_PARM_DECL (TEMPLATE_TYPE_PARM_INDEX (t2)) = decl;
1930e4b17023SJohn Marino TEMPLATE_TEMPLATE_PARM_TEMPLATE_INFO (t2)
1931e4b17023SJohn Marino = build_template_info (TEMPLATE_TEMPLATE_PARM_TEMPLATE_DECL (t), newargs);
1932e4b17023SJohn Marino
1933e4b17023SJohn Marino TREE_TYPE (decl) = t2;
1934e4b17023SJohn Marino TYPE_NAME (t2) = decl;
1935e4b17023SJohn Marino TYPE_STUB_DECL (t2) = decl;
1936e4b17023SJohn Marino TYPE_SIZE (t2) = 0;
1937e4b17023SJohn Marino SET_TYPE_STRUCTURAL_EQUALITY (t2);
1938e4b17023SJohn Marino
1939e4b17023SJohn Marino return t2;
1940e4b17023SJohn Marino }
1941e4b17023SJohn Marino
1942e4b17023SJohn Marino /* Called from count_trees via walk_tree. */
1943e4b17023SJohn Marino
1944e4b17023SJohn Marino static tree
count_trees_r(tree * tp,int * walk_subtrees,void * data)1945e4b17023SJohn Marino count_trees_r (tree *tp, int *walk_subtrees, void *data)
1946e4b17023SJohn Marino {
1947e4b17023SJohn Marino ++*((int *) data);
1948e4b17023SJohn Marino
1949e4b17023SJohn Marino if (TYPE_P (*tp))
1950e4b17023SJohn Marino *walk_subtrees = 0;
1951e4b17023SJohn Marino
1952e4b17023SJohn Marino return NULL_TREE;
1953e4b17023SJohn Marino }
1954e4b17023SJohn Marino
1955e4b17023SJohn Marino /* Debugging function for measuring the rough complexity of a tree
1956e4b17023SJohn Marino representation. */
1957e4b17023SJohn Marino
1958e4b17023SJohn Marino int
count_trees(tree t)1959e4b17023SJohn Marino count_trees (tree t)
1960e4b17023SJohn Marino {
1961e4b17023SJohn Marino int n_trees = 0;
1962e4b17023SJohn Marino cp_walk_tree_without_duplicates (&t, count_trees_r, &n_trees);
1963e4b17023SJohn Marino return n_trees;
1964e4b17023SJohn Marino }
1965e4b17023SJohn Marino
1966e4b17023SJohn Marino /* Called from verify_stmt_tree via walk_tree. */
1967e4b17023SJohn Marino
1968e4b17023SJohn Marino static tree
verify_stmt_tree_r(tree * tp,int * walk_subtrees ATTRIBUTE_UNUSED,void * data)1969e4b17023SJohn Marino verify_stmt_tree_r (tree* tp,
1970e4b17023SJohn Marino int* walk_subtrees ATTRIBUTE_UNUSED ,
1971e4b17023SJohn Marino void* data)
1972e4b17023SJohn Marino {
1973e4b17023SJohn Marino tree t = *tp;
1974e4b17023SJohn Marino htab_t *statements = (htab_t *) data;
1975e4b17023SJohn Marino void **slot;
1976e4b17023SJohn Marino
1977e4b17023SJohn Marino if (!STATEMENT_CODE_P (TREE_CODE (t)))
1978e4b17023SJohn Marino return NULL_TREE;
1979e4b17023SJohn Marino
1980e4b17023SJohn Marino /* If this statement is already present in the hash table, then
1981e4b17023SJohn Marino there is a circularity in the statement tree. */
1982e4b17023SJohn Marino gcc_assert (!htab_find (*statements, t));
1983e4b17023SJohn Marino
1984e4b17023SJohn Marino slot = htab_find_slot (*statements, t, INSERT);
1985e4b17023SJohn Marino *slot = t;
1986e4b17023SJohn Marino
1987e4b17023SJohn Marino return NULL_TREE;
1988e4b17023SJohn Marino }
1989e4b17023SJohn Marino
1990e4b17023SJohn Marino /* Debugging function to check that the statement T has not been
1991e4b17023SJohn Marino corrupted. For now, this function simply checks that T contains no
1992e4b17023SJohn Marino circularities. */
1993e4b17023SJohn Marino
1994e4b17023SJohn Marino void
verify_stmt_tree(tree t)1995e4b17023SJohn Marino verify_stmt_tree (tree t)
1996e4b17023SJohn Marino {
1997e4b17023SJohn Marino htab_t statements;
1998e4b17023SJohn Marino statements = htab_create (37, htab_hash_pointer, htab_eq_pointer, NULL);
1999e4b17023SJohn Marino cp_walk_tree (&t, verify_stmt_tree_r, &statements, NULL);
2000e4b17023SJohn Marino htab_delete (statements);
2001e4b17023SJohn Marino }
2002e4b17023SJohn Marino
2003e4b17023SJohn Marino /* Check if the type T depends on a type with no linkage and if so, return
2004e4b17023SJohn Marino it. If RELAXED_P then do not consider a class type declared within
2005e4b17023SJohn Marino a vague-linkage function to have no linkage. */
2006e4b17023SJohn Marino
2007e4b17023SJohn Marino tree
no_linkage_check(tree t,bool relaxed_p)2008e4b17023SJohn Marino no_linkage_check (tree t, bool relaxed_p)
2009e4b17023SJohn Marino {
2010e4b17023SJohn Marino tree r;
2011e4b17023SJohn Marino
2012e4b17023SJohn Marino /* There's no point in checking linkage on template functions; we
2013e4b17023SJohn Marino can't know their complete types. */
2014e4b17023SJohn Marino if (processing_template_decl)
2015e4b17023SJohn Marino return NULL_TREE;
2016e4b17023SJohn Marino
2017e4b17023SJohn Marino switch (TREE_CODE (t))
2018e4b17023SJohn Marino {
2019e4b17023SJohn Marino case RECORD_TYPE:
2020e4b17023SJohn Marino if (TYPE_PTRMEMFUNC_P (t))
2021e4b17023SJohn Marino goto ptrmem;
2022e4b17023SJohn Marino /* Lambda types that don't have mangling scope have no linkage. We
2023e4b17023SJohn Marino check CLASSTYPE_LAMBDA_EXPR here rather than LAMBDA_TYPE_P because
2024e4b17023SJohn Marino when we get here from pushtag none of the lambda information is
2025e4b17023SJohn Marino set up yet, so we want to assume that the lambda has linkage and
2026e4b17023SJohn Marino fix it up later if not. */
2027e4b17023SJohn Marino if (CLASSTYPE_LAMBDA_EXPR (t)
2028e4b17023SJohn Marino && LAMBDA_TYPE_EXTRA_SCOPE (t) == NULL_TREE)
2029e4b17023SJohn Marino return t;
2030e4b17023SJohn Marino /* Fall through. */
2031e4b17023SJohn Marino case UNION_TYPE:
2032e4b17023SJohn Marino if (!CLASS_TYPE_P (t))
2033e4b17023SJohn Marino return NULL_TREE;
2034e4b17023SJohn Marino /* Fall through. */
2035e4b17023SJohn Marino case ENUMERAL_TYPE:
2036e4b17023SJohn Marino /* Only treat anonymous types as having no linkage if they're at
2037e4b17023SJohn Marino namespace scope. This is core issue 966. */
2038e4b17023SJohn Marino if (TYPE_ANONYMOUS_P (t) && TYPE_NAMESPACE_SCOPE_P (t))
2039e4b17023SJohn Marino return t;
2040e4b17023SJohn Marino
2041e4b17023SJohn Marino for (r = CP_TYPE_CONTEXT (t); ; )
2042e4b17023SJohn Marino {
2043e4b17023SJohn Marino /* If we're a nested type of a !TREE_PUBLIC class, we might not
2044e4b17023SJohn Marino have linkage, or we might just be in an anonymous namespace.
2045e4b17023SJohn Marino If we're in a TREE_PUBLIC class, we have linkage. */
2046e4b17023SJohn Marino if (TYPE_P (r) && !TREE_PUBLIC (TYPE_NAME (r)))
2047e4b17023SJohn Marino return no_linkage_check (TYPE_CONTEXT (t), relaxed_p);
2048e4b17023SJohn Marino else if (TREE_CODE (r) == FUNCTION_DECL)
2049e4b17023SJohn Marino {
2050e4b17023SJohn Marino if (!relaxed_p || !vague_linkage_p (r))
2051e4b17023SJohn Marino return t;
2052e4b17023SJohn Marino else
2053e4b17023SJohn Marino r = CP_DECL_CONTEXT (r);
2054e4b17023SJohn Marino }
2055e4b17023SJohn Marino else
2056e4b17023SJohn Marino break;
2057e4b17023SJohn Marino }
2058e4b17023SJohn Marino
2059e4b17023SJohn Marino return NULL_TREE;
2060e4b17023SJohn Marino
2061e4b17023SJohn Marino case ARRAY_TYPE:
2062e4b17023SJohn Marino case POINTER_TYPE:
2063e4b17023SJohn Marino case REFERENCE_TYPE:
2064e4b17023SJohn Marino return no_linkage_check (TREE_TYPE (t), relaxed_p);
2065e4b17023SJohn Marino
2066e4b17023SJohn Marino case OFFSET_TYPE:
2067e4b17023SJohn Marino ptrmem:
2068e4b17023SJohn Marino r = no_linkage_check (TYPE_PTRMEM_POINTED_TO_TYPE (t),
2069e4b17023SJohn Marino relaxed_p);
2070e4b17023SJohn Marino if (r)
2071e4b17023SJohn Marino return r;
2072e4b17023SJohn Marino return no_linkage_check (TYPE_PTRMEM_CLASS_TYPE (t), relaxed_p);
2073e4b17023SJohn Marino
2074e4b17023SJohn Marino case METHOD_TYPE:
2075e4b17023SJohn Marino r = no_linkage_check (TYPE_METHOD_BASETYPE (t), relaxed_p);
2076e4b17023SJohn Marino if (r)
2077e4b17023SJohn Marino return r;
2078e4b17023SJohn Marino /* Fall through. */
2079e4b17023SJohn Marino case FUNCTION_TYPE:
2080e4b17023SJohn Marino {
2081e4b17023SJohn Marino tree parm;
2082e4b17023SJohn Marino for (parm = TYPE_ARG_TYPES (t);
2083e4b17023SJohn Marino parm && parm != void_list_node;
2084e4b17023SJohn Marino parm = TREE_CHAIN (parm))
2085e4b17023SJohn Marino {
2086e4b17023SJohn Marino r = no_linkage_check (TREE_VALUE (parm), relaxed_p);
2087e4b17023SJohn Marino if (r)
2088e4b17023SJohn Marino return r;
2089e4b17023SJohn Marino }
2090e4b17023SJohn Marino return no_linkage_check (TREE_TYPE (t), relaxed_p);
2091e4b17023SJohn Marino }
2092e4b17023SJohn Marino
2093e4b17023SJohn Marino default:
2094e4b17023SJohn Marino return NULL_TREE;
2095e4b17023SJohn Marino }
2096e4b17023SJohn Marino }
2097e4b17023SJohn Marino
2098e4b17023SJohn Marino #ifdef GATHER_STATISTICS
2099e4b17023SJohn Marino extern int depth_reached;
2100e4b17023SJohn Marino #endif
2101e4b17023SJohn Marino
2102e4b17023SJohn Marino void
cxx_print_statistics(void)2103e4b17023SJohn Marino cxx_print_statistics (void)
2104e4b17023SJohn Marino {
2105e4b17023SJohn Marino print_search_statistics ();
2106e4b17023SJohn Marino print_class_statistics ();
2107e4b17023SJohn Marino print_template_statistics ();
2108e4b17023SJohn Marino #ifdef GATHER_STATISTICS
2109e4b17023SJohn Marino fprintf (stderr, "maximum template instantiation depth reached: %d\n",
2110e4b17023SJohn Marino depth_reached);
2111e4b17023SJohn Marino #endif
2112e4b17023SJohn Marino }
2113e4b17023SJohn Marino
2114e4b17023SJohn Marino /* Return, as an INTEGER_CST node, the number of elements for TYPE
2115e4b17023SJohn Marino (which is an ARRAY_TYPE). This counts only elements of the top
2116e4b17023SJohn Marino array. */
2117e4b17023SJohn Marino
2118e4b17023SJohn Marino tree
array_type_nelts_top(tree type)2119e4b17023SJohn Marino array_type_nelts_top (tree type)
2120e4b17023SJohn Marino {
2121e4b17023SJohn Marino return fold_build2_loc (input_location,
2122e4b17023SJohn Marino PLUS_EXPR, sizetype,
2123e4b17023SJohn Marino array_type_nelts (type),
2124e4b17023SJohn Marino size_one_node);
2125e4b17023SJohn Marino }
2126e4b17023SJohn Marino
2127e4b17023SJohn Marino /* Return, as an INTEGER_CST node, the number of elements for TYPE
2128e4b17023SJohn Marino (which is an ARRAY_TYPE). This one is a recursive count of all
2129e4b17023SJohn Marino ARRAY_TYPEs that are clumped together. */
2130e4b17023SJohn Marino
2131e4b17023SJohn Marino tree
array_type_nelts_total(tree type)2132e4b17023SJohn Marino array_type_nelts_total (tree type)
2133e4b17023SJohn Marino {
2134e4b17023SJohn Marino tree sz = array_type_nelts_top (type);
2135e4b17023SJohn Marino type = TREE_TYPE (type);
2136e4b17023SJohn Marino while (TREE_CODE (type) == ARRAY_TYPE)
2137e4b17023SJohn Marino {
2138e4b17023SJohn Marino tree n = array_type_nelts_top (type);
2139e4b17023SJohn Marino sz = fold_build2_loc (input_location,
2140e4b17023SJohn Marino MULT_EXPR, sizetype, sz, n);
2141e4b17023SJohn Marino type = TREE_TYPE (type);
2142e4b17023SJohn Marino }
2143e4b17023SJohn Marino return sz;
2144e4b17023SJohn Marino }
2145e4b17023SJohn Marino
2146e4b17023SJohn Marino /* Called from break_out_target_exprs via mapcar. */
2147e4b17023SJohn Marino
2148e4b17023SJohn Marino static tree
bot_manip(tree * tp,int * walk_subtrees,void * data)2149e4b17023SJohn Marino bot_manip (tree* tp, int* walk_subtrees, void* data)
2150e4b17023SJohn Marino {
2151e4b17023SJohn Marino splay_tree target_remap = ((splay_tree) data);
2152e4b17023SJohn Marino tree t = *tp;
2153e4b17023SJohn Marino
2154e4b17023SJohn Marino if (!TYPE_P (t) && TREE_CONSTANT (t) && !TREE_SIDE_EFFECTS (t))
2155e4b17023SJohn Marino {
2156e4b17023SJohn Marino /* There can't be any TARGET_EXPRs or their slot variables below this
2157e4b17023SJohn Marino point. But we must make a copy, in case subsequent processing
2158e4b17023SJohn Marino alters any part of it. For example, during gimplification a cast
2159e4b17023SJohn Marino of the form (T) &X::f (where "f" is a member function) will lead
2160e4b17023SJohn Marino to replacing the PTRMEM_CST for &X::f with a VAR_DECL. */
2161e4b17023SJohn Marino *walk_subtrees = 0;
2162e4b17023SJohn Marino *tp = unshare_expr (t);
2163e4b17023SJohn Marino return NULL_TREE;
2164e4b17023SJohn Marino }
2165e4b17023SJohn Marino if (TREE_CODE (t) == TARGET_EXPR)
2166e4b17023SJohn Marino {
2167e4b17023SJohn Marino tree u;
2168e4b17023SJohn Marino
2169e4b17023SJohn Marino if (TREE_CODE (TREE_OPERAND (t, 1)) == AGGR_INIT_EXPR)
2170e4b17023SJohn Marino {
2171e4b17023SJohn Marino u = build_cplus_new (TREE_TYPE (t), TREE_OPERAND (t, 1),
2172e4b17023SJohn Marino tf_warning_or_error);
2173e4b17023SJohn Marino if (AGGR_INIT_ZERO_FIRST (TREE_OPERAND (t, 1)))
2174e4b17023SJohn Marino AGGR_INIT_ZERO_FIRST (TREE_OPERAND (u, 1)) = true;
2175e4b17023SJohn Marino }
2176e4b17023SJohn Marino else
2177e4b17023SJohn Marino u = build_target_expr_with_type (TREE_OPERAND (t, 1), TREE_TYPE (t),
2178e4b17023SJohn Marino tf_warning_or_error);
2179e4b17023SJohn Marino
2180e4b17023SJohn Marino TARGET_EXPR_IMPLICIT_P (u) = TARGET_EXPR_IMPLICIT_P (t);
2181e4b17023SJohn Marino TARGET_EXPR_LIST_INIT_P (u) = TARGET_EXPR_LIST_INIT_P (t);
2182e4b17023SJohn Marino TARGET_EXPR_DIRECT_INIT_P (u) = TARGET_EXPR_DIRECT_INIT_P (t);
2183e4b17023SJohn Marino
2184e4b17023SJohn Marino /* Map the old variable to the new one. */
2185e4b17023SJohn Marino splay_tree_insert (target_remap,
2186e4b17023SJohn Marino (splay_tree_key) TREE_OPERAND (t, 0),
2187e4b17023SJohn Marino (splay_tree_value) TREE_OPERAND (u, 0));
2188e4b17023SJohn Marino
2189e4b17023SJohn Marino TREE_OPERAND (u, 1) = break_out_target_exprs (TREE_OPERAND (u, 1));
2190e4b17023SJohn Marino
2191e4b17023SJohn Marino /* Replace the old expression with the new version. */
2192e4b17023SJohn Marino *tp = u;
2193e4b17023SJohn Marino /* We don't have to go below this point; the recursive call to
2194e4b17023SJohn Marino break_out_target_exprs will have handled anything below this
2195e4b17023SJohn Marino point. */
2196e4b17023SJohn Marino *walk_subtrees = 0;
2197e4b17023SJohn Marino return NULL_TREE;
2198e4b17023SJohn Marino }
2199e4b17023SJohn Marino
2200e4b17023SJohn Marino /* Make a copy of this node. */
2201e4b17023SJohn Marino t = copy_tree_r (tp, walk_subtrees, NULL);
2202e4b17023SJohn Marino if (TREE_CODE (*tp) == CALL_EXPR)
2203e4b17023SJohn Marino set_flags_from_callee (*tp);
2204e4b17023SJohn Marino return t;
2205e4b17023SJohn Marino }
2206e4b17023SJohn Marino
2207e4b17023SJohn Marino /* Replace all remapped VAR_DECLs in T with their new equivalents.
2208e4b17023SJohn Marino DATA is really a splay-tree mapping old variables to new
2209e4b17023SJohn Marino variables. */
2210e4b17023SJohn Marino
2211e4b17023SJohn Marino static tree
bot_replace(tree * t,int * walk_subtrees ATTRIBUTE_UNUSED,void * data)2212e4b17023SJohn Marino bot_replace (tree* t,
2213e4b17023SJohn Marino int* walk_subtrees ATTRIBUTE_UNUSED ,
2214e4b17023SJohn Marino void* data)
2215e4b17023SJohn Marino {
2216e4b17023SJohn Marino splay_tree target_remap = ((splay_tree) data);
2217e4b17023SJohn Marino
2218e4b17023SJohn Marino if (TREE_CODE (*t) == VAR_DECL)
2219e4b17023SJohn Marino {
2220e4b17023SJohn Marino splay_tree_node n = splay_tree_lookup (target_remap,
2221e4b17023SJohn Marino (splay_tree_key) *t);
2222e4b17023SJohn Marino if (n)
2223e4b17023SJohn Marino *t = (tree) n->value;
2224e4b17023SJohn Marino }
2225e4b17023SJohn Marino else if (TREE_CODE (*t) == PARM_DECL
2226e4b17023SJohn Marino && DECL_NAME (*t) == this_identifier)
2227e4b17023SJohn Marino {
2228e4b17023SJohn Marino /* In an NSDMI we need to replace the 'this' parameter we used for
2229e4b17023SJohn Marino parsing with the real one for this function. */
2230e4b17023SJohn Marino *t = current_class_ptr;
2231e4b17023SJohn Marino }
2232e4b17023SJohn Marino else if (TREE_CODE (*t) == CONVERT_EXPR
2233e4b17023SJohn Marino && CONVERT_EXPR_VBASE_PATH (*t))
2234e4b17023SJohn Marino {
2235e4b17023SJohn Marino /* In an NSDMI build_base_path defers building conversions to virtual
2236e4b17023SJohn Marino bases, and we handle it here. */
2237e4b17023SJohn Marino tree basetype = TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (*t)));
2238e4b17023SJohn Marino VEC(tree,gc) *vbases = CLASSTYPE_VBASECLASSES (current_class_type);
2239e4b17023SJohn Marino int i; tree binfo;
2240e4b17023SJohn Marino FOR_EACH_VEC_ELT (tree, vbases, i, binfo)
2241e4b17023SJohn Marino if (BINFO_TYPE (binfo) == basetype)
2242e4b17023SJohn Marino break;
2243e4b17023SJohn Marino *t = build_base_path (PLUS_EXPR, TREE_OPERAND (*t, 0), binfo, true,
2244e4b17023SJohn Marino tf_warning_or_error);
2245e4b17023SJohn Marino }
2246e4b17023SJohn Marino
2247e4b17023SJohn Marino return NULL_TREE;
2248e4b17023SJohn Marino }
2249e4b17023SJohn Marino
2250e4b17023SJohn Marino /* When we parse a default argument expression, we may create
2251e4b17023SJohn Marino temporary variables via TARGET_EXPRs. When we actually use the
2252e4b17023SJohn Marino default-argument expression, we make a copy of the expression
2253e4b17023SJohn Marino and replace the temporaries with appropriate local versions. */
2254e4b17023SJohn Marino
2255e4b17023SJohn Marino tree
break_out_target_exprs(tree t)2256e4b17023SJohn Marino break_out_target_exprs (tree t)
2257e4b17023SJohn Marino {
2258e4b17023SJohn Marino static int target_remap_count;
2259e4b17023SJohn Marino static splay_tree target_remap;
2260e4b17023SJohn Marino
2261e4b17023SJohn Marino if (!target_remap_count++)
2262e4b17023SJohn Marino target_remap = splay_tree_new (splay_tree_compare_pointers,
2263e4b17023SJohn Marino /*splay_tree_delete_key_fn=*/NULL,
2264e4b17023SJohn Marino /*splay_tree_delete_value_fn=*/NULL);
2265e4b17023SJohn Marino cp_walk_tree (&t, bot_manip, target_remap, NULL);
2266e4b17023SJohn Marino cp_walk_tree (&t, bot_replace, target_remap, NULL);
2267e4b17023SJohn Marino
2268e4b17023SJohn Marino if (!--target_remap_count)
2269e4b17023SJohn Marino {
2270e4b17023SJohn Marino splay_tree_delete (target_remap);
2271e4b17023SJohn Marino target_remap = NULL;
2272e4b17023SJohn Marino }
2273e4b17023SJohn Marino
2274e4b17023SJohn Marino return t;
2275e4b17023SJohn Marino }
2276e4b17023SJohn Marino
2277e4b17023SJohn Marino /* Similar to `build_nt', but for template definitions of dependent
2278e4b17023SJohn Marino expressions */
2279e4b17023SJohn Marino
2280e4b17023SJohn Marino tree
build_min_nt(enum tree_code code,...)2281e4b17023SJohn Marino build_min_nt (enum tree_code code, ...)
2282e4b17023SJohn Marino {
2283e4b17023SJohn Marino tree t;
2284e4b17023SJohn Marino int length;
2285e4b17023SJohn Marino int i;
2286e4b17023SJohn Marino va_list p;
2287e4b17023SJohn Marino
2288e4b17023SJohn Marino gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
2289e4b17023SJohn Marino
2290e4b17023SJohn Marino va_start (p, code);
2291e4b17023SJohn Marino
2292e4b17023SJohn Marino t = make_node (code);
2293e4b17023SJohn Marino length = TREE_CODE_LENGTH (code);
2294e4b17023SJohn Marino
2295e4b17023SJohn Marino for (i = 0; i < length; i++)
2296e4b17023SJohn Marino {
2297e4b17023SJohn Marino tree x = va_arg (p, tree);
2298e4b17023SJohn Marino TREE_OPERAND (t, i) = x;
2299e4b17023SJohn Marino }
2300e4b17023SJohn Marino
2301e4b17023SJohn Marino va_end (p);
2302e4b17023SJohn Marino return t;
2303e4b17023SJohn Marino }
2304e4b17023SJohn Marino
2305e4b17023SJohn Marino
2306e4b17023SJohn Marino /* Similar to `build', but for template definitions. */
2307e4b17023SJohn Marino
2308e4b17023SJohn Marino tree
build_min(enum tree_code code,tree tt,...)2309e4b17023SJohn Marino build_min (enum tree_code code, tree tt, ...)
2310e4b17023SJohn Marino {
2311e4b17023SJohn Marino tree t;
2312e4b17023SJohn Marino int length;
2313e4b17023SJohn Marino int i;
2314e4b17023SJohn Marino va_list p;
2315e4b17023SJohn Marino
2316e4b17023SJohn Marino gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
2317e4b17023SJohn Marino
2318e4b17023SJohn Marino va_start (p, tt);
2319e4b17023SJohn Marino
2320e4b17023SJohn Marino t = make_node (code);
2321e4b17023SJohn Marino length = TREE_CODE_LENGTH (code);
2322e4b17023SJohn Marino TREE_TYPE (t) = tt;
2323e4b17023SJohn Marino
2324e4b17023SJohn Marino for (i = 0; i < length; i++)
2325e4b17023SJohn Marino {
2326e4b17023SJohn Marino tree x = va_arg (p, tree);
2327e4b17023SJohn Marino TREE_OPERAND (t, i) = x;
2328e4b17023SJohn Marino if (x && !TYPE_P (x) && TREE_SIDE_EFFECTS (x))
2329e4b17023SJohn Marino TREE_SIDE_EFFECTS (t) = 1;
2330e4b17023SJohn Marino }
2331e4b17023SJohn Marino
2332e4b17023SJohn Marino va_end (p);
2333e4b17023SJohn Marino return t;
2334e4b17023SJohn Marino }
2335e4b17023SJohn Marino
2336e4b17023SJohn Marino /* Similar to `build', but for template definitions of non-dependent
2337e4b17023SJohn Marino expressions. NON_DEP is the non-dependent expression that has been
2338e4b17023SJohn Marino built. */
2339e4b17023SJohn Marino
2340e4b17023SJohn Marino tree
build_min_non_dep(enum tree_code code,tree non_dep,...)2341e4b17023SJohn Marino build_min_non_dep (enum tree_code code, tree non_dep, ...)
2342e4b17023SJohn Marino {
2343e4b17023SJohn Marino tree t;
2344e4b17023SJohn Marino int length;
2345e4b17023SJohn Marino int i;
2346e4b17023SJohn Marino va_list p;
2347e4b17023SJohn Marino
2348e4b17023SJohn Marino gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
2349e4b17023SJohn Marino
2350e4b17023SJohn Marino va_start (p, non_dep);
2351e4b17023SJohn Marino
2352e4b17023SJohn Marino if (REFERENCE_REF_P (non_dep))
2353e4b17023SJohn Marino non_dep = TREE_OPERAND (non_dep, 0);
2354e4b17023SJohn Marino
2355e4b17023SJohn Marino t = make_node (code);
2356e4b17023SJohn Marino length = TREE_CODE_LENGTH (code);
2357e4b17023SJohn Marino TREE_TYPE (t) = TREE_TYPE (non_dep);
2358e4b17023SJohn Marino TREE_SIDE_EFFECTS (t) = TREE_SIDE_EFFECTS (non_dep);
2359e4b17023SJohn Marino
2360e4b17023SJohn Marino for (i = 0; i < length; i++)
2361e4b17023SJohn Marino {
2362e4b17023SJohn Marino tree x = va_arg (p, tree);
2363e4b17023SJohn Marino TREE_OPERAND (t, i) = x;
2364e4b17023SJohn Marino }
2365e4b17023SJohn Marino
2366e4b17023SJohn Marino if (code == COMPOUND_EXPR && TREE_CODE (non_dep) != COMPOUND_EXPR)
2367e4b17023SJohn Marino /* This should not be considered a COMPOUND_EXPR, because it
2368e4b17023SJohn Marino resolves to an overload. */
2369e4b17023SJohn Marino COMPOUND_EXPR_OVERLOADED (t) = 1;
2370e4b17023SJohn Marino
2371e4b17023SJohn Marino va_end (p);
2372e4b17023SJohn Marino return convert_from_reference (t);
2373e4b17023SJohn Marino }
2374e4b17023SJohn Marino
2375e4b17023SJohn Marino /* Similar to `build_nt_call_vec', but for template definitions of
2376e4b17023SJohn Marino non-dependent expressions. NON_DEP is the non-dependent expression
2377e4b17023SJohn Marino that has been built. */
2378e4b17023SJohn Marino
2379e4b17023SJohn Marino tree
build_min_non_dep_call_vec(tree non_dep,tree fn,VEC (tree,gc)* argvec)2380e4b17023SJohn Marino build_min_non_dep_call_vec (tree non_dep, tree fn, VEC(tree,gc) *argvec)
2381e4b17023SJohn Marino {
2382e4b17023SJohn Marino tree t = build_nt_call_vec (fn, argvec);
2383e4b17023SJohn Marino if (REFERENCE_REF_P (non_dep))
2384e4b17023SJohn Marino non_dep = TREE_OPERAND (non_dep, 0);
2385e4b17023SJohn Marino TREE_TYPE (t) = TREE_TYPE (non_dep);
2386e4b17023SJohn Marino TREE_SIDE_EFFECTS (t) = TREE_SIDE_EFFECTS (non_dep);
2387e4b17023SJohn Marino return convert_from_reference (t);
2388e4b17023SJohn Marino }
2389e4b17023SJohn Marino
2390e4b17023SJohn Marino tree
get_type_decl(tree t)2391e4b17023SJohn Marino get_type_decl (tree t)
2392e4b17023SJohn Marino {
2393e4b17023SJohn Marino if (TREE_CODE (t) == TYPE_DECL)
2394e4b17023SJohn Marino return t;
2395e4b17023SJohn Marino if (TYPE_P (t))
2396e4b17023SJohn Marino return TYPE_STUB_DECL (t);
2397e4b17023SJohn Marino gcc_assert (t == error_mark_node);
2398e4b17023SJohn Marino return t;
2399e4b17023SJohn Marino }
2400e4b17023SJohn Marino
2401e4b17023SJohn Marino /* Returns the namespace that contains DECL, whether directly or
2402e4b17023SJohn Marino indirectly. */
2403e4b17023SJohn Marino
2404e4b17023SJohn Marino tree
decl_namespace_context(tree decl)2405e4b17023SJohn Marino decl_namespace_context (tree decl)
2406e4b17023SJohn Marino {
2407e4b17023SJohn Marino while (1)
2408e4b17023SJohn Marino {
2409e4b17023SJohn Marino if (TREE_CODE (decl) == NAMESPACE_DECL)
2410e4b17023SJohn Marino return decl;
2411e4b17023SJohn Marino else if (TYPE_P (decl))
2412e4b17023SJohn Marino decl = CP_DECL_CONTEXT (TYPE_MAIN_DECL (decl));
2413e4b17023SJohn Marino else
2414e4b17023SJohn Marino decl = CP_DECL_CONTEXT (decl);
2415e4b17023SJohn Marino }
2416e4b17023SJohn Marino }
2417e4b17023SJohn Marino
2418e4b17023SJohn Marino /* Returns true if decl is within an anonymous namespace, however deeply
2419e4b17023SJohn Marino nested, or false otherwise. */
2420e4b17023SJohn Marino
2421e4b17023SJohn Marino bool
decl_anon_ns_mem_p(const_tree decl)2422e4b17023SJohn Marino decl_anon_ns_mem_p (const_tree decl)
2423e4b17023SJohn Marino {
2424e4b17023SJohn Marino while (1)
2425e4b17023SJohn Marino {
2426e4b17023SJohn Marino if (decl == NULL_TREE || decl == error_mark_node)
2427e4b17023SJohn Marino return false;
2428e4b17023SJohn Marino if (TREE_CODE (decl) == NAMESPACE_DECL
2429e4b17023SJohn Marino && DECL_NAME (decl) == NULL_TREE)
2430e4b17023SJohn Marino return true;
2431e4b17023SJohn Marino /* Classes and namespaces inside anonymous namespaces have
2432e4b17023SJohn Marino TREE_PUBLIC == 0, so we can shortcut the search. */
2433e4b17023SJohn Marino else if (TYPE_P (decl))
24345ce9237cSJohn Marino return (TREE_PUBLIC (TYPE_MAIN_DECL (decl)) == 0);
2435e4b17023SJohn Marino else if (TREE_CODE (decl) == NAMESPACE_DECL)
2436e4b17023SJohn Marino return (TREE_PUBLIC (decl) == 0);
2437e4b17023SJohn Marino else
2438e4b17023SJohn Marino decl = DECL_CONTEXT (decl);
2439e4b17023SJohn Marino }
2440e4b17023SJohn Marino }
2441e4b17023SJohn Marino
2442e4b17023SJohn Marino /* Subroutine of cp_tree_equal: t1 and t2 are the CALL_EXPR_FNs of two
2443e4b17023SJohn Marino CALL_EXPRS. Return whether they are equivalent. */
2444e4b17023SJohn Marino
2445e4b17023SJohn Marino static bool
called_fns_equal(tree t1,tree t2)2446e4b17023SJohn Marino called_fns_equal (tree t1, tree t2)
2447e4b17023SJohn Marino {
2448e4b17023SJohn Marino /* Core 1321: dependent names are equivalent even if the overload sets
2449e4b17023SJohn Marino are different. But do compare explicit template arguments. */
2450e4b17023SJohn Marino tree name1 = dependent_name (t1);
2451e4b17023SJohn Marino tree name2 = dependent_name (t2);
2452e4b17023SJohn Marino if (name1 || name2)
2453e4b17023SJohn Marino {
2454e4b17023SJohn Marino tree targs1 = NULL_TREE, targs2 = NULL_TREE;
2455e4b17023SJohn Marino
2456e4b17023SJohn Marino if (name1 != name2)
2457e4b17023SJohn Marino return false;
2458e4b17023SJohn Marino
2459e4b17023SJohn Marino if (TREE_CODE (t1) == TEMPLATE_ID_EXPR)
2460e4b17023SJohn Marino targs1 = TREE_OPERAND (t1, 1);
2461e4b17023SJohn Marino if (TREE_CODE (t2) == TEMPLATE_ID_EXPR)
2462e4b17023SJohn Marino targs2 = TREE_OPERAND (t2, 1);
2463e4b17023SJohn Marino return cp_tree_equal (targs1, targs2);
2464e4b17023SJohn Marino }
2465e4b17023SJohn Marino else
2466e4b17023SJohn Marino return cp_tree_equal (t1, t2);
2467e4b17023SJohn Marino }
2468e4b17023SJohn Marino
2469e4b17023SJohn Marino /* Return truthvalue of whether T1 is the same tree structure as T2.
2470e4b17023SJohn Marino Return 1 if they are the same. Return 0 if they are different. */
2471e4b17023SJohn Marino
2472e4b17023SJohn Marino bool
cp_tree_equal(tree t1,tree t2)2473e4b17023SJohn Marino cp_tree_equal (tree t1, tree t2)
2474e4b17023SJohn Marino {
2475e4b17023SJohn Marino enum tree_code code1, code2;
2476e4b17023SJohn Marino
2477e4b17023SJohn Marino if (t1 == t2)
2478e4b17023SJohn Marino return true;
2479e4b17023SJohn Marino if (!t1 || !t2)
2480e4b17023SJohn Marino return false;
2481e4b17023SJohn Marino
2482e4b17023SJohn Marino for (code1 = TREE_CODE (t1);
2483e4b17023SJohn Marino CONVERT_EXPR_CODE_P (code1)
2484e4b17023SJohn Marino || code1 == NON_LVALUE_EXPR;
2485e4b17023SJohn Marino code1 = TREE_CODE (t1))
2486e4b17023SJohn Marino t1 = TREE_OPERAND (t1, 0);
2487e4b17023SJohn Marino for (code2 = TREE_CODE (t2);
2488e4b17023SJohn Marino CONVERT_EXPR_CODE_P (code2)
2489e4b17023SJohn Marino || code1 == NON_LVALUE_EXPR;
2490e4b17023SJohn Marino code2 = TREE_CODE (t2))
2491e4b17023SJohn Marino t2 = TREE_OPERAND (t2, 0);
2492e4b17023SJohn Marino
2493e4b17023SJohn Marino /* They might have become equal now. */
2494e4b17023SJohn Marino if (t1 == t2)
2495e4b17023SJohn Marino return true;
2496e4b17023SJohn Marino
2497e4b17023SJohn Marino if (code1 != code2)
2498e4b17023SJohn Marino return false;
2499e4b17023SJohn Marino
2500e4b17023SJohn Marino switch (code1)
2501e4b17023SJohn Marino {
2502e4b17023SJohn Marino case INTEGER_CST:
2503e4b17023SJohn Marino return TREE_INT_CST_LOW (t1) == TREE_INT_CST_LOW (t2)
2504e4b17023SJohn Marino && TREE_INT_CST_HIGH (t1) == TREE_INT_CST_HIGH (t2);
2505e4b17023SJohn Marino
2506e4b17023SJohn Marino case REAL_CST:
2507e4b17023SJohn Marino return REAL_VALUES_EQUAL (TREE_REAL_CST (t1), TREE_REAL_CST (t2));
2508e4b17023SJohn Marino
2509e4b17023SJohn Marino case STRING_CST:
2510e4b17023SJohn Marino return TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
2511e4b17023SJohn Marino && !memcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
2512e4b17023SJohn Marino TREE_STRING_LENGTH (t1));
2513e4b17023SJohn Marino
2514e4b17023SJohn Marino case FIXED_CST:
2515e4b17023SJohn Marino return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1),
2516e4b17023SJohn Marino TREE_FIXED_CST (t2));
2517e4b17023SJohn Marino
2518e4b17023SJohn Marino case COMPLEX_CST:
2519e4b17023SJohn Marino return cp_tree_equal (TREE_REALPART (t1), TREE_REALPART (t2))
2520e4b17023SJohn Marino && cp_tree_equal (TREE_IMAGPART (t1), TREE_IMAGPART (t2));
2521e4b17023SJohn Marino
2522e4b17023SJohn Marino case CONSTRUCTOR:
2523e4b17023SJohn Marino /* We need to do this when determining whether or not two
2524e4b17023SJohn Marino non-type pointer to member function template arguments
2525e4b17023SJohn Marino are the same. */
2526e4b17023SJohn Marino if (!same_type_p (TREE_TYPE (t1), TREE_TYPE (t2))
2527e4b17023SJohn Marino || CONSTRUCTOR_NELTS (t1) != CONSTRUCTOR_NELTS (t2))
2528e4b17023SJohn Marino return false;
2529e4b17023SJohn Marino {
2530e4b17023SJohn Marino tree field, value;
2531e4b17023SJohn Marino unsigned int i;
2532e4b17023SJohn Marino FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (t1), i, field, value)
2533e4b17023SJohn Marino {
2534e4b17023SJohn Marino constructor_elt *elt2 = CONSTRUCTOR_ELT (t2, i);
2535e4b17023SJohn Marino if (!cp_tree_equal (field, elt2->index)
2536e4b17023SJohn Marino || !cp_tree_equal (value, elt2->value))
2537e4b17023SJohn Marino return false;
2538e4b17023SJohn Marino }
2539e4b17023SJohn Marino }
2540e4b17023SJohn Marino return true;
2541e4b17023SJohn Marino
2542e4b17023SJohn Marino case TREE_LIST:
2543e4b17023SJohn Marino if (!cp_tree_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2)))
2544e4b17023SJohn Marino return false;
2545e4b17023SJohn Marino if (!cp_tree_equal (TREE_VALUE (t1), TREE_VALUE (t2)))
2546e4b17023SJohn Marino return false;
2547e4b17023SJohn Marino return cp_tree_equal (TREE_CHAIN (t1), TREE_CHAIN (t2));
2548e4b17023SJohn Marino
2549e4b17023SJohn Marino case SAVE_EXPR:
2550e4b17023SJohn Marino return cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
2551e4b17023SJohn Marino
2552e4b17023SJohn Marino case CALL_EXPR:
2553e4b17023SJohn Marino {
2554e4b17023SJohn Marino tree arg1, arg2;
2555e4b17023SJohn Marino call_expr_arg_iterator iter1, iter2;
2556e4b17023SJohn Marino if (!called_fns_equal (CALL_EXPR_FN (t1), CALL_EXPR_FN (t2)))
2557e4b17023SJohn Marino return false;
2558e4b17023SJohn Marino for (arg1 = first_call_expr_arg (t1, &iter1),
2559e4b17023SJohn Marino arg2 = first_call_expr_arg (t2, &iter2);
2560e4b17023SJohn Marino arg1 && arg2;
2561e4b17023SJohn Marino arg1 = next_call_expr_arg (&iter1),
2562e4b17023SJohn Marino arg2 = next_call_expr_arg (&iter2))
2563e4b17023SJohn Marino if (!cp_tree_equal (arg1, arg2))
2564e4b17023SJohn Marino return false;
2565e4b17023SJohn Marino if (arg1 || arg2)
2566e4b17023SJohn Marino return false;
2567e4b17023SJohn Marino return true;
2568e4b17023SJohn Marino }
2569e4b17023SJohn Marino
2570e4b17023SJohn Marino case TARGET_EXPR:
2571e4b17023SJohn Marino {
2572e4b17023SJohn Marino tree o1 = TREE_OPERAND (t1, 0);
2573e4b17023SJohn Marino tree o2 = TREE_OPERAND (t2, 0);
2574e4b17023SJohn Marino
2575e4b17023SJohn Marino /* Special case: if either target is an unallocated VAR_DECL,
2576e4b17023SJohn Marino it means that it's going to be unified with whatever the
2577e4b17023SJohn Marino TARGET_EXPR is really supposed to initialize, so treat it
2578e4b17023SJohn Marino as being equivalent to anything. */
2579e4b17023SJohn Marino if (TREE_CODE (o1) == VAR_DECL && DECL_NAME (o1) == NULL_TREE
2580e4b17023SJohn Marino && !DECL_RTL_SET_P (o1))
2581e4b17023SJohn Marino /*Nop*/;
2582e4b17023SJohn Marino else if (TREE_CODE (o2) == VAR_DECL && DECL_NAME (o2) == NULL_TREE
2583e4b17023SJohn Marino && !DECL_RTL_SET_P (o2))
2584e4b17023SJohn Marino /*Nop*/;
2585e4b17023SJohn Marino else if (!cp_tree_equal (o1, o2))
2586e4b17023SJohn Marino return false;
2587e4b17023SJohn Marino
2588e4b17023SJohn Marino return cp_tree_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
2589e4b17023SJohn Marino }
2590e4b17023SJohn Marino
2591e4b17023SJohn Marino case WITH_CLEANUP_EXPR:
2592e4b17023SJohn Marino if (!cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0)))
2593e4b17023SJohn Marino return false;
2594e4b17023SJohn Marino return cp_tree_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t1, 1));
2595e4b17023SJohn Marino
2596e4b17023SJohn Marino case COMPONENT_REF:
2597e4b17023SJohn Marino if (TREE_OPERAND (t1, 1) != TREE_OPERAND (t2, 1))
2598e4b17023SJohn Marino return false;
2599e4b17023SJohn Marino return cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
2600e4b17023SJohn Marino
2601e4b17023SJohn Marino case PARM_DECL:
2602e4b17023SJohn Marino /* For comparing uses of parameters in late-specified return types
2603e4b17023SJohn Marino with an out-of-class definition of the function, but can also come
2604e4b17023SJohn Marino up for expressions that involve 'this' in a member function
2605e4b17023SJohn Marino template. */
26065ce9237cSJohn Marino
26075ce9237cSJohn Marino if (comparing_specializations)
26085ce9237cSJohn Marino /* When comparing hash table entries, only an exact match is
26095ce9237cSJohn Marino good enough; we don't want to replace 'this' with the
26105ce9237cSJohn Marino version from another function. */
26115ce9237cSJohn Marino return false;
26125ce9237cSJohn Marino
2613e4b17023SJohn Marino if (same_type_p (TREE_TYPE (t1), TREE_TYPE (t2)))
2614e4b17023SJohn Marino {
2615e4b17023SJohn Marino if (DECL_ARTIFICIAL (t1) ^ DECL_ARTIFICIAL (t2))
2616e4b17023SJohn Marino return false;
2617e4b17023SJohn Marino if (DECL_ARTIFICIAL (t1)
2618e4b17023SJohn Marino || (DECL_PARM_LEVEL (t1) == DECL_PARM_LEVEL (t2)
2619e4b17023SJohn Marino && DECL_PARM_INDEX (t1) == DECL_PARM_INDEX (t2)))
2620e4b17023SJohn Marino return true;
2621e4b17023SJohn Marino }
2622e4b17023SJohn Marino return false;
2623e4b17023SJohn Marino
2624e4b17023SJohn Marino case VAR_DECL:
2625e4b17023SJohn Marino case CONST_DECL:
26265ce9237cSJohn Marino case FIELD_DECL:
2627e4b17023SJohn Marino case FUNCTION_DECL:
2628e4b17023SJohn Marino case TEMPLATE_DECL:
2629e4b17023SJohn Marino case IDENTIFIER_NODE:
2630e4b17023SJohn Marino case SSA_NAME:
2631e4b17023SJohn Marino return false;
2632e4b17023SJohn Marino
2633e4b17023SJohn Marino case BASELINK:
2634e4b17023SJohn Marino return (BASELINK_BINFO (t1) == BASELINK_BINFO (t2)
2635e4b17023SJohn Marino && BASELINK_ACCESS_BINFO (t1) == BASELINK_ACCESS_BINFO (t2)
2636e4b17023SJohn Marino && BASELINK_QUALIFIED_P (t1) == BASELINK_QUALIFIED_P (t2)
2637e4b17023SJohn Marino && cp_tree_equal (BASELINK_FUNCTIONS (t1),
2638e4b17023SJohn Marino BASELINK_FUNCTIONS (t2)));
2639e4b17023SJohn Marino
2640e4b17023SJohn Marino case TEMPLATE_PARM_INDEX:
2641e4b17023SJohn Marino return (TEMPLATE_PARM_IDX (t1) == TEMPLATE_PARM_IDX (t2)
2642e4b17023SJohn Marino && TEMPLATE_PARM_LEVEL (t1) == TEMPLATE_PARM_LEVEL (t2)
2643e4b17023SJohn Marino && (TEMPLATE_PARM_PARAMETER_PACK (t1)
2644e4b17023SJohn Marino == TEMPLATE_PARM_PARAMETER_PACK (t2))
2645e4b17023SJohn Marino && same_type_p (TREE_TYPE (TEMPLATE_PARM_DECL (t1)),
2646e4b17023SJohn Marino TREE_TYPE (TEMPLATE_PARM_DECL (t2))));
2647e4b17023SJohn Marino
2648e4b17023SJohn Marino case TEMPLATE_ID_EXPR:
2649e4b17023SJohn Marino return (cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0))
2650e4b17023SJohn Marino && cp_tree_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1)));
2651e4b17023SJohn Marino
2652e4b17023SJohn Marino case TREE_VEC:
2653e4b17023SJohn Marino {
2654e4b17023SJohn Marino unsigned ix;
2655e4b17023SJohn Marino if (TREE_VEC_LENGTH (t1) != TREE_VEC_LENGTH (t2))
2656e4b17023SJohn Marino return false;
2657e4b17023SJohn Marino for (ix = TREE_VEC_LENGTH (t1); ix--;)
2658e4b17023SJohn Marino if (!cp_tree_equal (TREE_VEC_ELT (t1, ix),
2659e4b17023SJohn Marino TREE_VEC_ELT (t2, ix)))
2660e4b17023SJohn Marino return false;
2661e4b17023SJohn Marino return true;
2662e4b17023SJohn Marino }
2663e4b17023SJohn Marino
2664e4b17023SJohn Marino case SIZEOF_EXPR:
2665e4b17023SJohn Marino case ALIGNOF_EXPR:
2666e4b17023SJohn Marino {
2667e4b17023SJohn Marino tree o1 = TREE_OPERAND (t1, 0);
2668e4b17023SJohn Marino tree o2 = TREE_OPERAND (t2, 0);
2669e4b17023SJohn Marino
2670e4b17023SJohn Marino if (TREE_CODE (o1) != TREE_CODE (o2))
2671e4b17023SJohn Marino return false;
2672e4b17023SJohn Marino if (TYPE_P (o1))
2673e4b17023SJohn Marino return same_type_p (o1, o2);
2674e4b17023SJohn Marino else
2675e4b17023SJohn Marino return cp_tree_equal (o1, o2);
2676e4b17023SJohn Marino }
2677e4b17023SJohn Marino
2678e4b17023SJohn Marino case MODOP_EXPR:
2679e4b17023SJohn Marino {
2680e4b17023SJohn Marino tree t1_op1, t2_op1;
2681e4b17023SJohn Marino
2682e4b17023SJohn Marino if (!cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0)))
2683e4b17023SJohn Marino return false;
2684e4b17023SJohn Marino
2685e4b17023SJohn Marino t1_op1 = TREE_OPERAND (t1, 1);
2686e4b17023SJohn Marino t2_op1 = TREE_OPERAND (t2, 1);
2687e4b17023SJohn Marino if (TREE_CODE (t1_op1) != TREE_CODE (t2_op1))
2688e4b17023SJohn Marino return false;
2689e4b17023SJohn Marino
2690e4b17023SJohn Marino return cp_tree_equal (TREE_OPERAND (t1, 2), TREE_OPERAND (t2, 2));
2691e4b17023SJohn Marino }
2692e4b17023SJohn Marino
2693e4b17023SJohn Marino case PTRMEM_CST:
2694e4b17023SJohn Marino /* Two pointer-to-members are the same if they point to the same
2695e4b17023SJohn Marino field or function in the same class. */
2696e4b17023SJohn Marino if (PTRMEM_CST_MEMBER (t1) != PTRMEM_CST_MEMBER (t2))
2697e4b17023SJohn Marino return false;
2698e4b17023SJohn Marino
2699e4b17023SJohn Marino return same_type_p (PTRMEM_CST_CLASS (t1), PTRMEM_CST_CLASS (t2));
2700e4b17023SJohn Marino
2701e4b17023SJohn Marino case OVERLOAD:
2702e4b17023SJohn Marino if (OVL_FUNCTION (t1) != OVL_FUNCTION (t2))
2703e4b17023SJohn Marino return false;
2704e4b17023SJohn Marino return cp_tree_equal (OVL_CHAIN (t1), OVL_CHAIN (t2));
2705e4b17023SJohn Marino
2706e4b17023SJohn Marino case TRAIT_EXPR:
2707e4b17023SJohn Marino if (TRAIT_EXPR_KIND (t1) != TRAIT_EXPR_KIND (t2))
2708e4b17023SJohn Marino return false;
2709e4b17023SJohn Marino return same_type_p (TRAIT_EXPR_TYPE1 (t1), TRAIT_EXPR_TYPE1 (t2))
2710e4b17023SJohn Marino && same_type_p (TRAIT_EXPR_TYPE2 (t1), TRAIT_EXPR_TYPE2 (t2));
2711e4b17023SJohn Marino
2712e4b17023SJohn Marino case CAST_EXPR:
2713e4b17023SJohn Marino case STATIC_CAST_EXPR:
2714e4b17023SJohn Marino case REINTERPRET_CAST_EXPR:
2715e4b17023SJohn Marino case CONST_CAST_EXPR:
2716e4b17023SJohn Marino case DYNAMIC_CAST_EXPR:
2717e4b17023SJohn Marino case IMPLICIT_CONV_EXPR:
2718e4b17023SJohn Marino case NEW_EXPR:
2719e4b17023SJohn Marino if (!same_type_p (TREE_TYPE (t1), TREE_TYPE (t2)))
2720e4b17023SJohn Marino return false;
2721e4b17023SJohn Marino /* Now compare operands as usual. */
2722e4b17023SJohn Marino break;
2723e4b17023SJohn Marino
2724e4b17023SJohn Marino case DEFERRED_NOEXCEPT:
2725e4b17023SJohn Marino return (cp_tree_equal (DEFERRED_NOEXCEPT_PATTERN (t1),
2726e4b17023SJohn Marino DEFERRED_NOEXCEPT_PATTERN (t2))
2727e4b17023SJohn Marino && comp_template_args (DEFERRED_NOEXCEPT_ARGS (t1),
2728e4b17023SJohn Marino DEFERRED_NOEXCEPT_ARGS (t2)));
2729e4b17023SJohn Marino break;
2730e4b17023SJohn Marino
2731e4b17023SJohn Marino default:
2732e4b17023SJohn Marino break;
2733e4b17023SJohn Marino }
2734e4b17023SJohn Marino
2735e4b17023SJohn Marino switch (TREE_CODE_CLASS (code1))
2736e4b17023SJohn Marino {
2737e4b17023SJohn Marino case tcc_unary:
2738e4b17023SJohn Marino case tcc_binary:
2739e4b17023SJohn Marino case tcc_comparison:
2740e4b17023SJohn Marino case tcc_expression:
2741e4b17023SJohn Marino case tcc_vl_exp:
2742e4b17023SJohn Marino case tcc_reference:
2743e4b17023SJohn Marino case tcc_statement:
2744e4b17023SJohn Marino {
2745e4b17023SJohn Marino int i, n;
2746e4b17023SJohn Marino
2747e4b17023SJohn Marino n = cp_tree_operand_length (t1);
2748e4b17023SJohn Marino if (TREE_CODE_CLASS (code1) == tcc_vl_exp
2749e4b17023SJohn Marino && n != TREE_OPERAND_LENGTH (t2))
2750e4b17023SJohn Marino return false;
2751e4b17023SJohn Marino
2752e4b17023SJohn Marino for (i = 0; i < n; ++i)
2753e4b17023SJohn Marino if (!cp_tree_equal (TREE_OPERAND (t1, i), TREE_OPERAND (t2, i)))
2754e4b17023SJohn Marino return false;
2755e4b17023SJohn Marino
2756e4b17023SJohn Marino return true;
2757e4b17023SJohn Marino }
2758e4b17023SJohn Marino
2759e4b17023SJohn Marino case tcc_type:
2760e4b17023SJohn Marino return same_type_p (t1, t2);
2761e4b17023SJohn Marino default:
2762e4b17023SJohn Marino gcc_unreachable ();
2763e4b17023SJohn Marino }
2764e4b17023SJohn Marino /* We can get here with --disable-checking. */
2765e4b17023SJohn Marino return false;
2766e4b17023SJohn Marino }
2767e4b17023SJohn Marino
2768e4b17023SJohn Marino /* The type of ARG when used as an lvalue. */
2769e4b17023SJohn Marino
2770e4b17023SJohn Marino tree
lvalue_type(tree arg)2771e4b17023SJohn Marino lvalue_type (tree arg)
2772e4b17023SJohn Marino {
2773e4b17023SJohn Marino tree type = TREE_TYPE (arg);
2774e4b17023SJohn Marino return type;
2775e4b17023SJohn Marino }
2776e4b17023SJohn Marino
2777e4b17023SJohn Marino /* The type of ARG for printing error messages; denote lvalues with
2778e4b17023SJohn Marino reference types. */
2779e4b17023SJohn Marino
2780e4b17023SJohn Marino tree
error_type(tree arg)2781e4b17023SJohn Marino error_type (tree arg)
2782e4b17023SJohn Marino {
2783e4b17023SJohn Marino tree type = TREE_TYPE (arg);
2784e4b17023SJohn Marino
2785e4b17023SJohn Marino if (TREE_CODE (type) == ARRAY_TYPE)
2786e4b17023SJohn Marino ;
2787e4b17023SJohn Marino else if (TREE_CODE (type) == ERROR_MARK)
2788e4b17023SJohn Marino ;
2789e4b17023SJohn Marino else if (real_lvalue_p (arg))
2790e4b17023SJohn Marino type = build_reference_type (lvalue_type (arg));
2791e4b17023SJohn Marino else if (MAYBE_CLASS_TYPE_P (type))
2792e4b17023SJohn Marino type = lvalue_type (arg);
2793e4b17023SJohn Marino
2794e4b17023SJohn Marino return type;
2795e4b17023SJohn Marino }
2796e4b17023SJohn Marino
2797e4b17023SJohn Marino /* Does FUNCTION use a variable-length argument list? */
2798e4b17023SJohn Marino
2799e4b17023SJohn Marino int
varargs_function_p(const_tree function)2800e4b17023SJohn Marino varargs_function_p (const_tree function)
2801e4b17023SJohn Marino {
2802e4b17023SJohn Marino return stdarg_p (TREE_TYPE (function));
2803e4b17023SJohn Marino }
2804e4b17023SJohn Marino
2805e4b17023SJohn Marino /* Returns 1 if decl is a member of a class. */
2806e4b17023SJohn Marino
2807e4b17023SJohn Marino int
member_p(const_tree decl)2808e4b17023SJohn Marino member_p (const_tree decl)
2809e4b17023SJohn Marino {
2810e4b17023SJohn Marino const_tree const ctx = DECL_CONTEXT (decl);
2811e4b17023SJohn Marino return (ctx && TYPE_P (ctx));
2812e4b17023SJohn Marino }
2813e4b17023SJohn Marino
2814e4b17023SJohn Marino /* Create a placeholder for member access where we don't actually have an
2815e4b17023SJohn Marino object that the access is against. */
2816e4b17023SJohn Marino
2817e4b17023SJohn Marino tree
build_dummy_object(tree type)2818e4b17023SJohn Marino build_dummy_object (tree type)
2819e4b17023SJohn Marino {
2820e4b17023SJohn Marino tree decl = build1 (NOP_EXPR, build_pointer_type (type), void_zero_node);
2821e4b17023SJohn Marino return cp_build_indirect_ref (decl, RO_NULL, tf_warning_or_error);
2822e4b17023SJohn Marino }
2823e4b17023SJohn Marino
2824e4b17023SJohn Marino /* We've gotten a reference to a member of TYPE. Return *this if appropriate,
2825e4b17023SJohn Marino or a dummy object otherwise. If BINFOP is non-0, it is filled with the
2826e4b17023SJohn Marino binfo path from current_class_type to TYPE, or 0. */
2827e4b17023SJohn Marino
2828e4b17023SJohn Marino tree
maybe_dummy_object(tree type,tree * binfop)2829e4b17023SJohn Marino maybe_dummy_object (tree type, tree* binfop)
2830e4b17023SJohn Marino {
2831e4b17023SJohn Marino tree decl, context;
2832e4b17023SJohn Marino tree binfo;
2833e4b17023SJohn Marino tree current = current_nonlambda_class_type ();
2834e4b17023SJohn Marino
2835e4b17023SJohn Marino if (current
2836e4b17023SJohn Marino && (binfo = lookup_base (current, type, ba_any, NULL)))
2837e4b17023SJohn Marino context = current;
2838e4b17023SJohn Marino else
2839e4b17023SJohn Marino {
2840e4b17023SJohn Marino /* Reference from a nested class member function. */
2841e4b17023SJohn Marino context = type;
2842e4b17023SJohn Marino binfo = TYPE_BINFO (type);
2843e4b17023SJohn Marino }
2844e4b17023SJohn Marino
2845e4b17023SJohn Marino if (binfop)
2846e4b17023SJohn Marino *binfop = binfo;
2847e4b17023SJohn Marino
2848e4b17023SJohn Marino if (current_class_ref
2849e4b17023SJohn Marino /* current_class_ref might not correspond to current_class_type if
2850e4b17023SJohn Marino we're in tsubst_default_argument or a lambda-declarator; in either
2851e4b17023SJohn Marino case, we want to use current_class_ref if it matches CONTEXT. */
2852e4b17023SJohn Marino && (same_type_ignoring_top_level_qualifiers_p
2853e4b17023SJohn Marino (TREE_TYPE (current_class_ref), context)))
2854e4b17023SJohn Marino decl = current_class_ref;
2855e4b17023SJohn Marino else if (current != current_class_type
2856e4b17023SJohn Marino && context == nonlambda_method_basetype ())
2857e4b17023SJohn Marino /* In a lambda, need to go through 'this' capture. */
2858e4b17023SJohn Marino decl = (build_x_indirect_ref
2859e4b17023SJohn Marino ((lambda_expr_this_capture
2860e4b17023SJohn Marino (CLASSTYPE_LAMBDA_EXPR (current_class_type))),
2861e4b17023SJohn Marino RO_NULL, tf_warning_or_error));
2862e4b17023SJohn Marino else
2863e4b17023SJohn Marino decl = build_dummy_object (context);
2864e4b17023SJohn Marino
2865e4b17023SJohn Marino return decl;
2866e4b17023SJohn Marino }
2867e4b17023SJohn Marino
2868e4b17023SJohn Marino /* Returns 1 if OB is a placeholder object, or a pointer to one. */
2869e4b17023SJohn Marino
2870e4b17023SJohn Marino int
is_dummy_object(const_tree ob)2871e4b17023SJohn Marino is_dummy_object (const_tree ob)
2872e4b17023SJohn Marino {
2873e4b17023SJohn Marino if (TREE_CODE (ob) == INDIRECT_REF)
2874e4b17023SJohn Marino ob = TREE_OPERAND (ob, 0);
2875e4b17023SJohn Marino return (TREE_CODE (ob) == NOP_EXPR
2876e4b17023SJohn Marino && TREE_OPERAND (ob, 0) == void_zero_node);
2877e4b17023SJohn Marino }
2878e4b17023SJohn Marino
2879e4b17023SJohn Marino /* Returns 1 iff type T is something we want to treat as a scalar type for
2880e4b17023SJohn Marino the purpose of deciding whether it is trivial/POD/standard-layout. */
2881e4b17023SJohn Marino
2882e4b17023SJohn Marino static bool
scalarish_type_p(const_tree t)2883e4b17023SJohn Marino scalarish_type_p (const_tree t)
2884e4b17023SJohn Marino {
2885e4b17023SJohn Marino if (t == error_mark_node)
2886e4b17023SJohn Marino return 1;
2887e4b17023SJohn Marino
2888e4b17023SJohn Marino return (SCALAR_TYPE_P (t)
2889e4b17023SJohn Marino || TREE_CODE (t) == VECTOR_TYPE);
2890e4b17023SJohn Marino }
2891e4b17023SJohn Marino
2892e4b17023SJohn Marino /* Returns true iff T requires non-trivial default initialization. */
2893e4b17023SJohn Marino
2894e4b17023SJohn Marino bool
type_has_nontrivial_default_init(const_tree t)2895e4b17023SJohn Marino type_has_nontrivial_default_init (const_tree t)
2896e4b17023SJohn Marino {
2897e4b17023SJohn Marino t = strip_array_types (CONST_CAST_TREE (t));
2898e4b17023SJohn Marino
2899e4b17023SJohn Marino if (CLASS_TYPE_P (t))
2900e4b17023SJohn Marino return TYPE_HAS_COMPLEX_DFLT (t);
2901e4b17023SJohn Marino else
2902e4b17023SJohn Marino return 0;
2903e4b17023SJohn Marino }
2904e4b17023SJohn Marino
2905e4b17023SJohn Marino /* Returns true iff copying an object of type T (including via move
2906e4b17023SJohn Marino constructor) is non-trivial. That is, T has no non-trivial copy
2907e4b17023SJohn Marino constructors and no non-trivial move constructors. */
2908e4b17023SJohn Marino
2909e4b17023SJohn Marino bool
type_has_nontrivial_copy_init(const_tree t)2910e4b17023SJohn Marino type_has_nontrivial_copy_init (const_tree t)
2911e4b17023SJohn Marino {
2912e4b17023SJohn Marino t = strip_array_types (CONST_CAST_TREE (t));
2913e4b17023SJohn Marino
2914e4b17023SJohn Marino if (CLASS_TYPE_P (t))
2915e4b17023SJohn Marino {
2916e4b17023SJohn Marino gcc_assert (COMPLETE_TYPE_P (t));
2917e4b17023SJohn Marino return ((TYPE_HAS_COPY_CTOR (t)
2918e4b17023SJohn Marino && TYPE_HAS_COMPLEX_COPY_CTOR (t))
2919e4b17023SJohn Marino || TYPE_HAS_COMPLEX_MOVE_CTOR (t));
2920e4b17023SJohn Marino }
2921e4b17023SJohn Marino else
2922e4b17023SJohn Marino return 0;
2923e4b17023SJohn Marino }
2924e4b17023SJohn Marino
2925e4b17023SJohn Marino /* Returns 1 iff type T is a trivially copyable type, as defined in
2926e4b17023SJohn Marino [basic.types] and [class]. */
2927e4b17023SJohn Marino
2928e4b17023SJohn Marino bool
trivially_copyable_p(const_tree t)2929e4b17023SJohn Marino trivially_copyable_p (const_tree t)
2930e4b17023SJohn Marino {
2931e4b17023SJohn Marino t = strip_array_types (CONST_CAST_TREE (t));
2932e4b17023SJohn Marino
2933e4b17023SJohn Marino if (CLASS_TYPE_P (t))
2934e4b17023SJohn Marino return ((!TYPE_HAS_COPY_CTOR (t)
2935e4b17023SJohn Marino || !TYPE_HAS_COMPLEX_COPY_CTOR (t))
2936e4b17023SJohn Marino && !TYPE_HAS_COMPLEX_MOVE_CTOR (t)
2937e4b17023SJohn Marino && (!TYPE_HAS_COPY_ASSIGN (t)
2938e4b17023SJohn Marino || !TYPE_HAS_COMPLEX_COPY_ASSIGN (t))
2939e4b17023SJohn Marino && !TYPE_HAS_COMPLEX_MOVE_ASSIGN (t)
2940e4b17023SJohn Marino && TYPE_HAS_TRIVIAL_DESTRUCTOR (t));
2941e4b17023SJohn Marino else
2942e4b17023SJohn Marino return scalarish_type_p (t);
2943e4b17023SJohn Marino }
2944e4b17023SJohn Marino
2945e4b17023SJohn Marino /* Returns 1 iff type T is a trivial type, as defined in [basic.types] and
2946e4b17023SJohn Marino [class]. */
2947e4b17023SJohn Marino
2948e4b17023SJohn Marino bool
trivial_type_p(const_tree t)2949e4b17023SJohn Marino trivial_type_p (const_tree t)
2950e4b17023SJohn Marino {
2951e4b17023SJohn Marino t = strip_array_types (CONST_CAST_TREE (t));
2952e4b17023SJohn Marino
2953e4b17023SJohn Marino if (CLASS_TYPE_P (t))
2954e4b17023SJohn Marino return (TYPE_HAS_TRIVIAL_DFLT (t)
2955e4b17023SJohn Marino && trivially_copyable_p (t));
2956e4b17023SJohn Marino else
2957e4b17023SJohn Marino return scalarish_type_p (t);
2958e4b17023SJohn Marino }
2959e4b17023SJohn Marino
2960e4b17023SJohn Marino /* Returns 1 iff type T is a POD type, as defined in [basic.types]. */
2961e4b17023SJohn Marino
2962e4b17023SJohn Marino bool
pod_type_p(const_tree t)2963e4b17023SJohn Marino pod_type_p (const_tree t)
2964e4b17023SJohn Marino {
2965e4b17023SJohn Marino /* This CONST_CAST is okay because strip_array_types returns its
2966e4b17023SJohn Marino argument unmodified and we assign it to a const_tree. */
2967e4b17023SJohn Marino t = strip_array_types (CONST_CAST_TREE(t));
2968e4b17023SJohn Marino
2969e4b17023SJohn Marino if (!CLASS_TYPE_P (t))
2970e4b17023SJohn Marino return scalarish_type_p (t);
2971e4b17023SJohn Marino else if (cxx_dialect > cxx98)
2972e4b17023SJohn Marino /* [class]/10: A POD struct is a class that is both a trivial class and a
2973e4b17023SJohn Marino standard-layout class, and has no non-static data members of type
2974e4b17023SJohn Marino non-POD struct, non-POD union (or array of such types).
2975e4b17023SJohn Marino
2976e4b17023SJohn Marino We don't need to check individual members because if a member is
2977e4b17023SJohn Marino non-std-layout or non-trivial, the class will be too. */
2978e4b17023SJohn Marino return (std_layout_type_p (t) && trivial_type_p (t));
2979e4b17023SJohn Marino else
2980e4b17023SJohn Marino /* The C++98 definition of POD is different. */
2981e4b17023SJohn Marino return !CLASSTYPE_NON_LAYOUT_POD_P (t);
2982e4b17023SJohn Marino }
2983e4b17023SJohn Marino
2984e4b17023SJohn Marino /* Returns true iff T is POD for the purpose of layout, as defined in the
2985e4b17023SJohn Marino C++ ABI. */
2986e4b17023SJohn Marino
2987e4b17023SJohn Marino bool
layout_pod_type_p(const_tree t)2988e4b17023SJohn Marino layout_pod_type_p (const_tree t)
2989e4b17023SJohn Marino {
2990e4b17023SJohn Marino t = strip_array_types (CONST_CAST_TREE (t));
2991e4b17023SJohn Marino
2992e4b17023SJohn Marino if (CLASS_TYPE_P (t))
2993e4b17023SJohn Marino return !CLASSTYPE_NON_LAYOUT_POD_P (t);
2994e4b17023SJohn Marino else
2995e4b17023SJohn Marino return scalarish_type_p (t);
2996e4b17023SJohn Marino }
2997e4b17023SJohn Marino
2998e4b17023SJohn Marino /* Returns true iff T is a standard-layout type, as defined in
2999e4b17023SJohn Marino [basic.types]. */
3000e4b17023SJohn Marino
3001e4b17023SJohn Marino bool
std_layout_type_p(const_tree t)3002e4b17023SJohn Marino std_layout_type_p (const_tree t)
3003e4b17023SJohn Marino {
3004e4b17023SJohn Marino t = strip_array_types (CONST_CAST_TREE (t));
3005e4b17023SJohn Marino
3006e4b17023SJohn Marino if (CLASS_TYPE_P (t))
3007e4b17023SJohn Marino return !CLASSTYPE_NON_STD_LAYOUT (t);
3008e4b17023SJohn Marino else
3009e4b17023SJohn Marino return scalarish_type_p (t);
3010e4b17023SJohn Marino }
3011e4b17023SJohn Marino
3012e4b17023SJohn Marino /* Nonzero iff type T is a class template implicit specialization. */
3013e4b17023SJohn Marino
3014e4b17023SJohn Marino bool
class_tmpl_impl_spec_p(const_tree t)3015e4b17023SJohn Marino class_tmpl_impl_spec_p (const_tree t)
3016e4b17023SJohn Marino {
3017e4b17023SJohn Marino return CLASS_TYPE_P (t) && CLASSTYPE_TEMPLATE_INSTANTIATION (t);
3018e4b17023SJohn Marino }
3019e4b17023SJohn Marino
3020e4b17023SJohn Marino /* Returns 1 iff zero initialization of type T means actually storing
3021e4b17023SJohn Marino zeros in it. */
3022e4b17023SJohn Marino
3023e4b17023SJohn Marino int
zero_init_p(const_tree t)3024e4b17023SJohn Marino zero_init_p (const_tree t)
3025e4b17023SJohn Marino {
3026e4b17023SJohn Marino /* This CONST_CAST is okay because strip_array_types returns its
3027e4b17023SJohn Marino argument unmodified and we assign it to a const_tree. */
3028e4b17023SJohn Marino t = strip_array_types (CONST_CAST_TREE(t));
3029e4b17023SJohn Marino
3030e4b17023SJohn Marino if (t == error_mark_node)
3031e4b17023SJohn Marino return 1;
3032e4b17023SJohn Marino
3033e4b17023SJohn Marino /* NULL pointers to data members are initialized with -1. */
3034e4b17023SJohn Marino if (TYPE_PTRMEM_P (t))
3035e4b17023SJohn Marino return 0;
3036e4b17023SJohn Marino
3037e4b17023SJohn Marino /* Classes that contain types that can't be zero-initialized, cannot
3038e4b17023SJohn Marino be zero-initialized themselves. */
3039e4b17023SJohn Marino if (CLASS_TYPE_P (t) && CLASSTYPE_NON_ZERO_INIT_P (t))
3040e4b17023SJohn Marino return 0;
3041e4b17023SJohn Marino
3042e4b17023SJohn Marino return 1;
3043e4b17023SJohn Marino }
3044e4b17023SJohn Marino
3045e4b17023SJohn Marino /* Table of valid C++ attributes. */
3046e4b17023SJohn Marino const struct attribute_spec cxx_attribute_table[] =
3047e4b17023SJohn Marino {
3048e4b17023SJohn Marino /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler,
3049e4b17023SJohn Marino affects_type_identity } */
3050e4b17023SJohn Marino { "java_interface", 0, 0, false, false, false,
3051e4b17023SJohn Marino handle_java_interface_attribute, false },
3052e4b17023SJohn Marino { "com_interface", 0, 0, false, false, false,
3053e4b17023SJohn Marino handle_com_interface_attribute, false },
3054e4b17023SJohn Marino { "init_priority", 1, 1, true, false, false,
3055e4b17023SJohn Marino handle_init_priority_attribute, false },
3056e4b17023SJohn Marino { NULL, 0, 0, false, false, false, NULL, false }
3057e4b17023SJohn Marino };
3058e4b17023SJohn Marino
3059e4b17023SJohn Marino /* Handle a "java_interface" attribute; arguments as in
3060e4b17023SJohn Marino struct attribute_spec.handler. */
3061e4b17023SJohn Marino static tree
handle_java_interface_attribute(tree * node,tree name,tree args ATTRIBUTE_UNUSED,int flags,bool * no_add_attrs)3062e4b17023SJohn Marino handle_java_interface_attribute (tree* node,
3063e4b17023SJohn Marino tree name,
3064e4b17023SJohn Marino tree args ATTRIBUTE_UNUSED ,
3065e4b17023SJohn Marino int flags,
3066e4b17023SJohn Marino bool* no_add_attrs)
3067e4b17023SJohn Marino {
3068e4b17023SJohn Marino if (DECL_P (*node)
3069e4b17023SJohn Marino || !CLASS_TYPE_P (*node)
3070e4b17023SJohn Marino || !TYPE_FOR_JAVA (*node))
3071e4b17023SJohn Marino {
3072e4b17023SJohn Marino error ("%qE attribute can only be applied to Java class definitions",
3073e4b17023SJohn Marino name);
3074e4b17023SJohn Marino *no_add_attrs = true;
3075e4b17023SJohn Marino return NULL_TREE;
3076e4b17023SJohn Marino }
3077e4b17023SJohn Marino if (!(flags & (int) ATTR_FLAG_TYPE_IN_PLACE))
3078e4b17023SJohn Marino *node = build_variant_type_copy (*node);
3079e4b17023SJohn Marino TYPE_JAVA_INTERFACE (*node) = 1;
3080e4b17023SJohn Marino
3081e4b17023SJohn Marino return NULL_TREE;
3082e4b17023SJohn Marino }
3083e4b17023SJohn Marino
3084e4b17023SJohn Marino /* Handle a "com_interface" attribute; arguments as in
3085e4b17023SJohn Marino struct attribute_spec.handler. */
3086e4b17023SJohn Marino static tree
handle_com_interface_attribute(tree * node,tree name,tree args ATTRIBUTE_UNUSED,int flags ATTRIBUTE_UNUSED,bool * no_add_attrs)3087e4b17023SJohn Marino handle_com_interface_attribute (tree* node,
3088e4b17023SJohn Marino tree name,
3089e4b17023SJohn Marino tree args ATTRIBUTE_UNUSED ,
3090e4b17023SJohn Marino int flags ATTRIBUTE_UNUSED ,
3091e4b17023SJohn Marino bool* no_add_attrs)
3092e4b17023SJohn Marino {
3093e4b17023SJohn Marino static int warned;
3094e4b17023SJohn Marino
3095e4b17023SJohn Marino *no_add_attrs = true;
3096e4b17023SJohn Marino
3097e4b17023SJohn Marino if (DECL_P (*node)
3098e4b17023SJohn Marino || !CLASS_TYPE_P (*node)
3099e4b17023SJohn Marino || *node != TYPE_MAIN_VARIANT (*node))
3100e4b17023SJohn Marino {
3101e4b17023SJohn Marino warning (OPT_Wattributes, "%qE attribute can only be applied "
3102e4b17023SJohn Marino "to class definitions", name);
3103e4b17023SJohn Marino return NULL_TREE;
3104e4b17023SJohn Marino }
3105e4b17023SJohn Marino
3106e4b17023SJohn Marino if (!warned++)
3107e4b17023SJohn Marino warning (0, "%qE is obsolete; g++ vtables are now COM-compatible by default",
3108e4b17023SJohn Marino name);
3109e4b17023SJohn Marino
3110e4b17023SJohn Marino return NULL_TREE;
3111e4b17023SJohn Marino }
3112e4b17023SJohn Marino
3113e4b17023SJohn Marino /* Handle an "init_priority" attribute; arguments as in
3114e4b17023SJohn Marino struct attribute_spec.handler. */
3115e4b17023SJohn Marino static tree
handle_init_priority_attribute(tree * node,tree name,tree args,int flags ATTRIBUTE_UNUSED,bool * no_add_attrs)3116e4b17023SJohn Marino handle_init_priority_attribute (tree* node,
3117e4b17023SJohn Marino tree name,
3118e4b17023SJohn Marino tree args,
3119e4b17023SJohn Marino int flags ATTRIBUTE_UNUSED ,
3120e4b17023SJohn Marino bool* no_add_attrs)
3121e4b17023SJohn Marino {
3122e4b17023SJohn Marino tree initp_expr = TREE_VALUE (args);
3123e4b17023SJohn Marino tree decl = *node;
3124e4b17023SJohn Marino tree type = TREE_TYPE (decl);
3125e4b17023SJohn Marino int pri;
3126e4b17023SJohn Marino
3127e4b17023SJohn Marino STRIP_NOPS (initp_expr);
3128e4b17023SJohn Marino
3129e4b17023SJohn Marino if (!initp_expr || TREE_CODE (initp_expr) != INTEGER_CST)
3130e4b17023SJohn Marino {
3131e4b17023SJohn Marino error ("requested init_priority is not an integer constant");
3132e4b17023SJohn Marino *no_add_attrs = true;
3133e4b17023SJohn Marino return NULL_TREE;
3134e4b17023SJohn Marino }
3135e4b17023SJohn Marino
3136e4b17023SJohn Marino pri = TREE_INT_CST_LOW (initp_expr);
3137e4b17023SJohn Marino
3138e4b17023SJohn Marino type = strip_array_types (type);
3139e4b17023SJohn Marino
3140e4b17023SJohn Marino if (decl == NULL_TREE
3141e4b17023SJohn Marino || TREE_CODE (decl) != VAR_DECL
3142e4b17023SJohn Marino || !TREE_STATIC (decl)
3143e4b17023SJohn Marino || DECL_EXTERNAL (decl)
3144e4b17023SJohn Marino || (TREE_CODE (type) != RECORD_TYPE
3145e4b17023SJohn Marino && TREE_CODE (type) != UNION_TYPE)
3146e4b17023SJohn Marino /* Static objects in functions are initialized the
3147e4b17023SJohn Marino first time control passes through that
3148e4b17023SJohn Marino function. This is not precise enough to pin down an
3149e4b17023SJohn Marino init_priority value, so don't allow it. */
3150e4b17023SJohn Marino || current_function_decl)
3151e4b17023SJohn Marino {
3152e4b17023SJohn Marino error ("can only use %qE attribute on file-scope definitions "
3153e4b17023SJohn Marino "of objects of class type", name);
3154e4b17023SJohn Marino *no_add_attrs = true;
3155e4b17023SJohn Marino return NULL_TREE;
3156e4b17023SJohn Marino }
3157e4b17023SJohn Marino
3158e4b17023SJohn Marino if (pri > MAX_INIT_PRIORITY || pri <= 0)
3159e4b17023SJohn Marino {
3160e4b17023SJohn Marino error ("requested init_priority is out of range");
3161e4b17023SJohn Marino *no_add_attrs = true;
3162e4b17023SJohn Marino return NULL_TREE;
3163e4b17023SJohn Marino }
3164e4b17023SJohn Marino
3165e4b17023SJohn Marino /* Check for init_priorities that are reserved for
3166e4b17023SJohn Marino language and runtime support implementations.*/
3167e4b17023SJohn Marino if (pri <= MAX_RESERVED_INIT_PRIORITY)
3168e4b17023SJohn Marino {
3169e4b17023SJohn Marino warning
3170e4b17023SJohn Marino (0, "requested init_priority is reserved for internal use");
3171e4b17023SJohn Marino }
3172e4b17023SJohn Marino
3173e4b17023SJohn Marino if (SUPPORTS_INIT_PRIORITY)
3174e4b17023SJohn Marino {
3175e4b17023SJohn Marino SET_DECL_INIT_PRIORITY (decl, pri);
3176e4b17023SJohn Marino DECL_HAS_INIT_PRIORITY_P (decl) = 1;
3177e4b17023SJohn Marino return NULL_TREE;
3178e4b17023SJohn Marino }
3179e4b17023SJohn Marino else
3180e4b17023SJohn Marino {
3181e4b17023SJohn Marino error ("%qE attribute is not supported on this platform", name);
3182e4b17023SJohn Marino *no_add_attrs = true;
3183e4b17023SJohn Marino return NULL_TREE;
3184e4b17023SJohn Marino }
3185e4b17023SJohn Marino }
3186e4b17023SJohn Marino
3187e4b17023SJohn Marino /* Return a new PTRMEM_CST of the indicated TYPE. The MEMBER is the
3188e4b17023SJohn Marino thing pointed to by the constant. */
3189e4b17023SJohn Marino
3190e4b17023SJohn Marino tree
make_ptrmem_cst(tree type,tree member)3191e4b17023SJohn Marino make_ptrmem_cst (tree type, tree member)
3192e4b17023SJohn Marino {
3193e4b17023SJohn Marino tree ptrmem_cst = make_node (PTRMEM_CST);
3194e4b17023SJohn Marino TREE_TYPE (ptrmem_cst) = type;
3195e4b17023SJohn Marino PTRMEM_CST_MEMBER (ptrmem_cst) = member;
3196e4b17023SJohn Marino return ptrmem_cst;
3197e4b17023SJohn Marino }
3198e4b17023SJohn Marino
3199e4b17023SJohn Marino /* Build a variant of TYPE that has the indicated ATTRIBUTES. May
3200e4b17023SJohn Marino return an existing type if an appropriate type already exists. */
3201e4b17023SJohn Marino
3202e4b17023SJohn Marino tree
cp_build_type_attribute_variant(tree type,tree attributes)3203e4b17023SJohn Marino cp_build_type_attribute_variant (tree type, tree attributes)
3204e4b17023SJohn Marino {
3205e4b17023SJohn Marino tree new_type;
3206e4b17023SJohn Marino
3207e4b17023SJohn Marino new_type = build_type_attribute_variant (type, attributes);
3208e4b17023SJohn Marino if (TREE_CODE (new_type) == FUNCTION_TYPE
3209e4b17023SJohn Marino || TREE_CODE (new_type) == METHOD_TYPE)
3210e4b17023SJohn Marino new_type = build_exception_variant (new_type,
3211e4b17023SJohn Marino TYPE_RAISES_EXCEPTIONS (type));
3212e4b17023SJohn Marino
3213e4b17023SJohn Marino /* Making a new main variant of a class type is broken. */
3214e4b17023SJohn Marino gcc_assert (!CLASS_TYPE_P (type) || new_type == type);
3215e4b17023SJohn Marino
3216e4b17023SJohn Marino return new_type;
3217e4b17023SJohn Marino }
3218e4b17023SJohn Marino
3219e4b17023SJohn Marino /* Return TRUE if TYPE1 and TYPE2 are identical for type hashing purposes.
3220e4b17023SJohn Marino Called only after doing all language independent checks. Only
3221e4b17023SJohn Marino to check TYPE_RAISES_EXCEPTIONS for FUNCTION_TYPE, the rest is already
3222e4b17023SJohn Marino compared in type_hash_eq. */
3223e4b17023SJohn Marino
3224e4b17023SJohn Marino bool
cxx_type_hash_eq(const_tree typea,const_tree typeb)3225e4b17023SJohn Marino cxx_type_hash_eq (const_tree typea, const_tree typeb)
3226e4b17023SJohn Marino {
3227e4b17023SJohn Marino gcc_assert (TREE_CODE (typea) == FUNCTION_TYPE
3228e4b17023SJohn Marino || TREE_CODE (typea) == METHOD_TYPE);
3229e4b17023SJohn Marino
3230e4b17023SJohn Marino return comp_except_specs (TYPE_RAISES_EXCEPTIONS (typea),
3231e4b17023SJohn Marino TYPE_RAISES_EXCEPTIONS (typeb), ce_exact);
3232e4b17023SJohn Marino }
3233e4b17023SJohn Marino
3234e4b17023SJohn Marino /* Apply FUNC to all language-specific sub-trees of TP in a pre-order
3235e4b17023SJohn Marino traversal. Called from walk_tree. */
3236e4b17023SJohn Marino
3237e4b17023SJohn Marino tree
cp_walk_subtrees(tree * tp,int * walk_subtrees_p,walk_tree_fn func,void * data,struct pointer_set_t * pset)3238e4b17023SJohn Marino cp_walk_subtrees (tree *tp, int *walk_subtrees_p, walk_tree_fn func,
3239e4b17023SJohn Marino void *data, struct pointer_set_t *pset)
3240e4b17023SJohn Marino {
3241e4b17023SJohn Marino enum tree_code code = TREE_CODE (*tp);
3242e4b17023SJohn Marino tree result;
3243e4b17023SJohn Marino
3244e4b17023SJohn Marino #define WALK_SUBTREE(NODE) \
3245e4b17023SJohn Marino do \
3246e4b17023SJohn Marino { \
3247e4b17023SJohn Marino result = cp_walk_tree (&(NODE), func, data, pset); \
3248e4b17023SJohn Marino if (result) goto out; \
3249e4b17023SJohn Marino } \
3250e4b17023SJohn Marino while (0)
3251e4b17023SJohn Marino
3252e4b17023SJohn Marino /* Not one of the easy cases. We must explicitly go through the
3253e4b17023SJohn Marino children. */
3254e4b17023SJohn Marino result = NULL_TREE;
3255e4b17023SJohn Marino switch (code)
3256e4b17023SJohn Marino {
3257e4b17023SJohn Marino case DEFAULT_ARG:
3258e4b17023SJohn Marino case TEMPLATE_TEMPLATE_PARM:
3259e4b17023SJohn Marino case BOUND_TEMPLATE_TEMPLATE_PARM:
3260e4b17023SJohn Marino case UNBOUND_CLASS_TEMPLATE:
3261e4b17023SJohn Marino case TEMPLATE_PARM_INDEX:
3262e4b17023SJohn Marino case TEMPLATE_TYPE_PARM:
3263e4b17023SJohn Marino case TYPENAME_TYPE:
3264e4b17023SJohn Marino case TYPEOF_TYPE:
3265e4b17023SJohn Marino case UNDERLYING_TYPE:
3266e4b17023SJohn Marino /* None of these have subtrees other than those already walked
3267e4b17023SJohn Marino above. */
3268e4b17023SJohn Marino *walk_subtrees_p = 0;
3269e4b17023SJohn Marino break;
3270e4b17023SJohn Marino
3271e4b17023SJohn Marino case BASELINK:
3272e4b17023SJohn Marino WALK_SUBTREE (BASELINK_FUNCTIONS (*tp));
3273e4b17023SJohn Marino *walk_subtrees_p = 0;
3274e4b17023SJohn Marino break;
3275e4b17023SJohn Marino
3276e4b17023SJohn Marino case PTRMEM_CST:
3277e4b17023SJohn Marino WALK_SUBTREE (TREE_TYPE (*tp));
3278e4b17023SJohn Marino *walk_subtrees_p = 0;
3279e4b17023SJohn Marino break;
3280e4b17023SJohn Marino
3281e4b17023SJohn Marino case TREE_LIST:
3282e4b17023SJohn Marino WALK_SUBTREE (TREE_PURPOSE (*tp));
3283e4b17023SJohn Marino break;
3284e4b17023SJohn Marino
3285e4b17023SJohn Marino case OVERLOAD:
3286e4b17023SJohn Marino WALK_SUBTREE (OVL_FUNCTION (*tp));
3287e4b17023SJohn Marino WALK_SUBTREE (OVL_CHAIN (*tp));
3288e4b17023SJohn Marino *walk_subtrees_p = 0;
3289e4b17023SJohn Marino break;
3290e4b17023SJohn Marino
3291e4b17023SJohn Marino case USING_DECL:
3292e4b17023SJohn Marino WALK_SUBTREE (DECL_NAME (*tp));
3293e4b17023SJohn Marino WALK_SUBTREE (USING_DECL_SCOPE (*tp));
3294e4b17023SJohn Marino WALK_SUBTREE (USING_DECL_DECLS (*tp));
3295e4b17023SJohn Marino *walk_subtrees_p = 0;
3296e4b17023SJohn Marino break;
3297e4b17023SJohn Marino
3298e4b17023SJohn Marino case RECORD_TYPE:
3299e4b17023SJohn Marino if (TYPE_PTRMEMFUNC_P (*tp))
3300e4b17023SJohn Marino WALK_SUBTREE (TYPE_PTRMEMFUNC_FN_TYPE (*tp));
3301e4b17023SJohn Marino break;
3302e4b17023SJohn Marino
3303e4b17023SJohn Marino case TYPE_ARGUMENT_PACK:
3304e4b17023SJohn Marino case NONTYPE_ARGUMENT_PACK:
3305e4b17023SJohn Marino {
3306e4b17023SJohn Marino tree args = ARGUMENT_PACK_ARGS (*tp);
3307e4b17023SJohn Marino int i, len = TREE_VEC_LENGTH (args);
3308e4b17023SJohn Marino for (i = 0; i < len; i++)
3309e4b17023SJohn Marino WALK_SUBTREE (TREE_VEC_ELT (args, i));
3310e4b17023SJohn Marino }
3311e4b17023SJohn Marino break;
3312e4b17023SJohn Marino
3313e4b17023SJohn Marino case TYPE_PACK_EXPANSION:
3314e4b17023SJohn Marino WALK_SUBTREE (TREE_TYPE (*tp));
3315e4b17023SJohn Marino WALK_SUBTREE (PACK_EXPANSION_EXTRA_ARGS (*tp));
3316e4b17023SJohn Marino *walk_subtrees_p = 0;
3317e4b17023SJohn Marino break;
3318e4b17023SJohn Marino
3319e4b17023SJohn Marino case EXPR_PACK_EXPANSION:
3320e4b17023SJohn Marino WALK_SUBTREE (TREE_OPERAND (*tp, 0));
3321e4b17023SJohn Marino WALK_SUBTREE (PACK_EXPANSION_EXTRA_ARGS (*tp));
3322e4b17023SJohn Marino *walk_subtrees_p = 0;
3323e4b17023SJohn Marino break;
3324e4b17023SJohn Marino
3325e4b17023SJohn Marino case CAST_EXPR:
3326e4b17023SJohn Marino case REINTERPRET_CAST_EXPR:
3327e4b17023SJohn Marino case STATIC_CAST_EXPR:
3328e4b17023SJohn Marino case CONST_CAST_EXPR:
3329e4b17023SJohn Marino case DYNAMIC_CAST_EXPR:
3330e4b17023SJohn Marino case IMPLICIT_CONV_EXPR:
3331e4b17023SJohn Marino if (TREE_TYPE (*tp))
3332e4b17023SJohn Marino WALK_SUBTREE (TREE_TYPE (*tp));
3333e4b17023SJohn Marino
3334e4b17023SJohn Marino {
3335e4b17023SJohn Marino int i;
3336e4b17023SJohn Marino for (i = 0; i < TREE_CODE_LENGTH (TREE_CODE (*tp)); ++i)
3337e4b17023SJohn Marino WALK_SUBTREE (TREE_OPERAND (*tp, i));
3338e4b17023SJohn Marino }
3339e4b17023SJohn Marino *walk_subtrees_p = 0;
3340e4b17023SJohn Marino break;
3341e4b17023SJohn Marino
3342e4b17023SJohn Marino case TRAIT_EXPR:
3343e4b17023SJohn Marino WALK_SUBTREE (TRAIT_EXPR_TYPE1 (*tp));
3344e4b17023SJohn Marino WALK_SUBTREE (TRAIT_EXPR_TYPE2 (*tp));
3345e4b17023SJohn Marino *walk_subtrees_p = 0;
3346e4b17023SJohn Marino break;
3347e4b17023SJohn Marino
3348e4b17023SJohn Marino case DECLTYPE_TYPE:
3349e4b17023SJohn Marino WALK_SUBTREE (DECLTYPE_TYPE_EXPR (*tp));
3350e4b17023SJohn Marino *walk_subtrees_p = 0;
3351e4b17023SJohn Marino break;
3352e4b17023SJohn Marino
3353e4b17023SJohn Marino
3354e4b17023SJohn Marino default:
3355e4b17023SJohn Marino return NULL_TREE;
3356e4b17023SJohn Marino }
3357e4b17023SJohn Marino
3358e4b17023SJohn Marino /* We didn't find what we were looking for. */
3359e4b17023SJohn Marino out:
3360e4b17023SJohn Marino return result;
3361e4b17023SJohn Marino
3362e4b17023SJohn Marino #undef WALK_SUBTREE
3363e4b17023SJohn Marino }
3364e4b17023SJohn Marino
3365e4b17023SJohn Marino /* Like save_expr, but for C++. */
3366e4b17023SJohn Marino
3367e4b17023SJohn Marino tree
cp_save_expr(tree expr)3368e4b17023SJohn Marino cp_save_expr (tree expr)
3369e4b17023SJohn Marino {
3370e4b17023SJohn Marino /* There is no reason to create a SAVE_EXPR within a template; if
3371e4b17023SJohn Marino needed, we can create the SAVE_EXPR when instantiating the
3372e4b17023SJohn Marino template. Furthermore, the middle-end cannot handle C++-specific
3373e4b17023SJohn Marino tree codes. */
3374e4b17023SJohn Marino if (processing_template_decl)
3375e4b17023SJohn Marino return expr;
3376e4b17023SJohn Marino return save_expr (expr);
3377e4b17023SJohn Marino }
3378e4b17023SJohn Marino
3379e4b17023SJohn Marino /* Initialize tree.c. */
3380e4b17023SJohn Marino
3381e4b17023SJohn Marino void
init_tree(void)3382e4b17023SJohn Marino init_tree (void)
3383e4b17023SJohn Marino {
3384e4b17023SJohn Marino list_hash_table = htab_create_ggc (31, list_hash, list_hash_eq, NULL);
3385e4b17023SJohn Marino }
3386e4b17023SJohn Marino
3387e4b17023SJohn Marino /* Returns the kind of special function that DECL (a FUNCTION_DECL)
3388e4b17023SJohn Marino is. Note that sfk_none is zero, so this function can be used as a
3389e4b17023SJohn Marino predicate to test whether or not DECL is a special function. */
3390e4b17023SJohn Marino
3391e4b17023SJohn Marino special_function_kind
special_function_p(const_tree decl)3392e4b17023SJohn Marino special_function_p (const_tree decl)
3393e4b17023SJohn Marino {
3394e4b17023SJohn Marino /* Rather than doing all this stuff with magic names, we should
3395e4b17023SJohn Marino probably have a field of type `special_function_kind' in
3396e4b17023SJohn Marino DECL_LANG_SPECIFIC. */
3397e4b17023SJohn Marino if (DECL_COPY_CONSTRUCTOR_P (decl))
3398e4b17023SJohn Marino return sfk_copy_constructor;
3399e4b17023SJohn Marino if (DECL_MOVE_CONSTRUCTOR_P (decl))
3400e4b17023SJohn Marino return sfk_move_constructor;
3401e4b17023SJohn Marino if (DECL_CONSTRUCTOR_P (decl))
3402e4b17023SJohn Marino return sfk_constructor;
3403e4b17023SJohn Marino if (DECL_OVERLOADED_OPERATOR_P (decl) == NOP_EXPR)
3404e4b17023SJohn Marino {
3405e4b17023SJohn Marino if (copy_fn_p (decl))
3406e4b17023SJohn Marino return sfk_copy_assignment;
3407e4b17023SJohn Marino if (move_fn_p (decl))
3408e4b17023SJohn Marino return sfk_move_assignment;
3409e4b17023SJohn Marino }
3410e4b17023SJohn Marino if (DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (decl))
3411e4b17023SJohn Marino return sfk_destructor;
3412e4b17023SJohn Marino if (DECL_COMPLETE_DESTRUCTOR_P (decl))
3413e4b17023SJohn Marino return sfk_complete_destructor;
3414e4b17023SJohn Marino if (DECL_BASE_DESTRUCTOR_P (decl))
3415e4b17023SJohn Marino return sfk_base_destructor;
3416e4b17023SJohn Marino if (DECL_DELETING_DESTRUCTOR_P (decl))
3417e4b17023SJohn Marino return sfk_deleting_destructor;
3418e4b17023SJohn Marino if (DECL_CONV_FN_P (decl))
3419e4b17023SJohn Marino return sfk_conversion;
3420e4b17023SJohn Marino
3421e4b17023SJohn Marino return sfk_none;
3422e4b17023SJohn Marino }
3423e4b17023SJohn Marino
3424e4b17023SJohn Marino /* Returns nonzero if TYPE is a character type, including wchar_t. */
3425e4b17023SJohn Marino
3426e4b17023SJohn Marino int
char_type_p(tree type)3427e4b17023SJohn Marino char_type_p (tree type)
3428e4b17023SJohn Marino {
3429e4b17023SJohn Marino return (same_type_p (type, char_type_node)
3430e4b17023SJohn Marino || same_type_p (type, unsigned_char_type_node)
3431e4b17023SJohn Marino || same_type_p (type, signed_char_type_node)
3432e4b17023SJohn Marino || same_type_p (type, char16_type_node)
3433e4b17023SJohn Marino || same_type_p (type, char32_type_node)
3434e4b17023SJohn Marino || same_type_p (type, wchar_type_node));
3435e4b17023SJohn Marino }
3436e4b17023SJohn Marino
3437e4b17023SJohn Marino /* Returns the kind of linkage associated with the indicated DECL. Th
3438e4b17023SJohn Marino value returned is as specified by the language standard; it is
3439e4b17023SJohn Marino independent of implementation details regarding template
3440e4b17023SJohn Marino instantiation, etc. For example, it is possible that a declaration
3441e4b17023SJohn Marino to which this function assigns external linkage would not show up
3442e4b17023SJohn Marino as a global symbol when you run `nm' on the resulting object file. */
3443e4b17023SJohn Marino
3444e4b17023SJohn Marino linkage_kind
decl_linkage(tree decl)3445e4b17023SJohn Marino decl_linkage (tree decl)
3446e4b17023SJohn Marino {
3447e4b17023SJohn Marino /* This function doesn't attempt to calculate the linkage from first
3448e4b17023SJohn Marino principles as given in [basic.link]. Instead, it makes use of
3449e4b17023SJohn Marino the fact that we have already set TREE_PUBLIC appropriately, and
3450e4b17023SJohn Marino then handles a few special cases. Ideally, we would calculate
3451e4b17023SJohn Marino linkage first, and then transform that into a concrete
3452e4b17023SJohn Marino implementation. */
3453e4b17023SJohn Marino
3454e4b17023SJohn Marino /* Things that don't have names have no linkage. */
3455e4b17023SJohn Marino if (!DECL_NAME (decl))
3456e4b17023SJohn Marino return lk_none;
3457e4b17023SJohn Marino
3458e4b17023SJohn Marino /* Fields have no linkage. */
3459e4b17023SJohn Marino if (TREE_CODE (decl) == FIELD_DECL)
3460e4b17023SJohn Marino return lk_none;
3461e4b17023SJohn Marino
3462e4b17023SJohn Marino /* Things that are TREE_PUBLIC have external linkage. */
3463e4b17023SJohn Marino if (TREE_PUBLIC (decl))
3464e4b17023SJohn Marino return lk_external;
3465e4b17023SJohn Marino
3466e4b17023SJohn Marino if (TREE_CODE (decl) == NAMESPACE_DECL)
3467e4b17023SJohn Marino return lk_external;
3468e4b17023SJohn Marino
3469e4b17023SJohn Marino /* Linkage of a CONST_DECL depends on the linkage of the enumeration
3470e4b17023SJohn Marino type. */
3471e4b17023SJohn Marino if (TREE_CODE (decl) == CONST_DECL)
3472e4b17023SJohn Marino return decl_linkage (TYPE_NAME (TREE_TYPE (decl)));
3473e4b17023SJohn Marino
3474e4b17023SJohn Marino /* Some things that are not TREE_PUBLIC have external linkage, too.
3475e4b17023SJohn Marino For example, on targets that don't have weak symbols, we make all
3476e4b17023SJohn Marino template instantiations have internal linkage (in the object
3477e4b17023SJohn Marino file), but the symbols should still be treated as having external
3478e4b17023SJohn Marino linkage from the point of view of the language. */
3479e4b17023SJohn Marino if ((TREE_CODE (decl) == FUNCTION_DECL
3480e4b17023SJohn Marino || TREE_CODE (decl) == VAR_DECL)
3481e4b17023SJohn Marino && DECL_COMDAT (decl))
3482e4b17023SJohn Marino return lk_external;
3483e4b17023SJohn Marino
3484e4b17023SJohn Marino /* Things in local scope do not have linkage, if they don't have
3485e4b17023SJohn Marino TREE_PUBLIC set. */
3486e4b17023SJohn Marino if (decl_function_context (decl))
3487e4b17023SJohn Marino return lk_none;
3488e4b17023SJohn Marino
3489e4b17023SJohn Marino /* Members of the anonymous namespace also have TREE_PUBLIC unset, but
3490e4b17023SJohn Marino are considered to have external linkage for language purposes. DECLs
3491e4b17023SJohn Marino really meant to have internal linkage have DECL_THIS_STATIC set. */
3492e4b17023SJohn Marino if (TREE_CODE (decl) == TYPE_DECL)
3493e4b17023SJohn Marino return lk_external;
3494e4b17023SJohn Marino if (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == FUNCTION_DECL)
3495e4b17023SJohn Marino {
3496e4b17023SJohn Marino if (!DECL_THIS_STATIC (decl))
3497e4b17023SJohn Marino return lk_external;
3498e4b17023SJohn Marino
3499e4b17023SJohn Marino /* Static data members and static member functions from classes
3500e4b17023SJohn Marino in anonymous namespace also don't have TREE_PUBLIC set. */
3501e4b17023SJohn Marino if (DECL_CLASS_CONTEXT (decl))
3502e4b17023SJohn Marino return lk_external;
3503e4b17023SJohn Marino }
3504e4b17023SJohn Marino
3505e4b17023SJohn Marino /* Everything else has internal linkage. */
3506e4b17023SJohn Marino return lk_internal;
3507e4b17023SJohn Marino }
3508e4b17023SJohn Marino
3509e4b17023SJohn Marino /* Returns the storage duration of the object or reference associated with
3510e4b17023SJohn Marino the indicated DECL, which should be a VAR_DECL or PARM_DECL. */
3511e4b17023SJohn Marino
3512e4b17023SJohn Marino duration_kind
decl_storage_duration(tree decl)3513e4b17023SJohn Marino decl_storage_duration (tree decl)
3514e4b17023SJohn Marino {
3515e4b17023SJohn Marino if (TREE_CODE (decl) == PARM_DECL)
3516e4b17023SJohn Marino return dk_auto;
3517e4b17023SJohn Marino if (TREE_CODE (decl) == FUNCTION_DECL)
3518e4b17023SJohn Marino return dk_static;
3519e4b17023SJohn Marino gcc_assert (TREE_CODE (decl) == VAR_DECL);
3520e4b17023SJohn Marino if (!TREE_STATIC (decl)
3521e4b17023SJohn Marino && !DECL_EXTERNAL (decl))
3522e4b17023SJohn Marino return dk_auto;
3523e4b17023SJohn Marino if (DECL_THREAD_LOCAL_P (decl))
3524e4b17023SJohn Marino return dk_thread;
3525e4b17023SJohn Marino return dk_static;
3526e4b17023SJohn Marino }
3527e4b17023SJohn Marino
3528e4b17023SJohn Marino /* EXP is an expression that we want to pre-evaluate. Returns (in
3529e4b17023SJohn Marino *INITP) an expression that will perform the pre-evaluation. The
3530e4b17023SJohn Marino value returned by this function is a side-effect free expression
3531e4b17023SJohn Marino equivalent to the pre-evaluated expression. Callers must ensure
3532e4b17023SJohn Marino that *INITP is evaluated before EXP. */
3533e4b17023SJohn Marino
3534e4b17023SJohn Marino tree
stabilize_expr(tree exp,tree * initp)3535e4b17023SJohn Marino stabilize_expr (tree exp, tree* initp)
3536e4b17023SJohn Marino {
3537e4b17023SJohn Marino tree init_expr;
3538e4b17023SJohn Marino
3539e4b17023SJohn Marino if (!TREE_SIDE_EFFECTS (exp))
3540e4b17023SJohn Marino init_expr = NULL_TREE;
3541e4b17023SJohn Marino else if (VOID_TYPE_P (TREE_TYPE (exp)))
3542e4b17023SJohn Marino {
3543e4b17023SJohn Marino *initp = exp;
3544e4b17023SJohn Marino return void_zero_node;
3545e4b17023SJohn Marino }
3546e4b17023SJohn Marino /* There are no expressions with REFERENCE_TYPE, but there can be call
3547e4b17023SJohn Marino arguments with such a type; just treat it as a pointer. */
3548e4b17023SJohn Marino else if (TREE_CODE (TREE_TYPE (exp)) == REFERENCE_TYPE
3549e4b17023SJohn Marino || SCALAR_TYPE_P (TREE_TYPE (exp))
3550e4b17023SJohn Marino || !lvalue_or_rvalue_with_address_p (exp))
3551e4b17023SJohn Marino {
3552e4b17023SJohn Marino init_expr = get_target_expr (exp);
3553e4b17023SJohn Marino exp = TARGET_EXPR_SLOT (init_expr);
3554e4b17023SJohn Marino }
3555e4b17023SJohn Marino else
3556e4b17023SJohn Marino {
3557e4b17023SJohn Marino bool xval = !real_lvalue_p (exp);
3558e4b17023SJohn Marino exp = cp_build_addr_expr (exp, tf_warning_or_error);
3559e4b17023SJohn Marino init_expr = get_target_expr (exp);
3560e4b17023SJohn Marino exp = TARGET_EXPR_SLOT (init_expr);
3561e4b17023SJohn Marino exp = cp_build_indirect_ref (exp, RO_NULL, tf_warning_or_error);
3562e4b17023SJohn Marino if (xval)
3563e4b17023SJohn Marino exp = move (exp);
3564e4b17023SJohn Marino }
3565e4b17023SJohn Marino *initp = init_expr;
3566e4b17023SJohn Marino
3567e4b17023SJohn Marino gcc_assert (!TREE_SIDE_EFFECTS (exp));
3568e4b17023SJohn Marino return exp;
3569e4b17023SJohn Marino }
3570e4b17023SJohn Marino
3571e4b17023SJohn Marino /* Add NEW_EXPR, an expression whose value we don't care about, after the
3572e4b17023SJohn Marino similar expression ORIG. */
3573e4b17023SJohn Marino
3574e4b17023SJohn Marino tree
add_stmt_to_compound(tree orig,tree new_expr)3575e4b17023SJohn Marino add_stmt_to_compound (tree orig, tree new_expr)
3576e4b17023SJohn Marino {
3577e4b17023SJohn Marino if (!new_expr || !TREE_SIDE_EFFECTS (new_expr))
3578e4b17023SJohn Marino return orig;
3579e4b17023SJohn Marino if (!orig || !TREE_SIDE_EFFECTS (orig))
3580e4b17023SJohn Marino return new_expr;
3581e4b17023SJohn Marino return build2 (COMPOUND_EXPR, void_type_node, orig, new_expr);
3582e4b17023SJohn Marino }
3583e4b17023SJohn Marino
3584e4b17023SJohn Marino /* Like stabilize_expr, but for a call whose arguments we want to
3585e4b17023SJohn Marino pre-evaluate. CALL is modified in place to use the pre-evaluated
3586e4b17023SJohn Marino arguments, while, upon return, *INITP contains an expression to
3587e4b17023SJohn Marino compute the arguments. */
3588e4b17023SJohn Marino
3589e4b17023SJohn Marino void
stabilize_call(tree call,tree * initp)3590e4b17023SJohn Marino stabilize_call (tree call, tree *initp)
3591e4b17023SJohn Marino {
3592e4b17023SJohn Marino tree inits = NULL_TREE;
3593e4b17023SJohn Marino int i;
3594e4b17023SJohn Marino int nargs = call_expr_nargs (call);
3595e4b17023SJohn Marino
3596e4b17023SJohn Marino if (call == error_mark_node || processing_template_decl)
3597e4b17023SJohn Marino {
3598e4b17023SJohn Marino *initp = NULL_TREE;
3599e4b17023SJohn Marino return;
3600e4b17023SJohn Marino }
3601e4b17023SJohn Marino
3602e4b17023SJohn Marino gcc_assert (TREE_CODE (call) == CALL_EXPR);
3603e4b17023SJohn Marino
3604e4b17023SJohn Marino for (i = 0; i < nargs; i++)
3605e4b17023SJohn Marino {
3606e4b17023SJohn Marino tree init;
3607e4b17023SJohn Marino CALL_EXPR_ARG (call, i) =
3608e4b17023SJohn Marino stabilize_expr (CALL_EXPR_ARG (call, i), &init);
3609e4b17023SJohn Marino inits = add_stmt_to_compound (inits, init);
3610e4b17023SJohn Marino }
3611e4b17023SJohn Marino
3612e4b17023SJohn Marino *initp = inits;
3613e4b17023SJohn Marino }
3614e4b17023SJohn Marino
3615e4b17023SJohn Marino /* Like stabilize_expr, but for an AGGR_INIT_EXPR whose arguments we want
3616e4b17023SJohn Marino to pre-evaluate. CALL is modified in place to use the pre-evaluated
3617e4b17023SJohn Marino arguments, while, upon return, *INITP contains an expression to
3618e4b17023SJohn Marino compute the arguments. */
3619e4b17023SJohn Marino
3620e4b17023SJohn Marino void
stabilize_aggr_init(tree call,tree * initp)3621e4b17023SJohn Marino stabilize_aggr_init (tree call, tree *initp)
3622e4b17023SJohn Marino {
3623e4b17023SJohn Marino tree inits = NULL_TREE;
3624e4b17023SJohn Marino int i;
3625e4b17023SJohn Marino int nargs = aggr_init_expr_nargs (call);
3626e4b17023SJohn Marino
3627e4b17023SJohn Marino if (call == error_mark_node)
3628e4b17023SJohn Marino return;
3629e4b17023SJohn Marino
3630e4b17023SJohn Marino gcc_assert (TREE_CODE (call) == AGGR_INIT_EXPR);
3631e4b17023SJohn Marino
3632e4b17023SJohn Marino for (i = 0; i < nargs; i++)
3633e4b17023SJohn Marino {
3634e4b17023SJohn Marino tree init;
3635e4b17023SJohn Marino AGGR_INIT_EXPR_ARG (call, i) =
3636e4b17023SJohn Marino stabilize_expr (AGGR_INIT_EXPR_ARG (call, i), &init);
3637e4b17023SJohn Marino inits = add_stmt_to_compound (inits, init);
3638e4b17023SJohn Marino }
3639e4b17023SJohn Marino
3640e4b17023SJohn Marino *initp = inits;
3641e4b17023SJohn Marino }
3642e4b17023SJohn Marino
3643e4b17023SJohn Marino /* Like stabilize_expr, but for an initialization.
3644e4b17023SJohn Marino
3645e4b17023SJohn Marino If the initialization is for an object of class type, this function
3646e4b17023SJohn Marino takes care not to introduce additional temporaries.
3647e4b17023SJohn Marino
3648e4b17023SJohn Marino Returns TRUE iff the expression was successfully pre-evaluated,
3649e4b17023SJohn Marino i.e., if INIT is now side-effect free, except for, possible, a
3650e4b17023SJohn Marino single call to a constructor. */
3651e4b17023SJohn Marino
3652e4b17023SJohn Marino bool
stabilize_init(tree init,tree * initp)3653e4b17023SJohn Marino stabilize_init (tree init, tree *initp)
3654e4b17023SJohn Marino {
3655e4b17023SJohn Marino tree t = init;
3656e4b17023SJohn Marino
3657e4b17023SJohn Marino *initp = NULL_TREE;
3658e4b17023SJohn Marino
3659e4b17023SJohn Marino if (t == error_mark_node || processing_template_decl)
3660e4b17023SJohn Marino return true;
3661e4b17023SJohn Marino
3662e4b17023SJohn Marino if (TREE_CODE (t) == INIT_EXPR
3663e4b17023SJohn Marino && TREE_CODE (TREE_OPERAND (t, 1)) != TARGET_EXPR
3664e4b17023SJohn Marino && TREE_CODE (TREE_OPERAND (t, 1)) != CONSTRUCTOR
3665e4b17023SJohn Marino && TREE_CODE (TREE_OPERAND (t, 1)) != AGGR_INIT_EXPR)
3666e4b17023SJohn Marino {
3667e4b17023SJohn Marino TREE_OPERAND (t, 1) = stabilize_expr (TREE_OPERAND (t, 1), initp);
3668e4b17023SJohn Marino return true;
3669e4b17023SJohn Marino }
3670e4b17023SJohn Marino
3671e4b17023SJohn Marino if (TREE_CODE (t) == INIT_EXPR)
3672e4b17023SJohn Marino t = TREE_OPERAND (t, 1);
3673e4b17023SJohn Marino if (TREE_CODE (t) == TARGET_EXPR)
3674e4b17023SJohn Marino t = TARGET_EXPR_INITIAL (t);
3675e4b17023SJohn Marino if (TREE_CODE (t) == COMPOUND_EXPR)
3676e4b17023SJohn Marino t = expr_last (t);
3677e4b17023SJohn Marino if (TREE_CODE (t) == CONSTRUCTOR)
3678e4b17023SJohn Marino {
3679e4b17023SJohn Marino /* Aggregate initialization: stabilize each of the field
3680e4b17023SJohn Marino initializers. */
3681e4b17023SJohn Marino unsigned i;
3682e4b17023SJohn Marino constructor_elt *ce;
3683e4b17023SJohn Marino bool good = true;
3684e4b17023SJohn Marino VEC(constructor_elt,gc) *v = CONSTRUCTOR_ELTS (t);
3685e4b17023SJohn Marino for (i = 0; VEC_iterate (constructor_elt, v, i, ce); ++i)
3686e4b17023SJohn Marino {
3687e4b17023SJohn Marino tree type = TREE_TYPE (ce->value);
3688e4b17023SJohn Marino tree subinit;
3689e4b17023SJohn Marino if (TREE_CODE (type) == REFERENCE_TYPE
3690e4b17023SJohn Marino || SCALAR_TYPE_P (type))
3691e4b17023SJohn Marino ce->value = stabilize_expr (ce->value, &subinit);
3692e4b17023SJohn Marino else if (!stabilize_init (ce->value, &subinit))
3693e4b17023SJohn Marino good = false;
3694e4b17023SJohn Marino *initp = add_stmt_to_compound (*initp, subinit);
3695e4b17023SJohn Marino }
3696e4b17023SJohn Marino return good;
3697e4b17023SJohn Marino }
3698e4b17023SJohn Marino
3699e4b17023SJohn Marino /* If the initializer is a COND_EXPR, we can't preevaluate
3700e4b17023SJohn Marino anything. */
3701e4b17023SJohn Marino if (TREE_CODE (t) == COND_EXPR)
3702e4b17023SJohn Marino return false;
3703e4b17023SJohn Marino
3704e4b17023SJohn Marino if (TREE_CODE (t) == CALL_EXPR)
3705e4b17023SJohn Marino {
3706e4b17023SJohn Marino stabilize_call (t, initp);
3707e4b17023SJohn Marino return true;
3708e4b17023SJohn Marino }
3709e4b17023SJohn Marino
3710e4b17023SJohn Marino if (TREE_CODE (t) == AGGR_INIT_EXPR)
3711e4b17023SJohn Marino {
3712e4b17023SJohn Marino stabilize_aggr_init (t, initp);
3713e4b17023SJohn Marino return true;
3714e4b17023SJohn Marino }
3715e4b17023SJohn Marino
3716e4b17023SJohn Marino /* The initialization is being performed via a bitwise copy -- and
3717e4b17023SJohn Marino the item copied may have side effects. */
3718e4b17023SJohn Marino return !TREE_SIDE_EFFECTS (init);
3719e4b17023SJohn Marino }
3720e4b17023SJohn Marino
3721e4b17023SJohn Marino /* Like "fold", but should be used whenever we might be processing the
3722e4b17023SJohn Marino body of a template. */
3723e4b17023SJohn Marino
3724e4b17023SJohn Marino tree
fold_if_not_in_template(tree expr)3725e4b17023SJohn Marino fold_if_not_in_template (tree expr)
3726e4b17023SJohn Marino {
3727e4b17023SJohn Marino /* In the body of a template, there is never any need to call
3728e4b17023SJohn Marino "fold". We will call fold later when actually instantiating the
3729e4b17023SJohn Marino template. Integral constant expressions in templates will be
3730e4b17023SJohn Marino evaluated via fold_non_dependent_expr, as necessary. */
3731e4b17023SJohn Marino if (processing_template_decl)
3732e4b17023SJohn Marino return expr;
3733e4b17023SJohn Marino
3734e4b17023SJohn Marino /* Fold C++ front-end specific tree codes. */
3735e4b17023SJohn Marino if (TREE_CODE (expr) == UNARY_PLUS_EXPR)
3736e4b17023SJohn Marino return fold_convert (TREE_TYPE (expr), TREE_OPERAND (expr, 0));
3737e4b17023SJohn Marino
3738e4b17023SJohn Marino return fold (expr);
3739e4b17023SJohn Marino }
3740e4b17023SJohn Marino
3741e4b17023SJohn Marino /* Returns true if a cast to TYPE may appear in an integral constant
3742e4b17023SJohn Marino expression. */
3743e4b17023SJohn Marino
3744e4b17023SJohn Marino bool
cast_valid_in_integral_constant_expression_p(tree type)3745e4b17023SJohn Marino cast_valid_in_integral_constant_expression_p (tree type)
3746e4b17023SJohn Marino {
3747e4b17023SJohn Marino return (INTEGRAL_OR_ENUMERATION_TYPE_P (type)
3748e4b17023SJohn Marino || cxx_dialect >= cxx0x
3749e4b17023SJohn Marino || dependent_type_p (type)
3750e4b17023SJohn Marino || type == error_mark_node);
3751e4b17023SJohn Marino }
3752e4b17023SJohn Marino
3753e4b17023SJohn Marino /* Return true if we need to fix linkage information of DECL. */
3754e4b17023SJohn Marino
3755e4b17023SJohn Marino static bool
cp_fix_function_decl_p(tree decl)3756e4b17023SJohn Marino cp_fix_function_decl_p (tree decl)
3757e4b17023SJohn Marino {
3758e4b17023SJohn Marino /* Skip if DECL is not externally visible. */
3759e4b17023SJohn Marino if (!TREE_PUBLIC (decl))
3760e4b17023SJohn Marino return false;
3761e4b17023SJohn Marino
3762e4b17023SJohn Marino /* We need to fix DECL if it a appears to be exported but with no
3763e4b17023SJohn Marino function body. Thunks do not have CFGs and we may need to
3764e4b17023SJohn Marino handle them specially later. */
3765e4b17023SJohn Marino if (!gimple_has_body_p (decl)
3766e4b17023SJohn Marino && !DECL_THUNK_P (decl)
3767e4b17023SJohn Marino && !DECL_EXTERNAL (decl))
3768e4b17023SJohn Marino {
3769e4b17023SJohn Marino struct cgraph_node *node = cgraph_get_node (decl);
3770e4b17023SJohn Marino
3771e4b17023SJohn Marino /* Don't fix same_body aliases. Although they don't have their own
3772e4b17023SJohn Marino CFG, they share it with what they alias to. */
3773e4b17023SJohn Marino if (!node || !node->alias
3774e4b17023SJohn Marino || !VEC_length (ipa_ref_t, node->ref_list.references))
3775e4b17023SJohn Marino return true;
3776e4b17023SJohn Marino }
3777e4b17023SJohn Marino
3778e4b17023SJohn Marino return false;
3779e4b17023SJohn Marino }
3780e4b17023SJohn Marino
3781e4b17023SJohn Marino /* Clean the C++ specific parts of the tree T. */
3782e4b17023SJohn Marino
3783e4b17023SJohn Marino void
cp_free_lang_data(tree t)3784e4b17023SJohn Marino cp_free_lang_data (tree t)
3785e4b17023SJohn Marino {
3786e4b17023SJohn Marino if (TREE_CODE (t) == METHOD_TYPE
3787e4b17023SJohn Marino || TREE_CODE (t) == FUNCTION_TYPE)
3788e4b17023SJohn Marino {
3789e4b17023SJohn Marino /* Default args are not interesting anymore. */
3790e4b17023SJohn Marino tree argtypes = TYPE_ARG_TYPES (t);
3791e4b17023SJohn Marino while (argtypes)
3792e4b17023SJohn Marino {
3793e4b17023SJohn Marino TREE_PURPOSE (argtypes) = 0;
3794e4b17023SJohn Marino argtypes = TREE_CHAIN (argtypes);
3795e4b17023SJohn Marino }
3796e4b17023SJohn Marino }
3797e4b17023SJohn Marino else if (TREE_CODE (t) == FUNCTION_DECL
3798e4b17023SJohn Marino && cp_fix_function_decl_p (t))
3799e4b17023SJohn Marino {
3800e4b17023SJohn Marino /* If T is used in this translation unit at all, the definition
3801e4b17023SJohn Marino must exist somewhere else since we have decided to not emit it
3802e4b17023SJohn Marino in this TU. So make it an external reference. */
3803e4b17023SJohn Marino DECL_EXTERNAL (t) = 1;
3804e4b17023SJohn Marino TREE_STATIC (t) = 0;
3805e4b17023SJohn Marino }
3806e4b17023SJohn Marino if (TREE_CODE (t) == NAMESPACE_DECL)
3807e4b17023SJohn Marino {
3808e4b17023SJohn Marino /* The list of users of a namespace isn't useful for the middle-end
3809e4b17023SJohn Marino or debug generators. */
3810e4b17023SJohn Marino DECL_NAMESPACE_USERS (t) = NULL_TREE;
3811e4b17023SJohn Marino /* Neither do we need the leftover chaining of namespaces
3812e4b17023SJohn Marino from the binding level. */
3813e4b17023SJohn Marino DECL_CHAIN (t) = NULL_TREE;
3814e4b17023SJohn Marino }
3815e4b17023SJohn Marino }
3816e4b17023SJohn Marino
3817e4b17023SJohn Marino /* Stub for c-common. Please keep in sync with c-decl.c.
3818e4b17023SJohn Marino FIXME: If address space support is target specific, then this
3819e4b17023SJohn Marino should be a C target hook. But currently this is not possible,
3820e4b17023SJohn Marino because this function is called via REGISTER_TARGET_PRAGMAS. */
3821e4b17023SJohn Marino void
c_register_addr_space(const char * word ATTRIBUTE_UNUSED,addr_space_t as ATTRIBUTE_UNUSED)3822e4b17023SJohn Marino c_register_addr_space (const char *word ATTRIBUTE_UNUSED,
3823e4b17023SJohn Marino addr_space_t as ATTRIBUTE_UNUSED)
3824e4b17023SJohn Marino {
3825e4b17023SJohn Marino }
3826e4b17023SJohn Marino
3827e4b17023SJohn Marino /* Return the number of operands in T that we care about for things like
3828e4b17023SJohn Marino mangling. */
3829e4b17023SJohn Marino
3830e4b17023SJohn Marino int
cp_tree_operand_length(const_tree t)3831e4b17023SJohn Marino cp_tree_operand_length (const_tree t)
3832e4b17023SJohn Marino {
3833e4b17023SJohn Marino enum tree_code code = TREE_CODE (t);
3834e4b17023SJohn Marino
3835e4b17023SJohn Marino switch (code)
3836e4b17023SJohn Marino {
3837e4b17023SJohn Marino case PREINCREMENT_EXPR:
3838e4b17023SJohn Marino case PREDECREMENT_EXPR:
3839e4b17023SJohn Marino case POSTINCREMENT_EXPR:
3840e4b17023SJohn Marino case POSTDECREMENT_EXPR:
3841e4b17023SJohn Marino return 1;
3842e4b17023SJohn Marino
3843e4b17023SJohn Marino case ARRAY_REF:
3844e4b17023SJohn Marino return 2;
3845e4b17023SJohn Marino
3846e4b17023SJohn Marino case EXPR_PACK_EXPANSION:
3847e4b17023SJohn Marino return 1;
3848e4b17023SJohn Marino
3849e4b17023SJohn Marino default:
3850e4b17023SJohn Marino return TREE_OPERAND_LENGTH (t);
3851e4b17023SJohn Marino }
3852e4b17023SJohn Marino }
3853e4b17023SJohn Marino
3854e4b17023SJohn Marino #if defined ENABLE_TREE_CHECKING && (GCC_VERSION >= 2007)
3855e4b17023SJohn Marino /* Complain that some language-specific thing hanging off a tree
3856e4b17023SJohn Marino node has been accessed improperly. */
3857e4b17023SJohn Marino
3858e4b17023SJohn Marino void
lang_check_failed(const char * file,int line,const char * function)3859e4b17023SJohn Marino lang_check_failed (const char* file, int line, const char* function)
3860e4b17023SJohn Marino {
3861e4b17023SJohn Marino internal_error ("lang_* check: failed in %s, at %s:%d",
3862e4b17023SJohn Marino function, trim_filename (file), line);
3863e4b17023SJohn Marino }
3864e4b17023SJohn Marino #endif /* ENABLE_TREE_CHECKING */
3865e4b17023SJohn Marino
3866e4b17023SJohn Marino #include "gt-cp-tree.h"
3867