* c-decl.c (c_expand_body): Don't call outlining_inline_function.
[official-gcc.git] / gcc / cp / semantics.c
blobf17019cc8ee90e17bdcfa5522c8822ef9e8298e6
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.
6 Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
7 Written by Mark Mitchell (mmitchell@usa.net) based on code found
8 formerly in parse.y and pt.c.
10 This file is part of GNU CC.
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.
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.
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. */
27 #include "config.h"
28 #include "system.h"
29 #include "tree.h"
30 #include "cp-tree.h"
31 #include "tree-inline.h"
32 #include "except.h"
33 #include "lex.h"
34 #include "toplev.h"
35 #include "flags.h"
36 #include "ggc.h"
37 #include "rtl.h"
38 #include "expr.h"
39 #include "output.h"
40 #include "timevar.h"
41 #include "debug.h"
43 /* There routines provide a modular interface to perform many parsing
44 operations. They may therefore be used during actual parsing, or
45 during template instantiation, which may be regarded as a
46 degenerate form of parsing. Since the current g++ parser is
47 lacking in several respects, and will be reimplemented, we are
48 attempting to move most code that is not directly related to
49 parsing into this file; that will make implementing the new parser
50 much easier since it will be able to make use of these routines. */
52 static tree maybe_convert_cond PARAMS ((tree));
53 static tree simplify_aggr_init_exprs_r PARAMS ((tree *, int *, void *));
54 static void deferred_type_access_control PARAMS ((void));
55 static void emit_associated_thunks PARAMS ((tree));
56 static void genrtl_try_block PARAMS ((tree));
57 static void genrtl_eh_spec_block PARAMS ((tree));
58 static void genrtl_handler PARAMS ((tree));
59 static void genrtl_ctor_stmt PARAMS ((tree));
60 static void genrtl_subobject PARAMS ((tree));
61 static void genrtl_named_return_value PARAMS ((void));
62 static void cp_expand_stmt PARAMS ((tree));
63 static void genrtl_start_function PARAMS ((tree));
64 static void genrtl_finish_function PARAMS ((tree));
65 static tree clear_decl_rtl PARAMS ((tree *, int *, void *));
67 /* Finish processing the COND, the SUBSTMT condition for STMT. */
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)
84 /* Returns non-zero if the current statement is a full expression,
85 i.e. temporaries created during that statement should be destroyed
86 at the end of the statement. */
88 int
89 stmts_are_full_exprs_p ()
91 return current_stmt_tree ()->stmts_are_full_exprs_p;
94 /* Returns the stmt_tree (if any) to which statements are currently
95 being added. If there is no active statement-tree, NULL is
96 returned. */
98 stmt_tree
99 current_stmt_tree ()
101 return (cfun
102 ? &cfun->language->x_stmt_tree
103 : &scope_chain->x_stmt_tree);
106 /* Nonzero if TYPE is an anonymous union or struct type. We have to use a
107 flag for this because "A union for which objects or pointers are
108 declared is not an anonymous union" [class.union]. */
111 anon_aggr_type_p (node)
112 tree node;
114 return (CLASS_TYPE_P (node) && TYPE_LANG_SPECIFIC(node)->anon_aggr);
117 /* Finish a scope. */
119 tree
120 do_poplevel ()
122 tree block = NULL_TREE;
124 if (stmts_are_full_exprs_p ())
126 tree scope_stmts = NULL_TREE;
128 if (!processing_template_decl)
129 scope_stmts = add_scope_stmt (/*begin_p=*/0, /*partial_p=*/0);
131 block = poplevel (kept_level_p (), 1, 0);
132 if (block && !processing_template_decl)
134 SCOPE_STMT_BLOCK (TREE_PURPOSE (scope_stmts)) = block;
135 SCOPE_STMT_BLOCK (TREE_VALUE (scope_stmts)) = block;
139 return block;
142 /* Begin a new scope. */
144 void
145 do_pushlevel ()
147 if (stmts_are_full_exprs_p ())
149 pushlevel (0);
150 if (!processing_template_decl)
151 add_scope_stmt (/*begin_p=*/1, /*partial_p=*/0);
155 /* Finish a goto-statement. */
157 tree
158 finish_goto_stmt (destination)
159 tree destination;
161 if (TREE_CODE (destination) == IDENTIFIER_NODE)
162 destination = lookup_label (destination);
164 /* We warn about unused labels with -Wunused. That means we have to
165 mark the used labels as used. */
166 if (TREE_CODE (destination) == LABEL_DECL)
167 TREE_USED (destination) = 1;
169 if (TREE_CODE (destination) != LABEL_DECL)
170 /* We don't inline calls to functions with computed gotos.
171 Those functions are typically up to some funny business,
172 and may be depending on the labels being at particular
173 addresses, or some such. */
174 DECL_UNINLINABLE (current_function_decl) = 1;
176 check_goto (destination);
178 return add_stmt (build_stmt (GOTO_STMT, destination));
181 /* COND is the condition-expression for an if, while, etc.,
182 statement. Convert it to a boolean value, if appropriate. */
184 tree
185 maybe_convert_cond (cond)
186 tree cond;
188 /* Empty conditions remain empty. */
189 if (!cond)
190 return NULL_TREE;
192 /* Wait until we instantiate templates before doing conversion. */
193 if (processing_template_decl)
194 return cond;
196 /* Do the conversion. */
197 cond = convert_from_reference (cond);
198 return condition_conversion (cond);
201 /* Finish an expression-statement, whose EXPRESSION is as indicated. */
203 tree
204 finish_expr_stmt (expr)
205 tree expr;
207 tree r = NULL_TREE;
209 if (expr != NULL_TREE)
211 if (!processing_template_decl
212 && !(stmts_are_full_exprs_p ())
213 && ((TREE_CODE (TREE_TYPE (expr)) == ARRAY_TYPE
214 && lvalue_p (expr))
215 || TREE_CODE (TREE_TYPE (expr)) == FUNCTION_TYPE))
216 expr = default_conversion (expr);
218 if (stmts_are_full_exprs_p ())
219 expr = convert_to_void (expr, "statement");
221 r = add_stmt (build_stmt (EXPR_STMT, expr));
224 finish_stmt ();
226 /* This was an expression-statement, so we save the type of the
227 expression. */
228 last_expr_type = expr ? TREE_TYPE (expr) : NULL_TREE;
230 return r;
234 /* Begin an if-statement. Returns a newly created IF_STMT if
235 appropriate. */
237 tree
238 begin_if_stmt ()
240 tree r;
241 do_pushlevel ();
242 r = build_stmt (IF_STMT, NULL_TREE, NULL_TREE, NULL_TREE);
243 add_stmt (r);
244 return r;
247 /* Process the COND of an if-statement, which may be given by
248 IF_STMT. */
250 void
251 finish_if_stmt_cond (cond, if_stmt)
252 tree cond;
253 tree if_stmt;
255 cond = maybe_convert_cond (cond);
256 FINISH_COND (cond, if_stmt, IF_COND (if_stmt));
259 /* Finish the then-clause of an if-statement, which may be given by
260 IF_STMT. */
262 tree
263 finish_then_clause (if_stmt)
264 tree if_stmt;
266 RECHAIN_STMTS (if_stmt, THEN_CLAUSE (if_stmt));
267 last_tree = if_stmt;
268 return if_stmt;
271 /* Begin the else-clause of an if-statement. */
273 void
274 begin_else_clause ()
278 /* Finish the else-clause of an if-statement, which may be given by
279 IF_STMT. */
281 void
282 finish_else_clause (if_stmt)
283 tree if_stmt;
285 RECHAIN_STMTS (if_stmt, ELSE_CLAUSE (if_stmt));
288 /* Finish an if-statement. */
290 void
291 finish_if_stmt ()
293 do_poplevel ();
294 finish_stmt ();
297 void
298 clear_out_block ()
300 /* If COND wasn't a declaration, clear out the
301 block we made for it and start a new one here so the
302 optimization in expand_end_loop will work. */
303 if (getdecls () == NULL_TREE)
305 do_poplevel ();
306 do_pushlevel ();
310 /* Begin a while-statement. Returns a newly created WHILE_STMT if
311 appropriate. */
313 tree
314 begin_while_stmt ()
316 tree r;
317 r = build_stmt (WHILE_STMT, NULL_TREE, NULL_TREE);
318 add_stmt (r);
319 do_pushlevel ();
320 return r;
323 /* Process the COND of a while-statement, which may be given by
324 WHILE_STMT. */
326 void
327 finish_while_stmt_cond (cond, while_stmt)
328 tree cond;
329 tree while_stmt;
331 cond = maybe_convert_cond (cond);
332 FINISH_COND (cond, while_stmt, WHILE_COND (while_stmt));
333 clear_out_block ();
336 /* Finish a while-statement, which may be given by WHILE_STMT. */
338 void
339 finish_while_stmt (while_stmt)
340 tree while_stmt;
342 do_poplevel ();
343 RECHAIN_STMTS (while_stmt, WHILE_BODY (while_stmt));
344 finish_stmt ();
347 /* Begin a do-statement. Returns a newly created DO_STMT if
348 appropriate. */
350 tree
351 begin_do_stmt ()
353 tree r = build_stmt (DO_STMT, NULL_TREE, NULL_TREE);
354 add_stmt (r);
355 return r;
358 /* Finish the body of a do-statement, which may be given by DO_STMT. */
360 void
361 finish_do_body (do_stmt)
362 tree do_stmt;
364 RECHAIN_STMTS (do_stmt, DO_BODY (do_stmt));
367 /* Finish a do-statement, which may be given by DO_STMT, and whose
368 COND is as indicated. */
370 void
371 finish_do_stmt (cond, do_stmt)
372 tree cond;
373 tree do_stmt;
375 cond = maybe_convert_cond (cond);
376 DO_COND (do_stmt) = cond;
377 finish_stmt ();
380 /* Finish a return-statement. The EXPRESSION returned, if any, is as
381 indicated. */
383 tree
384 finish_return_stmt (expr)
385 tree expr;
387 tree r;
389 if (!processing_template_decl)
390 expr = check_return_expr (expr);
391 if (!processing_template_decl)
393 if (DECL_DESTRUCTOR_P (current_function_decl))
395 /* Similarly, all destructors must run destructors for
396 base-classes before returning. So, all returns in a
397 destructor get sent to the DTOR_LABEL; finish_function emits
398 code to return a value there. */
399 return finish_goto_stmt (dtor_label);
402 r = add_stmt (build_stmt (RETURN_STMT, expr));
403 finish_stmt ();
405 return r;
408 /* Begin a for-statement. Returns a new FOR_STMT if appropriate. */
410 tree
411 begin_for_stmt ()
413 tree r;
415 r = build_stmt (FOR_STMT, NULL_TREE, NULL_TREE,
416 NULL_TREE, NULL_TREE);
417 NEW_FOR_SCOPE_P (r) = flag_new_for_scope > 0;
418 add_stmt (r);
419 if (NEW_FOR_SCOPE_P (r))
421 do_pushlevel ();
422 note_level_for_for ();
425 return r;
428 /* Finish the for-init-statement of a for-statement, which may be
429 given by FOR_STMT. */
431 void
432 finish_for_init_stmt (for_stmt)
433 tree for_stmt;
435 if (last_tree != for_stmt)
436 RECHAIN_STMTS (for_stmt, FOR_INIT_STMT (for_stmt));
437 do_pushlevel ();
440 /* Finish the COND of a for-statement, which may be given by
441 FOR_STMT. */
443 void
444 finish_for_cond (cond, for_stmt)
445 tree cond;
446 tree for_stmt;
448 cond = maybe_convert_cond (cond);
449 FINISH_COND (cond, for_stmt, FOR_COND (for_stmt));
450 clear_out_block ();
453 /* Finish the increment-EXPRESSION in a for-statement, which may be
454 given by FOR_STMT. */
456 void
457 finish_for_expr (expr, for_stmt)
458 tree expr;
459 tree for_stmt;
461 FOR_EXPR (for_stmt) = expr;
464 /* Finish the body of a for-statement, which may be given by
465 FOR_STMT. The increment-EXPR for the loop must be
466 provided. */
468 void
469 finish_for_stmt (for_stmt)
470 tree for_stmt;
472 /* Pop the scope for the body of the loop. */
473 do_poplevel ();
474 RECHAIN_STMTS (for_stmt, FOR_BODY (for_stmt));
475 if (NEW_FOR_SCOPE_P (for_stmt))
476 do_poplevel ();
477 finish_stmt ();
480 /* Finish a break-statement. */
482 tree
483 finish_break_stmt ()
485 return add_stmt (build_break_stmt ());
488 /* Finish a continue-statement. */
490 tree
491 finish_continue_stmt ()
493 return add_stmt (build_continue_stmt ());
496 /* Begin a switch-statement. Returns a new SWITCH_STMT if
497 appropriate. */
499 tree
500 begin_switch_stmt ()
502 tree r;
503 r = build_stmt (SWITCH_STMT, NULL_TREE, NULL_TREE);
504 add_stmt (r);
505 do_pushlevel ();
506 return r;
509 /* Finish the cond of a switch-statement. */
511 void
512 finish_switch_cond (cond, switch_stmt)
513 tree cond;
514 tree switch_stmt;
516 if (!processing_template_decl)
518 tree type;
519 tree index;
521 /* Convert the condition to an integer or enumeration type. */
522 cond = build_expr_type_conversion (WANT_INT | WANT_ENUM, cond, 1);
523 if (cond == NULL_TREE)
525 error ("switch quantity not an integer");
526 cond = error_mark_node;
528 if (cond != error_mark_node)
530 cond = default_conversion (cond);
531 cond = fold (build1 (CLEANUP_POINT_EXPR, TREE_TYPE (cond), cond));
534 type = TREE_TYPE (cond);
535 index = get_unwidened (cond, NULL_TREE);
536 /* We can't strip a conversion from a signed type to an unsigned,
537 because if we did, int_fits_type_p would do the wrong thing
538 when checking case values for being in range,
539 and it's too hard to do the right thing. */
540 if (TREE_UNSIGNED (TREE_TYPE (cond))
541 == TREE_UNSIGNED (TREE_TYPE (index)))
542 cond = index;
544 FINISH_COND (cond, switch_stmt, SWITCH_COND (switch_stmt));
545 push_switch (switch_stmt);
548 /* Finish the body of a switch-statement, which may be given by
549 SWITCH_STMT. The COND to switch on is indicated. */
551 void
552 finish_switch_stmt (switch_stmt)
553 tree switch_stmt;
555 RECHAIN_STMTS (switch_stmt, SWITCH_BODY (switch_stmt));
556 pop_switch ();
557 do_poplevel ();
558 finish_stmt ();
561 /* Generate the RTL for T, which is a TRY_BLOCK. */
563 static void
564 genrtl_try_block (t)
565 tree t;
567 if (CLEANUP_P (t))
569 expand_eh_region_start ();
570 expand_stmt (TRY_STMTS (t));
571 expand_eh_region_end_cleanup (TRY_HANDLERS (t));
573 else
575 if (!FN_TRY_BLOCK_P (t))
576 emit_line_note (input_filename, lineno);
578 expand_eh_region_start ();
579 expand_stmt (TRY_STMTS (t));
581 if (FN_TRY_BLOCK_P (t))
583 expand_start_all_catch ();
584 in_function_try_handler = 1;
585 expand_stmt (TRY_HANDLERS (t));
586 in_function_try_handler = 0;
587 expand_end_all_catch ();
589 else
591 expand_start_all_catch ();
592 expand_stmt (TRY_HANDLERS (t));
593 expand_end_all_catch ();
598 /* Generate the RTL for T, which is an EH_SPEC_BLOCK. */
600 static void
601 genrtl_eh_spec_block (t)
602 tree t;
604 expand_eh_region_start ();
605 expand_stmt (EH_SPEC_STMTS (t));
606 expand_eh_region_end_allowed (EH_SPEC_RAISES (t),
607 build_call (call_unexpected_node,
608 tree_cons (NULL_TREE,
609 build_exc_ptr (),
610 NULL_TREE)));
613 /* Begin a try-block. Returns a newly-created TRY_BLOCK if
614 appropriate. */
616 tree
617 begin_try_block ()
619 tree r = build_stmt (TRY_BLOCK, NULL_TREE, NULL_TREE);
620 add_stmt (r);
621 return r;
624 /* Likewise, for a function-try-block. */
626 tree
627 begin_function_try_block ()
629 tree r = build_stmt (TRY_BLOCK, NULL_TREE, NULL_TREE);
630 FN_TRY_BLOCK_P (r) = 1;
631 add_stmt (r);
632 return r;
635 /* Finish a try-block, which may be given by TRY_BLOCK. */
637 void
638 finish_try_block (try_block)
639 tree try_block;
641 RECHAIN_STMTS (try_block, TRY_STMTS (try_block));
644 /* Finish the body of a cleanup try-block, which may be given by
645 TRY_BLOCK. */
647 void
648 finish_cleanup_try_block (try_block)
649 tree try_block;
651 RECHAIN_STMTS (try_block, TRY_STMTS (try_block));
654 /* Finish an implicitly generated try-block, with a cleanup is given
655 by CLEANUP. */
657 void
658 finish_cleanup (cleanup, try_block)
659 tree cleanup;
660 tree try_block;
662 TRY_HANDLERS (try_block) = cleanup;
663 CLEANUP_P (try_block) = 1;
666 /* Likewise, for a function-try-block. */
668 void
669 finish_function_try_block (try_block)
670 tree try_block;
672 if (TREE_CHAIN (try_block)
673 && TREE_CODE (TREE_CHAIN (try_block)) == CTOR_INITIALIZER)
675 /* Chain the compound statement after the CTOR_INITIALIZER. */
676 TREE_CHAIN (TREE_CHAIN (try_block)) = last_tree;
677 /* And make the CTOR_INITIALIZER the body of the try-block. */
678 RECHAIN_STMTS (try_block, TRY_STMTS (try_block));
680 else
681 RECHAIN_STMTS (try_block, TRY_STMTS (try_block));
682 in_function_try_handler = 1;
685 /* Finish a handler-sequence for a try-block, which may be given by
686 TRY_BLOCK. */
688 void
689 finish_handler_sequence (try_block)
690 tree try_block;
692 RECHAIN_STMTS (try_block, TRY_HANDLERS (try_block));
693 check_handlers (TRY_HANDLERS (try_block));
696 /* Likewise, for a function-try-block. */
698 void
699 finish_function_handler_sequence (try_block)
700 tree try_block;
702 in_function_try_handler = 0;
703 RECHAIN_STMTS (try_block, TRY_HANDLERS (try_block));
704 check_handlers (TRY_HANDLERS (try_block));
707 /* Generate the RTL for T, which is a HANDLER. */
709 static void
710 genrtl_handler (t)
711 tree t;
713 genrtl_do_pushlevel ();
714 if (!processing_template_decl)
715 expand_start_catch (HANDLER_TYPE (t));
716 expand_stmt (HANDLER_BODY (t));
717 if (!processing_template_decl)
718 expand_end_catch ();
721 /* Begin a handler. Returns a HANDLER if appropriate. */
723 tree
724 begin_handler ()
726 tree r;
727 r = build_stmt (HANDLER, NULL_TREE, NULL_TREE);
728 add_stmt (r);
729 /* Create a binding level for the eh_info and the exception object
730 cleanup. */
731 do_pushlevel ();
732 note_level_for_catch ();
733 return r;
736 /* Finish the handler-parameters for a handler, which may be given by
737 HANDLER. DECL is the declaration for the catch parameter, or NULL
738 if this is a `catch (...)' clause. */
740 void
741 finish_handler_parms (decl, handler)
742 tree decl;
743 tree handler;
745 tree type = NULL_TREE;
746 if (processing_template_decl)
748 if (decl)
750 decl = pushdecl (decl);
751 decl = push_template_decl (decl);
752 add_decl_stmt (decl);
753 RECHAIN_STMTS (handler, HANDLER_PARMS (handler));
754 type = TREE_TYPE (decl);
757 else
758 type = expand_start_catch_block (decl);
760 HANDLER_TYPE (handler) = type;
763 /* Finish a handler, which may be given by HANDLER. The BLOCKs are
764 the return value from the matching call to finish_handler_parms. */
766 void
767 finish_handler (handler)
768 tree handler;
770 if (!processing_template_decl)
771 expand_end_catch_block ();
772 do_poplevel ();
773 RECHAIN_STMTS (handler, HANDLER_BODY (handler));
776 /* Generate the RTL for T, which is a CTOR_STMT. */
778 static void
779 genrtl_ctor_stmt (t)
780 tree t;
782 if (CTOR_BEGIN_P (t))
783 begin_protect_partials ();
784 else
785 /* After this point, any exceptions will cause the
786 destructor to be executed, so we no longer need to worry
787 about destroying the various subobjects ourselves. */
788 end_protect_partials ();
791 /* Begin a compound-statement. If HAS_NO_SCOPE is non-zero, the
792 compound-statement does not define a scope. Returns a new
793 COMPOUND_STMT if appropriate. */
795 tree
796 begin_compound_stmt (has_no_scope)
797 int has_no_scope;
799 tree r;
800 int is_try = 0;
802 r = build_stmt (COMPOUND_STMT, NULL_TREE);
804 if (last_tree && TREE_CODE (last_tree) == TRY_BLOCK)
805 is_try = 1;
807 add_stmt (r);
808 if (has_no_scope)
809 COMPOUND_STMT_NO_SCOPE (r) = 1;
811 last_expr_type = NULL_TREE;
813 if (!has_no_scope)
815 do_pushlevel ();
816 if (is_try)
817 note_level_for_try ();
819 else
820 /* Normally, we try hard to keep the BLOCK for a
821 statement-expression. But, if it's a statement-expression with
822 a scopeless block, there's nothing to keep, and we don't want
823 to accidentally keep a block *inside* the scopeless block. */
824 keep_next_level (0);
826 return r;
829 /* Finish a compound-statement, which may be given by COMPOUND_STMT.
830 If HAS_NO_SCOPE is non-zero, the compound statement does not define
831 a scope. */
833 tree
834 finish_compound_stmt (has_no_scope, compound_stmt)
835 int has_no_scope;
836 tree compound_stmt;
838 tree r;
839 tree t;
841 if (!has_no_scope)
842 r = do_poplevel ();
843 else
844 r = NULL_TREE;
846 RECHAIN_STMTS (compound_stmt, COMPOUND_BODY (compound_stmt));
848 /* When we call finish_stmt we will lose LAST_EXPR_TYPE. But, since
849 the precise purpose of that variable is store the type of the
850 last expression statement within the last compound statement, we
851 preserve the value. */
852 t = last_expr_type;
853 finish_stmt ();
854 last_expr_type = t;
856 return r;
859 /* Finish an asm-statement, whose components are a CV_QUALIFIER, a
860 STRING, some OUTPUT_OPERANDS, some INPUT_OPERANDS, and some
861 CLOBBERS. */
863 tree
864 finish_asm_stmt (cv_qualifier, string, output_operands,
865 input_operands, clobbers)
866 tree cv_qualifier;
867 tree string;
868 tree output_operands;
869 tree input_operands;
870 tree clobbers;
872 tree r;
873 tree t;
875 if (TREE_CHAIN (string))
876 string = combine_strings (string);
878 if (cv_qualifier != NULL_TREE
879 && cv_qualifier != ridpointers[(int) RID_VOLATILE])
881 warning ("%s qualifier ignored on asm",
882 IDENTIFIER_POINTER (cv_qualifier));
883 cv_qualifier = NULL_TREE;
886 if (!processing_template_decl)
888 int i;
889 int ninputs;
890 int noutputs;
892 for (t = input_operands; t; t = TREE_CHAIN (t))
894 tree converted_operand
895 = decay_conversion (TREE_VALUE (t));
897 /* If the type of the operand hasn't been determined (e.g.,
898 because it involves an overloaded function), then issue
899 an error message. There's no context available to
900 resolve the overloading. */
901 if (TREE_TYPE (converted_operand) == unknown_type_node)
903 error ("type of asm operand `%E' could not be determined",
904 TREE_VALUE (t));
905 converted_operand = error_mark_node;
907 TREE_VALUE (t) = converted_operand;
910 ninputs = list_length (input_operands);
911 noutputs = list_length (output_operands);
913 for (i = 0, t = output_operands; t; t = TREE_CHAIN (t), ++i)
915 bool allows_mem;
916 bool allows_reg;
917 bool is_inout;
918 const char *constraint;
919 tree operand;
921 constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t)));
922 operand = TREE_VALUE (output_operands);
924 if (!parse_output_constraint (&constraint,
925 i, ninputs, noutputs,
926 &allows_mem,
927 &allows_reg,
928 &is_inout))
930 /* By marking the type as erroneous, we will not try to
931 process this operand again in expand_asm_operands. */
932 TREE_TYPE (operand) = error_mark_node;
933 continue;
936 /* If the operand is a DECL that is going to end up in
937 memory, assume it is addressable. This is a bit more
938 conservative than it would ideally be; the exact test is
939 buried deep in expand_asm_operands and depends on the
940 DECL_RTL for the OPERAND -- which we don't have at this
941 point. */
942 if (!allows_reg && DECL_P (operand))
943 mark_addressable (operand);
947 r = build_stmt (ASM_STMT, cv_qualifier, string,
948 output_operands, input_operands,
949 clobbers);
950 return add_stmt (r);
953 /* Finish a label with the indicated NAME. */
955 void
956 finish_label_stmt (name)
957 tree name;
959 tree decl = define_label (input_filename, lineno, name);
960 add_stmt (build_stmt (LABEL_STMT, decl));
963 /* Finish a series of declarations for local labels. G++ allows users
964 to declare "local" labels, i.e., labels with scope. This extension
965 is useful when writing code involving statement-expressions. */
967 void
968 finish_label_decl (name)
969 tree name;
971 tree decl = declare_local_label (name);
972 add_decl_stmt (decl);
975 /* Generate the RTL for a SUBOBJECT. */
977 static void
978 genrtl_subobject (cleanup)
979 tree cleanup;
981 add_partial_entry (cleanup);
984 /* We're in a constructor, and have just constructed a a subobject of
985 *THIS. CLEANUP is code to run if an exception is thrown before the
986 end of the current function is reached. */
988 void
989 finish_subobject (cleanup)
990 tree cleanup;
992 tree r = build_stmt (SUBOBJECT, cleanup);
993 add_stmt (r);
996 /* When DECL goes out of scope, make sure that CLEANUP is executed. */
998 void
999 finish_decl_cleanup (decl, cleanup)
1000 tree decl;
1001 tree cleanup;
1003 add_stmt (build_stmt (CLEANUP_STMT, decl, cleanup));
1006 /* Generate the RTL for a RETURN_INIT. */
1008 static void
1009 genrtl_named_return_value ()
1011 tree decl = DECL_RESULT (current_function_decl);
1013 /* If this named return value comes in a register, put it in a
1014 pseudo-register. */
1015 if (DECL_REGISTER (decl))
1017 /* Note that the mode of the old DECL_RTL may be wider than the
1018 mode of DECL_RESULT, depending on the calling conventions for
1019 the processor. For example, on the Alpha, a 32-bit integer
1020 is returned in a DImode register -- the DECL_RESULT has
1021 SImode but the DECL_RTL for the DECL_RESULT has DImode. So,
1022 here, we use the mode the back-end has already assigned for
1023 the return value. */
1024 SET_DECL_RTL (decl, gen_reg_rtx (GET_MODE (DECL_RTL (decl))));
1025 if (TREE_ADDRESSABLE (decl))
1026 put_var_into_stack (decl);
1029 emit_local_var (decl);
1032 /* Bind a name and initialization to the return value of
1033 the current function. */
1035 void
1036 finish_named_return_value (return_id, init)
1037 tree return_id, init;
1039 tree decl = DECL_RESULT (current_function_decl);
1041 /* Give this error as many times as there are occurrences, so that
1042 users can use Emacs compilation buffers to find and fix all such
1043 places. */
1044 if (pedantic)
1045 pedwarn ("ISO C++ does not permit named return values");
1046 cp_deprecated ("the named return value extension");
1048 if (return_id != NULL_TREE)
1050 if (DECL_NAME (decl) == NULL_TREE)
1051 DECL_NAME (decl) = return_id;
1052 else
1054 error ("return identifier `%D' already in place", return_id);
1055 return;
1059 /* Can't let this happen for constructors. */
1060 if (DECL_CONSTRUCTOR_P (current_function_decl))
1062 error ("can't redefine default return value for constructors");
1063 return;
1066 /* If we have a named return value, put that in our scope as well. */
1067 if (DECL_NAME (decl) != NULL_TREE)
1069 /* Let `cp_finish_decl' know that this initializer is ok. */
1070 DECL_INITIAL (decl) = init;
1071 if (doing_semantic_analysis_p ())
1072 pushdecl (decl);
1073 if (!processing_template_decl)
1075 cp_finish_decl (decl, init, NULL_TREE, 0);
1076 add_stmt (build_stmt (RETURN_INIT, NULL_TREE, NULL_TREE));
1078 else
1079 add_stmt (build_stmt (RETURN_INIT, return_id, init));
1082 /* Don't use tree-inlining for functions with named return values.
1083 That doesn't work properly because we don't do any translation of
1084 the RETURN_INITs when they are copied. */
1085 DECL_UNINLINABLE (current_function_decl) = 1;
1088 /* The INIT_LIST is a list of mem-initializers, in the order they were
1089 written by the user. The TREE_VALUE of each node is a list of
1090 initializers for a particular subobject. The TREE_PURPOSE is a
1091 FIELD_DECL is the initializer is for a non-static data member, and
1092 a class type if the initializer is for a base class. */
1094 void
1095 finish_mem_initializers (init_list)
1096 tree init_list;
1098 tree member_init_list;
1099 tree base_init_list;
1100 tree last_base_warned_about;
1101 tree next;
1102 tree init;
1104 member_init_list = NULL_TREE;
1105 base_init_list = NULL_TREE;
1106 last_base_warned_about = NULL_TREE;
1108 for (init = init_list; init; init = next)
1110 next = TREE_CHAIN (init);
1111 if (TREE_CODE (TREE_PURPOSE (init)) == FIELD_DECL)
1113 TREE_CHAIN (init) = member_init_list;
1114 member_init_list = init;
1116 /* We're running through the initializers from right to left
1117 as we process them here. So, if we see a data member
1118 initializer after we see a base initializer, that
1119 actually means that the base initializer preceded the
1120 data member initializer. */
1121 if (warn_reorder && last_base_warned_about != base_init_list)
1123 tree base;
1125 for (base = base_init_list;
1126 base != last_base_warned_about;
1127 base = TREE_CHAIN (base))
1129 warning ("base initializer for `%T'",
1130 TREE_PURPOSE (base));
1131 warning (" will be re-ordered to precede member initializations");
1134 last_base_warned_about = base_init_list;
1137 else
1139 TREE_CHAIN (init) = base_init_list;
1140 base_init_list = init;
1144 setup_vtbl_ptr (member_init_list, base_init_list);
1147 /* Do the initialization work necessary at the beginning of a constructor
1148 or destructor. This means processing member initializers and setting
1149 vtable pointers.
1151 ??? The call to keep_next_level at the end applies to all functions, but
1152 should probably go somewhere else. */
1154 void
1155 setup_vtbl_ptr (member_init_list, base_init_list)
1156 tree member_init_list;
1157 tree base_init_list;
1159 my_friendly_assert (doing_semantic_analysis_p (), 19990919);
1160 my_friendly_assert (!vtbls_set_up_p, 20011220);
1162 if (processing_template_decl)
1163 add_stmt (build_min_nt (CTOR_INITIALIZER,
1164 member_init_list, base_init_list));
1165 else if (DECL_CONSTRUCTOR_P (current_function_decl))
1167 tree ctor_stmt;
1169 /* Mark the beginning of the constructor. */
1170 ctor_stmt = build_stmt (CTOR_STMT);
1171 CTOR_BEGIN_P (ctor_stmt) = 1;
1172 add_stmt (ctor_stmt);
1174 /* And actually initialize the base-classes and members. */
1175 emit_base_init (member_init_list, base_init_list);
1177 else if (DECL_DESTRUCTOR_P (current_function_decl))
1179 tree if_stmt;
1180 tree compound_stmt;
1182 /* If the dtor is empty, and we know there is not any possible
1183 way we could use any vtable entries, before they are possibly
1184 set by a base class dtor, we don't have to setup the vtables,
1185 as we know that any base class dtor will set up any vtables
1186 it needs. We avoid MI, because one base class dtor can do a
1187 virtual dispatch to an overridden function that would need to
1188 have a non-related vtable set up, we cannot avoid setting up
1189 vtables in that case. We could change this to see if there
1190 is just one vtable.
1192 ??? In the destructor for a class, the vtables are set
1193 appropriately for that class. There will be no non-related
1194 vtables. jason 2001-12-11. */
1195 if_stmt = begin_if_stmt ();
1197 /* If it is not safe to avoid setting up the vtables, then
1198 someone will change the condition to be boolean_true_node.
1199 (Actually, for now, we do not have code to set the condition
1200 appropriately, so we just assume that we always need to
1201 initialize the vtables.) */
1202 finish_if_stmt_cond (boolean_true_node, if_stmt);
1203 current_vcalls_possible_p = &IF_COND (if_stmt);
1205 compound_stmt = begin_compound_stmt (/*has_no_scope=*/0);
1207 /* Make all virtual function table pointers in non-virtual base
1208 classes point to CURRENT_CLASS_TYPE's virtual function
1209 tables. */
1210 initialize_vtbl_ptrs (current_class_ptr);
1212 finish_compound_stmt (/*has_no_scope=*/0, compound_stmt);
1213 finish_then_clause (if_stmt);
1214 finish_if_stmt ();
1216 /* And insert cleanups for our bases and members so that they
1217 will be properly destroyed if we throw. */
1218 push_base_cleanups ();
1221 /* Always keep the BLOCK node associated with the outermost pair of
1222 curly braces of a function. These are needed for correct
1223 operation of dwarfout.c. */
1224 keep_next_level (1);
1226 /* The virtual function tables are set up now. */
1227 vtbls_set_up_p = 1;
1230 /* Returns the stack of SCOPE_STMTs for the current function. */
1232 tree *
1233 current_scope_stmt_stack ()
1235 return &cfun->language->x_scope_stmt_stack;
1238 /* Finish a parenthesized expression EXPR. */
1240 tree
1241 finish_parenthesized_expr (expr)
1242 tree expr;
1244 if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (TREE_CODE (expr))))
1245 /* This inhibits warnings in truthvalue_conversion. */
1246 C_SET_EXP_ORIGINAL_CODE (expr, ERROR_MARK);
1248 if (TREE_CODE (expr) == OFFSET_REF)
1249 /* [expr.unary.op]/3 The qualified id of a pointer-to-member must not be
1250 enclosed in parentheses. */
1251 PTRMEM_OK_P (expr) = 0;
1252 return expr;
1255 /* Begin a statement-expression. The value returned must be passed to
1256 finish_stmt_expr. */
1258 tree
1259 begin_stmt_expr ()
1261 /* If we're outside a function, we won't have a statement-tree to
1262 work with. But, if we see a statement-expression we need to
1263 create one. */
1264 if (! cfun && !last_tree)
1265 begin_stmt_tree (&scope_chain->x_saved_tree);
1267 keep_next_level (1);
1268 /* If we're building a statement tree, then the upcoming compound
1269 statement will be chained onto the tree structure, starting at
1270 last_tree. We return last_tree so that we can later unhook the
1271 compound statement. */
1272 return last_tree;
1275 /* Used when beginning a statement-expression outside function scope.
1276 For example, when handling a file-scope initializer, we use this
1277 function. */
1279 tree
1280 begin_global_stmt_expr ()
1282 if (! cfun && !last_tree)
1283 begin_stmt_tree (&scope_chain->x_saved_tree);
1285 keep_next_level (1);
1287 return (last_tree != NULL_TREE) ? last_tree : expand_start_stmt_expr();
1290 /* Finish the STMT_EXPR last begun with begin_global_stmt_expr. */
1292 tree
1293 finish_global_stmt_expr (stmt_expr)
1294 tree stmt_expr;
1296 stmt_expr = expand_end_stmt_expr (stmt_expr);
1298 if (! cfun
1299 && TREE_CHAIN (scope_chain->x_saved_tree) == NULL_TREE)
1300 finish_stmt_tree (&scope_chain->x_saved_tree);
1302 return stmt_expr;
1305 /* Finish a statement-expression. RTL_EXPR should be the value
1306 returned by the previous begin_stmt_expr; EXPR is the
1307 statement-expression. Returns an expression representing the
1308 statement-expression. */
1310 tree
1311 finish_stmt_expr (rtl_expr)
1312 tree rtl_expr;
1314 tree result;
1316 /* If the last thing in the statement-expression was not an
1317 expression-statement, then it has type `void'. */
1318 if (!last_expr_type)
1319 last_expr_type = void_type_node;
1320 result = build_min (STMT_EXPR, last_expr_type, last_tree);
1321 TREE_SIDE_EFFECTS (result) = 1;
1323 /* Remove the compound statement from the tree structure; it is
1324 now saved in the STMT_EXPR. */
1325 last_tree = rtl_expr;
1326 TREE_CHAIN (last_tree) = NULL_TREE;
1328 /* If we created a statement-tree for this statement-expression,
1329 remove it now. */
1330 if (! cfun
1331 && TREE_CHAIN (scope_chain->x_saved_tree) == NULL_TREE)
1332 finish_stmt_tree (&scope_chain->x_saved_tree);
1334 return result;
1337 /* Finish a call to FN with ARGS. Returns a representation of the
1338 call. */
1340 tree
1341 finish_call_expr (fn, args, koenig)
1342 tree fn;
1343 tree args;
1344 int koenig;
1346 tree result;
1348 if (koenig)
1350 if (TREE_CODE (fn) == BIT_NOT_EXPR)
1351 fn = build_x_unary_op (BIT_NOT_EXPR, TREE_OPERAND (fn, 0));
1352 else if (TREE_CODE (fn) != TEMPLATE_ID_EXPR)
1353 fn = do_identifier (fn, 2, args);
1355 result = build_x_function_call (fn, args, current_class_ref);
1357 if (TREE_CODE (result) == CALL_EXPR
1358 && (! TREE_TYPE (result)
1359 || TREE_CODE (TREE_TYPE (result)) != VOID_TYPE))
1360 result = require_complete_type (result);
1362 return result;
1365 /* Finish a call to a postfix increment or decrement or EXPR. (Which
1366 is indicated by CODE, which should be POSTINCREMENT_EXPR or
1367 POSTDECREMENT_EXPR.) */
1369 tree
1370 finish_increment_expr (expr, code)
1371 tree expr;
1372 enum tree_code code;
1374 /* If we get an OFFSET_REF, turn it into what it really means (e.g.,
1375 a COMPONENT_REF). This way if we've got, say, a reference to a
1376 static member that's being operated on, we don't end up trying to
1377 find a member operator for the class it's in. */
1379 if (TREE_CODE (expr) == OFFSET_REF)
1380 expr = resolve_offset_ref (expr);
1381 return build_x_unary_op (code, expr);
1384 /* Finish a use of `this'. Returns an expression for `this'. */
1386 tree
1387 finish_this_expr ()
1389 tree result;
1391 if (current_class_ptr)
1393 result = current_class_ptr;
1395 else if (current_function_decl
1396 && DECL_STATIC_FUNCTION_P (current_function_decl))
1398 error ("`this' is unavailable for static member functions");
1399 result = error_mark_node;
1401 else
1403 if (current_function_decl)
1404 error ("invalid use of `this' in non-member function");
1405 else
1406 error ("invalid use of `this' at top level");
1407 result = error_mark_node;
1410 return result;
1413 /* Finish a member function call using OBJECT and ARGS as arguments to
1414 FN. Returns an expression for the call. */
1416 tree
1417 finish_object_call_expr (fn, object, args)
1418 tree fn;
1419 tree object;
1420 tree args;
1422 #if 0
1423 /* This is a future direction of this code, but because
1424 build_x_function_call cannot always undo what is done in
1425 build_component_ref entirely yet, we cannot do this. */
1427 tree real_fn = build_component_ref (object, fn, NULL_TREE, 1);
1428 return finish_call_expr (real_fn, args);
1429 #else
1430 if (DECL_DECLARES_TYPE_P (fn))
1432 if (processing_template_decl)
1433 /* This can happen on code like:
1435 class X;
1436 template <class T> void f(T t) {
1437 t.X();
1440 We just grab the underlying IDENTIFIER. */
1441 fn = DECL_NAME (fn);
1442 else
1444 error ("calling type `%T' like a method", fn);
1445 return error_mark_node;
1449 return build_method_call (object, fn, args, NULL_TREE, LOOKUP_NORMAL);
1450 #endif
1453 /* Finish a qualified member function call using OBJECT and ARGS as
1454 arguments to FN. Returns an expression for the call. */
1456 tree
1457 finish_qualified_object_call_expr (fn, object, args)
1458 tree fn;
1459 tree object;
1460 tree args;
1462 return build_scoped_method_call (object, TREE_OPERAND (fn, 0),
1463 TREE_OPERAND (fn, 1), args);
1466 /* Finish a pseudo-destructor call expression of OBJECT, with SCOPE
1467 being the scope, if any, of DESTRUCTOR. Returns an expression for
1468 the call. */
1470 tree
1471 finish_pseudo_destructor_call_expr (object, scope, destructor)
1472 tree object;
1473 tree scope;
1474 tree destructor;
1476 if (processing_template_decl)
1477 return build_min_nt (PSEUDO_DTOR_EXPR, object, scope, destructor);
1479 if (scope && scope != destructor)
1480 error ("destructor specifier `%T::~%T()' must have matching names",
1481 scope, destructor);
1483 if ((scope == NULL_TREE || IDENTIFIER_GLOBAL_VALUE (destructor))
1484 && (TREE_CODE (TREE_TYPE (object)) !=
1485 TREE_CODE (TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (destructor)))))
1486 error ("`%E' is not of type `%T'", object, destructor);
1488 return cp_convert (void_type_node, object);
1491 /* Finish a call to a globally qualified member function FN using
1492 ARGS. Returns an expression for the call. */
1494 tree
1495 finish_qualified_call_expr (fn, args)
1496 tree fn;
1497 tree args;
1499 if (processing_template_decl)
1500 return build_min_nt (CALL_EXPR, fn, args, NULL_TREE);
1501 else
1502 return build_member_call (TREE_OPERAND (fn, 0),
1503 TREE_OPERAND (fn, 1),
1504 args);
1507 /* Finish an expression of the form CODE EXPR. */
1509 tree
1510 finish_unary_op_expr (code, expr)
1511 enum tree_code code;
1512 tree expr;
1514 tree result = build_x_unary_op (code, expr);
1515 /* Inside a template, build_x_unary_op does not fold the
1516 expression. So check whether the result is folded before
1517 setting TREE_NEGATED_INT. */
1518 if (code == NEGATE_EXPR && TREE_CODE (expr) == INTEGER_CST
1519 && TREE_CODE (result) == INTEGER_CST
1520 && !TREE_UNSIGNED (TREE_TYPE (result))
1521 && INT_CST_LT (result, integer_zero_node))
1522 TREE_NEGATED_INT (result) = 1;
1523 overflow_warning (result);
1524 return result;
1527 /* Finish an id-expression. */
1529 tree
1530 finish_id_expr (expr)
1531 tree expr;
1533 if (TREE_CODE (expr) == IDENTIFIER_NODE)
1534 expr = do_identifier (expr, 1, NULL_TREE);
1536 if (TREE_TYPE (expr) == error_mark_node)
1537 expr = error_mark_node;
1538 return expr;
1541 static tree current_type_lookups;
1543 /* Perform deferred access control for types used in the type of a
1544 declaration. */
1546 static void
1547 deferred_type_access_control ()
1549 tree lookup = type_lookups;
1551 if (lookup == error_mark_node)
1552 return;
1554 for (; lookup; lookup = TREE_CHAIN (lookup))
1555 enforce_access (TREE_PURPOSE (lookup), TREE_VALUE (lookup));
1558 void
1559 decl_type_access_control (decl)
1560 tree decl;
1562 tree save_fn;
1564 if (type_lookups == error_mark_node)
1565 return;
1567 save_fn = current_function_decl;
1569 if (decl && TREE_CODE (decl) == FUNCTION_DECL)
1570 current_function_decl = decl;
1572 deferred_type_access_control ();
1574 current_function_decl = save_fn;
1576 /* Now strip away the checks for the current declarator; they were
1577 added to type_lookups after typed_declspecs saved the copy that
1578 ended up in current_type_lookups. */
1579 type_lookups = current_type_lookups;
1581 current_type_lookups = NULL_TREE;
1584 /* Record the lookups, if we're doing deferred access control. */
1586 void
1587 save_type_access_control (lookups)
1588 tree lookups;
1590 if (type_lookups != error_mark_node)
1592 my_friendly_assert (!current_type_lookups, 20010301);
1593 current_type_lookups = lookups;
1595 else
1596 my_friendly_assert (!lookups || lookups == error_mark_node, 20010301);
1599 /* Set things up so that the next deferred access control will succeed.
1600 This is needed for friend declarations see grokdeclarator for details. */
1602 void
1603 skip_type_access_control ()
1605 type_lookups = NULL_TREE;
1608 /* Reset the deferred access control. */
1610 void
1611 reset_type_access_control ()
1613 type_lookups = NULL_TREE;
1614 current_type_lookups = NULL_TREE;
1617 /* Begin a function definition declared with DECL_SPECS and
1618 DECLARATOR. Returns non-zero if the function-declaration is
1619 legal. */
1622 begin_function_definition (decl_specs, declarator)
1623 tree decl_specs;
1624 tree declarator;
1626 tree specs;
1627 tree attrs;
1629 split_specs_attrs (decl_specs, &specs, &attrs);
1630 if (!start_function (specs, declarator, attrs, SF_DEFAULT))
1631 return 0;
1633 deferred_type_access_control ();
1634 type_lookups = error_mark_node;
1636 /* The things we're about to see are not directly qualified by any
1637 template headers we've seen thus far. */
1638 reset_specialization ();
1640 return 1;
1643 /* Begin a constructor declarator of the form `SCOPE::NAME'. Returns
1644 a SCOPE_REF. */
1646 tree
1647 begin_constructor_declarator (scope, name)
1648 tree scope;
1649 tree name;
1651 tree result = build_nt (SCOPE_REF, scope, name);
1652 enter_scope_of (result);
1653 return result;
1656 /* Finish an init-declarator. Returns a DECL. */
1658 tree
1659 finish_declarator (declarator, declspecs, attributes,
1660 prefix_attributes, initialized)
1661 tree declarator;
1662 tree declspecs;
1663 tree attributes;
1664 tree prefix_attributes;
1665 int initialized;
1667 return start_decl (declarator, declspecs, initialized, attributes,
1668 prefix_attributes);
1671 /* Finish a translation unit. */
1673 void
1674 finish_translation_unit ()
1676 /* In case there were missing closebraces,
1677 get us back to the global binding level. */
1678 pop_everything ();
1679 while (current_namespace != global_namespace)
1680 pop_namespace ();
1682 /* Do file scope __FUNCTION__ et al. */
1683 finish_fname_decls ();
1685 finish_file ();
1688 /* Finish a template type parameter, specified as AGGR IDENTIFIER.
1689 Returns the parameter. */
1691 tree
1692 finish_template_type_parm (aggr, identifier)
1693 tree aggr;
1694 tree identifier;
1696 if (aggr != class_type_node)
1698 pedwarn ("template type parameters must use the keyword `class' or `typename'");
1699 aggr = class_type_node;
1702 return build_tree_list (aggr, identifier);
1705 /* Finish a template template parameter, specified as AGGR IDENTIFIER.
1706 Returns the parameter. */
1708 tree
1709 finish_template_template_parm (aggr, identifier)
1710 tree aggr;
1711 tree identifier;
1713 tree decl = build_decl (TYPE_DECL, identifier, NULL_TREE);
1714 tree tmpl = build_lang_decl (TEMPLATE_DECL, identifier, NULL_TREE);
1715 DECL_TEMPLATE_PARMS (tmpl) = current_template_parms;
1716 DECL_TEMPLATE_RESULT (tmpl) = decl;
1717 DECL_ARTIFICIAL (decl) = 1;
1718 end_template_decl ();
1720 my_friendly_assert (DECL_TEMPLATE_PARMS (tmpl), 20010110);
1722 return finish_template_type_parm (aggr, tmpl);
1725 /* Finish a parameter list, indicated by PARMS. If ELLIPSIS is
1726 non-zero, the parameter list was terminated by a `...'. */
1728 tree
1729 finish_parmlist (parms, ellipsis)
1730 tree parms;
1731 int ellipsis;
1733 if (parms)
1735 /* We mark the PARMS as a parmlist so that declarator processing can
1736 disambiguate certain constructs. */
1737 TREE_PARMLIST (parms) = 1;
1738 /* We do not append void_list_node here, but leave it to grokparms
1739 to do that. */
1740 PARMLIST_ELLIPSIS_P (parms) = ellipsis;
1742 return parms;
1745 /* Begin a class definition, as indicated by T. */
1747 tree
1748 begin_class_definition (t)
1749 tree t;
1751 /* Check the bases are accessible. */
1752 decl_type_access_control (TYPE_NAME (t));
1753 reset_type_access_control ();
1755 if (processing_template_parmlist)
1757 error ("definition of `%#T' inside template parameter list", t);
1758 return error_mark_node;
1761 /* In a definition of a member class template, we will get here with
1762 an implicit typename. */
1763 if (IMPLICIT_TYPENAME_P (t))
1764 t = TREE_TYPE (t);
1765 /* A non-implicit typename comes from code like:
1767 template <typename T> struct A {
1768 template <typename U> struct A<T>::B ...
1770 This is erroneous. */
1771 else if (TREE_CODE (t) == TYPENAME_TYPE)
1773 error ("invalid definition of qualified type `%T'", t);
1774 t = error_mark_node;
1777 if (t == error_mark_node || ! IS_AGGR_TYPE (t))
1779 t = make_aggr_type (RECORD_TYPE);
1780 pushtag (make_anon_name (), t, 0);
1783 /* If we generated a partial instantiation of this type, but now
1784 we're seeing a real definition, we're actually looking at a
1785 partial specialization. Consider:
1787 template <class T, class U>
1788 struct Y {};
1790 template <class T>
1791 struct X {};
1793 template <class T, class U>
1794 void f()
1796 typename X<Y<T, U> >::A a;
1799 template <class T, class U>
1800 struct X<Y<T, U> >
1804 We have to undo the effects of the previous partial
1805 instantiation. */
1806 if (PARTIAL_INSTANTIATION_P (t))
1808 if (!pedantic)
1810 /* Unfortunately, when we're not in pedantic mode, we
1811 attempt to actually fill in some of the fields of the
1812 partial instantiation, in order to support the implicit
1813 typename extension. Clear those fields now, in
1814 preparation for the definition here. The fields cleared
1815 here must match those set in instantiate_class_template.
1816 Look for a comment mentioning begin_class_definition
1817 there. */
1818 TYPE_BINFO_BASETYPES (t) = NULL_TREE;
1819 TYPE_FIELDS (t) = NULL_TREE;
1820 TYPE_METHODS (t) = NULL_TREE;
1821 CLASSTYPE_TAGS (t) = NULL_TREE;
1822 CLASSTYPE_VBASECLASSES (t) = NULL_TREE;
1823 TYPE_SIZE (t) = NULL_TREE;
1826 /* This isn't a partial instantiation any more. */
1827 PARTIAL_INSTANTIATION_P (t) = 0;
1829 /* If this type was already complete, and we see another definition,
1830 that's an error. */
1831 else if (COMPLETE_TYPE_P (t))
1832 duplicate_tag_error (t);
1834 /* Update the location of the decl. */
1835 DECL_SOURCE_FILE (TYPE_NAME (t)) = input_filename;
1836 DECL_SOURCE_LINE (TYPE_NAME (t)) = lineno;
1838 if (TYPE_BEING_DEFINED (t))
1840 t = make_aggr_type (TREE_CODE (t));
1841 pushtag (TYPE_IDENTIFIER (t), t, 0);
1843 maybe_process_partial_specialization (t);
1844 pushclass (t, 1);
1845 TYPE_BEING_DEFINED (t) = 1;
1846 TYPE_PACKED (t) = flag_pack_struct;
1847 /* Reset the interface data, at the earliest possible
1848 moment, as it might have been set via a class foo;
1849 before. */
1850 if (! TYPE_ANONYMOUS_P (t))
1852 CLASSTYPE_INTERFACE_ONLY (t) = interface_only;
1853 SET_CLASSTYPE_INTERFACE_UNKNOWN_X
1854 (t, interface_unknown);
1856 reset_specialization();
1858 /* Make a declaration for this class in its own scope. */
1859 build_self_reference ();
1861 return t;
1864 /* Finish the member declaration given by DECL. */
1866 void
1867 finish_member_declaration (decl)
1868 tree decl;
1870 if (decl == error_mark_node || decl == NULL_TREE)
1871 return;
1873 if (decl == void_type_node)
1874 /* The COMPONENT was a friend, not a member, and so there's
1875 nothing for us to do. */
1876 return;
1878 /* We should see only one DECL at a time. */
1879 my_friendly_assert (TREE_CHAIN (decl) == NULL_TREE, 0);
1881 /* Set up access control for DECL. */
1882 TREE_PRIVATE (decl)
1883 = (current_access_specifier == access_private_node);
1884 TREE_PROTECTED (decl)
1885 = (current_access_specifier == access_protected_node);
1886 if (TREE_CODE (decl) == TEMPLATE_DECL)
1888 TREE_PRIVATE (DECL_TEMPLATE_RESULT (decl)) = TREE_PRIVATE (decl);
1889 TREE_PROTECTED (DECL_TEMPLATE_RESULT (decl)) = TREE_PROTECTED (decl);
1892 /* Mark the DECL as a member of the current class. */
1893 DECL_CONTEXT (decl) = current_class_type;
1895 /* [dcl.link]
1897 A C language linkage is ignored for the names of class members
1898 and the member function type of class member functions. */
1899 if (DECL_LANG_SPECIFIC (decl) && DECL_LANGUAGE (decl) == lang_c)
1900 SET_DECL_LANGUAGE (decl, lang_cplusplus);
1902 /* Put functions on the TYPE_METHODS list and everything else on the
1903 TYPE_FIELDS list. Note that these are built up in reverse order.
1904 We reverse them (to obtain declaration order) in finish_struct. */
1905 if (TREE_CODE (decl) == FUNCTION_DECL
1906 || DECL_FUNCTION_TEMPLATE_P (decl))
1908 /* We also need to add this function to the
1909 CLASSTYPE_METHOD_VEC. */
1910 add_method (current_class_type, decl, /*error_p=*/0);
1912 TREE_CHAIN (decl) = TYPE_METHODS (current_class_type);
1913 TYPE_METHODS (current_class_type) = decl;
1915 else
1917 /* All TYPE_DECLs go at the end of TYPE_FIELDS. Ordinary fields
1918 go at the beginning. The reason is that lookup_field_1
1919 searches the list in order, and we want a field name to
1920 override a type name so that the "struct stat hack" will
1921 work. In particular:
1923 struct S { enum E { }; int E } s;
1924 s.E = 3;
1926 is legal. In addition, the FIELD_DECLs must be maintained in
1927 declaration order so that class layout works as expected.
1928 However, we don't need that order until class layout, so we
1929 save a little time by putting FIELD_DECLs on in reverse order
1930 here, and then reversing them in finish_struct_1. (We could
1931 also keep a pointer to the correct insertion points in the
1932 list.) */
1934 if (TREE_CODE (decl) == TYPE_DECL)
1935 TYPE_FIELDS (current_class_type)
1936 = chainon (TYPE_FIELDS (current_class_type), decl);
1937 else
1939 TREE_CHAIN (decl) = TYPE_FIELDS (current_class_type);
1940 TYPE_FIELDS (current_class_type) = decl;
1943 /* Enter the DECL into the scope of the class. */
1944 if (TREE_CODE (decl) != USING_DECL)
1945 pushdecl_class_level (decl);
1949 /* Finish a class definition T with the indicate ATTRIBUTES. If SEMI,
1950 the definition is immediately followed by a semicolon. Returns the
1951 type. */
1953 tree
1954 finish_class_definition (t, attributes, semi, pop_scope_p)
1955 tree t;
1956 tree attributes;
1957 int semi;
1958 int pop_scope_p;
1960 /* finish_struct nukes this anyway; if finish_exception does too,
1961 then it can go. */
1962 if (semi)
1963 note_got_semicolon (t);
1965 /* If we got any attributes in class_head, xref_tag will stick them in
1966 TREE_TYPE of the type. Grab them now. */
1967 attributes = chainon (TREE_TYPE (t), attributes);
1968 TREE_TYPE (t) = NULL_TREE;
1970 if (TREE_CODE (t) == ENUMERAL_TYPE)
1972 else
1974 t = finish_struct (t, attributes);
1975 if (semi)
1976 note_got_semicolon (t);
1979 if (! semi)
1980 check_for_missing_semicolon (t);
1981 if (pop_scope_p)
1982 pop_scope (CP_DECL_CONTEXT (TYPE_MAIN_DECL (t)));
1983 if (current_function_decl)
1984 type_lookups = error_mark_node;
1985 if (current_scope () == current_function_decl)
1986 do_pending_defargs ();
1988 return t;
1991 /* Finish processing the default argument expressions cached during
1992 the processing of a class definition. */
1994 void
1995 begin_inline_definitions ()
1997 if (current_scope () == current_function_decl)
1998 do_pending_inlines ();
2001 /* Finish processing the inline function definitions cached during the
2002 processing of a class definition. */
2004 void
2005 finish_inline_definitions ()
2007 if (current_class_type == NULL_TREE)
2008 clear_inline_text_obstack ();
2011 /* Finish processing the declaration of a member class template
2012 TYPES whose template parameters are given by PARMS. */
2014 tree
2015 finish_member_class_template (types)
2016 tree types;
2018 tree t;
2020 /* If there are declared, but undefined, partial specializations
2021 mixed in with the typespecs they will not yet have passed through
2022 maybe_process_partial_specialization, so we do that here. */
2023 for (t = types; t != NULL_TREE; t = TREE_CHAIN (t))
2024 if (IS_AGGR_TYPE_CODE (TREE_CODE (TREE_VALUE (t))))
2025 maybe_process_partial_specialization (TREE_VALUE (t));
2027 note_list_got_semicolon (types);
2028 grok_x_components (types);
2029 if (TYPE_CONTEXT (TREE_VALUE (types)) != current_class_type)
2030 /* The component was in fact a friend declaration. We avoid
2031 finish_member_template_decl performing certain checks by
2032 unsetting TYPES. */
2033 types = NULL_TREE;
2035 finish_member_template_decl (types);
2037 /* As with other component type declarations, we do
2038 not store the new DECL on the list of
2039 component_decls. */
2040 return NULL_TREE;
2043 /* Finish processing a complete template declaration. The PARMS are
2044 the template parameters. */
2046 void
2047 finish_template_decl (parms)
2048 tree parms;
2050 if (parms)
2051 end_template_decl ();
2052 else
2053 end_specialization ();
2056 /* Finish processing a template-id (which names a type) of the form
2057 NAME < ARGS >. Return the TYPE_DECL for the type named by the
2058 template-id. If ENTERING_SCOPE is non-zero we are about to enter
2059 the scope of template-id indicated. */
2061 tree
2062 finish_template_type (name, args, entering_scope)
2063 tree name;
2064 tree args;
2065 int entering_scope;
2067 tree decl;
2069 decl = lookup_template_class (name, args,
2070 NULL_TREE, NULL_TREE,
2071 entering_scope, /*complain=*/1);
2072 if (decl != error_mark_node)
2073 decl = TYPE_STUB_DECL (decl);
2075 return decl;
2078 /* SR is a SCOPE_REF node. Enter the scope of SR, whether it is a
2079 namespace scope or a class scope. */
2081 void
2082 enter_scope_of (sr)
2083 tree sr;
2085 tree scope = TREE_OPERAND (sr, 0);
2087 if (TREE_CODE (scope) == NAMESPACE_DECL)
2089 push_decl_namespace (scope);
2090 TREE_COMPLEXITY (sr) = -1;
2092 else if (scope != current_class_type)
2094 if (TREE_CODE (scope) == TYPENAME_TYPE)
2096 /* In a declarator for a template class member, the scope will
2097 get here as an implicit typename, a TYPENAME_TYPE with a type. */
2098 scope = TREE_TYPE (scope);
2099 TREE_OPERAND (sr, 0) = scope;
2101 push_nested_class (scope, 3);
2102 TREE_COMPLEXITY (sr) = current_class_depth;
2106 /* Finish processing a BASE_CLASS with the indicated ACCESS_SPECIFIER.
2107 Return a TREE_LIST containing the ACCESS_SPECIFIER and the
2108 BASE_CLASS, or NULL_TREE if an error occurred. The
2109 ACCESS_SPECIFIER is one of
2110 access_{default,public,protected_private}[_virtual]_node.*/
2112 tree
2113 finish_base_specifier (access_specifier, base_class)
2114 tree access_specifier;
2115 tree base_class;
2117 tree result;
2119 if (! is_aggr_type (base_class, 1))
2120 result = NULL_TREE;
2121 else
2123 if (cp_type_quals (base_class) != 0)
2125 error ("base class `%T' has cv qualifiers", base_class);
2126 base_class = TYPE_MAIN_VARIANT (base_class);
2128 result = build_tree_list (access_specifier, base_class);
2131 return result;
2134 /* Called when multiple declarators are processed. If that is not
2135 premitted in this context, an error is issued. */
2137 void
2138 check_multiple_declarators ()
2140 /* [temp]
2142 In a template-declaration, explicit specialization, or explicit
2143 instantiation the init-declarator-list in the declaration shall
2144 contain at most one declarator.
2146 We don't just use PROCESSING_TEMPLATE_DECL for the first
2147 condition since that would disallow the perfectly legal code,
2148 like `template <class T> struct S { int i, j; };'. */
2149 tree scope = current_scope ();
2151 if (scope && TREE_CODE (scope) == FUNCTION_DECL)
2152 /* It's OK to write `template <class T> void f() { int i, j;}'. */
2153 return;
2155 if (PROCESSING_REAL_TEMPLATE_DECL_P ()
2156 || processing_explicit_instantiation
2157 || processing_specialization)
2158 error ("multiple declarators in template declaration");
2161 /* Implement the __typeof keyword: Return the type of EXPR, suitable for
2162 use as a type-specifier. */
2164 tree
2165 finish_typeof (expr)
2166 tree expr;
2168 if (processing_template_decl)
2170 tree t;
2172 t = make_aggr_type (TYPEOF_TYPE);
2173 TYPE_FIELDS (t) = expr;
2175 return t;
2178 if (TREE_CODE (expr) == OFFSET_REF)
2179 expr = resolve_offset_ref (expr);
2181 return TREE_TYPE (expr);
2184 /* Compute the value of the `sizeof' operator. */
2186 tree
2187 finish_sizeof (t)
2188 tree t;
2190 if (processing_template_decl)
2191 return build_min_nt (SIZEOF_EXPR, t);
2193 return TYPE_P (t) ? c_sizeof (t) : expr_sizeof (t);
2196 /* Implement the __alignof keyword: Return the minimum required
2197 alignment of T, measured in bytes. */
2199 tree
2200 finish_alignof (t)
2201 tree t;
2203 if (processing_template_decl)
2204 return build_min_nt (ALIGNOF_EXPR, t);
2206 return TYPE_P (t) ? c_alignof (t) : c_alignof_expr (t);
2209 /* Generate RTL for the statement T, and its substatements, and any
2210 other statements at its nesting level. */
2212 static void
2213 cp_expand_stmt (t)
2214 tree t;
2216 switch (TREE_CODE (t))
2218 case CLEANUP_STMT:
2219 genrtl_decl_cleanup (CLEANUP_DECL (t), CLEANUP_EXPR (t));
2220 break;
2222 case CTOR_STMT:
2223 genrtl_ctor_stmt (t);
2224 break;
2226 case TRY_BLOCK:
2227 genrtl_try_block (t);
2228 break;
2230 case EH_SPEC_BLOCK:
2231 genrtl_eh_spec_block (t);
2232 break;
2234 case HANDLER:
2235 genrtl_handler (t);
2236 break;
2238 case SUBOBJECT:
2239 genrtl_subobject (SUBOBJECT_CLEANUP (t));
2240 break;
2242 case RETURN_INIT:
2243 genrtl_named_return_value ();
2244 break;
2246 case USING_STMT:
2247 break;
2249 default:
2250 my_friendly_abort (19990810);
2251 break;
2255 /* Called from expand_body via walk_tree. Replace all AGGR_INIT_EXPRs
2256 will equivalent CALL_EXPRs. */
2258 static tree
2259 simplify_aggr_init_exprs_r (tp, walk_subtrees, data)
2260 tree *tp;
2261 int *walk_subtrees ATTRIBUTE_UNUSED;
2262 void *data ATTRIBUTE_UNUSED;
2264 tree aggr_init_expr;
2265 tree call_expr;
2266 tree fn;
2267 tree args;
2268 tree slot;
2269 tree type;
2270 int copy_from_buffer_p;
2272 aggr_init_expr = *tp;
2273 /* We don't need to walk into types; there's nothing in a type that
2274 needs simplification. (And, furthermore, there are places we
2275 actively don't want to go. For example, we don't want to wander
2276 into the default arguments for a FUNCTION_DECL that appears in a
2277 CALL_EXPR.) */
2278 if (TYPE_P (aggr_init_expr))
2280 *walk_subtrees = 0;
2281 return NULL_TREE;
2283 /* Only AGGR_INIT_EXPRs are interesting. */
2284 else if (TREE_CODE (aggr_init_expr) != AGGR_INIT_EXPR)
2285 return NULL_TREE;
2287 /* Form an appropriate CALL_EXPR. */
2288 fn = TREE_OPERAND (aggr_init_expr, 0);
2289 args = TREE_OPERAND (aggr_init_expr, 1);
2290 slot = TREE_OPERAND (aggr_init_expr, 2);
2291 type = TREE_TYPE (aggr_init_expr);
2292 if (AGGR_INIT_VIA_CTOR_P (aggr_init_expr))
2294 /* Replace the first argument with the address of the third
2295 argument to the AGGR_INIT_EXPR. */
2296 mark_addressable (slot);
2297 args = tree_cons (NULL_TREE,
2298 build1 (ADDR_EXPR,
2299 build_pointer_type (TREE_TYPE (slot)),
2300 slot),
2301 TREE_CHAIN (args));
2303 call_expr = build (CALL_EXPR,
2304 TREE_TYPE (TREE_TYPE (TREE_TYPE (fn))),
2305 fn, args, NULL_TREE);
2306 TREE_SIDE_EFFECTS (call_expr) = 1;
2308 /* If we're using the non-reentrant PCC calling convention, then we
2309 need to copy the returned value out of the static buffer into the
2310 SLOT. */
2311 copy_from_buffer_p = 0;
2312 #ifdef PCC_STATIC_STRUCT_RETURN
2313 if (!AGGR_INIT_VIA_CTOR_P (aggr_init_expr) && aggregate_value_p (type))
2315 int old_ac = flag_access_control;
2317 flag_access_control = 0;
2318 call_expr = build_aggr_init (slot, call_expr,
2319 DIRECT_BIND | LOOKUP_ONLYCONVERTING);
2320 flag_access_control = old_ac;
2321 copy_from_buffer_p = 1;
2323 #endif
2325 /* If this AGGR_INIT_EXPR indicates the value returned by a
2326 function, then we want to use the value of the initialized
2327 location as the result. */
2328 if (AGGR_INIT_VIA_CTOR_P (aggr_init_expr) || copy_from_buffer_p)
2330 call_expr = build (COMPOUND_EXPR, type,
2331 call_expr, slot);
2332 TREE_SIDE_EFFECTS (call_expr) = 1;
2335 /* Replace the AGGR_INIT_EXPR with the CALL_EXPR. */
2336 TREE_CHAIN (call_expr) = TREE_CHAIN (aggr_init_expr);
2337 *tp = call_expr;
2339 /* Keep iterating. */
2340 return NULL_TREE;
2343 /* Emit all thunks to FN that should be emitted when FN is emitted. */
2345 static void
2346 emit_associated_thunks (fn)
2347 tree fn;
2349 /* When we use vcall offsets, we emit thunks with the virtual
2350 functions to which they thunk. The whole point of vcall offsets
2351 is so that you can know statically the entire set of thunks that
2352 will ever be needed for a given virtual function, thereby
2353 enabling you to output all the thunks with the function itself. */
2354 if (DECL_VIRTUAL_P (fn))
2356 tree binfo;
2357 tree v;
2359 for (binfo = TYPE_BINFO (DECL_CONTEXT (fn));
2360 binfo;
2361 binfo = TREE_CHAIN (binfo))
2362 for (v = BINFO_VIRTUALS (binfo); v; v = TREE_CHAIN (v))
2363 if (BV_FN (v) == fn
2364 && (!integer_zerop (BV_DELTA (v))
2365 || BV_USE_VCALL_INDEX_P (v)))
2367 tree thunk;
2368 tree vcall_index;
2370 if (BV_USE_VCALL_INDEX_P (v))
2372 vcall_index = BV_VCALL_INDEX (v);
2373 my_friendly_assert (vcall_index != NULL_TREE, 20000621);
2375 else
2376 vcall_index = NULL_TREE;
2378 thunk = make_thunk (build1 (ADDR_EXPR,
2379 vfunc_ptr_type_node,
2380 fn),
2381 BV_DELTA (v),
2382 vcall_index);
2383 use_thunk (thunk, /*emit_p=*/1);
2388 /* Generate RTL for FN. */
2390 void
2391 expand_body (fn)
2392 tree fn;
2394 int saved_lineno;
2395 const char *saved_input_filename;
2397 /* When the parser calls us after finishing the body of a template
2398 function, we don't really want to expand the body. When we're
2399 processing an in-class definition of an inline function,
2400 PROCESSING_TEMPLATE_DECL will no longer be set here, so we have
2401 to look at the function itself. */
2402 if (processing_template_decl
2403 || (DECL_LANG_SPECIFIC (fn)
2404 && DECL_TEMPLATE_INFO (fn)
2405 && uses_template_parms (DECL_TI_ARGS (fn))))
2407 /* Normally, collection only occurs in rest_of_compilation. So,
2408 if we don't collect here, we never collect junk generated
2409 during the processing of templates until we hit a
2410 non-template function. */
2411 ggc_collect ();
2412 return;
2415 /* Replace AGGR_INIT_EXPRs with appropriate CALL_EXPRs. */
2416 walk_tree_without_duplicates (&DECL_SAVED_TREE (fn),
2417 simplify_aggr_init_exprs_r,
2418 NULL);
2420 /* If this is a constructor or destructor body, we have to clone
2421 it. */
2422 if (maybe_clone_body (fn))
2424 /* We don't want to process FN again, so pretend we've written
2425 it out, even though we haven't. */
2426 TREE_ASM_WRITTEN (fn) = 1;
2427 return;
2430 /* There's no reason to do any of the work here if we're only doing
2431 semantic analysis; this code just generates RTL. */
2432 if (flag_syntax_only)
2433 return;
2435 /* If possible, avoid generating RTL for this function. Instead,
2436 just record it as an inline function, and wait until end-of-file
2437 to decide whether to write it out or not. */
2438 if (/* We have to generate RTL if it's not an inline function. */
2439 (DECL_INLINE (fn) || DECL_COMDAT (fn))
2440 /* Or if we have to emit code for inline functions anyhow. */
2441 && !flag_keep_inline_functions
2442 /* Or if we actually have a reference to the function. */
2443 && !DECL_NEEDED_P (fn))
2445 /* Set DECL_EXTERNAL so that assemble_external will be called as
2446 necessary. We'll clear it again in finish_file. */
2447 if (!DECL_EXTERNAL (fn))
2449 DECL_NOT_REALLY_EXTERN (fn) = 1;
2450 DECL_EXTERNAL (fn) = 1;
2452 /* Remember this function. In finish_file we'll decide if
2453 we actually need to write this function out. */
2454 defer_fn (fn);
2455 /* Let the back-end know that this function exists. */
2456 (*debug_hooks->deferred_inline_function) (fn);
2457 return;
2460 /* Compute the appropriate object-file linkage for inline
2461 functions. */
2462 if (DECL_DECLARED_INLINE_P (fn))
2463 import_export_decl (fn);
2465 /* If FN is external, then there's no point in generating RTL for
2466 it. This situation can arise with an inline function under
2467 `-fexternal-templates'; we instantiate the function, even though
2468 we're not planning on emitting it, in case we get a chance to
2469 inline it. */
2470 if (DECL_EXTERNAL (fn))
2471 return;
2473 /* Emit any thunks that should be emitted at the same time as FN. */
2474 emit_associated_thunks (fn);
2476 timevar_push (TV_INTEGRATION);
2478 /* Optimize the body of the function before expanding it. */
2479 optimize_function (fn);
2481 timevar_pop (TV_INTEGRATION);
2482 timevar_push (TV_EXPAND);
2484 /* Save the current file name and line number. When we expand the
2485 body of the function, we'll set LINENO and INPUT_FILENAME so that
2486 error-mesages come out in the right places. */
2487 saved_lineno = lineno;
2488 saved_input_filename = input_filename;
2489 lineno = DECL_SOURCE_LINE (fn);
2490 input_filename = DECL_SOURCE_FILE (fn);
2492 genrtl_start_function (fn);
2493 current_function_is_thunk = DECL_THUNK_P (fn);
2495 /* Expand the body. */
2496 expand_stmt (DECL_SAVED_TREE (fn));
2498 /* Statements should always be full-expressions at the outermost set
2499 of curly braces for a function. */
2500 my_friendly_assert (stmts_are_full_exprs_p (), 19990831);
2502 /* The outermost statement for a function contains the line number
2503 recorded when we finished processing the function. */
2504 lineno = STMT_LINENO (DECL_SAVED_TREE (fn));
2506 /* Generate code for the function. */
2507 genrtl_finish_function (fn);
2509 /* If possible, obliterate the body of the function so that it can
2510 be garbage collected. */
2511 if (dump_enabled_p (TDI_all))
2512 /* Keep the body; we're going to dump it. */
2514 else if (DECL_INLINE (fn) && flag_inline_trees)
2515 /* We might need the body of this function so that we can expand
2516 it inline somewhere else. */
2518 else
2519 /* We don't need the body; blow it away. */
2520 DECL_SAVED_TREE (fn) = NULL_TREE;
2522 /* And restore the current source position. */
2523 lineno = saved_lineno;
2524 input_filename = saved_input_filename;
2525 extract_interface_info ();
2527 timevar_pop (TV_EXPAND);
2530 /* Helper function for walk_tree, used by finish_function to override all
2531 the RETURN_STMTs and pertinent CLEANUP_STMTs for the named return
2532 value optimization. */
2534 tree
2535 nullify_returns_r (tp, walk_subtrees, data)
2536 tree *tp;
2537 int *walk_subtrees;
2538 void *data;
2540 tree nrv = (tree) data;
2542 /* No need to walk into types. There wouldn't be any need to walk into
2543 non-statements, except that we have to consider STMT_EXPRs. */
2544 if (TYPE_P (*tp))
2545 *walk_subtrees = 0;
2546 else if (TREE_CODE (*tp) == RETURN_STMT)
2547 RETURN_EXPR (*tp) = NULL_TREE;
2548 else if (TREE_CODE (*tp) == CLEANUP_STMT
2549 && CLEANUP_DECL (*tp) == nrv)
2550 CLEANUP_EXPR (*tp) = NULL_TREE;
2552 /* Keep iterating. */
2553 return NULL_TREE;
2556 /* Start generating the RTL for FN. */
2558 static void
2559 genrtl_start_function (fn)
2560 tree fn;
2562 /* Tell everybody what function we're processing. */
2563 current_function_decl = fn;
2564 /* Get the RTL machinery going for this function. */
2565 init_function_start (fn, DECL_SOURCE_FILE (fn), DECL_SOURCE_LINE (fn));
2566 /* Let everybody know that we're expanding this function, not doing
2567 semantic analysis. */
2568 expanding_p = 1;
2570 /* Even though we're inside a function body, we still don't want to
2571 call expand_expr to calculate the size of a variable-sized array.
2572 We haven't necessarily assigned RTL to all variables yet, so it's
2573 not safe to try to expand expressions involving them. */
2574 immediate_size_expand = 0;
2575 cfun->x_dont_save_pending_sizes_p = 1;
2577 /* Let the user know we're compiling this function. */
2578 announce_function (fn);
2580 /* Initialize the per-function data. */
2581 my_friendly_assert (!DECL_PENDING_INLINE_P (fn), 20000911);
2582 if (DECL_SAVED_FUNCTION_DATA (fn))
2584 /* If we already parsed this function, and we're just expanding it
2585 now, restore saved state. */
2586 *cp_function_chain = *DECL_SAVED_FUNCTION_DATA (fn);
2588 /* This function is being processed in whole-function mode; we
2589 already did semantic analysis. */
2590 cfun->x_whole_function_mode_p = 1;
2592 /* If we decided that we didn't want to inline this function,
2593 make sure the back-end knows that. */
2594 if (!current_function_cannot_inline)
2595 current_function_cannot_inline = cp_function_chain->cannot_inline;
2597 /* We don't need the saved data anymore. */
2598 free (DECL_SAVED_FUNCTION_DATA (fn));
2599 DECL_SAVED_FUNCTION_DATA (fn) = NULL;
2602 /* Tell the cross-reference machinery that we're defining this
2603 function. */
2604 GNU_xref_function (fn, DECL_ARGUMENTS (fn));
2606 /* Keep track of how many functions we're presently expanding. */
2607 ++function_depth;
2609 /* Create a binding level for the parameters. */
2610 expand_function_start (fn, /*parms_have_cleanups=*/0);
2611 /* If this function is `main'. */
2612 if (DECL_MAIN_P (fn))
2613 expand_main_function ();
2615 /* Give our named return value the same RTL as our RESULT_DECL. */
2616 if (current_function_return_value)
2617 COPY_DECL_RTL (DECL_RESULT (fn), current_function_return_value);
2620 /* Finish generating the RTL for FN. */
2622 static void
2623 genrtl_finish_function (fn)
2624 tree fn;
2626 tree t;
2628 #if 0
2629 if (write_symbols != NO_DEBUG)
2631 /* Keep this code around in case we later want to control debug info
2632 based on whether a type is "used". (jason 1999-11-11) */
2634 tree ttype = target_type (fntype);
2635 tree parmdecl;
2637 if (IS_AGGR_TYPE (ttype))
2638 /* Let debugger know it should output info for this type. */
2639 note_debug_info_needed (ttype);
2641 for (parmdecl = DECL_ARGUMENTS (fndecl); parmdecl; parmdecl = TREE_CHAIN (parmdecl))
2643 ttype = target_type (TREE_TYPE (parmdecl));
2644 if (IS_AGGR_TYPE (ttype))
2645 /* Let debugger know it should output info for this type. */
2646 note_debug_info_needed (ttype);
2649 #endif
2651 /* Clean house because we will need to reorder insns here. */
2652 do_pending_stack_adjust ();
2654 /* If we have a named return value, we need to force a return so that
2655 the return register is USEd. */
2656 if (DECL_NAME (DECL_RESULT (fn)))
2657 emit_jump (return_label);
2659 /* We hard-wired immediate_size_expand to zero in start_function.
2660 Expand_function_end will decrement this variable. So, we set the
2661 variable to one here, so that after the decrement it will remain
2662 zero. */
2663 immediate_size_expand = 1;
2665 /* Generate rtl for function exit. */
2666 expand_function_end (input_filename, lineno, 0);
2668 /* If this is a nested function (like a template instantiation that
2669 we're compiling in the midst of compiling something else), push a
2670 new GC context. That will keep local variables on the stack from
2671 being collected while we're doing the compilation of this
2672 function. */
2673 if (function_depth > 1)
2674 ggc_push_context ();
2676 /* There's no need to defer outputting this function any more; we
2677 know we want to output it. */
2678 DECL_DEFER_OUTPUT (fn) = 0;
2680 /* Run the optimizers and output the assembler code for this
2681 function. */
2682 rest_of_compilation (fn);
2684 /* Undo the call to ggc_push_context above. */
2685 if (function_depth > 1)
2686 ggc_pop_context ();
2688 #if 0
2689 /* Keep this code around in case we later want to control debug info
2690 based on whether a type is "used". (jason 1999-11-11) */
2692 if (ctype && TREE_ASM_WRITTEN (fn))
2693 note_debug_info_needed (ctype);
2694 #endif
2696 /* If this function is marked with the constructor attribute, add it
2697 to the list of functions to be called along with constructors
2698 from static duration objects. */
2699 if (DECL_STATIC_CONSTRUCTOR (fn))
2700 static_ctors = tree_cons (NULL_TREE, fn, static_ctors);
2702 /* If this function is marked with the destructor attribute, add it
2703 to the list of functions to be called along with destructors from
2704 static duration objects. */
2705 if (DECL_STATIC_DESTRUCTOR (fn))
2706 static_dtors = tree_cons (NULL_TREE, fn, static_dtors);
2708 --function_depth;
2710 /* In C++, we should never be saving RTL for the function. */
2711 my_friendly_assert (!DECL_SAVED_INSNS (fn), 20010903);
2713 /* Since we don't need the RTL for this function anymore, stop
2714 pointing to it. That's especially important for LABEL_DECLs,
2715 since you can reach all the instructions in the function from the
2716 CODE_LABEL stored in the DECL_RTL for the LABEL_DECL. Walk the
2717 BLOCK-tree, clearing DECL_RTL for LABEL_DECLs and non-static
2718 local variables. */
2719 walk_tree_without_duplicates (&DECL_SAVED_TREE (fn),
2720 clear_decl_rtl,
2721 NULL);
2723 /* Clear out the RTL for the arguments. */
2724 for (t = DECL_ARGUMENTS (fn); t; t = TREE_CHAIN (t))
2726 SET_DECL_RTL (t, NULL_RTX);
2727 DECL_INCOMING_RTL (t) = NULL_RTX;
2730 if (!(flag_inline_trees && DECL_INLINE (fn)))
2731 /* DECL_INITIAL must remain nonzero so we know this was an
2732 actual function definition. */
2733 DECL_INITIAL (fn) = error_mark_node;
2735 /* Let the error reporting routines know that we're outside a
2736 function. For a nested function, this value is used in
2737 pop_cp_function_context and then reset via pop_function_context. */
2738 current_function_decl = NULL_TREE;
2741 /* Clear out the DECL_RTL for the non-static variables in BLOCK and
2742 its sub-blocks. */
2744 static tree
2745 clear_decl_rtl (tp, walk_subtrees, data)
2746 tree *tp;
2747 int *walk_subtrees ATTRIBUTE_UNUSED;
2748 void *data ATTRIBUTE_UNUSED;
2750 if (nonstatic_local_decl_p (*tp))
2751 SET_DECL_RTL (*tp, NULL_RTX);
2753 return NULL_TREE;
2756 /* Perform initialization related to this module. */
2758 void
2759 init_cp_semantics ()
2761 lang_expand_stmt = cp_expand_stmt;