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