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
35 /* There routines provide a modular interface to perform many parsing
36 operations. They may therefore be used during actual parsing, or
37 during template instantiation, which may be regarded as a
38 degenerate form of parsing. Since the current g++ parser is
39 lacking in several respects, and will be reimplemented, we are
40 attempting to move most code that is not directly related to
41 parsing into this file; that will make implementing the new parser
42 much easier since it will be able to make use of these routines. */
44 static void finish_expr_stmt_real
PROTO((tree
, int));
45 static tree expand_cond
PROTO((tree
));
46 static tree maybe_convert_cond
PROTO((tree
));
48 /* When parsing a template, LAST_TREE contains the last statement
49 parsed. These are chained together through the TREE_CHAIN field,
50 but often need to be re-organized since the parse is performed
51 bottom-up. This macro makes LAST_TREE the indicated SUBSTMT of
54 #define RECHAIN_STMTS(stmt, substmt) \
56 substmt = TREE_CHAIN (stmt); \
57 TREE_CHAIN (stmt) = NULL_TREE; \
61 /* Finish processing the COND, the SUBSTMT condition for STMT. */
63 #define FINISH_COND(cond, stmt, substmt) \
65 if (last_tree != stmt) \
67 RECHAIN_STMTS (stmt, substmt); \
68 if (!processing_template_decl) \
70 cond = build_tree_list (substmt, cond); \
78 /* T is a statement. Add it to the statement-tree. */
84 /* Add T to the statement-tree. */
85 last_tree
= TREE_CHAIN (last_tree
) = t
;
87 /* When we expand a statement-tree, we must know whether or not the
88 statements are full-expresions. We record that fact here. */
89 if (building_stmt_tree ())
90 STMT_IS_FULL_EXPR_P (last_tree
) = stmts_are_full_exprs_p
;
93 /* COND is the condition-expression for an if, while, etc.,
94 statement. Convert it to a boolean value, if appropriate. */
97 maybe_convert_cond (cond
)
100 /* Empty conditions remain empty. */
104 /* Wait until we instantiate templates before doing conversion. */
105 if (processing_template_decl
)
108 /* Do the conversion. */
109 cond
= convert_from_reference (cond
);
110 return condition_conversion (cond
);
113 /* Finish an expression-statement, whose EXPRESSION is as indicated.
114 If ASSIGNED_THIS is non-zero, then this statement just assigned to
115 the `this' pointer. */
118 finish_expr_stmt_real (expr
, assigned_this
)
122 if (expr
!= NULL_TREE
)
124 if (building_stmt_tree ())
125 add_tree (build_min_nt (EXPR_STMT
, expr
));
128 emit_line_note (input_filename
, lineno
);
129 /* Do default conversion if safe and possibly important,
130 in case within ({...}). */
131 if (!stmts_are_full_exprs_p
&&
132 ((TREE_CODE (TREE_TYPE (expr
)) == ARRAY_TYPE
134 || TREE_CODE (TREE_TYPE (expr
)) == FUNCTION_TYPE
))
135 expr
= default_conversion (expr
);
137 if (stmts_are_full_exprs_p
)
138 expand_start_target_temps ();
140 cplus_expand_expr_stmt (expr
);
142 if (stmts_are_full_exprs_p
)
144 expand_end_target_temps ();
150 /* If this statement assigned to the `this' pointer, record that
151 fact for finish_stmt. */
153 current_function_just_assigned_this
= 1;
157 /* This was an expression-statement, so we save the type of the
159 last_expr_type
= expr
? TREE_TYPE (expr
) : NULL_TREE
;
162 /* Like finish_expr_stmt_real, but ASSIGNS_THIS is always zero. */
165 finish_expr_stmt (expr
)
168 finish_expr_stmt_real (expr
, /*assigns_this=*/0);
171 /* Begin an if-statement. Returns a newly created IF_STMT if
179 if (building_stmt_tree ())
181 r
= build_min_nt (IF_STMT
, NULL_TREE
, NULL_TREE
, NULL_TREE
);
192 /* Process the COND of an if-statement, which may be given by
196 finish_if_stmt_cond (cond
, if_stmt
)
200 cond
= maybe_convert_cond (cond
);
202 if (building_stmt_tree ())
203 FINISH_COND (cond
, if_stmt
, IF_COND (if_stmt
));
206 emit_line_note (input_filename
, lineno
);
207 expand_start_cond (cond
, 0);
211 /* Finish the then-clause of an if-statement, which may be given by
215 finish_then_clause (if_stmt
)
218 if (building_stmt_tree ())
220 RECHAIN_STMTS (if_stmt
, THEN_CLAUSE (if_stmt
));
228 /* Begin the else-clause of an if-statement. */
233 if (!building_stmt_tree ())
234 expand_start_else ();
237 /* Finish the else-clause of an if-statement, which may be given by
241 finish_else_clause (if_stmt
)
244 if (building_stmt_tree ())
245 RECHAIN_STMTS (if_stmt
, ELSE_CLAUSE (if_stmt
));
248 /* Finsh an if-statement. */
253 if (!building_stmt_tree ())
260 /* Begin a while-statement. Returns a newly created WHILE_STMT if
268 if (building_stmt_tree ())
270 r
= build_min_nt (WHILE_STMT
, NULL_TREE
, NULL_TREE
);
276 emit_line_note (input_filename
, lineno
);
277 expand_start_loop (1);
286 /* Process the COND of an if-statement, which may be given by
290 finish_while_stmt_cond (cond
, while_stmt
)
294 cond
= maybe_convert_cond (cond
);
296 if (building_stmt_tree ())
297 FINISH_COND (cond
, while_stmt
, WHILE_COND (while_stmt
));
300 emit_line_note (input_filename
, lineno
);
301 expand_exit_loop_if_false (0, cond
);
304 /* If COND wasn't a declaration, clear out the
305 block we made for it and start a new one here so the
306 optimization in expand_end_loop will work. */
307 if (getdecls () == NULL_TREE
)
314 /* Finish a while-statement, which may be given by WHILE_STMT. */
317 finish_while_stmt (while_stmt
)
322 if (building_stmt_tree ())
323 RECHAIN_STMTS (while_stmt
, WHILE_BODY (while_stmt
));
329 /* Begin a do-statement. Returns a newly created DO_STMT if
335 if (building_stmt_tree ())
337 tree r
= build_min_nt (DO_STMT
, NULL_TREE
, NULL_TREE
);
344 emit_line_note (input_filename
, lineno
);
345 expand_start_loop_continue_elsewhere (1);
350 /* Finish the body of a do-statement, which may be given by DO_STMT. */
353 finish_do_body (do_stmt
)
356 if (building_stmt_tree ())
357 RECHAIN_STMTS (do_stmt
, DO_BODY (do_stmt
));
359 expand_loop_continue_here ();
362 /* Finish a do-statement, which may be given by DO_STMT, and whose
363 COND is as indicated. */
366 finish_do_stmt (cond
, do_stmt
)
370 cond
= maybe_convert_cond (cond
);
372 if (building_stmt_tree ())
373 DO_COND (do_stmt
) = cond
;
376 emit_line_note (input_filename
, lineno
);
377 expand_exit_loop_if_false (0, cond
);
385 /* Finish a return-statement. The EXPRESSION returned, if any, is as
389 finish_return_stmt (expr
)
392 if (building_stmt_tree ())
393 add_tree (build_min_nt (RETURN_STMT
, expr
));
396 emit_line_note (input_filename
, lineno
);
397 c_expand_return (expr
);
403 /* Begin a for-statement. Returns a new FOR_STMT if appropriate. */
410 if (building_stmt_tree ())
412 r
= build_min_nt (FOR_STMT
, NULL_TREE
, NULL_TREE
,
413 NULL_TREE
, NULL_TREE
);
419 if (flag_new_for_scope
> 0)
422 note_level_for_for ();
428 /* Finish the for-init-statement of a for-statement, which may be
429 given by FOR_STMT. */
432 finish_for_init_stmt (for_stmt
)
435 if (building_stmt_tree ())
437 if (last_tree
!= for_stmt
)
438 RECHAIN_STMTS (for_stmt
, FOR_INIT_STMT (for_stmt
));
443 emit_line_note (input_filename
, lineno
);
444 expand_start_loop_continue_elsewhere (1);
450 /* Finish the COND of a for-statement, which may be given by
454 finish_for_cond (cond
, for_stmt
)
458 cond
= maybe_convert_cond (cond
);
460 if (building_stmt_tree ())
461 FINISH_COND (cond
, for_stmt
, FOR_COND (for_stmt
));
464 emit_line_note (input_filename
, lineno
);
466 expand_exit_loop_if_false (0, cond
);
469 /* If the cond wasn't a declaration, clear out the
470 block we made for it and start a new one here so the
471 optimization in expand_end_loop will work. */
472 if (getdecls () == NULL_TREE
)
479 /* Finish the increment-EXPRESSION in a for-statement, which may be
480 given by FOR_STMT. */
483 finish_for_expr (expr
, for_stmt
)
487 if (building_stmt_tree ())
488 FOR_EXPR (for_stmt
) = expr
;
490 /* Don't let the tree nodes for EXPR be discarded
491 by clear_momentary during the parsing of the next stmt. */
495 /* Finish the body of a for-statement, which may be given by
496 FOR_STMT. The increment-EXPR for the loop must be
500 finish_for_stmt (expr
, for_stmt
)
504 /* Pop the scope for the body of the loop. */
507 if (building_stmt_tree ())
508 RECHAIN_STMTS (for_stmt
, FOR_BODY (for_stmt
));
511 emit_line_note (input_filename
, lineno
);
512 expand_loop_continue_here ();
514 finish_expr_stmt (expr
);
520 if (flag_new_for_scope
> 0)
526 /* Finish a break-statement. */
531 emit_line_note (input_filename
, lineno
);
532 if (building_stmt_tree ())
533 add_tree (build_min_nt (BREAK_STMT
));
534 else if ( ! expand_exit_something ())
535 cp_error ("break statement not within loop or switch");
538 /* Finish a continue-statement. */
541 finish_continue_stmt ()
543 emit_line_note (input_filename
, lineno
);
544 if (building_stmt_tree ())
545 add_tree (build_min_nt (CONTINUE_STMT
));
546 else if (! expand_continue_loop (0))
547 cp_error ("continue statement not within a loop");
550 /* Begin a switch-statement. Returns a new SWITCH_STMT if
558 if (building_stmt_tree ())
560 r
= build_min_nt (SWITCH_STMT
, NULL_TREE
, NULL_TREE
);
571 /* Finish the cond of a switch-statement. */
574 finish_switch_cond (cond
, switch_stmt
)
578 if (building_stmt_tree ())
579 FINISH_COND (cond
, switch_stmt
, SWITCH_COND (switch_stmt
));
580 else if (cond
!= error_mark_node
)
582 emit_line_note (input_filename
, lineno
);
583 c_expand_start_case (cond
);
586 /* The code is in error, but we don't want expand_end_case to
588 c_expand_start_case (boolean_false_node
);
592 /* Don't let the tree nodes for COND be discarded by
593 clear_momentary during the parsing of the next stmt. */
597 /* Finish the body of a switch-statement, which may be given by
598 SWITCH_STMT. The COND to switch on is indicated. */
601 finish_switch_stmt (cond
, switch_stmt
)
605 if (building_stmt_tree ())
606 RECHAIN_STMTS (switch_stmt
, SWITCH_BODY (switch_stmt
));
608 expand_end_case (cond
);
615 /* Finish a case-label. */
618 finish_case_label (low_value
, high_value
)
622 if (building_stmt_tree ())
624 /* Add a representation for the case label to the statement
626 add_tree (build_min_nt (CASE_LABEL
, low_value
, high_value
));
627 /* And warn about crossing initializations, etc. */
628 if (!processing_template_decl
)
629 define_case_label ();
633 do_case (low_value
, high_value
);
636 /* Finish a goto-statement. */
639 finish_goto_stmt (destination
)
642 if (TREE_CODE (destination
) == IDENTIFIER_NODE
)
643 destination
= lookup_label (destination
);
645 /* We warn about unused labels with -Wunused. That means we have to
646 mark the used labels as used. */
647 if (TREE_CODE (destination
) == LABEL_DECL
)
648 TREE_USED (destination
) = 1;
650 if (building_stmt_tree ())
651 add_tree (build_min_nt (GOTO_STMT
, destination
));
654 emit_line_note (input_filename
, lineno
);
656 if (TREE_CODE (destination
) == LABEL_DECL
)
658 label_rtx (destination
);
659 expand_goto (destination
);
662 expand_computed_goto (destination
);
666 /* Begin a try-block. Returns a newly-created TRY_BLOCK if
672 if (building_stmt_tree ())
674 tree r
= build_min_nt (TRY_BLOCK
, NULL_TREE
,
681 emit_line_note (input_filename
, lineno
);
682 expand_start_try_stmts ();
687 /* Likewise, for a function-try-block. */
690 begin_function_try_block ()
692 if (building_stmt_tree ())
694 tree r
= build_min_nt (TRY_BLOCK
, NULL_TREE
,
696 FN_TRY_BLOCK_P (r
) = 1;
702 if (! current_function_parms_stored
)
704 expand_start_early_try_stmts ();
709 /* Finish a try-block, which may be given by TRY_BLOCK. */
712 finish_try_block (try_block
)
715 if (building_stmt_tree ())
716 RECHAIN_STMTS (try_block
, TRY_STMTS (try_block
));
718 expand_start_all_catch ();
721 /* Finish the body of a cleanup try-block, which may be given by
725 finish_cleanup_try_block (try_block
)
728 if (building_stmt_tree ())
729 RECHAIN_STMTS (try_block
, TRY_STMTS (try_block
));
732 /* Finish an implicitly generated try-block, with a cleanup is given
736 finish_cleanup (cleanup
, try_block
)
740 if (building_stmt_tree ())
742 TRY_HANDLERS (try_block
) = cleanup
;
743 CLEANUP_P (try_block
) = 1;
746 expand_eh_region_end (protect_with_terminate (cleanup
));
749 /* Likewise, for a function-try-block. */
752 finish_function_try_block (try_block
)
755 if (building_stmt_tree ())
757 if (TREE_CHAIN (try_block
)
758 && TREE_CODE (TREE_CHAIN (try_block
)) == CTOR_INITIALIZER
)
760 /* Chain the compound statement after the CTOR_INITIALIZER. */
761 TREE_CHAIN (TREE_CHAIN (try_block
)) = last_tree
;
762 /* And make the CTOR_INITIALIZER the body of the try-block. */
763 RECHAIN_STMTS (try_block
, TRY_STMTS (try_block
));
766 RECHAIN_STMTS (try_block
, TRY_STMTS (try_block
));
770 end_protect_partials ();
771 expand_start_all_catch ();
774 in_function_try_handler
= 1;
777 /* Finish a handler-sequence for a try-block, which may be given by
781 finish_handler_sequence (try_block
)
784 if (building_stmt_tree ())
785 RECHAIN_STMTS (try_block
, TRY_HANDLERS (try_block
));
787 expand_end_all_catch ();
790 /* Likewise, for a function-try-block. */
793 finish_function_handler_sequence (try_block
)
796 in_function_try_handler
= 0;
798 if (building_stmt_tree ())
799 RECHAIN_STMTS (try_block
, TRY_HANDLERS (try_block
));
801 expand_end_all_catch ();
804 /* Begin a handler. Returns a HANDLER if appropriate. */
811 if (building_stmt_tree ())
813 r
= build_min_nt (HANDLER
, NULL_TREE
, NULL_TREE
);
824 /* Finish the handler-parameters for a handler, which may be given by
825 HANDLER. DECL is the declaration for the catch parameter, or NULL
826 if this is a `catch (...)' clause. */
829 finish_handler_parms (decl
, handler
)
833 tree blocks
= NULL_TREE
;
835 if (processing_template_decl
)
839 decl
= pushdecl (decl
);
840 decl
= push_template_decl (decl
);
841 add_decl_stmt (decl
);
842 RECHAIN_STMTS (handler
, HANDLER_PARMS (handler
));
845 else if (building_stmt_tree ())
846 blocks
= expand_start_catch_block (decl
);
851 /* Note the beginning of a handler for TYPE. This function is called
852 at the point to which control should be transferred when an
853 appropriately-typed exception is thrown. */
856 begin_catch_block (type
)
859 if (building_stmt_tree ())
860 add_tree (build (START_CATCH_STMT
, type
));
862 start_catch_handler (type
);
865 /* Finish a handler, which may be given by HANDLER. The BLOCKs are
866 the return value from the matching call to finish_handler_parms. */
869 finish_handler (blocks
, handler
)
873 if (!processing_template_decl
)
875 if (building_stmt_tree ())
876 expand_end_catch_block (blocks
);
878 if (!building_stmt_tree ())
880 /* Fall to outside the try statement when done executing
881 handler and we fall off end of handler. This is jump
882 Lresume in the documentation. */
883 expand_goto (top_label_entry (&caught_return_label_stack
));
884 end_catch_handler ();
888 if (building_stmt_tree ())
889 RECHAIN_STMTS (handler
, HANDLER_BODY (handler
));
894 /* Begin a compound-statement. If HAS_NO_SCOPE is non-zero, the
895 compound-statement does not define a scope. Returns a new
896 COMPOUND_STMT if appropriate. */
899 begin_compound_stmt (has_no_scope
)
904 if (building_stmt_tree ())
906 r
= build_min_nt (COMPOUND_STMT
, NULL_TREE
);
909 COMPOUND_STMT_NO_SCOPE (r
) = 1;
914 last_expr_type
= NULL_TREE
;
919 /* Normally, we try hard to keep the BLOCK for a
920 statement-expression. But, if it's a statement-expression with
921 a scopeless block, there's nothing to keep, and we don't want
922 to accidentally keep a block *inside* the scopeless block. */
925 /* If this is the outermost block of the function, declare the
926 variables __FUNCTION__, __PRETTY_FUNCTION__, and so forth. */
927 if (!current_function_name_declared
&& !processing_template_decl
)
929 declare_function_name ();
930 current_function_name_declared
= 1;
937 /* Finish a compound-statement, which may be given by COMPOUND_STMT.
938 If HAS_NO_SCOPE is non-zero, the compound statement does not define
942 finish_compound_stmt (has_no_scope
, compound_stmt
)
954 if (building_stmt_tree ())
955 RECHAIN_STMTS (compound_stmt
, COMPOUND_BODY (compound_stmt
));
957 /* When we call finish_stmt we will lose LAST_EXPR_TYPE. But, since
958 the precise purpose of that variable is store the type of the
959 last expression statement within the last compound statement, we
960 preserve the value. */
968 /* Finish an asm-statement, whose components are a CV_QUALIFIER, a
969 STRING, some OUTPUT_OPERANDS, some INPUT_OPERANDS, and some
973 finish_asm_stmt (cv_qualifier
, string
, output_operands
,
974 input_operands
, clobbers
)
977 tree output_operands
;
981 if (TREE_CHAIN (string
))
983 if (building_stmt_tree ())
984 /* We need to build the combined string on the permanent
985 obstack so that we can use it during instantiations. */
986 push_permanent_obstack ();
988 string
= combine_strings (string
);
990 if (building_stmt_tree ())
994 if (cv_qualifier
!= NULL_TREE
995 && cv_qualifier
!= ridpointers
[(int) RID_VOLATILE
])
997 cp_warning ("%s qualifier ignored on asm",
998 IDENTIFIER_POINTER (cv_qualifier
));
999 cv_qualifier
= NULL_TREE
;
1002 if (building_stmt_tree ())
1004 tree r
= build_min_nt (ASM_STMT
, cv_qualifier
, string
,
1005 output_operands
, input_operands
,
1011 emit_line_note (input_filename
, lineno
);
1012 if (output_operands
!= NULL_TREE
|| input_operands
!= NULL_TREE
1013 || clobbers
!= NULL_TREE
)
1017 for (t
= input_operands
; t
; t
= TREE_CHAIN (t
))
1018 TREE_VALUE (t
) = decay_conversion (TREE_VALUE (t
));
1020 c_expand_asm_operands (string
, output_operands
,
1023 cv_qualifier
!= NULL_TREE
,
1024 input_filename
, lineno
);
1027 expand_asm (string
);
1033 /* Finish a label with the indicated NAME. */
1036 finish_label_stmt (name
)
1039 tree decl
= define_label (input_filename
, lineno
, name
);
1041 if (building_stmt_tree ())
1042 add_tree (build_min_nt (LABEL_STMT
, decl
));
1044 expand_label (decl
);
1047 /* Finish a series of declarations for local labels. G++ allows users
1048 to declare "local" labels, i.e., labels with scope. This extension
1049 is useful when writing code involving statement-expressions. */
1052 finish_label_decl (name
)
1055 tree decl
= declare_local_label (name
);
1056 if (building_stmt_tree ())
1057 add_decl_stmt (decl
);
1060 /* Create a declaration statement for the declaration given by the
1064 add_decl_stmt (decl
)
1069 /* We need the type to last until instantiation time. */
1070 decl_stmt
= build_min_nt (DECL_STMT
, decl
);
1071 add_tree (decl_stmt
);
1074 /* We're in a constructor, and have just constructed a a subobject of
1075 *THIS. CLEANUP is code to run if an exception is thrown before the
1076 end of the current function is reached. */
1079 finish_subobject (cleanup
)
1082 if (building_stmt_tree ())
1084 tree r
= build_min_nt (SUBOBJECT
, cleanup
);
1088 add_partial_entry (cleanup
);
1091 /* When DECL goes out of scope, make sure that CLEANUP is executed. */
1094 finish_decl_cleanup (decl
, cleanup
)
1098 if (building_stmt_tree ())
1099 add_tree (build_min_nt (CLEANUP_STMT
, decl
, cleanup
));
1101 || (DECL_SIZE (decl
) && TREE_TYPE (decl
) != error_mark_node
))
1102 expand_decl_cleanup (decl
, cleanup
);
1105 /* Bind a name and initialization to the return value of
1106 the current function. */
1109 finish_named_return_value (return_id
, init
)
1110 tree return_id
, init
;
1112 tree decl
= DECL_RESULT (current_function_decl
);
1115 /* Give this error as many times as there are occurrences,
1116 so that users can use Emacs compilation buffers to find
1117 and fix all such places. */
1118 pedwarn ("ANSI C++ does not permit named return values");
1120 if (return_id
!= NULL_TREE
)
1122 if (DECL_NAME (decl
) == NULL_TREE
)
1124 DECL_NAME (decl
) = return_id
;
1125 DECL_ASSEMBLER_NAME (decl
) = return_id
;
1129 cp_error ("return identifier `%D' already in place", return_id
);
1134 /* Can't let this happen for constructors. */
1135 if (DECL_CONSTRUCTOR_P (current_function_decl
))
1137 error ("can't redefine default return value for constructors");
1141 /* If we have a named return value, put that in our scope as well. */
1142 if (DECL_NAME (decl
) != NULL_TREE
)
1144 /* Let `cp_finish_decl' know that this initializer is ok. */
1145 DECL_INITIAL (decl
) = init
;
1146 if (doing_semantic_analysis_p ())
1149 if (building_stmt_tree ())
1150 add_tree (build_min_nt (RETURN_INIT
, return_id
, init
));
1153 cp_finish_decl (decl
, init
, NULL_TREE
, 0, 0);
1154 store_return_init (decl
);
1159 /* Cache the value of this class's main virtual function table pointer
1160 in a register variable. This will save one indirection if a
1161 more than one virtual function call is made this function. */
1166 if (base_init_expr
== 0
1167 && DECL_CONSTRUCTOR_P (current_function_decl
))
1169 if (building_stmt_tree ())
1170 add_tree (build_min_nt
1172 current_member_init_list
, current_base_init_list
));
1174 emit_base_init (current_class_type
);
1177 /* Always keep the BLOCK node associated with the outermost pair of
1178 curley braces of a function. These are needed for correct
1179 operation of dwarfout.c. */
1180 keep_next_level (1);
1183 /* Begin a new scope. */
1188 if (!building_stmt_tree ())
1190 emit_line_note (input_filename
, lineno
);
1194 if (stmts_are_full_exprs_p
)
1197 if (!building_stmt_tree ()
1198 && !current_function
->x_whole_function_mode_p
)
1199 expand_start_bindings (0);
1200 else if (building_stmt_tree () && !processing_template_decl
)
1202 tree ss
= build_min_nt (SCOPE_STMT
);
1203 SCOPE_BEGIN_P (ss
) = 1;
1205 current_scope_stmt_stack
1206 = tree_cons (NULL_TREE
, ss
, current_scope_stmt_stack
);
1211 /* Finish a scope. */
1218 if (stmts_are_full_exprs_p
)
1220 if (!building_stmt_tree ()
1221 && !current_function
->x_whole_function_mode_p
)
1222 expand_end_bindings (getdecls (), kept_level_p (), 0);
1223 else if (building_stmt_tree () && !processing_template_decl
)
1225 tree ss
= build_min_nt (SCOPE_STMT
);
1226 SCOPE_NULLIFIED_P (ss
) = !kept_level_p ();
1227 SCOPE_NULLIFIED_P (TREE_VALUE (current_scope_stmt_stack
))
1228 = SCOPE_NULLIFIED_P (ss
);
1230 current_scope_stmt_stack
= TREE_CHAIN (current_scope_stmt_stack
);
1232 /* When not in function-at-a-time mode, expand_end_bindings
1233 will warn about unused variables. But, in
1234 function-at-a-time mode expand_end_bindings is not passed
1235 the list of variables in the current scope, and therefore
1236 no warning is emitted. So, we explicitly warn here. */
1237 warn_about_unused_variables (getdecls ());
1240 t
= poplevel (kept_level_p (), 1, 0);
1246 /* Finish a parenthesized expression EXPR. */
1249 finish_parenthesized_expr (expr
)
1252 if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (TREE_CODE (expr
))))
1253 /* This inhibits warnings in truthvalue_conversion. */
1254 C_SET_EXP_ORIGINAL_CODE (expr
, ERROR_MARK
);
1259 /* Begin a statement-expression. The value returned must be passed to
1260 finish_stmt_expr. */
1265 keep_next_level (1);
1266 /* If we're building a statement tree, then the upcoming compound
1267 statement will be chained onto the tree structure, starting at
1268 last_tree. We return last_tree so that we can later unhook the
1269 compound statement. */
1270 return building_stmt_tree () ? last_tree
: expand_start_stmt_expr();
1273 /* Finish a statement-expression. RTL_EXPR should be the value
1274 returned by the previous begin_stmt_expr; EXPR is the
1275 statement-expression. Returns an expression representing the
1276 statement-expression. */
1279 finish_stmt_expr (rtl_expr
, expr
)
1285 if (!building_stmt_tree ())
1287 rtl_expr
= expand_end_stmt_expr (rtl_expr
);
1288 /* The statements have side effects, so the group does. */
1289 TREE_SIDE_EFFECTS (rtl_expr
) = 1;
1292 if (building_stmt_tree ())
1294 /* If the last thing in the statement-expression was not an
1295 expression-statement, then it has type `void'. */
1296 if (!last_expr_type
)
1297 last_expr_type
= void_type_node
;
1298 result
= build_min (STMT_EXPR
, last_expr_type
, last_tree
);
1299 TREE_SIDE_EFFECTS (result
) = 1;
1301 /* Remove the compound statement from the tree structure; it is
1302 now saved in the STMT_EXPR. */
1303 last_tree
= rtl_expr
;
1304 TREE_CHAIN (last_tree
) = NULL_TREE
;
1306 else if (expr
&& TREE_CODE (expr
) == BLOCK
)
1308 result
= build (BIND_EXPR
, TREE_TYPE (rtl_expr
),
1309 NULL_TREE
, rtl_expr
, expr
);
1310 delete_block (expr
);
1315 if (expr
&& TREE_CODE (expr
) == BLOCK
)
1316 /* Remove the block from the tree at this point. It gets put back
1317 at the proper place when the STMT_EXPR or BIND_EXPR is
1319 delete_block (expr
);
1324 /* Finish a call to FN with ARGS. Returns a representation of the
1328 finish_call_expr (fn
, args
, koenig
)
1337 if (TREE_CODE (fn
) == BIT_NOT_EXPR
)
1338 fn
= build_x_unary_op (BIT_NOT_EXPR
, TREE_OPERAND (fn
, 0));
1339 else if (TREE_CODE (fn
) != TEMPLATE_ID_EXPR
)
1340 fn
= do_identifier (fn
, 2, args
);
1342 result
= build_x_function_call (fn
, args
, current_class_ref
);
1344 if (TREE_CODE (result
) == CALL_EXPR
1345 && (! TREE_TYPE (result
)
1346 || TREE_CODE (TREE_TYPE (result
)) != VOID_TYPE
))
1347 result
= require_complete_type (result
);
1352 /* Finish a call to a postfix increment or decrement or EXPR. (Which
1353 is indicated by CODE, which should be POSTINCREMENT_EXPR or
1354 POSTDECREMENT_EXPR.) */
1357 finish_increment_expr (expr
, code
)
1359 enum tree_code code
;
1361 /* If we get an OFFSET_REF, turn it into what it really means (e.g.,
1362 a COMPONENT_REF). This way if we've got, say, a reference to a
1363 static member that's being operated on, we don't end up trying to
1364 find a member operator for the class it's in. */
1366 if (TREE_CODE (expr
) == OFFSET_REF
)
1367 expr
= resolve_offset_ref (expr
);
1368 return build_x_unary_op (code
, expr
);
1371 /* Finish a use of `this'. Returns an expression for `this'. */
1378 if (current_class_ptr
)
1380 #ifdef WARNING_ABOUT_CCD
1381 TREE_USED (current_class_ptr
) = 1;
1383 result
= current_class_ptr
;
1385 else if (current_function_decl
1386 && DECL_STATIC_FUNCTION_P (current_function_decl
))
1388 error ("`this' is unavailable for static member functions");
1389 result
= error_mark_node
;
1393 if (current_function_decl
)
1394 error ("invalid use of `this' in non-member function");
1396 error ("invalid use of `this' at top level");
1397 result
= error_mark_node
;
1403 /* Finish a member function call using OBJECT and ARGS as arguments to
1404 FN. Returns an expression for the call. */
1407 finish_object_call_expr (fn
, object
, args
)
1413 /* This is a future direction of this code, but because
1414 build_x_function_call cannot always undo what is done in
1415 build_component_ref entirely yet, we cannot do this. */
1417 tree real_fn
= build_component_ref (object
, fn
, NULL_TREE
, 1);
1418 return finish_call_expr (real_fn
, args
);
1420 if (TREE_CODE (fn
) == TYPE_DECL
)
1422 if (processing_template_decl
)
1423 /* This can happen on code like:
1426 template <class T> void f(T t) {
1430 We just grab the underlying IDENTIFIER. */
1431 fn
= DECL_NAME (fn
);
1434 cp_error ("calling type `%T' like a method", fn
);
1435 return error_mark_node
;
1439 return build_method_call (object
, fn
, args
, NULL_TREE
, LOOKUP_NORMAL
);
1443 /* Finish a qualified member function call using OBJECT and ARGS as
1444 arguments to FN. Returns an expressino for the call. */
1447 finish_qualified_object_call_expr (fn
, object
, args
)
1452 return build_scoped_method_call (object
, TREE_OPERAND (fn
, 0),
1453 TREE_OPERAND (fn
, 1), args
);
1456 /* Finish a pseudo-destructor call expression of OBJECT, with SCOPE
1457 being the scope, if any, of DESTRUCTOR. Returns an expression for
1461 finish_pseudo_destructor_call_expr (object
, scope
, destructor
)
1466 if (processing_template_decl
)
1467 return build_min_nt (PSEUDO_DTOR_EXPR
, object
, scope
, destructor
);
1469 if (scope
&& scope
!= destructor
)
1470 cp_error ("destructor specifier `%T::~%T()' must have matching names",
1473 if ((scope
== NULL_TREE
|| IDENTIFIER_GLOBAL_VALUE (destructor
))
1474 && (TREE_CODE (TREE_TYPE (object
)) !=
1475 TREE_CODE (TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (destructor
)))))
1476 cp_error ("`%E' is not of type `%T'", object
, destructor
);
1478 return cp_convert (void_type_node
, object
);
1481 /* Finish a call to a globally qualified member function FN using
1482 ARGS. Returns an expression for the call. */
1485 finish_qualified_call_expr (fn
, args
)
1489 if (processing_template_decl
)
1490 return build_min_nt (CALL_EXPR
, fn
, args
, NULL_TREE
);
1492 return build_member_call (TREE_OPERAND (fn
, 0),
1493 TREE_OPERAND (fn
, 1),
1497 /* Finish an expression taking the address of LABEL. Returns an
1498 expression for the address. */
1501 finish_label_address_expr (label
)
1506 label
= lookup_label (label
);
1507 if (label
== NULL_TREE
)
1508 result
= null_pointer_node
;
1511 TREE_USED (label
) = 1;
1512 result
= build1 (ADDR_EXPR
, ptr_type_node
, label
);
1513 TREE_CONSTANT (result
) = 1;
1519 /* Finish an expression of the form CODE EXPR. */
1522 finish_unary_op_expr (code
, expr
)
1523 enum tree_code code
;
1526 tree result
= build_x_unary_op (code
, expr
);
1527 if (code
== NEGATE_EXPR
&& TREE_CODE (expr
) == INTEGER_CST
)
1528 TREE_NEGATED_INT (result
) = 1;
1529 overflow_warning (result
);
1533 /* Finish an id-expression. */
1536 finish_id_expr (expr
)
1539 if (TREE_CODE (expr
) == IDENTIFIER_NODE
)
1540 expr
= do_identifier (expr
, 1, NULL_TREE
);
1545 /* Begin a new-placement. */
1548 begin_new_placement ()
1550 /* The arguments to a placement new might be passed to a
1551 deallocation function, in the event that the allocation throws an
1552 exception. Since we don't expand exception handlers until the
1553 end of a function, we must make sure the arguments stay around
1555 return suspend_momentary ();
1558 /* Finish a new-placement. The ARGS are the placement arguments. The
1559 COOKIE is the value returned by the previous call to
1560 begin_new_placement. */
1563 finish_new_placement (args
, cookie
)
1567 resume_momentary (cookie
);
1571 /* Begin a function defniition declared with DECL_SPECS and
1572 DECLARATOR. Returns non-zero if the function-declaration is
1576 begin_function_definition (decl_specs
, declarator
)
1582 split_specs_attrs (decl_specs
, &specs
, &attrs
);
1583 if (!start_function (specs
, declarator
, attrs
, SF_DEFAULT
))
1586 reinit_parse_for_function ();
1587 /* The things we're about to see are not directly qualified by any
1588 template headers we've seen thus far. */
1589 reset_specialization ();
1594 /* Begin a constructor declarator of the form `SCOPE::NAME'. Returns
1598 begin_constructor_declarator (scope
, name
)
1602 tree result
= build_parse_node (SCOPE_REF
, scope
, name
);
1603 enter_scope_of (result
);
1607 /* Finish an init-declarator. Returns a DECL. */
1610 finish_declarator (declarator
, declspecs
, attributes
,
1611 prefix_attributes
, initialized
)
1615 tree prefix_attributes
;
1618 return start_decl (declarator
, declspecs
, initialized
, attributes
,
1622 /* Finish a translation unit. */
1625 finish_translation_unit ()
1627 /* In case there were missing closebraces,
1628 get us back to the global binding level. */
1630 while (current_namespace
!= global_namespace
)
1635 /* Finish a template type parameter, specified as AGGR IDENTIFIER.
1636 Returns the parameter. */
1639 finish_template_type_parm (aggr
, identifier
)
1643 if (aggr
!= class_type_node
)
1645 pedwarn ("template type parameters must use the keyword `class' or `typename'");
1646 aggr
= class_type_node
;
1649 return build_tree_list (aggr
, identifier
);
1652 /* Finish a template template parameter, specified as AGGR IDENTIFIER.
1653 Returns the parameter. */
1656 finish_template_template_parm (aggr
, identifier
)
1660 tree decl
= build_decl (TYPE_DECL
, identifier
, NULL_TREE
);
1661 tree tmpl
= build_lang_decl (TEMPLATE_DECL
, identifier
, NULL_TREE
);
1662 DECL_TEMPLATE_PARMS (tmpl
) = current_template_parms
;
1663 DECL_TEMPLATE_RESULT (tmpl
) = decl
;
1664 SET_DECL_ARTIFICIAL (decl
);
1665 end_template_decl ();
1667 return finish_template_type_parm (aggr
, tmpl
);
1670 /* Finish a parameter list, indicated by PARMS. If ELLIPSIS is
1671 non-zero, the parameter list was terminated by a `...'. */
1674 finish_parmlist (parms
, ellipsis
)
1679 chainon (parms
, void_list_node
);
1680 /* We mark the PARMS as a parmlist so that declarator processing can
1681 disambiguate certain constructs. */
1682 if (parms
!= NULL_TREE
)
1683 TREE_PARMLIST (parms
) = 1;
1688 /* Begin a class definition, as indicated by T. */
1691 begin_class_definition (t
)
1694 push_permanent_obstack ();
1696 if (t
== error_mark_node
1697 || ! IS_AGGR_TYPE (t
))
1699 t
= make_lang_type (RECORD_TYPE
);
1700 pushtag (make_anon_name (), t
, 0);
1703 /* In a definition of a member class template, we will get here with an
1704 implicit typename, a TYPENAME_TYPE with a type. */
1705 if (TREE_CODE (t
) == TYPENAME_TYPE
)
1708 /* If we generated a partial instantiation of this type, but now
1709 we're seeing a real definition, we're actually looking at a
1710 partial specialization. Consider:
1712 template <class T, class U>
1718 template <class T, class U>
1721 typename X<Y<T, U> >::A a;
1724 template <class T, class U>
1729 We have to undo the effects of the previous partial
1731 if (PARTIAL_INSTANTIATION_P (t
))
1735 /* Unfortunately, when we're not in pedantic mode, we
1736 attempt to actually fill in some of the fields of the
1737 partial instantiation, in order to support the implicit
1738 typename extension. Clear those fields now, in
1739 preparation for the definition here. The fields cleared
1740 here must match those set in instantiate_class_template.
1741 Look for a comment mentioning begin_class_definition
1743 TYPE_BINFO_BASETYPES (t
) = NULL_TREE
;
1744 TYPE_FIELDS (t
) = NULL_TREE
;
1745 TYPE_METHODS (t
) = NULL_TREE
;
1746 CLASSTYPE_TAGS (t
) = NULL_TREE
;
1747 TYPE_SIZE (t
) = NULL_TREE
;
1750 /* This isn't a partial instantiation any more. */
1751 PARTIAL_INSTANTIATION_P (t
) = 0;
1753 /* If this type was already complete, and we see another definition,
1755 else if (TYPE_SIZE (t
))
1756 duplicate_tag_error (t
);
1758 /* Update the location of the decl. */
1759 DECL_SOURCE_FILE (TYPE_NAME (t
)) = input_filename
;
1760 DECL_SOURCE_LINE (TYPE_NAME (t
)) = lineno
;
1762 if (TYPE_BEING_DEFINED (t
))
1764 t
= make_lang_type (TREE_CODE (t
));
1765 pushtag (TYPE_IDENTIFIER (t
), t
, 0);
1767 maybe_process_partial_specialization (t
);
1769 TYPE_BEING_DEFINED (t
) = 1;
1770 /* Reset the interface data, at the earliest possible
1771 moment, as it might have been set via a class foo;
1774 tree name
= TYPE_IDENTIFIER (t
);
1776 if (! ANON_AGGRNAME_P (name
))
1778 CLASSTYPE_INTERFACE_ONLY (t
) = interface_only
;
1779 SET_CLASSTYPE_INTERFACE_UNKNOWN_X
1780 (t
, interface_unknown
);
1783 /* Only leave this bit clear if we know this
1784 class is part of an interface-only specification. */
1785 if (! CLASSTYPE_INTERFACE_KNOWN (t
)
1786 || ! CLASSTYPE_INTERFACE_ONLY (t
))
1787 CLASSTYPE_VTABLE_NEEDS_WRITING (t
) = 1;
1790 tmp
= TYPE_IDENTIFIER ($
<ttype
>0);
1791 if (tmp
&& IDENTIFIER_TEMPLATE (tmp
))
1792 overload_template_name (tmp
, 1);
1794 reset_specialization();
1796 /* In case this is a local class within a template
1797 function, we save the current tree structure so
1798 that we can get it back later. */
1801 /* Make a declaration for this class in its own scope. */
1802 build_self_reference ();
1807 /* Finish the member declaration given by DECL. */
1810 finish_member_declaration (decl
)
1813 if (decl
== error_mark_node
|| decl
== NULL_TREE
)
1816 if (decl
== void_type_node
)
1817 /* The COMPONENT was a friend, not a member, and so there's
1818 nothing for us to do. */
1821 /* We should see only one DECL at a time. */
1822 my_friendly_assert (TREE_CHAIN (decl
) == NULL_TREE
, 0);
1824 /* Set up access control for DECL. */
1826 = (current_access_specifier
== access_private_node
);
1827 TREE_PROTECTED (decl
)
1828 = (current_access_specifier
== access_protected_node
);
1829 if (TREE_CODE (decl
) == TEMPLATE_DECL
)
1831 TREE_PRIVATE (DECL_RESULT (decl
)) = TREE_PRIVATE (decl
);
1832 TREE_PROTECTED (DECL_RESULT (decl
)) = TREE_PROTECTED (decl
);
1835 /* Mark the DECL as a member of the current class. */
1836 if (TREE_CODE (decl
) == FUNCTION_DECL
1837 || DECL_FUNCTION_TEMPLATE_P (decl
))
1838 /* Historically, DECL_CONTEXT was not set for a FUNCTION_DECL in
1839 finish_struct. Presumably it is already set as the function is
1840 parsed. Perhaps DECL_CLASS_CONTEXT is already set, too? */
1841 DECL_CLASS_CONTEXT (decl
) = current_class_type
;
1843 DECL_CONTEXT (decl
) = current_class_type
;
1845 /* Put functions on the TYPE_METHODS list and everything else on the
1846 TYPE_FIELDS list. Note that these are built up in reverse order.
1847 We reverse them (to obtain declaration order) in finish_struct. */
1848 if (TREE_CODE (decl
) == FUNCTION_DECL
1849 || DECL_FUNCTION_TEMPLATE_P (decl
))
1851 /* We also need to add this function to the
1852 CLASSTYPE_METHOD_VEC. */
1853 add_method (current_class_type
, 0, decl
);
1855 TREE_CHAIN (decl
) = TYPE_METHODS (current_class_type
);
1856 TYPE_METHODS (current_class_type
) = decl
;
1860 /* All TYPE_DECLs go at the end of TYPE_FIELDS. Ordinary fields
1861 go at the beginning. The reason is that lookup_field_1
1862 searches the list in order, and we want a field name to
1863 override a type name so that the "struct stat hack" will
1864 work. In particular:
1866 struct S { enum E { }; int E } s;
1869 is legal. In addition, the FIELD_DECLs must be maintained in
1870 declaration order so that class layout works as expected.
1871 However, we don't need that order until class layout, so we
1872 save a little time by putting FIELD_DECLs on in reverse order
1873 here, and then reversing them in finish_struct_1. (We could
1874 also keep a pointer to the correct insertion points in the
1877 if (TREE_CODE (decl
) == TYPE_DECL
)
1878 TYPE_FIELDS (current_class_type
)
1879 = chainon (TYPE_FIELDS (current_class_type
), decl
);
1882 TREE_CHAIN (decl
) = TYPE_FIELDS (current_class_type
);
1883 TYPE_FIELDS (current_class_type
) = decl
;
1886 /* Enter the DECL into the scope of the class. */
1887 if (TREE_CODE (decl
) != USING_DECL
)
1888 pushdecl_class_level (decl
);
1892 /* Finish a class definition T with the indicate ATTRIBUTES. If SEMI,
1893 the definition is immediately followed by a semicolon. Returns the
1897 finish_class_definition (t
, attributes
, semi
, pop_scope_p
)
1903 /* finish_struct nukes this anyway; if finish_exception does too,
1906 note_got_semicolon (t
);
1908 /* If we got any attributes in class_head, xref_tag will stick them in
1909 TREE_TYPE of the type. Grab them now. */
1910 attributes
= chainon (TREE_TYPE (t
), attributes
);
1911 TREE_TYPE (t
) = NULL_TREE
;
1913 if (TREE_CODE (t
) == ENUMERAL_TYPE
)
1917 t
= finish_struct (t
, attributes
);
1919 note_got_semicolon (t
);
1925 check_for_missing_semicolon (t
);
1927 pop_scope (CP_DECL_CONTEXT (TYPE_MAIN_DECL (t
)));
1928 if (current_scope () == current_function_decl
)
1929 do_pending_defargs ();
1934 /* Finish processing the default argument expressions cached during
1935 the processing of a class definition. */
1938 begin_inline_definitions ()
1941 && current_scope () == current_function_decl
)
1942 do_pending_inlines ();
1945 /* Finish processing the inline function definitions cached during the
1946 processing of a class definition. */
1949 finish_inline_definitions ()
1951 if (current_class_type
== NULL_TREE
)
1952 clear_inline_text_obstack ();
1954 /* Undo the begin_tree in begin_class_definition. */
1958 /* Finish processing the declaration of a member class template
1959 TYPES whose template parameters are given by PARMS. */
1962 finish_member_class_template (types
)
1967 /* If there are declared, but undefined, partial specializations
1968 mixed in with the typespecs they will not yet have passed through
1969 maybe_process_partial_specialization, so we do that here. */
1970 for (t
= types
; t
!= NULL_TREE
; t
= TREE_CHAIN (t
))
1971 if (IS_AGGR_TYPE_CODE (TREE_CODE (TREE_VALUE (t
))))
1972 maybe_process_partial_specialization (TREE_VALUE (t
));
1974 note_list_got_semicolon (types
);
1975 grok_x_components (types
);
1976 if (TYPE_CONTEXT (TREE_VALUE (types
)) != current_class_type
)
1977 /* The component was in fact a friend declaration. We avoid
1978 finish_member_template_decl performing certain checks by
1982 finish_member_template_decl (types
);
1984 /* As with other component type declarations, we do
1985 not store the new DECL on the list of
1990 /* Finish processsing a complete template declaration. The PARMS are
1991 the template parameters. */
1994 finish_template_decl (parms
)
1998 end_template_decl ();
2000 end_specialization ();
2003 /* Finish processing a a template-id (which names a type) of the form
2004 NAME < ARGS >. Return the TYPE_DECL for the type named by the
2005 template-id. If ENTERING_SCOPE is non-zero we are about to enter
2006 the scope of template-id indicated. */
2009 finish_template_type (name
, args
, entering_scope
)
2016 decl
= lookup_template_class (name
, args
,
2017 NULL_TREE
, NULL_TREE
, entering_scope
);
2018 if (decl
!= error_mark_node
)
2019 decl
= TYPE_STUB_DECL (decl
);
2024 /* SR is a SCOPE_REF node. Enter the scope of SR, whether it is a
2025 namespace scope or a class scope. */
2031 tree scope
= TREE_OPERAND (sr
, 0);
2033 if (TREE_CODE (scope
) == NAMESPACE_DECL
)
2035 push_decl_namespace (scope
);
2036 TREE_COMPLEXITY (sr
) = -1;
2038 else if (scope
!= current_class_type
)
2040 if (TREE_CODE (scope
) == TYPENAME_TYPE
)
2042 /* In a declarator for a template class member, the scope will
2043 get here as an implicit typename, a TYPENAME_TYPE with a type. */
2044 scope
= TREE_TYPE (scope
);
2045 TREE_OPERAND (sr
, 0) = scope
;
2047 push_nested_class (scope
, 3);
2048 TREE_COMPLEXITY (sr
) = current_class_depth
;
2052 /* Finish processing a BASE_CLASS with the indicated ACCESS_SPECIFIER.
2053 Return a TREE_LIST containing the ACCESS_SPECIFIER and the
2054 BASE_CLASS, or NULL_TREE if an error occurred. The
2055 ACCESSS_SPECIFIER is one of
2056 access_{default,public,protected_private}[_virtual]_node.*/
2059 finish_base_specifier (access_specifier
, base_class
)
2060 tree access_specifier
;
2066 if (base_class
== NULL_TREE
)
2068 error ("invalid base class");
2069 type
= error_mark_node
;
2072 type
= TREE_TYPE (base_class
);
2074 if (! is_aggr_type (type
, 1))
2077 result
= build_tree_list (access_specifier
, type
);
2082 /* Called when multiple declarators are processed. If that is not
2083 premitted in this context, an error is issued. */
2086 check_multiple_declarators ()
2090 In a template-declaration, explicit specialization, or explicit
2091 instantiation the init-declarator-list in the declaration shall
2092 contain at most one declarator.
2094 We don't just use PROCESSING_TEMPLATE_DECL for the first
2095 condition since that would disallow the perfectly legal code,
2096 like `template <class T> struct S { int i, j; };'. */
2097 tree scope
= current_scope ();
2099 if (scope
&& TREE_CODE (scope
) == FUNCTION_DECL
)
2100 /* It's OK to write `template <class T> void f() { int i, j;}'. */
2103 if (PROCESSING_REAL_TEMPLATE_DECL_P ()
2104 || processing_explicit_instantiation
2105 || processing_specialization
)
2106 cp_error ("multiple declarators in template declaration");
2110 finish_typeof (expr
)
2113 if (processing_template_decl
)
2117 push_permanent_obstack ();
2118 t
= make_lang_type (TYPEOF_TYPE
);
2119 TYPE_FIELDS (t
) = expr
;
2125 return TREE_TYPE (expr
);
2128 /* Create an empty statement tree for FN. */
2131 begin_stmt_tree (fn
)
2134 /* We create a trivial EXPR_STMT so that last_tree is never NULL in
2135 what follows. We remove the extraneous statement in
2136 finish_stmt_tree. */
2137 DECL_SAVED_TREE (fn
) = build_nt (EXPR_STMT
, void_zero_node
);
2138 last_tree
= DECL_SAVED_TREE (fn
);
2139 last_expr_type
= NULL_TREE
;
2142 /* Finish the statement tree for FN. */
2145 finish_stmt_tree (fn
)
2150 /* Remove the fake extra statement added in begin_stmt_tree. */
2151 stmt
= TREE_CHAIN (DECL_SAVED_TREE (fn
));
2152 DECL_SAVED_TREE (fn
) = stmt
;
2154 /* The line-number recorded in the outermost statement in a function
2155 is the line number of the end of the function. */
2156 STMT_LINENO (stmt
) = lineno
;
2157 STMT_LINENO_FOR_FN_P (stmt
) = 1;
2160 /* We're about to expand T, a statement. Set up appropriate context
2161 for the substitution. */
2167 if (!STMT_LINENO_FOR_FN_P (t
))
2168 lineno
= STMT_LINENO (t
);
2169 stmts_are_full_exprs_p
= STMT_IS_FULL_EXPR_P (t
);
2172 /* Some statements, like for-statements or if-statements, require a
2173 condition. This condition can be a declaration. If T is such a
2174 declaration it is processed, and an expression appropriate to use
2175 as the condition is returned. Otherwise, T itself is returned. */
2181 if (t
&& TREE_CODE (t
) == TREE_LIST
)
2183 expand_stmt (TREE_PURPOSE (t
));
2184 return TREE_VALUE (t
);
2190 /* Generate RTL for the statement T, and its substatements, and any
2191 other statements at its nesting level. */
2199 while (t
&& t
!= error_mark_node
)
2201 int saved_stmts_are_full_exprs_p
;
2203 /* Assume we'll have nothing to return. */
2206 /* Set up context appropriately for handling this statement. */
2207 saved_stmts_are_full_exprs_p
= stmts_are_full_exprs_p
;
2210 switch (TREE_CODE (t
))
2213 finish_return_stmt (RETURN_EXPR (t
));
2217 finish_expr_stmt_real (EXPR_STMT_EXPR (t
),
2218 EXPR_STMT_ASSIGNS_THIS (t
));
2224 int i
= suspend_momentary ();
2226 emit_line_note (input_filename
, lineno
);
2227 decl
= DECL_STMT_DECL (t
);
2228 /* If this is a declaration for an automatic local
2229 variable, initialize it. Note that we might also see a
2230 declaration for a namespace-scope object (declared with
2231 `extern') or an object with static storage duration
2232 (declared with `static'). We don't have to handle the
2233 initialization of those objects here; the former can
2234 never be a definition (only a declaration), and the
2235 latter is handled in finish_file. */
2236 if (TREE_CODE (decl
) == VAR_DECL
2237 && !TREE_STATIC (decl
)
2238 && !DECL_EXTERNAL (decl
))
2239 /* Let the back-end know about this variable. */
2240 emit_local_var (decl
);
2242 resume_momentary (i
);
2247 finish_decl_cleanup (CLEANUP_DECL (t
), CLEANUP_EXPR (t
));
2250 case START_CATCH_STMT
:
2251 begin_catch_block (TREE_TYPE (t
));
2259 expand_stmt (FOR_INIT_STMT (t
));
2260 finish_for_init_stmt (NULL_TREE
);
2261 finish_for_cond (expand_cond (FOR_COND (t
)), NULL_TREE
);
2263 finish_for_expr (tmp
, NULL_TREE
);
2264 expand_stmt (FOR_BODY (t
));
2265 finish_for_stmt (tmp
, NULL_TREE
);
2271 begin_while_stmt ();
2272 finish_while_stmt_cond (expand_cond (WHILE_COND (t
)), NULL_TREE
);
2273 expand_stmt (WHILE_BODY (t
));
2274 finish_while_stmt (NULL_TREE
);
2281 expand_stmt (DO_BODY (t
));
2282 finish_do_body (NULL_TREE
);
2283 finish_do_stmt (DO_COND (t
), NULL_TREE
);
2289 finish_if_stmt_cond (expand_cond (IF_COND (t
)), NULL_TREE
);
2290 if (THEN_CLAUSE (t
))
2292 expand_stmt (THEN_CLAUSE (t
));
2293 finish_then_clause (NULL_TREE
);
2295 if (ELSE_CLAUSE (t
))
2297 begin_else_clause ();
2298 expand_stmt (ELSE_CLAUSE (t
));
2299 finish_else_clause (NULL_TREE
);
2305 begin_compound_stmt (COMPOUND_STMT_NO_SCOPE (t
));
2306 expand_stmt (COMPOUND_BODY (t
));
2307 rval
= finish_compound_stmt (COMPOUND_STMT_NO_SCOPE (t
),
2312 finish_break_stmt ();
2316 finish_continue_stmt ();
2323 begin_switch_stmt ();
2324 cond
= expand_cond (SWITCH_COND (t
));
2325 finish_switch_cond (cond
, NULL_TREE
);
2326 expand_stmt (SWITCH_BODY (t
));
2327 finish_switch_stmt (cond
, NULL_TREE
);
2332 finish_case_label (CASE_LOW (t
), CASE_HIGH (t
));
2336 expand_label (LABEL_STMT_LABEL (t
));
2340 finish_goto_stmt (GOTO_DESTINATION (t
));
2344 finish_asm_stmt (ASM_CV_QUAL (t
), ASM_STRING (t
), ASM_OUTPUTS
2345 (t
), ASM_INPUTS (t
), ASM_CLOBBERS (t
));
2351 expand_eh_region_start ();
2352 expand_stmt (TRY_STMTS (t
));
2353 finish_cleanup_try_block (NULL_TREE
);
2354 finish_cleanup (TRY_HANDLERS (t
), NULL_TREE
);
2358 if (FN_TRY_BLOCK_P (t
))
2359 begin_function_try_block ();
2363 expand_stmt (TRY_STMTS (t
));
2365 if (FN_TRY_BLOCK_P (t
))
2367 finish_function_try_block (NULL_TREE
);
2368 expand_stmt (TRY_HANDLERS (t
));
2369 finish_function_handler_sequence (NULL_TREE
);
2373 finish_try_block (NULL_TREE
);
2374 expand_stmt (TRY_HANDLERS (t
));
2375 finish_handler_sequence (NULL_TREE
);
2382 expand_stmt (HANDLER_BODY (t
));
2383 finish_handler (NULL_TREE
, NULL_TREE
);
2387 finish_subobject (SUBOBJECT_CLEANUP (t
));
2391 if (SCOPE_BEGIN_P (t
))
2392 expand_start_bindings (2 * SCOPE_NULLIFIED_P (t
));
2393 else if (SCOPE_END_P (t
))
2394 expand_end_bindings (NULL_TREE
, !SCOPE_NULLIFIED_P (t
), 0);
2397 case CTOR_INITIALIZER
:
2398 current_member_init_list
= TREE_OPERAND (t
, 0);
2399 current_base_init_list
= TREE_OPERAND (t
, 1);
2404 /* Clear this out so that finish_named_return_value can set it
2406 DECL_NAME (DECL_RESULT (current_function_decl
)) = NULL_TREE
;
2407 finish_named_return_value (TREE_OPERAND (t
, 0),
2408 TREE_OPERAND (t
, 1));
2412 my_friendly_abort (19990810);
2416 /* Restore saved state. */
2417 stmts_are_full_exprs_p
= saved_stmts_are_full_exprs_p
;
2419 /* Go on to the next statement in this scope. */
2426 /* Generate RTL for FN. */
2433 char *saved_input_filename
;
2435 /* When the parser calls us after finishing the body of a template
2436 function, we don't really want to expand the body. When we're
2437 processing an in-class definition of an inline function,
2438 PROCESSING_TEMPLATE_DECL will no longer be set here, so we have
2439 to look at the function itself. */
2440 if (processing_template_decl
2441 || (DECL_LANG_SPECIFIC (fn
)
2442 && DECL_TEMPLATE_INFO (fn
)
2443 && uses_template_parms (DECL_TI_ARGS (fn
))))
2446 /* Save the current file name and line number. When we expand the
2447 body of the funciton, we'll set LINENO and INPUT_FILENAME so that
2448 error-mesages come out in the right places. */
2449 saved_lineno
= lineno
;
2450 saved_input_filename
= input_filename
;
2451 lineno
= DECL_SOURCE_LINE (fn
);
2452 input_filename
= DECL_SOURCE_FILE (fn
);
2454 start_function (NULL_TREE
, fn
, NULL_TREE
, SF_PRE_PARSED
| SF_EXPAND
);
2455 store_parm_decls ();
2457 /* We don't need to redeclare __FUNCTION__, __PRETTY_FUNCTION__, or
2458 any of the other magic variables we set up when starting a
2460 current_function_name_declared
= 1;
2462 /* Expand the body. */
2463 expand_stmt (DECL_SAVED_TREE (fn
));
2465 /* Statements should always be full-expressions at the outermost set
2466 of curly braces for a function. */
2467 my_friendly_assert (stmts_are_full_exprs_p
, 19990831);
2469 /* The outermost statement for a function contains the line number
2470 recorded when we finished processing the function. */
2471 lineno
= STMT_LINENO (DECL_SAVED_TREE (fn
));
2473 /* Generate code for the function. */
2474 finish_function (lineno
, 0);
2476 /* And restore the current source position. */
2477 lineno
= saved_lineno
;
2478 input_filename
= saved_input_filename
;