1 /* Language-dependent node constructors for parse phase of GNU compiler.
2 Copyright (C) 1987, 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
4 Hacked by Michael Tiemann (tiemann@cygnus.com)
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GCC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING. If not, write to
20 the Free Software Foundation, 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA. */
25 #include "coretypes.h"
33 #include "insn-config.h"
34 #include "integrate.h"
35 #include "tree-inline.h"
40 static tree
bot_manip (tree
*, int *, void *);
41 static tree
bot_replace (tree
*, int *, void *);
42 static tree
build_cplus_array_type_1 (tree
, tree
);
43 static int list_hash_eq (const void *, const void *);
44 static hashval_t
list_hash_pieces (tree
, tree
, tree
);
45 static hashval_t
list_hash (const void *);
46 static cp_lvalue_kind
lvalue_p_1 (tree
, int);
47 static tree
build_target_expr (tree
, tree
);
48 static tree
count_trees_r (tree
*, int *, void *);
49 static tree
verify_stmt_tree_r (tree
*, int *, void *);
50 static tree
build_local_temp (tree
);
52 static tree
handle_java_interface_attribute (tree
*, tree
, tree
, int, bool *);
53 static tree
handle_com_interface_attribute (tree
*, tree
, tree
, int, bool *);
54 static tree
handle_init_priority_attribute (tree
*, tree
, tree
, int, bool *);
56 /* If REF is an lvalue, returns the kind of lvalue that REF is.
57 Otherwise, returns clk_none. If TREAT_CLASS_RVALUES_AS_LVALUES is
58 nonzero, rvalues of class type are considered lvalues. */
62 int treat_class_rvalues_as_lvalues
)
64 cp_lvalue_kind op1_lvalue_kind
= clk_none
;
65 cp_lvalue_kind op2_lvalue_kind
= clk_none
;
67 /* Expressions of reference type are sometimes wrapped in
68 INDIRECT_REFs. INDIRECT_REFs are just internal compiler
69 representation, not part of the language, so we have to look
71 if (TREE_CODE (ref
) == INDIRECT_REF
72 && TREE_CODE (TREE_TYPE (TREE_OPERAND (ref
, 0)))
74 return lvalue_p_1 (TREE_OPERAND (ref
, 0),
75 treat_class_rvalues_as_lvalues
);
77 if (TREE_CODE (TREE_TYPE (ref
)) == REFERENCE_TYPE
)
79 /* unnamed rvalue references are rvalues */
80 if (TYPE_REF_IS_RVALUE (TREE_TYPE (ref
))
81 && TREE_CODE (ref
) != PARM_DECL
82 && TREE_CODE (ref
) != VAR_DECL
83 && TREE_CODE (ref
) != COMPONENT_REF
)
86 /* lvalue references and named rvalue refences are lvalues */
90 if (ref
== current_class_ptr
)
93 switch (TREE_CODE (ref
))
95 /* preincrements and predecrements are valid lvals, provided
96 what they refer to are valid lvals. */
97 case PREINCREMENT_EXPR
:
98 case PREDECREMENT_EXPR
:
101 case WITH_CLEANUP_EXPR
:
104 return lvalue_p_1 (TREE_OPERAND (ref
, 0),
105 treat_class_rvalues_as_lvalues
);
108 op1_lvalue_kind
= lvalue_p_1 (TREE_OPERAND (ref
, 0),
109 treat_class_rvalues_as_lvalues
);
110 /* Look at the member designator. */
112 /* The "field" can be a FUNCTION_DECL or an OVERLOAD in some
114 || TREE_CODE (TREE_OPERAND (ref
, 1)) != FIELD_DECL
)
116 else if (DECL_C_BIT_FIELD (TREE_OPERAND (ref
, 1)))
118 /* Clear the ordinary bit. If this object was a class
119 rvalue we want to preserve that information. */
120 op1_lvalue_kind
&= ~clk_ordinary
;
121 /* The lvalue is for a bitfield. */
122 op1_lvalue_kind
|= clk_bitfield
;
124 else if (DECL_PACKED (TREE_OPERAND (ref
, 1)))
125 op1_lvalue_kind
|= clk_packed
;
127 return op1_lvalue_kind
;
134 if (TREE_READONLY (ref
) && ! TREE_STATIC (ref
)
135 && DECL_LANG_SPECIFIC (ref
)
136 && DECL_IN_AGGR_P (ref
))
142 if (TREE_CODE (TREE_TYPE (ref
)) != METHOD_TYPE
)
146 /* A currently unresolved scope ref. */
151 /* Disallow <? and >? as lvalues if either argument side-effects. */
152 if (TREE_SIDE_EFFECTS (TREE_OPERAND (ref
, 0))
153 || TREE_SIDE_EFFECTS (TREE_OPERAND (ref
, 1)))
155 op1_lvalue_kind
= lvalue_p_1 (TREE_OPERAND (ref
, 0),
156 treat_class_rvalues_as_lvalues
);
157 op2_lvalue_kind
= lvalue_p_1 (TREE_OPERAND (ref
, 1),
158 treat_class_rvalues_as_lvalues
);
162 op1_lvalue_kind
= lvalue_p_1 (TREE_OPERAND (ref
, 1),
163 treat_class_rvalues_as_lvalues
);
164 op2_lvalue_kind
= lvalue_p_1 (TREE_OPERAND (ref
, 2),
165 treat_class_rvalues_as_lvalues
);
172 return lvalue_p_1 (TREE_OPERAND (ref
, 1),
173 treat_class_rvalues_as_lvalues
);
176 return treat_class_rvalues_as_lvalues
? clk_class
: clk_none
;
179 return (treat_class_rvalues_as_lvalues
180 && CLASS_TYPE_P (TREE_TYPE (ref
))
181 ? clk_class
: clk_none
);
184 /* Any class-valued call would be wrapped in a TARGET_EXPR. */
188 /* All functions (except non-static-member functions) are
190 return (DECL_NONSTATIC_MEMBER_FUNCTION_P (ref
)
191 ? clk_none
: clk_ordinary
);
193 case NON_DEPENDENT_EXPR
:
194 /* We must consider NON_DEPENDENT_EXPRs to be lvalues so that
195 things like "&E" where "E" is an expression with a
196 non-dependent type work. It is safe to be lenient because an
197 error will be issued when the template is instantiated if "E"
205 /* If one operand is not an lvalue at all, then this expression is
207 if (!op1_lvalue_kind
|| !op2_lvalue_kind
)
210 /* Otherwise, it's an lvalue, and it has all the odd properties
211 contributed by either operand. */
212 op1_lvalue_kind
= op1_lvalue_kind
| op2_lvalue_kind
;
213 /* It's not an ordinary lvalue if it involves either a bit-field or
215 if ((op1_lvalue_kind
& ~clk_ordinary
) != clk_none
)
216 op1_lvalue_kind
&= ~clk_ordinary
;
217 return op1_lvalue_kind
;
220 /* Returns the kind of lvalue that REF is, in the sense of
221 [basic.lval]. This function should really be named lvalue_p; it
222 computes the C++ definition of lvalue. */
225 real_lvalue_p (tree ref
)
227 return lvalue_p_1 (ref
,
228 /*treat_class_rvalues_as_lvalues=*/0);
231 /* This differs from real_lvalue_p in that class rvalues are
232 considered lvalues. */
238 (lvalue_p_1 (ref
, /*class rvalue ok*/ 1) != clk_none
);
241 /* Test whether DECL is a builtin that may appear in a
242 constant-expression. */
245 builtin_valid_in_constant_expr_p (tree decl
)
247 /* At present BUILT_IN_CONSTANT_P is the only builtin we're allowing
248 in constant-expressions. We may want to add other builtins later. */
249 return DECL_IS_BUILTIN_CONSTANT_P (decl
);
252 /* Build a TARGET_EXPR, initializing the DECL with the VALUE. */
255 build_target_expr (tree decl
, tree value
)
259 t
= build4 (TARGET_EXPR
, TREE_TYPE (decl
), decl
, value
,
260 cxx_maybe_build_cleanup (decl
), NULL_TREE
);
261 /* We always set TREE_SIDE_EFFECTS so that expand_expr does not
262 ignore the TARGET_EXPR. If there really turn out to be no
263 side-effects, then the optimizer should be able to get rid of
264 whatever code is generated anyhow. */
265 TREE_SIDE_EFFECTS (t
) = 1;
270 /* Return an undeclared local temporary of type TYPE for use in building a
274 build_local_temp (tree type
)
276 tree slot
= build_decl (VAR_DECL
, NULL_TREE
, type
);
277 DECL_ARTIFICIAL (slot
) = 1;
278 DECL_IGNORED_P (slot
) = 1;
279 DECL_CONTEXT (slot
) = current_function_decl
;
280 layout_decl (slot
, 0);
284 /* Set various status flags when building an AGGR_INIT_EXPR object T. */
287 process_aggr_init_operands (tree t
)
291 side_effects
= TREE_SIDE_EFFECTS (t
);
295 n
= TREE_OPERAND_LENGTH (t
);
296 for (i
= 1; i
< n
; i
++)
298 tree op
= TREE_OPERAND (t
, i
);
299 if (op
&& TREE_SIDE_EFFECTS (op
))
306 TREE_SIDE_EFFECTS (t
) = side_effects
;
309 /* Build an AGGR_INIT_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE,
310 FN, and SLOT. NARGS is the number of call arguments which are specified
311 as a tree array ARGS. */
314 build_aggr_init_array (tree return_type
, tree fn
, tree slot
, int nargs
,
320 t
= build_vl_exp (AGGR_INIT_EXPR
, nargs
+ 3);
321 TREE_TYPE (t
) = return_type
;
322 AGGR_INIT_EXPR_FN (t
) = fn
;
323 AGGR_INIT_EXPR_SLOT (t
) = slot
;
324 for (i
= 0; i
< nargs
; i
++)
325 AGGR_INIT_EXPR_ARG (t
, i
) = args
[i
];
326 process_aggr_init_operands (t
);
330 /* INIT is a CALL_EXPR or AGGR_INIT_EXPR which needs info about its
331 target. TYPE is the type that this initialization should appear to
334 Build an encapsulation of the initialization to perform
335 and return it so that it can be processed by language-independent
336 and language-specific expression expanders. */
339 build_cplus_new (tree type
, tree init
)
346 /* Make sure that we're not trying to create an instance of an
348 abstract_virtuals_error (NULL_TREE
, type
);
350 if (TREE_CODE (init
) == CALL_EXPR
)
351 fn
= CALL_EXPR_FN (init
);
352 else if (TREE_CODE (init
) == AGGR_INIT_EXPR
)
353 fn
= AGGR_INIT_EXPR_FN (init
);
355 return convert (type
, init
);
357 is_ctor
= (TREE_CODE (fn
) == ADDR_EXPR
358 && TREE_CODE (TREE_OPERAND (fn
, 0)) == FUNCTION_DECL
359 && DECL_CONSTRUCTOR_P (TREE_OPERAND (fn
, 0)));
361 slot
= build_local_temp (type
);
363 /* We split the CALL_EXPR into its function and its arguments here.
364 Then, in expand_expr, we put them back together. The reason for
365 this is that this expression might be a default argument
366 expression. In that case, we need a new temporary every time the
367 expression is used. That's what break_out_target_exprs does; it
368 replaces every AGGR_INIT_EXPR with a copy that uses a fresh
369 temporary slot. Then, expand_expr builds up a call-expression
370 using the new slot. */
372 /* If we don't need to use a constructor to create an object of this
373 type, don't mess with AGGR_INIT_EXPR. */
374 if (is_ctor
|| TREE_ADDRESSABLE (type
))
376 if (TREE_CODE(init
) == CALL_EXPR
)
377 rval
= build_aggr_init_array (void_type_node
, fn
, slot
,
378 call_expr_nargs (init
),
379 CALL_EXPR_ARGP (init
));
381 rval
= build_aggr_init_array (void_type_node
, fn
, slot
,
382 aggr_init_expr_nargs (init
),
383 AGGR_INIT_EXPR_ARGP (init
));
384 TREE_SIDE_EFFECTS (rval
) = 1;
385 AGGR_INIT_VIA_CTOR_P (rval
) = is_ctor
;
390 rval
= build_target_expr (slot
, rval
);
391 TARGET_EXPR_IMPLICIT_P (rval
) = 1;
396 /* Build a TARGET_EXPR using INIT to initialize a new temporary of the
400 build_target_expr_with_type (tree init
, tree type
)
402 gcc_assert (!VOID_TYPE_P (type
));
404 if (TREE_CODE (init
) == TARGET_EXPR
)
406 else if (CLASS_TYPE_P (type
) && !TYPE_HAS_TRIVIAL_INIT_REF (type
)
407 && TREE_CODE (init
) != COND_EXPR
408 && TREE_CODE (init
) != CONSTRUCTOR
409 && TREE_CODE (init
) != VA_ARG_EXPR
)
410 /* We need to build up a copy constructor call. COND_EXPR is a special
411 case because we already have copies on the arms and we don't want
412 another one here. A CONSTRUCTOR is aggregate initialization, which
413 is handled separately. A VA_ARG_EXPR is magic creation of an
414 aggregate; there's no additional work to be done. */
415 return force_rvalue (init
);
417 return force_target_expr (type
, init
);
420 /* Like the above function, but without the checking. This function should
421 only be used by code which is deliberately trying to subvert the type
422 system, such as call_builtin_trap. */
425 force_target_expr (tree type
, tree init
)
429 gcc_assert (!VOID_TYPE_P (type
));
431 slot
= build_local_temp (type
);
432 return build_target_expr (slot
, init
);
435 /* Like build_target_expr_with_type, but use the type of INIT. */
438 get_target_expr (tree init
)
440 return build_target_expr_with_type (init
, TREE_TYPE (init
));
443 /* If EXPR is a bitfield reference, convert it to the declared type of
444 the bitfield, and return the resulting expression. Otherwise,
445 return EXPR itself. */
448 convert_bitfield_to_declared_type (tree expr
)
452 bitfield_type
= is_bitfield_expr_with_lowered_type (expr
);
454 expr
= convert_to_integer (TYPE_MAIN_VARIANT (bitfield_type
),
459 /* EXPR is being used in an rvalue context. Return a version of EXPR
460 that is marked as an rvalue. */
467 if (error_operand_p (expr
))
472 Non-class rvalues always have cv-unqualified types. */
473 type
= TREE_TYPE (expr
);
474 if (!CLASS_TYPE_P (type
) && cp_type_quals (type
))
475 type
= TYPE_MAIN_VARIANT (type
);
477 if (!processing_template_decl
&& real_lvalue_p (expr
))
478 expr
= build1 (NON_LVALUE_EXPR
, type
, expr
);
479 else if (type
!= TREE_TYPE (expr
))
480 expr
= build_nop (type
, expr
);
486 /* Hash an ARRAY_TYPE. K is really of type `tree'. */
489 cplus_array_hash (const void* k
)
492 const_tree
const t
= (const_tree
) k
;
494 hash
= (htab_hash_pointer (TREE_TYPE (t
))
495 ^ htab_hash_pointer (TYPE_DOMAIN (t
)));
500 typedef struct cplus_array_info
{
505 /* Compare two ARRAY_TYPEs. K1 is really of type `tree', K2 is really
506 of type `cplus_array_info*'. */
509 cplus_array_compare (const void * k1
, const void * k2
)
511 const_tree
const t1
= (const_tree
) k1
;
512 const cplus_array_info
*const t2
= (const cplus_array_info
*) k2
;
514 if (!comptypes (TREE_TYPE (t1
), t2
->type
, COMPARE_STRUCTURAL
))
517 if (!TYPE_DOMAIN (t1
))
523 return comptypes (TYPE_DOMAIN (t1
), t2
->domain
, COMPARE_STRUCTURAL
);
526 static GTY ((param_is (union tree_node
))) htab_t cplus_array_htab
;
530 build_cplus_array_type_1 (tree elt_type
, tree index_type
)
534 if (elt_type
== error_mark_node
|| index_type
== error_mark_node
)
535 return error_mark_node
;
537 if (dependent_type_p (elt_type
)
539 && value_dependent_expression_p (TYPE_MAX_VALUE (index_type
))))
542 cplus_array_info cai
;
545 if (cplus_array_htab
== NULL
)
546 cplus_array_htab
= htab_create_ggc (61, &cplus_array_hash
,
547 &cplus_array_compare
, NULL
);
549 hash
= (htab_hash_pointer (elt_type
)
550 ^ htab_hash_pointer (index_type
));
552 cai
.domain
= index_type
;
554 e
= htab_find_slot_with_hash (cplus_array_htab
, &cai
, hash
, INSERT
);
556 /* We have found the type: we're done. */
560 /* Build a new array type. */
561 t
= make_node (ARRAY_TYPE
);
562 TREE_TYPE (t
) = elt_type
;
563 TYPE_DOMAIN (t
) = index_type
;
565 /* Complete building the array type. */
566 if (TYPE_STRUCTURAL_EQUALITY_P (elt_type
)
567 || (index_type
&& TYPE_STRUCTURAL_EQUALITY_P (index_type
)))
568 SET_TYPE_STRUCTURAL_EQUALITY (t
);
569 else if (TYPE_CANONICAL (elt_type
) != elt_type
571 && TYPE_CANONICAL (index_type
) != index_type
))
574 (build_cplus_array_type_1 (TYPE_CANONICAL (elt_type
),
576 TYPE_CANONICAL (index_type
)
579 /* Store it in the hash table. */
584 t
= build_array_type (elt_type
, index_type
);
586 /* Push these needs up so that initialization takes place
588 TYPE_NEEDS_CONSTRUCTING (t
)
589 = TYPE_NEEDS_CONSTRUCTING (TYPE_MAIN_VARIANT (elt_type
));
590 TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t
)
591 = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TYPE_MAIN_VARIANT (elt_type
));
596 build_cplus_array_type (tree elt_type
, tree index_type
)
599 int type_quals
= cp_type_quals (elt_type
);
601 if (type_quals
!= TYPE_UNQUALIFIED
)
602 elt_type
= cp_build_qualified_type (elt_type
, TYPE_UNQUALIFIED
);
604 t
= build_cplus_array_type_1 (elt_type
, index_type
);
606 if (type_quals
!= TYPE_UNQUALIFIED
)
607 t
= cp_build_qualified_type (t
, type_quals
);
612 /* Return a reference type node referring to TO_TYPE. If RVAL is
613 true, return an rvalue reference type, otherwise return an lvalue
614 reference type. If a type node exists, reuse it, otherwise create
617 cp_build_reference_type (tree to_type
, bool rval
)
620 lvalue_ref
= build_reference_type (to_type
);
624 /* This code to create rvalue reference types is based on and tied
625 to the code creating lvalue reference types in the middle-end
626 functions build_reference_type_for_mode and build_reference_type.
628 It works by putting the rvalue reference type nodes after the
629 lvalue reference nodes in the TYPE_NEXT_REF_TO linked list, so
630 they will effectively be ignored by the middle end. */
632 for (t
= lvalue_ref
; (t
= TYPE_NEXT_REF_TO (t
)); )
633 if (TYPE_REF_IS_RVALUE (t
))
636 t
= copy_node (lvalue_ref
);
638 TYPE_REF_IS_RVALUE (t
) = true;
639 TYPE_NEXT_REF_TO (t
) = TYPE_NEXT_REF_TO (lvalue_ref
);
640 TYPE_NEXT_REF_TO (lvalue_ref
) = t
;
641 TYPE_MAIN_VARIANT (t
) = t
;
643 if (TYPE_STRUCTURAL_EQUALITY_P (to_type
))
644 SET_TYPE_STRUCTURAL_EQUALITY (t
);
645 else if (TYPE_CANONICAL (to_type
) != to_type
)
647 = cp_build_reference_type (TYPE_CANONICAL (to_type
), rval
);
649 TYPE_CANONICAL (t
) = t
;
659 /* Make a variant of TYPE, qualified with the TYPE_QUALS. Handles
660 arrays correctly. In particular, if TYPE is an array of T's, and
661 TYPE_QUALS is non-empty, returns an array of qualified T's.
663 FLAGS determines how to deal with illformed qualifications. If
664 tf_ignore_bad_quals is set, then bad qualifications are dropped
665 (this is permitted if TYPE was introduced via a typedef or template
666 type parameter). If bad qualifications are dropped and tf_warning
667 is set, then a warning is issued for non-const qualifications. If
668 tf_ignore_bad_quals is not set and tf_error is not set, we
669 return error_mark_node. Otherwise, we issue an error, and ignore
672 Qualification of a reference type is valid when the reference came
673 via a typedef or template type argument. [dcl.ref] No such
674 dispensation is provided for qualifying a function type. [dcl.fct]
675 DR 295 queries this and the proposed resolution brings it into line
676 with qualifying a reference. We implement the DR. We also behave
677 in a similar manner for restricting non-pointer types. */
680 cp_build_qualified_type_real (tree type
,
682 tsubst_flags_t complain
)
685 int bad_quals
= TYPE_UNQUALIFIED
;
687 if (type
== error_mark_node
)
690 if (type_quals
== cp_type_quals (type
))
693 if (TREE_CODE (type
) == ARRAY_TYPE
)
695 /* In C++, the qualification really applies to the array element
696 type. Obtain the appropriately qualified element type. */
699 = cp_build_qualified_type_real (TREE_TYPE (type
),
703 if (element_type
== error_mark_node
)
704 return error_mark_node
;
706 /* See if we already have an identically qualified type. */
707 for (t
= TYPE_MAIN_VARIANT (type
); t
; t
= TYPE_NEXT_VARIANT (t
))
708 if (cp_type_quals (t
) == type_quals
709 && TYPE_NAME (t
) == TYPE_NAME (type
)
710 && TYPE_CONTEXT (t
) == TYPE_CONTEXT (type
))
715 tree domain
= TYPE_DOMAIN (type
);
717 /* Make a new array type, just like the old one, but with the
718 appropriately qualified element type. */
719 t
= build_variant_type_copy (type
);
720 TREE_TYPE (t
) = element_type
;
722 /* This is a new type. */
723 TYPE_CANONICAL (t
) = t
;
725 if (dependent_type_p (element_type
)
727 && value_dependent_expression_p (TYPE_MAX_VALUE (domain
))))
729 /* The new dependent array type we just created might be
730 equivalent to an existing dependent array type, so we
731 need to keep track of this new array type with a
732 lookup into CPLUS_ARRAY_HTAB. Note that we cannot
733 directly call build_cplus_array_type (that would
734 recurse) or build_cplus_array_type_1 (that would lose
737 cplus_array_info cai
;
740 if (cplus_array_htab
== NULL
)
741 cplus_array_htab
= htab_create_ggc (61, &cplus_array_hash
,
742 &cplus_array_compare
,
745 hash
= (htab_hash_pointer (element_type
)
746 ^ htab_hash_pointer (domain
));
747 cai
.type
= element_type
;
750 e
= htab_find_slot_with_hash (cplus_array_htab
, &cai
, hash
,
753 /* Save this new type. */
757 if (TYPE_STRUCTURAL_EQUALITY_P (TREE_TYPE (t
))
759 && TYPE_STRUCTURAL_EQUALITY_P (TYPE_DOMAIN (t
))))
760 SET_TYPE_STRUCTURAL_EQUALITY (t
);
764 (build_array_type (TYPE_CANONICAL (TREE_TYPE (t
)),
766 TYPE_CANONICAL (TYPE_DOMAIN(t
))
770 /* Even if we already had this variant, we update
771 TYPE_NEEDS_CONSTRUCTING and TYPE_HAS_NONTRIVIAL_DESTRUCTOR in case
772 they changed since the variant was originally created.
774 This seems hokey; if there is some way to use a previous
775 variant *without* coming through here,
776 TYPE_NEEDS_CONSTRUCTING will never be updated. */
777 TYPE_NEEDS_CONSTRUCTING (t
)
778 = TYPE_NEEDS_CONSTRUCTING (TYPE_MAIN_VARIANT (element_type
));
779 TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t
)
780 = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TYPE_MAIN_VARIANT (element_type
));
783 else if (TYPE_PTRMEMFUNC_P (type
))
785 /* For a pointer-to-member type, we can't just return a
786 cv-qualified version of the RECORD_TYPE. If we do, we
787 haven't changed the field that contains the actual pointer to
788 a method, and so TYPE_PTRMEMFUNC_FN_TYPE will be wrong. */
791 t
= TYPE_PTRMEMFUNC_FN_TYPE (type
);
792 t
= cp_build_qualified_type_real (t
, type_quals
, complain
);
793 return build_ptrmemfunc_type (t
);
796 /* A reference or method type shall not be cv qualified.
797 [dcl.ref], [dct.fct] */
798 if (type_quals
& (TYPE_QUAL_CONST
| TYPE_QUAL_VOLATILE
)
799 && (TREE_CODE (type
) == REFERENCE_TYPE
800 || TREE_CODE (type
) == METHOD_TYPE
))
802 bad_quals
|= type_quals
& (TYPE_QUAL_CONST
| TYPE_QUAL_VOLATILE
);
803 type_quals
&= ~(TYPE_QUAL_CONST
| TYPE_QUAL_VOLATILE
);
806 /* A restrict-qualified type must be a pointer (or reference)
807 to object or incomplete type, or a function type. */
808 if ((type_quals
& TYPE_QUAL_RESTRICT
)
809 && TREE_CODE (type
) != TEMPLATE_TYPE_PARM
810 && TREE_CODE (type
) != TYPENAME_TYPE
811 && TREE_CODE (type
) != FUNCTION_TYPE
812 && !POINTER_TYPE_P (type
))
814 bad_quals
|= TYPE_QUAL_RESTRICT
;
815 type_quals
&= ~TYPE_QUAL_RESTRICT
;
818 if (bad_quals
== TYPE_UNQUALIFIED
)
820 else if (!(complain
& (tf_error
| tf_ignore_bad_quals
)))
821 return error_mark_node
;
824 if (complain
& tf_ignore_bad_quals
)
825 /* We're not going to warn about constifying things that can't
827 bad_quals
&= ~TYPE_QUAL_CONST
;
830 tree bad_type
= build_qualified_type (ptr_type_node
, bad_quals
);
832 if (!(complain
& tf_ignore_bad_quals
))
833 error ("%qV qualifiers cannot be applied to %qT",
838 /* Retrieve (or create) the appropriately qualified variant. */
839 result
= build_qualified_type (type
, type_quals
);
841 /* If this was a pointer-to-method type, and we just made a copy,
842 then we need to unshare the record that holds the cached
843 pointer-to-member-function type, because these will be distinct
844 between the unqualified and qualified types. */
846 && TREE_CODE (type
) == POINTER_TYPE
847 && TREE_CODE (TREE_TYPE (type
)) == METHOD_TYPE
)
848 TYPE_LANG_SPECIFIC (result
) = NULL
;
853 /* Returns the canonical version of TYPE. In other words, if TYPE is
854 a typedef, returns the underlying type. The cv-qualification of
855 the type returned matches the type input; they will always be
859 canonical_type_variant (tree t
)
861 return cp_build_qualified_type (TYPE_MAIN_VARIANT (t
), cp_type_quals (t
));
864 /* Makes a copy of BINFO and TYPE, which is to be inherited into a
865 graph dominated by T. If BINFO is NULL, TYPE is a dependent base,
866 and we do a shallow copy. If BINFO is non-NULL, we do a deep copy.
867 VIRT indicates whether TYPE is inherited virtually or not.
868 IGO_PREV points at the previous binfo of the inheritance graph
869 order chain. The newly copied binfo's TREE_CHAIN forms this
872 The CLASSTYPE_VBASECLASSES vector of T is constructed in the
873 correct order. That is in the order the bases themselves should be
876 The BINFO_INHERITANCE of a virtual base class points to the binfo
877 of the most derived type. ??? We could probably change this so that
878 BINFO_INHERITANCE becomes synonymous with BINFO_PRIMARY, and hence
879 remove a field. They currently can only differ for primary virtual
883 copy_binfo (tree binfo
, tree type
, tree t
, tree
*igo_prev
, int virt
)
889 /* See if we've already made this virtual base. */
890 new_binfo
= binfo_for_vbase (type
, t
);
895 new_binfo
= make_tree_binfo (binfo
? BINFO_N_BASE_BINFOS (binfo
) : 0);
896 BINFO_TYPE (new_binfo
) = type
;
898 /* Chain it into the inheritance graph. */
899 TREE_CHAIN (*igo_prev
) = new_binfo
;
900 *igo_prev
= new_binfo
;
907 gcc_assert (!BINFO_DEPENDENT_BASE_P (binfo
));
908 gcc_assert (SAME_BINFO_TYPE_P (BINFO_TYPE (binfo
), type
));
910 BINFO_OFFSET (new_binfo
) = BINFO_OFFSET (binfo
);
911 BINFO_VIRTUALS (new_binfo
) = BINFO_VIRTUALS (binfo
);
913 /* We do not need to copy the accesses, as they are read only. */
914 BINFO_BASE_ACCESSES (new_binfo
) = BINFO_BASE_ACCESSES (binfo
);
916 /* Recursively copy base binfos of BINFO. */
917 for (ix
= 0; BINFO_BASE_ITERATE (binfo
, ix
, base_binfo
); ix
++)
921 gcc_assert (!BINFO_DEPENDENT_BASE_P (base_binfo
));
922 new_base_binfo
= copy_binfo (base_binfo
, BINFO_TYPE (base_binfo
),
924 BINFO_VIRTUAL_P (base_binfo
));
926 if (!BINFO_INHERITANCE_CHAIN (new_base_binfo
))
927 BINFO_INHERITANCE_CHAIN (new_base_binfo
) = new_binfo
;
928 BINFO_BASE_APPEND (new_binfo
, new_base_binfo
);
932 BINFO_DEPENDENT_BASE_P (new_binfo
) = 1;
936 /* Push it onto the list after any virtual bases it contains
937 will have been pushed. */
938 VEC_quick_push (tree
, CLASSTYPE_VBASECLASSES (t
), new_binfo
);
939 BINFO_VIRTUAL_P (new_binfo
) = 1;
940 BINFO_INHERITANCE_CHAIN (new_binfo
) = TYPE_BINFO (t
);
946 /* Hashing of lists so that we don't make duplicates.
947 The entry point is `list_hash_canon'. */
949 /* Now here is the hash table. When recording a list, it is added
950 to the slot whose index is the hash code mod the table size.
951 Note that the hash table is used for several kinds of lists.
952 While all these live in the same table, they are completely independent,
953 and the hash code is computed differently for each of these. */
955 static GTY ((param_is (union tree_node
))) htab_t list_hash_table
;
964 /* Compare ENTRY (an entry in the hash table) with DATA (a list_proxy
965 for a node we are thinking about adding). */
968 list_hash_eq (const void* entry
, const void* data
)
970 const_tree
const t
= (const_tree
) entry
;
971 const struct list_proxy
*const proxy
= (const struct list_proxy
*) data
;
973 return (TREE_VALUE (t
) == proxy
->value
974 && TREE_PURPOSE (t
) == proxy
->purpose
975 && TREE_CHAIN (t
) == proxy
->chain
);
978 /* Compute a hash code for a list (chain of TREE_LIST nodes
979 with goodies in the TREE_PURPOSE, TREE_VALUE, and bits of the
980 TREE_COMMON slots), by adding the hash codes of the individual entries. */
983 list_hash_pieces (tree purpose
, tree value
, tree chain
)
985 hashval_t hashcode
= 0;
988 hashcode
+= TREE_HASH (chain
);
991 hashcode
+= TREE_HASH (value
);
995 hashcode
+= TREE_HASH (purpose
);
1001 /* Hash an already existing TREE_LIST. */
1004 list_hash (const void* p
)
1006 const_tree
const t
= (const_tree
) p
;
1007 return list_hash_pieces (TREE_PURPOSE (t
),
1012 /* Given list components PURPOSE, VALUE, AND CHAIN, return the canonical
1013 object for an identical list if one already exists. Otherwise, build a
1014 new one, and record it as the canonical object. */
1017 hash_tree_cons (tree purpose
, tree value
, tree chain
)
1021 struct list_proxy proxy
;
1023 /* Hash the list node. */
1024 hashcode
= list_hash_pieces (purpose
, value
, chain
);
1025 /* Create a proxy for the TREE_LIST we would like to create. We
1026 don't actually create it so as to avoid creating garbage. */
1027 proxy
.purpose
= purpose
;
1028 proxy
.value
= value
;
1029 proxy
.chain
= chain
;
1030 /* See if it is already in the table. */
1031 slot
= htab_find_slot_with_hash (list_hash_table
, &proxy
, hashcode
,
1033 /* If not, create a new node. */
1035 *slot
= tree_cons (purpose
, value
, chain
);
1036 return (tree
) *slot
;
1039 /* Constructor for hashed lists. */
1042 hash_tree_chain (tree value
, tree chain
)
1044 return hash_tree_cons (NULL_TREE
, value
, chain
);
1048 debug_binfo (tree elem
)
1053 fprintf (stderr
, "type \"%s\", offset = " HOST_WIDE_INT_PRINT_DEC
1055 TYPE_NAME_STRING (BINFO_TYPE (elem
)),
1056 TREE_INT_CST_LOW (BINFO_OFFSET (elem
)));
1057 debug_tree (BINFO_TYPE (elem
));
1058 if (BINFO_VTABLE (elem
))
1059 fprintf (stderr
, "vtable decl \"%s\"\n",
1060 IDENTIFIER_POINTER (DECL_NAME (get_vtbl_decl_for_binfo (elem
))));
1062 fprintf (stderr
, "no vtable decl yet\n");
1063 fprintf (stderr
, "virtuals:\n");
1064 virtuals
= BINFO_VIRTUALS (elem
);
1069 tree fndecl
= TREE_VALUE (virtuals
);
1070 fprintf (stderr
, "%s [%ld =? %ld]\n",
1071 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (fndecl
)),
1072 (long) n
, (long) TREE_INT_CST_LOW (DECL_VINDEX (fndecl
)));
1074 virtuals
= TREE_CHAIN (virtuals
);
1078 /* Build a representation for the qualified name SCOPE::NAME. TYPE is
1079 the type of the result expression, if known, or NULL_TREE if the
1080 resulting expression is type-dependent. If TEMPLATE_P is true,
1081 NAME is known to be a template because the user explicitly used the
1082 "template" keyword after the "::".
1084 All SCOPE_REFs should be built by use of this function. */
1087 build_qualified_name (tree type
, tree scope
, tree name
, bool template_p
)
1090 if (type
== error_mark_node
1091 || scope
== error_mark_node
1092 || name
== error_mark_node
)
1093 return error_mark_node
;
1094 t
= build2 (SCOPE_REF
, type
, scope
, name
);
1095 QUALIFIED_NAME_IS_TEMPLATE (t
) = template_p
;
1099 /* Returns nonzero if X is an expression for a (possibly overloaded)
1100 function. If "f" is a function or function template, "f", "c->f",
1101 "c.f", "C::f", and "f<int>" will all be considered possibly
1102 overloaded functions. Returns 2 if the function is actually
1103 overloaded, i.e., if it is impossible to know the type of the
1104 function without performing overload resolution. */
1107 is_overloaded_fn (tree x
)
1109 /* A baselink is also considered an overloaded function. */
1110 if (TREE_CODE (x
) == OFFSET_REF
1111 || TREE_CODE (x
) == COMPONENT_REF
)
1112 x
= TREE_OPERAND (x
, 1);
1114 x
= BASELINK_FUNCTIONS (x
);
1115 if (TREE_CODE (x
) == TEMPLATE_ID_EXPR
1116 || DECL_FUNCTION_TEMPLATE_P (OVL_CURRENT (x
))
1117 || (TREE_CODE (x
) == OVERLOAD
&& OVL_CHAIN (x
)))
1119 return (TREE_CODE (x
) == FUNCTION_DECL
1120 || TREE_CODE (x
) == OVERLOAD
);
1123 /* Returns true iff X is an expression for an overloaded function
1124 whose type cannot be known without performing overload
1128 really_overloaded_fn (tree x
)
1130 return is_overloaded_fn (x
) == 2;
1134 get_first_fn (tree from
)
1136 gcc_assert (is_overloaded_fn (from
));
1137 /* A baselink is also considered an overloaded function. */
1138 if (TREE_CODE (from
) == COMPONENT_REF
)
1139 from
= TREE_OPERAND (from
, 1);
1140 if (BASELINK_P (from
))
1141 from
= BASELINK_FUNCTIONS (from
);
1142 return OVL_CURRENT (from
);
1145 /* Return a new OVL node, concatenating it with the old one. */
1148 ovl_cons (tree decl
, tree chain
)
1150 tree result
= make_node (OVERLOAD
);
1151 TREE_TYPE (result
) = unknown_type_node
;
1152 OVL_FUNCTION (result
) = decl
;
1153 TREE_CHAIN (result
) = chain
;
1158 /* Build a new overloaded function. If this is the first one,
1159 just return it; otherwise, ovl_cons the _DECLs */
1162 build_overload (tree decl
, tree chain
)
1164 if (! chain
&& TREE_CODE (decl
) != TEMPLATE_DECL
)
1166 if (chain
&& TREE_CODE (chain
) != OVERLOAD
)
1167 chain
= ovl_cons (chain
, NULL_TREE
);
1168 return ovl_cons (decl
, chain
);
1172 #define PRINT_RING_SIZE 4
1175 cxx_printable_name (tree decl
, int v
)
1177 static tree decl_ring
[PRINT_RING_SIZE
];
1178 static char *print_ring
[PRINT_RING_SIZE
];
1179 static int ring_counter
;
1182 /* Only cache functions. */
1184 || TREE_CODE (decl
) != FUNCTION_DECL
1185 || DECL_LANG_SPECIFIC (decl
) == 0)
1186 return lang_decl_name (decl
, v
);
1188 /* See if this print name is lying around. */
1189 for (i
= 0; i
< PRINT_RING_SIZE
; i
++)
1190 if (decl_ring
[i
] == decl
)
1191 /* yes, so return it. */
1192 return print_ring
[i
];
1194 if (++ring_counter
== PRINT_RING_SIZE
)
1197 if (current_function_decl
!= NULL_TREE
)
1199 if (decl_ring
[ring_counter
] == current_function_decl
)
1201 if (ring_counter
== PRINT_RING_SIZE
)
1203 gcc_assert (decl_ring
[ring_counter
] != current_function_decl
);
1206 if (print_ring
[ring_counter
])
1207 free (print_ring
[ring_counter
]);
1209 print_ring
[ring_counter
] = xstrdup (lang_decl_name (decl
, v
));
1210 decl_ring
[ring_counter
] = decl
;
1211 return print_ring
[ring_counter
];
1214 /* Build the FUNCTION_TYPE or METHOD_TYPE which may throw exceptions
1215 listed in RAISES. */
1218 build_exception_variant (tree type
, tree raises
)
1220 tree v
= TYPE_MAIN_VARIANT (type
);
1221 int type_quals
= TYPE_QUALS (type
);
1223 for (; v
; v
= TYPE_NEXT_VARIANT (v
))
1224 if (check_qualified_type (v
, type
, type_quals
)
1225 && comp_except_specs (raises
, TYPE_RAISES_EXCEPTIONS (v
), 1))
1228 /* Need to build a new variant. */
1229 v
= build_variant_type_copy (type
);
1230 TYPE_RAISES_EXCEPTIONS (v
) = raises
;
1234 /* Given a TEMPLATE_TEMPLATE_PARM node T, create a new
1235 BOUND_TEMPLATE_TEMPLATE_PARM bound with NEWARGS as its template
1239 bind_template_template_parm (tree t
, tree newargs
)
1241 tree decl
= TYPE_NAME (t
);
1244 t2
= make_aggr_type (BOUND_TEMPLATE_TEMPLATE_PARM
);
1245 decl
= build_decl (TYPE_DECL
, DECL_NAME (decl
), NULL_TREE
);
1247 /* These nodes have to be created to reflect new TYPE_DECL and template
1249 TEMPLATE_TYPE_PARM_INDEX (t2
) = copy_node (TEMPLATE_TYPE_PARM_INDEX (t
));
1250 TEMPLATE_PARM_DECL (TEMPLATE_TYPE_PARM_INDEX (t2
)) = decl
;
1251 TEMPLATE_TEMPLATE_PARM_TEMPLATE_INFO (t2
)
1252 = tree_cons (TEMPLATE_TEMPLATE_PARM_TEMPLATE_DECL (t
),
1253 newargs
, NULL_TREE
);
1255 TREE_TYPE (decl
) = t2
;
1256 TYPE_NAME (t2
) = decl
;
1257 TYPE_STUB_DECL (t2
) = decl
;
1259 SET_TYPE_STRUCTURAL_EQUALITY (t2
);
1264 /* Called from count_trees via walk_tree. */
1267 count_trees_r (tree
*tp
, int *walk_subtrees
, void *data
)
1277 /* Debugging function for measuring the rough complexity of a tree
1281 count_trees (tree t
)
1284 walk_tree_without_duplicates (&t
, count_trees_r
, &n_trees
);
1288 /* Called from verify_stmt_tree via walk_tree. */
1291 verify_stmt_tree_r (tree
* tp
,
1292 int* walk_subtrees ATTRIBUTE_UNUSED
,
1296 htab_t
*statements
= (htab_t
*) data
;
1299 if (!STATEMENT_CODE_P (TREE_CODE (t
)))
1302 /* If this statement is already present in the hash table, then
1303 there is a circularity in the statement tree. */
1304 gcc_assert (!htab_find (*statements
, t
));
1306 slot
= htab_find_slot (*statements
, t
, INSERT
);
1312 /* Debugging function to check that the statement T has not been
1313 corrupted. For now, this function simply checks that T contains no
1317 verify_stmt_tree (tree t
)
1320 statements
= htab_create (37, htab_hash_pointer
, htab_eq_pointer
, NULL
);
1321 walk_tree (&t
, verify_stmt_tree_r
, &statements
, NULL
);
1322 htab_delete (statements
);
1325 /* Check if the type T depends on a type with no linkage and if so, return
1326 it. If RELAXED_P then do not consider a class type declared within
1327 a TREE_PUBLIC function to have no linkage. */
1330 no_linkage_check (tree t
, bool relaxed_p
)
1334 /* There's no point in checking linkage on template functions; we
1335 can't know their complete types. */
1336 if (processing_template_decl
)
1339 switch (TREE_CODE (t
))
1344 if (TYPE_PTRMEMFUNC_P (t
))
1348 if (!CLASS_TYPE_P (t
))
1352 if (TYPE_ANONYMOUS_P (t
))
1354 fn
= decl_function_context (TYPE_MAIN_DECL (t
));
1355 if (fn
&& (!relaxed_p
|| !TREE_PUBLIC (fn
)))
1361 case REFERENCE_TYPE
:
1362 return no_linkage_check (TREE_TYPE (t
), relaxed_p
);
1366 r
= no_linkage_check (TYPE_PTRMEM_POINTED_TO_TYPE (t
),
1370 return no_linkage_check (TYPE_PTRMEM_CLASS_TYPE (t
), relaxed_p
);
1373 r
= no_linkage_check (TYPE_METHOD_BASETYPE (t
), relaxed_p
);
1380 for (parm
= TYPE_ARG_TYPES (t
);
1381 parm
&& parm
!= void_list_node
;
1382 parm
= TREE_CHAIN (parm
))
1384 r
= no_linkage_check (TREE_VALUE (parm
), relaxed_p
);
1388 return no_linkage_check (TREE_TYPE (t
), relaxed_p
);
1396 #ifdef GATHER_STATISTICS
1397 extern int depth_reached
;
1401 cxx_print_statistics (void)
1403 print_search_statistics ();
1404 print_class_statistics ();
1405 #ifdef GATHER_STATISTICS
1406 fprintf (stderr
, "maximum template instantiation depth reached: %d\n",
1411 /* Return, as an INTEGER_CST node, the number of elements for TYPE
1412 (which is an ARRAY_TYPE). This counts only elements of the top
1416 array_type_nelts_top (tree type
)
1418 return fold_build2 (PLUS_EXPR
, sizetype
,
1419 array_type_nelts (type
),
1423 /* Return, as an INTEGER_CST node, the number of elements for TYPE
1424 (which is an ARRAY_TYPE). This one is a recursive count of all
1425 ARRAY_TYPEs that are clumped together. */
1428 array_type_nelts_total (tree type
)
1430 tree sz
= array_type_nelts_top (type
);
1431 type
= TREE_TYPE (type
);
1432 while (TREE_CODE (type
) == ARRAY_TYPE
)
1434 tree n
= array_type_nelts_top (type
);
1435 sz
= fold_build2 (MULT_EXPR
, sizetype
, sz
, n
);
1436 type
= TREE_TYPE (type
);
1441 /* Called from break_out_target_exprs via mapcar. */
1444 bot_manip (tree
* tp
, int* walk_subtrees
, void* data
)
1446 splay_tree target_remap
= ((splay_tree
) data
);
1449 if (!TYPE_P (t
) && TREE_CONSTANT (t
))
1451 /* There can't be any TARGET_EXPRs or their slot variables below
1452 this point. We used to check !TREE_SIDE_EFFECTS, but then we
1453 failed to copy an ADDR_EXPR of the slot VAR_DECL. */
1457 if (TREE_CODE (t
) == TARGET_EXPR
)
1461 if (TREE_CODE (TREE_OPERAND (t
, 1)) == AGGR_INIT_EXPR
)
1463 (TREE_TYPE (t
), break_out_target_exprs (TREE_OPERAND (t
, 1)));
1465 u
= build_target_expr_with_type
1466 (break_out_target_exprs (TREE_OPERAND (t
, 1)), TREE_TYPE (t
));
1468 /* Map the old variable to the new one. */
1469 splay_tree_insert (target_remap
,
1470 (splay_tree_key
) TREE_OPERAND (t
, 0),
1471 (splay_tree_value
) TREE_OPERAND (u
, 0));
1473 /* Replace the old expression with the new version. */
1475 /* We don't have to go below this point; the recursive call to
1476 break_out_target_exprs will have handled anything below this
1482 /* Make a copy of this node. */
1483 return copy_tree_r (tp
, walk_subtrees
, NULL
);
1486 /* Replace all remapped VAR_DECLs in T with their new equivalents.
1487 DATA is really a splay-tree mapping old variables to new
1491 bot_replace (tree
* t
,
1492 int* walk_subtrees ATTRIBUTE_UNUSED
,
1495 splay_tree target_remap
= ((splay_tree
) data
);
1497 if (TREE_CODE (*t
) == VAR_DECL
)
1499 splay_tree_node n
= splay_tree_lookup (target_remap
,
1500 (splay_tree_key
) *t
);
1502 *t
= (tree
) n
->value
;
1508 /* When we parse a default argument expression, we may create
1509 temporary variables via TARGET_EXPRs. When we actually use the
1510 default-argument expression, we make a copy of the expression, but
1511 we must replace the temporaries with appropriate local versions. */
1514 break_out_target_exprs (tree t
)
1516 static int target_remap_count
;
1517 static splay_tree target_remap
;
1519 if (!target_remap_count
++)
1520 target_remap
= splay_tree_new (splay_tree_compare_pointers
,
1521 /*splay_tree_delete_key_fn=*/NULL
,
1522 /*splay_tree_delete_value_fn=*/NULL
);
1523 walk_tree (&t
, bot_manip
, target_remap
, NULL
);
1524 walk_tree (&t
, bot_replace
, target_remap
, NULL
);
1526 if (!--target_remap_count
)
1528 splay_tree_delete (target_remap
);
1529 target_remap
= NULL
;
1535 /* Similar to `build_nt', but for template definitions of dependent
1539 build_min_nt (enum tree_code code
, ...)
1546 gcc_assert (TREE_CODE_CLASS (code
) != tcc_vl_exp
);
1550 t
= make_node (code
);
1551 length
= TREE_CODE_LENGTH (code
);
1553 for (i
= 0; i
< length
; i
++)
1555 tree x
= va_arg (p
, tree
);
1556 TREE_OPERAND (t
, i
) = x
;
1564 /* Similar to `build', but for template definitions. */
1567 build_min (enum tree_code code
, tree tt
, ...)
1574 gcc_assert (TREE_CODE_CLASS (code
) != tcc_vl_exp
);
1578 t
= make_node (code
);
1579 length
= TREE_CODE_LENGTH (code
);
1582 for (i
= 0; i
< length
; i
++)
1584 tree x
= va_arg (p
, tree
);
1585 TREE_OPERAND (t
, i
) = x
;
1586 if (x
&& !TYPE_P (x
) && TREE_SIDE_EFFECTS (x
))
1587 TREE_SIDE_EFFECTS (t
) = 1;
1594 /* Similar to `build', but for template definitions of non-dependent
1595 expressions. NON_DEP is the non-dependent expression that has been
1599 build_min_non_dep (enum tree_code code
, tree non_dep
, ...)
1606 gcc_assert (TREE_CODE_CLASS (code
) != tcc_vl_exp
);
1608 va_start (p
, non_dep
);
1610 t
= make_node (code
);
1611 length
= TREE_CODE_LENGTH (code
);
1612 TREE_TYPE (t
) = TREE_TYPE (non_dep
);
1613 TREE_SIDE_EFFECTS (t
) = TREE_SIDE_EFFECTS (non_dep
);
1615 for (i
= 0; i
< length
; i
++)
1617 tree x
= va_arg (p
, tree
);
1618 TREE_OPERAND (t
, i
) = x
;
1621 if (code
== COMPOUND_EXPR
&& TREE_CODE (non_dep
) != COMPOUND_EXPR
)
1622 /* This should not be considered a COMPOUND_EXPR, because it
1623 resolves to an overload. */
1624 COMPOUND_EXPR_OVERLOADED (t
) = 1;
1630 /* Similar to `build_call_list', but for template definitions of non-dependent
1631 expressions. NON_DEP is the non-dependent expression that has been
1635 build_min_non_dep_call_list (tree non_dep
, tree fn
, tree arglist
)
1637 tree t
= build_nt_call_list (fn
, arglist
);
1638 TREE_TYPE (t
) = TREE_TYPE (non_dep
);
1639 TREE_SIDE_EFFECTS (t
) = TREE_SIDE_EFFECTS (non_dep
);
1644 get_type_decl (tree t
)
1646 if (TREE_CODE (t
) == TYPE_DECL
)
1649 return TYPE_STUB_DECL (t
);
1650 gcc_assert (t
== error_mark_node
);
1654 /* Returns the namespace that contains DECL, whether directly or
1658 decl_namespace_context (tree decl
)
1662 if (TREE_CODE (decl
) == NAMESPACE_DECL
)
1664 else if (TYPE_P (decl
))
1665 decl
= CP_DECL_CONTEXT (TYPE_MAIN_DECL (decl
));
1667 decl
= CP_DECL_CONTEXT (decl
);
1671 /* Returns true if decl is within an anonymous namespace, however deeply
1672 nested, or false otherwise. */
1675 decl_anon_ns_mem_p (tree decl
)
1679 if (decl
== NULL_TREE
|| decl
== error_mark_node
)
1681 if (TREE_CODE (decl
) == NAMESPACE_DECL
1682 && DECL_NAME (decl
) == NULL_TREE
)
1684 /* Classes and namespaces inside anonymous namespaces have
1685 TREE_PUBLIC == 0, so we can shortcut the search. */
1686 else if (TYPE_P (decl
))
1687 return (TREE_PUBLIC (TYPE_NAME (decl
)) == 0);
1688 else if (TREE_CODE (decl
) == NAMESPACE_DECL
)
1689 return (TREE_PUBLIC (decl
) == 0);
1691 decl
= DECL_CONTEXT (decl
);
1695 /* Return truthvalue of whether T1 is the same tree structure as T2.
1696 Return 1 if they are the same. Return 0 if they are different. */
1699 cp_tree_equal (tree t1
, tree t2
)
1701 enum tree_code code1
, code2
;
1708 for (code1
= TREE_CODE (t1
);
1709 code1
== NOP_EXPR
|| code1
== CONVERT_EXPR
1710 || code1
== NON_LVALUE_EXPR
;
1711 code1
= TREE_CODE (t1
))
1712 t1
= TREE_OPERAND (t1
, 0);
1713 for (code2
= TREE_CODE (t2
);
1714 code2
== NOP_EXPR
|| code2
== CONVERT_EXPR
1715 || code1
== NON_LVALUE_EXPR
;
1716 code2
= TREE_CODE (t2
))
1717 t2
= TREE_OPERAND (t2
, 0);
1719 /* They might have become equal now. */
1729 return TREE_INT_CST_LOW (t1
) == TREE_INT_CST_LOW (t2
)
1730 && TREE_INT_CST_HIGH (t1
) == TREE_INT_CST_HIGH (t2
);
1733 return REAL_VALUES_EQUAL (TREE_REAL_CST (t1
), TREE_REAL_CST (t2
));
1736 return TREE_STRING_LENGTH (t1
) == TREE_STRING_LENGTH (t2
)
1737 && !memcmp (TREE_STRING_POINTER (t1
), TREE_STRING_POINTER (t2
),
1738 TREE_STRING_LENGTH (t1
));
1741 return cp_tree_equal (TREE_REALPART (t1
), TREE_REALPART (t2
))
1742 && cp_tree_equal (TREE_IMAGPART (t1
), TREE_IMAGPART (t2
));
1745 /* We need to do this when determining whether or not two
1746 non-type pointer to member function template arguments
1748 if (!(same_type_p (TREE_TYPE (t1
), TREE_TYPE (t2
))
1749 /* The first operand is RTL. */
1750 && TREE_OPERAND (t1
, 0) == TREE_OPERAND (t2
, 0)))
1752 return cp_tree_equal (TREE_OPERAND (t1
, 1), TREE_OPERAND (t2
, 1));
1755 if (!cp_tree_equal (TREE_PURPOSE (t1
), TREE_PURPOSE (t2
)))
1757 if (!cp_tree_equal (TREE_VALUE (t1
), TREE_VALUE (t2
)))
1759 return cp_tree_equal (TREE_CHAIN (t1
), TREE_CHAIN (t2
));
1762 return cp_tree_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
1767 call_expr_arg_iterator iter1
, iter2
;
1768 if (!cp_tree_equal (CALL_EXPR_FN (t1
), CALL_EXPR_FN (t2
)))
1770 for (arg1
= first_call_expr_arg (t1
, &iter1
),
1771 arg2
= first_call_expr_arg (t2
, &iter2
);
1773 arg1
= next_call_expr_arg (&iter1
),
1774 arg2
= next_call_expr_arg (&iter2
))
1775 if (!cp_tree_equal (arg1
, arg2
))
1777 return (arg1
|| arg2
);
1782 tree o1
= TREE_OPERAND (t1
, 0);
1783 tree o2
= TREE_OPERAND (t2
, 0);
1785 /* Special case: if either target is an unallocated VAR_DECL,
1786 it means that it's going to be unified with whatever the
1787 TARGET_EXPR is really supposed to initialize, so treat it
1788 as being equivalent to anything. */
1789 if (TREE_CODE (o1
) == VAR_DECL
&& DECL_NAME (o1
) == NULL_TREE
1790 && !DECL_RTL_SET_P (o1
))
1792 else if (TREE_CODE (o2
) == VAR_DECL
&& DECL_NAME (o2
) == NULL_TREE
1793 && !DECL_RTL_SET_P (o2
))
1795 else if (!cp_tree_equal (o1
, o2
))
1798 return cp_tree_equal (TREE_OPERAND (t1
, 1), TREE_OPERAND (t2
, 1));
1801 case WITH_CLEANUP_EXPR
:
1802 if (!cp_tree_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0)))
1804 return cp_tree_equal (TREE_OPERAND (t1
, 1), TREE_OPERAND (t1
, 1));
1807 if (TREE_OPERAND (t1
, 1) != TREE_OPERAND (t2
, 1))
1809 return cp_tree_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
1816 case IDENTIFIER_NODE
:
1821 return (BASELINK_BINFO (t1
) == BASELINK_BINFO (t2
)
1822 && BASELINK_ACCESS_BINFO (t1
) == BASELINK_ACCESS_BINFO (t2
)
1823 && cp_tree_equal (BASELINK_FUNCTIONS (t1
),
1824 BASELINK_FUNCTIONS (t2
)));
1826 case TEMPLATE_PARM_INDEX
:
1827 return (TEMPLATE_PARM_IDX (t1
) == TEMPLATE_PARM_IDX (t2
)
1828 && TEMPLATE_PARM_LEVEL (t1
) == TEMPLATE_PARM_LEVEL (t2
)
1829 && same_type_p (TREE_TYPE (TEMPLATE_PARM_DECL (t1
)),
1830 TREE_TYPE (TEMPLATE_PARM_DECL (t2
))));
1832 case TEMPLATE_ID_EXPR
:
1837 if (!cp_tree_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0)))
1839 vec1
= TREE_OPERAND (t1
, 1);
1840 vec2
= TREE_OPERAND (t2
, 1);
1843 return !vec1
&& !vec2
;
1845 if (TREE_VEC_LENGTH (vec1
) != TREE_VEC_LENGTH (vec2
))
1848 for (ix
= TREE_VEC_LENGTH (vec1
); ix
--;)
1849 if (!cp_tree_equal (TREE_VEC_ELT (vec1
, ix
),
1850 TREE_VEC_ELT (vec2
, ix
)))
1859 tree o1
= TREE_OPERAND (t1
, 0);
1860 tree o2
= TREE_OPERAND (t2
, 0);
1862 if (TREE_CODE (o1
) != TREE_CODE (o2
))
1865 return same_type_p (o1
, o2
);
1867 return cp_tree_equal (o1
, o2
);
1872 tree t1_op1
, t2_op1
;
1874 if (!cp_tree_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0)))
1877 t1_op1
= TREE_OPERAND (t1
, 1);
1878 t2_op1
= TREE_OPERAND (t2
, 1);
1879 if (TREE_CODE (t1_op1
) != TREE_CODE (t2_op1
))
1882 return cp_tree_equal (TREE_OPERAND (t1
, 2), TREE_OPERAND (t2
, 2));
1886 /* Two pointer-to-members are the same if they point to the same
1887 field or function in the same class. */
1888 if (PTRMEM_CST_MEMBER (t1
) != PTRMEM_CST_MEMBER (t2
))
1891 return same_type_p (PTRMEM_CST_CLASS (t1
), PTRMEM_CST_CLASS (t2
));
1894 if (OVL_FUNCTION (t1
) != OVL_FUNCTION (t2
))
1896 return cp_tree_equal (OVL_CHAIN (t1
), OVL_CHAIN (t2
));
1899 if (TRAIT_EXPR_KIND (t1
) != TRAIT_EXPR_KIND (t2
))
1901 return same_type_p (TRAIT_EXPR_TYPE1 (t1
), TRAIT_EXPR_TYPE1 (t2
))
1902 && same_type_p (TRAIT_EXPR_TYPE2 (t1
), TRAIT_EXPR_TYPE2 (t2
));
1908 switch (TREE_CODE_CLASS (code1
))
1912 case tcc_comparison
:
1913 case tcc_expression
:
1920 n
= TREE_OPERAND_LENGTH (t1
);
1921 if (TREE_CODE_CLASS (code1
) == tcc_vl_exp
1922 && n
!= TREE_OPERAND_LENGTH (t2
))
1925 for (i
= 0; i
< n
; ++i
)
1926 if (!cp_tree_equal (TREE_OPERAND (t1
, i
), TREE_OPERAND (t2
, i
)))
1933 return same_type_p (t1
, t2
);
1937 /* We can get here with --disable-checking. */
1941 /* The type of ARG when used as an lvalue. */
1944 lvalue_type (tree arg
)
1946 tree type
= TREE_TYPE (arg
);
1950 /* The type of ARG for printing error messages; denote lvalues with
1954 error_type (tree arg
)
1956 tree type
= TREE_TYPE (arg
);
1958 if (TREE_CODE (type
) == ARRAY_TYPE
)
1960 else if (TREE_CODE (type
) == ERROR_MARK
)
1962 else if (real_lvalue_p (arg
))
1963 type
= build_reference_type (lvalue_type (arg
));
1964 else if (IS_AGGR_TYPE (type
))
1965 type
= lvalue_type (arg
);
1970 /* Does FUNCTION use a variable-length argument list? */
1973 varargs_function_p (tree function
)
1975 tree parm
= TYPE_ARG_TYPES (TREE_TYPE (function
));
1976 for (; parm
; parm
= TREE_CHAIN (parm
))
1977 if (TREE_VALUE (parm
) == void_type_node
)
1982 /* Returns 1 if decl is a member of a class. */
1985 member_p (tree decl
)
1987 const tree ctx
= DECL_CONTEXT (decl
);
1988 return (ctx
&& TYPE_P (ctx
));
1991 /* Create a placeholder for member access where we don't actually have an
1992 object that the access is against. */
1995 build_dummy_object (tree type
)
1997 tree decl
= build1 (NOP_EXPR
, build_pointer_type (type
), void_zero_node
);
1998 return build_indirect_ref (decl
, NULL
);
2001 /* We've gotten a reference to a member of TYPE. Return *this if appropriate,
2002 or a dummy object otherwise. If BINFOP is non-0, it is filled with the
2003 binfo path from current_class_type to TYPE, or 0. */
2006 maybe_dummy_object (tree type
, tree
* binfop
)
2011 if (current_class_type
2012 && (binfo
= lookup_base (current_class_type
, type
,
2013 ba_unique
| ba_quiet
, NULL
)))
2014 context
= current_class_type
;
2017 /* Reference from a nested class member function. */
2019 binfo
= TYPE_BINFO (type
);
2025 if (current_class_ref
&& context
== current_class_type
2026 /* Kludge: Make sure that current_class_type is actually
2027 correct. It might not be if we're in the middle of
2028 tsubst_default_argument. */
2029 && same_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (current_class_ref
)),
2030 current_class_type
))
2031 decl
= current_class_ref
;
2033 decl
= build_dummy_object (context
);
2038 /* Returns 1 if OB is a placeholder object, or a pointer to one. */
2041 is_dummy_object (tree ob
)
2043 if (TREE_CODE (ob
) == INDIRECT_REF
)
2044 ob
= TREE_OPERAND (ob
, 0);
2045 return (TREE_CODE (ob
) == NOP_EXPR
2046 && TREE_OPERAND (ob
, 0) == void_zero_node
);
2049 /* Returns 1 iff type T is a POD type, as defined in [basic.types]. */
2054 t
= strip_array_types (t
);
2056 if (t
== error_mark_node
)
2058 if (INTEGRAL_TYPE_P (t
))
2059 return 1; /* integral, character or enumeral type */
2060 if (FLOAT_TYPE_P (t
))
2063 return 1; /* pointer to non-member */
2064 if (TYPE_PTR_TO_MEMBER_P (t
))
2065 return 1; /* pointer to member */
2067 if (TREE_CODE (t
) == VECTOR_TYPE
)
2068 return 1; /* vectors are (small) arrays of scalars */
2070 if (! CLASS_TYPE_P (t
))
2071 return 0; /* other non-class type (reference or function) */
2072 if (CLASSTYPE_NON_POD_P (t
))
2077 /* Nonzero iff type T is a class template implicit specialization. */
2080 class_tmpl_impl_spec_p (tree t
)
2082 return CLASS_TYPE_P (t
) && CLASSTYPE_TEMPLATE_INSTANTIATION (t
);
2085 /* Returns 1 iff zero initialization of type T means actually storing
2089 zero_init_p (tree t
)
2091 t
= strip_array_types (t
);
2093 if (t
== error_mark_node
)
2096 /* NULL pointers to data members are initialized with -1. */
2097 if (TYPE_PTRMEM_P (t
))
2100 /* Classes that contain types that can't be zero-initialized, cannot
2101 be zero-initialized themselves. */
2102 if (CLASS_TYPE_P (t
) && CLASSTYPE_NON_ZERO_INIT_P (t
))
2108 /* Table of valid C++ attributes. */
2109 const struct attribute_spec cxx_attribute_table
[] =
2111 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
2112 { "java_interface", 0, 0, false, false, false, handle_java_interface_attribute
},
2113 { "com_interface", 0, 0, false, false, false, handle_com_interface_attribute
},
2114 { "init_priority", 1, 1, true, false, false, handle_init_priority_attribute
},
2115 { NULL
, 0, 0, false, false, false, NULL
}
2118 /* Handle a "java_interface" attribute; arguments as in
2119 struct attribute_spec.handler. */
2121 handle_java_interface_attribute (tree
* node
,
2123 tree args ATTRIBUTE_UNUSED
,
2128 || !CLASS_TYPE_P (*node
)
2129 || !TYPE_FOR_JAVA (*node
))
2131 error ("%qE attribute can only be applied to Java class definitions",
2133 *no_add_attrs
= true;
2136 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
2137 *node
= build_variant_type_copy (*node
);
2138 TYPE_JAVA_INTERFACE (*node
) = 1;
2143 /* Handle a "com_interface" attribute; arguments as in
2144 struct attribute_spec.handler. */
2146 handle_com_interface_attribute (tree
* node
,
2148 tree args ATTRIBUTE_UNUSED
,
2149 int flags ATTRIBUTE_UNUSED
,
2154 *no_add_attrs
= true;
2157 || !CLASS_TYPE_P (*node
)
2158 || *node
!= TYPE_MAIN_VARIANT (*node
))
2160 warning (OPT_Wattributes
, "%qE attribute can only be applied "
2161 "to class definitions", name
);
2166 warning (0, "%qE is obsolete; g++ vtables are now COM-compatible by default",
2172 /* Handle an "init_priority" attribute; arguments as in
2173 struct attribute_spec.handler. */
2175 handle_init_priority_attribute (tree
* node
,
2178 int flags ATTRIBUTE_UNUSED
,
2181 tree initp_expr
= TREE_VALUE (args
);
2183 tree type
= TREE_TYPE (decl
);
2186 STRIP_NOPS (initp_expr
);
2188 if (!initp_expr
|| TREE_CODE (initp_expr
) != INTEGER_CST
)
2190 error ("requested init_priority is not an integer constant");
2191 *no_add_attrs
= true;
2195 pri
= TREE_INT_CST_LOW (initp_expr
);
2197 type
= strip_array_types (type
);
2199 if (decl
== NULL_TREE
2200 || TREE_CODE (decl
) != VAR_DECL
2201 || !TREE_STATIC (decl
)
2202 || DECL_EXTERNAL (decl
)
2203 || (TREE_CODE (type
) != RECORD_TYPE
2204 && TREE_CODE (type
) != UNION_TYPE
)
2205 /* Static objects in functions are initialized the
2206 first time control passes through that
2207 function. This is not precise enough to pin down an
2208 init_priority value, so don't allow it. */
2209 || current_function_decl
)
2211 error ("can only use %qE attribute on file-scope definitions "
2212 "of objects of class type", name
);
2213 *no_add_attrs
= true;
2217 if (pri
> MAX_INIT_PRIORITY
|| pri
<= 0)
2219 error ("requested init_priority is out of range");
2220 *no_add_attrs
= true;
2224 /* Check for init_priorities that are reserved for
2225 language and runtime support implementations.*/
2226 if (pri
<= MAX_RESERVED_INIT_PRIORITY
)
2229 (0, "requested init_priority is reserved for internal use");
2232 if (SUPPORTS_INIT_PRIORITY
)
2234 SET_DECL_INIT_PRIORITY (decl
, pri
);
2235 DECL_HAS_INIT_PRIORITY_P (decl
) = 1;
2240 error ("%qE attribute is not supported on this platform", name
);
2241 *no_add_attrs
= true;
2246 /* Return a new PTRMEM_CST of the indicated TYPE. The MEMBER is the
2247 thing pointed to by the constant. */
2250 make_ptrmem_cst (tree type
, tree member
)
2252 tree ptrmem_cst
= make_node (PTRMEM_CST
);
2253 TREE_TYPE (ptrmem_cst
) = type
;
2254 PTRMEM_CST_MEMBER (ptrmem_cst
) = member
;
2258 /* Build a variant of TYPE that has the indicated ATTRIBUTES. May
2259 return an existing type of an appropriate type already exists. */
2262 cp_build_type_attribute_variant (tree type
, tree attributes
)
2266 new_type
= build_type_attribute_variant (type
, attributes
);
2267 if (TREE_CODE (new_type
) == FUNCTION_TYPE
2268 && (TYPE_RAISES_EXCEPTIONS (new_type
)
2269 != TYPE_RAISES_EXCEPTIONS (type
)))
2270 new_type
= build_exception_variant (new_type
,
2271 TYPE_RAISES_EXCEPTIONS (type
));
2273 /* Making a new main variant of a class type is broken. */
2274 gcc_assert (!CLASS_TYPE_P (type
) || new_type
== type
);
2279 /* Apply FUNC to all language-specific sub-trees of TP in a pre-order
2280 traversal. Called from walk_tree. */
2283 cp_walk_subtrees (tree
*tp
, int *walk_subtrees_p
, walk_tree_fn func
,
2284 void *data
, struct pointer_set_t
*pset
)
2286 enum tree_code code
= TREE_CODE (*tp
);
2289 #define WALK_SUBTREE(NODE) \
2292 result = walk_tree (&(NODE), func, data, pset); \
2293 if (result) goto out; \
2297 /* Not one of the easy cases. We must explicitly go through the
2303 case TEMPLATE_TEMPLATE_PARM
:
2304 case BOUND_TEMPLATE_TEMPLATE_PARM
:
2305 case UNBOUND_CLASS_TEMPLATE
:
2306 case TEMPLATE_PARM_INDEX
:
2307 case TEMPLATE_TYPE_PARM
:
2310 /* None of these have subtrees other than those already walked
2312 *walk_subtrees_p
= 0;
2316 WALK_SUBTREE (BASELINK_FUNCTIONS (*tp
));
2317 *walk_subtrees_p
= 0;
2321 WALK_SUBTREE (TINST_DECL (*tp
));
2322 *walk_subtrees_p
= 0;
2326 WALK_SUBTREE (TREE_TYPE (*tp
));
2327 *walk_subtrees_p
= 0;
2331 WALK_SUBTREE (TREE_PURPOSE (*tp
));
2335 WALK_SUBTREE (OVL_FUNCTION (*tp
));
2336 WALK_SUBTREE (OVL_CHAIN (*tp
));
2337 *walk_subtrees_p
= 0;
2341 if (TYPE_PTRMEMFUNC_P (*tp
))
2342 WALK_SUBTREE (TYPE_PTRMEMFUNC_FN_TYPE (*tp
));
2345 case TYPE_ARGUMENT_PACK
:
2346 case NONTYPE_ARGUMENT_PACK
:
2348 tree args
= ARGUMENT_PACK_ARGS (*tp
);
2349 int i
, len
= TREE_VEC_LENGTH (args
);
2350 for (i
= 0; i
< len
; i
++)
2351 WALK_SUBTREE (TREE_VEC_ELT (args
, i
));
2355 case TYPE_PACK_EXPANSION
:
2356 WALK_SUBTREE (TREE_TYPE (*tp
));
2357 *walk_subtrees_p
= 0;
2360 case EXPR_PACK_EXPANSION
:
2361 WALK_SUBTREE (TREE_OPERAND (*tp
, 0));
2362 *walk_subtrees_p
= 0;
2366 if (TREE_TYPE (*tp
))
2367 WALK_SUBTREE (TREE_TYPE (*tp
));
2371 for (i
= 0; i
< TREE_CODE_LENGTH (TREE_CODE (*tp
)); ++i
)
2372 WALK_SUBTREE (TREE_OPERAND (*tp
, i
));
2374 *walk_subtrees_p
= 0;
2378 WALK_SUBTREE (TRAIT_EXPR_TYPE1 (*tp
));
2379 WALK_SUBTREE (TRAIT_EXPR_TYPE2 (*tp
));
2380 *walk_subtrees_p
= 0;
2384 WALK_SUBTREE (DECLTYPE_TYPE_EXPR (*tp
));
2385 *walk_subtrees_p
= 0;
2393 /* We didn't find what we were looking for. */
2400 /* Decide whether there are language-specific reasons to not inline a
2401 function as a tree. */
2404 cp_cannot_inline_tree_fn (tree
* fnp
)
2408 /* We can inline a template instantiation only if it's fully
2410 if (DECL_TEMPLATE_INFO (fn
)
2411 && TI_PENDING_TEMPLATE_FLAG (DECL_TEMPLATE_INFO (fn
)))
2413 /* Don't instantiate functions that are not going to be
2415 if (!DECL_INLINE (DECL_TEMPLATE_RESULT
2416 (template_for_substitution (fn
))))
2419 fn
= *fnp
= instantiate_decl (fn
, /*defer_ok=*/0, /*undefined_ok=*/0);
2421 if (TI_PENDING_TEMPLATE_FLAG (DECL_TEMPLATE_INFO (fn
)))
2425 if (flag_really_no_inline
2426 && lookup_attribute ("always_inline", DECL_ATTRIBUTES (fn
)) == NULL
)
2429 /* Don't auto-inline functions that might be replaced at link-time
2430 with an alternative definition. */
2431 if (!DECL_DECLARED_INLINE_P (fn
) && DECL_REPLACEABLE_P (fn
))
2433 DECL_UNINLINABLE (fn
) = 1;
2437 if (varargs_function_p (fn
))
2439 DECL_UNINLINABLE (fn
) = 1;
2443 if (! function_attribute_inlinable_p (fn
))
2445 DECL_UNINLINABLE (fn
) = 1;
2452 /* Determine whether VAR is a declaration of an automatic variable in
2456 cp_auto_var_in_fn_p (tree var
, tree fn
)
2458 return (DECL_P (var
) && DECL_CONTEXT (var
) == fn
2459 && nonstatic_local_decl_p (var
));
2462 /* Like save_expr, but for C++. */
2465 cp_save_expr (tree expr
)
2467 /* There is no reason to create a SAVE_EXPR within a template; if
2468 needed, we can create the SAVE_EXPR when instantiating the
2469 template. Furthermore, the middle-end cannot handle C++-specific
2471 if (processing_template_decl
)
2473 return save_expr (expr
);
2476 /* Initialize tree.c. */
2481 list_hash_table
= htab_create_ggc (31, list_hash
, list_hash_eq
, NULL
);
2484 /* Returns the kind of special function that DECL (a FUNCTION_DECL)
2485 is. Note that sfk_none is zero, so this function can be used as a
2486 predicate to test whether or not DECL is a special function. */
2488 special_function_kind
2489 special_function_p (tree decl
)
2491 /* Rather than doing all this stuff with magic names, we should
2492 probably have a field of type `special_function_kind' in
2493 DECL_LANG_SPECIFIC. */
2494 if (DECL_COPY_CONSTRUCTOR_P (decl
))
2495 return sfk_copy_constructor
;
2496 if (DECL_CONSTRUCTOR_P (decl
))
2497 return sfk_constructor
;
2498 if (DECL_OVERLOADED_OPERATOR_P (decl
) == NOP_EXPR
)
2499 return sfk_assignment_operator
;
2500 if (DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (decl
))
2501 return sfk_destructor
;
2502 if (DECL_COMPLETE_DESTRUCTOR_P (decl
))
2503 return sfk_complete_destructor
;
2504 if (DECL_BASE_DESTRUCTOR_P (decl
))
2505 return sfk_base_destructor
;
2506 if (DECL_DELETING_DESTRUCTOR_P (decl
))
2507 return sfk_deleting_destructor
;
2508 if (DECL_CONV_FN_P (decl
))
2509 return sfk_conversion
;
2514 /* Returns nonzero if TYPE is a character type, including wchar_t. */
2517 char_type_p (tree type
)
2519 return (same_type_p (type
, char_type_node
)
2520 || same_type_p (type
, unsigned_char_type_node
)
2521 || same_type_p (type
, signed_char_type_node
)
2522 || same_type_p (type
, wchar_type_node
));
2525 /* Returns the kind of linkage associated with the indicated DECL. Th
2526 value returned is as specified by the language standard; it is
2527 independent of implementation details regarding template
2528 instantiation, etc. For example, it is possible that a declaration
2529 to which this function assigns external linkage would not show up
2530 as a global symbol when you run `nm' on the resulting object file. */
2533 decl_linkage (tree decl
)
2535 /* This function doesn't attempt to calculate the linkage from first
2536 principles as given in [basic.link]. Instead, it makes use of
2537 the fact that we have already set TREE_PUBLIC appropriately, and
2538 then handles a few special cases. Ideally, we would calculate
2539 linkage first, and then transform that into a concrete
2542 /* Things that don't have names have no linkage. */
2543 if (!DECL_NAME (decl
))
2546 /* Things that are TREE_PUBLIC have external linkage. */
2547 if (TREE_PUBLIC (decl
))
2550 if (TREE_CODE (decl
) == NAMESPACE_DECL
)
2553 /* Linkage of a CONST_DECL depends on the linkage of the enumeration
2555 if (TREE_CODE (decl
) == CONST_DECL
)
2556 return decl_linkage (TYPE_NAME (TREE_TYPE (decl
)));
2558 /* Some things that are not TREE_PUBLIC have external linkage, too.
2559 For example, on targets that don't have weak symbols, we make all
2560 template instantiations have internal linkage (in the object
2561 file), but the symbols should still be treated as having external
2562 linkage from the point of view of the language. */
2563 if (TREE_CODE (decl
) != TYPE_DECL
&& DECL_LANG_SPECIFIC (decl
)
2564 && DECL_COMDAT (decl
))
2567 /* Things in local scope do not have linkage, if they don't have
2569 if (decl_function_context (decl
))
2572 /* Members of the anonymous namespace also have TREE_PUBLIC unset, but
2573 are considered to have external linkage for language purposes. DECLs
2574 really meant to have internal linkage have DECL_THIS_STATIC set. */
2575 if (TREE_CODE (decl
) == TYPE_DECL
2576 || ((TREE_CODE (decl
) == VAR_DECL
|| TREE_CODE (decl
) == FUNCTION_DECL
)
2577 && !DECL_THIS_STATIC (decl
)))
2580 /* Everything else has internal linkage. */
2584 /* EXP is an expression that we want to pre-evaluate. Returns (in
2585 *INITP) an expression that will perform the pre-evaluation. The
2586 value returned by this function is a side-effect free expression
2587 equivalent to the pre-evaluated expression. Callers must ensure
2588 that *INITP is evaluated before EXP. */
2591 stabilize_expr (tree exp
, tree
* initp
)
2595 if (!TREE_SIDE_EFFECTS (exp
))
2596 init_expr
= NULL_TREE
;
2597 else if (!real_lvalue_p (exp
)
2598 || !TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (exp
)))
2600 init_expr
= get_target_expr (exp
);
2601 exp
= TARGET_EXPR_SLOT (init_expr
);
2605 exp
= build_unary_op (ADDR_EXPR
, exp
, 1);
2606 init_expr
= get_target_expr (exp
);
2607 exp
= TARGET_EXPR_SLOT (init_expr
);
2608 exp
= build_indirect_ref (exp
, 0);
2612 gcc_assert (!TREE_SIDE_EFFECTS (exp
));
2616 /* Add NEW, an expression whose value we don't care about, after the
2617 similar expression ORIG. */
2620 add_stmt_to_compound (tree orig
, tree
new)
2622 if (!new || !TREE_SIDE_EFFECTS (new))
2624 if (!orig
|| !TREE_SIDE_EFFECTS (orig
))
2626 return build2 (COMPOUND_EXPR
, void_type_node
, orig
, new);
2629 /* Like stabilize_expr, but for a call whose arguments we want to
2630 pre-evaluate. CALL is modified in place to use the pre-evaluated
2631 arguments, while, upon return, *INITP contains an expression to
2632 compute the arguments. */
2635 stabilize_call (tree call
, tree
*initp
)
2637 tree inits
= NULL_TREE
;
2639 int nargs
= call_expr_nargs (call
);
2641 if (call
== error_mark_node
)
2644 gcc_assert (TREE_CODE (call
) == CALL_EXPR
);
2646 for (i
= 0; i
< nargs
; i
++)
2649 CALL_EXPR_ARG (call
, i
) =
2650 stabilize_expr (CALL_EXPR_ARG (call
, i
), &init
);
2651 inits
= add_stmt_to_compound (inits
, init
);
2657 /* Like stabilize_expr, but for an AGGR_INIT_EXPR whose arguments we want
2658 to pre-evaluate. CALL is modified in place to use the pre-evaluated
2659 arguments, while, upon return, *INITP contains an expression to
2660 compute the arguments. */
2663 stabilize_aggr_init (tree call
, tree
*initp
)
2665 tree inits
= NULL_TREE
;
2667 int nargs
= aggr_init_expr_nargs (call
);
2669 if (call
== error_mark_node
)
2672 gcc_assert (TREE_CODE (call
) == AGGR_INIT_EXPR
);
2674 for (i
= 0; i
< nargs
; i
++)
2677 AGGR_INIT_EXPR_ARG (call
, i
) =
2678 stabilize_expr (AGGR_INIT_EXPR_ARG (call
, i
), &init
);
2679 inits
= add_stmt_to_compound (inits
, init
);
2685 /* Like stabilize_expr, but for an initialization.
2687 If the initialization is for an object of class type, this function
2688 takes care not to introduce additional temporaries.
2690 Returns TRUE iff the expression was successfully pre-evaluated,
2691 i.e., if INIT is now side-effect free, except for, possible, a
2692 single call to a constructor. */
2695 stabilize_init (tree init
, tree
*initp
)
2701 if (t
== error_mark_node
)
2704 if (TREE_CODE (t
) == INIT_EXPR
2705 && TREE_CODE (TREE_OPERAND (t
, 1)) != TARGET_EXPR
)
2707 TREE_OPERAND (t
, 1) = stabilize_expr (TREE_OPERAND (t
, 1), initp
);
2711 if (TREE_CODE (t
) == INIT_EXPR
)
2712 t
= TREE_OPERAND (t
, 1);
2713 if (TREE_CODE (t
) == TARGET_EXPR
)
2714 t
= TARGET_EXPR_INITIAL (t
);
2715 if (TREE_CODE (t
) == COMPOUND_EXPR
)
2717 if (TREE_CODE (t
) == CONSTRUCTOR
2718 && EMPTY_CONSTRUCTOR_P (t
))
2719 /* Default-initialization. */
2722 /* If the initializer is a COND_EXPR, we can't preevaluate
2724 if (TREE_CODE (t
) == COND_EXPR
)
2727 if (TREE_CODE (t
) == CALL_EXPR
)
2729 stabilize_call (t
, initp
);
2733 if (TREE_CODE (t
) == AGGR_INIT_EXPR
)
2735 stabilize_aggr_init (t
, initp
);
2739 /* The initialization is being performed via a bitwise copy -- and
2740 the item copied may have side effects. */
2741 return TREE_SIDE_EFFECTS (init
);
2744 /* Like "fold", but should be used whenever we might be processing the
2745 body of a template. */
2748 fold_if_not_in_template (tree expr
)
2750 /* In the body of a template, there is never any need to call
2751 "fold". We will call fold later when actually instantiating the
2752 template. Integral constant expressions in templates will be
2753 evaluated via fold_non_dependent_expr, as necessary. */
2754 if (processing_template_decl
)
2757 /* Fold C++ front-end specific tree codes. */
2758 if (TREE_CODE (expr
) == UNARY_PLUS_EXPR
)
2759 return fold_convert (TREE_TYPE (expr
), TREE_OPERAND (expr
, 0));
2764 /* Returns true if a cast to TYPE may appear in an integral constant
2768 cast_valid_in_integral_constant_expression_p (tree type
)
2770 return (INTEGRAL_OR_ENUMERATION_TYPE_P (type
)
2771 || dependent_type_p (type
)
2772 || type
== error_mark_node
);
2776 #if defined ENABLE_TREE_CHECKING && (GCC_VERSION >= 2007)
2777 /* Complain that some language-specific thing hanging off a tree
2778 node has been accessed improperly. */
2781 lang_check_failed (const char* file
, int line
, const char* function
)
2783 internal_error ("lang_* check: failed in %s, at %s:%d",
2784 function
, trim_filename (file
), line
);
2786 #endif /* ENABLE_TREE_CHECKING */
2788 #include "gt-cp-tree.h"