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 Free Software Foundation, Inc.
4 Hacked by Michael Tiemann (tiemann@cygnus.com)
6 This file is part of GNU CC.
8 GNU CC 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 GNU CC 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 GNU CC; see the file COPYING. If not, write to
20 the Free Software Foundation, 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
32 #include "insn-config.h"
33 #include "integrate.h"
35 static tree bot_manip PARAMS ((tree *, int *, void *));
36 static tree bot_replace PARAMS ((tree *, int *, void *));
37 static tree build_cplus_array_type_1 PARAMS ((tree, tree));
38 static int list_hash_eq PARAMS ((const void *, const void *));
39 static hashval_t list_hash_pieces PARAMS ((tree, tree, tree));
40 static hashval_t list_hash PARAMS ((const void *));
41 static cp_lvalue_kind lvalue_p_1 PARAMS ((tree, int));
42 static tree no_linkage_helper PARAMS ((tree *, int *, void *));
43 static tree build_srcloc PARAMS ((const char *, int));
44 static tree mark_local_for_remap_r PARAMS ((tree *, int *, void *));
45 static tree cp_unsave_r PARAMS ((tree *, int *, void *));
46 static void cp_unsave PARAMS ((tree *));
47 static tree build_target_expr PARAMS ((tree, tree));
48 static tree count_trees_r PARAMS ((tree *, int *, void *));
49 static tree verify_stmt_tree_r PARAMS ((tree *, int *, void *));
50 static tree find_tree_r PARAMS ((tree *, int *, void *));
51 extern int cp_statement_code_p PARAMS ((enum tree_code));
53 /* If REF is an lvalue, returns the kind of lvalue that REF is.
54 Otherwise, returns clk_none. If TREAT_CLASS_RVALUES_AS_LVALUES is
55 non-zero, rvalues of class type are considered lvalues. */
58 lvalue_p_1 (ref, treat_class_rvalues_as_lvalues)
60 int treat_class_rvalues_as_lvalues;
62 cp_lvalue_kind op1_lvalue_kind = clk_none;
63 cp_lvalue_kind op2_lvalue_kind = clk_none;
65 if (TREE_CODE (TREE_TYPE (ref)) == REFERENCE_TYPE)
68 if (ref == current_class_ptr)
71 switch (TREE_CODE (ref))
73 /* preincrements and predecrements are valid lvals, provided
74 what they refer to are valid lvals. */
75 case PREINCREMENT_EXPR:
76 case PREDECREMENT_EXPR:
80 case WITH_CLEANUP_EXPR:
84 return lvalue_p_1 (TREE_OPERAND (ref, 0),
85 treat_class_rvalues_as_lvalues);
88 op1_lvalue_kind = lvalue_p_1 (TREE_OPERAND (ref, 0),
89 treat_class_rvalues_as_lvalues);
91 /* The "field" can be a FUNCTION_DECL or an OVERLOAD in some
93 && TREE_CODE (TREE_OPERAND (ref, 1)) == FIELD_DECL
94 && DECL_C_BIT_FIELD (TREE_OPERAND (ref, 1)))
96 /* Clear the ordinary bit. If this object was a class
97 rvalue we want to preserve that information. */
98 op1_lvalue_kind &= ~clk_ordinary;
99 /* The lvalue is for a btifield. */
100 op1_lvalue_kind |= clk_bitfield;
102 return op1_lvalue_kind;
108 if (TREE_READONLY (ref) && ! TREE_STATIC (ref)
109 && DECL_LANG_SPECIFIC (ref)
110 && DECL_IN_AGGR_P (ref))
116 if (TREE_CODE (TREE_TYPE (ref)) != METHOD_TYPE)
120 /* A currently unresolved scope ref. */
122 my_friendly_abort (103);
124 if (TREE_CODE (TREE_OPERAND (ref, 1)) == FUNCTION_DECL)
129 op1_lvalue_kind = lvalue_p_1 (TREE_OPERAND (ref, 0),
130 treat_class_rvalues_as_lvalues);
131 op2_lvalue_kind = lvalue_p_1 (TREE_OPERAND (ref, 1),
132 treat_class_rvalues_as_lvalues);
136 op1_lvalue_kind = lvalue_p_1 (TREE_OPERAND (ref, 1),
137 treat_class_rvalues_as_lvalues);
138 op2_lvalue_kind = lvalue_p_1 (TREE_OPERAND (ref, 2),
139 treat_class_rvalues_as_lvalues);
146 return lvalue_p_1 (TREE_OPERAND (ref, 1),
147 treat_class_rvalues_as_lvalues);
150 return treat_class_rvalues_as_lvalues ? clk_class : clk_none;
154 return ((treat_class_rvalues_as_lvalues
155 && IS_AGGR_TYPE (TREE_TYPE (ref)))
156 ? clk_class : clk_none);
159 /* All functions (except non-static-member functions) are
161 return (DECL_NONSTATIC_MEMBER_FUNCTION_P (ref)
162 ? clk_none : clk_ordinary);
168 /* If one operand is not an lvalue at all, then this expression is
170 if (!op1_lvalue_kind || !op2_lvalue_kind)
173 /* Otherwise, it's an lvalue, and it has all the odd properties
174 contributed by either operand. */
175 op1_lvalue_kind = op1_lvalue_kind | op2_lvalue_kind;
176 /* It's not an ordinary lvalue if it involves either a bit-field or
178 if ((op1_lvalue_kind & ~clk_ordinary) != clk_none)
179 op1_lvalue_kind &= ~clk_ordinary;
180 return op1_lvalue_kind;
183 /* If REF is an lvalue, returns the kind of lvalue that REF is.
184 Otherwise, returns clk_none. Lvalues can be assigned, unless they
185 have TREE_READONLY, or unless they are FUNCTION_DECLs. Lvalues can
186 have their address taken, unless they have DECL_REGISTER. */
192 return lvalue_p_1 (ref, /*treat_class_rvalues_as_lvalues=*/0);
195 /* This differs from real_lvalue_p in that class rvalues are
196 considered lvalues. */
203 (lvalue_p_1 (ref, /*treat_class_rvalues_as_lvalues=*/1) != clk_none);
206 /* Return nonzero if REF is an lvalue valid for this language;
207 otherwise, print an error message and return zero. */
210 lvalue_or_else (ref, string)
214 int win = lvalue_p (ref);
216 error ("non-lvalue in %s", string);
220 /* Build a TARGET_EXPR, initializing the DECL with the VALUE. */
223 build_target_expr (decl, value)
229 t = build (TARGET_EXPR, TREE_TYPE (decl), decl, value,
230 maybe_build_cleanup (decl), NULL_TREE);
231 /* We always set TREE_SIDE_EFFECTS so that expand_expr does not
232 ignore the TARGET_EXPR. If there really turn out to be no
233 side-effects, then the optimizer should be able to get rid of
234 whatever code is generated anyhow. */
235 TREE_SIDE_EFFECTS (t) = 1;
240 /* INIT is a CALL_EXPR which needs info about its target.
241 TYPE is the type that this initialization should appear to have.
243 Build an encapsulation of the initialization to perform
244 and return it so that it can be processed by language-independent
245 and language-specific expression expanders. */
248 build_cplus_new (type, init)
256 /* Make sure that we're not trying to create an instance of an
258 abstract_virtuals_error (NULL_TREE, type);
260 if (TREE_CODE (init) != CALL_EXPR && TREE_CODE (init) != AGGR_INIT_EXPR)
261 return convert (type, init);
263 slot = build (VAR_DECL, type);
264 DECL_ARTIFICIAL (slot) = 1;
265 DECL_CONTEXT (slot) = current_function_decl;
266 layout_decl (slot, 0);
268 /* We split the CALL_EXPR into its function and its arguments here.
269 Then, in expand_expr, we put them back together. The reason for
270 this is that this expression might be a default argument
271 expression. In that case, we need a new temporary every time the
272 expression is used. That's what break_out_target_exprs does; it
273 replaces every AGGR_INIT_EXPR with a copy that uses a fresh
274 temporary slot. Then, expand_expr builds up a call-expression
275 using the new slot. */
276 fn = TREE_OPERAND (init, 0);
277 rval = build (AGGR_INIT_EXPR, type, fn, TREE_OPERAND (init, 1), slot);
278 TREE_SIDE_EFFECTS (rval) = 1;
279 AGGR_INIT_VIA_CTOR_P (rval)
280 = (TREE_CODE (fn) == ADDR_EXPR
281 && TREE_CODE (TREE_OPERAND (fn, 0)) == FUNCTION_DECL
282 && DECL_CONSTRUCTOR_P (TREE_OPERAND (fn, 0)));
283 rval = build_target_expr (slot, rval);
288 /* Buidl a TARGET_EXPR using INIT to initialize a new temporary of the
292 build_target_expr_with_type (init, type)
299 if (TREE_CODE (init) == TARGET_EXPR)
302 slot = build (VAR_DECL, type);
303 DECL_ARTIFICIAL (slot) = 1;
304 DECL_CONTEXT (slot) = current_function_decl;
305 layout_decl (slot, 0);
306 rval = build_target_expr (slot, init);
311 /* Like build_target_expr_with_type, but use the type of INIT. */
314 get_target_expr (init)
317 return build_target_expr_with_type (init, TREE_TYPE (init));
320 /* Recursively perform a preorder search EXP for CALL_EXPRs, making
321 copies where they are found. Returns a deep copy all nodes transitively
322 containing CALL_EXPRs. */
325 break_out_calls (exp)
328 register tree t1, t2 = NULL_TREE;
329 register enum tree_code code;
330 register int changed = 0;
333 if (exp == NULL_TREE)
336 code = TREE_CODE (exp);
338 if (code == CALL_EXPR)
339 return copy_node (exp);
341 /* Don't try and defeat a save_expr, as it should only be done once. */
342 if (code == SAVE_EXPR)
345 switch (TREE_CODE_CLASS (code))
350 case 'c': /* a constant */
351 case 't': /* a type node */
352 case 'x': /* something random, like an identifier or an ERROR_MARK. */
355 case 'd': /* A decl node */
356 #if 0 /* This is bogus. jason 9/21/94 */
358 t1 = break_out_calls (DECL_INITIAL (exp));
359 if (t1 != DECL_INITIAL (exp))
361 exp = copy_node (exp);
362 DECL_INITIAL (exp) = t1;
367 case 'b': /* A block node */
369 /* Don't know how to handle these correctly yet. Must do a
370 break_out_calls on all DECL_INITIAL values for local variables,
371 and also break_out_calls on all sub-blocks and sub-statements. */
376 case 'e': /* an expression */
377 case 'r': /* a reference */
378 case 's': /* an expression with side effects */
379 for (i = TREE_CODE_LENGTH (code) - 1; i >= 0; i--)
381 t1 = break_out_calls (TREE_OPERAND (exp, i));
382 if (t1 != TREE_OPERAND (exp, i))
384 exp = copy_node (exp);
385 TREE_OPERAND (exp, i) = t1;
390 case '<': /* a comparison expression */
391 case '2': /* a binary arithmetic expression */
392 t2 = break_out_calls (TREE_OPERAND (exp, 1));
393 if (t2 != TREE_OPERAND (exp, 1))
395 case '1': /* a unary arithmetic expression */
396 t1 = break_out_calls (TREE_OPERAND (exp, 0));
397 if (t1 != TREE_OPERAND (exp, 0))
401 if (TREE_CODE_LENGTH (code) == 1)
402 return build1 (code, TREE_TYPE (exp), t1);
404 return build (code, TREE_TYPE (exp), t1, t2);
411 /* Here is how primitive or already-canonicalized types' hash
412 codes are made. MUST BE CONSISTENT WITH tree.c !!! */
413 #define TYPE_HASH(TYPE) ((HOST_WIDE_INT) (TYPE) & 0777777)
415 /* Construct, lay out and return the type of methods belonging to class
416 BASETYPE and whose arguments are described by ARGTYPES and whose values
417 are described by RETTYPE. If each type exists already, reuse it. */
420 build_cplus_method_type (basetype, rettype, argtypes)
421 tree basetype, rettype, argtypes;
427 /* Make a node of the sort we want. */
428 t = make_node (METHOD_TYPE);
430 TYPE_METHOD_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype);
431 TREE_TYPE (t) = rettype;
432 ptype = build_pointer_type (basetype);
434 /* The actual arglist for this function includes a "hidden" argument
435 which is "this". Put it into the list of argument types. */
436 argtypes = tree_cons (NULL_TREE, ptype, argtypes);
437 TYPE_ARG_TYPES (t) = argtypes;
438 TREE_SIDE_EFFECTS (argtypes) = 1; /* Mark first argtype as "artificial". */
440 /* If we already have such a type, use the old one and free this one.
441 Note that it also frees up the above cons cell if found. */
442 hashcode = TYPE_HASH (basetype) + TYPE_HASH (rettype) +
443 type_hash_list (argtypes);
445 t = type_hash_canon (hashcode, t);
447 if (!COMPLETE_TYPE_P (t))
454 build_cplus_array_type_1 (elt_type, index_type)
460 if (elt_type == error_mark_node || index_type == error_mark_node)
461 return error_mark_node;
463 if (processing_template_decl
464 || uses_template_parms (elt_type)
465 || uses_template_parms (index_type))
467 t = make_node (ARRAY_TYPE);
468 TREE_TYPE (t) = elt_type;
469 TYPE_DOMAIN (t) = index_type;
472 t = build_array_type (elt_type, index_type);
474 /* Push these needs up so that initialization takes place
476 TYPE_NEEDS_CONSTRUCTING (t)
477 = TYPE_NEEDS_CONSTRUCTING (TYPE_MAIN_VARIANT (elt_type));
478 TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)
479 = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TYPE_MAIN_VARIANT (elt_type));
484 build_cplus_array_type (elt_type, index_type)
489 int type_quals = CP_TYPE_QUALS (elt_type);
491 elt_type = TYPE_MAIN_VARIANT (elt_type);
493 t = build_cplus_array_type_1 (elt_type, index_type);
495 if (type_quals != TYPE_UNQUALIFIED)
496 t = cp_build_qualified_type (t, type_quals);
501 /* Make a variant of TYPE, qualified with the TYPE_QUALS. Handles
502 arrays correctly. In particular, if TYPE is an array of T's, and
503 TYPE_QUALS is non-empty, returns an array of qualified T's. If
504 at attempt is made to qualify a type illegally, and COMPLAIN is
505 non-zero, an error is issued. If COMPLAIN is zero, error_mark_node
509 cp_build_qualified_type_real (type, type_quals, complain)
516 if (type == error_mark_node)
519 if (type_quals == CP_TYPE_QUALS (type))
522 /* A restrict-qualified pointer type must be a pointer (or reference)
523 to object or incomplete type. */
524 if ((type_quals & TYPE_QUAL_RESTRICT)
525 && TREE_CODE (type) != TEMPLATE_TYPE_PARM
526 && (!POINTER_TYPE_P (type)
527 || TYPE_PTRMEM_P (type)
528 || TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE))
531 cp_error ("`%T' cannot be `restrict'-qualified", type);
533 return error_mark_node;
535 type_quals &= ~TYPE_QUAL_RESTRICT;
538 if (type_quals != TYPE_UNQUALIFIED
539 && TREE_CODE (type) == FUNCTION_TYPE)
542 cp_error ("`%T' cannot be `const'-, `volatile'-, or `restrict'-qualified", type);
544 return error_mark_node;
545 type_quals = TYPE_UNQUALIFIED;
547 else if (TREE_CODE (type) == ARRAY_TYPE)
549 /* In C++, the qualification really applies to the array element
550 type. Obtain the appropriately qualified element type. */
553 = cp_build_qualified_type_real (TREE_TYPE (type),
557 if (element_type == error_mark_node)
558 return error_mark_node;
560 /* See if we already have an identically qualified type. */
561 for (t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
562 if (CP_TYPE_QUALS (t) == type_quals)
565 /* If we didn't already have it, create it now. */
568 /* Make a new array type, just like the old one, but with the
569 appropriately qualified element type. */
570 t = build_type_copy (type);
571 TREE_TYPE (t) = element_type;
574 /* Even if we already had this variant, we update
575 TYPE_NEEDS_CONSTRUCTING and TYPE_HAS_NONTRIVIAL_DESTRUCTOR in case
576 they changed since the variant was originally created.
578 This seems hokey; if there is some way to use a previous
579 variant *without* coming through here,
580 TYPE_NEEDS_CONSTRUCTING will never be updated. */
581 TYPE_NEEDS_CONSTRUCTING (t)
582 = TYPE_NEEDS_CONSTRUCTING (TYPE_MAIN_VARIANT (element_type));
583 TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)
584 = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TYPE_MAIN_VARIANT (element_type));
587 else if (TYPE_PTRMEMFUNC_P (type))
589 /* For a pointer-to-member type, we can't just return a
590 cv-qualified version of the RECORD_TYPE. If we do, we
591 haven't change the field that contains the actual pointer to
592 a method, and so TYPE_PTRMEMFUNC_FN_TYPE will be wrong. */
595 t = TYPE_PTRMEMFUNC_FN_TYPE (type);
596 t = cp_build_qualified_type_real (t, type_quals, complain);
597 return build_ptrmemfunc_type (t);
600 /* Retrieve (or create) the appropriately qualified variant. */
601 result = build_qualified_type (type, type_quals);
603 /* If this was a pointer-to-method type, and we just made a copy,
604 then we need to clear the cached associated
605 pointer-to-member-function type; it is not valid for the new
608 && TREE_CODE (type) == POINTER_TYPE
609 && TREE_CODE (TREE_TYPE (type)) == METHOD_TYPE)
610 TYPE_SET_PTRMEMFUNC_TYPE (result, NULL_TREE);
615 /* Returns the canonical version of TYPE. In other words, if TYPE is
616 a typedef, returns the underlying type. The cv-qualification of
617 the type returned matches the type input; they will always be
621 canonical_type_variant (t)
624 return cp_build_qualified_type (TYPE_MAIN_VARIANT (t), CP_TYPE_QUALS (t));
627 /* Makes new binfos for the indirect bases under BINFO, and updates
628 BINFO_OFFSET for them and their bases. */
631 unshare_base_binfos (binfo)
634 tree binfos = BINFO_BASETYPES (binfo);
638 if (binfos == NULL_TREE)
641 /* Now unshare the structure beneath BINFO. */
642 for (j = TREE_VEC_LENGTH (binfos)-1;
645 tree base_binfo = TREE_VEC_ELT (binfos, j);
646 new_binfo = TREE_VEC_ELT (binfos, j)
647 = make_binfo (BINFO_OFFSET (base_binfo),
649 BINFO_VTABLE (base_binfo),
650 BINFO_VIRTUALS (base_binfo));
651 TREE_VIA_PUBLIC (new_binfo) = TREE_VIA_PUBLIC (base_binfo);
652 TREE_VIA_PROTECTED (new_binfo) = TREE_VIA_PROTECTED (base_binfo);
653 TREE_VIA_VIRTUAL (new_binfo) = TREE_VIA_VIRTUAL (base_binfo);
654 BINFO_INHERITANCE_CHAIN (new_binfo) = binfo;
655 BINFO_PRIMARY_BASE_OF (new_binfo) = NULL_TREE;
656 unshare_base_binfos (new_binfo);
661 /* Hashing of lists so that we don't make duplicates.
662 The entry point is `list_hash_canon'. */
664 /* Now here is the hash table. When recording a list, it is added
665 to the slot whose index is the hash code mod the table size.
666 Note that the hash table is used for several kinds of lists.
667 While all these live in the same table, they are completely independent,
668 and the hash code is computed differently for each of these. */
670 static htab_t list_hash_table;
679 /* Compare ENTRY (an entry in the hash table) with DATA (a list_proxy
680 for a node we are thinking about adding). */
683 list_hash_eq (entry, data)
687 tree t = (tree) entry;
688 struct list_proxy *proxy = (struct list_proxy *) data;
690 return (TREE_VALUE (t) == proxy->value
691 && TREE_PURPOSE (t) == proxy->purpose
692 && TREE_CHAIN (t) == proxy->chain);
695 /* Compute a hash code for a list (chain of TREE_LIST nodes
696 with goodies in the TREE_PURPOSE, TREE_VALUE, and bits of the
697 TREE_COMMON slots), by adding the hash codes of the individual entries. */
700 list_hash_pieces (purpose, value, chain)
705 hashval_t hashcode = 0;
708 hashcode += TYPE_HASH (chain);
711 hashcode += TYPE_HASH (value);
715 hashcode += TYPE_HASH (purpose);
721 /* Hash an already existing TREE_LIST. */
728 return list_hash_pieces (TREE_PURPOSE (t),
733 /* Given list components PURPOSE, VALUE, AND CHAIN, return the canonical
734 object for an identical list if one already exists. Otherwise, build a
735 new one, and record it as the canonical object. */
738 hash_tree_cons (purpose, value, chain)
739 tree purpose, value, chain;
743 struct list_proxy proxy;
745 /* Hash the list node. */
746 hashcode = list_hash_pieces (purpose, value, chain);
747 /* Create a proxy for the TREE_LIST we would like to create. We
748 don't actually create it so as to avoid creating garbage. */
749 proxy.purpose = purpose;
752 /* See if it is already in the table. */
753 slot = htab_find_slot_with_hash (list_hash_table, &proxy, hashcode,
755 /* If not, create a new node. */
757 *slot = (PTR) tree_cons (purpose, value, chain);
761 /* Constructor for hashed lists. */
764 hash_tree_chain (value, chain)
767 return hash_tree_cons (NULL_TREE, value, chain);
770 /* Similar, but used for concatenating two lists. */
773 hash_chainon (list1, list2)
780 if (TREE_CHAIN (list1) == NULL_TREE)
781 return hash_tree_chain (TREE_VALUE (list1), list2);
782 return hash_tree_chain (TREE_VALUE (list1),
783 hash_chainon (TREE_CHAIN (list1), list2));
786 /* Build an association between TYPE and some parameters:
788 OFFSET is the offset added to `this' to convert it to a pointer
791 BINFO is the base binfo to use, if we are deriving from one. This
792 is necessary, as we want specialized parent binfos from base
793 classes, so that the VTABLE_NAMEs of bases are for the most derived
794 type, instead of the simple type.
796 VTABLE is the virtual function table with which to initialize
797 sub-objects of type TYPE.
799 VIRTUALS are the virtual functions sitting in VTABLE. */
802 make_binfo (offset, binfo, vtable, virtuals)
804 tree vtable, virtuals;
806 tree new_binfo = make_tree_vec (11);
809 if (TREE_CODE (binfo) == TREE_VEC)
810 type = BINFO_TYPE (binfo);
814 binfo = CLASS_TYPE_P (type) ? TYPE_BINFO (binfo) : NULL_TREE;
817 TREE_TYPE (new_binfo) = TYPE_MAIN_VARIANT (type);
818 BINFO_OFFSET (new_binfo) = offset;
819 BINFO_VTABLE (new_binfo) = vtable;
820 BINFO_VIRTUALS (new_binfo) = virtuals;
822 if (binfo && BINFO_BASETYPES (binfo) != NULL_TREE)
823 BINFO_BASETYPES (new_binfo) = copy_node (BINFO_BASETYPES (binfo));
827 /* Return the binfo value for ELEM in TYPE. */
830 binfo_value (elem, type)
834 if (get_base_distance (elem, type, 0, (tree *)0) == -2)
835 compiler_error ("base class `%s' ambiguous in binfo_value",
836 TYPE_NAME_STRING (elem));
838 return TYPE_BINFO (type);
839 if (TREE_CODE (elem) == RECORD_TYPE && TYPE_BINFO (elem) == type)
841 return get_binfo (elem, type, 0);
844 /* Return a TREE_LIST whose TREE_VALUE nodes along the
845 BINFO_INHERITANCE_CHAIN for BINFO, but in the opposite order. In
846 other words, while the BINFO_INHERITANCE_CHAIN goes from base
847 classes to derived classes, the reversed path goes from derived
848 classes to base classes. */
856 reversed_path = NULL_TREE;
859 reversed_path = tree_cons (NULL_TREE, binfo, reversed_path);
860 binfo = BINFO_INHERITANCE_CHAIN (binfo);
863 return reversed_path;
873 fprintf (stderr, "type \"%s\", offset = ",
874 TYPE_NAME_STRING (BINFO_TYPE (elem)));
875 fprintf (stderr, HOST_WIDE_INT_PRINT_DEC,
876 TREE_INT_CST_LOW (BINFO_OFFSET (elem)));
877 fprintf (stderr, "\nvtable type:\n");
878 debug_tree (BINFO_TYPE (elem));
879 if (BINFO_VTABLE (elem))
880 fprintf (stderr, "vtable decl \"%s\"\n",
881 IDENTIFIER_POINTER (DECL_NAME (get_vtbl_decl_for_binfo (elem))));
883 fprintf (stderr, "no vtable decl yet\n");
884 fprintf (stderr, "virtuals:\n");
885 virtuals = BINFO_VIRTUALS (elem);
890 tree fndecl = TREE_VALUE (virtuals);
891 fprintf (stderr, "%s [%ld =? %ld]\n",
892 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (fndecl)),
893 (long) n, (long) TREE_INT_CST_LOW (DECL_VINDEX (fndecl)));
895 virtuals = TREE_CHAIN (virtuals);
904 if (TREE_CODE (t) == FUNCTION_DECL)
906 else if (TREE_CODE (t) == OVERLOAD)
908 for (i=0; t; t = OVL_CHAIN (t))
913 my_friendly_abort (359);
921 /* A baselink is also considered an overloaded function. */
922 if (TREE_CODE (x) == OFFSET_REF)
923 x = TREE_OPERAND (x, 1);
926 return (TREE_CODE (x) == FUNCTION_DECL
927 || TREE_CODE (x) == TEMPLATE_ID_EXPR
928 || DECL_FUNCTION_TEMPLATE_P (x)
929 || TREE_CODE (x) == OVERLOAD);
933 really_overloaded_fn (x)
936 /* A baselink is also considered an overloaded function. */
937 if (TREE_CODE (x) == OFFSET_REF)
938 x = TREE_OPERAND (x, 1);
941 return (TREE_CODE (x) == OVERLOAD
942 && (TREE_CHAIN (x) != NULL_TREE
943 || DECL_FUNCTION_TEMPLATE_P (OVL_FUNCTION (x))));
950 my_friendly_assert (is_overloaded_fn (from), 9);
951 /* A baselink is also considered an overloaded function. */
952 if (BASELINK_P (from))
953 from = TREE_VALUE (from);
954 return OVL_CURRENT (from);
957 /* Returns nonzero if T is a ->* or .* expression that refers to a
964 return (TREE_CODE (t) == OFFSET_REF
965 && TYPE_PTRMEMFUNC_P (TREE_TYPE (TREE_OPERAND (t, 1))));
968 /* Return a new OVL node, concatenating it with the old one. */
971 ovl_cons (decl, chain)
975 tree result = make_node (OVERLOAD);
976 TREE_TYPE (result) = unknown_type_node;
977 OVL_FUNCTION (result) = decl;
978 TREE_CHAIN (result) = chain;
983 /* Build a new overloaded function. If this is the first one,
984 just return it; otherwise, ovl_cons the _DECLs */
987 build_overload (decl, chain)
991 if (! chain && TREE_CODE (decl) != TEMPLATE_DECL)
993 if (chain && TREE_CODE (chain) != OVERLOAD)
994 chain = ovl_cons (chain, NULL_TREE);
995 return ovl_cons (decl, chain);
998 /* True if fn is in ovl. */
1001 ovl_member (fn, ovl)
1005 if (ovl == NULL_TREE)
1007 if (TREE_CODE (ovl) != OVERLOAD)
1009 for (; ovl; ovl = OVL_CHAIN (ovl))
1010 if (OVL_FUNCTION (ovl) == fn)
1016 is_aggr_type_2 (t1, t2)
1019 if (TREE_CODE (t1) != TREE_CODE (t2))
1021 return IS_AGGR_TYPE (t1) && IS_AGGR_TYPE (t2);
1024 /* Returns non-zero if CODE is the code for a statement. */
1027 cp_statement_code_p (code)
1028 enum tree_code code;
1035 case CTOR_INITIALIZER:
1048 #define PRINT_RING_SIZE 4
1051 lang_printable_name (decl, v)
1055 static tree decl_ring[PRINT_RING_SIZE];
1056 static char *print_ring[PRINT_RING_SIZE];
1057 static int ring_counter;
1060 /* Only cache functions. */
1062 || TREE_CODE (decl) != FUNCTION_DECL
1063 || DECL_LANG_SPECIFIC (decl) == 0)
1064 return lang_decl_name (decl, v);
1066 /* See if this print name is lying around. */
1067 for (i = 0; i < PRINT_RING_SIZE; i++)
1068 if (decl_ring[i] == decl)
1069 /* yes, so return it. */
1070 return print_ring[i];
1072 if (++ring_counter == PRINT_RING_SIZE)
1075 if (current_function_decl != NULL_TREE)
1077 if (decl_ring[ring_counter] == current_function_decl)
1079 if (ring_counter == PRINT_RING_SIZE)
1081 if (decl_ring[ring_counter] == current_function_decl)
1082 my_friendly_abort (106);
1085 if (print_ring[ring_counter])
1086 free (print_ring[ring_counter]);
1088 print_ring[ring_counter] = xstrdup (lang_decl_name (decl, v));
1089 decl_ring[ring_counter] = decl;
1090 return print_ring[ring_counter];
1093 /* Build the FUNCTION_TYPE or METHOD_TYPE which may throw exceptions
1094 listed in RAISES. */
1097 build_exception_variant (type, raises)
1101 tree v = TYPE_MAIN_VARIANT (type);
1102 int type_quals = TYPE_QUALS (type);
1104 for (; v; v = TYPE_NEXT_VARIANT (v))
1105 if (TYPE_QUALS (v) == type_quals
1106 && comp_except_specs (raises, TYPE_RAISES_EXCEPTIONS (v), 1))
1109 /* Need to build a new variant. */
1110 v = build_type_copy (type);
1111 TYPE_RAISES_EXCEPTIONS (v) = raises;
1115 /* Given a TEMPLATE_TEMPLATE_PARM or BOUND_TEMPLATE_TEMPLATE_PARM
1116 node T, create a new one together with its
1117 lang_specific field and its corresponding *_DECL node.
1118 If NEWARGS is not NULL_TREE, this parameter is bound with new set of
1122 copy_template_template_parm (t, newargs)
1126 tree decl = TYPE_NAME (t);
1129 if (newargs == NULL_TREE)
1131 t2 = make_aggr_type (TREE_CODE (t));
1132 decl = copy_decl (decl);
1134 /* No need to copy these. */
1135 TEMPLATE_TYPE_PARM_INDEX (t2) = TEMPLATE_TYPE_PARM_INDEX (t);
1136 TEMPLATE_TEMPLATE_PARM_TEMPLATE_INFO (t2)
1137 = TEMPLATE_TEMPLATE_PARM_TEMPLATE_INFO (t);
1141 t2 = make_aggr_type (BOUND_TEMPLATE_TEMPLATE_PARM);
1142 decl = build_decl (TYPE_DECL, DECL_NAME (decl), NULL_TREE);
1144 /* These nodes have to be created to reflect new TYPE_DECL and template
1146 TEMPLATE_TYPE_PARM_INDEX (t2) = copy_node (TEMPLATE_TYPE_PARM_INDEX (t));
1147 TEMPLATE_PARM_DECL (TEMPLATE_TYPE_PARM_INDEX (t2)) = decl;
1148 TEMPLATE_TEMPLATE_PARM_TEMPLATE_INFO (t2)
1149 = tree_cons (TEMPLATE_TEMPLATE_PARM_TEMPLATE_DECL (t),
1150 newargs, NULL_TREE);
1153 TREE_TYPE (decl) = t2;
1154 TYPE_NAME (t2) = decl;
1155 TYPE_STUB_DECL (t2) = decl;
1160 /* Apply FUNC to all the sub-trees of TP in a pre-order traversal.
1161 FUNC is called with the DATA and the address of each sub-tree. If
1162 FUNC returns a non-NULL value, the traversal is aborted, and the
1163 value returned by FUNC is returned. If HTAB is non-NULL it is used
1164 to record the nodes visited, and to avoid visiting a node more than
1168 walk_tree (tp, func, data, htab)
1174 enum tree_code code;
1178 #define WALK_SUBTREE(NODE) \
1181 result = walk_tree (&(NODE), func, data, htab); \
1187 /* Skip empty subtrees. */
1195 /* Don't walk the same tree twice, if the user has requested
1196 that we avoid doing so. */
1197 if (htab_find (htab, *tp))
1199 /* If we haven't already seen this node, add it to the table. */
1200 slot = htab_find_slot (htab, *tp, INSERT);
1204 /* Call the function. */
1206 result = (*func) (tp, &walk_subtrees, data);
1208 /* If we found something, return it. */
1212 /* Even if we didn't, FUNC may have decided that there was nothing
1213 interesting below this point in the tree. */
1217 code = TREE_CODE (*tp);
1219 /* Handle common cases up front. */
1220 if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (code))
1221 || TREE_CODE_CLASS (code) == 'r'
1222 || TREE_CODE_CLASS (code) == 's')
1226 /* Set lineno here so we get the right instantiation context
1227 if we call instantiate_decl from inlinable_function_p. */
1228 if (statement_code_p (code) && !STMT_LINENO_FOR_FN_P (*tp))
1229 lineno = STMT_LINENO (*tp);
1231 /* Walk over all the sub-trees of this operand. */
1232 len = first_rtl_op (code);
1233 /* TARGET_EXPRs are peculiar: operands 1 and 3 can be the same.
1234 But, we only want to walk once. */
1235 if (code == TARGET_EXPR
1236 && TREE_OPERAND (*tp, 3) == TREE_OPERAND (*tp, 1))
1238 /* Go through the subtrees. We need to do this in forward order so
1239 that the scope of a FOR_EXPR is handled properly. */
1240 for (i = 0; i < len; ++i)
1241 WALK_SUBTREE (TREE_OPERAND (*tp, i));
1243 /* For statements, we also walk the chain so that we cover the
1244 entire statement tree. */
1245 if (statement_code_p (code))
1247 if (code == DECL_STMT
1248 && DECL_STMT_DECL (*tp)
1249 && DECL_P (DECL_STMT_DECL (*tp)))
1251 /* Walk the DECL_INITIAL and DECL_SIZE. We don't want to walk
1252 into declarations that are just mentioned, rather than
1253 declared; they don't really belong to this part of the tree.
1254 And, we can see cycles: the initializer for a declaration can
1255 refer to the declaration itself. */
1256 WALK_SUBTREE (DECL_INITIAL (DECL_STMT_DECL (*tp)));
1257 WALK_SUBTREE (DECL_SIZE (DECL_STMT_DECL (*tp)));
1258 WALK_SUBTREE (DECL_SIZE_UNIT (DECL_STMT_DECL (*tp)));
1261 /* This can be tail-recursion optimized if we write it this way. */
1262 return walk_tree (&TREE_CHAIN (*tp), func, data, htab);
1265 /* We didn't find what we were looking for. */
1268 else if (TREE_CODE_CLASS (code) == 'd')
1270 WALK_SUBTREE (TREE_TYPE (*tp));
1272 /* We didn't find what we were looking for. */
1276 /* Not one of the easy cases. We must explicitly go through the
1281 case IDENTIFIER_NODE:
1286 case TEMPLATE_TEMPLATE_PARM:
1287 case BOUND_TEMPLATE_TEMPLATE_PARM:
1288 case TEMPLATE_PARM_INDEX:
1289 case TEMPLATE_TYPE_PARM:
1300 /* None of thse have subtrees other than those already walked
1305 WALK_SUBTREE (TREE_TYPE (*tp));
1309 case REFERENCE_TYPE:
1310 WALK_SUBTREE (TREE_TYPE (*tp));
1314 /* A BASELINK_P's TREE_PURPOSE is a BINFO, and hence circular. */
1315 if (!BASELINK_P (*tp))
1316 WALK_SUBTREE (TREE_PURPOSE (*tp));
1317 WALK_SUBTREE (TREE_VALUE (*tp));
1318 WALK_SUBTREE (TREE_CHAIN (*tp));
1322 WALK_SUBTREE (OVL_FUNCTION (*tp));
1323 WALK_SUBTREE (OVL_CHAIN (*tp));
1328 int len = TREE_VEC_LENGTH (*tp);
1330 WALK_SUBTREE (TREE_VEC_ELT (*tp, len));
1335 WALK_SUBTREE (TREE_REALPART (*tp));
1336 WALK_SUBTREE (TREE_IMAGPART (*tp));
1340 WALK_SUBTREE (CONSTRUCTOR_ELTS (*tp));
1344 WALK_SUBTREE (TYPE_METHOD_BASETYPE (*tp));
1348 WALK_SUBTREE (TREE_TYPE (*tp));
1350 tree arg = TYPE_ARG_TYPES (*tp);
1352 /* We never want to walk into default arguments. */
1353 for (; arg; arg = TREE_CHAIN (arg))
1354 WALK_SUBTREE (TREE_VALUE (arg));
1359 WALK_SUBTREE (TREE_TYPE (*tp));
1360 WALK_SUBTREE (TYPE_DOMAIN (*tp));
1364 WALK_SUBTREE (TYPE_MIN_VALUE (*tp));
1365 WALK_SUBTREE (TYPE_MAX_VALUE (*tp));
1369 WALK_SUBTREE (TREE_TYPE (*tp));
1370 WALK_SUBTREE (TYPE_OFFSET_BASETYPE (*tp));
1374 if (TYPE_PTRMEMFUNC_P (*tp))
1375 WALK_SUBTREE (TYPE_PTRMEMFUNC_FN_TYPE (*tp));
1379 my_friendly_abort (19990803);
1382 /* We didn't find what we were looking for. */
1388 /* Like walk_tree, but does not walk duplicate nodes more than
1392 walk_tree_without_duplicates (tp, func, data)
1400 htab = htab_create (37, htab_hash_pointer, htab_eq_pointer, NULL);
1401 result = walk_tree (tp, func, data, htab);
1406 /* Called from count_trees via walk_tree. */
1409 count_trees_r (tp, walk_subtrees, data)
1410 tree *tp ATTRIBUTE_UNUSED;
1411 int *walk_subtrees ATTRIBUTE_UNUSED;
1418 /* Debugging function for measuring the rough complexity of a tree
1426 walk_tree_without_duplicates (&t, count_trees_r, &n_trees);
1430 /* Called from verify_stmt_tree via walk_tree. */
1433 verify_stmt_tree_r (tp, walk_subtrees, data)
1435 int *walk_subtrees ATTRIBUTE_UNUSED;
1439 htab_t *statements = (htab_t *) data;
1442 if (!statement_code_p (TREE_CODE (t)))
1445 /* If this statement is already present in the hash table, then
1446 there is a circularity in the statement tree. */
1447 if (htab_find (*statements, t))
1448 my_friendly_abort (20000727);
1450 slot = htab_find_slot (*statements, t, INSERT);
1456 /* Debugging function to check that the statement T has not been
1457 corrupted. For now, this function simply checks that T contains no
1461 verify_stmt_tree (t)
1465 statements = htab_create (37, htab_hash_pointer, htab_eq_pointer, NULL);
1466 walk_tree (&t, verify_stmt_tree_r, &statements, NULL);
1467 htab_delete (statements);
1470 /* Called from find_tree via walk_tree. */
1473 find_tree_r (tp, walk_subtrees, data)
1475 int *walk_subtrees ATTRIBUTE_UNUSED;
1478 if (*tp == (tree) data)
1484 /* Returns X if X appears in the tree structure rooted at T. */
1491 return walk_tree_without_duplicates (&t, find_tree_r, x);
1494 /* Passed to walk_tree. Checks for the use of types with no linkage. */
1497 no_linkage_helper (tp, walk_subtrees, data)
1499 int *walk_subtrees ATTRIBUTE_UNUSED;
1500 void *data ATTRIBUTE_UNUSED;
1505 && (CLASS_TYPE_P (t) || TREE_CODE (t) == ENUMERAL_TYPE)
1506 && (decl_function_context (TYPE_MAIN_DECL (t))
1507 || TYPE_ANONYMOUS_P (t)))
1512 /* Check if the type T depends on a type with no linkage and if so, return
1516 no_linkage_check (t)
1519 /* There's no point in checking linkage on template functions; we
1520 can't know their complete types. */
1521 if (processing_template_decl)
1524 t = walk_tree_without_duplicates (&t, no_linkage_helper, NULL);
1525 if (t != error_mark_node)
1530 /* Passed to walk_tree. Copies the node pointed to, if appropriate. */
1533 copy_tree_r (tp, walk_subtrees, data)
1536 void *data ATTRIBUTE_UNUSED;
1538 enum tree_code code = TREE_CODE (*tp);
1540 /* We make copies of most nodes. */
1541 if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (code))
1542 || TREE_CODE_CLASS (code) == 'r'
1543 || TREE_CODE_CLASS (code) == 'c'
1544 || TREE_CODE_CLASS (code) == 's'
1545 || code == TREE_LIST
1547 || code == OVERLOAD)
1549 /* Because the chain gets clobbered when we make a copy, we save it
1551 tree chain = TREE_CHAIN (*tp);
1553 /* Copy the node. */
1554 *tp = copy_node (*tp);
1556 /* Now, restore the chain, if appropriate. That will cause
1557 walk_tree to walk into the chain as well. */
1558 if (code == PARM_DECL || code == TREE_LIST || code == OVERLOAD
1559 || statement_code_p (code))
1560 TREE_CHAIN (*tp) = chain;
1562 /* For now, we don't update BLOCKs when we make copies. So, we
1563 have to nullify all scope-statements. */
1564 if (TREE_CODE (*tp) == SCOPE_STMT)
1565 SCOPE_STMT_BLOCK (*tp) = NULL_TREE;
1567 else if (code == TEMPLATE_TEMPLATE_PARM
1568 || code == BOUND_TEMPLATE_TEMPLATE_PARM)
1569 /* These must be copied specially. */
1570 *tp = copy_template_template_parm (*tp, NULL_TREE);
1571 else if (TREE_CODE_CLASS (code) == 't')
1572 /* There's no need to copy types, or anything beneath them. */
1578 #ifdef GATHER_STATISTICS
1579 extern int depth_reached;
1583 print_lang_statistics ()
1585 print_search_statistics ();
1586 print_class_statistics ();
1587 #ifdef GATHER_STATISTICS
1588 fprintf (stderr, "maximum template instantiation depth reached: %d\n",
1593 /* Return, as an INTEGER_CST node, the number of elements for TYPE
1594 (which is an ARRAY_TYPE). This counts only elements of the top
1598 array_type_nelts_top (type)
1601 return fold (build (PLUS_EXPR, sizetype,
1602 array_type_nelts (type),
1606 /* Return, as an INTEGER_CST node, the number of elements for TYPE
1607 (which is an ARRAY_TYPE). This one is a recursive count of all
1608 ARRAY_TYPEs that are clumped together. */
1611 array_type_nelts_total (type)
1614 tree sz = array_type_nelts_top (type);
1615 type = TREE_TYPE (type);
1616 while (TREE_CODE (type) == ARRAY_TYPE)
1618 tree n = array_type_nelts_top (type);
1619 sz = fold (build (MULT_EXPR, sizetype, sz, n));
1620 type = TREE_TYPE (type);
1625 /* Called from break_out_target_exprs via mapcar. */
1628 bot_manip (tp, walk_subtrees, data)
1633 splay_tree target_remap = ((splay_tree) data);
1636 if (TREE_CONSTANT (t))
1638 /* There can't be any TARGET_EXPRs or their slot variables below
1639 this point. We used to check !TREE_SIDE_EFFECTS, but then we
1640 failed to copy an ADDR_EXPR of the slot VAR_DECL. */
1644 if (TREE_CODE (t) == TARGET_EXPR)
1648 if (TREE_CODE (TREE_OPERAND (t, 1)) == AGGR_INIT_EXPR)
1650 mark_used (TREE_OPERAND (TREE_OPERAND (TREE_OPERAND (t, 1), 0), 0));
1652 (TREE_TYPE (t), break_out_target_exprs (TREE_OPERAND (t, 1)));
1656 u = build_target_expr_with_type
1657 (break_out_target_exprs (TREE_OPERAND (t, 1)), TREE_TYPE (t));
1660 /* Map the old variable to the new one. */
1661 splay_tree_insert (target_remap,
1662 (splay_tree_key) TREE_OPERAND (t, 0),
1663 (splay_tree_value) TREE_OPERAND (u, 0));
1665 /* Replace the old expression with the new version. */
1667 /* We don't have to go below this point; the recursive call to
1668 break_out_target_exprs will have handled anything below this
1673 else if (TREE_CODE (t) == CALL_EXPR)
1674 mark_used (TREE_OPERAND (TREE_OPERAND (t, 0), 0));
1676 /* Make a copy of this node. */
1677 return copy_tree_r (tp, walk_subtrees, NULL);
1680 /* Replace all remapped VAR_DECLs in T with their new equivalents.
1681 DATA is really a splay-tree mapping old variables to new
1685 bot_replace (t, walk_subtrees, data)
1687 int *walk_subtrees ATTRIBUTE_UNUSED;
1690 splay_tree target_remap = ((splay_tree) data);
1692 if (TREE_CODE (*t) == VAR_DECL)
1694 splay_tree_node n = splay_tree_lookup (target_remap,
1695 (splay_tree_key) *t);
1697 *t = (tree) n->value;
1703 /* When we parse a default argument expression, we may create
1704 temporary variables via TARGET_EXPRs. When we actually use the
1705 default-argument expression, we make a copy of the expression, but
1706 we must replace the temporaries with appropriate local versions. */
1709 break_out_target_exprs (t)
1712 static int target_remap_count;
1713 static splay_tree target_remap;
1715 if (!target_remap_count++)
1716 target_remap = splay_tree_new (splay_tree_compare_pointers,
1717 /*splay_tree_delete_key_fn=*/NULL,
1718 /*splay_tree_delete_value_fn=*/NULL);
1719 walk_tree (&t, bot_manip, target_remap, NULL);
1720 walk_tree (&t, bot_replace, target_remap, NULL);
1722 if (!--target_remap_count)
1724 splay_tree_delete (target_remap);
1725 target_remap = NULL;
1731 /* Obstack used for allocating nodes in template function and variable
1734 /* Similar to `build_nt', except that we set TREE_COMPLEXITY to be the
1735 current line number. */
1738 build_min_nt VPARAMS ((enum tree_code code, ...))
1740 #ifndef ANSI_PROTOTYPES
1741 enum tree_code code;
1745 register int length;
1750 #ifndef ANSI_PROTOTYPES
1751 code = va_arg (p, enum tree_code);
1754 t = make_node (code);
1755 length = TREE_CODE_LENGTH (code);
1756 TREE_COMPLEXITY (t) = lineno;
1758 for (i = 0; i < length; i++)
1760 tree x = va_arg (p, tree);
1761 TREE_OPERAND (t, i) = x;
1768 /* Similar to `build', except we set TREE_COMPLEXITY to the current
1772 build_min VPARAMS ((enum tree_code code, tree tt, ...))
1774 #ifndef ANSI_PROTOTYPES
1775 enum tree_code code;
1780 register int length;
1785 #ifndef ANSI_PROTOTYPES
1786 code = va_arg (p, enum tree_code);
1787 tt = va_arg (p, tree);
1790 t = make_node (code);
1791 length = TREE_CODE_LENGTH (code);
1793 TREE_COMPLEXITY (t) = lineno;
1795 for (i = 0; i < length; i++)
1797 tree x = va_arg (p, tree);
1798 TREE_OPERAND (t, i) = x;
1805 /* Returns an INTEGER_CST (of type `int') corresponding to I.
1806 Multiple calls with the same value of I may or may not yield the
1807 same node; therefore, callers should never modify the node
1811 build_shared_int_cst (i)
1814 static tree cache[256];
1817 return build_int_2 (i, 0);
1820 cache[i] = build_int_2 (i, 0);
1829 if (TREE_CODE (t) == TYPE_DECL)
1832 return TYPE_STUB_DECL (t);
1833 if (t == error_mark_node)
1836 my_friendly_abort (42);
1838 /* Stop compiler from complaining control reaches end of non-void function. */
1842 /* Return first vector element whose BINFO_TYPE is ELEM.
1843 Return 0 if ELEM is not in VEC. VEC may be NULL_TREE. */
1846 vec_binfo_member (elem, vec)
1852 for (i = 0; i < TREE_VEC_LENGTH (vec); ++i)
1853 if (same_type_p (elem, BINFO_TYPE (TREE_VEC_ELT (vec, i))))
1854 return TREE_VEC_ELT (vec, i);
1859 /* Returns the namespace that contains DECL, whether directly or
1863 decl_namespace_context (decl)
1868 if (TREE_CODE (decl) == NAMESPACE_DECL)
1870 else if (TYPE_P (decl))
1871 decl = CP_DECL_CONTEXT (TYPE_MAIN_DECL (decl));
1873 decl = CP_DECL_CONTEXT (decl);
1877 /* Return truthvalue of whether T1 is the same tree structure as T2.
1878 Return 1 if they are the same.
1879 Return 0 if they are understandably different.
1880 Return -1 if either contains tree structure not understood by
1884 cp_tree_equal (t1, t2)
1887 register enum tree_code code1, code2;
1892 if (t1 == 0 || t2 == 0)
1895 code1 = TREE_CODE (t1);
1896 code2 = TREE_CODE (t2);
1898 if (code1 == NOP_EXPR || code1 == CONVERT_EXPR || code1 == NON_LVALUE_EXPR)
1900 if (code2 == NOP_EXPR || code2 == CONVERT_EXPR || code2 == NON_LVALUE_EXPR)
1901 return cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
1903 return cp_tree_equal (TREE_OPERAND (t1, 0), t2);
1905 else if (code2 == NOP_EXPR || code2 == CONVERT_EXPR
1906 || code2 == NON_LVALUE_EXPR)
1907 return cp_tree_equal (t1, TREE_OPERAND (t2, 0));
1915 return TREE_INT_CST_LOW (t1) == TREE_INT_CST_LOW (t2)
1916 && TREE_INT_CST_HIGH (t1) == TREE_INT_CST_HIGH (t2);
1919 return REAL_VALUES_EQUAL (TREE_REAL_CST (t1), TREE_REAL_CST (t2));
1922 return TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
1923 && !memcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
1924 TREE_STRING_LENGTH (t1));
1927 /* We need to do this when determining whether or not two
1928 non-type pointer to member function template arguments
1930 if (!(same_type_p (TREE_TYPE (t1), TREE_TYPE (t2))
1931 /* The first operand is RTL. */
1932 && TREE_OPERAND (t1, 0) == TREE_OPERAND (t2, 0)))
1934 return cp_tree_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
1937 cmp = cp_tree_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2));
1940 cmp = cp_tree_equal (TREE_VALUE (t1), TREE_VALUE (t2));
1943 return cp_tree_equal (TREE_CHAIN (t1), TREE_CHAIN (t2));
1946 return cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
1949 cmp = cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
1952 return simple_cst_list_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
1955 /* Special case: if either target is an unallocated VAR_DECL,
1956 it means that it's going to be unified with whatever the
1957 TARGET_EXPR is really supposed to initialize, so treat it
1958 as being equivalent to anything. */
1959 if ((TREE_CODE (TREE_OPERAND (t1, 0)) == VAR_DECL
1960 && DECL_NAME (TREE_OPERAND (t1, 0)) == NULL_TREE
1961 && !DECL_RTL_SET_P (TREE_OPERAND (t1, 0)))
1962 || (TREE_CODE (TREE_OPERAND (t2, 0)) == VAR_DECL
1963 && DECL_NAME (TREE_OPERAND (t2, 0)) == NULL_TREE
1964 && !DECL_RTL_SET_P (TREE_OPERAND (t2, 0))))
1967 cmp = cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
1970 return cp_tree_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
1972 case WITH_CLEANUP_EXPR:
1973 cmp = cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
1976 return cp_tree_equal (TREE_OPERAND (t1, 2), TREE_OPERAND (t1, 2));
1979 if (TREE_OPERAND (t1, 1) == TREE_OPERAND (t2, 1))
1980 return cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
1989 case TEMPLATE_PARM_INDEX:
1990 return TEMPLATE_PARM_IDX (t1) == TEMPLATE_PARM_IDX (t2)
1991 && TEMPLATE_PARM_LEVEL (t1) == TEMPLATE_PARM_LEVEL (t2);
1995 if (TREE_CODE (TREE_OPERAND (t1, 0)) != TREE_CODE (TREE_OPERAND (t2, 0)))
1997 if (TYPE_P (TREE_OPERAND (t1, 0)))
1998 return same_type_p (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
2002 /* Two pointer-to-members are the same if they point to the same
2003 field or function in the same class. */
2004 return (PTRMEM_CST_MEMBER (t1) == PTRMEM_CST_MEMBER (t2)
2005 && same_type_p (PTRMEM_CST_CLASS (t1), PTRMEM_CST_CLASS (t2)));
2011 switch (TREE_CODE_CLASS (code1))
2023 for (i = 0; i < TREE_CODE_LENGTH (code1); ++i)
2025 cmp = cp_tree_equal (TREE_OPERAND (t1, i), TREE_OPERAND (t2, i));
2033 return same_type_p (t1, t2) ? 1 : 0;
2039 /* Build a wrapper around some pointer PTR so we can use it as a tree. */
2042 build_ptr_wrapper (ptr)
2045 tree t = make_node (WRAPPER);
2046 WRAPPER_PTR (t) = ptr;
2050 /* Build a wrapper around some integer I so we can use it as a tree. */
2053 build_int_wrapper (i)
2056 tree t = make_node (WRAPPER);
2057 WRAPPER_INT (t) = i;
2062 build_srcloc (file, line)
2068 t = make_node (SRCLOC);
2069 SRCLOC_FILE (t) = file;
2070 SRCLOC_LINE (t) = line;
2076 build_srcloc_here ()
2078 return build_srcloc (input_filename, lineno);
2081 /* The type of ARG when used as an lvalue. */
2087 tree type = TREE_TYPE (arg);
2088 if (TREE_CODE (arg) == OVERLOAD)
2089 type = unknown_type_node;
2093 /* The type of ARG for printing error messages; denote lvalues with
2100 tree type = TREE_TYPE (arg);
2101 if (TREE_CODE (type) == ARRAY_TYPE)
2103 else if (real_lvalue_p (arg))
2104 type = build_reference_type (lvalue_type (arg));
2105 else if (IS_AGGR_TYPE (type))
2106 type = lvalue_type (arg);
2111 /* Does FUNCTION use a variable-length argument list? */
2114 varargs_function_p (function)
2117 tree parm = TYPE_ARG_TYPES (TREE_TYPE (function));
2118 for (; parm; parm = TREE_CHAIN (parm))
2119 if (TREE_VALUE (parm) == void_type_node)
2124 /* Returns 1 if decl is a member of a class. */
2130 const tree ctx = DECL_CONTEXT (decl);
2131 return (ctx && TYPE_P (ctx));
2134 /* Create a placeholder for member access where we don't actually have an
2135 object that the access is against. */
2138 build_dummy_object (type)
2141 tree decl = build1 (NOP_EXPR, build_pointer_type (type), void_zero_node);
2142 return build_indirect_ref (decl, NULL);
2145 /* We've gotten a reference to a member of TYPE. Return *this if appropriate,
2146 or a dummy object otherwise. If BINFOP is non-0, it is filled with the
2147 binfo path from current_class_type to TYPE, or 0. */
2150 maybe_dummy_object (type, binfop)
2156 if (current_class_type
2157 && get_base_distance (type, current_class_type, 0, binfop) != -1)
2158 context = current_class_type;
2161 /* Reference from a nested class member function. */
2164 *binfop = TYPE_BINFO (type);
2167 if (current_class_ref && context == current_class_type)
2168 decl = current_class_ref;
2170 decl = build_dummy_object (context);
2175 /* Returns 1 if OB is a placeholder object, or a pointer to one. */
2178 is_dummy_object (ob)
2181 if (TREE_CODE (ob) == INDIRECT_REF)
2182 ob = TREE_OPERAND (ob, 0);
2183 return (TREE_CODE (ob) == NOP_EXPR
2184 && TREE_OPERAND (ob, 0) == void_zero_node);
2187 /* Returns 1 iff type T is a POD type, as defined in [basic.types]. */
2193 t = strip_array_types (t);
2195 if (INTEGRAL_TYPE_P (t))
2196 return 1; /* integral, character or enumeral type */
2197 if (FLOAT_TYPE_P (t))
2200 return 1; /* pointer to non-member */
2201 if (TYPE_PTRMEM_P (t))
2202 return 1; /* pointer to member object */
2203 if (TYPE_PTRMEMFUNC_P (t))
2204 return 1; /* pointer to member function */
2206 if (! CLASS_TYPE_P (t))
2207 return 0; /* other non-class type (reference or function) */
2208 if (CLASSTYPE_NON_POD_P (t))
2213 /* Return a 1 if ATTR_NAME and ATTR_ARGS denote a valid C++-specific
2214 attribute for either declaration DECL or type TYPE and 0 otherwise.
2215 Plugged into valid_lang_attribute. */
2218 cp_valid_lang_attribute (attr_name, attr_args, decl, type)
2220 tree attr_args ATTRIBUTE_UNUSED;
2221 tree decl ATTRIBUTE_UNUSED;
2222 tree type ATTRIBUTE_UNUSED;
2224 if (is_attribute_p ("java_interface", attr_name))
2226 if (attr_args != NULL_TREE
2227 || decl != NULL_TREE
2228 || ! CLASS_TYPE_P (type)
2229 || ! TYPE_FOR_JAVA (type))
2231 error ("`java_interface' attribute can only be applied to Java class definitions");
2234 TYPE_JAVA_INTERFACE (type) = 1;
2237 if (is_attribute_p ("com_interface", attr_name))
2240 if (attr_args != NULL_TREE
2241 || decl != NULL_TREE
2242 || ! CLASS_TYPE_P (type)
2243 || type != TYPE_MAIN_VARIANT (type))
2245 warning ("`com_interface' attribute can only be applied to class definitions");
2251 `com_interface' is obsolete; g++ vtables are now COM-compatible by default");
2254 else if (is_attribute_p ("init_priority", attr_name))
2256 tree initp_expr = (attr_args ? TREE_VALUE (attr_args): NULL_TREE);
2260 STRIP_NOPS (initp_expr);
2262 if (!initp_expr || TREE_CODE (initp_expr) != INTEGER_CST)
2264 error ("requested init_priority is not an integer constant");
2268 pri = TREE_INT_CST_LOW (initp_expr);
2270 type = strip_array_types (type);
2272 if (decl == NULL_TREE
2273 || TREE_CODE (decl) != VAR_DECL
2274 || ! TREE_STATIC (decl)
2275 || DECL_EXTERNAL (decl)
2276 || (TREE_CODE (type) != RECORD_TYPE
2277 && TREE_CODE (type) != UNION_TYPE)
2278 /* Static objects in functions are initialized the
2279 first time control passes through that
2280 function. This is not precise enough to pin down an
2281 init_priority value, so don't allow it. */
2282 || current_function_decl)
2284 error ("can only use init_priority attribute on file-scope definitions of objects of class type");
2288 if (pri > MAX_INIT_PRIORITY || pri <= 0)
2290 error ("requested init_priority is out of range");
2294 /* Check for init_priorities that are reserved for
2295 language and runtime support implementations.*/
2296 if (pri <= MAX_RESERVED_INIT_PRIORITY)
2299 ("requested init_priority is reserved for internal use");
2302 if (SUPPORTS_INIT_PRIORITY)
2304 DECL_INIT_PRIORITY (decl) = pri;
2309 error ("init_priority attribute is not supported on this platform");
2317 /* Return a new PTRMEM_CST of the indicated TYPE. The MEMBER is the
2318 thing pointed to by the constant. */
2321 make_ptrmem_cst (type, member)
2325 tree ptrmem_cst = make_node (PTRMEM_CST);
2326 /* If would seem a great convenience if make_node would set
2327 TREE_CONSTANT for things of class `c', but it does not. */
2328 TREE_CONSTANT (ptrmem_cst) = 1;
2329 TREE_TYPE (ptrmem_cst) = type;
2330 PTRMEM_CST_MEMBER (ptrmem_cst) = member;
2334 /* Initialize tree.c. */
2339 make_lang_type_fn = cp_make_lang_type;
2340 lang_unsave = cp_unsave;
2341 lang_statement_code_p = cp_statement_code_p;
2342 lang_set_decl_assembler_name = mangle_decl;
2343 list_hash_table = htab_create (31, list_hash, list_hash_eq, NULL);
2344 ggc_add_root (&list_hash_table, 1,
2345 sizeof (list_hash_table),
2346 mark_tree_hashtable);
2349 /* The SAVE_EXPR pointed to by TP is being copied. If ST contains
2350 information indicating to what new SAVE_EXPR this one should be
2351 mapped, use that one. Otherwise, create a new node and enter it in
2352 ST. FN is the function into which the copy will be placed. */
2355 remap_save_expr (tp, st, fn, walk_subtrees)
2363 /* See if we already encountered this SAVE_EXPR. */
2364 n = splay_tree_lookup (st, (splay_tree_key) *tp);
2366 /* If we didn't already remap this SAVE_EXPR, do so now. */
2369 tree t = copy_node (*tp);
2371 /* The SAVE_EXPR is now part of the function into which we
2372 are inlining this body. */
2373 SAVE_EXPR_CONTEXT (t) = fn;
2374 /* And we haven't evaluated it yet. */
2375 SAVE_EXPR_RTL (t) = NULL_RTX;
2376 /* Remember this SAVE_EXPR. */
2377 n = splay_tree_insert (st,
2378 (splay_tree_key) *tp,
2379 (splay_tree_value) t);
2382 /* We've already walked into this SAVE_EXPR, so we needn't do it
2386 /* Replace this SAVE_EXPR with the copy. */
2387 *tp = (tree) n->value;
2390 /* Called via walk_tree. If *TP points to a DECL_STMT for a local
2391 declaration, copies the declaration and enters it in the splay_tree
2392 pointed to by DATA (which is really a `splay_tree *'). */
2395 mark_local_for_remap_r (tp, walk_subtrees, data)
2397 int *walk_subtrees ATTRIBUTE_UNUSED;
2401 splay_tree st = (splay_tree) data;
2405 if (TREE_CODE (t) == DECL_STMT
2406 && nonstatic_local_decl_p (DECL_STMT_DECL (t)))
2407 decl = DECL_STMT_DECL (t);
2408 else if (TREE_CODE (t) == LABEL_STMT)
2409 decl = LABEL_STMT_LABEL (t);
2410 else if (TREE_CODE (t) == TARGET_EXPR
2411 && nonstatic_local_decl_p (TREE_OPERAND (t, 0)))
2412 decl = TREE_OPERAND (t, 0);
2413 else if (TREE_CODE (t) == CASE_LABEL)
2414 decl = CASE_LABEL_DECL (t);
2423 copy = copy_decl_for_inlining (decl,
2424 DECL_CONTEXT (decl),
2425 DECL_CONTEXT (decl));
2427 /* Remember the copy. */
2428 splay_tree_insert (st,
2429 (splay_tree_key) decl,
2430 (splay_tree_value) copy);
2436 /* Called via walk_tree when an expression is unsaved. Using the
2437 splay_tree pointed to by ST (which is really a `splay_tree'),
2438 remaps all local declarations to appropriate replacements. */
2441 cp_unsave_r (tp, walk_subtrees, data)
2446 splay_tree st = (splay_tree) data;
2449 /* Only a local declaration (variable or label). */
2450 if (nonstatic_local_decl_p (*tp))
2452 /* Lookup the declaration. */
2453 n = splay_tree_lookup (st, (splay_tree_key) *tp);
2455 /* If it's there, remap it. */
2457 *tp = (tree) n->value;
2459 else if (TREE_CODE (*tp) == SAVE_EXPR)
2460 remap_save_expr (tp, st, current_function_decl, walk_subtrees);
2463 copy_tree_r (tp, walk_subtrees, NULL);
2465 /* Do whatever unsaving is required. */
2466 unsave_expr_1 (*tp);
2469 /* Keep iterating. */
2473 /* Called by unsave_expr_now whenever an expression (*TP) needs to be
2482 /* Create a splay-tree to map old local variable declarations to new
2484 st = splay_tree_new (splay_tree_compare_pointers, NULL, NULL);
2486 /* Walk the tree once figuring out what needs to be remapped. */
2487 walk_tree (tp, mark_local_for_remap_r, st, NULL);
2489 /* Walk the tree again, copying, remapping, and unsaving. */
2490 walk_tree (tp, cp_unsave_r, st, NULL);
2493 splay_tree_delete (st);
2496 /* Returns the kind of special function that DECL (a FUNCTION_DECL)
2497 is. Note that this sfk_none is zero, so this function can be used
2498 as a predicate to test whether or not DECL is a special function. */
2500 special_function_kind
2501 special_function_p (decl)
2504 /* Rather than doing all this stuff with magic names, we should
2505 probably have a field of type `special_function_kind' in
2506 DECL_LANG_SPECIFIC. */
2507 if (DECL_COPY_CONSTRUCTOR_P (decl))
2508 return sfk_copy_constructor;
2509 if (DECL_CONSTRUCTOR_P (decl))
2510 return sfk_constructor;
2511 if (DECL_OVERLOADED_OPERATOR_P (decl) == NOP_EXPR)
2512 return sfk_assignment_operator;
2513 if (DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (decl))
2514 return sfk_destructor;
2515 if (DECL_COMPLETE_DESTRUCTOR_P (decl))
2516 return sfk_complete_destructor;
2517 if (DECL_BASE_DESTRUCTOR_P (decl))
2518 return sfk_base_destructor;
2519 if (DECL_DELETING_DESTRUCTOR_P (decl))
2520 return sfk_deleting_destructor;
2521 if (DECL_CONV_FN_P (decl))
2522 return sfk_conversion;
2527 /* Returns non-zero if TYPE is a character type, including wchar_t. */
2533 return (same_type_p (type, char_type_node)
2534 || same_type_p (type, unsigned_char_type_node)
2535 || same_type_p (type, signed_char_type_node)
2536 || same_type_p (type, wchar_type_node));
2539 /* Returns the kind of linkage associated with the indicated DECL. Th
2540 value returned is as specified by the language standard; it is
2541 independent of implementation details regarding template
2542 instantiation, etc. For example, it is possible that a declaration
2543 to which this function assigns external linkage would not show up
2544 as a global symbol when you run `nm' on the resulting object file. */
2550 /* This function doesn't attempt to calculate the linkage from first
2551 principles as given in [basic.link]. Instead, it makes use of
2552 the fact that we have already set TREE_PUBLIC appropriately, and
2553 then handles a few special cases. Ideally, we would calculate
2554 linkage first, and then transform that into a concrete
2557 /* Things that don't have names have no linkage. */
2558 if (!DECL_NAME (decl))
2561 /* Things that are TREE_PUBLIC have external linkage. */
2562 if (TREE_PUBLIC (decl))
2565 /* Some things that are not TREE_PUBLIC have external linkage, too.
2566 For example, on targets that don't have weak symbols, we make all
2567 template instantiations have internal linkage (in the object
2568 file), but the symbols should still be treated as having external
2569 linkage from the point of view of the language. */
2570 if (DECL_LANG_SPECIFIC (decl) && DECL_COMDAT (decl))
2573 /* Things in local scope do not have linkage, if they don't have
2575 if (decl_function_context (decl))
2578 /* Everything else has internal linkage. */