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 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)
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
36 /* There routines provide a modular interface to perform many parsing
37 operations. They may therefore be used during actual parsing, or
38 during template instantiation, which may be regarded as a
39 degenerate form of parsing. Since the current g++ parser is
40 lacking in several respects, and will be reimplemented, we are
41 attempting to move most code that is not directly related to
42 parsing into this file; that will make implementing the new parser
43 much easier since it will be able to make use of these routines. */
45 static tree expand_cond
PROTO((tree
));
46 static tree maybe_convert_cond
PROTO((tree
));
48 /* Record the fact that STMT was the last statement added to the
51 #define SET_LAST_STMT(stmt) \
52 (current_stmt_tree->x_last_stmt = (stmt))
54 /* When parsing a template, LAST_TREE contains the last statement
55 parsed. These are chained together through the TREE_CHAIN field,
56 but often need to be re-organized since the parse is performed
57 bottom-up. This macro makes LAST_TREE the indicated SUBSTMT of
60 #define RECHAIN_STMTS(stmt, substmt) \
62 substmt = TREE_CHAIN (stmt); \
63 TREE_CHAIN (stmt) = NULL_TREE; \
64 SET_LAST_STMT (stmt); \
67 /* Finish processing the COND, the SUBSTMT condition for STMT. */
69 #define FINISH_COND(cond, stmt, substmt) \
71 if (last_tree != stmt) \
73 RECHAIN_STMTS (stmt, substmt); \
74 if (!processing_template_decl) \
76 cond = build_tree_list (substmt, cond); \
84 /* T is a statement. Add it to the statement-tree. */
90 /* Add T to the statement-tree. */
91 TREE_CHAIN (last_tree
) = t
;
94 /* When we expand a statement-tree, we must know whether or not the
95 statements are full-expresions. We record that fact here. */
96 if (building_stmt_tree ())
97 STMT_IS_FULL_EXPR_P (last_tree
) = stmts_are_full_exprs_p
;
100 /* COND is the condition-expression for an if, while, etc.,
101 statement. Convert it to a boolean value, if appropriate. */
104 maybe_convert_cond (cond
)
107 /* Empty conditions remain empty. */
111 /* Wait until we instantiate templates before doing conversion. */
112 if (processing_template_decl
)
115 /* Do the conversion. */
116 cond
= convert_from_reference (cond
);
117 return condition_conversion (cond
);
120 /* Finish an expression-statement, whose EXPRESSION is as indicated. */
123 finish_expr_stmt (expr
)
126 if (expr
!= NULL_TREE
)
128 if (building_stmt_tree ())
129 add_tree (build_min_nt (EXPR_STMT
, expr
));
132 emit_line_note (input_filename
, lineno
);
133 /* Do default conversion if safe and possibly important,
134 in case within ({...}). */
135 if (!stmts_are_full_exprs_p
&&
136 ((TREE_CODE (TREE_TYPE (expr
)) == ARRAY_TYPE
138 || TREE_CODE (TREE_TYPE (expr
)) == FUNCTION_TYPE
))
139 expr
= default_conversion (expr
);
141 if (stmts_are_full_exprs_p
)
142 expand_start_target_temps ();
144 cplus_expand_expr_stmt (expr
);
146 if (stmts_are_full_exprs_p
)
148 expand_end_target_temps ();
156 /* This was an expression-statement, so we save the type of the
158 last_expr_type
= expr
? TREE_TYPE (expr
) : NULL_TREE
;
161 /* Begin an if-statement. Returns a newly created IF_STMT if
171 if (building_stmt_tree ())
173 r
= build_min_nt (IF_STMT
, NULL_TREE
, NULL_TREE
, NULL_TREE
);
182 /* Process the COND of an if-statement, which may be given by
186 finish_if_stmt_cond (cond
, if_stmt
)
190 cond
= maybe_convert_cond (cond
);
192 if (building_stmt_tree ())
193 FINISH_COND (cond
, if_stmt
, IF_COND (if_stmt
));
196 emit_line_note (input_filename
, lineno
);
197 expand_start_cond (cond
, 0);
201 /* Finish the then-clause of an if-statement, which may be given by
205 finish_then_clause (if_stmt
)
208 if (building_stmt_tree ())
210 RECHAIN_STMTS (if_stmt
, THEN_CLAUSE (if_stmt
));
211 SET_LAST_STMT (if_stmt
);
218 /* Begin the else-clause of an if-statement. */
223 if (!building_stmt_tree ())
224 expand_start_else ();
227 /* Finish the else-clause of an if-statement, which may be given by
231 finish_else_clause (if_stmt
)
234 if (building_stmt_tree ())
235 RECHAIN_STMTS (if_stmt
, ELSE_CLAUSE (if_stmt
));
238 /* Finsh an if-statement. */
243 if (!building_stmt_tree ())
250 /* Begin a while-statement. Returns a newly created WHILE_STMT if
258 if (building_stmt_tree ())
260 r
= build_min_nt (WHILE_STMT
, NULL_TREE
, NULL_TREE
);
266 emit_line_note (input_filename
, lineno
);
267 expand_start_loop (1);
276 /* Process the COND of an if-statement, which may be given by
280 finish_while_stmt_cond (cond
, while_stmt
)
284 cond
= maybe_convert_cond (cond
);
286 if (building_stmt_tree ())
287 FINISH_COND (cond
, while_stmt
, WHILE_COND (while_stmt
));
290 emit_line_note (input_filename
, lineno
);
291 expand_exit_loop_if_false (0, cond
);
294 /* If COND wasn't a declaration, clear out the
295 block we made for it and start a new one here so the
296 optimization in expand_end_loop will work. */
297 if (getdecls () == NULL_TREE
)
304 /* Finish a while-statement, which may be given by WHILE_STMT. */
307 finish_while_stmt (while_stmt
)
312 if (building_stmt_tree ())
313 RECHAIN_STMTS (while_stmt
, WHILE_BODY (while_stmt
));
319 /* Begin a do-statement. Returns a newly created DO_STMT if
325 if (building_stmt_tree ())
327 tree r
= build_min_nt (DO_STMT
, NULL_TREE
, NULL_TREE
);
334 emit_line_note (input_filename
, lineno
);
335 expand_start_loop_continue_elsewhere (1);
340 /* Finish the body of a do-statement, which may be given by DO_STMT. */
343 finish_do_body (do_stmt
)
346 if (building_stmt_tree ())
347 RECHAIN_STMTS (do_stmt
, DO_BODY (do_stmt
));
349 expand_loop_continue_here ();
352 /* Finish a do-statement, which may be given by DO_STMT, and whose
353 COND is as indicated. */
356 finish_do_stmt (cond
, do_stmt
)
360 cond
= maybe_convert_cond (cond
);
362 if (building_stmt_tree ())
363 DO_COND (do_stmt
) = cond
;
366 emit_line_note (input_filename
, lineno
);
367 expand_exit_loop_if_false (0, cond
);
375 /* Finish a return-statement. The EXPRESSION returned, if any, is as
379 finish_return_stmt (expr
)
382 if (doing_semantic_analysis_p () && !processing_template_decl
)
383 expr
= check_return_expr (expr
);
385 if (doing_semantic_analysis_p () && !processing_template_decl
)
387 if (DECL_CONSTRUCTOR_P (current_function_decl
) && ctor_label
)
389 /* Even returns without a value in a constructor must return
390 `this'. We accomplish this by sending all returns in a
391 constructor to the CTOR_LABEL; finish_function emits code to
392 return a value there. When we finally generate the real
393 return statement, CTOR_LABEL is no longer set, and we fall
394 through into the normal return-processing code below. */
395 finish_goto_stmt (ctor_label
);
398 else if (DECL_DESTRUCTOR_P (current_function_decl
))
400 /* Similarly, all destructors must run destructors for
401 base-classes before returning. So, all returns in a
402 destructor get sent to the DTOR_LABEL; finsh_function emits
403 code to return a value there. */
404 finish_goto_stmt (dtor_label
);
409 if (building_stmt_tree ())
410 add_tree (build_min_nt (RETURN_STMT
, expr
));
413 emit_line_note (input_filename
, lineno
);
414 c_expand_return (expr
);
420 /* Begin a for-statement. Returns a new FOR_STMT if appropriate. */
427 if (building_stmt_tree ())
429 r
= build_min_nt (FOR_STMT
, NULL_TREE
, NULL_TREE
,
430 NULL_TREE
, NULL_TREE
);
436 if (flag_new_for_scope
> 0)
439 note_level_for_for ();
445 /* Finish the for-init-statement of a for-statement, which may be
446 given by FOR_STMT. */
449 finish_for_init_stmt (for_stmt
)
452 if (building_stmt_tree ())
454 if (last_tree
!= for_stmt
)
455 RECHAIN_STMTS (for_stmt
, FOR_INIT_STMT (for_stmt
));
460 emit_line_note (input_filename
, lineno
);
461 expand_start_loop_continue_elsewhere (1);
467 /* Finish the COND of a for-statement, which may be given by
471 finish_for_cond (cond
, for_stmt
)
475 cond
= maybe_convert_cond (cond
);
477 if (building_stmt_tree ())
478 FINISH_COND (cond
, for_stmt
, FOR_COND (for_stmt
));
481 emit_line_note (input_filename
, lineno
);
483 expand_exit_loop_if_false (0, cond
);
486 /* If the cond wasn't a declaration, clear out the
487 block we made for it and start a new one here so the
488 optimization in expand_end_loop will work. */
489 if (getdecls () == NULL_TREE
)
496 /* Finish the increment-EXPRESSION in a for-statement, which may be
497 given by FOR_STMT. */
500 finish_for_expr (expr
, for_stmt
)
504 if (building_stmt_tree ())
505 FOR_EXPR (for_stmt
) = expr
;
507 /* Don't let the tree nodes for EXPR be discarded
508 by clear_momentary during the parsing of the next stmt. */
512 /* Finish the body of a for-statement, which may be given by
513 FOR_STMT. The increment-EXPR for the loop must be
517 finish_for_stmt (expr
, for_stmt
)
521 /* Pop the scope for the body of the loop. */
524 if (building_stmt_tree ())
525 RECHAIN_STMTS (for_stmt
, FOR_BODY (for_stmt
));
528 emit_line_note (input_filename
, lineno
);
529 expand_loop_continue_here ();
531 finish_expr_stmt (expr
);
537 if (flag_new_for_scope
> 0)
543 /* Finish a break-statement. */
548 emit_line_note (input_filename
, lineno
);
549 if (building_stmt_tree ())
550 add_tree (build_min_nt (BREAK_STMT
));
551 else if ( ! expand_exit_something ())
552 cp_error ("break statement not within loop or switch");
555 /* Finish a continue-statement. */
558 finish_continue_stmt ()
560 emit_line_note (input_filename
, lineno
);
561 if (building_stmt_tree ())
562 add_tree (build_min_nt (CONTINUE_STMT
));
563 else if (! expand_continue_loop (0))
564 cp_error ("continue statement not within a loop");
567 /* Begin a switch-statement. Returns a new SWITCH_STMT if
575 if (building_stmt_tree ())
577 r
= build_min_nt (SWITCH_STMT
, NULL_TREE
, NULL_TREE
);
588 /* Finish the cond of a switch-statement. */
591 finish_switch_cond (cond
, switch_stmt
)
595 if (building_stmt_tree ())
596 FINISH_COND (cond
, switch_stmt
, SWITCH_COND (switch_stmt
));
597 else if (cond
!= error_mark_node
)
599 emit_line_note (input_filename
, lineno
);
600 c_expand_start_case (cond
);
603 /* The code is in error, but we don't want expand_end_case to
605 c_expand_start_case (boolean_false_node
);
609 /* Don't let the tree nodes for COND be discarded by
610 clear_momentary during the parsing of the next stmt. */
614 /* Finish the body of a switch-statement, which may be given by
615 SWITCH_STMT. The COND to switch on is indicated. */
618 finish_switch_stmt (cond
, switch_stmt
)
622 if (building_stmt_tree ())
623 RECHAIN_STMTS (switch_stmt
, SWITCH_BODY (switch_stmt
));
625 expand_end_case (cond
);
632 /* Finish a case-label. */
635 finish_case_label (low_value
, high_value
)
639 if (building_stmt_tree ())
641 /* Add a representation for the case label to the statement
643 add_tree (build_min_nt (CASE_LABEL
, low_value
, high_value
));
644 /* And warn about crossing initializations, etc. */
645 if (!processing_template_decl
)
646 define_case_label ();
650 do_case (low_value
, high_value
);
653 /* Finish a goto-statement. */
656 finish_goto_stmt (destination
)
659 if (TREE_CODE (destination
) == IDENTIFIER_NODE
)
660 destination
= lookup_label (destination
);
662 /* We warn about unused labels with -Wunused. That means we have to
663 mark the used labels as used. */
664 if (TREE_CODE (destination
) == LABEL_DECL
)
665 TREE_USED (destination
) = 1;
667 if (building_stmt_tree ())
668 add_tree (build_min_nt (GOTO_STMT
, destination
));
671 emit_line_note (input_filename
, lineno
);
673 if (TREE_CODE (destination
) == LABEL_DECL
)
675 label_rtx (destination
);
676 expand_goto (destination
);
679 expand_computed_goto (destination
);
683 /* Begin a try-block. Returns a newly-created TRY_BLOCK if
689 if (building_stmt_tree ())
691 tree r
= build_min_nt (TRY_BLOCK
, NULL_TREE
,
698 emit_line_note (input_filename
, lineno
);
699 expand_start_try_stmts ();
704 /* Likewise, for a function-try-block. */
707 begin_function_try_block ()
709 if (building_stmt_tree ())
711 tree r
= build_min_nt (TRY_BLOCK
, NULL_TREE
,
713 FN_TRY_BLOCK_P (r
) = 1;
719 if (! current_function_parms_stored
)
721 expand_start_early_try_stmts ();
726 /* Finish a try-block, which may be given by TRY_BLOCK. */
729 finish_try_block (try_block
)
732 if (building_stmt_tree ())
733 RECHAIN_STMTS (try_block
, TRY_STMTS (try_block
));
735 expand_start_all_catch ();
738 /* Finish the body of a cleanup try-block, which may be given by
742 finish_cleanup_try_block (try_block
)
745 if (building_stmt_tree ())
746 RECHAIN_STMTS (try_block
, TRY_STMTS (try_block
));
749 /* Finish an implicitly generated try-block, with a cleanup is given
753 finish_cleanup (cleanup
, try_block
)
757 if (building_stmt_tree ())
759 TRY_HANDLERS (try_block
) = cleanup
;
760 CLEANUP_P (try_block
) = 1;
763 expand_eh_region_end (protect_with_terminate (cleanup
));
766 /* Likewise, for a function-try-block. */
769 finish_function_try_block (try_block
)
772 if (building_stmt_tree ())
774 if (TREE_CHAIN (try_block
)
775 && TREE_CODE (TREE_CHAIN (try_block
)) == CTOR_INITIALIZER
)
777 /* Chain the compound statement after the CTOR_INITIALIZER. */
778 TREE_CHAIN (TREE_CHAIN (try_block
)) = last_tree
;
779 /* And make the CTOR_INITIALIZER the body of the try-block. */
780 RECHAIN_STMTS (try_block
, TRY_STMTS (try_block
));
783 RECHAIN_STMTS (try_block
, TRY_STMTS (try_block
));
787 end_protect_partials ();
788 expand_start_all_catch ();
791 in_function_try_handler
= 1;
794 /* Finish a handler-sequence for a try-block, which may be given by
798 finish_handler_sequence (try_block
)
801 if (building_stmt_tree ())
802 RECHAIN_STMTS (try_block
, TRY_HANDLERS (try_block
));
804 expand_end_all_catch ();
807 /* Likewise, for a function-try-block. */
810 finish_function_handler_sequence (try_block
)
813 in_function_try_handler
= 0;
815 if (building_stmt_tree ())
816 RECHAIN_STMTS (try_block
, TRY_HANDLERS (try_block
));
818 expand_end_all_catch ();
821 /* Begin a handler. Returns a HANDLER if appropriate. */
828 if (building_stmt_tree ())
830 r
= build_min_nt (HANDLER
, NULL_TREE
, NULL_TREE
);
841 /* Finish the handler-parameters for a handler, which may be given by
842 HANDLER. DECL is the declaration for the catch parameter, or NULL
843 if this is a `catch (...)' clause. */
846 finish_handler_parms (decl
, handler
)
850 tree blocks
= NULL_TREE
;
852 if (processing_template_decl
)
856 decl
= pushdecl (decl
);
857 decl
= push_template_decl (decl
);
858 add_decl_stmt (decl
);
859 RECHAIN_STMTS (handler
, HANDLER_PARMS (handler
));
862 else if (building_stmt_tree ())
863 blocks
= expand_start_catch_block (decl
);
868 /* Note the beginning of a handler for TYPE. This function is called
869 at the point to which control should be transferred when an
870 appropriately-typed exception is thrown. */
873 begin_catch_block (type
)
876 if (building_stmt_tree ())
877 add_tree (build (START_CATCH_STMT
, type
));
879 start_catch_handler (type
);
882 /* Finish a handler, which may be given by HANDLER. The BLOCKs are
883 the return value from the matching call to finish_handler_parms. */
886 finish_handler (blocks
, handler
)
890 if (!processing_template_decl
)
892 if (building_stmt_tree ())
893 expand_end_catch_block (blocks
);
895 if (!building_stmt_tree ())
897 /* Fall to outside the try statement when done executing
898 handler and we fall off end of handler. This is jump
899 Lresume in the documentation. */
900 expand_goto (top_label_entry (&caught_return_label_stack
));
901 end_catch_handler ();
905 if (building_stmt_tree ())
906 RECHAIN_STMTS (handler
, HANDLER_BODY (handler
));
911 /* Begin a compound-statement. If HAS_NO_SCOPE is non-zero, the
912 compound-statement does not define a scope. Returns a new
913 COMPOUND_STMT if appropriate. */
916 begin_compound_stmt (has_no_scope
)
921 if (building_stmt_tree ())
923 r
= build_min_nt (COMPOUND_STMT
, NULL_TREE
);
926 COMPOUND_STMT_NO_SCOPE (r
) = 1;
931 last_expr_type
= NULL_TREE
;
936 /* Normally, we try hard to keep the BLOCK for a
937 statement-expression. But, if it's a statement-expression with
938 a scopeless block, there's nothing to keep, and we don't want
939 to accidentally keep a block *inside* the scopeless block. */
942 /* If this is the outermost block of the function, declare the
943 variables __FUNCTION__, __PRETTY_FUNCTION__, and so forth. */
945 && !current_function_name_declared
946 && !processing_template_decl
949 declare_function_name ();
950 current_function_name_declared
= 1;
957 /* Finish a compound-statement, which may be given by COMPOUND_STMT.
958 If HAS_NO_SCOPE is non-zero, the compound statement does not define
962 finish_compound_stmt (has_no_scope
, compound_stmt
)
974 if (building_stmt_tree ())
975 RECHAIN_STMTS (compound_stmt
, COMPOUND_BODY (compound_stmt
));
977 /* When we call finish_stmt we will lose LAST_EXPR_TYPE. But, since
978 the precise purpose of that variable is store the type of the
979 last expression statement within the last compound statement, we
980 preserve the value. */
988 /* Finish an asm-statement, whose components are a CV_QUALIFIER, a
989 STRING, some OUTPUT_OPERANDS, some INPUT_OPERANDS, and some
993 finish_asm_stmt (cv_qualifier
, string
, output_operands
,
994 input_operands
, clobbers
)
997 tree output_operands
;
1001 if (TREE_CHAIN (string
))
1003 if (building_stmt_tree ())
1004 /* We need to build the combined string on the permanent
1005 obstack so that we can use it during instantiations. */
1006 push_permanent_obstack ();
1008 string
= combine_strings (string
);
1010 if (building_stmt_tree ())
1014 if (cv_qualifier
!= NULL_TREE
1015 && cv_qualifier
!= ridpointers
[(int) RID_VOLATILE
])
1017 cp_warning ("%s qualifier ignored on asm",
1018 IDENTIFIER_POINTER (cv_qualifier
));
1019 cv_qualifier
= NULL_TREE
;
1022 if (building_stmt_tree ())
1024 tree r
= build_min_nt (ASM_STMT
, cv_qualifier
, string
,
1025 output_operands
, input_operands
,
1031 emit_line_note (input_filename
, lineno
);
1032 if (output_operands
!= NULL_TREE
|| input_operands
!= NULL_TREE
1033 || clobbers
!= NULL_TREE
)
1037 for (t
= input_operands
; t
; t
= TREE_CHAIN (t
))
1038 TREE_VALUE (t
) = decay_conversion (TREE_VALUE (t
));
1040 c_expand_asm_operands (string
, output_operands
,
1043 cv_qualifier
!= NULL_TREE
,
1044 input_filename
, lineno
);
1047 expand_asm (string
);
1053 /* Finish a label with the indicated NAME. */
1056 finish_label_stmt (name
)
1059 tree decl
= define_label (input_filename
, lineno
, name
);
1061 if (building_stmt_tree ())
1062 add_tree (build_min_nt (LABEL_STMT
, decl
));
1064 expand_label (decl
);
1067 /* Finish a series of declarations for local labels. G++ allows users
1068 to declare "local" labels, i.e., labels with scope. This extension
1069 is useful when writing code involving statement-expressions. */
1072 finish_label_decl (name
)
1075 tree decl
= declare_local_label (name
);
1076 if (building_stmt_tree ())
1077 add_decl_stmt (decl
);
1080 /* Create a declaration statement for the declaration given by the
1084 add_decl_stmt (decl
)
1089 /* We need the type to last until instantiation time. */
1090 decl_stmt
= build_min_nt (DECL_STMT
, decl
);
1091 add_tree (decl_stmt
);
1094 /* We're in a constructor, and have just constructed a a subobject of
1095 *THIS. CLEANUP is code to run if an exception is thrown before the
1096 end of the current function is reached. */
1099 finish_subobject (cleanup
)
1102 if (building_stmt_tree ())
1104 tree r
= build_min_nt (SUBOBJECT
, cleanup
);
1108 add_partial_entry (cleanup
);
1111 /* When DECL goes out of scope, make sure that CLEANUP is executed. */
1114 finish_decl_cleanup (decl
, cleanup
)
1118 if (building_stmt_tree ())
1119 add_tree (build_min_nt (CLEANUP_STMT
, decl
, cleanup
));
1121 || (DECL_SIZE (decl
) && TREE_TYPE (decl
) != error_mark_node
))
1122 expand_decl_cleanup (decl
, cleanup
);
1125 /* Bind a name and initialization to the return value of
1126 the current function. */
1129 finish_named_return_value (return_id
, init
)
1130 tree return_id
, init
;
1132 tree decl
= DECL_RESULT (current_function_decl
);
1135 /* Give this error as many times as there are occurrences,
1136 so that users can use Emacs compilation buffers to find
1137 and fix all such places. */
1138 pedwarn ("ANSI C++ does not permit named return values");
1140 if (return_id
!= NULL_TREE
)
1142 if (DECL_NAME (decl
) == NULL_TREE
)
1144 DECL_NAME (decl
) = return_id
;
1145 DECL_ASSEMBLER_NAME (decl
) = return_id
;
1149 cp_error ("return identifier `%D' already in place", return_id
);
1154 /* Can't let this happen for constructors. */
1155 if (DECL_CONSTRUCTOR_P (current_function_decl
))
1157 error ("can't redefine default return value for constructors");
1161 /* If we have a named return value, put that in our scope as well. */
1162 if (DECL_NAME (decl
) != NULL_TREE
)
1164 /* Let `cp_finish_decl' know that this initializer is ok. */
1165 DECL_INITIAL (decl
) = init
;
1166 if (doing_semantic_analysis_p ())
1169 if (building_stmt_tree ())
1170 add_tree (build_min_nt (RETURN_INIT
, return_id
, init
));
1173 cp_finish_decl (decl
, init
, NULL_TREE
, 0, 0);
1174 store_return_init (decl
);
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. */
1186 my_friendly_assert (doing_semantic_analysis_p (), 19990919);
1188 /* If we've already done this, there's no need to do it again. */
1192 if (DECL_CONSTRUCTOR_P (current_function_decl
))
1194 if (processing_template_decl
)
1195 add_tree (build_min_nt
1197 current_member_init_list
, current_base_init_list
));
1199 finish_expr_stmt (emit_base_init (current_class_type
));
1201 else if (DECL_DESTRUCTOR_P (current_function_decl
)
1202 && !processing_template_decl
)
1204 tree binfo
= TYPE_BINFO (current_class_type
);
1208 /* If the dtor is empty, and we know there is not possible way we
1209 could use any vtable entries, before they are possibly set by
1210 a base class dtor, we don't have to setup the vtables, as we
1211 know that any base class dtoring will set up any vtables it
1212 needs. We avoid MI, because one base class dtor can do a
1213 virtual dispatch to an overridden function that would need to
1214 have a non-related vtable set up, we cannot avoid setting up
1215 vtables in that case. We could change this to see if there is
1217 if_stmt
= begin_if_stmt ();
1219 /* If it is not safe to avoid setting up the vtables, then
1220 someone will change the condition to be boolean_true_node.
1221 (Actually, for now, we do not have code to set the condition
1222 appropriate, so we just assume that we always need to
1223 initialize the vtables.) */
1224 finish_if_stmt_cond (boolean_true_node
, if_stmt
);
1225 current_vcalls_possible_p
= &IF_COND (if_stmt
);
1226 compound_stmt
= begin_compound_stmt (/*has_no_scope=*/0);
1228 /* Make all virtual function table pointers in non-virtual base
1229 classes point to CURRENT_CLASS_TYPE's virtual function
1231 expand_direct_vtbls_init (binfo
, binfo
, 1, 0, current_class_ptr
);
1233 if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type
))
1234 expand_indirect_vtbls_init (binfo
, current_class_ref
,
1237 finish_compound_stmt (/*has_no_scope=*/0, compound_stmt
);
1238 finish_then_clause (if_stmt
);
1242 /* Always keep the BLOCK node associated with the outermost pair of
1243 curly braces of a function. These are needed for correct
1244 operation of dwarfout.c. */
1245 keep_next_level (1);
1247 /* The virtual function tables are set up now. */
1251 /* Begin a new scope. */
1256 if (!building_stmt_tree ())
1258 emit_line_note (input_filename
, lineno
);
1262 if (stmts_are_full_exprs_p
)
1265 if (!building_stmt_tree ()
1266 && !current_function
->x_whole_function_mode_p
)
1267 expand_start_bindings (0);
1268 else if (building_stmt_tree () && !processing_template_decl
)
1270 tree ss
= build_min_nt (SCOPE_STMT
);
1271 SCOPE_BEGIN_P (ss
) = 1;
1273 current_scope_stmt_stack
1274 = tree_cons (NULL_TREE
, ss
, current_scope_stmt_stack
);
1279 /* Finish a scope. */
1286 if (stmts_are_full_exprs_p
)
1288 if (!building_stmt_tree ()
1289 && !current_function
->x_whole_function_mode_p
)
1290 expand_end_bindings (getdecls (), kept_level_p (), 0);
1291 else if (building_stmt_tree () && !processing_template_decl
)
1293 tree ss
= build_min_nt (SCOPE_STMT
);
1294 SCOPE_NULLIFIED_P (ss
) = !kept_level_p ();
1295 SCOPE_NULLIFIED_P (TREE_VALUE (current_scope_stmt_stack
))
1296 = SCOPE_NULLIFIED_P (ss
);
1298 current_scope_stmt_stack
= TREE_CHAIN (current_scope_stmt_stack
);
1300 /* When not in function-at-a-time mode, expand_end_bindings
1301 will warn about unused variables. But, in
1302 function-at-a-time mode expand_end_bindings is not passed
1303 the list of variables in the current scope, and therefore
1304 no warning is emitted. So, we explicitly warn here. */
1305 warn_about_unused_variables (getdecls ());
1308 t
= poplevel (kept_level_p (), 1, 0);
1314 /* Finish a parenthesized expression EXPR. */
1317 finish_parenthesized_expr (expr
)
1320 if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (TREE_CODE (expr
))))
1321 /* This inhibits warnings in truthvalue_conversion. */
1322 C_SET_EXP_ORIGINAL_CODE (expr
, ERROR_MARK
);
1327 /* Begin a statement-expression. The value returned must be passed to
1328 finish_stmt_expr. */
1333 /* If we're outside a function, we won't have a statement-tree to
1334 work with. But, if we see a statement-expression we need to
1336 if (!current_function
&& !last_tree
)
1337 begin_stmt_tree (&scope_chain
->x_saved_tree
);
1339 keep_next_level (1);
1340 /* If we're building a statement tree, then the upcoming compound
1341 statement will be chained onto the tree structure, starting at
1342 last_tree. We return last_tree so that we can later unhook the
1343 compound statement. */
1344 return building_stmt_tree () ? last_tree
: expand_start_stmt_expr();
1347 /* Finish a statement-expression. RTL_EXPR should be the value
1348 returned by the previous begin_stmt_expr; EXPR is the
1349 statement-expression. Returns an expression representing the
1350 statement-expression. */
1353 finish_stmt_expr (rtl_expr
)
1358 if (!building_stmt_tree ())
1359 rtl_expr
= expand_end_stmt_expr (rtl_expr
);
1361 if (building_stmt_tree ())
1363 /* If the last thing in the statement-expression was not an
1364 expression-statement, then it has type `void'. */
1365 if (!last_expr_type
)
1366 last_expr_type
= void_type_node
;
1367 result
= build_min (STMT_EXPR
, last_expr_type
, last_tree
);
1368 TREE_SIDE_EFFECTS (result
) = 1;
1370 /* Remove the compound statement from the tree structure; it is
1371 now saved in the STMT_EXPR. */
1372 SET_LAST_STMT (rtl_expr
);
1373 TREE_CHAIN (last_tree
) = NULL_TREE
;
1378 /* If we created a statement-tree for this statement-expression,
1380 if (!current_function
1381 && TREE_CHAIN (scope_chain
->x_saved_tree
) == NULL_TREE
)
1382 finish_stmt_tree (&scope_chain
->x_saved_tree
);
1387 /* Finish a call to FN with ARGS. Returns a representation of the
1391 finish_call_expr (fn
, args
, koenig
)
1400 if (TREE_CODE (fn
) == BIT_NOT_EXPR
)
1401 fn
= build_x_unary_op (BIT_NOT_EXPR
, TREE_OPERAND (fn
, 0));
1402 else if (TREE_CODE (fn
) != TEMPLATE_ID_EXPR
)
1403 fn
= do_identifier (fn
, 2, args
);
1405 result
= build_x_function_call (fn
, args
, current_class_ref
);
1407 if (TREE_CODE (result
) == CALL_EXPR
1408 && (! TREE_TYPE (result
)
1409 || TREE_CODE (TREE_TYPE (result
)) != VOID_TYPE
))
1410 result
= require_complete_type (result
);
1415 /* Finish a call to a postfix increment or decrement or EXPR. (Which
1416 is indicated by CODE, which should be POSTINCREMENT_EXPR or
1417 POSTDECREMENT_EXPR.) */
1420 finish_increment_expr (expr
, code
)
1422 enum tree_code code
;
1424 /* If we get an OFFSET_REF, turn it into what it really means (e.g.,
1425 a COMPONENT_REF). This way if we've got, say, a reference to a
1426 static member that's being operated on, we don't end up trying to
1427 find a member operator for the class it's in. */
1429 if (TREE_CODE (expr
) == OFFSET_REF
)
1430 expr
= resolve_offset_ref (expr
);
1431 return build_x_unary_op (code
, expr
);
1434 /* Finish a use of `this'. Returns an expression for `this'. */
1441 if (current_class_ptr
)
1443 #ifdef WARNING_ABOUT_CCD
1444 TREE_USED (current_class_ptr
) = 1;
1446 result
= current_class_ptr
;
1448 else if (current_function_decl
1449 && DECL_STATIC_FUNCTION_P (current_function_decl
))
1451 error ("`this' is unavailable for static member functions");
1452 result
= error_mark_node
;
1456 if (current_function_decl
)
1457 error ("invalid use of `this' in non-member function");
1459 error ("invalid use of `this' at top level");
1460 result
= error_mark_node
;
1466 /* Finish a member function call using OBJECT and ARGS as arguments to
1467 FN. Returns an expression for the call. */
1470 finish_object_call_expr (fn
, object
, args
)
1476 /* This is a future direction of this code, but because
1477 build_x_function_call cannot always undo what is done in
1478 build_component_ref entirely yet, we cannot do this. */
1480 tree real_fn
= build_component_ref (object
, fn
, NULL_TREE
, 1);
1481 return finish_call_expr (real_fn
, args
);
1483 if (DECL_DECLARES_TYPE_P (fn
))
1485 if (processing_template_decl
)
1486 /* This can happen on code like:
1489 template <class T> void f(T t) {
1493 We just grab the underlying IDENTIFIER. */
1494 fn
= DECL_NAME (fn
);
1497 cp_error ("calling type `%T' like a method", fn
);
1498 return error_mark_node
;
1502 return build_method_call (object
, fn
, args
, NULL_TREE
, LOOKUP_NORMAL
);
1506 /* Finish a qualified member function call using OBJECT and ARGS as
1507 arguments to FN. Returns an expressino for the call. */
1510 finish_qualified_object_call_expr (fn
, object
, args
)
1515 return build_scoped_method_call (object
, TREE_OPERAND (fn
, 0),
1516 TREE_OPERAND (fn
, 1), args
);
1519 /* Finish a pseudo-destructor call expression of OBJECT, with SCOPE
1520 being the scope, if any, of DESTRUCTOR. Returns an expression for
1524 finish_pseudo_destructor_call_expr (object
, scope
, destructor
)
1529 if (processing_template_decl
)
1530 return build_min_nt (PSEUDO_DTOR_EXPR
, object
, scope
, destructor
);
1532 if (scope
&& scope
!= destructor
)
1533 cp_error ("destructor specifier `%T::~%T()' must have matching names",
1536 if ((scope
== NULL_TREE
|| IDENTIFIER_GLOBAL_VALUE (destructor
))
1537 && (TREE_CODE (TREE_TYPE (object
)) !=
1538 TREE_CODE (TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (destructor
)))))
1539 cp_error ("`%E' is not of type `%T'", object
, destructor
);
1541 return cp_convert (void_type_node
, object
);
1544 /* Finish a call to a globally qualified member function FN using
1545 ARGS. Returns an expression for the call. */
1548 finish_qualified_call_expr (fn
, args
)
1552 if (processing_template_decl
)
1553 return build_min_nt (CALL_EXPR
, fn
, args
, NULL_TREE
);
1555 return build_member_call (TREE_OPERAND (fn
, 0),
1556 TREE_OPERAND (fn
, 1),
1560 /* Finish an expression taking the address of LABEL. Returns an
1561 expression for the address. */
1564 finish_label_address_expr (label
)
1569 label
= lookup_label (label
);
1570 if (label
== NULL_TREE
)
1571 result
= null_pointer_node
;
1574 TREE_USED (label
) = 1;
1575 result
= build1 (ADDR_EXPR
, ptr_type_node
, label
);
1576 TREE_CONSTANT (result
) = 1;
1582 /* Finish an expression of the form CODE EXPR. */
1585 finish_unary_op_expr (code
, expr
)
1586 enum tree_code code
;
1589 tree result
= build_x_unary_op (code
, expr
);
1590 if (code
== NEGATE_EXPR
&& TREE_CODE (expr
) == INTEGER_CST
)
1591 TREE_NEGATED_INT (result
) = 1;
1592 overflow_warning (result
);
1596 /* Finish an id-expression. */
1599 finish_id_expr (expr
)
1602 if (TREE_CODE (expr
) == IDENTIFIER_NODE
)
1603 expr
= do_identifier (expr
, 1, NULL_TREE
);
1608 /* Begin a new-placement. */
1611 begin_new_placement ()
1613 /* The arguments to a placement new might be passed to a
1614 deallocation function, in the event that the allocation throws an
1615 exception. Since we don't expand exception handlers until the
1616 end of a function, we must make sure the arguments stay around
1618 return suspend_momentary ();
1621 /* Finish a new-placement. The ARGS are the placement arguments. The
1622 COOKIE is the value returned by the previous call to
1623 begin_new_placement. */
1626 finish_new_placement (args
, cookie
)
1630 resume_momentary (cookie
);
1634 /* Begin a function defniition declared with DECL_SPECS and
1635 DECLARATOR. Returns non-zero if the function-declaration is
1639 begin_function_definition (decl_specs
, declarator
)
1645 split_specs_attrs (decl_specs
, &specs
, &attrs
);
1646 if (!start_function (specs
, declarator
, attrs
, SF_DEFAULT
))
1649 reinit_parse_for_function ();
1650 /* The things we're about to see are not directly qualified by any
1651 template headers we've seen thus far. */
1652 reset_specialization ();
1657 /* Begin a constructor declarator of the form `SCOPE::NAME'. Returns
1661 begin_constructor_declarator (scope
, name
)
1665 tree result
= build_parse_node (SCOPE_REF
, scope
, name
);
1666 enter_scope_of (result
);
1670 /* Finish an init-declarator. Returns a DECL. */
1673 finish_declarator (declarator
, declspecs
, attributes
,
1674 prefix_attributes
, initialized
)
1678 tree prefix_attributes
;
1681 return start_decl (declarator
, declspecs
, initialized
, attributes
,
1685 /* Finish a translation unit. */
1688 finish_translation_unit ()
1690 /* In case there were missing closebraces,
1691 get us back to the global binding level. */
1693 while (current_namespace
!= global_namespace
)
1698 /* Finish a template type parameter, specified as AGGR IDENTIFIER.
1699 Returns the parameter. */
1702 finish_template_type_parm (aggr
, identifier
)
1706 if (aggr
!= class_type_node
)
1708 pedwarn ("template type parameters must use the keyword `class' or `typename'");
1709 aggr
= class_type_node
;
1712 return build_tree_list (aggr
, identifier
);
1715 /* Finish a template template parameter, specified as AGGR IDENTIFIER.
1716 Returns the parameter. */
1719 finish_template_template_parm (aggr
, identifier
)
1723 tree decl
= build_decl (TYPE_DECL
, identifier
, NULL_TREE
);
1724 tree tmpl
= build_lang_decl (TEMPLATE_DECL
, identifier
, NULL_TREE
);
1725 DECL_TEMPLATE_PARMS (tmpl
) = current_template_parms
;
1726 DECL_TEMPLATE_RESULT (tmpl
) = decl
;
1727 SET_DECL_ARTIFICIAL (decl
);
1728 end_template_decl ();
1730 return finish_template_type_parm (aggr
, tmpl
);
1733 /* Finish a parameter list, indicated by PARMS. If ELLIPSIS is
1734 non-zero, the parameter list was terminated by a `...'. */
1737 finish_parmlist (parms
, ellipsis
)
1742 chainon (parms
, void_list_node
);
1743 /* We mark the PARMS as a parmlist so that declarator processing can
1744 disambiguate certain constructs. */
1745 if (parms
!= NULL_TREE
)
1746 TREE_PARMLIST (parms
) = 1;
1751 /* Begin a class definition, as indicated by T. */
1754 begin_class_definition (t
)
1757 push_permanent_obstack ();
1759 if (t
== error_mark_node
1760 || ! IS_AGGR_TYPE (t
))
1762 t
= make_lang_type (RECORD_TYPE
);
1763 pushtag (make_anon_name (), t
, 0);
1766 /* In a definition of a member class template, we will get here with an
1767 implicit typename, a TYPENAME_TYPE with a type. */
1768 if (TREE_CODE (t
) == TYPENAME_TYPE
)
1771 /* If we generated a partial instantiation of this type, but now
1772 we're seeing a real definition, we're actually looking at a
1773 partial specialization. Consider:
1775 template <class T, class U>
1781 template <class T, class U>
1784 typename X<Y<T, U> >::A a;
1787 template <class T, class U>
1792 We have to undo the effects of the previous partial
1794 if (PARTIAL_INSTANTIATION_P (t
))
1798 /* Unfortunately, when we're not in pedantic mode, we
1799 attempt to actually fill in some of the fields of the
1800 partial instantiation, in order to support the implicit
1801 typename extension. Clear those fields now, in
1802 preparation for the definition here. The fields cleared
1803 here must match those set in instantiate_class_template.
1804 Look for a comment mentioning begin_class_definition
1806 TYPE_BINFO_BASETYPES (t
) = NULL_TREE
;
1807 TYPE_FIELDS (t
) = NULL_TREE
;
1808 TYPE_METHODS (t
) = NULL_TREE
;
1809 CLASSTYPE_TAGS (t
) = NULL_TREE
;
1810 TYPE_SIZE (t
) = NULL_TREE
;
1813 /* This isn't a partial instantiation any more. */
1814 PARTIAL_INSTANTIATION_P (t
) = 0;
1816 /* If this type was already complete, and we see another definition,
1818 else if (TYPE_SIZE (t
))
1819 duplicate_tag_error (t
);
1821 /* Update the location of the decl. */
1822 DECL_SOURCE_FILE (TYPE_NAME (t
)) = input_filename
;
1823 DECL_SOURCE_LINE (TYPE_NAME (t
)) = lineno
;
1825 if (TYPE_BEING_DEFINED (t
))
1827 t
= make_lang_type (TREE_CODE (t
));
1828 pushtag (TYPE_IDENTIFIER (t
), t
, 0);
1830 maybe_process_partial_specialization (t
);
1832 TYPE_BEING_DEFINED (t
) = 1;
1833 /* Reset the interface data, at the earliest possible
1834 moment, as it might have been set via a class foo;
1837 tree name
= TYPE_IDENTIFIER (t
);
1839 if (! ANON_AGGRNAME_P (name
))
1841 CLASSTYPE_INTERFACE_ONLY (t
) = interface_only
;
1842 SET_CLASSTYPE_INTERFACE_UNKNOWN_X
1843 (t
, interface_unknown
);
1846 /* Only leave this bit clear if we know this
1847 class is part of an interface-only specification. */
1848 if (! CLASSTYPE_INTERFACE_KNOWN (t
)
1849 || ! CLASSTYPE_INTERFACE_ONLY (t
))
1850 CLASSTYPE_VTABLE_NEEDS_WRITING (t
) = 1;
1853 tmp
= TYPE_IDENTIFIER ($
<ttype
>0);
1854 if (tmp
&& IDENTIFIER_TEMPLATE (tmp
))
1855 overload_template_name (tmp
, 1);
1857 reset_specialization();
1859 /* Make a declaration for this class in its own scope. */
1860 build_self_reference ();
1865 /* Finish the member declaration given by DECL. */
1868 finish_member_declaration (decl
)
1871 if (decl
== error_mark_node
|| decl
== NULL_TREE
)
1874 if (decl
== void_type_node
)
1875 /* The COMPONENT was a friend, not a member, and so there's
1876 nothing for us to do. */
1879 /* We should see only one DECL at a time. */
1880 my_friendly_assert (TREE_CHAIN (decl
) == NULL_TREE
, 0);
1882 /* Set up access control for DECL. */
1884 = (current_access_specifier
== access_private_node
);
1885 TREE_PROTECTED (decl
)
1886 = (current_access_specifier
== access_protected_node
);
1887 if (TREE_CODE (decl
) == TEMPLATE_DECL
)
1889 TREE_PRIVATE (DECL_RESULT (decl
)) = TREE_PRIVATE (decl
);
1890 TREE_PROTECTED (DECL_RESULT (decl
)) = TREE_PROTECTED (decl
);
1893 /* Mark the DECL as a member of the current class. */
1894 if (TREE_CODE (decl
) == FUNCTION_DECL
1895 || DECL_FUNCTION_TEMPLATE_P (decl
))
1896 /* Historically, DECL_CONTEXT was not set for a FUNCTION_DECL in
1897 finish_struct. Presumably it is already set as the function is
1898 parsed. Perhaps DECL_CLASS_CONTEXT is already set, too? */
1899 DECL_CLASS_CONTEXT (decl
) = current_class_type
;
1901 DECL_CONTEXT (decl
) = current_class_type
;
1903 /* Put functions on the TYPE_METHODS list and everything else on the
1904 TYPE_FIELDS list. Note that these are built up in reverse order.
1905 We reverse them (to obtain declaration order) in finish_struct. */
1906 if (TREE_CODE (decl
) == FUNCTION_DECL
1907 || DECL_FUNCTION_TEMPLATE_P (decl
))
1909 /* We also need to add this function to the
1910 CLASSTYPE_METHOD_VEC. */
1911 add_method (current_class_type
, 0, decl
);
1913 TREE_CHAIN (decl
) = TYPE_METHODS (current_class_type
);
1914 TYPE_METHODS (current_class_type
) = decl
;
1918 /* All TYPE_DECLs go at the end of TYPE_FIELDS. Ordinary fields
1919 go at the beginning. The reason is that lookup_field_1
1920 searches the list in order, and we want a field name to
1921 override a type name so that the "struct stat hack" will
1922 work. In particular:
1924 struct S { enum E { }; int E } s;
1927 is legal. In addition, the FIELD_DECLs must be maintained in
1928 declaration order so that class layout works as expected.
1929 However, we don't need that order until class layout, so we
1930 save a little time by putting FIELD_DECLs on in reverse order
1931 here, and then reversing them in finish_struct_1. (We could
1932 also keep a pointer to the correct insertion points in the
1935 if (TREE_CODE (decl
) == TYPE_DECL
)
1936 TYPE_FIELDS (current_class_type
)
1937 = chainon (TYPE_FIELDS (current_class_type
), decl
);
1940 TREE_CHAIN (decl
) = TYPE_FIELDS (current_class_type
);
1941 TYPE_FIELDS (current_class_type
) = decl
;
1944 /* Enter the DECL into the scope of the class. */
1945 if (TREE_CODE (decl
) != USING_DECL
)
1946 pushdecl_class_level (decl
);
1950 /* Finish a class definition T with the indicate ATTRIBUTES. If SEMI,
1951 the definition is immediately followed by a semicolon. Returns the
1955 finish_class_definition (t
, attributes
, semi
, pop_scope_p
)
1961 /* finish_struct nukes this anyway; if finish_exception does too,
1964 note_got_semicolon (t
);
1966 /* If we got any attributes in class_head, xref_tag will stick them in
1967 TREE_TYPE of the type. Grab them now. */
1968 attributes
= chainon (TREE_TYPE (t
), attributes
);
1969 TREE_TYPE (t
) = NULL_TREE
;
1971 if (TREE_CODE (t
) == ENUMERAL_TYPE
)
1975 t
= finish_struct (t
, attributes
);
1977 note_got_semicolon (t
);
1983 check_for_missing_semicolon (t
);
1985 pop_scope (CP_DECL_CONTEXT (TYPE_MAIN_DECL (t
)));
1986 if (current_scope () == current_function_decl
)
1987 do_pending_defargs ();
1992 /* Finish processing the default argument expressions cached during
1993 the processing of a class definition. */
1996 begin_inline_definitions ()
1999 && current_scope () == current_function_decl
)
2000 do_pending_inlines ();
2003 /* Finish processing the inline function definitions cached during the
2004 processing of a class definition. */
2007 finish_inline_definitions ()
2009 if (current_class_type
== NULL_TREE
)
2010 clear_inline_text_obstack ();
2013 /* Finish processing the declaration of a member class template
2014 TYPES whose template parameters are given by PARMS. */
2017 finish_member_class_template (types
)
2022 /* If there are declared, but undefined, partial specializations
2023 mixed in with the typespecs they will not yet have passed through
2024 maybe_process_partial_specialization, so we do that here. */
2025 for (t
= types
; t
!= NULL_TREE
; t
= TREE_CHAIN (t
))
2026 if (IS_AGGR_TYPE_CODE (TREE_CODE (TREE_VALUE (t
))))
2027 maybe_process_partial_specialization (TREE_VALUE (t
));
2029 note_list_got_semicolon (types
);
2030 grok_x_components (types
);
2031 if (TYPE_CONTEXT (TREE_VALUE (types
)) != current_class_type
)
2032 /* The component was in fact a friend declaration. We avoid
2033 finish_member_template_decl performing certain checks by
2037 finish_member_template_decl (types
);
2039 /* As with other component type declarations, we do
2040 not store the new DECL on the list of
2045 /* Finish processsing a complete template declaration. The PARMS are
2046 the template parameters. */
2049 finish_template_decl (parms
)
2053 end_template_decl ();
2055 end_specialization ();
2058 /* Finish processing a a template-id (which names a type) of the form
2059 NAME < ARGS >. Return the TYPE_DECL for the type named by the
2060 template-id. If ENTERING_SCOPE is non-zero we are about to enter
2061 the scope of template-id indicated. */
2064 finish_template_type (name
, args
, entering_scope
)
2071 decl
= lookup_template_class (name
, args
,
2072 NULL_TREE
, NULL_TREE
, entering_scope
);
2073 if (decl
!= error_mark_node
)
2074 decl
= TYPE_STUB_DECL (decl
);
2079 /* SR is a SCOPE_REF node. Enter the scope of SR, whether it is a
2080 namespace scope or a class scope. */
2086 tree scope
= TREE_OPERAND (sr
, 0);
2088 if (TREE_CODE (scope
) == NAMESPACE_DECL
)
2090 push_decl_namespace (scope
);
2091 TREE_COMPLEXITY (sr
) = -1;
2093 else if (scope
!= current_class_type
)
2095 if (TREE_CODE (scope
) == TYPENAME_TYPE
)
2097 /* In a declarator for a template class member, the scope will
2098 get here as an implicit typename, a TYPENAME_TYPE with a type. */
2099 scope
= TREE_TYPE (scope
);
2100 TREE_OPERAND (sr
, 0) = scope
;
2102 push_nested_class (scope
, 3);
2103 TREE_COMPLEXITY (sr
) = current_class_depth
;
2107 /* Finish processing a BASE_CLASS with the indicated ACCESS_SPECIFIER.
2108 Return a TREE_LIST containing the ACCESS_SPECIFIER and the
2109 BASE_CLASS, or NULL_TREE if an error occurred. The
2110 ACCESSS_SPECIFIER is one of
2111 access_{default,public,protected_private}[_virtual]_node.*/
2114 finish_base_specifier (access_specifier
, base_class
)
2115 tree access_specifier
;
2121 if (base_class
== NULL_TREE
)
2123 error ("invalid base class");
2124 type
= error_mark_node
;
2127 type
= TREE_TYPE (base_class
);
2129 if (! is_aggr_type (type
, 1))
2132 result
= build_tree_list (access_specifier
, type
);
2137 /* Called when multiple declarators are processed. If that is not
2138 premitted in this context, an error is issued. */
2141 check_multiple_declarators ()
2145 In a template-declaration, explicit specialization, or explicit
2146 instantiation the init-declarator-list in the declaration shall
2147 contain at most one declarator.
2149 We don't just use PROCESSING_TEMPLATE_DECL for the first
2150 condition since that would disallow the perfectly legal code,
2151 like `template <class T> struct S { int i, j; };'. */
2152 tree scope
= current_scope ();
2154 if (scope
&& TREE_CODE (scope
) == FUNCTION_DECL
)
2155 /* It's OK to write `template <class T> void f() { int i, j;}'. */
2158 if (PROCESSING_REAL_TEMPLATE_DECL_P ()
2159 || processing_explicit_instantiation
2160 || processing_specialization
)
2161 cp_error ("multiple declarators in template declaration");
2165 finish_typeof (expr
)
2168 if (processing_template_decl
)
2172 push_permanent_obstack ();
2173 t
= make_lang_type (TYPEOF_TYPE
);
2174 TYPE_FIELDS (t
) = expr
;
2180 return TREE_TYPE (expr
);
2183 /* Create an empty statement tree rooted at T. */
2189 /* We create a trivial EXPR_STMT so that last_tree is never NULL in
2190 what follows. We remove the extraneous statement in
2191 finish_stmt_tree. */
2192 *t
= build_nt (EXPR_STMT
, void_zero_node
);
2194 last_expr_type
= NULL_TREE
;
2197 /* Finish the statement tree rooted at T. */
2200 finish_stmt_tree (t
)
2205 /* Remove the fake extra statement added in begin_stmt_tree. */
2206 stmt
= TREE_CHAIN (*t
);
2208 SET_LAST_STMT (NULL_TREE
);
2210 if (current_function
)
2212 /* The line-number recorded in the outermost statement in a function
2213 is the line number of the end of the function. */
2214 STMT_LINENO (stmt
) = lineno
;
2215 STMT_LINENO_FOR_FN_P (stmt
) = 1;
2219 /* We're about to expand T, a statement. Set up appropriate context
2220 for the substitution. */
2226 if (!STMT_LINENO_FOR_FN_P (t
))
2227 lineno
= STMT_LINENO (t
);
2228 stmts_are_full_exprs_p
= STMT_IS_FULL_EXPR_P (t
);
2231 /* Some statements, like for-statements or if-statements, require a
2232 condition. This condition can be a declaration. If T is such a
2233 declaration it is processed, and an expression appropriate to use
2234 as the condition is returned. Otherwise, T itself is returned. */
2240 if (t
&& TREE_CODE (t
) == TREE_LIST
)
2242 expand_stmt (TREE_PURPOSE (t
));
2243 return TREE_VALUE (t
);
2249 /* Generate RTL for the statement T, and its substatements, and any
2250 other statements at its nesting level. */
2256 tree rval
= NULL_TREE
;
2258 while (t
&& t
!= error_mark_node
)
2260 int saved_stmts_are_full_exprs_p
;
2262 /* Assume we'll have nothing to return. */
2265 /* Set up context appropriately for handling this statement. */
2266 saved_stmts_are_full_exprs_p
= stmts_are_full_exprs_p
;
2269 switch (TREE_CODE (t
))
2272 finish_return_stmt (RETURN_EXPR (t
));
2276 finish_expr_stmt (EXPR_STMT_EXPR (t
));
2282 int i
= suspend_momentary ();
2284 emit_line_note (input_filename
, lineno
);
2285 decl
= DECL_STMT_DECL (t
);
2286 /* If this is a declaration for an automatic local
2287 variable, initialize it. Note that we might also see a
2288 declaration for a namespace-scope object (declared with
2289 `extern'). We don't have to handle the initialization
2290 of those objects here; they can only be declarations,
2291 rather than definitions. */
2292 if (TREE_CODE (decl
) == VAR_DECL
2293 && !TREE_STATIC (decl
)
2294 && !DECL_EXTERNAL (decl
))
2296 /* Let the back-end know about this variable. */
2297 if (!ANON_AGGR_TYPE_P (TREE_TYPE (decl
)))
2298 emit_local_var (decl
);
2300 expand_anon_union_decl (decl
, NULL_TREE
,
2301 DECL_ANON_UNION_ELEMS (decl
));
2303 else if (TREE_CODE (decl
) == VAR_DECL
&& TREE_STATIC (decl
))
2304 rest_of_decl_compilation
2305 (decl
, IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)),
2306 /*top_level=*/0, /*at_end=*/0);
2308 resume_momentary (i
);
2313 finish_decl_cleanup (CLEANUP_DECL (t
), CLEANUP_EXPR (t
));
2316 case START_CATCH_STMT
:
2317 begin_catch_block (TREE_TYPE (t
));
2325 expand_stmt (FOR_INIT_STMT (t
));
2326 finish_for_init_stmt (NULL_TREE
);
2327 finish_for_cond (expand_cond (FOR_COND (t
)), NULL_TREE
);
2329 finish_for_expr (tmp
, NULL_TREE
);
2330 expand_stmt (FOR_BODY (t
));
2331 finish_for_stmt (tmp
, NULL_TREE
);
2337 begin_while_stmt ();
2338 finish_while_stmt_cond (expand_cond (WHILE_COND (t
)), NULL_TREE
);
2339 expand_stmt (WHILE_BODY (t
));
2340 finish_while_stmt (NULL_TREE
);
2347 expand_stmt (DO_BODY (t
));
2348 finish_do_body (NULL_TREE
);
2349 finish_do_stmt (DO_COND (t
), NULL_TREE
);
2355 finish_if_stmt_cond (expand_cond (IF_COND (t
)), NULL_TREE
);
2356 if (THEN_CLAUSE (t
))
2358 expand_stmt (THEN_CLAUSE (t
));
2359 finish_then_clause (NULL_TREE
);
2361 if (ELSE_CLAUSE (t
))
2363 begin_else_clause ();
2364 expand_stmt (ELSE_CLAUSE (t
));
2365 finish_else_clause (NULL_TREE
);
2371 begin_compound_stmt (COMPOUND_STMT_NO_SCOPE (t
));
2372 expand_stmt (COMPOUND_BODY (t
));
2373 rval
= finish_compound_stmt (COMPOUND_STMT_NO_SCOPE (t
),
2378 finish_break_stmt ();
2382 finish_continue_stmt ();
2389 begin_switch_stmt ();
2390 cond
= expand_cond (SWITCH_COND (t
));
2391 finish_switch_cond (cond
, NULL_TREE
);
2392 expand_stmt (SWITCH_BODY (t
));
2393 finish_switch_stmt (cond
, NULL_TREE
);
2398 finish_case_label (CASE_LOW (t
), CASE_HIGH (t
));
2402 expand_label (LABEL_STMT_LABEL (t
));
2406 finish_goto_stmt (GOTO_DESTINATION (t
));
2410 finish_asm_stmt (ASM_CV_QUAL (t
), ASM_STRING (t
), ASM_OUTPUTS
2411 (t
), ASM_INPUTS (t
), ASM_CLOBBERS (t
));
2417 expand_eh_region_start ();
2418 expand_stmt (TRY_STMTS (t
));
2419 finish_cleanup_try_block (NULL_TREE
);
2420 finish_cleanup (TRY_HANDLERS (t
), NULL_TREE
);
2424 if (FN_TRY_BLOCK_P (t
))
2425 begin_function_try_block ();
2429 expand_stmt (TRY_STMTS (t
));
2431 if (FN_TRY_BLOCK_P (t
))
2433 finish_function_try_block (NULL_TREE
);
2434 expand_stmt (TRY_HANDLERS (t
));
2435 finish_function_handler_sequence (NULL_TREE
);
2439 finish_try_block (NULL_TREE
);
2440 expand_stmt (TRY_HANDLERS (t
));
2441 finish_handler_sequence (NULL_TREE
);
2448 expand_stmt (HANDLER_BODY (t
));
2449 finish_handler (NULL_TREE
, NULL_TREE
);
2453 finish_subobject (SUBOBJECT_CLEANUP (t
));
2457 if (SCOPE_BEGIN_P (t
))
2458 expand_start_bindings (2 * SCOPE_NULLIFIED_P (t
));
2459 else if (SCOPE_END_P (t
))
2460 expand_end_bindings (NULL_TREE
, !SCOPE_NULLIFIED_P (t
), 0);
2464 /* Clear this out so that finish_named_return_value can set it
2466 DECL_NAME (DECL_RESULT (current_function_decl
)) = NULL_TREE
;
2467 finish_named_return_value (TREE_OPERAND (t
, 0),
2468 TREE_OPERAND (t
, 1));
2472 my_friendly_abort (19990810);
2476 /* Restore saved state. */
2477 stmts_are_full_exprs_p
= saved_stmts_are_full_exprs_p
;
2479 /* Go on to the next statement in this scope. */
2486 /* Generate RTL for FN. */
2493 char *saved_input_filename
;
2495 /* When the parser calls us after finishing the body of a template
2496 function, we don't really want to expand the body. When we're
2497 processing an in-class definition of an inline function,
2498 PROCESSING_TEMPLATE_DECL will no longer be set here, so we have
2499 to look at the function itself. */
2500 if (processing_template_decl
2501 || (DECL_LANG_SPECIFIC (fn
)
2502 && DECL_TEMPLATE_INFO (fn
)
2503 && uses_template_parms (DECL_TI_ARGS (fn
))))
2506 /* There's no reason to do any of the work here if we're only doing
2507 semantic analysis; this code just generates RTL. */
2508 if (flag_syntax_only
)
2511 /* Save the current file name and line number. When we expand the
2512 body of the function, we'll set LINENO and INPUT_FILENAME so that
2513 error-mesages come out in the right places. */
2514 saved_lineno
= lineno
;
2515 saved_input_filename
= input_filename
;
2516 lineno
= DECL_SOURCE_LINE (fn
);
2517 input_filename
= DECL_SOURCE_FILE (fn
);
2519 start_function (NULL_TREE
, fn
, NULL_TREE
, SF_PRE_PARSED
| SF_EXPAND
);
2520 store_parm_decls ();
2522 /* We don't need to redeclare __FUNCTION__, __PRETTY_FUNCTION__, or
2523 any of the other magic variables we set up when starting a
2525 current_function_name_declared
= 1;
2527 /* Expand the body. */
2528 expand_stmt (DECL_SAVED_TREE (fn
));
2530 /* Statements should always be full-expressions at the outermost set
2531 of curly braces for a function. */
2532 my_friendly_assert (stmts_are_full_exprs_p
, 19990831);
2534 /* The outermost statement for a function contains the line number
2535 recorded when we finished processing the function. */
2536 lineno
= STMT_LINENO (DECL_SAVED_TREE (fn
));
2538 /* Generate code for the function. */
2539 finish_function (lineno
, 0);
2541 /* And restore the current source position. */
2542 lineno
= saved_lineno
;
2543 input_filename
= saved_input_filename
;