1 /* Perform the semantic phase of parsing, i.e., the process of
2 building tree structure, checking semantic consistency, and
3 building RTL. These routines are used both during actual parsing
4 and during the instantiation of template functions.
6 Copyright (C) 1998, 1999 Free Software Foundation, Inc.
7 Written by Mark Mitchell (mmitchell@usa.net) based on code found
8 formerly in parse.y and pt.c.
10 This file is part of GNU CC.
12 GNU CC is free software; you can redistribute it and/or modify it
13 under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2, or (at your option)
17 GNU CC is distributed in the hope that it will be useful, but
18 WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with GNU CC; see the file COPYING. If not, write to the Free
24 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
37 /* There routines provide a modular interface to perform many parsing
38 operations. They may therefore be used during actual parsing, or
39 during template instantiation, which may be regarded as a
40 degenerate form of parsing. Since the current g++ parser is
41 lacking in several respects, and will be reimplemented, we are
42 attempting to move most code that is not directly related to
43 parsing into this file; that will make implementing the new parser
44 much easier since it will be able to make use of these routines. */
46 static tree expand_cond PROTO((tree));
47 static tree maybe_convert_cond PROTO((tree));
49 /* Record the fact that STMT was the last statement added to the
52 #define SET_LAST_STMT(stmt) \
53 (current_stmt_tree->x_last_stmt = (stmt))
55 /* When parsing a template, LAST_TREE contains the last statement
56 parsed. These are chained together through the TREE_CHAIN field,
57 but often need to be re-organized since the parse is performed
58 bottom-up. This macro makes LAST_TREE the indicated SUBSTMT of
61 #define RECHAIN_STMTS(stmt, substmt) \
63 substmt = TREE_CHAIN (stmt); \
64 TREE_CHAIN (stmt) = NULL_TREE; \
65 SET_LAST_STMT (stmt); \
68 /* Finish processing the COND, the SUBSTMT condition for STMT. */
70 #define FINISH_COND(cond, stmt, substmt) \
72 if (last_tree != stmt) \
74 RECHAIN_STMTS (stmt, substmt); \
75 if (!processing_template_decl) \
77 cond = build_tree_list (substmt, cond); \
85 /* T is a statement. Add it to the statement-tree. */
91 /* Add T to the statement-tree. */
92 TREE_CHAIN (last_tree) = t;
95 /* When we expand a statement-tree, we must know whether or not the
96 statements are full-expresions. We record that fact here. */
97 if (building_stmt_tree ())
98 STMT_IS_FULL_EXPR_P (last_tree) = stmts_are_full_exprs_p;
101 /* COND is the condition-expression for an if, while, etc.,
102 statement. Convert it to a boolean value, if appropriate. */
105 maybe_convert_cond (cond)
108 /* Empty conditions remain empty. */
112 /* Wait until we instantiate templates before doing conversion. */
113 if (processing_template_decl)
116 /* Do the conversion. */
117 cond = convert_from_reference (cond);
118 return condition_conversion (cond);
121 /* Finish an expression-statement, whose EXPRESSION is as indicated. */
124 finish_expr_stmt (expr)
127 if (expr != NULL_TREE)
129 if (building_stmt_tree ())
131 /* Do default conversion if safe and possibly important,
132 in case within ({...}). */
133 if (!processing_template_decl
134 && !stmts_are_full_exprs_p
135 && ((TREE_CODE (TREE_TYPE (expr)) == ARRAY_TYPE
137 || TREE_CODE (TREE_TYPE (expr)) == FUNCTION_TYPE))
138 expr = default_conversion (expr);
140 if (!processing_template_decl)
141 expr = break_out_cleanups (expr);
143 add_tree (build_min_nt (EXPR_STMT, expr));
147 emit_line_note (input_filename, lineno);
149 if (stmts_are_full_exprs_p)
150 expand_start_target_temps ();
152 cplus_expand_expr_stmt (expr);
154 if (stmts_are_full_exprs_p)
155 expand_end_target_temps ();
161 /* This was an expression-statement, so we save the type of the
163 last_expr_type = expr ? TREE_TYPE (expr) : NULL_TREE;
166 /* Begin an if-statement. Returns a newly created IF_STMT if
176 if (building_stmt_tree ())
178 r = build_min_nt (IF_STMT, NULL_TREE, NULL_TREE, NULL_TREE);
187 /* Process the COND of an if-statement, which may be given by
191 finish_if_stmt_cond (cond, if_stmt)
195 cond = maybe_convert_cond (cond);
197 if (building_stmt_tree ())
198 FINISH_COND (cond, if_stmt, IF_COND (if_stmt));
201 emit_line_note (input_filename, lineno);
202 expand_start_cond (cond, 0);
206 /* Finish the then-clause of an if-statement, which may be given by
210 finish_then_clause (if_stmt)
213 if (building_stmt_tree ())
215 RECHAIN_STMTS (if_stmt, THEN_CLAUSE (if_stmt));
216 SET_LAST_STMT (if_stmt);
223 /* Begin the else-clause of an if-statement. */
228 if (!building_stmt_tree ())
229 expand_start_else ();
232 /* Finish the else-clause of an if-statement, which may be given by
236 finish_else_clause (if_stmt)
239 if (building_stmt_tree ())
240 RECHAIN_STMTS (if_stmt, ELSE_CLAUSE (if_stmt));
243 /* Finsh an if-statement. */
248 if (!building_stmt_tree ())
255 /* Begin a while-statement. Returns a newly created WHILE_STMT if
263 if (building_stmt_tree ())
265 r = build_min_nt (WHILE_STMT, NULL_TREE, NULL_TREE);
271 emit_line_note (input_filename, lineno);
272 expand_start_loop (1);
281 /* Process the COND of an if-statement, which may be given by
285 finish_while_stmt_cond (cond, while_stmt)
289 cond = maybe_convert_cond (cond);
291 if (building_stmt_tree ())
292 FINISH_COND (cond, while_stmt, WHILE_COND (while_stmt));
295 emit_line_note (input_filename, lineno);
296 expand_exit_loop_if_false (0, cond);
299 /* If COND wasn't a declaration, clear out the
300 block we made for it and start a new one here so the
301 optimization in expand_end_loop will work. */
302 if (getdecls () == NULL_TREE)
309 /* Finish a while-statement, which may be given by WHILE_STMT. */
312 finish_while_stmt (while_stmt)
317 if (building_stmt_tree ())
318 RECHAIN_STMTS (while_stmt, WHILE_BODY (while_stmt));
324 /* Begin a do-statement. Returns a newly created DO_STMT if
330 if (building_stmt_tree ())
332 tree r = build_min_nt (DO_STMT, NULL_TREE, NULL_TREE);
339 emit_line_note (input_filename, lineno);
340 expand_start_loop_continue_elsewhere (1);
345 /* Finish the body of a do-statement, which may be given by DO_STMT. */
348 finish_do_body (do_stmt)
351 if (building_stmt_tree ())
352 RECHAIN_STMTS (do_stmt, DO_BODY (do_stmt));
354 expand_loop_continue_here ();
357 /* Finish a do-statement, which may be given by DO_STMT, and whose
358 COND is as indicated. */
361 finish_do_stmt (cond, do_stmt)
365 cond = maybe_convert_cond (cond);
367 if (building_stmt_tree ())
368 DO_COND (do_stmt) = cond;
371 emit_line_note (input_filename, lineno);
372 expand_exit_loop_if_false (0, cond);
379 /* Finish a return-statement. The EXPRESSION returned, if any, is as
383 finish_return_stmt (expr)
386 if (doing_semantic_analysis_p () && !processing_template_decl)
387 expr = check_return_expr (expr);
389 if (doing_semantic_analysis_p () && !processing_template_decl)
391 if (DECL_CONSTRUCTOR_P (current_function_decl) && ctor_label)
393 /* Even returns without a value in a constructor must return
394 `this'. We accomplish this by sending all returns in a
395 constructor to the CTOR_LABEL; finish_function emits code to
396 return a value there. When we finally generate the real
397 return statement, CTOR_LABEL is no longer set, and we fall
398 through into the normal return-processing code below. */
399 finish_goto_stmt (ctor_label);
402 else if (DECL_DESTRUCTOR_P (current_function_decl))
404 /* Similarly, all destructors must run destructors for
405 base-classes before returning. So, all returns in a
406 destructor get sent to the DTOR_LABEL; finsh_function emits
407 code to return a value there. */
408 finish_goto_stmt (dtor_label);
413 if (building_stmt_tree ())
414 add_tree (build_min_nt (RETURN_STMT, expr));
417 emit_line_note (input_filename, lineno);
418 c_expand_return (expr);
424 /* Begin a for-statement. Returns a new FOR_STMT if appropriate. */
431 if (building_stmt_tree ())
433 r = build_min_nt (FOR_STMT, NULL_TREE, NULL_TREE,
434 NULL_TREE, NULL_TREE);
440 if (flag_new_for_scope > 0)
443 note_level_for_for ();
449 /* Finish the for-init-statement of a for-statement, which may be
450 given by FOR_STMT. */
453 finish_for_init_stmt (for_stmt)
456 if (building_stmt_tree ())
458 if (last_tree != for_stmt)
459 RECHAIN_STMTS (for_stmt, FOR_INIT_STMT (for_stmt));
464 emit_line_note (input_filename, lineno);
465 expand_start_loop_continue_elsewhere (1);
471 /* Finish the COND of a for-statement, which may be given by
475 finish_for_cond (cond, for_stmt)
479 cond = maybe_convert_cond (cond);
481 if (building_stmt_tree ())
482 FINISH_COND (cond, for_stmt, FOR_COND (for_stmt));
485 emit_line_note (input_filename, lineno);
487 expand_exit_loop_if_false (0, cond);
490 /* If the cond wasn't a declaration, clear out the
491 block we made for it and start a new one here so the
492 optimization in expand_end_loop will work. */
493 if (getdecls () == NULL_TREE)
500 /* Finish the increment-EXPRESSION in a for-statement, which may be
501 given by FOR_STMT. */
504 finish_for_expr (expr, for_stmt)
508 if (building_stmt_tree ())
509 FOR_EXPR (for_stmt) = expr;
512 /* Finish the body of a for-statement, which may be given by
513 FOR_STMT. The increment-EXPR for the loop must be
517 finish_for_stmt (expr, for_stmt)
521 /* Pop the scope for the body of the loop. */
524 if (building_stmt_tree ())
525 RECHAIN_STMTS (for_stmt, FOR_BODY (for_stmt));
528 emit_line_note (input_filename, lineno);
529 expand_loop_continue_here ();
531 finish_expr_stmt (expr);
535 if (flag_new_for_scope > 0)
541 /* Finish a break-statement. */
546 emit_line_note (input_filename, lineno);
547 if (building_stmt_tree ())
548 add_tree (build_min_nt (BREAK_STMT));
549 else if ( ! expand_exit_something ())
550 cp_error ("break statement not within loop or switch");
553 /* Finish a continue-statement. */
556 finish_continue_stmt ()
558 emit_line_note (input_filename, lineno);
559 if (building_stmt_tree ())
560 add_tree (build_min_nt (CONTINUE_STMT));
561 else if (! expand_continue_loop (0))
562 cp_error ("continue statement not within a loop");
565 /* Begin a switch-statement. Returns a new SWITCH_STMT if
573 if (building_stmt_tree ())
575 r = build_min_nt (SWITCH_STMT, NULL_TREE, NULL_TREE);
586 /* Finish the cond of a switch-statement. */
589 finish_switch_cond (cond, switch_stmt)
593 if (building_stmt_tree ())
594 FINISH_COND (cond, switch_stmt, SWITCH_COND (switch_stmt));
595 else if (cond != error_mark_node)
597 emit_line_note (input_filename, lineno);
598 c_expand_start_case (cond);
601 /* The code is in error, but we don't want expand_end_case to
603 c_expand_start_case (boolean_false_node);
608 /* Finish the body of a switch-statement, which may be given by
609 SWITCH_STMT. The COND to switch on is indicated. */
612 finish_switch_stmt (cond, switch_stmt)
616 if (building_stmt_tree ())
617 RECHAIN_STMTS (switch_stmt, SWITCH_BODY (switch_stmt));
619 expand_end_case (cond);
625 /* Finish a case-label. */
628 finish_case_label (low_value, high_value)
632 if (building_stmt_tree ())
634 /* Add a representation for the case label to the statement
636 add_tree (build_min_nt (CASE_LABEL, low_value, high_value));
637 /* And warn about crossing initializations, etc. */
638 if (!processing_template_decl)
639 define_case_label ();
643 do_case (low_value, high_value);
646 /* Finish a goto-statement. */
649 finish_goto_stmt (destination)
652 if (TREE_CODE (destination) == IDENTIFIER_NODE)
653 destination = lookup_label (destination);
655 /* We warn about unused labels with -Wunused. That means we have to
656 mark the used labels as used. */
657 if (TREE_CODE (destination) == LABEL_DECL)
658 TREE_USED (destination) = 1;
660 if (building_stmt_tree ())
662 if (TREE_CODE (destination) != LABEL_DECL)
663 /* We don't inline calls to functions with computed gotos.
664 Those functions are typically up to some funny business,
665 and may be depending on the labels being at particular
666 addresses, or some such. */
667 DECL_UNINLINABLE (current_function_decl) = 1;
669 add_tree (build_min_nt (GOTO_STMT, destination));
673 emit_line_note (input_filename, lineno);
675 if (TREE_CODE (destination) == LABEL_DECL)
677 label_rtx (destination);
678 expand_goto (destination);
681 expand_computed_goto (destination);
685 /* Begin a try-block. Returns a newly-created TRY_BLOCK if
691 if (building_stmt_tree ())
693 tree r = build_min_nt (TRY_BLOCK, NULL_TREE,
700 emit_line_note (input_filename, lineno);
701 expand_start_try_stmts ();
706 /* Likewise, for a function-try-block. */
709 begin_function_try_block ()
711 if (building_stmt_tree ())
713 tree r = build_min_nt (TRY_BLOCK, NULL_TREE,
715 FN_TRY_BLOCK_P (r) = 1;
721 if (! current_function_parms_stored)
723 expand_start_early_try_stmts ();
728 /* Finish a try-block, which may be given by TRY_BLOCK. */
731 finish_try_block (try_block)
734 if (building_stmt_tree ())
735 RECHAIN_STMTS (try_block, TRY_STMTS (try_block));
737 expand_start_all_catch ();
740 /* Finish the body of a cleanup try-block, which may be given by
744 finish_cleanup_try_block (try_block)
747 if (building_stmt_tree ())
748 RECHAIN_STMTS (try_block, TRY_STMTS (try_block));
751 /* Finish an implicitly generated try-block, with a cleanup is given
755 finish_cleanup (cleanup, try_block)
759 if (building_stmt_tree ())
761 TRY_HANDLERS (try_block) = cleanup;
762 CLEANUP_P (try_block) = 1;
765 expand_eh_region_end (protect_with_terminate (cleanup));
768 /* Likewise, for a function-try-block. */
771 finish_function_try_block (try_block)
774 if (building_stmt_tree ())
776 if (TREE_CHAIN (try_block)
777 && TREE_CODE (TREE_CHAIN (try_block)) == CTOR_INITIALIZER)
779 /* Chain the compound statement after the CTOR_INITIALIZER. */
780 TREE_CHAIN (TREE_CHAIN (try_block)) = last_tree;
781 /* And make the CTOR_INITIALIZER the body of the try-block. */
782 RECHAIN_STMTS (try_block, TRY_STMTS (try_block));
785 RECHAIN_STMTS (try_block, TRY_STMTS (try_block));
789 end_protect_partials ();
790 expand_start_all_catch ();
793 in_function_try_handler = 1;
796 /* Finish a handler-sequence for a try-block, which may be given by
800 finish_handler_sequence (try_block)
803 if (building_stmt_tree ())
804 RECHAIN_STMTS (try_block, TRY_HANDLERS (try_block));
806 expand_end_all_catch ();
809 /* Likewise, for a function-try-block. */
812 finish_function_handler_sequence (try_block)
815 in_function_try_handler = 0;
817 if (building_stmt_tree ())
818 RECHAIN_STMTS (try_block, TRY_HANDLERS (try_block));
820 expand_end_all_catch ();
823 /* Begin a handler. Returns a HANDLER if appropriate. */
830 if (building_stmt_tree ())
832 r = build_min_nt (HANDLER, NULL_TREE, NULL_TREE);
843 /* Finish the handler-parameters for a handler, which may be given by
844 HANDLER. DECL is the declaration for the catch parameter, or NULL
845 if this is a `catch (...)' clause. */
848 finish_handler_parms (decl, handler)
852 tree blocks = NULL_TREE;
854 if (processing_template_decl)
858 decl = pushdecl (decl);
859 decl = push_template_decl (decl);
860 add_decl_stmt (decl);
861 RECHAIN_STMTS (handler, HANDLER_PARMS (handler));
864 else if (building_stmt_tree ())
865 blocks = expand_start_catch_block (decl);
870 /* Note the beginning of a handler for TYPE. This function is called
871 at the point to which control should be transferred when an
872 appropriately-typed exception is thrown. */
875 begin_catch_block (type)
878 if (building_stmt_tree ())
879 add_tree (build (START_CATCH_STMT, type));
881 start_catch_handler (type);
884 /* Finish a handler, which may be given by HANDLER. The BLOCKs are
885 the return value from the matching call to finish_handler_parms. */
888 finish_handler (blocks, handler)
892 if (!processing_template_decl)
894 if (building_stmt_tree ())
895 expand_end_catch_block (blocks);
897 if (!building_stmt_tree ())
899 /* Fall to outside the try statement when done executing
900 handler and we fall off end of handler. This is jump
901 Lresume in the documentation. */
902 expand_goto (top_label_entry (&caught_return_label_stack));
903 end_catch_handler ();
909 if (building_stmt_tree ())
910 RECHAIN_STMTS (handler, HANDLER_BODY (handler));
913 /* Begin a compound-statement. If HAS_NO_SCOPE is non-zero, the
914 compound-statement does not define a scope. Returns a new
915 COMPOUND_STMT if appropriate. */
918 begin_compound_stmt (has_no_scope)
923 if (building_stmt_tree ())
925 r = build_min_nt (COMPOUND_STMT, NULL_TREE);
928 COMPOUND_STMT_NO_SCOPE (r) = 1;
933 last_expr_type = NULL_TREE;
938 /* Normally, we try hard to keep the BLOCK for a
939 statement-expression. But, if it's a statement-expression with
940 a scopeless block, there's nothing to keep, and we don't want
941 to accidentally keep a block *inside* the scopeless block. */
944 /* If this is the outermost block of the function, declare the
945 variables __FUNCTION__, __PRETTY_FUNCTION__, and so forth. */
947 && !current_function_name_declared
950 /* When we get callbacks from the middle-end, we need to know
951 we're in the midst of declaring these variables. */
952 current_function_name_declared = 2;
953 /* Actually insert the declarations. */
954 declare_function_name ();
955 /* And now just remember that we're all done. */
956 current_function_name_declared = 1;
963 /* Finish a compound-statement, which may be given by COMPOUND_STMT.
964 If HAS_NO_SCOPE is non-zero, the compound statement does not define
968 finish_compound_stmt (has_no_scope, compound_stmt)
980 if (building_stmt_tree ())
981 RECHAIN_STMTS (compound_stmt, COMPOUND_BODY (compound_stmt));
983 /* When we call finish_stmt we will lose LAST_EXPR_TYPE. But, since
984 the precise purpose of that variable is store the type of the
985 last expression statement within the last compound statement, we
986 preserve the value. */
994 /* Finish an asm-statement, whose components are a CV_QUALIFIER, a
995 STRING, some OUTPUT_OPERANDS, some INPUT_OPERANDS, and some
999 finish_asm_stmt (cv_qualifier, string, output_operands,
1000 input_operands, clobbers)
1003 tree output_operands;
1004 tree input_operands;
1007 if (TREE_CHAIN (string))
1008 string = combine_strings (string);
1010 if (cv_qualifier != NULL_TREE
1011 && cv_qualifier != ridpointers[(int) RID_VOLATILE])
1013 cp_warning ("%s qualifier ignored on asm",
1014 IDENTIFIER_POINTER (cv_qualifier));
1015 cv_qualifier = NULL_TREE;
1018 if (building_stmt_tree ())
1020 tree r = build_min_nt (ASM_STMT, cv_qualifier, string,
1021 output_operands, input_operands,
1027 emit_line_note (input_filename, lineno);
1028 if (output_operands != NULL_TREE || input_operands != NULL_TREE
1029 || clobbers != NULL_TREE)
1033 for (t = input_operands; t; t = TREE_CHAIN (t))
1034 TREE_VALUE (t) = decay_conversion (TREE_VALUE (t));
1036 c_expand_asm_operands (string, output_operands,
1039 cv_qualifier != NULL_TREE,
1040 input_filename, lineno);
1043 expand_asm (string);
1049 /* Finish a label with the indicated NAME. */
1052 finish_label_stmt (name)
1055 tree decl = define_label (input_filename, lineno, name);
1057 if (building_stmt_tree ())
1058 add_tree (build_min_nt (LABEL_STMT, decl));
1060 expand_label (decl);
1063 /* Finish a series of declarations for local labels. G++ allows users
1064 to declare "local" labels, i.e., labels with scope. This extension
1065 is useful when writing code involving statement-expressions. */
1068 finish_label_decl (name)
1071 tree decl = declare_local_label (name);
1072 if (building_stmt_tree ())
1073 add_decl_stmt (decl);
1076 /* Create a declaration statement for the declaration given by the
1080 add_decl_stmt (decl)
1085 /* We need the type to last until instantiation time. */
1086 decl_stmt = build_min_nt (DECL_STMT, decl);
1087 add_tree (decl_stmt);
1090 /* We're in a constructor, and have just constructed a a subobject of
1091 *THIS. CLEANUP is code to run if an exception is thrown before the
1092 end of the current function is reached. */
1095 finish_subobject (cleanup)
1098 if (building_stmt_tree ())
1100 tree r = build_min_nt (SUBOBJECT, cleanup);
1104 add_partial_entry (cleanup);
1107 /* When DECL goes out of scope, make sure that CLEANUP is executed. */
1110 finish_decl_cleanup (decl, cleanup)
1114 if (building_stmt_tree ())
1115 add_tree (build_min_nt (CLEANUP_STMT, decl, cleanup));
1117 || (DECL_SIZE (decl) && TREE_TYPE (decl) != error_mark_node))
1118 expand_decl_cleanup (decl, cleanup);
1121 /* Bind a name and initialization to the return value of
1122 the current function. */
1125 finish_named_return_value (return_id, init)
1126 tree return_id, init;
1128 tree decl = DECL_RESULT (current_function_decl);
1131 /* Give this error as many times as there are occurrences,
1132 so that users can use Emacs compilation buffers to find
1133 and fix all such places. */
1134 pedwarn ("ANSI C++ does not permit named return values");
1136 if (return_id != NULL_TREE)
1138 if (DECL_NAME (decl) == NULL_TREE)
1140 DECL_NAME (decl) = return_id;
1141 DECL_ASSEMBLER_NAME (decl) = return_id;
1145 cp_error ("return identifier `%D' already in place", return_id);
1150 /* Can't let this happen for constructors. */
1151 if (DECL_CONSTRUCTOR_P (current_function_decl))
1153 error ("can't redefine default return value for constructors");
1157 /* If we have a named return value, put that in our scope as well. */
1158 if (DECL_NAME (decl) != NULL_TREE)
1160 /* Let `cp_finish_decl' know that this initializer is ok. */
1161 DECL_INITIAL (decl) = init;
1162 if (doing_semantic_analysis_p ())
1165 if (building_stmt_tree ())
1166 add_tree (build_min_nt (RETURN_INIT, return_id, init));
1169 cp_finish_decl (decl, init, NULL_TREE, 0);
1170 store_return_init (decl);
1175 /* Cache the value of this class's main virtual function table pointer
1176 in a register variable. This will save one indirection if a
1177 more than one virtual function call is made this function. */
1182 my_friendly_assert (doing_semantic_analysis_p (), 19990919);
1184 /* If we've already done this, there's no need to do it again. */
1188 if (DECL_CONSTRUCTOR_P (current_function_decl))
1190 if (processing_template_decl)
1191 add_tree (build_min_nt
1193 current_member_init_list, current_base_init_list));
1198 /* Mark the beginning of the constructor. */
1199 ctor_stmt = build_min_nt (CTOR_STMT);
1200 CTOR_BEGIN_P (ctor_stmt) = 1;
1201 add_tree (ctor_stmt);
1203 /* And actually initialize the base-classes and members. */
1204 finish_expr_stmt (emit_base_init (current_class_type));
1207 else if (DECL_DESTRUCTOR_P (current_function_decl)
1208 && !processing_template_decl)
1210 tree binfo = TYPE_BINFO (current_class_type);
1215 /* If the dtor is empty, and we know there is not possible way we
1216 could use any vtable entries, before they are possibly set by
1217 a base class dtor, we don't have to setup the vtables, as we
1218 know that any base class dtoring will set up any vtables it
1219 needs. We avoid MI, because one base class dtor can do a
1220 virtual dispatch to an overridden function that would need to
1221 have a non-related vtable set up, we cannot avoid setting up
1222 vtables in that case. We could change this to see if there is
1224 if_stmt = begin_if_stmt ();
1226 /* If it is not safe to avoid setting up the vtables, then
1227 someone will change the condition to be boolean_true_node.
1228 (Actually, for now, we do not have code to set the condition
1229 appropriately, so we just assume that we always need to
1230 initialize the vtables.) */
1231 finish_if_stmt_cond (boolean_true_node, if_stmt);
1232 current_vcalls_possible_p = &IF_COND (if_stmt);
1234 /* Don't declare __PRETTY_FUNCTION__ and friends here when we
1235 open the block for the if-body. */
1236 saved_cfnd = current_function_name_declared;
1237 current_function_name_declared = 1;
1238 compound_stmt = begin_compound_stmt (/*has_no_scope=*/0);
1239 current_function_name_declared = saved_cfnd;
1241 /* Make all virtual function table pointers in non-virtual base
1242 classes point to CURRENT_CLASS_TYPE's virtual function
1244 expand_direct_vtbls_init (binfo, binfo, 1, 0, current_class_ptr);
1246 if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type))
1247 expand_indirect_vtbls_init (binfo, current_class_ref,
1250 finish_compound_stmt (/*has_no_scope=*/0, compound_stmt);
1251 finish_then_clause (if_stmt);
1255 /* Always keep the BLOCK node associated with the outermost pair of
1256 curly braces of a function. These are needed for correct
1257 operation of dwarfout.c. */
1258 keep_next_level (1);
1260 /* The virtual function tables are set up now. */
1264 /* Add a scope-statement to the statement-tree. BEGIN_P indicates
1265 whether this statements opens or closes a scope. PARTIAL_P is true
1266 for a partial scope, i.e, the scope that begins after a label when
1267 an object that needs a cleanup is created. */
1270 add_scope_stmt (begin_p, partial_p)
1276 /* Build the statement. */
1277 ss = build_min_nt (SCOPE_STMT);
1278 SCOPE_BEGIN_P (ss) = begin_p;
1279 SCOPE_PARTIAL_P (ss) = partial_p;
1281 /* If we're finishing a scope, figure out whether the scope was
1282 really necessary. */
1285 SCOPE_NULLIFIED_P (ss) = !kept_level_p ();
1286 SCOPE_NULLIFIED_P (TREE_VALUE (current_scope_stmt_stack))
1287 = SCOPE_NULLIFIED_P (ss);
1290 /* Keep the scope stack up to date. */
1292 current_scope_stmt_stack
1293 = tree_cons (NULL_TREE, ss, current_scope_stmt_stack);
1295 current_scope_stmt_stack = TREE_CHAIN (current_scope_stmt_stack);
1297 /* Add the new statement to the statement-tree. */
1301 /* Begin a new scope. */
1306 if (!building_stmt_tree ())
1308 emit_line_note (input_filename, lineno);
1311 if (stmts_are_full_exprs_p)
1314 if (!building_stmt_tree ()
1315 && !current_function->x_whole_function_mode_p)
1316 expand_start_bindings (0);
1317 else if (building_stmt_tree () && !processing_template_decl)
1318 add_scope_stmt (/*begin_p=*/1, /*partial_p=*/0);
1322 /* Finish a scope. */
1329 if (stmts_are_full_exprs_p)
1331 if (!building_stmt_tree ()
1332 && !current_function->x_whole_function_mode_p)
1333 expand_end_bindings (getdecls (), kept_level_p (), 0);
1334 else if (building_stmt_tree () && !processing_template_decl)
1336 add_scope_stmt (/*begin_p=*/0, /*partial_p=*/0);
1338 /* When not in function-at-a-time mode, expand_end_bindings
1339 will warn about unused variables. But, in
1340 function-at-a-time mode expand_end_bindings is not passed
1341 the list of variables in the current scope, and therefore
1342 no warning is emitted. So, we explicitly warn here. */
1343 warn_about_unused_variables (getdecls ());
1346 t = poplevel (kept_level_p (), 1, 0);
1351 /* Finish a parenthesized expression EXPR. */
1354 finish_parenthesized_expr (expr)
1357 if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (TREE_CODE (expr))))
1358 /* This inhibits warnings in truthvalue_conversion. */
1359 C_SET_EXP_ORIGINAL_CODE (expr, ERROR_MARK);
1364 /* Begin a statement-expression. The value returned must be passed to
1365 finish_stmt_expr. */
1370 /* If we're outside a function, we won't have a statement-tree to
1371 work with. But, if we see a statement-expression we need to
1373 if (!current_function && !last_tree)
1374 begin_stmt_tree (&scope_chain->x_saved_tree);
1376 keep_next_level (1);
1377 /* If we're building a statement tree, then the upcoming compound
1378 statement will be chained onto the tree structure, starting at
1379 last_tree. We return last_tree so that we can later unhook the
1380 compound statement. */
1381 return building_stmt_tree () ? last_tree : expand_start_stmt_expr();
1384 /* Finish a statement-expression. RTL_EXPR should be the value
1385 returned by the previous begin_stmt_expr; EXPR is the
1386 statement-expression. Returns an expression representing the
1387 statement-expression. */
1390 finish_stmt_expr (rtl_expr)
1395 if (!building_stmt_tree ())
1396 rtl_expr = expand_end_stmt_expr (rtl_expr);
1398 if (building_stmt_tree ())
1400 /* If the last thing in the statement-expression was not an
1401 expression-statement, then it has type `void'. */
1402 if (!last_expr_type)
1403 last_expr_type = void_type_node;
1404 result = build_min (STMT_EXPR, last_expr_type, last_tree);
1405 TREE_SIDE_EFFECTS (result) = 1;
1407 /* Remove the compound statement from the tree structure; it is
1408 now saved in the STMT_EXPR. */
1409 SET_LAST_STMT (rtl_expr);
1410 TREE_CHAIN (last_tree) = NULL_TREE;
1415 /* If we created a statement-tree for this statement-expression,
1417 if (!current_function
1418 && TREE_CHAIN (scope_chain->x_saved_tree) == NULL_TREE)
1419 finish_stmt_tree (&scope_chain->x_saved_tree);
1424 /* Finish a call to FN with ARGS. Returns a representation of the
1428 finish_call_expr (fn, args, koenig)
1437 if (TREE_CODE (fn) == BIT_NOT_EXPR)
1438 fn = build_x_unary_op (BIT_NOT_EXPR, TREE_OPERAND (fn, 0));
1439 else if (TREE_CODE (fn) != TEMPLATE_ID_EXPR)
1440 fn = do_identifier (fn, 2, args);
1442 result = build_x_function_call (fn, args, current_class_ref);
1444 if (TREE_CODE (result) == CALL_EXPR
1445 && (! TREE_TYPE (result)
1446 || TREE_CODE (TREE_TYPE (result)) != VOID_TYPE))
1447 result = require_complete_type (result);
1452 /* Finish a call to a postfix increment or decrement or EXPR. (Which
1453 is indicated by CODE, which should be POSTINCREMENT_EXPR or
1454 POSTDECREMENT_EXPR.) */
1457 finish_increment_expr (expr, code)
1459 enum tree_code code;
1461 /* If we get an OFFSET_REF, turn it into what it really means (e.g.,
1462 a COMPONENT_REF). This way if we've got, say, a reference to a
1463 static member that's being operated on, we don't end up trying to
1464 find a member operator for the class it's in. */
1466 if (TREE_CODE (expr) == OFFSET_REF)
1467 expr = resolve_offset_ref (expr);
1468 return build_x_unary_op (code, expr);
1471 /* Finish a use of `this'. Returns an expression for `this'. */
1478 if (current_class_ptr)
1480 #ifdef WARNING_ABOUT_CCD
1481 TREE_USED (current_class_ptr) = 1;
1483 result = current_class_ptr;
1485 else if (current_function_decl
1486 && DECL_STATIC_FUNCTION_P (current_function_decl))
1488 error ("`this' is unavailable for static member functions");
1489 result = error_mark_node;
1493 if (current_function_decl)
1494 error ("invalid use of `this' in non-member function");
1496 error ("invalid use of `this' at top level");
1497 result = error_mark_node;
1503 /* Finish a member function call using OBJECT and ARGS as arguments to
1504 FN. Returns an expression for the call. */
1507 finish_object_call_expr (fn, object, args)
1513 /* This is a future direction of this code, but because
1514 build_x_function_call cannot always undo what is done in
1515 build_component_ref entirely yet, we cannot do this. */
1517 tree real_fn = build_component_ref (object, fn, NULL_TREE, 1);
1518 return finish_call_expr (real_fn, args);
1520 if (DECL_DECLARES_TYPE_P (fn))
1522 if (processing_template_decl)
1523 /* This can happen on code like:
1526 template <class T> void f(T t) {
1530 We just grab the underlying IDENTIFIER. */
1531 fn = DECL_NAME (fn);
1534 cp_error ("calling type `%T' like a method", fn);
1535 return error_mark_node;
1539 return build_method_call (object, fn, args, NULL_TREE, LOOKUP_NORMAL);
1543 /* Finish a qualified member function call using OBJECT and ARGS as
1544 arguments to FN. Returns an expressino for the call. */
1547 finish_qualified_object_call_expr (fn, object, args)
1552 return build_scoped_method_call (object, TREE_OPERAND (fn, 0),
1553 TREE_OPERAND (fn, 1), args);
1556 /* Finish a pseudo-destructor call expression of OBJECT, with SCOPE
1557 being the scope, if any, of DESTRUCTOR. Returns an expression for
1561 finish_pseudo_destructor_call_expr (object, scope, destructor)
1566 if (processing_template_decl)
1567 return build_min_nt (PSEUDO_DTOR_EXPR, object, scope, destructor);
1569 if (scope && scope != destructor)
1570 cp_error ("destructor specifier `%T::~%T()' must have matching names",
1573 if ((scope == NULL_TREE || IDENTIFIER_GLOBAL_VALUE (destructor))
1574 && (TREE_CODE (TREE_TYPE (object)) !=
1575 TREE_CODE (TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (destructor)))))
1576 cp_error ("`%E' is not of type `%T'", object, destructor);
1578 return cp_convert (void_type_node, object);
1581 /* Finish a call to a globally qualified member function FN using
1582 ARGS. Returns an expression for the call. */
1585 finish_qualified_call_expr (fn, args)
1589 if (processing_template_decl)
1590 return build_min_nt (CALL_EXPR, fn, args, NULL_TREE);
1592 return build_member_call (TREE_OPERAND (fn, 0),
1593 TREE_OPERAND (fn, 1),
1597 /* Finish an expression taking the address of LABEL. Returns an
1598 expression for the address. */
1601 finish_label_address_expr (label)
1606 label = lookup_label (label);
1607 if (label == NULL_TREE)
1608 result = null_pointer_node;
1611 TREE_USED (label) = 1;
1612 result = build1 (ADDR_EXPR, ptr_type_node, label);
1613 TREE_CONSTANT (result) = 1;
1614 /* This function cannot be inlined. All jumps to the addressed
1615 label should wind up at the same point. */
1616 DECL_UNINLINABLE (current_function_decl) = 1;
1622 /* Finish an expression of the form CODE EXPR. */
1625 finish_unary_op_expr (code, expr)
1626 enum tree_code code;
1629 tree result = build_x_unary_op (code, expr);
1630 /* Inside a template, build_x_unary_op does not fold the
1631 expression. So check whether the result is folded before
1632 setting TREE_NEGATED_INT. */
1633 if (code == NEGATE_EXPR && TREE_CODE (expr) == INTEGER_CST
1634 && TREE_CODE (result) == INTEGER_CST
1635 && !TREE_UNSIGNED (TREE_TYPE (result))
1636 && INT_CST_LT (result, integer_zero_node))
1637 TREE_NEGATED_INT (result) = 1;
1638 overflow_warning (result);
1642 /* Finish an id-expression. */
1645 finish_id_expr (expr)
1648 if (TREE_CODE (expr) == IDENTIFIER_NODE)
1649 expr = do_identifier (expr, 1, NULL_TREE);
1654 /* Begin a function defniition declared with DECL_SPECS and
1655 DECLARATOR. Returns non-zero if the function-declaration is
1659 begin_function_definition (decl_specs, declarator)
1665 split_specs_attrs (decl_specs, &specs, &attrs);
1666 if (!start_function (specs, declarator, attrs, SF_DEFAULT))
1669 reinit_parse_for_function ();
1670 /* The things we're about to see are not directly qualified by any
1671 template headers we've seen thus far. */
1672 reset_specialization ();
1677 /* Begin a constructor declarator of the form `SCOPE::NAME'. Returns
1681 begin_constructor_declarator (scope, name)
1685 tree result = build_parse_node (SCOPE_REF, scope, name);
1686 enter_scope_of (result);
1690 /* Finish an init-declarator. Returns a DECL. */
1693 finish_declarator (declarator, declspecs, attributes,
1694 prefix_attributes, initialized)
1698 tree prefix_attributes;
1701 return start_decl (declarator, declspecs, initialized, attributes,
1705 /* Finish a translation unit. */
1708 finish_translation_unit ()
1710 /* In case there were missing closebraces,
1711 get us back to the global binding level. */
1713 while (current_namespace != global_namespace)
1718 /* Finish a template type parameter, specified as AGGR IDENTIFIER.
1719 Returns the parameter. */
1722 finish_template_type_parm (aggr, identifier)
1726 if (aggr != class_type_node)
1728 pedwarn ("template type parameters must use the keyword `class' or `typename'");
1729 aggr = class_type_node;
1732 return build_tree_list (aggr, identifier);
1735 /* Finish a template template parameter, specified as AGGR IDENTIFIER.
1736 Returns the parameter. */
1739 finish_template_template_parm (aggr, identifier)
1743 tree decl = build_decl (TYPE_DECL, identifier, NULL_TREE);
1744 tree tmpl = build_lang_decl (TEMPLATE_DECL, identifier, NULL_TREE);
1745 DECL_TEMPLATE_PARMS (tmpl) = current_template_parms;
1746 DECL_TEMPLATE_RESULT (tmpl) = decl;
1747 SET_DECL_ARTIFICIAL (decl);
1748 end_template_decl ();
1750 return finish_template_type_parm (aggr, tmpl);
1753 /* Finish a parameter list, indicated by PARMS. If ELLIPSIS is
1754 non-zero, the parameter list was terminated by a `...'. */
1757 finish_parmlist (parms, ellipsis)
1762 chainon (parms, void_list_node);
1763 /* We mark the PARMS as a parmlist so that declarator processing can
1764 disambiguate certain constructs. */
1765 if (parms != NULL_TREE)
1766 TREE_PARMLIST (parms) = 1;
1771 /* Begin a class definition, as indicated by T. */
1774 begin_class_definition (t)
1777 if (t == error_mark_node
1778 || ! IS_AGGR_TYPE (t))
1780 t = make_lang_type (RECORD_TYPE);
1781 pushtag (make_anon_name (), t, 0);
1784 /* In a definition of a member class template, we will get here with an
1785 implicit typename, a TYPENAME_TYPE with a type. */
1786 if (TREE_CODE (t) == TYPENAME_TYPE)
1789 /* If we generated a partial instantiation of this type, but now
1790 we're seeing a real definition, we're actually looking at a
1791 partial specialization. Consider:
1793 template <class T, class U>
1799 template <class T, class U>
1802 typename X<Y<T, U> >::A a;
1805 template <class T, class U>
1810 We have to undo the effects of the previous partial
1812 if (PARTIAL_INSTANTIATION_P (t))
1816 /* Unfortunately, when we're not in pedantic mode, we
1817 attempt to actually fill in some of the fields of the
1818 partial instantiation, in order to support the implicit
1819 typename extension. Clear those fields now, in
1820 preparation for the definition here. The fields cleared
1821 here must match those set in instantiate_class_template.
1822 Look for a comment mentioning begin_class_definition
1824 TYPE_BINFO_BASETYPES (t) = NULL_TREE;
1825 TYPE_FIELDS (t) = NULL_TREE;
1826 TYPE_METHODS (t) = NULL_TREE;
1827 CLASSTYPE_TAGS (t) = NULL_TREE;
1828 TYPE_SIZE (t) = NULL_TREE;
1831 /* This isn't a partial instantiation any more. */
1832 PARTIAL_INSTANTIATION_P (t) = 0;
1834 /* If this type was already complete, and we see another definition,
1836 else if (TYPE_SIZE (t))
1837 duplicate_tag_error (t);
1839 /* Update the location of the decl. */
1840 DECL_SOURCE_FILE (TYPE_NAME (t)) = input_filename;
1841 DECL_SOURCE_LINE (TYPE_NAME (t)) = lineno;
1843 if (TYPE_BEING_DEFINED (t))
1845 t = make_lang_type (TREE_CODE (t));
1846 pushtag (TYPE_IDENTIFIER (t), t, 0);
1848 maybe_process_partial_specialization (t);
1850 TYPE_BEING_DEFINED (t) = 1;
1851 /* Reset the interface data, at the earliest possible
1852 moment, as it might have been set via a class foo;
1855 tree name = TYPE_IDENTIFIER (t);
1857 if (! ANON_AGGRNAME_P (name))
1859 CLASSTYPE_INTERFACE_ONLY (t) = interface_only;
1860 SET_CLASSTYPE_INTERFACE_UNKNOWN_X
1861 (t, interface_unknown);
1864 /* Only leave this bit clear if we know this
1865 class is part of an interface-only specification. */
1866 if (! CLASSTYPE_INTERFACE_KNOWN (t)
1867 || ! CLASSTYPE_INTERFACE_ONLY (t))
1868 CLASSTYPE_VTABLE_NEEDS_WRITING (t) = 1;
1871 tmp = TYPE_IDENTIFIER ($<ttype>0);
1872 if (tmp && IDENTIFIER_TEMPLATE (tmp))
1873 overload_template_name (tmp, 1);
1875 reset_specialization();
1877 /* Make a declaration for this class in its own scope. */
1878 build_self_reference ();
1883 /* Finish the member declaration given by DECL. */
1886 finish_member_declaration (decl)
1889 if (decl == error_mark_node || decl == NULL_TREE)
1892 if (decl == void_type_node)
1893 /* The COMPONENT was a friend, not a member, and so there's
1894 nothing for us to do. */
1897 /* We should see only one DECL at a time. */
1898 my_friendly_assert (TREE_CHAIN (decl) == NULL_TREE, 0);
1900 /* Set up access control for DECL. */
1902 = (current_access_specifier == access_private_node);
1903 TREE_PROTECTED (decl)
1904 = (current_access_specifier == access_protected_node);
1905 if (TREE_CODE (decl) == TEMPLATE_DECL)
1907 TREE_PRIVATE (DECL_RESULT (decl)) = TREE_PRIVATE (decl);
1908 TREE_PROTECTED (DECL_RESULT (decl)) = TREE_PROTECTED (decl);
1911 /* Mark the DECL as a member of the current class. */
1912 if (TREE_CODE (decl) == FUNCTION_DECL
1913 || DECL_FUNCTION_TEMPLATE_P (decl))
1914 /* Historically, DECL_CONTEXT was not set for a FUNCTION_DECL in
1915 finish_struct. Presumably it is already set as the function is
1916 parsed. Perhaps DECL_CLASS_CONTEXT is already set, too? */
1917 DECL_CLASS_CONTEXT (decl) = current_class_type;
1919 DECL_CONTEXT (decl) = current_class_type;
1921 /* Put functions on the TYPE_METHODS list and everything else on the
1922 TYPE_FIELDS list. Note that these are built up in reverse order.
1923 We reverse them (to obtain declaration order) in finish_struct. */
1924 if (TREE_CODE (decl) == FUNCTION_DECL
1925 || DECL_FUNCTION_TEMPLATE_P (decl))
1927 /* We also need to add this function to the
1928 CLASSTYPE_METHOD_VEC. */
1929 add_method (current_class_type, 0, decl);
1931 TREE_CHAIN (decl) = TYPE_METHODS (current_class_type);
1932 TYPE_METHODS (current_class_type) = decl;
1936 /* All TYPE_DECLs go at the end of TYPE_FIELDS. Ordinary fields
1937 go at the beginning. The reason is that lookup_field_1
1938 searches the list in order, and we want a field name to
1939 override a type name so that the "struct stat hack" will
1940 work. In particular:
1942 struct S { enum E { }; int E } s;
1945 is legal. In addition, the FIELD_DECLs must be maintained in
1946 declaration order so that class layout works as expected.
1947 However, we don't need that order until class layout, so we
1948 save a little time by putting FIELD_DECLs on in reverse order
1949 here, and then reversing them in finish_struct_1. (We could
1950 also keep a pointer to the correct insertion points in the
1953 if (TREE_CODE (decl) == TYPE_DECL)
1954 TYPE_FIELDS (current_class_type)
1955 = chainon (TYPE_FIELDS (current_class_type), decl);
1958 TREE_CHAIN (decl) = TYPE_FIELDS (current_class_type);
1959 TYPE_FIELDS (current_class_type) = decl;
1962 /* Enter the DECL into the scope of the class. */
1963 if (TREE_CODE (decl) != USING_DECL)
1964 pushdecl_class_level (decl);
1968 /* Finish a class definition T with the indicate ATTRIBUTES. If SEMI,
1969 the definition is immediately followed by a semicolon. Returns the
1973 finish_class_definition (t, attributes, semi, pop_scope_p)
1979 /* finish_struct nukes this anyway; if finish_exception does too,
1982 note_got_semicolon (t);
1984 /* If we got any attributes in class_head, xref_tag will stick them in
1985 TREE_TYPE of the type. Grab them now. */
1986 attributes = chainon (TREE_TYPE (t), attributes);
1987 TREE_TYPE (t) = NULL_TREE;
1989 if (TREE_CODE (t) == ENUMERAL_TYPE)
1993 t = finish_struct (t, attributes);
1995 note_got_semicolon (t);
1999 check_for_missing_semicolon (t);
2001 pop_scope (CP_DECL_CONTEXT (TYPE_MAIN_DECL (t)));
2002 if (current_scope () == current_function_decl)
2003 do_pending_defargs ();
2008 /* Finish processing the default argument expressions cached during
2009 the processing of a class definition. */
2012 begin_inline_definitions ()
2015 && current_scope () == current_function_decl)
2016 do_pending_inlines ();
2019 /* Finish processing the inline function definitions cached during the
2020 processing of a class definition. */
2023 finish_inline_definitions ()
2025 if (current_class_type == NULL_TREE)
2026 clear_inline_text_obstack ();
2029 /* Finish processing the declaration of a member class template
2030 TYPES whose template parameters are given by PARMS. */
2033 finish_member_class_template (types)
2038 /* If there are declared, but undefined, partial specializations
2039 mixed in with the typespecs they will not yet have passed through
2040 maybe_process_partial_specialization, so we do that here. */
2041 for (t = types; t != NULL_TREE; t = TREE_CHAIN (t))
2042 if (IS_AGGR_TYPE_CODE (TREE_CODE (TREE_VALUE (t))))
2043 maybe_process_partial_specialization (TREE_VALUE (t));
2045 note_list_got_semicolon (types);
2046 grok_x_components (types);
2047 if (TYPE_CONTEXT (TREE_VALUE (types)) != current_class_type)
2048 /* The component was in fact a friend declaration. We avoid
2049 finish_member_template_decl performing certain checks by
2053 finish_member_template_decl (types);
2055 /* As with other component type declarations, we do
2056 not store the new DECL on the list of
2061 /* Finish processsing a complete template declaration. The PARMS are
2062 the template parameters. */
2065 finish_template_decl (parms)
2069 end_template_decl ();
2071 end_specialization ();
2074 /* Finish processing a a template-id (which names a type) of the form
2075 NAME < ARGS >. Return the TYPE_DECL for the type named by the
2076 template-id. If ENTERING_SCOPE is non-zero we are about to enter
2077 the scope of template-id indicated. */
2080 finish_template_type (name, args, entering_scope)
2087 decl = lookup_template_class (name, args,
2088 NULL_TREE, NULL_TREE, entering_scope);
2089 if (decl != error_mark_node)
2090 decl = TYPE_STUB_DECL (decl);
2095 /* SR is a SCOPE_REF node. Enter the scope of SR, whether it is a
2096 namespace scope or a class scope. */
2102 tree scope = TREE_OPERAND (sr, 0);
2104 if (TREE_CODE (scope) == NAMESPACE_DECL)
2106 push_decl_namespace (scope);
2107 TREE_COMPLEXITY (sr) = -1;
2109 else if (scope != current_class_type)
2111 if (TREE_CODE (scope) == TYPENAME_TYPE)
2113 /* In a declarator for a template class member, the scope will
2114 get here as an implicit typename, a TYPENAME_TYPE with a type. */
2115 scope = TREE_TYPE (scope);
2116 TREE_OPERAND (sr, 0) = scope;
2118 push_nested_class (scope, 3);
2119 TREE_COMPLEXITY (sr) = current_class_depth;
2123 /* Finish processing a BASE_CLASS with the indicated ACCESS_SPECIFIER.
2124 Return a TREE_LIST containing the ACCESS_SPECIFIER and the
2125 BASE_CLASS, or NULL_TREE if an error occurred. The
2126 ACCESSS_SPECIFIER is one of
2127 access_{default,public,protected_private}[_virtual]_node.*/
2130 finish_base_specifier (access_specifier, base_class)
2131 tree access_specifier;
2137 if (base_class == NULL_TREE)
2139 error ("invalid base class");
2140 type = error_mark_node;
2143 type = TREE_TYPE (base_class);
2145 if (! is_aggr_type (type, 1))
2148 result = build_tree_list (access_specifier, type);
2153 /* Called when multiple declarators are processed. If that is not
2154 premitted in this context, an error is issued. */
2157 check_multiple_declarators ()
2161 In a template-declaration, explicit specialization, or explicit
2162 instantiation the init-declarator-list in the declaration shall
2163 contain at most one declarator.
2165 We don't just use PROCESSING_TEMPLATE_DECL for the first
2166 condition since that would disallow the perfectly legal code,
2167 like `template <class T> struct S { int i, j; };'. */
2168 tree scope = current_scope ();
2170 if (scope && TREE_CODE (scope) == FUNCTION_DECL)
2171 /* It's OK to write `template <class T> void f() { int i, j;}'. */
2174 if (PROCESSING_REAL_TEMPLATE_DECL_P ()
2175 || processing_explicit_instantiation
2176 || processing_specialization)
2177 cp_error ("multiple declarators in template declaration");
2181 finish_typeof (expr)
2184 if (processing_template_decl)
2188 t = make_lang_type (TYPEOF_TYPE);
2189 TYPE_FIELDS (t) = expr;
2194 return TREE_TYPE (expr);
2197 /* Create an empty statement tree rooted at T. */
2203 /* We create a trivial EXPR_STMT so that last_tree is never NULL in
2204 what follows. We remove the extraneous statement in
2205 finish_stmt_tree. */
2206 *t = build_nt (EXPR_STMT, void_zero_node);
2208 last_expr_type = NULL_TREE;
2211 /* Finish the statement tree rooted at T. */
2214 finish_stmt_tree (t)
2219 /* Remove the fake extra statement added in begin_stmt_tree. */
2220 stmt = TREE_CHAIN (*t);
2222 SET_LAST_STMT (NULL_TREE);
2224 if (current_function)
2226 /* The line-number recorded in the outermost statement in a function
2227 is the line number of the end of the function. */
2228 STMT_LINENO (stmt) = lineno;
2229 STMT_LINENO_FOR_FN_P (stmt) = 1;
2233 /* We're about to expand T, a statement. Set up appropriate context
2234 for the substitution. */
2240 if (!STMT_LINENO_FOR_FN_P (t))
2241 lineno = STMT_LINENO (t);
2242 stmts_are_full_exprs_p = STMT_IS_FULL_EXPR_P (t);
2245 /* Some statements, like for-statements or if-statements, require a
2246 condition. This condition can be a declaration. If T is such a
2247 declaration it is processed, and an expression appropriate to use
2248 as the condition is returned. Otherwise, T itself is returned. */
2254 if (t && TREE_CODE (t) == TREE_LIST)
2256 expand_stmt (TREE_PURPOSE (t));
2257 return TREE_VALUE (t);
2263 /* Generate RTL for the statement T, and its substatements, and any
2264 other statements at its nesting level. */
2270 tree rval = NULL_TREE;
2272 while (t && t != error_mark_node)
2274 int saved_stmts_are_full_exprs_p;
2276 /* Assume we'll have nothing to return. */
2279 /* Set up context appropriately for handling this statement. */
2280 saved_stmts_are_full_exprs_p = stmts_are_full_exprs_p;
2283 switch (TREE_CODE (t))
2286 finish_return_stmt (RETURN_EXPR (t));
2290 finish_expr_stmt (EXPR_STMT_EXPR (t));
2297 emit_line_note (input_filename, lineno);
2298 decl = DECL_STMT_DECL (t);
2299 /* If this is a declaration for an automatic local
2300 variable, initialize it. Note that we might also see a
2301 declaration for a namespace-scope object (declared with
2302 `extern'). We don't have to handle the initialization
2303 of those objects here; they can only be declarations,
2304 rather than definitions. */
2305 if (TREE_CODE (decl) == VAR_DECL
2306 && !TREE_STATIC (decl)
2307 && !DECL_EXTERNAL (decl))
2309 /* Let the back-end know about this variable. */
2310 if (!ANON_AGGR_TYPE_P (TREE_TYPE (decl)))
2311 emit_local_var (decl);
2313 expand_anon_union_decl (decl, NULL_TREE,
2314 DECL_ANON_UNION_ELEMS (decl));
2316 else if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl))
2317 make_rtl_for_local_static (decl);
2322 finish_decl_cleanup (CLEANUP_DECL (t), CLEANUP_EXPR (t));
2325 case START_CATCH_STMT:
2326 begin_catch_block (TREE_TYPE (t));
2330 if (CTOR_BEGIN_P (t))
2331 begin_protect_partials ();
2333 /* After this point, any exceptions will cause the
2334 destructor to be executed, so we no longer need to worry
2335 about destroying the various subobjects ourselves. */
2336 end_protect_partials ();
2344 expand_stmt (FOR_INIT_STMT (t));
2345 finish_for_init_stmt (NULL_TREE);
2346 finish_for_cond (expand_cond (FOR_COND (t)), NULL_TREE);
2348 finish_for_expr (tmp, NULL_TREE);
2349 expand_stmt (FOR_BODY (t));
2350 finish_for_stmt (tmp, NULL_TREE);
2356 begin_while_stmt ();
2357 finish_while_stmt_cond (expand_cond (WHILE_COND (t)), NULL_TREE);
2358 expand_stmt (WHILE_BODY (t));
2359 finish_while_stmt (NULL_TREE);
2366 expand_stmt (DO_BODY (t));
2367 finish_do_body (NULL_TREE);
2368 finish_do_stmt (DO_COND (t), NULL_TREE);
2374 finish_if_stmt_cond (expand_cond (IF_COND (t)), NULL_TREE);
2375 if (THEN_CLAUSE (t))
2377 expand_stmt (THEN_CLAUSE (t));
2378 finish_then_clause (NULL_TREE);
2380 if (ELSE_CLAUSE (t))
2382 begin_else_clause ();
2383 expand_stmt (ELSE_CLAUSE (t));
2384 finish_else_clause (NULL_TREE);
2390 begin_compound_stmt (COMPOUND_STMT_NO_SCOPE (t));
2391 expand_stmt (COMPOUND_BODY (t));
2392 rval = finish_compound_stmt (COMPOUND_STMT_NO_SCOPE (t),
2397 finish_break_stmt ();
2401 finish_continue_stmt ();
2408 begin_switch_stmt ();
2409 cond = expand_cond (SWITCH_COND (t));
2410 finish_switch_cond (cond, NULL_TREE);
2411 expand_stmt (SWITCH_BODY (t));
2412 finish_switch_stmt (cond, NULL_TREE);
2417 finish_case_label (CASE_LOW (t), CASE_HIGH (t));
2421 expand_label (LABEL_STMT_LABEL (t));
2425 finish_goto_stmt (GOTO_DESTINATION (t));
2429 finish_asm_stmt (ASM_CV_QUAL (t), ASM_STRING (t), ASM_OUTPUTS
2430 (t), ASM_INPUTS (t), ASM_CLOBBERS (t));
2436 expand_eh_region_start ();
2437 expand_stmt (TRY_STMTS (t));
2438 finish_cleanup_try_block (NULL_TREE);
2439 finish_cleanup (TRY_HANDLERS (t), NULL_TREE);
2443 if (FN_TRY_BLOCK_P (t))
2444 begin_function_try_block ();
2448 expand_stmt (TRY_STMTS (t));
2450 if (FN_TRY_BLOCK_P (t))
2452 finish_function_try_block (NULL_TREE);
2453 expand_stmt (TRY_HANDLERS (t));
2454 finish_function_handler_sequence (NULL_TREE);
2458 finish_try_block (NULL_TREE);
2459 expand_stmt (TRY_HANDLERS (t));
2460 finish_handler_sequence (NULL_TREE);
2467 expand_stmt (HANDLER_BODY (t));
2468 finish_handler (NULL_TREE, NULL_TREE);
2472 finish_subobject (SUBOBJECT_CLEANUP (t));
2476 if (SCOPE_BEGIN_P (t))
2477 expand_start_bindings (2 * SCOPE_NULLIFIED_P (t));
2478 else if (SCOPE_END_P (t))
2479 expand_end_bindings (NULL_TREE, !SCOPE_NULLIFIED_P (t),
2480 SCOPE_PARTIAL_P (t));
2484 /* Clear this out so that finish_named_return_value can set it
2486 DECL_NAME (DECL_RESULT (current_function_decl)) = NULL_TREE;
2487 finish_named_return_value (TREE_OPERAND (t, 0),
2488 TREE_OPERAND (t, 1));
2492 my_friendly_abort (19990810);
2496 /* Restore saved state. */
2497 stmts_are_full_exprs_p = saved_stmts_are_full_exprs_p;
2499 /* Go on to the next statement in this scope. */
2506 /* Generate RTL for FN. */
2513 char *saved_input_filename;
2515 /* When the parser calls us after finishing the body of a template
2516 function, we don't really want to expand the body. When we're
2517 processing an in-class definition of an inline function,
2518 PROCESSING_TEMPLATE_DECL will no longer be set here, so we have
2519 to look at the function itself. */
2520 if (processing_template_decl
2521 || (DECL_LANG_SPECIFIC (fn)
2522 && DECL_TEMPLATE_INFO (fn)
2523 && uses_template_parms (DECL_TI_ARGS (fn))))
2525 /* Normally, collection only occurs in rest_of_compilation. So,
2526 if we don't collect here, we never collect junk generated
2527 during the processing of templates until we hit a
2528 non-template function. */
2533 /* There's no reason to do any of the work here if we're only doing
2534 semantic analysis; this code just generates RTL. */
2535 if (flag_syntax_only)
2538 /* Optimize the body of the function before expanding it. */
2539 optimize_function (fn);
2541 /* Save the current file name and line number. When we expand the
2542 body of the function, we'll set LINENO and INPUT_FILENAME so that
2543 error-mesages come out in the right places. */
2544 saved_lineno = lineno;
2545 saved_input_filename = input_filename;
2546 lineno = DECL_SOURCE_LINE (fn);
2547 input_filename = DECL_SOURCE_FILE (fn);
2549 start_function (NULL_TREE, fn, NULL_TREE, SF_PRE_PARSED | SF_EXPAND);
2550 store_parm_decls ();
2552 /* We don't need to redeclare __FUNCTION__, __PRETTY_FUNCTION__, or
2553 any of the other magic variables we set up when starting a
2555 current_function_name_declared = 1;
2557 /* Expand the body. */
2558 expand_stmt (DECL_SAVED_TREE (fn));
2560 /* Statements should always be full-expressions at the outermost set
2561 of curly braces for a function. */
2562 my_friendly_assert (stmts_are_full_exprs_p, 19990831);
2564 /* The outermost statement for a function contains the line number
2565 recorded when we finished processing the function. */
2566 lineno = STMT_LINENO (DECL_SAVED_TREE (fn));
2568 /* Generate code for the function. */
2569 finish_function (lineno, 0);
2571 /* If possible, obliterate the body of the function so that it can
2572 be garbage collected. */
2573 if (flag_dump_translation_unit)
2574 /* Keep the body; we're going to dump it. */
2576 else if (DECL_INLINE (fn) && flag_inline_trees)
2577 /* We might need the body of this function so that we can expand
2578 it inline somewhere else. */
2581 /* We don't need the body; blow it away. */
2582 DECL_SAVED_TREE (fn) = NULL_TREE;
2584 /* And restore the current source position. */
2585 lineno = saved_lineno;
2586 input_filename = saved_input_filename;