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