]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/cp/semantics.c
* gcc.c-torture/execute/loop-6.c: New test.
[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
d569399b 6 Copyright (C) 1998, 1999, 2000 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"
31#include "except.h"
32#include "lex.h"
12027a89 33#include "toplev.h"
84df082b 34#include "flags.h"
d658cd4c 35#include "ggc.h"
d9b2d9da 36#include "rtl.h"
225ff119 37#include "output.h"
ea11ca7e 38#include "timevar.h"
ad321293
MM
39
40/* There routines provide a modular interface to perform many parsing
41 operations. They may therefore be used during actual parsing, or
42 during template instantiation, which may be regarded as a
43 degenerate form of parsing. Since the current g++ parser is
44 lacking in several respects, and will be reimplemented, we are
45 attempting to move most code that is not directly related to
46 parsing into this file; that will make implementing the new parser
47 much easier since it will be able to make use of these routines. */
48
158991b7
KG
49static tree expand_cond PARAMS ((tree));
50static tree maybe_convert_cond PARAMS ((tree));
51static tree simplify_aggr_init_exprs_r PARAMS ((tree *, int *, void *));
c2e407f1 52static void deferred_type_access_control PARAMS ((void));
558475f0 53
6f80451c
MM
54/* Record the fact that STMT was the last statement added to the
55 statement tree. */
56
57#define SET_LAST_STMT(stmt) \
58 (current_stmt_tree->x_last_stmt = (stmt))
59
ad321293
MM
60/* When parsing a template, LAST_TREE contains the last statement
61 parsed. These are chained together through the TREE_CHAIN field,
62 but often need to be re-organized since the parse is performed
63 bottom-up. This macro makes LAST_TREE the indicated SUBSTMT of
64 STMT. */
65
cb39191d
MM
66#define RECHAIN_STMTS(stmt, substmt) \
67 do { \
68 substmt = TREE_CHAIN (stmt); \
69 TREE_CHAIN (stmt) = NULL_TREE; \
6f80451c 70 SET_LAST_STMT (stmt); \
ad321293
MM
71 } while (0)
72
527f0080
MM
73/* Finish processing the COND, the SUBSTMT condition for STMT. */
74
ed5511d9
MM
75#define FINISH_COND(cond, stmt, substmt) \
76 do { \
77 if (last_tree != stmt) \
78 { \
79 RECHAIN_STMTS (stmt, substmt); \
80 if (!processing_template_decl) \
81 { \
82 cond = build_tree_list (substmt, cond); \
83 substmt = cond; \
84 } \
85 } \
86 else \
87 substmt = cond; \
527f0080
MM
88 } while (0)
89
a7e4cfa0 90/* T is a statement. Add it to the statement-tree. */
ad321293 91
a7e4cfa0
MM
92void
93add_tree (t)
94 tree t;
95{
96 /* Add T to the statement-tree. */
6f80451c
MM
97 TREE_CHAIN (last_tree) = t;
98 SET_LAST_STMT (t);
a7e4cfa0
MM
99
100 /* When we expand a statement-tree, we must know whether or not the
101 statements are full-expresions. We record that fact here. */
102 if (building_stmt_tree ())
103 STMT_IS_FULL_EXPR_P (last_tree) = stmts_are_full_exprs_p;
104}
105
ed5511d9
MM
106/* COND is the condition-expression for an if, while, etc.,
107 statement. Convert it to a boolean value, if appropriate. */
108
109static tree
110maybe_convert_cond (cond)
111 tree cond;
112{
113 /* Empty conditions remain empty. */
114 if (!cond)
115 return NULL_TREE;
116
117 /* Wait until we instantiate templates before doing conversion. */
118 if (processing_template_decl)
119 return cond;
120
121 /* Do the conversion. */
122 cond = convert_from_reference (cond);
123 return condition_conversion (cond);
124}
125
9bfadf57 126/* Finish an expression-statement, whose EXPRESSION is as indicated. */
a7e4cfa0 127
9bfadf57
MM
128void
129finish_expr_stmt (expr)
ad321293
MM
130 tree expr;
131{
ce4a0391 132 if (expr != NULL_TREE)
ad321293 133 {
558475f0 134 if (building_stmt_tree ())
ce4a0391 135 {
ce4a0391
MM
136 /* Do default conversion if safe and possibly important,
137 in case within ({...}). */
364460b6
MM
138 if (!processing_template_decl
139 && !stmts_are_full_exprs_p
140 && ((TREE_CODE (TREE_TYPE (expr)) == ARRAY_TYPE
141 && lvalue_p (expr))
142 || TREE_CODE (TREE_TYPE (expr)) == FUNCTION_TYPE))
ce4a0391 143 expr = default_conversion (expr);
f1dedc31 144
2bdb0643
JM
145 if (stmts_are_full_exprs_p)
146 expr = convert_to_void (expr, "statement");
147
364460b6
MM
148 if (!processing_template_decl)
149 expr = break_out_cleanups (expr);
150
151 add_tree (build_min_nt (EXPR_STMT, expr));
152 }
153 else
154 {
155 emit_line_note (input_filename, lineno);
156
f1dedc31
MM
157 if (stmts_are_full_exprs_p)
158 expand_start_target_temps ();
159
558475f0 160 cplus_expand_expr_stmt (expr);
558475f0 161
f1dedc31 162 if (stmts_are_full_exprs_p)
f31c0a32 163 expand_end_target_temps ();
f1dedc31 164 }
ad321293 165 }
ce4a0391 166
ad321293 167 finish_stmt ();
558475f0
MM
168
169 /* This was an expression-statement, so we save the type of the
170 expression. */
171 last_expr_type = expr ? TREE_TYPE (expr) : NULL_TREE;
ad321293
MM
172}
173
174/* Begin an if-statement. Returns a newly created IF_STMT if
175 appropriate. */
176
177tree
178begin_if_stmt ()
179{
180 tree r;
181
9bfadf57
MM
182 do_pushlevel ();
183
558475f0 184 if (building_stmt_tree ())
ad321293
MM
185 {
186 r = build_min_nt (IF_STMT, NULL_TREE, NULL_TREE, NULL_TREE);
187 add_tree (r);
188 }
189 else
190 r = NULL_TREE;
191
ad321293
MM
192 return r;
193}
194
195/* Process the COND of an if-statement, which may be given by
196 IF_STMT. */
197
198void
199finish_if_stmt_cond (cond, if_stmt)
200 tree cond;
201 tree if_stmt;
202{
ed5511d9
MM
203 cond = maybe_convert_cond (cond);
204
558475f0 205 if (building_stmt_tree ())
a7e4cfa0 206 FINISH_COND (cond, if_stmt, IF_COND (if_stmt));
ad321293
MM
207 else
208 {
209 emit_line_note (input_filename, lineno);
ed5511d9 210 expand_start_cond (cond, 0);
ad321293
MM
211 }
212}
213
214/* Finish the then-clause of an if-statement, which may be given by
215 IF_STMT. */
216
217tree
218finish_then_clause (if_stmt)
219 tree if_stmt;
220{
558475f0 221 if (building_stmt_tree ())
ad321293 222 {
cb39191d 223 RECHAIN_STMTS (if_stmt, THEN_CLAUSE (if_stmt));
6f80451c 224 SET_LAST_STMT (if_stmt);
ad321293
MM
225 return if_stmt;
226 }
227 else
228 return NULL_TREE;
229}
230
231/* Begin the else-clause of an if-statement. */
232
233void
234begin_else_clause ()
235{
558475f0 236 if (!building_stmt_tree ())
ad321293
MM
237 expand_start_else ();
238}
239
240/* Finish the else-clause of an if-statement, which may be given by
241 IF_STMT. */
242
243void
244finish_else_clause (if_stmt)
245 tree if_stmt;
246{
558475f0 247 if (building_stmt_tree ())
cb39191d 248 RECHAIN_STMTS (if_stmt, ELSE_CLAUSE (if_stmt));
ad321293
MM
249}
250
251/* Finsh an if-statement. */
252
253void
254finish_if_stmt ()
255{
558475f0 256 if (!building_stmt_tree ())
ad321293
MM
257 expand_end_cond ();
258
259 do_poplevel ();
260 finish_stmt ();
261}
262
263/* Begin a while-statement. Returns a newly created WHILE_STMT if
264 appropriate. */
265
266tree
267begin_while_stmt ()
268{
269 tree r;
270
558475f0 271 if (building_stmt_tree ())
ad321293
MM
272 {
273 r = build_min_nt (WHILE_STMT, NULL_TREE, NULL_TREE);
274 add_tree (r);
275 }
276 else
277 {
278 emit_nop ();
279 emit_line_note (input_filename, lineno);
280 expand_start_loop (1);
281 r = NULL_TREE;
282 }
283
284 do_pushlevel ();
285
286 return r;
287}
288
27d26ee7 289/* Process the COND of a while-statement, which may be given by
ad321293
MM
290 WHILE_STMT. */
291
292void
293finish_while_stmt_cond (cond, while_stmt)
294 tree cond;
295 tree while_stmt;
296{
ed5511d9
MM
297 cond = maybe_convert_cond (cond);
298
558475f0 299 if (building_stmt_tree ())
a7e4cfa0 300 FINISH_COND (cond, while_stmt, WHILE_COND (while_stmt));
ad321293
MM
301 else
302 {
303 emit_line_note (input_filename, lineno);
ed5511d9 304 expand_exit_loop_if_false (0, cond);
ad321293
MM
305 }
306
307 /* If COND wasn't a declaration, clear out the
308 block we made for it and start a new one here so the
309 optimization in expand_end_loop will work. */
310 if (getdecls () == NULL_TREE)
311 {
312 do_poplevel ();
313 do_pushlevel ();
314 }
315}
316
317/* Finish a while-statement, which may be given by WHILE_STMT. */
318
319void
320finish_while_stmt (while_stmt)
321 tree while_stmt;
322{
323 do_poplevel ();
324
558475f0 325 if (building_stmt_tree ())
cb39191d 326 RECHAIN_STMTS (while_stmt, WHILE_BODY (while_stmt));
ad321293
MM
327 else
328 expand_end_loop ();
329 finish_stmt ();
330}
331
332/* Begin a do-statement. Returns a newly created DO_STMT if
333 appropriate. */
334
335tree
336begin_do_stmt ()
337{
558475f0 338 if (building_stmt_tree ())
ad321293
MM
339 {
340 tree r = build_min_nt (DO_STMT, NULL_TREE, NULL_TREE);
341 add_tree (r);
342 return r;
343 }
344 else
345 {
346 emit_nop ();
347 emit_line_note (input_filename, lineno);
348 expand_start_loop_continue_elsewhere (1);
349 return NULL_TREE;
350 }
351}
352
353/* Finish the body of a do-statement, which may be given by DO_STMT. */
354
355void
356finish_do_body (do_stmt)
357 tree do_stmt;
358{
558475f0 359 if (building_stmt_tree ())
cb39191d 360 RECHAIN_STMTS (do_stmt, DO_BODY (do_stmt));
ad321293
MM
361 else
362 expand_loop_continue_here ();
363}
364
365/* Finish a do-statement, which may be given by DO_STMT, and whose
366 COND is as indicated. */
367
368void
369finish_do_stmt (cond, do_stmt)
370 tree cond;
371 tree do_stmt;
372{
ed5511d9
MM
373 cond = maybe_convert_cond (cond);
374
558475f0 375 if (building_stmt_tree ())
2a1e9fdd 376 DO_COND (do_stmt) = cond;
ad321293
MM
377 else
378 {
379 emit_line_note (input_filename, lineno);
ed5511d9 380 expand_exit_loop_if_false (0, cond);
ad321293
MM
381 expand_end_loop ();
382 }
383
ad321293
MM
384 finish_stmt ();
385}
386
387/* Finish a return-statement. The EXPRESSION returned, if any, is as
388 indicated. */
389
390void
391finish_return_stmt (expr)
392 tree expr;
393{
efee38a9
MM
394 if (doing_semantic_analysis_p () && !processing_template_decl)
395 expr = check_return_expr (expr);
396
397 if (doing_semantic_analysis_p () && !processing_template_decl)
398 {
399 if (DECL_CONSTRUCTOR_P (current_function_decl) && ctor_label)
400 {
401 /* Even returns without a value in a constructor must return
402 `this'. We accomplish this by sending all returns in a
403 constructor to the CTOR_LABEL; finish_function emits code to
404 return a value there. When we finally generate the real
405 return statement, CTOR_LABEL is no longer set, and we fall
406 through into the normal return-processing code below. */
407 finish_goto_stmt (ctor_label);
408 return;
409 }
410 else if (DECL_DESTRUCTOR_P (current_function_decl))
411 {
412 /* Similarly, all destructors must run destructors for
413 base-classes before returning. So, all returns in a
414 destructor get sent to the DTOR_LABEL; finsh_function emits
415 code to return a value there. */
416 finish_goto_stmt (dtor_label);
417 return;
418 }
419 }
420
558475f0
MM
421 if (building_stmt_tree ())
422 add_tree (build_min_nt (RETURN_STMT, expr));
423 else
424 {
425 emit_line_note (input_filename, lineno);
426 c_expand_return (expr);
427 }
428
ad321293
MM
429 finish_stmt ();
430}
431
432/* Begin a for-statement. Returns a new FOR_STMT if appropriate. */
433
434tree
435begin_for_stmt ()
436{
437 tree r;
438
558475f0 439 if (building_stmt_tree ())
ad321293
MM
440 {
441 r = build_min_nt (FOR_STMT, NULL_TREE, NULL_TREE,
442 NULL_TREE, NULL_TREE);
443 add_tree (r);
444 }
445 else
446 r = NULL_TREE;
447
448 if (flag_new_for_scope > 0)
449 {
450 do_pushlevel ();
451 note_level_for_for ();
452 }
453
454 return r;
455}
456
457/* Finish the for-init-statement of a for-statement, which may be
458 given by FOR_STMT. */
459
460void
461finish_for_init_stmt (for_stmt)
462 tree for_stmt;
463{
558475f0 464 if (building_stmt_tree ())
ad321293
MM
465 {
466 if (last_tree != for_stmt)
cb39191d 467 RECHAIN_STMTS (for_stmt, FOR_INIT_STMT (for_stmt));
ad321293
MM
468 }
469 else
470 {
471 emit_nop ();
472 emit_line_note (input_filename, lineno);
473 expand_start_loop_continue_elsewhere (1);
474 }
475
476 do_pushlevel ();
477}
478
479/* Finish the COND of a for-statement, which may be given by
480 FOR_STMT. */
481
482void
483finish_for_cond (cond, for_stmt)
484 tree cond;
485 tree for_stmt;
486{
ed5511d9
MM
487 cond = maybe_convert_cond (cond);
488
558475f0 489 if (building_stmt_tree ())
a7e4cfa0 490 FINISH_COND (cond, for_stmt, FOR_COND (for_stmt));
ad321293
MM
491 else
492 {
493 emit_line_note (input_filename, lineno);
1dcf683e 494 if (cond)
ed5511d9 495 expand_exit_loop_if_false (0, cond);
ad321293
MM
496 }
497
498 /* If the cond wasn't a declaration, clear out the
499 block we made for it and start a new one here so the
500 optimization in expand_end_loop will work. */
501 if (getdecls () == NULL_TREE)
502 {
503 do_poplevel ();
504 do_pushlevel ();
505 }
506}
507
508/* Finish the increment-EXPRESSION in a for-statement, which may be
509 given by FOR_STMT. */
510
511void
512finish_for_expr (expr, for_stmt)
513 tree expr;
514 tree for_stmt;
515{
558475f0 516 if (building_stmt_tree ())
2a1e9fdd 517 FOR_EXPR (for_stmt) = expr;
ad321293
MM
518}
519
520/* Finish the body of a for-statement, which may be given by
521 FOR_STMT. The increment-EXPR for the loop must be
522 provided. */
523
524void
525finish_for_stmt (expr, for_stmt)
526 tree expr;
527 tree for_stmt;
528{
529 /* Pop the scope for the body of the loop. */
530 do_poplevel ();
531
558475f0 532 if (building_stmt_tree ())
cb39191d 533 RECHAIN_STMTS (for_stmt, FOR_BODY (for_stmt));
ad321293
MM
534 else
535 {
536 emit_line_note (input_filename, lineno);
537 expand_loop_continue_here ();
538 if (expr)
f1dedc31 539 finish_expr_stmt (expr);
ad321293
MM
540 expand_end_loop ();
541 }
542
ad321293
MM
543 if (flag_new_for_scope > 0)
544 do_poplevel ();
545
546 finish_stmt ();
547}
548
549/* Finish a break-statement. */
550
551void
552finish_break_stmt ()
553{
554 emit_line_note (input_filename, lineno);
558475f0 555 if (building_stmt_tree ())
ad321293
MM
556 add_tree (build_min_nt (BREAK_STMT));
557 else if ( ! expand_exit_something ())
8251199e 558 cp_error ("break statement not within loop or switch");
ad321293
MM
559}
560
561/* Finish a continue-statement. */
562
563void
564finish_continue_stmt ()
565{
566 emit_line_note (input_filename, lineno);
558475f0 567 if (building_stmt_tree ())
ad321293
MM
568 add_tree (build_min_nt (CONTINUE_STMT));
569 else if (! expand_continue_loop (0))
8251199e 570 cp_error ("continue statement not within a loop");
ad321293
MM
571}
572
527f0080
MM
573/* Begin a switch-statement. Returns a new SWITCH_STMT if
574 appropriate. */
ad321293 575
527f0080 576tree
ad321293
MM
577begin_switch_stmt ()
578{
527f0080
MM
579 tree r;
580
581 if (building_stmt_tree ())
582 {
583 r = build_min_nt (SWITCH_STMT, NULL_TREE, NULL_TREE);
584 add_tree (r);
585 }
586 else
587 r = NULL_TREE;
588
ad321293 589 do_pushlevel ();
527f0080
MM
590
591 return r;
ad321293
MM
592}
593
527f0080 594/* Finish the cond of a switch-statement. */
ad321293 595
527f0080
MM
596void
597finish_switch_cond (cond, switch_stmt)
ad321293 598 tree cond;
527f0080 599 tree switch_stmt;
ad321293 600{
558475f0 601 if (building_stmt_tree ())
373eb3b3
MM
602 {
603 if (!processing_template_decl)
604 {
605 /* Convert the condition to an integer or enumeration type. */
606 cond = build_expr_type_conversion (WANT_INT | WANT_ENUM, cond, 1);
607 if (cond == NULL_TREE)
608 {
609 error ("switch quantity not an integer");
610 cond = error_mark_node;
611 }
612 if (cond != error_mark_node)
613 {
614 tree idx;
615 tree type;
616
617 cond = default_conversion (cond);
618 type = TREE_TYPE (cond);
619 idx = get_unwidened (cond, 0);
620 /* We can't strip a conversion from a signed type to an unsigned,
621 because if we did, int_fits_type_p would do the wrong thing
622 when checking case values for being in range,
623 and it's too hard to do the right thing. */
624 if (TREE_UNSIGNED (TREE_TYPE (cond))
625 == TREE_UNSIGNED (TREE_TYPE (idx)))
626 cond = idx;
627
628 cond = fold (build1 (CLEANUP_POINT_EXPR, type, cond));
629 }
630 }
631 FINISH_COND (cond, switch_stmt, SWITCH_COND (switch_stmt));
632 }
0db982be 633 else if (cond != error_mark_node)
ad321293
MM
634 {
635 emit_line_note (input_filename, lineno);
636 c_expand_start_case (cond);
ad321293 637 }
0db982be 638 else
527f0080
MM
639 /* The code is in error, but we don't want expand_end_case to
640 crash. */
641 c_expand_start_case (boolean_false_node);
0db982be 642
ad321293 643 push_switch ();
ad321293
MM
644}
645
646/* Finish the body of a switch-statement, which may be given by
647 SWITCH_STMT. The COND to switch on is indicated. */
648
649void
650finish_switch_stmt (cond, switch_stmt)
651 tree cond;
652 tree switch_stmt;
653{
558475f0 654 if (building_stmt_tree ())
cb39191d 655 RECHAIN_STMTS (switch_stmt, SWITCH_BODY (switch_stmt));
ad321293
MM
656 else
657 expand_end_case (cond);
ad321293
MM
658 pop_switch ();
659 do_poplevel ();
660 finish_stmt ();
661}
662
663/* Finish a case-label. */
664
665void
666finish_case_label (low_value, high_value)
667 tree low_value;
668 tree high_value;
669{
558475f0
MM
670 if (building_stmt_tree ())
671 {
b35d4555
MM
672 /* Add a representation for the case label to the statement
673 tree. */
558475f0 674 add_tree (build_min_nt (CASE_LABEL, low_value, high_value));
b35d4555
MM
675 /* And warn about crossing initializations, etc. */
676 if (!processing_template_decl)
677 define_case_label ();
558475f0
MM
678 return;
679 }
680
ad321293
MM
681 do_case (low_value, high_value);
682}
683
ad321293
MM
684/* Finish a goto-statement. */
685
686void
687finish_goto_stmt (destination)
688 tree destination;
689{
3fa56191
MM
690 if (TREE_CODE (destination) == IDENTIFIER_NODE)
691 destination = lookup_label (destination);
692
88848bde
MM
693 /* We warn about unused labels with -Wunused. That means we have to
694 mark the used labels as used. */
695 if (TREE_CODE (destination) == LABEL_DECL)
696 TREE_USED (destination) = 1;
697
558475f0 698 if (building_stmt_tree ())
46e8c075
MM
699 {
700 if (TREE_CODE (destination) != LABEL_DECL)
701 /* We don't inline calls to functions with computed gotos.
702 Those functions are typically up to some funny business,
703 and may be depending on the labels being at particular
704 addresses, or some such. */
705 DECL_UNINLINABLE (current_function_decl) = 1;
706
6625cdb5
JM
707 check_goto (destination);
708
46e8c075
MM
709 add_tree (build_min_nt (GOTO_STMT, destination));
710 }
ad321293
MM
711 else
712 {
713 emit_line_note (input_filename, lineno);
714
3fa56191 715 if (TREE_CODE (destination) == LABEL_DECL)
ad321293 716 {
b35d4555 717 label_rtx (destination);
3fa56191 718 expand_goto (destination);
ad321293
MM
719 }
720 else
721 expand_computed_goto (destination);
722 }
723}
724
725/* Begin a try-block. Returns a newly-created TRY_BLOCK if
726 appropriate. */
727
728tree
729begin_try_block ()
730{
558475f0 731 if (building_stmt_tree ())
ad321293
MM
732 {
733 tree r = build_min_nt (TRY_BLOCK, NULL_TREE,
734 NULL_TREE);
735 add_tree (r);
736 return r;
737 }
738 else
739 {
740 emit_line_note (input_filename, lineno);
741 expand_start_try_stmts ();
742 return NULL_TREE;
743 }
744}
745
0dde4175
JM
746/* Likewise, for a function-try-block. */
747
748tree
749begin_function_try_block ()
750{
558475f0 751 if (building_stmt_tree ())
0dde4175
JM
752 {
753 tree r = build_min_nt (TRY_BLOCK, NULL_TREE,
754 NULL_TREE);
62409b39 755 FN_TRY_BLOCK_P (r) = 1;
0dde4175
JM
756 add_tree (r);
757 return r;
758 }
759 else
760 {
761 if (! current_function_parms_stored)
762 store_parm_decls ();
763 expand_start_early_try_stmts ();
764 return NULL_TREE;
765 }
766}
767
ad321293
MM
768/* Finish a try-block, which may be given by TRY_BLOCK. */
769
770void
771finish_try_block (try_block)
772 tree try_block;
773{
558475f0 774 if (building_stmt_tree ())
cb39191d 775 RECHAIN_STMTS (try_block, TRY_STMTS (try_block));
ad321293 776 else
558475f0 777 expand_start_all_catch ();
ad321293
MM
778}
779
efa8eda3
MM
780/* Finish the body of a cleanup try-block, which may be given by
781 TRY_BLOCK. */
782
62409b39
MM
783void
784finish_cleanup_try_block (try_block)
785 tree try_block;
786{
787 if (building_stmt_tree ())
788 RECHAIN_STMTS (try_block, TRY_STMTS (try_block));
789}
790
f1dedc31
MM
791/* Finish an implicitly generated try-block, with a cleanup is given
792 by CLEANUP. */
793
794void
795finish_cleanup (cleanup, try_block)
796 tree cleanup;
797 tree try_block;
798{
799 if (building_stmt_tree ())
800 {
2a1e9fdd 801 TRY_HANDLERS (try_block) = cleanup;
f1dedc31
MM
802 CLEANUP_P (try_block) = 1;
803 }
804 else
805 expand_eh_region_end (protect_with_terminate (cleanup));
806}
807
0dde4175
JM
808/* Likewise, for a function-try-block. */
809
810void
811finish_function_try_block (try_block)
f1dedc31 812 tree try_block;
0dde4175 813{
558475f0 814 if (building_stmt_tree ())
62409b39
MM
815 {
816 if (TREE_CHAIN (try_block)
817 && TREE_CODE (TREE_CHAIN (try_block)) == CTOR_INITIALIZER)
818 {
819 /* Chain the compound statement after the CTOR_INITIALIZER. */
820 TREE_CHAIN (TREE_CHAIN (try_block)) = last_tree;
821 /* And make the CTOR_INITIALIZER the body of the try-block. */
822 RECHAIN_STMTS (try_block, TRY_STMTS (try_block));
823 }
824 else
825 RECHAIN_STMTS (try_block, TRY_STMTS (try_block));
826 }
0dde4175
JM
827 else
828 {
829 end_protect_partials ();
830 expand_start_all_catch ();
0dde4175 831 }
b35d4555
MM
832
833 in_function_try_handler = 1;
0dde4175
JM
834}
835
ad321293
MM
836/* Finish a handler-sequence for a try-block, which may be given by
837 TRY_BLOCK. */
838
839void
840finish_handler_sequence (try_block)
841 tree try_block;
842{
558475f0 843 if (building_stmt_tree ())
2bc9f1d1
JM
844 {
845 RECHAIN_STMTS (try_block, TRY_HANDLERS (try_block));
846 check_handlers (TRY_HANDLERS (try_block));
847 }
ad321293 848 else
f1dedc31 849 expand_end_all_catch ();
ad321293
MM
850}
851
0dde4175
JM
852/* Likewise, for a function-try-block. */
853
854void
855finish_function_handler_sequence (try_block)
856 tree try_block;
857{
b35d4555
MM
858 in_function_try_handler = 0;
859
558475f0 860 if (building_stmt_tree ())
2bc9f1d1
JM
861 {
862 RECHAIN_STMTS (try_block, TRY_HANDLERS (try_block));
863 check_handlers (TRY_HANDLERS (try_block));
864 }
0dde4175 865 else
b35d4555 866 expand_end_all_catch ();
0dde4175
JM
867}
868
ad321293
MM
869/* Begin a handler. Returns a HANDLER if appropriate. */
870
871tree
872begin_handler ()
873{
874 tree r;
875
558475f0 876 if (building_stmt_tree ())
ad321293
MM
877 {
878 r = build_min_nt (HANDLER, NULL_TREE, NULL_TREE);
879 add_tree (r);
880 }
881 else
882 r = NULL_TREE;
883
884 do_pushlevel ();
885
886 return r;
887}
888
889/* Finish the handler-parameters for a handler, which may be given by
b35d4555
MM
890 HANDLER. DECL is the declaration for the catch parameter, or NULL
891 if this is a `catch (...)' clause. */
ad321293 892
b35d4555
MM
893tree
894finish_handler_parms (decl, handler)
895 tree decl;
ad321293 896 tree handler;
b35d4555
MM
897{
898 tree blocks = NULL_TREE;
899
900 if (processing_template_decl)
901 {
902 if (decl)
903 {
904 decl = pushdecl (decl);
905 decl = push_template_decl (decl);
906 add_decl_stmt (decl);
907 RECHAIN_STMTS (handler, HANDLER_PARMS (handler));
908 }
909 }
910 else if (building_stmt_tree ())
911 blocks = expand_start_catch_block (decl);
912
2bc9f1d1
JM
913 if (decl)
914 TREE_TYPE (handler) = TREE_TYPE (decl);
915
b35d4555
MM
916 return blocks;
917}
918
919/* Note the beginning of a handler for TYPE. This function is called
920 at the point to which control should be transferred when an
921 appropriately-typed exception is thrown. */
922
923void
924begin_catch_block (type)
925 tree type;
ad321293 926{
558475f0 927 if (building_stmt_tree ())
b35d4555
MM
928 add_tree (build (START_CATCH_STMT, type));
929 else
930 start_catch_handler (type);
ad321293
MM
931}
932
b35d4555
MM
933/* Finish a handler, which may be given by HANDLER. The BLOCKs are
934 the return value from the matching call to finish_handler_parms. */
ad321293
MM
935
936void
b35d4555
MM
937finish_handler (blocks, handler)
938 tree blocks;
ad321293
MM
939 tree handler;
940{
b35d4555
MM
941 if (!processing_template_decl)
942 {
943 if (building_stmt_tree ())
944 expand_end_catch_block (blocks);
945
946 if (!building_stmt_tree ())
947 {
948 /* Fall to outside the try statement when done executing
949 handler and we fall off end of handler. This is jump
950 Lresume in the documentation. */
951 expand_goto (top_label_entry (&caught_return_label_stack));
952 end_catch_handler ();
953 }
954 }
955
13e8cf82
MM
956 do_poplevel ();
957
558475f0 958 if (building_stmt_tree ())
cb39191d 959 RECHAIN_STMTS (handler, HANDLER_BODY (handler));
ad321293
MM
960}
961
962/* Begin a compound-statement. If HAS_NO_SCOPE is non-zero, the
963 compound-statement does not define a scope. Returns a new
964 COMPOUND_STMT if appropriate. */
965
966tree
967begin_compound_stmt (has_no_scope)
968 int has_no_scope;
969{
970 tree r;
6625cdb5 971 int is_try = 0;
ad321293 972
558475f0 973 if (building_stmt_tree ())
ad321293
MM
974 {
975 r = build_min_nt (COMPOUND_STMT, NULL_TREE);
6625cdb5
JM
976 /* Mark that this block is for a try so that we can yell at
977 people trying to jump in. */
978 if (last_tree && TREE_CODE (last_tree) == TRY_BLOCK)
979 is_try = 1;
ad321293
MM
980 add_tree (r);
981 if (has_no_scope)
982 COMPOUND_STMT_NO_SCOPE (r) = 1;
983 }
984 else
985 r = NULL_TREE;
986
558475f0
MM
987 last_expr_type = NULL_TREE;
988
ad321293 989 if (!has_no_scope)
6625cdb5
JM
990 {
991 do_pushlevel ();
992 if (is_try)
993 note_level_for_eh ();
994 }
f1dedc31
MM
995 else
996 /* Normally, we try hard to keep the BLOCK for a
997 statement-expression. But, if it's a statement-expression with
998 a scopeless block, there's nothing to keep, and we don't want
999 to accidentally keep a block *inside* the scopeless block. */
1000 keep_next_level (0);
ad321293 1001
24bef158
MM
1002 /* If this is the outermost block of the function, declare the
1003 variables __FUNCTION__, __PRETTY_FUNCTION__, and so forth. */
01d939e8 1004 if (cfun
6f80451c 1005 && !current_function_name_declared
9bfadf57 1006 && !has_no_scope)
24bef158 1007 {
24bef158 1008 current_function_name_declared = 1;
2ce07e2d 1009 declare_function_name ();
24bef158
MM
1010 }
1011
ad321293
MM
1012 return r;
1013}
1014
1015
1016/* Finish a compound-statement, which may be given by COMPOUND_STMT.
1017 If HAS_NO_SCOPE is non-zero, the compound statement does not define
1018 a scope. */
1019
1020tree
1021finish_compound_stmt (has_no_scope, compound_stmt)
1022 int has_no_scope;
1023 tree compound_stmt;
1024{
1025 tree r;
558475f0 1026 tree t;
ad321293
MM
1027
1028 if (!has_no_scope)
1029 r = do_poplevel ();
1030 else
1031 r = NULL_TREE;
1032
558475f0 1033 if (building_stmt_tree ())
cb39191d 1034 RECHAIN_STMTS (compound_stmt, COMPOUND_BODY (compound_stmt));
ad321293 1035
cb39191d 1036 /* When we call finish_stmt we will lose LAST_EXPR_TYPE. But, since
558475f0
MM
1037 the precise purpose of that variable is store the type of the
1038 last expression statement within the last compound statement, we
1039 preserve the value. */
1040 t = last_expr_type;
ad321293 1041 finish_stmt ();
558475f0 1042 last_expr_type = t;
ad321293
MM
1043
1044 return r;
1045}
1046
1047/* Finish an asm-statement, whose components are a CV_QUALIFIER, a
1048 STRING, some OUTPUT_OPERANDS, some INPUT_OPERANDS, and some
1049 CLOBBERS. */
1050
1051void
1052finish_asm_stmt (cv_qualifier, string, output_operands,
3ebc5c52 1053 input_operands, clobbers)
ad321293
MM
1054 tree cv_qualifier;
1055 tree string;
1056 tree output_operands;
1057 tree input_operands;
1058 tree clobbers;
1059{
1060 if (TREE_CHAIN (string))
cd9f6678 1061 string = combine_strings (string);
ad321293 1062
f71f87f9
MM
1063 if (cv_qualifier != NULL_TREE
1064 && cv_qualifier != ridpointers[(int) RID_VOLATILE])
1065 {
1066 cp_warning ("%s qualifier ignored on asm",
1067 IDENTIFIER_POINTER (cv_qualifier));
1068 cv_qualifier = NULL_TREE;
1069 }
1070
558475f0 1071 if (building_stmt_tree ())
ad321293
MM
1072 {
1073 tree r = build_min_nt (ASM_STMT, cv_qualifier, string,
1074 output_operands, input_operands,
1075 clobbers);
1076 add_tree (r);
1077 }
1078 else
1079 {
1080 emit_line_note (input_filename, lineno);
6e9438cf
AG
1081 if (output_operands != NULL_TREE || input_operands != NULL_TREE
1082 || clobbers != NULL_TREE)
1083 {
7dc5bd62
MM
1084 tree t;
1085
7dc5bd62
MM
1086 for (t = input_operands; t; t = TREE_CHAIN (t))
1087 TREE_VALUE (t) = decay_conversion (TREE_VALUE (t));
1088
6e9438cf
AG
1089 c_expand_asm_operands (string, output_operands,
1090 input_operands,
1091 clobbers,
f71f87f9 1092 cv_qualifier != NULL_TREE,
6e9438cf
AG
1093 input_filename, lineno);
1094 }
1095 else
f71f87f9 1096 expand_asm (string);
a64c757e 1097
ad321293
MM
1098 finish_stmt ();
1099 }
1100}
b4c4a9ec 1101
f01b0acb
MM
1102/* Finish a label with the indicated NAME. */
1103
1104void
1105finish_label_stmt (name)
1106 tree name;
1107{
3fa56191 1108 tree decl = define_label (input_filename, lineno, name);
f01b0acb 1109
558475f0 1110 if (building_stmt_tree ())
acef433b 1111 add_tree (build_min_nt (LABEL_STMT, decl));
3fa56191
MM
1112 else if (decl)
1113 expand_label (decl);
f01b0acb
MM
1114}
1115
acef433b
MM
1116/* Finish a series of declarations for local labels. G++ allows users
1117 to declare "local" labels, i.e., labels with scope. This extension
1118 is useful when writing code involving statement-expressions. */
1119
1120void
1121finish_label_decl (name)
1122 tree name;
1123{
1124 tree decl = declare_local_label (name);
1125 if (building_stmt_tree ())
1126 add_decl_stmt (decl);
1127}
1128
9188c363
MM
1129/* Create a declaration statement for the declaration given by the
1130 DECL. */
1131
1132void
1133add_decl_stmt (decl)
1134 tree decl;
1135{
1136 tree decl_stmt;
1137
1138 /* We need the type to last until instantiation time. */
9188c363
MM
1139 decl_stmt = build_min_nt (DECL_STMT, decl);
1140 add_tree (decl_stmt);
1141}
1142
f1dedc31
MM
1143/* We're in a constructor, and have just constructed a a subobject of
1144 *THIS. CLEANUP is code to run if an exception is thrown before the
1145 end of the current function is reached. */
1146
1147void
1148finish_subobject (cleanup)
1149 tree cleanup;
1150{
1151 if (building_stmt_tree ())
1152 {
1153 tree r = build_min_nt (SUBOBJECT, cleanup);
1154 add_tree (r);
1155 }
1156 else
1157 add_partial_entry (cleanup);
1158}
1159
24bef158
MM
1160/* When DECL goes out of scope, make sure that CLEANUP is executed. */
1161
1162void
1163finish_decl_cleanup (decl, cleanup)
1164 tree decl;
1165 tree cleanup;
1166{
1167 if (building_stmt_tree ())
1168 add_tree (build_min_nt (CLEANUP_STMT, decl, cleanup));
b35d4555
MM
1169 else if (!decl
1170 || (DECL_SIZE (decl) && TREE_TYPE (decl) != error_mark_node))
24bef158
MM
1171 expand_decl_cleanup (decl, cleanup);
1172}
1173
558475f0
MM
1174/* Bind a name and initialization to the return value of
1175 the current function. */
1176
1177void
1178finish_named_return_value (return_id, init)
1179 tree return_id, init;
1180{
1181 tree decl = DECL_RESULT (current_function_decl);
1182
1183 if (pedantic)
1184 /* Give this error as many times as there are occurrences,
1185 so that users can use Emacs compilation buffers to find
1186 and fix all such places. */
cab1f180 1187 pedwarn ("ISO C++ does not permit named return values");
558475f0
MM
1188
1189 if (return_id != NULL_TREE)
1190 {
1191 if (DECL_NAME (decl) == NULL_TREE)
1192 {
1193 DECL_NAME (decl) = return_id;
1194 DECL_ASSEMBLER_NAME (decl) = return_id;
1195 }
1196 else
1197 {
1198 cp_error ("return identifier `%D' already in place", return_id);
1199 return;
1200 }
1201 }
1202
1203 /* Can't let this happen for constructors. */
1204 if (DECL_CONSTRUCTOR_P (current_function_decl))
1205 {
1206 error ("can't redefine default return value for constructors");
1207 return;
1208 }
1209
1210 /* If we have a named return value, put that in our scope as well. */
1211 if (DECL_NAME (decl) != NULL_TREE)
1212 {
1213 /* Let `cp_finish_decl' know that this initializer is ok. */
1214 DECL_INITIAL (decl) = init;
b35d4555
MM
1215 if (doing_semantic_analysis_p ())
1216 pushdecl (decl);
558475f0
MM
1217
1218 if (building_stmt_tree ())
2a1e9fdd 1219 add_tree (build_min_nt (RETURN_INIT, return_id, init));
558475f0
MM
1220 else
1221 {
cd9f6678 1222 cp_finish_decl (decl, init, NULL_TREE, 0);
558475f0
MM
1223 store_return_init (decl);
1224 }
1225 }
f0ad3f46
MM
1226
1227 /* Don't use tree-inlining for functions with named return values.
1228 That doesn't work properly because we don't do any translation of
1229 the RETURN_INITs when they are copied. */
1230 DECL_UNINLINABLE (current_function_decl) = 1;
558475f0
MM
1231}
1232
1233/* Cache the value of this class's main virtual function table pointer
1234 in a register variable. This will save one indirection if a
1235 more than one virtual function call is made this function. */
1236
1237void
fd74ca0b
MM
1238setup_vtbl_ptr (member_init_list, base_init_list)
1239 tree member_init_list;
1240 tree base_init_list;
558475f0 1241{
9bfadf57
MM
1242 my_friendly_assert (doing_semantic_analysis_p (), 19990919);
1243
1244 /* If we've already done this, there's no need to do it again. */
1245 if (vtbls_set_up_p)
1246 return;
1247
1248 if (DECL_CONSTRUCTOR_P (current_function_decl))
558475f0 1249 {
9bfadf57 1250 if (processing_template_decl)
558475f0
MM
1251 add_tree (build_min_nt
1252 (CTOR_INITIALIZER,
fd74ca0b 1253 member_init_list, base_init_list));
558475f0 1254 else
46e8c075
MM
1255 {
1256 tree ctor_stmt;
1257
1258 /* Mark the beginning of the constructor. */
1259 ctor_stmt = build_min_nt (CTOR_STMT);
1260 CTOR_BEGIN_P (ctor_stmt) = 1;
1261 add_tree (ctor_stmt);
1262
1263 /* And actually initialize the base-classes and members. */
fd74ca0b 1264 emit_base_init (member_init_list, base_init_list);
46e8c075 1265 }
9bfadf57
MM
1266 }
1267 else if (DECL_DESTRUCTOR_P (current_function_decl)
1268 && !processing_template_decl)
1269 {
9bfadf57
MM
1270 tree if_stmt;
1271 tree compound_stmt;
f9817201 1272 int saved_cfnd;
9bfadf57 1273
3ec6bad3
MM
1274 /* If the dtor is empty, and we know there is not any possible
1275 way we could use any vtable entries, before they are possibly
1276 set by a base class dtor, we don't have to setup the vtables,
1277 as we know that any base class dtor will set up any vtables
1278 it needs. We avoid MI, because one base class dtor can do a
9bfadf57
MM
1279 virtual dispatch to an overridden function that would need to
1280 have a non-related vtable set up, we cannot avoid setting up
3ec6bad3
MM
1281 vtables in that case. We could change this to see if there
1282 is just one vtable. */
9bfadf57
MM
1283 if_stmt = begin_if_stmt ();
1284
1285 /* If it is not safe to avoid setting up the vtables, then
1286 someone will change the condition to be boolean_true_node.
1287 (Actually, for now, we do not have code to set the condition
f9817201 1288 appropriately, so we just assume that we always need to
9bfadf57
MM
1289 initialize the vtables.) */
1290 finish_if_stmt_cond (boolean_true_node, if_stmt);
1291 current_vcalls_possible_p = &IF_COND (if_stmt);
f9817201
MM
1292
1293 /* Don't declare __PRETTY_FUNCTION__ and friends here when we
1294 open the block for the if-body. */
1295 saved_cfnd = current_function_name_declared;
1296 current_function_name_declared = 1;
9bfadf57 1297 compound_stmt = begin_compound_stmt (/*has_no_scope=*/0);
f9817201 1298 current_function_name_declared = saved_cfnd;
9bfadf57
MM
1299
1300 /* Make all virtual function table pointers in non-virtual base
1301 classes point to CURRENT_CLASS_TYPE's virtual function
1302 tables. */
cf2e003b 1303 initialize_vtbl_ptrs (current_class_ptr);
9bfadf57
MM
1304
1305 finish_compound_stmt (/*has_no_scope=*/0, compound_stmt);
1306 finish_then_clause (if_stmt);
1307 finish_if_stmt ();
558475f0 1308 }
f1dedc31
MM
1309
1310 /* Always keep the BLOCK node associated with the outermost pair of
9bfadf57 1311 curly braces of a function. These are needed for correct
f1dedc31
MM
1312 operation of dwarfout.c. */
1313 keep_next_level (1);
9bfadf57
MM
1314
1315 /* The virtual function tables are set up now. */
1316 vtbls_set_up_p = 1;
558475f0
MM
1317}
1318
8f471b0d
MM
1319/* Add a scope-statement to the statement-tree. BEGIN_P indicates
1320 whether this statements opens or closes a scope. PARTIAL_P is true
1321 for a partial scope, i.e, the scope that begins after a label when
d9b2d9da
MM
1322 an object that needs a cleanup is created. If BEGIN_P is nonzero,
1323 returns a new TREE_LIST representing the top of the SCOPE_STMT
1324 stack. The TREE_PURPOSE is the new SCOPE_STMT. If BEGIN_P is
1325 zero, returns a TREE_LIST whose TREE_VALUE is the new SCOPE_STMT,
1326 and whose TREE_PURPOSE is the matching SCOPE_STMT iwth
1327 SCOPE_BEGIN_P set. */
8f471b0d 1328
d9b2d9da 1329tree
8f471b0d
MM
1330add_scope_stmt (begin_p, partial_p)
1331 int begin_p;
1332 int partial_p;
1333{
1334 tree ss;
d9b2d9da 1335 tree top;
8f471b0d
MM
1336
1337 /* Build the statement. */
d9b2d9da 1338 ss = build_min_nt (SCOPE_STMT, NULL_TREE);
8f471b0d
MM
1339 SCOPE_BEGIN_P (ss) = begin_p;
1340 SCOPE_PARTIAL_P (ss) = partial_p;
1341
8f471b0d
MM
1342 /* Keep the scope stack up to date. */
1343 if (begin_p)
d9b2d9da
MM
1344 {
1345 current_scope_stmt_stack
1346 = tree_cons (ss, NULL_TREE, current_scope_stmt_stack);
1347 top = current_scope_stmt_stack;
1348 }
8f471b0d 1349 else
d9b2d9da
MM
1350 {
1351 top = current_scope_stmt_stack;
1352 TREE_VALUE (top) = ss;
1353 current_scope_stmt_stack = TREE_CHAIN (top);
1354 }
8f471b0d
MM
1355
1356 /* Add the new statement to the statement-tree. */
1357 add_tree (ss);
d9b2d9da
MM
1358
1359 return top;
8f471b0d
MM
1360}
1361
558475f0
MM
1362/* Begin a new scope. */
1363
b35d4555 1364void
558475f0
MM
1365do_pushlevel ()
1366{
1367 if (!building_stmt_tree ())
1368 {
1369 emit_line_note (input_filename, lineno);
1370 clear_last_expr ();
1371 }
f1dedc31 1372 if (stmts_are_full_exprs_p)
b35d4555
MM
1373 {
1374 pushlevel (0);
1375 if (!building_stmt_tree ()
01d939e8 1376 && !cfun->x_whole_function_mode_p)
d9b2d9da
MM
1377 my_friendly_abort (19991129);
1378
1379 if (building_stmt_tree () && !processing_template_decl)
8f471b0d 1380 add_scope_stmt (/*begin_p=*/1, /*partial_p=*/0);
b35d4555 1381 }
f1dedc31 1382}
558475f0
MM
1383
1384/* Finish a scope. */
1385
b35d4555 1386tree
558475f0
MM
1387do_poplevel ()
1388{
d9b2d9da 1389 tree block = NULL_TREE;
558475f0 1390
f1dedc31 1391 if (stmts_are_full_exprs_p)
b35d4555 1392 {
d9b2d9da 1393 tree scope_stmts;
d9b2d9da
MM
1394
1395 if (building_stmt_tree () && !processing_template_decl)
1396 scope_stmts = add_scope_stmt (/*begin_p=*/0, /*partial_p=*/0);
1397 else
1398 scope_stmts = NULL_TREE;
1399
1400 block = poplevel (kept_level_p (), 1, 0);
1401 if (block && !processing_template_decl)
b35d4555 1402 {
d9b2d9da
MM
1403 SCOPE_STMT_BLOCK (TREE_PURPOSE (scope_stmts)) = block;
1404 SCOPE_STMT_BLOCK (TREE_VALUE (scope_stmts)) = block;
b35d4555 1405 }
b35d4555 1406 }
d9b2d9da
MM
1407
1408 return block;
558475f0
MM
1409}
1410
b4c4a9ec
MM
1411/* Finish a parenthesized expression EXPR. */
1412
1413tree
1414finish_parenthesized_expr (expr)
1415 tree expr;
1416{
1417 if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (TREE_CODE (expr))))
1418 /* This inhibits warnings in truthvalue_conversion. */
1419 C_SET_EXP_ORIGINAL_CODE (expr, ERROR_MARK);
1420
1421 return expr;
1422}
1423
b69b1501
MM
1424/* Begin a statement-expression. The value returned must be passed to
1425 finish_stmt_expr. */
b4c4a9ec
MM
1426
1427tree
1428begin_stmt_expr ()
1429{
6f80451c
MM
1430 /* If we're outside a function, we won't have a statement-tree to
1431 work with. But, if we see a statement-expression we need to
1432 create one. */
01d939e8 1433 if (! cfun && !last_tree)
6f80451c
MM
1434 begin_stmt_tree (&scope_chain->x_saved_tree);
1435
f1dedc31 1436 keep_next_level (1);
558475f0 1437 /* If we're building a statement tree, then the upcoming compound
b69b1501
MM
1438 statement will be chained onto the tree structure, starting at
1439 last_tree. We return last_tree so that we can later unhook the
1440 compound statement. */
558475f0 1441 return building_stmt_tree () ? last_tree : expand_start_stmt_expr();
b4c4a9ec
MM
1442}
1443
1444/* Finish a statement-expression. RTL_EXPR should be the value
1445 returned by the previous begin_stmt_expr; EXPR is the
1446 statement-expression. Returns an expression representing the
1447 statement-expression. */
1448
1449tree
5ba57b55 1450finish_stmt_expr (rtl_expr)
b4c4a9ec 1451 tree rtl_expr;
b4c4a9ec
MM
1452{
1453 tree result;
1454
558475f0 1455 if (!building_stmt_tree ())
c557501d 1456 rtl_expr = expand_end_stmt_expr (rtl_expr);
b4c4a9ec 1457
558475f0 1458 if (building_stmt_tree ())
b69b1501 1459 {
f1dedc31
MM
1460 /* If the last thing in the statement-expression was not an
1461 expression-statement, then it has type `void'. */
1462 if (!last_expr_type)
1463 last_expr_type = void_type_node;
1464 result = build_min (STMT_EXPR, last_expr_type, last_tree);
1465 TREE_SIDE_EFFECTS (result) = 1;
1466
b69b1501 1467 /* Remove the compound statement from the tree structure; it is
558475f0 1468 now saved in the STMT_EXPR. */
6f80451c 1469 SET_LAST_STMT (rtl_expr);
b69b1501
MM
1470 TREE_CHAIN (last_tree) = NULL_TREE;
1471 }
5ba57b55 1472 else
f1dedc31
MM
1473 result = rtl_expr;
1474
6f80451c
MM
1475 /* If we created a statement-tree for this statement-expression,
1476 remove it now. */
01d939e8 1477 if (! cfun
6f80451c
MM
1478 && TREE_CHAIN (scope_chain->x_saved_tree) == NULL_TREE)
1479 finish_stmt_tree (&scope_chain->x_saved_tree);
1480
b4c4a9ec
MM
1481 return result;
1482}
1483
1484/* Finish a call to FN with ARGS. Returns a representation of the
1485 call. */
1486
1487tree
a759e627 1488finish_call_expr (fn, args, koenig)
b4c4a9ec
MM
1489 tree fn;
1490 tree args;
a759e627 1491 int koenig;
b4c4a9ec 1492{
a759e627
ML
1493 tree result;
1494
1495 if (koenig)
03d82991
JM
1496 {
1497 if (TREE_CODE (fn) == BIT_NOT_EXPR)
1498 fn = build_x_unary_op (BIT_NOT_EXPR, TREE_OPERAND (fn, 0));
1499 else if (TREE_CODE (fn) != TEMPLATE_ID_EXPR)
e13a4123 1500 fn = do_identifier (fn, 2, args);
03d82991 1501 }
a759e627 1502 result = build_x_function_call (fn, args, current_class_ref);
b4c4a9ec
MM
1503
1504 if (TREE_CODE (result) == CALL_EXPR
66543169
NS
1505 && (! TREE_TYPE (result)
1506 || TREE_CODE (TREE_TYPE (result)) != VOID_TYPE))
b4c4a9ec
MM
1507 result = require_complete_type (result);
1508
1509 return result;
1510}
1511
1512/* Finish a call to a postfix increment or decrement or EXPR. (Which
1513 is indicated by CODE, which should be POSTINCREMENT_EXPR or
1514 POSTDECREMENT_EXPR.) */
1515
1516tree
1517finish_increment_expr (expr, code)
1518 tree expr;
1519 enum tree_code code;
1520{
1521 /* If we get an OFFSET_REF, turn it into what it really means (e.g.,
1522 a COMPONENT_REF). This way if we've got, say, a reference to a
1523 static member that's being operated on, we don't end up trying to
1524 find a member operator for the class it's in. */
1525
1526 if (TREE_CODE (expr) == OFFSET_REF)
1527 expr = resolve_offset_ref (expr);
1528 return build_x_unary_op (code, expr);
1529}
1530
1531/* Finish a use of `this'. Returns an expression for `this'. */
1532
1533tree
1534finish_this_expr ()
1535{
1536 tree result;
1537
1538 if (current_class_ptr)
1539 {
1540#ifdef WARNING_ABOUT_CCD
1541 TREE_USED (current_class_ptr) = 1;
1542#endif
1543 result = current_class_ptr;
1544 }
1545 else if (current_function_decl
1546 && DECL_STATIC_FUNCTION_P (current_function_decl))
1547 {
8251199e 1548 error ("`this' is unavailable for static member functions");
b4c4a9ec
MM
1549 result = error_mark_node;
1550 }
1551 else
1552 {
1553 if (current_function_decl)
8251199e 1554 error ("invalid use of `this' in non-member function");
b4c4a9ec 1555 else
8251199e 1556 error ("invalid use of `this' at top level");
b4c4a9ec
MM
1557 result = error_mark_node;
1558 }
1559
1560 return result;
1561}
1562
1563/* Finish a member function call using OBJECT and ARGS as arguments to
1564 FN. Returns an expression for the call. */
1565
1566tree
1567finish_object_call_expr (fn, object, args)
1568 tree fn;
1569 tree object;
1570 tree args;
1571{
1572#if 0
1573 /* This is a future direction of this code, but because
1574 build_x_function_call cannot always undo what is done in
1575 build_component_ref entirely yet, we cannot do this. */
1576
1577 tree real_fn = build_component_ref (object, fn, NULL_TREE, 1);
1578 return finish_call_expr (real_fn, args);
1579#else
c219b878 1580 if (DECL_DECLARES_TYPE_P (fn))
c68c56f7
MM
1581 {
1582 if (processing_template_decl)
1583 /* This can happen on code like:
1584
1585 class X;
1586 template <class T> void f(T t) {
1587 t.X();
1588 }
1589
1590 We just grab the underlying IDENTIFIER. */
1591 fn = DECL_NAME (fn);
1592 else
1593 {
8251199e 1594 cp_error ("calling type `%T' like a method", fn);
c68c56f7
MM
1595 return error_mark_node;
1596 }
1597 }
1598
b4c4a9ec
MM
1599 return build_method_call (object, fn, args, NULL_TREE, LOOKUP_NORMAL);
1600#endif
1601}
1602
1603/* Finish a qualified member function call using OBJECT and ARGS as
1604 arguments to FN. Returns an expressino for the call. */
1605
1606tree
1607finish_qualified_object_call_expr (fn, object, args)
1608 tree fn;
1609 tree object;
1610 tree args;
1611{
6eabb241
MM
1612 return build_scoped_method_call (object, TREE_OPERAND (fn, 0),
1613 TREE_OPERAND (fn, 1), args);
b4c4a9ec
MM
1614}
1615
1616/* Finish a pseudo-destructor call expression of OBJECT, with SCOPE
1617 being the scope, if any, of DESTRUCTOR. Returns an expression for
1618 the call. */
1619
1620tree
1621finish_pseudo_destructor_call_expr (object, scope, destructor)
1622 tree object;
1623 tree scope;
1624 tree destructor;
1625{
40242ccf
MM
1626 if (processing_template_decl)
1627 return build_min_nt (PSEUDO_DTOR_EXPR, object, scope, destructor);
1628
b4c4a9ec 1629 if (scope && scope != destructor)
8251199e 1630 cp_error ("destructor specifier `%T::~%T()' must have matching names",
b4c4a9ec
MM
1631 scope, destructor);
1632
1633 if ((scope == NULL_TREE || IDENTIFIER_GLOBAL_VALUE (destructor))
1634 && (TREE_CODE (TREE_TYPE (object)) !=
1635 TREE_CODE (TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (destructor)))))
8251199e 1636 cp_error ("`%E' is not of type `%T'", object, destructor);
b4c4a9ec
MM
1637
1638 return cp_convert (void_type_node, object);
1639}
1640
1641/* Finish a call to a globally qualified member function FN using
1642 ARGS. Returns an expression for the call. */
1643
1644tree
75d587eb 1645finish_qualified_call_expr (fn, args)
b4c4a9ec
MM
1646 tree fn;
1647 tree args;
1648{
1649 if (processing_template_decl)
2a1e9fdd 1650 return build_min_nt (CALL_EXPR, fn, args, NULL_TREE);
b4c4a9ec
MM
1651 else
1652 return build_member_call (TREE_OPERAND (fn, 0),
1653 TREE_OPERAND (fn, 1),
1654 args);
1655}
1656
1657/* Finish an expression taking the address of LABEL. Returns an
1658 expression for the address. */
1659
1660tree
1661finish_label_address_expr (label)
1662 tree label;
1663{
1664 tree result;
1665
1666 label = lookup_label (label);
1667 if (label == NULL_TREE)
1668 result = null_pointer_node;
1669 else
1670 {
1671 TREE_USED (label) = 1;
1672 result = build1 (ADDR_EXPR, ptr_type_node, label);
1673 TREE_CONSTANT (result) = 1;
46e8c075
MM
1674 /* This function cannot be inlined. All jumps to the addressed
1675 label should wind up at the same point. */
1676 DECL_UNINLINABLE (current_function_decl) = 1;
b4c4a9ec
MM
1677 }
1678
1679 return result;
1680}
1681
ce4a0391
MM
1682/* Finish an expression of the form CODE EXPR. */
1683
1684tree
1685finish_unary_op_expr (code, expr)
1686 enum tree_code code;
1687 tree expr;
1688{
1689 tree result = build_x_unary_op (code, expr);
7c355bca
ML
1690 /* Inside a template, build_x_unary_op does not fold the
1691 expression. So check whether the result is folded before
1692 setting TREE_NEGATED_INT. */
1693 if (code == NEGATE_EXPR && TREE_CODE (expr) == INTEGER_CST
88b4335f
NS
1694 && TREE_CODE (result) == INTEGER_CST
1695 && !TREE_UNSIGNED (TREE_TYPE (result))
1696 && INT_CST_LT (result, integer_zero_node))
ce4a0391
MM
1697 TREE_NEGATED_INT (result) = 1;
1698 overflow_warning (result);
1699 return result;
1700}
1701
1702/* Finish an id-expression. */
1703
1704tree
1705finish_id_expr (expr)
1706 tree expr;
1707{
1708 if (TREE_CODE (expr) == IDENTIFIER_NODE)
a759e627 1709 expr = do_identifier (expr, 1, NULL_TREE);
ce4a0391
MM
1710
1711 return expr;
1712}
1713
70adf8a9
JM
1714static tree current_type_lookups;
1715
1716/* Perform deferred access control for types used in the type of a
1717 declaration. */
1718
1f51a992 1719static void
70adf8a9
JM
1720deferred_type_access_control ()
1721{
1f51a992 1722 tree lookup = type_lookups;
70adf8a9
JM
1723
1724 if (lookup == error_mark_node)
1725 return;
1726
1727 for (; lookup; lookup = TREE_CHAIN (lookup))
1728 enforce_access (TREE_PURPOSE (lookup), TREE_VALUE (lookup));
1729}
1730
70adf8a9 1731void
1f51a992
JM
1732decl_type_access_control (decl)
1733 tree decl;
70adf8a9 1734{
1f51a992 1735 tree save_fn;
70adf8a9 1736
1f51a992
JM
1737 if (type_lookups == error_mark_node)
1738 return;
1739
1740 save_fn = current_function_decl;
1741
1742 if (decl && TREE_CODE (decl) == FUNCTION_DECL)
1743 current_function_decl = decl;
70adf8a9 1744
70adf8a9 1745 deferred_type_access_control ();
1f51a992
JM
1746
1747 current_function_decl = save_fn;
1748
1749 /* Now strip away the checks for the current declarator; they were
1750 added to type_lookups after typed_declspecs saved the copy that
1751 ended up in current_type_lookups. */
1752 type_lookups = current_type_lookups;
1753}
1754
1755void
1756save_type_access_control (lookups)
1757 tree lookups;
1758{
1759 current_type_lookups = lookups;
1760}
70adf8a9
JM
1761
1762/* Begin a function definition declared with DECL_SPECS and
b4c4a9ec
MM
1763 DECLARATOR. Returns non-zero if the function-declaration is
1764 legal. */
1765
1766int
1f51a992 1767begin_function_definition (decl_specs, declarator)
b4c4a9ec
MM
1768 tree decl_specs;
1769 tree declarator;
1770{
1771 tree specs;
1772 tree attrs;
70adf8a9 1773
b4c4a9ec 1774 split_specs_attrs (decl_specs, &specs, &attrs);
a8f73d4b 1775 if (!start_function (specs, declarator, attrs, SF_DEFAULT))
b4c4a9ec 1776 return 0;
1f51a992
JM
1777
1778 deferred_type_access_control ();
1779 type_lookups = error_mark_node;
1780
39c01e4c
MM
1781 /* The things we're about to see are not directly qualified by any
1782 template headers we've seen thus far. */
1783 reset_specialization ();
1784
b4c4a9ec
MM
1785 return 1;
1786}
1787
1788/* Begin a constructor declarator of the form `SCOPE::NAME'. Returns
1789 a SCOPE_REF. */
1790
1791tree
1792begin_constructor_declarator (scope, name)
1793 tree scope;
1794 tree name;
1795{
1796 tree result = build_parse_node (SCOPE_REF, scope, name);
830fcda8 1797 enter_scope_of (result);
b4c4a9ec
MM
1798 return result;
1799}
1800
ce4a0391
MM
1801/* Finish an init-declarator. Returns a DECL. */
1802
1803tree
1804finish_declarator (declarator, declspecs, attributes,
1805 prefix_attributes, initialized)
1806 tree declarator;
1807 tree declspecs;
1808 tree attributes;
1809 tree prefix_attributes;
1810 int initialized;
1811{
1812 return start_decl (declarator, declspecs, initialized, attributes,
1813 prefix_attributes);
1814}
1815
8014a339 1816/* Finish a translation unit. */
ce4a0391
MM
1817
1818void
1819finish_translation_unit ()
1820{
1821 /* In case there were missing closebraces,
1822 get us back to the global binding level. */
273a708f 1823 pop_everything ();
ce4a0391
MM
1824 while (current_namespace != global_namespace)
1825 pop_namespace ();
1826 finish_file ();
1827}
1828
b4c4a9ec
MM
1829/* Finish a template type parameter, specified as AGGR IDENTIFIER.
1830 Returns the parameter. */
1831
1832tree
1833finish_template_type_parm (aggr, identifier)
1834 tree aggr;
1835 tree identifier;
1836{
6eabb241 1837 if (aggr != class_type_node)
b4c4a9ec 1838 {
8251199e 1839 pedwarn ("template type parameters must use the keyword `class' or `typename'");
b4c4a9ec
MM
1840 aggr = class_type_node;
1841 }
1842
1843 return build_tree_list (aggr, identifier);
1844}
1845
1846/* Finish a template template parameter, specified as AGGR IDENTIFIER.
1847 Returns the parameter. */
1848
1849tree
1850finish_template_template_parm (aggr, identifier)
1851 tree aggr;
1852 tree identifier;
1853{
1854 tree decl = build_decl (TYPE_DECL, identifier, NULL_TREE);
1855 tree tmpl = build_lang_decl (TEMPLATE_DECL, identifier, NULL_TREE);
1856 DECL_TEMPLATE_PARMS (tmpl) = current_template_parms;
1857 DECL_TEMPLATE_RESULT (tmpl) = decl;
1858 SET_DECL_ARTIFICIAL (decl);
1859 end_template_decl ();
1860
1861 return finish_template_type_parm (aggr, tmpl);
1862}
ce4a0391
MM
1863
1864/* Finish a parameter list, indicated by PARMS. If ELLIPSIS is
1865 non-zero, the parameter list was terminated by a `...'. */
1866
1867tree
1868finish_parmlist (parms, ellipsis)
1869 tree parms;
1870 int ellipsis;
1871{
1872 if (!ellipsis)
1873 chainon (parms, void_list_node);
1874 /* We mark the PARMS as a parmlist so that declarator processing can
1875 disambiguate certain constructs. */
1876 if (parms != NULL_TREE)
1877 TREE_PARMLIST (parms) = 1;
1878
1879 return parms;
1880}
1881
1882/* Begin a class definition, as indicated by T. */
1883
1884tree
1885begin_class_definition (t)
1886 tree t;
1887{
ce4a0391
MM
1888 if (t == error_mark_node
1889 || ! IS_AGGR_TYPE (t))
1890 {
33848bb0 1891 t = make_aggr_type (RECORD_TYPE);
ce4a0391
MM
1892 pushtag (make_anon_name (), t, 0);
1893 }
830fcda8
JM
1894
1895 /* In a definition of a member class template, we will get here with an
1896 implicit typename, a TYPENAME_TYPE with a type. */
1897 if (TREE_CODE (t) == TYPENAME_TYPE)
1898 t = TREE_TYPE (t);
4c571114
MM
1899
1900 /* If we generated a partial instantiation of this type, but now
1901 we're seeing a real definition, we're actually looking at a
1902 partial specialization. Consider:
1903
1904 template <class T, class U>
1905 struct Y {};
1906
1907 template <class T>
1908 struct X {};
1909
1910 template <class T, class U>
1911 void f()
1912 {
1913 typename X<Y<T, U> >::A a;
1914 }
1915
1916 template <class T, class U>
1917 struct X<Y<T, U> >
1918 {
1919 };
1920
1921 We have to undo the effects of the previous partial
1922 instantiation. */
1923 if (PARTIAL_INSTANTIATION_P (t))
1924 {
1925 if (!pedantic)
1926 {
1927 /* Unfortunately, when we're not in pedantic mode, we
1928 attempt to actually fill in some of the fields of the
1929 partial instantiation, in order to support the implicit
1930 typename extension. Clear those fields now, in
1931 preparation for the definition here. The fields cleared
1932 here must match those set in instantiate_class_template.
1933 Look for a comment mentioning begin_class_definition
1934 there. */
1935 TYPE_BINFO_BASETYPES (t) = NULL_TREE;
1936 TYPE_FIELDS (t) = NULL_TREE;
1937 TYPE_METHODS (t) = NULL_TREE;
1938 CLASSTYPE_TAGS (t) = NULL_TREE;
1939 TYPE_SIZE (t) = NULL_TREE;
1940 }
830fcda8 1941
4c571114
MM
1942 /* This isn't a partial instantiation any more. */
1943 PARTIAL_INSTANTIATION_P (t) = 0;
1944 }
1945 /* If this type was already complete, and we see another definition,
1946 that's an error. */
d0f062fb 1947 else if (COMPLETE_TYPE_P (t))
ce4a0391 1948 duplicate_tag_error (t);
4c571114 1949
b4f70b3d
NS
1950 /* Update the location of the decl. */
1951 DECL_SOURCE_FILE (TYPE_NAME (t)) = input_filename;
1952 DECL_SOURCE_LINE (TYPE_NAME (t)) = lineno;
1953
4c571114 1954 if (TYPE_BEING_DEFINED (t))
ce4a0391 1955 {
33848bb0 1956 t = make_aggr_type (TREE_CODE (t));
ce4a0391 1957 pushtag (TYPE_IDENTIFIER (t), t, 0);
ce4a0391 1958 }
ff350acd 1959 maybe_process_partial_specialization (t);
8f032717 1960 pushclass (t, 1);
ce4a0391 1961 TYPE_BEING_DEFINED (t) = 1;
55760a0c 1962 TYPE_PACKED (t) = flag_pack_struct;
ce4a0391
MM
1963 /* Reset the interface data, at the earliest possible
1964 moment, as it might have been set via a class foo;
1965 before. */
6eabb241
MM
1966 {
1967 tree name = TYPE_IDENTIFIER (t);
1968
1969 if (! ANON_AGGRNAME_P (name))
1970 {
1971 CLASSTYPE_INTERFACE_ONLY (t) = interface_only;
1972 SET_CLASSTYPE_INTERFACE_UNKNOWN_X
1973 (t, interface_unknown);
1974 }
1975
1976 /* Only leave this bit clear if we know this
1977 class is part of an interface-only specification. */
1978 if (! CLASSTYPE_INTERFACE_KNOWN (t)
1979 || ! CLASSTYPE_INTERFACE_ONLY (t))
1980 CLASSTYPE_VTABLE_NEEDS_WRITING (t) = 1;
1981 }
ce4a0391
MM
1982 reset_specialization();
1983
b7975aed
MM
1984 /* Make a declaration for this class in its own scope. */
1985 build_self_reference ();
1986
830fcda8 1987 return t;
ce4a0391
MM
1988}
1989
61a127b3
MM
1990/* Finish the member declaration given by DECL. */
1991
1992void
1993finish_member_declaration (decl)
1994 tree decl;
1995{
1996 if (decl == error_mark_node || decl == NULL_TREE)
1997 return;
1998
1999 if (decl == void_type_node)
2000 /* The COMPONENT was a friend, not a member, and so there's
2001 nothing for us to do. */
2002 return;
2003
2004 /* We should see only one DECL at a time. */
2005 my_friendly_assert (TREE_CHAIN (decl) == NULL_TREE, 0);
2006
2007 /* Set up access control for DECL. */
2008 TREE_PRIVATE (decl)
2009 = (current_access_specifier == access_private_node);
2010 TREE_PROTECTED (decl)
2011 = (current_access_specifier == access_protected_node);
2012 if (TREE_CODE (decl) == TEMPLATE_DECL)
2013 {
17aec3eb
RK
2014 TREE_PRIVATE (DECL_TEMPLATE_RESULT (decl)) = TREE_PRIVATE (decl);
2015 TREE_PROTECTED (DECL_TEMPLATE_RESULT (decl)) = TREE_PROTECTED (decl);
61a127b3
MM
2016 }
2017
2018 /* Mark the DECL as a member of the current class. */
4f1c5b7d 2019 DECL_CONTEXT (decl) = current_class_type;
61a127b3 2020
421844e7
MM
2021 /* [dcl.link]
2022
2023 A C language linkage is ignored for the names of class members
2024 and the member function type of class member functions. */
2025 if (DECL_LANG_SPECIFIC (decl) && DECL_LANGUAGE (decl) == lang_c)
2026 DECL_LANGUAGE (decl) = lang_cplusplus;
2027
61a127b3
MM
2028 /* Put functions on the TYPE_METHODS list and everything else on the
2029 TYPE_FIELDS list. Note that these are built up in reverse order.
2030 We reverse them (to obtain declaration order) in finish_struct. */
2031 if (TREE_CODE (decl) == FUNCTION_DECL
2032 || DECL_FUNCTION_TEMPLATE_P (decl))
2033 {
2034 /* We also need to add this function to the
2035 CLASSTYPE_METHOD_VEC. */
2036 add_method (current_class_type, 0, decl);
2037
2038 TREE_CHAIN (decl) = TYPE_METHODS (current_class_type);
2039 TYPE_METHODS (current_class_type) = decl;
2040 }
2041 else
2042 {
2043 /* All TYPE_DECLs go at the end of TYPE_FIELDS. Ordinary fields
2044 go at the beginning. The reason is that lookup_field_1
2045 searches the list in order, and we want a field name to
2046 override a type name so that the "struct stat hack" will
2047 work. In particular:
2048
2049 struct S { enum E { }; int E } s;
2050 s.E = 3;
2051
2052 is legal. In addition, the FIELD_DECLs must be maintained in
2053 declaration order so that class layout works as expected.
2054 However, we don't need that order until class layout, so we
2055 save a little time by putting FIELD_DECLs on in reverse order
2056 here, and then reversing them in finish_struct_1. (We could
2057 also keep a pointer to the correct insertion points in the
2058 list.) */
2059
2060 if (TREE_CODE (decl) == TYPE_DECL)
2061 TYPE_FIELDS (current_class_type)
2062 = chainon (TYPE_FIELDS (current_class_type), decl);
2063 else
2064 {
2065 TREE_CHAIN (decl) = TYPE_FIELDS (current_class_type);
2066 TYPE_FIELDS (current_class_type) = decl;
2067 }
8f032717
MM
2068
2069 /* Enter the DECL into the scope of the class. */
2070 if (TREE_CODE (decl) != USING_DECL)
2071 pushdecl_class_level (decl);
61a127b3
MM
2072 }
2073}
2074
2075/* Finish a class definition T with the indicate ATTRIBUTES. If SEMI,
2076 the definition is immediately followed by a semicolon. Returns the
2077 type. */
ce4a0391
MM
2078
2079tree
fbdd0024 2080finish_class_definition (t, attributes, semi, pop_scope_p)
ce4a0391 2081 tree t;
ce4a0391
MM
2082 tree attributes;
2083 int semi;
fbdd0024 2084 int pop_scope_p;
ce4a0391 2085{
ce4a0391
MM
2086 /* finish_struct nukes this anyway; if finish_exception does too,
2087 then it can go. */
2088 if (semi)
2089 note_got_semicolon (t);
2090
dc8263bc
JM
2091 /* If we got any attributes in class_head, xref_tag will stick them in
2092 TREE_TYPE of the type. Grab them now. */
2093 attributes = chainon (TREE_TYPE (t), attributes);
2094 TREE_TYPE (t) = NULL_TREE;
2095
ce4a0391
MM
2096 if (TREE_CODE (t) == ENUMERAL_TYPE)
2097 ;
2098 else
2099 {
9f33663b 2100 t = finish_struct (t, attributes);
ce4a0391
MM
2101 if (semi)
2102 note_got_semicolon (t);
2103 }
2104
ce4a0391
MM
2105 if (! semi)
2106 check_for_missing_semicolon (t);
fbdd0024
MM
2107 if (pop_scope_p)
2108 pop_scope (CP_DECL_CONTEXT (TYPE_MAIN_DECL (t)));
ce4a0391
MM
2109 if (current_scope () == current_function_decl)
2110 do_pending_defargs ();
2111
2112 return t;
2113}
2114
2115/* Finish processing the default argument expressions cached during
2116 the processing of a class definition. */
2117
2118void
51632249 2119begin_inline_definitions ()
ce4a0391
MM
2120{
2121 if (pending_inlines
2122 && current_scope () == current_function_decl)
2123 do_pending_inlines ();
2124}
2125
2126/* Finish processing the inline function definitions cached during the
2127 processing of a class definition. */
2128
2129void
51632249 2130finish_inline_definitions ()
ce4a0391
MM
2131{
2132 if (current_class_type == NULL_TREE)
2133 clear_inline_text_obstack ();
ce4a0391 2134}
35acd3f2
MM
2135
2136/* Finish processing the declaration of a member class template
2137 TYPES whose template parameters are given by PARMS. */
2138
2139tree
61a127b3 2140finish_member_class_template (types)
35acd3f2
MM
2141 tree types;
2142{
36a117a5
MM
2143 tree t;
2144
2145 /* If there are declared, but undefined, partial specializations
2146 mixed in with the typespecs they will not yet have passed through
2147 maybe_process_partial_specialization, so we do that here. */
2148 for (t = types; t != NULL_TREE; t = TREE_CHAIN (t))
2149 if (IS_AGGR_TYPE_CODE (TREE_CODE (TREE_VALUE (t))))
2150 maybe_process_partial_specialization (TREE_VALUE (t));
2151
35acd3f2 2152 note_list_got_semicolon (types);
61a127b3 2153 grok_x_components (types);
35acd3f2
MM
2154 if (TYPE_CONTEXT (TREE_VALUE (types)) != current_class_type)
2155 /* The component was in fact a friend declaration. We avoid
2156 finish_member_template_decl performing certain checks by
2157 unsetting TYPES. */
2158 types = NULL_TREE;
61a127b3
MM
2159
2160 finish_member_template_decl (types);
2161
35acd3f2
MM
2162 /* As with other component type declarations, we do
2163 not store the new DECL on the list of
2164 component_decls. */
2165 return NULL_TREE;
2166}
36a117a5
MM
2167
2168/* Finish processsing a complete template declaration. The PARMS are
2169 the template parameters. */
2170
2171void
2172finish_template_decl (parms)
2173 tree parms;
2174{
2175 if (parms)
2176 end_template_decl ();
2177 else
2178 end_specialization ();
2179}
2180
2181/* Finish processing a a template-id (which names a type) of the form
2182 NAME < ARGS >. Return the TYPE_DECL for the type named by the
2183 template-id. If ENTERING_SCOPE is non-zero we are about to enter
2184 the scope of template-id indicated. */
2185
2186tree
2187finish_template_type (name, args, entering_scope)
2188 tree name;
2189 tree args;
2190 int entering_scope;
2191{
2192 tree decl;
2193
2194 decl = lookup_template_class (name, args,
2195 NULL_TREE, NULL_TREE, entering_scope);
2196 if (decl != error_mark_node)
2197 decl = TYPE_STUB_DECL (decl);
2198
2199 return decl;
2200}
648f19f6
MM
2201
2202/* SR is a SCOPE_REF node. Enter the scope of SR, whether it is a
2203 namespace scope or a class scope. */
2204
2205void
2206enter_scope_of (sr)
2207 tree sr;
2208{
2209 tree scope = TREE_OPERAND (sr, 0);
2210
2211 if (TREE_CODE (scope) == NAMESPACE_DECL)
2212 {
2213 push_decl_namespace (scope);
2214 TREE_COMPLEXITY (sr) = -1;
2215 }
2216 else if (scope != current_class_type)
2217 {
830fcda8
JM
2218 if (TREE_CODE (scope) == TYPENAME_TYPE)
2219 {
2220 /* In a declarator for a template class member, the scope will
2221 get here as an implicit typename, a TYPENAME_TYPE with a type. */
2222 scope = TREE_TYPE (scope);
2223 TREE_OPERAND (sr, 0) = scope;
2224 }
648f19f6
MM
2225 push_nested_class (scope, 3);
2226 TREE_COMPLEXITY (sr) = current_class_depth;
2227 }
2228}
ea6021e8
MM
2229
2230/* Finish processing a BASE_CLASS with the indicated ACCESS_SPECIFIER.
2231 Return a TREE_LIST containing the ACCESS_SPECIFIER and the
2232 BASE_CLASS, or NULL_TREE if an error occurred. The
2233 ACCESSS_SPECIFIER is one of
2234 access_{default,public,protected_private}[_virtual]_node.*/
2235
2236tree
6eabb241 2237finish_base_specifier (access_specifier, base_class)
ea6021e8
MM
2238 tree access_specifier;
2239 tree base_class;
ea6021e8
MM
2240{
2241 tree type;
2242 tree result;
2243
2244 if (base_class == NULL_TREE)
2245 {
8251199e 2246 error ("invalid base class");
ea6021e8
MM
2247 type = error_mark_node;
2248 }
2249 else
2250 type = TREE_TYPE (base_class);
6eabb241 2251
ea6021e8
MM
2252 if (! is_aggr_type (type, 1))
2253 result = NULL_TREE;
ea6021e8
MM
2254 else
2255 result = build_tree_list (access_specifier, type);
2256
2257 return result;
2258}
61a127b3
MM
2259
2260/* Called when multiple declarators are processed. If that is not
2261 premitted in this context, an error is issued. */
2262
2263void
2264check_multiple_declarators ()
2265{
2266 /* [temp]
2267
2268 In a template-declaration, explicit specialization, or explicit
2269 instantiation the init-declarator-list in the declaration shall
2270 contain at most one declarator.
2271
2272 We don't just use PROCESSING_TEMPLATE_DECL for the first
2273 condition since that would disallow the perfectly legal code,
2274 like `template <class T> struct S { int i, j; };'. */
2275 tree scope = current_scope ();
2276
2277 if (scope && TREE_CODE (scope) == FUNCTION_DECL)
2278 /* It's OK to write `template <class T> void f() { int i, j;}'. */
2279 return;
2280
2281 if (PROCESSING_REAL_TEMPLATE_DECL_P ()
2282 || processing_explicit_instantiation
2283 || processing_specialization)
2284 cp_error ("multiple declarators in template declaration");
2285}
2286
b894fc05
JM
2287tree
2288finish_typeof (expr)
2289 tree expr;
2290{
2291 if (processing_template_decl)
2292 {
2293 tree t;
2294
33848bb0 2295 t = make_aggr_type (TYPEOF_TYPE);
b894fc05 2296 TYPE_FIELDS (t) = expr;
b894fc05
JM
2297
2298 return t;
2299 }
2300
2301 return TREE_TYPE (expr);
2302}
558475f0 2303
6f80451c 2304/* Create an empty statement tree rooted at T. */
558475f0
MM
2305
2306void
6f80451c
MM
2307begin_stmt_tree (t)
2308 tree *t;
558475f0
MM
2309{
2310 /* We create a trivial EXPR_STMT so that last_tree is never NULL in
2311 what follows. We remove the extraneous statement in
2312 finish_stmt_tree. */
6f80451c
MM
2313 *t = build_nt (EXPR_STMT, void_zero_node);
2314 SET_LAST_STMT (*t);
558475f0
MM
2315 last_expr_type = NULL_TREE;
2316}
2317
6f80451c 2318/* Finish the statement tree rooted at T. */
558475f0
MM
2319
2320void
6f80451c
MM
2321finish_stmt_tree (t)
2322 tree *t;
558475f0 2323{
a7e4cfa0
MM
2324 tree stmt;
2325
2326 /* Remove the fake extra statement added in begin_stmt_tree. */
6f80451c
MM
2327 stmt = TREE_CHAIN (*t);
2328 *t = stmt;
2329 SET_LAST_STMT (NULL_TREE);
a7e4cfa0 2330
01d939e8 2331 if (cfun)
6f80451c
MM
2332 {
2333 /* The line-number recorded in the outermost statement in a function
2334 is the line number of the end of the function. */
2335 STMT_LINENO (stmt) = lineno;
2336 STMT_LINENO_FOR_FN_P (stmt) = 1;
2337 }
a7e4cfa0
MM
2338}
2339
2340/* We're about to expand T, a statement. Set up appropriate context
2341 for the substitution. */
2342
2343void
2344prep_stmt (t)
2345 tree t;
2346{
2347 if (!STMT_LINENO_FOR_FN_P (t))
2348 lineno = STMT_LINENO (t);
2349 stmts_are_full_exprs_p = STMT_IS_FULL_EXPR_P (t);
558475f0
MM
2350}
2351
527f0080
MM
2352/* Some statements, like for-statements or if-statements, require a
2353 condition. This condition can be a declaration. If T is such a
2354 declaration it is processed, and an expression appropriate to use
2355 as the condition is returned. Otherwise, T itself is returned. */
2356
2357static tree
2358expand_cond (t)
2359 tree t;
2360{
ed5511d9 2361 if (t && TREE_CODE (t) == TREE_LIST)
527f0080 2362 {
ed5511d9
MM
2363 expand_stmt (TREE_PURPOSE (t));
2364 return TREE_VALUE (t);
527f0080
MM
2365 }
2366 else
2367 return t;
2368}
2369
62409b39
MM
2370/* Generate RTL for the statement T, and its substatements, and any
2371 other statements at its nesting level. */
558475f0
MM
2372
2373tree
2374expand_stmt (t)
2375 tree t;
2376{
47d7090e 2377 tree rval = NULL_TREE;
a7e4cfa0 2378
62409b39
MM
2379 while (t && t != error_mark_node)
2380 {
2381 int saved_stmts_are_full_exprs_p;
558475f0 2382
62409b39
MM
2383 /* Assume we'll have nothing to return. */
2384 rval = NULL_TREE;
a7e4cfa0 2385
62409b39
MM
2386 /* Set up context appropriately for handling this statement. */
2387 saved_stmts_are_full_exprs_p = stmts_are_full_exprs_p;
2388 prep_stmt (t);
a7e4cfa0 2389
62409b39
MM
2390 switch (TREE_CODE (t))
2391 {
2392 case RETURN_STMT:
2393 finish_return_stmt (RETURN_EXPR (t));
2394 break;
558475f0 2395
62409b39 2396 case EXPR_STMT:
9bfadf57 2397 finish_expr_stmt (EXPR_STMT_EXPR (t));
62409b39 2398 break;
558475f0 2399
62409b39 2400 case DECL_STMT:
acef433b 2401 {
62409b39 2402 tree decl;
62409b39
MM
2403
2404 emit_line_note (input_filename, lineno);
2405 decl = DECL_STMT_DECL (t);
b35d4555
MM
2406 /* If this is a declaration for an automatic local
2407 variable, initialize it. Note that we might also see a
2408 declaration for a namespace-scope object (declared with
9ed9e79a
MM
2409 `extern'). We don't have to handle the initialization
2410 of those objects here; they can only be declarations,
2411 rather than definitions. */
b35d4555
MM
2412 if (TREE_CODE (decl) == VAR_DECL
2413 && !TREE_STATIC (decl)
2414 && !DECL_EXTERNAL (decl))
0fa5e05c
MM
2415 {
2416 /* Let the back-end know about this variable. */
2417 if (!ANON_AGGR_TYPE_P (TREE_TYPE (decl)))
2418 emit_local_var (decl);
2419 else
2420 expand_anon_union_decl (decl, NULL_TREE,
2421 DECL_ANON_UNION_ELEMS (decl));
2422 }
cf74fb86
JM
2423 else if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl))
2424 {
2425 if (DECL_ARTIFICIAL (decl) && ! TREE_USED (decl))
2426 /* Do not emit unused decls. This is not just an
2427 optimization. We really do not want to emit
2428 __PRETTY_FUNCTION__ etc, if they're never used. */
2429 DECL_IGNORED_P (decl) = 1;
2430 else
2431 make_rtl_for_local_static (decl);
2432 }
acef433b 2433 }
62409b39 2434 break;
558475f0 2435
24bef158
MM
2436 case CLEANUP_STMT:
2437 finish_decl_cleanup (CLEANUP_DECL (t), CLEANUP_EXPR (t));
2438 break;
2439
b35d4555
MM
2440 case START_CATCH_STMT:
2441 begin_catch_block (TREE_TYPE (t));
2442 break;
2443
46e8c075
MM
2444 case CTOR_STMT:
2445 if (CTOR_BEGIN_P (t))
2446 begin_protect_partials ();
2447 else
2448 /* After this point, any exceptions will cause the
2449 destructor to be executed, so we no longer need to worry
2450 about destroying the various subobjects ourselves. */
2451 end_protect_partials ();
2452 break;
2453
62409b39
MM
2454 case FOR_STMT:
2455 {
2456 tree tmp;
2457
2458 begin_for_stmt ();
2459 expand_stmt (FOR_INIT_STMT (t));
2460 finish_for_init_stmt (NULL_TREE);
2461 finish_for_cond (expand_cond (FOR_COND (t)), NULL_TREE);
2462 tmp = FOR_EXPR (t);
2463 finish_for_expr (tmp, NULL_TREE);
2464 expand_stmt (FOR_BODY (t));
2465 finish_for_stmt (tmp, NULL_TREE);
2466 }
2467 break;
558475f0 2468
62409b39
MM
2469 case WHILE_STMT:
2470 {
2471 begin_while_stmt ();
2472 finish_while_stmt_cond (expand_cond (WHILE_COND (t)), NULL_TREE);
2473 expand_stmt (WHILE_BODY (t));
2474 finish_while_stmt (NULL_TREE);
2475 }
2476 break;
558475f0 2477
62409b39
MM
2478 case DO_STMT:
2479 {
2480 begin_do_stmt ();
2481 expand_stmt (DO_BODY (t));
2482 finish_do_body (NULL_TREE);
2483 finish_do_stmt (DO_COND (t), NULL_TREE);
2484 }
2485 break;
527f0080 2486
62409b39
MM
2487 case IF_STMT:
2488 begin_if_stmt ();
2489 finish_if_stmt_cond (expand_cond (IF_COND (t)), NULL_TREE);
2490 if (THEN_CLAUSE (t))
2491 {
2492 expand_stmt (THEN_CLAUSE (t));
2493 finish_then_clause (NULL_TREE);
2494 }
2495 if (ELSE_CLAUSE (t))
2496 {
2497 begin_else_clause ();
2498 expand_stmt (ELSE_CLAUSE (t));
2499 finish_else_clause (NULL_TREE);
2500 }
2501 finish_if_stmt ();
2502 break;
558475f0 2503
62409b39
MM
2504 case COMPOUND_STMT:
2505 begin_compound_stmt (COMPOUND_STMT_NO_SCOPE (t));
2506 expand_stmt (COMPOUND_BODY (t));
2507 rval = finish_compound_stmt (COMPOUND_STMT_NO_SCOPE (t),
2508 NULL_TREE);
2509 break;
558475f0 2510
62409b39
MM
2511 case BREAK_STMT:
2512 finish_break_stmt ();
2513 break;
558475f0 2514
62409b39
MM
2515 case CONTINUE_STMT:
2516 finish_continue_stmt ();
2517 break;
558475f0 2518
62409b39
MM
2519 case SWITCH_STMT:
2520 {
2521 tree cond;
558475f0 2522
62409b39
MM
2523 begin_switch_stmt ();
2524 cond = expand_cond (SWITCH_COND (t));
2525 finish_switch_cond (cond, NULL_TREE);
2526 expand_stmt (SWITCH_BODY (t));
2527 finish_switch_stmt (cond, NULL_TREE);
2528 }
2529 break;
2530
2531 case CASE_LABEL:
2532 finish_case_label (CASE_LOW (t), CASE_HIGH (t));
2533 break;
2534
2535 case LABEL_STMT:
b35d4555 2536 expand_label (LABEL_STMT_LABEL (t));
62409b39
MM
2537 break;
2538
2539 case GOTO_STMT:
b35d4555 2540 finish_goto_stmt (GOTO_DESTINATION (t));
62409b39
MM
2541 break;
2542
2543 case ASM_STMT:
2544 finish_asm_stmt (ASM_CV_QUAL (t), ASM_STRING (t), ASM_OUTPUTS
2545 (t), ASM_INPUTS (t), ASM_CLOBBERS (t));
2546 break;
2547
2548 case TRY_BLOCK:
2549 if (CLEANUP_P (t))
2550 {
2551 expand_eh_region_start ();
2552 expand_stmt (TRY_STMTS (t));
2553 finish_cleanup_try_block (NULL_TREE);
2554 finish_cleanup (TRY_HANDLERS (t), NULL_TREE);
2555 }
2556 else
2557 {
b35d4555
MM
2558 if (FN_TRY_BLOCK_P (t))
2559 begin_function_try_block ();
2560 else
2561 begin_try_block ();
2562
62409b39 2563 expand_stmt (TRY_STMTS (t));
b35d4555
MM
2564
2565 if (FN_TRY_BLOCK_P (t))
2566 {
2567 finish_function_try_block (NULL_TREE);
2568 expand_stmt (TRY_HANDLERS (t));
2569 finish_function_handler_sequence (NULL_TREE);
2570 }
2571 else
2572 {
2573 finish_try_block (NULL_TREE);
2574 expand_stmt (TRY_HANDLERS (t));
2575 finish_handler_sequence (NULL_TREE);
2576 }
62409b39
MM
2577 }
2578 break;
2579
2580 case HANDLER:
2581 begin_handler ();
62409b39 2582 expand_stmt (HANDLER_BODY (t));
b35d4555 2583 finish_handler (NULL_TREE, NULL_TREE);
62409b39
MM
2584 break;
2585
2586 case SUBOBJECT:
2587 finish_subobject (SUBOBJECT_CLEANUP (t));
2588 break;
2589
b35d4555 2590 case SCOPE_STMT:
d9b2d9da
MM
2591 if (!SCOPE_NO_CLEANUPS_P (t))
2592 {
2593 if (SCOPE_BEGIN_P (t))
a97901e6
MM
2594 expand_start_bindings_and_block (2 * SCOPE_NULLIFIED_P (t),
2595 SCOPE_STMT_BLOCK (t));
d9b2d9da 2596 else if (SCOPE_END_P (t))
6625cdb5 2597 expand_end_bindings (NULL_TREE, !SCOPE_NULLIFIED_P (t), 0);
d9b2d9da
MM
2598 }
2599 else if (!SCOPE_NULLIFIED_P (t))
a97901e6
MM
2600 {
2601 rtx note = emit_note (NULL,
2602 (SCOPE_BEGIN_P (t)
2603 ? NOTE_INSN_BLOCK_BEG
2604 : NOTE_INSN_BLOCK_END));
2605 NOTE_BLOCK (note) = SCOPE_STMT_BLOCK (t);
2606 }
2607
b35d4555
MM
2608 break;
2609
b35d4555
MM
2610 case RETURN_INIT:
2611 /* Clear this out so that finish_named_return_value can set it
2612 again. */
2613 DECL_NAME (DECL_RESULT (current_function_decl)) = NULL_TREE;
2614 finish_named_return_value (TREE_OPERAND (t, 0),
2615 TREE_OPERAND (t, 1));
2616 break;
2617
62409b39
MM
2618 default:
2619 my_friendly_abort (19990810);
2620 break;
f1dedc31 2621 }
558475f0 2622
62409b39
MM
2623 /* Restore saved state. */
2624 stmts_are_full_exprs_p = saved_stmts_are_full_exprs_p;
558475f0 2625
62409b39
MM
2626 /* Go on to the next statement in this scope. */
2627 t = TREE_CHAIN (t);
558475f0
MM
2628 }
2629
a7e4cfa0 2630 return rval;
558475f0
MM
2631}
2632
3eb24f73
MM
2633/* Called from expand_body via walk_tree. Replace all AGGR_INIT_EXPRs
2634 will equivalent CALL_EXPRs. */
2635
2636static tree
2637simplify_aggr_init_exprs_r (tp, walk_subtrees, data)
2638 tree *tp;
2639 int *walk_subtrees ATTRIBUTE_UNUSED;
2640 void *data ATTRIBUTE_UNUSED;
2641{
2642 tree aggr_init_expr;
2643 tree call_expr;
2644 tree fn;
2645 tree args;
2646 tree slot;
2647 tree type;
2648 tree call_type;
2649 int copy_from_buffer_p;
2650
3eb24f73 2651 aggr_init_expr = *tp;
22e92ac3
MM
2652 /* We don't need to walk into types; there's nothing in a type that
2653 needs simplification. (And, furthermore, there are places we
2654 actively don't want to go. For example, we don't want to wander
2655 into the default arguments for a FUNCTION_DECL that appears in a
2656 CALL_EXPR.) */
2657 if (TYPE_P (aggr_init_expr))
2658 {
2659 *walk_subtrees = 0;
2660 return NULL_TREE;
2661 }
2662 /* Only AGGR_INIT_EXPRs are interesting. */
2663 else if (TREE_CODE (aggr_init_expr) != AGGR_INIT_EXPR)
3eb24f73
MM
2664 return NULL_TREE;
2665
2666 /* Form an appropriate CALL_EXPR. */
2667 fn = TREE_OPERAND (aggr_init_expr, 0);
2668 args = TREE_OPERAND (aggr_init_expr, 1);
2669 slot = TREE_OPERAND (aggr_init_expr, 2);
2670 type = TREE_TYPE (aggr_init_expr);
2671 call_type = type;
2672 if (AGGR_INIT_VIA_CTOR_P (aggr_init_expr))
2673 {
2674 /* Replace the first argument with the address of the third
2675 argument to the AGGR_INIT_EXPR. */
2676 call_type = build_pointer_type (type);
2677 mark_addressable (slot);
2678 args = tree_cons (NULL_TREE, build1 (ADDR_EXPR, call_type, slot),
2679 TREE_CHAIN (args));
2680 }
2681 call_expr = build (CALL_EXPR, call_type, fn, args, NULL_TREE);
2682 TREE_SIDE_EFFECTS (call_expr) = 1;
2683
2684 /* If we're using the non-reentrant PCC calling convention, then we
2685 need to copy the returned value out of the static buffer into the
2686 SLOT. */
2687 copy_from_buffer_p = 0;
2688#ifdef PCC_STATIC_STRUCT_RETURN
2689 if (!AGGR_INIT_VIA_CTOR_P (aggr_init_expr) && aggregate_value_p (type))
2690 {
2691 int old_ac;
2692
2693 flag_access_control = 0;
2694 call_expr = build_aggr_init (slot, call_expr, LOOKUP_ONLYCONVERTING);
2695 flag_access_control = old_ac;
2696 copy_from_buffer_p = 1;
2697 }
2698#endif
2699
2700 /* If this AGGR_INIT_EXPR indicates the value returned by a
2701 function, then we want to use the value of the initialized
2702 location as the result. */
2703 if (AGGR_INIT_VIA_CTOR_P (aggr_init_expr) || copy_from_buffer_p)
2704 {
2705 call_expr = build (COMPOUND_EXPR, type,
2706 call_expr, slot);
2707 TREE_SIDE_EFFECTS (call_expr) = 1;
2708 }
2709
2710 /* Replace the AGGR_INIT_EXPR with the CALL_EXPR. */
2711 TREE_CHAIN (call_expr) = TREE_CHAIN (aggr_init_expr);
2712 *tp = call_expr;
2713
2714 /* Keep iterating. */
2715 return NULL_TREE;
2716}
2717
558475f0
MM
2718/* Generate RTL for FN. */
2719
2720void
2721expand_body (fn)
2722 tree fn;
2723{
62409b39 2724 int saved_lineno;
3b304f5b 2725 const char *saved_input_filename;
558475f0 2726
62409b39
MM
2727 /* When the parser calls us after finishing the body of a template
2728 function, we don't really want to expand the body. When we're
2729 processing an in-class definition of an inline function,
2730 PROCESSING_TEMPLATE_DECL will no longer be set here, so we have
2731 to look at the function itself. */
2732 if (processing_template_decl
2733 || (DECL_LANG_SPECIFIC (fn)
2734 && DECL_TEMPLATE_INFO (fn)
2735 && uses_template_parms (DECL_TI_ARGS (fn))))
d658cd4c
MM
2736 {
2737 /* Normally, collection only occurs in rest_of_compilation. So,
2738 if we don't collect here, we never collect junk generated
2739 during the processing of templates until we hit a
2740 non-template function. */
2741 ggc_collect ();
2742 return;
2743 }
62409b39 2744
3eb24f73
MM
2745 /* Replace AGGR_INIT_EXPRs with appropriate CALL_EXPRs. */
2746 walk_tree (&DECL_SAVED_TREE (fn), simplify_aggr_init_exprs_r, NULL);
2747
db9b2174
MM
2748 /* If this is a constructor or destructor body, we have to clone it
2749 under the new ABI. */
2750 if (maybe_clone_body (fn))
2751 {
2752 /* We don't want to process FN again, so pretend we've written
2753 it out, even though we haven't. */
2754 TREE_ASM_WRITTEN (fn) = 1;
2755 return;
2756 }
2757
84df082b
MM
2758 /* There's no reason to do any of the work here if we're only doing
2759 semantic analysis; this code just generates RTL. */
2760 if (flag_syntax_only)
2761 return;
2762
21b0c6dc
MM
2763 /* If possible, avoid generating RTL for this function. Instead,
2764 just record it as an inline function, and wait until end-of-file
2765 to decide whether to write it out or not. */
56e770bf
MM
2766 if (/* We have to generate RTL if it's not an inline function. */
2767 (DECL_INLINE (fn) || DECL_COMDAT (fn))
21b0c6dc
MM
2768 /* Or if we have to keep all inline functions anyhow. */
2769 && !flag_keep_inline_functions
2770 /* Or if we actually have a reference to the function. */
2771 && !DECL_NEEDED_P (fn)
21b0c6dc 2772 /* Or if this is a nested function. */
4f1c5b7d 2773 && !decl_function_context (fn))
21b0c6dc
MM
2774 {
2775 /* Give the function RTL now so that we can assign it to a
2776 function pointer, etc. */
2777 make_function_rtl (fn);
2778 /* Set DECL_EXTERNAL so that assemble_external will be called as
2779 necessary. We'll clear it again in finish_file. */
2780 if (!DECL_EXTERNAL (fn))
2781 {
2782 DECL_NOT_REALLY_EXTERN (fn) = 1;
2783 DECL_EXTERNAL (fn) = 1;
2784 }
2785 /* Remember this function. In finish_file we'll decide if
2786 we actually need to write this function out. */
56e770bf 2787 defer_fn (fn);
de23a892
MM
2788 /* Let the back-end know that this funtion exists. */
2789 note_deferral_of_defined_inline_function (fn);
21b0c6dc
MM
2790 return;
2791 }
2792
297a5329 2793 timevar_push (TV_INTEGRATION);
ea11ca7e 2794
46e8c075
MM
2795 /* Optimize the body of the function before expanding it. */
2796 optimize_function (fn);
2797
297a5329
JM
2798 timevar_pop (TV_INTEGRATION);
2799 timevar_push (TV_EXPAND);
2800
62409b39 2801 /* Save the current file name and line number. When we expand the
84df082b 2802 body of the function, we'll set LINENO and INPUT_FILENAME so that
62409b39
MM
2803 error-mesages come out in the right places. */
2804 saved_lineno = lineno;
2805 saved_input_filename = input_filename;
2806 lineno = DECL_SOURCE_LINE (fn);
2807 input_filename = DECL_SOURCE_FILE (fn);
2808
a8f73d4b 2809 start_function (NULL_TREE, fn, NULL_TREE, SF_PRE_PARSED | SF_EXPAND);
558475f0 2810 store_parm_decls ();
6462c441 2811 current_function_is_thunk = DECL_THUNK_P (fn);
558475f0 2812
24bef158
MM
2813 /* We don't need to redeclare __FUNCTION__, __PRETTY_FUNCTION__, or
2814 any of the other magic variables we set up when starting a
2815 function body. */
2816 current_function_name_declared = 1;
2817
558475f0 2818 /* Expand the body. */
b35d4555 2819 expand_stmt (DECL_SAVED_TREE (fn));
558475f0 2820
62409b39
MM
2821 /* Statements should always be full-expressions at the outermost set
2822 of curly braces for a function. */
2823 my_friendly_assert (stmts_are_full_exprs_p, 19990831);
2824
2825 /* The outermost statement for a function contains the line number
2826 recorded when we finished processing the function. */
2827 lineno = STMT_LINENO (DECL_SAVED_TREE (fn));
2828
2829 /* Generate code for the function. */
0acf7199 2830 finish_function (0);
62409b39 2831
46e8c075
MM
2832 /* If possible, obliterate the body of the function so that it can
2833 be garbage collected. */
2834 if (flag_dump_translation_unit)
2835 /* Keep the body; we're going to dump it. */
2836 ;
2837 else if (DECL_INLINE (fn) && flag_inline_trees)
2838 /* We might need the body of this function so that we can expand
2839 it inline somewhere else. */
2840 ;
2841 else
2842 /* We don't need the body; blow it away. */
d658cd4c
MM
2843 DECL_SAVED_TREE (fn) = NULL_TREE;
2844
62409b39
MM
2845 /* And restore the current source position. */
2846 lineno = saved_lineno;
2847 input_filename = saved_input_filename;
ea11ca7e
JM
2848
2849 timevar_pop (TV_EXPAND);
558475f0 2850}