xref: /openbsd/gnu/usr.bin/gcc/gcc/cp/tree.c (revision 4e43c760)
1 /* Language-dependent node constructors for parse phase of GNU compiler.
2    Copyright (C) 1987, 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3    1999, 2000, 2001, 2002 Free Software Foundation, Inc.
4    Hacked by Michael Tiemann (tiemann@cygnus.com)
5 
6 This file is part of GNU CC.
7 
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)
11 any later version.
12 
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.
17 
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.  */
22 
23 #include "config.h"
24 #include "system.h"
25 #include "tree.h"
26 #include "cp-tree.h"
27 #include "flags.h"
28 #include "real.h"
29 #include "rtl.h"
30 #include "toplev.h"
31 #include "ggc.h"
32 #include "insn-config.h"
33 #include "integrate.h"
34 #include "tree-inline.h"
35 #include "target.h"
36 
37 static tree bot_manip PARAMS ((tree *, int *, void *));
38 static tree bot_replace PARAMS ((tree *, int *, void *));
39 static tree build_cplus_array_type_1 PARAMS ((tree, tree));
40 static int list_hash_eq PARAMS ((const void *, const void *));
41 static hashval_t list_hash_pieces PARAMS ((tree, tree, tree));
42 static hashval_t list_hash PARAMS ((const void *));
43 static cp_lvalue_kind lvalue_p_1 PARAMS ((tree, int, int));
44 static tree no_linkage_helper PARAMS ((tree *, int *, void *));
45 static tree build_srcloc PARAMS ((const char *, int));
46 static tree mark_local_for_remap_r PARAMS ((tree *, int *, void *));
47 static tree cp_unsave_r PARAMS ((tree *, int *, void *));
48 static tree build_target_expr PARAMS ((tree, tree));
49 static tree count_trees_r PARAMS ((tree *, int *, void *));
50 static tree verify_stmt_tree_r PARAMS ((tree *, int *, void *));
51 static tree find_tree_r PARAMS ((tree *, int *, void *));
52 extern int cp_statement_code_p PARAMS ((enum tree_code));
53 
54 static tree handle_java_interface_attribute PARAMS ((tree *, tree, tree, int, bool *));
55 static tree handle_com_interface_attribute PARAMS ((tree *, tree, tree, int, bool *));
56 static tree handle_init_priority_attribute PARAMS ((tree *, tree, tree, int, bool *));
57 
58 /* If REF is an lvalue, returns the kind of lvalue that REF is.
59    Otherwise, returns clk_none.  If TREAT_CLASS_RVALUES_AS_LVALUES is
60    nonzero, rvalues of class type are considered lvalues.  */
61 
62 static cp_lvalue_kind
lvalue_p_1(ref,treat_class_rvalues_as_lvalues,allow_cast_as_lvalue)63 lvalue_p_1 (ref, treat_class_rvalues_as_lvalues, allow_cast_as_lvalue)
64      tree ref;
65      int treat_class_rvalues_as_lvalues;
66      int allow_cast_as_lvalue;
67 {
68   cp_lvalue_kind op1_lvalue_kind = clk_none;
69   cp_lvalue_kind op2_lvalue_kind = clk_none;
70 
71   if (TREE_CODE (TREE_TYPE (ref)) == REFERENCE_TYPE)
72     return clk_ordinary;
73 
74   if (ref == current_class_ptr)
75     return clk_none;
76 
77   switch (TREE_CODE (ref))
78     {
79       /* preincrements and predecrements are valid lvals, provided
80 	 what they refer to are valid lvals.  */
81     case PREINCREMENT_EXPR:
82     case PREDECREMENT_EXPR:
83     case SAVE_EXPR:
84     case UNSAVE_EXPR:
85     case TRY_CATCH_EXPR:
86     case WITH_CLEANUP_EXPR:
87     case REALPART_EXPR:
88     case IMAGPART_EXPR:
89       return lvalue_p_1 (TREE_OPERAND (ref, 0),
90 			 treat_class_rvalues_as_lvalues,
91 			 allow_cast_as_lvalue);
92 
93     case NOP_EXPR:
94       /* If expression doesn't change the type, we consider it as an
95 	 lvalue even when cast_as_lvalue extension isn't selected.
96 	 That's because parts of the compiler are alleged to be sloppy
97 	 about sticking in NOP_EXPR node for no good reason.  */
98       if (allow_cast_as_lvalue ||
99 	  same_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (ref)),
100 		       TYPE_MAIN_VARIANT (TREE_TYPE (TREE_OPERAND (ref, 0)))))
101 	return lvalue_p_1 (TREE_OPERAND (ref, 0),
102 			   treat_class_rvalues_as_lvalues,
103 			   allow_cast_as_lvalue);
104       else
105 	return clk_none;
106 
107     case COMPONENT_REF:
108       op1_lvalue_kind = lvalue_p_1 (TREE_OPERAND (ref, 0),
109 				    treat_class_rvalues_as_lvalues,
110 				    allow_cast_as_lvalue);
111       if (op1_lvalue_kind
112 	  /* The "field" can be a FUNCTION_DECL or an OVERLOAD in some
113 	     situations.  */
114 	  && TREE_CODE (TREE_OPERAND (ref, 1)) == FIELD_DECL
115 	  && DECL_C_BIT_FIELD (TREE_OPERAND (ref, 1)))
116 	{
117 	  /* Clear the ordinary bit.  If this object was a class
118 	     rvalue we want to preserve that information.  */
119 	  op1_lvalue_kind &= ~clk_ordinary;
120 	  /* The lvalue is for a btifield.  */
121 	  op1_lvalue_kind |= clk_bitfield;
122 	}
123       return op1_lvalue_kind;
124 
125     case STRING_CST:
126       return clk_ordinary;
127 
128     case VAR_DECL:
129       if (TREE_READONLY (ref) && ! TREE_STATIC (ref)
130 	  && DECL_LANG_SPECIFIC (ref)
131 	  && DECL_IN_AGGR_P (ref))
132 	return clk_none;
133     case INDIRECT_REF:
134     case ARRAY_REF:
135     case PARM_DECL:
136     case RESULT_DECL:
137       if (TREE_CODE (TREE_TYPE (ref)) != METHOD_TYPE)
138 	return clk_ordinary;
139       break;
140 
141       /* A currently unresolved scope ref.  */
142     case SCOPE_REF:
143       abort ();
144     case OFFSET_REF:
145       if (TREE_CODE (TREE_OPERAND (ref, 1)) == FUNCTION_DECL)
146 	return clk_ordinary;
147       /* Fall through.  */
148     case MAX_EXPR:
149     case MIN_EXPR:
150       op1_lvalue_kind = lvalue_p_1 (TREE_OPERAND (ref, 0),
151 				    treat_class_rvalues_as_lvalues,
152 				    allow_cast_as_lvalue);
153       op2_lvalue_kind = lvalue_p_1 (TREE_OPERAND (ref, 1),
154 				    treat_class_rvalues_as_lvalues,
155 				    allow_cast_as_lvalue);
156       break;
157 
158     case COND_EXPR:
159       op1_lvalue_kind = lvalue_p_1 (TREE_OPERAND (ref, 1),
160 				    treat_class_rvalues_as_lvalues,
161 				    allow_cast_as_lvalue);
162       op2_lvalue_kind = lvalue_p_1 (TREE_OPERAND (ref, 2),
163 				    treat_class_rvalues_as_lvalues,
164 				    allow_cast_as_lvalue);
165       break;
166 
167     case MODIFY_EXPR:
168       return clk_ordinary;
169 
170     case COMPOUND_EXPR:
171       return lvalue_p_1 (TREE_OPERAND (ref, 1),
172 			 treat_class_rvalues_as_lvalues,
173 			 allow_cast_as_lvalue);
174 
175     case TARGET_EXPR:
176       return treat_class_rvalues_as_lvalues ? clk_class : clk_none;
177 
178     case CALL_EXPR:
179     case VA_ARG_EXPR:
180       return ((treat_class_rvalues_as_lvalues
181 	       && IS_AGGR_TYPE (TREE_TYPE (ref)))
182 	      ? clk_class : clk_none);
183 
184     case FUNCTION_DECL:
185       /* All functions (except non-static-member functions) are
186 	 lvalues.  */
187       return (DECL_NONSTATIC_MEMBER_FUNCTION_P (ref)
188 	      ? clk_none : clk_ordinary);
189 
190     default:
191       break;
192     }
193 
194   /* If one operand is not an lvalue at all, then this expression is
195      not an lvalue.  */
196   if (!op1_lvalue_kind || !op2_lvalue_kind)
197     return clk_none;
198 
199   /* Otherwise, it's an lvalue, and it has all the odd properties
200      contributed by either operand.  */
201   op1_lvalue_kind = op1_lvalue_kind | op2_lvalue_kind;
202   /* It's not an ordinary lvalue if it involves either a bit-field or
203      a class rvalue.  */
204   if ((op1_lvalue_kind & ~clk_ordinary) != clk_none)
205     op1_lvalue_kind &= ~clk_ordinary;
206   return op1_lvalue_kind;
207 }
208 
209 /* If REF is an lvalue, returns the kind of lvalue that REF is.
210    Otherwise, returns clk_none.  Lvalues can be assigned, unless they
211    have TREE_READONLY, or unless they are FUNCTION_DECLs.  Lvalues can
212    have their address taken, unless they have DECL_REGISTER.  */
213 
214 cp_lvalue_kind
real_lvalue_p(ref)215 real_lvalue_p (ref)
216      tree ref;
217 {
218   return lvalue_p_1 (ref, /*treat_class_rvalues_as_lvalues=*/ 0, /*cast*/ 1);
219 }
220 
221 /* Returns the kind of lvalue that REF is, in the sense of
222    [basic.lval].  This function should really be named lvalue_p; it
223    computes the C++ definition of lvalue.  */
224 
225 cp_lvalue_kind
real_non_cast_lvalue_p(tree ref)226 real_non_cast_lvalue_p (tree ref)
227 {
228   return lvalue_p_1 (ref,
229 		     /*treat_class_rvalues_as_lvalues=*/0,
230 		     /*allow_cast_as_lvalue=*/0);
231 }
232 
233 /* This differs from real_lvalue_p in that class rvalues are
234    considered lvalues.  */
235 
236 int
lvalue_p(ref)237 lvalue_p (ref)
238      tree ref;
239 {
240   return
241     (lvalue_p_1 (ref, /*class rvalue ok*/ 1, /*cast*/ 1) != clk_none);
242 }
243 
244 int
non_cast_lvalue_p(ref)245 non_cast_lvalue_p (ref)
246      tree ref;
247 {
248   return
249     (lvalue_p_1 (ref, /*class rvalue ok*/ 1, /*cast*/ 0) != clk_none);
250 }
251 
252 /* Return nonzero if REF is an lvalue valid for this language;
253    otherwise, print an error message and return zero.  */
254 
255 int
lvalue_or_else(ref,string)256 lvalue_or_else (ref, string)
257      tree ref;
258      const char *string;
259 {
260   int ret = lvalue_p_1 (ref, /* class rvalue ok */ 1, /* cast ok */ 1);
261   int win = (ret != clk_none);
262   if (! win)
263     error ("non-lvalue in %s", string);
264   return win;
265 }
266 
267 int
non_cast_lvalue_or_else(ref,string)268 non_cast_lvalue_or_else (ref, string)
269      tree ref;
270      const char *string;
271 {
272   int ret = lvalue_p_1 (ref, /* class rvalue ok */ 1, /* cast ok */ 0);
273   int win = (ret != clk_none);
274   if (! win)
275     error ("non-lvalue in %s", string);
276   return win;
277 }
278 
279 /* Build a TARGET_EXPR, initializing the DECL with the VALUE.  */
280 
281 static tree
build_target_expr(decl,value)282 build_target_expr (decl, value)
283      tree decl;
284      tree value;
285 {
286   tree t;
287 
288   t = build (TARGET_EXPR, TREE_TYPE (decl), decl, value,
289 	     cxx_maybe_build_cleanup (decl), NULL_TREE);
290   /* We always set TREE_SIDE_EFFECTS so that expand_expr does not
291      ignore the TARGET_EXPR.  If there really turn out to be no
292      side-effects, then the optimizer should be able to get rid of
293      whatever code is generated anyhow.  */
294   TREE_SIDE_EFFECTS (t) = 1;
295 
296   return t;
297 }
298 
299 /* INIT is a CALL_EXPR which needs info about its target.
300    TYPE is the type that this initialization should appear to have.
301 
302    Build an encapsulation of the initialization to perform
303    and return it so that it can be processed by language-independent
304    and language-specific expression expanders.  */
305 
306 tree
build_cplus_new(type,init)307 build_cplus_new (type, init)
308      tree type;
309      tree init;
310 {
311   tree fn;
312   tree slot;
313   tree rval;
314 
315   /* Make sure that we're not trying to create an instance of an
316      abstract class.  */
317   abstract_virtuals_error (NULL_TREE, type);
318 
319   if (TREE_CODE (init) != CALL_EXPR && TREE_CODE (init) != AGGR_INIT_EXPR)
320     return convert (type, init);
321 
322   slot = build (VAR_DECL, type);
323   DECL_ARTIFICIAL (slot) = 1;
324   DECL_CONTEXT (slot) = current_function_decl;
325   layout_decl (slot, 0);
326 
327   /* We split the CALL_EXPR into its function and its arguments here.
328      Then, in expand_expr, we put them back together.  The reason for
329      this is that this expression might be a default argument
330      expression.  In that case, we need a new temporary every time the
331      expression is used.  That's what break_out_target_exprs does; it
332      replaces every AGGR_INIT_EXPR with a copy that uses a fresh
333      temporary slot.  Then, expand_expr builds up a call-expression
334      using the new slot.  */
335   fn = TREE_OPERAND (init, 0);
336   rval = build (AGGR_INIT_EXPR, type, fn, TREE_OPERAND (init, 1), slot);
337   TREE_SIDE_EFFECTS (rval) = 1;
338   AGGR_INIT_VIA_CTOR_P (rval)
339     = (TREE_CODE (fn) == ADDR_EXPR
340        && TREE_CODE (TREE_OPERAND (fn, 0)) == FUNCTION_DECL
341        && DECL_CONSTRUCTOR_P (TREE_OPERAND (fn, 0)));
342   rval = build_target_expr (slot, rval);
343 
344   return rval;
345 }
346 
347 /* Build a TARGET_EXPR using INIT to initialize a new temporary of the
348    indicated TYPE.  */
349 
350 tree
build_target_expr_with_type(init,type)351 build_target_expr_with_type (init, type)
352      tree init;
353      tree type;
354 {
355   tree slot;
356   tree rval;
357 
358   if (TREE_CODE (init) == TARGET_EXPR)
359     return init;
360   else if (CLASS_TYPE_P (type) && !TYPE_HAS_TRIVIAL_INIT_REF (type)
361 	   && TREE_CODE (init) != COND_EXPR
362 	   && TREE_CODE (init) != CONSTRUCTOR)
363     /* We need to build up a copy constructor call.  COND_EXPR is a special
364        case because we already have copies on the arms and we don't want
365        another one here.  A CONSTRUCTOR is aggregate initialization, which
366        is handled separately.  */
367     return force_rvalue (init);
368 
369   slot = build (VAR_DECL, type);
370   DECL_ARTIFICIAL (slot) = 1;
371   DECL_CONTEXT (slot) = current_function_decl;
372   layout_decl (slot, 0);
373   rval = build_target_expr (slot, init);
374 
375   return rval;
376 }
377 
378 /* Like build_target_expr_with_type, but use the type of INIT.  */
379 
380 tree
get_target_expr(init)381 get_target_expr (init)
382      tree init;
383 {
384   return build_target_expr_with_type (init, TREE_TYPE (init));
385 }
386 
387 /* Construct, lay out and return the type of methods belonging to class
388    BASETYPE and whose arguments are described by ARGTYPES and whose values
389    are described by RETTYPE.  If each type exists already, reuse it.  */
390 
391 tree
build_cplus_method_type(basetype,rettype,argtypes)392 build_cplus_method_type (basetype, rettype, argtypes)
393      tree basetype, rettype, argtypes;
394 {
395   register tree t;
396   tree ptype;
397   int hashcode;
398 
399   /* Make a node of the sort we want.  */
400   t = make_node (METHOD_TYPE);
401 
402   TYPE_METHOD_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype);
403   TREE_TYPE (t) = rettype;
404   ptype = build_pointer_type (basetype);
405 
406   /* The actual arglist for this function includes a "hidden" argument
407      which is "this".  Put it into the list of argument types.  */
408   argtypes = tree_cons (NULL_TREE, ptype, argtypes);
409   TYPE_ARG_TYPES (t) = argtypes;
410   TREE_SIDE_EFFECTS (argtypes) = 1;  /* Mark first argtype as "artificial".  */
411 
412   /* If we already have such a type, use the old one and free this one.
413      Note that it also frees up the above cons cell if found.  */
414   hashcode = TYPE_HASH (basetype) + TYPE_HASH (rettype) +
415     type_hash_list (argtypes);
416 
417   t = type_hash_canon (hashcode, t);
418 
419   if (!COMPLETE_TYPE_P (t))
420     layout_type (t);
421 
422   return t;
423 }
424 
425 static tree
build_cplus_array_type_1(elt_type,index_type)426 build_cplus_array_type_1 (elt_type, index_type)
427      tree elt_type;
428      tree index_type;
429 {
430   tree t;
431 
432   if (elt_type == error_mark_node || index_type == error_mark_node)
433     return error_mark_node;
434 
435   /* Don't do the minimal thing just because processing_template_decl is
436      set; we want to give string constants the right type immediately, so
437      we don't have to fix them up at instantiation time.  */
438   if ((processing_template_decl
439        && index_type && TYPE_MAX_VALUE (index_type)
440        && TREE_CODE (TYPE_MAX_VALUE (index_type)) != INTEGER_CST)
441       || uses_template_parms (elt_type)
442       || (index_type && uses_template_parms (index_type)))
443     {
444       t = make_node (ARRAY_TYPE);
445       TREE_TYPE (t) = elt_type;
446       TYPE_DOMAIN (t) = index_type;
447     }
448   else
449     t = build_array_type (elt_type, index_type);
450 
451   /* Push these needs up so that initialization takes place
452      more easily.  */
453   TYPE_NEEDS_CONSTRUCTING (t)
454     = TYPE_NEEDS_CONSTRUCTING (TYPE_MAIN_VARIANT (elt_type));
455   TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)
456     = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TYPE_MAIN_VARIANT (elt_type));
457   return t;
458 }
459 
460 tree
build_cplus_array_type(elt_type,index_type)461 build_cplus_array_type (elt_type, index_type)
462      tree elt_type;
463      tree index_type;
464 {
465   tree t;
466   int type_quals = cp_type_quals (elt_type);
467   int cv_quals = type_quals & (TYPE_QUAL_CONST|TYPE_QUAL_VOLATILE);
468   int other_quals = type_quals & ~(TYPE_QUAL_CONST|TYPE_QUAL_VOLATILE);
469 
470   if (cv_quals)
471     elt_type = cp_build_qualified_type (elt_type, other_quals);
472 
473   t = build_cplus_array_type_1 (elt_type, index_type);
474 
475   if (cv_quals)
476     t = cp_build_qualified_type (t, cv_quals);
477 
478   return t;
479 }
480 
481 /* Make a variant of TYPE, qualified with the TYPE_QUALS.  Handles
482    arrays correctly.  In particular, if TYPE is an array of T's, and
483    TYPE_QUALS is non-empty, returns an array of qualified T's.
484 
485    FLAGS determines how to deal with illformed qualifications. If
486    tf_ignore_bad_quals is set, then bad qualifications are dropped
487    (this is permitted if TYPE was introduced via a typedef or template
488    type parameter). If bad qualifications are dropped and tf_warning
489    is set, then a warning is issued for non-const qualifications.  If
490    tf_ignore_bad_quals is not set and tf_error is not set, we
491    return error_mark_node. Otherwise, we issue an error, and ignore
492    the qualifications.
493 
494    Qualification of a reference type is valid when the reference came
495    via a typedef or template type argument. [dcl.ref] No such
496    dispensation is provided for qualifying a function type.  [dcl.fct]
497    DR 295 queries this and the proposed resolution brings it into line
498    with qualifiying a reference.  We implement the DR.  We also behave
499    in a similar manner for restricting non-pointer types.  */
500 
501 tree
cp_build_qualified_type_real(type,type_quals,complain)502 cp_build_qualified_type_real (type, type_quals, complain)
503      tree type;
504      int type_quals;
505      tsubst_flags_t complain;
506 {
507   tree result;
508   int bad_quals = TYPE_UNQUALIFIED;
509   /* We keep bad function qualifiers separate, so that we can decide
510      whether to implement DR 295 or not. DR 295 break existing code,
511      unfortunately. Remove this variable to implement the defect
512      report.  */
513   int bad_func_quals = TYPE_UNQUALIFIED;
514 
515   if (type == error_mark_node)
516     return type;
517 
518   if (type_quals == cp_type_quals (type))
519     return type;
520 
521   /* A reference, fucntion or method type shall not be cv qualified.
522      [dcl.ref], [dct.fct]  */
523   if (type_quals & (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE)
524       && (TREE_CODE (type) == REFERENCE_TYPE
525 	  || TREE_CODE (type) == FUNCTION_TYPE
526 	  || TREE_CODE (type) == METHOD_TYPE))
527     {
528       bad_quals |= type_quals & (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE);
529       if (TREE_CODE (type) != REFERENCE_TYPE)
530 	bad_func_quals |= type_quals & (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE);
531       type_quals &= ~(TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE);
532     }
533 
534   /* A restrict-qualified type must be a pointer (or reference)
535      to object or incomplete type.  */
536   if ((type_quals & TYPE_QUAL_RESTRICT)
537       && TREE_CODE (type) != TEMPLATE_TYPE_PARM
538       && TREE_CODE (type) != TYPENAME_TYPE
539       && !POINTER_TYPE_P (type))
540     {
541       bad_quals |= TYPE_QUAL_RESTRICT;
542       type_quals &= ~TYPE_QUAL_RESTRICT;
543     }
544 
545   if (bad_quals == TYPE_UNQUALIFIED)
546     /*OK*/;
547   else if (!(complain & (tf_error | tf_ignore_bad_quals)))
548     return error_mark_node;
549   else if (bad_func_quals && !(complain & tf_error))
550     return error_mark_node;
551   else
552     {
553       if (complain & tf_ignore_bad_quals)
554  	/* We're not going to warn about constifying things that can't
555  	   be constified.  */
556  	bad_quals &= ~TYPE_QUAL_CONST;
557       bad_quals |= bad_func_quals;
558       if (bad_quals)
559  	{
560  	  tree bad_type = build_qualified_type (ptr_type_node, bad_quals);
561 
562  	  if (!(complain & tf_ignore_bad_quals)
563 	      || bad_func_quals)
564  	    error ("`%V' qualifiers cannot be applied to `%T'",
565 		   bad_type, type);
566  	}
567     }
568 
569   if (TREE_CODE (type) == ARRAY_TYPE)
570     {
571       /* In C++, the qualification really applies to the array element
572 	 type.  Obtain the appropriately qualified element type.  */
573       tree t;
574       tree element_type
575 	= cp_build_qualified_type_real (TREE_TYPE (type),
576 					type_quals,
577 					complain);
578 
579       if (element_type == error_mark_node)
580 	return error_mark_node;
581 
582       /* See if we already have an identically qualified type.  */
583       for (t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
584 	if (cp_type_quals (t) == type_quals
585 	    && TYPE_NAME (t) == TYPE_NAME (type)
586 	    && TYPE_CONTEXT (t) == TYPE_CONTEXT (type))
587 	  break;
588 
589       if (!t)
590 	{
591 	  /* Make a new array type, just like the old one, but with the
592 	     appropriately qualified element type.  */
593 	  t = build_type_copy (type);
594 	  TREE_TYPE (t) = element_type;
595 	}
596 
597       /* Even if we already had this variant, we update
598 	 TYPE_NEEDS_CONSTRUCTING and TYPE_HAS_NONTRIVIAL_DESTRUCTOR in case
599 	 they changed since the variant was originally created.
600 
601 	 This seems hokey; if there is some way to use a previous
602 	 variant *without* coming through here,
603 	 TYPE_NEEDS_CONSTRUCTING will never be updated.  */
604       TYPE_NEEDS_CONSTRUCTING (t)
605 	= TYPE_NEEDS_CONSTRUCTING (TYPE_MAIN_VARIANT (element_type));
606       TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)
607 	= TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TYPE_MAIN_VARIANT (element_type));
608       return t;
609     }
610   else if (TYPE_PTRMEMFUNC_P (type))
611     {
612       /* For a pointer-to-member type, we can't just return a
613 	 cv-qualified version of the RECORD_TYPE.  If we do, we
614 	 haven't changed the field that contains the actual pointer to
615 	 a method, and so TYPE_PTRMEMFUNC_FN_TYPE will be wrong.  */
616       tree t;
617 
618       t = TYPE_PTRMEMFUNC_FN_TYPE (type);
619       t = cp_build_qualified_type_real (t, type_quals, complain);
620       return build_ptrmemfunc_type (t);
621     }
622 
623   /* Retrieve (or create) the appropriately qualified variant.  */
624   result = build_qualified_type (type, type_quals);
625 
626   /* If this was a pointer-to-method type, and we just made a copy,
627      then we need to unshare the record that holds the cached
628      pointer-to-member-function type, because these will be distinct
629      between the unqualified and qualified types.  */
630   if (result != type
631       && TREE_CODE (type) == POINTER_TYPE
632       && TREE_CODE (TREE_TYPE (type)) == METHOD_TYPE)
633     TYPE_LANG_SPECIFIC (result) = NULL;
634 
635   return result;
636 }
637 
638 /* Returns the canonical version of TYPE.  In other words, if TYPE is
639    a typedef, returns the underlying type.  The cv-qualification of
640    the type returned matches the type input; they will always be
641    compatible types.  */
642 
643 tree
canonical_type_variant(t)644 canonical_type_variant (t)
645      tree t;
646 {
647   return cp_build_qualified_type (TYPE_MAIN_VARIANT (t), cp_type_quals (t));
648 }
649 
650 /* Makes new binfos for the indirect bases under BINFO, and updates
651    BINFO_OFFSET for them and their bases.  */
652 
653 void
unshare_base_binfos(binfo)654 unshare_base_binfos (binfo)
655      tree binfo;
656 {
657   tree binfos = BINFO_BASETYPES (binfo);
658   tree new_binfo;
659   int j;
660 
661   if (binfos == NULL_TREE)
662     return;
663 
664   /* Now unshare the structure beneath BINFO.  */
665   for (j = TREE_VEC_LENGTH (binfos)-1;
666        j >= 0; j--)
667     {
668       tree base_binfo = TREE_VEC_ELT (binfos, j);
669       new_binfo = TREE_VEC_ELT (binfos, j)
670 	= make_binfo (BINFO_OFFSET (base_binfo),
671 		      base_binfo,
672 		      BINFO_VTABLE (base_binfo),
673 		      BINFO_VIRTUALS (base_binfo));
674       TREE_VIA_PUBLIC (new_binfo) = TREE_VIA_PUBLIC (base_binfo);
675       TREE_VIA_PROTECTED (new_binfo) = TREE_VIA_PROTECTED (base_binfo);
676       TREE_VIA_VIRTUAL (new_binfo) = TREE_VIA_VIRTUAL (base_binfo);
677       BINFO_INHERITANCE_CHAIN (new_binfo) = binfo;
678       BINFO_PRIMARY_BASE_OF (new_binfo) = NULL_TREE;
679       unshare_base_binfos (new_binfo);
680     }
681 }
682 
683 
684 /* Hashing of lists so that we don't make duplicates.
685    The entry point is `list_hash_canon'.  */
686 
687 /* Now here is the hash table.  When recording a list, it is added
688    to the slot whose index is the hash code mod the table size.
689    Note that the hash table is used for several kinds of lists.
690    While all these live in the same table, they are completely independent,
691    and the hash code is computed differently for each of these.  */
692 
693 static GTY ((param_is (union tree_node))) htab_t list_hash_table;
694 
695 struct list_proxy
696 {
697   tree purpose;
698   tree value;
699   tree chain;
700 };
701 
702 /* Compare ENTRY (an entry in the hash table) with DATA (a list_proxy
703    for a node we are thinking about adding).  */
704 
705 static int
list_hash_eq(entry,data)706 list_hash_eq (entry, data)
707      const void *entry;
708      const void *data;
709 {
710   tree t = (tree) entry;
711   struct list_proxy *proxy = (struct list_proxy *) data;
712 
713   return (TREE_VALUE (t) == proxy->value
714 	  && TREE_PURPOSE (t) == proxy->purpose
715 	  && TREE_CHAIN (t) == proxy->chain);
716 }
717 
718 /* Compute a hash code for a list (chain of TREE_LIST nodes
719    with goodies in the TREE_PURPOSE, TREE_VALUE, and bits of the
720    TREE_COMMON slots), by adding the hash codes of the individual entries.  */
721 
722 static hashval_t
list_hash_pieces(purpose,value,chain)723 list_hash_pieces (purpose, value, chain)
724      tree purpose;
725      tree value;
726      tree chain;
727 {
728   hashval_t hashcode = 0;
729 
730   if (chain)
731     hashcode += TYPE_HASH (chain);
732 
733   if (value)
734     hashcode += TYPE_HASH (value);
735   else
736     hashcode += 1007;
737   if (purpose)
738     hashcode += TYPE_HASH (purpose);
739   else
740     hashcode += 1009;
741   return hashcode;
742 }
743 
744 /* Hash an already existing TREE_LIST.  */
745 
746 static hashval_t
list_hash(p)747 list_hash (p)
748      const void *p;
749 {
750   tree t = (tree) p;
751   return list_hash_pieces (TREE_PURPOSE (t),
752 			   TREE_VALUE (t),
753 			   TREE_CHAIN (t));
754 }
755 
756 /* Given list components PURPOSE, VALUE, AND CHAIN, return the canonical
757    object for an identical list if one already exists.  Otherwise, build a
758    new one, and record it as the canonical object.  */
759 
760 tree
hash_tree_cons(purpose,value,chain)761 hash_tree_cons (purpose, value, chain)
762      tree purpose, value, chain;
763 {
764   int hashcode = 0;
765   PTR* slot;
766   struct list_proxy proxy;
767 
768   /* Hash the list node.  */
769   hashcode = list_hash_pieces (purpose, value, chain);
770   /* Create a proxy for the TREE_LIST we would like to create.  We
771      don't actually create it so as to avoid creating garbage.  */
772   proxy.purpose = purpose;
773   proxy.value = value;
774   proxy.chain = chain;
775   /* See if it is already in the table.  */
776   slot = htab_find_slot_with_hash (list_hash_table, &proxy, hashcode,
777 				   INSERT);
778   /* If not, create a new node.  */
779   if (!*slot)
780     *slot = (PTR) tree_cons (purpose, value, chain);
781   return *slot;
782 }
783 
784 /* Constructor for hashed lists.  */
785 
786 tree
hash_tree_chain(value,chain)787 hash_tree_chain (value, chain)
788      tree value, chain;
789 {
790   return hash_tree_cons (NULL_TREE, value, chain);
791 }
792 
793 /* Similar, but used for concatenating two lists.  */
794 
795 tree
hash_chainon(list1,list2)796 hash_chainon (list1, list2)
797      tree list1, list2;
798 {
799   if (list2 == 0)
800     return list1;
801   if (list1 == 0)
802     return list2;
803   if (TREE_CHAIN (list1) == NULL_TREE)
804     return hash_tree_chain (TREE_VALUE (list1), list2);
805   return hash_tree_chain (TREE_VALUE (list1),
806 			  hash_chainon (TREE_CHAIN (list1), list2));
807 }
808 
809 /* Build an association between TYPE and some parameters:
810 
811    OFFSET is the offset added to `this' to convert it to a pointer
812    of type `TYPE *'
813 
814    BINFO is the base binfo to use, if we are deriving from one.  This
815    is necessary, as we want specialized parent binfos from base
816    classes, so that the VTABLE_NAMEs of bases are for the most derived
817    type, instead of the simple type.
818 
819    VTABLE is the virtual function table with which to initialize
820    sub-objects of type TYPE.
821 
822    VIRTUALS are the virtual functions sitting in VTABLE.  */
823 
824 tree
make_binfo(offset,binfo,vtable,virtuals)825 make_binfo (offset, binfo, vtable, virtuals)
826      tree offset, binfo;
827      tree vtable, virtuals;
828 {
829   tree new_binfo = make_tree_vec (11);
830   tree type;
831 
832   if (TREE_CODE (binfo) == TREE_VEC)
833     type = BINFO_TYPE (binfo);
834   else
835     {
836       type = binfo;
837       binfo = CLASS_TYPE_P (type) ? TYPE_BINFO (binfo) : NULL_TREE;
838     }
839 
840   TREE_TYPE (new_binfo) = TYPE_MAIN_VARIANT (type);
841   BINFO_OFFSET (new_binfo) = offset;
842   BINFO_VTABLE (new_binfo) = vtable;
843   BINFO_VIRTUALS (new_binfo) = virtuals;
844 
845   if (binfo && BINFO_BASETYPES (binfo) != NULL_TREE)
846     BINFO_BASETYPES (new_binfo) = copy_node (BINFO_BASETYPES (binfo));
847   return new_binfo;
848 }
849 
850 /* Return a TREE_LIST whose TREE_VALUE nodes along the
851    BINFO_INHERITANCE_CHAIN for BINFO, but in the opposite order.  In
852    other words, while the BINFO_INHERITANCE_CHAIN goes from base
853    classes to derived classes, the reversed path goes from derived
854    classes to base classes.  */
855 
856 tree
reverse_path(binfo)857 reverse_path (binfo)
858      tree binfo;
859 {
860   tree reversed_path;
861 
862   reversed_path = NULL_TREE;
863   while (binfo)
864     {
865       reversed_path = tree_cons (NULL_TREE, binfo, reversed_path);
866       binfo = BINFO_INHERITANCE_CHAIN (binfo);
867     }
868 
869   return reversed_path;
870 }
871 
872 void
debug_binfo(elem)873 debug_binfo (elem)
874      tree elem;
875 {
876   HOST_WIDE_INT n;
877   tree virtuals;
878 
879   fprintf (stderr, "type \"%s\", offset = ",
880 	   TYPE_NAME_STRING (BINFO_TYPE (elem)));
881   fprintf (stderr, HOST_WIDE_INT_PRINT_DEC,
882 	   TREE_INT_CST_LOW (BINFO_OFFSET (elem)));
883   fprintf (stderr, "\nvtable type:\n");
884   debug_tree (BINFO_TYPE (elem));
885   if (BINFO_VTABLE (elem))
886     fprintf (stderr, "vtable decl \"%s\"\n",
887 	     IDENTIFIER_POINTER (DECL_NAME (get_vtbl_decl_for_binfo (elem))));
888   else
889     fprintf (stderr, "no vtable decl yet\n");
890   fprintf (stderr, "virtuals:\n");
891   virtuals = BINFO_VIRTUALS (elem);
892   n = 0;
893 
894   while (virtuals)
895     {
896       tree fndecl = TREE_VALUE (virtuals);
897       fprintf (stderr, "%s [%ld =? %ld]\n",
898 	       IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (fndecl)),
899 	       (long) n, (long) TREE_INT_CST_LOW (DECL_VINDEX (fndecl)));
900       ++n;
901       virtuals = TREE_CHAIN (virtuals);
902     }
903 }
904 
905 int
count_functions(t)906 count_functions (t)
907      tree t;
908 {
909   int i;
910   if (TREE_CODE (t) == FUNCTION_DECL)
911     return 1;
912   else if (TREE_CODE (t) == OVERLOAD)
913     {
914       for (i=0; t; t = OVL_CHAIN (t))
915 	i++;
916       return i;
917     }
918 
919   abort ();
920   return 0;
921 }
922 
923 int
is_overloaded_fn(x)924 is_overloaded_fn (x)
925      tree x;
926 {
927   /* A baselink is also considered an overloaded function.  */
928   if (TREE_CODE (x) == OFFSET_REF)
929     x = TREE_OPERAND (x, 1);
930   if (BASELINK_P (x))
931     x = BASELINK_FUNCTIONS (x);
932   return (TREE_CODE (x) == FUNCTION_DECL
933 	  || TREE_CODE (x) == TEMPLATE_ID_EXPR
934 	  || DECL_FUNCTION_TEMPLATE_P (x)
935 	  || TREE_CODE (x) == OVERLOAD);
936 }
937 
938 int
really_overloaded_fn(x)939 really_overloaded_fn (x)
940      tree x;
941 {
942   /* A baselink is also considered an overloaded function.  */
943   if (TREE_CODE (x) == OFFSET_REF)
944     x = TREE_OPERAND (x, 1);
945   if (BASELINK_P (x))
946     x = BASELINK_FUNCTIONS (x);
947 
948   return ((TREE_CODE (x) == OVERLOAD && OVL_CHAIN (x))
949 	  || DECL_FUNCTION_TEMPLATE_P (OVL_CURRENT (x))
950 	  || TREE_CODE (x) == TEMPLATE_ID_EXPR);
951 }
952 
953 /* Return the OVERLOAD or FUNCTION_DECL inside FNS.  FNS can be an
954    OVERLOAD, FUNCTION_DECL, TEMPLATE_ID_EXPR, or baselink.  */
955 
956 tree
get_overloaded_fn(fns)957 get_overloaded_fn (fns)
958      tree fns;
959 {
960   if (TREE_CODE (fns) == TEMPLATE_ID_EXPR)
961     fns = TREE_OPERAND (fns, 0);
962   if (BASELINK_P (fns))
963     fns = BASELINK_FUNCTIONS (fns);
964   return fns;
965 }
966 
967 tree
get_first_fn(from)968 get_first_fn (from)
969      tree from;
970 {
971   my_friendly_assert (is_overloaded_fn (from), 9);
972   /* A baselink is also considered an overloaded function.  */
973   if (BASELINK_P (from))
974     from = BASELINK_FUNCTIONS (from);
975   return OVL_CURRENT (from);
976 }
977 
978 /* Returns nonzero if T is a ->* or .* expression that refers to a
979    member function.  */
980 
981 int
bound_pmf_p(t)982 bound_pmf_p (t)
983      tree t;
984 {
985   return (TREE_CODE (t) == OFFSET_REF
986 	  && TYPE_PTRMEMFUNC_P (TREE_TYPE (TREE_OPERAND (t, 1))));
987 }
988 
989 /* Return a new OVL node, concatenating it with the old one.  */
990 
991 tree
ovl_cons(decl,chain)992 ovl_cons (decl, chain)
993      tree decl;
994      tree chain;
995 {
996   tree result = make_node (OVERLOAD);
997   TREE_TYPE (result) = unknown_type_node;
998   OVL_FUNCTION (result) = decl;
999   TREE_CHAIN (result) = chain;
1000 
1001   return result;
1002 }
1003 
1004 /* Build a new overloaded function. If this is the first one,
1005    just return it; otherwise, ovl_cons the _DECLs */
1006 
1007 tree
build_overload(decl,chain)1008 build_overload (decl, chain)
1009      tree decl;
1010      tree chain;
1011 {
1012   if (! chain && TREE_CODE (decl) != TEMPLATE_DECL)
1013     return decl;
1014   if (chain && TREE_CODE (chain) != OVERLOAD)
1015     chain = ovl_cons (chain, NULL_TREE);
1016   return ovl_cons (decl, chain);
1017 }
1018 
1019 int
is_aggr_type_2(t1,t2)1020 is_aggr_type_2 (t1, t2)
1021      tree t1, t2;
1022 {
1023   if (TREE_CODE (t1) != TREE_CODE (t2))
1024     return 0;
1025   return IS_AGGR_TYPE (t1) && IS_AGGR_TYPE (t2);
1026 }
1027 
1028 /* Returns nonzero if CODE is the code for a statement.  */
1029 
1030 int
cp_statement_code_p(code)1031 cp_statement_code_p (code)
1032      enum tree_code code;
1033 {
1034   switch (code)
1035     {
1036     case CTOR_INITIALIZER:
1037     case RETURN_INIT:
1038     case TRY_BLOCK:
1039     case HANDLER:
1040     case EH_SPEC_BLOCK:
1041     case USING_STMT:
1042     case TAG_DEFN:
1043       return 1;
1044 
1045     default:
1046       return 0;
1047     }
1048 }
1049 
1050 #define PRINT_RING_SIZE 4
1051 
1052 const char *
cxx_printable_name(decl,v)1053 cxx_printable_name (decl, v)
1054      tree decl;
1055      int v;
1056 {
1057   static tree decl_ring[PRINT_RING_SIZE];
1058   static char *print_ring[PRINT_RING_SIZE];
1059   static int ring_counter;
1060   int i;
1061 
1062   /* Only cache functions.  */
1063   if (v < 2
1064       || TREE_CODE (decl) != FUNCTION_DECL
1065       || DECL_LANG_SPECIFIC (decl) == 0)
1066     return lang_decl_name (decl, v);
1067 
1068   /* See if this print name is lying around.  */
1069   for (i = 0; i < PRINT_RING_SIZE; i++)
1070     if (decl_ring[i] == decl)
1071       /* yes, so return it.  */
1072       return print_ring[i];
1073 
1074   if (++ring_counter == PRINT_RING_SIZE)
1075     ring_counter = 0;
1076 
1077   if (current_function_decl != NULL_TREE)
1078     {
1079       if (decl_ring[ring_counter] == current_function_decl)
1080 	ring_counter += 1;
1081       if (ring_counter == PRINT_RING_SIZE)
1082 	ring_counter = 0;
1083       if (decl_ring[ring_counter] == current_function_decl)
1084 	abort ();
1085     }
1086 
1087   if (print_ring[ring_counter])
1088     free (print_ring[ring_counter]);
1089 
1090   print_ring[ring_counter] = xstrdup (lang_decl_name (decl, v));
1091   decl_ring[ring_counter] = decl;
1092   return print_ring[ring_counter];
1093 }
1094 
1095 /* Build the FUNCTION_TYPE or METHOD_TYPE which may throw exceptions
1096    listed in RAISES.  */
1097 
1098 tree
build_exception_variant(type,raises)1099 build_exception_variant (type, raises)
1100      tree type;
1101      tree raises;
1102 {
1103   tree v = TYPE_MAIN_VARIANT (type);
1104   int type_quals = TYPE_QUALS (type);
1105 
1106   for (; v; v = TYPE_NEXT_VARIANT (v))
1107     if (TYPE_QUALS (v) == type_quals
1108         && comp_except_specs (raises, TYPE_RAISES_EXCEPTIONS (v), 1))
1109       return v;
1110 
1111   /* Need to build a new variant.  */
1112   v = build_type_copy (type);
1113   TYPE_RAISES_EXCEPTIONS (v) = raises;
1114   return v;
1115 }
1116 
1117 /* Given a TEMPLATE_TEMPLATE_PARM node T, create a new
1118    BOUND_TEMPLATE_TEMPLATE_PARM bound with NEWARGS as its template
1119    arguments.  */
1120 
1121 tree
bind_template_template_parm(t,newargs)1122 bind_template_template_parm (t, newargs)
1123      tree t;
1124      tree newargs;
1125 {
1126   tree decl = TYPE_NAME (t);
1127   tree t2;
1128 
1129   t2 = make_aggr_type (BOUND_TEMPLATE_TEMPLATE_PARM);
1130   decl = build_decl (TYPE_DECL, DECL_NAME (decl), NULL_TREE);
1131 
1132   /* These nodes have to be created to reflect new TYPE_DECL and template
1133      arguments.  */
1134   TEMPLATE_TYPE_PARM_INDEX (t2) = copy_node (TEMPLATE_TYPE_PARM_INDEX (t));
1135   TEMPLATE_PARM_DECL (TEMPLATE_TYPE_PARM_INDEX (t2)) = decl;
1136   TEMPLATE_TEMPLATE_PARM_TEMPLATE_INFO (t2)
1137     = tree_cons (TEMPLATE_TEMPLATE_PARM_TEMPLATE_DECL (t),
1138 		 newargs, NULL_TREE);
1139 
1140   TREE_TYPE (decl) = t2;
1141   TYPE_NAME (t2) = decl;
1142   TYPE_STUB_DECL (t2) = decl;
1143   TYPE_SIZE (t2) = 0;
1144 
1145   return t2;
1146 }
1147 
1148 /* Called from count_trees via walk_tree.  */
1149 
1150 static tree
count_trees_r(tp,walk_subtrees,data)1151 count_trees_r (tp, walk_subtrees, data)
1152      tree *tp ATTRIBUTE_UNUSED;
1153      int *walk_subtrees ATTRIBUTE_UNUSED;
1154      void *data;
1155 {
1156   ++ *((int*) data);
1157   return NULL_TREE;
1158 }
1159 
1160 /* Debugging function for measuring the rough complexity of a tree
1161    representation.  */
1162 
1163 int
count_trees(t)1164 count_trees (t)
1165      tree t;
1166 {
1167   int n_trees = 0;
1168   walk_tree_without_duplicates (&t, count_trees_r, &n_trees);
1169   return n_trees;
1170 }
1171 
1172 /* Called from verify_stmt_tree via walk_tree.  */
1173 
1174 static tree
verify_stmt_tree_r(tp,walk_subtrees,data)1175 verify_stmt_tree_r (tp, walk_subtrees, data)
1176      tree *tp;
1177      int *walk_subtrees ATTRIBUTE_UNUSED;
1178      void *data;
1179 {
1180   tree t = *tp;
1181   htab_t *statements = (htab_t *) data;
1182   void **slot;
1183 
1184   if (!statement_code_p (TREE_CODE (t)))
1185     return NULL_TREE;
1186 
1187   /* If this statement is already present in the hash table, then
1188      there is a circularity in the statement tree.  */
1189   if (htab_find (*statements, t))
1190     abort ();
1191 
1192   slot = htab_find_slot (*statements, t, INSERT);
1193   *slot = t;
1194 
1195   return NULL_TREE;
1196 }
1197 
1198 /* Debugging function to check that the statement T has not been
1199    corrupted.  For now, this function simply checks that T contains no
1200    circularities.  */
1201 
1202 void
verify_stmt_tree(t)1203 verify_stmt_tree (t)
1204      tree t;
1205 {
1206   htab_t statements;
1207   statements = htab_create (37, htab_hash_pointer, htab_eq_pointer, NULL);
1208   walk_tree (&t, verify_stmt_tree_r, &statements, NULL);
1209   htab_delete (statements);
1210 }
1211 
1212 /* Called from find_tree via walk_tree.  */
1213 
1214 static tree
find_tree_r(tp,walk_subtrees,data)1215 find_tree_r (tp, walk_subtrees, data)
1216      tree *tp;
1217      int *walk_subtrees ATTRIBUTE_UNUSED;
1218      void *data;
1219 {
1220   if (*tp == (tree) data)
1221     return (tree) data;
1222 
1223   return NULL_TREE;
1224 }
1225 
1226 /* Returns X if X appears in the tree structure rooted at T.  */
1227 
1228 tree
find_tree(t,x)1229 find_tree (t, x)
1230      tree t;
1231      tree x;
1232 {
1233   return walk_tree_without_duplicates (&t, find_tree_r, x);
1234 }
1235 
1236 /* Passed to walk_tree.  Checks for the use of types with no linkage.  */
1237 
1238 static tree
no_linkage_helper(tp,walk_subtrees,data)1239 no_linkage_helper (tp, walk_subtrees, data)
1240      tree *tp;
1241      int *walk_subtrees ATTRIBUTE_UNUSED;
1242      void *data ATTRIBUTE_UNUSED;
1243 {
1244   tree t = *tp;
1245 
1246   if (TYPE_P (t)
1247       && (CLASS_TYPE_P (t) || TREE_CODE (t) == ENUMERAL_TYPE)
1248       && (decl_function_context (TYPE_MAIN_DECL (t))
1249 	  || TYPE_ANONYMOUS_P (t)))
1250     return t;
1251   return NULL_TREE;
1252 }
1253 
1254 /* Check if the type T depends on a type with no linkage and if so, return
1255    it.  */
1256 
1257 tree
no_linkage_check(t)1258 no_linkage_check (t)
1259      tree t;
1260 {
1261   /* There's no point in checking linkage on template functions; we
1262      can't know their complete types.  */
1263   if (processing_template_decl)
1264     return NULL_TREE;
1265 
1266   t = walk_tree_without_duplicates (&t, no_linkage_helper, NULL);
1267   if (t != error_mark_node)
1268     return t;
1269   return NULL_TREE;
1270 }
1271 
1272 #ifdef GATHER_STATISTICS
1273 extern int depth_reached;
1274 #endif
1275 
1276 void
cxx_print_statistics()1277 cxx_print_statistics ()
1278 {
1279   print_search_statistics ();
1280   print_class_statistics ();
1281 #ifdef GATHER_STATISTICS
1282   fprintf (stderr, "maximum template instantiation depth reached: %d\n",
1283 	   depth_reached);
1284 #endif
1285 }
1286 
1287 /* Return, as an INTEGER_CST node, the number of elements for TYPE
1288    (which is an ARRAY_TYPE).  This counts only elements of the top
1289    array.  */
1290 
1291 tree
array_type_nelts_top(type)1292 array_type_nelts_top (type)
1293      tree type;
1294 {
1295   return fold (build (PLUS_EXPR, sizetype,
1296 		      array_type_nelts (type),
1297 		      integer_one_node));
1298 }
1299 
1300 /* Return, as an INTEGER_CST node, the number of elements for TYPE
1301    (which is an ARRAY_TYPE).  This one is a recursive count of all
1302    ARRAY_TYPEs that are clumped together.  */
1303 
1304 tree
array_type_nelts_total(type)1305 array_type_nelts_total (type)
1306      tree type;
1307 {
1308   tree sz = array_type_nelts_top (type);
1309   type = TREE_TYPE (type);
1310   while (TREE_CODE (type) == ARRAY_TYPE)
1311     {
1312       tree n = array_type_nelts_top (type);
1313       sz = fold (build (MULT_EXPR, sizetype, sz, n));
1314       type = TREE_TYPE (type);
1315     }
1316   return sz;
1317 }
1318 
1319 /* Called from break_out_target_exprs via mapcar.  */
1320 
1321 static tree
bot_manip(tp,walk_subtrees,data)1322 bot_manip (tp, walk_subtrees, data)
1323      tree *tp;
1324      int *walk_subtrees;
1325      void *data;
1326 {
1327   splay_tree target_remap = ((splay_tree) data);
1328   tree t = *tp;
1329 
1330   if (TREE_CONSTANT (t))
1331     {
1332       /* There can't be any TARGET_EXPRs or their slot variables below
1333          this point.  We used to check !TREE_SIDE_EFFECTS, but then we
1334          failed to copy an ADDR_EXPR of the slot VAR_DECL.  */
1335       *walk_subtrees = 0;
1336       return NULL_TREE;
1337     }
1338   if (TREE_CODE (t) == TARGET_EXPR)
1339     {
1340       tree u;
1341 
1342       if (TREE_CODE (TREE_OPERAND (t, 1)) == AGGR_INIT_EXPR)
1343 	{
1344 	  mark_used (TREE_OPERAND (TREE_OPERAND (TREE_OPERAND (t, 1), 0), 0));
1345 	  u = build_cplus_new
1346 	    (TREE_TYPE (t), break_out_target_exprs (TREE_OPERAND (t, 1)));
1347 	}
1348       else
1349 	{
1350 	  u = build_target_expr_with_type
1351 	    (break_out_target_exprs (TREE_OPERAND (t, 1)), TREE_TYPE (t));
1352 	}
1353 
1354       /* Map the old variable to the new one.  */
1355       splay_tree_insert (target_remap,
1356 			 (splay_tree_key) TREE_OPERAND (t, 0),
1357 			 (splay_tree_value) TREE_OPERAND (u, 0));
1358 
1359       /* Replace the old expression with the new version.  */
1360       *tp = u;
1361       /* We don't have to go below this point; the recursive call to
1362 	 break_out_target_exprs will have handled anything below this
1363 	 point.  */
1364       *walk_subtrees = 0;
1365       return NULL_TREE;
1366     }
1367   else if (TREE_CODE (t) == CALL_EXPR)
1368     mark_used (TREE_OPERAND (TREE_OPERAND (t, 0), 0));
1369 
1370   /* Make a copy of this node.  */
1371   return copy_tree_r (tp, walk_subtrees, NULL);
1372 }
1373 
1374 /* Replace all remapped VAR_DECLs in T with their new equivalents.
1375    DATA is really a splay-tree mapping old variables to new
1376    variables.  */
1377 
1378 static tree
bot_replace(t,walk_subtrees,data)1379 bot_replace (t, walk_subtrees, data)
1380      tree *t;
1381      int *walk_subtrees ATTRIBUTE_UNUSED;
1382      void *data;
1383 {
1384   splay_tree target_remap = ((splay_tree) data);
1385 
1386   if (TREE_CODE (*t) == VAR_DECL)
1387     {
1388       splay_tree_node n = splay_tree_lookup (target_remap,
1389 					     (splay_tree_key) *t);
1390       if (n)
1391 	*t = (tree) n->value;
1392     }
1393 
1394   return NULL_TREE;
1395 }
1396 
1397 /* When we parse a default argument expression, we may create
1398    temporary variables via TARGET_EXPRs.  When we actually use the
1399    default-argument expression, we make a copy of the expression, but
1400    we must replace the temporaries with appropriate local versions.  */
1401 
1402 tree
break_out_target_exprs(t)1403 break_out_target_exprs (t)
1404      tree t;
1405 {
1406   static int target_remap_count;
1407   static splay_tree target_remap;
1408 
1409   if (!target_remap_count++)
1410     target_remap = splay_tree_new (splay_tree_compare_pointers,
1411 				   /*splay_tree_delete_key_fn=*/NULL,
1412 				   /*splay_tree_delete_value_fn=*/NULL);
1413   walk_tree (&t, bot_manip, target_remap, NULL);
1414   walk_tree (&t, bot_replace, target_remap, NULL);
1415 
1416   if (!--target_remap_count)
1417     {
1418       splay_tree_delete (target_remap);
1419       target_remap = NULL;
1420     }
1421 
1422   return t;
1423 }
1424 
1425 /* Obstack used for allocating nodes in template function and variable
1426    definitions.  */
1427 
1428 /* Similar to `build_nt', except that we set TREE_COMPLEXITY to be the
1429    current line number.  */
1430 
1431 tree
build_min_nt(enum tree_code code,...)1432 build_min_nt VPARAMS ((enum tree_code code, ...))
1433 {
1434   register tree t;
1435   register int length;
1436   register int i;
1437 
1438   VA_OPEN (p, code);
1439   VA_FIXEDARG (p, enum tree_code, code);
1440 
1441   t = make_node (code);
1442   length = TREE_CODE_LENGTH (code);
1443   TREE_COMPLEXITY (t) = lineno;
1444 
1445   for (i = 0; i < length; i++)
1446     {
1447       tree x = va_arg (p, tree);
1448       TREE_OPERAND (t, i) = x;
1449     }
1450 
1451   VA_CLOSE (p);
1452   return t;
1453 }
1454 
1455 /* Similar to `build', except we set TREE_COMPLEXITY to the current
1456    line-number.  */
1457 
1458 tree
build_min(enum tree_code code,tree tt,...)1459 build_min VPARAMS ((enum tree_code code, tree tt, ...))
1460 {
1461   register tree t;
1462   register int length;
1463   register int i;
1464 
1465   VA_OPEN (p, tt);
1466   VA_FIXEDARG (p, enum tree_code, code);
1467   VA_FIXEDARG (p, tree, tt);
1468 
1469   t = make_node (code);
1470   length = TREE_CODE_LENGTH (code);
1471   TREE_TYPE (t) = tt;
1472   TREE_COMPLEXITY (t) = lineno;
1473 
1474   for (i = 0; i < length; i++)
1475     {
1476       tree x = va_arg (p, tree);
1477       TREE_OPERAND (t, i) = x;
1478     }
1479 
1480   VA_CLOSE (p);
1481   return t;
1482 }
1483 
1484 /* Returns an INTEGER_CST (of type `int') corresponding to I.
1485    Multiple calls with the same value of I may or may not yield the
1486    same node; therefore, callers should never modify the node
1487    returned.  */
1488 
1489 static GTY(()) tree shared_int_cache[256];
1490 
1491 tree
build_shared_int_cst(i)1492 build_shared_int_cst (i)
1493      int i;
1494 {
1495   if (i >= 256)
1496     return build_int_2 (i, 0);
1497 
1498   if (!shared_int_cache[i])
1499     shared_int_cache[i] = build_int_2 (i, 0);
1500 
1501   return shared_int_cache[i];
1502 }
1503 
1504 tree
get_type_decl(t)1505 get_type_decl (t)
1506      tree t;
1507 {
1508   if (TREE_CODE (t) == TYPE_DECL)
1509     return t;
1510   if (TYPE_P (t))
1511     return TYPE_STUB_DECL (t);
1512   if (t == error_mark_node)
1513     return t;
1514 
1515   abort ();
1516 
1517   /* Stop compiler from complaining control reaches end of non-void function.  */
1518   return 0;
1519 }
1520 
1521 /* Return first vector element whose BINFO_TYPE is ELEM.
1522    Return 0 if ELEM is not in VEC.  VEC may be NULL_TREE.  */
1523 
1524 tree
vec_binfo_member(elem,vec)1525 vec_binfo_member (elem, vec)
1526      tree elem, vec;
1527 {
1528   int i;
1529 
1530   if (vec)
1531     for (i = 0; i < TREE_VEC_LENGTH (vec); ++i)
1532       if (same_type_p (elem, BINFO_TYPE (TREE_VEC_ELT (vec, i))))
1533 	return TREE_VEC_ELT (vec, i);
1534 
1535   return NULL_TREE;
1536 }
1537 
1538 /* Returns the namespace that contains DECL, whether directly or
1539    indirectly.  */
1540 
1541 tree
decl_namespace_context(decl)1542 decl_namespace_context (decl)
1543      tree decl;
1544 {
1545   while (1)
1546     {
1547       if (TREE_CODE (decl) == NAMESPACE_DECL)
1548 	return decl;
1549       else if (TYPE_P (decl))
1550 	decl = CP_DECL_CONTEXT (TYPE_MAIN_DECL (decl));
1551       else
1552 	decl = CP_DECL_CONTEXT (decl);
1553     }
1554 }
1555 
1556 /* Return truthvalue of whether T1 is the same tree structure as T2.
1557    Return 1 if they are the same.
1558    Return 0 if they are understandably different.
1559    Return -1 if either contains tree structure not understood by
1560    this function.  */
1561 
1562 int
cp_tree_equal(t1,t2)1563 cp_tree_equal (t1, t2)
1564      tree t1, t2;
1565 {
1566   register enum tree_code code1, code2;
1567   int cmp;
1568 
1569   if (t1 == t2)
1570     return 1;
1571   if (t1 == 0 || t2 == 0)
1572     return 0;
1573 
1574   code1 = TREE_CODE (t1);
1575   code2 = TREE_CODE (t2);
1576 
1577   if (code1 == NOP_EXPR || code1 == CONVERT_EXPR || code1 == NON_LVALUE_EXPR)
1578     {
1579       if (code2 == NOP_EXPR || code2 == CONVERT_EXPR || code2 == NON_LVALUE_EXPR)
1580 	return cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
1581       else
1582 	return cp_tree_equal (TREE_OPERAND (t1, 0), t2);
1583     }
1584   else if (code2 == NOP_EXPR || code2 == CONVERT_EXPR
1585 	   || code2 == NON_LVALUE_EXPR)
1586     return cp_tree_equal (t1, TREE_OPERAND (t2, 0));
1587 
1588   if (code1 != code2)
1589     return 0;
1590 
1591   switch (code1)
1592     {
1593     case INTEGER_CST:
1594       return TREE_INT_CST_LOW (t1) == TREE_INT_CST_LOW (t2)
1595 	&& TREE_INT_CST_HIGH (t1) == TREE_INT_CST_HIGH (t2);
1596 
1597     case REAL_CST:
1598       return REAL_VALUES_EQUAL (TREE_REAL_CST (t1), TREE_REAL_CST (t2));
1599 
1600     case STRING_CST:
1601       return TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
1602 	&& !memcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
1603 		  TREE_STRING_LENGTH (t1));
1604 
1605     case CONSTRUCTOR:
1606       /* We need to do this when determining whether or not two
1607 	 non-type pointer to member function template arguments
1608 	 are the same.  */
1609       if (!(same_type_p (TREE_TYPE (t1), TREE_TYPE (t2))
1610 	    /* The first operand is RTL.  */
1611 	    && TREE_OPERAND (t1, 0) == TREE_OPERAND (t2, 0)))
1612 	return 0;
1613       return cp_tree_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
1614 
1615     case TREE_LIST:
1616       cmp = cp_tree_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2));
1617       if (cmp <= 0)
1618 	return cmp;
1619       cmp = cp_tree_equal (TREE_VALUE (t1), TREE_VALUE (t2));
1620       if (cmp <= 0)
1621 	return cmp;
1622       return cp_tree_equal (TREE_CHAIN (t1), TREE_CHAIN (t2));
1623 
1624     case SAVE_EXPR:
1625       return cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
1626 
1627     case CALL_EXPR:
1628       cmp = cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
1629       if (cmp <= 0)
1630 	return cmp;
1631       return simple_cst_list_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
1632 
1633     case TARGET_EXPR:
1634       /* Special case: if either target is an unallocated VAR_DECL,
1635 	 it means that it's going to be unified with whatever the
1636 	 TARGET_EXPR is really supposed to initialize, so treat it
1637 	 as being equivalent to anything.  */
1638       if ((TREE_CODE (TREE_OPERAND (t1, 0)) == VAR_DECL
1639 	   && DECL_NAME (TREE_OPERAND (t1, 0)) == NULL_TREE
1640 	   && !DECL_RTL_SET_P (TREE_OPERAND (t1, 0)))
1641 	  || (TREE_CODE (TREE_OPERAND (t2, 0)) == VAR_DECL
1642 	      && DECL_NAME (TREE_OPERAND (t2, 0)) == NULL_TREE
1643 	      && !DECL_RTL_SET_P (TREE_OPERAND (t2, 0))))
1644 	cmp = 1;
1645       else
1646 	cmp = cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
1647       if (cmp <= 0)
1648 	return cmp;
1649       return cp_tree_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
1650 
1651     case WITH_CLEANUP_EXPR:
1652       cmp = cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
1653       if (cmp <= 0)
1654 	return cmp;
1655       return cp_tree_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t1, 1));
1656 
1657     case COMPONENT_REF:
1658       if (TREE_OPERAND (t1, 1) == TREE_OPERAND (t2, 1))
1659 	return cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
1660       return 0;
1661 
1662     case VAR_DECL:
1663     case PARM_DECL:
1664     case CONST_DECL:
1665     case FUNCTION_DECL:
1666       return 0;
1667 
1668     case TEMPLATE_PARM_INDEX:
1669       return (TEMPLATE_PARM_IDX (t1) == TEMPLATE_PARM_IDX (t2)
1670 	      && TEMPLATE_PARM_LEVEL (t1) == TEMPLATE_PARM_LEVEL (t2)
1671 	      && same_type_p (TREE_TYPE (TEMPLATE_PARM_DECL (t1)),
1672 			      TREE_TYPE (TEMPLATE_PARM_DECL (t2))));
1673 
1674     case SIZEOF_EXPR:
1675     case ALIGNOF_EXPR:
1676       if (TREE_CODE (TREE_OPERAND (t1, 0)) != TREE_CODE (TREE_OPERAND (t2, 0)))
1677 	return 0;
1678       if (TYPE_P (TREE_OPERAND (t1, 0)))
1679 	return same_type_p (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
1680       break;
1681 
1682     case PTRMEM_CST:
1683       /* Two pointer-to-members are the same if they point to the same
1684 	 field or function in the same class.  */
1685       return (PTRMEM_CST_MEMBER (t1) == PTRMEM_CST_MEMBER (t2)
1686 	      && same_type_p (PTRMEM_CST_CLASS (t1), PTRMEM_CST_CLASS (t2)));
1687 
1688     default:
1689       break;
1690     }
1691 
1692   switch (TREE_CODE_CLASS (code1))
1693     {
1694     case '1':
1695     case '2':
1696     case '<':
1697     case 'e':
1698     case 'r':
1699     case 's':
1700       {
1701 	int i;
1702 
1703 	cmp = 1;
1704 	for (i = 0; i < TREE_CODE_LENGTH (code1); ++i)
1705 	  {
1706 	    cmp = cp_tree_equal (TREE_OPERAND (t1, i), TREE_OPERAND (t2, i));
1707 	    if (cmp <= 0)
1708 	      return cmp;
1709 	  }
1710 	return cmp;
1711       }
1712 
1713       case 't':
1714 	return same_type_p (t1, t2) ? 1 : 0;
1715     }
1716 
1717   return -1;
1718 }
1719 
1720 /* Build a wrapper around a 'struct z_candidate' so we can use it as a
1721    tree.  */
1722 
1723 tree
build_zc_wrapper(ptr)1724 build_zc_wrapper (ptr)
1725      struct z_candidate *ptr;
1726 {
1727   tree t = make_node (WRAPPER);
1728   WRAPPER_ZC (t) = ptr;
1729   return t;
1730 }
1731 
1732 static tree
build_srcloc(file,line)1733 build_srcloc (file, line)
1734      const char *file;
1735      int line;
1736 {
1737   tree t;
1738 
1739   t = make_node (SRCLOC);
1740   SRCLOC_FILE (t) = file;
1741   SRCLOC_LINE (t) = line;
1742 
1743   return t;
1744 }
1745 
1746 tree
build_srcloc_here()1747 build_srcloc_here ()
1748 {
1749   return build_srcloc (input_filename, lineno);
1750 }
1751 
1752 /* The type of ARG when used as an lvalue.  */
1753 
1754 tree
lvalue_type(arg)1755 lvalue_type (arg)
1756      tree arg;
1757 {
1758   tree type = TREE_TYPE (arg);
1759   if (TREE_CODE (arg) == OVERLOAD)
1760     type = unknown_type_node;
1761   return type;
1762 }
1763 
1764 /* The type of ARG for printing error messages; denote lvalues with
1765    reference types.  */
1766 
1767 tree
error_type(arg)1768 error_type (arg)
1769      tree arg;
1770 {
1771   tree type = TREE_TYPE (arg);
1772   if (TREE_CODE (type) == ARRAY_TYPE)
1773     ;
1774   else if (real_lvalue_p (arg))
1775     type = build_reference_type (lvalue_type (arg));
1776   else if (IS_AGGR_TYPE (type))
1777     type = lvalue_type (arg);
1778 
1779   return type;
1780 }
1781 
1782 /* Does FUNCTION use a variable-length argument list?  */
1783 
1784 int
varargs_function_p(function)1785 varargs_function_p (function)
1786      tree function;
1787 {
1788   tree parm = TYPE_ARG_TYPES (TREE_TYPE (function));
1789   for (; parm; parm = TREE_CHAIN (parm))
1790     if (TREE_VALUE (parm) == void_type_node)
1791       return 0;
1792   return 1;
1793 }
1794 
1795 /* Returns 1 if decl is a member of a class.  */
1796 
1797 int
member_p(decl)1798 member_p (decl)
1799      tree decl;
1800 {
1801   const tree ctx = DECL_CONTEXT (decl);
1802   return (ctx && TYPE_P (ctx));
1803 }
1804 
1805 /* Create a placeholder for member access where we don't actually have an
1806    object that the access is against.  */
1807 
1808 tree
build_dummy_object(type)1809 build_dummy_object (type)
1810      tree type;
1811 {
1812   tree decl = build1 (NOP_EXPR, build_pointer_type (type), void_zero_node);
1813   return build_indirect_ref (decl, NULL);
1814 }
1815 
1816 /* We've gotten a reference to a member of TYPE.  Return *this if appropriate,
1817    or a dummy object otherwise.  If BINFOP is non-0, it is filled with the
1818    binfo path from current_class_type to TYPE, or 0.  */
1819 
1820 tree
maybe_dummy_object(type,binfop)1821 maybe_dummy_object (type, binfop)
1822      tree type;
1823      tree *binfop;
1824 {
1825   tree decl, context;
1826   tree binfo;
1827 
1828   if (current_class_type
1829       && (binfo = lookup_base (current_class_type, type,
1830 			       ba_ignore | ba_quiet, NULL)))
1831     context = current_class_type;
1832   else
1833     {
1834       /* Reference from a nested class member function.  */
1835       context = type;
1836       binfo = TYPE_BINFO (type);
1837     }
1838 
1839   if (binfop)
1840     *binfop = binfo;
1841 
1842   if (current_class_ref && context == current_class_type
1843       /* Kludge: Make sure that current_class_type is actually
1844          correct.  It might not be if we're in the middle of
1845          tsubst_default_argument.  */
1846       && same_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (current_class_ref)),
1847 		      current_class_type))
1848     decl = current_class_ref;
1849   else
1850     decl = build_dummy_object (context);
1851 
1852   return decl;
1853 }
1854 
1855 /* Returns 1 if OB is a placeholder object, or a pointer to one.  */
1856 
1857 int
is_dummy_object(ob)1858 is_dummy_object (ob)
1859      tree ob;
1860 {
1861   if (TREE_CODE (ob) == INDIRECT_REF)
1862     ob = TREE_OPERAND (ob, 0);
1863   return (TREE_CODE (ob) == NOP_EXPR
1864 	  && TREE_OPERAND (ob, 0) == void_zero_node);
1865 }
1866 
1867 /* Returns 1 iff type T is a POD type, as defined in [basic.types].  */
1868 
1869 int
pod_type_p(t)1870 pod_type_p (t)
1871      tree t;
1872 {
1873   t = strip_array_types (t);
1874 
1875   if (t == error_mark_node)
1876     return 1;
1877   if (INTEGRAL_TYPE_P (t))
1878     return 1;  /* integral, character or enumeral type */
1879   if (FLOAT_TYPE_P (t))
1880     return 1;
1881   if (TYPE_PTR_P (t))
1882     return 1; /* pointer to non-member */
1883   if (TYPE_PTRMEM_P (t))
1884     return 1; /* pointer to member object */
1885   if (TYPE_PTRMEMFUNC_P (t))
1886     return 1; /* pointer to member function */
1887 
1888   if (! CLASS_TYPE_P (t))
1889     return 0; /* other non-class type (reference or function) */
1890   if (CLASSTYPE_NON_POD_P (t))
1891     return 0;
1892   return 1;
1893 }
1894 
1895 /* Returns 1 iff zero initialization of type T means actually storing
1896    zeros in it.  */
1897 
1898 int
zero_init_p(t)1899 zero_init_p (t)
1900      tree t;
1901 {
1902   t = strip_array_types (t);
1903 
1904   if (t == error_mark_node)
1905     return 1;
1906 
1907   /* NULL pointers to data members are initialized with -1.  */
1908   if (TYPE_PTRMEM_P (t))
1909     return 0;
1910 
1911   /* Classes that contain types that can't be zero-initialized, cannot
1912      be zero-initialized themselves.  */
1913   if (CLASS_TYPE_P (t) && CLASSTYPE_NON_ZERO_INIT_P (t))
1914     return 0;
1915 
1916   return 1;
1917 }
1918 
1919 /* Table of valid C++ attributes.  */
1920 const struct attribute_spec cxx_attribute_table[] =
1921 {
1922   /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
1923   { "java_interface", 0, 0, false, false, false, handle_java_interface_attribute },
1924   { "com_interface",  0, 0, false, false, false, handle_com_interface_attribute },
1925   { "init_priority",  1, 1, true,  false, false, handle_init_priority_attribute },
1926   { NULL,             0, 0, false, false, false, NULL }
1927 };
1928 
1929 /* Handle a "java_interface" attribute; arguments as in
1930    struct attribute_spec.handler.  */
1931 static tree
handle_java_interface_attribute(node,name,args,flags,no_add_attrs)1932 handle_java_interface_attribute (node, name, args, flags, no_add_attrs)
1933      tree *node;
1934      tree name;
1935      tree args ATTRIBUTE_UNUSED;
1936      int flags;
1937      bool *no_add_attrs;
1938 {
1939   if (DECL_P (*node)
1940       || !CLASS_TYPE_P (*node)
1941       || !TYPE_FOR_JAVA (*node))
1942     {
1943       error ("`%s' attribute can only be applied to Java class definitions",
1944 	     IDENTIFIER_POINTER (name));
1945       *no_add_attrs = true;
1946       return NULL_TREE;
1947     }
1948   if (!(flags & (int) ATTR_FLAG_TYPE_IN_PLACE))
1949     *node = build_type_copy (*node);
1950   TYPE_JAVA_INTERFACE (*node) = 1;
1951 
1952   return NULL_TREE;
1953 }
1954 
1955 /* Handle a "com_interface" attribute; arguments as in
1956    struct attribute_spec.handler.  */
1957 static tree
handle_com_interface_attribute(node,name,args,flags,no_add_attrs)1958 handle_com_interface_attribute (node, name, args, flags, no_add_attrs)
1959      tree *node;
1960      tree name;
1961      tree args ATTRIBUTE_UNUSED;
1962      int flags ATTRIBUTE_UNUSED;
1963      bool *no_add_attrs;
1964 {
1965   static int warned;
1966 
1967   *no_add_attrs = true;
1968 
1969   if (DECL_P (*node)
1970       || !CLASS_TYPE_P (*node)
1971       || *node != TYPE_MAIN_VARIANT (*node))
1972     {
1973       warning ("`%s' attribute can only be applied to class definitions",
1974 	       IDENTIFIER_POINTER (name));
1975       return NULL_TREE;
1976     }
1977 
1978   if (!warned++)
1979     warning ("`%s' is obsolete; g++ vtables are now COM-compatible by default",
1980 	     IDENTIFIER_POINTER (name));
1981 
1982   return NULL_TREE;
1983 }
1984 
1985 /* Handle an "init_priority" attribute; arguments as in
1986    struct attribute_spec.handler.  */
1987 static tree
handle_init_priority_attribute(node,name,args,flags,no_add_attrs)1988 handle_init_priority_attribute (node, name, args, flags, no_add_attrs)
1989      tree *node;
1990      tree name;
1991      tree args;
1992      int flags ATTRIBUTE_UNUSED;
1993      bool *no_add_attrs;
1994 {
1995   tree initp_expr = TREE_VALUE (args);
1996   tree decl = *node;
1997   tree type = TREE_TYPE (decl);
1998   int pri;
1999 
2000   STRIP_NOPS (initp_expr);
2001 
2002   if (!initp_expr || TREE_CODE (initp_expr) != INTEGER_CST)
2003     {
2004       error ("requested init_priority is not an integer constant");
2005       *no_add_attrs = true;
2006       return NULL_TREE;
2007     }
2008 
2009   pri = TREE_INT_CST_LOW (initp_expr);
2010 
2011   type = strip_array_types (type);
2012 
2013   if (decl == NULL_TREE
2014       || TREE_CODE (decl) != VAR_DECL
2015       || !TREE_STATIC (decl)
2016       || DECL_EXTERNAL (decl)
2017       || (TREE_CODE (type) != RECORD_TYPE
2018 	  && TREE_CODE (type) != UNION_TYPE)
2019       /* Static objects in functions are initialized the
2020 	 first time control passes through that
2021 	 function. This is not precise enough to pin down an
2022 	 init_priority value, so don't allow it.  */
2023       || current_function_decl)
2024     {
2025       error ("can only use `%s' attribute on file-scope definitions of objects of class type",
2026 	     IDENTIFIER_POINTER (name));
2027       *no_add_attrs = true;
2028       return NULL_TREE;
2029     }
2030 
2031   if (pri > MAX_INIT_PRIORITY || pri <= 0)
2032     {
2033       error ("requested init_priority is out of range");
2034       *no_add_attrs = true;
2035       return NULL_TREE;
2036     }
2037 
2038   /* Check for init_priorities that are reserved for
2039      language and runtime support implementations.*/
2040   if (pri <= MAX_RESERVED_INIT_PRIORITY)
2041     {
2042       warning
2043 	("requested init_priority is reserved for internal use");
2044     }
2045 
2046   if (SUPPORTS_INIT_PRIORITY)
2047     {
2048       DECL_INIT_PRIORITY (decl) = pri;
2049       return NULL_TREE;
2050     }
2051   else
2052     {
2053       error ("`%s' attribute is not supported on this platform",
2054 	     IDENTIFIER_POINTER (name));
2055       *no_add_attrs = true;
2056       return NULL_TREE;
2057     }
2058 }
2059 
2060 /* Return a new PTRMEM_CST of the indicated TYPE.  The MEMBER is the
2061    thing pointed to by the constant.  */
2062 
2063 tree
make_ptrmem_cst(type,member)2064 make_ptrmem_cst (type, member)
2065      tree type;
2066      tree member;
2067 {
2068   tree ptrmem_cst = make_node (PTRMEM_CST);
2069   /* If would seem a great convenience if make_node would set
2070      TREE_CONSTANT for things of class `c', but it does not.  */
2071   TREE_CONSTANT (ptrmem_cst) = 1;
2072   TREE_TYPE (ptrmem_cst) = type;
2073   PTRMEM_CST_MEMBER (ptrmem_cst) = member;
2074   return ptrmem_cst;
2075 }
2076 
2077 /* Apply FUNC to all language-specific sub-trees of TP in a pre-order
2078    traversal.  Called from walk_tree().  */
2079 
2080 tree
cp_walk_subtrees(tp,walk_subtrees_p,func,data,htab)2081 cp_walk_subtrees (tp, walk_subtrees_p, func, data, htab)
2082      tree *tp;
2083      int *walk_subtrees_p;
2084      walk_tree_fn func;
2085      void *data;
2086      void *htab;
2087 {
2088   enum tree_code code = TREE_CODE (*tp);
2089   tree result;
2090 
2091 #define WALK_SUBTREE(NODE)				\
2092   do							\
2093     {							\
2094       result = walk_tree (&(NODE), func, data, htab);	\
2095       if (result)					\
2096 	return result;					\
2097     }							\
2098   while (0)
2099 
2100   /* Not one of the easy cases.  We must explicitly go through the
2101      children.  */
2102   switch (code)
2103     {
2104     case DEFAULT_ARG:
2105     case TEMPLATE_TEMPLATE_PARM:
2106     case BOUND_TEMPLATE_TEMPLATE_PARM:
2107     case UNBOUND_CLASS_TEMPLATE:
2108     case TEMPLATE_PARM_INDEX:
2109     case TEMPLATE_TYPE_PARM:
2110     case TYPENAME_TYPE:
2111     case TYPEOF_TYPE:
2112       /* None of thse have subtrees other than those already walked
2113          above.  */
2114       *walk_subtrees_p = 0;
2115       break;
2116 
2117     case PTRMEM_CST:
2118       WALK_SUBTREE (TREE_TYPE (*tp));
2119       *walk_subtrees_p = 0;
2120       break;
2121 
2122     case TREE_LIST:
2123       /* A BASELINK_P's TREE_PURPOSE is a BINFO, and hence circular.  */
2124       if (!BASELINK_P (*tp))
2125         WALK_SUBTREE (TREE_PURPOSE (*tp));
2126       break;
2127 
2128     case OVERLOAD:
2129       WALK_SUBTREE (OVL_FUNCTION (*tp));
2130       WALK_SUBTREE (OVL_CHAIN (*tp));
2131       *walk_subtrees_p = 0;
2132       break;
2133 
2134     case RECORD_TYPE:
2135       if (TYPE_PTRMEMFUNC_P (*tp))
2136 	WALK_SUBTREE (TYPE_PTRMEMFUNC_FN_TYPE (*tp));
2137       break;
2138 
2139     default:
2140       break;
2141     }
2142 
2143   /* We didn't find what we were looking for.  */
2144   return NULL_TREE;
2145 
2146 #undef WALK_SUBTREE
2147 }
2148 
2149 /* Decide whether there are language-specific reasons to not inline a
2150    function as a tree.  */
2151 
2152 int
cp_cannot_inline_tree_fn(fnp)2153 cp_cannot_inline_tree_fn (fnp)
2154      tree *fnp;
2155 {
2156   tree fn = *fnp;
2157 
2158   if (flag_really_no_inline
2159       && lookup_attribute ("always_inline", DECL_ATTRIBUTES (fn)) == NULL)
2160     return 1;
2161 
2162   /* We can inline a template instantiation only if it's fully
2163      instantiated.  */
2164   if (DECL_TEMPLATE_INFO (fn)
2165       && TI_PENDING_TEMPLATE_FLAG (DECL_TEMPLATE_INFO (fn)))
2166     {
2167       fn = *fnp = instantiate_decl (fn, /*defer_ok=*/0);
2168       if (TI_PENDING_TEMPLATE_FLAG (DECL_TEMPLATE_INFO (fn)))
2169 	return 1;
2170     }
2171 
2172   /* Don't auto-inline anything that might not be bound within
2173      this unit of translation.  */
2174   if (!DECL_DECLARED_INLINE_P (fn) && !(*targetm.binds_local_p) (fn))
2175     {
2176       DECL_UNINLINABLE (fn) = 1;
2177       return 1;
2178     }
2179 
2180   if (varargs_function_p (fn))
2181     {
2182       DECL_UNINLINABLE (fn) = 1;
2183       return 1;
2184     }
2185 
2186   if (! function_attribute_inlinable_p (fn))
2187     {
2188       DECL_UNINLINABLE (fn) = 1;
2189       return 1;
2190     }
2191 
2192   return 0;
2193 }
2194 
2195 /* Add any pending functions other than the current function (already
2196    handled by the caller), that thus cannot be inlined, to FNS_P, then
2197    return the latest function added to the array, PREV_FN.  */
2198 
2199 tree
cp_add_pending_fn_decls(fns_p,prev_fn)2200 cp_add_pending_fn_decls (fns_p, prev_fn)
2201      void *fns_p;
2202      tree prev_fn;
2203 {
2204   varray_type *fnsp = (varray_type *)fns_p;
2205   struct saved_scope *s;
2206 
2207   for (s = scope_chain; s; s = s->prev)
2208     if (s->function_decl && s->function_decl != prev_fn)
2209       {
2210 	VARRAY_PUSH_TREE (*fnsp, s->function_decl);
2211 	prev_fn = s->function_decl;
2212       }
2213 
2214   return prev_fn;
2215 }
2216 
2217 /* Determine whether a tree node is an OVERLOAD node.  Used to decide
2218    whether to copy a node or to preserve its chain when inlining a
2219    function.  */
2220 
2221 int
cp_is_overload_p(t)2222 cp_is_overload_p (t)
2223      tree t;
2224 {
2225   return TREE_CODE (t) == OVERLOAD;
2226 }
2227 
2228 /* Determine whether VAR is a declaration of an automatic variable in
2229    function FN.  */
2230 
2231 int
cp_auto_var_in_fn_p(var,fn)2232 cp_auto_var_in_fn_p (var, fn)
2233      tree var, fn;
2234 {
2235   return (DECL_P (var) && DECL_CONTEXT (var) == fn
2236 	  && nonstatic_local_decl_p (var));
2237 }
2238 
2239 /* Tell whether a declaration is needed for the RESULT of a function
2240    FN being inlined into CALLER or if the top node of target_exprs is
2241    to be used.  */
2242 
2243 tree
cp_copy_res_decl_for_inlining(result,fn,caller,decl_map_,need_decl,target_exprs)2244 cp_copy_res_decl_for_inlining (result, fn, caller, decl_map_,
2245 			       need_decl, target_exprs)
2246      tree result, fn, caller;
2247      void *decl_map_;
2248      int *need_decl;
2249      void *target_exprs;
2250 {
2251   splay_tree decl_map = (splay_tree)decl_map_;
2252   varray_type *texps = (varray_type *)target_exprs;
2253   tree var;
2254   int aggregate_return_p;
2255 
2256   /* Figure out whether or not FN returns an aggregate.  */
2257   aggregate_return_p = IS_AGGR_TYPE (TREE_TYPE (result));
2258   *need_decl = ! aggregate_return_p;
2259 
2260   /* If FN returns an aggregate then the caller will always create the
2261      temporary (using a TARGET_EXPR) and the call will be the
2262      initializing expression for the TARGET_EXPR.  If we were just to
2263      create a new VAR_DECL here, then the result of this function
2264      would be copied (bitwise) into the variable initialized by the
2265      TARGET_EXPR.  That's incorrect, so we must transform any
2266      references to the RESULT into references to the target.  */
2267   if (aggregate_return_p)
2268     {
2269       if (VARRAY_ACTIVE_SIZE (*texps) == 0)
2270 	abort ();
2271       var = TREE_OPERAND (VARRAY_TOP_TREE (*texps), 0);
2272       if (! same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (var),
2273 						       TREE_TYPE (result)))
2274 	abort ();
2275     }
2276   /* Otherwise, make an appropriate copy.  */
2277   else
2278     var = copy_decl_for_inlining (result, fn, caller);
2279 
2280   if (DECL_SAVED_FUNCTION_DATA (fn))
2281     {
2282       tree nrv = DECL_SAVED_FUNCTION_DATA (fn)->x_return_value;
2283       if (nrv)
2284 	{
2285 	  /* We have a named return value; copy the name and source
2286 	     position so we can get reasonable debugging information, and
2287 	     register the return variable as its equivalent.  */
2288 	  DECL_NAME (var) = DECL_NAME (nrv);
2289 	  DECL_SOURCE_LOCATION (var) = DECL_SOURCE_LOCATION (nrv);
2290 	  DECL_ABSTRACT_ORIGIN (var) = DECL_ORIGIN (nrv);
2291 	  /* Don't lose initialization info.  */
2292 	  DECL_INITIAL (var) = DECL_INITIAL (nrv);
2293 	  /* Don't forget that it needs to go in the stack.  */
2294 	  TREE_ADDRESSABLE (var) = TREE_ADDRESSABLE (nrv);
2295 
2296 	  splay_tree_insert (decl_map,
2297 			     (splay_tree_key) nrv,
2298 			     (splay_tree_value) var);
2299 	}
2300     }
2301 
2302   return var;
2303 }
2304 
2305 /* Initialize tree.c.  */
2306 
2307 void
init_tree()2308 init_tree ()
2309 {
2310   lang_statement_code_p = cp_statement_code_p;
2311   list_hash_table = htab_create_ggc (31, list_hash, list_hash_eq, NULL);
2312 }
2313 
2314 /* Called via walk_tree.  If *TP points to a DECL_STMT for a local
2315    declaration, copies the declaration and enters it in the splay_tree
2316    pointed to by DATA (which is really a `splay_tree *').  */
2317 
2318 static tree
mark_local_for_remap_r(tp,walk_subtrees,data)2319 mark_local_for_remap_r (tp, walk_subtrees, data)
2320      tree *tp;
2321      int *walk_subtrees ATTRIBUTE_UNUSED;
2322      void *data;
2323 {
2324   tree t = *tp;
2325   splay_tree st = (splay_tree) data;
2326   tree decl;
2327 
2328 
2329   if (TREE_CODE (t) == DECL_STMT
2330       && nonstatic_local_decl_p (DECL_STMT_DECL (t)))
2331     decl = DECL_STMT_DECL (t);
2332   else if (TREE_CODE (t) == LABEL_STMT)
2333     decl = LABEL_STMT_LABEL (t);
2334   else if (TREE_CODE (t) == TARGET_EXPR
2335 	   && nonstatic_local_decl_p (TREE_OPERAND (t, 0)))
2336     decl = TREE_OPERAND (t, 0);
2337   else if (TREE_CODE (t) == CASE_LABEL)
2338     decl = CASE_LABEL_DECL (t);
2339   else
2340     decl = NULL_TREE;
2341 
2342   if (decl)
2343     {
2344       tree copy;
2345 
2346       /* Make a copy.  */
2347       copy = copy_decl_for_inlining (decl,
2348 				     DECL_CONTEXT (decl),
2349 				     DECL_CONTEXT (decl));
2350 
2351       /* Remember the copy.  */
2352       splay_tree_insert (st,
2353 			 (splay_tree_key) decl,
2354 			 (splay_tree_value) copy);
2355     }
2356 
2357   return NULL_TREE;
2358 }
2359 
2360 /* Called via walk_tree when an expression is unsaved.  Using the
2361    splay_tree pointed to by ST (which is really a `splay_tree'),
2362    remaps all local declarations to appropriate replacements.  */
2363 
2364 static tree
cp_unsave_r(tp,walk_subtrees,data)2365 cp_unsave_r (tp, walk_subtrees, data)
2366      tree *tp;
2367      int *walk_subtrees;
2368      void *data;
2369 {
2370   splay_tree st = (splay_tree) data;
2371   splay_tree_node n;
2372 
2373   /* Only a local declaration (variable or label).  */
2374   if (nonstatic_local_decl_p (*tp))
2375     {
2376       /* Lookup the declaration.  */
2377       n = splay_tree_lookup (st, (splay_tree_key) *tp);
2378 
2379       /* If it's there, remap it.  */
2380       if (n)
2381 	*tp = (tree) n->value;
2382     }
2383   else if (TREE_CODE (*tp) == SAVE_EXPR)
2384     remap_save_expr (tp, st, current_function_decl, walk_subtrees);
2385   else
2386     {
2387       copy_tree_r (tp, walk_subtrees, NULL);
2388 
2389       /* Do whatever unsaving is required.  */
2390       unsave_expr_1 (*tp);
2391     }
2392 
2393   /* Keep iterating.  */
2394   return NULL_TREE;
2395 }
2396 
2397 /* Called whenever an expression needs to be unsaved.  */
2398 
2399 tree
cxx_unsave_expr_now(tp)2400 cxx_unsave_expr_now (tp)
2401      tree tp;
2402 {
2403   splay_tree st;
2404 
2405   /* Create a splay-tree to map old local variable declarations to new
2406      ones.  */
2407   st = splay_tree_new (splay_tree_compare_pointers, NULL, NULL);
2408 
2409   /* Walk the tree once figuring out what needs to be remapped.  */
2410   walk_tree (&tp, mark_local_for_remap_r, st, NULL);
2411 
2412   /* Walk the tree again, copying, remapping, and unsaving.  */
2413   walk_tree (&tp, cp_unsave_r, st, NULL);
2414 
2415   /* Clean up.  */
2416   splay_tree_delete (st);
2417 
2418   return tp;
2419 }
2420 
2421 /* Returns the kind of special function that DECL (a FUNCTION_DECL)
2422    is.  Note that sfk_none is zero, so this function can be used as a
2423    predicate to test whether or not DECL is a special function.  */
2424 
2425 special_function_kind
special_function_p(decl)2426 special_function_p (decl)
2427      tree decl;
2428 {
2429   /* Rather than doing all this stuff with magic names, we should
2430      probably have a field of type `special_function_kind' in
2431      DECL_LANG_SPECIFIC.  */
2432   if (DECL_COPY_CONSTRUCTOR_P (decl))
2433     return sfk_copy_constructor;
2434   if (DECL_CONSTRUCTOR_P (decl))
2435     return sfk_constructor;
2436   if (DECL_OVERLOADED_OPERATOR_P (decl) == NOP_EXPR)
2437     return sfk_assignment_operator;
2438   if (DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (decl))
2439     return sfk_destructor;
2440   if (DECL_COMPLETE_DESTRUCTOR_P (decl))
2441     return sfk_complete_destructor;
2442   if (DECL_BASE_DESTRUCTOR_P (decl))
2443     return sfk_base_destructor;
2444   if (DECL_DELETING_DESTRUCTOR_P (decl))
2445     return sfk_deleting_destructor;
2446   if (DECL_CONV_FN_P (decl))
2447     return sfk_conversion;
2448 
2449   return sfk_none;
2450 }
2451 
2452 /* Returns true if and only if NODE is a name, i.e., a node created
2453    by the parser when processing an id-expression.  */
2454 
2455 bool
name_p(tree node)2456 name_p (tree node)
2457 {
2458   if (TREE_CODE (node) == TEMPLATE_ID_EXPR)
2459     node = TREE_OPERAND (node, 0);
2460   return (/* An ordinary unqualified name.  */
2461 	  TREE_CODE (node) == IDENTIFIER_NODE
2462 	  /* A destructor name.  */
2463 	  || TREE_CODE (node) == BIT_NOT_EXPR
2464 	  /* A qualified name.  */
2465 	  || TREE_CODE (node) == SCOPE_REF);
2466 }
2467 
2468 /* Returns nonzero if TYPE is a character type, including wchar_t.  */
2469 
2470 int
char_type_p(type)2471 char_type_p (type)
2472      tree type;
2473 {
2474   return (same_type_p (type, char_type_node)
2475 	  || same_type_p (type, unsigned_char_type_node)
2476 	  || same_type_p (type, signed_char_type_node)
2477 	  || same_type_p (type, wchar_type_node));
2478 }
2479 
2480 /* Returns the kind of linkage associated with the indicated DECL.  Th
2481    value returned is as specified by the language standard; it is
2482    independent of implementation details regarding template
2483    instantiation, etc.  For example, it is possible that a declaration
2484    to which this function assigns external linkage would not show up
2485    as a global symbol when you run `nm' on the resulting object file.  */
2486 
2487 linkage_kind
decl_linkage(decl)2488 decl_linkage (decl)
2489      tree decl;
2490 {
2491   /* This function doesn't attempt to calculate the linkage from first
2492      principles as given in [basic.link].  Instead, it makes use of
2493      the fact that we have already set TREE_PUBLIC appropriately, and
2494      then handles a few special cases.  Ideally, we would calculate
2495      linkage first, and then transform that into a concrete
2496      implementation.  */
2497 
2498   /* Things that don't have names have no linkage.  */
2499   if (!DECL_NAME (decl))
2500     return lk_none;
2501 
2502   /* Things that are TREE_PUBLIC have external linkage.  */
2503   if (TREE_PUBLIC (decl))
2504     return lk_external;
2505 
2506   /* Some things that are not TREE_PUBLIC have external linkage, too.
2507      For example, on targets that don't have weak symbols, we make all
2508      template instantiations have internal linkage (in the object
2509      file), but the symbols should still be treated as having external
2510      linkage from the point of view of the language.  */
2511   if (DECL_LANG_SPECIFIC (decl) && DECL_COMDAT (decl))
2512     return lk_external;
2513 
2514   /* Things in local scope do not have linkage, if they don't have
2515      TREE_PUBLIC set.  */
2516   if (decl_function_context (decl))
2517     return lk_none;
2518 
2519   /* Everything else has internal linkage.  */
2520   return lk_internal;
2521 }
2522 
2523 /* EXP is an expression that we want to pre-evaluate.  Returns via INITP an
2524    expression to perform the pre-evaluation, and returns directly an
2525    expression to use the precalculated result.  */
2526 
2527 tree
stabilize_expr(exp,initp)2528 stabilize_expr (exp, initp)
2529      tree exp;
2530      tree *initp;
2531 {
2532   tree init_expr;
2533 
2534   if (!TREE_SIDE_EFFECTS (exp))
2535     {
2536       init_expr = void_zero_node;
2537     }
2538   else if (!real_lvalue_p (exp)
2539 	   || !TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (exp)))
2540     {
2541       init_expr = get_target_expr (exp);
2542       exp = TARGET_EXPR_SLOT (init_expr);
2543     }
2544   else
2545     {
2546       exp = build_unary_op (ADDR_EXPR, exp, 1);
2547       init_expr = get_target_expr (exp);
2548       exp = TARGET_EXPR_SLOT (init_expr);
2549       exp = build_indirect_ref (exp, 0);
2550     }
2551 
2552   *initp = init_expr;
2553   return exp;
2554 }
2555 
2556 #if defined ENABLE_TREE_CHECKING && (GCC_VERSION >= 2007)
2557 /* Complain that some language-specific thing hanging off a tree
2558    node has been accessed improperly.  */
2559 
2560 void
lang_check_failed(file,line,function)2561 lang_check_failed (file, line, function)
2562      const char *file;
2563      int line;
2564      const char *function;
2565 {
2566   internal_error ("lang_* check: failed in %s, at %s:%d",
2567 		  function, trim_filename (file), line);
2568 }
2569 #endif /* ENABLE_TREE_CHECKING */
2570 
2571 #include "gt-cp-tree.h"
2572