1 /* Language-dependent node constructors for parse phase of GNU compiler.
2 Copyright (C) 1987, 88, 92-98, 1999 Free Software Foundation, Inc.
3 Hacked by Michael Tiemann (tiemann@cygnus.com)
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
31 static tree bot_manip PROTO((tree));
32 static tree perm_manip PROTO((tree));
33 static tree build_cplus_array_type_1 PROTO((tree, tree));
34 static void list_hash_add PROTO((int, tree));
35 static int list_hash PROTO((tree, tree, tree));
36 static tree list_hash_lookup PROTO((int, tree, tree, tree));
37 static void propagate_binfo_offsets PROTO((tree, tree));
38 static int avoid_overlap PROTO((tree, tree));
39 static cp_lvalue_kind lvalue_p_1 PROTO((tree, int));
40 static tree no_linkage_helper PROTO((tree));
41 static tree build_srcloc PROTO((char *, int));
43 #define CEIL(x,y) (((x) + (y) - 1) / (y))
45 /* If REF is an lvalue, returns the kind of lvalue that REF is.
46 Otherwise, returns clk_none. If TREAT_CLASS_RVALUES_AS_LVALUES is
47 non-zero, rvalues of class type are considered lvalues. */
50 lvalue_p_1 (ref, treat_class_rvalues_as_lvalues)
52 int treat_class_rvalues_as_lvalues;
54 cp_lvalue_kind op1_lvalue_kind = clk_none;
55 cp_lvalue_kind op2_lvalue_kind = clk_none;
57 if (TREE_CODE (TREE_TYPE (ref)) == REFERENCE_TYPE)
60 if (ref == current_class_ptr && flag_this_is_variable <= 0)
63 switch (TREE_CODE (ref))
65 /* preincrements and predecrements are valid lvals, provided
66 what they refer to are valid lvals. */
67 case PREINCREMENT_EXPR:
68 case PREDECREMENT_EXPR:
72 case WITH_CLEANUP_EXPR:
76 return lvalue_p_1 (TREE_OPERAND (ref, 0),
77 treat_class_rvalues_as_lvalues);
80 op1_lvalue_kind = lvalue_p_1 (TREE_OPERAND (ref, 0),
81 treat_class_rvalues_as_lvalues);
83 /* The "field" can be a FUNCTION_DECL or an OVERLOAD in some
85 && TREE_CODE (TREE_OPERAND (ref, 1)) == FIELD_DECL
86 && DECL_BIT_FIELD (TREE_OPERAND (ref, 1)))
88 /* Clear the ordinary bit. If this object was a class
89 rvalue we want to preserve that information. */
90 op1_lvalue_kind &= ~clk_ordinary;
91 /* The lvalue is for a btifield. */
92 op1_lvalue_kind |= clk_bitfield;
94 return op1_lvalue_kind;
100 if (TREE_READONLY (ref) && ! TREE_STATIC (ref)
101 && DECL_LANG_SPECIFIC (ref)
102 && DECL_IN_AGGR_P (ref))
108 if (TREE_CODE (TREE_TYPE (ref)) != METHOD_TYPE)
112 /* A currently unresolved scope ref. */
114 my_friendly_abort (103);
116 if (TREE_CODE (TREE_OPERAND (ref, 1)) == FUNCTION_DECL)
121 op1_lvalue_kind = lvalue_p_1 (TREE_OPERAND (ref, 0),
122 treat_class_rvalues_as_lvalues);
123 op2_lvalue_kind = lvalue_p_1 (TREE_OPERAND (ref, 1),
124 treat_class_rvalues_as_lvalues);
128 op1_lvalue_kind = lvalue_p_1 (TREE_OPERAND (ref, 1),
129 treat_class_rvalues_as_lvalues);
130 op2_lvalue_kind = lvalue_p_1 (TREE_OPERAND (ref, 2),
131 treat_class_rvalues_as_lvalues);
138 return lvalue_p_1 (TREE_OPERAND (ref, 1),
139 treat_class_rvalues_as_lvalues);
142 return treat_class_rvalues_as_lvalues ? clk_class : clk_none;
145 return ((treat_class_rvalues_as_lvalues
146 && IS_AGGR_TYPE (TREE_TYPE (ref)))
147 ? clk_class : clk_none);
150 /* All functions (except non-static-member functions) are
152 return (DECL_NONSTATIC_MEMBER_FUNCTION_P (ref)
153 ? clk_none : clk_ordinary);
159 /* If one operand is not an lvalue at all, then this expression is
161 if (!op1_lvalue_kind || !op2_lvalue_kind)
164 /* Otherwise, it's an lvalue, and it has all the odd properties
165 contributed by either operand. */
166 op1_lvalue_kind = op1_lvalue_kind | op2_lvalue_kind;
167 /* It's not an ordinary lvalue if it involves either a bit-field or
169 if ((op1_lvalue_kind & ~clk_ordinary) != clk_none)
170 op1_lvalue_kind &= ~clk_ordinary;
171 return op1_lvalue_kind;
174 /* If REF is an lvalue, returns the kind of lvalue that REF is.
175 Otherwise, returns clk_none. Lvalues can be assigned, unless they
176 have TREE_READONLY, or unless they are FUNCTION_DECLs. Lvalues can
177 have their address taken, unless they have DECL_REGISTER. */
183 return lvalue_p_1 (ref, /*treat_class_rvalues_as_lvalues=*/0);
186 /* This differs from real_lvalue_p in that class rvalues are
187 considered lvalues. */
194 (lvalue_p_1 (ref, /*treat_class_rvalues_as_lvalues=*/1) != clk_none);
197 /* Return nonzero if REF is an lvalue valid for this language;
198 otherwise, print an error message and return zero. */
201 lvalue_or_else (ref, string)
205 int win = lvalue_p (ref);
207 error ("non-lvalue in %s", string);
211 /* INIT is a CALL_EXPR which needs info about its target.
212 TYPE is the type that this initialization should appear to have.
214 Build an encapsulation of the initialization to perform
215 and return it so that it can be processed by language-independent
216 and language-specific expression expanders. */
219 build_cplus_new (type, init)
226 /* Make sure that we're not trying to create an instance of an
228 abstract_virtuals_error (NULL_TREE, type);
230 if (TREE_CODE (init) != CALL_EXPR && TREE_CODE (init) != AGGR_INIT_EXPR)
231 return convert (type, init);
233 slot = build (VAR_DECL, type);
234 DECL_ARTIFICIAL (slot) = 1;
235 layout_decl (slot, 0);
236 rval = build (AGGR_INIT_EXPR, type,
237 TREE_OPERAND (init, 0), TREE_OPERAND (init, 1), slot);
238 TREE_SIDE_EFFECTS (rval) = 1;
239 rval = build (TARGET_EXPR, type, slot, rval, NULL_TREE, NULL_TREE);
240 TREE_SIDE_EFFECTS (rval) = 1;
245 /* Encapsulate the expression INIT in a TARGET_EXPR. */
248 get_target_expr (init)
254 slot = build (VAR_DECL, TREE_TYPE (init));
255 DECL_ARTIFICIAL (slot) = 1;
256 layout_decl (slot, 0);
257 rval = build (TARGET_EXPR, TREE_TYPE (init), slot, init,
258 NULL_TREE, NULL_TREE);
259 TREE_SIDE_EFFECTS (rval) = 1;
264 /* Recursively search EXP for CALL_EXPRs that need cleanups and replace
265 these CALL_EXPRs with tree nodes that will perform the cleanups. */
268 break_out_cleanups (exp)
273 if (TREE_CODE (tmp) == CALL_EXPR
274 && TYPE_NEEDS_DESTRUCTOR (TREE_TYPE (tmp)))
275 return build_cplus_new (TREE_TYPE (tmp), tmp);
277 while (TREE_CODE (tmp) == NOP_EXPR
278 || TREE_CODE (tmp) == CONVERT_EXPR
279 || TREE_CODE (tmp) == NON_LVALUE_EXPR)
281 if (TREE_CODE (TREE_OPERAND (tmp, 0)) == CALL_EXPR
282 && TYPE_NEEDS_DESTRUCTOR (TREE_TYPE (TREE_OPERAND (tmp, 0))))
284 TREE_OPERAND (tmp, 0)
285 = build_cplus_new (TREE_TYPE (TREE_OPERAND (tmp, 0)),
286 TREE_OPERAND (tmp, 0));
290 tmp = TREE_OPERAND (tmp, 0);
295 /* Recursively perform a preorder search EXP for CALL_EXPRs, making
296 copies where they are found. Returns a deep copy all nodes transitively
297 containing CALL_EXPRs. */
300 break_out_calls (exp)
303 register tree t1, t2 = NULL_TREE;
304 register enum tree_code code;
305 register int changed = 0;
308 if (exp == NULL_TREE)
311 code = TREE_CODE (exp);
313 if (code == CALL_EXPR)
314 return copy_node (exp);
316 /* Don't try and defeat a save_expr, as it should only be done once. */
317 if (code == SAVE_EXPR)
320 switch (TREE_CODE_CLASS (code))
325 case 'c': /* a constant */
326 case 't': /* a type node */
327 case 'x': /* something random, like an identifier or an ERROR_MARK. */
330 case 'd': /* A decl node */
331 #if 0 /* This is bogus. jason 9/21/94 */
333 t1 = break_out_calls (DECL_INITIAL (exp));
334 if (t1 != DECL_INITIAL (exp))
336 exp = copy_node (exp);
337 DECL_INITIAL (exp) = t1;
342 case 'b': /* A block node */
344 /* Don't know how to handle these correctly yet. Must do a
345 break_out_calls on all DECL_INITIAL values for local variables,
346 and also break_out_calls on all sub-blocks and sub-statements. */
351 case 'e': /* an expression */
352 case 'r': /* a reference */
353 case 's': /* an expression with side effects */
354 for (i = tree_code_length[(int) code] - 1; i >= 0; i--)
356 t1 = break_out_calls (TREE_OPERAND (exp, i));
357 if (t1 != TREE_OPERAND (exp, i))
359 exp = copy_node (exp);
360 TREE_OPERAND (exp, i) = t1;
365 case '<': /* a comparison expression */
366 case '2': /* a binary arithmetic expression */
367 t2 = break_out_calls (TREE_OPERAND (exp, 1));
368 if (t2 != TREE_OPERAND (exp, 1))
370 case '1': /* a unary arithmetic expression */
371 t1 = break_out_calls (TREE_OPERAND (exp, 0));
372 if (t1 != TREE_OPERAND (exp, 0))
376 if (tree_code_length[(int) code] == 1)
377 return build1 (code, TREE_TYPE (exp), t1);
379 return build (code, TREE_TYPE (exp), t1, t2);
386 extern struct obstack *current_obstack;
387 extern struct obstack permanent_obstack, class_obstack;
388 extern struct obstack *saveable_obstack;
389 extern struct obstack *expression_obstack;
391 /* Here is how primitive or already-canonicalized types' hash
392 codes are made. MUST BE CONSISTENT WITH tree.c !!! */
393 #define TYPE_HASH(TYPE) ((HOST_WIDE_INT) (TYPE) & 0777777)
395 /* Construct, lay out and return the type of methods belonging to class
396 BASETYPE and whose arguments are described by ARGTYPES and whose values
397 are described by RETTYPE. If each type exists already, reuse it. */
400 build_cplus_method_type (basetype, rettype, argtypes)
401 tree basetype, rettype, argtypes;
407 /* Make a node of the sort we want. */
408 t = make_node (METHOD_TYPE);
410 TYPE_METHOD_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype);
411 TREE_TYPE (t) = rettype;
412 ptype = build_pointer_type (basetype);
414 /* The actual arglist for this function includes a "hidden" argument
415 which is "this". Put it into the list of argument types. Make
416 sure that the new argument list is allocated on the same obstack
418 push_obstacks (TYPE_OBSTACK (t), TYPE_OBSTACK (t));
419 argtypes = tree_cons (NULL_TREE, ptype, argtypes);
420 TYPE_ARG_TYPES (t) = argtypes;
421 TREE_SIDE_EFFECTS (argtypes) = 1; /* Mark first argtype as "artificial". */
424 /* If we already have such a type, use the old one and free this one.
425 Note that it also frees up the above cons cell if found. */
426 hashcode = TYPE_HASH (basetype) + TYPE_HASH (rettype) +
427 type_hash_list (argtypes);
429 t = type_hash_canon (hashcode, t);
431 if (TYPE_SIZE (t) == 0)
438 build_cplus_array_type_1 (elt_type, index_type)
444 if (elt_type == error_mark_node || index_type == error_mark_node)
445 return error_mark_node;
447 push_obstacks_nochange ();
449 /* If both ELT_TYPE and INDEX_TYPE are permanent,
450 make this permanent too. */
451 if (TREE_PERMANENT (elt_type)
452 && (index_type == 0 || TREE_PERMANENT (index_type)))
453 end_temporary_allocation ();
455 if (processing_template_decl
456 || uses_template_parms (elt_type)
457 || uses_template_parms (index_type))
459 t = make_node (ARRAY_TYPE);
460 TREE_TYPE (t) = elt_type;
461 TYPE_DOMAIN (t) = index_type;
464 t = build_array_type (elt_type, index_type);
466 /* Push these needs up so that initialization takes place
468 TYPE_NEEDS_CONSTRUCTING (t)
469 = TYPE_NEEDS_CONSTRUCTING (TYPE_MAIN_VARIANT (elt_type));
470 TYPE_NEEDS_DESTRUCTOR (t)
471 = TYPE_NEEDS_DESTRUCTOR (TYPE_MAIN_VARIANT (elt_type));
477 build_cplus_array_type (elt_type, index_type)
482 int type_quals = CP_TYPE_QUALS (elt_type);
484 elt_type = TYPE_MAIN_VARIANT (elt_type);
486 t = build_cplus_array_type_1 (elt_type, index_type);
488 if (type_quals != TYPE_UNQUALIFIED)
489 t = cp_build_qualified_type (t, type_quals);
494 /* Make a variant of TYPE, qualified with the TYPE_QUALS. Handles
495 arrays correctly. In particular, if TYPE is an array of T's, and
496 TYPE_QUALS is non-empty, returns an array of qualified T's. If
497 at attempt is made to qualify a type illegally, and COMPLAIN is
498 non-zero, an error is issued. If COMPLAIN is zero, error_mark_node
502 cp_build_qualified_type_real (type, type_quals, complain)
509 if (type == error_mark_node)
512 if (type_quals == TYPE_QUALS (type))
515 /* A restrict-qualified pointer type must be a pointer (or reference)
516 to object or incomplete type. */
517 if ((type_quals & TYPE_QUAL_RESTRICT)
518 && TREE_CODE (type) != TEMPLATE_TYPE_PARM
519 && (!POINTER_TYPE_P (type)
520 || TYPE_PTRMEM_P (type)
521 || TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE))
524 cp_error ("`%T' cannot be `restrict'-qualified", type);
526 return error_mark_node;
528 type_quals &= ~TYPE_QUAL_RESTRICT;
531 if (type_quals != TYPE_UNQUALIFIED
532 && TREE_CODE (type) == FUNCTION_TYPE)
535 cp_error ("`%T' cannot be `const'-, `volatile'-, or `restrict'-qualified", type);
537 return error_mark_node;
538 type_quals = TYPE_UNQUALIFIED;
540 else if (TREE_CODE (type) == ARRAY_TYPE)
542 /* In C++, the qualification really applies to the array element
543 type. Obtain the appropriately qualified element type. */
546 = cp_build_qualified_type_real (TREE_TYPE (type),
550 if (element_type == error_mark_node)
551 return error_mark_node;
553 /* See if we already have an identically qualified type. */
554 for (t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
555 if (CP_TYPE_QUALS (t) == type_quals)
558 /* If we didn't already have it, create it now. */
561 /* Make a new array type, just like the old one, but with the
562 appropriately qualified element type. */
563 t = build_type_copy (type);
564 TREE_TYPE (t) = element_type;
567 /* Even if we already had this variant, we update
568 TYPE_NEEDS_CONSTRUCTING and TYPE_NEEDS_DESTRUCTOR in case
569 they changed since the variant was originally created.
571 This seems hokey; if there is some way to use a previous
572 variant *without* coming through here,
573 TYPE_NEEDS_CONSTRUCTING will never be updated. */
574 TYPE_NEEDS_CONSTRUCTING (t)
575 = TYPE_NEEDS_CONSTRUCTING (TYPE_MAIN_VARIANT (element_type));
576 TYPE_NEEDS_DESTRUCTOR (t)
577 = TYPE_NEEDS_DESTRUCTOR (TYPE_MAIN_VARIANT (element_type));
580 else if (TYPE_PTRMEMFUNC_P (type))
582 /* For a pointer-to-member type, we can't just return a
583 cv-qualified version of the RECORD_TYPE. If we do, we
584 haven't change the field that contains the actual pointer to
585 a method, and so TYPE_PTRMEMFUNC_FN_TYPE will be wrong. */
588 t = TYPE_PTRMEMFUNC_FN_TYPE (type);
589 t = cp_build_qualified_type_real (t, type_quals, complain);
590 return build_ptrmemfunc_type (t);
593 /* Retrieve (or create) the appropriately qualified variant. */
594 result = build_qualified_type (type, type_quals);
596 /* If this was a pointer-to-method type, and we just made a copy,
597 then we need to clear the cached associated
598 pointer-to-member-function type; it is not valid for the new
601 && TREE_CODE (type) == POINTER_TYPE
602 && TREE_CODE (TREE_TYPE (type)) == METHOD_TYPE)
603 TYPE_SET_PTRMEMFUNC_TYPE (result, NULL_TREE);
608 /* Returns the canonical version of TYPE. In other words, if TYPE is
609 a typedef, returns the underlying type. The cv-qualification of
610 the type returned matches the type input; they will always be
614 canonical_type_variant (t)
617 return cp_build_qualified_type (TYPE_MAIN_VARIANT (t), CP_TYPE_QUALS (t));
620 /* Add OFFSET to all base types of T.
622 OFFSET, which is a type offset, is number of bytes.
624 Note that we don't have to worry about having two paths to the
625 same base type, since this type owns its association list. */
628 propagate_binfo_offsets (binfo, offset)
632 tree binfos = BINFO_BASETYPES (binfo);
633 int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
635 for (i = 0; i < n_baselinks; /* note increment is done in the loop. */)
637 tree base_binfo = TREE_VEC_ELT (binfos, i);
639 if (TREE_VIA_VIRTUAL (base_binfo))
644 tree delta = NULL_TREE;
646 for (j = i+1; j < n_baselinks; j++)
647 if (! TREE_VIA_VIRTUAL (TREE_VEC_ELT (binfos, j)))
649 /* The next basetype offset must take into account the space
650 between the classes, not just the size of each class. */
651 delta = size_binop (MINUS_EXPR,
652 BINFO_OFFSET (TREE_VEC_ELT (binfos, j)),
653 BINFO_OFFSET (base_binfo));
658 if (BINFO_OFFSET_ZEROP (base_binfo))
659 BINFO_OFFSET (base_binfo) = offset;
661 BINFO_OFFSET (base_binfo)
662 = size_binop (PLUS_EXPR, BINFO_OFFSET (base_binfo), offset);
664 BINFO_OFFSET (base_binfo) = offset;
667 propagate_binfo_offsets (base_binfo, offset);
669 /* Go to our next class that counts for offset propagation. */
672 offset = size_binop (PLUS_EXPR, offset, delta);
677 /* Makes new binfos for the indirect bases under BINFO, and updates
678 BINFO_OFFSET for them and their bases. */
681 unshare_base_binfos (binfo)
684 tree binfos = BINFO_BASETYPES (binfo);
688 if (binfos == NULL_TREE)
691 /* Now unshare the structure beneath BINFO. */
692 for (j = TREE_VEC_LENGTH (binfos)-1;
695 tree base_binfo = TREE_VEC_ELT (binfos, j);
696 new_binfo = TREE_VEC_ELT (binfos, j)
697 = make_binfo (BINFO_OFFSET (base_binfo),
699 BINFO_VTABLE (base_binfo),
700 BINFO_VIRTUALS (base_binfo));
701 TREE_VIA_PUBLIC (new_binfo) = TREE_VIA_PUBLIC (base_binfo);
702 TREE_VIA_PROTECTED (new_binfo) = TREE_VIA_PROTECTED (base_binfo);
703 TREE_VIA_VIRTUAL (new_binfo) = TREE_VIA_VIRTUAL (base_binfo);
704 BINFO_INHERITANCE_CHAIN (new_binfo) = binfo;
705 unshare_base_binfos (new_binfo);
709 /* Finish the work of layout_record, now taking virtual bases into account.
710 Also compute the actual offsets that our base classes will have.
711 This must be performed after the fields are laid out, since virtual
712 baseclasses must lay down at the end of the record.
714 Returns the maximum number of virtual functions any of the
715 baseclasses provide. */
718 layout_basetypes (rec, max)
722 tree binfos = TYPE_BINFO_BASETYPES (rec);
723 int i, n_baseclasses = binfos ? TREE_VEC_LENGTH (binfos) : 0;
727 unsigned int record_align = MAX (BITS_PER_UNIT, TYPE_ALIGN (rec));
728 unsigned int desired_align;
730 /* Record size so far is CONST_SIZE bits, where CONST_SIZE is an integer. */
731 register unsigned int const_size = 0;
732 unsigned int nonvirtual_const_size;
734 #ifdef STRUCTURE_SIZE_BOUNDARY
735 /* Packed structures don't need to have minimum size. */
736 if (! TYPE_PACKED (rec))
737 record_align = MAX (record_align, STRUCTURE_SIZE_BOUNDARY);
740 /* Get all the virtual base types that this type uses. The
741 TREE_VALUE slot holds the virtual baseclass type. Note that
742 get_vbase_types makes copies of the virtual base BINFOs, so that
743 the vbase_types are unshared. */
744 vbase_types = CLASSTYPE_VBASECLASSES (rec);
746 my_friendly_assert (TREE_CODE (TYPE_SIZE (rec)) == INTEGER_CST, 19970302);
747 const_size = TREE_INT_CST_LOW (TYPE_SIZE (rec));
749 nonvirtual_const_size = const_size;
753 tree basetype = BINFO_TYPE (vbase_types);
756 desired_align = TYPE_ALIGN (basetype);
757 record_align = MAX (record_align, desired_align);
760 offset = integer_zero_node;
763 /* Give each virtual base type the alignment it wants. */
764 const_size = CEIL (const_size, desired_align) * desired_align;
765 offset = size_int (CEIL (const_size, BITS_PER_UNIT));
768 if (CLASSTYPE_VSIZE (basetype) > max)
769 max = CLASSTYPE_VSIZE (basetype);
770 BINFO_OFFSET (vbase_types) = offset;
772 /* Every virtual baseclass takes a least a UNIT, so that we can
773 take it's address and get something different for each base. */
774 const_size += MAX (BITS_PER_UNIT,
775 TREE_INT_CST_LOW (CLASSTYPE_SIZE (basetype)));
777 vbase_types = TREE_CHAIN (vbase_types);
782 /* Because a virtual base might take a single byte above,
783 we have to re-adjust the total size to make sure it is
784 a multiple of the alignment. */
785 /* Give the whole object the alignment it wants. */
786 const_size = CEIL (const_size, record_align) * record_align;
789 /* Set the alignment in the complete type. We don't set CLASSTYPE_ALIGN
790 here, as that is for this class, without any virtual base classes. */
791 TYPE_ALIGN (rec) = record_align;
792 if (const_size != nonvirtual_const_size)
794 TYPE_SIZE (rec) = size_int (const_size);
795 TYPE_SIZE_UNIT (rec) = size_binop (FLOOR_DIV_EXPR, TYPE_SIZE (rec),
796 size_int (BITS_PER_UNIT));
799 /* Now propagate offset information throughout the lattice. */
800 for (i = 0; i < n_baseclasses; i++)
802 register tree base_binfo = TREE_VEC_ELT (binfos, i);
803 register tree basetype = BINFO_TYPE (base_binfo);
804 tree field = TYPE_FIELDS (rec);
806 if (TREE_VIA_VIRTUAL (base_binfo))
809 my_friendly_assert (TREE_TYPE (field) == basetype, 23897);
811 if (get_base_distance (basetype, rec, 0, (tree*)0) == -2)
812 cp_warning ("direct base `%T' inaccessible in `%T' due to ambiguity",
815 BINFO_OFFSET (base_binfo)
816 = size_int (CEIL (TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field)),
818 propagate_binfo_offsets (base_binfo, BINFO_OFFSET (base_binfo));
819 TYPE_FIELDS (rec) = TREE_CHAIN (field);
822 for (vbase_types = CLASSTYPE_VBASECLASSES (rec); vbase_types;
823 vbase_types = TREE_CHAIN (vbase_types))
825 BINFO_INHERITANCE_CHAIN (vbase_types) = TYPE_BINFO (rec);
826 unshare_base_binfos (vbase_types);
827 propagate_binfo_offsets (vbase_types, BINFO_OFFSET (vbase_types));
831 tree basetype = BINFO_TYPE (vbase_types);
832 if (get_base_distance (basetype, rec, 0, (tree*)0) == -2)
833 cp_warning ("virtual base `%T' inaccessible in `%T' due to ambiguity",
841 /* If the empty base field in DECL overlaps with a base of the same type in
842 NEWDECL, which is either another base field or the first data field of
843 the class, pad the base just before NEWDECL and return 1. Otherwise,
847 avoid_overlap (decl, newdecl)
852 if (newdecl == NULL_TREE
853 || ! types_overlap_p (TREE_TYPE (decl), TREE_TYPE (newdecl)))
856 for (field = decl; TREE_CHAIN (field) && TREE_CHAIN (field) != newdecl;
857 field = TREE_CHAIN (field))
860 DECL_SIZE (field) = integer_one_node;
865 /* Returns a list of fields to stand in for the base class subobjects
866 of REC. These fields are later removed by layout_basetypes. */
869 build_base_fields (rec)
872 /* Chain to hold all the new FIELD_DECLs which stand in for base class
874 tree base_decls = NULL_TREE;
875 tree binfos = TYPE_BINFO_BASETYPES (rec);
876 int n_baseclasses = binfos ? TREE_VEC_LENGTH (binfos) : 0;
878 int i, saw_empty = 0;
879 unsigned int base_align = 0;
881 for (i = 0; i < n_baseclasses; ++i)
883 register tree base_binfo = TREE_VEC_ELT (binfos, i);
884 register tree basetype = BINFO_TYPE (base_binfo);
886 if (TYPE_SIZE (basetype) == 0)
887 /* This error is now reported in xref_tag, thus giving better
888 location information. */
891 if (TREE_VIA_VIRTUAL (base_binfo))
894 decl = build_lang_decl (FIELD_DECL, NULL_TREE, basetype);
895 DECL_ARTIFICIAL (decl) = 1;
896 DECL_FIELD_CONTEXT (decl) = DECL_CLASS_CONTEXT (decl) = rec;
897 DECL_SIZE (decl) = CLASSTYPE_SIZE (basetype);
898 DECL_ALIGN (decl) = CLASSTYPE_ALIGN (basetype);
899 TREE_CHAIN (decl) = base_decls;
904 /* Brain damage for backwards compatibility. For no good reason,
905 the old layout_basetypes made every base at least as large as
906 the alignment for the bases up to that point, gratuitously
907 wasting space. So we do the same thing here. */
908 base_align = MAX (base_align, DECL_ALIGN (decl));
910 = size_int (MAX (TREE_INT_CST_LOW (DECL_SIZE (decl)),
913 else if (DECL_SIZE (decl) == integer_zero_node)
917 /* Reverse the list of fields so we allocate the bases in the proper
919 base_decls = nreverse (base_decls);
921 /* In the presence of empty base classes, we run the risk of allocating
922 two objects of the same class on top of one another. Avoid that. */
923 if (flag_new_abi && saw_empty)
924 for (decl = base_decls; decl; decl = TREE_CHAIN (decl))
926 if (DECL_SIZE (decl) == integer_zero_node)
928 /* First step through the following bases until we find
929 an overlap or a non-empty base. */
930 for (nextdecl = TREE_CHAIN (decl); nextdecl;
931 nextdecl = TREE_CHAIN (nextdecl))
933 if (avoid_overlap (decl, nextdecl)
934 || DECL_SIZE (nextdecl) != integer_zero_node)
938 /* If we're still looking, also check against the first
940 for (nextdecl = TYPE_FIELDS (rec);
941 nextdecl && TREE_CODE (nextdecl) != FIELD_DECL;
942 nextdecl = TREE_CHAIN (nextdecl))
944 avoid_overlap (decl, nextdecl);
952 /* Returns list of virtual base class pointers in a FIELD_DECL chain. */
955 build_vbase_pointer_fields (rec)
958 /* Chain to hold all the new FIELD_DECLs which point at virtual
960 tree vbase_decls = NULL_TREE;
961 tree binfos = TYPE_BINFO_BASETYPES (rec);
962 int n_baseclasses = binfos ? TREE_VEC_LENGTH (binfos) : 0;
966 /* Handle basetypes almost like fields, but record their
967 offsets differently. */
969 for (i = 0; i < n_baseclasses; i++)
971 register tree base_binfo = TREE_VEC_ELT (binfos, i);
972 register tree basetype = BINFO_TYPE (base_binfo);
974 if (TYPE_SIZE (basetype) == 0)
975 /* This error is now reported in xref_tag, thus giving better
976 location information. */
979 /* All basetypes are recorded in the association list of the
982 if (TREE_VIA_VIRTUAL (base_binfo))
987 /* The offset for a virtual base class is only used in computing
988 virtual function tables and for initializing virtual base
989 pointers. It is built once `get_vbase_types' is called. */
991 /* If this basetype can come from another vbase pointer
992 without an additional indirection, we will share
993 that pointer. If an indirection is involved, we
994 make our own pointer. */
995 for (j = 0; j < n_baseclasses; j++)
997 tree other_base_binfo = TREE_VEC_ELT (binfos, j);
998 if (! TREE_VIA_VIRTUAL (other_base_binfo)
999 && binfo_member (basetype,
1000 CLASSTYPE_VBASECLASSES (BINFO_TYPE
1005 FORMAT_VBASE_NAME (name, basetype);
1006 decl = build_lang_decl (FIELD_DECL, get_identifier (name),
1007 build_pointer_type (basetype));
1008 /* If you change any of the below, take a look at all the
1009 other VFIELD_BASEs and VTABLE_BASEs in the code, and change
1011 DECL_ASSEMBLER_NAME (decl) = get_identifier (VTABLE_BASE);
1012 DECL_VIRTUAL_P (decl) = 1;
1013 DECL_ARTIFICIAL (decl) = 1;
1014 DECL_FIELD_CONTEXT (decl) = rec;
1015 DECL_CLASS_CONTEXT (decl) = rec;
1016 DECL_FCONTEXT (decl) = basetype;
1017 DECL_SAVED_INSNS (decl) = 0;
1018 DECL_FIELD_SIZE (decl) = 0;
1019 DECL_ALIGN (decl) = TYPE_ALIGN (ptr_type_node);
1020 TREE_CHAIN (decl) = vbase_decls;
1021 BINFO_VPTR_FIELD (base_binfo) = decl;
1025 /* The space this decl occupies has already been accounted for. */
1033 /* Hashing of lists so that we don't make duplicates.
1034 The entry point is `list_hash_canon'. */
1036 /* Each hash table slot is a bucket containing a chain
1037 of these structures. */
1041 struct list_hash *next; /* Next structure in the bucket. */
1042 int hashcode; /* Hash code of this list. */
1043 tree list; /* The list recorded here. */
1046 /* Now here is the hash table. When recording a list, it is added
1047 to the slot whose index is the hash code mod the table size.
1048 Note that the hash table is used for several kinds of lists.
1049 While all these live in the same table, they are completely independent,
1050 and the hash code is computed differently for each of these. */
1052 #define TYPE_HASH_SIZE 59
1053 static struct list_hash *list_hash_table[TYPE_HASH_SIZE];
1055 /* Compute a hash code for a list (chain of TREE_LIST nodes
1056 with goodies in the TREE_PURPOSE, TREE_VALUE, and bits of the
1057 TREE_COMMON slots), by adding the hash codes of the individual entries. */
1060 list_hash (purpose, value, chain)
1061 tree purpose, value, chain;
1063 register int hashcode = 0;
1066 hashcode += TYPE_HASH (chain);
1069 hashcode += TYPE_HASH (value);
1073 hashcode += TYPE_HASH (purpose);
1079 /* Look in the type hash table for a type isomorphic to TYPE.
1080 If one is found, return it. Otherwise return 0. */
1083 list_hash_lookup (hashcode, purpose, value, chain)
1085 tree purpose, value, chain;
1087 register struct list_hash *h;
1089 for (h = list_hash_table[hashcode % TYPE_HASH_SIZE]; h; h = h->next)
1090 if (h->hashcode == hashcode
1091 && TREE_PURPOSE (h->list) == purpose
1092 && TREE_VALUE (h->list) == value
1093 && TREE_CHAIN (h->list) == chain)
1098 /* Add an entry to the list-hash-table
1099 for a list TYPE whose hash code is HASHCODE. */
1102 list_hash_add (hashcode, list)
1106 register struct list_hash *h;
1108 h = (struct list_hash *) obstack_alloc (&class_obstack, sizeof (struct list_hash));
1109 h->hashcode = hashcode;
1111 h->next = list_hash_table[hashcode % TYPE_HASH_SIZE];
1112 list_hash_table[hashcode % TYPE_HASH_SIZE] = h;
1115 /* Given list components PURPOSE, VALUE, AND CHAIN, return the canonical
1116 object for an identical list if one already exists. Otherwise, build a
1117 new one, and record it as the canonical object. */
1119 /* Set to 1 to debug without canonicalization. Never set by program. */
1121 static int debug_no_list_hash = 0;
1124 hash_tree_cons (purpose, value, chain)
1125 tree purpose, value, chain;
1127 struct obstack *ambient_obstack = current_obstack;
1131 if (! debug_no_list_hash)
1133 hashcode = list_hash (purpose, value, chain);
1134 t = list_hash_lookup (hashcode, purpose, value, chain);
1139 current_obstack = &class_obstack;
1141 t = tree_cons (purpose, value, chain);
1143 /* If this is a new list, record it for later reuse. */
1144 if (! debug_no_list_hash)
1145 list_hash_add (hashcode, t);
1147 current_obstack = ambient_obstack;
1151 /* Constructor for hashed lists. */
1154 hash_tree_chain (value, chain)
1157 return hash_tree_cons (NULL_TREE, value, chain);
1160 /* Similar, but used for concatenating two lists. */
1163 hash_chainon (list1, list2)
1170 if (TREE_CHAIN (list1) == NULL_TREE)
1171 return hash_tree_chain (TREE_VALUE (list1), list2);
1172 return hash_tree_chain (TREE_VALUE (list1),
1173 hash_chainon (TREE_CHAIN (list1), list2));
1176 /* Build an association between TYPE and some parameters:
1178 OFFSET is the offset added to `this' to convert it to a pointer
1181 BINFO is the base binfo to use, if we are deriving from one. This
1182 is necessary, as we want specialized parent binfos from base
1183 classes, so that the VTABLE_NAMEs of bases are for the most derived
1184 type, instead of the simple type.
1186 VTABLE is the virtual function table with which to initialize
1187 sub-objects of type TYPE.
1189 VIRTUALS are the virtual functions sitting in VTABLE. */
1192 make_binfo (offset, binfo, vtable, virtuals)
1194 tree vtable, virtuals;
1196 tree new_binfo = make_tree_vec (7);
1199 if (TREE_CODE (binfo) == TREE_VEC)
1200 type = BINFO_TYPE (binfo);
1204 binfo = CLASS_TYPE_P (type) ? TYPE_BINFO (binfo) : NULL_TREE;
1207 TREE_TYPE (new_binfo) = TYPE_MAIN_VARIANT (type);
1208 BINFO_OFFSET (new_binfo) = offset;
1209 BINFO_VTABLE (new_binfo) = vtable;
1210 BINFO_VIRTUALS (new_binfo) = virtuals;
1211 BINFO_VPTR_FIELD (new_binfo) = NULL_TREE;
1213 if (binfo && BINFO_BASETYPES (binfo) != NULL_TREE)
1214 BINFO_BASETYPES (new_binfo) = copy_node (BINFO_BASETYPES (binfo));
1218 /* Return the binfo value for ELEM in TYPE. */
1221 binfo_value (elem, type)
1225 if (get_base_distance (elem, type, 0, (tree *)0) == -2)
1226 compiler_error ("base class `%s' ambiguous in binfo_value",
1227 TYPE_NAME_STRING (elem));
1229 return TYPE_BINFO (type);
1230 if (TREE_CODE (elem) == RECORD_TYPE && TYPE_BINFO (elem) == type)
1232 return get_binfo (elem, type, 0);
1235 /* Return a reversed copy of the BINFO-chain given by PATH. (If the
1236 BINFO_INHERITANCE_CHAIN points from base classes to derived
1237 classes, it will instead point from derived classes to base
1238 classes.) Returns the first node in the reversed chain. */
1244 register tree prev = NULL_TREE, cur;
1245 push_expression_obstack ();
1246 for (cur = path; cur; cur = BINFO_INHERITANCE_CHAIN (cur))
1248 tree r = copy_node (cur);
1249 BINFO_INHERITANCE_CHAIN (r) = prev;
1260 unsigned HOST_WIDE_INT n;
1263 fprintf (stderr, "type \"%s\"; offset = %ld\n",
1264 TYPE_NAME_STRING (BINFO_TYPE (elem)),
1265 (long) TREE_INT_CST_LOW (BINFO_OFFSET (elem)));
1266 fprintf (stderr, "vtable type:\n");
1267 debug_tree (BINFO_TYPE (elem));
1268 if (BINFO_VTABLE (elem))
1269 fprintf (stderr, "vtable decl \"%s\"\n", IDENTIFIER_POINTER (DECL_NAME (BINFO_VTABLE (elem))));
1271 fprintf (stderr, "no vtable decl yet\n");
1272 fprintf (stderr, "virtuals:\n");
1273 virtuals = BINFO_VIRTUALS (elem);
1275 n = skip_rtti_stuff (&virtuals, BINFO_TYPE (elem));
1279 tree fndecl = TREE_VALUE (virtuals);
1280 fprintf (stderr, "%s [%ld =? %ld]\n",
1281 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (fndecl)),
1282 (long) n, (long) TREE_INT_CST_LOW (DECL_VINDEX (fndecl)));
1284 virtuals = TREE_CHAIN (virtuals);
1288 /* Initialize an CPLUS_BINDING node that does not live on an obstack. */
1292 struct tree_binding* node;
1294 static struct tree_binding* source;
1297 extern struct obstack permanent_obstack;
1298 push_obstacks (&permanent_obstack, &permanent_obstack);
1299 source = (struct tree_binding*)make_node (CPLUS_BINDING);
1303 TREE_PERMANENT ((tree)node) = 0;
1312 if (TREE_CODE (t) == FUNCTION_DECL)
1314 else if (TREE_CODE (t) == OVERLOAD)
1316 for (i=0; t; t = OVL_CHAIN (t))
1321 my_friendly_abort (359);
1326 is_overloaded_fn (x)
1329 /* A baselink is also considered an overloaded function. */
1330 if (TREE_CODE (x) == OFFSET_REF)
1331 x = TREE_OPERAND (x, 1);
1334 return (TREE_CODE (x) == FUNCTION_DECL
1335 || TREE_CODE (x) == TEMPLATE_ID_EXPR
1336 || DECL_FUNCTION_TEMPLATE_P (x)
1337 || TREE_CODE (x) == OVERLOAD);
1341 really_overloaded_fn (x)
1344 /* A baselink is also considered an overloaded function. */
1345 if (TREE_CODE (x) == OFFSET_REF)
1346 x = TREE_OPERAND (x, 1);
1349 return (TREE_CODE (x) == OVERLOAD
1350 && (TREE_CHAIN (x) != NULL_TREE
1351 || DECL_FUNCTION_TEMPLATE_P (OVL_FUNCTION (x))));
1358 my_friendly_assert (is_overloaded_fn (from), 9);
1359 /* A baselink is also considered an overloaded function. */
1360 if (BASELINK_P (from))
1361 from = TREE_VALUE (from);
1362 return OVL_CURRENT (from);
1365 /* Returns nonzero if T is a ->* or .* expression that refers to a
1372 return (TREE_CODE (t) == OFFSET_REF
1373 && TYPE_PTRMEMFUNC_P (TREE_TYPE (TREE_OPERAND (t, 1))));
1376 /* Return a new OVL node, concatenating it with the old one. */
1379 ovl_cons (decl, chain)
1383 tree result = make_node (OVERLOAD);
1384 TREE_TYPE (result) = unknown_type_node;
1385 OVL_FUNCTION (result) = decl;
1386 TREE_CHAIN (result) = chain;
1391 /* Same as ovl_cons, but on the scratch_obstack. */
1394 scratch_ovl_cons (value, chain)
1398 register struct obstack *ambient_obstack = current_obstack;
1399 extern struct obstack *expression_obstack;
1400 current_obstack = expression_obstack;
1401 node = ovl_cons (value, chain);
1402 current_obstack = ambient_obstack;
1406 /* Build a new overloaded function. If this is the first one,
1407 just return it; otherwise, ovl_cons the _DECLs */
1410 build_overload (decl, chain)
1414 if (! chain && TREE_CODE (decl) != TEMPLATE_DECL)
1416 if (chain && TREE_CODE (chain) != OVERLOAD)
1417 chain = ovl_cons (chain, NULL_TREE);
1418 return ovl_cons (decl, chain);
1421 /* True if fn is in ovl. */
1424 ovl_member (fn, ovl)
1428 if (ovl == NULL_TREE)
1430 if (TREE_CODE (ovl) != OVERLOAD)
1432 for (; ovl; ovl = OVL_CHAIN (ovl))
1433 if (OVL_FUNCTION (ovl) == fn)
1439 is_aggr_type_2 (t1, t2)
1442 if (TREE_CODE (t1) != TREE_CODE (t2))
1444 return IS_AGGR_TYPE (t1) && IS_AGGR_TYPE (t2);
1447 #define PRINT_RING_SIZE 4
1450 lang_printable_name (decl, v)
1454 static tree decl_ring[PRINT_RING_SIZE];
1455 static char *print_ring[PRINT_RING_SIZE];
1456 static int ring_counter;
1459 /* Only cache functions. */
1461 || TREE_CODE (decl) != FUNCTION_DECL
1462 || DECL_LANG_SPECIFIC (decl) == 0)
1463 return lang_decl_name (decl, v);
1465 /* See if this print name is lying around. */
1466 for (i = 0; i < PRINT_RING_SIZE; i++)
1467 if (decl_ring[i] == decl)
1468 /* yes, so return it. */
1469 return print_ring[i];
1471 if (++ring_counter == PRINT_RING_SIZE)
1474 if (current_function_decl != NULL_TREE)
1476 if (decl_ring[ring_counter] == current_function_decl)
1478 if (ring_counter == PRINT_RING_SIZE)
1480 if (decl_ring[ring_counter] == current_function_decl)
1481 my_friendly_abort (106);
1484 if (print_ring[ring_counter])
1485 free (print_ring[ring_counter]);
1487 print_ring[ring_counter] = xstrdup (lang_decl_name (decl, v));
1488 decl_ring[ring_counter] = decl;
1489 return print_ring[ring_counter];
1492 /* Build the FUNCTION_TYPE or METHOD_TYPE which may throw exceptions
1493 listed in RAISES. */
1496 build_exception_variant (type, raises)
1500 tree v = TYPE_MAIN_VARIANT (type);
1501 int type_quals = TYPE_QUALS (type);
1503 for (; v; v = TYPE_NEXT_VARIANT (v))
1504 if (TYPE_QUALS (v) == type_quals
1505 && comp_except_specs (raises, TYPE_RAISES_EXCEPTIONS (v), 1))
1508 /* Need to build a new variant. */
1509 v = build_type_copy (type);
1511 if (raises && ! TREE_PERMANENT (raises))
1512 raises = copy_to_permanent (raises);
1514 TYPE_RAISES_EXCEPTIONS (v) = raises;
1518 /* Given a TEMPLATE_TEMPLATE_PARM node T, create a new one together with its
1519 lang_specific field and its corresponding TEMPLATE_DECL node */
1522 copy_template_template_parm (t)
1525 tree template = TYPE_NAME (t);
1528 /* Make sure these end up on the permanent_obstack. */
1529 push_permanent_obstack ();
1531 t2 = make_lang_type (TEMPLATE_TEMPLATE_PARM);
1532 template = copy_node (template);
1533 copy_lang_decl (template);
1537 TREE_TYPE (template) = t2;
1538 TYPE_NAME (t2) = template;
1539 TYPE_STUB_DECL (t2) = template;
1541 /* No need to copy these */
1542 TYPE_FIELDS (t2) = TYPE_FIELDS (t);
1543 TEMPLATE_TEMPLATE_PARM_TEMPLATE_INFO (t2)
1544 = TEMPLATE_TEMPLATE_PARM_TEMPLATE_INFO (t);
1548 /* Walk through the tree structure T, applying func. If func ever returns
1549 non-null, return that value. */
1552 search_tree (t, func)
1554 tree (*func) PROTO((tree));
1556 #define TRY(ARG) if (tmp=search_tree (ARG, func), tmp != NULL_TREE) return tmp
1559 enum tree_code code;
1568 /* Handle some common cases up front. */
1569 code = TREE_CODE (t);
1570 if (TREE_CODE_CLASS (code) == '1')
1572 TRY (TREE_OPERAND (t, 0));
1575 else if (TREE_CODE_CLASS (code) == '2' || TREE_CODE_CLASS (code) == '<')
1577 TRY (TREE_OPERAND (t, 0));
1578 TRY (TREE_OPERAND (t, 1));
1587 case IDENTIFIER_NODE:
1594 case NAMESPACE_DECL:
1598 TRY (TREE_TYPE (t));
1602 TRY (TREE_TYPE (t));
1603 TRY (TREE_CHAIN (t));
1607 TRY (TREE_PURPOSE (t));
1608 TRY (TREE_VALUE (t));
1609 TRY (TREE_CHAIN (t));
1613 TRY (OVL_FUNCTION (t));
1614 TRY (OVL_CHAIN (t));
1619 int len = TREE_VEC_LENGTH (t);
1623 TRY (TREE_VEC_ELT (t, len));
1634 TRY (TREE_TYPE (t));
1639 case AGGR_INIT_EXPR:
1641 TRY (TREE_OPERAND (t, 0));
1642 TRY (TREE_OPERAND (t, 1));
1643 TRY (TREE_OPERAND (t, 2));
1646 case TRUTH_AND_EXPR:
1648 case TRUTH_XOR_EXPR:
1649 case TRUTH_ANDIF_EXPR:
1650 case TRUTH_ORIF_EXPR:
1651 case PREDECREMENT_EXPR:
1652 case PREINCREMENT_EXPR:
1653 case POSTDECREMENT_EXPR:
1654 case POSTINCREMENT_EXPR:
1657 case TRY_CATCH_EXPR:
1658 case WITH_CLEANUP_EXPR:
1663 TRY (TREE_OPERAND (t, 0));
1664 TRY (TREE_OPERAND (t, 1));
1670 case TRUTH_NOT_EXPR:
1672 case CLEANUP_POINT_EXPR:
1677 TRY (TREE_OPERAND (t, 0));
1684 case PSEUDO_DTOR_EXPR:
1688 TRY (TREE_REALPART (t));
1689 TRY (TREE_IMAGPART (t));
1693 TRY (CONSTRUCTOR_ELTS (t));
1696 case TEMPLATE_TEMPLATE_PARM:
1697 case TEMPLATE_PARM_INDEX:
1698 case TEMPLATE_TYPE_PARM:
1716 case REFERENCE_TYPE:
1717 TRY (TREE_TYPE (t));
1722 TRY (TREE_TYPE (t));
1723 TRY (TYPE_ARG_TYPES (t));
1727 TRY (TREE_TYPE (t));
1728 TRY (TYPE_DOMAIN (t));
1732 TRY (TYPE_MAX_VALUE (t));
1736 TRY (TREE_TYPE (t));
1737 TRY (TYPE_OFFSET_BASETYPE (t));
1741 if (TYPE_PTRMEMFUNC_P (t))
1742 TRY (TYPE_PTRMEMFUNC_FN_TYPE (t));
1746 my_friendly_abort (19990803);
1754 /* Passed to search_tree. Checks for the use of types with no linkage. */
1757 no_linkage_helper (t)
1761 && (IS_AGGR_TYPE (t) || TREE_CODE (t) == ENUMERAL_TYPE)
1762 && (decl_function_context (TYPE_MAIN_DECL (t))
1763 || ANON_AGGRNAME_P (TYPE_IDENTIFIER (t))))
1768 /* Check if the type T depends on a type with no linkage and if so, return
1772 no_linkage_check (t)
1775 /* There's no point in checking linkage on template functions; we
1776 can't know their complete types. */
1777 if (processing_template_decl)
1780 t = search_tree (t, no_linkage_helper);
1781 if (t != error_mark_node)
1787 /* Make copies of all the nodes below T. If FUNC is non-NULL, call it
1793 tree (*func) PROTO((tree));
1796 enum tree_code code;
1808 /* Handle some common cases up front. */
1809 code = TREE_CODE (t);
1810 if (TREE_CODE_CLASS (code) == '1')
1813 TREE_TYPE (t) = mapcar (TREE_TYPE (t), func);
1814 TREE_OPERAND (t, 0) = mapcar (TREE_OPERAND (t, 0), func);
1817 else if (TREE_CODE_CLASS (code) == '2' || TREE_CODE_CLASS (code) == '<')
1820 TREE_TYPE (t) = mapcar (TREE_TYPE (t), func);
1821 TREE_OPERAND (t, 0) = mapcar (TREE_OPERAND (t, 0), func);
1822 TREE_OPERAND (t, 1) = mapcar (TREE_OPERAND (t, 1), func);
1826 switch (TREE_CODE (t))
1829 return error_mark_node;
1834 /* Rather than aborting, return error_mark_node. This allows us
1835 to report a sensible error message on code like this:
1837 void g() { int i; f<i>(7); }
1841 void g() { const int i = 7; f<i>(7); }
1843 however, we must actually return the constant initializer. */
1844 if (TREE_READONLY_DECL_P (t))
1846 tmp = decl_constant_value (t);
1848 return mapcar (tmp, func);
1850 return error_mark_node;
1854 tree chain = TREE_CHAIN (t);
1856 TREE_CHAIN (t) = mapcar (chain, func);
1857 TREE_TYPE (t) = mapcar (TREE_TYPE (t), func);
1858 DECL_INITIAL (t) = mapcar (DECL_INITIAL (t), func);
1859 DECL_SIZE (t) = mapcar (DECL_SIZE (t), func);
1865 tree chain = TREE_CHAIN (t);
1867 TREE_PURPOSE (t) = mapcar (TREE_PURPOSE (t), func);
1868 TREE_VALUE (t) = mapcar (TREE_VALUE (t), func);
1869 TREE_CHAIN (t) = mapcar (chain, func);
1875 tree chain = OVL_CHAIN (t);
1877 OVL_FUNCTION (t) = mapcar (OVL_FUNCTION (t), func);
1878 OVL_CHAIN (t) = mapcar (chain, func);
1884 int len = TREE_VEC_LENGTH (t);
1888 TREE_VEC_ELT (t, len) = mapcar (TREE_VEC_ELT (t, len), func);
1895 return copy_node (t);
1899 TREE_TYPE (t) = mapcar (TREE_TYPE (t), func);
1900 PTRMEM_CST_MEMBER (t) = mapcar (PTRMEM_CST_MEMBER (t), func);
1905 case AGGR_INIT_EXPR:
1907 TREE_OPERAND (t, 0) = mapcar (TREE_OPERAND (t, 0), func);
1908 TREE_OPERAND (t, 1) = mapcar (TREE_OPERAND (t, 1), func);
1909 TREE_OPERAND (t, 2) = mapcar (TREE_OPERAND (t, 2), func);
1912 case TRUTH_AND_EXPR:
1914 case TRUTH_XOR_EXPR:
1915 case TRUTH_ANDIF_EXPR:
1916 case TRUTH_ORIF_EXPR:
1917 case PREDECREMENT_EXPR:
1918 case PREINCREMENT_EXPR:
1919 case POSTDECREMENT_EXPR:
1920 case POSTINCREMENT_EXPR:
1923 case TRY_CATCH_EXPR:
1924 case WITH_CLEANUP_EXPR:
1929 TREE_OPERAND (t, 0) = mapcar (TREE_OPERAND (t, 0), func);
1930 TREE_OPERAND (t, 1) = mapcar (TREE_OPERAND (t, 1), func);
1935 TREE_TYPE (t) = mapcar (TREE_TYPE (t), func);
1936 TREE_OPERAND (t, 0) = mapcar (TREE_OPERAND (t, 0), func);
1937 TREE_OPERAND (t, 1) = mapcar (TREE_OPERAND (t, 1), func);
1938 TREE_OPERAND (t, 2) = NULL_TREE;
1944 case TRUTH_NOT_EXPR:
1946 case CLEANUP_POINT_EXPR:
1950 TREE_TYPE (t) = mapcar (TREE_TYPE (t), func);
1951 TREE_OPERAND (t, 0) = mapcar (TREE_OPERAND (t, 0), func);
1955 tmp = build_pointer_type (mapcar (TREE_TYPE (t), func));
1956 return cp_build_qualified_type (tmp, TYPE_QUALS (t));
1957 case REFERENCE_TYPE:
1958 tmp = build_reference_type (mapcar (TREE_TYPE (t), func));
1959 return cp_build_qualified_type (tmp, TYPE_QUALS (t));
1961 tmp = build_function_type (mapcar (TREE_TYPE (t), func),
1962 mapcar (TYPE_ARG_TYPES (t), func));
1963 return cp_build_qualified_type (tmp, TYPE_QUALS (t));
1965 tmp = build_cplus_array_type (mapcar (TREE_TYPE (t), func),
1966 mapcar (TYPE_DOMAIN (t), func));
1967 return cp_build_qualified_type (tmp, CP_TYPE_QUALS (t));
1969 tmp = build_index_type (mapcar (TYPE_MAX_VALUE (t), func));
1970 return cp_build_qualified_type (tmp, TYPE_QUALS (t));
1972 tmp = build_offset_type (mapcar (TYPE_OFFSET_BASETYPE (t), func),
1973 mapcar (TREE_TYPE (t), func));
1974 return cp_build_qualified_type (tmp, TYPE_QUALS (t));
1976 tmp = build_cplus_method_type
1977 (mapcar (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (t))), func),
1978 mapcar (TREE_TYPE (t), func),
1979 mapcar (TREE_CHAIN (TYPE_ARG_TYPES (t)), func));
1980 return cp_build_qualified_type (tmp, TYPE_QUALS (t));
1984 TREE_REALPART (t) = mapcar (TREE_REALPART (t), func);
1985 TREE_IMAGPART (t) = mapcar (TREE_REALPART (t), func);
1990 CONSTRUCTOR_ELTS (t) = mapcar (CONSTRUCTOR_ELTS (t), func);
1993 case TEMPLATE_TEMPLATE_PARM:
1994 return copy_template_template_parm (t);
1998 TREE_OPERAND (t, 0) = mapcar (TREE_OPERAND (t, 0), func);
1999 TREE_OPERAND (t, 1) = mapcar (TREE_OPERAND (t, 1), func);
2000 TREE_OPERAND (t, 2) = NULL_TREE;
2005 TREE_OPERAND (t, 0) = mapcar (TREE_OPERAND (t, 0), func);
2006 TREE_OPERAND (t, 1) = mapcar (TREE_OPERAND (t, 1), func);
2007 TREE_OPERAND (t, 2) = mapcar (TREE_OPERAND (t, 2), func);
2014 TREE_OPERAND (t, 0) = mapcar (TREE_OPERAND (t, 0), func);
2019 TREE_TYPE (t) = mapcar (TREE_TYPE (t), func);
2023 if (TYPE_PTRMEMFUNC_P (t))
2024 return build_ptrmemfunc_type
2025 (mapcar (TYPE_PTRMEMFUNC_FN_TYPE (t), func));
2026 /* else fall through */
2029 my_friendly_abort (19990815);
2031 my_friendly_abort (107);
2036 /* Returns T if T is allocated on the permanent obstack, NULL_TREE
2043 return TREE_PERMANENT (t) ? t : NULL_TREE;
2050 if (TREE_PERMANENT (t))
2053 /* Support `void f () { extern int i; A<&i> a; }' */
2054 if ((TREE_CODE (t) == VAR_DECL || TREE_CODE (t) == FUNCTION_DECL)
2059 /* copy_rtx won't make a new SYMBOL_REF, so call make_decl_rtl again. */
2061 make_decl_rtl (t, NULL_PTR, 1);
2068 /* Assuming T is a node built bottom-up, make it all exist on
2069 permanent obstack, if it is not permanent already. */
2072 copy_to_permanent (t)
2075 if (t == NULL_TREE || TREE_PERMANENT (t))
2078 push_permanent_obstack ();
2079 t = mapcar (t, perm_manip);
2085 #ifdef GATHER_STATISTICS
2086 extern int depth_reached;
2090 print_lang_statistics ()
2092 extern struct obstack decl_obstack;
2093 print_obstack_statistics ("class_obstack", &class_obstack);
2094 print_obstack_statistics ("decl_obstack", &decl_obstack);
2095 print_search_statistics ();
2096 print_class_statistics ();
2097 #ifdef GATHER_STATISTICS
2098 fprintf (stderr, "maximum template instantiation depth reached: %d\n",
2103 /* This is used by the `assert' macro. It is provided in libgcc.a,
2104 which `cc' doesn't know how to link. Note that the C++ front-end
2105 no longer actually uses the `assert' macro (instead, it calls
2106 my_friendly_assert). But all of the back-end files still need this. */
2109 __eprintf (string, expression, line, filename)
2111 const char *expression;
2113 const char *filename;
2115 fprintf (stderr, string, expression, line, filename);
2120 /* Return, as an INTEGER_CST node, the number of elements for TYPE
2121 (which is an ARRAY_TYPE). This counts only elements of the top
2125 array_type_nelts_top (type)
2128 return fold (build (PLUS_EXPR, sizetype,
2129 array_type_nelts (type),
2133 /* Return, as an INTEGER_CST node, the number of elements for TYPE
2134 (which is an ARRAY_TYPE). This one is a recursive count of all
2135 ARRAY_TYPEs that are clumped together. */
2138 array_type_nelts_total (type)
2141 tree sz = array_type_nelts_top (type);
2142 type = TREE_TYPE (type);
2143 while (TREE_CODE (type) == ARRAY_TYPE)
2145 tree n = array_type_nelts_top (type);
2146 sz = fold (build (MULT_EXPR, sizetype, sz, n));
2147 type = TREE_TYPE (type);
2157 if (TREE_CODE (t) != TREE_LIST && ! TREE_SIDE_EFFECTS (t))
2159 else if (TREE_CODE (t) == TARGET_EXPR)
2161 if (TREE_CODE (TREE_OPERAND (t, 1)) == AGGR_INIT_EXPR)
2163 mark_used (TREE_OPERAND (TREE_OPERAND (TREE_OPERAND (t, 1), 0), 0));
2164 return build_cplus_new
2165 (TREE_TYPE (t), break_out_target_exprs (TREE_OPERAND (t, 1)));
2168 TREE_OPERAND (t, 0) = build (VAR_DECL, TREE_TYPE (t));
2169 layout_decl (TREE_OPERAND (t, 0), 0);
2172 else if (TREE_CODE (t) == CALL_EXPR)
2173 mark_used (TREE_OPERAND (TREE_OPERAND (t, 0), 0));
2178 /* Actually, we'll just clean out the target exprs for the moment. */
2181 break_out_target_exprs (t)
2184 return mapcar (t, bot_manip);
2187 /* Obstack used for allocating nodes in template function and variable
2190 /* Similar to `build_nt', except we build
2191 on the permanent_obstack, regardless. */
2194 build_min_nt VPROTO((enum tree_code code, ...))
2197 enum tree_code code;
2199 register struct obstack *ambient_obstack = expression_obstack;
2202 register int length;
2208 code = va_arg (p, enum tree_code);
2211 expression_obstack = &permanent_obstack;
2213 t = make_node (code);
2214 length = tree_code_length[(int) code];
2215 TREE_COMPLEXITY (t) = lineno;
2217 for (i = 0; i < length; i++)
2219 tree x = va_arg (p, tree);
2220 TREE_OPERAND (t, i) = copy_to_permanent (x);
2224 expression_obstack = ambient_obstack;
2228 /* Similar to `build', except we build
2229 on the permanent_obstack, regardless. */
2232 build_min VPROTO((enum tree_code code, tree tt, ...))
2235 enum tree_code code;
2238 register struct obstack *ambient_obstack = expression_obstack;
2241 register int length;
2247 code = va_arg (p, enum tree_code);
2248 tt = va_arg (p, tree);
2251 expression_obstack = &permanent_obstack;
2253 t = make_node (code);
2254 length = tree_code_length[(int) code];
2255 TREE_TYPE (t) = copy_to_permanent (tt);
2256 TREE_COMPLEXITY (t) = lineno;
2258 for (i = 0; i < length; i++)
2260 tree x = va_arg (p, tree);
2261 TREE_OPERAND (t, i) = copy_to_permanent (x);
2265 expression_obstack = ambient_obstack;
2269 /* Same as `tree_cons' but make a permanent object. */
2272 min_tree_cons (purpose, value, chain)
2273 tree purpose, value, chain;
2276 register struct obstack *ambient_obstack = current_obstack;
2277 current_obstack = &permanent_obstack;
2279 node = tree_cons (copy_to_permanent (purpose),
2280 copy_to_permanent (value), chain);
2281 current_obstack = ambient_obstack;
2289 if (TREE_CODE (t) == TYPE_DECL)
2291 if (TREE_CODE_CLASS (TREE_CODE (t)) == 't')
2292 return TYPE_STUB_DECL (t);
2294 my_friendly_abort (42);
2296 /* Stop compiler from complaining control reaches end of non-void function. */
2301 can_free (obstack, t)
2302 struct obstack *obstack;
2307 if (TREE_CODE (t) == TREE_VEC)
2308 size = (TREE_VEC_LENGTH (t)-1) * sizeof (tree) + sizeof (struct tree_vec);
2310 my_friendly_abort (42);
2312 #define ROUND(x) ((x + obstack_alignment_mask (obstack)) \
2313 & ~ obstack_alignment_mask (obstack))
2314 if ((char *)t + ROUND (size) == obstack_next_free (obstack))
2321 /* Return first vector element whose BINFO_TYPE is ELEM.
2322 Return 0 if ELEM is not in VEC. VEC may be NULL_TREE. */
2325 vec_binfo_member (elem, vec)
2331 for (i = 0; i < TREE_VEC_LENGTH (vec); ++i)
2332 if (same_type_p (elem, BINFO_TYPE (TREE_VEC_ELT (vec, i))))
2333 return TREE_VEC_ELT (vec, i);
2338 /* Kludge around the fact that DECL_CONTEXT for virtual functions returns
2339 the wrong thing for decl_function_context. Hopefully the uses in the
2340 backend won't matter, since we don't need a static chain for local class
2344 hack_decl_function_context (decl)
2347 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_FUNCTION_MEMBER_P (decl))
2348 return decl_function_context (TYPE_MAIN_DECL (DECL_CLASS_CONTEXT (decl)));
2349 return decl_function_context (decl);
2352 /* Returns the namespace that contains DECL, whether directly or
2356 decl_namespace_context (decl)
2361 if (TREE_CODE (decl) == NAMESPACE_DECL)
2363 else if (TYPE_P (decl))
2364 decl = CP_DECL_CONTEXT (TYPE_MAIN_DECL (decl));
2366 decl = CP_DECL_CONTEXT (decl);
2370 /* Return truthvalue of whether T1 is the same tree structure as T2.
2371 Return 1 if they are the same.
2372 Return 0 if they are understandably different.
2373 Return -1 if either contains tree structure not understood by
2377 cp_tree_equal (t1, t2)
2380 register enum tree_code code1, code2;
2385 if (t1 == 0 || t2 == 0)
2388 code1 = TREE_CODE (t1);
2389 code2 = TREE_CODE (t2);
2391 if (code1 == NOP_EXPR || code1 == CONVERT_EXPR || code1 == NON_LVALUE_EXPR)
2393 if (code2 == NOP_EXPR || code2 == CONVERT_EXPR || code2 == NON_LVALUE_EXPR)
2394 return cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
2396 return cp_tree_equal (TREE_OPERAND (t1, 0), t2);
2398 else if (code2 == NOP_EXPR || code2 == CONVERT_EXPR
2399 || code2 == NON_LVALUE_EXPR)
2400 return cp_tree_equal (t1, TREE_OPERAND (t2, 0));
2408 return TREE_INT_CST_LOW (t1) == TREE_INT_CST_LOW (t2)
2409 && TREE_INT_CST_HIGH (t1) == TREE_INT_CST_HIGH (t2);
2412 return REAL_VALUES_EQUAL (TREE_REAL_CST (t1), TREE_REAL_CST (t2));
2415 return TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
2416 && !bcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
2417 TREE_STRING_LENGTH (t1));
2420 /* We need to do this when determining whether or not two
2421 non-type pointer to member function template arguments
2423 if (!(same_type_p (TREE_TYPE (t1), TREE_TYPE (t2))
2424 /* The first operand is RTL. */
2425 && TREE_OPERAND (t1, 0) == TREE_OPERAND (t2, 0)))
2427 return cp_tree_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
2430 cmp = cp_tree_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2));
2433 cmp = cp_tree_equal (TREE_VALUE (t1), TREE_VALUE (t2));
2436 return cp_tree_equal (TREE_CHAIN (t1), TREE_CHAIN (t2));
2439 return cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
2442 cmp = cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
2445 return simple_cst_list_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
2448 /* Special case: if either target is an unallocated VAR_DECL,
2449 it means that it's going to be unified with whatever the
2450 TARGET_EXPR is really supposed to initialize, so treat it
2451 as being equivalent to anything. */
2452 if ((TREE_CODE (TREE_OPERAND (t1, 0)) == VAR_DECL
2453 && DECL_NAME (TREE_OPERAND (t1, 0)) == NULL_TREE
2454 && DECL_RTL (TREE_OPERAND (t1, 0)) == 0)
2455 || (TREE_CODE (TREE_OPERAND (t2, 0)) == VAR_DECL
2456 && DECL_NAME (TREE_OPERAND (t2, 0)) == NULL_TREE
2457 && DECL_RTL (TREE_OPERAND (t2, 0)) == 0))
2460 cmp = cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
2463 return cp_tree_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
2465 case WITH_CLEANUP_EXPR:
2466 cmp = cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
2469 return cp_tree_equal (TREE_OPERAND (t1, 2), TREE_OPERAND (t1, 2));
2472 if (TREE_OPERAND (t1, 1) == TREE_OPERAND (t2, 1))
2473 return cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
2482 case TEMPLATE_PARM_INDEX:
2483 return TEMPLATE_PARM_IDX (t1) == TEMPLATE_PARM_IDX (t2)
2484 && TEMPLATE_PARM_LEVEL (t1) == TEMPLATE_PARM_LEVEL (t2);
2488 if (TREE_CODE (TREE_OPERAND (t1, 0)) != TREE_CODE (TREE_OPERAND (t2, 0)))
2490 if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (t1, 0))) == 't')
2491 return same_type_p (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
2495 /* Two pointer-to-members are the same if they point to the same
2496 field or function in the same class. */
2497 return (PTRMEM_CST_MEMBER (t1) == PTRMEM_CST_MEMBER (t2)
2498 && same_type_p (PTRMEM_CST_CLASS (t1), PTRMEM_CST_CLASS (t2)));
2504 switch (TREE_CODE_CLASS (code1))
2514 for (i=0; i<tree_code_length[(int) code1]; ++i)
2516 cmp = cp_tree_equal (TREE_OPERAND (t1, i), TREE_OPERAND (t2, i));
2526 /* Similar to make_tree_vec, but build on the momentary_obstack.
2527 Thus, these vectors are really and truly temporary. */
2534 push_expression_obstack ();
2535 node = make_tree_vec (len);
2540 /* Build a wrapper around some pointer PTR so we can use it as a tree. */
2543 build_ptr_wrapper (ptr)
2546 tree t = make_node (WRAPPER);
2547 WRAPPER_PTR (t) = ptr;
2551 /* Same, but on the expression_obstack. */
2554 build_expr_ptr_wrapper (ptr)
2558 push_expression_obstack ();
2559 t = build_ptr_wrapper (ptr);
2564 /* Build a wrapper around some integer I so we can use it as a tree. */
2567 build_int_wrapper (i)
2570 tree t = make_node (WRAPPER);
2571 WRAPPER_INT (t) = i;
2576 build_srcloc (file, line)
2582 /* Make sure that we put these on the permanent obstack; up in
2583 add_pending_template, we pass this return value into perm_tree_cons,
2584 which also puts it on the permanent_obstack. However, this wasn't
2585 explicitly doing the same. */
2586 register struct obstack *ambient_obstack = current_obstack;
2587 current_obstack = &permanent_obstack;
2589 t = make_node (SRCLOC);
2590 SRCLOC_FILE (t) = file;
2591 SRCLOC_LINE (t) = line;
2593 current_obstack = ambient_obstack;
2599 build_srcloc_here ()
2601 return build_srcloc (input_filename, lineno);
2605 push_expression_obstack ()
2607 push_obstacks_nochange ();
2608 current_obstack = expression_obstack;
2611 /* Begin allocating on the permanent obstack. When you're done
2612 allocating there, call pop_obstacks to return to the previous set
2616 push_permanent_obstack ()
2618 push_obstacks_nochange ();
2619 end_temporary_allocation ();
2622 /* The type of ARG when used as an lvalue. */
2628 tree type = TREE_TYPE (arg);
2629 if (TREE_CODE (arg) == OVERLOAD)
2630 type = unknown_type_node;
2634 /* The type of ARG for printing error messages; denote lvalues with
2641 tree type = TREE_TYPE (arg);
2642 if (TREE_CODE (type) == ARRAY_TYPE)
2644 else if (real_lvalue_p (arg))
2645 type = build_reference_type (lvalue_type (arg));
2646 else if (IS_AGGR_TYPE (type))
2647 type = lvalue_type (arg);
2652 /* Does FUNCTION use a variable-length argument list? */
2655 varargs_function_p (function)
2658 tree parm = TYPE_ARG_TYPES (TREE_TYPE (function));
2659 for (; parm; parm = TREE_CHAIN (parm))
2660 if (TREE_VALUE (parm) == void_type_node)
2665 /* Returns 1 if decl is a member of a class. */
2671 tree ctx = DECL_CONTEXT (decl);
2672 return (ctx && TREE_CODE_CLASS (TREE_CODE (ctx)) == 't');
2675 /* Create a placeholder for member access where we don't actually have an
2676 object that the access is against. */
2679 build_dummy_object (type)
2682 tree decl = build1 (NOP_EXPR, build_pointer_type (type), void_zero_node);
2683 return build_indirect_ref (decl, NULL_PTR);
2686 /* We've gotten a reference to a member of TYPE. Return *this if appropriate,
2687 or a dummy object otherwise. If BINFOP is non-0, it is filled with the
2688 binfo path from current_class_type to TYPE, or 0. */
2691 maybe_dummy_object (type, binfop)
2697 if (current_class_type
2698 && get_base_distance (type, current_class_type, 0, binfop) != -1)
2699 context = current_class_type;
2702 /* Reference from a nested class member function. */
2705 *binfop = TYPE_BINFO (type);
2708 if (current_class_ref && context == current_class_type)
2709 decl = current_class_ref;
2711 decl = build_dummy_object (context);
2716 /* Returns 1 if OB is a placeholder object, or a pointer to one. */
2719 is_dummy_object (ob)
2722 if (TREE_CODE (ob) == INDIRECT_REF)
2723 ob = TREE_OPERAND (ob, 0);
2724 return (TREE_CODE (ob) == NOP_EXPR
2725 && TREE_OPERAND (ob, 0) == void_zero_node);
2728 /* Returns 1 iff type T is a POD type, as defined in [basic.types]. */
2734 while (TREE_CODE (t) == ARRAY_TYPE)
2737 if (INTEGRAL_TYPE_P (t))
2738 return 1; /* integral, character or enumeral type */
2739 if (FLOAT_TYPE_P (t))
2742 return 1; /* pointer to non-member */
2743 if (TYPE_PTRMEM_P (t))
2744 return 1; /* pointer to member object */
2745 if (TYPE_PTRMEMFUNC_P (t))
2746 return 1; /* pointer to member function */
2748 if (! CLASS_TYPE_P (t))
2749 return 0; /* other non-class type (reference or function) */
2750 if (CLASSTYPE_NON_POD_P (t))
2755 /* Return a 1 if ATTR_NAME and ATTR_ARGS denote a valid C++-specific
2756 attribute for either declaration DECL or type TYPE and 0 otherwise.
2757 Plugged into valid_lang_attribute. */
2760 cp_valid_lang_attribute (attr_name, attr_args, decl, type)
2762 tree attr_args ATTRIBUTE_UNUSED;
2763 tree decl ATTRIBUTE_UNUSED;
2764 tree type ATTRIBUTE_UNUSED;
2766 if (is_attribute_p ("com_interface", attr_name))
2768 if (! flag_vtable_thunks)
2770 error ("`com_interface' only supported with -fvtable-thunks");
2774 if (attr_args != NULL_TREE
2775 || decl != NULL_TREE
2776 || ! CLASS_TYPE_P (type)
2777 || type != TYPE_MAIN_VARIANT (type))
2779 warning ("`com_interface' attribute can only be applied to class definitions");
2783 CLASSTYPE_COM_INTERFACE (type) = 1;
2786 else if (is_attribute_p ("init_priority", attr_name))
2788 tree initp_expr = (attr_args ? TREE_VALUE (attr_args): NULL_TREE);
2792 STRIP_NOPS (initp_expr);
2794 if (!initp_expr || TREE_CODE (initp_expr) != INTEGER_CST)
2796 error ("requested init_priority is not an integer constant");
2800 pri = TREE_INT_CST_LOW (initp_expr);
2802 while (TREE_CODE (type) == ARRAY_TYPE)
2803 type = TREE_TYPE (type);
2805 if (decl == NULL_TREE
2806 || TREE_CODE (decl) != VAR_DECL
2807 || ! TREE_STATIC (decl)
2808 || DECL_EXTERNAL (decl)
2809 || (TREE_CODE (type) != RECORD_TYPE
2810 && TREE_CODE (type) != UNION_TYPE)
2811 /* Static objects in functions are initialized the
2812 first time control passes through that
2813 function. This is not precise enough to pin down an
2814 init_priority value, so don't allow it. */
2815 || current_function_decl)
2817 error ("can only use init_priority attribute on file-scope definitions of objects of class type");
2821 if (pri > MAX_INIT_PRIORITY || pri <= 0)
2823 error ("requested init_priority is out of range");
2827 /* Check for init_priorities that are reserved for
2828 language and runtime support implementations.*/
2829 if (pri <= MAX_RESERVED_INIT_PRIORITY)
2832 ("requested init_priority is reserved for internal use");
2835 DECL_INIT_PRIORITY (decl) = pri;
2842 /* Return a new PTRMEM_CST of the indicated TYPE. The MEMBER is the
2843 thing pointed to by the constant. */
2846 make_ptrmem_cst (type, member)
2850 tree ptrmem_cst = make_node (PTRMEM_CST);
2851 /* If would seem a great convenience if make_node would set
2852 TREE_CONSTANT for things of class `c', but it does not. */
2853 TREE_CONSTANT (ptrmem_cst) = 1;
2854 TREE_TYPE (ptrmem_cst) = type;
2855 PTRMEM_CST_MEMBER (ptrmem_cst) = member;
2859 /* Initialize unsave for C++. */
2861 init_cplus_unsave ()
2863 lang_unsave_expr_now = cplus_unsave_expr_now;
2866 /* The C++ version of unsave_expr_now.
2867 See gcc/tree.c:unsave_expr_now for comments. */
2870 cplus_unsave_expr_now (expr)
2876 else if (TREE_CODE (expr) == AGGR_INIT_EXPR)
2878 unsave_expr_now (TREE_OPERAND (expr,0));
2879 if (TREE_OPERAND (expr, 1)
2880 && TREE_CODE (TREE_OPERAND (expr, 1)) == TREE_LIST)
2882 tree exp = TREE_OPERAND (expr, 1);
2885 unsave_expr_now (TREE_VALUE (exp));
2886 exp = TREE_CHAIN (exp);
2889 unsave_expr_now (TREE_OPERAND (expr,2));