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
39 /* There routines provide a modular interface to perform many parsing
40 operations. They may therefore be used during actual parsing, or
41 during template instantiation, which may be regarded as a
42 degenerate form of parsing. Since the current g++ parser is
43 lacking in several respects, and will be reimplemented, we are
44 attempting to move most code that is not directly related to
45 parsing into this file; that will make implementing the new parser
46 much easier since it will be able to make use of these routines. */
48 static tree expand_cond PARAMS ((tree));
49 static tree maybe_convert_cond PARAMS ((tree));
50 static tree simplify_aggr_init_exprs_r PARAMS ((tree *, int *, void *));
51 static void deferred_type_access_control PARAMS ((void));
53 /* Record the fact that STMT was the last statement added to the
56 #define SET_LAST_STMT(stmt) \
57 (current_stmt_tree->x_last_stmt = (stmt))
59 /* When parsing a template, LAST_TREE contains the last statement
60 parsed. These are chained together through the TREE_CHAIN field,
61 but often need to be re-organized since the parse is performed
62 bottom-up. This macro makes LAST_TREE the indicated SUBSTMT of
65 #define RECHAIN_STMTS(stmt, substmt) \
67 substmt = TREE_CHAIN (stmt); \
68 TREE_CHAIN (stmt) = NULL_TREE; \
69 SET_LAST_STMT (stmt); \
72 /* Finish processing the COND, the SUBSTMT condition for STMT. */
74 #define FINISH_COND(cond, stmt, substmt) \
76 if (last_tree != stmt) \
78 RECHAIN_STMTS (stmt, substmt); \
79 if (!processing_template_decl) \
81 cond = build_tree_list (substmt, cond); \
89 /* T is a statement. Add it to the statement-tree. */
95 /* Add T to the statement-tree. */
96 TREE_CHAIN (last_tree) = t;
99 /* When we expand a statement-tree, we must know whether or not the
100 statements are full-expresions. We record that fact here. */
101 if (building_stmt_tree ())
102 STMT_IS_FULL_EXPR_P (last_tree) = stmts_are_full_exprs_p;
105 /* COND is the condition-expression for an if, while, etc.,
106 statement. Convert it to a boolean value, if appropriate. */
109 maybe_convert_cond (cond)
112 /* Empty conditions remain empty. */
116 /* Wait until we instantiate templates before doing conversion. */
117 if (processing_template_decl)
120 /* Do the conversion. */
121 cond = convert_from_reference (cond);
122 return condition_conversion (cond);
125 /* Finish an expression-statement, whose EXPRESSION is as indicated. */
128 finish_expr_stmt (expr)
131 if (expr != NULL_TREE)
133 if (building_stmt_tree ())
135 /* Do default conversion if safe and possibly important,
136 in case within ({...}). */
137 if (!processing_template_decl
138 && !stmts_are_full_exprs_p
139 && ((TREE_CODE (TREE_TYPE (expr)) == ARRAY_TYPE
141 || TREE_CODE (TREE_TYPE (expr)) == FUNCTION_TYPE))
142 expr = default_conversion (expr);
144 if (stmts_are_full_exprs_p)
145 expr = convert_to_void (expr, "statement");
147 if (!processing_template_decl)
148 expr = break_out_cleanups (expr);
150 add_tree (build_min_nt (EXPR_STMT, expr));
154 emit_line_note (input_filename, lineno);
156 if (stmts_are_full_exprs_p)
157 expand_start_target_temps ();
159 cplus_expand_expr_stmt (expr);
161 if (stmts_are_full_exprs_p)
162 expand_end_target_temps ();
168 /* This was an expression-statement, so we save the type of the
170 last_expr_type = expr ? TREE_TYPE (expr) : NULL_TREE;
173 /* Begin an if-statement. Returns a newly created IF_STMT if
183 if (building_stmt_tree ())
185 r = build_min_nt (IF_STMT, NULL_TREE, NULL_TREE, NULL_TREE);
194 /* Process the COND of an if-statement, which may be given by
198 finish_if_stmt_cond (cond, if_stmt)
202 cond = maybe_convert_cond (cond);
204 if (building_stmt_tree ())
205 FINISH_COND (cond, if_stmt, IF_COND (if_stmt));
208 emit_line_note (input_filename, lineno);
209 expand_start_cond (cond, 0);
213 /* Finish the then-clause of an if-statement, which may be given by
217 finish_then_clause (if_stmt)
220 if (building_stmt_tree ())
222 RECHAIN_STMTS (if_stmt, THEN_CLAUSE (if_stmt));
223 SET_LAST_STMT (if_stmt);
230 /* Begin the else-clause of an if-statement. */
235 if (!building_stmt_tree ())
236 expand_start_else ();
239 /* Finish the else-clause of an if-statement, which may be given by
243 finish_else_clause (if_stmt)
246 if (building_stmt_tree ())
247 RECHAIN_STMTS (if_stmt, ELSE_CLAUSE (if_stmt));
250 /* Finsh an if-statement. */
255 if (!building_stmt_tree ())
262 /* Begin a while-statement. Returns a newly created WHILE_STMT if
270 if (building_stmt_tree ())
272 r = build_min_nt (WHILE_STMT, NULL_TREE, NULL_TREE);
278 emit_line_note (input_filename, lineno);
279 expand_start_loop (1);
288 /* Process the COND of a while-statement, which may be given by
292 finish_while_stmt_cond (cond, while_stmt)
296 cond = maybe_convert_cond (cond);
298 if (building_stmt_tree ())
299 FINISH_COND (cond, while_stmt, WHILE_COND (while_stmt));
302 emit_line_note (input_filename, lineno);
303 expand_exit_loop_if_false (0, cond);
306 /* If COND wasn't a declaration, clear out the
307 block we made for it and start a new one here so the
308 optimization in expand_end_loop will work. */
309 if (getdecls () == NULL_TREE)
316 /* Finish a while-statement, which may be given by WHILE_STMT. */
319 finish_while_stmt (while_stmt)
324 if (building_stmt_tree ())
325 RECHAIN_STMTS (while_stmt, WHILE_BODY (while_stmt));
331 /* Begin a do-statement. Returns a newly created DO_STMT if
337 if (building_stmt_tree ())
339 tree r = build_min_nt (DO_STMT, NULL_TREE, NULL_TREE);
346 emit_line_note (input_filename, lineno);
347 expand_start_loop_continue_elsewhere (1);
352 /* Finish the body of a do-statement, which may be given by DO_STMT. */
355 finish_do_body (do_stmt)
358 if (building_stmt_tree ())
359 RECHAIN_STMTS (do_stmt, DO_BODY (do_stmt));
361 expand_loop_continue_here ();
364 /* Finish a do-statement, which may be given by DO_STMT, and whose
365 COND is as indicated. */
368 finish_do_stmt (cond, do_stmt)
372 cond = maybe_convert_cond (cond);
374 if (building_stmt_tree ())
375 DO_COND (do_stmt) = cond;
378 emit_line_note (input_filename, lineno);
379 expand_exit_loop_if_false (0, cond);
386 /* Finish a return-statement. The EXPRESSION returned, if any, is as
390 finish_return_stmt (expr)
393 if (doing_semantic_analysis_p () && !processing_template_decl)
394 expr = check_return_expr (expr);
396 if (doing_semantic_analysis_p () && !processing_template_decl)
398 if (DECL_CONSTRUCTOR_P (current_function_decl) && ctor_label)
400 /* Even returns without a value in a constructor must return
401 `this'. We accomplish this by sending all returns in a
402 constructor to the CTOR_LABEL; finish_function emits code to
403 return a value there. When we finally generate the real
404 return statement, CTOR_LABEL is no longer set, and we fall
405 through into the normal return-processing code below. */
406 finish_goto_stmt (ctor_label);
409 else if (DECL_DESTRUCTOR_P (current_function_decl))
411 /* Similarly, all destructors must run destructors for
412 base-classes before returning. So, all returns in a
413 destructor get sent to the DTOR_LABEL; finsh_function emits
414 code to return a value there. */
415 finish_goto_stmt (dtor_label);
420 if (building_stmt_tree ())
421 add_tree (build_min_nt (RETURN_STMT, expr));
424 emit_line_note (input_filename, lineno);
425 c_expand_return (expr);
431 /* Begin a for-statement. Returns a new FOR_STMT if appropriate. */
438 if (building_stmt_tree ())
440 r = build_min_nt (FOR_STMT, NULL_TREE, NULL_TREE,
441 NULL_TREE, NULL_TREE);
447 if (flag_new_for_scope > 0)
450 note_level_for_for ();
456 /* Finish the for-init-statement of a for-statement, which may be
457 given by FOR_STMT. */
460 finish_for_init_stmt (for_stmt)
463 if (building_stmt_tree ())
465 if (last_tree != for_stmt)
466 RECHAIN_STMTS (for_stmt, FOR_INIT_STMT (for_stmt));
471 emit_line_note (input_filename, lineno);
472 expand_start_loop_continue_elsewhere (1);
478 /* Finish the COND of a for-statement, which may be given by
482 finish_for_cond (cond, for_stmt)
486 cond = maybe_convert_cond (cond);
488 if (building_stmt_tree ())
489 FINISH_COND (cond, for_stmt, FOR_COND (for_stmt));
492 emit_line_note (input_filename, lineno);
494 expand_exit_loop_if_false (0, cond);
497 /* If the cond wasn't a declaration, clear out the
498 block we made for it and start a new one here so the
499 optimization in expand_end_loop will work. */
500 if (getdecls () == NULL_TREE)
507 /* Finish the increment-EXPRESSION in a for-statement, which may be
508 given by FOR_STMT. */
511 finish_for_expr (expr, for_stmt)
515 if (building_stmt_tree ())
516 FOR_EXPR (for_stmt) = expr;
519 /* Finish the body of a for-statement, which may be given by
520 FOR_STMT. The increment-EXPR for the loop must be
524 finish_for_stmt (expr, for_stmt)
528 /* Pop the scope for the body of the loop. */
531 if (building_stmt_tree ())
532 RECHAIN_STMTS (for_stmt, FOR_BODY (for_stmt));
535 emit_line_note (input_filename, lineno);
536 expand_loop_continue_here ();
538 finish_expr_stmt (expr);
542 if (flag_new_for_scope > 0)
548 /* Finish a break-statement. */
553 emit_line_note (input_filename, lineno);
554 if (building_stmt_tree ())
555 add_tree (build_min_nt (BREAK_STMT));
556 else if ( ! expand_exit_something ())
557 cp_error ("break statement not within loop or switch");
560 /* Finish a continue-statement. */
563 finish_continue_stmt ()
565 emit_line_note (input_filename, lineno);
566 if (building_stmt_tree ())
567 add_tree (build_min_nt (CONTINUE_STMT));
568 else if (! expand_continue_loop (0))
569 cp_error ("continue statement not within a loop");
572 /* Begin a switch-statement. Returns a new SWITCH_STMT if
580 if (building_stmt_tree ())
582 r = build_min_nt (SWITCH_STMT, NULL_TREE, NULL_TREE);
593 /* Finish the cond of a switch-statement. */
596 finish_switch_cond (cond, switch_stmt)
600 if (building_stmt_tree ())
602 if (!processing_template_decl)
604 /* Convert the condition to an integer or enumeration type. */
605 cond = build_expr_type_conversion (WANT_INT | WANT_ENUM, cond, 1);
606 if (cond == NULL_TREE)
608 error ("switch quantity not an integer");
609 cond = error_mark_node;
611 if (cond != error_mark_node)
616 cond = default_conversion (cond);
617 type = TREE_TYPE (cond);
618 idx = get_unwidened (cond, 0);
619 /* We can't strip a conversion from a signed type to an unsigned,
620 because if we did, int_fits_type_p would do the wrong thing
621 when checking case values for being in range,
622 and it's too hard to do the right thing. */
623 if (TREE_UNSIGNED (TREE_TYPE (cond))
624 == TREE_UNSIGNED (TREE_TYPE (idx)))
627 cond = fold (build1 (CLEANUP_POINT_EXPR, type, cond));
630 FINISH_COND (cond, switch_stmt, SWITCH_COND (switch_stmt));
632 else if (cond != error_mark_node)
634 emit_line_note (input_filename, lineno);
635 c_expand_start_case (cond);
638 /* The code is in error, but we don't want expand_end_case to
640 c_expand_start_case (boolean_false_node);
645 /* Finish the body of a switch-statement, which may be given by
646 SWITCH_STMT. The COND to switch on is indicated. */
649 finish_switch_stmt (cond, switch_stmt)
653 if (building_stmt_tree ())
654 RECHAIN_STMTS (switch_stmt, SWITCH_BODY (switch_stmt));
656 expand_end_case (cond);
662 /* Finish a case-label. */
665 finish_case_label (low_value, high_value)
669 if (building_stmt_tree ())
671 /* Add a representation for the case label to the statement
673 add_tree (build_min_nt (CASE_LABEL, low_value, high_value));
674 /* And warn about crossing initializations, etc. */
675 if (!processing_template_decl)
676 define_case_label ();
680 do_case (low_value, high_value);
683 /* Finish a goto-statement. */
686 finish_goto_stmt (destination)
689 if (TREE_CODE (destination) == IDENTIFIER_NODE)
690 destination = lookup_label (destination);
692 /* We warn about unused labels with -Wunused. That means we have to
693 mark the used labels as used. */
694 if (TREE_CODE (destination) == LABEL_DECL)
695 TREE_USED (destination) = 1;
697 if (building_stmt_tree ())
699 if (TREE_CODE (destination) != LABEL_DECL)
700 /* We don't inline calls to functions with computed gotos.
701 Those functions are typically up to some funny business,
702 and may be depending on the labels being at particular
703 addresses, or some such. */
704 DECL_UNINLINABLE (current_function_decl) = 1;
706 add_tree (build_min_nt (GOTO_STMT, destination));
710 emit_line_note (input_filename, lineno);
712 if (TREE_CODE (destination) == LABEL_DECL)
714 label_rtx (destination);
715 expand_goto (destination);
718 expand_computed_goto (destination);
722 /* Begin a try-block. Returns a newly-created TRY_BLOCK if
728 if (building_stmt_tree ())
730 tree r = build_min_nt (TRY_BLOCK, NULL_TREE,
737 emit_line_note (input_filename, lineno);
738 expand_start_try_stmts ();
743 /* Likewise, for a function-try-block. */
746 begin_function_try_block ()
748 if (building_stmt_tree ())
750 tree r = build_min_nt (TRY_BLOCK, NULL_TREE,
752 FN_TRY_BLOCK_P (r) = 1;
758 if (! current_function_parms_stored)
760 expand_start_early_try_stmts ();
765 /* Finish a try-block, which may be given by TRY_BLOCK. */
768 finish_try_block (try_block)
771 if (building_stmt_tree ())
772 RECHAIN_STMTS (try_block, TRY_STMTS (try_block));
774 expand_start_all_catch ();
777 /* Finish the body of a cleanup try-block, which may be given by
781 finish_cleanup_try_block (try_block)
784 if (building_stmt_tree ())
785 RECHAIN_STMTS (try_block, TRY_STMTS (try_block));
788 /* Finish an implicitly generated try-block, with a cleanup is given
792 finish_cleanup (cleanup, try_block)
796 if (building_stmt_tree ())
798 TRY_HANDLERS (try_block) = cleanup;
799 CLEANUP_P (try_block) = 1;
802 expand_eh_region_end (protect_with_terminate (cleanup));
805 /* Likewise, for a function-try-block. */
808 finish_function_try_block (try_block)
811 if (building_stmt_tree ())
813 if (TREE_CHAIN (try_block)
814 && TREE_CODE (TREE_CHAIN (try_block)) == CTOR_INITIALIZER)
816 /* Chain the compound statement after the CTOR_INITIALIZER. */
817 TREE_CHAIN (TREE_CHAIN (try_block)) = last_tree;
818 /* And make the CTOR_INITIALIZER the body of the try-block. */
819 RECHAIN_STMTS (try_block, TRY_STMTS (try_block));
822 RECHAIN_STMTS (try_block, TRY_STMTS (try_block));
826 end_protect_partials ();
827 expand_start_all_catch ();
830 in_function_try_handler = 1;
833 /* Finish a handler-sequence for a try-block, which may be given by
837 finish_handler_sequence (try_block)
840 if (building_stmt_tree ())
841 RECHAIN_STMTS (try_block, TRY_HANDLERS (try_block));
843 expand_end_all_catch ();
846 /* Likewise, for a function-try-block. */
849 finish_function_handler_sequence (try_block)
852 in_function_try_handler = 0;
854 if (building_stmt_tree ())
855 RECHAIN_STMTS (try_block, TRY_HANDLERS (try_block));
857 expand_end_all_catch ();
860 /* Begin a handler. Returns a HANDLER if appropriate. */
867 if (building_stmt_tree ())
869 r = build_min_nt (HANDLER, NULL_TREE, NULL_TREE);
880 /* Finish the handler-parameters for a handler, which may be given by
881 HANDLER. DECL is the declaration for the catch parameter, or NULL
882 if this is a `catch (...)' clause. */
885 finish_handler_parms (decl, handler)
889 tree blocks = NULL_TREE;
891 if (processing_template_decl)
895 decl = pushdecl (decl);
896 decl = push_template_decl (decl);
897 add_decl_stmt (decl);
898 RECHAIN_STMTS (handler, HANDLER_PARMS (handler));
901 else if (building_stmt_tree ())
902 blocks = expand_start_catch_block (decl);
907 /* Note the beginning of a handler for TYPE. This function is called
908 at the point to which control should be transferred when an
909 appropriately-typed exception is thrown. */
912 begin_catch_block (type)
915 if (building_stmt_tree ())
916 add_tree (build (START_CATCH_STMT, type));
918 start_catch_handler (type);
921 /* Finish a handler, which may be given by HANDLER. The BLOCKs are
922 the return value from the matching call to finish_handler_parms. */
925 finish_handler (blocks, handler)
929 if (!processing_template_decl)
931 if (building_stmt_tree ())
932 expand_end_catch_block (blocks);
934 if (!building_stmt_tree ())
936 /* Fall to outside the try statement when done executing
937 handler and we fall off end of handler. This is jump
938 Lresume in the documentation. */
939 expand_goto (top_label_entry (&caught_return_label_stack));
940 end_catch_handler ();
946 if (building_stmt_tree ())
947 RECHAIN_STMTS (handler, HANDLER_BODY (handler));
950 /* Begin a compound-statement. If HAS_NO_SCOPE is non-zero, the
951 compound-statement does not define a scope. Returns a new
952 COMPOUND_STMT if appropriate. */
955 begin_compound_stmt (has_no_scope)
960 if (building_stmt_tree ())
962 r = build_min_nt (COMPOUND_STMT, NULL_TREE);
965 COMPOUND_STMT_NO_SCOPE (r) = 1;
970 last_expr_type = NULL_TREE;
975 /* Normally, we try hard to keep the BLOCK for a
976 statement-expression. But, if it's a statement-expression with
977 a scopeless block, there's nothing to keep, and we don't want
978 to accidentally keep a block *inside* the scopeless block. */
981 /* If this is the outermost block of the function, declare the
982 variables __FUNCTION__, __PRETTY_FUNCTION__, and so forth. */
984 && !current_function_name_declared
987 current_function_name_declared = 1;
988 declare_function_name ();
995 /* Finish a compound-statement, which may be given by COMPOUND_STMT.
996 If HAS_NO_SCOPE is non-zero, the compound statement does not define
1000 finish_compound_stmt (has_no_scope, compound_stmt)
1012 if (building_stmt_tree ())
1013 RECHAIN_STMTS (compound_stmt, COMPOUND_BODY (compound_stmt));
1015 /* When we call finish_stmt we will lose LAST_EXPR_TYPE. But, since
1016 the precise purpose of that variable is store the type of the
1017 last expression statement within the last compound statement, we
1018 preserve the value. */
1026 /* Finish an asm-statement, whose components are a CV_QUALIFIER, a
1027 STRING, some OUTPUT_OPERANDS, some INPUT_OPERANDS, and some
1031 finish_asm_stmt (cv_qualifier, string, output_operands,
1032 input_operands, clobbers)
1035 tree output_operands;
1036 tree input_operands;
1039 if (TREE_CHAIN (string))
1040 string = combine_strings (string);
1042 if (cv_qualifier != NULL_TREE
1043 && cv_qualifier != ridpointers[(int) RID_VOLATILE])
1045 cp_warning ("%s qualifier ignored on asm",
1046 IDENTIFIER_POINTER (cv_qualifier));
1047 cv_qualifier = NULL_TREE;
1050 if (building_stmt_tree ())
1052 tree r = build_min_nt (ASM_STMT, cv_qualifier, string,
1053 output_operands, input_operands,
1059 emit_line_note (input_filename, lineno);
1060 if (output_operands != NULL_TREE || input_operands != NULL_TREE
1061 || clobbers != NULL_TREE)
1065 for (t = input_operands; t; t = TREE_CHAIN (t))
1066 TREE_VALUE (t) = decay_conversion (TREE_VALUE (t));
1068 c_expand_asm_operands (string, output_operands,
1071 cv_qualifier != NULL_TREE,
1072 input_filename, lineno);
1075 expand_asm (string);
1081 /* Finish a label with the indicated NAME. */
1084 finish_label_stmt (name)
1087 tree decl = define_label (input_filename, lineno, name);
1089 if (building_stmt_tree ())
1090 add_tree (build_min_nt (LABEL_STMT, decl));
1092 expand_label (decl);
1095 /* Finish a series of declarations for local labels. G++ allows users
1096 to declare "local" labels, i.e., labels with scope. This extension
1097 is useful when writing code involving statement-expressions. */
1100 finish_label_decl (name)
1103 tree decl = declare_local_label (name);
1104 if (building_stmt_tree ())
1105 add_decl_stmt (decl);
1108 /* Create a declaration statement for the declaration given by the
1112 add_decl_stmt (decl)
1117 /* We need the type to last until instantiation time. */
1118 decl_stmt = build_min_nt (DECL_STMT, decl);
1119 add_tree (decl_stmt);
1122 /* We're in a constructor, and have just constructed a a subobject of
1123 *THIS. CLEANUP is code to run if an exception is thrown before the
1124 end of the current function is reached. */
1127 finish_subobject (cleanup)
1130 if (building_stmt_tree ())
1132 tree r = build_min_nt (SUBOBJECT, cleanup);
1136 add_partial_entry (cleanup);
1139 /* When DECL goes out of scope, make sure that CLEANUP is executed. */
1142 finish_decl_cleanup (decl, cleanup)
1146 if (building_stmt_tree ())
1147 add_tree (build_min_nt (CLEANUP_STMT, decl, cleanup));
1149 || (DECL_SIZE (decl) && TREE_TYPE (decl) != error_mark_node))
1150 expand_decl_cleanup (decl, cleanup);
1153 /* Bind a name and initialization to the return value of
1154 the current function. */
1157 finish_named_return_value (return_id, init)
1158 tree return_id, init;
1160 tree decl = DECL_RESULT (current_function_decl);
1163 /* Give this error as many times as there are occurrences,
1164 so that users can use Emacs compilation buffers to find
1165 and fix all such places. */
1166 pedwarn ("ISO C++ does not permit named return values");
1168 if (return_id != NULL_TREE)
1170 if (DECL_NAME (decl) == NULL_TREE)
1172 DECL_NAME (decl) = return_id;
1173 DECL_ASSEMBLER_NAME (decl) = return_id;
1177 cp_error ("return identifier `%D' already in place", return_id);
1182 /* Can't let this happen for constructors. */
1183 if (DECL_CONSTRUCTOR_P (current_function_decl))
1185 error ("can't redefine default return value for constructors");
1189 /* If we have a named return value, put that in our scope as well. */
1190 if (DECL_NAME (decl) != NULL_TREE)
1192 /* Let `cp_finish_decl' know that this initializer is ok. */
1193 DECL_INITIAL (decl) = init;
1194 if (doing_semantic_analysis_p ())
1197 if (building_stmt_tree ())
1198 add_tree (build_min_nt (RETURN_INIT, return_id, init));
1201 cp_finish_decl (decl, init, NULL_TREE, 0);
1202 store_return_init (decl);
1206 /* Don't use tree-inlining for functions with named return values.
1207 That doesn't work properly because we don't do any translation of
1208 the RETURN_INITs when they are copied. */
1209 DECL_UNINLINABLE (current_function_decl) = 1;
1212 /* Cache the value of this class's main virtual function table pointer
1213 in a register variable. This will save one indirection if a
1214 more than one virtual function call is made this function. */
1219 my_friendly_assert (doing_semantic_analysis_p (), 19990919);
1221 /* If we've already done this, there's no need to do it again. */
1225 if (DECL_CONSTRUCTOR_P (current_function_decl))
1227 if (processing_template_decl)
1228 add_tree (build_min_nt
1230 current_member_init_list, current_base_init_list));
1235 /* Mark the beginning of the constructor. */
1236 ctor_stmt = build_min_nt (CTOR_STMT);
1237 CTOR_BEGIN_P (ctor_stmt) = 1;
1238 add_tree (ctor_stmt);
1240 /* And actually initialize the base-classes and members. */
1241 emit_base_init (current_class_type);
1244 else if (DECL_DESTRUCTOR_P (current_function_decl)
1245 && !processing_template_decl)
1251 /* If the dtor is empty, and we know there is not possible way we
1252 could use any vtable entries, before they are possibly set by
1253 a base class dtor, we don't have to setup the vtables, as we
1254 know that any base class dtoring will set up any vtables it
1255 needs. We avoid MI, because one base class dtor can do a
1256 virtual dispatch to an overridden function that would need to
1257 have a non-related vtable set up, we cannot avoid setting up
1258 vtables in that case. We could change this to see if there is
1260 if_stmt = begin_if_stmt ();
1262 /* If it is not safe to avoid setting up the vtables, then
1263 someone will change the condition to be boolean_true_node.
1264 (Actually, for now, we do not have code to set the condition
1265 appropriately, so we just assume that we always need to
1266 initialize the vtables.) */
1267 finish_if_stmt_cond (boolean_true_node, if_stmt);
1268 current_vcalls_possible_p = &IF_COND (if_stmt);
1270 /* Don't declare __PRETTY_FUNCTION__ and friends here when we
1271 open the block for the if-body. */
1272 saved_cfnd = current_function_name_declared;
1273 current_function_name_declared = 1;
1274 compound_stmt = begin_compound_stmt (/*has_no_scope=*/0);
1275 current_function_name_declared = saved_cfnd;
1277 /* Make all virtual function table pointers in non-virtual base
1278 classes point to CURRENT_CLASS_TYPE's virtual function
1280 initialize_vtbl_ptrs (current_class_type,
1283 finish_compound_stmt (/*has_no_scope=*/0, compound_stmt);
1284 finish_then_clause (if_stmt);
1288 /* Always keep the BLOCK node associated with the outermost pair of
1289 curly braces of a function. These are needed for correct
1290 operation of dwarfout.c. */
1291 keep_next_level (1);
1293 /* The virtual function tables are set up now. */
1297 /* Add a scope-statement to the statement-tree. BEGIN_P indicates
1298 whether this statements opens or closes a scope. PARTIAL_P is true
1299 for a partial scope, i.e, the scope that begins after a label when
1300 an object that needs a cleanup is created. If BEGIN_P is nonzero,
1301 returns a new TREE_LIST representing the top of the SCOPE_STMT
1302 stack. The TREE_PURPOSE is the new SCOPE_STMT. If BEGIN_P is
1303 zero, returns a TREE_LIST whose TREE_VALUE is the new SCOPE_STMT,
1304 and whose TREE_PURPOSE is the matching SCOPE_STMT iwth
1305 SCOPE_BEGIN_P set. */
1308 add_scope_stmt (begin_p, partial_p)
1315 /* Build the statement. */
1316 ss = build_min_nt (SCOPE_STMT, NULL_TREE);
1317 SCOPE_BEGIN_P (ss) = begin_p;
1318 SCOPE_PARTIAL_P (ss) = partial_p;
1320 /* Keep the scope stack up to date. */
1323 current_scope_stmt_stack
1324 = tree_cons (ss, NULL_TREE, current_scope_stmt_stack);
1325 top = current_scope_stmt_stack;
1329 top = current_scope_stmt_stack;
1330 TREE_VALUE (top) = ss;
1331 current_scope_stmt_stack = TREE_CHAIN (top);
1334 /* Add the new statement to the statement-tree. */
1340 /* Begin a new scope. */
1345 if (!building_stmt_tree ())
1347 emit_line_note (input_filename, lineno);
1350 if (stmts_are_full_exprs_p)
1353 if (!building_stmt_tree ()
1354 && !cfun->x_whole_function_mode_p)
1355 my_friendly_abort (19991129);
1357 if (building_stmt_tree () && !processing_template_decl)
1358 add_scope_stmt (/*begin_p=*/1, /*partial_p=*/0);
1362 /* Finish a scope. */
1367 tree block = NULL_TREE;
1369 if (stmts_are_full_exprs_p)
1373 if (building_stmt_tree () && !processing_template_decl)
1374 scope_stmts = add_scope_stmt (/*begin_p=*/0, /*partial_p=*/0);
1376 scope_stmts = NULL_TREE;
1378 block = poplevel (kept_level_p (), 1, 0);
1379 if (block && !processing_template_decl)
1381 SCOPE_STMT_BLOCK (TREE_PURPOSE (scope_stmts)) = block;
1382 SCOPE_STMT_BLOCK (TREE_VALUE (scope_stmts)) = block;
1389 /* Finish a parenthesized expression EXPR. */
1392 finish_parenthesized_expr (expr)
1395 if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (TREE_CODE (expr))))
1396 /* This inhibits warnings in truthvalue_conversion. */
1397 C_SET_EXP_ORIGINAL_CODE (expr, ERROR_MARK);
1402 /* Begin a statement-expression. The value returned must be passed to
1403 finish_stmt_expr. */
1408 /* If we're outside a function, we won't have a statement-tree to
1409 work with. But, if we see a statement-expression we need to
1411 if (! cfun && !last_tree)
1412 begin_stmt_tree (&scope_chain->x_saved_tree);
1414 keep_next_level (1);
1415 /* If we're building a statement tree, then the upcoming compound
1416 statement will be chained onto the tree structure, starting at
1417 last_tree. We return last_tree so that we can later unhook the
1418 compound statement. */
1419 return building_stmt_tree () ? last_tree : expand_start_stmt_expr();
1422 /* Finish a statement-expression. RTL_EXPR should be the value
1423 returned by the previous begin_stmt_expr; EXPR is the
1424 statement-expression. Returns an expression representing the
1425 statement-expression. */
1428 finish_stmt_expr (rtl_expr)
1433 if (!building_stmt_tree ())
1434 rtl_expr = expand_end_stmt_expr (rtl_expr);
1436 if (building_stmt_tree ())
1438 /* If the last thing in the statement-expression was not an
1439 expression-statement, then it has type `void'. */
1440 if (!last_expr_type)
1441 last_expr_type = void_type_node;
1442 result = build_min (STMT_EXPR, last_expr_type, last_tree);
1443 TREE_SIDE_EFFECTS (result) = 1;
1445 /* Remove the compound statement from the tree structure; it is
1446 now saved in the STMT_EXPR. */
1447 SET_LAST_STMT (rtl_expr);
1448 TREE_CHAIN (last_tree) = NULL_TREE;
1453 /* If we created a statement-tree for this statement-expression,
1456 && TREE_CHAIN (scope_chain->x_saved_tree) == NULL_TREE)
1457 finish_stmt_tree (&scope_chain->x_saved_tree);
1462 /* Finish a call to FN with ARGS. Returns a representation of the
1466 finish_call_expr (fn, args, koenig)
1475 if (TREE_CODE (fn) == BIT_NOT_EXPR)
1476 fn = build_x_unary_op (BIT_NOT_EXPR, TREE_OPERAND (fn, 0));
1477 else if (TREE_CODE (fn) != TEMPLATE_ID_EXPR)
1478 fn = do_identifier (fn, 2, args);
1480 result = build_x_function_call (fn, args, current_class_ref);
1482 if (TREE_CODE (result) == CALL_EXPR
1483 && (! TREE_TYPE (result)
1484 || TREE_CODE (TREE_TYPE (result)) != VOID_TYPE))
1485 result = require_complete_type (result);
1490 /* Finish a call to a postfix increment or decrement or EXPR. (Which
1491 is indicated by CODE, which should be POSTINCREMENT_EXPR or
1492 POSTDECREMENT_EXPR.) */
1495 finish_increment_expr (expr, code)
1497 enum tree_code code;
1499 /* If we get an OFFSET_REF, turn it into what it really means (e.g.,
1500 a COMPONENT_REF). This way if we've got, say, a reference to a
1501 static member that's being operated on, we don't end up trying to
1502 find a member operator for the class it's in. */
1504 if (TREE_CODE (expr) == OFFSET_REF)
1505 expr = resolve_offset_ref (expr);
1506 return build_x_unary_op (code, expr);
1509 /* Finish a use of `this'. Returns an expression for `this'. */
1516 if (current_class_ptr)
1518 #ifdef WARNING_ABOUT_CCD
1519 TREE_USED (current_class_ptr) = 1;
1521 result = current_class_ptr;
1523 else if (current_function_decl
1524 && DECL_STATIC_FUNCTION_P (current_function_decl))
1526 error ("`this' is unavailable for static member functions");
1527 result = error_mark_node;
1531 if (current_function_decl)
1532 error ("invalid use of `this' in non-member function");
1534 error ("invalid use of `this' at top level");
1535 result = error_mark_node;
1541 /* Finish a member function call using OBJECT and ARGS as arguments to
1542 FN. Returns an expression for the call. */
1545 finish_object_call_expr (fn, object, args)
1551 /* This is a future direction of this code, but because
1552 build_x_function_call cannot always undo what is done in
1553 build_component_ref entirely yet, we cannot do this. */
1555 tree real_fn = build_component_ref (object, fn, NULL_TREE, 1);
1556 return finish_call_expr (real_fn, args);
1558 if (DECL_DECLARES_TYPE_P (fn))
1560 if (processing_template_decl)
1561 /* This can happen on code like:
1564 template <class T> void f(T t) {
1568 We just grab the underlying IDENTIFIER. */
1569 fn = DECL_NAME (fn);
1572 cp_error ("calling type `%T' like a method", fn);
1573 return error_mark_node;
1577 return build_method_call (object, fn, args, NULL_TREE, LOOKUP_NORMAL);
1581 /* Finish a qualified member function call using OBJECT and ARGS as
1582 arguments to FN. Returns an expressino for the call. */
1585 finish_qualified_object_call_expr (fn, object, args)
1590 return build_scoped_method_call (object, TREE_OPERAND (fn, 0),
1591 TREE_OPERAND (fn, 1), args);
1594 /* Finish a pseudo-destructor call expression of OBJECT, with SCOPE
1595 being the scope, if any, of DESTRUCTOR. Returns an expression for
1599 finish_pseudo_destructor_call_expr (object, scope, destructor)
1604 if (processing_template_decl)
1605 return build_min_nt (PSEUDO_DTOR_EXPR, object, scope, destructor);
1607 if (scope && scope != destructor)
1608 cp_error ("destructor specifier `%T::~%T()' must have matching names",
1611 if ((scope == NULL_TREE || IDENTIFIER_GLOBAL_VALUE (destructor))
1612 && (TREE_CODE (TREE_TYPE (object)) !=
1613 TREE_CODE (TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (destructor)))))
1614 cp_error ("`%E' is not of type `%T'", object, destructor);
1616 return cp_convert (void_type_node, object);
1619 /* Finish a call to a globally qualified member function FN using
1620 ARGS. Returns an expression for the call. */
1623 finish_qualified_call_expr (fn, args)
1627 if (processing_template_decl)
1628 return build_min_nt (CALL_EXPR, fn, args, NULL_TREE);
1630 return build_member_call (TREE_OPERAND (fn, 0),
1631 TREE_OPERAND (fn, 1),
1635 /* Finish an expression taking the address of LABEL. Returns an
1636 expression for the address. */
1639 finish_label_address_expr (label)
1644 label = lookup_label (label);
1645 if (label == NULL_TREE)
1646 result = null_pointer_node;
1649 TREE_USED (label) = 1;
1650 result = build1 (ADDR_EXPR, ptr_type_node, label);
1651 TREE_CONSTANT (result) = 1;
1652 /* This function cannot be inlined. All jumps to the addressed
1653 label should wind up at the same point. */
1654 DECL_UNINLINABLE (current_function_decl) = 1;
1660 /* Finish an expression of the form CODE EXPR. */
1663 finish_unary_op_expr (code, expr)
1664 enum tree_code code;
1667 tree result = build_x_unary_op (code, expr);
1668 /* Inside a template, build_x_unary_op does not fold the
1669 expression. So check whether the result is folded before
1670 setting TREE_NEGATED_INT. */
1671 if (code == NEGATE_EXPR && TREE_CODE (expr) == INTEGER_CST
1672 && TREE_CODE (result) == INTEGER_CST
1673 && !TREE_UNSIGNED (TREE_TYPE (result))
1674 && INT_CST_LT (result, integer_zero_node))
1675 TREE_NEGATED_INT (result) = 1;
1676 overflow_warning (result);
1680 /* Finish an id-expression. */
1683 finish_id_expr (expr)
1686 if (TREE_CODE (expr) == IDENTIFIER_NODE)
1687 expr = do_identifier (expr, 1, NULL_TREE);
1692 static tree current_type_lookups;
1694 /* Perform deferred access control for types used in the type of a
1698 deferred_type_access_control ()
1700 tree lookup = type_lookups;
1702 if (lookup == error_mark_node)
1705 for (; lookup; lookup = TREE_CHAIN (lookup))
1706 enforce_access (TREE_PURPOSE (lookup), TREE_VALUE (lookup));
1710 decl_type_access_control (decl)
1715 if (type_lookups == error_mark_node)
1718 save_fn = current_function_decl;
1720 if (decl && TREE_CODE (decl) == FUNCTION_DECL)
1721 current_function_decl = decl;
1723 deferred_type_access_control ();
1725 current_function_decl = save_fn;
1727 /* Now strip away the checks for the current declarator; they were
1728 added to type_lookups after typed_declspecs saved the copy that
1729 ended up in current_type_lookups. */
1730 type_lookups = current_type_lookups;
1734 save_type_access_control (lookups)
1737 current_type_lookups = lookups;
1740 /* Begin a function definition declared with DECL_SPECS and
1741 DECLARATOR. Returns non-zero if the function-declaration is
1745 begin_function_definition (decl_specs, declarator)
1752 split_specs_attrs (decl_specs, &specs, &attrs);
1753 if (!start_function (specs, declarator, attrs, SF_DEFAULT))
1756 deferred_type_access_control ();
1757 type_lookups = error_mark_node;
1759 reinit_parse_for_function ();
1760 /* The things we're about to see are not directly qualified by any
1761 template headers we've seen thus far. */
1762 reset_specialization ();
1767 /* Begin a constructor declarator of the form `SCOPE::NAME'. Returns
1771 begin_constructor_declarator (scope, name)
1775 tree result = build_parse_node (SCOPE_REF, scope, name);
1776 enter_scope_of (result);
1780 /* Finish an init-declarator. Returns a DECL. */
1783 finish_declarator (declarator, declspecs, attributes,
1784 prefix_attributes, initialized)
1788 tree prefix_attributes;
1791 return start_decl (declarator, declspecs, initialized, attributes,
1795 /* Finish a translation unit. */
1798 finish_translation_unit ()
1800 /* In case there were missing closebraces,
1801 get us back to the global binding level. */
1803 while (current_namespace != global_namespace)
1808 /* Finish a template type parameter, specified as AGGR IDENTIFIER.
1809 Returns the parameter. */
1812 finish_template_type_parm (aggr, identifier)
1816 if (aggr != class_type_node)
1818 pedwarn ("template type parameters must use the keyword `class' or `typename'");
1819 aggr = class_type_node;
1822 return build_tree_list (aggr, identifier);
1825 /* Finish a template template parameter, specified as AGGR IDENTIFIER.
1826 Returns the parameter. */
1829 finish_template_template_parm (aggr, identifier)
1833 tree decl = build_decl (TYPE_DECL, identifier, NULL_TREE);
1834 tree tmpl = build_lang_decl (TEMPLATE_DECL, identifier, NULL_TREE);
1835 DECL_TEMPLATE_PARMS (tmpl) = current_template_parms;
1836 DECL_TEMPLATE_RESULT (tmpl) = decl;
1837 SET_DECL_ARTIFICIAL (decl);
1838 end_template_decl ();
1840 return finish_template_type_parm (aggr, tmpl);
1843 /* Finish a parameter list, indicated by PARMS. If ELLIPSIS is
1844 non-zero, the parameter list was terminated by a `...'. */
1847 finish_parmlist (parms, ellipsis)
1852 chainon (parms, void_list_node);
1853 /* We mark the PARMS as a parmlist so that declarator processing can
1854 disambiguate certain constructs. */
1855 if (parms != NULL_TREE)
1856 TREE_PARMLIST (parms) = 1;
1861 /* Begin a class definition, as indicated by T. */
1864 begin_class_definition (t)
1867 if (t == error_mark_node
1868 || ! IS_AGGR_TYPE (t))
1870 t = make_aggr_type (RECORD_TYPE);
1871 pushtag (make_anon_name (), t, 0);
1874 /* In a definition of a member class template, we will get here with an
1875 implicit typename, a TYPENAME_TYPE with a type. */
1876 if (TREE_CODE (t) == TYPENAME_TYPE)
1879 /* If we generated a partial instantiation of this type, but now
1880 we're seeing a real definition, we're actually looking at a
1881 partial specialization. Consider:
1883 template <class T, class U>
1889 template <class T, class U>
1892 typename X<Y<T, U> >::A a;
1895 template <class T, class U>
1900 We have to undo the effects of the previous partial
1902 if (PARTIAL_INSTANTIATION_P (t))
1906 /* Unfortunately, when we're not in pedantic mode, we
1907 attempt to actually fill in some of the fields of the
1908 partial instantiation, in order to support the implicit
1909 typename extension. Clear those fields now, in
1910 preparation for the definition here. The fields cleared
1911 here must match those set in instantiate_class_template.
1912 Look for a comment mentioning begin_class_definition
1914 TYPE_BINFO_BASETYPES (t) = NULL_TREE;
1915 TYPE_FIELDS (t) = NULL_TREE;
1916 TYPE_METHODS (t) = NULL_TREE;
1917 CLASSTYPE_TAGS (t) = NULL_TREE;
1918 TYPE_SIZE (t) = NULL_TREE;
1921 /* This isn't a partial instantiation any more. */
1922 PARTIAL_INSTANTIATION_P (t) = 0;
1924 /* If this type was already complete, and we see another definition,
1926 else if (COMPLETE_TYPE_P (t))
1927 duplicate_tag_error (t);
1929 /* Update the location of the decl. */
1930 DECL_SOURCE_FILE (TYPE_NAME (t)) = input_filename;
1931 DECL_SOURCE_LINE (TYPE_NAME (t)) = lineno;
1933 if (TYPE_BEING_DEFINED (t))
1935 t = make_aggr_type (TREE_CODE (t));
1936 pushtag (TYPE_IDENTIFIER (t), t, 0);
1938 maybe_process_partial_specialization (t);
1940 TYPE_BEING_DEFINED (t) = 1;
1941 /* Reset the interface data, at the earliest possible
1942 moment, as it might have been set via a class foo;
1945 tree name = TYPE_IDENTIFIER (t);
1947 if (! ANON_AGGRNAME_P (name))
1949 CLASSTYPE_INTERFACE_ONLY (t) = interface_only;
1950 SET_CLASSTYPE_INTERFACE_UNKNOWN_X
1951 (t, interface_unknown);
1954 /* Only leave this bit clear if we know this
1955 class is part of an interface-only specification. */
1956 if (! CLASSTYPE_INTERFACE_KNOWN (t)
1957 || ! CLASSTYPE_INTERFACE_ONLY (t))
1958 CLASSTYPE_VTABLE_NEEDS_WRITING (t) = 1;
1961 tmp = TYPE_IDENTIFIER ($<ttype>0);
1962 if (tmp && IDENTIFIER_TEMPLATE (tmp))
1963 overload_template_name (tmp, 1);
1965 reset_specialization();
1967 /* Make a declaration for this class in its own scope. */
1968 build_self_reference ();
1973 /* Finish the member declaration given by DECL. */
1976 finish_member_declaration (decl)
1979 if (decl == error_mark_node || decl == NULL_TREE)
1982 if (decl == void_type_node)
1983 /* The COMPONENT was a friend, not a member, and so there's
1984 nothing for us to do. */
1987 /* We should see only one DECL at a time. */
1988 my_friendly_assert (TREE_CHAIN (decl) == NULL_TREE, 0);
1990 /* Set up access control for DECL. */
1992 = (current_access_specifier == access_private_node);
1993 TREE_PROTECTED (decl)
1994 = (current_access_specifier == access_protected_node);
1995 if (TREE_CODE (decl) == TEMPLATE_DECL)
1997 TREE_PRIVATE (DECL_TEMPLATE_RESULT (decl)) = TREE_PRIVATE (decl);
1998 TREE_PROTECTED (DECL_TEMPLATE_RESULT (decl)) = TREE_PROTECTED (decl);
2001 /* Mark the DECL as a member of the current class. */
2002 DECL_CONTEXT (decl) = current_class_type;
2004 /* Put functions on the TYPE_METHODS list and everything else on the
2005 TYPE_FIELDS list. Note that these are built up in reverse order.
2006 We reverse them (to obtain declaration order) in finish_struct. */
2007 if (TREE_CODE (decl) == FUNCTION_DECL
2008 || DECL_FUNCTION_TEMPLATE_P (decl))
2010 /* We also need to add this function to the
2011 CLASSTYPE_METHOD_VEC. */
2012 add_method (current_class_type, 0, decl);
2014 TREE_CHAIN (decl) = TYPE_METHODS (current_class_type);
2015 TYPE_METHODS (current_class_type) = decl;
2019 /* All TYPE_DECLs go at the end of TYPE_FIELDS. Ordinary fields
2020 go at the beginning. The reason is that lookup_field_1
2021 searches the list in order, and we want a field name to
2022 override a type name so that the "struct stat hack" will
2023 work. In particular:
2025 struct S { enum E { }; int E } s;
2028 is legal. In addition, the FIELD_DECLs must be maintained in
2029 declaration order so that class layout works as expected.
2030 However, we don't need that order until class layout, so we
2031 save a little time by putting FIELD_DECLs on in reverse order
2032 here, and then reversing them in finish_struct_1. (We could
2033 also keep a pointer to the correct insertion points in the
2036 if (TREE_CODE (decl) == TYPE_DECL)
2037 TYPE_FIELDS (current_class_type)
2038 = chainon (TYPE_FIELDS (current_class_type), decl);
2041 TREE_CHAIN (decl) = TYPE_FIELDS (current_class_type);
2042 TYPE_FIELDS (current_class_type) = decl;
2045 /* Enter the DECL into the scope of the class. */
2046 if (TREE_CODE (decl) != USING_DECL)
2047 pushdecl_class_level (decl);
2051 /* Finish a class definition T with the indicate ATTRIBUTES. If SEMI,
2052 the definition is immediately followed by a semicolon. Returns the
2056 finish_class_definition (t, attributes, semi, pop_scope_p)
2062 /* finish_struct nukes this anyway; if finish_exception does too,
2065 note_got_semicolon (t);
2067 /* If we got any attributes in class_head, xref_tag will stick them in
2068 TREE_TYPE of the type. Grab them now. */
2069 attributes = chainon (TREE_TYPE (t), attributes);
2070 TREE_TYPE (t) = NULL_TREE;
2072 if (TREE_CODE (t) == ENUMERAL_TYPE)
2076 t = finish_struct (t, attributes);
2078 note_got_semicolon (t);
2082 check_for_missing_semicolon (t);
2084 pop_scope (CP_DECL_CONTEXT (TYPE_MAIN_DECL (t)));
2085 if (current_scope () == current_function_decl)
2086 do_pending_defargs ();
2091 /* Finish processing the default argument expressions cached during
2092 the processing of a class definition. */
2095 begin_inline_definitions ()
2098 && current_scope () == current_function_decl)
2099 do_pending_inlines ();
2102 /* Finish processing the inline function definitions cached during the
2103 processing of a class definition. */
2106 finish_inline_definitions ()
2108 if (current_class_type == NULL_TREE)
2109 clear_inline_text_obstack ();
2112 /* Finish processing the declaration of a member class template
2113 TYPES whose template parameters are given by PARMS. */
2116 finish_member_class_template (types)
2121 /* If there are declared, but undefined, partial specializations
2122 mixed in with the typespecs they will not yet have passed through
2123 maybe_process_partial_specialization, so we do that here. */
2124 for (t = types; t != NULL_TREE; t = TREE_CHAIN (t))
2125 if (IS_AGGR_TYPE_CODE (TREE_CODE (TREE_VALUE (t))))
2126 maybe_process_partial_specialization (TREE_VALUE (t));
2128 note_list_got_semicolon (types);
2129 grok_x_components (types);
2130 if (TYPE_CONTEXT (TREE_VALUE (types)) != current_class_type)
2131 /* The component was in fact a friend declaration. We avoid
2132 finish_member_template_decl performing certain checks by
2136 finish_member_template_decl (types);
2138 /* As with other component type declarations, we do
2139 not store the new DECL on the list of
2144 /* Finish processsing a complete template declaration. The PARMS are
2145 the template parameters. */
2148 finish_template_decl (parms)
2152 end_template_decl ();
2154 end_specialization ();
2157 /* Finish processing a a template-id (which names a type) of the form
2158 NAME < ARGS >. Return the TYPE_DECL for the type named by the
2159 template-id. If ENTERING_SCOPE is non-zero we are about to enter
2160 the scope of template-id indicated. */
2163 finish_template_type (name, args, entering_scope)
2170 decl = lookup_template_class (name, args,
2171 NULL_TREE, NULL_TREE, entering_scope);
2172 if (decl != error_mark_node)
2173 decl = TYPE_STUB_DECL (decl);
2178 /* SR is a SCOPE_REF node. Enter the scope of SR, whether it is a
2179 namespace scope or a class scope. */
2185 tree scope = TREE_OPERAND (sr, 0);
2187 if (TREE_CODE (scope) == NAMESPACE_DECL)
2189 push_decl_namespace (scope);
2190 TREE_COMPLEXITY (sr) = -1;
2192 else if (scope != current_class_type)
2194 if (TREE_CODE (scope) == TYPENAME_TYPE)
2196 /* In a declarator for a template class member, the scope will
2197 get here as an implicit typename, a TYPENAME_TYPE with a type. */
2198 scope = TREE_TYPE (scope);
2199 TREE_OPERAND (sr, 0) = scope;
2201 push_nested_class (scope, 3);
2202 TREE_COMPLEXITY (sr) = current_class_depth;
2206 /* Finish processing a BASE_CLASS with the indicated ACCESS_SPECIFIER.
2207 Return a TREE_LIST containing the ACCESS_SPECIFIER and the
2208 BASE_CLASS, or NULL_TREE if an error occurred. The
2209 ACCESSS_SPECIFIER is one of
2210 access_{default,public,protected_private}[_virtual]_node.*/
2213 finish_base_specifier (access_specifier, base_class)
2214 tree access_specifier;
2220 if (base_class == NULL_TREE)
2222 error ("invalid base class");
2223 type = error_mark_node;
2226 type = TREE_TYPE (base_class);
2228 if (! is_aggr_type (type, 1))
2231 result = build_tree_list (access_specifier, type);
2236 /* Called when multiple declarators are processed. If that is not
2237 premitted in this context, an error is issued. */
2240 check_multiple_declarators ()
2244 In a template-declaration, explicit specialization, or explicit
2245 instantiation the init-declarator-list in the declaration shall
2246 contain at most one declarator.
2248 We don't just use PROCESSING_TEMPLATE_DECL for the first
2249 condition since that would disallow the perfectly legal code,
2250 like `template <class T> struct S { int i, j; };'. */
2251 tree scope = current_scope ();
2253 if (scope && TREE_CODE (scope) == FUNCTION_DECL)
2254 /* It's OK to write `template <class T> void f() { int i, j;}'. */
2257 if (PROCESSING_REAL_TEMPLATE_DECL_P ()
2258 || processing_explicit_instantiation
2259 || processing_specialization)
2260 cp_error ("multiple declarators in template declaration");
2264 finish_typeof (expr)
2267 if (processing_template_decl)
2271 t = make_aggr_type (TYPEOF_TYPE);
2272 TYPE_FIELDS (t) = expr;
2277 return TREE_TYPE (expr);
2280 /* Create an empty statement tree rooted at T. */
2286 /* We create a trivial EXPR_STMT so that last_tree is never NULL in
2287 what follows. We remove the extraneous statement in
2288 finish_stmt_tree. */
2289 *t = build_nt (EXPR_STMT, void_zero_node);
2291 last_expr_type = NULL_TREE;
2294 /* Finish the statement tree rooted at T. */
2297 finish_stmt_tree (t)
2302 /* Remove the fake extra statement added in begin_stmt_tree. */
2303 stmt = TREE_CHAIN (*t);
2305 SET_LAST_STMT (NULL_TREE);
2309 /* The line-number recorded in the outermost statement in a function
2310 is the line number of the end of the function. */
2311 STMT_LINENO (stmt) = lineno;
2312 STMT_LINENO_FOR_FN_P (stmt) = 1;
2316 /* We're about to expand T, a statement. Set up appropriate context
2317 for the substitution. */
2323 if (!STMT_LINENO_FOR_FN_P (t))
2324 lineno = STMT_LINENO (t);
2325 stmts_are_full_exprs_p = STMT_IS_FULL_EXPR_P (t);
2328 /* Some statements, like for-statements or if-statements, require a
2329 condition. This condition can be a declaration. If T is such a
2330 declaration it is processed, and an expression appropriate to use
2331 as the condition is returned. Otherwise, T itself is returned. */
2337 if (t && TREE_CODE (t) == TREE_LIST)
2339 expand_stmt (TREE_PURPOSE (t));
2340 return TREE_VALUE (t);
2346 /* Generate RTL for the statement T, and its substatements, and any
2347 other statements at its nesting level. */
2353 tree rval = NULL_TREE;
2355 while (t && t != error_mark_node)
2357 int saved_stmts_are_full_exprs_p;
2359 /* Assume we'll have nothing to return. */
2362 /* Set up context appropriately for handling this statement. */
2363 saved_stmts_are_full_exprs_p = stmts_are_full_exprs_p;
2366 switch (TREE_CODE (t))
2369 finish_return_stmt (RETURN_EXPR (t));
2373 finish_expr_stmt (EXPR_STMT_EXPR (t));
2380 emit_line_note (input_filename, lineno);
2381 decl = DECL_STMT_DECL (t);
2382 /* If this is a declaration for an automatic local
2383 variable, initialize it. Note that we might also see a
2384 declaration for a namespace-scope object (declared with
2385 `extern'). We don't have to handle the initialization
2386 of those objects here; they can only be declarations,
2387 rather than definitions. */
2388 if (TREE_CODE (decl) == VAR_DECL
2389 && !TREE_STATIC (decl)
2390 && !DECL_EXTERNAL (decl))
2392 /* Let the back-end know about this variable. */
2393 if (!ANON_AGGR_TYPE_P (TREE_TYPE (decl)))
2394 emit_local_var (decl);
2396 expand_anon_union_decl (decl, NULL_TREE,
2397 DECL_ANON_UNION_ELEMS (decl));
2399 else if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl))
2401 if (DECL_ARTIFICIAL (decl) && ! TREE_USED (decl))
2402 /* Do not emit unused decls. This is not just an
2403 optimization. We really do not want to emit
2404 __PRETTY_FUNCTION__ etc, if they're never used. */
2405 DECL_IGNORED_P (decl) = 1;
2407 make_rtl_for_local_static (decl);
2413 finish_decl_cleanup (CLEANUP_DECL (t), CLEANUP_EXPR (t));
2416 case START_CATCH_STMT:
2417 begin_catch_block (TREE_TYPE (t));
2421 if (CTOR_BEGIN_P (t))
2422 begin_protect_partials ();
2424 /* After this point, any exceptions will cause the
2425 destructor to be executed, so we no longer need to worry
2426 about destroying the various subobjects ourselves. */
2427 end_protect_partials ();
2435 expand_stmt (FOR_INIT_STMT (t));
2436 finish_for_init_stmt (NULL_TREE);
2437 finish_for_cond (expand_cond (FOR_COND (t)), NULL_TREE);
2439 finish_for_expr (tmp, NULL_TREE);
2440 expand_stmt (FOR_BODY (t));
2441 finish_for_stmt (tmp, NULL_TREE);
2447 begin_while_stmt ();
2448 finish_while_stmt_cond (expand_cond (WHILE_COND (t)), NULL_TREE);
2449 expand_stmt (WHILE_BODY (t));
2450 finish_while_stmt (NULL_TREE);
2457 expand_stmt (DO_BODY (t));
2458 finish_do_body (NULL_TREE);
2459 finish_do_stmt (DO_COND (t), NULL_TREE);
2465 finish_if_stmt_cond (expand_cond (IF_COND (t)), NULL_TREE);
2466 if (THEN_CLAUSE (t))
2468 expand_stmt (THEN_CLAUSE (t));
2469 finish_then_clause (NULL_TREE);
2471 if (ELSE_CLAUSE (t))
2473 begin_else_clause ();
2474 expand_stmt (ELSE_CLAUSE (t));
2475 finish_else_clause (NULL_TREE);
2481 begin_compound_stmt (COMPOUND_STMT_NO_SCOPE (t));
2482 expand_stmt (COMPOUND_BODY (t));
2483 rval = finish_compound_stmt (COMPOUND_STMT_NO_SCOPE (t),
2488 finish_break_stmt ();
2492 finish_continue_stmt ();
2499 begin_switch_stmt ();
2500 cond = expand_cond (SWITCH_COND (t));
2501 finish_switch_cond (cond, NULL_TREE);
2502 expand_stmt (SWITCH_BODY (t));
2503 finish_switch_stmt (cond, NULL_TREE);
2508 finish_case_label (CASE_LOW (t), CASE_HIGH (t));
2512 expand_label (LABEL_STMT_LABEL (t));
2516 finish_goto_stmt (GOTO_DESTINATION (t));
2520 finish_asm_stmt (ASM_CV_QUAL (t), ASM_STRING (t), ASM_OUTPUTS
2521 (t), ASM_INPUTS (t), ASM_CLOBBERS (t));
2527 expand_eh_region_start ();
2528 expand_stmt (TRY_STMTS (t));
2529 finish_cleanup_try_block (NULL_TREE);
2530 finish_cleanup (TRY_HANDLERS (t), NULL_TREE);
2534 if (FN_TRY_BLOCK_P (t))
2535 begin_function_try_block ();
2539 expand_stmt (TRY_STMTS (t));
2541 if (FN_TRY_BLOCK_P (t))
2543 finish_function_try_block (NULL_TREE);
2544 expand_stmt (TRY_HANDLERS (t));
2545 finish_function_handler_sequence (NULL_TREE);
2549 finish_try_block (NULL_TREE);
2550 expand_stmt (TRY_HANDLERS (t));
2551 finish_handler_sequence (NULL_TREE);
2558 expand_stmt (HANDLER_BODY (t));
2559 finish_handler (NULL_TREE, NULL_TREE);
2563 finish_subobject (SUBOBJECT_CLEANUP (t));
2567 if (!SCOPE_NO_CLEANUPS_P (t))
2569 if (SCOPE_BEGIN_P (t))
2570 expand_start_bindings_and_block (2 * SCOPE_NULLIFIED_P (t),
2571 SCOPE_STMT_BLOCK (t));
2572 else if (SCOPE_END_P (t))
2573 expand_end_bindings (NULL_TREE, !SCOPE_NULLIFIED_P (t),
2574 SCOPE_PARTIAL_P (t));
2576 else if (!SCOPE_NULLIFIED_P (t))
2578 rtx note = emit_note (NULL,
2580 ? NOTE_INSN_BLOCK_BEG
2581 : NOTE_INSN_BLOCK_END));
2582 NOTE_BLOCK (note) = SCOPE_STMT_BLOCK (t);
2588 /* Clear this out so that finish_named_return_value can set it
2590 DECL_NAME (DECL_RESULT (current_function_decl)) = NULL_TREE;
2591 finish_named_return_value (TREE_OPERAND (t, 0),
2592 TREE_OPERAND (t, 1));
2596 my_friendly_abort (19990810);
2600 /* Restore saved state. */
2601 stmts_are_full_exprs_p = saved_stmts_are_full_exprs_p;
2603 /* Go on to the next statement in this scope. */
2610 /* Called from expand_body via walk_tree. Replace all AGGR_INIT_EXPRs
2611 will equivalent CALL_EXPRs. */
2614 simplify_aggr_init_exprs_r (tp, walk_subtrees, data)
2616 int *walk_subtrees ATTRIBUTE_UNUSED;
2617 void *data ATTRIBUTE_UNUSED;
2619 tree aggr_init_expr;
2626 int copy_from_buffer_p;
2628 aggr_init_expr = *tp;
2629 /* We don't need to walk into types; there's nothing in a type that
2630 needs simplification. (And, furthermore, there are places we
2631 actively don't want to go. For example, we don't want to wander
2632 into the default arguments for a FUNCTION_DECL that appears in a
2634 if (TYPE_P (aggr_init_expr))
2639 /* Only AGGR_INIT_EXPRs are interesting. */
2640 else if (TREE_CODE (aggr_init_expr) != AGGR_INIT_EXPR)
2643 /* Form an appropriate CALL_EXPR. */
2644 fn = TREE_OPERAND (aggr_init_expr, 0);
2645 args = TREE_OPERAND (aggr_init_expr, 1);
2646 slot = TREE_OPERAND (aggr_init_expr, 2);
2647 type = TREE_TYPE (aggr_init_expr);
2649 if (AGGR_INIT_VIA_CTOR_P (aggr_init_expr))
2651 /* Replace the first argument with the address of the third
2652 argument to the AGGR_INIT_EXPR. */
2653 call_type = build_pointer_type (type);
2654 mark_addressable (slot);
2655 args = tree_cons (NULL_TREE, build1 (ADDR_EXPR, call_type, slot),
2658 call_expr = build (CALL_EXPR, call_type, fn, args, NULL_TREE);
2659 TREE_SIDE_EFFECTS (call_expr) = 1;
2661 /* If we're using the non-reentrant PCC calling convention, then we
2662 need to copy the returned value out of the static buffer into the
2664 copy_from_buffer_p = 0;
2665 #ifdef PCC_STATIC_STRUCT_RETURN
2666 if (!AGGR_INIT_VIA_CTOR_P (aggr_init_expr) && aggregate_value_p (type))
2670 flag_access_control = 0;
2671 call_expr = build_aggr_init (slot, call_expr, LOOKUP_ONLYCONVERTING);
2672 flag_access_control = old_ac;
2673 copy_from_buffer_p = 1;
2677 /* If this AGGR_INIT_EXPR indicates the value returned by a
2678 function, then we want to use the value of the initialized
2679 location as the result. */
2680 if (AGGR_INIT_VIA_CTOR_P (aggr_init_expr) || copy_from_buffer_p)
2682 call_expr = build (COMPOUND_EXPR, type,
2684 TREE_SIDE_EFFECTS (call_expr) = 1;
2687 /* Replace the AGGR_INIT_EXPR with the CALL_EXPR. */
2688 TREE_CHAIN (call_expr) = TREE_CHAIN (aggr_init_expr);
2691 /* Keep iterating. */
2695 /* Generate RTL for FN. */
2702 char *saved_input_filename;
2704 /* When the parser calls us after finishing the body of a template
2705 function, we don't really want to expand the body. When we're
2706 processing an in-class definition of an inline function,
2707 PROCESSING_TEMPLATE_DECL will no longer be set here, so we have
2708 to look at the function itself. */
2709 if (processing_template_decl
2710 || (DECL_LANG_SPECIFIC (fn)
2711 && DECL_TEMPLATE_INFO (fn)
2712 && uses_template_parms (DECL_TI_ARGS (fn))))
2714 /* Normally, collection only occurs in rest_of_compilation. So,
2715 if we don't collect here, we never collect junk generated
2716 during the processing of templates until we hit a
2717 non-template function. */
2722 /* Replace AGGR_INIT_EXPRs with appropriate CALL_EXPRs. */
2723 walk_tree (&DECL_SAVED_TREE (fn), simplify_aggr_init_exprs_r, NULL);
2725 /* There's no reason to do any of the work here if we're only doing
2726 semantic analysis; this code just generates RTL. */
2727 if (flag_syntax_only)
2730 /* If possible, avoid generating RTL for this function. Instead,
2731 just record it as an inline function, and wait until end-of-file
2732 to decide whether to write it out or not. */
2733 if (/* We have to generate RTL if it's not an inline function. */
2734 (DECL_INLINE (fn) || DECL_COMDAT (fn))
2735 /* Or if we have to keep all inline functions anyhow. */
2736 && !flag_keep_inline_functions
2737 /* Or if we actually have a reference to the function. */
2738 && !DECL_NEEDED_P (fn)
2739 /* Or if this is a nested function. */
2740 && !decl_function_context (fn))
2742 /* Give the function RTL now so that we can assign it to a
2743 function pointer, etc. */
2744 make_function_rtl (fn);
2745 /* Set DECL_EXTERNAL so that assemble_external will be called as
2746 necessary. We'll clear it again in finish_file. */
2747 if (!DECL_EXTERNAL (fn))
2749 DECL_NOT_REALLY_EXTERN (fn) = 1;
2750 DECL_EXTERNAL (fn) = 1;
2752 /* Remember this function. In finish_file we'll decide if
2753 we actually need to write this function out. */
2755 /* Let the back-end know that this funtion exists. */
2756 note_deferral_of_defined_inline_function (fn);
2760 /* Optimize the body of the function before expanding it. */
2761 optimize_function (fn);
2763 /* Save the current file name and line number. When we expand the
2764 body of the function, we'll set LINENO and INPUT_FILENAME so that
2765 error-mesages come out in the right places. */
2766 saved_lineno = lineno;
2767 saved_input_filename = input_filename;
2768 lineno = DECL_SOURCE_LINE (fn);
2769 input_filename = DECL_SOURCE_FILE (fn);
2771 start_function (NULL_TREE, fn, NULL_TREE, SF_PRE_PARSED | SF_EXPAND);
2772 store_parm_decls ();
2774 /* We don't need to redeclare __FUNCTION__, __PRETTY_FUNCTION__, or
2775 any of the other magic variables we set up when starting a
2777 current_function_name_declared = 1;
2779 /* Expand the body. */
2780 expand_stmt (DECL_SAVED_TREE (fn));
2782 /* Statements should always be full-expressions at the outermost set
2783 of curly braces for a function. */
2784 my_friendly_assert (stmts_are_full_exprs_p, 19990831);
2786 /* The outermost statement for a function contains the line number
2787 recorded when we finished processing the function. */
2788 lineno = STMT_LINENO (DECL_SAVED_TREE (fn));
2790 /* Generate code for the function. */
2791 finish_function (lineno, 0);
2793 /* If possible, obliterate the body of the function so that it can
2794 be garbage collected. */
2795 if (flag_dump_translation_unit)
2796 /* Keep the body; we're going to dump it. */
2798 else if (DECL_INLINE (fn) && flag_inline_trees)
2799 /* We might need the body of this function so that we can expand
2800 it inline somewhere else. */
2803 /* We don't need the body; blow it away. */
2804 DECL_SAVED_TREE (fn) = NULL_TREE;
2806 /* And restore the current source position. */
2807 lineno = saved_lineno;
2808 input_filename = saved_input_filename;