1 /* Perform the semantic phase of parsing, i.e., the process of
2 building tree structure, checking semantic consistency, and
3 building RTL. These routines are used both during actual parsing
4 and during the instantiation of template functions.
6 Copyright (C) 1998, 1999, 2000 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
40 /* There routines provide a modular interface to perform many parsing
41 operations. They may therefore be used during actual parsing, or
42 during template instantiation, which may be regarded as a
43 degenerate form of parsing. Since the current g++ parser is
44 lacking in several respects, and will be reimplemented, we are
45 attempting to move most code that is not directly related to
46 parsing into this file; that will make implementing the new parser
47 much easier since it will be able to make use of these routines. */
49 static tree expand_cond PARAMS ((tree));
50 static tree maybe_convert_cond PARAMS ((tree));
51 static tree simplify_aggr_init_exprs_r PARAMS ((tree *, int *, void *));
52 static void deferred_type_access_control PARAMS ((void));
54 /* Record the fact that STMT was the last statement added to the
57 #define SET_LAST_STMT(stmt) \
58 (current_stmt_tree->x_last_stmt = (stmt))
60 /* When parsing a template, LAST_TREE contains the last statement
61 parsed. These are chained together through the TREE_CHAIN field,
62 but often need to be re-organized since the parse is performed
63 bottom-up. This macro makes LAST_TREE the indicated SUBSTMT of
66 #define RECHAIN_STMTS(stmt, substmt) \
68 substmt = TREE_CHAIN (stmt); \
69 TREE_CHAIN (stmt) = NULL_TREE; \
70 SET_LAST_STMT (stmt); \
73 /* Finish processing the COND, the SUBSTMT condition for STMT. */
75 #define FINISH_COND(cond, stmt, substmt) \
77 if (last_tree != stmt) \
79 RECHAIN_STMTS (stmt, substmt); \
80 if (!processing_template_decl) \
82 cond = build_tree_list (substmt, cond); \
90 /* T is a statement. Add it to the statement-tree. */
96 /* Add T to the statement-tree. */
97 TREE_CHAIN (last_tree) = t;
100 /* When we expand a statement-tree, we must know whether or not the
101 statements are full-expresions. We record that fact here. */
102 if (building_stmt_tree ())
103 STMT_IS_FULL_EXPR_P (last_tree) = stmts_are_full_exprs_p;
106 /* COND is the condition-expression for an if, while, etc.,
107 statement. Convert it to a boolean value, if appropriate. */
110 maybe_convert_cond (cond)
113 /* Empty conditions remain empty. */
117 /* Wait until we instantiate templates before doing conversion. */
118 if (processing_template_decl)
121 /* Do the conversion. */
122 cond = convert_from_reference (cond);
123 return condition_conversion (cond);
126 /* Finish an expression-statement, whose EXPRESSION is as indicated. */
129 finish_expr_stmt (expr)
132 if (expr != NULL_TREE)
134 if (building_stmt_tree ())
136 /* Do default conversion if safe and possibly important,
137 in case within ({...}). */
138 if (!processing_template_decl
139 && !stmts_are_full_exprs_p
140 && ((TREE_CODE (TREE_TYPE (expr)) == ARRAY_TYPE
142 || TREE_CODE (TREE_TYPE (expr)) == FUNCTION_TYPE))
143 expr = default_conversion (expr);
145 if (stmts_are_full_exprs_p)
146 expr = convert_to_void (expr, "statement");
148 if (!processing_template_decl)
149 expr = break_out_cleanups (expr);
151 add_tree (build_min_nt (EXPR_STMT, expr));
155 emit_line_note (input_filename, lineno);
157 if (stmts_are_full_exprs_p)
158 expand_start_target_temps ();
160 cplus_expand_expr_stmt (expr);
162 if (stmts_are_full_exprs_p)
163 expand_end_target_temps ();
169 /* This was an expression-statement, so we save the type of the
171 last_expr_type = expr ? TREE_TYPE (expr) : NULL_TREE;
174 /* Begin an if-statement. Returns a newly created IF_STMT if
184 if (building_stmt_tree ())
186 r = build_min_nt (IF_STMT, NULL_TREE, NULL_TREE, NULL_TREE);
195 /* Process the COND of an if-statement, which may be given by
199 finish_if_stmt_cond (cond, if_stmt)
203 cond = maybe_convert_cond (cond);
205 if (building_stmt_tree ())
206 FINISH_COND (cond, if_stmt, IF_COND (if_stmt));
209 emit_line_note (input_filename, lineno);
210 expand_start_cond (cond, 0);
214 /* Finish the then-clause of an if-statement, which may be given by
218 finish_then_clause (if_stmt)
221 if (building_stmt_tree ())
223 RECHAIN_STMTS (if_stmt, THEN_CLAUSE (if_stmt));
224 SET_LAST_STMT (if_stmt);
231 /* Begin the else-clause of an if-statement. */
236 if (!building_stmt_tree ())
237 expand_start_else ();
240 /* Finish the else-clause of an if-statement, which may be given by
244 finish_else_clause (if_stmt)
247 if (building_stmt_tree ())
248 RECHAIN_STMTS (if_stmt, ELSE_CLAUSE (if_stmt));
251 /* Finsh an if-statement. */
256 if (!building_stmt_tree ())
263 /* Begin a while-statement. Returns a newly created WHILE_STMT if
271 if (building_stmt_tree ())
273 r = build_min_nt (WHILE_STMT, NULL_TREE, NULL_TREE);
279 emit_line_note (input_filename, lineno);
280 expand_start_loop (1);
289 /* Process the COND of a while-statement, which may be given by
293 finish_while_stmt_cond (cond, while_stmt)
297 cond = maybe_convert_cond (cond);
299 if (building_stmt_tree ())
300 FINISH_COND (cond, while_stmt, WHILE_COND (while_stmt));
303 emit_line_note (input_filename, lineno);
304 expand_exit_loop_if_false (0, cond);
307 /* If COND wasn't a declaration, clear out the
308 block we made for it and start a new one here so the
309 optimization in expand_end_loop will work. */
310 if (getdecls () == NULL_TREE)
317 /* Finish a while-statement, which may be given by WHILE_STMT. */
320 finish_while_stmt (while_stmt)
325 if (building_stmt_tree ())
326 RECHAIN_STMTS (while_stmt, WHILE_BODY (while_stmt));
332 /* Begin a do-statement. Returns a newly created DO_STMT if
338 if (building_stmt_tree ())
340 tree r = build_min_nt (DO_STMT, NULL_TREE, NULL_TREE);
347 emit_line_note (input_filename, lineno);
348 expand_start_loop_continue_elsewhere (1);
353 /* Finish the body of a do-statement, which may be given by DO_STMT. */
356 finish_do_body (do_stmt)
359 if (building_stmt_tree ())
360 RECHAIN_STMTS (do_stmt, DO_BODY (do_stmt));
362 expand_loop_continue_here ();
365 /* Finish a do-statement, which may be given by DO_STMT, and whose
366 COND is as indicated. */
369 finish_do_stmt (cond, do_stmt)
373 cond = maybe_convert_cond (cond);
375 if (building_stmt_tree ())
376 DO_COND (do_stmt) = cond;
379 emit_line_note (input_filename, lineno);
380 expand_exit_loop_if_false (0, cond);
387 /* Finish a return-statement. The EXPRESSION returned, if any, is as
391 finish_return_stmt (expr)
394 if (doing_semantic_analysis_p () && !processing_template_decl)
395 expr = check_return_expr (expr);
397 if (doing_semantic_analysis_p () && !processing_template_decl)
399 if (DECL_CONSTRUCTOR_P (current_function_decl) && ctor_label)
401 /* Even returns without a value in a constructor must return
402 `this'. We accomplish this by sending all returns in a
403 constructor to the CTOR_LABEL; finish_function emits code to
404 return a value there. When we finally generate the real
405 return statement, CTOR_LABEL is no longer set, and we fall
406 through into the normal return-processing code below. */
407 finish_goto_stmt (ctor_label);
410 else if (DECL_DESTRUCTOR_P (current_function_decl))
412 /* Similarly, all destructors must run destructors for
413 base-classes before returning. So, all returns in a
414 destructor get sent to the DTOR_LABEL; finsh_function emits
415 code to return a value there. */
416 finish_goto_stmt (dtor_label);
421 if (building_stmt_tree ())
422 add_tree (build_min_nt (RETURN_STMT, expr));
425 emit_line_note (input_filename, lineno);
426 c_expand_return (expr);
432 /* Begin a for-statement. Returns a new FOR_STMT if appropriate. */
439 if (building_stmt_tree ())
441 r = build_min_nt (FOR_STMT, NULL_TREE, NULL_TREE,
442 NULL_TREE, NULL_TREE);
448 if (flag_new_for_scope > 0)
451 note_level_for_for ();
457 /* Finish the for-init-statement of a for-statement, which may be
458 given by FOR_STMT. */
461 finish_for_init_stmt (for_stmt)
464 if (building_stmt_tree ())
466 if (last_tree != for_stmt)
467 RECHAIN_STMTS (for_stmt, FOR_INIT_STMT (for_stmt));
472 emit_line_note (input_filename, lineno);
473 expand_start_loop_continue_elsewhere (1);
479 /* Finish the COND of a for-statement, which may be given by
483 finish_for_cond (cond, for_stmt)
487 cond = maybe_convert_cond (cond);
489 if (building_stmt_tree ())
490 FINISH_COND (cond, for_stmt, FOR_COND (for_stmt));
493 emit_line_note (input_filename, lineno);
495 expand_exit_loop_if_false (0, cond);
498 /* If the cond wasn't a declaration, clear out the
499 block we made for it and start a new one here so the
500 optimization in expand_end_loop will work. */
501 if (getdecls () == NULL_TREE)
508 /* Finish the increment-EXPRESSION in a for-statement, which may be
509 given by FOR_STMT. */
512 finish_for_expr (expr, for_stmt)
516 if (building_stmt_tree ())
517 FOR_EXPR (for_stmt) = expr;
520 /* Finish the body of a for-statement, which may be given by
521 FOR_STMT. The increment-EXPR for the loop must be
525 finish_for_stmt (expr, for_stmt)
529 /* Pop the scope for the body of the loop. */
532 if (building_stmt_tree ())
533 RECHAIN_STMTS (for_stmt, FOR_BODY (for_stmt));
536 emit_line_note (input_filename, lineno);
537 expand_loop_continue_here ();
539 finish_expr_stmt (expr);
543 if (flag_new_for_scope > 0)
549 /* Finish a break-statement. */
554 emit_line_note (input_filename, lineno);
555 if (building_stmt_tree ())
556 add_tree (build_min_nt (BREAK_STMT));
557 else if ( ! expand_exit_something ())
558 cp_error ("break statement not within loop or switch");
561 /* Finish a continue-statement. */
564 finish_continue_stmt ()
566 emit_line_note (input_filename, lineno);
567 if (building_stmt_tree ())
568 add_tree (build_min_nt (CONTINUE_STMT));
569 else if (! expand_continue_loop (0))
570 cp_error ("continue statement not within a loop");
573 /* Begin a switch-statement. Returns a new SWITCH_STMT if
581 if (building_stmt_tree ())
583 r = build_min_nt (SWITCH_STMT, NULL_TREE, NULL_TREE);
594 /* Finish the cond of a switch-statement. */
597 finish_switch_cond (cond, switch_stmt)
601 if (building_stmt_tree ())
603 if (!processing_template_decl)
605 /* Convert the condition to an integer or enumeration type. */
606 cond = build_expr_type_conversion (WANT_INT | WANT_ENUM, cond, 1);
607 if (cond == NULL_TREE)
609 error ("switch quantity not an integer");
610 cond = error_mark_node;
612 if (cond != error_mark_node)
617 cond = default_conversion (cond);
618 type = TREE_TYPE (cond);
619 idx = get_unwidened (cond, 0);
620 /* We can't strip a conversion from a signed type to an unsigned,
621 because if we did, int_fits_type_p would do the wrong thing
622 when checking case values for being in range,
623 and it's too hard to do the right thing. */
624 if (TREE_UNSIGNED (TREE_TYPE (cond))
625 == TREE_UNSIGNED (TREE_TYPE (idx)))
628 cond = fold (build1 (CLEANUP_POINT_EXPR, type, cond));
631 FINISH_COND (cond, switch_stmt, SWITCH_COND (switch_stmt));
633 else if (cond != error_mark_node)
635 emit_line_note (input_filename, lineno);
636 c_expand_start_case (cond);
639 /* The code is in error, but we don't want expand_end_case to
641 c_expand_start_case (boolean_false_node);
646 /* Finish the body of a switch-statement, which may be given by
647 SWITCH_STMT. The COND to switch on is indicated. */
650 finish_switch_stmt (cond, switch_stmt)
654 if (building_stmt_tree ())
655 RECHAIN_STMTS (switch_stmt, SWITCH_BODY (switch_stmt));
657 expand_end_case (cond);
663 /* Finish a case-label. */
666 finish_case_label (low_value, high_value)
670 if (building_stmt_tree ())
672 /* Add a representation for the case label to the statement
674 add_tree (build_min_nt (CASE_LABEL, low_value, high_value));
675 /* And warn about crossing initializations, etc. */
676 if (!processing_template_decl)
677 define_case_label ();
681 do_case (low_value, high_value);
684 /* Finish a goto-statement. */
687 finish_goto_stmt (destination)
690 if (TREE_CODE (destination) == IDENTIFIER_NODE)
691 destination = lookup_label (destination);
693 /* We warn about unused labels with -Wunused. That means we have to
694 mark the used labels as used. */
695 if (TREE_CODE (destination) == LABEL_DECL)
696 TREE_USED (destination) = 1;
698 if (building_stmt_tree ())
700 if (TREE_CODE (destination) != LABEL_DECL)
701 /* We don't inline calls to functions with computed gotos.
702 Those functions are typically up to some funny business,
703 and may be depending on the labels being at particular
704 addresses, or some such. */
705 DECL_UNINLINABLE (current_function_decl) = 1;
707 check_goto (destination);
709 add_tree (build_min_nt (GOTO_STMT, destination));
713 emit_line_note (input_filename, lineno);
715 if (TREE_CODE (destination) == LABEL_DECL)
717 label_rtx (destination);
718 expand_goto (destination);
721 expand_computed_goto (destination);
725 /* Begin a try-block. Returns a newly-created TRY_BLOCK if
731 if (building_stmt_tree ())
733 tree r = build_min_nt (TRY_BLOCK, NULL_TREE,
740 emit_line_note (input_filename, lineno);
741 expand_start_try_stmts ();
746 /* Likewise, for a function-try-block. */
749 begin_function_try_block ()
751 if (building_stmt_tree ())
753 tree r = build_min_nt (TRY_BLOCK, NULL_TREE,
755 FN_TRY_BLOCK_P (r) = 1;
761 if (! current_function_parms_stored)
763 expand_start_early_try_stmts ();
768 /* Finish a try-block, which may be given by TRY_BLOCK. */
771 finish_try_block (try_block)
774 if (building_stmt_tree ())
775 RECHAIN_STMTS (try_block, TRY_STMTS (try_block));
777 expand_start_all_catch ();
780 /* Finish the body of a cleanup try-block, which may be given by
784 finish_cleanup_try_block (try_block)
787 if (building_stmt_tree ())
788 RECHAIN_STMTS (try_block, TRY_STMTS (try_block));
791 /* Finish an implicitly generated try-block, with a cleanup is given
795 finish_cleanup (cleanup, try_block)
799 if (building_stmt_tree ())
801 TRY_HANDLERS (try_block) = cleanup;
802 CLEANUP_P (try_block) = 1;
805 expand_eh_region_end (protect_with_terminate (cleanup));
808 /* Likewise, for a function-try-block. */
811 finish_function_try_block (try_block)
814 if (building_stmt_tree ())
816 if (TREE_CHAIN (try_block)
817 && TREE_CODE (TREE_CHAIN (try_block)) == CTOR_INITIALIZER)
819 /* Chain the compound statement after the CTOR_INITIALIZER. */
820 TREE_CHAIN (TREE_CHAIN (try_block)) = last_tree;
821 /* And make the CTOR_INITIALIZER the body of the try-block. */
822 RECHAIN_STMTS (try_block, TRY_STMTS (try_block));
825 RECHAIN_STMTS (try_block, TRY_STMTS (try_block));
829 end_protect_partials ();
830 expand_start_all_catch ();
833 in_function_try_handler = 1;
836 /* Finish a handler-sequence for a try-block, which may be given by
840 finish_handler_sequence (try_block)
843 if (building_stmt_tree ())
845 RECHAIN_STMTS (try_block, TRY_HANDLERS (try_block));
846 check_handlers (TRY_HANDLERS (try_block));
849 expand_end_all_catch ();
852 /* Likewise, for a function-try-block. */
855 finish_function_handler_sequence (try_block)
858 in_function_try_handler = 0;
860 if (building_stmt_tree ())
862 RECHAIN_STMTS (try_block, TRY_HANDLERS (try_block));
863 check_handlers (TRY_HANDLERS (try_block));
866 expand_end_all_catch ();
869 /* Begin a handler. Returns a HANDLER if appropriate. */
876 if (building_stmt_tree ())
878 r = build_min_nt (HANDLER, NULL_TREE, NULL_TREE);
889 /* Finish the handler-parameters for a handler, which may be given by
890 HANDLER. DECL is the declaration for the catch parameter, or NULL
891 if this is a `catch (...)' clause. */
894 finish_handler_parms (decl, handler)
898 tree blocks = NULL_TREE;
900 if (processing_template_decl)
904 decl = pushdecl (decl);
905 decl = push_template_decl (decl);
906 add_decl_stmt (decl);
907 RECHAIN_STMTS (handler, HANDLER_PARMS (handler));
910 else if (building_stmt_tree ())
911 blocks = expand_start_catch_block (decl);
914 TREE_TYPE (handler) = TREE_TYPE (decl);
919 /* Note the beginning of a handler for TYPE. This function is called
920 at the point to which control should be transferred when an
921 appropriately-typed exception is thrown. */
924 begin_catch_block (type)
927 if (building_stmt_tree ())
928 add_tree (build (START_CATCH_STMT, type));
930 start_catch_handler (type);
933 /* Finish a handler, which may be given by HANDLER. The BLOCKs are
934 the return value from the matching call to finish_handler_parms. */
937 finish_handler (blocks, handler)
941 if (!processing_template_decl)
943 if (building_stmt_tree ())
944 expand_end_catch_block (blocks);
946 if (!building_stmt_tree ())
948 /* Fall to outside the try statement when done executing
949 handler and we fall off end of handler. This is jump
950 Lresume in the documentation. */
951 expand_goto (top_label_entry (&caught_return_label_stack));
952 end_catch_handler ();
958 if (building_stmt_tree ())
959 RECHAIN_STMTS (handler, HANDLER_BODY (handler));
962 /* Begin a compound-statement. If HAS_NO_SCOPE is non-zero, the
963 compound-statement does not define a scope. Returns a new
964 COMPOUND_STMT if appropriate. */
967 begin_compound_stmt (has_no_scope)
973 if (building_stmt_tree ())
975 r = build_min_nt (COMPOUND_STMT, NULL_TREE);
976 /* Mark that this block is for a try so that we can yell at
977 people trying to jump in. */
978 if (last_tree && TREE_CODE (last_tree) == TRY_BLOCK)
982 COMPOUND_STMT_NO_SCOPE (r) = 1;
987 last_expr_type = NULL_TREE;
993 note_level_for_eh ();
996 /* Normally, we try hard to keep the BLOCK for a
997 statement-expression. But, if it's a statement-expression with
998 a scopeless block, there's nothing to keep, and we don't want
999 to accidentally keep a block *inside* the scopeless block. */
1000 keep_next_level (0);
1002 /* If this is the outermost block of the function, declare the
1003 variables __FUNCTION__, __PRETTY_FUNCTION__, and so forth. */
1005 && !current_function_name_declared
1008 current_function_name_declared = 1;
1009 declare_function_name ();
1016 /* Finish a compound-statement, which may be given by COMPOUND_STMT.
1017 If HAS_NO_SCOPE is non-zero, the compound statement does not define
1021 finish_compound_stmt (has_no_scope, compound_stmt)
1033 if (building_stmt_tree ())
1034 RECHAIN_STMTS (compound_stmt, COMPOUND_BODY (compound_stmt));
1036 /* When we call finish_stmt we will lose LAST_EXPR_TYPE. But, since
1037 the precise purpose of that variable is store the type of the
1038 last expression statement within the last compound statement, we
1039 preserve the value. */
1047 /* Finish an asm-statement, whose components are a CV_QUALIFIER, a
1048 STRING, some OUTPUT_OPERANDS, some INPUT_OPERANDS, and some
1052 finish_asm_stmt (cv_qualifier, string, output_operands,
1053 input_operands, clobbers)
1056 tree output_operands;
1057 tree input_operands;
1060 if (TREE_CHAIN (string))
1061 string = combine_strings (string);
1063 if (cv_qualifier != NULL_TREE
1064 && cv_qualifier != ridpointers[(int) RID_VOLATILE])
1066 cp_warning ("%s qualifier ignored on asm",
1067 IDENTIFIER_POINTER (cv_qualifier));
1068 cv_qualifier = NULL_TREE;
1071 if (building_stmt_tree ())
1073 tree r = build_min_nt (ASM_STMT, cv_qualifier, string,
1074 output_operands, input_operands,
1080 emit_line_note (input_filename, lineno);
1081 if (output_operands != NULL_TREE || input_operands != NULL_TREE
1082 || clobbers != NULL_TREE)
1086 for (t = input_operands; t; t = TREE_CHAIN (t))
1087 TREE_VALUE (t) = decay_conversion (TREE_VALUE (t));
1089 c_expand_asm_operands (string, output_operands,
1092 cv_qualifier != NULL_TREE,
1093 input_filename, lineno);
1096 expand_asm (string);
1102 /* Finish a label with the indicated NAME. */
1105 finish_label_stmt (name)
1108 tree decl = define_label (input_filename, lineno, name);
1110 if (building_stmt_tree ())
1111 add_tree (build_min_nt (LABEL_STMT, decl));
1113 expand_label (decl);
1116 /* Finish a series of declarations for local labels. G++ allows users
1117 to declare "local" labels, i.e., labels with scope. This extension
1118 is useful when writing code involving statement-expressions. */
1121 finish_label_decl (name)
1124 tree decl = declare_local_label (name);
1125 if (building_stmt_tree ())
1126 add_decl_stmt (decl);
1129 /* Create a declaration statement for the declaration given by the
1133 add_decl_stmt (decl)
1138 /* We need the type to last until instantiation time. */
1139 decl_stmt = build_min_nt (DECL_STMT, decl);
1140 add_tree (decl_stmt);
1143 /* We're in a constructor, and have just constructed a a subobject of
1144 *THIS. CLEANUP is code to run if an exception is thrown before the
1145 end of the current function is reached. */
1148 finish_subobject (cleanup)
1151 if (building_stmt_tree ())
1153 tree r = build_min_nt (SUBOBJECT, cleanup);
1157 add_partial_entry (cleanup);
1160 /* When DECL goes out of scope, make sure that CLEANUP is executed. */
1163 finish_decl_cleanup (decl, cleanup)
1167 if (building_stmt_tree ())
1168 add_tree (build_min_nt (CLEANUP_STMT, decl, cleanup));
1170 || (DECL_SIZE (decl) && TREE_TYPE (decl) != error_mark_node))
1171 expand_decl_cleanup (decl, cleanup);
1174 /* Bind a name and initialization to the return value of
1175 the current function. */
1178 finish_named_return_value (return_id, init)
1179 tree return_id, init;
1181 tree decl = DECL_RESULT (current_function_decl);
1184 /* Give this error as many times as there are occurrences,
1185 so that users can use Emacs compilation buffers to find
1186 and fix all such places. */
1187 pedwarn ("ISO C++ does not permit named return values");
1189 if (return_id != NULL_TREE)
1191 if (DECL_NAME (decl) == NULL_TREE)
1193 DECL_NAME (decl) = return_id;
1194 DECL_ASSEMBLER_NAME (decl) = return_id;
1198 cp_error ("return identifier `%D' already in place", return_id);
1203 /* Can't let this happen for constructors. */
1204 if (DECL_CONSTRUCTOR_P (current_function_decl))
1206 error ("can't redefine default return value for constructors");
1210 /* If we have a named return value, put that in our scope as well. */
1211 if (DECL_NAME (decl) != NULL_TREE)
1213 /* Let `cp_finish_decl' know that this initializer is ok. */
1214 DECL_INITIAL (decl) = init;
1215 if (doing_semantic_analysis_p ())
1218 if (building_stmt_tree ())
1219 add_tree (build_min_nt (RETURN_INIT, return_id, init));
1222 cp_finish_decl (decl, init, NULL_TREE, 0);
1223 store_return_init (decl);
1227 /* Don't use tree-inlining for functions with named return values.
1228 That doesn't work properly because we don't do any translation of
1229 the RETURN_INITs when they are copied. */
1230 DECL_UNINLINABLE (current_function_decl) = 1;
1233 /* Cache the value of this class's main virtual function table pointer
1234 in a register variable. This will save one indirection if a
1235 more than one virtual function call is made this function. */
1240 my_friendly_assert (doing_semantic_analysis_p (), 19990919);
1242 /* If we've already done this, there's no need to do it again. */
1246 if (DECL_CONSTRUCTOR_P (current_function_decl))
1248 if (processing_template_decl)
1249 add_tree (build_min_nt
1251 current_member_init_list, current_base_init_list));
1256 /* Mark the beginning of the constructor. */
1257 ctor_stmt = build_min_nt (CTOR_STMT);
1258 CTOR_BEGIN_P (ctor_stmt) = 1;
1259 add_tree (ctor_stmt);
1261 /* And actually initialize the base-classes and members. */
1265 else if (DECL_DESTRUCTOR_P (current_function_decl)
1266 && !processing_template_decl)
1272 /* If the dtor is empty, and we know there is not any possible
1273 way we could use any vtable entries, before they are possibly
1274 set by a base class dtor, we don't have to setup the vtables,
1275 as we know that any base class dtor will set up any vtables
1276 it needs. We avoid MI, because one base class dtor can do a
1277 virtual dispatch to an overridden function that would need to
1278 have a non-related vtable set up, we cannot avoid setting up
1279 vtables in that case. We could change this to see if there
1280 is just one vtable. */
1281 if_stmt = begin_if_stmt ();
1283 /* If it is not safe to avoid setting up the vtables, then
1284 someone will change the condition to be boolean_true_node.
1285 (Actually, for now, we do not have code to set the condition
1286 appropriately, so we just assume that we always need to
1287 initialize the vtables.) */
1288 finish_if_stmt_cond (boolean_true_node, if_stmt);
1289 current_vcalls_possible_p = &IF_COND (if_stmt);
1291 /* Don't declare __PRETTY_FUNCTION__ and friends here when we
1292 open the block for the if-body. */
1293 saved_cfnd = current_function_name_declared;
1294 current_function_name_declared = 1;
1295 compound_stmt = begin_compound_stmt (/*has_no_scope=*/0);
1296 current_function_name_declared = saved_cfnd;
1298 /* Make all virtual function table pointers in non-virtual base
1299 classes point to CURRENT_CLASS_TYPE's virtual function
1301 initialize_vtbl_ptrs (current_class_ptr);
1303 finish_compound_stmt (/*has_no_scope=*/0, compound_stmt);
1304 finish_then_clause (if_stmt);
1308 /* Always keep the BLOCK node associated with the outermost pair of
1309 curly braces of a function. These are needed for correct
1310 operation of dwarfout.c. */
1311 keep_next_level (1);
1313 /* The virtual function tables are set up now. */
1317 /* Add a scope-statement to the statement-tree. BEGIN_P indicates
1318 whether this statements opens or closes a scope. PARTIAL_P is true
1319 for a partial scope, i.e, the scope that begins after a label when
1320 an object that needs a cleanup is created. If BEGIN_P is nonzero,
1321 returns a new TREE_LIST representing the top of the SCOPE_STMT
1322 stack. The TREE_PURPOSE is the new SCOPE_STMT. If BEGIN_P is
1323 zero, returns a TREE_LIST whose TREE_VALUE is the new SCOPE_STMT,
1324 and whose TREE_PURPOSE is the matching SCOPE_STMT iwth
1325 SCOPE_BEGIN_P set. */
1328 add_scope_stmt (begin_p, partial_p)
1335 /* Build the statement. */
1336 ss = build_min_nt (SCOPE_STMT, NULL_TREE);
1337 SCOPE_BEGIN_P (ss) = begin_p;
1338 SCOPE_PARTIAL_P (ss) = partial_p;
1340 /* Keep the scope stack up to date. */
1343 current_scope_stmt_stack
1344 = tree_cons (ss, NULL_TREE, current_scope_stmt_stack);
1345 top = current_scope_stmt_stack;
1349 top = current_scope_stmt_stack;
1350 TREE_VALUE (top) = ss;
1351 current_scope_stmt_stack = TREE_CHAIN (top);
1354 /* Add the new statement to the statement-tree. */
1360 /* Begin a new scope. */
1365 if (!building_stmt_tree ())
1367 emit_line_note (input_filename, lineno);
1370 if (stmts_are_full_exprs_p)
1373 if (!building_stmt_tree ()
1374 && !cfun->x_whole_function_mode_p)
1375 my_friendly_abort (19991129);
1377 if (building_stmt_tree () && !processing_template_decl)
1378 add_scope_stmt (/*begin_p=*/1, /*partial_p=*/0);
1382 /* Finish a scope. */
1387 tree block = NULL_TREE;
1389 if (stmts_are_full_exprs_p)
1393 if (building_stmt_tree () && !processing_template_decl)
1394 scope_stmts = add_scope_stmt (/*begin_p=*/0, /*partial_p=*/0);
1396 scope_stmts = NULL_TREE;
1398 block = poplevel (kept_level_p (), 1, 0);
1399 if (block && !processing_template_decl)
1401 SCOPE_STMT_BLOCK (TREE_PURPOSE (scope_stmts)) = block;
1402 SCOPE_STMT_BLOCK (TREE_VALUE (scope_stmts)) = block;
1409 /* Finish a parenthesized expression EXPR. */
1412 finish_parenthesized_expr (expr)
1415 if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (TREE_CODE (expr))))
1416 /* This inhibits warnings in truthvalue_conversion. */
1417 C_SET_EXP_ORIGINAL_CODE (expr, ERROR_MARK);
1422 /* Begin a statement-expression. The value returned must be passed to
1423 finish_stmt_expr. */
1428 /* If we're outside a function, we won't have a statement-tree to
1429 work with. But, if we see a statement-expression we need to
1431 if (! cfun && !last_tree)
1432 begin_stmt_tree (&scope_chain->x_saved_tree);
1434 keep_next_level (1);
1435 /* If we're building a statement tree, then the upcoming compound
1436 statement will be chained onto the tree structure, starting at
1437 last_tree. We return last_tree so that we can later unhook the
1438 compound statement. */
1439 return building_stmt_tree () ? last_tree : expand_start_stmt_expr();
1442 /* Finish a statement-expression. RTL_EXPR should be the value
1443 returned by the previous begin_stmt_expr; EXPR is the
1444 statement-expression. Returns an expression representing the
1445 statement-expression. */
1448 finish_stmt_expr (rtl_expr)
1453 if (!building_stmt_tree ())
1454 rtl_expr = expand_end_stmt_expr (rtl_expr);
1456 if (building_stmt_tree ())
1458 /* If the last thing in the statement-expression was not an
1459 expression-statement, then it has type `void'. */
1460 if (!last_expr_type)
1461 last_expr_type = void_type_node;
1462 result = build_min (STMT_EXPR, last_expr_type, last_tree);
1463 TREE_SIDE_EFFECTS (result) = 1;
1465 /* Remove the compound statement from the tree structure; it is
1466 now saved in the STMT_EXPR. */
1467 SET_LAST_STMT (rtl_expr);
1468 TREE_CHAIN (last_tree) = NULL_TREE;
1473 /* If we created a statement-tree for this statement-expression,
1476 && TREE_CHAIN (scope_chain->x_saved_tree) == NULL_TREE)
1477 finish_stmt_tree (&scope_chain->x_saved_tree);
1482 /* Finish a call to FN with ARGS. Returns a representation of the
1486 finish_call_expr (fn, args, koenig)
1495 if (TREE_CODE (fn) == BIT_NOT_EXPR)
1496 fn = build_x_unary_op (BIT_NOT_EXPR, TREE_OPERAND (fn, 0));
1497 else if (TREE_CODE (fn) != TEMPLATE_ID_EXPR)
1498 fn = do_identifier (fn, 2, args);
1500 result = build_x_function_call (fn, args, current_class_ref);
1502 if (TREE_CODE (result) == CALL_EXPR
1503 && (! TREE_TYPE (result)
1504 || TREE_CODE (TREE_TYPE (result)) != VOID_TYPE))
1505 result = require_complete_type (result);
1510 /* Finish a call to a postfix increment or decrement or EXPR. (Which
1511 is indicated by CODE, which should be POSTINCREMENT_EXPR or
1512 POSTDECREMENT_EXPR.) */
1515 finish_increment_expr (expr, code)
1517 enum tree_code code;
1519 /* If we get an OFFSET_REF, turn it into what it really means (e.g.,
1520 a COMPONENT_REF). This way if we've got, say, a reference to a
1521 static member that's being operated on, we don't end up trying to
1522 find a member operator for the class it's in. */
1524 if (TREE_CODE (expr) == OFFSET_REF)
1525 expr = resolve_offset_ref (expr);
1526 return build_x_unary_op (code, expr);
1529 /* Finish a use of `this'. Returns an expression for `this'. */
1536 if (current_class_ptr)
1538 #ifdef WARNING_ABOUT_CCD
1539 TREE_USED (current_class_ptr) = 1;
1541 result = current_class_ptr;
1543 else if (current_function_decl
1544 && DECL_STATIC_FUNCTION_P (current_function_decl))
1546 error ("`this' is unavailable for static member functions");
1547 result = error_mark_node;
1551 if (current_function_decl)
1552 error ("invalid use of `this' in non-member function");
1554 error ("invalid use of `this' at top level");
1555 result = error_mark_node;
1561 /* Finish a member function call using OBJECT and ARGS as arguments to
1562 FN. Returns an expression for the call. */
1565 finish_object_call_expr (fn, object, args)
1571 /* This is a future direction of this code, but because
1572 build_x_function_call cannot always undo what is done in
1573 build_component_ref entirely yet, we cannot do this. */
1575 tree real_fn = build_component_ref (object, fn, NULL_TREE, 1);
1576 return finish_call_expr (real_fn, args);
1578 if (DECL_DECLARES_TYPE_P (fn))
1580 if (processing_template_decl)
1581 /* This can happen on code like:
1584 template <class T> void f(T t) {
1588 We just grab the underlying IDENTIFIER. */
1589 fn = DECL_NAME (fn);
1592 cp_error ("calling type `%T' like a method", fn);
1593 return error_mark_node;
1597 return build_method_call (object, fn, args, NULL_TREE, LOOKUP_NORMAL);
1601 /* Finish a qualified member function call using OBJECT and ARGS as
1602 arguments to FN. Returns an expressino for the call. */
1605 finish_qualified_object_call_expr (fn, object, args)
1610 return build_scoped_method_call (object, TREE_OPERAND (fn, 0),
1611 TREE_OPERAND (fn, 1), args);
1614 /* Finish a pseudo-destructor call expression of OBJECT, with SCOPE
1615 being the scope, if any, of DESTRUCTOR. Returns an expression for
1619 finish_pseudo_destructor_call_expr (object, scope, destructor)
1624 if (processing_template_decl)
1625 return build_min_nt (PSEUDO_DTOR_EXPR, object, scope, destructor);
1627 if (scope && scope != destructor)
1628 cp_error ("destructor specifier `%T::~%T()' must have matching names",
1631 if ((scope == NULL_TREE || IDENTIFIER_GLOBAL_VALUE (destructor))
1632 && (TREE_CODE (TREE_TYPE (object)) !=
1633 TREE_CODE (TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (destructor)))))
1634 cp_error ("`%E' is not of type `%T'", object, destructor);
1636 return cp_convert (void_type_node, object);
1639 /* Finish a call to a globally qualified member function FN using
1640 ARGS. Returns an expression for the call. */
1643 finish_qualified_call_expr (fn, args)
1647 if (processing_template_decl)
1648 return build_min_nt (CALL_EXPR, fn, args, NULL_TREE);
1650 return build_member_call (TREE_OPERAND (fn, 0),
1651 TREE_OPERAND (fn, 1),
1655 /* Finish an expression taking the address of LABEL. Returns an
1656 expression for the address. */
1659 finish_label_address_expr (label)
1664 label = lookup_label (label);
1665 if (label == NULL_TREE)
1666 result = null_pointer_node;
1669 TREE_USED (label) = 1;
1670 result = build1 (ADDR_EXPR, ptr_type_node, label);
1671 TREE_CONSTANT (result) = 1;
1672 /* This function cannot be inlined. All jumps to the addressed
1673 label should wind up at the same point. */
1674 DECL_UNINLINABLE (current_function_decl) = 1;
1680 /* Finish an expression of the form CODE EXPR. */
1683 finish_unary_op_expr (code, expr)
1684 enum tree_code code;
1687 tree result = build_x_unary_op (code, expr);
1688 /* Inside a template, build_x_unary_op does not fold the
1689 expression. So check whether the result is folded before
1690 setting TREE_NEGATED_INT. */
1691 if (code == NEGATE_EXPR && TREE_CODE (expr) == INTEGER_CST
1692 && TREE_CODE (result) == INTEGER_CST
1693 && !TREE_UNSIGNED (TREE_TYPE (result))
1694 && INT_CST_LT (result, integer_zero_node))
1695 TREE_NEGATED_INT (result) = 1;
1696 overflow_warning (result);
1700 /* Finish an id-expression. */
1703 finish_id_expr (expr)
1706 if (TREE_CODE (expr) == IDENTIFIER_NODE)
1707 expr = do_identifier (expr, 1, NULL_TREE);
1712 static tree current_type_lookups;
1714 /* Perform deferred access control for types used in the type of a
1718 deferred_type_access_control ()
1720 tree lookup = type_lookups;
1722 if (lookup == error_mark_node)
1725 for (; lookup; lookup = TREE_CHAIN (lookup))
1726 enforce_access (TREE_PURPOSE (lookup), TREE_VALUE (lookup));
1730 decl_type_access_control (decl)
1735 if (type_lookups == error_mark_node)
1738 save_fn = current_function_decl;
1740 if (decl && TREE_CODE (decl) == FUNCTION_DECL)
1741 current_function_decl = decl;
1743 deferred_type_access_control ();
1745 current_function_decl = save_fn;
1747 /* Now strip away the checks for the current declarator; they were
1748 added to type_lookups after typed_declspecs saved the copy that
1749 ended up in current_type_lookups. */
1750 type_lookups = current_type_lookups;
1754 save_type_access_control (lookups)
1757 current_type_lookups = lookups;
1760 /* Begin a function definition declared with DECL_SPECS and
1761 DECLARATOR. Returns non-zero if the function-declaration is
1765 begin_function_definition (decl_specs, declarator)
1772 split_specs_attrs (decl_specs, &specs, &attrs);
1773 if (!start_function (specs, declarator, attrs, SF_DEFAULT))
1776 deferred_type_access_control ();
1777 type_lookups = error_mark_node;
1779 reinit_parse_for_function ();
1780 /* The things we're about to see are not directly qualified by any
1781 template headers we've seen thus far. */
1782 reset_specialization ();
1787 /* Begin a constructor declarator of the form `SCOPE::NAME'. Returns
1791 begin_constructor_declarator (scope, name)
1795 tree result = build_parse_node (SCOPE_REF, scope, name);
1796 enter_scope_of (result);
1800 /* Finish an init-declarator. Returns a DECL. */
1803 finish_declarator (declarator, declspecs, attributes,
1804 prefix_attributes, initialized)
1808 tree prefix_attributes;
1811 return start_decl (declarator, declspecs, initialized, attributes,
1815 /* Finish a translation unit. */
1818 finish_translation_unit ()
1820 /* In case there were missing closebraces,
1821 get us back to the global binding level. */
1823 while (current_namespace != global_namespace)
1828 /* Finish a template type parameter, specified as AGGR IDENTIFIER.
1829 Returns the parameter. */
1832 finish_template_type_parm (aggr, identifier)
1836 if (aggr != class_type_node)
1838 pedwarn ("template type parameters must use the keyword `class' or `typename'");
1839 aggr = class_type_node;
1842 return build_tree_list (aggr, identifier);
1845 /* Finish a template template parameter, specified as AGGR IDENTIFIER.
1846 Returns the parameter. */
1849 finish_template_template_parm (aggr, identifier)
1853 tree decl = build_decl (TYPE_DECL, identifier, NULL_TREE);
1854 tree tmpl = build_lang_decl (TEMPLATE_DECL, identifier, NULL_TREE);
1855 DECL_TEMPLATE_PARMS (tmpl) = current_template_parms;
1856 DECL_TEMPLATE_RESULT (tmpl) = decl;
1857 SET_DECL_ARTIFICIAL (decl);
1858 end_template_decl ();
1860 return finish_template_type_parm (aggr, tmpl);
1863 /* Finish a parameter list, indicated by PARMS. If ELLIPSIS is
1864 non-zero, the parameter list was terminated by a `...'. */
1867 finish_parmlist (parms, ellipsis)
1872 chainon (parms, void_list_node);
1873 /* We mark the PARMS as a parmlist so that declarator processing can
1874 disambiguate certain constructs. */
1875 if (parms != NULL_TREE)
1876 TREE_PARMLIST (parms) = 1;
1881 /* Begin a class definition, as indicated by T. */
1884 begin_class_definition (t)
1887 if (t == error_mark_node
1888 || ! IS_AGGR_TYPE (t))
1890 t = make_aggr_type (RECORD_TYPE);
1891 pushtag (make_anon_name (), t, 0);
1894 /* In a definition of a member class template, we will get here with an
1895 implicit typename, a TYPENAME_TYPE with a type. */
1896 if (TREE_CODE (t) == TYPENAME_TYPE)
1899 /* If we generated a partial instantiation of this type, but now
1900 we're seeing a real definition, we're actually looking at a
1901 partial specialization. Consider:
1903 template <class T, class U>
1909 template <class T, class U>
1912 typename X<Y<T, U> >::A a;
1915 template <class T, class U>
1920 We have to undo the effects of the previous partial
1922 if (PARTIAL_INSTANTIATION_P (t))
1926 /* Unfortunately, when we're not in pedantic mode, we
1927 attempt to actually fill in some of the fields of the
1928 partial instantiation, in order to support the implicit
1929 typename extension. Clear those fields now, in
1930 preparation for the definition here. The fields cleared
1931 here must match those set in instantiate_class_template.
1932 Look for a comment mentioning begin_class_definition
1934 TYPE_BINFO_BASETYPES (t) = NULL_TREE;
1935 TYPE_FIELDS (t) = NULL_TREE;
1936 TYPE_METHODS (t) = NULL_TREE;
1937 CLASSTYPE_TAGS (t) = NULL_TREE;
1938 TYPE_SIZE (t) = NULL_TREE;
1941 /* This isn't a partial instantiation any more. */
1942 PARTIAL_INSTANTIATION_P (t) = 0;
1944 /* If this type was already complete, and we see another definition,
1946 else if (COMPLETE_TYPE_P (t))
1947 duplicate_tag_error (t);
1949 /* Update the location of the decl. */
1950 DECL_SOURCE_FILE (TYPE_NAME (t)) = input_filename;
1951 DECL_SOURCE_LINE (TYPE_NAME (t)) = lineno;
1953 if (TYPE_BEING_DEFINED (t))
1955 t = make_aggr_type (TREE_CODE (t));
1956 pushtag (TYPE_IDENTIFIER (t), t, 0);
1958 maybe_process_partial_specialization (t);
1960 TYPE_BEING_DEFINED (t) = 1;
1961 TYPE_PACKED (t) = flag_pack_struct;
1962 /* Reset the interface data, at the earliest possible
1963 moment, as it might have been set via a class foo;
1966 tree name = TYPE_IDENTIFIER (t);
1968 if (! ANON_AGGRNAME_P (name))
1970 CLASSTYPE_INTERFACE_ONLY (t) = interface_only;
1971 SET_CLASSTYPE_INTERFACE_UNKNOWN_X
1972 (t, interface_unknown);
1975 /* Only leave this bit clear if we know this
1976 class is part of an interface-only specification. */
1977 if (! CLASSTYPE_INTERFACE_KNOWN (t)
1978 || ! CLASSTYPE_INTERFACE_ONLY (t))
1979 CLASSTYPE_VTABLE_NEEDS_WRITING (t) = 1;
1981 reset_specialization();
1983 /* Make a declaration for this class in its own scope. */
1984 build_self_reference ();
1989 /* Finish the member declaration given by DECL. */
1992 finish_member_declaration (decl)
1995 if (decl == error_mark_node || decl == NULL_TREE)
1998 if (decl == void_type_node)
1999 /* The COMPONENT was a friend, not a member, and so there's
2000 nothing for us to do. */
2003 /* We should see only one DECL at a time. */
2004 my_friendly_assert (TREE_CHAIN (decl) == NULL_TREE, 0);
2006 /* Set up access control for DECL. */
2008 = (current_access_specifier == access_private_node);
2009 TREE_PROTECTED (decl)
2010 = (current_access_specifier == access_protected_node);
2011 if (TREE_CODE (decl) == TEMPLATE_DECL)
2013 TREE_PRIVATE (DECL_TEMPLATE_RESULT (decl)) = TREE_PRIVATE (decl);
2014 TREE_PROTECTED (DECL_TEMPLATE_RESULT (decl)) = TREE_PROTECTED (decl);
2017 /* Mark the DECL as a member of the current class. */
2018 DECL_CONTEXT (decl) = current_class_type;
2022 A C language linkage is ignored for the names of class members
2023 and the member function type of class member functions. */
2024 if (DECL_LANG_SPECIFIC (decl) && DECL_LANGUAGE (decl) == lang_c)
2025 DECL_LANGUAGE (decl) = lang_cplusplus;
2027 /* Put functions on the TYPE_METHODS list and everything else on the
2028 TYPE_FIELDS list. Note that these are built up in reverse order.
2029 We reverse them (to obtain declaration order) in finish_struct. */
2030 if (TREE_CODE (decl) == FUNCTION_DECL
2031 || DECL_FUNCTION_TEMPLATE_P (decl))
2033 /* We also need to add this function to the
2034 CLASSTYPE_METHOD_VEC. */
2035 add_method (current_class_type, 0, decl);
2037 TREE_CHAIN (decl) = TYPE_METHODS (current_class_type);
2038 TYPE_METHODS (current_class_type) = decl;
2042 /* All TYPE_DECLs go at the end of TYPE_FIELDS. Ordinary fields
2043 go at the beginning. The reason is that lookup_field_1
2044 searches the list in order, and we want a field name to
2045 override a type name so that the "struct stat hack" will
2046 work. In particular:
2048 struct S { enum E { }; int E } s;
2051 is legal. In addition, the FIELD_DECLs must be maintained in
2052 declaration order so that class layout works as expected.
2053 However, we don't need that order until class layout, so we
2054 save a little time by putting FIELD_DECLs on in reverse order
2055 here, and then reversing them in finish_struct_1. (We could
2056 also keep a pointer to the correct insertion points in the
2059 if (TREE_CODE (decl) == TYPE_DECL)
2060 TYPE_FIELDS (current_class_type)
2061 = chainon (TYPE_FIELDS (current_class_type), decl);
2064 TREE_CHAIN (decl) = TYPE_FIELDS (current_class_type);
2065 TYPE_FIELDS (current_class_type) = decl;
2068 /* Enter the DECL into the scope of the class. */
2069 if (TREE_CODE (decl) != USING_DECL)
2070 pushdecl_class_level (decl);
2074 /* Finish a class definition T with the indicate ATTRIBUTES. If SEMI,
2075 the definition is immediately followed by a semicolon. Returns the
2079 finish_class_definition (t, attributes, semi, pop_scope_p)
2085 /* finish_struct nukes this anyway; if finish_exception does too,
2088 note_got_semicolon (t);
2090 /* If we got any attributes in class_head, xref_tag will stick them in
2091 TREE_TYPE of the type. Grab them now. */
2092 attributes = chainon (TREE_TYPE (t), attributes);
2093 TREE_TYPE (t) = NULL_TREE;
2095 if (TREE_CODE (t) == ENUMERAL_TYPE)
2099 t = finish_struct (t, attributes);
2101 note_got_semicolon (t);
2105 check_for_missing_semicolon (t);
2107 pop_scope (CP_DECL_CONTEXT (TYPE_MAIN_DECL (t)));
2108 if (current_scope () == current_function_decl)
2109 do_pending_defargs ();
2114 /* Finish processing the default argument expressions cached during
2115 the processing of a class definition. */
2118 begin_inline_definitions ()
2121 && current_scope () == current_function_decl)
2122 do_pending_inlines ();
2125 /* Finish processing the inline function definitions cached during the
2126 processing of a class definition. */
2129 finish_inline_definitions ()
2131 if (current_class_type == NULL_TREE)
2132 clear_inline_text_obstack ();
2135 /* Finish processing the declaration of a member class template
2136 TYPES whose template parameters are given by PARMS. */
2139 finish_member_class_template (types)
2144 /* If there are declared, but undefined, partial specializations
2145 mixed in with the typespecs they will not yet have passed through
2146 maybe_process_partial_specialization, so we do that here. */
2147 for (t = types; t != NULL_TREE; t = TREE_CHAIN (t))
2148 if (IS_AGGR_TYPE_CODE (TREE_CODE (TREE_VALUE (t))))
2149 maybe_process_partial_specialization (TREE_VALUE (t));
2151 note_list_got_semicolon (types);
2152 grok_x_components (types);
2153 if (TYPE_CONTEXT (TREE_VALUE (types)) != current_class_type)
2154 /* The component was in fact a friend declaration. We avoid
2155 finish_member_template_decl performing certain checks by
2159 finish_member_template_decl (types);
2161 /* As with other component type declarations, we do
2162 not store the new DECL on the list of
2167 /* Finish processsing a complete template declaration. The PARMS are
2168 the template parameters. */
2171 finish_template_decl (parms)
2175 end_template_decl ();
2177 end_specialization ();
2180 /* Finish processing a a template-id (which names a type) of the form
2181 NAME < ARGS >. Return the TYPE_DECL for the type named by the
2182 template-id. If ENTERING_SCOPE is non-zero we are about to enter
2183 the scope of template-id indicated. */
2186 finish_template_type (name, args, entering_scope)
2193 decl = lookup_template_class (name, args,
2194 NULL_TREE, NULL_TREE, entering_scope);
2195 if (decl != error_mark_node)
2196 decl = TYPE_STUB_DECL (decl);
2201 /* SR is a SCOPE_REF node. Enter the scope of SR, whether it is a
2202 namespace scope or a class scope. */
2208 tree scope = TREE_OPERAND (sr, 0);
2210 if (TREE_CODE (scope) == NAMESPACE_DECL)
2212 push_decl_namespace (scope);
2213 TREE_COMPLEXITY (sr) = -1;
2215 else if (scope != current_class_type)
2217 if (TREE_CODE (scope) == TYPENAME_TYPE)
2219 /* In a declarator for a template class member, the scope will
2220 get here as an implicit typename, a TYPENAME_TYPE with a type. */
2221 scope = TREE_TYPE (scope);
2222 TREE_OPERAND (sr, 0) = scope;
2224 push_nested_class (scope, 3);
2225 TREE_COMPLEXITY (sr) = current_class_depth;
2229 /* Finish processing a BASE_CLASS with the indicated ACCESS_SPECIFIER.
2230 Return a TREE_LIST containing the ACCESS_SPECIFIER and the
2231 BASE_CLASS, or NULL_TREE if an error occurred. The
2232 ACCESSS_SPECIFIER is one of
2233 access_{default,public,protected_private}[_virtual]_node.*/
2236 finish_base_specifier (access_specifier, base_class)
2237 tree access_specifier;
2243 if (base_class == NULL_TREE)
2245 error ("invalid base class");
2246 type = error_mark_node;
2249 type = TREE_TYPE (base_class);
2251 if (! is_aggr_type (type, 1))
2254 result = build_tree_list (access_specifier, type);
2259 /* Called when multiple declarators are processed. If that is not
2260 premitted in this context, an error is issued. */
2263 check_multiple_declarators ()
2267 In a template-declaration, explicit specialization, or explicit
2268 instantiation the init-declarator-list in the declaration shall
2269 contain at most one declarator.
2271 We don't just use PROCESSING_TEMPLATE_DECL for the first
2272 condition since that would disallow the perfectly legal code,
2273 like `template <class T> struct S { int i, j; };'. */
2274 tree scope = current_scope ();
2276 if (scope && TREE_CODE (scope) == FUNCTION_DECL)
2277 /* It's OK to write `template <class T> void f() { int i, j;}'. */
2280 if (PROCESSING_REAL_TEMPLATE_DECL_P ()
2281 || processing_explicit_instantiation
2282 || processing_specialization)
2283 cp_error ("multiple declarators in template declaration");
2287 finish_typeof (expr)
2290 if (processing_template_decl)
2294 t = make_aggr_type (TYPEOF_TYPE);
2295 TYPE_FIELDS (t) = expr;
2300 return TREE_TYPE (expr);
2303 /* Create an empty statement tree rooted at T. */
2309 /* We create a trivial EXPR_STMT so that last_tree is never NULL in
2310 what follows. We remove the extraneous statement in
2311 finish_stmt_tree. */
2312 *t = build_nt (EXPR_STMT, void_zero_node);
2314 last_expr_type = NULL_TREE;
2317 /* Finish the statement tree rooted at T. */
2320 finish_stmt_tree (t)
2325 /* Remove the fake extra statement added in begin_stmt_tree. */
2326 stmt = TREE_CHAIN (*t);
2328 SET_LAST_STMT (NULL_TREE);
2332 /* The line-number recorded in the outermost statement in a function
2333 is the line number of the end of the function. */
2334 STMT_LINENO (stmt) = lineno;
2335 STMT_LINENO_FOR_FN_P (stmt) = 1;
2339 /* We're about to expand T, a statement. Set up appropriate context
2340 for the substitution. */
2346 if (!STMT_LINENO_FOR_FN_P (t))
2347 lineno = STMT_LINENO (t);
2348 stmts_are_full_exprs_p = STMT_IS_FULL_EXPR_P (t);
2351 /* Some statements, like for-statements or if-statements, require a
2352 condition. This condition can be a declaration. If T is such a
2353 declaration it is processed, and an expression appropriate to use
2354 as the condition is returned. Otherwise, T itself is returned. */
2360 if (t && TREE_CODE (t) == TREE_LIST)
2362 expand_stmt (TREE_PURPOSE (t));
2363 return TREE_VALUE (t);
2369 /* Generate RTL for the statement T, and its substatements, and any
2370 other statements at its nesting level. */
2376 tree rval = NULL_TREE;
2378 while (t && t != error_mark_node)
2380 int saved_stmts_are_full_exprs_p;
2382 /* Assume we'll have nothing to return. */
2385 /* Set up context appropriately for handling this statement. */
2386 saved_stmts_are_full_exprs_p = stmts_are_full_exprs_p;
2389 switch (TREE_CODE (t))
2392 finish_return_stmt (RETURN_EXPR (t));
2396 finish_expr_stmt (EXPR_STMT_EXPR (t));
2403 emit_line_note (input_filename, lineno);
2404 decl = DECL_STMT_DECL (t);
2405 /* If this is a declaration for an automatic local
2406 variable, initialize it. Note that we might also see a
2407 declaration for a namespace-scope object (declared with
2408 `extern'). We don't have to handle the initialization
2409 of those objects here; they can only be declarations,
2410 rather than definitions. */
2411 if (TREE_CODE (decl) == VAR_DECL
2412 && !TREE_STATIC (decl)
2413 && !DECL_EXTERNAL (decl))
2415 /* Let the back-end know about this variable. */
2416 if (!ANON_AGGR_TYPE_P (TREE_TYPE (decl)))
2417 emit_local_var (decl);
2419 expand_anon_union_decl (decl, NULL_TREE,
2420 DECL_ANON_UNION_ELEMS (decl));
2422 else if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl))
2424 if (DECL_ARTIFICIAL (decl) && ! TREE_USED (decl))
2425 /* Do not emit unused decls. This is not just an
2426 optimization. We really do not want to emit
2427 __PRETTY_FUNCTION__ etc, if they're never used. */
2428 DECL_IGNORED_P (decl) = 1;
2430 make_rtl_for_local_static (decl);
2436 finish_decl_cleanup (CLEANUP_DECL (t), CLEANUP_EXPR (t));
2439 case START_CATCH_STMT:
2440 begin_catch_block (TREE_TYPE (t));
2444 if (CTOR_BEGIN_P (t))
2445 begin_protect_partials ();
2447 /* After this point, any exceptions will cause the
2448 destructor to be executed, so we no longer need to worry
2449 about destroying the various subobjects ourselves. */
2450 end_protect_partials ();
2458 expand_stmt (FOR_INIT_STMT (t));
2459 finish_for_init_stmt (NULL_TREE);
2460 finish_for_cond (expand_cond (FOR_COND (t)), NULL_TREE);
2462 finish_for_expr (tmp, NULL_TREE);
2463 expand_stmt (FOR_BODY (t));
2464 finish_for_stmt (tmp, NULL_TREE);
2470 begin_while_stmt ();
2471 finish_while_stmt_cond (expand_cond (WHILE_COND (t)), NULL_TREE);
2472 expand_stmt (WHILE_BODY (t));
2473 finish_while_stmt (NULL_TREE);
2480 expand_stmt (DO_BODY (t));
2481 finish_do_body (NULL_TREE);
2482 finish_do_stmt (DO_COND (t), NULL_TREE);
2488 finish_if_stmt_cond (expand_cond (IF_COND (t)), NULL_TREE);
2489 if (THEN_CLAUSE (t))
2491 expand_stmt (THEN_CLAUSE (t));
2492 finish_then_clause (NULL_TREE);
2494 if (ELSE_CLAUSE (t))
2496 begin_else_clause ();
2497 expand_stmt (ELSE_CLAUSE (t));
2498 finish_else_clause (NULL_TREE);
2504 begin_compound_stmt (COMPOUND_STMT_NO_SCOPE (t));
2505 expand_stmt (COMPOUND_BODY (t));
2506 rval = finish_compound_stmt (COMPOUND_STMT_NO_SCOPE (t),
2511 finish_break_stmt ();
2515 finish_continue_stmt ();
2522 begin_switch_stmt ();
2523 cond = expand_cond (SWITCH_COND (t));
2524 finish_switch_cond (cond, NULL_TREE);
2525 expand_stmt (SWITCH_BODY (t));
2526 finish_switch_stmt (cond, NULL_TREE);
2531 finish_case_label (CASE_LOW (t), CASE_HIGH (t));
2535 expand_label (LABEL_STMT_LABEL (t));
2539 finish_goto_stmt (GOTO_DESTINATION (t));
2543 finish_asm_stmt (ASM_CV_QUAL (t), ASM_STRING (t), ASM_OUTPUTS
2544 (t), ASM_INPUTS (t), ASM_CLOBBERS (t));
2550 expand_eh_region_start ();
2551 expand_stmt (TRY_STMTS (t));
2552 finish_cleanup_try_block (NULL_TREE);
2553 finish_cleanup (TRY_HANDLERS (t), NULL_TREE);
2557 if (FN_TRY_BLOCK_P (t))
2558 begin_function_try_block ();
2562 expand_stmt (TRY_STMTS (t));
2564 if (FN_TRY_BLOCK_P (t))
2566 finish_function_try_block (NULL_TREE);
2567 expand_stmt (TRY_HANDLERS (t));
2568 finish_function_handler_sequence (NULL_TREE);
2572 finish_try_block (NULL_TREE);
2573 expand_stmt (TRY_HANDLERS (t));
2574 finish_handler_sequence (NULL_TREE);
2581 expand_stmt (HANDLER_BODY (t));
2582 finish_handler (NULL_TREE, NULL_TREE);
2586 finish_subobject (SUBOBJECT_CLEANUP (t));
2590 if (!SCOPE_NO_CLEANUPS_P (t))
2592 if (SCOPE_BEGIN_P (t))
2593 expand_start_bindings_and_block (2 * SCOPE_NULLIFIED_P (t),
2594 SCOPE_STMT_BLOCK (t));
2595 else if (SCOPE_END_P (t))
2596 expand_end_bindings (NULL_TREE, !SCOPE_NULLIFIED_P (t), 0);
2598 else if (!SCOPE_NULLIFIED_P (t))
2600 rtx note = emit_note (NULL,
2602 ? NOTE_INSN_BLOCK_BEG
2603 : NOTE_INSN_BLOCK_END));
2604 NOTE_BLOCK (note) = SCOPE_STMT_BLOCK (t);
2610 /* Clear this out so that finish_named_return_value can set it
2612 DECL_NAME (DECL_RESULT (current_function_decl)) = NULL_TREE;
2613 finish_named_return_value (TREE_OPERAND (t, 0),
2614 TREE_OPERAND (t, 1));
2618 my_friendly_abort (19990810);
2622 /* Restore saved state. */
2623 stmts_are_full_exprs_p = saved_stmts_are_full_exprs_p;
2625 /* Go on to the next statement in this scope. */
2632 /* Called from expand_body via walk_tree. Replace all AGGR_INIT_EXPRs
2633 will equivalent CALL_EXPRs. */
2636 simplify_aggr_init_exprs_r (tp, walk_subtrees, data)
2638 int *walk_subtrees ATTRIBUTE_UNUSED;
2639 void *data ATTRIBUTE_UNUSED;
2641 tree aggr_init_expr;
2648 int copy_from_buffer_p;
2650 aggr_init_expr = *tp;
2651 /* We don't need to walk into types; there's nothing in a type that
2652 needs simplification. (And, furthermore, there are places we
2653 actively don't want to go. For example, we don't want to wander
2654 into the default arguments for a FUNCTION_DECL that appears in a
2656 if (TYPE_P (aggr_init_expr))
2661 /* Only AGGR_INIT_EXPRs are interesting. */
2662 else if (TREE_CODE (aggr_init_expr) != AGGR_INIT_EXPR)
2665 /* Form an appropriate CALL_EXPR. */
2666 fn = TREE_OPERAND (aggr_init_expr, 0);
2667 args = TREE_OPERAND (aggr_init_expr, 1);
2668 slot = TREE_OPERAND (aggr_init_expr, 2);
2669 type = TREE_TYPE (aggr_init_expr);
2671 if (AGGR_INIT_VIA_CTOR_P (aggr_init_expr))
2673 /* Replace the first argument with the address of the third
2674 argument to the AGGR_INIT_EXPR. */
2675 call_type = build_pointer_type (type);
2676 mark_addressable (slot);
2677 args = tree_cons (NULL_TREE, build1 (ADDR_EXPR, call_type, slot),
2680 call_expr = build (CALL_EXPR, call_type, fn, args, NULL_TREE);
2681 TREE_SIDE_EFFECTS (call_expr) = 1;
2683 /* If we're using the non-reentrant PCC calling convention, then we
2684 need to copy the returned value out of the static buffer into the
2686 copy_from_buffer_p = 0;
2687 #ifdef PCC_STATIC_STRUCT_RETURN
2688 if (!AGGR_INIT_VIA_CTOR_P (aggr_init_expr) && aggregate_value_p (type))
2692 flag_access_control = 0;
2693 call_expr = build_aggr_init (slot, call_expr, LOOKUP_ONLYCONVERTING);
2694 flag_access_control = old_ac;
2695 copy_from_buffer_p = 1;
2699 /* If this AGGR_INIT_EXPR indicates the value returned by a
2700 function, then we want to use the value of the initialized
2701 location as the result. */
2702 if (AGGR_INIT_VIA_CTOR_P (aggr_init_expr) || copy_from_buffer_p)
2704 call_expr = build (COMPOUND_EXPR, type,
2706 TREE_SIDE_EFFECTS (call_expr) = 1;
2709 /* Replace the AGGR_INIT_EXPR with the CALL_EXPR. */
2710 TREE_CHAIN (call_expr) = TREE_CHAIN (aggr_init_expr);
2713 /* Keep iterating. */
2717 /* Generate RTL for FN. */
2724 const char *saved_input_filename;
2726 /* When the parser calls us after finishing the body of a template
2727 function, we don't really want to expand the body. When we're
2728 processing an in-class definition of an inline function,
2729 PROCESSING_TEMPLATE_DECL will no longer be set here, so we have
2730 to look at the function itself. */
2731 if (processing_template_decl
2732 || (DECL_LANG_SPECIFIC (fn)
2733 && DECL_TEMPLATE_INFO (fn)
2734 && uses_template_parms (DECL_TI_ARGS (fn))))
2736 /* Normally, collection only occurs in rest_of_compilation. So,
2737 if we don't collect here, we never collect junk generated
2738 during the processing of templates until we hit a
2739 non-template function. */
2744 /* Replace AGGR_INIT_EXPRs with appropriate CALL_EXPRs. */
2745 walk_tree (&DECL_SAVED_TREE (fn), simplify_aggr_init_exprs_r, NULL);
2747 /* If this is a constructor or destructor body, we have to clone it
2748 under the new ABI. */
2749 if (maybe_clone_body (fn))
2751 /* We don't want to process FN again, so pretend we've written
2752 it out, even though we haven't. */
2753 TREE_ASM_WRITTEN (fn) = 1;
2757 /* There's no reason to do any of the work here if we're only doing
2758 semantic analysis; this code just generates RTL. */
2759 if (flag_syntax_only)
2762 /* If possible, avoid generating RTL for this function. Instead,
2763 just record it as an inline function, and wait until end-of-file
2764 to decide whether to write it out or not. */
2765 if (/* We have to generate RTL if it's not an inline function. */
2766 (DECL_INLINE (fn) || DECL_COMDAT (fn))
2767 /* Or if we have to keep all inline functions anyhow. */
2768 && !flag_keep_inline_functions
2769 /* Or if we actually have a reference to the function. */
2770 && !DECL_NEEDED_P (fn)
2771 /* Or if this is a nested function. */
2772 && !decl_function_context (fn))
2774 /* Give the function RTL now so that we can assign it to a
2775 function pointer, etc. */
2776 make_function_rtl (fn);
2777 /* Set DECL_EXTERNAL so that assemble_external will be called as
2778 necessary. We'll clear it again in finish_file. */
2779 if (!DECL_EXTERNAL (fn))
2781 DECL_NOT_REALLY_EXTERN (fn) = 1;
2782 DECL_EXTERNAL (fn) = 1;
2784 /* Remember this function. In finish_file we'll decide if
2785 we actually need to write this function out. */
2787 /* Let the back-end know that this funtion exists. */
2788 note_deferral_of_defined_inline_function (fn);
2792 timevar_push (TV_INTEGRATION);
2794 /* Optimize the body of the function before expanding it. */
2795 optimize_function (fn);
2797 timevar_pop (TV_INTEGRATION);
2798 timevar_push (TV_EXPAND);
2800 /* Save the current file name and line number. When we expand the
2801 body of the function, we'll set LINENO and INPUT_FILENAME so that
2802 error-mesages come out in the right places. */
2803 saved_lineno = lineno;
2804 saved_input_filename = input_filename;
2805 lineno = DECL_SOURCE_LINE (fn);
2806 input_filename = DECL_SOURCE_FILE (fn);
2808 start_function (NULL_TREE, fn, NULL_TREE, SF_PRE_PARSED | SF_EXPAND);
2809 store_parm_decls ();
2810 current_function_is_thunk = DECL_THUNK_P (fn);
2812 /* We don't need to redeclare __FUNCTION__, __PRETTY_FUNCTION__, or
2813 any of the other magic variables we set up when starting a
2815 current_function_name_declared = 1;
2817 /* Expand the body. */
2818 expand_stmt (DECL_SAVED_TREE (fn));
2820 /* Statements should always be full-expressions at the outermost set
2821 of curly braces for a function. */
2822 my_friendly_assert (stmts_are_full_exprs_p, 19990831);
2824 /* The outermost statement for a function contains the line number
2825 recorded when we finished processing the function. */
2826 lineno = STMT_LINENO (DECL_SAVED_TREE (fn));
2828 /* Generate code for the function. */
2829 finish_function (0);
2831 /* If possible, obliterate the body of the function so that it can
2832 be garbage collected. */
2833 if (flag_dump_translation_unit)
2834 /* Keep the body; we're going to dump it. */
2836 else if (DECL_INLINE (fn) && flag_inline_trees)
2837 /* We might need the body of this function so that we can expand
2838 it inline somewhere else. */
2841 /* We don't need the body; blow it away. */
2842 DECL_SAVED_TREE (fn) = NULL_TREE;
2844 /* And restore the current source position. */
2845 lineno = saved_lineno;
2846 input_filename = saved_input_filename;
2848 timevar_pop (TV_EXPAND);