]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/cp/semantics.c
i386.c (legitimate_constant_p): UNSPEC_TP is not legitimate constant.
[thirdparty/gcc.git] / gcc / cp / semantics.c
CommitLineData
ad321293
MM
1/* Perform the semantic phase of parsing, i.e., the process of
2 building tree structure, checking semantic consistency, and
3 building RTL. These routines are used both during actual parsing
4 and during the instantiation of template functions.
5
a4200657 6 Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
ad321293
MM
7 Written by Mark Mitchell (mmitchell@usa.net) based on code found
8 formerly in parse.y and pt.c.
9
10 This file is part of GNU CC.
11
12 GNU CC is free software; you can redistribute it and/or modify it
13 under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2, or (at your option)
15 any later version.
16
17 GNU CC is distributed in the hope that it will be useful, but
18 WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 General Public License for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with GNU CC; see the file COPYING. If not, write to the Free
24 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
25 02111-1307, USA. */
26
27#include "config.h"
8d052bc7 28#include "system.h"
ad321293
MM
29#include "tree.h"
30#include "cp-tree.h"
25af8512 31#include "tree-inline.h"
ad321293
MM
32#include "except.h"
33#include "lex.h"
12027a89 34#include "toplev.h"
84df082b 35#include "flags.h"
d658cd4c 36#include "ggc.h"
d9b2d9da 37#include "rtl.h"
d6684bc8 38#include "expr.h"
225ff119 39#include "output.h"
ea11ca7e 40#include "timevar.h"
2b85879e 41#include "debug.h"
ad321293
MM
42
43/* There routines provide a modular interface to perform many parsing
44 operations. They may therefore be used during actual parsing, or
45 during template instantiation, which may be regarded as a
46 degenerate form of parsing. Since the current g++ parser is
47 lacking in several respects, and will be reimplemented, we are
48 attempting to move most code that is not directly related to
49 parsing into this file; that will make implementing the new parser
50 much easier since it will be able to make use of these routines. */
51
158991b7
KG
52static tree maybe_convert_cond PARAMS ((tree));
53static tree simplify_aggr_init_exprs_r PARAMS ((tree *, int *, void *));
c2e407f1 54static void deferred_type_access_control PARAMS ((void));
31f8e4f3 55static void emit_associated_thunks PARAMS ((tree));
54f7877c 56static void genrtl_try_block PARAMS ((tree));
52a11cbf 57static void genrtl_eh_spec_block PARAMS ((tree));
54f7877c 58static void genrtl_handler PARAMS ((tree));
54f7877c
MM
59static void genrtl_named_return_value PARAMS ((void));
60static void cp_expand_stmt PARAMS ((tree));
f444e36b
MM
61static void genrtl_start_function PARAMS ((tree));
62static void genrtl_finish_function PARAMS ((tree));
b850de4f 63static tree clear_decl_rtl PARAMS ((tree *, int *, void *));
558475f0 64
527f0080
MM
65/* Finish processing the COND, the SUBSTMT condition for STMT. */
66
c3af729a 67#define FINISH_COND(COND, STMT, SUBSTMT) \
ed5511d9 68 do { \
c3af729a 69 if (last_tree != (STMT)) \
ed5511d9 70 { \
c3af729a
GS
71 RECHAIN_STMTS (STMT, SUBSTMT); \
72 if (!processing_template_decl) \
73 { \
74 (COND) = build_tree_list (SUBSTMT, COND); \
75 (SUBSTMT) = (COND); \
76 } \
ed5511d9
MM
77 } \
78 else \
c3af729a 79 (SUBSTMT) = (COND); \
527f0080 80 } while (0)
35b1567d 81
f2c5f623
BC
82/* Returns non-zero if the current statement is a full expression,
83 i.e. temporaries created during that statement should be destroyed
84 at the end of the statement. */
35b1567d 85
f2c5f623
BC
86int
87stmts_are_full_exprs_p ()
88{
ae499cce
MM
89 return current_stmt_tree ()->stmts_are_full_exprs_p;
90}
91
92/* Returns the stmt_tree (if any) to which statements are currently
93 being added. If there is no active statement-tree, NULL is
94 returned. */
95
96stmt_tree
97current_stmt_tree ()
98{
99 return (cfun
e2500fed 100 ? &cfun->language->base.x_stmt_tree
ae499cce 101 : &scope_chain->x_stmt_tree);
f2c5f623 102}
35b1567d 103
f2c5f623
BC
104/* Nonzero if TYPE is an anonymous union or struct type. We have to use a
105 flag for this because "A union for which objects or pointers are
106 declared is not an anonymous union" [class.union]. */
35b1567d 107
f2c5f623
BC
108int
109anon_aggr_type_p (node)
110 tree node;
35b1567d 111{
e2500fed 112 return ANON_AGGR_TYPE_P (node);
35b1567d
BC
113}
114
f2c5f623 115/* Finish a scope. */
35b1567d
BC
116
117tree
f2c5f623 118do_poplevel ()
35b1567d
BC
119{
120 tree block = NULL_TREE;
121
f2c5f623 122 if (stmts_are_full_exprs_p ())
35b1567d 123 {
50e60bc3 124 tree scope_stmts = NULL_TREE;
f2c5f623
BC
125
126 if (!processing_template_decl)
127 scope_stmts = add_scope_stmt (/*begin_p=*/0, /*partial_p=*/0);
35b1567d
BC
128
129 block = poplevel (kept_level_p (), 1, 0);
130 if (block && !processing_template_decl)
131 {
132 SCOPE_STMT_BLOCK (TREE_PURPOSE (scope_stmts)) = block;
133 SCOPE_STMT_BLOCK (TREE_VALUE (scope_stmts)) = block;
134 }
135 }
136
137 return block;
138}
139
f2c5f623 140/* Begin a new scope. */
35b1567d
BC
141
142void
f2c5f623 143do_pushlevel ()
35b1567d 144{
f2c5f623 145 if (stmts_are_full_exprs_p ())
35b1567d 146 {
f2c5f623
BC
147 pushlevel (0);
148 if (!processing_template_decl)
149 add_scope_stmt (/*begin_p=*/1, /*partial_p=*/0);
35b1567d
BC
150 }
151}
152
35b1567d
BC
153/* Finish a goto-statement. */
154
3e4d04a1 155tree
35b1567d
BC
156finish_goto_stmt (destination)
157 tree destination;
158{
159 if (TREE_CODE (destination) == IDENTIFIER_NODE)
160 destination = lookup_label (destination);
161
162 /* We warn about unused labels with -Wunused. That means we have to
163 mark the used labels as used. */
164 if (TREE_CODE (destination) == LABEL_DECL)
165 TREE_USED (destination) = 1;
166
167 if (TREE_CODE (destination) != LABEL_DECL)
168 /* We don't inline calls to functions with computed gotos.
169 Those functions are typically up to some funny business,
170 and may be depending on the labels being at particular
171 addresses, or some such. */
172 DECL_UNINLINABLE (current_function_decl) = 1;
173
174 check_goto (destination);
175
3e4d04a1 176 return add_stmt (build_stmt (GOTO_STMT, destination));
35b1567d
BC
177}
178
ed5511d9
MM
179/* COND is the condition-expression for an if, while, etc.,
180 statement. Convert it to a boolean value, if appropriate. */
181
f2c5f623 182tree
ed5511d9
MM
183maybe_convert_cond (cond)
184 tree cond;
185{
186 /* Empty conditions remain empty. */
187 if (!cond)
188 return NULL_TREE;
189
190 /* Wait until we instantiate templates before doing conversion. */
191 if (processing_template_decl)
192 return cond;
193
194 /* Do the conversion. */
195 cond = convert_from_reference (cond);
196 return condition_conversion (cond);
197}
198
9bfadf57 199/* Finish an expression-statement, whose EXPRESSION is as indicated. */
a7e4cfa0 200
3e4d04a1 201tree
9bfadf57 202finish_expr_stmt (expr)
ad321293
MM
203 tree expr;
204{
3e4d04a1 205 tree r = NULL_TREE;
0481bc21 206 tree expr_type = NULL_TREE;;
3e4d04a1 207
ce4a0391 208 if (expr != NULL_TREE)
ad321293 209 {
35b1567d 210 if (!processing_template_decl
f2c5f623 211 && !(stmts_are_full_exprs_p ())
35b1567d
BC
212 && ((TREE_CODE (TREE_TYPE (expr)) == ARRAY_TYPE
213 && lvalue_p (expr))
214 || TREE_CODE (TREE_TYPE (expr)) == FUNCTION_TYPE))
215 expr = default_conversion (expr);
216
0481bc21
MM
217 /* Remember the type of the expression. */
218 expr_type = TREE_TYPE (expr);
219
f2c5f623 220 if (stmts_are_full_exprs_p ())
35b1567d
BC
221 expr = convert_to_void (expr, "statement");
222
3e4d04a1 223 r = add_stmt (build_stmt (EXPR_STMT, expr));
35b1567d 224 }
364460b6 225
35b1567d 226 finish_stmt ();
558475f0 227
35b1567d
BC
228 /* This was an expression-statement, so we save the type of the
229 expression. */
0481bc21 230 last_expr_type = expr_type;
3e4d04a1
RH
231
232 return r;
35b1567d
BC
233}
234
35b1567d 235
ad321293
MM
236/* Begin an if-statement. Returns a newly created IF_STMT if
237 appropriate. */
238
239tree
240begin_if_stmt ()
241{
242 tree r;
9bfadf57 243 do_pushlevel ();
0dfdeca6 244 r = build_stmt (IF_STMT, NULL_TREE, NULL_TREE, NULL_TREE);
ae499cce 245 add_stmt (r);
ad321293
MM
246 return r;
247}
248
249/* Process the COND of an if-statement, which may be given by
250 IF_STMT. */
251
252void
253finish_if_stmt_cond (cond, if_stmt)
254 tree cond;
255 tree if_stmt;
256{
ed5511d9 257 cond = maybe_convert_cond (cond);
35b1567d 258 FINISH_COND (cond, if_stmt, IF_COND (if_stmt));
ad321293
MM
259}
260
261/* Finish the then-clause of an if-statement, which may be given by
262 IF_STMT. */
263
264tree
265finish_then_clause (if_stmt)
266 tree if_stmt;
267{
35b1567d 268 RECHAIN_STMTS (if_stmt, THEN_CLAUSE (if_stmt));
ae499cce 269 last_tree = if_stmt;
35b1567d 270 return if_stmt;
ad321293
MM
271}
272
273/* Begin the else-clause of an if-statement. */
274
275void
276begin_else_clause ()
277{
ad321293
MM
278}
279
280/* Finish the else-clause of an if-statement, which may be given by
281 IF_STMT. */
282
283void
284finish_else_clause (if_stmt)
285 tree if_stmt;
286{
35b1567d 287 RECHAIN_STMTS (if_stmt, ELSE_CLAUSE (if_stmt));
ad321293
MM
288}
289
dfbb4f34 290/* Finish an if-statement. */
ad321293
MM
291
292void
293finish_if_stmt ()
294{
ad321293
MM
295 do_poplevel ();
296 finish_stmt ();
297}
298
35b1567d
BC
299void
300clear_out_block ()
301{
302 /* If COND wasn't a declaration, clear out the
303 block we made for it and start a new one here so the
304 optimization in expand_end_loop will work. */
305 if (getdecls () == NULL_TREE)
306 {
307 do_poplevel ();
308 do_pushlevel ();
309 }
310}
311
ad321293
MM
312/* Begin a while-statement. Returns a newly created WHILE_STMT if
313 appropriate. */
314
315tree
316begin_while_stmt ()
317{
318 tree r;
0dfdeca6 319 r = build_stmt (WHILE_STMT, NULL_TREE, NULL_TREE);
ae499cce 320 add_stmt (r);
ad321293 321 do_pushlevel ();
ad321293
MM
322 return r;
323}
324
27d26ee7 325/* Process the COND of a while-statement, which may be given by
ad321293
MM
326 WHILE_STMT. */
327
328void
329finish_while_stmt_cond (cond, while_stmt)
330 tree cond;
331 tree while_stmt;
332{
ed5511d9 333 cond = maybe_convert_cond (cond);
35b1567d
BC
334 FINISH_COND (cond, while_stmt, WHILE_COND (while_stmt));
335 clear_out_block ();
ad321293
MM
336}
337
338/* Finish a while-statement, which may be given by WHILE_STMT. */
339
340void
341finish_while_stmt (while_stmt)
342 tree while_stmt;
343{
344 do_poplevel ();
35b1567d 345 RECHAIN_STMTS (while_stmt, WHILE_BODY (while_stmt));
ad321293
MM
346 finish_stmt ();
347}
348
349/* Begin a do-statement. Returns a newly created DO_STMT if
350 appropriate. */
351
352tree
353begin_do_stmt ()
354{
0dfdeca6 355 tree r = build_stmt (DO_STMT, NULL_TREE, NULL_TREE);
ae499cce 356 add_stmt (r);
35b1567d 357 return r;
ad321293
MM
358}
359
360/* Finish the body of a do-statement, which may be given by DO_STMT. */
361
362void
363finish_do_body (do_stmt)
364 tree do_stmt;
365{
35b1567d 366 RECHAIN_STMTS (do_stmt, DO_BODY (do_stmt));
ad321293
MM
367}
368
369/* Finish a do-statement, which may be given by DO_STMT, and whose
370 COND is as indicated. */
371
372void
373finish_do_stmt (cond, do_stmt)
374 tree cond;
375 tree do_stmt;
376{
ed5511d9 377 cond = maybe_convert_cond (cond);
35b1567d
BC
378 DO_COND (do_stmt) = cond;
379 finish_stmt ();
380}
ed5511d9 381
ad321293
MM
382/* Finish a return-statement. The EXPRESSION returned, if any, is as
383 indicated. */
384
3e4d04a1 385tree
ad321293
MM
386finish_return_stmt (expr)
387 tree expr;
388{
3e4d04a1
RH
389 tree r;
390
35b1567d 391 if (!processing_template_decl)
efee38a9 392 expr = check_return_expr (expr);
35b1567d 393 if (!processing_template_decl)
efee38a9 394 {
a0de9d20 395 if (DECL_DESTRUCTOR_P (current_function_decl))
efee38a9
MM
396 {
397 /* Similarly, all destructors must run destructors for
398 base-classes before returning. So, all returns in a
dfbb4f34 399 destructor get sent to the DTOR_LABEL; finish_function emits
efee38a9 400 code to return a value there. */
3e4d04a1 401 return finish_goto_stmt (dtor_label);
efee38a9
MM
402 }
403 }
3e4d04a1 404 r = add_stmt (build_stmt (RETURN_STMT, expr));
35b1567d 405 finish_stmt ();
3e4d04a1
RH
406
407 return r;
35b1567d 408}
efee38a9 409
ad321293
MM
410/* Begin a for-statement. Returns a new FOR_STMT if appropriate. */
411
412tree
413begin_for_stmt ()
414{
415 tree r;
416
0dfdeca6
BC
417 r = build_stmt (FOR_STMT, NULL_TREE, NULL_TREE,
418 NULL_TREE, NULL_TREE);
f2c5f623 419 NEW_FOR_SCOPE_P (r) = flag_new_for_scope > 0;
f2c5f623 420 if (NEW_FOR_SCOPE_P (r))
ad321293
MM
421 {
422 do_pushlevel ();
423 note_level_for_for ();
424 }
18ba380b 425 add_stmt (r);
ad321293
MM
426
427 return r;
428}
429
430/* Finish the for-init-statement of a for-statement, which may be
431 given by FOR_STMT. */
432
433void
434finish_for_init_stmt (for_stmt)
435 tree for_stmt;
436{
35b1567d
BC
437 if (last_tree != for_stmt)
438 RECHAIN_STMTS (for_stmt, FOR_INIT_STMT (for_stmt));
ad321293
MM
439 do_pushlevel ();
440}
441
442/* Finish the COND of a for-statement, which may be given by
443 FOR_STMT. */
444
445void
446finish_for_cond (cond, for_stmt)
447 tree cond;
448 tree for_stmt;
449{
ed5511d9 450 cond = maybe_convert_cond (cond);
35b1567d
BC
451 FINISH_COND (cond, for_stmt, FOR_COND (for_stmt));
452 clear_out_block ();
ad321293
MM
453}
454
455/* Finish the increment-EXPRESSION in a for-statement, which may be
456 given by FOR_STMT. */
457
458void
459finish_for_expr (expr, for_stmt)
460 tree expr;
461 tree for_stmt;
462{
35b1567d 463 FOR_EXPR (for_stmt) = expr;
ad321293
MM
464}
465
466/* Finish the body of a for-statement, which may be given by
467 FOR_STMT. The increment-EXPR for the loop must be
468 provided. */
469
470void
35b1567d 471finish_for_stmt (for_stmt)
ad321293
MM
472 tree for_stmt;
473{
474 /* Pop the scope for the body of the loop. */
475 do_poplevel ();
35b1567d 476 RECHAIN_STMTS (for_stmt, FOR_BODY (for_stmt));
f2c5f623 477 if (NEW_FOR_SCOPE_P (for_stmt))
ad321293 478 do_poplevel ();
ad321293
MM
479 finish_stmt ();
480}
481
482/* Finish a break-statement. */
483
3e4d04a1 484tree
ad321293
MM
485finish_break_stmt ()
486{
3e4d04a1 487 return add_stmt (build_break_stmt ());
35b1567d
BC
488}
489
ad321293
MM
490/* Finish a continue-statement. */
491
3e4d04a1 492tree
ad321293
MM
493finish_continue_stmt ()
494{
3e4d04a1 495 return add_stmt (build_continue_stmt ());
ad321293
MM
496}
497
35b1567d
BC
498/* Begin a switch-statement. Returns a new SWITCH_STMT if
499 appropriate. */
500
501tree
502begin_switch_stmt ()
503{
504 tree r;
6f9fdf4d 505 r = build_stmt (SWITCH_STMT, NULL_TREE, NULL_TREE, NULL_TREE);
ae499cce 506 add_stmt (r);
35b1567d 507 do_pushlevel ();
527f0080 508 return r;
ad321293
MM
509}
510
527f0080 511/* Finish the cond of a switch-statement. */
ad321293 512
527f0080
MM
513void
514finish_switch_cond (cond, switch_stmt)
ad321293 515 tree cond;
527f0080 516 tree switch_stmt;
ad321293 517{
6f9fdf4d 518 tree orig_type = NULL;
35b1567d 519 if (!processing_template_decl)
373eb3b3 520 {
56cb9733
MM
521 tree index;
522
35b1567d
BC
523 /* Convert the condition to an integer or enumeration type. */
524 cond = build_expr_type_conversion (WANT_INT | WANT_ENUM, cond, 1);
525 if (cond == NULL_TREE)
373eb3b3 526 {
35b1567d
BC
527 error ("switch quantity not an integer");
528 cond = error_mark_node;
529 }
6f9fdf4d 530 orig_type = TREE_TYPE (cond);
35b1567d
BC
531 if (cond != error_mark_node)
532 {
35b1567d 533 cond = default_conversion (cond);
2bb5d995 534 cond = fold (build1 (CLEANUP_POINT_EXPR, TREE_TYPE (cond), cond));
373eb3b3 535 }
56cb9733 536
25c8b645
JJ
537 if (cond != error_mark_node)
538 {
539 index = get_unwidened (cond, NULL_TREE);
540 /* We can't strip a conversion from a signed type to an unsigned,
541 because if we did, int_fits_type_p would do the wrong thing
542 when checking case values for being in range,
543 and it's too hard to do the right thing. */
544 if (TREE_UNSIGNED (TREE_TYPE (cond))
545 == TREE_UNSIGNED (TREE_TYPE (index)))
546 cond = index;
547 }
ad321293 548 }
35b1567d 549 FINISH_COND (cond, switch_stmt, SWITCH_COND (switch_stmt));
6f9fdf4d 550 SWITCH_TYPE (switch_stmt) = orig_type;
56cb9733 551 push_switch (switch_stmt);
ad321293
MM
552}
553
554/* Finish the body of a switch-statement, which may be given by
555 SWITCH_STMT. The COND to switch on is indicated. */
556
557void
35b1567d 558finish_switch_stmt (switch_stmt)
ad321293
MM
559 tree switch_stmt;
560{
35b1567d 561 RECHAIN_STMTS (switch_stmt, SWITCH_BODY (switch_stmt));
ad321293
MM
562 pop_switch ();
563 do_poplevel ();
564 finish_stmt ();
565}
566
35b1567d 567/* Generate the RTL for T, which is a TRY_BLOCK. */
6625cdb5 568
54f7877c
MM
569static void
570genrtl_try_block (t)
35b1567d
BC
571 tree t;
572{
573 if (CLEANUP_P (t))
574 {
575 expand_eh_region_start ();
576 expand_stmt (TRY_STMTS (t));
52a11cbf 577 expand_eh_region_end_cleanup (TRY_HANDLERS (t));
46e8c075 578 }
ad321293
MM
579 else
580 {
f444e36b
MM
581 if (!FN_TRY_BLOCK_P (t))
582 emit_line_note (input_filename, lineno);
35b1567d 583
52a11cbf 584 expand_eh_region_start ();
35b1567d 585 expand_stmt (TRY_STMTS (t));
ad321293 586
35b1567d 587 if (FN_TRY_BLOCK_P (t))
ad321293 588 {
35b1567d
BC
589 expand_start_all_catch ();
590 in_function_try_handler = 1;
591 expand_stmt (TRY_HANDLERS (t));
592 in_function_try_handler = 0;
593 expand_end_all_catch ();
594 }
595 else
596 {
597 expand_start_all_catch ();
598 expand_stmt (TRY_HANDLERS (t));
599 expand_end_all_catch ();
ad321293 600 }
ad321293
MM
601 }
602}
603
52a11cbf
RH
604/* Generate the RTL for T, which is an EH_SPEC_BLOCK. */
605
606static void
607genrtl_eh_spec_block (t)
608 tree t;
609{
610 expand_eh_region_start ();
611 expand_stmt (EH_SPEC_STMTS (t));
612 expand_eh_region_end_allowed (EH_SPEC_RAISES (t),
613 build_call (call_unexpected_node,
614 tree_cons (NULL_TREE,
615 build_exc_ptr (),
616 NULL_TREE)));
617}
618
ad321293
MM
619/* Begin a try-block. Returns a newly-created TRY_BLOCK if
620 appropriate. */
621
622tree
623begin_try_block ()
624{
0dfdeca6 625 tree r = build_stmt (TRY_BLOCK, NULL_TREE, NULL_TREE);
ae499cce 626 add_stmt (r);
35b1567d 627 return r;
ad321293
MM
628}
629
0dde4175
JM
630/* Likewise, for a function-try-block. */
631
632tree
633begin_function_try_block ()
634{
0dfdeca6 635 tree r = build_stmt (TRY_BLOCK, NULL_TREE, NULL_TREE);
35b1567d 636 FN_TRY_BLOCK_P (r) = 1;
ae499cce 637 add_stmt (r);
35b1567d 638 return r;
0dde4175
JM
639}
640
ad321293
MM
641/* Finish a try-block, which may be given by TRY_BLOCK. */
642
643void
644finish_try_block (try_block)
645 tree try_block;
646{
35b1567d 647 RECHAIN_STMTS (try_block, TRY_STMTS (try_block));
ad321293
MM
648}
649
efa8eda3
MM
650/* Finish the body of a cleanup try-block, which may be given by
651 TRY_BLOCK. */
652
62409b39
MM
653void
654finish_cleanup_try_block (try_block)
655 tree try_block;
656{
35b1567d 657 RECHAIN_STMTS (try_block, TRY_STMTS (try_block));
62409b39
MM
658}
659
f1dedc31
MM
660/* Finish an implicitly generated try-block, with a cleanup is given
661 by CLEANUP. */
662
663void
664finish_cleanup (cleanup, try_block)
665 tree cleanup;
666 tree try_block;
667{
35b1567d
BC
668 TRY_HANDLERS (try_block) = cleanup;
669 CLEANUP_P (try_block) = 1;
f1dedc31
MM
670}
671
0dde4175
JM
672/* Likewise, for a function-try-block. */
673
674void
675finish_function_try_block (try_block)
a0de9d20 676 tree try_block;
0dde4175 677{
35b1567d
BC
678 if (TREE_CHAIN (try_block)
679 && TREE_CODE (TREE_CHAIN (try_block)) == CTOR_INITIALIZER)
62409b39 680 {
35b1567d
BC
681 /* Chain the compound statement after the CTOR_INITIALIZER. */
682 TREE_CHAIN (TREE_CHAIN (try_block)) = last_tree;
683 /* And make the CTOR_INITIALIZER the body of the try-block. */
684 RECHAIN_STMTS (try_block, TRY_STMTS (try_block));
62409b39 685 }
0dde4175 686 else
35b1567d 687 RECHAIN_STMTS (try_block, TRY_STMTS (try_block));
b35d4555 688 in_function_try_handler = 1;
0dde4175
JM
689}
690
ad321293
MM
691/* Finish a handler-sequence for a try-block, which may be given by
692 TRY_BLOCK. */
693
694void
695finish_handler_sequence (try_block)
696 tree try_block;
697{
35b1567d
BC
698 RECHAIN_STMTS (try_block, TRY_HANDLERS (try_block));
699 check_handlers (TRY_HANDLERS (try_block));
ad321293
MM
700}
701
0dde4175
JM
702/* Likewise, for a function-try-block. */
703
704void
705finish_function_handler_sequence (try_block)
706 tree try_block;
707{
b35d4555 708 in_function_try_handler = 0;
35b1567d
BC
709 RECHAIN_STMTS (try_block, TRY_HANDLERS (try_block));
710 check_handlers (TRY_HANDLERS (try_block));
711}
712
713/* Generate the RTL for T, which is a HANDLER. */
b35d4555 714
54f7877c 715static void
35b1567d
BC
716genrtl_handler (t)
717 tree t;
718{
719 genrtl_do_pushlevel ();
1a6025b4
JM
720 if (!processing_template_decl)
721 expand_start_catch (HANDLER_TYPE (t));
35b1567d
BC
722 expand_stmt (HANDLER_BODY (t));
723 if (!processing_template_decl)
52a11cbf 724 expand_end_catch ();
0dde4175
JM
725}
726
ad321293
MM
727/* Begin a handler. Returns a HANDLER if appropriate. */
728
729tree
730begin_handler ()
731{
732 tree r;
0dfdeca6 733 r = build_stmt (HANDLER, NULL_TREE, NULL_TREE);
ae499cce 734 add_stmt (r);
1a6025b4
JM
735 /* Create a binding level for the eh_info and the exception object
736 cleanup. */
ad321293 737 do_pushlevel ();
1a6025b4 738 note_level_for_catch ();
ad321293
MM
739 return r;
740}
741
742/* Finish the handler-parameters for a handler, which may be given by
b35d4555
MM
743 HANDLER. DECL is the declaration for the catch parameter, or NULL
744 if this is a `catch (...)' clause. */
ad321293 745
1a6025b4 746void
b35d4555
MM
747finish_handler_parms (decl, handler)
748 tree decl;
ad321293 749 tree handler;
b35d4555 750{
1a6025b4 751 tree type = NULL_TREE;
b35d4555
MM
752 if (processing_template_decl)
753 {
754 if (decl)
755 {
756 decl = pushdecl (decl);
757 decl = push_template_decl (decl);
758 add_decl_stmt (decl);
759 RECHAIN_STMTS (handler, HANDLER_PARMS (handler));
1a6025b4 760 type = TREE_TYPE (decl);
b35d4555
MM
761 }
762 }
35b1567d 763 else
1a6025b4 764 type = expand_start_catch_block (decl);
35b1567d 765
1a6025b4 766 HANDLER_TYPE (handler) = type;
35b1567d
BC
767}
768
769/* Finish a handler, which may be given by HANDLER. The BLOCKs are
770 the return value from the matching call to finish_handler_parms. */
771
772void
1a6025b4 773finish_handler (handler)
35b1567d
BC
774 tree handler;
775{
776 if (!processing_template_decl)
1a6025b4 777 expand_end_catch_block ();
35b1567d
BC
778 do_poplevel ();
779 RECHAIN_STMTS (handler, HANDLER_BODY (handler));
780}
781
ad321293
MM
782/* Begin a compound-statement. If HAS_NO_SCOPE is non-zero, the
783 compound-statement does not define a scope. Returns a new
784 COMPOUND_STMT if appropriate. */
785
786tree
787begin_compound_stmt (has_no_scope)
788 int has_no_scope;
789{
790 tree r;
6625cdb5 791 int is_try = 0;
ad321293 792
0dfdeca6 793 r = build_stmt (COMPOUND_STMT, NULL_TREE);
35b1567d
BC
794
795 if (last_tree && TREE_CODE (last_tree) == TRY_BLOCK)
796 is_try = 1;
797
ae499cce 798 add_stmt (r);
35b1567d
BC
799 if (has_no_scope)
800 COMPOUND_STMT_NO_SCOPE (r) = 1;
ad321293 801
558475f0
MM
802 last_expr_type = NULL_TREE;
803
ad321293 804 if (!has_no_scope)
6625cdb5
JM
805 {
806 do_pushlevel ();
807 if (is_try)
826840d9 808 note_level_for_try ();
6625cdb5 809 }
f1dedc31
MM
810 else
811 /* Normally, we try hard to keep the BLOCK for a
812 statement-expression. But, if it's a statement-expression with
813 a scopeless block, there's nothing to keep, and we don't want
814 to accidentally keep a block *inside* the scopeless block. */
815 keep_next_level (0);
ad321293
MM
816
817 return r;
818}
819
ad321293
MM
820/* Finish a compound-statement, which may be given by COMPOUND_STMT.
821 If HAS_NO_SCOPE is non-zero, the compound statement does not define
822 a scope. */
823
824tree
825finish_compound_stmt (has_no_scope, compound_stmt)
826 int has_no_scope;
827 tree compound_stmt;
828{
829 tree r;
558475f0 830 tree t;
ad321293
MM
831
832 if (!has_no_scope)
833 r = do_poplevel ();
834 else
835 r = NULL_TREE;
836
35b1567d 837 RECHAIN_STMTS (compound_stmt, COMPOUND_BODY (compound_stmt));
ad321293 838
cb39191d 839 /* When we call finish_stmt we will lose LAST_EXPR_TYPE. But, since
558475f0
MM
840 the precise purpose of that variable is store the type of the
841 last expression statement within the last compound statement, we
842 preserve the value. */
843 t = last_expr_type;
ad321293 844 finish_stmt ();
558475f0 845 last_expr_type = t;
ad321293
MM
846
847 return r;
848}
849
35b1567d
BC
850/* Finish an asm-statement, whose components are a CV_QUALIFIER, a
851 STRING, some OUTPUT_OPERANDS, some INPUT_OPERANDS, and some
852 CLOBBERS. */
7dc5bd62 853
3e4d04a1 854tree
35b1567d
BC
855finish_asm_stmt (cv_qualifier, string, output_operands,
856 input_operands, clobbers)
857 tree cv_qualifier;
858 tree string;
859 tree output_operands;
860 tree input_operands;
861 tree clobbers;
862{
863 tree r;
abfc8a36
MM
864 tree t;
865
35b1567d
BC
866 if (cv_qualifier != NULL_TREE
867 && cv_qualifier != ridpointers[(int) RID_VOLATILE])
868 {
33bd39a2 869 warning ("%s qualifier ignored on asm",
35b1567d
BC
870 IDENTIFIER_POINTER (cv_qualifier));
871 cv_qualifier = NULL_TREE;
ad321293 872 }
35b1567d 873
abfc8a36 874 if (!processing_template_decl)
40b18c0a
MM
875 {
876 int i;
877 int ninputs;
878 int noutputs;
879
880 for (t = input_operands; t; t = TREE_CHAIN (t))
881 {
882 tree converted_operand
883 = decay_conversion (TREE_VALUE (t));
884
885 /* If the type of the operand hasn't been determined (e.g.,
886 because it involves an overloaded function), then issue
887 an error message. There's no context available to
888 resolve the overloading. */
889 if (TREE_TYPE (converted_operand) == unknown_type_node)
890 {
33bd39a2 891 error ("type of asm operand `%E' could not be determined",
40b18c0a
MM
892 TREE_VALUE (t));
893 converted_operand = error_mark_node;
894 }
895 TREE_VALUE (t) = converted_operand;
896 }
897
898 ninputs = list_length (input_operands);
899 noutputs = list_length (output_operands);
900
901 for (i = 0, t = output_operands; t; t = TREE_CHAIN (t), ++i)
902 {
903 bool allows_mem;
904 bool allows_reg;
905 bool is_inout;
906 const char *constraint;
907 tree operand;
908
84b72302 909 constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t)));
40b18c0a
MM
910 operand = TREE_VALUE (output_operands);
911
912 if (!parse_output_constraint (&constraint,
913 i, ninputs, noutputs,
914 &allows_mem,
915 &allows_reg,
916 &is_inout))
917 {
918 /* By marking the type as erroneous, we will not try to
919 process this operand again in expand_asm_operands. */
920 TREE_TYPE (operand) = error_mark_node;
921 continue;
922 }
923
924 /* If the operand is a DECL that is going to end up in
925 memory, assume it is addressable. This is a bit more
926 conservative than it would ideally be; the exact test is
927 buried deep in expand_asm_operands and depends on the
928 DECL_RTL for the OPERAND -- which we don't have at this
929 point. */
930 if (!allows_reg && DECL_P (operand))
dffd7eb6 931 cxx_mark_addressable (operand);
40b18c0a
MM
932 }
933 }
abfc8a36 934
0dfdeca6
BC
935 r = build_stmt (ASM_STMT, cv_qualifier, string,
936 output_operands, input_operands,
937 clobbers);
3e4d04a1 938 return add_stmt (r);
ad321293 939}
b4c4a9ec 940
f01b0acb
MM
941/* Finish a label with the indicated NAME. */
942
943void
944finish_label_stmt (name)
945 tree name;
946{
3fa56191 947 tree decl = define_label (input_filename, lineno, name);
ae499cce 948 add_stmt (build_stmt (LABEL_STMT, decl));
f01b0acb
MM
949}
950
acef433b
MM
951/* Finish a series of declarations for local labels. G++ allows users
952 to declare "local" labels, i.e., labels with scope. This extension
953 is useful when writing code involving statement-expressions. */
954
955void
956finish_label_decl (name)
957 tree name;
958{
959 tree decl = declare_local_label (name);
35b1567d 960 add_decl_stmt (decl);
acef433b
MM
961}
962
659e5a7a 963/* When DECL goes out of scope, make sure that CLEANUP is executed. */
f1dedc31
MM
964
965void
659e5a7a
JM
966finish_decl_cleanup (decl, cleanup)
967 tree decl;
f1dedc31
MM
968 tree cleanup;
969{
659e5a7a 970 add_stmt (build_stmt (CLEANUP_STMT, decl, cleanup));
35b1567d
BC
971}
972
659e5a7a 973/* If the current scope exits with an exception, run CLEANUP. */
24bef158 974
659e5a7a
JM
975void
976finish_eh_cleanup (cleanup)
24bef158
MM
977 tree cleanup;
978{
659e5a7a
JM
979 tree r = build_stmt (CLEANUP_STMT, NULL_TREE, cleanup);
980 CLEANUP_EH_ONLY (r) = 1;
981 add_stmt (r);
35b1567d
BC
982}
983
984/* Generate the RTL for a RETURN_INIT. */
985
54f7877c 986static void
44835fdd 987genrtl_named_return_value ()
35b1567d 988{
156ce211 989 tree decl = DECL_RESULT (current_function_decl);
35b1567d 990
44835fdd
MM
991 /* If this named return value comes in a register, put it in a
992 pseudo-register. */
993 if (DECL_REGISTER (decl))
35b1567d 994 {
44835fdd
MM
995 /* Note that the mode of the old DECL_RTL may be wider than the
996 mode of DECL_RESULT, depending on the calling conventions for
997 the processor. For example, on the Alpha, a 32-bit integer
998 is returned in a DImode register -- the DECL_RESULT has
999 SImode but the DECL_RTL for the DECL_RESULT has DImode. So,
1000 here, we use the mode the back-end has already assigned for
1001 the return value. */
19e7881c 1002 SET_DECL_RTL (decl, gen_reg_rtx (GET_MODE (DECL_RTL (decl))));
44835fdd
MM
1003 if (TREE_ADDRESSABLE (decl))
1004 put_var_into_stack (decl);
35b1567d 1005 }
156ce211
RH
1006
1007 emit_local_var (decl);
24bef158
MM
1008}
1009
558475f0
MM
1010/* Bind a name and initialization to the return value of
1011 the current function. */
1012
1013void
1014finish_named_return_value (return_id, init)
1015 tree return_id, init;
1016{
1017 tree decl = DECL_RESULT (current_function_decl);
1018
44835fdd
MM
1019 /* Give this error as many times as there are occurrences, so that
1020 users can use Emacs compilation buffers to find and fix all such
1021 places. */
558475f0 1022 if (pedantic)
cab1f180 1023 pedwarn ("ISO C++ does not permit named return values");
44835fdd 1024 cp_deprecated ("the named return value extension");
558475f0
MM
1025
1026 if (return_id != NULL_TREE)
1027 {
1028 if (DECL_NAME (decl) == NULL_TREE)
92643fea 1029 DECL_NAME (decl) = return_id;
558475f0
MM
1030 else
1031 {
33bd39a2 1032 error ("return identifier `%D' already in place", return_id);
558475f0
MM
1033 return;
1034 }
1035 }
1036
1037 /* Can't let this happen for constructors. */
1038 if (DECL_CONSTRUCTOR_P (current_function_decl))
1039 {
1040 error ("can't redefine default return value for constructors");
1041 return;
1042 }
1043
1044 /* If we have a named return value, put that in our scope as well. */
1045 if (DECL_NAME (decl) != NULL_TREE)
1046 {
1047 /* Let `cp_finish_decl' know that this initializer is ok. */
1048 DECL_INITIAL (decl) = init;
b35d4555
MM
1049 if (doing_semantic_analysis_p ())
1050 pushdecl (decl);
44835fdd
MM
1051 if (!processing_template_decl)
1052 {
1053 cp_finish_decl (decl, init, NULL_TREE, 0);
ae499cce 1054 add_stmt (build_stmt (RETURN_INIT, NULL_TREE, NULL_TREE));
44835fdd
MM
1055 }
1056 else
ae499cce 1057 add_stmt (build_stmt (RETURN_INIT, return_id, init));
558475f0 1058 }
f0ad3f46
MM
1059
1060 /* Don't use tree-inlining for functions with named return values.
1061 That doesn't work properly because we don't do any translation of
1062 the RETURN_INITs when they are copied. */
1063 DECL_UNINLINABLE (current_function_decl) = 1;
558475f0
MM
1064}
1065
da15dae6
MM
1066/* Begin processing a mem-initializer-list. */
1067
1068void
1069begin_mem_initializers ()
1070{
1071 if (! DECL_CONSTRUCTOR_P (current_function_decl))
1072 error ("only constructors take base initializers");
1073}
1074
bf3428d0
MM
1075/* The INIT_LIST is a list of mem-initializers, in the order they were
1076 written by the user. The TREE_VALUE of each node is a list of
1077 initializers for a particular subobject. The TREE_PURPOSE is a
1078 FIELD_DECL is the initializer is for a non-static data member, and
1079 a class type if the initializer is for a base class. */
1080
1081void
1082finish_mem_initializers (init_list)
1083 tree init_list;
1084{
1085 tree member_init_list;
1086 tree base_init_list;
1087 tree last_base_warned_about;
1088 tree next;
1089 tree init;
1090
1091 member_init_list = NULL_TREE;
1092 base_init_list = NULL_TREE;
1093 last_base_warned_about = NULL_TREE;
1094
1095 for (init = init_list; init; init = next)
1096 {
1097 next = TREE_CHAIN (init);
1098 if (TREE_CODE (TREE_PURPOSE (init)) == FIELD_DECL)
1099 {
1100 TREE_CHAIN (init) = member_init_list;
1101 member_init_list = init;
1102
1103 /* We're running through the initializers from right to left
1104 as we process them here. So, if we see a data member
1105 initializer after we see a base initializer, that
aba649ba 1106 actually means that the base initializer preceded the
bf3428d0
MM
1107 data member initializer. */
1108 if (warn_reorder && last_base_warned_about != base_init_list)
1109 {
1110 tree base;
1111
1112 for (base = base_init_list;
1113 base != last_base_warned_about;
1114 base = TREE_CHAIN (base))
1115 {
33bd39a2 1116 warning ("base initializer for `%T'",
bf3428d0
MM
1117 TREE_PURPOSE (base));
1118 warning (" will be re-ordered to precede member initializations");
1119 }
1120
1121 last_base_warned_about = base_init_list;
1122 }
1123 }
1124 else
1125 {
1126 TREE_CHAIN (init) = base_init_list;
1127 base_init_list = init;
1128 }
1129 }
1130
a0de9d20
JM
1131 if (processing_template_decl)
1132 add_stmt (build_min_nt (CTOR_INITIALIZER,
1133 member_init_list, base_init_list));
cdd2559c
JM
1134 else
1135 emit_base_init (member_init_list, base_init_list);
558475f0
MM
1136}
1137
8f17b5c5 1138/* Returns the stack of SCOPE_STMTs for the current function. */
35b1567d 1139
8f17b5c5
MM
1140tree *
1141current_scope_stmt_stack ()
8f471b0d 1142{
e2500fed 1143 return &cfun->language->base.x_scope_stmt_stack;
8f471b0d
MM
1144}
1145
b4c4a9ec
MM
1146/* Finish a parenthesized expression EXPR. */
1147
1148tree
1149finish_parenthesized_expr (expr)
1150 tree expr;
1151{
1152 if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (TREE_CODE (expr))))
78ef5b89 1153 /* This inhibits warnings in c_common_truthvalue_conversion. */
b4c4a9ec
MM
1154 C_SET_EXP_ORIGINAL_CODE (expr, ERROR_MARK);
1155
19420d00
NS
1156 if (TREE_CODE (expr) == OFFSET_REF)
1157 /* [expr.unary.op]/3 The qualified id of a pointer-to-member must not be
1158 enclosed in parentheses. */
1159 PTRMEM_OK_P (expr) = 0;
b4c4a9ec
MM
1160 return expr;
1161}
1162
b69b1501
MM
1163/* Begin a statement-expression. The value returned must be passed to
1164 finish_stmt_expr. */
b4c4a9ec
MM
1165
1166tree
1167begin_stmt_expr ()
1168{
6f80451c
MM
1169 /* If we're outside a function, we won't have a statement-tree to
1170 work with. But, if we see a statement-expression we need to
1171 create one. */
01d939e8 1172 if (! cfun && !last_tree)
6f80451c
MM
1173 begin_stmt_tree (&scope_chain->x_saved_tree);
1174
f1dedc31 1175 keep_next_level (1);
558475f0 1176 /* If we're building a statement tree, then the upcoming compound
b69b1501
MM
1177 statement will be chained onto the tree structure, starting at
1178 last_tree. We return last_tree so that we can later unhook the
1179 compound statement. */
35b1567d
BC
1180 return last_tree;
1181}
1182
596fd31c
MM
1183/* Used when beginning a statement-expression outside function scope.
1184 For example, when handling a file-scope initializer, we use this
1185 function. */
35b1567d 1186
596fd31c
MM
1187tree
1188begin_global_stmt_expr ()
35b1567d 1189{
596fd31c
MM
1190 if (! cfun && !last_tree)
1191 begin_stmt_tree (&scope_chain->x_saved_tree);
35b1567d 1192
596fd31c
MM
1193 keep_next_level (1);
1194
b2123dc0 1195 return last_tree ? last_tree : expand_start_stmt_expr(/*has_scope=*/1);
596fd31c
MM
1196}
1197
1198/* Finish the STMT_EXPR last begun with begin_global_stmt_expr. */
1199
1200tree
1201finish_global_stmt_expr (stmt_expr)
1202 tree stmt_expr;
1203{
1204 stmt_expr = expand_end_stmt_expr (stmt_expr);
35b1567d
BC
1205
1206 if (! cfun
1207 && TREE_CHAIN (scope_chain->x_saved_tree) == NULL_TREE)
1208 finish_stmt_tree (&scope_chain->x_saved_tree);
1209
596fd31c 1210 return stmt_expr;
b4c4a9ec
MM
1211}
1212
1213/* Finish a statement-expression. RTL_EXPR should be the value
1214 returned by the previous begin_stmt_expr; EXPR is the
1215 statement-expression. Returns an expression representing the
1216 statement-expression. */
1217
1218tree
5ba57b55 1219finish_stmt_expr (rtl_expr)
b4c4a9ec 1220 tree rtl_expr;
b4c4a9ec
MM
1221{
1222 tree result;
1223
35b1567d
BC
1224 /* If the last thing in the statement-expression was not an
1225 expression-statement, then it has type `void'. */
1226 if (!last_expr_type)
1227 last_expr_type = void_type_node;
1228 result = build_min (STMT_EXPR, last_expr_type, last_tree);
1229 TREE_SIDE_EFFECTS (result) = 1;
1230
1231 /* Remove the compound statement from the tree structure; it is
1232 now saved in the STMT_EXPR. */
ae499cce 1233 last_tree = rtl_expr;
35b1567d 1234 TREE_CHAIN (last_tree) = NULL_TREE;
f1dedc31 1235
6f80451c
MM
1236 /* If we created a statement-tree for this statement-expression,
1237 remove it now. */
01d939e8 1238 if (! cfun
6f80451c
MM
1239 && TREE_CHAIN (scope_chain->x_saved_tree) == NULL_TREE)
1240 finish_stmt_tree (&scope_chain->x_saved_tree);
1241
b4c4a9ec
MM
1242 return result;
1243}
1244
4ba126e4
MM
1245/* Generate an expression for `FN (ARGS)'.
1246
1247 If DISALLOW_VIRTUAL is true, the call to FN will be not generated
1248 as a virtual call, even if FN is virtual. (This flag is set when
1249 encountering an expression where the function name is explicitly
1250 qualified. For example a call to `X::f' never generates a virtual
1251 call.)
1252
1253 Returns code for the call. */
b4c4a9ec
MM
1254
1255tree
4ba126e4 1256finish_call_expr (tree fn, tree args, bool disallow_virtual)
b4c4a9ec 1257{
4ba126e4
MM
1258 if (fn == error_mark_node || args == error_mark_node)
1259 return error_mark_node;
1260
1261 if (processing_template_decl)
1262 return build_nt (CALL_EXPR, fn, args, NULL_TREE);
1263
1264 /* ARGS should be a list of arguments. */
1265 my_friendly_assert (!args || TREE_CODE (args) == TREE_LIST,
1266 20020712);
a759e627 1267
4ba126e4 1268 if (BASELINK_P (fn))
03d82991 1269 {
4ba126e4
MM
1270 tree object;
1271
1272 /* A call to a member function. From [over.call.func]:
1273
1274 If the keyword this is in scope and refers to the class of
1275 that member function, or a derived class thereof, then the
1276 function call is transformed into a qualified function call
1277 using (*this) as the postfix-expression to the left of the
1278 . operator.... [Otherwise] a contrived object of type T
1279 becomes the implied object argument.
1280
1281 This paragraph is unclear about this situation:
1282
1283 struct A { void f(); };
1284 struct B : public A {};
1285 struct C : public A { void g() { B::f(); }};
1286
1287 In particular, for `B::f', this paragraph does not make clear
1288 whether "the class of that member function" refers to `A' or
1289 to `B'. We believe it refers to `B'. */
1290 if (current_class_type
1291 && DERIVED_FROM_P (BINFO_TYPE (BASELINK_ACCESS_BINFO (fn)),
1292 current_class_type)
1293 && current_class_ref)
1294 object = current_class_ref;
1295 else
1296 {
1297 tree representative_fn;
b4c4a9ec 1298
4ba126e4
MM
1299 representative_fn = BASELINK_FUNCTIONS (fn);
1300 if (TREE_CODE (representative_fn) == TEMPLATE_ID_EXPR)
1301 representative_fn = TREE_OPERAND (representative_fn, 0);
1302 representative_fn = get_first_fn (representative_fn);
1303 object = build_dummy_object (DECL_CONTEXT (representative_fn));
1304 }
b4c4a9ec 1305
4ba126e4
MM
1306 return build_new_method_call (object, fn, args, NULL_TREE,
1307 (disallow_virtual
1308 ? LOOKUP_NONVIRTUAL : 0));
1309 }
1310 else if (is_overloaded_fn (fn))
1311 /* A call to a namespace-scope function. */
1312 return build_new_function_call (fn, args);
1313 else if (CLASS_TYPE_P (TREE_TYPE (fn)))
1314 {
1315 /* If the "function" is really an object of class type, it might
1316 have an overloaded `operator ()'. */
1317 tree result;
1318 result = build_opfncall (CALL_EXPR, LOOKUP_NORMAL, fn, args, NULL_TREE);
1319 if (result)
1320 return result;
1321 }
1322
1323 /* A call where the function is unknown. */
1324 return build_function_call (fn, args);
b4c4a9ec
MM
1325}
1326
1327/* Finish a call to a postfix increment or decrement or EXPR. (Which
1328 is indicated by CODE, which should be POSTINCREMENT_EXPR or
1329 POSTDECREMENT_EXPR.) */
1330
1331tree
1332finish_increment_expr (expr, code)
1333 tree expr;
1334 enum tree_code code;
1335{
1336 /* If we get an OFFSET_REF, turn it into what it really means (e.g.,
1337 a COMPONENT_REF). This way if we've got, say, a reference to a
1338 static member that's being operated on, we don't end up trying to
1339 find a member operator for the class it's in. */
1340
1341 if (TREE_CODE (expr) == OFFSET_REF)
1342 expr = resolve_offset_ref (expr);
1343 return build_x_unary_op (code, expr);
1344}
1345
1346/* Finish a use of `this'. Returns an expression for `this'. */
1347
1348tree
1349finish_this_expr ()
1350{
1351 tree result;
1352
1353 if (current_class_ptr)
1354 {
b4c4a9ec
MM
1355 result = current_class_ptr;
1356 }
1357 else if (current_function_decl
1358 && DECL_STATIC_FUNCTION_P (current_function_decl))
1359 {
8251199e 1360 error ("`this' is unavailable for static member functions");
b4c4a9ec
MM
1361 result = error_mark_node;
1362 }
1363 else
1364 {
1365 if (current_function_decl)
8251199e 1366 error ("invalid use of `this' in non-member function");
b4c4a9ec 1367 else
8251199e 1368 error ("invalid use of `this' at top level");
b4c4a9ec
MM
1369 result = error_mark_node;
1370 }
1371
1372 return result;
1373}
1374
1375/* Finish a member function call using OBJECT and ARGS as arguments to
1376 FN. Returns an expression for the call. */
1377
1378tree
1379finish_object_call_expr (fn, object, args)
1380 tree fn;
1381 tree object;
1382 tree args;
1383{
c219b878 1384 if (DECL_DECLARES_TYPE_P (fn))
c68c56f7
MM
1385 {
1386 if (processing_template_decl)
1387 /* This can happen on code like:
1388
1389 class X;
1390 template <class T> void f(T t) {
1391 t.X();
1392 }
1393
1394 We just grab the underlying IDENTIFIER. */
1395 fn = DECL_NAME (fn);
1396 else
1397 {
33bd39a2 1398 error ("calling type `%T' like a method", fn);
c68c56f7
MM
1399 return error_mark_node;
1400 }
1401 }
4ba126e4 1402
50ad9642
MM
1403 if (name_p (fn))
1404 return build_method_call (object, fn, args, NULL_TREE, LOOKUP_NORMAL);
1405 else
1406 return build_new_method_call (object, fn, args, NULL_TREE, LOOKUP_NORMAL);
b4c4a9ec
MM
1407}
1408
1409/* Finish a qualified member function call using OBJECT and ARGS as
509fc277 1410 arguments to FN. Returns an expression for the call. */
b4c4a9ec
MM
1411
1412tree
1413finish_qualified_object_call_expr (fn, object, args)
1414 tree fn;
1415 tree object;
1416 tree args;
1417{
6eabb241
MM
1418 return build_scoped_method_call (object, TREE_OPERAND (fn, 0),
1419 TREE_OPERAND (fn, 1), args);
b4c4a9ec
MM
1420}
1421
1422/* Finish a pseudo-destructor call expression of OBJECT, with SCOPE
1423 being the scope, if any, of DESTRUCTOR. Returns an expression for
1424 the call. */
1425
1426tree
1427finish_pseudo_destructor_call_expr (object, scope, destructor)
1428 tree object;
1429 tree scope;
1430 tree destructor;
1431{
40242ccf
MM
1432 if (processing_template_decl)
1433 return build_min_nt (PSEUDO_DTOR_EXPR, object, scope, destructor);
1434
b4c4a9ec 1435 if (scope && scope != destructor)
33bd39a2 1436 error ("destructor specifier `%T::~%T()' must have matching names",
b4c4a9ec
MM
1437 scope, destructor);
1438
1439 if ((scope == NULL_TREE || IDENTIFIER_GLOBAL_VALUE (destructor))
1440 && (TREE_CODE (TREE_TYPE (object)) !=
1441 TREE_CODE (TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (destructor)))))
33bd39a2 1442 error ("`%E' is not of type `%T'", object, destructor);
b4c4a9ec
MM
1443
1444 return cp_convert (void_type_node, object);
1445}
1446
ce4a0391
MM
1447/* Finish an expression of the form CODE EXPR. */
1448
1449tree
1450finish_unary_op_expr (code, expr)
1451 enum tree_code code;
1452 tree expr;
1453{
1454 tree result = build_x_unary_op (code, expr);
7c355bca
ML
1455 /* Inside a template, build_x_unary_op does not fold the
1456 expression. So check whether the result is folded before
1457 setting TREE_NEGATED_INT. */
1458 if (code == NEGATE_EXPR && TREE_CODE (expr) == INTEGER_CST
88b4335f
NS
1459 && TREE_CODE (result) == INTEGER_CST
1460 && !TREE_UNSIGNED (TREE_TYPE (result))
1461 && INT_CST_LT (result, integer_zero_node))
ce4a0391
MM
1462 TREE_NEGATED_INT (result) = 1;
1463 overflow_warning (result);
1464 return result;
1465}
1466
1467/* Finish an id-expression. */
1468
1469tree
1470finish_id_expr (expr)
1471 tree expr;
1472{
1473 if (TREE_CODE (expr) == IDENTIFIER_NODE)
a759e627 1474 expr = do_identifier (expr, 1, NULL_TREE);
ce4a0391 1475
3d7e9ba4
NS
1476 if (TREE_TYPE (expr) == error_mark_node)
1477 expr = error_mark_node;
ce4a0391
MM
1478 return expr;
1479}
1480
5f261ba9
MM
1481/* Return the declaration for the function-name variable indicated by
1482 ID. */
1483
1484tree
1485finish_fname (tree id)
1486{
1487 tree decl;
1488
1489 decl = fname_decl (C_RID_CODE (id), id);
1490 if (processing_template_decl)
1491 decl = build_min_nt (LOOKUP_EXPR, DECL_NAME (decl));
1492 return decl;
1493}
1494
70adf8a9
JM
1495static tree current_type_lookups;
1496
1497/* Perform deferred access control for types used in the type of a
1498 declaration. */
1499
1f51a992 1500static void
70adf8a9
JM
1501deferred_type_access_control ()
1502{
1f51a992 1503 tree lookup = type_lookups;
70adf8a9
JM
1504
1505 if (lookup == error_mark_node)
1506 return;
1507
1508 for (; lookup; lookup = TREE_CHAIN (lookup))
1509 enforce_access (TREE_PURPOSE (lookup), TREE_VALUE (lookup));
1510}
1511
70adf8a9 1512void
1f51a992
JM
1513decl_type_access_control (decl)
1514 tree decl;
70adf8a9 1515{
1f51a992 1516 tree save_fn;
70adf8a9 1517
1f51a992
JM
1518 if (type_lookups == error_mark_node)
1519 return;
1520
1521 save_fn = current_function_decl;
1522
1523 if (decl && TREE_CODE (decl) == FUNCTION_DECL)
1524 current_function_decl = decl;
70adf8a9 1525
70adf8a9 1526 deferred_type_access_control ();
1f51a992
JM
1527
1528 current_function_decl = save_fn;
1529
1530 /* Now strip away the checks for the current declarator; they were
1531 added to type_lookups after typed_declspecs saved the copy that
1532 ended up in current_type_lookups. */
1533 type_lookups = current_type_lookups;
1534}
1535
1536void
1537save_type_access_control (lookups)
1538 tree lookups;
1539{
ab04e34b 1540 current_type_lookups = lookups;
788bf0e3
NS
1541}
1542
1543/* Reset the deferred access control. */
1544
1545void
1546reset_type_access_control ()
1547{
1548 type_lookups = NULL_TREE;
1549 current_type_lookups = NULL_TREE;
1f51a992 1550}
70adf8a9 1551
15c7fb9c
MM
1552/* Begin a function definition declared with DECL_SPECS, ATTRIBUTES,
1553 and DECLARATOR. Returns non-zero if the function-declaration is
b4c4a9ec
MM
1554 legal. */
1555
1556int
15c7fb9c 1557begin_function_definition (decl_specs, attributes, declarator)
b4c4a9ec 1558 tree decl_specs;
15c7fb9c 1559 tree attributes;
b4c4a9ec
MM
1560 tree declarator;
1561{
15c7fb9c 1562 if (!start_function (decl_specs, declarator, attributes, SF_DEFAULT))
b4c4a9ec 1563 return 0;
1f51a992
JM
1564
1565 deferred_type_access_control ();
1566 type_lookups = error_mark_node;
1567
39c01e4c
MM
1568 /* The things we're about to see are not directly qualified by any
1569 template headers we've seen thus far. */
1570 reset_specialization ();
1571
b4c4a9ec
MM
1572 return 1;
1573}
1574
1575/* Begin a constructor declarator of the form `SCOPE::NAME'. Returns
1576 a SCOPE_REF. */
1577
1578tree
1579begin_constructor_declarator (scope, name)
1580 tree scope;
1581 tree name;
1582{
718b8ea5 1583 tree result = build_nt (SCOPE_REF, scope, name);
830fcda8 1584 enter_scope_of (result);
b4c4a9ec
MM
1585 return result;
1586}
1587
ce4a0391
MM
1588/* Finish an init-declarator. Returns a DECL. */
1589
1590tree
1591finish_declarator (declarator, declspecs, attributes,
1592 prefix_attributes, initialized)
1593 tree declarator;
1594 tree declspecs;
1595 tree attributes;
1596 tree prefix_attributes;
1597 int initialized;
1598{
1599 return start_decl (declarator, declspecs, initialized, attributes,
1600 prefix_attributes);
1601}
1602
8014a339 1603/* Finish a translation unit. */
ce4a0391
MM
1604
1605void
1606finish_translation_unit ()
1607{
1608 /* In case there were missing closebraces,
1609 get us back to the global binding level. */
273a708f 1610 pop_everything ();
ce4a0391
MM
1611 while (current_namespace != global_namespace)
1612 pop_namespace ();
0ba8a114
NS
1613
1614 /* Do file scope __FUNCTION__ et al. */
1615 finish_fname_decls ();
1616
ce4a0391
MM
1617 finish_file ();
1618}
1619
b4c4a9ec
MM
1620/* Finish a template type parameter, specified as AGGR IDENTIFIER.
1621 Returns the parameter. */
1622
1623tree
1624finish_template_type_parm (aggr, identifier)
1625 tree aggr;
1626 tree identifier;
1627{
6eabb241 1628 if (aggr != class_type_node)
b4c4a9ec 1629 {
8251199e 1630 pedwarn ("template type parameters must use the keyword `class' or `typename'");
b4c4a9ec
MM
1631 aggr = class_type_node;
1632 }
1633
1634 return build_tree_list (aggr, identifier);
1635}
1636
1637/* Finish a template template parameter, specified as AGGR IDENTIFIER.
1638 Returns the parameter. */
1639
1640tree
1641finish_template_template_parm (aggr, identifier)
1642 tree aggr;
1643 tree identifier;
1644{
1645 tree decl = build_decl (TYPE_DECL, identifier, NULL_TREE);
1646 tree tmpl = build_lang_decl (TEMPLATE_DECL, identifier, NULL_TREE);
1647 DECL_TEMPLATE_PARMS (tmpl) = current_template_parms;
1648 DECL_TEMPLATE_RESULT (tmpl) = decl;
c727aa5e 1649 DECL_ARTIFICIAL (decl) = 1;
b4c4a9ec
MM
1650 end_template_decl ();
1651
b37bf5bd
NS
1652 my_friendly_assert (DECL_TEMPLATE_PARMS (tmpl), 20010110);
1653
b4c4a9ec
MM
1654 return finish_template_type_parm (aggr, tmpl);
1655}
ce4a0391 1656
8ba658ee
MM
1657/* ARGUMENT is the default-argument value for a template template
1658 parameter. If ARGUMENT is invalid, issue error messages and return
1659 the ERROR_MARK_NODE. Otherwise, ARGUMENT itself is returned. */
1660
1661tree
1662check_template_template_default_arg (tree argument)
1663{
1664 if (TREE_CODE (argument) != TEMPLATE_DECL
1665 && TREE_CODE (argument) != TEMPLATE_TEMPLATE_PARM
1666 && TREE_CODE (argument) != TYPE_DECL
1667 && TREE_CODE (argument) != UNBOUND_CLASS_TEMPLATE)
1668 {
1669 error ("invalid default template argument");
1670 return error_mark_node;
1671 }
1672
1673 return argument;
1674}
1675
ce4a0391
MM
1676/* Finish a parameter list, indicated by PARMS. If ELLIPSIS is
1677 non-zero, the parameter list was terminated by a `...'. */
1678
1679tree
1680finish_parmlist (parms, ellipsis)
1681 tree parms;
1682 int ellipsis;
1683{
5cce22b6
NS
1684 if (parms)
1685 {
1686 /* We mark the PARMS as a parmlist so that declarator processing can
1687 disambiguate certain constructs. */
1688 TREE_PARMLIST (parms) = 1;
1689 /* We do not append void_list_node here, but leave it to grokparms
1690 to do that. */
1691 PARMLIST_ELLIPSIS_P (parms) = ellipsis;
1692 }
ce4a0391
MM
1693 return parms;
1694}
1695
1696/* Begin a class definition, as indicated by T. */
1697
1698tree
1699begin_class_definition (t)
1700 tree t;
1701{
7437519c
ZW
1702 if (t == error_mark_node)
1703 return error_mark_node;
1704
788bf0e3
NS
1705 /* Check the bases are accessible. */
1706 decl_type_access_control (TYPE_NAME (t));
1707 reset_type_access_control ();
1708
522d6614
NS
1709 if (processing_template_parmlist)
1710 {
33bd39a2 1711 error ("definition of `%#T' inside template parameter list", t);
522d6614
NS
1712 return error_mark_node;
1713 }
47ee8904
MM
1714
1715 /* In a definition of a member class template, we will get here with
1716 an implicit typename. */
1717 if (IMPLICIT_TYPENAME_P (t))
1718 t = TREE_TYPE (t);
1719 /* A non-implicit typename comes from code like:
1720
1721 template <typename T> struct A {
1722 template <typename U> struct A<T>::B ...
1723
1724 This is erroneous. */
1725 else if (TREE_CODE (t) == TYPENAME_TYPE)
1726 {
33bd39a2 1727 error ("invalid definition of qualified type `%T'", t);
47ee8904
MM
1728 t = error_mark_node;
1729 }
1730
1731 if (t == error_mark_node || ! IS_AGGR_TYPE (t))
ce4a0391 1732 {
33848bb0 1733 t = make_aggr_type (RECORD_TYPE);
ce4a0391
MM
1734 pushtag (make_anon_name (), t, 0);
1735 }
830fcda8 1736
4c571114
MM
1737 /* If we generated a partial instantiation of this type, but now
1738 we're seeing a real definition, we're actually looking at a
1739 partial specialization. Consider:
1740
1741 template <class T, class U>
1742 struct Y {};
1743
1744 template <class T>
1745 struct X {};
1746
1747 template <class T, class U>
1748 void f()
1749 {
1750 typename X<Y<T, U> >::A a;
1751 }
1752
1753 template <class T, class U>
1754 struct X<Y<T, U> >
1755 {
1756 };
1757
1758 We have to undo the effects of the previous partial
1759 instantiation. */
1760 if (PARTIAL_INSTANTIATION_P (t))
1761 {
1762 if (!pedantic)
1763 {
1764 /* Unfortunately, when we're not in pedantic mode, we
1765 attempt to actually fill in some of the fields of the
1766 partial instantiation, in order to support the implicit
1767 typename extension. Clear those fields now, in
1768 preparation for the definition here. The fields cleared
1769 here must match those set in instantiate_class_template.
1770 Look for a comment mentioning begin_class_definition
1771 there. */
1772 TYPE_BINFO_BASETYPES (t) = NULL_TREE;
1773 TYPE_FIELDS (t) = NULL_TREE;
1774 TYPE_METHODS (t) = NULL_TREE;
1775 CLASSTYPE_TAGS (t) = NULL_TREE;
1ddd4323 1776 CLASSTYPE_VBASECLASSES (t) = NULL_TREE;
4c571114
MM
1777 TYPE_SIZE (t) = NULL_TREE;
1778 }
830fcda8 1779
4c571114
MM
1780 /* This isn't a partial instantiation any more. */
1781 PARTIAL_INSTANTIATION_P (t) = 0;
1782 }
1783 /* If this type was already complete, and we see another definition,
1784 that's an error. */
d0f062fb 1785 else if (COMPLETE_TYPE_P (t))
ce4a0391 1786 duplicate_tag_error (t);
4c571114 1787
b4f70b3d
NS
1788 /* Update the location of the decl. */
1789 DECL_SOURCE_FILE (TYPE_NAME (t)) = input_filename;
1790 DECL_SOURCE_LINE (TYPE_NAME (t)) = lineno;
1791
4c571114 1792 if (TYPE_BEING_DEFINED (t))
ce4a0391 1793 {
33848bb0 1794 t = make_aggr_type (TREE_CODE (t));
ce4a0391 1795 pushtag (TYPE_IDENTIFIER (t), t, 0);
ce4a0391 1796 }
ff350acd 1797 maybe_process_partial_specialization (t);
8f032717 1798 pushclass (t, 1);
ce4a0391 1799 TYPE_BEING_DEFINED (t) = 1;
55760a0c 1800 TYPE_PACKED (t) = flag_pack_struct;
ce4a0391
MM
1801 /* Reset the interface data, at the earliest possible
1802 moment, as it might have been set via a class foo;
1803 before. */
1951a1b6
JM
1804 if (! TYPE_ANONYMOUS_P (t))
1805 {
1806 CLASSTYPE_INTERFACE_ONLY (t) = interface_only;
1807 SET_CLASSTYPE_INTERFACE_UNKNOWN_X
1808 (t, interface_unknown);
1809 }
ce4a0391
MM
1810 reset_specialization();
1811
b7975aed
MM
1812 /* Make a declaration for this class in its own scope. */
1813 build_self_reference ();
1814
830fcda8 1815 return t;
ce4a0391
MM
1816}
1817
61a127b3
MM
1818/* Finish the member declaration given by DECL. */
1819
1820void
1821finish_member_declaration (decl)
1822 tree decl;
1823{
1824 if (decl == error_mark_node || decl == NULL_TREE)
1825 return;
1826
1827 if (decl == void_type_node)
1828 /* The COMPONENT was a friend, not a member, and so there's
1829 nothing for us to do. */
1830 return;
1831
1832 /* We should see only one DECL at a time. */
1833 my_friendly_assert (TREE_CHAIN (decl) == NULL_TREE, 0);
1834
1835 /* Set up access control for DECL. */
1836 TREE_PRIVATE (decl)
1837 = (current_access_specifier == access_private_node);
1838 TREE_PROTECTED (decl)
1839 = (current_access_specifier == access_protected_node);
1840 if (TREE_CODE (decl) == TEMPLATE_DECL)
1841 {
17aec3eb
RK
1842 TREE_PRIVATE (DECL_TEMPLATE_RESULT (decl)) = TREE_PRIVATE (decl);
1843 TREE_PROTECTED (DECL_TEMPLATE_RESULT (decl)) = TREE_PROTECTED (decl);
61a127b3
MM
1844 }
1845
1846 /* Mark the DECL as a member of the current class. */
4f1c5b7d 1847 DECL_CONTEXT (decl) = current_class_type;
61a127b3 1848
421844e7
MM
1849 /* [dcl.link]
1850
1851 A C language linkage is ignored for the names of class members
1852 and the member function type of class member functions. */
1853 if (DECL_LANG_SPECIFIC (decl) && DECL_LANGUAGE (decl) == lang_c)
5d2ed28c 1854 SET_DECL_LANGUAGE (decl, lang_cplusplus);
421844e7 1855
61a127b3
MM
1856 /* Put functions on the TYPE_METHODS list and everything else on the
1857 TYPE_FIELDS list. Note that these are built up in reverse order.
1858 We reverse them (to obtain declaration order) in finish_struct. */
1859 if (TREE_CODE (decl) == FUNCTION_DECL
1860 || DECL_FUNCTION_TEMPLATE_P (decl))
1861 {
1862 /* We also need to add this function to the
1863 CLASSTYPE_METHOD_VEC. */
452a394b 1864 add_method (current_class_type, decl, /*error_p=*/0);
61a127b3
MM
1865
1866 TREE_CHAIN (decl) = TYPE_METHODS (current_class_type);
1867 TYPE_METHODS (current_class_type) = decl;
1868 }
1869 else
1870 {
1871 /* All TYPE_DECLs go at the end of TYPE_FIELDS. Ordinary fields
1872 go at the beginning. The reason is that lookup_field_1
1873 searches the list in order, and we want a field name to
1874 override a type name so that the "struct stat hack" will
1875 work. In particular:
1876
1877 struct S { enum E { }; int E } s;
1878 s.E = 3;
1879
1880 is legal. In addition, the FIELD_DECLs must be maintained in
1881 declaration order so that class layout works as expected.
1882 However, we don't need that order until class layout, so we
1883 save a little time by putting FIELD_DECLs on in reverse order
1884 here, and then reversing them in finish_struct_1. (We could
1885 also keep a pointer to the correct insertion points in the
1886 list.) */
1887
1888 if (TREE_CODE (decl) == TYPE_DECL)
1889 TYPE_FIELDS (current_class_type)
1890 = chainon (TYPE_FIELDS (current_class_type), decl);
1891 else
1892 {
1893 TREE_CHAIN (decl) = TYPE_FIELDS (current_class_type);
1894 TYPE_FIELDS (current_class_type) = decl;
1895 }
8f032717
MM
1896
1897 /* Enter the DECL into the scope of the class. */
1898 if (TREE_CODE (decl) != USING_DECL)
1899 pushdecl_class_level (decl);
61a127b3
MM
1900 }
1901}
1902
1903/* Finish a class definition T with the indicate ATTRIBUTES. If SEMI,
1904 the definition is immediately followed by a semicolon. Returns the
1905 type. */
ce4a0391
MM
1906
1907tree
fbdd0024 1908finish_class_definition (t, attributes, semi, pop_scope_p)
ce4a0391 1909 tree t;
ce4a0391
MM
1910 tree attributes;
1911 int semi;
fbdd0024 1912 int pop_scope_p;
ce4a0391 1913{
7437519c
ZW
1914 if (t == error_mark_node)
1915 return error_mark_node;
1916
ce4a0391
MM
1917 /* finish_struct nukes this anyway; if finish_exception does too,
1918 then it can go. */
1919 if (semi)
1920 note_got_semicolon (t);
1921
dc8263bc
JM
1922 /* If we got any attributes in class_head, xref_tag will stick them in
1923 TREE_TYPE of the type. Grab them now. */
a588fe25
JM
1924 attributes = chainon (TYPE_ATTRIBUTES (t), attributes);
1925 TYPE_ATTRIBUTES (t) = NULL_TREE;
dc8263bc 1926
ce4a0391
MM
1927 if (TREE_CODE (t) == ENUMERAL_TYPE)
1928 ;
1929 else
1930 {
9f33663b 1931 t = finish_struct (t, attributes);
ce4a0391
MM
1932 if (semi)
1933 note_got_semicolon (t);
1934 }
1935
ce4a0391
MM
1936 if (! semi)
1937 check_for_missing_semicolon (t);
fbdd0024
MM
1938 if (pop_scope_p)
1939 pop_scope (CP_DECL_CONTEXT (TYPE_MAIN_DECL (t)));
ce4a0391
MM
1940 if (current_scope () == current_function_decl)
1941 do_pending_defargs ();
1942
1943 return t;
1944}
1945
1946/* Finish processing the default argument expressions cached during
1947 the processing of a class definition. */
1948
1949void
51632249 1950begin_inline_definitions ()
ce4a0391 1951{
0e5921e8 1952 if (current_scope () == current_function_decl)
ce4a0391
MM
1953 do_pending_inlines ();
1954}
1955
35acd3f2
MM
1956/* Finish processing the declaration of a member class template
1957 TYPES whose template parameters are given by PARMS. */
1958
1959tree
61a127b3 1960finish_member_class_template (types)
35acd3f2
MM
1961 tree types;
1962{
36a117a5
MM
1963 tree t;
1964
1965 /* If there are declared, but undefined, partial specializations
1966 mixed in with the typespecs they will not yet have passed through
1967 maybe_process_partial_specialization, so we do that here. */
1968 for (t = types; t != NULL_TREE; t = TREE_CHAIN (t))
1969 if (IS_AGGR_TYPE_CODE (TREE_CODE (TREE_VALUE (t))))
1970 maybe_process_partial_specialization (TREE_VALUE (t));
1971
35acd3f2 1972 note_list_got_semicolon (types);
61a127b3 1973 grok_x_components (types);
35acd3f2
MM
1974 if (TYPE_CONTEXT (TREE_VALUE (types)) != current_class_type)
1975 /* The component was in fact a friend declaration. We avoid
1976 finish_member_template_decl performing certain checks by
1977 unsetting TYPES. */
1978 types = NULL_TREE;
61a127b3
MM
1979
1980 finish_member_template_decl (types);
1981
35acd3f2
MM
1982 /* As with other component type declarations, we do
1983 not store the new DECL on the list of
1984 component_decls. */
1985 return NULL_TREE;
1986}
36a117a5 1987
306ef644 1988/* Finish processing a complete template declaration. The PARMS are
36a117a5
MM
1989 the template parameters. */
1990
1991void
1992finish_template_decl (parms)
1993 tree parms;
1994{
1995 if (parms)
1996 end_template_decl ();
1997 else
1998 end_specialization ();
1999}
2000
509fc277 2001/* Finish processing a template-id (which names a type) of the form
36a117a5
MM
2002 NAME < ARGS >. Return the TYPE_DECL for the type named by the
2003 template-id. If ENTERING_SCOPE is non-zero we are about to enter
2004 the scope of template-id indicated. */
2005
2006tree
2007finish_template_type (name, args, entering_scope)
2008 tree name;
2009 tree args;
2010 int entering_scope;
2011{
2012 tree decl;
2013
2014 decl = lookup_template_class (name, args,
f9c244b8
NS
2015 NULL_TREE, NULL_TREE,
2016 entering_scope, /*complain=*/1);
36a117a5
MM
2017 if (decl != error_mark_node)
2018 decl = TYPE_STUB_DECL (decl);
2019
2020 return decl;
2021}
648f19f6
MM
2022
2023/* SR is a SCOPE_REF node. Enter the scope of SR, whether it is a
2024 namespace scope or a class scope. */
2025
2026void
2027enter_scope_of (sr)
2028 tree sr;
2029{
2030 tree scope = TREE_OPERAND (sr, 0);
2031
2032 if (TREE_CODE (scope) == NAMESPACE_DECL)
2033 {
2034 push_decl_namespace (scope);
2035 TREE_COMPLEXITY (sr) = -1;
2036 }
2037 else if (scope != current_class_type)
2038 {
830fcda8
JM
2039 if (TREE_CODE (scope) == TYPENAME_TYPE)
2040 {
2041 /* In a declarator for a template class member, the scope will
2042 get here as an implicit typename, a TYPENAME_TYPE with a type. */
2043 scope = TREE_TYPE (scope);
2044 TREE_OPERAND (sr, 0) = scope;
2045 }
648f19f6
MM
2046 push_nested_class (scope, 3);
2047 TREE_COMPLEXITY (sr) = current_class_depth;
2048 }
2049}
ea6021e8
MM
2050
2051/* Finish processing a BASE_CLASS with the indicated ACCESS_SPECIFIER.
2052 Return a TREE_LIST containing the ACCESS_SPECIFIER and the
2053 BASE_CLASS, or NULL_TREE if an error occurred. The
aba649ba 2054 ACCESS_SPECIFIER is one of
ea6021e8
MM
2055 access_{default,public,protected_private}[_virtual]_node.*/
2056
2057tree
6eabb241 2058finish_base_specifier (access_specifier, base_class)
ea6021e8
MM
2059 tree access_specifier;
2060 tree base_class;
ea6021e8 2061{
ea6021e8
MM
2062 tree result;
2063
acb044ee
GDR
2064 if (base_class == error_mark_node)
2065 {
2066 error ("invalid base-class specification");
2067 result = NULL_TREE;
2068 }
2069 else if (! is_aggr_type (base_class, 1))
ea6021e8 2070 result = NULL_TREE;
ea6021e8 2071 else
bb92901d 2072 {
89d684bb 2073 if (cp_type_quals (base_class) != 0)
bb92901d 2074 {
33bd39a2 2075 error ("base class `%T' has cv qualifiers", base_class);
bb92901d
NS
2076 base_class = TYPE_MAIN_VARIANT (base_class);
2077 }
2078 result = build_tree_list (access_specifier, base_class);
2079 }
ea6021e8
MM
2080
2081 return result;
2082}
61a127b3
MM
2083
2084/* Called when multiple declarators are processed. If that is not
2085 premitted in this context, an error is issued. */
2086
2087void
2088check_multiple_declarators ()
2089{
2090 /* [temp]
2091
2092 In a template-declaration, explicit specialization, or explicit
2093 instantiation the init-declarator-list in the declaration shall
2094 contain at most one declarator.
2095
2096 We don't just use PROCESSING_TEMPLATE_DECL for the first
2097 condition since that would disallow the perfectly legal code,
2098 like `template <class T> struct S { int i, j; };'. */
5f261ba9 2099 if (at_function_scope_p ())
61a127b3
MM
2100 /* It's OK to write `template <class T> void f() { int i, j;}'. */
2101 return;
2102
2103 if (PROCESSING_REAL_TEMPLATE_DECL_P ()
2104 || processing_explicit_instantiation
2105 || processing_specialization)
33bd39a2 2106 error ("multiple declarators in template declaration");
61a127b3
MM
2107}
2108
0213a355
JM
2109/* Implement the __typeof keyword: Return the type of EXPR, suitable for
2110 use as a type-specifier. */
2111
b894fc05
JM
2112tree
2113finish_typeof (expr)
2114 tree expr;
2115{
2116 if (processing_template_decl)
2117 {
2118 tree t;
2119
33848bb0 2120 t = make_aggr_type (TYPEOF_TYPE);
b894fc05 2121 TYPE_FIELDS (t) = expr;
b894fc05
JM
2122
2123 return t;
2124 }
2125
12fa82db
MM
2126 if (TREE_CODE (expr) == OFFSET_REF)
2127 expr = resolve_offset_ref (expr);
2128
b894fc05
JM
2129 return TREE_TYPE (expr);
2130}
558475f0 2131
0213a355
JM
2132/* Compute the value of the `sizeof' operator. */
2133
2134tree
2135finish_sizeof (t)
2136 tree t;
2137{
2138 if (processing_template_decl)
78a40378 2139 return build_min_nt (SIZEOF_EXPR, t);
0213a355 2140
fa72b064 2141 return TYPE_P (t) ? cxx_sizeof (t) : expr_sizeof (t);
0213a355
JM
2142}
2143
2144/* Implement the __alignof keyword: Return the minimum required
2145 alignment of T, measured in bytes. */
2146
2147tree
2148finish_alignof (t)
2149 tree t;
2150{
2151 if (processing_template_decl)
78a40378 2152 return build_min_nt (ALIGNOF_EXPR, t);
0213a355 2153
fa72b064 2154 return TYPE_P (t) ? cxx_alignof (t) : c_alignof_expr (t);
0213a355
JM
2155}
2156
62409b39
MM
2157/* Generate RTL for the statement T, and its substatements, and any
2158 other statements at its nesting level. */
558475f0 2159
54f7877c
MM
2160static void
2161cp_expand_stmt (t)
558475f0
MM
2162 tree t;
2163{
54f7877c 2164 switch (TREE_CODE (t))
62409b39 2165 {
54f7877c
MM
2166 case TRY_BLOCK:
2167 genrtl_try_block (t);
2168 break;
558475f0 2169
52a11cbf
RH
2170 case EH_SPEC_BLOCK:
2171 genrtl_eh_spec_block (t);
2172 break;
2173
54f7877c
MM
2174 case HANDLER:
2175 genrtl_handler (t);
2176 break;
558475f0 2177
54f7877c
MM
2178 case RETURN_INIT:
2179 genrtl_named_return_value ();
2180 break;
2181
9da99f7d
NS
2182 case USING_STMT:
2183 break;
2184
54f7877c 2185 default:
a98facb0 2186 abort ();
54f7877c
MM
2187 break;
2188 }
558475f0
MM
2189}
2190
3eb24f73
MM
2191/* Called from expand_body via walk_tree. Replace all AGGR_INIT_EXPRs
2192 will equivalent CALL_EXPRs. */
2193
2194static tree
2195simplify_aggr_init_exprs_r (tp, walk_subtrees, data)
2196 tree *tp;
2197 int *walk_subtrees ATTRIBUTE_UNUSED;
2198 void *data ATTRIBUTE_UNUSED;
2199{
2200 tree aggr_init_expr;
2201 tree call_expr;
2202 tree fn;
2203 tree args;
2204 tree slot;
2205 tree type;
3eb24f73
MM
2206 int copy_from_buffer_p;
2207
3eb24f73 2208 aggr_init_expr = *tp;
22e92ac3
MM
2209 /* We don't need to walk into types; there's nothing in a type that
2210 needs simplification. (And, furthermore, there are places we
2211 actively don't want to go. For example, we don't want to wander
2212 into the default arguments for a FUNCTION_DECL that appears in a
2213 CALL_EXPR.) */
2214 if (TYPE_P (aggr_init_expr))
2215 {
2216 *walk_subtrees = 0;
2217 return NULL_TREE;
2218 }
2219 /* Only AGGR_INIT_EXPRs are interesting. */
2220 else if (TREE_CODE (aggr_init_expr) != AGGR_INIT_EXPR)
3eb24f73
MM
2221 return NULL_TREE;
2222
2223 /* Form an appropriate CALL_EXPR. */
2224 fn = TREE_OPERAND (aggr_init_expr, 0);
2225 args = TREE_OPERAND (aggr_init_expr, 1);
2226 slot = TREE_OPERAND (aggr_init_expr, 2);
2227 type = TREE_TYPE (aggr_init_expr);
3eb24f73
MM
2228 if (AGGR_INIT_VIA_CTOR_P (aggr_init_expr))
2229 {
2230 /* Replace the first argument with the address of the third
2231 argument to the AGGR_INIT_EXPR. */
dffd7eb6 2232 cxx_mark_addressable (slot);
b850de4f
MM
2233 args = tree_cons (NULL_TREE,
2234 build1 (ADDR_EXPR,
2235 build_pointer_type (TREE_TYPE (slot)),
2236 slot),
3eb24f73
MM
2237 TREE_CHAIN (args));
2238 }
b850de4f
MM
2239 call_expr = build (CALL_EXPR,
2240 TREE_TYPE (TREE_TYPE (TREE_TYPE (fn))),
2241 fn, args, NULL_TREE);
3eb24f73
MM
2242 TREE_SIDE_EFFECTS (call_expr) = 1;
2243
2244 /* If we're using the non-reentrant PCC calling convention, then we
2245 need to copy the returned value out of the static buffer into the
2246 SLOT. */
2247 copy_from_buffer_p = 0;
2248#ifdef PCC_STATIC_STRUCT_RETURN
2249 if (!AGGR_INIT_VIA_CTOR_P (aggr_init_expr) && aggregate_value_p (type))
2250 {
41251458 2251 int old_ac = flag_access_control;
3eb24f73
MM
2252
2253 flag_access_control = 0;
46af705a
JDA
2254 call_expr = build_aggr_init (slot, call_expr,
2255 DIRECT_BIND | LOOKUP_ONLYCONVERTING);
3eb24f73
MM
2256 flag_access_control = old_ac;
2257 copy_from_buffer_p = 1;
2258 }
2259#endif
2260
2261 /* If this AGGR_INIT_EXPR indicates the value returned by a
2262 function, then we want to use the value of the initialized
2263 location as the result. */
2264 if (AGGR_INIT_VIA_CTOR_P (aggr_init_expr) || copy_from_buffer_p)
2265 {
2266 call_expr = build (COMPOUND_EXPR, type,
2267 call_expr, slot);
2268 TREE_SIDE_EFFECTS (call_expr) = 1;
2269 }
2270
2271 /* Replace the AGGR_INIT_EXPR with the CALL_EXPR. */
2272 TREE_CHAIN (call_expr) = TREE_CHAIN (aggr_init_expr);
2273 *tp = call_expr;
2274
2275 /* Keep iterating. */
2276 return NULL_TREE;
2277}
2278
31f8e4f3
MM
2279/* Emit all thunks to FN that should be emitted when FN is emitted. */
2280
2281static void
2282emit_associated_thunks (fn)
2283 tree fn;
2284{
2285 /* When we use vcall offsets, we emit thunks with the virtual
2286 functions to which they thunk. The whole point of vcall offsets
2287 is so that you can know statically the entire set of thunks that
2288 will ever be needed for a given virtual function, thereby
2289 enabling you to output all the thunks with the function itself. */
3461fba7 2290 if (DECL_VIRTUAL_P (fn))
31f8e4f3
MM
2291 {
2292 tree binfo;
2293 tree v;
2294
2295 for (binfo = TYPE_BINFO (DECL_CONTEXT (fn));
2296 binfo;
2297 binfo = TREE_CHAIN (binfo))
2298 for (v = BINFO_VIRTUALS (binfo); v; v = TREE_CHAIN (v))
2299 if (BV_FN (v) == fn
2300 && (!integer_zerop (BV_DELTA (v))
d0cd8b44 2301 || BV_USE_VCALL_INDEX_P (v)))
31f8e4f3
MM
2302 {
2303 tree thunk;
2304 tree vcall_index;
2305
2306 if (BV_USE_VCALL_INDEX_P (v))
2307 {
2308 vcall_index = BV_VCALL_INDEX (v);
2309 my_friendly_assert (vcall_index != NULL_TREE, 20000621);
2310 }
2311 else
2312 vcall_index = NULL_TREE;
2313
2314 thunk = make_thunk (build1 (ADDR_EXPR,
2315 vfunc_ptr_type_node,
2316 fn),
2317 BV_DELTA (v),
d0cd8b44 2318 vcall_index);
31f8e4f3
MM
2319 use_thunk (thunk, /*emit_p=*/1);
2320 }
2321 }
2322}
2323
558475f0
MM
2324/* Generate RTL for FN. */
2325
2326void
2327expand_body (fn)
2328 tree fn;
2329{
62409b39 2330 int saved_lineno;
3b304f5b 2331 const char *saved_input_filename;
367aa585 2332 tree saved_function;
558475f0 2333
62409b39
MM
2334 /* When the parser calls us after finishing the body of a template
2335 function, we don't really want to expand the body. When we're
2336 processing an in-class definition of an inline function,
2337 PROCESSING_TEMPLATE_DECL will no longer be set here, so we have
2338 to look at the function itself. */
2339 if (processing_template_decl
2340 || (DECL_LANG_SPECIFIC (fn)
2341 && DECL_TEMPLATE_INFO (fn)
2342 && uses_template_parms (DECL_TI_ARGS (fn))))
d658cd4c
MM
2343 {
2344 /* Normally, collection only occurs in rest_of_compilation. So,
2345 if we don't collect here, we never collect junk generated
2346 during the processing of templates until we hit a
2347 non-template function. */
2348 ggc_collect ();
2349 return;
2350 }
62409b39 2351
3eb24f73 2352 /* Replace AGGR_INIT_EXPRs with appropriate CALL_EXPRs. */
ee94fce6
MM
2353 walk_tree_without_duplicates (&DECL_SAVED_TREE (fn),
2354 simplify_aggr_init_exprs_r,
2355 NULL);
3eb24f73 2356
3461fba7
NS
2357 /* If this is a constructor or destructor body, we have to clone
2358 it. */
db9b2174
MM
2359 if (maybe_clone_body (fn))
2360 {
2361 /* We don't want to process FN again, so pretend we've written
2362 it out, even though we haven't. */
2363 TREE_ASM_WRITTEN (fn) = 1;
2364 return;
2365 }
2366
84df082b
MM
2367 /* There's no reason to do any of the work here if we're only doing
2368 semantic analysis; this code just generates RTL. */
2369 if (flag_syntax_only)
2370 return;
2371
21b0c6dc
MM
2372 /* If possible, avoid generating RTL for this function. Instead,
2373 just record it as an inline function, and wait until end-of-file
2374 to decide whether to write it out or not. */
56e770bf
MM
2375 if (/* We have to generate RTL if it's not an inline function. */
2376 (DECL_INLINE (fn) || DECL_COMDAT (fn))
4f8e1232 2377 /* Or if we have to emit code for inline functions anyhow. */
21b0c6dc
MM
2378 && !flag_keep_inline_functions
2379 /* Or if we actually have a reference to the function. */
4f8e1232 2380 && !DECL_NEEDED_P (fn))
21b0c6dc 2381 {
21b0c6dc
MM
2382 /* Set DECL_EXTERNAL so that assemble_external will be called as
2383 necessary. We'll clear it again in finish_file. */
2384 if (!DECL_EXTERNAL (fn))
2385 {
2386 DECL_NOT_REALLY_EXTERN (fn) = 1;
2387 DECL_EXTERNAL (fn) = 1;
2388 }
2389 /* Remember this function. In finish_file we'll decide if
2390 we actually need to write this function out. */
56e770bf 2391 defer_fn (fn);
aba649ba 2392 /* Let the back-end know that this function exists. */
2b85879e 2393 (*debug_hooks->deferred_inline_function) (fn);
21b0c6dc
MM
2394 return;
2395 }
2396
92788413
MM
2397 /* Compute the appropriate object-file linkage for inline
2398 functions. */
79065db2 2399 if (DECL_DECLARED_INLINE_P (fn))
92788413
MM
2400 import_export_decl (fn);
2401
4f8e1232
MM
2402 /* If FN is external, then there's no point in generating RTL for
2403 it. This situation can arise with an inline function under
83662e2b 2404 `-fexternal-templates'; we instantiate the function, even though
4f8e1232
MM
2405 we're not planning on emitting it, in case we get a chance to
2406 inline it. */
2407 if (DECL_EXTERNAL (fn))
2408 return;
2409
62409b39 2410 /* Save the current file name and line number. When we expand the
84df082b 2411 body of the function, we'll set LINENO and INPUT_FILENAME so that
62409b39
MM
2412 error-mesages come out in the right places. */
2413 saved_lineno = lineno;
2414 saved_input_filename = input_filename;
367aa585 2415 saved_function = current_function_decl;
62409b39
MM
2416 lineno = DECL_SOURCE_LINE (fn);
2417 input_filename = DECL_SOURCE_FILE (fn);
367aa585
JM
2418 current_function_decl = fn;
2419
2420 timevar_push (TV_INTEGRATION);
2421
2422 /* Optimize the body of the function before expanding it. */
2423 optimize_function (fn);
2424
2425 timevar_pop (TV_INTEGRATION);
2426 timevar_push (TV_EXPAND);
62409b39 2427
f444e36b 2428 genrtl_start_function (fn);
6462c441 2429 current_function_is_thunk = DECL_THUNK_P (fn);
558475f0 2430
558475f0 2431 /* Expand the body. */
b35d4555 2432 expand_stmt (DECL_SAVED_TREE (fn));
558475f0 2433
62409b39
MM
2434 /* Statements should always be full-expressions at the outermost set
2435 of curly braces for a function. */
f2c5f623 2436 my_friendly_assert (stmts_are_full_exprs_p (), 19990831);
62409b39
MM
2437
2438 /* The outermost statement for a function contains the line number
2439 recorded when we finished processing the function. */
2440 lineno = STMT_LINENO (DECL_SAVED_TREE (fn));
2441
2442 /* Generate code for the function. */
f444e36b 2443 genrtl_finish_function (fn);
62409b39 2444
46e8c075
MM
2445 /* If possible, obliterate the body of the function so that it can
2446 be garbage collected. */
b7442fb5 2447 if (dump_enabled_p (TDI_all))
46e8c075
MM
2448 /* Keep the body; we're going to dump it. */
2449 ;
2450 else if (DECL_INLINE (fn) && flag_inline_trees)
2451 /* We might need the body of this function so that we can expand
2452 it inline somewhere else. */
2453 ;
2454 else
2455 /* We don't need the body; blow it away. */
d658cd4c
MM
2456 DECL_SAVED_TREE (fn) = NULL_TREE;
2457
62409b39 2458 /* And restore the current source position. */
367aa585 2459 current_function_decl = saved_function;
62409b39
MM
2460 lineno = saved_lineno;
2461 input_filename = saved_input_filename;
f12eef58 2462 extract_interface_info ();
ea11ca7e
JM
2463
2464 timevar_pop (TV_EXPAND);
14691f8d
RH
2465
2466 /* Emit any thunks that should be emitted at the same time as FN. */
2467 emit_associated_thunks (fn);
558475f0 2468}
54f7877c 2469
07b2f2fd
JM
2470/* Helper function for walk_tree, used by finish_function to override all
2471 the RETURN_STMTs and pertinent CLEANUP_STMTs for the named return
2472 value optimization. */
0d97bf4c 2473
07b2f2fd 2474tree
0d97bf4c
JM
2475nullify_returns_r (tp, walk_subtrees, data)
2476 tree *tp;
2477 int *walk_subtrees;
07b2f2fd 2478 void *data;
0d97bf4c 2479{
07b2f2fd
JM
2480 tree nrv = (tree) data;
2481
2482 /* No need to walk into types. There wouldn't be any need to walk into
2483 non-statements, except that we have to consider STMT_EXPRs. */
0d97bf4c
JM
2484 if (TYPE_P (*tp))
2485 *walk_subtrees = 0;
2486 else if (TREE_CODE (*tp) == RETURN_STMT)
07b2f2fd
JM
2487 RETURN_EXPR (*tp) = NULL_TREE;
2488 else if (TREE_CODE (*tp) == CLEANUP_STMT
2489 && CLEANUP_DECL (*tp) == nrv)
659e5a7a 2490 CLEANUP_EH_ONLY (*tp) = 1;
0d97bf4c
JM
2491
2492 /* Keep iterating. */
2493 return NULL_TREE;
2494}
2495
f444e36b
MM
2496/* Start generating the RTL for FN. */
2497
2498static void
2499genrtl_start_function (fn)
2500 tree fn;
2501{
f444e36b
MM
2502 /* Tell everybody what function we're processing. */
2503 current_function_decl = fn;
2504 /* Get the RTL machinery going for this function. */
2505 init_function_start (fn, DECL_SOURCE_FILE (fn), DECL_SOURCE_LINE (fn));
2506 /* Let everybody know that we're expanding this function, not doing
2507 semantic analysis. */
2508 expanding_p = 1;
2509
2510 /* Even though we're inside a function body, we still don't want to
2511 call expand_expr to calculate the size of a variable-sized array.
2512 We haven't necessarily assigned RTL to all variables yet, so it's
2513 not safe to try to expand expressions involving them. */
2514 immediate_size_expand = 0;
2515 cfun->x_dont_save_pending_sizes_p = 1;
2516
2517 /* Let the user know we're compiling this function. */
2518 announce_function (fn);
2519
2520 /* Initialize the per-function data. */
2521 my_friendly_assert (!DECL_PENDING_INLINE_P (fn), 20000911);
2522 if (DECL_SAVED_FUNCTION_DATA (fn))
2523 {
2524 /* If we already parsed this function, and we're just expanding it
2525 now, restore saved state. */
2526 *cp_function_chain = *DECL_SAVED_FUNCTION_DATA (fn);
2527
2528 /* This function is being processed in whole-function mode; we
2529 already did semantic analysis. */
2530 cfun->x_whole_function_mode_p = 1;
2531
2532 /* If we decided that we didn't want to inline this function,
2533 make sure the back-end knows that. */
2534 if (!current_function_cannot_inline)
2535 current_function_cannot_inline = cp_function_chain->cannot_inline;
2536
edf5cd1d
JM
2537 /* We don't need the saved data anymore. Unless this is an inline
2538 function; we need the named return value info for
2539 cp_copy_res_decl_for_inlining. */
2540 if (! DECL_INLINE (fn))
e2500fed 2541 DECL_SAVED_FUNCTION_DATA (fn) = NULL;
f444e36b
MM
2542 }
2543
f444e36b
MM
2544 /* Keep track of how many functions we're presently expanding. */
2545 ++function_depth;
2546
2547 /* Create a binding level for the parameters. */
a0de9d20 2548 expand_function_start (fn, /*parms_have_cleanups=*/0);
f444e36b
MM
2549 /* If this function is `main'. */
2550 if (DECL_MAIN_P (fn))
2551 expand_main_function ();
0d97bf4c 2552
07b2f2fd
JM
2553 /* Give our named return value the same RTL as our RESULT_DECL. */
2554 if (current_function_return_value)
2555 COPY_DECL_RTL (DECL_RESULT (fn), current_function_return_value);
f444e36b
MM
2556}
2557
2558/* Finish generating the RTL for FN. */
2559
2560static void
2561genrtl_finish_function (fn)
2562 tree fn;
2563{
4f8e1232 2564 tree t;
f444e36b
MM
2565
2566#if 0
2567 if (write_symbols != NO_DEBUG)
2568 {
2569 /* Keep this code around in case we later want to control debug info
2570 based on whether a type is "used". (jason 1999-11-11) */
2571
2572 tree ttype = target_type (fntype);
2573 tree parmdecl;
2574
2575 if (IS_AGGR_TYPE (ttype))
2576 /* Let debugger know it should output info for this type. */
2577 note_debug_info_needed (ttype);
2578
2579 for (parmdecl = DECL_ARGUMENTS (fndecl); parmdecl; parmdecl = TREE_CHAIN (parmdecl))
2580 {
2581 ttype = target_type (TREE_TYPE (parmdecl));
2582 if (IS_AGGR_TYPE (ttype))
2583 /* Let debugger know it should output info for this type. */
2584 note_debug_info_needed (ttype);
2585 }
2586 }
2587#endif
2588
2589 /* Clean house because we will need to reorder insns here. */
2590 do_pending_stack_adjust ();
2591
a0de9d20
JM
2592 /* If we have a named return value, we need to force a return so that
2593 the return register is USEd. */
2594 if (DECL_NAME (DECL_RESULT (fn)))
e6fe680d 2595 emit_jump (return_label);
f444e36b
MM
2596
2597 /* We hard-wired immediate_size_expand to zero in start_function.
2598 Expand_function_end will decrement this variable. So, we set the
2599 variable to one here, so that after the decrement it will remain
2600 zero. */
2601 immediate_size_expand = 1;
2602
2603 /* Generate rtl for function exit. */
f21add07 2604 expand_function_end (input_filename, lineno, 0);
f444e36b 2605
f444e36b
MM
2606 /* If this is a nested function (like a template instantiation that
2607 we're compiling in the midst of compiling something else), push a
2608 new GC context. That will keep local variables on the stack from
2609 being collected while we're doing the compilation of this
2610 function. */
2611 if (function_depth > 1)
2612 ggc_push_context ();
2613
b850de4f
MM
2614 /* There's no need to defer outputting this function any more; we
2615 know we want to output it. */
2616 DECL_DEFER_OUTPUT (fn) = 0;
2617
f444e36b
MM
2618 /* Run the optimizers and output the assembler code for this
2619 function. */
2620 rest_of_compilation (fn);
2621
2622 /* Undo the call to ggc_push_context above. */
2623 if (function_depth > 1)
2624 ggc_pop_context ();
2625
f444e36b
MM
2626#if 0
2627 /* Keep this code around in case we later want to control debug info
2628 based on whether a type is "used". (jason 1999-11-11) */
2629
2630 if (ctype && TREE_ASM_WRITTEN (fn))
2631 note_debug_info_needed (ctype);
2632#endif
2633
2634 /* If this function is marked with the constructor attribute, add it
2635 to the list of functions to be called along with constructors
2636 from static duration objects. */
2637 if (DECL_STATIC_CONSTRUCTOR (fn))
2638 static_ctors = tree_cons (NULL_TREE, fn, static_ctors);
2639
2640 /* If this function is marked with the destructor attribute, add it
2641 to the list of functions to be called along with destructors from
2642 static duration objects. */
2643 if (DECL_STATIC_DESTRUCTOR (fn))
2644 static_dtors = tree_cons (NULL_TREE, fn, static_dtors);
2645
f444e36b
MM
2646 --function_depth;
2647
4f8e1232
MM
2648 /* In C++, we should never be saving RTL for the function. */
2649 my_friendly_assert (!DECL_SAVED_INSNS (fn), 20010903);
b850de4f 2650
4f8e1232
MM
2651 /* Since we don't need the RTL for this function anymore, stop
2652 pointing to it. That's especially important for LABEL_DECLs,
2653 since you can reach all the instructions in the function from the
2654 CODE_LABEL stored in the DECL_RTL for the LABEL_DECL. Walk the
2655 BLOCK-tree, clearing DECL_RTL for LABEL_DECLs and non-static
2656 local variables. */
2657 walk_tree_without_duplicates (&DECL_SAVED_TREE (fn),
2658 clear_decl_rtl,
2659 NULL);
f444e36b 2660
4f8e1232
MM
2661 /* Clear out the RTL for the arguments. */
2662 for (t = DECL_ARGUMENTS (fn); t; t = TREE_CHAIN (t))
2663 {
2664 SET_DECL_RTL (t, NULL_RTX);
2665 DECL_INCOMING_RTL (t) = NULL_RTX;
b850de4f 2666 }
4f8e1232
MM
2667
2668 if (!(flag_inline_trees && DECL_INLINE (fn)))
2669 /* DECL_INITIAL must remain nonzero so we know this was an
2670 actual function definition. */
2671 DECL_INITIAL (fn) = error_mark_node;
b850de4f 2672
f444e36b
MM
2673 /* Let the error reporting routines know that we're outside a
2674 function. For a nested function, this value is used in
2675 pop_cp_function_context and then reset via pop_function_context. */
2676 current_function_decl = NULL_TREE;
2677}
2678
b850de4f
MM
2679/* Clear out the DECL_RTL for the non-static variables in BLOCK and
2680 its sub-blocks. */
2681
2682static tree
2683clear_decl_rtl (tp, walk_subtrees, data)
2684 tree *tp;
2685 int *walk_subtrees ATTRIBUTE_UNUSED;
2686 void *data ATTRIBUTE_UNUSED;
2687{
2688 if (nonstatic_local_decl_p (*tp))
2689 SET_DECL_RTL (*tp, NULL_RTX);
2690
2691 return NULL_TREE;
2692}
2693
54f7877c
MM
2694/* Perform initialization related to this module. */
2695
2696void
2697init_cp_semantics ()
2698{
2699 lang_expand_stmt = cp_expand_stmt;
2700}