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 *));
52 /* Record the fact that STMT was the last statement added to the
55 #define SET_LAST_STMT(stmt) \
56 (current_stmt_tree->x_last_stmt = (stmt))
58 /* When parsing a template, LAST_TREE contains the last statement
59 parsed. These are chained together through the TREE_CHAIN field,
60 but often need to be re-organized since the parse is performed
61 bottom-up. This macro makes LAST_TREE the indicated SUBSTMT of
64 #define RECHAIN_STMTS(stmt, substmt) \
66 substmt = TREE_CHAIN (stmt); \
67 TREE_CHAIN (stmt) = NULL_TREE; \
68 SET_LAST_STMT (stmt); \
71 /* Finish processing the COND, the SUBSTMT condition for STMT. */
73 #define FINISH_COND(cond, stmt, substmt) \
75 if (last_tree != stmt) \
77 RECHAIN_STMTS (stmt, substmt); \
78 if (!processing_template_decl) \
80 cond = build_tree_list (substmt, cond); \
88 /* T is a statement. Add it to the statement-tree. */
94 /* Add T to the statement-tree. */
95 TREE_CHAIN (last_tree
) = t
;
98 /* When we expand a statement-tree, we must know whether or not the
99 statements are full-expresions. We record that fact here. */
100 if (building_stmt_tree ())
101 STMT_IS_FULL_EXPR_P (last_tree
) = stmts_are_full_exprs_p
;
104 /* COND is the condition-expression for an if, while, etc.,
105 statement. Convert it to a boolean value, if appropriate. */
108 maybe_convert_cond (cond
)
111 /* Empty conditions remain empty. */
115 /* Wait until we instantiate templates before doing conversion. */
116 if (processing_template_decl
)
119 /* Do the conversion. */
120 cond
= convert_from_reference (cond
);
121 return condition_conversion (cond
);
124 /* Finish an expression-statement, whose EXPRESSION is as indicated. */
127 finish_expr_stmt (expr
)
130 if (expr
!= NULL_TREE
)
132 if (building_stmt_tree ())
134 /* Do default conversion if safe and possibly important,
135 in case within ({...}). */
136 if (!processing_template_decl
137 && !stmts_are_full_exprs_p
138 && ((TREE_CODE (TREE_TYPE (expr
)) == ARRAY_TYPE
140 || TREE_CODE (TREE_TYPE (expr
)) == FUNCTION_TYPE
))
141 expr
= default_conversion (expr
);
143 if (!processing_template_decl
)
144 expr
= break_out_cleanups (expr
);
146 add_tree (build_min_nt (EXPR_STMT
, expr
));
150 emit_line_note (input_filename
, lineno
);
152 if (stmts_are_full_exprs_p
)
153 expand_start_target_temps ();
155 cplus_expand_expr_stmt (expr
);
157 if (stmts_are_full_exprs_p
)
158 expand_end_target_temps ();
164 /* This was an expression-statement, so we save the type of the
166 last_expr_type
= expr
? TREE_TYPE (expr
) : NULL_TREE
;
169 /* Begin an if-statement. Returns a newly created IF_STMT if
179 if (building_stmt_tree ())
181 r
= build_min_nt (IF_STMT
, NULL_TREE
, NULL_TREE
, NULL_TREE
);
190 /* Process the COND of an if-statement, which may be given by
194 finish_if_stmt_cond (cond
, if_stmt
)
198 cond
= maybe_convert_cond (cond
);
200 if (building_stmt_tree ())
201 FINISH_COND (cond
, if_stmt
, IF_COND (if_stmt
));
204 emit_line_note (input_filename
, lineno
);
205 expand_start_cond (cond
, 0);
209 /* Finish the then-clause of an if-statement, which may be given by
213 finish_then_clause (if_stmt
)
216 if (building_stmt_tree ())
218 RECHAIN_STMTS (if_stmt
, THEN_CLAUSE (if_stmt
));
219 SET_LAST_STMT (if_stmt
);
226 /* Begin the else-clause of an if-statement. */
231 if (!building_stmt_tree ())
232 expand_start_else ();
235 /* Finish the else-clause of an if-statement, which may be given by
239 finish_else_clause (if_stmt
)
242 if (building_stmt_tree ())
243 RECHAIN_STMTS (if_stmt
, ELSE_CLAUSE (if_stmt
));
246 /* Finsh an if-statement. */
251 if (!building_stmt_tree ())
258 /* Begin a while-statement. Returns a newly created WHILE_STMT if
266 if (building_stmt_tree ())
268 r
= build_min_nt (WHILE_STMT
, NULL_TREE
, NULL_TREE
);
274 emit_line_note (input_filename
, lineno
);
275 expand_start_loop (1);
284 /* Process the COND of a while-statement, which may be given by
288 finish_while_stmt_cond (cond
, while_stmt
)
292 cond
= maybe_convert_cond (cond
);
294 if (building_stmt_tree ())
295 FINISH_COND (cond
, while_stmt
, WHILE_COND (while_stmt
));
298 emit_line_note (input_filename
, lineno
);
299 expand_exit_loop_if_false (0, cond
);
302 /* If COND wasn't a declaration, clear out the
303 block we made for it and start a new one here so the
304 optimization in expand_end_loop will work. */
305 if (getdecls () == NULL_TREE
)
312 /* Finish a while-statement, which may be given by WHILE_STMT. */
315 finish_while_stmt (while_stmt
)
320 if (building_stmt_tree ())
321 RECHAIN_STMTS (while_stmt
, WHILE_BODY (while_stmt
));
327 /* Begin a do-statement. Returns a newly created DO_STMT if
333 if (building_stmt_tree ())
335 tree r
= build_min_nt (DO_STMT
, NULL_TREE
, NULL_TREE
);
342 emit_line_note (input_filename
, lineno
);
343 expand_start_loop_continue_elsewhere (1);
348 /* Finish the body of a do-statement, which may be given by DO_STMT. */
351 finish_do_body (do_stmt
)
354 if (building_stmt_tree ())
355 RECHAIN_STMTS (do_stmt
, DO_BODY (do_stmt
));
357 expand_loop_continue_here ();
360 /* Finish a do-statement, which may be given by DO_STMT, and whose
361 COND is as indicated. */
364 finish_do_stmt (cond
, do_stmt
)
368 cond
= maybe_convert_cond (cond
);
370 if (building_stmt_tree ())
371 DO_COND (do_stmt
) = cond
;
374 emit_line_note (input_filename
, lineno
);
375 expand_exit_loop_if_false (0, cond
);
382 /* Finish a return-statement. The EXPRESSION returned, if any, is as
386 finish_return_stmt (expr
)
389 if (doing_semantic_analysis_p () && !processing_template_decl
)
390 expr
= check_return_expr (expr
);
392 if (doing_semantic_analysis_p () && !processing_template_decl
)
394 if (DECL_CONSTRUCTOR_P (current_function_decl
) && ctor_label
)
396 /* Even returns without a value in a constructor must return
397 `this'. We accomplish this by sending all returns in a
398 constructor to the CTOR_LABEL; finish_function emits code to
399 return a value there. When we finally generate the real
400 return statement, CTOR_LABEL is no longer set, and we fall
401 through into the normal return-processing code below. */
402 finish_goto_stmt (ctor_label
);
405 else if (DECL_DESTRUCTOR_P (current_function_decl
))
407 /* Similarly, all destructors must run destructors for
408 base-classes before returning. So, all returns in a
409 destructor get sent to the DTOR_LABEL; finsh_function emits
410 code to return a value there. */
411 finish_goto_stmt (dtor_label
);
416 if (building_stmt_tree ())
417 add_tree (build_min_nt (RETURN_STMT
, expr
));
420 emit_line_note (input_filename
, lineno
);
421 c_expand_return (expr
);
427 /* Begin a for-statement. Returns a new FOR_STMT if appropriate. */
434 if (building_stmt_tree ())
436 r
= build_min_nt (FOR_STMT
, NULL_TREE
, NULL_TREE
,
437 NULL_TREE
, NULL_TREE
);
443 if (flag_new_for_scope
> 0)
446 note_level_for_for ();
452 /* Finish the for-init-statement of a for-statement, which may be
453 given by FOR_STMT. */
456 finish_for_init_stmt (for_stmt
)
459 if (building_stmt_tree ())
461 if (last_tree
!= for_stmt
)
462 RECHAIN_STMTS (for_stmt
, FOR_INIT_STMT (for_stmt
));
467 emit_line_note (input_filename
, lineno
);
468 expand_start_loop_continue_elsewhere (1);
474 /* Finish the COND of a for-statement, which may be given by
478 finish_for_cond (cond
, for_stmt
)
482 cond
= maybe_convert_cond (cond
);
484 if (building_stmt_tree ())
485 FINISH_COND (cond
, for_stmt
, FOR_COND (for_stmt
));
488 emit_line_note (input_filename
, lineno
);
490 expand_exit_loop_if_false (0, cond
);
493 /* If the cond wasn't a declaration, clear out the
494 block we made for it and start a new one here so the
495 optimization in expand_end_loop will work. */
496 if (getdecls () == NULL_TREE
)
503 /* Finish the increment-EXPRESSION in a for-statement, which may be
504 given by FOR_STMT. */
507 finish_for_expr (expr
, for_stmt
)
511 if (building_stmt_tree ())
512 FOR_EXPR (for_stmt
) = expr
;
515 /* Finish the body of a for-statement, which may be given by
516 FOR_STMT. The increment-EXPR for the loop must be
520 finish_for_stmt (expr
, for_stmt
)
524 /* Pop the scope for the body of the loop. */
527 if (building_stmt_tree ())
528 RECHAIN_STMTS (for_stmt
, FOR_BODY (for_stmt
));
531 emit_line_note (input_filename
, lineno
);
532 expand_loop_continue_here ();
534 finish_expr_stmt (expr
);
538 if (flag_new_for_scope
> 0)
544 /* Finish a break-statement. */
549 emit_line_note (input_filename
, lineno
);
550 if (building_stmt_tree ())
551 add_tree (build_min_nt (BREAK_STMT
));
552 else if ( ! expand_exit_something ())
553 cp_error ("break statement not within loop or switch");
556 /* Finish a continue-statement. */
559 finish_continue_stmt ()
561 emit_line_note (input_filename
, lineno
);
562 if (building_stmt_tree ())
563 add_tree (build_min_nt (CONTINUE_STMT
));
564 else if (! expand_continue_loop (0))
565 cp_error ("continue statement not within a loop");
568 /* Begin a switch-statement. Returns a new SWITCH_STMT if
576 if (building_stmt_tree ())
578 r
= build_min_nt (SWITCH_STMT
, NULL_TREE
, NULL_TREE
);
589 /* Finish the cond of a switch-statement. */
592 finish_switch_cond (cond
, switch_stmt
)
596 if (building_stmt_tree ())
598 if (!processing_template_decl
)
600 /* Convert the condition to an integer or enumeration type. */
601 cond
= build_expr_type_conversion (WANT_INT
| WANT_ENUM
, cond
, 1);
602 if (cond
== NULL_TREE
)
604 error ("switch quantity not an integer");
605 cond
= error_mark_node
;
607 if (cond
!= error_mark_node
)
612 cond
= default_conversion (cond
);
613 type
= TREE_TYPE (cond
);
614 idx
= get_unwidened (cond
, 0);
615 /* We can't strip a conversion from a signed type to an unsigned,
616 because if we did, int_fits_type_p would do the wrong thing
617 when checking case values for being in range,
618 and it's too hard to do the right thing. */
619 if (TREE_UNSIGNED (TREE_TYPE (cond
))
620 == TREE_UNSIGNED (TREE_TYPE (idx
)))
623 cond
= fold (build1 (CLEANUP_POINT_EXPR
, type
, cond
));
626 FINISH_COND (cond
, switch_stmt
, SWITCH_COND (switch_stmt
));
628 else if (cond
!= error_mark_node
)
630 emit_line_note (input_filename
, lineno
);
631 c_expand_start_case (cond
);
634 /* The code is in error, but we don't want expand_end_case to
636 c_expand_start_case (boolean_false_node
);
641 /* Finish the body of a switch-statement, which may be given by
642 SWITCH_STMT. The COND to switch on is indicated. */
645 finish_switch_stmt (cond
, switch_stmt
)
649 if (building_stmt_tree ())
650 RECHAIN_STMTS (switch_stmt
, SWITCH_BODY (switch_stmt
));
652 expand_end_case (cond
);
658 /* Finish a case-label. */
661 finish_case_label (low_value
, high_value
)
665 if (building_stmt_tree ())
667 /* Add a representation for the case label to the statement
669 add_tree (build_min_nt (CASE_LABEL
, low_value
, high_value
));
670 /* And warn about crossing initializations, etc. */
671 if (!processing_template_decl
)
672 define_case_label ();
676 do_case (low_value
, high_value
);
679 /* Finish a goto-statement. */
682 finish_goto_stmt (destination
)
685 if (TREE_CODE (destination
) == IDENTIFIER_NODE
)
686 destination
= lookup_label (destination
);
688 /* We warn about unused labels with -Wunused. That means we have to
689 mark the used labels as used. */
690 if (TREE_CODE (destination
) == LABEL_DECL
)
691 TREE_USED (destination
) = 1;
693 if (building_stmt_tree ())
695 if (TREE_CODE (destination
) != LABEL_DECL
)
696 /* We don't inline calls to functions with computed gotos.
697 Those functions are typically up to some funny business,
698 and may be depending on the labels being at particular
699 addresses, or some such. */
700 DECL_UNINLINABLE (current_function_decl
) = 1;
702 add_tree (build_min_nt (GOTO_STMT
, destination
));
706 emit_line_note (input_filename
, lineno
);
708 if (TREE_CODE (destination
) == LABEL_DECL
)
710 label_rtx (destination
);
711 expand_goto (destination
);
714 expand_computed_goto (destination
);
718 /* Begin a try-block. Returns a newly-created TRY_BLOCK if
724 if (building_stmt_tree ())
726 tree r
= build_min_nt (TRY_BLOCK
, NULL_TREE
,
733 emit_line_note (input_filename
, lineno
);
734 expand_start_try_stmts ();
739 /* Likewise, for a function-try-block. */
742 begin_function_try_block ()
744 if (building_stmt_tree ())
746 tree r
= build_min_nt (TRY_BLOCK
, NULL_TREE
,
748 FN_TRY_BLOCK_P (r
) = 1;
754 if (! current_function_parms_stored
)
756 expand_start_early_try_stmts ();
761 /* Finish a try-block, which may be given by TRY_BLOCK. */
764 finish_try_block (try_block
)
767 if (building_stmt_tree ())
768 RECHAIN_STMTS (try_block
, TRY_STMTS (try_block
));
770 expand_start_all_catch ();
773 /* Finish the body of a cleanup try-block, which may be given by
777 finish_cleanup_try_block (try_block
)
780 if (building_stmt_tree ())
781 RECHAIN_STMTS (try_block
, TRY_STMTS (try_block
));
784 /* Finish an implicitly generated try-block, with a cleanup is given
788 finish_cleanup (cleanup
, try_block
)
792 if (building_stmt_tree ())
794 TRY_HANDLERS (try_block
) = cleanup
;
795 CLEANUP_P (try_block
) = 1;
798 expand_eh_region_end (protect_with_terminate (cleanup
));
801 /* Likewise, for a function-try-block. */
804 finish_function_try_block (try_block
)
807 if (building_stmt_tree ())
809 if (TREE_CHAIN (try_block
)
810 && TREE_CODE (TREE_CHAIN (try_block
)) == CTOR_INITIALIZER
)
812 /* Chain the compound statement after the CTOR_INITIALIZER. */
813 TREE_CHAIN (TREE_CHAIN (try_block
)) = last_tree
;
814 /* And make the CTOR_INITIALIZER the body of the try-block. */
815 RECHAIN_STMTS (try_block
, TRY_STMTS (try_block
));
818 RECHAIN_STMTS (try_block
, TRY_STMTS (try_block
));
822 end_protect_partials ();
823 expand_start_all_catch ();
826 in_function_try_handler
= 1;
829 /* Finish a handler-sequence for a try-block, which may be given by
833 finish_handler_sequence (try_block
)
836 if (building_stmt_tree ())
837 RECHAIN_STMTS (try_block
, TRY_HANDLERS (try_block
));
839 expand_end_all_catch ();
842 /* Likewise, for a function-try-block. */
845 finish_function_handler_sequence (try_block
)
848 in_function_try_handler
= 0;
850 if (building_stmt_tree ())
851 RECHAIN_STMTS (try_block
, TRY_HANDLERS (try_block
));
853 expand_end_all_catch ();
856 /* Begin a handler. Returns a HANDLER if appropriate. */
863 if (building_stmt_tree ())
865 r
= build_min_nt (HANDLER
, NULL_TREE
, NULL_TREE
);
876 /* Finish the handler-parameters for a handler, which may be given by
877 HANDLER. DECL is the declaration for the catch parameter, or NULL
878 if this is a `catch (...)' clause. */
881 finish_handler_parms (decl
, handler
)
885 tree blocks
= NULL_TREE
;
887 if (processing_template_decl
)
891 decl
= pushdecl (decl
);
892 decl
= push_template_decl (decl
);
893 add_decl_stmt (decl
);
894 RECHAIN_STMTS (handler
, HANDLER_PARMS (handler
));
897 else if (building_stmt_tree ())
898 blocks
= expand_start_catch_block (decl
);
903 /* Note the beginning of a handler for TYPE. This function is called
904 at the point to which control should be transferred when an
905 appropriately-typed exception is thrown. */
908 begin_catch_block (type
)
911 if (building_stmt_tree ())
912 add_tree (build (START_CATCH_STMT
, type
));
914 start_catch_handler (type
);
917 /* Finish a handler, which may be given by HANDLER. The BLOCKs are
918 the return value from the matching call to finish_handler_parms. */
921 finish_handler (blocks
, handler
)
925 if (!processing_template_decl
)
927 if (building_stmt_tree ())
928 expand_end_catch_block (blocks
);
930 if (!building_stmt_tree ())
932 /* Fall to outside the try statement when done executing
933 handler and we fall off end of handler. This is jump
934 Lresume in the documentation. */
935 expand_goto (top_label_entry (&caught_return_label_stack
));
936 end_catch_handler ();
942 if (building_stmt_tree ())
943 RECHAIN_STMTS (handler
, HANDLER_BODY (handler
));
946 /* Begin a compound-statement. If HAS_NO_SCOPE is non-zero, the
947 compound-statement does not define a scope. Returns a new
948 COMPOUND_STMT if appropriate. */
951 begin_compound_stmt (has_no_scope
)
956 if (building_stmt_tree ())
958 r
= build_min_nt (COMPOUND_STMT
, NULL_TREE
);
961 COMPOUND_STMT_NO_SCOPE (r
) = 1;
966 last_expr_type
= NULL_TREE
;
971 /* Normally, we try hard to keep the BLOCK for a
972 statement-expression. But, if it's a statement-expression with
973 a scopeless block, there's nothing to keep, and we don't want
974 to accidentally keep a block *inside* the scopeless block. */
977 /* If this is the outermost block of the function, declare the
978 variables __FUNCTION__, __PRETTY_FUNCTION__, and so forth. */
980 && !current_function_name_declared
983 current_function_name_declared
= 1;
984 declare_function_name ();
991 /* Finish a compound-statement, which may be given by COMPOUND_STMT.
992 If HAS_NO_SCOPE is non-zero, the compound statement does not define
996 finish_compound_stmt (has_no_scope
, compound_stmt
)
1008 if (building_stmt_tree ())
1009 RECHAIN_STMTS (compound_stmt
, COMPOUND_BODY (compound_stmt
));
1011 /* When we call finish_stmt we will lose LAST_EXPR_TYPE. But, since
1012 the precise purpose of that variable is store the type of the
1013 last expression statement within the last compound statement, we
1014 preserve the value. */
1022 /* Finish an asm-statement, whose components are a CV_QUALIFIER, a
1023 STRING, some OUTPUT_OPERANDS, some INPUT_OPERANDS, and some
1027 finish_asm_stmt (cv_qualifier
, string
, output_operands
,
1028 input_operands
, clobbers
)
1031 tree output_operands
;
1032 tree input_operands
;
1035 if (TREE_CHAIN (string
))
1036 string
= combine_strings (string
);
1038 if (cv_qualifier
!= NULL_TREE
1039 && cv_qualifier
!= ridpointers
[(int) RID_VOLATILE
])
1041 cp_warning ("%s qualifier ignored on asm",
1042 IDENTIFIER_POINTER (cv_qualifier
));
1043 cv_qualifier
= NULL_TREE
;
1046 if (building_stmt_tree ())
1048 tree r
= build_min_nt (ASM_STMT
, cv_qualifier
, string
,
1049 output_operands
, input_operands
,
1055 emit_line_note (input_filename
, lineno
);
1056 if (output_operands
!= NULL_TREE
|| input_operands
!= NULL_TREE
1057 || clobbers
!= NULL_TREE
)
1061 for (t
= input_operands
; t
; t
= TREE_CHAIN (t
))
1062 TREE_VALUE (t
) = decay_conversion (TREE_VALUE (t
));
1064 c_expand_asm_operands (string
, output_operands
,
1067 cv_qualifier
!= NULL_TREE
,
1068 input_filename
, lineno
);
1071 expand_asm (string
);
1077 /* Finish a label with the indicated NAME. */
1080 finish_label_stmt (name
)
1083 tree decl
= define_label (input_filename
, lineno
, name
);
1085 if (building_stmt_tree ())
1086 add_tree (build_min_nt (LABEL_STMT
, decl
));
1088 expand_label (decl
);
1091 /* Finish a series of declarations for local labels. G++ allows users
1092 to declare "local" labels, i.e., labels with scope. This extension
1093 is useful when writing code involving statement-expressions. */
1096 finish_label_decl (name
)
1099 tree decl
= declare_local_label (name
);
1100 if (building_stmt_tree ())
1101 add_decl_stmt (decl
);
1104 /* Create a declaration statement for the declaration given by the
1108 add_decl_stmt (decl
)
1113 /* We need the type to last until instantiation time. */
1114 decl_stmt
= build_min_nt (DECL_STMT
, decl
);
1115 add_tree (decl_stmt
);
1118 /* We're in a constructor, and have just constructed a a subobject of
1119 *THIS. CLEANUP is code to run if an exception is thrown before the
1120 end of the current function is reached. */
1123 finish_subobject (cleanup
)
1126 if (building_stmt_tree ())
1128 tree r
= build_min_nt (SUBOBJECT
, cleanup
);
1132 add_partial_entry (cleanup
);
1135 /* When DECL goes out of scope, make sure that CLEANUP is executed. */
1138 finish_decl_cleanup (decl
, cleanup
)
1142 if (building_stmt_tree ())
1143 add_tree (build_min_nt (CLEANUP_STMT
, decl
, cleanup
));
1145 || (DECL_SIZE (decl
) && TREE_TYPE (decl
) != error_mark_node
))
1146 expand_decl_cleanup (decl
, cleanup
);
1149 /* Bind a name and initialization to the return value of
1150 the current function. */
1153 finish_named_return_value (return_id
, init
)
1154 tree return_id
, init
;
1156 tree decl
= DECL_RESULT (current_function_decl
);
1159 /* Give this error as many times as there are occurrences,
1160 so that users can use Emacs compilation buffers to find
1161 and fix all such places. */
1162 pedwarn ("ISO C++ does not permit named return values");
1164 if (return_id
!= NULL_TREE
)
1166 if (DECL_NAME (decl
) == NULL_TREE
)
1168 DECL_NAME (decl
) = return_id
;
1169 DECL_ASSEMBLER_NAME (decl
) = return_id
;
1173 cp_error ("return identifier `%D' already in place", return_id
);
1178 /* Can't let this happen for constructors. */
1179 if (DECL_CONSTRUCTOR_P (current_function_decl
))
1181 error ("can't redefine default return value for constructors");
1185 /* If we have a named return value, put that in our scope as well. */
1186 if (DECL_NAME (decl
) != NULL_TREE
)
1188 /* Let `cp_finish_decl' know that this initializer is ok. */
1189 DECL_INITIAL (decl
) = init
;
1190 if (doing_semantic_analysis_p ())
1193 if (building_stmt_tree ())
1194 add_tree (build_min_nt (RETURN_INIT
, return_id
, init
));
1197 cp_finish_decl (decl
, init
, NULL_TREE
, 0);
1198 store_return_init (decl
);
1202 /* Don't use tree-inlining for functions with named return values.
1203 That doesn't work properly because we don't do any translation of
1204 the RETURN_INITs when they are copied. */
1205 DECL_UNINLINABLE (current_function_decl
) = 1;
1208 /* Cache the value of this class's main virtual function table pointer
1209 in a register variable. This will save one indirection if a
1210 more than one virtual function call is made this function. */
1215 my_friendly_assert (doing_semantic_analysis_p (), 19990919);
1217 /* If we've already done this, there's no need to do it again. */
1221 if (DECL_CONSTRUCTOR_P (current_function_decl
))
1223 if (processing_template_decl
)
1224 add_tree (build_min_nt
1226 current_member_init_list
, current_base_init_list
));
1231 /* Mark the beginning of the constructor. */
1232 ctor_stmt
= build_min_nt (CTOR_STMT
);
1233 CTOR_BEGIN_P (ctor_stmt
) = 1;
1234 add_tree (ctor_stmt
);
1236 /* And actually initialize the base-classes and members. */
1237 finish_expr_stmt (emit_base_init (current_class_type
));
1240 else if (DECL_DESTRUCTOR_P (current_function_decl
)
1241 && !processing_template_decl
)
1247 /* If the dtor is empty, and we know there is not possible way we
1248 could use any vtable entries, before they are possibly set by
1249 a base class dtor, we don't have to setup the vtables, as we
1250 know that any base class dtoring will set up any vtables it
1251 needs. We avoid MI, because one base class dtor can do a
1252 virtual dispatch to an overridden function that would need to
1253 have a non-related vtable set up, we cannot avoid setting up
1254 vtables in that case. We could change this to see if there is
1256 if_stmt
= begin_if_stmt ();
1258 /* If it is not safe to avoid setting up the vtables, then
1259 someone will change the condition to be boolean_true_node.
1260 (Actually, for now, we do not have code to set the condition
1261 appropriately, so we just assume that we always need to
1262 initialize the vtables.) */
1263 finish_if_stmt_cond (boolean_true_node
, if_stmt
);
1264 current_vcalls_possible_p
= &IF_COND (if_stmt
);
1266 /* Don't declare __PRETTY_FUNCTION__ and friends here when we
1267 open the block for the if-body. */
1268 saved_cfnd
= current_function_name_declared
;
1269 current_function_name_declared
= 1;
1270 compound_stmt
= begin_compound_stmt (/*has_no_scope=*/0);
1271 current_function_name_declared
= saved_cfnd
;
1273 /* Make all virtual function table pointers in non-virtual base
1274 classes point to CURRENT_CLASS_TYPE's virtual function
1276 initialize_vtbl_ptrs (current_class_type
,
1279 finish_compound_stmt (/*has_no_scope=*/0, compound_stmt
);
1280 finish_then_clause (if_stmt
);
1284 /* Always keep the BLOCK node associated with the outermost pair of
1285 curly braces of a function. These are needed for correct
1286 operation of dwarfout.c. */
1287 keep_next_level (1);
1289 /* The virtual function tables are set up now. */
1293 /* Add a scope-statement to the statement-tree. BEGIN_P indicates
1294 whether this statements opens or closes a scope. PARTIAL_P is true
1295 for a partial scope, i.e, the scope that begins after a label when
1296 an object that needs a cleanup is created. If BEGIN_P is nonzero,
1297 returns a new TREE_LIST representing the top of the SCOPE_STMT
1298 stack. The TREE_PURPOSE is the new SCOPE_STMT. If BEGIN_P is
1299 zero, returns a TREE_LIST whose TREE_VALUE is the new SCOPE_STMT,
1300 and whose TREE_PURPOSE is the matching SCOPE_STMT iwth
1301 SCOPE_BEGIN_P set. */
1304 add_scope_stmt (begin_p
, partial_p
)
1311 /* Build the statement. */
1312 ss
= build_min_nt (SCOPE_STMT
, NULL_TREE
);
1313 SCOPE_BEGIN_P (ss
) = begin_p
;
1314 SCOPE_PARTIAL_P (ss
) = partial_p
;
1316 /* Keep the scope stack up to date. */
1319 current_scope_stmt_stack
1320 = tree_cons (ss
, NULL_TREE
, current_scope_stmt_stack
);
1321 top
= current_scope_stmt_stack
;
1325 top
= current_scope_stmt_stack
;
1326 TREE_VALUE (top
) = ss
;
1327 current_scope_stmt_stack
= TREE_CHAIN (top
);
1330 /* Add the new statement to the statement-tree. */
1336 /* Begin a new scope. */
1341 if (!building_stmt_tree ())
1343 emit_line_note (input_filename
, lineno
);
1346 if (stmts_are_full_exprs_p
)
1349 if (!building_stmt_tree ()
1350 && !cfun
->x_whole_function_mode_p
)
1351 my_friendly_abort (19991129);
1353 if (building_stmt_tree () && !processing_template_decl
)
1354 add_scope_stmt (/*begin_p=*/1, /*partial_p=*/0);
1358 /* Finish a scope. */
1363 tree block
= NULL_TREE
;
1365 if (stmts_are_full_exprs_p
)
1369 if (building_stmt_tree () && !processing_template_decl
)
1370 scope_stmts
= add_scope_stmt (/*begin_p=*/0, /*partial_p=*/0);
1372 scope_stmts
= NULL_TREE
;
1374 block
= poplevel (kept_level_p (), 1, 0);
1375 if (block
&& !processing_template_decl
)
1377 SCOPE_STMT_BLOCK (TREE_PURPOSE (scope_stmts
)) = block
;
1378 SCOPE_STMT_BLOCK (TREE_VALUE (scope_stmts
)) = block
;
1385 /* Finish a parenthesized expression EXPR. */
1388 finish_parenthesized_expr (expr
)
1391 if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (TREE_CODE (expr
))))
1392 /* This inhibits warnings in truthvalue_conversion. */
1393 C_SET_EXP_ORIGINAL_CODE (expr
, ERROR_MARK
);
1398 /* Begin a statement-expression. The value returned must be passed to
1399 finish_stmt_expr. */
1404 /* If we're outside a function, we won't have a statement-tree to
1405 work with. But, if we see a statement-expression we need to
1407 if (! cfun
&& !last_tree
)
1408 begin_stmt_tree (&scope_chain
->x_saved_tree
);
1410 keep_next_level (1);
1411 /* If we're building a statement tree, then the upcoming compound
1412 statement will be chained onto the tree structure, starting at
1413 last_tree. We return last_tree so that we can later unhook the
1414 compound statement. */
1415 return building_stmt_tree () ? last_tree
: expand_start_stmt_expr();
1418 /* Finish a statement-expression. RTL_EXPR should be the value
1419 returned by the previous begin_stmt_expr; EXPR is the
1420 statement-expression. Returns an expression representing the
1421 statement-expression. */
1424 finish_stmt_expr (rtl_expr
)
1429 if (!building_stmt_tree ())
1430 rtl_expr
= expand_end_stmt_expr (rtl_expr
);
1432 if (building_stmt_tree ())
1434 /* If the last thing in the statement-expression was not an
1435 expression-statement, then it has type `void'. */
1436 if (!last_expr_type
)
1437 last_expr_type
= void_type_node
;
1438 result
= build_min (STMT_EXPR
, last_expr_type
, last_tree
);
1439 TREE_SIDE_EFFECTS (result
) = 1;
1441 /* Remove the compound statement from the tree structure; it is
1442 now saved in the STMT_EXPR. */
1443 SET_LAST_STMT (rtl_expr
);
1444 TREE_CHAIN (last_tree
) = NULL_TREE
;
1449 /* If we created a statement-tree for this statement-expression,
1452 && TREE_CHAIN (scope_chain
->x_saved_tree
) == NULL_TREE
)
1453 finish_stmt_tree (&scope_chain
->x_saved_tree
);
1458 /* Finish a call to FN with ARGS. Returns a representation of the
1462 finish_call_expr (fn
, args
, koenig
)
1471 if (TREE_CODE (fn
) == BIT_NOT_EXPR
)
1472 fn
= build_x_unary_op (BIT_NOT_EXPR
, TREE_OPERAND (fn
, 0));
1473 else if (TREE_CODE (fn
) != TEMPLATE_ID_EXPR
)
1474 fn
= do_identifier (fn
, 2, args
);
1476 result
= build_x_function_call (fn
, args
, current_class_ref
);
1478 if (TREE_CODE (result
) == CALL_EXPR
1479 && (! TREE_TYPE (result
)
1480 || TREE_CODE (TREE_TYPE (result
)) != VOID_TYPE
))
1481 result
= require_complete_type (result
);
1486 /* Finish a call to a postfix increment or decrement or EXPR. (Which
1487 is indicated by CODE, which should be POSTINCREMENT_EXPR or
1488 POSTDECREMENT_EXPR.) */
1491 finish_increment_expr (expr
, code
)
1493 enum tree_code code
;
1495 /* If we get an OFFSET_REF, turn it into what it really means (e.g.,
1496 a COMPONENT_REF). This way if we've got, say, a reference to a
1497 static member that's being operated on, we don't end up trying to
1498 find a member operator for the class it's in. */
1500 if (TREE_CODE (expr
) == OFFSET_REF
)
1501 expr
= resolve_offset_ref (expr
);
1502 return build_x_unary_op (code
, expr
);
1505 /* Finish a use of `this'. Returns an expression for `this'. */
1512 if (current_class_ptr
)
1514 #ifdef WARNING_ABOUT_CCD
1515 TREE_USED (current_class_ptr
) = 1;
1517 result
= current_class_ptr
;
1519 else if (current_function_decl
1520 && DECL_STATIC_FUNCTION_P (current_function_decl
))
1522 error ("`this' is unavailable for static member functions");
1523 result
= error_mark_node
;
1527 if (current_function_decl
)
1528 error ("invalid use of `this' in non-member function");
1530 error ("invalid use of `this' at top level");
1531 result
= error_mark_node
;
1537 /* Finish a member function call using OBJECT and ARGS as arguments to
1538 FN. Returns an expression for the call. */
1541 finish_object_call_expr (fn
, object
, args
)
1547 /* This is a future direction of this code, but because
1548 build_x_function_call cannot always undo what is done in
1549 build_component_ref entirely yet, we cannot do this. */
1551 tree real_fn
= build_component_ref (object
, fn
, NULL_TREE
, 1);
1552 return finish_call_expr (real_fn
, args
);
1554 if (DECL_DECLARES_TYPE_P (fn
))
1556 if (processing_template_decl
)
1557 /* This can happen on code like:
1560 template <class T> void f(T t) {
1564 We just grab the underlying IDENTIFIER. */
1565 fn
= DECL_NAME (fn
);
1568 cp_error ("calling type `%T' like a method", fn
);
1569 return error_mark_node
;
1573 return build_method_call (object
, fn
, args
, NULL_TREE
, LOOKUP_NORMAL
);
1577 /* Finish a qualified member function call using OBJECT and ARGS as
1578 arguments to FN. Returns an expressino for the call. */
1581 finish_qualified_object_call_expr (fn
, object
, args
)
1586 return build_scoped_method_call (object
, TREE_OPERAND (fn
, 0),
1587 TREE_OPERAND (fn
, 1), args
);
1590 /* Finish a pseudo-destructor call expression of OBJECT, with SCOPE
1591 being the scope, if any, of DESTRUCTOR. Returns an expression for
1595 finish_pseudo_destructor_call_expr (object
, scope
, destructor
)
1600 if (processing_template_decl
)
1601 return build_min_nt (PSEUDO_DTOR_EXPR
, object
, scope
, destructor
);
1603 if (scope
&& scope
!= destructor
)
1604 cp_error ("destructor specifier `%T::~%T()' must have matching names",
1607 if ((scope
== NULL_TREE
|| IDENTIFIER_GLOBAL_VALUE (destructor
))
1608 && (TREE_CODE (TREE_TYPE (object
)) !=
1609 TREE_CODE (TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (destructor
)))))
1610 cp_error ("`%E' is not of type `%T'", object
, destructor
);
1612 return cp_convert (void_type_node
, object
);
1615 /* Finish a call to a globally qualified member function FN using
1616 ARGS. Returns an expression for the call. */
1619 finish_qualified_call_expr (fn
, args
)
1623 if (processing_template_decl
)
1624 return build_min_nt (CALL_EXPR
, fn
, args
, NULL_TREE
);
1626 return build_member_call (TREE_OPERAND (fn
, 0),
1627 TREE_OPERAND (fn
, 1),
1631 /* Finish an expression taking the address of LABEL. Returns an
1632 expression for the address. */
1635 finish_label_address_expr (label
)
1640 label
= lookup_label (label
);
1641 if (label
== NULL_TREE
)
1642 result
= null_pointer_node
;
1645 TREE_USED (label
) = 1;
1646 result
= build1 (ADDR_EXPR
, ptr_type_node
, label
);
1647 TREE_CONSTANT (result
) = 1;
1648 /* This function cannot be inlined. All jumps to the addressed
1649 label should wind up at the same point. */
1650 DECL_UNINLINABLE (current_function_decl
) = 1;
1656 /* Finish an expression of the form CODE EXPR. */
1659 finish_unary_op_expr (code
, expr
)
1660 enum tree_code code
;
1663 tree result
= build_x_unary_op (code
, expr
);
1664 /* Inside a template, build_x_unary_op does not fold the
1665 expression. So check whether the result is folded before
1666 setting TREE_NEGATED_INT. */
1667 if (code
== NEGATE_EXPR
&& TREE_CODE (expr
) == INTEGER_CST
1668 && TREE_CODE (result
) == INTEGER_CST
1669 && !TREE_UNSIGNED (TREE_TYPE (result
))
1670 && INT_CST_LT (result
, integer_zero_node
))
1671 TREE_NEGATED_INT (result
) = 1;
1672 overflow_warning (result
);
1676 /* Finish an id-expression. */
1679 finish_id_expr (expr
)
1682 if (TREE_CODE (expr
) == IDENTIFIER_NODE
)
1683 expr
= do_identifier (expr
, 1, NULL_TREE
);
1688 static tree current_type_lookups
;
1690 /* Perform deferred access control for types used in the type of a
1694 deferred_type_access_control ()
1696 tree lookup
= type_lookups
;
1698 if (lookup
== error_mark_node
)
1701 for (; lookup
; lookup
= TREE_CHAIN (lookup
))
1702 enforce_access (TREE_PURPOSE (lookup
), TREE_VALUE (lookup
));
1706 decl_type_access_control (decl
)
1711 if (type_lookups
== error_mark_node
)
1714 save_fn
= current_function_decl
;
1716 if (decl
&& TREE_CODE (decl
) == FUNCTION_DECL
)
1717 current_function_decl
= decl
;
1719 deferred_type_access_control ();
1721 current_function_decl
= save_fn
;
1723 /* Now strip away the checks for the current declarator; they were
1724 added to type_lookups after typed_declspecs saved the copy that
1725 ended up in current_type_lookups. */
1726 type_lookups
= current_type_lookups
;
1730 save_type_access_control (lookups
)
1733 current_type_lookups
= lookups
;
1736 /* Begin a function definition declared with DECL_SPECS and
1737 DECLARATOR. Returns non-zero if the function-declaration is
1741 begin_function_definition (decl_specs
, declarator
)
1748 split_specs_attrs (decl_specs
, &specs
, &attrs
);
1749 if (!start_function (specs
, declarator
, attrs
, SF_DEFAULT
))
1752 deferred_type_access_control ();
1753 type_lookups
= error_mark_node
;
1755 reinit_parse_for_function ();
1756 /* The things we're about to see are not directly qualified by any
1757 template headers we've seen thus far. */
1758 reset_specialization ();
1763 /* Begin a constructor declarator of the form `SCOPE::NAME'. Returns
1767 begin_constructor_declarator (scope
, name
)
1771 tree result
= build_parse_node (SCOPE_REF
, scope
, name
);
1772 enter_scope_of (result
);
1776 /* Finish an init-declarator. Returns a DECL. */
1779 finish_declarator (declarator
, declspecs
, attributes
,
1780 prefix_attributes
, initialized
)
1784 tree prefix_attributes
;
1787 return start_decl (declarator
, declspecs
, initialized
, attributes
,
1791 /* Finish a translation unit. */
1794 finish_translation_unit ()
1796 /* In case there were missing closebraces,
1797 get us back to the global binding level. */
1799 while (current_namespace
!= global_namespace
)
1804 /* Finish a template type parameter, specified as AGGR IDENTIFIER.
1805 Returns the parameter. */
1808 finish_template_type_parm (aggr
, identifier
)
1812 if (aggr
!= class_type_node
)
1814 pedwarn ("template type parameters must use the keyword `class' or `typename'");
1815 aggr
= class_type_node
;
1818 return build_tree_list (aggr
, identifier
);
1821 /* Finish a template template parameter, specified as AGGR IDENTIFIER.
1822 Returns the parameter. */
1825 finish_template_template_parm (aggr
, identifier
)
1829 tree decl
= build_decl (TYPE_DECL
, identifier
, NULL_TREE
);
1830 tree tmpl
= build_lang_decl (TEMPLATE_DECL
, identifier
, NULL_TREE
);
1831 DECL_TEMPLATE_PARMS (tmpl
) = current_template_parms
;
1832 DECL_TEMPLATE_RESULT (tmpl
) = decl
;
1833 SET_DECL_ARTIFICIAL (decl
);
1834 end_template_decl ();
1836 return finish_template_type_parm (aggr
, tmpl
);
1839 /* Finish a parameter list, indicated by PARMS. If ELLIPSIS is
1840 non-zero, the parameter list was terminated by a `...'. */
1843 finish_parmlist (parms
, ellipsis
)
1848 chainon (parms
, void_list_node
);
1849 /* We mark the PARMS as a parmlist so that declarator processing can
1850 disambiguate certain constructs. */
1851 if (parms
!= NULL_TREE
)
1852 TREE_PARMLIST (parms
) = 1;
1857 /* Begin a class definition, as indicated by T. */
1860 begin_class_definition (t
)
1863 if (t
== error_mark_node
1864 || ! IS_AGGR_TYPE (t
))
1866 t
= make_aggr_type (RECORD_TYPE
);
1867 pushtag (make_anon_name (), t
, 0);
1870 /* In a definition of a member class template, we will get here with an
1871 implicit typename, a TYPENAME_TYPE with a type. */
1872 if (TREE_CODE (t
) == TYPENAME_TYPE
)
1875 /* If we generated a partial instantiation of this type, but now
1876 we're seeing a real definition, we're actually looking at a
1877 partial specialization. Consider:
1879 template <class T, class U>
1885 template <class T, class U>
1888 typename X<Y<T, U> >::A a;
1891 template <class T, class U>
1896 We have to undo the effects of the previous partial
1898 if (PARTIAL_INSTANTIATION_P (t
))
1902 /* Unfortunately, when we're not in pedantic mode, we
1903 attempt to actually fill in some of the fields of the
1904 partial instantiation, in order to support the implicit
1905 typename extension. Clear those fields now, in
1906 preparation for the definition here. The fields cleared
1907 here must match those set in instantiate_class_template.
1908 Look for a comment mentioning begin_class_definition
1910 TYPE_BINFO_BASETYPES (t
) = NULL_TREE
;
1911 TYPE_FIELDS (t
) = NULL_TREE
;
1912 TYPE_METHODS (t
) = NULL_TREE
;
1913 CLASSTYPE_TAGS (t
) = NULL_TREE
;
1914 TYPE_SIZE (t
) = NULL_TREE
;
1917 /* This isn't a partial instantiation any more. */
1918 PARTIAL_INSTANTIATION_P (t
) = 0;
1920 /* If this type was already complete, and we see another definition,
1922 else if (COMPLETE_TYPE_P (t
))
1923 duplicate_tag_error (t
);
1925 /* Update the location of the decl. */
1926 DECL_SOURCE_FILE (TYPE_NAME (t
)) = input_filename
;
1927 DECL_SOURCE_LINE (TYPE_NAME (t
)) = lineno
;
1929 if (TYPE_BEING_DEFINED (t
))
1931 t
= make_aggr_type (TREE_CODE (t
));
1932 pushtag (TYPE_IDENTIFIER (t
), t
, 0);
1934 maybe_process_partial_specialization (t
);
1936 TYPE_BEING_DEFINED (t
) = 1;
1937 /* Reset the interface data, at the earliest possible
1938 moment, as it might have been set via a class foo;
1941 tree name
= TYPE_IDENTIFIER (t
);
1943 if (! ANON_AGGRNAME_P (name
))
1945 CLASSTYPE_INTERFACE_ONLY (t
) = interface_only
;
1946 SET_CLASSTYPE_INTERFACE_UNKNOWN_X
1947 (t
, interface_unknown
);
1950 /* Only leave this bit clear if we know this
1951 class is part of an interface-only specification. */
1952 if (! CLASSTYPE_INTERFACE_KNOWN (t
)
1953 || ! CLASSTYPE_INTERFACE_ONLY (t
))
1954 CLASSTYPE_VTABLE_NEEDS_WRITING (t
) = 1;
1957 tmp
= TYPE_IDENTIFIER ($
<ttype
>0);
1958 if (tmp
&& IDENTIFIER_TEMPLATE (tmp
))
1959 overload_template_name (tmp
, 1);
1961 reset_specialization();
1963 /* Make a declaration for this class in its own scope. */
1964 build_self_reference ();
1969 /* Finish the member declaration given by DECL. */
1972 finish_member_declaration (decl
)
1975 if (decl
== error_mark_node
|| decl
== NULL_TREE
)
1978 if (decl
== void_type_node
)
1979 /* The COMPONENT was a friend, not a member, and so there's
1980 nothing for us to do. */
1983 /* We should see only one DECL at a time. */
1984 my_friendly_assert (TREE_CHAIN (decl
) == NULL_TREE
, 0);
1986 /* Set up access control for DECL. */
1988 = (current_access_specifier
== access_private_node
);
1989 TREE_PROTECTED (decl
)
1990 = (current_access_specifier
== access_protected_node
);
1991 if (TREE_CODE (decl
) == TEMPLATE_DECL
)
1993 TREE_PRIVATE (DECL_RESULT (decl
)) = TREE_PRIVATE (decl
);
1994 TREE_PROTECTED (DECL_RESULT (decl
)) = TREE_PROTECTED (decl
);
1997 /* Mark the DECL as a member of the current class. */
1998 DECL_CONTEXT (decl
) = current_class_type
;
2000 /* Put functions on the TYPE_METHODS list and everything else on the
2001 TYPE_FIELDS list. Note that these are built up in reverse order.
2002 We reverse them (to obtain declaration order) in finish_struct. */
2003 if (TREE_CODE (decl
) == FUNCTION_DECL
2004 || DECL_FUNCTION_TEMPLATE_P (decl
))
2006 /* We also need to add this function to the
2007 CLASSTYPE_METHOD_VEC. */
2008 add_method (current_class_type
, 0, decl
);
2010 TREE_CHAIN (decl
) = TYPE_METHODS (current_class_type
);
2011 TYPE_METHODS (current_class_type
) = decl
;
2015 /* All TYPE_DECLs go at the end of TYPE_FIELDS. Ordinary fields
2016 go at the beginning. The reason is that lookup_field_1
2017 searches the list in order, and we want a field name to
2018 override a type name so that the "struct stat hack" will
2019 work. In particular:
2021 struct S { enum E { }; int E } s;
2024 is legal. In addition, the FIELD_DECLs must be maintained in
2025 declaration order so that class layout works as expected.
2026 However, we don't need that order until class layout, so we
2027 save a little time by putting FIELD_DECLs on in reverse order
2028 here, and then reversing them in finish_struct_1. (We could
2029 also keep a pointer to the correct insertion points in the
2032 if (TREE_CODE (decl
) == TYPE_DECL
)
2033 TYPE_FIELDS (current_class_type
)
2034 = chainon (TYPE_FIELDS (current_class_type
), decl
);
2037 TREE_CHAIN (decl
) = TYPE_FIELDS (current_class_type
);
2038 TYPE_FIELDS (current_class_type
) = decl
;
2041 /* Enter the DECL into the scope of the class. */
2042 if (TREE_CODE (decl
) != USING_DECL
)
2043 pushdecl_class_level (decl
);
2047 /* Finish a class definition T with the indicate ATTRIBUTES. If SEMI,
2048 the definition is immediately followed by a semicolon. Returns the
2052 finish_class_definition (t
, attributes
, semi
, pop_scope_p
)
2058 /* finish_struct nukes this anyway; if finish_exception does too,
2061 note_got_semicolon (t
);
2063 /* If we got any attributes in class_head, xref_tag will stick them in
2064 TREE_TYPE of the type. Grab them now. */
2065 attributes
= chainon (TREE_TYPE (t
), attributes
);
2066 TREE_TYPE (t
) = NULL_TREE
;
2068 if (TREE_CODE (t
) == ENUMERAL_TYPE
)
2072 t
= finish_struct (t
, attributes
);
2074 note_got_semicolon (t
);
2078 check_for_missing_semicolon (t
);
2080 pop_scope (CP_DECL_CONTEXT (TYPE_MAIN_DECL (t
)));
2081 if (current_scope () == current_function_decl
)
2082 do_pending_defargs ();
2087 /* Finish processing the default argument expressions cached during
2088 the processing of a class definition. */
2091 begin_inline_definitions ()
2094 && current_scope () == current_function_decl
)
2095 do_pending_inlines ();
2098 /* Finish processing the inline function definitions cached during the
2099 processing of a class definition. */
2102 finish_inline_definitions ()
2104 if (current_class_type
== NULL_TREE
)
2105 clear_inline_text_obstack ();
2108 /* Finish processing the declaration of a member class template
2109 TYPES whose template parameters are given by PARMS. */
2112 finish_member_class_template (types
)
2117 /* If there are declared, but undefined, partial specializations
2118 mixed in with the typespecs they will not yet have passed through
2119 maybe_process_partial_specialization, so we do that here. */
2120 for (t
= types
; t
!= NULL_TREE
; t
= TREE_CHAIN (t
))
2121 if (IS_AGGR_TYPE_CODE (TREE_CODE (TREE_VALUE (t
))))
2122 maybe_process_partial_specialization (TREE_VALUE (t
));
2124 note_list_got_semicolon (types
);
2125 grok_x_components (types
);
2126 if (TYPE_CONTEXT (TREE_VALUE (types
)) != current_class_type
)
2127 /* The component was in fact a friend declaration. We avoid
2128 finish_member_template_decl performing certain checks by
2132 finish_member_template_decl (types
);
2134 /* As with other component type declarations, we do
2135 not store the new DECL on the list of
2140 /* Finish processsing a complete template declaration. The PARMS are
2141 the template parameters. */
2144 finish_template_decl (parms
)
2148 end_template_decl ();
2150 end_specialization ();
2153 /* Finish processing a a template-id (which names a type) of the form
2154 NAME < ARGS >. Return the TYPE_DECL for the type named by the
2155 template-id. If ENTERING_SCOPE is non-zero we are about to enter
2156 the scope of template-id indicated. */
2159 finish_template_type (name
, args
, entering_scope
)
2166 decl
= lookup_template_class (name
, args
,
2167 NULL_TREE
, NULL_TREE
, entering_scope
);
2168 if (decl
!= error_mark_node
)
2169 decl
= TYPE_STUB_DECL (decl
);
2174 /* SR is a SCOPE_REF node. Enter the scope of SR, whether it is a
2175 namespace scope or a class scope. */
2181 tree scope
= TREE_OPERAND (sr
, 0);
2183 if (TREE_CODE (scope
) == NAMESPACE_DECL
)
2185 push_decl_namespace (scope
);
2186 TREE_COMPLEXITY (sr
) = -1;
2188 else if (scope
!= current_class_type
)
2190 if (TREE_CODE (scope
) == TYPENAME_TYPE
)
2192 /* In a declarator for a template class member, the scope will
2193 get here as an implicit typename, a TYPENAME_TYPE with a type. */
2194 scope
= TREE_TYPE (scope
);
2195 TREE_OPERAND (sr
, 0) = scope
;
2197 push_nested_class (scope
, 3);
2198 TREE_COMPLEXITY (sr
) = current_class_depth
;
2202 /* Finish processing a BASE_CLASS with the indicated ACCESS_SPECIFIER.
2203 Return a TREE_LIST containing the ACCESS_SPECIFIER and the
2204 BASE_CLASS, or NULL_TREE if an error occurred. The
2205 ACCESSS_SPECIFIER is one of
2206 access_{default,public,protected_private}[_virtual]_node.*/
2209 finish_base_specifier (access_specifier
, base_class
)
2210 tree access_specifier
;
2216 if (base_class
== NULL_TREE
)
2218 error ("invalid base class");
2219 type
= error_mark_node
;
2222 type
= TREE_TYPE (base_class
);
2224 if (! is_aggr_type (type
, 1))
2227 result
= build_tree_list (access_specifier
, type
);
2232 /* Called when multiple declarators are processed. If that is not
2233 premitted in this context, an error is issued. */
2236 check_multiple_declarators ()
2240 In a template-declaration, explicit specialization, or explicit
2241 instantiation the init-declarator-list in the declaration shall
2242 contain at most one declarator.
2244 We don't just use PROCESSING_TEMPLATE_DECL for the first
2245 condition since that would disallow the perfectly legal code,
2246 like `template <class T> struct S { int i, j; };'. */
2247 tree scope
= current_scope ();
2249 if (scope
&& TREE_CODE (scope
) == FUNCTION_DECL
)
2250 /* It's OK to write `template <class T> void f() { int i, j;}'. */
2253 if (PROCESSING_REAL_TEMPLATE_DECL_P ()
2254 || processing_explicit_instantiation
2255 || processing_specialization
)
2256 cp_error ("multiple declarators in template declaration");
2260 finish_typeof (expr
)
2263 if (processing_template_decl
)
2267 t
= make_aggr_type (TYPEOF_TYPE
);
2268 TYPE_FIELDS (t
) = expr
;
2273 return TREE_TYPE (expr
);
2276 /* Create an empty statement tree rooted at T. */
2282 /* We create a trivial EXPR_STMT so that last_tree is never NULL in
2283 what follows. We remove the extraneous statement in
2284 finish_stmt_tree. */
2285 *t
= build_nt (EXPR_STMT
, void_zero_node
);
2287 last_expr_type
= NULL_TREE
;
2290 /* Finish the statement tree rooted at T. */
2293 finish_stmt_tree (t
)
2298 /* Remove the fake extra statement added in begin_stmt_tree. */
2299 stmt
= TREE_CHAIN (*t
);
2301 SET_LAST_STMT (NULL_TREE
);
2305 /* The line-number recorded in the outermost statement in a function
2306 is the line number of the end of the function. */
2307 STMT_LINENO (stmt
) = lineno
;
2308 STMT_LINENO_FOR_FN_P (stmt
) = 1;
2312 /* We're about to expand T, a statement. Set up appropriate context
2313 for the substitution. */
2319 if (!STMT_LINENO_FOR_FN_P (t
))
2320 lineno
= STMT_LINENO (t
);
2321 stmts_are_full_exprs_p
= STMT_IS_FULL_EXPR_P (t
);
2324 /* Some statements, like for-statements or if-statements, require a
2325 condition. This condition can be a declaration. If T is such a
2326 declaration it is processed, and an expression appropriate to use
2327 as the condition is returned. Otherwise, T itself is returned. */
2333 if (t
&& TREE_CODE (t
) == TREE_LIST
)
2335 expand_stmt (TREE_PURPOSE (t
));
2336 return TREE_VALUE (t
);
2342 /* Generate RTL for the statement T, and its substatements, and any
2343 other statements at its nesting level. */
2349 tree rval
= NULL_TREE
;
2351 while (t
&& t
!= error_mark_node
)
2353 int saved_stmts_are_full_exprs_p
;
2355 /* Assume we'll have nothing to return. */
2358 /* Set up context appropriately for handling this statement. */
2359 saved_stmts_are_full_exprs_p
= stmts_are_full_exprs_p
;
2362 switch (TREE_CODE (t
))
2365 finish_return_stmt (RETURN_EXPR (t
));
2369 finish_expr_stmt (EXPR_STMT_EXPR (t
));
2376 emit_line_note (input_filename
, lineno
);
2377 decl
= DECL_STMT_DECL (t
);
2378 /* If this is a declaration for an automatic local
2379 variable, initialize it. Note that we might also see a
2380 declaration for a namespace-scope object (declared with
2381 `extern'). We don't have to handle the initialization
2382 of those objects here; they can only be declarations,
2383 rather than definitions. */
2384 if (TREE_CODE (decl
) == VAR_DECL
2385 && !TREE_STATIC (decl
)
2386 && !DECL_EXTERNAL (decl
))
2388 /* Let the back-end know about this variable. */
2389 if (!ANON_AGGR_TYPE_P (TREE_TYPE (decl
)))
2390 emit_local_var (decl
);
2392 expand_anon_union_decl (decl
, NULL_TREE
,
2393 DECL_ANON_UNION_ELEMS (decl
));
2395 else if (TREE_CODE (decl
) == VAR_DECL
&& TREE_STATIC (decl
))
2397 if (DECL_ARTIFICIAL (decl
) && ! TREE_USED (decl
))
2398 /* Do not emit unused decls. This is not just an
2399 optimization. We really do not want to emit
2400 __PRETTY_FUNCTION__ etc, if they're never used. */
2401 DECL_IGNORED_P (decl
) = 1;
2403 make_rtl_for_local_static (decl
);
2409 finish_decl_cleanup (CLEANUP_DECL (t
), CLEANUP_EXPR (t
));
2412 case START_CATCH_STMT
:
2413 begin_catch_block (TREE_TYPE (t
));
2417 if (CTOR_BEGIN_P (t
))
2418 begin_protect_partials ();
2420 /* After this point, any exceptions will cause the
2421 destructor to be executed, so we no longer need to worry
2422 about destroying the various subobjects ourselves. */
2423 end_protect_partials ();
2431 expand_stmt (FOR_INIT_STMT (t
));
2432 finish_for_init_stmt (NULL_TREE
);
2433 finish_for_cond (expand_cond (FOR_COND (t
)), NULL_TREE
);
2435 finish_for_expr (tmp
, NULL_TREE
);
2436 expand_stmt (FOR_BODY (t
));
2437 finish_for_stmt (tmp
, NULL_TREE
);
2443 begin_while_stmt ();
2444 finish_while_stmt_cond (expand_cond (WHILE_COND (t
)), NULL_TREE
);
2445 expand_stmt (WHILE_BODY (t
));
2446 finish_while_stmt (NULL_TREE
);
2453 expand_stmt (DO_BODY (t
));
2454 finish_do_body (NULL_TREE
);
2455 finish_do_stmt (DO_COND (t
), NULL_TREE
);
2461 finish_if_stmt_cond (expand_cond (IF_COND (t
)), NULL_TREE
);
2462 if (THEN_CLAUSE (t
))
2464 expand_stmt (THEN_CLAUSE (t
));
2465 finish_then_clause (NULL_TREE
);
2467 if (ELSE_CLAUSE (t
))
2469 begin_else_clause ();
2470 expand_stmt (ELSE_CLAUSE (t
));
2471 finish_else_clause (NULL_TREE
);
2477 begin_compound_stmt (COMPOUND_STMT_NO_SCOPE (t
));
2478 expand_stmt (COMPOUND_BODY (t
));
2479 rval
= finish_compound_stmt (COMPOUND_STMT_NO_SCOPE (t
),
2484 finish_break_stmt ();
2488 finish_continue_stmt ();
2495 begin_switch_stmt ();
2496 cond
= expand_cond (SWITCH_COND (t
));
2497 finish_switch_cond (cond
, NULL_TREE
);
2498 expand_stmt (SWITCH_BODY (t
));
2499 finish_switch_stmt (cond
, NULL_TREE
);
2504 finish_case_label (CASE_LOW (t
), CASE_HIGH (t
));
2508 expand_label (LABEL_STMT_LABEL (t
));
2512 finish_goto_stmt (GOTO_DESTINATION (t
));
2516 finish_asm_stmt (ASM_CV_QUAL (t
), ASM_STRING (t
), ASM_OUTPUTS
2517 (t
), ASM_INPUTS (t
), ASM_CLOBBERS (t
));
2523 expand_eh_region_start ();
2524 expand_stmt (TRY_STMTS (t
));
2525 finish_cleanup_try_block (NULL_TREE
);
2526 finish_cleanup (TRY_HANDLERS (t
), NULL_TREE
);
2530 if (FN_TRY_BLOCK_P (t
))
2531 begin_function_try_block ();
2535 expand_stmt (TRY_STMTS (t
));
2537 if (FN_TRY_BLOCK_P (t
))
2539 finish_function_try_block (NULL_TREE
);
2540 expand_stmt (TRY_HANDLERS (t
));
2541 finish_function_handler_sequence (NULL_TREE
);
2545 finish_try_block (NULL_TREE
);
2546 expand_stmt (TRY_HANDLERS (t
));
2547 finish_handler_sequence (NULL_TREE
);
2554 expand_stmt (HANDLER_BODY (t
));
2555 finish_handler (NULL_TREE
, NULL_TREE
);
2559 finish_subobject (SUBOBJECT_CLEANUP (t
));
2563 if (!SCOPE_NO_CLEANUPS_P (t
))
2565 if (SCOPE_BEGIN_P (t
))
2566 expand_start_bindings_and_block (2 * SCOPE_NULLIFIED_P (t
),
2567 SCOPE_STMT_BLOCK (t
));
2568 else if (SCOPE_END_P (t
))
2569 expand_end_bindings (NULL_TREE
, !SCOPE_NULLIFIED_P (t
),
2570 SCOPE_PARTIAL_P (t
));
2572 else if (!SCOPE_NULLIFIED_P (t
))
2574 rtx note
= emit_note (NULL
,
2576 ? NOTE_INSN_BLOCK_BEG
2577 : NOTE_INSN_BLOCK_END
));
2578 NOTE_BLOCK (note
) = SCOPE_STMT_BLOCK (t
);
2584 /* Clear this out so that finish_named_return_value can set it
2586 DECL_NAME (DECL_RESULT (current_function_decl
)) = NULL_TREE
;
2587 finish_named_return_value (TREE_OPERAND (t
, 0),
2588 TREE_OPERAND (t
, 1));
2592 my_friendly_abort (19990810);
2596 /* Restore saved state. */
2597 stmts_are_full_exprs_p
= saved_stmts_are_full_exprs_p
;
2599 /* Go on to the next statement in this scope. */
2606 /* Called from expand_body via walk_tree. Replace all AGGR_INIT_EXPRs
2607 will equivalent CALL_EXPRs. */
2610 simplify_aggr_init_exprs_r (tp
, walk_subtrees
, data
)
2612 int *walk_subtrees ATTRIBUTE_UNUSED
;
2613 void *data ATTRIBUTE_UNUSED
;
2615 tree aggr_init_expr
;
2622 int copy_from_buffer_p
;
2624 aggr_init_expr
= *tp
;
2625 /* We don't need to walk into types; there's nothing in a type that
2626 needs simplification. (And, furthermore, there are places we
2627 actively don't want to go. For example, we don't want to wander
2628 into the default arguments for a FUNCTION_DECL that appears in a
2630 if (TYPE_P (aggr_init_expr
))
2635 /* Only AGGR_INIT_EXPRs are interesting. */
2636 else if (TREE_CODE (aggr_init_expr
) != AGGR_INIT_EXPR
)
2639 /* Form an appropriate CALL_EXPR. */
2640 fn
= TREE_OPERAND (aggr_init_expr
, 0);
2641 args
= TREE_OPERAND (aggr_init_expr
, 1);
2642 slot
= TREE_OPERAND (aggr_init_expr
, 2);
2643 type
= TREE_TYPE (aggr_init_expr
);
2645 if (AGGR_INIT_VIA_CTOR_P (aggr_init_expr
))
2647 /* Replace the first argument with the address of the third
2648 argument to the AGGR_INIT_EXPR. */
2649 call_type
= build_pointer_type (type
);
2650 mark_addressable (slot
);
2651 args
= tree_cons (NULL_TREE
, build1 (ADDR_EXPR
, call_type
, slot
),
2654 call_expr
= build (CALL_EXPR
, call_type
, fn
, args
, NULL_TREE
);
2655 TREE_SIDE_EFFECTS (call_expr
) = 1;
2657 /* If we're using the non-reentrant PCC calling convention, then we
2658 need to copy the returned value out of the static buffer into the
2660 copy_from_buffer_p
= 0;
2661 #ifdef PCC_STATIC_STRUCT_RETURN
2662 if (!AGGR_INIT_VIA_CTOR_P (aggr_init_expr
) && aggregate_value_p (type
))
2666 flag_access_control
= 0;
2667 call_expr
= build_aggr_init (slot
, call_expr
, LOOKUP_ONLYCONVERTING
);
2668 flag_access_control
= old_ac
;
2669 copy_from_buffer_p
= 1;
2673 /* If this AGGR_INIT_EXPR indicates the value returned by a
2674 function, then we want to use the value of the initialized
2675 location as the result. */
2676 if (AGGR_INIT_VIA_CTOR_P (aggr_init_expr
) || copy_from_buffer_p
)
2678 call_expr
= build (COMPOUND_EXPR
, type
,
2680 TREE_SIDE_EFFECTS (call_expr
) = 1;
2683 /* Replace the AGGR_INIT_EXPR with the CALL_EXPR. */
2684 TREE_CHAIN (call_expr
) = TREE_CHAIN (aggr_init_expr
);
2687 /* Keep iterating. */
2691 /* Generate RTL for FN. */
2698 char *saved_input_filename
;
2700 /* When the parser calls us after finishing the body of a template
2701 function, we don't really want to expand the body. When we're
2702 processing an in-class definition of an inline function,
2703 PROCESSING_TEMPLATE_DECL will no longer be set here, so we have
2704 to look at the function itself. */
2705 if (processing_template_decl
2706 || (DECL_LANG_SPECIFIC (fn
)
2707 && DECL_TEMPLATE_INFO (fn
)
2708 && uses_template_parms (DECL_TI_ARGS (fn
))))
2710 /* Normally, collection only occurs in rest_of_compilation. So,
2711 if we don't collect here, we never collect junk generated
2712 during the processing of templates until we hit a
2713 non-template function. */
2718 /* Replace AGGR_INIT_EXPRs with appropriate CALL_EXPRs. */
2719 walk_tree (&DECL_SAVED_TREE (fn
), simplify_aggr_init_exprs_r
, NULL
);
2721 /* There's no reason to do any of the work here if we're only doing
2722 semantic analysis; this code just generates RTL. */
2723 if (flag_syntax_only
)
2726 /* If possible, avoid generating RTL for this function. Instead,
2727 just record it as an inline function, and wait until end-of-file
2728 to decide whether to write it out or not. */
2729 if (/* We have to generate RTL if we can't inline trees. */
2731 /* Or if it's not an inline function. */
2733 /* Or if we have to keep all inline functions anyhow. */
2734 && !flag_keep_inline_functions
2735 /* Or if we actually have a reference to the function. */
2736 && !DECL_NEEDED_P (fn
)
2737 /* Or if we're at the end-of-file, and this function is not
2739 && (!at_eof
|| DECL_COMDAT (fn
))
2740 /* Or if this is a nested function. */
2741 && !decl_function_context (fn
))
2743 /* Give the function RTL now so that we can assign it to a
2744 function pointer, etc. */
2745 make_function_rtl (fn
);
2746 /* Set DECL_EXTERNAL so that assemble_external will be called as
2747 necessary. We'll clear it again in finish_file. */
2748 if (!DECL_EXTERNAL (fn
))
2750 DECL_NOT_REALLY_EXTERN (fn
) = 1;
2751 DECL_EXTERNAL (fn
) = 1;
2753 /* Remember this function. In finish_file we'll decide if
2754 we actually need to write this function out. */
2755 mark_inline_for_output (fn
);
2756 /* Let the back-end know that this funtion exists. */
2757 note_deferral_of_defined_inline_function (fn
);
2761 /* Optimize the body of the function before expanding it. */
2762 optimize_function (fn
);
2764 /* Save the current file name and line number. When we expand the
2765 body of the function, we'll set LINENO and INPUT_FILENAME so that
2766 error-mesages come out in the right places. */
2767 saved_lineno
= lineno
;
2768 saved_input_filename
= input_filename
;
2769 lineno
= DECL_SOURCE_LINE (fn
);
2770 input_filename
= DECL_SOURCE_FILE (fn
);
2772 start_function (NULL_TREE
, fn
, NULL_TREE
, SF_PRE_PARSED
| SF_EXPAND
);
2773 store_parm_decls ();
2775 /* We don't need to redeclare __FUNCTION__, __PRETTY_FUNCTION__, or
2776 any of the other magic variables we set up when starting a
2778 current_function_name_declared
= 1;
2780 /* Expand the body. */
2781 expand_stmt (DECL_SAVED_TREE (fn
));
2783 /* Statements should always be full-expressions at the outermost set
2784 of curly braces for a function. */
2785 my_friendly_assert (stmts_are_full_exprs_p
, 19990831);
2787 /* The outermost statement for a function contains the line number
2788 recorded when we finished processing the function. */
2789 lineno
= STMT_LINENO (DECL_SAVED_TREE (fn
));
2791 /* Generate code for the function. */
2792 finish_function (lineno
, 0);
2794 /* If possible, obliterate the body of the function so that it can
2795 be garbage collected. */
2796 if (flag_dump_translation_unit
)
2797 /* Keep the body; we're going to dump it. */
2799 else if (DECL_INLINE (fn
) && flag_inline_trees
)
2800 /* We might need the body of this function so that we can expand
2801 it inline somewhere else. */
2804 /* We don't need the body; blow it away. */
2805 DECL_SAVED_TREE (fn
) = NULL_TREE
;
2807 /* And restore the current source position. */
2808 lineno
= saved_lineno
;
2809 input_filename
= saved_input_filename
;