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