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