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 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, 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
25 #include "coretypes.h"
33 #include "insn-config.h"
34 #include "integrate.h"
35 #include "tree-inline.h"
38 static tree bot_manip PARAMS ((tree *, int *, void *));
39 static tree bot_replace PARAMS ((tree *, int *, void *));
40 static tree build_cplus_array_type_1 PARAMS ((tree, tree));
41 static int list_hash_eq PARAMS ((const void *, const void *));
42 static hashval_t list_hash_pieces PARAMS ((tree, tree, tree));
43 static hashval_t list_hash PARAMS ((const void *));
44 static cp_lvalue_kind lvalue_p_1 PARAMS ((tree, int, int));
45 static tree no_linkage_helper PARAMS ((tree *, int *, void *));
46 static tree build_srcloc PARAMS ((const char *, int));
47 static tree mark_local_for_remap_r PARAMS ((tree *, int *, void *));
48 static tree cp_unsave_r PARAMS ((tree *, int *, void *));
49 static tree build_target_expr PARAMS ((tree, tree));
50 static tree count_trees_r PARAMS ((tree *, int *, void *));
51 static tree verify_stmt_tree_r PARAMS ((tree *, int *, void *));
52 static tree find_tree_r PARAMS ((tree *, int *, void *));
53 extern int cp_statement_code_p PARAMS ((enum tree_code));
55 static tree handle_java_interface_attribute PARAMS ((tree *, tree, tree, int, bool *));
56 static tree handle_com_interface_attribute PARAMS ((tree *, tree, tree, int, bool *));
57 static tree handle_init_priority_attribute PARAMS ((tree *, tree, tree, int, bool *));
59 /* If REF is an lvalue, returns the kind of lvalue that REF is.
60 Otherwise, returns clk_none. If TREAT_CLASS_RVALUES_AS_LVALUES is
61 nonzero, rvalues of class type are considered lvalues. */
64 lvalue_p_1 (ref, treat_class_rvalues_as_lvalues, allow_cast_as_lvalue)
66 int treat_class_rvalues_as_lvalues;
67 int allow_cast_as_lvalue;
69 cp_lvalue_kind op1_lvalue_kind = clk_none;
70 cp_lvalue_kind op2_lvalue_kind = clk_none;
72 if (TREE_CODE (TREE_TYPE (ref)) == REFERENCE_TYPE)
75 if (ref == current_class_ptr)
78 switch (TREE_CODE (ref))
80 /* preincrements and predecrements are valid lvals, provided
81 what they refer to are valid lvals. */
82 case PREINCREMENT_EXPR:
83 case PREDECREMENT_EXPR:
87 case WITH_CLEANUP_EXPR:
90 return lvalue_p_1 (TREE_OPERAND (ref, 0),
91 treat_class_rvalues_as_lvalues,
92 allow_cast_as_lvalue);
95 if (allow_cast_as_lvalue)
96 return lvalue_p_1 (TREE_OPERAND (ref, 0),
97 treat_class_rvalues_as_lvalues,
98 allow_cast_as_lvalue);
103 op1_lvalue_kind = lvalue_p_1 (TREE_OPERAND (ref, 0),
104 treat_class_rvalues_as_lvalues,
105 allow_cast_as_lvalue);
107 /* The "field" can be a FUNCTION_DECL or an OVERLOAD in some
109 && TREE_CODE (TREE_OPERAND (ref, 1)) == FIELD_DECL
110 && DECL_C_BIT_FIELD (TREE_OPERAND (ref, 1)))
112 /* Clear the ordinary bit. If this object was a class
113 rvalue we want to preserve that information. */
114 op1_lvalue_kind &= ~clk_ordinary;
115 /* The lvalue is for a btifield. */
116 op1_lvalue_kind |= clk_bitfield;
118 return op1_lvalue_kind;
124 if (TREE_READONLY (ref) && ! TREE_STATIC (ref)
125 && DECL_LANG_SPECIFIC (ref)
126 && DECL_IN_AGGR_P (ref))
132 if (TREE_CODE (TREE_TYPE (ref)) != METHOD_TYPE)
136 /* A currently unresolved scope ref. */
140 if (TREE_CODE (TREE_OPERAND (ref, 1)) == FUNCTION_DECL)
145 op1_lvalue_kind = lvalue_p_1 (TREE_OPERAND (ref, 0),
146 treat_class_rvalues_as_lvalues,
147 allow_cast_as_lvalue);
148 op2_lvalue_kind = lvalue_p_1 (TREE_OPERAND (ref, 1),
149 treat_class_rvalues_as_lvalues,
150 allow_cast_as_lvalue);
154 op1_lvalue_kind = lvalue_p_1 (TREE_OPERAND (ref, 1),
155 treat_class_rvalues_as_lvalues,
156 allow_cast_as_lvalue);
157 op2_lvalue_kind = lvalue_p_1 (TREE_OPERAND (ref, 2),
158 treat_class_rvalues_as_lvalues,
159 allow_cast_as_lvalue);
166 return lvalue_p_1 (TREE_OPERAND (ref, 1),
167 treat_class_rvalues_as_lvalues,
168 allow_cast_as_lvalue);
171 return treat_class_rvalues_as_lvalues ? clk_class : clk_none;
175 /* Any class-valued call would be wrapped in a TARGET_EXPR. */
179 /* All functions (except non-static-member functions) are
181 return (DECL_NONSTATIC_MEMBER_FUNCTION_P (ref)
182 ? clk_none : clk_ordinary);
188 /* If one operand is not an lvalue at all, then this expression is
190 if (!op1_lvalue_kind || !op2_lvalue_kind)
193 /* Otherwise, it's an lvalue, and it has all the odd properties
194 contributed by either operand. */
195 op1_lvalue_kind = op1_lvalue_kind | op2_lvalue_kind;
196 /* It's not an ordinary lvalue if it involves either a bit-field or
198 if ((op1_lvalue_kind & ~clk_ordinary) != clk_none)
199 op1_lvalue_kind &= ~clk_ordinary;
200 return op1_lvalue_kind;
203 /* If REF is an lvalue, returns the kind of lvalue that REF is.
204 Otherwise, returns clk_none. Lvalues can be assigned, unless they
205 have TREE_READONLY, or unless they are FUNCTION_DECLs. Lvalues can
206 have their address taken, unless they have DECL_REGISTER. */
212 return lvalue_p_1 (ref, /*treat_class_rvalues_as_lvalues=*/ 0, /*cast*/ 1);
215 /* This differs from real_lvalue_p in that class rvalues are
216 considered lvalues. */
223 (lvalue_p_1 (ref, /*class rvalue ok*/ 1, /*cast*/ 1) != clk_none);
227 non_cast_lvalue_p (ref)
231 (lvalue_p_1 (ref, /*class rvalue ok*/ 1, /*cast*/ 0) != clk_none);
234 /* Return nonzero if REF is an lvalue valid for this language;
235 otherwise, print an error message and return zero. */
238 lvalue_or_else (ref, string)
242 int ret = lvalue_p_1 (ref, /* class rvalue ok */ 1, /* cast ok */ 1);
243 int win = (ret != clk_none);
245 error ("non-lvalue in %s", string);
250 non_cast_lvalue_or_else (ref, string)
254 int ret = lvalue_p_1 (ref, /* class rvalue ok */ 1, /* cast ok */ 0);
255 int win = (ret != clk_none);
257 error ("non-lvalue in %s", string);
261 /* Build a TARGET_EXPR, initializing the DECL with the VALUE. */
264 build_target_expr (decl, value)
270 t = build (TARGET_EXPR, TREE_TYPE (decl), decl, value,
271 cxx_maybe_build_cleanup (decl), NULL_TREE);
272 /* We always set TREE_SIDE_EFFECTS so that expand_expr does not
273 ignore the TARGET_EXPR. If there really turn out to be no
274 side-effects, then the optimizer should be able to get rid of
275 whatever code is generated anyhow. */
276 TREE_SIDE_EFFECTS (t) = 1;
281 /* INIT is a CALL_EXPR which needs info about its target.
282 TYPE is the type that this initialization should appear to have.
284 Build an encapsulation of the initialization to perform
285 and return it so that it can be processed by language-independent
286 and language-specific expression expanders. */
289 build_cplus_new (type, init)
298 /* Make sure that we're not trying to create an instance of an
300 abstract_virtuals_error (NULL_TREE, type);
302 if (TREE_CODE (init) != CALL_EXPR && TREE_CODE (init) != AGGR_INIT_EXPR)
303 return convert (type, init);
305 fn = TREE_OPERAND (init, 0);
306 is_ctor = (TREE_CODE (fn) == ADDR_EXPR
307 && TREE_CODE (TREE_OPERAND (fn, 0)) == FUNCTION_DECL
308 && DECL_CONSTRUCTOR_P (TREE_OPERAND (fn, 0)));
310 slot = build (VAR_DECL, type);
311 DECL_ARTIFICIAL (slot) = 1;
312 DECL_CONTEXT (slot) = current_function_decl;
313 layout_decl (slot, 0);
315 /* We split the CALL_EXPR into its function and its arguments here.
316 Then, in expand_expr, we put them back together. The reason for
317 this is that this expression might be a default argument
318 expression. In that case, we need a new temporary every time the
319 expression is used. That's what break_out_target_exprs does; it
320 replaces every AGGR_INIT_EXPR with a copy that uses a fresh
321 temporary slot. Then, expand_expr builds up a call-expression
322 using the new slot. */
324 /* If we don't need to use a constructor to create an object of this
325 type, don't mess with AGGR_INIT_EXPR. */
326 if (is_ctor || TREE_ADDRESSABLE (type))
328 rval = build (AGGR_INIT_EXPR, type, fn, TREE_OPERAND (init, 1), slot);
329 TREE_SIDE_EFFECTS (rval) = 1;
330 AGGR_INIT_VIA_CTOR_P (rval) = is_ctor;
335 rval = build_target_expr (slot, rval);
340 /* Build a TARGET_EXPR using INIT to initialize a new temporary of the
344 build_target_expr_with_type (init, type)
351 if (TREE_CODE (init) == TARGET_EXPR)
354 slot = build (VAR_DECL, type);
355 DECL_ARTIFICIAL (slot) = 1;
356 DECL_CONTEXT (slot) = current_function_decl;
357 layout_decl (slot, 0);
358 rval = build_target_expr (slot, init);
363 /* Like build_target_expr_with_type, but use the type of INIT. */
366 get_target_expr (init)
369 return build_target_expr_with_type (init, TREE_TYPE (init));
372 /* Recursively perform a preorder search EXP for CALL_EXPRs, making
373 copies where they are found. Returns a deep copy all nodes transitively
374 containing CALL_EXPRs. */
377 break_out_calls (exp)
380 register tree t1, t2 = NULL_TREE;
381 register enum tree_code code;
382 register int changed = 0;
385 if (exp == NULL_TREE)
388 code = TREE_CODE (exp);
390 if (code == CALL_EXPR)
391 return copy_node (exp);
393 /* Don't try and defeat a save_expr, as it should only be done once. */
394 if (code == SAVE_EXPR)
397 switch (TREE_CODE_CLASS (code))
402 case 'c': /* a constant */
403 case 't': /* a type node */
404 case 'x': /* something random, like an identifier or an ERROR_MARK. */
407 case 'd': /* A decl node */
410 case 'b': /* A block node */
412 /* Don't know how to handle these correctly yet. Must do a
413 break_out_calls on all DECL_INITIAL values for local variables,
414 and also break_out_calls on all sub-blocks and sub-statements. */
419 case 'e': /* an expression */
420 case 'r': /* a reference */
421 case 's': /* an expression with side effects */
422 for (i = TREE_CODE_LENGTH (code) - 1; i >= 0; i--)
424 t1 = break_out_calls (TREE_OPERAND (exp, i));
425 if (t1 != TREE_OPERAND (exp, i))
427 exp = copy_node (exp);
428 TREE_OPERAND (exp, i) = t1;
433 case '<': /* a comparison expression */
434 case '2': /* a binary arithmetic expression */
435 t2 = break_out_calls (TREE_OPERAND (exp, 1));
436 if (t2 != TREE_OPERAND (exp, 1))
438 case '1': /* a unary arithmetic expression */
439 t1 = break_out_calls (TREE_OPERAND (exp, 0));
440 if (t1 != TREE_OPERAND (exp, 0))
444 if (TREE_CODE_LENGTH (code) == 1)
445 return build1 (code, TREE_TYPE (exp), t1);
447 return build (code, TREE_TYPE (exp), t1, t2);
454 /* Construct, lay out and return the type of methods belonging to class
455 BASETYPE and whose arguments are described by ARGTYPES and whose values
456 are described by RETTYPE. If each type exists already, reuse it. */
459 build_cplus_method_type (basetype, rettype, argtypes)
460 tree basetype, rettype, argtypes;
466 /* Make a node of the sort we want. */
467 t = make_node (METHOD_TYPE);
469 TYPE_METHOD_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype);
470 TREE_TYPE (t) = rettype;
471 ptype = build_pointer_type (basetype);
473 /* The actual arglist for this function includes a "hidden" argument
474 which is "this". Put it into the list of argument types. */
475 argtypes = tree_cons (NULL_TREE, ptype, argtypes);
476 TYPE_ARG_TYPES (t) = argtypes;
477 TREE_SIDE_EFFECTS (argtypes) = 1; /* Mark first argtype as "artificial". */
479 /* If we already have such a type, use the old one and free this one.
480 Note that it also frees up the above cons cell if found. */
481 hashcode = TYPE_HASH (basetype) + TYPE_HASH (rettype) +
482 type_hash_list (argtypes);
484 t = type_hash_canon (hashcode, t);
486 if (!COMPLETE_TYPE_P (t))
493 build_cplus_array_type_1 (elt_type, index_type)
499 if (elt_type == error_mark_node || index_type == error_mark_node)
500 return error_mark_node;
502 /* Don't do the minimal thing just because processing_template_decl is
503 set; we want to give string constants the right type immediately, so
504 we don't have to fix them up at instantiation time. */
505 if ((processing_template_decl
506 && index_type && TYPE_MAX_VALUE (index_type)
507 && TREE_CODE (TYPE_MAX_VALUE (index_type)) != INTEGER_CST)
508 || uses_template_parms (elt_type)
509 || uses_template_parms (index_type))
511 t = make_node (ARRAY_TYPE);
512 TREE_TYPE (t) = elt_type;
513 TYPE_DOMAIN (t) = index_type;
516 t = build_array_type (elt_type, index_type);
518 /* Push these needs up so that initialization takes place
520 TYPE_NEEDS_CONSTRUCTING (t)
521 = TYPE_NEEDS_CONSTRUCTING (TYPE_MAIN_VARIANT (elt_type));
522 TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)
523 = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TYPE_MAIN_VARIANT (elt_type));
528 build_cplus_array_type (elt_type, index_type)
533 int type_quals = cp_type_quals (elt_type);
534 int cv_quals = type_quals & (TYPE_QUAL_CONST|TYPE_QUAL_VOLATILE);
535 int other_quals = type_quals & ~(TYPE_QUAL_CONST|TYPE_QUAL_VOLATILE);
538 elt_type = cp_build_qualified_type (elt_type, other_quals);
540 t = build_cplus_array_type_1 (elt_type, index_type);
543 t = cp_build_qualified_type (t, cv_quals);
548 /* Make a variant of TYPE, qualified with the TYPE_QUALS. Handles
549 arrays correctly. In particular, if TYPE is an array of T's, and
550 TYPE_QUALS is non-empty, returns an array of qualified T's.
552 FLAGS determines how to deal with illformed qualifications. If
553 tf_ignore_bad_quals is set, then bad qualifications are dropped
554 (this is permitted if TYPE was introduced via a typedef or template
555 type parameter). If bad qualifications are dropped and tf_warning
556 is set, then a warning is issued for non-const qualifications. If
557 tf_ignore_bad_quals is not set and tf_error is not set, we
558 return error_mark_node. Otherwise, we issue an error, and ignore
561 Qualification of a reference type is valid when the reference came
562 via a typedef or template type argument. [dcl.ref] No such
563 dispensation is provided for qualifying a function type. [dcl.fct]
564 DR 295 queries this and the proposed resolution brings it into line
565 with qualifiying a reference. We implement the DR. We also behave
566 in a similar manner for restricting non-pointer types. */
569 cp_build_qualified_type_real (type, type_quals, complain)
572 tsubst_flags_t complain;
575 int bad_quals = TYPE_UNQUALIFIED;
576 /* We keep bad function qualifiers separate, so that we can decide
577 whether to implement DR 295 or not. DR 295 break existing code,
578 unfortunately. Remove this variable to implement the defect
580 int bad_func_quals = TYPE_UNQUALIFIED;
582 if (type == error_mark_node)
585 if (type_quals == cp_type_quals (type))
588 /* A reference, fucntion or method type shall not be cv qualified.
589 [dcl.ref], [dct.fct] */
590 if (type_quals & (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE)
591 && (TREE_CODE (type) == REFERENCE_TYPE
592 || TREE_CODE (type) == FUNCTION_TYPE
593 || TREE_CODE (type) == METHOD_TYPE))
595 bad_quals |= type_quals & (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE);
596 if (TREE_CODE (type) != REFERENCE_TYPE)
597 bad_func_quals |= type_quals & (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE);
598 type_quals &= ~(TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE);
601 /* A restrict-qualified type must be a pointer (or reference)
602 to object or incomplete type. */
603 if ((type_quals & TYPE_QUAL_RESTRICT)
604 && TREE_CODE (type) != TEMPLATE_TYPE_PARM
605 && TREE_CODE (type) != TYPENAME_TYPE
606 && !POINTER_TYPE_P (type))
608 bad_quals |= TYPE_QUAL_RESTRICT;
609 type_quals &= ~TYPE_QUAL_RESTRICT;
612 if (bad_quals == TYPE_UNQUALIFIED)
614 else if (!(complain & (tf_error | tf_ignore_bad_quals)))
615 return error_mark_node;
616 else if (bad_func_quals && !(complain & tf_error))
617 return error_mark_node;
620 if (complain & tf_ignore_bad_quals)
621 /* We're not going to warn about constifying things that can't
623 bad_quals &= ~TYPE_QUAL_CONST;
624 bad_quals |= bad_func_quals;
627 tree bad_type = build_qualified_type (ptr_type_node, bad_quals);
629 if (!(complain & tf_ignore_bad_quals)
631 error ("`%V' qualifiers cannot be applied to `%T'",
636 if (TREE_CODE (type) == ARRAY_TYPE)
638 /* In C++, the qualification really applies to the array element
639 type. Obtain the appropriately qualified element type. */
642 = cp_build_qualified_type_real (TREE_TYPE (type),
646 if (element_type == error_mark_node)
647 return error_mark_node;
649 /* See if we already have an identically qualified type. */
650 for (t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
651 if (cp_type_quals (t) == type_quals
652 && TYPE_NAME (t) == TYPE_NAME (type)
653 && TYPE_CONTEXT (t) == TYPE_CONTEXT (type))
658 /* Make a new array type, just like the old one, but with the
659 appropriately qualified element type. */
660 t = build_type_copy (type);
661 TREE_TYPE (t) = element_type;
664 /* Even if we already had this variant, we update
665 TYPE_NEEDS_CONSTRUCTING and TYPE_HAS_NONTRIVIAL_DESTRUCTOR in case
666 they changed since the variant was originally created.
668 This seems hokey; if there is some way to use a previous
669 variant *without* coming through here,
670 TYPE_NEEDS_CONSTRUCTING will never be updated. */
671 TYPE_NEEDS_CONSTRUCTING (t)
672 = TYPE_NEEDS_CONSTRUCTING (TYPE_MAIN_VARIANT (element_type));
673 TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)
674 = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TYPE_MAIN_VARIANT (element_type));
677 else if (TYPE_PTRMEMFUNC_P (type))
679 /* For a pointer-to-member type, we can't just return a
680 cv-qualified version of the RECORD_TYPE. If we do, we
681 haven't changed the field that contains the actual pointer to
682 a method, and so TYPE_PTRMEMFUNC_FN_TYPE will be wrong. */
685 t = TYPE_PTRMEMFUNC_FN_TYPE (type);
686 t = cp_build_qualified_type_real (t, type_quals, complain);
687 return build_ptrmemfunc_type (t);
690 /* Retrieve (or create) the appropriately qualified variant. */
691 result = build_qualified_type (type, type_quals);
693 /* If this was a pointer-to-method type, and we just made a copy,
694 then we need to unshare the record that holds the cached
695 pointer-to-member-function type, because these will be distinct
696 between the unqualified and qualified types. */
698 && TREE_CODE (type) == POINTER_TYPE
699 && TREE_CODE (TREE_TYPE (type)) == METHOD_TYPE)
700 TYPE_LANG_SPECIFIC (result) = NULL;
705 /* Returns the canonical version of TYPE. In other words, if TYPE is
706 a typedef, returns the underlying type. The cv-qualification of
707 the type returned matches the type input; they will always be
711 canonical_type_variant (t)
714 return cp_build_qualified_type (TYPE_MAIN_VARIANT (t), cp_type_quals (t));
717 /* Makes new binfos for the indirect bases under BINFO, and updates
718 BINFO_OFFSET for them and their bases. */
721 unshare_base_binfos (binfo)
724 tree binfos = BINFO_BASETYPES (binfo);
728 if (binfos == NULL_TREE)
731 /* Now unshare the structure beneath BINFO. */
732 for (j = TREE_VEC_LENGTH (binfos)-1;
735 tree base_binfo = TREE_VEC_ELT (binfos, j);
736 new_binfo = TREE_VEC_ELT (binfos, j)
737 = make_binfo (BINFO_OFFSET (base_binfo),
739 BINFO_VTABLE (base_binfo),
740 BINFO_VIRTUALS (base_binfo));
741 TREE_VIA_PUBLIC (new_binfo) = TREE_VIA_PUBLIC (base_binfo);
742 TREE_VIA_PROTECTED (new_binfo) = TREE_VIA_PROTECTED (base_binfo);
743 TREE_VIA_VIRTUAL (new_binfo) = TREE_VIA_VIRTUAL (base_binfo);
744 BINFO_INHERITANCE_CHAIN (new_binfo) = binfo;
745 BINFO_PRIMARY_BASE_OF (new_binfo) = NULL_TREE;
746 unshare_base_binfos (new_binfo);
751 /* Hashing of lists so that we don't make duplicates.
752 The entry point is `list_hash_canon'. */
754 /* Now here is the hash table. When recording a list, it is added
755 to the slot whose index is the hash code mod the table size.
756 Note that the hash table is used for several kinds of lists.
757 While all these live in the same table, they are completely independent,
758 and the hash code is computed differently for each of these. */
760 static GTY ((param_is (union tree_node))) htab_t list_hash_table;
769 /* Compare ENTRY (an entry in the hash table) with DATA (a list_proxy
770 for a node we are thinking about adding). */
773 list_hash_eq (entry, data)
777 tree t = (tree) entry;
778 struct list_proxy *proxy = (struct list_proxy *) data;
780 return (TREE_VALUE (t) == proxy->value
781 && TREE_PURPOSE (t) == proxy->purpose
782 && TREE_CHAIN (t) == proxy->chain);
785 /* Compute a hash code for a list (chain of TREE_LIST nodes
786 with goodies in the TREE_PURPOSE, TREE_VALUE, and bits of the
787 TREE_COMMON slots), by adding the hash codes of the individual entries. */
790 list_hash_pieces (purpose, value, chain)
795 hashval_t hashcode = 0;
798 hashcode += TYPE_HASH (chain);
801 hashcode += TYPE_HASH (value);
805 hashcode += TYPE_HASH (purpose);
811 /* Hash an already existing TREE_LIST. */
818 return list_hash_pieces (TREE_PURPOSE (t),
823 /* Given list components PURPOSE, VALUE, AND CHAIN, return the canonical
824 object for an identical list if one already exists. Otherwise, build a
825 new one, and record it as the canonical object. */
828 hash_tree_cons (purpose, value, chain)
829 tree purpose, value, chain;
833 struct list_proxy proxy;
835 /* Hash the list node. */
836 hashcode = list_hash_pieces (purpose, value, chain);
837 /* Create a proxy for the TREE_LIST we would like to create. We
838 don't actually create it so as to avoid creating garbage. */
839 proxy.purpose = purpose;
842 /* See if it is already in the table. */
843 slot = htab_find_slot_with_hash (list_hash_table, &proxy, hashcode,
845 /* If not, create a new node. */
847 *slot = (PTR) tree_cons (purpose, value, chain);
851 /* Constructor for hashed lists. */
854 hash_tree_chain (value, chain)
857 return hash_tree_cons (NULL_TREE, value, chain);
860 /* Similar, but used for concatenating two lists. */
863 hash_chainon (list1, list2)
870 if (TREE_CHAIN (list1) == NULL_TREE)
871 return hash_tree_chain (TREE_VALUE (list1), list2);
872 return hash_tree_chain (TREE_VALUE (list1),
873 hash_chainon (TREE_CHAIN (list1), list2));
876 /* Build an association between TYPE and some parameters:
878 OFFSET is the offset added to `this' to convert it to a pointer
881 BINFO is the base binfo to use, if we are deriving from one. This
882 is necessary, as we want specialized parent binfos from base
883 classes, so that the VTABLE_NAMEs of bases are for the most derived
884 type, instead of the simple type.
886 VTABLE is the virtual function table with which to initialize
887 sub-objects of type TYPE.
889 VIRTUALS are the virtual functions sitting in VTABLE. */
892 make_binfo (offset, binfo, vtable, virtuals)
894 tree vtable, virtuals;
896 tree new_binfo = make_tree_vec (11);
899 if (TREE_CODE (binfo) == TREE_VEC)
900 type = BINFO_TYPE (binfo);
904 binfo = CLASS_TYPE_P (type) ? TYPE_BINFO (binfo) : NULL_TREE;
907 TREE_TYPE (new_binfo) = TYPE_MAIN_VARIANT (type);
908 BINFO_OFFSET (new_binfo) = offset;
909 BINFO_VTABLE (new_binfo) = vtable;
910 BINFO_VIRTUALS (new_binfo) = virtuals;
912 if (binfo && BINFO_BASETYPES (binfo) != NULL_TREE)
913 BINFO_BASETYPES (new_binfo) = copy_node (BINFO_BASETYPES (binfo));
917 /* Return a TREE_LIST whose TREE_VALUE nodes along the
918 BINFO_INHERITANCE_CHAIN for BINFO, but in the opposite order. In
919 other words, while the BINFO_INHERITANCE_CHAIN goes from base
920 classes to derived classes, the reversed path goes from derived
921 classes to base classes. */
929 reversed_path = NULL_TREE;
932 reversed_path = tree_cons (NULL_TREE, binfo, reversed_path);
933 binfo = BINFO_INHERITANCE_CHAIN (binfo);
936 return reversed_path;
946 fprintf (stderr, "type \"%s\", offset = ",
947 TYPE_NAME_STRING (BINFO_TYPE (elem)));
948 fprintf (stderr, HOST_WIDE_INT_PRINT_DEC,
949 TREE_INT_CST_LOW (BINFO_OFFSET (elem)));
950 fprintf (stderr, "\nvtable type:\n");
951 debug_tree (BINFO_TYPE (elem));
952 if (BINFO_VTABLE (elem))
953 fprintf (stderr, "vtable decl \"%s\"\n",
954 IDENTIFIER_POINTER (DECL_NAME (get_vtbl_decl_for_binfo (elem))));
956 fprintf (stderr, "no vtable decl yet\n");
957 fprintf (stderr, "virtuals:\n");
958 virtuals = BINFO_VIRTUALS (elem);
963 tree fndecl = TREE_VALUE (virtuals);
964 fprintf (stderr, "%s [%ld =? %ld]\n",
965 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (fndecl)),
966 (long) n, (long) TREE_INT_CST_LOW (DECL_VINDEX (fndecl)));
968 virtuals = TREE_CHAIN (virtuals);
977 if (TREE_CODE (t) == FUNCTION_DECL)
979 else if (TREE_CODE (t) == OVERLOAD)
981 for (i=0; t; t = OVL_CHAIN (t))
994 /* A baselink is also considered an overloaded function. */
995 if (TREE_CODE (x) == OFFSET_REF)
996 x = TREE_OPERAND (x, 1);
998 x = BASELINK_FUNCTIONS (x);
999 return (TREE_CODE (x) == FUNCTION_DECL
1000 || TREE_CODE (x) == TEMPLATE_ID_EXPR
1001 || DECL_FUNCTION_TEMPLATE_P (x)
1002 || TREE_CODE (x) == OVERLOAD);
1006 really_overloaded_fn (x)
1009 /* A baselink is also considered an overloaded function. */
1010 if (TREE_CODE (x) == OFFSET_REF)
1011 x = TREE_OPERAND (x, 1);
1013 x = BASELINK_FUNCTIONS (x);
1015 return ((TREE_CODE (x) == OVERLOAD && OVL_CHAIN (x))
1016 || DECL_FUNCTION_TEMPLATE_P (OVL_CURRENT (x))
1017 || TREE_CODE (x) == TEMPLATE_ID_EXPR);
1024 my_friendly_assert (is_overloaded_fn (from), 9);
1025 /* A baselink is also considered an overloaded function. */
1026 if (BASELINK_P (from))
1027 from = BASELINK_FUNCTIONS (from);
1028 return OVL_CURRENT (from);
1031 /* Returns nonzero if T is a ->* or .* expression that refers to a
1038 return (TREE_CODE (t) == OFFSET_REF
1039 && TYPE_PTRMEMFUNC_P (TREE_TYPE (TREE_OPERAND (t, 1))));
1042 /* Return a new OVL node, concatenating it with the old one. */
1045 ovl_cons (decl, chain)
1049 tree result = make_node (OVERLOAD);
1050 TREE_TYPE (result) = unknown_type_node;
1051 OVL_FUNCTION (result) = decl;
1052 TREE_CHAIN (result) = chain;
1057 /* Build a new overloaded function. If this is the first one,
1058 just return it; otherwise, ovl_cons the _DECLs */
1061 build_overload (decl, chain)
1065 if (! chain && TREE_CODE (decl) != TEMPLATE_DECL)
1067 if (chain && TREE_CODE (chain) != OVERLOAD)
1068 chain = ovl_cons (chain, NULL_TREE);
1069 return ovl_cons (decl, chain);
1073 is_aggr_type_2 (t1, t2)
1076 if (TREE_CODE (t1) != TREE_CODE (t2))
1078 return IS_AGGR_TYPE (t1) && IS_AGGR_TYPE (t2);
1081 /* Returns nonzero if CODE is the code for a statement. */
1084 cp_statement_code_p (code)
1085 enum tree_code code;
1089 case CTOR_INITIALIZER:
1102 #define PRINT_RING_SIZE 4
1105 cxx_printable_name (decl, v)
1109 static tree decl_ring[PRINT_RING_SIZE];
1110 static char *print_ring[PRINT_RING_SIZE];
1111 static int ring_counter;
1114 /* Only cache functions. */
1116 || TREE_CODE (decl) != FUNCTION_DECL
1117 || DECL_LANG_SPECIFIC (decl) == 0)
1118 return lang_decl_name (decl, v);
1120 /* See if this print name is lying around. */
1121 for (i = 0; i < PRINT_RING_SIZE; i++)
1122 if (decl_ring[i] == decl)
1123 /* yes, so return it. */
1124 return print_ring[i];
1126 if (++ring_counter == PRINT_RING_SIZE)
1129 if (current_function_decl != NULL_TREE)
1131 if (decl_ring[ring_counter] == current_function_decl)
1133 if (ring_counter == PRINT_RING_SIZE)
1135 if (decl_ring[ring_counter] == current_function_decl)
1139 if (print_ring[ring_counter])
1140 free (print_ring[ring_counter]);
1142 print_ring[ring_counter] = xstrdup (lang_decl_name (decl, v));
1143 decl_ring[ring_counter] = decl;
1144 return print_ring[ring_counter];
1147 /* Build the FUNCTION_TYPE or METHOD_TYPE which may throw exceptions
1148 listed in RAISES. */
1151 build_exception_variant (type, raises)
1155 tree v = TYPE_MAIN_VARIANT (type);
1156 int type_quals = TYPE_QUALS (type);
1158 for (; v; v = TYPE_NEXT_VARIANT (v))
1159 if (TYPE_QUALS (v) == type_quals
1160 && comp_except_specs (raises, TYPE_RAISES_EXCEPTIONS (v), 1))
1163 /* Need to build a new variant. */
1164 v = build_type_copy (type);
1165 TYPE_RAISES_EXCEPTIONS (v) = raises;
1169 /* Given a TEMPLATE_TEMPLATE_PARM node T, create a new
1170 BOUND_TEMPLATE_TEMPLATE_PARM bound with NEWARGS as its template
1174 bind_template_template_parm (t, newargs)
1178 tree decl = TYPE_NAME (t);
1181 t2 = make_aggr_type (BOUND_TEMPLATE_TEMPLATE_PARM);
1182 decl = build_decl (TYPE_DECL, DECL_NAME (decl), NULL_TREE);
1184 /* These nodes have to be created to reflect new TYPE_DECL and template
1186 TEMPLATE_TYPE_PARM_INDEX (t2) = copy_node (TEMPLATE_TYPE_PARM_INDEX (t));
1187 TEMPLATE_PARM_DECL (TEMPLATE_TYPE_PARM_INDEX (t2)) = decl;
1188 TEMPLATE_TEMPLATE_PARM_TEMPLATE_INFO (t2)
1189 = tree_cons (TEMPLATE_TEMPLATE_PARM_TEMPLATE_DECL (t),
1190 newargs, NULL_TREE);
1192 TREE_TYPE (decl) = t2;
1193 TYPE_NAME (t2) = decl;
1194 TYPE_STUB_DECL (t2) = decl;
1200 /* Called from count_trees via walk_tree. */
1203 count_trees_r (tp, walk_subtrees, data)
1204 tree *tp ATTRIBUTE_UNUSED;
1205 int *walk_subtrees ATTRIBUTE_UNUSED;
1212 /* Debugging function for measuring the rough complexity of a tree
1220 walk_tree_without_duplicates (&t, count_trees_r, &n_trees);
1224 /* Called from verify_stmt_tree via walk_tree. */
1227 verify_stmt_tree_r (tp, walk_subtrees, data)
1229 int *walk_subtrees ATTRIBUTE_UNUSED;
1233 htab_t *statements = (htab_t *) data;
1236 if (!statement_code_p (TREE_CODE (t)))
1239 /* If this statement is already present in the hash table, then
1240 there is a circularity in the statement tree. */
1241 if (htab_find (*statements, t))
1244 slot = htab_find_slot (*statements, t, INSERT);
1250 /* Debugging function to check that the statement T has not been
1251 corrupted. For now, this function simply checks that T contains no
1255 verify_stmt_tree (t)
1259 statements = htab_create (37, htab_hash_pointer, htab_eq_pointer, NULL);
1260 walk_tree (&t, verify_stmt_tree_r, &statements, NULL);
1261 htab_delete (statements);
1264 /* Called from find_tree via walk_tree. */
1267 find_tree_r (tp, walk_subtrees, data)
1269 int *walk_subtrees ATTRIBUTE_UNUSED;
1272 if (*tp == (tree) data)
1278 /* Returns X if X appears in the tree structure rooted at T. */
1285 return walk_tree_without_duplicates (&t, find_tree_r, x);
1288 /* Passed to walk_tree. Checks for the use of types with no linkage. */
1291 no_linkage_helper (tp, walk_subtrees, data)
1293 int *walk_subtrees ATTRIBUTE_UNUSED;
1294 void *data ATTRIBUTE_UNUSED;
1299 && (CLASS_TYPE_P (t) || TREE_CODE (t) == ENUMERAL_TYPE)
1300 && (decl_function_context (TYPE_MAIN_DECL (t))
1301 || TYPE_ANONYMOUS_P (t)))
1306 /* Check if the type T depends on a type with no linkage and if so, return
1310 no_linkage_check (t)
1313 /* There's no point in checking linkage on template functions; we
1314 can't know their complete types. */
1315 if (processing_template_decl)
1318 t = walk_tree_without_duplicates (&t, no_linkage_helper, NULL);
1319 if (t != error_mark_node)
1324 #ifdef GATHER_STATISTICS
1325 extern int depth_reached;
1329 cxx_print_statistics ()
1331 print_search_statistics ();
1332 print_class_statistics ();
1333 #ifdef GATHER_STATISTICS
1334 fprintf (stderr, "maximum template instantiation depth reached: %d\n",
1339 /* Return, as an INTEGER_CST node, the number of elements for TYPE
1340 (which is an ARRAY_TYPE). This counts only elements of the top
1344 array_type_nelts_top (type)
1347 return fold (build (PLUS_EXPR, sizetype,
1348 array_type_nelts (type),
1352 /* Return, as an INTEGER_CST node, the number of elements for TYPE
1353 (which is an ARRAY_TYPE). This one is a recursive count of all
1354 ARRAY_TYPEs that are clumped together. */
1357 array_type_nelts_total (type)
1360 tree sz = array_type_nelts_top (type);
1361 type = TREE_TYPE (type);
1362 while (TREE_CODE (type) == ARRAY_TYPE)
1364 tree n = array_type_nelts_top (type);
1365 sz = fold (build (MULT_EXPR, sizetype, sz, n));
1366 type = TREE_TYPE (type);
1371 /* Called from break_out_target_exprs via mapcar. */
1374 bot_manip (tp, walk_subtrees, data)
1379 splay_tree target_remap = ((splay_tree) data);
1382 if (TREE_CONSTANT (t))
1384 /* There can't be any TARGET_EXPRs or their slot variables below
1385 this point. We used to check !TREE_SIDE_EFFECTS, but then we
1386 failed to copy an ADDR_EXPR of the slot VAR_DECL. */
1390 if (TREE_CODE (t) == TARGET_EXPR)
1394 if (TREE_CODE (TREE_OPERAND (t, 1)) == AGGR_INIT_EXPR)
1396 mark_used (TREE_OPERAND (TREE_OPERAND (TREE_OPERAND (t, 1), 0), 0));
1398 (TREE_TYPE (t), break_out_target_exprs (TREE_OPERAND (t, 1)));
1402 u = build_target_expr_with_type
1403 (break_out_target_exprs (TREE_OPERAND (t, 1)), TREE_TYPE (t));
1406 /* Map the old variable to the new one. */
1407 splay_tree_insert (target_remap,
1408 (splay_tree_key) TREE_OPERAND (t, 0),
1409 (splay_tree_value) TREE_OPERAND (u, 0));
1411 /* Replace the old expression with the new version. */
1413 /* We don't have to go below this point; the recursive call to
1414 break_out_target_exprs will have handled anything below this
1419 else if (TREE_CODE (t) == CALL_EXPR)
1420 mark_used (TREE_OPERAND (TREE_OPERAND (t, 0), 0));
1422 /* Make a copy of this node. */
1423 return copy_tree_r (tp, walk_subtrees, NULL);
1426 /* Replace all remapped VAR_DECLs in T with their new equivalents.
1427 DATA is really a splay-tree mapping old variables to new
1431 bot_replace (t, walk_subtrees, data)
1433 int *walk_subtrees ATTRIBUTE_UNUSED;
1436 splay_tree target_remap = ((splay_tree) data);
1438 if (TREE_CODE (*t) == VAR_DECL)
1440 splay_tree_node n = splay_tree_lookup (target_remap,
1441 (splay_tree_key) *t);
1443 *t = (tree) n->value;
1449 /* When we parse a default argument expression, we may create
1450 temporary variables via TARGET_EXPRs. When we actually use the
1451 default-argument expression, we make a copy of the expression, but
1452 we must replace the temporaries with appropriate local versions. */
1455 break_out_target_exprs (t)
1458 static int target_remap_count;
1459 static splay_tree target_remap;
1461 if (!target_remap_count++)
1462 target_remap = splay_tree_new (splay_tree_compare_pointers,
1463 /*splay_tree_delete_key_fn=*/NULL,
1464 /*splay_tree_delete_value_fn=*/NULL);
1465 walk_tree (&t, bot_manip, target_remap, NULL);
1466 walk_tree (&t, bot_replace, target_remap, NULL);
1468 if (!--target_remap_count)
1470 splay_tree_delete (target_remap);
1471 target_remap = NULL;
1477 /* Obstack used for allocating nodes in template function and variable
1480 /* Similar to `build_nt', except that we set TREE_COMPLEXITY to be the
1481 current line number. */
1484 build_min_nt VPARAMS ((enum tree_code code, ...))
1487 register int length;
1491 VA_FIXEDARG (p, enum tree_code, code);
1493 t = make_node (code);
1494 length = TREE_CODE_LENGTH (code);
1495 TREE_COMPLEXITY (t) = lineno;
1497 for (i = 0; i < length; i++)
1499 tree x = va_arg (p, tree);
1500 TREE_OPERAND (t, i) = x;
1507 /* Similar to `build', except we set TREE_COMPLEXITY to the current
1511 build_min VPARAMS ((enum tree_code code, tree tt, ...))
1514 register int length;
1518 VA_FIXEDARG (p, enum tree_code, code);
1519 VA_FIXEDARG (p, tree, tt);
1521 t = make_node (code);
1522 length = TREE_CODE_LENGTH (code);
1524 TREE_COMPLEXITY (t) = lineno;
1526 for (i = 0; i < length; i++)
1528 tree x = va_arg (p, tree);
1529 TREE_OPERAND (t, i) = x;
1536 /* Returns an INTEGER_CST (of type `int') corresponding to I.
1537 Multiple calls with the same value of I may or may not yield the
1538 same node; therefore, callers should never modify the node
1541 static GTY(()) tree shared_int_cache[256];
1544 build_shared_int_cst (i)
1548 return build_int_2 (i, 0);
1550 if (!shared_int_cache[i])
1551 shared_int_cache[i] = build_int_2 (i, 0);
1553 return shared_int_cache[i];
1560 if (TREE_CODE (t) == TYPE_DECL)
1563 return TYPE_STUB_DECL (t);
1564 if (t == error_mark_node)
1569 /* Stop compiler from complaining control reaches end of non-void function. */
1573 /* Return first vector element whose BINFO_TYPE is ELEM.
1574 Return 0 if ELEM is not in VEC. VEC may be NULL_TREE. */
1577 vec_binfo_member (elem, vec)
1583 for (i = 0; i < TREE_VEC_LENGTH (vec); ++i)
1584 if (same_type_p (elem, BINFO_TYPE (TREE_VEC_ELT (vec, i))))
1585 return TREE_VEC_ELT (vec, i);
1590 /* Returns the namespace that contains DECL, whether directly or
1594 decl_namespace_context (decl)
1599 if (TREE_CODE (decl) == NAMESPACE_DECL)
1601 else if (TYPE_P (decl))
1602 decl = CP_DECL_CONTEXT (TYPE_MAIN_DECL (decl));
1604 decl = CP_DECL_CONTEXT (decl);
1608 /* Return truthvalue of whether T1 is the same tree structure as T2.
1609 Return 1 if they are the same.
1610 Return 0 if they are understandably different.
1611 Return -1 if either contains tree structure not understood by
1615 cp_tree_equal (t1, t2)
1618 register enum tree_code code1, code2;
1623 if (t1 == 0 || t2 == 0)
1626 code1 = TREE_CODE (t1);
1627 code2 = TREE_CODE (t2);
1629 if (code1 == NOP_EXPR || code1 == CONVERT_EXPR || code1 == NON_LVALUE_EXPR)
1631 if (code2 == NOP_EXPR || code2 == CONVERT_EXPR || code2 == NON_LVALUE_EXPR)
1632 return cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
1634 return cp_tree_equal (TREE_OPERAND (t1, 0), t2);
1636 else if (code2 == NOP_EXPR || code2 == CONVERT_EXPR
1637 || code2 == NON_LVALUE_EXPR)
1638 return cp_tree_equal (t1, TREE_OPERAND (t2, 0));
1646 return TREE_INT_CST_LOW (t1) == TREE_INT_CST_LOW (t2)
1647 && TREE_INT_CST_HIGH (t1) == TREE_INT_CST_HIGH (t2);
1650 return REAL_VALUES_EQUAL (TREE_REAL_CST (t1), TREE_REAL_CST (t2));
1653 return TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
1654 && !memcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
1655 TREE_STRING_LENGTH (t1));
1658 /* We need to do this when determining whether or not two
1659 non-type pointer to member function template arguments
1661 if (!(same_type_p (TREE_TYPE (t1), TREE_TYPE (t2))
1662 /* The first operand is RTL. */
1663 && TREE_OPERAND (t1, 0) == TREE_OPERAND (t2, 0)))
1665 return cp_tree_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
1668 cmp = cp_tree_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2));
1671 cmp = cp_tree_equal (TREE_VALUE (t1), TREE_VALUE (t2));
1674 return cp_tree_equal (TREE_CHAIN (t1), TREE_CHAIN (t2));
1677 return cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
1680 cmp = cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
1683 return simple_cst_list_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
1686 /* Special case: if either target is an unallocated VAR_DECL,
1687 it means that it's going to be unified with whatever the
1688 TARGET_EXPR is really supposed to initialize, so treat it
1689 as being equivalent to anything. */
1690 if ((TREE_CODE (TREE_OPERAND (t1, 0)) == VAR_DECL
1691 && DECL_NAME (TREE_OPERAND (t1, 0)) == NULL_TREE
1692 && !DECL_RTL_SET_P (TREE_OPERAND (t1, 0)))
1693 || (TREE_CODE (TREE_OPERAND (t2, 0)) == VAR_DECL
1694 && DECL_NAME (TREE_OPERAND (t2, 0)) == NULL_TREE
1695 && !DECL_RTL_SET_P (TREE_OPERAND (t2, 0))))
1698 cmp = cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
1701 return cp_tree_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
1703 case WITH_CLEANUP_EXPR:
1704 cmp = cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
1707 return cp_tree_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t1, 1));
1710 if (TREE_OPERAND (t1, 1) == TREE_OPERAND (t2, 1))
1711 return cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
1720 case TEMPLATE_PARM_INDEX:
1721 return (TEMPLATE_PARM_IDX (t1) == TEMPLATE_PARM_IDX (t2)
1722 && TEMPLATE_PARM_LEVEL (t1) == TEMPLATE_PARM_LEVEL (t2)
1723 && same_type_p (TREE_TYPE (TEMPLATE_PARM_DECL (t1)),
1724 TREE_TYPE (TEMPLATE_PARM_DECL (t2))));
1728 if (TREE_CODE (TREE_OPERAND (t1, 0)) != TREE_CODE (TREE_OPERAND (t2, 0)))
1730 if (TYPE_P (TREE_OPERAND (t1, 0)))
1731 return same_type_p (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
1735 /* Two pointer-to-members are the same if they point to the same
1736 field or function in the same class. */
1737 return (PTRMEM_CST_MEMBER (t1) == PTRMEM_CST_MEMBER (t2)
1738 && same_type_p (PTRMEM_CST_CLASS (t1), PTRMEM_CST_CLASS (t2)));
1744 switch (TREE_CODE_CLASS (code1))
1756 for (i = 0; i < TREE_CODE_LENGTH (code1); ++i)
1758 cmp = cp_tree_equal (TREE_OPERAND (t1, i), TREE_OPERAND (t2, i));
1766 return same_type_p (t1, t2) ? 1 : 0;
1772 /* Build a wrapper around a 'struct z_candidate' so we can use it as a
1776 build_zc_wrapper (ptr)
1777 struct z_candidate *ptr;
1779 tree t = make_node (WRAPPER);
1780 WRAPPER_ZC (t) = ptr;
1785 build_srcloc (file, line)
1791 t = make_node (SRCLOC);
1792 SRCLOC_FILE (t) = file;
1793 SRCLOC_LINE (t) = line;
1799 build_srcloc_here ()
1801 return build_srcloc (input_filename, lineno);
1804 /* The type of ARG when used as an lvalue. */
1810 tree type = TREE_TYPE (arg);
1811 if (TREE_CODE (arg) == OVERLOAD)
1812 type = unknown_type_node;
1816 /* The type of ARG for printing error messages; denote lvalues with
1823 tree type = TREE_TYPE (arg);
1824 if (TREE_CODE (type) == ARRAY_TYPE)
1826 else if (real_lvalue_p (arg))
1827 type = build_reference_type (lvalue_type (arg));
1828 else if (IS_AGGR_TYPE (type))
1829 type = lvalue_type (arg);
1834 /* Does FUNCTION use a variable-length argument list? */
1837 varargs_function_p (function)
1840 tree parm = TYPE_ARG_TYPES (TREE_TYPE (function));
1841 for (; parm; parm = TREE_CHAIN (parm))
1842 if (TREE_VALUE (parm) == void_type_node)
1847 /* Returns 1 if decl is a member of a class. */
1853 const tree ctx = DECL_CONTEXT (decl);
1854 return (ctx && TYPE_P (ctx));
1857 /* Create a placeholder for member access where we don't actually have an
1858 object that the access is against. */
1861 build_dummy_object (type)
1864 tree decl = build1 (NOP_EXPR, build_pointer_type (type), void_zero_node);
1865 return build_indirect_ref (decl, NULL);
1868 /* We've gotten a reference to a member of TYPE. Return *this if appropriate,
1869 or a dummy object otherwise. If BINFOP is non-0, it is filled with the
1870 binfo path from current_class_type to TYPE, or 0. */
1873 maybe_dummy_object (type, binfop)
1880 if (current_class_type
1881 && (binfo = lookup_base (current_class_type, type,
1882 ba_ignore | ba_quiet, NULL)))
1883 context = current_class_type;
1886 /* Reference from a nested class member function. */
1888 binfo = TYPE_BINFO (type);
1894 if (current_class_ref && context == current_class_type
1895 /* Kludge: Make sure that current_class_type is actually
1896 correct. It might not be if we're in the middle of
1897 tsubst_default_argument. */
1898 && same_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (current_class_ref)),
1899 current_class_type))
1900 decl = current_class_ref;
1902 decl = build_dummy_object (context);
1907 /* Returns 1 if OB is a placeholder object, or a pointer to one. */
1910 is_dummy_object (ob)
1913 if (TREE_CODE (ob) == INDIRECT_REF)
1914 ob = TREE_OPERAND (ob, 0);
1915 return (TREE_CODE (ob) == NOP_EXPR
1916 && TREE_OPERAND (ob, 0) == void_zero_node);
1919 /* Returns 1 iff type T is a POD type, as defined in [basic.types]. */
1925 t = strip_array_types (t);
1927 if (t == error_mark_node)
1929 if (INTEGRAL_TYPE_P (t))
1930 return 1; /* integral, character or enumeral type */
1931 if (FLOAT_TYPE_P (t))
1934 return 1; /* pointer to non-member */
1935 if (TYPE_PTRMEM_P (t))
1936 return 1; /* pointer to member object */
1937 if (TYPE_PTRMEMFUNC_P (t))
1938 return 1; /* pointer to member function */
1940 if (! CLASS_TYPE_P (t))
1941 return 0; /* other non-class type (reference or function) */
1942 if (CLASSTYPE_NON_POD_P (t))
1947 /* Returns 1 iff zero initialization of type T means actually storing
1954 t = strip_array_types (t);
1956 if (t == error_mark_node)
1959 /* NULL pointers to data members are initialized with -1. */
1960 if (TYPE_PTRMEM_P (t))
1963 /* Classes that contain types that can't be zero-initialized, cannot
1964 be zero-initialized themselves. */
1965 if (CLASS_TYPE_P (t) && CLASSTYPE_NON_ZERO_INIT_P (t))
1971 /* Table of valid C++ attributes. */
1972 const struct attribute_spec cxx_attribute_table[] =
1974 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
1975 { "java_interface", 0, 0, false, false, false, handle_java_interface_attribute },
1976 { "com_interface", 0, 0, false, false, false, handle_com_interface_attribute },
1977 { "init_priority", 1, 1, true, false, false, handle_init_priority_attribute },
1978 { NULL, 0, 0, false, false, false, NULL }
1981 /* Handle a "java_interface" attribute; arguments as in
1982 struct attribute_spec.handler. */
1984 handle_java_interface_attribute (node, name, args, flags, no_add_attrs)
1987 tree args ATTRIBUTE_UNUSED;
1992 || !CLASS_TYPE_P (*node)
1993 || !TYPE_FOR_JAVA (*node))
1995 error ("`%s' attribute can only be applied to Java class definitions",
1996 IDENTIFIER_POINTER (name));
1997 *no_add_attrs = true;
2000 if (!(flags & (int) ATTR_FLAG_TYPE_IN_PLACE))
2001 *node = build_type_copy (*node);
2002 TYPE_JAVA_INTERFACE (*node) = 1;
2007 /* Handle a "com_interface" attribute; arguments as in
2008 struct attribute_spec.handler. */
2010 handle_com_interface_attribute (node, name, args, flags, no_add_attrs)
2013 tree args ATTRIBUTE_UNUSED;
2014 int flags ATTRIBUTE_UNUSED;
2019 *no_add_attrs = true;
2022 || !CLASS_TYPE_P (*node)
2023 || *node != TYPE_MAIN_VARIANT (*node))
2025 warning ("`%s' attribute can only be applied to class definitions",
2026 IDENTIFIER_POINTER (name));
2031 warning ("`%s' is obsolete; g++ vtables are now COM-compatible by default",
2032 IDENTIFIER_POINTER (name));
2037 /* Handle an "init_priority" attribute; arguments as in
2038 struct attribute_spec.handler. */
2040 handle_init_priority_attribute (node, name, args, flags, no_add_attrs)
2044 int flags ATTRIBUTE_UNUSED;
2047 tree initp_expr = TREE_VALUE (args);
2049 tree type = TREE_TYPE (decl);
2052 STRIP_NOPS (initp_expr);
2054 if (!initp_expr || TREE_CODE (initp_expr) != INTEGER_CST)
2056 error ("requested init_priority is not an integer constant");
2057 *no_add_attrs = true;
2061 pri = TREE_INT_CST_LOW (initp_expr);
2063 type = strip_array_types (type);
2065 if (decl == NULL_TREE
2066 || TREE_CODE (decl) != VAR_DECL
2067 || !TREE_STATIC (decl)
2068 || DECL_EXTERNAL (decl)
2069 || (TREE_CODE (type) != RECORD_TYPE
2070 && TREE_CODE (type) != UNION_TYPE)
2071 /* Static objects in functions are initialized the
2072 first time control passes through that
2073 function. This is not precise enough to pin down an
2074 init_priority value, so don't allow it. */
2075 || current_function_decl)
2077 error ("can only use `%s' attribute on file-scope definitions of objects of class type",
2078 IDENTIFIER_POINTER (name));
2079 *no_add_attrs = true;
2083 if (pri > MAX_INIT_PRIORITY || pri <= 0)
2085 error ("requested init_priority is out of range");
2086 *no_add_attrs = true;
2090 /* Check for init_priorities that are reserved for
2091 language and runtime support implementations.*/
2092 if (pri <= MAX_RESERVED_INIT_PRIORITY)
2095 ("requested init_priority is reserved for internal use");
2098 if (SUPPORTS_INIT_PRIORITY)
2100 DECL_INIT_PRIORITY (decl) = pri;
2105 error ("`%s' attribute is not supported on this platform",
2106 IDENTIFIER_POINTER (name));
2107 *no_add_attrs = true;
2112 /* Return a new PTRMEM_CST of the indicated TYPE. The MEMBER is the
2113 thing pointed to by the constant. */
2116 make_ptrmem_cst (type, member)
2120 tree ptrmem_cst = make_node (PTRMEM_CST);
2121 /* If would seem a great convenience if make_node would set
2122 TREE_CONSTANT for things of class `c', but it does not. */
2123 TREE_CONSTANT (ptrmem_cst) = 1;
2124 TREE_TYPE (ptrmem_cst) = type;
2125 PTRMEM_CST_MEMBER (ptrmem_cst) = member;
2129 /* Apply FUNC to all language-specific sub-trees of TP in a pre-order
2130 traversal. Called from walk_tree(). */
2133 cp_walk_subtrees (tp, walk_subtrees_p, func, data, htab)
2135 int *walk_subtrees_p;
2140 enum tree_code code = TREE_CODE (*tp);
2143 #define WALK_SUBTREE(NODE) \
2146 result = walk_tree (&(NODE), func, data, htab); \
2152 /* Not one of the easy cases. We must explicitly go through the
2157 case TEMPLATE_TEMPLATE_PARM:
2158 case BOUND_TEMPLATE_TEMPLATE_PARM:
2159 case UNBOUND_CLASS_TEMPLATE:
2160 case TEMPLATE_PARM_INDEX:
2161 case TEMPLATE_TYPE_PARM:
2164 /* None of thse have subtrees other than those already walked
2166 *walk_subtrees_p = 0;
2170 WALK_SUBTREE (TREE_TYPE (*tp));
2171 *walk_subtrees_p = 0;
2175 /* A BASELINK_P's TREE_PURPOSE is a BINFO, and hence circular. */
2176 if (!BASELINK_P (*tp))
2177 WALK_SUBTREE (TREE_PURPOSE (*tp));
2181 WALK_SUBTREE (OVL_FUNCTION (*tp));
2182 WALK_SUBTREE (OVL_CHAIN (*tp));
2183 *walk_subtrees_p = 0;
2187 if (TYPE_PTRMEMFUNC_P (*tp))
2188 WALK_SUBTREE (TYPE_PTRMEMFUNC_FN_TYPE (*tp));
2195 /* We didn't find what we were looking for. */
2201 /* Decide whether there are language-specific reasons to not inline a
2202 function as a tree. */
2205 cp_cannot_inline_tree_fn (fnp)
2210 if (flag_really_no_inline
2211 && lookup_attribute ("always_inline", DECL_ATTRIBUTES (fn)) == NULL)
2214 /* We can inline a template instantiation only if it's fully
2216 if (DECL_TEMPLATE_INFO (fn)
2217 && TI_PENDING_TEMPLATE_FLAG (DECL_TEMPLATE_INFO (fn)))
2219 fn = *fnp = instantiate_decl (fn, /*defer_ok=*/0);
2220 if (TI_PENDING_TEMPLATE_FLAG (DECL_TEMPLATE_INFO (fn)))
2224 /* Don't auto-inline anything that might not be bound within
2225 this unit of translation. */
2226 if (!DECL_DECLARED_INLINE_P (fn) && !(*targetm.binds_local_p) (fn))
2228 DECL_UNINLINABLE (fn) = 1;
2232 if (varargs_function_p (fn))
2234 DECL_UNINLINABLE (fn) = 1;
2238 if (! function_attribute_inlinable_p (fn))
2240 DECL_UNINLINABLE (fn) = 1;
2247 /* Add any pending functions other than the current function (already
2248 handled by the caller), that thus cannot be inlined, to FNS_P, then
2249 return the latest function added to the array, PREV_FN. */
2252 cp_add_pending_fn_decls (fns_p, prev_fn)
2256 varray_type *fnsp = (varray_type *)fns_p;
2257 struct saved_scope *s;
2259 for (s = scope_chain; s; s = s->prev)
2260 if (s->function_decl && s->function_decl != prev_fn)
2262 VARRAY_PUSH_TREE (*fnsp, s->function_decl);
2263 prev_fn = s->function_decl;
2269 /* Determine whether a tree node is an OVERLOAD node. Used to decide
2270 whether to copy a node or to preserve its chain when inlining a
2274 cp_is_overload_p (t)
2277 return TREE_CODE (t) == OVERLOAD;
2280 /* Determine whether VAR is a declaration of an automatic variable in
2284 cp_auto_var_in_fn_p (var, fn)
2287 return (DECL_P (var) && DECL_CONTEXT (var) == fn
2288 && nonstatic_local_decl_p (var));
2291 /* Tell whether a declaration is needed for the RESULT of a function
2292 FN being inlined into CALLER or if the top node of target_exprs is
2296 cp_copy_res_decl_for_inlining (result, fn, caller, decl_map_,
2297 need_decl, return_slot_addr)
2298 tree result, fn, caller;
2301 tree return_slot_addr;
2303 splay_tree decl_map = (splay_tree)decl_map_;
2306 /* If FN returns an aggregate then the caller will always pass the
2307 address of the return slot explicitly. If we were just to
2308 create a new VAR_DECL here, then the result of this function
2309 would be copied (bitwise) into the variable initialized by the
2310 TARGET_EXPR. That's incorrect, so we must transform any
2311 references to the RESULT into references to the target. */
2313 /* We should have an explicit return slot iff the return type is
2314 TREE_ADDRESSABLE. See simplify_aggr_init_expr. */
2315 if (TREE_ADDRESSABLE (TREE_TYPE (result))
2316 != (return_slot_addr != NULL_TREE))
2319 *need_decl = !return_slot_addr;
2320 if (return_slot_addr)
2322 var = build_indirect_ref (return_slot_addr, "");
2323 if (! same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (var),
2324 TREE_TYPE (result)))
2327 /* Otherwise, make an appropriate copy. */
2329 var = copy_decl_for_inlining (result, fn, caller);
2331 if (DECL_SAVED_FUNCTION_DATA (fn))
2333 tree nrv = DECL_SAVED_FUNCTION_DATA (fn)->x_return_value;
2336 /* We have a named return value; copy the name and source
2337 position so we can get reasonable debugging information, and
2338 register the return variable as its equivalent. */
2339 if (TREE_CODE (var) == VAR_DECL)
2341 DECL_NAME (var) = DECL_NAME (nrv);
2342 DECL_SOURCE_LOCATION (var) = DECL_SOURCE_LOCATION (nrv);
2343 DECL_ABSTRACT_ORIGIN (var) = DECL_ORIGIN (nrv);
2344 /* Don't lose initialization info. */
2345 DECL_INITIAL (var) = DECL_INITIAL (nrv);
2346 /* Don't forget that it needs to go in the stack. */
2347 TREE_ADDRESSABLE (var) = TREE_ADDRESSABLE (nrv);
2350 splay_tree_insert (decl_map,
2351 (splay_tree_key) nrv,
2352 (splay_tree_value) var);
2359 /* Record that we're about to start inlining FN, and return nonzero if
2360 that's OK. Used for lang_hooks.tree_inlining.start_inlining. */
2363 cp_start_inlining (fn)
2366 if (DECL_TEMPLATE_INSTANTIATION (fn))
2367 return push_tinst_level (fn);
2372 /* Record that we're done inlining FN. Used for
2373 lang_hooks.tree_inlining.end_inlining. */
2376 cp_end_inlining (fn)
2377 tree fn ATTRIBUTE_UNUSED;
2379 if (DECL_TEMPLATE_INSTANTIATION (fn))
2383 /* Initialize tree.c. */
2388 lang_statement_code_p = cp_statement_code_p;
2389 list_hash_table = htab_create_ggc (31, list_hash, list_hash_eq, NULL);
2392 /* Called via walk_tree. If *TP points to a DECL_STMT for a local
2393 declaration, copies the declaration and enters it in the splay_tree
2394 pointed to by DATA (which is really a `splay_tree *'). */
2397 mark_local_for_remap_r (tp, walk_subtrees, data)
2399 int *walk_subtrees ATTRIBUTE_UNUSED;
2403 splay_tree st = (splay_tree) data;
2407 if (TREE_CODE (t) == DECL_STMT
2408 && nonstatic_local_decl_p (DECL_STMT_DECL (t)))
2409 decl = DECL_STMT_DECL (t);
2410 else if (TREE_CODE (t) == LABEL_STMT)
2411 decl = LABEL_STMT_LABEL (t);
2412 else if (TREE_CODE (t) == TARGET_EXPR
2413 && nonstatic_local_decl_p (TREE_OPERAND (t, 0)))
2414 decl = TREE_OPERAND (t, 0);
2415 else if (TREE_CODE (t) == CASE_LABEL)
2416 decl = CASE_LABEL_DECL (t);
2425 copy = copy_decl_for_inlining (decl,
2426 DECL_CONTEXT (decl),
2427 DECL_CONTEXT (decl));
2429 /* Remember the copy. */
2430 splay_tree_insert (st,
2431 (splay_tree_key) decl,
2432 (splay_tree_value) copy);
2438 /* Called via walk_tree when an expression is unsaved. Using the
2439 splay_tree pointed to by ST (which is really a `splay_tree'),
2440 remaps all local declarations to appropriate replacements. */
2443 cp_unsave_r (tp, walk_subtrees, data)
2448 splay_tree st = (splay_tree) data;
2451 /* Only a local declaration (variable or label). */
2452 if (nonstatic_local_decl_p (*tp))
2454 /* Lookup the declaration. */
2455 n = splay_tree_lookup (st, (splay_tree_key) *tp);
2457 /* If it's there, remap it. */
2459 *tp = (tree) n->value;
2461 else if (TREE_CODE (*tp) == SAVE_EXPR)
2462 remap_save_expr (tp, st, current_function_decl, walk_subtrees);
2465 copy_tree_r (tp, walk_subtrees, NULL);
2467 /* Do whatever unsaving is required. */
2468 unsave_expr_1 (*tp);
2471 /* Keep iterating. */
2475 /* Called whenever an expression needs to be unsaved. */
2478 cxx_unsave_expr_now (tp)
2483 /* Create a splay-tree to map old local variable declarations to new
2485 st = splay_tree_new (splay_tree_compare_pointers, NULL, NULL);
2487 /* Walk the tree once figuring out what needs to be remapped. */
2488 walk_tree (&tp, mark_local_for_remap_r, st, NULL);
2490 /* Walk the tree again, copying, remapping, and unsaving. */
2491 walk_tree (&tp, cp_unsave_r, st, NULL);
2494 splay_tree_delete (st);
2499 /* Returns the kind of special function that DECL (a FUNCTION_DECL)
2500 is. Note that sfk_none is zero, so this function can be used as a
2501 predicate to test whether or not DECL is a special function. */
2503 special_function_kind
2504 special_function_p (decl)
2507 /* Rather than doing all this stuff with magic names, we should
2508 probably have a field of type `special_function_kind' in
2509 DECL_LANG_SPECIFIC. */
2510 if (DECL_COPY_CONSTRUCTOR_P (decl))
2511 return sfk_copy_constructor;
2512 if (DECL_CONSTRUCTOR_P (decl))
2513 return sfk_constructor;
2514 if (DECL_OVERLOADED_OPERATOR_P (decl) == NOP_EXPR)
2515 return sfk_assignment_operator;
2516 if (DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (decl))
2517 return sfk_destructor;
2518 if (DECL_COMPLETE_DESTRUCTOR_P (decl))
2519 return sfk_complete_destructor;
2520 if (DECL_BASE_DESTRUCTOR_P (decl))
2521 return sfk_base_destructor;
2522 if (DECL_DELETING_DESTRUCTOR_P (decl))
2523 return sfk_deleting_destructor;
2524 if (DECL_CONV_FN_P (decl))
2525 return sfk_conversion;
2530 /* Returns true if and only if NODE is a name, i.e., a node created
2531 by the parser when processing an id-expression. */
2536 if (TREE_CODE (node) == TEMPLATE_ID_EXPR)
2537 node = TREE_OPERAND (node, 0);
2538 return (/* An ordinary unqualified name. */
2539 TREE_CODE (node) == IDENTIFIER_NODE
2540 /* A destructor name. */
2541 || TREE_CODE (node) == BIT_NOT_EXPR
2542 /* A qualified name. */
2543 || TREE_CODE (node) == SCOPE_REF);
2546 /* Returns nonzero if TYPE is a character type, including wchar_t. */
2552 return (same_type_p (type, char_type_node)
2553 || same_type_p (type, unsigned_char_type_node)
2554 || same_type_p (type, signed_char_type_node)
2555 || same_type_p (type, wchar_type_node));
2558 /* Returns the kind of linkage associated with the indicated DECL. Th
2559 value returned is as specified by the language standard; it is
2560 independent of implementation details regarding template
2561 instantiation, etc. For example, it is possible that a declaration
2562 to which this function assigns external linkage would not show up
2563 as a global symbol when you run `nm' on the resulting object file. */
2569 /* This function doesn't attempt to calculate the linkage from first
2570 principles as given in [basic.link]. Instead, it makes use of
2571 the fact that we have already set TREE_PUBLIC appropriately, and
2572 then handles a few special cases. Ideally, we would calculate
2573 linkage first, and then transform that into a concrete
2576 /* Things that don't have names have no linkage. */
2577 if (!DECL_NAME (decl))
2580 /* Things that are TREE_PUBLIC have external linkage. */
2581 if (TREE_PUBLIC (decl))
2584 /* Some things that are not TREE_PUBLIC have external linkage, too.
2585 For example, on targets that don't have weak symbols, we make all
2586 template instantiations have internal linkage (in the object
2587 file), but the symbols should still be treated as having external
2588 linkage from the point of view of the language. */
2589 if (DECL_LANG_SPECIFIC (decl) && DECL_COMDAT (decl))
2592 /* Things in local scope do not have linkage, if they don't have
2594 if (decl_function_context (decl))
2597 /* Everything else has internal linkage. */
2601 /* EXP is an expression that we want to pre-evaluate. Returns via INITP an
2602 expression to perform the pre-evaluation, and returns directly an
2603 expression to use the precalculated result. */
2606 stabilize_expr (exp, initp)
2612 if (!TREE_SIDE_EFFECTS (exp))
2614 init_expr = void_zero_node;
2616 else if (!real_lvalue_p (exp)
2617 || !TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (exp)))
2619 init_expr = get_target_expr (exp);
2620 exp = TARGET_EXPR_SLOT (init_expr);
2624 exp = build_unary_op (ADDR_EXPR, exp, 1);
2625 init_expr = get_target_expr (exp);
2626 exp = TARGET_EXPR_SLOT (init_expr);
2627 exp = build_indirect_ref (exp, 0);
2634 #if defined ENABLE_TREE_CHECKING && (GCC_VERSION >= 2007)
2635 /* Complain that some language-specific thing hanging off a tree
2636 node has been accessed improperly. */
2639 lang_check_failed (file, line, function)
2642 const char *function;
2644 internal_error ("lang_* check: failed in %s, at %s:%d",
2645 function, trim_filename (file), line);
2647 #endif /* ENABLE_TREE_CHECKING */
2649 #include "gt-cp-tree.h"