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
38 /* There routines provide a modular interface to perform many parsing
39 operations. They may therefore be used during actual parsing, or
40 during template instantiation, which may be regarded as a
41 degenerate form of parsing. Since the current g++ parser is
42 lacking in several respects, and will be reimplemented, we are
43 attempting to move most code that is not directly related to
44 parsing into this file; that will make implementing the new parser
45 much easier since it will be able to make use of these routines. */
47 static tree expand_cond
PROTO((tree
));
48 static tree maybe_convert_cond
PROTO((tree
));
50 /* Record the fact that STMT was the last statement added to the
53 #define SET_LAST_STMT(stmt) \
54 (current_stmt_tree->x_last_stmt = (stmt))
56 /* When parsing a template, LAST_TREE contains the last statement
57 parsed. These are chained together through the TREE_CHAIN field,
58 but often need to be re-organized since the parse is performed
59 bottom-up. This macro makes LAST_TREE the indicated SUBSTMT of
62 #define RECHAIN_STMTS(stmt, substmt) \
64 substmt = TREE_CHAIN (stmt); \
65 TREE_CHAIN (stmt) = NULL_TREE; \
66 SET_LAST_STMT (stmt); \
69 /* Finish processing the COND, the SUBSTMT condition for STMT. */
71 #define FINISH_COND(cond, stmt, substmt) \
73 if (last_tree != stmt) \
75 RECHAIN_STMTS (stmt, substmt); \
76 if (!processing_template_decl) \
78 cond = build_tree_list (substmt, cond); \
86 /* T is a statement. Add it to the statement-tree. */
92 /* Add T to the statement-tree. */
93 TREE_CHAIN (last_tree
) = t
;
96 /* When we expand a statement-tree, we must know whether or not the
97 statements are full-expresions. We record that fact here. */
98 if (building_stmt_tree ())
99 STMT_IS_FULL_EXPR_P (last_tree
) = stmts_are_full_exprs_p
;
102 /* COND is the condition-expression for an if, while, etc.,
103 statement. Convert it to a boolean value, if appropriate. */
106 maybe_convert_cond (cond
)
109 /* Empty conditions remain empty. */
113 /* Wait until we instantiate templates before doing conversion. */
114 if (processing_template_decl
)
117 /* Do the conversion. */
118 cond
= convert_from_reference (cond
);
119 return condition_conversion (cond
);
122 /* Finish an expression-statement, whose EXPRESSION is as indicated. */
125 finish_expr_stmt (expr
)
128 if (expr
!= NULL_TREE
)
130 if (building_stmt_tree ())
132 /* Do default conversion if safe and possibly important,
133 in case within ({...}). */
134 if (!processing_template_decl
135 && !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 (!processing_template_decl
)
142 expr
= break_out_cleanups (expr
);
144 add_tree (build_min_nt (EXPR_STMT
, expr
));
148 emit_line_note (input_filename
, lineno
);
150 if (stmts_are_full_exprs_p
)
151 expand_start_target_temps ();
153 cplus_expand_expr_stmt (expr
);
155 if (stmts_are_full_exprs_p
)
156 expand_end_target_temps ();
162 /* This was an expression-statement, so we save the type of the
164 last_expr_type
= expr
? TREE_TYPE (expr
) : NULL_TREE
;
167 /* Begin an if-statement. Returns a newly created IF_STMT if
177 if (building_stmt_tree ())
179 r
= build_min_nt (IF_STMT
, NULL_TREE
, NULL_TREE
, NULL_TREE
);
188 /* Process the COND of an if-statement, which may be given by
192 finish_if_stmt_cond (cond
, if_stmt
)
196 cond
= maybe_convert_cond (cond
);
198 if (building_stmt_tree ())
199 FINISH_COND (cond
, if_stmt
, IF_COND (if_stmt
));
202 emit_line_note (input_filename
, lineno
);
203 expand_start_cond (cond
, 0);
207 /* Finish the then-clause of an if-statement, which may be given by
211 finish_then_clause (if_stmt
)
214 if (building_stmt_tree ())
216 RECHAIN_STMTS (if_stmt
, THEN_CLAUSE (if_stmt
));
217 SET_LAST_STMT (if_stmt
);
224 /* Begin the else-clause of an if-statement. */
229 if (!building_stmt_tree ())
230 expand_start_else ();
233 /* Finish the else-clause of an if-statement, which may be given by
237 finish_else_clause (if_stmt
)
240 if (building_stmt_tree ())
241 RECHAIN_STMTS (if_stmt
, ELSE_CLAUSE (if_stmt
));
244 /* Finsh an if-statement. */
249 if (!building_stmt_tree ())
256 /* Begin a while-statement. Returns a newly created WHILE_STMT if
264 if (building_stmt_tree ())
266 r
= build_min_nt (WHILE_STMT
, NULL_TREE
, NULL_TREE
);
272 emit_line_note (input_filename
, lineno
);
273 expand_start_loop (1);
282 /* Process the COND of an if-statement, which may be given by
286 finish_while_stmt_cond (cond
, while_stmt
)
290 cond
= maybe_convert_cond (cond
);
292 if (building_stmt_tree ())
293 FINISH_COND (cond
, while_stmt
, WHILE_COND (while_stmt
));
296 emit_line_note (input_filename
, lineno
);
297 expand_exit_loop_if_false (0, cond
);
300 /* If COND wasn't a declaration, clear out the
301 block we made for it and start a new one here so the
302 optimization in expand_end_loop will work. */
303 if (getdecls () == NULL_TREE
)
310 /* Finish a while-statement, which may be given by WHILE_STMT. */
313 finish_while_stmt (while_stmt
)
318 if (building_stmt_tree ())
319 RECHAIN_STMTS (while_stmt
, WHILE_BODY (while_stmt
));
325 /* Begin a do-statement. Returns a newly created DO_STMT if
331 if (building_stmt_tree ())
333 tree r
= build_min_nt (DO_STMT
, NULL_TREE
, NULL_TREE
);
340 emit_line_note (input_filename
, lineno
);
341 expand_start_loop_continue_elsewhere (1);
346 /* Finish the body of a do-statement, which may be given by DO_STMT. */
349 finish_do_body (do_stmt
)
352 if (building_stmt_tree ())
353 RECHAIN_STMTS (do_stmt
, DO_BODY (do_stmt
));
355 expand_loop_continue_here ();
358 /* Finish a do-statement, which may be given by DO_STMT, and whose
359 COND is as indicated. */
362 finish_do_stmt (cond
, do_stmt
)
366 cond
= maybe_convert_cond (cond
);
368 if (building_stmt_tree ())
369 DO_COND (do_stmt
) = cond
;
372 emit_line_note (input_filename
, lineno
);
373 expand_exit_loop_if_false (0, cond
);
380 /* Finish a return-statement. The EXPRESSION returned, if any, is as
384 finish_return_stmt (expr
)
387 if (doing_semantic_analysis_p () && !processing_template_decl
)
388 expr
= check_return_expr (expr
);
390 if (doing_semantic_analysis_p () && !processing_template_decl
)
392 if (DECL_CONSTRUCTOR_P (current_function_decl
) && ctor_label
)
394 /* Even returns without a value in a constructor must return
395 `this'. We accomplish this by sending all returns in a
396 constructor to the CTOR_LABEL; finish_function emits code to
397 return a value there. When we finally generate the real
398 return statement, CTOR_LABEL is no longer set, and we fall
399 through into the normal return-processing code below. */
400 finish_goto_stmt (ctor_label
);
403 else if (DECL_DESTRUCTOR_P (current_function_decl
))
405 /* Similarly, all destructors must run destructors for
406 base-classes before returning. So, all returns in a
407 destructor get sent to the DTOR_LABEL; finsh_function emits
408 code to return a value there. */
409 finish_goto_stmt (dtor_label
);
414 if (building_stmt_tree ())
415 add_tree (build_min_nt (RETURN_STMT
, expr
));
418 emit_line_note (input_filename
, lineno
);
419 c_expand_return (expr
);
425 /* Begin a for-statement. Returns a new FOR_STMT if appropriate. */
432 if (building_stmt_tree ())
434 r
= build_min_nt (FOR_STMT
, NULL_TREE
, NULL_TREE
,
435 NULL_TREE
, NULL_TREE
);
441 if (flag_new_for_scope
> 0)
444 note_level_for_for ();
450 /* Finish the for-init-statement of a for-statement, which may be
451 given by FOR_STMT. */
454 finish_for_init_stmt (for_stmt
)
457 if (building_stmt_tree ())
459 if (last_tree
!= for_stmt
)
460 RECHAIN_STMTS (for_stmt
, FOR_INIT_STMT (for_stmt
));
465 emit_line_note (input_filename
, lineno
);
466 expand_start_loop_continue_elsewhere (1);
472 /* Finish the COND of a for-statement, which may be given by
476 finish_for_cond (cond
, for_stmt
)
480 cond
= maybe_convert_cond (cond
);
482 if (building_stmt_tree ())
483 FINISH_COND (cond
, for_stmt
, FOR_COND (for_stmt
));
486 emit_line_note (input_filename
, lineno
);
488 expand_exit_loop_if_false (0, cond
);
491 /* If the cond wasn't a declaration, clear out the
492 block we made for it and start a new one here so the
493 optimization in expand_end_loop will work. */
494 if (getdecls () == NULL_TREE
)
501 /* Finish the increment-EXPRESSION in a for-statement, which may be
502 given by FOR_STMT. */
505 finish_for_expr (expr
, for_stmt
)
509 if (building_stmt_tree ())
510 FOR_EXPR (for_stmt
) = expr
;
513 /* Finish the body of a for-statement, which may be given by
514 FOR_STMT. The increment-EXPR for the loop must be
518 finish_for_stmt (expr
, for_stmt
)
522 /* Pop the scope for the body of the loop. */
525 if (building_stmt_tree ())
526 RECHAIN_STMTS (for_stmt
, FOR_BODY (for_stmt
));
529 emit_line_note (input_filename
, lineno
);
530 expand_loop_continue_here ();
532 finish_expr_stmt (expr
);
536 if (flag_new_for_scope
> 0)
542 /* Finish a break-statement. */
547 emit_line_note (input_filename
, lineno
);
548 if (building_stmt_tree ())
549 add_tree (build_min_nt (BREAK_STMT
));
550 else if ( ! expand_exit_something ())
551 cp_error ("break statement not within loop or switch");
554 /* Finish a continue-statement. */
557 finish_continue_stmt ()
559 emit_line_note (input_filename
, lineno
);
560 if (building_stmt_tree ())
561 add_tree (build_min_nt (CONTINUE_STMT
));
562 else if (! expand_continue_loop (0))
563 cp_error ("continue statement not within a loop");
566 /* Begin a switch-statement. Returns a new SWITCH_STMT if
574 if (building_stmt_tree ())
576 r
= build_min_nt (SWITCH_STMT
, NULL_TREE
, NULL_TREE
);
587 /* Finish the cond of a switch-statement. */
590 finish_switch_cond (cond
, switch_stmt
)
594 if (building_stmt_tree ())
596 if (!processing_template_decl
)
598 /* Convert the condition to an integer or enumeration type. */
599 cond
= build_expr_type_conversion (WANT_INT
| WANT_ENUM
, cond
, 1);
600 if (cond
== NULL_TREE
)
602 error ("switch quantity not an integer");
603 cond
= error_mark_node
;
605 if (cond
!= error_mark_node
)
610 cond
= default_conversion (cond
);
611 type
= TREE_TYPE (cond
);
612 idx
= get_unwidened (cond
, 0);
613 /* We can't strip a conversion from a signed type to an unsigned,
614 because if we did, int_fits_type_p would do the wrong thing
615 when checking case values for being in range,
616 and it's too hard to do the right thing. */
617 if (TREE_UNSIGNED (TREE_TYPE (cond
))
618 == TREE_UNSIGNED (TREE_TYPE (idx
)))
621 cond
= fold (build1 (CLEANUP_POINT_EXPR
, type
, cond
));
624 FINISH_COND (cond
, switch_stmt
, SWITCH_COND (switch_stmt
));
626 else if (cond
!= error_mark_node
)
628 emit_line_note (input_filename
, lineno
);
629 c_expand_start_case (cond
);
632 /* The code is in error, but we don't want expand_end_case to
634 c_expand_start_case (boolean_false_node
);
639 /* Finish the body of a switch-statement, which may be given by
640 SWITCH_STMT. The COND to switch on is indicated. */
643 finish_switch_stmt (cond
, switch_stmt
)
647 if (building_stmt_tree ())
648 RECHAIN_STMTS (switch_stmt
, SWITCH_BODY (switch_stmt
));
650 expand_end_case (cond
);
656 /* Finish a case-label. */
659 finish_case_label (low_value
, high_value
)
663 if (building_stmt_tree ())
665 /* Add a representation for the case label to the statement
667 add_tree (build_min_nt (CASE_LABEL
, low_value
, high_value
));
668 /* And warn about crossing initializations, etc. */
669 if (!processing_template_decl
)
670 define_case_label ();
674 do_case (low_value
, high_value
);
677 /* Finish a goto-statement. */
680 finish_goto_stmt (destination
)
683 if (TREE_CODE (destination
) == IDENTIFIER_NODE
)
684 destination
= lookup_label (destination
);
686 /* We warn about unused labels with -Wunused. That means we have to
687 mark the used labels as used. */
688 if (TREE_CODE (destination
) == LABEL_DECL
)
689 TREE_USED (destination
) = 1;
691 if (building_stmt_tree ())
693 if (TREE_CODE (destination
) != LABEL_DECL
)
694 /* We don't inline calls to functions with computed gotos.
695 Those functions are typically up to some funny business,
696 and may be depending on the labels being at particular
697 addresses, or some such. */
698 DECL_UNINLINABLE (current_function_decl
) = 1;
700 add_tree (build_min_nt (GOTO_STMT
, destination
));
704 emit_line_note (input_filename
, lineno
);
706 if (TREE_CODE (destination
) == LABEL_DECL
)
708 label_rtx (destination
);
709 expand_goto (destination
);
712 expand_computed_goto (destination
);
716 /* Begin a try-block. Returns a newly-created TRY_BLOCK if
722 if (building_stmt_tree ())
724 tree r
= build_min_nt (TRY_BLOCK
, NULL_TREE
,
731 emit_line_note (input_filename
, lineno
);
732 expand_start_try_stmts ();
737 /* Likewise, for a function-try-block. */
740 begin_function_try_block ()
742 if (building_stmt_tree ())
744 tree r
= build_min_nt (TRY_BLOCK
, NULL_TREE
,
746 FN_TRY_BLOCK_P (r
) = 1;
752 if (! current_function_parms_stored
)
754 expand_start_early_try_stmts ();
759 /* Finish a try-block, which may be given by TRY_BLOCK. */
762 finish_try_block (try_block
)
765 if (building_stmt_tree ())
766 RECHAIN_STMTS (try_block
, TRY_STMTS (try_block
));
768 expand_start_all_catch ();
771 /* Finish the body of a cleanup try-block, which may be given by
775 finish_cleanup_try_block (try_block
)
778 if (building_stmt_tree ())
779 RECHAIN_STMTS (try_block
, TRY_STMTS (try_block
));
782 /* Finish an implicitly generated try-block, with a cleanup is given
786 finish_cleanup (cleanup
, try_block
)
790 if (building_stmt_tree ())
792 TRY_HANDLERS (try_block
) = cleanup
;
793 CLEANUP_P (try_block
) = 1;
796 expand_eh_region_end (protect_with_terminate (cleanup
));
799 /* Likewise, for a function-try-block. */
802 finish_function_try_block (try_block
)
805 if (building_stmt_tree ())
807 if (TREE_CHAIN (try_block
)
808 && TREE_CODE (TREE_CHAIN (try_block
)) == CTOR_INITIALIZER
)
810 /* Chain the compound statement after the CTOR_INITIALIZER. */
811 TREE_CHAIN (TREE_CHAIN (try_block
)) = last_tree
;
812 /* And make the CTOR_INITIALIZER the body of the try-block. */
813 RECHAIN_STMTS (try_block
, TRY_STMTS (try_block
));
816 RECHAIN_STMTS (try_block
, TRY_STMTS (try_block
));
820 end_protect_partials ();
821 expand_start_all_catch ();
824 in_function_try_handler
= 1;
827 /* Finish a handler-sequence for a try-block, which may be given by
831 finish_handler_sequence (try_block
)
834 if (building_stmt_tree ())
835 RECHAIN_STMTS (try_block
, TRY_HANDLERS (try_block
));
837 expand_end_all_catch ();
840 /* Likewise, for a function-try-block. */
843 finish_function_handler_sequence (try_block
)
846 in_function_try_handler
= 0;
848 if (building_stmt_tree ())
849 RECHAIN_STMTS (try_block
, TRY_HANDLERS (try_block
));
851 expand_end_all_catch ();
854 /* Begin a handler. Returns a HANDLER if appropriate. */
861 if (building_stmt_tree ())
863 r
= build_min_nt (HANDLER
, NULL_TREE
, NULL_TREE
);
874 /* Finish the handler-parameters for a handler, which may be given by
875 HANDLER. DECL is the declaration for the catch parameter, or NULL
876 if this is a `catch (...)' clause. */
879 finish_handler_parms (decl
, handler
)
883 tree blocks
= NULL_TREE
;
885 if (processing_template_decl
)
889 decl
= pushdecl (decl
);
890 decl
= push_template_decl (decl
);
891 add_decl_stmt (decl
);
892 RECHAIN_STMTS (handler
, HANDLER_PARMS (handler
));
895 else if (building_stmt_tree ())
896 blocks
= expand_start_catch_block (decl
);
901 /* Note the beginning of a handler for TYPE. This function is called
902 at the point to which control should be transferred when an
903 appropriately-typed exception is thrown. */
906 begin_catch_block (type
)
909 if (building_stmt_tree ())
910 add_tree (build (START_CATCH_STMT
, type
));
912 start_catch_handler (type
);
915 /* Finish a handler, which may be given by HANDLER. The BLOCKs are
916 the return value from the matching call to finish_handler_parms. */
919 finish_handler (blocks
, handler
)
923 if (!processing_template_decl
)
925 if (building_stmt_tree ())
926 expand_end_catch_block (blocks
);
928 if (!building_stmt_tree ())
930 /* Fall to outside the try statement when done executing
931 handler and we fall off end of handler. This is jump
932 Lresume in the documentation. */
933 expand_goto (top_label_entry (&caught_return_label_stack
));
934 end_catch_handler ();
940 if (building_stmt_tree ())
941 RECHAIN_STMTS (handler
, HANDLER_BODY (handler
));
944 /* Begin a compound-statement. If HAS_NO_SCOPE is non-zero, the
945 compound-statement does not define a scope. Returns a new
946 COMPOUND_STMT if appropriate. */
949 begin_compound_stmt (has_no_scope
)
954 if (building_stmt_tree ())
956 r
= build_min_nt (COMPOUND_STMT
, NULL_TREE
);
959 COMPOUND_STMT_NO_SCOPE (r
) = 1;
964 last_expr_type
= NULL_TREE
;
969 /* Normally, we try hard to keep the BLOCK for a
970 statement-expression. But, if it's a statement-expression with
971 a scopeless block, there's nothing to keep, and we don't want
972 to accidentally keep a block *inside* the scopeless block. */
975 /* If this is the outermost block of the function, declare the
976 variables __FUNCTION__, __PRETTY_FUNCTION__, and so forth. */
978 && !current_function_name_declared
981 /* When we get callbacks from the middle-end, we need to know
982 we're in the midst of declaring these variables. */
983 current_function_name_declared
= 2;
984 /* Actually insert the declarations. */
985 declare_function_name ();
986 /* And now just remember that we're all done. */
987 current_function_name_declared
= 1;
994 /* Finish a compound-statement, which may be given by COMPOUND_STMT.
995 If HAS_NO_SCOPE is non-zero, the compound statement does not define
999 finish_compound_stmt (has_no_scope
, compound_stmt
)
1011 if (building_stmt_tree ())
1012 RECHAIN_STMTS (compound_stmt
, COMPOUND_BODY (compound_stmt
));
1014 /* When we call finish_stmt we will lose LAST_EXPR_TYPE. But, since
1015 the precise purpose of that variable is store the type of the
1016 last expression statement within the last compound statement, we
1017 preserve the value. */
1025 /* Finish an asm-statement, whose components are a CV_QUALIFIER, a
1026 STRING, some OUTPUT_OPERANDS, some INPUT_OPERANDS, and some
1030 finish_asm_stmt (cv_qualifier
, string
, output_operands
,
1031 input_operands
, clobbers
)
1034 tree output_operands
;
1035 tree input_operands
;
1038 if (TREE_CHAIN (string
))
1039 string
= combine_strings (string
);
1041 if (cv_qualifier
!= NULL_TREE
1042 && cv_qualifier
!= ridpointers
[(int) RID_VOLATILE
])
1044 cp_warning ("%s qualifier ignored on asm",
1045 IDENTIFIER_POINTER (cv_qualifier
));
1046 cv_qualifier
= NULL_TREE
;
1049 if (building_stmt_tree ())
1051 tree r
= build_min_nt (ASM_STMT
, cv_qualifier
, string
,
1052 output_operands
, input_operands
,
1058 emit_line_note (input_filename
, lineno
);
1059 if (output_operands
!= NULL_TREE
|| input_operands
!= NULL_TREE
1060 || clobbers
!= NULL_TREE
)
1064 for (t
= input_operands
; t
; t
= TREE_CHAIN (t
))
1065 TREE_VALUE (t
) = decay_conversion (TREE_VALUE (t
));
1067 c_expand_asm_operands (string
, output_operands
,
1070 cv_qualifier
!= NULL_TREE
,
1071 input_filename
, lineno
);
1074 expand_asm (string
);
1080 /* Finish a label with the indicated NAME. */
1083 finish_label_stmt (name
)
1086 tree decl
= define_label (input_filename
, lineno
, name
);
1088 if (building_stmt_tree ())
1089 add_tree (build_min_nt (LABEL_STMT
, decl
));
1091 expand_label (decl
);
1094 /* Finish a series of declarations for local labels. G++ allows users
1095 to declare "local" labels, i.e., labels with scope. This extension
1096 is useful when writing code involving statement-expressions. */
1099 finish_label_decl (name
)
1102 tree decl
= declare_local_label (name
);
1103 if (building_stmt_tree ())
1104 add_decl_stmt (decl
);
1107 /* Create a declaration statement for the declaration given by the
1111 add_decl_stmt (decl
)
1116 /* We need the type to last until instantiation time. */
1117 decl_stmt
= build_min_nt (DECL_STMT
, decl
);
1118 add_tree (decl_stmt
);
1121 /* We're in a constructor, and have just constructed a a subobject of
1122 *THIS. CLEANUP is code to run if an exception is thrown before the
1123 end of the current function is reached. */
1126 finish_subobject (cleanup
)
1129 if (building_stmt_tree ())
1131 tree r
= build_min_nt (SUBOBJECT
, cleanup
);
1135 add_partial_entry (cleanup
);
1138 /* When DECL goes out of scope, make sure that CLEANUP is executed. */
1141 finish_decl_cleanup (decl
, cleanup
)
1145 if (building_stmt_tree ())
1146 add_tree (build_min_nt (CLEANUP_STMT
, decl
, cleanup
));
1148 || (DECL_SIZE (decl
) && TREE_TYPE (decl
) != error_mark_node
))
1149 expand_decl_cleanup (decl
, cleanup
);
1152 /* Bind a name and initialization to the return value of
1153 the current function. */
1156 finish_named_return_value (return_id
, init
)
1157 tree return_id
, init
;
1159 tree decl
= DECL_RESULT (current_function_decl
);
1162 /* Give this error as many times as there are occurrences,
1163 so that users can use Emacs compilation buffers to find
1164 and fix all such places. */
1165 pedwarn ("ANSI C++ does not permit named return values");
1167 if (return_id
!= NULL_TREE
)
1169 if (DECL_NAME (decl
) == NULL_TREE
)
1171 DECL_NAME (decl
) = return_id
;
1172 DECL_ASSEMBLER_NAME (decl
) = return_id
;
1176 cp_error ("return identifier `%D' already in place", return_id
);
1181 /* Can't let this happen for constructors. */
1182 if (DECL_CONSTRUCTOR_P (current_function_decl
))
1184 error ("can't redefine default return value for constructors");
1188 /* If we have a named return value, put that in our scope as well. */
1189 if (DECL_NAME (decl
) != NULL_TREE
)
1191 /* Let `cp_finish_decl' know that this initializer is ok. */
1192 DECL_INITIAL (decl
) = init
;
1193 if (doing_semantic_analysis_p ())
1196 if (building_stmt_tree ())
1197 add_tree (build_min_nt (RETURN_INIT
, return_id
, init
));
1200 cp_finish_decl (decl
, init
, NULL_TREE
, 0);
1201 store_return_init (decl
);
1206 /* Cache the value of this class's main virtual function table pointer
1207 in a register variable. This will save one indirection if a
1208 more than one virtual function call is made this function. */
1213 my_friendly_assert (doing_semantic_analysis_p (), 19990919);
1215 /* If we've already done this, there's no need to do it again. */
1219 if (DECL_CONSTRUCTOR_P (current_function_decl
))
1221 if (processing_template_decl
)
1222 add_tree (build_min_nt
1224 current_member_init_list
, current_base_init_list
));
1229 /* Mark the beginning of the constructor. */
1230 ctor_stmt
= build_min_nt (CTOR_STMT
);
1231 CTOR_BEGIN_P (ctor_stmt
) = 1;
1232 add_tree (ctor_stmt
);
1234 /* And actually initialize the base-classes and members. */
1235 finish_expr_stmt (emit_base_init (current_class_type
));
1238 else if (DECL_DESTRUCTOR_P (current_function_decl
)
1239 && !processing_template_decl
)
1241 tree binfo
= TYPE_BINFO (current_class_type
);
1246 /* If the dtor is empty, and we know there is not possible way we
1247 could use any vtable entries, before they are possibly set by
1248 a base class dtor, we don't have to setup the vtables, as we
1249 know that any base class dtoring will set up any vtables it
1250 needs. We avoid MI, because one base class dtor can do a
1251 virtual dispatch to an overridden function that would need to
1252 have a non-related vtable set up, we cannot avoid setting up
1253 vtables in that case. We could change this to see if there is
1255 if_stmt
= begin_if_stmt ();
1257 /* If it is not safe to avoid setting up the vtables, then
1258 someone will change the condition to be boolean_true_node.
1259 (Actually, for now, we do not have code to set the condition
1260 appropriately, so we just assume that we always need to
1261 initialize the vtables.) */
1262 finish_if_stmt_cond (boolean_true_node
, if_stmt
);
1263 current_vcalls_possible_p
= &IF_COND (if_stmt
);
1265 /* Don't declare __PRETTY_FUNCTION__ and friends here when we
1266 open the block for the if-body. */
1267 saved_cfnd
= current_function_name_declared
;
1268 current_function_name_declared
= 1;
1269 compound_stmt
= begin_compound_stmt (/*has_no_scope=*/0);
1270 current_function_name_declared
= saved_cfnd
;
1272 /* Make all virtual function table pointers in non-virtual base
1273 classes point to CURRENT_CLASS_TYPE's virtual function
1275 expand_direct_vtbls_init (binfo
, binfo
, 1, 0, current_class_ptr
);
1277 if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type
))
1278 expand_indirect_vtbls_init (binfo
, current_class_ref
,
1281 finish_compound_stmt (/*has_no_scope=*/0, compound_stmt
);
1282 finish_then_clause (if_stmt
);
1286 /* Always keep the BLOCK node associated with the outermost pair of
1287 curly braces of a function. These are needed for correct
1288 operation of dwarfout.c. */
1289 keep_next_level (1);
1291 /* The virtual function tables are set up now. */
1295 /* Add a scope-statement to the statement-tree. BEGIN_P indicates
1296 whether this statements opens or closes a scope. PARTIAL_P is true
1297 for a partial scope, i.e, the scope that begins after a label when
1298 an object that needs a cleanup is created. If BEGIN_P is nonzero,
1299 returns a new TREE_LIST representing the top of the SCOPE_STMT
1300 stack. The TREE_PURPOSE is the new SCOPE_STMT. If BEGIN_P is
1301 zero, returns a TREE_LIST whose TREE_VALUE is the new SCOPE_STMT,
1302 and whose TREE_PURPOSE is the matching SCOPE_STMT iwth
1303 SCOPE_BEGIN_P set. */
1306 add_scope_stmt (begin_p
, partial_p
)
1313 /* Build the statement. */
1314 ss
= build_min_nt (SCOPE_STMT
, NULL_TREE
);
1315 SCOPE_BEGIN_P (ss
) = begin_p
;
1316 SCOPE_PARTIAL_P (ss
) = partial_p
;
1318 /* Keep the scope stack up to date. */
1321 current_scope_stmt_stack
1322 = tree_cons (ss
, NULL_TREE
, current_scope_stmt_stack
);
1323 top
= current_scope_stmt_stack
;
1327 top
= current_scope_stmt_stack
;
1328 TREE_VALUE (top
) = ss
;
1329 current_scope_stmt_stack
= TREE_CHAIN (top
);
1332 /* Add the new statement to the statement-tree. */
1338 /* Begin a new scope. */
1343 if (!building_stmt_tree ())
1345 emit_line_note (input_filename
, lineno
);
1348 if (stmts_are_full_exprs_p
)
1351 if (!building_stmt_tree ()
1352 && !current_function
->x_whole_function_mode_p
)
1353 my_friendly_abort (19991129);
1355 if (building_stmt_tree () && !processing_template_decl
)
1356 add_scope_stmt (/*begin_p=*/1, /*partial_p=*/0);
1360 /* Finish a scope. */
1365 tree block
= NULL_TREE
;
1367 if (stmts_are_full_exprs_p
)
1371 if (building_stmt_tree () && !processing_template_decl
)
1372 scope_stmts
= add_scope_stmt (/*begin_p=*/0, /*partial_p=*/0);
1374 scope_stmts
= NULL_TREE
;
1376 block
= poplevel (kept_level_p (), 1, 0);
1377 if (block
&& !processing_template_decl
)
1379 SCOPE_STMT_BLOCK (TREE_PURPOSE (scope_stmts
)) = block
;
1380 SCOPE_STMT_BLOCK (TREE_VALUE (scope_stmts
)) = block
;
1387 /* Finish a parenthesized expression EXPR. */
1390 finish_parenthesized_expr (expr
)
1393 if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (TREE_CODE (expr
))))
1394 /* This inhibits warnings in truthvalue_conversion. */
1395 C_SET_EXP_ORIGINAL_CODE (expr
, ERROR_MARK
);
1400 /* Begin a statement-expression. The value returned must be passed to
1401 finish_stmt_expr. */
1406 /* If we're outside a function, we won't have a statement-tree to
1407 work with. But, if we see a statement-expression we need to
1409 if (!current_function
&& !last_tree
)
1410 begin_stmt_tree (&scope_chain
->x_saved_tree
);
1412 keep_next_level (1);
1413 /* If we're building a statement tree, then the upcoming compound
1414 statement will be chained onto the tree structure, starting at
1415 last_tree. We return last_tree so that we can later unhook the
1416 compound statement. */
1417 return building_stmt_tree () ? last_tree
: expand_start_stmt_expr();
1420 /* Finish a statement-expression. RTL_EXPR should be the value
1421 returned by the previous begin_stmt_expr; EXPR is the
1422 statement-expression. Returns an expression representing the
1423 statement-expression. */
1426 finish_stmt_expr (rtl_expr
)
1431 if (!building_stmt_tree ())
1432 rtl_expr
= expand_end_stmt_expr (rtl_expr
);
1434 if (building_stmt_tree ())
1436 /* If the last thing in the statement-expression was not an
1437 expression-statement, then it has type `void'. */
1438 if (!last_expr_type
)
1439 last_expr_type
= void_type_node
;
1440 result
= build_min (STMT_EXPR
, last_expr_type
, last_tree
);
1441 TREE_SIDE_EFFECTS (result
) = 1;
1443 /* Remove the compound statement from the tree structure; it is
1444 now saved in the STMT_EXPR. */
1445 SET_LAST_STMT (rtl_expr
);
1446 TREE_CHAIN (last_tree
) = NULL_TREE
;
1451 /* If we created a statement-tree for this statement-expression,
1453 if (!current_function
1454 && TREE_CHAIN (scope_chain
->x_saved_tree
) == NULL_TREE
)
1455 finish_stmt_tree (&scope_chain
->x_saved_tree
);
1460 /* Finish a call to FN with ARGS. Returns a representation of the
1464 finish_call_expr (fn
, args
, koenig
)
1473 if (TREE_CODE (fn
) == BIT_NOT_EXPR
)
1474 fn
= build_x_unary_op (BIT_NOT_EXPR
, TREE_OPERAND (fn
, 0));
1475 else if (TREE_CODE (fn
) != TEMPLATE_ID_EXPR
)
1476 fn
= do_identifier (fn
, 2, args
);
1478 result
= build_x_function_call (fn
, args
, current_class_ref
);
1480 if (TREE_CODE (result
) == CALL_EXPR
1481 && (! TREE_TYPE (result
)
1482 || TREE_CODE (TREE_TYPE (result
)) != VOID_TYPE
))
1483 result
= require_complete_type (result
);
1488 /* Finish a call to a postfix increment or decrement or EXPR. (Which
1489 is indicated by CODE, which should be POSTINCREMENT_EXPR or
1490 POSTDECREMENT_EXPR.) */
1493 finish_increment_expr (expr
, code
)
1495 enum tree_code code
;
1497 /* If we get an OFFSET_REF, turn it into what it really means (e.g.,
1498 a COMPONENT_REF). This way if we've got, say, a reference to a
1499 static member that's being operated on, we don't end up trying to
1500 find a member operator for the class it's in. */
1502 if (TREE_CODE (expr
) == OFFSET_REF
)
1503 expr
= resolve_offset_ref (expr
);
1504 return build_x_unary_op (code
, expr
);
1507 /* Finish a use of `this'. Returns an expression for `this'. */
1514 if (current_class_ptr
)
1516 #ifdef WARNING_ABOUT_CCD
1517 TREE_USED (current_class_ptr
) = 1;
1519 result
= current_class_ptr
;
1521 else if (current_function_decl
1522 && DECL_STATIC_FUNCTION_P (current_function_decl
))
1524 error ("`this' is unavailable for static member functions");
1525 result
= error_mark_node
;
1529 if (current_function_decl
)
1530 error ("invalid use of `this' in non-member function");
1532 error ("invalid use of `this' at top level");
1533 result
= error_mark_node
;
1539 /* Finish a member function call using OBJECT and ARGS as arguments to
1540 FN. Returns an expression for the call. */
1543 finish_object_call_expr (fn
, object
, args
)
1549 /* This is a future direction of this code, but because
1550 build_x_function_call cannot always undo what is done in
1551 build_component_ref entirely yet, we cannot do this. */
1553 tree real_fn
= build_component_ref (object
, fn
, NULL_TREE
, 1);
1554 return finish_call_expr (real_fn
, args
);
1556 if (DECL_DECLARES_TYPE_P (fn
))
1558 if (processing_template_decl
)
1559 /* This can happen on code like:
1562 template <class T> void f(T t) {
1566 We just grab the underlying IDENTIFIER. */
1567 fn
= DECL_NAME (fn
);
1570 cp_error ("calling type `%T' like a method", fn
);
1571 return error_mark_node
;
1575 return build_method_call (object
, fn
, args
, NULL_TREE
, LOOKUP_NORMAL
);
1579 /* Finish a qualified member function call using OBJECT and ARGS as
1580 arguments to FN. Returns an expressino for the call. */
1583 finish_qualified_object_call_expr (fn
, object
, args
)
1588 return build_scoped_method_call (object
, TREE_OPERAND (fn
, 0),
1589 TREE_OPERAND (fn
, 1), args
);
1592 /* Finish a pseudo-destructor call expression of OBJECT, with SCOPE
1593 being the scope, if any, of DESTRUCTOR. Returns an expression for
1597 finish_pseudo_destructor_call_expr (object
, scope
, destructor
)
1602 if (processing_template_decl
)
1603 return build_min_nt (PSEUDO_DTOR_EXPR
, object
, scope
, destructor
);
1605 if (scope
&& scope
!= destructor
)
1606 cp_error ("destructor specifier `%T::~%T()' must have matching names",
1609 if ((scope
== NULL_TREE
|| IDENTIFIER_GLOBAL_VALUE (destructor
))
1610 && (TREE_CODE (TREE_TYPE (object
)) !=
1611 TREE_CODE (TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (destructor
)))))
1612 cp_error ("`%E' is not of type `%T'", object
, destructor
);
1614 return cp_convert (void_type_node
, object
);
1617 /* Finish a call to a globally qualified member function FN using
1618 ARGS. Returns an expression for the call. */
1621 finish_qualified_call_expr (fn
, args
)
1625 if (processing_template_decl
)
1626 return build_min_nt (CALL_EXPR
, fn
, args
, NULL_TREE
);
1628 return build_member_call (TREE_OPERAND (fn
, 0),
1629 TREE_OPERAND (fn
, 1),
1633 /* Finish an expression taking the address of LABEL. Returns an
1634 expression for the address. */
1637 finish_label_address_expr (label
)
1642 label
= lookup_label (label
);
1643 if (label
== NULL_TREE
)
1644 result
= null_pointer_node
;
1647 TREE_USED (label
) = 1;
1648 result
= build1 (ADDR_EXPR
, ptr_type_node
, label
);
1649 TREE_CONSTANT (result
) = 1;
1650 /* This function cannot be inlined. All jumps to the addressed
1651 label should wind up at the same point. */
1652 DECL_UNINLINABLE (current_function_decl
) = 1;
1658 /* Finish an expression of the form CODE EXPR. */
1661 finish_unary_op_expr (code
, expr
)
1662 enum tree_code code
;
1665 tree result
= build_x_unary_op (code
, expr
);
1666 /* Inside a template, build_x_unary_op does not fold the
1667 expression. So check whether the result is folded before
1668 setting TREE_NEGATED_INT. */
1669 if (code
== NEGATE_EXPR
&& TREE_CODE (expr
) == INTEGER_CST
1670 && TREE_CODE (result
) == INTEGER_CST
1671 && !TREE_UNSIGNED (TREE_TYPE (result
))
1672 && INT_CST_LT (result
, integer_zero_node
))
1673 TREE_NEGATED_INT (result
) = 1;
1674 overflow_warning (result
);
1678 /* Finish an id-expression. */
1681 finish_id_expr (expr
)
1684 if (TREE_CODE (expr
) == IDENTIFIER_NODE
)
1685 expr
= do_identifier (expr
, 1, NULL_TREE
);
1690 /* Begin a function defniition declared with DECL_SPECS and
1691 DECLARATOR. Returns non-zero if the function-declaration is
1695 begin_function_definition (decl_specs
, declarator
)
1701 split_specs_attrs (decl_specs
, &specs
, &attrs
);
1702 if (!start_function (specs
, declarator
, attrs
, SF_DEFAULT
))
1705 reinit_parse_for_function ();
1706 /* The things we're about to see are not directly qualified by any
1707 template headers we've seen thus far. */
1708 reset_specialization ();
1713 /* Begin a constructor declarator of the form `SCOPE::NAME'. Returns
1717 begin_constructor_declarator (scope
, name
)
1721 tree result
= build_parse_node (SCOPE_REF
, scope
, name
);
1722 enter_scope_of (result
);
1726 /* Finish an init-declarator. Returns a DECL. */
1729 finish_declarator (declarator
, declspecs
, attributes
,
1730 prefix_attributes
, initialized
)
1734 tree prefix_attributes
;
1737 return start_decl (declarator
, declspecs
, initialized
, attributes
,
1741 /* Finish a translation unit. */
1744 finish_translation_unit ()
1746 /* In case there were missing closebraces,
1747 get us back to the global binding level. */
1749 while (current_namespace
!= global_namespace
)
1754 /* Finish a template type parameter, specified as AGGR IDENTIFIER.
1755 Returns the parameter. */
1758 finish_template_type_parm (aggr
, identifier
)
1762 if (aggr
!= class_type_node
)
1764 pedwarn ("template type parameters must use the keyword `class' or `typename'");
1765 aggr
= class_type_node
;
1768 return build_tree_list (aggr
, identifier
);
1771 /* Finish a template template parameter, specified as AGGR IDENTIFIER.
1772 Returns the parameter. */
1775 finish_template_template_parm (aggr
, identifier
)
1779 tree decl
= build_decl (TYPE_DECL
, identifier
, NULL_TREE
);
1780 tree tmpl
= build_lang_decl (TEMPLATE_DECL
, identifier
, NULL_TREE
);
1781 DECL_TEMPLATE_PARMS (tmpl
) = current_template_parms
;
1782 DECL_TEMPLATE_RESULT (tmpl
) = decl
;
1783 SET_DECL_ARTIFICIAL (decl
);
1784 end_template_decl ();
1786 return finish_template_type_parm (aggr
, tmpl
);
1789 /* Finish a parameter list, indicated by PARMS. If ELLIPSIS is
1790 non-zero, the parameter list was terminated by a `...'. */
1793 finish_parmlist (parms
, ellipsis
)
1798 chainon (parms
, void_list_node
);
1799 /* We mark the PARMS as a parmlist so that declarator processing can
1800 disambiguate certain constructs. */
1801 if (parms
!= NULL_TREE
)
1802 TREE_PARMLIST (parms
) = 1;
1807 /* Begin a class definition, as indicated by T. */
1810 begin_class_definition (t
)
1813 if (t
== error_mark_node
1814 || ! IS_AGGR_TYPE (t
))
1816 t
= make_lang_type (RECORD_TYPE
);
1817 pushtag (make_anon_name (), t
, 0);
1820 /* In a definition of a member class template, we will get here with an
1821 implicit typename, a TYPENAME_TYPE with a type. */
1822 if (TREE_CODE (t
) == TYPENAME_TYPE
)
1825 /* If we generated a partial instantiation of this type, but now
1826 we're seeing a real definition, we're actually looking at a
1827 partial specialization. Consider:
1829 template <class T, class U>
1835 template <class T, class U>
1838 typename X<Y<T, U> >::A a;
1841 template <class T, class U>
1846 We have to undo the effects of the previous partial
1848 if (PARTIAL_INSTANTIATION_P (t
))
1852 /* Unfortunately, when we're not in pedantic mode, we
1853 attempt to actually fill in some of the fields of the
1854 partial instantiation, in order to support the implicit
1855 typename extension. Clear those fields now, in
1856 preparation for the definition here. The fields cleared
1857 here must match those set in instantiate_class_template.
1858 Look for a comment mentioning begin_class_definition
1860 TYPE_BINFO_BASETYPES (t
) = NULL_TREE
;
1861 TYPE_FIELDS (t
) = NULL_TREE
;
1862 TYPE_METHODS (t
) = NULL_TREE
;
1863 CLASSTYPE_TAGS (t
) = NULL_TREE
;
1864 TYPE_SIZE (t
) = NULL_TREE
;
1867 /* This isn't a partial instantiation any more. */
1868 PARTIAL_INSTANTIATION_P (t
) = 0;
1870 /* If this type was already complete, and we see another definition,
1872 else if (TYPE_SIZE (t
))
1873 duplicate_tag_error (t
);
1875 /* Update the location of the decl. */
1876 DECL_SOURCE_FILE (TYPE_NAME (t
)) = input_filename
;
1877 DECL_SOURCE_LINE (TYPE_NAME (t
)) = lineno
;
1879 if (TYPE_BEING_DEFINED (t
))
1881 t
= make_lang_type (TREE_CODE (t
));
1882 pushtag (TYPE_IDENTIFIER (t
), t
, 0);
1884 maybe_process_partial_specialization (t
);
1886 TYPE_BEING_DEFINED (t
) = 1;
1887 /* Reset the interface data, at the earliest possible
1888 moment, as it might have been set via a class foo;
1891 tree name
= TYPE_IDENTIFIER (t
);
1893 if (! ANON_AGGRNAME_P (name
))
1895 CLASSTYPE_INTERFACE_ONLY (t
) = interface_only
;
1896 SET_CLASSTYPE_INTERFACE_UNKNOWN_X
1897 (t
, interface_unknown
);
1900 /* Only leave this bit clear if we know this
1901 class is part of an interface-only specification. */
1902 if (! CLASSTYPE_INTERFACE_KNOWN (t
)
1903 || ! CLASSTYPE_INTERFACE_ONLY (t
))
1904 CLASSTYPE_VTABLE_NEEDS_WRITING (t
) = 1;
1907 tmp
= TYPE_IDENTIFIER ($
<ttype
>0);
1908 if (tmp
&& IDENTIFIER_TEMPLATE (tmp
))
1909 overload_template_name (tmp
, 1);
1911 reset_specialization();
1913 /* Make a declaration for this class in its own scope. */
1914 build_self_reference ();
1919 /* Finish the member declaration given by DECL. */
1922 finish_member_declaration (decl
)
1925 if (decl
== error_mark_node
|| decl
== NULL_TREE
)
1928 if (decl
== void_type_node
)
1929 /* The COMPONENT was a friend, not a member, and so there's
1930 nothing for us to do. */
1933 /* We should see only one DECL at a time. */
1934 my_friendly_assert (TREE_CHAIN (decl
) == NULL_TREE
, 0);
1936 /* Set up access control for DECL. */
1938 = (current_access_specifier
== access_private_node
);
1939 TREE_PROTECTED (decl
)
1940 = (current_access_specifier
== access_protected_node
);
1941 if (TREE_CODE (decl
) == TEMPLATE_DECL
)
1943 TREE_PRIVATE (DECL_RESULT (decl
)) = TREE_PRIVATE (decl
);
1944 TREE_PROTECTED (DECL_RESULT (decl
)) = TREE_PROTECTED (decl
);
1947 /* Mark the DECL as a member of the current class. */
1948 if (TREE_CODE (decl
) == FUNCTION_DECL
1949 || DECL_FUNCTION_TEMPLATE_P (decl
))
1950 /* Historically, DECL_CONTEXT was not set for a FUNCTION_DECL in
1951 finish_struct. Presumably it is already set as the function is
1952 parsed. Perhaps DECL_CLASS_CONTEXT is already set, too? */
1953 DECL_CLASS_CONTEXT (decl
) = current_class_type
;
1955 DECL_CONTEXT (decl
) = current_class_type
;
1957 /* Put functions on the TYPE_METHODS list and everything else on the
1958 TYPE_FIELDS list. Note that these are built up in reverse order.
1959 We reverse them (to obtain declaration order) in finish_struct. */
1960 if (TREE_CODE (decl
) == FUNCTION_DECL
1961 || DECL_FUNCTION_TEMPLATE_P (decl
))
1963 /* We also need to add this function to the
1964 CLASSTYPE_METHOD_VEC. */
1965 add_method (current_class_type
, 0, decl
);
1967 TREE_CHAIN (decl
) = TYPE_METHODS (current_class_type
);
1968 TYPE_METHODS (current_class_type
) = decl
;
1972 /* All TYPE_DECLs go at the end of TYPE_FIELDS. Ordinary fields
1973 go at the beginning. The reason is that lookup_field_1
1974 searches the list in order, and we want a field name to
1975 override a type name so that the "struct stat hack" will
1976 work. In particular:
1978 struct S { enum E { }; int E } s;
1981 is legal. In addition, the FIELD_DECLs must be maintained in
1982 declaration order so that class layout works as expected.
1983 However, we don't need that order until class layout, so we
1984 save a little time by putting FIELD_DECLs on in reverse order
1985 here, and then reversing them in finish_struct_1. (We could
1986 also keep a pointer to the correct insertion points in the
1989 if (TREE_CODE (decl
) == TYPE_DECL
)
1990 TYPE_FIELDS (current_class_type
)
1991 = chainon (TYPE_FIELDS (current_class_type
), decl
);
1994 TREE_CHAIN (decl
) = TYPE_FIELDS (current_class_type
);
1995 TYPE_FIELDS (current_class_type
) = decl
;
1998 /* Enter the DECL into the scope of the class. */
1999 if (TREE_CODE (decl
) != USING_DECL
)
2000 pushdecl_class_level (decl
);
2004 /* Finish a class definition T with the indicate ATTRIBUTES. If SEMI,
2005 the definition is immediately followed by a semicolon. Returns the
2009 finish_class_definition (t
, attributes
, semi
, pop_scope_p
)
2015 /* finish_struct nukes this anyway; if finish_exception does too,
2018 note_got_semicolon (t
);
2020 /* If we got any attributes in class_head, xref_tag will stick them in
2021 TREE_TYPE of the type. Grab them now. */
2022 attributes
= chainon (TREE_TYPE (t
), attributes
);
2023 TREE_TYPE (t
) = NULL_TREE
;
2025 if (TREE_CODE (t
) == ENUMERAL_TYPE
)
2029 t
= finish_struct (t
, attributes
);
2031 note_got_semicolon (t
);
2035 check_for_missing_semicolon (t
);
2037 pop_scope (CP_DECL_CONTEXT (TYPE_MAIN_DECL (t
)));
2038 if (current_scope () == current_function_decl
)
2039 do_pending_defargs ();
2044 /* Finish processing the default argument expressions cached during
2045 the processing of a class definition. */
2048 begin_inline_definitions ()
2051 && current_scope () == current_function_decl
)
2052 do_pending_inlines ();
2055 /* Finish processing the inline function definitions cached during the
2056 processing of a class definition. */
2059 finish_inline_definitions ()
2061 if (current_class_type
== NULL_TREE
)
2062 clear_inline_text_obstack ();
2065 /* Finish processing the declaration of a member class template
2066 TYPES whose template parameters are given by PARMS. */
2069 finish_member_class_template (types
)
2074 /* If there are declared, but undefined, partial specializations
2075 mixed in with the typespecs they will not yet have passed through
2076 maybe_process_partial_specialization, so we do that here. */
2077 for (t
= types
; t
!= NULL_TREE
; t
= TREE_CHAIN (t
))
2078 if (IS_AGGR_TYPE_CODE (TREE_CODE (TREE_VALUE (t
))))
2079 maybe_process_partial_specialization (TREE_VALUE (t
));
2081 note_list_got_semicolon (types
);
2082 grok_x_components (types
);
2083 if (TYPE_CONTEXT (TREE_VALUE (types
)) != current_class_type
)
2084 /* The component was in fact a friend declaration. We avoid
2085 finish_member_template_decl performing certain checks by
2089 finish_member_template_decl (types
);
2091 /* As with other component type declarations, we do
2092 not store the new DECL on the list of
2097 /* Finish processsing a complete template declaration. The PARMS are
2098 the template parameters. */
2101 finish_template_decl (parms
)
2105 end_template_decl ();
2107 end_specialization ();
2110 /* Finish processing a a template-id (which names a type) of the form
2111 NAME < ARGS >. Return the TYPE_DECL for the type named by the
2112 template-id. If ENTERING_SCOPE is non-zero we are about to enter
2113 the scope of template-id indicated. */
2116 finish_template_type (name
, args
, entering_scope
)
2123 decl
= lookup_template_class (name
, args
,
2124 NULL_TREE
, NULL_TREE
, entering_scope
);
2125 if (decl
!= error_mark_node
)
2126 decl
= TYPE_STUB_DECL (decl
);
2131 /* SR is a SCOPE_REF node. Enter the scope of SR, whether it is a
2132 namespace scope or a class scope. */
2138 tree scope
= TREE_OPERAND (sr
, 0);
2140 if (TREE_CODE (scope
) == NAMESPACE_DECL
)
2142 push_decl_namespace (scope
);
2143 TREE_COMPLEXITY (sr
) = -1;
2145 else if (scope
!= current_class_type
)
2147 if (TREE_CODE (scope
) == TYPENAME_TYPE
)
2149 /* In a declarator for a template class member, the scope will
2150 get here as an implicit typename, a TYPENAME_TYPE with a type. */
2151 scope
= TREE_TYPE (scope
);
2152 TREE_OPERAND (sr
, 0) = scope
;
2154 push_nested_class (scope
, 3);
2155 TREE_COMPLEXITY (sr
) = current_class_depth
;
2159 /* Finish processing a BASE_CLASS with the indicated ACCESS_SPECIFIER.
2160 Return a TREE_LIST containing the ACCESS_SPECIFIER and the
2161 BASE_CLASS, or NULL_TREE if an error occurred. The
2162 ACCESSS_SPECIFIER is one of
2163 access_{default,public,protected_private}[_virtual]_node.*/
2166 finish_base_specifier (access_specifier
, base_class
)
2167 tree access_specifier
;
2173 if (base_class
== NULL_TREE
)
2175 error ("invalid base class");
2176 type
= error_mark_node
;
2179 type
= TREE_TYPE (base_class
);
2181 if (! is_aggr_type (type
, 1))
2184 result
= build_tree_list (access_specifier
, type
);
2189 /* Called when multiple declarators are processed. If that is not
2190 premitted in this context, an error is issued. */
2193 check_multiple_declarators ()
2197 In a template-declaration, explicit specialization, or explicit
2198 instantiation the init-declarator-list in the declaration shall
2199 contain at most one declarator.
2201 We don't just use PROCESSING_TEMPLATE_DECL for the first
2202 condition since that would disallow the perfectly legal code,
2203 like `template <class T> struct S { int i, j; };'. */
2204 tree scope
= current_scope ();
2206 if (scope
&& TREE_CODE (scope
) == FUNCTION_DECL
)
2207 /* It's OK to write `template <class T> void f() { int i, j;}'. */
2210 if (PROCESSING_REAL_TEMPLATE_DECL_P ()
2211 || processing_explicit_instantiation
2212 || processing_specialization
)
2213 cp_error ("multiple declarators in template declaration");
2217 finish_typeof (expr
)
2220 if (processing_template_decl
)
2224 t
= make_lang_type (TYPEOF_TYPE
);
2225 TYPE_FIELDS (t
) = expr
;
2230 return TREE_TYPE (expr
);
2233 /* Create an empty statement tree rooted at T. */
2239 /* We create a trivial EXPR_STMT so that last_tree is never NULL in
2240 what follows. We remove the extraneous statement in
2241 finish_stmt_tree. */
2242 *t
= build_nt (EXPR_STMT
, void_zero_node
);
2244 last_expr_type
= NULL_TREE
;
2247 /* Finish the statement tree rooted at T. */
2250 finish_stmt_tree (t
)
2255 /* Remove the fake extra statement added in begin_stmt_tree. */
2256 stmt
= TREE_CHAIN (*t
);
2258 SET_LAST_STMT (NULL_TREE
);
2260 if (current_function
)
2262 /* The line-number recorded in the outermost statement in a function
2263 is the line number of the end of the function. */
2264 STMT_LINENO (stmt
) = lineno
;
2265 STMT_LINENO_FOR_FN_P (stmt
) = 1;
2269 /* We're about to expand T, a statement. Set up appropriate context
2270 for the substitution. */
2276 if (!STMT_LINENO_FOR_FN_P (t
))
2277 lineno
= STMT_LINENO (t
);
2278 stmts_are_full_exprs_p
= STMT_IS_FULL_EXPR_P (t
);
2281 /* Some statements, like for-statements or if-statements, require a
2282 condition. This condition can be a declaration. If T is such a
2283 declaration it is processed, and an expression appropriate to use
2284 as the condition is returned. Otherwise, T itself is returned. */
2290 if (t
&& TREE_CODE (t
) == TREE_LIST
)
2292 expand_stmt (TREE_PURPOSE (t
));
2293 return TREE_VALUE (t
);
2299 /* Generate RTL for the statement T, and its substatements, and any
2300 other statements at its nesting level. */
2306 tree rval
= NULL_TREE
;
2308 while (t
&& t
!= error_mark_node
)
2310 int saved_stmts_are_full_exprs_p
;
2312 /* Assume we'll have nothing to return. */
2315 /* Set up context appropriately for handling this statement. */
2316 saved_stmts_are_full_exprs_p
= stmts_are_full_exprs_p
;
2319 switch (TREE_CODE (t
))
2322 finish_return_stmt (RETURN_EXPR (t
));
2326 finish_expr_stmt (EXPR_STMT_EXPR (t
));
2333 emit_line_note (input_filename
, lineno
);
2334 decl
= DECL_STMT_DECL (t
);
2335 /* If this is a declaration for an automatic local
2336 variable, initialize it. Note that we might also see a
2337 declaration for a namespace-scope object (declared with
2338 `extern'). We don't have to handle the initialization
2339 of those objects here; they can only be declarations,
2340 rather than definitions. */
2341 if (TREE_CODE (decl
) == VAR_DECL
2342 && !TREE_STATIC (decl
)
2343 && !DECL_EXTERNAL (decl
))
2345 /* Let the back-end know about this variable. */
2346 if (!ANON_AGGR_TYPE_P (TREE_TYPE (decl
)))
2347 emit_local_var (decl
);
2349 expand_anon_union_decl (decl
, NULL_TREE
,
2350 DECL_ANON_UNION_ELEMS (decl
));
2352 else if (TREE_CODE (decl
) == VAR_DECL
&& TREE_STATIC (decl
))
2353 make_rtl_for_local_static (decl
);
2358 finish_decl_cleanup (CLEANUP_DECL (t
), CLEANUP_EXPR (t
));
2361 case START_CATCH_STMT
:
2362 begin_catch_block (TREE_TYPE (t
));
2366 if (CTOR_BEGIN_P (t
))
2367 begin_protect_partials ();
2369 /* After this point, any exceptions will cause the
2370 destructor to be executed, so we no longer need to worry
2371 about destroying the various subobjects ourselves. */
2372 end_protect_partials ();
2380 expand_stmt (FOR_INIT_STMT (t
));
2381 finish_for_init_stmt (NULL_TREE
);
2382 finish_for_cond (expand_cond (FOR_COND (t
)), NULL_TREE
);
2384 finish_for_expr (tmp
, NULL_TREE
);
2385 expand_stmt (FOR_BODY (t
));
2386 finish_for_stmt (tmp
, NULL_TREE
);
2392 begin_while_stmt ();
2393 finish_while_stmt_cond (expand_cond (WHILE_COND (t
)), NULL_TREE
);
2394 expand_stmt (WHILE_BODY (t
));
2395 finish_while_stmt (NULL_TREE
);
2402 expand_stmt (DO_BODY (t
));
2403 finish_do_body (NULL_TREE
);
2404 finish_do_stmt (DO_COND (t
), NULL_TREE
);
2410 finish_if_stmt_cond (expand_cond (IF_COND (t
)), NULL_TREE
);
2411 if (THEN_CLAUSE (t
))
2413 expand_stmt (THEN_CLAUSE (t
));
2414 finish_then_clause (NULL_TREE
);
2416 if (ELSE_CLAUSE (t
))
2418 begin_else_clause ();
2419 expand_stmt (ELSE_CLAUSE (t
));
2420 finish_else_clause (NULL_TREE
);
2426 begin_compound_stmt (COMPOUND_STMT_NO_SCOPE (t
));
2427 expand_stmt (COMPOUND_BODY (t
));
2428 rval
= finish_compound_stmt (COMPOUND_STMT_NO_SCOPE (t
),
2433 finish_break_stmt ();
2437 finish_continue_stmt ();
2444 begin_switch_stmt ();
2445 cond
= expand_cond (SWITCH_COND (t
));
2446 finish_switch_cond (cond
, NULL_TREE
);
2447 expand_stmt (SWITCH_BODY (t
));
2448 finish_switch_stmt (cond
, NULL_TREE
);
2453 finish_case_label (CASE_LOW (t
), CASE_HIGH (t
));
2457 expand_label (LABEL_STMT_LABEL (t
));
2461 finish_goto_stmt (GOTO_DESTINATION (t
));
2465 finish_asm_stmt (ASM_CV_QUAL (t
), ASM_STRING (t
), ASM_OUTPUTS
2466 (t
), ASM_INPUTS (t
), ASM_CLOBBERS (t
));
2472 expand_eh_region_start ();
2473 expand_stmt (TRY_STMTS (t
));
2474 finish_cleanup_try_block (NULL_TREE
);
2475 finish_cleanup (TRY_HANDLERS (t
), NULL_TREE
);
2479 if (FN_TRY_BLOCK_P (t
))
2480 begin_function_try_block ();
2484 expand_stmt (TRY_STMTS (t
));
2486 if (FN_TRY_BLOCK_P (t
))
2488 finish_function_try_block (NULL_TREE
);
2489 expand_stmt (TRY_HANDLERS (t
));
2490 finish_function_handler_sequence (NULL_TREE
);
2494 finish_try_block (NULL_TREE
);
2495 expand_stmt (TRY_HANDLERS (t
));
2496 finish_handler_sequence (NULL_TREE
);
2503 expand_stmt (HANDLER_BODY (t
));
2504 finish_handler (NULL_TREE
, NULL_TREE
);
2508 finish_subobject (SUBOBJECT_CLEANUP (t
));
2512 if (!SCOPE_NO_CLEANUPS_P (t
))
2514 if (SCOPE_BEGIN_P (t
))
2515 expand_start_bindings (2 * SCOPE_NULLIFIED_P (t
));
2516 else if (SCOPE_END_P (t
))
2517 expand_end_bindings (NULL_TREE
, !SCOPE_NULLIFIED_P (t
),
2518 SCOPE_PARTIAL_P (t
));
2520 else if (!SCOPE_NULLIFIED_P (t
))
2523 ? NOTE_INSN_BLOCK_BEG
2524 : NOTE_INSN_BLOCK_END
));
2528 /* Clear this out so that finish_named_return_value can set it
2530 DECL_NAME (DECL_RESULT (current_function_decl
)) = NULL_TREE
;
2531 finish_named_return_value (TREE_OPERAND (t
, 0),
2532 TREE_OPERAND (t
, 1));
2536 my_friendly_abort (19990810);
2540 /* Restore saved state. */
2541 stmts_are_full_exprs_p
= saved_stmts_are_full_exprs_p
;
2543 /* Go on to the next statement in this scope. */
2550 /* Called from expand_body via walk_tree. Replace all AGGR_INIT_EXPRs
2551 will equivalent CALL_EXPRs. */
2554 simplify_aggr_init_exprs_r (tp
, walk_subtrees
, data
)
2556 int *walk_subtrees ATTRIBUTE_UNUSED
;
2557 void *data ATTRIBUTE_UNUSED
;
2559 tree aggr_init_expr
;
2566 int copy_from_buffer_p
;
2568 /* Only AGGR_INIT_EXPRs are interesting. */
2569 aggr_init_expr
= *tp
;
2570 if (TREE_CODE (aggr_init_expr
) != AGGR_INIT_EXPR
)
2573 /* Form an appropriate CALL_EXPR. */
2574 fn
= TREE_OPERAND (aggr_init_expr
, 0);
2575 args
= TREE_OPERAND (aggr_init_expr
, 1);
2576 slot
= TREE_OPERAND (aggr_init_expr
, 2);
2577 type
= TREE_TYPE (aggr_init_expr
);
2579 if (AGGR_INIT_VIA_CTOR_P (aggr_init_expr
))
2581 /* Replace the first argument with the address of the third
2582 argument to the AGGR_INIT_EXPR. */
2583 call_type
= build_pointer_type (type
);
2584 mark_addressable (slot
);
2585 args
= tree_cons (NULL_TREE
, build1 (ADDR_EXPR
, call_type
, slot
),
2588 call_expr
= build (CALL_EXPR
, call_type
, fn
, args
, NULL_TREE
);
2589 TREE_SIDE_EFFECTS (call_expr
) = 1;
2591 /* If we're using the non-reentrant PCC calling convention, then we
2592 need to copy the returned value out of the static buffer into the
2594 copy_from_buffer_p
= 0;
2595 #ifdef PCC_STATIC_STRUCT_RETURN
2596 if (!AGGR_INIT_VIA_CTOR_P (aggr_init_expr
) && aggregate_value_p (type
))
2600 flag_access_control
= 0;
2601 call_expr
= build_aggr_init (slot
, call_expr
, LOOKUP_ONLYCONVERTING
);
2602 flag_access_control
= old_ac
;
2603 copy_from_buffer_p
= 1;
2607 /* If this AGGR_INIT_EXPR indicates the value returned by a
2608 function, then we want to use the value of the initialized
2609 location as the result. */
2610 if (AGGR_INIT_VIA_CTOR_P (aggr_init_expr
) || copy_from_buffer_p
)
2612 call_expr
= build (COMPOUND_EXPR
, type
,
2614 TREE_SIDE_EFFECTS (call_expr
) = 1;
2617 /* Replace the AGGR_INIT_EXPR with the CALL_EXPR. */
2618 TREE_CHAIN (call_expr
) = TREE_CHAIN (aggr_init_expr
);
2621 /* Keep iterating. */
2625 /* Generate RTL for FN. */
2632 char *saved_input_filename
;
2634 /* When the parser calls us after finishing the body of a template
2635 function, we don't really want to expand the body. When we're
2636 processing an in-class definition of an inline function,
2637 PROCESSING_TEMPLATE_DECL will no longer be set here, so we have
2638 to look at the function itself. */
2639 if (processing_template_decl
2640 || (DECL_LANG_SPECIFIC (fn
)
2641 && DECL_TEMPLATE_INFO (fn
)
2642 && uses_template_parms (DECL_TI_ARGS (fn
))))
2644 /* Normally, collection only occurs in rest_of_compilation. So,
2645 if we don't collect here, we never collect junk generated
2646 during the processing of templates until we hit a
2647 non-template function. */
2652 /* Replace AGGR_INIT_EXPRs with appropriate CALL_EXPRs. */
2653 walk_tree (&DECL_SAVED_TREE (fn
), simplify_aggr_init_exprs_r
, NULL
);
2655 /* There's no reason to do any of the work here if we're only doing
2656 semantic analysis; this code just generates RTL. */
2657 if (flag_syntax_only
)
2660 /* If possible, avoid generating RTL for this function. Instead,
2661 just record it as an inline function, and wait until end-of-file
2662 to decide whether to write it out or not. */
2663 if (/* We have to generate RTL if we can't inline trees. */
2665 /* Or if it's not an inline function. */
2667 /* Or if we have to keep all inline functions anyhow. */
2668 && !flag_keep_inline_functions
2669 /* Or if we actually have a reference to the function. */
2670 && !DECL_NEEDED_P (fn
)
2671 /* Or if we're at the end-of-file, and this function is not
2673 && (!at_eof
|| DECL_COMDAT (fn
))
2674 /* Or if this is a nested function. */
2675 && !hack_decl_function_context (fn
))
2677 /* Give the function RTL now so that we can assign it to a
2678 function pointer, etc. */
2679 make_function_rtl (fn
);
2680 /* Set DECL_EXTERNAL so that assemble_external will be called as
2681 necessary. We'll clear it again in finish_file. */
2682 if (!DECL_EXTERNAL (fn
))
2684 DECL_NOT_REALLY_EXTERN (fn
) = 1;
2685 DECL_EXTERNAL (fn
) = 1;
2687 /* Remember this function. In finish_file we'll decide if
2688 we actually need to write this function out. */
2689 mark_inline_for_output (fn
);
2693 /* Optimize the body of the function before expanding it. */
2694 optimize_function (fn
);
2696 /* Save the current file name and line number. When we expand the
2697 body of the function, we'll set LINENO and INPUT_FILENAME so that
2698 error-mesages come out in the right places. */
2699 saved_lineno
= lineno
;
2700 saved_input_filename
= input_filename
;
2701 lineno
= DECL_SOURCE_LINE (fn
);
2702 input_filename
= DECL_SOURCE_FILE (fn
);
2704 start_function (NULL_TREE
, fn
, NULL_TREE
, SF_PRE_PARSED
| SF_EXPAND
);
2705 store_parm_decls ();
2707 /* We don't need to redeclare __FUNCTION__, __PRETTY_FUNCTION__, or
2708 any of the other magic variables we set up when starting a
2710 current_function_name_declared
= 1;
2712 /* Expand the body. */
2713 expand_stmt (DECL_SAVED_TREE (fn
));
2715 /* Statements should always be full-expressions at the outermost set
2716 of curly braces for a function. */
2717 my_friendly_assert (stmts_are_full_exprs_p
, 19990831);
2719 /* The outermost statement for a function contains the line number
2720 recorded when we finished processing the function. */
2721 lineno
= STMT_LINENO (DECL_SAVED_TREE (fn
));
2723 /* Generate code for the function. */
2724 finish_function (lineno
, 0);
2726 /* If possible, obliterate the body of the function so that it can
2727 be garbage collected. */
2728 if (flag_dump_translation_unit
)
2729 /* Keep the body; we're going to dump it. */
2731 else if (DECL_INLINE (fn
) && flag_inline_trees
)
2732 /* We might need the body of this function so that we can expand
2733 it inline somewhere else. */
2736 /* We don't need the body; blow it away. */
2737 DECL_SAVED_TREE (fn
) = NULL_TREE
;
2739 /* And restore the current source position. */
2740 lineno
= saved_lineno
;
2741 input_filename
= saved_input_filename
;