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 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
35 /* There routines provide a modular interface to perform many parsing
36 operations. They may therefore be used during actual parsing, or
37 during template instantiation, which may be regarded as a
38 degenerate form of parsing. Since the current g++ parser is
39 lacking in several respects, and will be reimplemented, we are
40 attempting to move most code that is not directly related to
41 parsing into this file; that will make implementing the new parser
42 much easier since it will be able to make use of these routines. */
44 /* When parsing a template, LAST_TREE contains the last statement
45 parsed. These are chained together through the TREE_CHAIN field,
46 but often need to be re-organized since the parse is performed
47 bottom-up. This macro makes LAST_TREE the indicated SUBSTMT of
50 #define RECHAIN_STMTS(stmt, substmt, last) \
53 TREE_CHAIN (stmt) = NULL_TREE; \
57 #define RECHAIN_STMTS_FROM_LAST(stmt, substmt) \
58 RECHAIN_STMTS (stmt, substmt, last_tree)
60 #define RECHAIN_STMTS_FROM_CHAIN(stmt, substmt) \
61 RECHAIN_STMTS (stmt, substmt, TREE_CHAIN (stmt))
63 /* Finish an expression-statement, whose EXPRESSION is as indicated. */
66 finish_expr_stmt (expr
)
69 if (expr
!= NULL_TREE
)
71 if (!processing_template_decl
)
73 emit_line_note (input_filename
, lineno
);
74 /* Do default conversion if safe and possibly important,
75 in case within ({...}). */
76 if ((TREE_CODE (TREE_TYPE (expr
)) == ARRAY_TYPE
78 || TREE_CODE (TREE_TYPE (expr
)) == FUNCTION_TYPE
)
79 expr
= default_conversion (expr
);
82 cplus_expand_expr_stmt (expr
);
89 /* Begin an if-statement. Returns a newly created IF_STMT if
97 if (processing_template_decl
)
99 r
= build_min_nt (IF_STMT
, NULL_TREE
, NULL_TREE
, NULL_TREE
);
110 /* Process the COND of an if-statement, which may be given by
114 finish_if_stmt_cond (cond
, if_stmt
)
118 if (processing_template_decl
)
120 if (last_tree
!= if_stmt
)
121 RECHAIN_STMTS_FROM_LAST (if_stmt
, IF_COND (if_stmt
));
123 IF_COND (if_stmt
) = cond
;
127 emit_line_note (input_filename
, lineno
);
128 expand_start_cond (condition_conversion (cond
), 0);
132 /* Finish the then-clause of an if-statement, which may be given by
136 finish_then_clause (if_stmt
)
139 if (processing_template_decl
)
141 RECHAIN_STMTS_FROM_CHAIN (if_stmt
,
142 THEN_CLAUSE (if_stmt
));
150 /* Begin the else-clause of an if-statement. */
155 if (!processing_template_decl
)
156 expand_start_else ();
159 /* Finish the else-clause of an if-statement, which may be given by
163 finish_else_clause (if_stmt
)
166 if (processing_template_decl
)
167 RECHAIN_STMTS_FROM_CHAIN (if_stmt
, ELSE_CLAUSE (if_stmt
));
170 /* Finsh an if-statement. */
175 if (!processing_template_decl
)
182 /* Begin a while-statement. Returns a newly created WHILE_STMT if
190 if (processing_template_decl
)
192 r
= build_min_nt (WHILE_STMT
, NULL_TREE
, NULL_TREE
);
198 emit_line_note (input_filename
, lineno
);
199 expand_start_loop (1);
208 /* Process the COND of an if-statement, which may be given by
212 finish_while_stmt_cond (cond
, while_stmt
)
216 if (processing_template_decl
)
218 if (last_tree
!= while_stmt
)
219 RECHAIN_STMTS_FROM_LAST (while_stmt
,
220 WHILE_COND (while_stmt
));
222 TREE_OPERAND (while_stmt
, 0) = cond
;
226 emit_line_note (input_filename
, lineno
);
227 expand_exit_loop_if_false (0, condition_conversion (cond
));
230 /* If COND wasn't a declaration, clear out the
231 block we made for it and start a new one here so the
232 optimization in expand_end_loop will work. */
233 if (getdecls () == NULL_TREE
)
240 /* Finish a while-statement, which may be given by WHILE_STMT. */
243 finish_while_stmt (while_stmt
)
248 if (processing_template_decl
)
249 RECHAIN_STMTS_FROM_CHAIN (while_stmt
, WHILE_BODY (while_stmt
));
255 /* Begin a do-statement. Returns a newly created DO_STMT if
261 if (processing_template_decl
)
263 tree r
= build_min_nt (DO_STMT
, NULL_TREE
, NULL_TREE
);
270 emit_line_note (input_filename
, lineno
);
271 expand_start_loop_continue_elsewhere (1);
276 /* Finish the body of a do-statement, which may be given by DO_STMT. */
279 finish_do_body (do_stmt
)
282 if (processing_template_decl
)
283 RECHAIN_STMTS_FROM_CHAIN (do_stmt
, DO_BODY (do_stmt
));
285 expand_loop_continue_here ();
288 /* Finish a do-statement, which may be given by DO_STMT, and whose
289 COND is as indicated. */
292 finish_do_stmt (cond
, do_stmt
)
296 if (processing_template_decl
)
297 DO_COND (do_stmt
) = cond
;
300 emit_line_note (input_filename
, lineno
);
301 expand_exit_loop_if_false (0, condition_conversion (cond
));
309 /* Finish a return-statement. The EXPRESSION returned, if any, is as
313 finish_return_stmt (expr
)
316 emit_line_note (input_filename
, lineno
);
317 c_expand_return (expr
);
321 /* Begin a for-statement. Returns a new FOR_STMT if appropriate. */
328 if (processing_template_decl
)
330 r
= build_min_nt (FOR_STMT
, NULL_TREE
, NULL_TREE
,
331 NULL_TREE
, NULL_TREE
);
337 if (flag_new_for_scope
> 0)
340 note_level_for_for ();
346 /* Finish the for-init-statement of a for-statement, which may be
347 given by FOR_STMT. */
350 finish_for_init_stmt (for_stmt
)
353 if (processing_template_decl
)
355 if (last_tree
!= for_stmt
)
356 RECHAIN_STMTS_FROM_CHAIN (for_stmt
, FOR_INIT_STMT (for_stmt
));
361 emit_line_note (input_filename
, lineno
);
362 expand_start_loop_continue_elsewhere (1);
368 /* Finish the COND of a for-statement, which may be given by
372 finish_for_cond (cond
, for_stmt
)
376 if (processing_template_decl
)
378 if (last_tree
!= for_stmt
)
379 RECHAIN_STMTS_FROM_LAST (for_stmt
, FOR_COND (for_stmt
));
381 FOR_COND (for_stmt
) = cond
;
385 emit_line_note (input_filename
, lineno
);
387 expand_exit_loop_if_false (0, condition_conversion (cond
));
390 /* If the cond wasn't a declaration, clear out the
391 block we made for it and start a new one here so the
392 optimization in expand_end_loop will work. */
393 if (getdecls () == NULL_TREE
)
400 /* Finish the increment-EXPRESSION in a for-statement, which may be
401 given by FOR_STMT. */
404 finish_for_expr (expr
, for_stmt
)
408 if (processing_template_decl
)
409 FOR_EXPR (for_stmt
) = expr
;
411 /* Don't let the tree nodes for EXPR be discarded
412 by clear_momentary during the parsing of the next stmt. */
416 /* Finish the body of a for-statement, which may be given by
417 FOR_STMT. The increment-EXPR for the loop must be
421 finish_for_stmt (expr
, for_stmt
)
425 /* Pop the scope for the body of the loop. */
428 if (processing_template_decl
)
429 RECHAIN_STMTS_FROM_CHAIN (for_stmt
, FOR_BODY (for_stmt
));
432 emit_line_note (input_filename
, lineno
);
433 expand_loop_continue_here ();
435 cplus_expand_expr_stmt (expr
);
441 if (flag_new_for_scope
> 0)
447 /* Finish a break-statement. */
452 emit_line_note (input_filename
, lineno
);
453 if (processing_template_decl
)
454 add_tree (build_min_nt (BREAK_STMT
));
455 else if ( ! expand_exit_something ())
456 cp_error ("break statement not within loop or switch");
459 /* Finish a continue-statement. */
462 finish_continue_stmt ()
464 emit_line_note (input_filename
, lineno
);
465 if (processing_template_decl
)
466 add_tree (build_min_nt (CONTINUE_STMT
));
467 else if (! expand_continue_loop (0))
468 cp_error ("continue statement not within a loop");
471 /* Begin a switch-statement. */
479 /* Finish the cond of a switch-statement. Returns a new
480 SWITCH_STMT if appropriate. */
483 finish_switch_cond (cond
)
488 if (processing_template_decl
)
490 r
= build_min_nt (SWITCH_STMT
, cond
, NULL_TREE
);
495 emit_line_note (input_filename
, lineno
);
496 c_expand_start_case (cond
);
501 /* Don't let the tree nodes for COND be discarded by
502 clear_momentary during the parsing of the next stmt. */
508 /* Finish the body of a switch-statement, which may be given by
509 SWITCH_STMT. The COND to switch on is indicated. */
512 finish_switch_stmt (cond
, switch_stmt
)
516 if (processing_template_decl
)
517 RECHAIN_STMTS_FROM_CHAIN (switch_stmt
, SWITCH_BODY (switch_stmt
));
519 expand_end_case (cond
);
526 /* Finish a case-label. */
529 finish_case_label (low_value
, high_value
)
533 do_case (low_value
, high_value
);
537 /* Finish a goto-statement. */
540 finish_goto_stmt (destination
)
543 if (processing_template_decl
)
544 add_tree (build_min_nt (GOTO_STMT
, destination
));
547 emit_line_note (input_filename
, lineno
);
549 if (TREE_CODE (destination
) == IDENTIFIER_NODE
)
551 tree decl
= lookup_label (destination
);
552 TREE_USED (decl
) = 1;
556 expand_computed_goto (destination
);
560 /* Begin a try-block. Returns a newly-created TRY_BLOCK if
566 if (processing_template_decl
)
568 tree r
= build_min_nt (TRY_BLOCK
, NULL_TREE
,
575 emit_line_note (input_filename
, lineno
);
576 expand_start_try_stmts ();
581 /* Finish a try-block, which may be given by TRY_BLOCK. */
584 finish_try_block (try_block
)
587 if (processing_template_decl
)
588 RECHAIN_STMTS_FROM_LAST (try_block
, TRY_STMTS (try_block
));
591 expand_start_all_catch ();
595 /* Finish a handler-sequence for a try-block, which may be given by
599 finish_handler_sequence (try_block
)
602 if (processing_template_decl
)
603 RECHAIN_STMTS_FROM_CHAIN (try_block
, TRY_HANDLERS (try_block
));
606 expand_end_all_catch ();
610 /* Begin a handler. Returns a HANDLER if appropriate. */
617 if (processing_template_decl
)
619 r
= build_min_nt (HANDLER
, NULL_TREE
, NULL_TREE
);
630 /* Finish the handler-parameters for a handler, which may be given by
634 finish_handler_parms (handler
)
637 if (processing_template_decl
)
638 RECHAIN_STMTS_FROM_CHAIN (handler
, HANDLER_PARMS (handler
));
641 /* Finish a handler, which may be given by HANDLER. */
644 finish_handler (handler
)
647 if (processing_template_decl
)
648 RECHAIN_STMTS_FROM_CHAIN (handler
, HANDLER_BODY (handler
));
650 expand_end_catch_block ();
655 /* Begin a compound-statement. If HAS_NO_SCOPE is non-zero, the
656 compound-statement does not define a scope. Returns a new
657 COMPOUND_STMT if appropriate. */
660 begin_compound_stmt (has_no_scope
)
665 if (processing_template_decl
)
667 r
= build_min_nt (COMPOUND_STMT
, NULL_TREE
);
670 COMPOUND_STMT_NO_SCOPE (r
) = 1;
682 /* Finish a compound-statement, which may be given by COMPOUND_STMT.
683 If HAS_NO_SCOPE is non-zero, the compound statement does not define
687 finish_compound_stmt (has_no_scope
, compound_stmt
)
698 if (processing_template_decl
)
699 RECHAIN_STMTS_FROM_CHAIN (compound_stmt
,
700 COMPOUND_BODY (compound_stmt
));
707 /* Finish an asm-statement, whose components are a CV_QUALIFIER, a
708 STRING, some OUTPUT_OPERANDS, some INPUT_OPERANDS, and some
712 finish_asm_stmt (cv_qualifier
, string
, output_operands
,
713 input_operands
, clobbers
)
716 tree output_operands
;
720 if (TREE_CHAIN (string
))
721 string
= combine_strings (string
);
723 if (processing_template_decl
)
725 tree r
= build_min_nt (ASM_STMT
, cv_qualifier
, string
,
726 output_operands
, input_operands
,
732 emit_line_note (input_filename
, lineno
);
733 if (output_operands
!= NULL_TREE
|| input_operands
!= NULL_TREE
734 || clobbers
!= NULL_TREE
)
736 if (cv_qualifier
!= NULL_TREE
737 && cv_qualifier
!= ridpointers
[(int) RID_VOLATILE
])
738 cp_warning ("%s qualifier ignored on asm",
739 IDENTIFIER_POINTER (cv_qualifier
));
741 c_expand_asm_operands (string
, output_operands
,
745 == ridpointers
[(int) RID_VOLATILE
],
746 input_filename
, lineno
);
750 if (cv_qualifier
!= NULL_TREE
)
751 cp_warning ("%s qualifier ignored on asm",
752 IDENTIFIER_POINTER (cv_qualifier
));
760 /* Finish a parenthesized expression EXPR. */
763 finish_parenthesized_expr (expr
)
766 if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (TREE_CODE (expr
))))
767 /* This inhibits warnings in truthvalue_conversion. */
768 C_SET_EXP_ORIGINAL_CODE (expr
, ERROR_MARK
);
773 /* Begin a statement-expression. The value returned must be passed to
780 /* If we're processing_template_decl, then the upcoming compound
781 statement will be chained onto the tree structure, starting at
782 last_tree. We return last_tree so that we can later unhook the
783 compound statement. */
784 return processing_template_decl
? last_tree
: expand_start_stmt_expr();
787 /* Finish a statement-expression. RTL_EXPR should be the value
788 returned by the previous begin_stmt_expr; EXPR is the
789 statement-expression. Returns an expression representing the
790 statement-expression. */
793 finish_stmt_expr (rtl_expr
, expr
)
799 if (!processing_template_decl
)
801 rtl_expr
= expand_end_stmt_expr (rtl_expr
);
802 /* The statements have side effects, so the group does. */
803 TREE_SIDE_EFFECTS (rtl_expr
) = 1;
806 if (TREE_CODE (expr
) == BLOCK
)
808 /* Make a BIND_EXPR for the BLOCK already made. */
809 if (processing_template_decl
)
810 result
= build (BIND_EXPR
, NULL_TREE
,
811 NULL_TREE
, last_tree
, expr
);
813 result
= build (BIND_EXPR
, TREE_TYPE (rtl_expr
),
814 NULL_TREE
, rtl_expr
, expr
);
816 /* Remove the block from the tree at this point.
817 It gets put back at the proper place
818 when the BIND_EXPR is expanded. */
824 if (processing_template_decl
)
826 /* Remove the compound statement from the tree structure; it is
827 now saved in the BIND_EXPR. */
828 last_tree
= rtl_expr
;
829 TREE_CHAIN (last_tree
) = NULL_TREE
;
835 /* Finish a call to FN with ARGS. Returns a representation of the
839 finish_call_expr (fn
, args
, koenig
)
848 if (TREE_CODE (fn
) == BIT_NOT_EXPR
)
849 fn
= build_x_unary_op (BIT_NOT_EXPR
, TREE_OPERAND (fn
, 0));
850 else if (TREE_CODE (fn
) != TEMPLATE_ID_EXPR
)
851 fn
= do_identifier (fn
, 0, args
);
853 result
= build_x_function_call (fn
, args
, current_class_ref
);
855 if (TREE_CODE (result
) == CALL_EXPR
856 && TREE_TYPE (result
) != void_type_node
)
857 result
= require_complete_type (result
);
862 /* Finish a call to a postfix increment or decrement or EXPR. (Which
863 is indicated by CODE, which should be POSTINCREMENT_EXPR or
864 POSTDECREMENT_EXPR.) */
867 finish_increment_expr (expr
, code
)
871 /* If we get an OFFSET_REF, turn it into what it really means (e.g.,
872 a COMPONENT_REF). This way if we've got, say, a reference to a
873 static member that's being operated on, we don't end up trying to
874 find a member operator for the class it's in. */
876 if (TREE_CODE (expr
) == OFFSET_REF
)
877 expr
= resolve_offset_ref (expr
);
878 return build_x_unary_op (code
, expr
);
881 /* Finish a use of `this'. Returns an expression for `this'. */
888 if (current_class_ptr
)
890 #ifdef WARNING_ABOUT_CCD
891 TREE_USED (current_class_ptr
) = 1;
893 result
= current_class_ptr
;
895 else if (current_function_decl
896 && DECL_STATIC_FUNCTION_P (current_function_decl
))
898 error ("`this' is unavailable for static member functions");
899 result
= error_mark_node
;
903 if (current_function_decl
)
904 error ("invalid use of `this' in non-member function");
906 error ("invalid use of `this' at top level");
907 result
= error_mark_node
;
913 /* Finish a member function call using OBJECT and ARGS as arguments to
914 FN. Returns an expression for the call. */
917 finish_object_call_expr (fn
, object
, args
)
923 /* This is a future direction of this code, but because
924 build_x_function_call cannot always undo what is done in
925 build_component_ref entirely yet, we cannot do this. */
927 tree real_fn
= build_component_ref (object
, fn
, NULL_TREE
, 1);
928 return finish_call_expr (real_fn
, args
);
930 if (TREE_CODE (fn
) == TYPE_DECL
)
932 if (processing_template_decl
)
933 /* This can happen on code like:
936 template <class T> void f(T t) {
940 We just grab the underlying IDENTIFIER. */
944 cp_error ("calling type `%T' like a method", fn
);
945 return error_mark_node
;
949 return build_method_call (object
, fn
, args
, NULL_TREE
, LOOKUP_NORMAL
);
953 /* Finish a qualified member function call using OBJECT and ARGS as
954 arguments to FN. Returns an expressino for the call. */
957 finish_qualified_object_call_expr (fn
, object
, args
)
962 if (IS_SIGNATURE (TREE_OPERAND (fn
, 0)))
964 warning ("signature name in scope resolution ignored");
965 return finish_object_call_expr (TREE_OPERAND (fn
, 1), object
, args
);
968 return build_scoped_method_call (object
, TREE_OPERAND (fn
, 0),
969 TREE_OPERAND (fn
, 1), args
);
972 /* Finish a pseudo-destructor call expression of OBJECT, with SCOPE
973 being the scope, if any, of DESTRUCTOR. Returns an expression for
977 finish_pseudo_destructor_call_expr (object
, scope
, destructor
)
982 if (scope
&& scope
!= destructor
)
983 cp_error ("destructor specifier `%T::~%T()' must have matching names",
986 if ((scope
== NULL_TREE
|| IDENTIFIER_GLOBAL_VALUE (destructor
))
987 && (TREE_CODE (TREE_TYPE (object
)) !=
988 TREE_CODE (TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (destructor
)))))
989 cp_error ("`%E' is not of type `%T'", object
, destructor
);
991 return cp_convert (void_type_node
, object
);
994 /* Finish a call to a globally qualified member function FN using
995 ARGS. Returns an expression for the call. */
998 finish_globally_qualified_member_call_expr (fn
, args
)
1002 if (processing_template_decl
)
1003 return build_min_nt (CALL_EXPR
, copy_to_permanent (fn
), args
,
1006 return build_member_call (TREE_OPERAND (fn
, 0),
1007 TREE_OPERAND (fn
, 1),
1011 /* Finish an expression taking the address of LABEL. Returns an
1012 expression for the address. */
1015 finish_label_address_expr (label
)
1020 label
= lookup_label (label
);
1021 if (label
== NULL_TREE
)
1022 result
= null_pointer_node
;
1025 TREE_USED (label
) = 1;
1026 result
= build1 (ADDR_EXPR
, ptr_type_node
, label
);
1027 TREE_CONSTANT (result
) = 1;
1033 /* Finish an expression of the form CODE EXPR. */
1036 finish_unary_op_expr (code
, expr
)
1037 enum tree_code code
;
1040 tree result
= build_x_unary_op (code
, expr
);
1041 if (code
== NEGATE_EXPR
&& TREE_CODE (expr
) == INTEGER_CST
)
1042 TREE_NEGATED_INT (result
) = 1;
1043 overflow_warning (result
);
1047 /* Finish an id-expression. */
1050 finish_id_expr (expr
)
1053 if (TREE_CODE (expr
) == IDENTIFIER_NODE
)
1054 expr
= do_identifier (expr
, 1, NULL_TREE
);
1059 /* Begin a new-placement. */
1062 begin_new_placement ()
1064 /* The arguments to a placement new might be passed to a
1065 deallocation function, in the event that the allocation throws an
1066 exception. Since we don't expand exception handlers until the
1067 end of a function, we must make sure the arguments stay around
1069 return suspend_momentary ();
1072 /* Finish a new-placement. The ARGS are the placement arguments. The
1073 COOKIE is the value returned by the previous call to
1074 begin_new_placement. */
1077 finish_new_placement (args
, cookie
)
1081 resume_momentary (cookie
);
1085 /* Begin a function defniition declared with DECL_SPECS and
1086 DECLARATOR. Returns non-zero if the function-declaration is
1090 begin_function_definition (decl_specs
, declarator
)
1096 split_specs_attrs (decl_specs
, &specs
, &attrs
);
1097 if (!start_function (specs
, declarator
, attrs
, 0))
1100 reinit_parse_for_function ();
1104 /* Begin a constructor declarator of the form `SCOPE::NAME'. Returns
1108 begin_constructor_declarator (scope
, name
)
1112 tree result
= build_parse_node (SCOPE_REF
, scope
, name
);
1114 if (scope
!= current_class_type
)
1116 push_nested_class (scope
, 3);
1117 TREE_COMPLEXITY (result
) = current_class_depth
;
1123 /* Finish an init-declarator. Returns a DECL. */
1126 finish_declarator (declarator
, declspecs
, attributes
,
1127 prefix_attributes
, initialized
)
1131 tree prefix_attributes
;
1134 return start_decl (declarator
, declspecs
, initialized
, attributes
,
1138 /* Finish a transltation unit. */
1141 finish_translation_unit ()
1143 /* In case there were missing closebraces,
1144 get us back to the global binding level. */
1145 while (! toplevel_bindings_p ())
1147 while (current_namespace
!= global_namespace
)
1152 /* Finish a template type parameter, specified as AGGR IDENTIFIER.
1153 Returns the parameter. */
1156 finish_template_type_parm (aggr
, identifier
)
1160 if (aggr
== signature_type_node
)
1161 sorry ("signature as template type parameter");
1162 else if (aggr
!= class_type_node
)
1164 pedwarn ("template type parameters must use the keyword `class' or `typename'");
1165 aggr
= class_type_node
;
1168 return build_tree_list (aggr
, identifier
);
1171 /* Finish a template template parameter, specified as AGGR IDENTIFIER.
1172 Returns the parameter. */
1175 finish_template_template_parm (aggr
, identifier
)
1179 tree decl
= build_decl (TYPE_DECL
, identifier
, NULL_TREE
);
1180 tree tmpl
= build_lang_decl (TEMPLATE_DECL
, identifier
, NULL_TREE
);
1181 DECL_TEMPLATE_PARMS (tmpl
) = current_template_parms
;
1182 DECL_TEMPLATE_RESULT (tmpl
) = decl
;
1183 SET_DECL_ARTIFICIAL (decl
);
1184 end_template_decl ();
1186 return finish_template_type_parm (aggr
, tmpl
);
1189 /* Finish a parameter list, indicated by PARMS. If ELLIPSIS is
1190 non-zero, the parameter list was terminated by a `...'. */
1193 finish_parmlist (parms
, ellipsis
)
1198 chainon (parms
, void_list_node
);
1199 /* We mark the PARMS as a parmlist so that declarator processing can
1200 disambiguate certain constructs. */
1201 if (parms
!= NULL_TREE
)
1202 TREE_PARMLIST (parms
) = 1;
1207 /* Begin a class definition, as indicated by T. */
1210 begin_class_definition (t
)
1215 push_obstacks_nochange ();
1216 end_temporary_allocation ();
1218 if (t
== error_mark_node
1219 || ! IS_AGGR_TYPE (t
))
1221 t
= new_type
= make_lang_type (RECORD_TYPE
);
1222 pushtag (make_anon_name (), t
, 0);
1225 duplicate_tag_error (t
);
1226 if (TYPE_SIZE (t
) || TYPE_BEING_DEFINED (t
))
1228 t
= make_lang_type (TREE_CODE (t
));
1229 pushtag (TYPE_IDENTIFIER (t
), t
, 0);
1232 if (processing_template_decl
&& TYPE_CONTEXT (t
)
1233 && TREE_CODE (TYPE_CONTEXT (t
)) != NAMESPACE_DECL
1234 && ! current_class_type
)
1235 push_template_decl (TYPE_STUB_DECL (t
));
1237 TYPE_BEING_DEFINED (t
) = 1;
1238 if (IS_AGGR_TYPE (t
) && CLASSTYPE_USE_TEMPLATE (t
))
1240 if (CLASSTYPE_IMPLICIT_INSTANTIATION (t
)
1241 && TYPE_SIZE (t
) == NULL_TREE
)
1243 SET_CLASSTYPE_TEMPLATE_SPECIALIZATION (t
);
1244 if (processing_template_decl
)
1245 push_template_decl (TYPE_MAIN_DECL (t
));
1247 else if (CLASSTYPE_TEMPLATE_INSTANTIATION (t
))
1248 cp_error ("specialization after instantiation of `%T'", t
);
1250 /* Reset the interface data, at the earliest possible
1251 moment, as it might have been set via a class foo;
1253 /* Don't change signatures. */
1254 if (! IS_SIGNATURE (t
))
1256 extern tree pending_vtables
;
1258 tree name
= TYPE_IDENTIFIER (t
);
1260 if (! ANON_AGGRNAME_P (name
))
1262 CLASSTYPE_INTERFACE_ONLY (t
) = interface_only
;
1263 SET_CLASSTYPE_INTERFACE_UNKNOWN_X
1264 (t
, interface_unknown
);
1267 /* Record how to set the access of this class's
1268 virtual functions. If write_virtuals == 2 or 3, then
1269 inline virtuals are ``extern inline''. */
1270 switch (write_virtuals
)
1277 needs_writing
= !! value_member (name
, pending_vtables
);
1280 needs_writing
= ! CLASSTYPE_INTERFACE_ONLY (t
)
1281 && CLASSTYPE_INTERFACE_KNOWN (t
);
1286 CLASSTYPE_VTABLE_NEEDS_WRITING (t
) = needs_writing
;
1289 t
= TYPE_IDENTIFIER ($
<ttype
>0);
1290 if (t
&& IDENTIFIER_TEMPLATE (t
))
1291 overload_template_name (t
, 1);
1293 reset_specialization();
1295 /* In case this is a local class within a template
1296 function, we save the current tree structure so
1297 that we can get it back later. */
1303 /* Finish a class definition T, with the indicated COMPONENTS, and
1304 with the indicate ATTRIBUTES. If SEMI, the definition is
1305 immediately followed by a semicolon. Returns the type. */
1308 finish_class_definition (t
, components
, attributes
, semi
)
1315 /* Need to rework class nesting in the presence of nested classes,
1317 shadow_tag (CLASSTYPE_AS_LIST (t
)); */
1320 /* finish_struct nukes this anyway; if finish_exception does too,
1323 note_got_semicolon (t
);
1325 /* If we got any attributes in class_head, xref_tag will stick them in
1326 TREE_TYPE of the type. Grab them now. */
1327 attributes
= chainon (TREE_TYPE (t
), attributes
);
1328 TREE_TYPE (t
) = NULL_TREE
;
1330 if (TREE_CODE (t
) == ENUMERAL_TYPE
)
1334 t
= finish_struct (t
, components
, attributes
, semi
);
1336 note_got_semicolon (t
);
1342 check_for_missing_semicolon (t
);
1343 if (current_scope () == current_function_decl
)
1344 do_pending_defargs ();
1349 /* Finish processing the default argument expressions cached during
1350 the processing of a class definition. */
1353 finish_default_args ()
1356 && current_scope () == current_function_decl
)
1357 do_pending_inlines ();
1360 /* Finish processing the inline function definitions cached during the
1361 processing of a class definition. */
1364 begin_inline_definitions ()
1366 if (current_class_type
== NULL_TREE
)
1367 clear_inline_text_obstack ();
1369 /* Undo the begin_tree in begin_class_definition. */
1373 /* Finish processing the declaration of a member class template
1374 TYPES whose template parameters are given by PARMS. */
1377 finish_member_class_template (parms
, types
)
1381 note_list_got_semicolon (types
);
1382 grok_x_components (types
, NULL_TREE
);
1383 if (TYPE_CONTEXT (TREE_VALUE (types
)) != current_class_type
)
1384 /* The component was in fact a friend declaration. We avoid
1385 finish_member_template_decl performing certain checks by
1388 finish_member_template_decl (parms
, types
);
1389 /* As with other component type declarations, we do
1390 not store the new DECL on the list of