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