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