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, 2001 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
41 /* There routines provide a modular interface to perform many parsing
42 operations. They may therefore be used during actual parsing, or
43 during template instantiation, which may be regarded as a
44 degenerate form of parsing. Since the current g++ parser is
45 lacking in several respects, and will be reimplemented, we are
46 attempting to move most code that is not directly related to
47 parsing into this file; that will make implementing the new parser
48 much easier since it will be able to make use of these routines. */
50 static tree maybe_convert_cond PARAMS ((tree));
51 static tree simplify_aggr_init_exprs_r PARAMS ((tree *, int *, void *));
52 static void deferred_type_access_control PARAMS ((void));
53 static void emit_associated_thunks PARAMS ((tree));
54 static void genrtl_try_block PARAMS ((tree));
55 static void genrtl_eh_spec_block PARAMS ((tree));
56 static void genrtl_handler PARAMS ((tree));
57 static void genrtl_ctor_stmt PARAMS ((tree));
58 static void genrtl_subobject PARAMS ((tree));
59 static void genrtl_named_return_value PARAMS ((void));
60 static void cp_expand_stmt PARAMS ((tree));
61 static void genrtl_start_function PARAMS ((tree));
62 static void genrtl_finish_function PARAMS ((tree));
63 static tree clear_decl_rtl PARAMS ((tree *, int *, void *));
65 /* Finish processing the COND, the SUBSTMT condition for STMT. */
67 #define FINISH_COND(cond, stmt, substmt) \
69 if (last_tree != stmt) \
71 RECHAIN_STMTS (stmt, substmt); \
72 if (!processing_template_decl) \
74 cond = build_tree_list (substmt, cond); \
82 /* Returns non-zero if the current statement is a full expression,
83 i.e. temporaries created during that statement should be destroyed
84 at the end of the statement. */
87 stmts_are_full_exprs_p ()
89 return current_stmt_tree ()->stmts_are_full_exprs_p;
92 /* Returns the stmt_tree (if any) to which statements are currently
93 being added. If there is no active statement-tree, NULL is
100 ? &cfun->language->x_stmt_tree
101 : &scope_chain->x_stmt_tree);
104 /* Nonzero if TYPE is an anonymous union or struct type. We have to use a
105 flag for this because "A union for which objects or pointers are
106 declared is not an anonymous union" [class.union]. */
109 anon_aggr_type_p (node)
112 return (CLASS_TYPE_P (node) && TYPE_LANG_SPECIFIC(node)->anon_aggr);
115 /* Finish a scope. */
120 tree block = NULL_TREE;
122 if (stmts_are_full_exprs_p ())
124 tree scope_stmts = NULL_TREE;
126 if (!processing_template_decl)
127 scope_stmts = add_scope_stmt (/*begin_p=*/0, /*partial_p=*/0);
129 block = poplevel (kept_level_p (), 1, 0);
130 if (block && !processing_template_decl)
132 SCOPE_STMT_BLOCK (TREE_PURPOSE (scope_stmts)) = block;
133 SCOPE_STMT_BLOCK (TREE_VALUE (scope_stmts)) = block;
140 /* Begin a new scope. */
145 if (stmts_are_full_exprs_p ())
148 if (!processing_template_decl)
149 add_scope_stmt (/*begin_p=*/1, /*partial_p=*/0);
153 /* Finish a goto-statement. */
156 finish_goto_stmt (destination)
159 if (TREE_CODE (destination) == IDENTIFIER_NODE)
160 destination = lookup_label (destination);
162 /* We warn about unused labels with -Wunused. That means we have to
163 mark the used labels as used. */
164 if (TREE_CODE (destination) == LABEL_DECL)
165 TREE_USED (destination) = 1;
167 if (TREE_CODE (destination) != LABEL_DECL)
168 /* We don't inline calls to functions with computed gotos.
169 Those functions are typically up to some funny business,
170 and may be depending on the labels being at particular
171 addresses, or some such. */
172 DECL_UNINLINABLE (current_function_decl) = 1;
174 check_goto (destination);
176 return add_stmt (build_stmt (GOTO_STMT, destination));
179 /* COND is the condition-expression for an if, while, etc.,
180 statement. Convert it to a boolean value, if appropriate. */
183 maybe_convert_cond (cond)
186 /* Empty conditions remain empty. */
190 /* Wait until we instantiate templates before doing conversion. */
191 if (processing_template_decl)
194 /* Do the conversion. */
195 cond = convert_from_reference (cond);
196 return condition_conversion (cond);
199 /* Finish an expression-statement, whose EXPRESSION is as indicated. */
202 finish_expr_stmt (expr)
207 if (expr != NULL_TREE)
209 if (!processing_template_decl
210 && !(stmts_are_full_exprs_p ())
211 && ((TREE_CODE (TREE_TYPE (expr)) == ARRAY_TYPE
213 || TREE_CODE (TREE_TYPE (expr)) == FUNCTION_TYPE))
214 expr = default_conversion (expr);
216 if (stmts_are_full_exprs_p ())
217 expr = convert_to_void (expr, "statement");
219 r = add_stmt (build_stmt (EXPR_STMT, expr));
224 /* This was an expression-statement, so we save the type of the
226 last_expr_type = expr ? TREE_TYPE (expr) : NULL_TREE;
232 /* Begin an if-statement. Returns a newly created IF_STMT if
240 r = build_stmt (IF_STMT, NULL_TREE, NULL_TREE, NULL_TREE);
245 /* Process the COND of an if-statement, which may be given by
249 finish_if_stmt_cond (cond, if_stmt)
253 cond = maybe_convert_cond (cond);
254 FINISH_COND (cond, if_stmt, IF_COND (if_stmt));
257 /* Finish the then-clause of an if-statement, which may be given by
261 finish_then_clause (if_stmt)
264 RECHAIN_STMTS (if_stmt, THEN_CLAUSE (if_stmt));
269 /* Begin the else-clause of an if-statement. */
276 /* Finish the else-clause of an if-statement, which may be given by
280 finish_else_clause (if_stmt)
283 RECHAIN_STMTS (if_stmt, ELSE_CLAUSE (if_stmt));
286 /* Finish an if-statement. */
298 /* If COND wasn't a declaration, clear out the
299 block we made for it and start a new one here so the
300 optimization in expand_end_loop will work. */
301 if (getdecls () == NULL_TREE)
308 /* Begin a while-statement. Returns a newly created WHILE_STMT if
315 r = build_stmt (WHILE_STMT, NULL_TREE, NULL_TREE);
321 /* Process the COND of a while-statement, which may be given by
325 finish_while_stmt_cond (cond, while_stmt)
329 cond = maybe_convert_cond (cond);
330 FINISH_COND (cond, while_stmt, WHILE_COND (while_stmt));
334 /* Finish a while-statement, which may be given by WHILE_STMT. */
337 finish_while_stmt (while_stmt)
341 RECHAIN_STMTS (while_stmt, WHILE_BODY (while_stmt));
345 /* Begin a do-statement. Returns a newly created DO_STMT if
351 tree r = build_stmt (DO_STMT, NULL_TREE, NULL_TREE);
356 /* Finish the body of a do-statement, which may be given by DO_STMT. */
359 finish_do_body (do_stmt)
362 RECHAIN_STMTS (do_stmt, DO_BODY (do_stmt));
365 /* Finish a do-statement, which may be given by DO_STMT, and whose
366 COND is as indicated. */
369 finish_do_stmt (cond, do_stmt)
373 cond = maybe_convert_cond (cond);
374 DO_COND (do_stmt) = cond;
378 /* Finish a return-statement. The EXPRESSION returned, if any, is as
382 finish_return_stmt (expr)
387 if (!processing_template_decl)
388 expr = check_return_expr (expr);
389 if (!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 return finish_goto_stmt (ctor_label);
401 else if (DECL_DESTRUCTOR_P (current_function_decl))
403 /* Similarly, all destructors must run destructors for
404 base-classes before returning. So, all returns in a
405 destructor get sent to the DTOR_LABEL; finish_function emits
406 code to return a value there. */
407 return finish_goto_stmt (dtor_label);
410 r = add_stmt (build_stmt (RETURN_STMT, expr));
416 /* Begin a for-statement. Returns a new FOR_STMT if appropriate. */
423 r = build_stmt (FOR_STMT, NULL_TREE, NULL_TREE,
424 NULL_TREE, NULL_TREE);
425 NEW_FOR_SCOPE_P (r) = flag_new_for_scope > 0;
427 if (NEW_FOR_SCOPE_P (r))
430 note_level_for_for ();
436 /* Finish the for-init-statement of a for-statement, which may be
437 given by FOR_STMT. */
440 finish_for_init_stmt (for_stmt)
443 if (last_tree != for_stmt)
444 RECHAIN_STMTS (for_stmt, FOR_INIT_STMT (for_stmt));
448 /* Finish the COND of a for-statement, which may be given by
452 finish_for_cond (cond, for_stmt)
456 cond = maybe_convert_cond (cond);
457 FINISH_COND (cond, for_stmt, FOR_COND (for_stmt));
461 /* Finish the increment-EXPRESSION in a for-statement, which may be
462 given by FOR_STMT. */
465 finish_for_expr (expr, for_stmt)
469 FOR_EXPR (for_stmt) = expr;
472 /* Finish the body of a for-statement, which may be given by
473 FOR_STMT. The increment-EXPR for the loop must be
477 finish_for_stmt (for_stmt)
480 /* Pop the scope for the body of the loop. */
482 RECHAIN_STMTS (for_stmt, FOR_BODY (for_stmt));
483 if (NEW_FOR_SCOPE_P (for_stmt))
488 /* Finish a break-statement. */
493 return add_stmt (build_break_stmt ());
496 /* Finish a continue-statement. */
499 finish_continue_stmt ()
501 return add_stmt (build_continue_stmt ());
504 /* Begin a switch-statement. Returns a new SWITCH_STMT if
511 r = build_stmt (SWITCH_STMT, NULL_TREE, NULL_TREE);
517 /* Finish the cond of a switch-statement. */
520 finish_switch_cond (cond, switch_stmt)
524 if (!processing_template_decl)
529 /* Convert the condition to an integer or enumeration type. */
530 cond = build_expr_type_conversion (WANT_INT | WANT_ENUM, cond, 1);
531 if (cond == NULL_TREE)
533 error ("switch quantity not an integer");
534 cond = error_mark_node;
536 if (cond != error_mark_node)
538 cond = default_conversion (cond);
539 cond = fold (build1 (CLEANUP_POINT_EXPR, TREE_TYPE (cond), cond));
542 type = TREE_TYPE (cond);
543 index = get_unwidened (cond, NULL_TREE);
544 /* We can't strip a conversion from a signed type to an unsigned,
545 because if we did, int_fits_type_p would do the wrong thing
546 when checking case values for being in range,
547 and it's too hard to do the right thing. */
548 if (TREE_UNSIGNED (TREE_TYPE (cond))
549 == TREE_UNSIGNED (TREE_TYPE (index)))
552 FINISH_COND (cond, switch_stmt, SWITCH_COND (switch_stmt));
553 push_switch (switch_stmt);
556 /* Finish the body of a switch-statement, which may be given by
557 SWITCH_STMT. The COND to switch on is indicated. */
560 finish_switch_stmt (switch_stmt)
563 RECHAIN_STMTS (switch_stmt, SWITCH_BODY (switch_stmt));
569 /* Generate the RTL for T, which is a TRY_BLOCK. */
577 expand_eh_region_start ();
578 expand_stmt (TRY_STMTS (t));
579 expand_eh_region_end_cleanup (TRY_HANDLERS (t));
583 if (!FN_TRY_BLOCK_P (t))
584 emit_line_note (input_filename, lineno);
586 expand_eh_region_start ();
587 expand_stmt (TRY_STMTS (t));
589 if (FN_TRY_BLOCK_P (t))
591 end_protect_partials ();
592 expand_start_all_catch ();
593 in_function_try_handler = 1;
594 expand_stmt (TRY_HANDLERS (t));
595 in_function_try_handler = 0;
596 expand_end_all_catch ();
600 expand_start_all_catch ();
601 expand_stmt (TRY_HANDLERS (t));
602 expand_end_all_catch ();
607 /* Generate the RTL for T, which is an EH_SPEC_BLOCK. */
610 genrtl_eh_spec_block (t)
613 expand_eh_region_start ();
614 expand_stmt (EH_SPEC_STMTS (t));
615 expand_eh_region_end_allowed (EH_SPEC_RAISES (t),
616 build_call (call_unexpected_node,
617 tree_cons (NULL_TREE,
622 /* Begin a try-block. Returns a newly-created TRY_BLOCK if
628 tree r = build_stmt (TRY_BLOCK, NULL_TREE, NULL_TREE);
633 /* Likewise, for a function-try-block. */
636 begin_function_try_block ()
638 tree r = build_stmt (TRY_BLOCK, NULL_TREE, NULL_TREE);
639 FN_TRY_BLOCK_P (r) = 1;
644 /* Finish a try-block, which may be given by TRY_BLOCK. */
647 finish_try_block (try_block)
650 RECHAIN_STMTS (try_block, TRY_STMTS (try_block));
653 /* Finish the body of a cleanup try-block, which may be given by
657 finish_cleanup_try_block (try_block)
660 RECHAIN_STMTS (try_block, TRY_STMTS (try_block));
663 /* Finish an implicitly generated try-block, with a cleanup is given
667 finish_cleanup (cleanup, try_block)
671 TRY_HANDLERS (try_block) = cleanup;
672 CLEANUP_P (try_block) = 1;
675 /* Likewise, for a function-try-block. */
678 finish_function_try_block (try_block)
681 if (TREE_CHAIN (try_block)
682 && TREE_CODE (TREE_CHAIN (try_block)) == CTOR_INITIALIZER)
684 /* Chain the compound statement after the CTOR_INITIALIZER. */
685 TREE_CHAIN (TREE_CHAIN (try_block)) = last_tree;
686 /* And make the CTOR_INITIALIZER the body of the try-block. */
687 RECHAIN_STMTS (try_block, TRY_STMTS (try_block));
690 RECHAIN_STMTS (try_block, TRY_STMTS (try_block));
691 in_function_try_handler = 1;
694 /* Finish a handler-sequence for a try-block, which may be given by
698 finish_handler_sequence (try_block)
701 RECHAIN_STMTS (try_block, TRY_HANDLERS (try_block));
702 check_handlers (TRY_HANDLERS (try_block));
705 /* Likewise, for a function-try-block. */
708 finish_function_handler_sequence (try_block)
711 in_function_try_handler = 0;
712 RECHAIN_STMTS (try_block, TRY_HANDLERS (try_block));
713 check_handlers (TRY_HANDLERS (try_block));
716 /* Generate the RTL for T, which is a HANDLER. */
722 genrtl_do_pushlevel ();
723 if (!processing_template_decl)
724 expand_start_catch (HANDLER_TYPE (t));
725 expand_stmt (HANDLER_BODY (t));
726 if (!processing_template_decl)
730 /* Begin a handler. Returns a HANDLER if appropriate. */
736 r = build_stmt (HANDLER, NULL_TREE, NULL_TREE);
738 /* Create a binding level for the eh_info and the exception object
741 note_level_for_catch ();
745 /* Finish the handler-parameters for a handler, which may be given by
746 HANDLER. DECL is the declaration for the catch parameter, or NULL
747 if this is a `catch (...)' clause. */
750 finish_handler_parms (decl, handler)
754 tree type = NULL_TREE;
755 if (processing_template_decl)
759 decl = pushdecl (decl);
760 decl = push_template_decl (decl);
761 add_decl_stmt (decl);
762 RECHAIN_STMTS (handler, HANDLER_PARMS (handler));
763 type = TREE_TYPE (decl);
767 type = expand_start_catch_block (decl);
769 HANDLER_TYPE (handler) = type;
772 /* Finish a handler, which may be given by HANDLER. The BLOCKs are
773 the return value from the matching call to finish_handler_parms. */
776 finish_handler (handler)
779 if (!processing_template_decl)
780 expand_end_catch_block ();
782 RECHAIN_STMTS (handler, HANDLER_BODY (handler));
785 /* Generate the RTL for T, which is a CTOR_STMT. */
791 if (CTOR_BEGIN_P (t))
792 begin_protect_partials ();
794 /* After this point, any exceptions will cause the
795 destructor to be executed, so we no longer need to worry
796 about destroying the various subobjects ourselves. */
797 end_protect_partials ();
800 /* Begin a compound-statement. If HAS_NO_SCOPE is non-zero, the
801 compound-statement does not define a scope. Returns a new
802 COMPOUND_STMT if appropriate. */
805 begin_compound_stmt (has_no_scope)
811 r = build_stmt (COMPOUND_STMT, NULL_TREE);
813 if (last_tree && TREE_CODE (last_tree) == TRY_BLOCK)
818 COMPOUND_STMT_NO_SCOPE (r) = 1;
820 last_expr_type = NULL_TREE;
826 note_level_for_try ();
829 /* Normally, we try hard to keep the BLOCK for a
830 statement-expression. But, if it's a statement-expression with
831 a scopeless block, there's nothing to keep, and we don't want
832 to accidentally keep a block *inside* the scopeless block. */
838 /* Finish a compound-statement, which may be given by COMPOUND_STMT.
839 If HAS_NO_SCOPE is non-zero, the compound statement does not define
843 finish_compound_stmt (has_no_scope, compound_stmt)
855 RECHAIN_STMTS (compound_stmt, COMPOUND_BODY (compound_stmt));
857 /* When we call finish_stmt we will lose LAST_EXPR_TYPE. But, since
858 the precise purpose of that variable is store the type of the
859 last expression statement within the last compound statement, we
860 preserve the value. */
868 /* Finish an asm-statement, whose components are a CV_QUALIFIER, a
869 STRING, some OUTPUT_OPERANDS, some INPUT_OPERANDS, and some
873 finish_asm_stmt (cv_qualifier, string, output_operands,
874 input_operands, clobbers)
877 tree output_operands;
884 if (TREE_CHAIN (string))
885 string = combine_strings (string);
887 if (cv_qualifier != NULL_TREE
888 && cv_qualifier != ridpointers[(int) RID_VOLATILE])
890 cp_warning ("%s qualifier ignored on asm",
891 IDENTIFIER_POINTER (cv_qualifier));
892 cv_qualifier = NULL_TREE;
895 if (!processing_template_decl)
896 for (t = input_operands; t; t = TREE_CHAIN (t))
898 tree converted_operand
899 = decay_conversion (TREE_VALUE (t));
901 /* If the type of the operand hasn't been determined (e.g.,
902 because it involves an overloaded function), then issue an
903 error message. There's no context available to resolve the
905 if (TREE_TYPE (converted_operand) == unknown_type_node)
907 cp_error ("type of asm operand `%E' could not be determined",
909 converted_operand = error_mark_node;
911 TREE_VALUE (t) = converted_operand;
914 r = build_stmt (ASM_STMT, cv_qualifier, string,
915 output_operands, input_operands,
920 /* Finish a label with the indicated NAME. */
923 finish_label_stmt (name)
926 tree decl = define_label (input_filename, lineno, name);
927 add_stmt (build_stmt (LABEL_STMT, decl));
930 /* Finish a series of declarations for local labels. G++ allows users
931 to declare "local" labels, i.e., labels with scope. This extension
932 is useful when writing code involving statement-expressions. */
935 finish_label_decl (name)
938 tree decl = declare_local_label (name);
939 add_decl_stmt (decl);
942 /* Generate the RTL for a SUBOBJECT. */
945 genrtl_subobject (cleanup)
948 add_partial_entry (cleanup);
951 /* We're in a constructor, and have just constructed a a subobject of
952 *THIS. CLEANUP is code to run if an exception is thrown before the
953 end of the current function is reached. */
956 finish_subobject (cleanup)
959 tree r = build_stmt (SUBOBJECT, cleanup);
963 /* When DECL goes out of scope, make sure that CLEANUP is executed. */
966 finish_decl_cleanup (decl, cleanup)
970 add_stmt (build_stmt (CLEANUP_STMT, decl, cleanup));
973 /* Generate the RTL for a RETURN_INIT. */
976 genrtl_named_return_value ()
978 tree decl = DECL_RESULT (current_function_decl);
980 /* If this named return value comes in a register, put it in a
982 if (DECL_REGISTER (decl))
984 /* Note that the mode of the old DECL_RTL may be wider than the
985 mode of DECL_RESULT, depending on the calling conventions for
986 the processor. For example, on the Alpha, a 32-bit integer
987 is returned in a DImode register -- the DECL_RESULT has
988 SImode but the DECL_RTL for the DECL_RESULT has DImode. So,
989 here, we use the mode the back-end has already assigned for
991 SET_DECL_RTL (decl, gen_reg_rtx (GET_MODE (DECL_RTL (decl))));
992 if (TREE_ADDRESSABLE (decl))
993 put_var_into_stack (decl);
996 emit_local_var (decl);
999 /* Bind a name and initialization to the return value of
1000 the current function. */
1003 finish_named_return_value (return_id, init)
1004 tree return_id, init;
1006 tree decl = DECL_RESULT (current_function_decl);
1008 /* Give this error as many times as there are occurrences, so that
1009 users can use Emacs compilation buffers to find and fix all such
1012 pedwarn ("ISO C++ does not permit named return values");
1013 cp_deprecated ("the named return value extension");
1015 if (return_id != NULL_TREE)
1017 if (DECL_NAME (decl) == NULL_TREE)
1018 DECL_NAME (decl) = return_id;
1021 cp_error ("return identifier `%D' already in place", return_id);
1026 /* Can't let this happen for constructors. */
1027 if (DECL_CONSTRUCTOR_P (current_function_decl))
1029 error ("can't redefine default return value for constructors");
1033 /* If we have a named return value, put that in our scope as well. */
1034 if (DECL_NAME (decl) != NULL_TREE)
1036 /* Let `cp_finish_decl' know that this initializer is ok. */
1037 DECL_INITIAL (decl) = init;
1038 if (doing_semantic_analysis_p ())
1040 if (!processing_template_decl)
1042 cp_finish_decl (decl, init, NULL_TREE, 0);
1043 add_stmt (build_stmt (RETURN_INIT, NULL_TREE, NULL_TREE));
1046 add_stmt (build_stmt (RETURN_INIT, return_id, init));
1049 /* Don't use tree-inlining for functions with named return values.
1050 That doesn't work properly because we don't do any translation of
1051 the RETURN_INITs when they are copied. */
1052 DECL_UNINLINABLE (current_function_decl) = 1;
1055 /* The INIT_LIST is a list of mem-initializers, in the order they were
1056 written by the user. The TREE_VALUE of each node is a list of
1057 initializers for a particular subobject. The TREE_PURPOSE is a
1058 FIELD_DECL is the initializer is for a non-static data member, and
1059 a class type if the initializer is for a base class. */
1062 finish_mem_initializers (init_list)
1065 tree member_init_list;
1066 tree base_init_list;
1067 tree last_base_warned_about;
1071 member_init_list = NULL_TREE;
1072 base_init_list = NULL_TREE;
1073 last_base_warned_about = NULL_TREE;
1075 for (init = init_list; init; init = next)
1077 next = TREE_CHAIN (init);
1078 if (TREE_CODE (TREE_PURPOSE (init)) == FIELD_DECL)
1080 TREE_CHAIN (init) = member_init_list;
1081 member_init_list = init;
1083 /* We're running through the initializers from right to left
1084 as we process them here. So, if we see a data member
1085 initializer after we see a base initializer, that
1086 actually means that the base initializer preceeded the
1087 data member initializer. */
1088 if (warn_reorder && last_base_warned_about != base_init_list)
1092 for (base = base_init_list;
1093 base != last_base_warned_about;
1094 base = TREE_CHAIN (base))
1096 cp_warning ("base initializer for `%T'",
1097 TREE_PURPOSE (base));
1098 warning (" will be re-ordered to precede member initializations");
1101 last_base_warned_about = base_init_list;
1106 TREE_CHAIN (init) = base_init_list;
1107 base_init_list = init;
1111 setup_vtbl_ptr (member_init_list, base_init_list);
1114 /* Cache the value of this class's main virtual function table pointer
1115 in a register variable. This will save one indirection if a
1116 more than one virtual function call is made this function. */
1119 setup_vtbl_ptr (member_init_list, base_init_list)
1120 tree member_init_list;
1121 tree base_init_list;
1123 my_friendly_assert (doing_semantic_analysis_p (), 19990919);
1125 /* If we've already done this, there's no need to do it again. */
1129 if (DECL_CONSTRUCTOR_P (current_function_decl))
1131 if (processing_template_decl)
1132 add_stmt (build_min_nt
1134 member_init_list, base_init_list));
1139 /* Mark the beginning of the constructor. */
1140 ctor_stmt = build_stmt (CTOR_STMT);
1141 CTOR_BEGIN_P (ctor_stmt) = 1;
1142 add_stmt (ctor_stmt);
1144 /* And actually initialize the base-classes and members. */
1145 emit_base_init (member_init_list, base_init_list);
1148 else if (DECL_DESTRUCTOR_P (current_function_decl)
1149 && !processing_template_decl)
1154 /* If the dtor is empty, and we know there is not any possible
1155 way we could use any vtable entries, before they are possibly
1156 set by a base class dtor, we don't have to setup the vtables,
1157 as we know that any base class dtor will set up any vtables
1158 it needs. We avoid MI, because one base class dtor can do a
1159 virtual dispatch to an overridden function that would need to
1160 have a non-related vtable set up, we cannot avoid setting up
1161 vtables in that case. We could change this to see if there
1162 is just one vtable. */
1163 if_stmt = begin_if_stmt ();
1165 /* If it is not safe to avoid setting up the vtables, then
1166 someone will change the condition to be boolean_true_node.
1167 (Actually, for now, we do not have code to set the condition
1168 appropriately, so we just assume that we always need to
1169 initialize the vtables.) */
1170 finish_if_stmt_cond (boolean_true_node, if_stmt);
1171 current_vcalls_possible_p = &IF_COND (if_stmt);
1173 compound_stmt = begin_compound_stmt (/*has_no_scope=*/0);
1175 /* Make all virtual function table pointers in non-virtual base
1176 classes point to CURRENT_CLASS_TYPE's virtual function
1178 initialize_vtbl_ptrs (current_class_ptr);
1180 finish_compound_stmt (/*has_no_scope=*/0, compound_stmt);
1181 finish_then_clause (if_stmt);
1185 /* Always keep the BLOCK node associated with the outermost pair of
1186 curly braces of a function. These are needed for correct
1187 operation of dwarfout.c. */
1188 keep_next_level (1);
1190 /* The virtual function tables are set up now. */
1194 /* Returns the stack of SCOPE_STMTs for the current function. */
1197 current_scope_stmt_stack ()
1199 return &cfun->language->x_scope_stmt_stack;
1202 /* Finish a parenthesized expression EXPR. */
1205 finish_parenthesized_expr (expr)
1208 if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (TREE_CODE (expr))))
1209 /* This inhibits warnings in truthvalue_conversion. */
1210 C_SET_EXP_ORIGINAL_CODE (expr, ERROR_MARK);
1212 if (TREE_CODE (expr) == OFFSET_REF)
1213 /* [expr.unary.op]/3 The qualified id of a pointer-to-member must not be
1214 enclosed in parentheses. */
1215 PTRMEM_OK_P (expr) = 0;
1219 /* Begin a statement-expression. The value returned must be passed to
1220 finish_stmt_expr. */
1225 /* If we're outside a function, we won't have a statement-tree to
1226 work with. But, if we see a statement-expression we need to
1228 if (! cfun && !last_tree)
1229 begin_stmt_tree (&scope_chain->x_saved_tree);
1231 keep_next_level (1);
1232 /* If we're building a statement tree, then the upcoming compound
1233 statement will be chained onto the tree structure, starting at
1234 last_tree. We return last_tree so that we can later unhook the
1235 compound statement. */
1239 /* Used when beginning a statement-expression outside function scope.
1240 For example, when handling a file-scope initializer, we use this
1244 begin_global_stmt_expr ()
1246 if (! cfun && !last_tree)
1247 begin_stmt_tree (&scope_chain->x_saved_tree);
1249 keep_next_level (1);
1251 return (last_tree != NULL_TREE) ? last_tree : expand_start_stmt_expr();
1254 /* Finish the STMT_EXPR last begun with begin_global_stmt_expr. */
1257 finish_global_stmt_expr (stmt_expr)
1260 stmt_expr = expand_end_stmt_expr (stmt_expr);
1263 && TREE_CHAIN (scope_chain->x_saved_tree) == NULL_TREE)
1264 finish_stmt_tree (&scope_chain->x_saved_tree);
1269 /* Finish a statement-expression. RTL_EXPR should be the value
1270 returned by the previous begin_stmt_expr; EXPR is the
1271 statement-expression. Returns an expression representing the
1272 statement-expression. */
1275 finish_stmt_expr (rtl_expr)
1280 /* If the last thing in the statement-expression was not an
1281 expression-statement, then it has type `void'. */
1282 if (!last_expr_type)
1283 last_expr_type = void_type_node;
1284 result = build_min (STMT_EXPR, last_expr_type, last_tree);
1285 TREE_SIDE_EFFECTS (result) = 1;
1287 /* Remove the compound statement from the tree structure; it is
1288 now saved in the STMT_EXPR. */
1289 last_tree = rtl_expr;
1290 TREE_CHAIN (last_tree) = NULL_TREE;
1292 /* If we created a statement-tree for this statement-expression,
1295 && TREE_CHAIN (scope_chain->x_saved_tree) == NULL_TREE)
1296 finish_stmt_tree (&scope_chain->x_saved_tree);
1301 /* Finish a call to FN with ARGS. Returns a representation of the
1305 finish_call_expr (fn, args, koenig)
1314 if (TREE_CODE (fn) == BIT_NOT_EXPR)
1315 fn = build_x_unary_op (BIT_NOT_EXPR, TREE_OPERAND (fn, 0));
1316 else if (TREE_CODE (fn) != TEMPLATE_ID_EXPR)
1317 fn = do_identifier (fn, 2, args);
1319 result = build_x_function_call (fn, args, current_class_ref);
1321 if (TREE_CODE (result) == CALL_EXPR
1322 && (! TREE_TYPE (result)
1323 || TREE_CODE (TREE_TYPE (result)) != VOID_TYPE))
1324 result = require_complete_type (result);
1329 /* Finish a call to a postfix increment or decrement or EXPR. (Which
1330 is indicated by CODE, which should be POSTINCREMENT_EXPR or
1331 POSTDECREMENT_EXPR.) */
1334 finish_increment_expr (expr, code)
1336 enum tree_code code;
1338 /* If we get an OFFSET_REF, turn it into what it really means (e.g.,
1339 a COMPONENT_REF). This way if we've got, say, a reference to a
1340 static member that's being operated on, we don't end up trying to
1341 find a member operator for the class it's in. */
1343 if (TREE_CODE (expr) == OFFSET_REF)
1344 expr = resolve_offset_ref (expr);
1345 return build_x_unary_op (code, expr);
1348 /* Finish a use of `this'. Returns an expression for `this'. */
1355 if (current_class_ptr)
1357 #ifdef WARNING_ABOUT_CCD
1358 TREE_USED (current_class_ptr) = 1;
1360 result = current_class_ptr;
1362 else if (current_function_decl
1363 && DECL_STATIC_FUNCTION_P (current_function_decl))
1365 error ("`this' is unavailable for static member functions");
1366 result = error_mark_node;
1370 if (current_function_decl)
1371 error ("invalid use of `this' in non-member function");
1373 error ("invalid use of `this' at top level");
1374 result = error_mark_node;
1380 /* Finish a member function call using OBJECT and ARGS as arguments to
1381 FN. Returns an expression for the call. */
1384 finish_object_call_expr (fn, object, args)
1390 /* This is a future direction of this code, but because
1391 build_x_function_call cannot always undo what is done in
1392 build_component_ref entirely yet, we cannot do this. */
1394 tree real_fn = build_component_ref (object, fn, NULL_TREE, 1);
1395 return finish_call_expr (real_fn, args);
1397 if (DECL_DECLARES_TYPE_P (fn))
1399 if (processing_template_decl)
1400 /* This can happen on code like:
1403 template <class T> void f(T t) {
1407 We just grab the underlying IDENTIFIER. */
1408 fn = DECL_NAME (fn);
1411 cp_error ("calling type `%T' like a method", fn);
1412 return error_mark_node;
1416 return build_method_call (object, fn, args, NULL_TREE, LOOKUP_NORMAL);
1420 /* Finish a qualified member function call using OBJECT and ARGS as
1421 arguments to FN. Returns an expression for the call. */
1424 finish_qualified_object_call_expr (fn, object, args)
1429 return build_scoped_method_call (object, TREE_OPERAND (fn, 0),
1430 TREE_OPERAND (fn, 1), args);
1433 /* Finish a pseudo-destructor call expression of OBJECT, with SCOPE
1434 being the scope, if any, of DESTRUCTOR. Returns an expression for
1438 finish_pseudo_destructor_call_expr (object, scope, destructor)
1443 if (processing_template_decl)
1444 return build_min_nt (PSEUDO_DTOR_EXPR, object, scope, destructor);
1446 if (scope && scope != destructor)
1447 cp_error ("destructor specifier `%T::~%T()' must have matching names",
1450 if ((scope == NULL_TREE || IDENTIFIER_GLOBAL_VALUE (destructor))
1451 && (TREE_CODE (TREE_TYPE (object)) !=
1452 TREE_CODE (TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (destructor)))))
1453 cp_error ("`%E' is not of type `%T'", object, destructor);
1455 return cp_convert (void_type_node, object);
1458 /* Finish a call to a globally qualified member function FN using
1459 ARGS. Returns an expression for the call. */
1462 finish_qualified_call_expr (fn, args)
1466 if (processing_template_decl)
1467 return build_min_nt (CALL_EXPR, fn, args, NULL_TREE);
1469 return build_member_call (TREE_OPERAND (fn, 0),
1470 TREE_OPERAND (fn, 1),
1474 /* Finish an expression of the form CODE EXPR. */
1477 finish_unary_op_expr (code, expr)
1478 enum tree_code code;
1481 tree result = build_x_unary_op (code, expr);
1482 /* Inside a template, build_x_unary_op does not fold the
1483 expression. So check whether the result is folded before
1484 setting TREE_NEGATED_INT. */
1485 if (code == NEGATE_EXPR && TREE_CODE (expr) == INTEGER_CST
1486 && TREE_CODE (result) == INTEGER_CST
1487 && !TREE_UNSIGNED (TREE_TYPE (result))
1488 && INT_CST_LT (result, integer_zero_node))
1489 TREE_NEGATED_INT (result) = 1;
1490 overflow_warning (result);
1494 /* Finish an id-expression. */
1497 finish_id_expr (expr)
1500 if (TREE_CODE (expr) == IDENTIFIER_NODE)
1501 expr = do_identifier (expr, 1, NULL_TREE);
1503 if (TREE_TYPE (expr) == error_mark_node)
1504 expr = error_mark_node;
1508 static tree current_type_lookups;
1510 /* Perform deferred access control for types used in the type of a
1514 deferred_type_access_control ()
1516 tree lookup = type_lookups;
1518 if (lookup == error_mark_node)
1521 for (; lookup; lookup = TREE_CHAIN (lookup))
1522 enforce_access (TREE_PURPOSE (lookup), TREE_VALUE (lookup));
1526 decl_type_access_control (decl)
1531 if (type_lookups == error_mark_node)
1534 save_fn = current_function_decl;
1536 if (decl && TREE_CODE (decl) == FUNCTION_DECL)
1537 current_function_decl = decl;
1539 deferred_type_access_control ();
1541 current_function_decl = save_fn;
1543 /* Now strip away the checks for the current declarator; they were
1544 added to type_lookups after typed_declspecs saved the copy that
1545 ended up in current_type_lookups. */
1546 type_lookups = current_type_lookups;
1548 current_type_lookups = NULL_TREE;
1551 /* Record the lookups, if we're doing deferred access control. */
1554 save_type_access_control (lookups)
1557 if (type_lookups != error_mark_node)
1559 my_friendly_assert (!current_type_lookups, 20010301);
1560 current_type_lookups = lookups;
1563 my_friendly_assert (!lookups || lookups == error_mark_node, 20010301);
1566 /* Set things up so that the next deferred access control will succeed.
1567 This is needed for friend declarations see grokdeclarator for details. */
1570 skip_type_access_control ()
1572 type_lookups = NULL_TREE;
1575 /* Reset the deferred access control. */
1578 reset_type_access_control ()
1580 type_lookups = NULL_TREE;
1581 current_type_lookups = NULL_TREE;
1584 /* Begin a function definition declared with DECL_SPECS and
1585 DECLARATOR. Returns non-zero if the function-declaration is
1589 begin_function_definition (decl_specs, declarator)
1596 split_specs_attrs (decl_specs, &specs, &attrs);
1597 if (!start_function (specs, declarator, attrs, SF_DEFAULT))
1600 deferred_type_access_control ();
1601 type_lookups = error_mark_node;
1603 /* The things we're about to see are not directly qualified by any
1604 template headers we've seen thus far. */
1605 reset_specialization ();
1610 /* Begin a constructor declarator of the form `SCOPE::NAME'. Returns
1614 begin_constructor_declarator (scope, name)
1618 tree result = build_nt (SCOPE_REF, scope, name);
1619 enter_scope_of (result);
1623 /* Finish an init-declarator. Returns a DECL. */
1626 finish_declarator (declarator, declspecs, attributes,
1627 prefix_attributes, initialized)
1631 tree prefix_attributes;
1634 return start_decl (declarator, declspecs, initialized, attributes,
1638 /* Finish a translation unit. */
1641 finish_translation_unit ()
1643 /* In case there were missing closebraces,
1644 get us back to the global binding level. */
1646 while (current_namespace != global_namespace)
1649 /* Do file scope __FUNCTION__ et al. */
1650 finish_fname_decls ();
1655 /* Finish a template type parameter, specified as AGGR IDENTIFIER.
1656 Returns the parameter. */
1659 finish_template_type_parm (aggr, identifier)
1663 if (aggr != class_type_node)
1665 pedwarn ("template type parameters must use the keyword `class' or `typename'");
1666 aggr = class_type_node;
1669 return build_tree_list (aggr, identifier);
1672 /* Finish a template template parameter, specified as AGGR IDENTIFIER.
1673 Returns the parameter. */
1676 finish_template_template_parm (aggr, identifier)
1680 tree decl = build_decl (TYPE_DECL, identifier, NULL_TREE);
1681 tree tmpl = build_lang_decl (TEMPLATE_DECL, identifier, NULL_TREE);
1682 DECL_TEMPLATE_PARMS (tmpl) = current_template_parms;
1683 DECL_TEMPLATE_RESULT (tmpl) = decl;
1684 DECL_ARTIFICIAL (decl) = 1;
1685 end_template_decl ();
1687 my_friendly_assert (DECL_TEMPLATE_PARMS (tmpl), 20010110);
1689 return finish_template_type_parm (aggr, tmpl);
1692 /* Finish a parameter list, indicated by PARMS. If ELLIPSIS is
1693 non-zero, the parameter list was terminated by a `...'. */
1696 finish_parmlist (parms, ellipsis)
1702 /* We mark the PARMS as a parmlist so that declarator processing can
1703 disambiguate certain constructs. */
1704 TREE_PARMLIST (parms) = 1;
1705 /* We do not append void_list_node here, but leave it to grokparms
1707 PARMLIST_ELLIPSIS_P (parms) = ellipsis;
1712 /* Begin a class definition, as indicated by T. */
1715 begin_class_definition (t)
1718 /* Check the bases are accessible. */
1719 decl_type_access_control (TYPE_NAME (t));
1720 reset_type_access_control ();
1722 if (processing_template_parmlist)
1724 cp_error ("definition of `%#T' inside template parameter list", t);
1725 return error_mark_node;
1728 /* In a definition of a member class template, we will get here with
1729 an implicit typename. */
1730 if (IMPLICIT_TYPENAME_P (t))
1732 /* A non-implicit typename comes from code like:
1734 template <typename T> struct A {
1735 template <typename U> struct A<T>::B ...
1737 This is erroneous. */
1738 else if (TREE_CODE (t) == TYPENAME_TYPE)
1740 cp_error ("invalid definition of qualified type `%T'", t);
1741 t = error_mark_node;
1744 if (t == error_mark_node || ! IS_AGGR_TYPE (t))
1746 t = make_aggr_type (RECORD_TYPE);
1747 pushtag (make_anon_name (), t, 0);
1750 /* If we generated a partial instantiation of this type, but now
1751 we're seeing a real definition, we're actually looking at a
1752 partial specialization. Consider:
1754 template <class T, class U>
1760 template <class T, class U>
1763 typename X<Y<T, U> >::A a;
1766 template <class T, class U>
1771 We have to undo the effects of the previous partial
1773 if (PARTIAL_INSTANTIATION_P (t))
1777 /* Unfortunately, when we're not in pedantic mode, we
1778 attempt to actually fill in some of the fields of the
1779 partial instantiation, in order to support the implicit
1780 typename extension. Clear those fields now, in
1781 preparation for the definition here. The fields cleared
1782 here must match those set in instantiate_class_template.
1783 Look for a comment mentioning begin_class_definition
1785 TYPE_BINFO_BASETYPES (t) = NULL_TREE;
1786 TYPE_FIELDS (t) = NULL_TREE;
1787 TYPE_METHODS (t) = NULL_TREE;
1788 CLASSTYPE_TAGS (t) = NULL_TREE;
1789 CLASSTYPE_VBASECLASSES (t) = NULL_TREE;
1790 TYPE_SIZE (t) = NULL_TREE;
1793 /* This isn't a partial instantiation any more. */
1794 PARTIAL_INSTANTIATION_P (t) = 0;
1796 /* If this type was already complete, and we see another definition,
1798 else if (COMPLETE_TYPE_P (t))
1799 duplicate_tag_error (t);
1801 /* Update the location of the decl. */
1802 DECL_SOURCE_FILE (TYPE_NAME (t)) = input_filename;
1803 DECL_SOURCE_LINE (TYPE_NAME (t)) = lineno;
1805 if (TYPE_BEING_DEFINED (t))
1807 t = make_aggr_type (TREE_CODE (t));
1808 pushtag (TYPE_IDENTIFIER (t), t, 0);
1810 maybe_process_partial_specialization (t);
1812 TYPE_BEING_DEFINED (t) = 1;
1813 TYPE_PACKED (t) = flag_pack_struct;
1814 /* Reset the interface data, at the earliest possible
1815 moment, as it might have been set via a class foo;
1817 if (! TYPE_ANONYMOUS_P (t))
1819 CLASSTYPE_INTERFACE_ONLY (t) = interface_only;
1820 SET_CLASSTYPE_INTERFACE_UNKNOWN_X
1821 (t, interface_unknown);
1823 reset_specialization();
1825 /* Make a declaration for this class in its own scope. */
1826 build_self_reference ();
1831 /* Finish the member declaration given by DECL. */
1834 finish_member_declaration (decl)
1837 if (decl == error_mark_node || decl == NULL_TREE)
1840 if (decl == void_type_node)
1841 /* The COMPONENT was a friend, not a member, and so there's
1842 nothing for us to do. */
1845 /* We should see only one DECL at a time. */
1846 my_friendly_assert (TREE_CHAIN (decl) == NULL_TREE, 0);
1848 /* Set up access control for DECL. */
1850 = (current_access_specifier == access_private_node);
1851 TREE_PROTECTED (decl)
1852 = (current_access_specifier == access_protected_node);
1853 if (TREE_CODE (decl) == TEMPLATE_DECL)
1855 TREE_PRIVATE (DECL_TEMPLATE_RESULT (decl)) = TREE_PRIVATE (decl);
1856 TREE_PROTECTED (DECL_TEMPLATE_RESULT (decl)) = TREE_PROTECTED (decl);
1859 /* Mark the DECL as a member of the current class. */
1860 DECL_CONTEXT (decl) = current_class_type;
1864 A C language linkage is ignored for the names of class members
1865 and the member function type of class member functions. */
1866 if (DECL_LANG_SPECIFIC (decl) && DECL_LANGUAGE (decl) == lang_c)
1867 SET_DECL_LANGUAGE (decl, lang_cplusplus);
1869 /* Put functions on the TYPE_METHODS list and everything else on the
1870 TYPE_FIELDS list. Note that these are built up in reverse order.
1871 We reverse them (to obtain declaration order) in finish_struct. */
1872 if (TREE_CODE (decl) == FUNCTION_DECL
1873 || DECL_FUNCTION_TEMPLATE_P (decl))
1875 /* We also need to add this function to the
1876 CLASSTYPE_METHOD_VEC. */
1877 add_method (current_class_type, decl, /*error_p=*/0);
1879 TREE_CHAIN (decl) = TYPE_METHODS (current_class_type);
1880 TYPE_METHODS (current_class_type) = decl;
1884 /* All TYPE_DECLs go at the end of TYPE_FIELDS. Ordinary fields
1885 go at the beginning. The reason is that lookup_field_1
1886 searches the list in order, and we want a field name to
1887 override a type name so that the "struct stat hack" will
1888 work. In particular:
1890 struct S { enum E { }; int E } s;
1893 is legal. In addition, the FIELD_DECLs must be maintained in
1894 declaration order so that class layout works as expected.
1895 However, we don't need that order until class layout, so we
1896 save a little time by putting FIELD_DECLs on in reverse order
1897 here, and then reversing them in finish_struct_1. (We could
1898 also keep a pointer to the correct insertion points in the
1901 if (TREE_CODE (decl) == TYPE_DECL)
1902 TYPE_FIELDS (current_class_type)
1903 = chainon (TYPE_FIELDS (current_class_type), decl);
1906 TREE_CHAIN (decl) = TYPE_FIELDS (current_class_type);
1907 TYPE_FIELDS (current_class_type) = decl;
1910 /* Enter the DECL into the scope of the class. */
1911 if (TREE_CODE (decl) != USING_DECL)
1912 pushdecl_class_level (decl);
1916 /* Finish a class definition T with the indicate ATTRIBUTES. If SEMI,
1917 the definition is immediately followed by a semicolon. Returns the
1921 finish_class_definition (t, attributes, semi, pop_scope_p)
1927 /* finish_struct nukes this anyway; if finish_exception does too,
1930 note_got_semicolon (t);
1932 /* If we got any attributes in class_head, xref_tag will stick them in
1933 TREE_TYPE of the type. Grab them now. */
1934 attributes = chainon (TREE_TYPE (t), attributes);
1935 TREE_TYPE (t) = NULL_TREE;
1937 if (TREE_CODE (t) == ENUMERAL_TYPE)
1941 t = finish_struct (t, attributes);
1943 note_got_semicolon (t);
1947 check_for_missing_semicolon (t);
1949 pop_scope (CP_DECL_CONTEXT (TYPE_MAIN_DECL (t)));
1950 if (current_function_decl)
1951 type_lookups = error_mark_node;
1952 if (current_scope () == current_function_decl)
1953 do_pending_defargs ();
1958 /* Finish processing the default argument expressions cached during
1959 the processing of a class definition. */
1962 begin_inline_definitions ()
1964 if (current_scope () == current_function_decl)
1965 do_pending_inlines ();
1968 /* Finish processing the inline function definitions cached during the
1969 processing of a class definition. */
1972 finish_inline_definitions ()
1974 if (current_class_type == NULL_TREE)
1975 clear_inline_text_obstack ();
1978 /* Finish processing the declaration of a member class template
1979 TYPES whose template parameters are given by PARMS. */
1982 finish_member_class_template (types)
1987 /* If there are declared, but undefined, partial specializations
1988 mixed in with the typespecs they will not yet have passed through
1989 maybe_process_partial_specialization, so we do that here. */
1990 for (t = types; t != NULL_TREE; t = TREE_CHAIN (t))
1991 if (IS_AGGR_TYPE_CODE (TREE_CODE (TREE_VALUE (t))))
1992 maybe_process_partial_specialization (TREE_VALUE (t));
1994 note_list_got_semicolon (types);
1995 grok_x_components (types);
1996 if (TYPE_CONTEXT (TREE_VALUE (types)) != current_class_type)
1997 /* The component was in fact a friend declaration. We avoid
1998 finish_member_template_decl performing certain checks by
2002 finish_member_template_decl (types);
2004 /* As with other component type declarations, we do
2005 not store the new DECL on the list of
2010 /* Finish processsing a complete template declaration. The PARMS are
2011 the template parameters. */
2014 finish_template_decl (parms)
2018 end_template_decl ();
2020 end_specialization ();
2023 /* Finish processing a template-id (which names a type) of the form
2024 NAME < ARGS >. Return the TYPE_DECL for the type named by the
2025 template-id. If ENTERING_SCOPE is non-zero we are about to enter
2026 the scope of template-id indicated. */
2029 finish_template_type (name, args, entering_scope)
2036 decl = lookup_template_class (name, args,
2037 NULL_TREE, NULL_TREE,
2038 entering_scope, /*complain=*/1);
2039 if (decl != error_mark_node)
2040 decl = TYPE_STUB_DECL (decl);
2045 /* SR is a SCOPE_REF node. Enter the scope of SR, whether it is a
2046 namespace scope or a class scope. */
2052 tree scope = TREE_OPERAND (sr, 0);
2054 if (TREE_CODE (scope) == NAMESPACE_DECL)
2056 push_decl_namespace (scope);
2057 TREE_COMPLEXITY (sr) = -1;
2059 else if (scope != current_class_type)
2061 if (TREE_CODE (scope) == TYPENAME_TYPE)
2063 /* In a declarator for a template class member, the scope will
2064 get here as an implicit typename, a TYPENAME_TYPE with a type. */
2065 scope = TREE_TYPE (scope);
2066 TREE_OPERAND (sr, 0) = scope;
2068 push_nested_class (scope, 3);
2069 TREE_COMPLEXITY (sr) = current_class_depth;
2073 /* Finish processing a BASE_CLASS with the indicated ACCESS_SPECIFIER.
2074 Return a TREE_LIST containing the ACCESS_SPECIFIER and the
2075 BASE_CLASS, or NULL_TREE if an error occurred. The
2076 ACCESSS_SPECIFIER is one of
2077 access_{default,public,protected_private}[_virtual]_node.*/
2080 finish_base_specifier (access_specifier, base_class)
2081 tree access_specifier;
2086 if (! is_aggr_type (base_class, 1))
2090 if (CP_TYPE_QUALS (base_class) != 0)
2092 cp_error ("base class `%T' has cv qualifiers", base_class);
2093 base_class = TYPE_MAIN_VARIANT (base_class);
2095 result = build_tree_list (access_specifier, base_class);
2101 /* Called when multiple declarators are processed. If that is not
2102 premitted in this context, an error is issued. */
2105 check_multiple_declarators ()
2109 In a template-declaration, explicit specialization, or explicit
2110 instantiation the init-declarator-list in the declaration shall
2111 contain at most one declarator.
2113 We don't just use PROCESSING_TEMPLATE_DECL for the first
2114 condition since that would disallow the perfectly legal code,
2115 like `template <class T> struct S { int i, j; };'. */
2116 tree scope = current_scope ();
2118 if (scope && TREE_CODE (scope) == FUNCTION_DECL)
2119 /* It's OK to write `template <class T> void f() { int i, j;}'. */
2122 if (PROCESSING_REAL_TEMPLATE_DECL_P ()
2123 || processing_explicit_instantiation
2124 || processing_specialization)
2125 cp_error ("multiple declarators in template declaration");
2129 finish_typeof (expr)
2132 if (processing_template_decl)
2136 t = make_aggr_type (TYPEOF_TYPE);
2137 TYPE_FIELDS (t) = expr;
2142 if (TREE_CODE (expr) == OFFSET_REF)
2143 expr = resolve_offset_ref (expr);
2145 return TREE_TYPE (expr);
2148 /* Generate RTL for the statement T, and its substatements, and any
2149 other statements at its nesting level. */
2155 switch (TREE_CODE (t))
2158 genrtl_decl_cleanup (CLEANUP_DECL (t), CLEANUP_EXPR (t));
2162 genrtl_ctor_stmt (t);
2166 genrtl_try_block (t);
2170 genrtl_eh_spec_block (t);
2178 genrtl_subobject (SUBOBJECT_CLEANUP (t));
2182 genrtl_named_return_value ();
2189 my_friendly_abort (19990810);
2194 /* Called from expand_body via walk_tree. Replace all AGGR_INIT_EXPRs
2195 will equivalent CALL_EXPRs. */
2198 simplify_aggr_init_exprs_r (tp, walk_subtrees, data)
2200 int *walk_subtrees ATTRIBUTE_UNUSED;
2201 void *data ATTRIBUTE_UNUSED;
2203 tree aggr_init_expr;
2209 int copy_from_buffer_p;
2211 aggr_init_expr = *tp;
2212 /* We don't need to walk into types; there's nothing in a type that
2213 needs simplification. (And, furthermore, there are places we
2214 actively don't want to go. For example, we don't want to wander
2215 into the default arguments for a FUNCTION_DECL that appears in a
2217 if (TYPE_P (aggr_init_expr))
2222 /* Only AGGR_INIT_EXPRs are interesting. */
2223 else if (TREE_CODE (aggr_init_expr) != AGGR_INIT_EXPR)
2226 /* Form an appropriate CALL_EXPR. */
2227 fn = TREE_OPERAND (aggr_init_expr, 0);
2228 args = TREE_OPERAND (aggr_init_expr, 1);
2229 slot = TREE_OPERAND (aggr_init_expr, 2);
2230 type = TREE_TYPE (aggr_init_expr);
2231 if (AGGR_INIT_VIA_CTOR_P (aggr_init_expr))
2233 /* Replace the first argument with the address of the third
2234 argument to the AGGR_INIT_EXPR. */
2235 mark_addressable (slot);
2236 args = tree_cons (NULL_TREE,
2238 build_pointer_type (TREE_TYPE (slot)),
2242 call_expr = build (CALL_EXPR,
2243 TREE_TYPE (TREE_TYPE (TREE_TYPE (fn))),
2244 fn, args, NULL_TREE);
2245 TREE_SIDE_EFFECTS (call_expr) = 1;
2247 /* If we're using the non-reentrant PCC calling convention, then we
2248 need to copy the returned value out of the static buffer into the
2250 copy_from_buffer_p = 0;
2251 #ifdef PCC_STATIC_STRUCT_RETURN
2252 if (!AGGR_INIT_VIA_CTOR_P (aggr_init_expr) && aggregate_value_p (type))
2254 int old_ac = flag_access_control;
2256 flag_access_control = 0;
2257 call_expr = build_aggr_init (slot, call_expr, LOOKUP_ONLYCONVERTING);
2258 flag_access_control = old_ac;
2259 copy_from_buffer_p = 1;
2263 /* If this AGGR_INIT_EXPR indicates the value returned by a
2264 function, then we want to use the value of the initialized
2265 location as the result. */
2266 if (AGGR_INIT_VIA_CTOR_P (aggr_init_expr) || copy_from_buffer_p)
2268 call_expr = build (COMPOUND_EXPR, type,
2270 TREE_SIDE_EFFECTS (call_expr) = 1;
2273 /* Replace the AGGR_INIT_EXPR with the CALL_EXPR. */
2274 TREE_CHAIN (call_expr) = TREE_CHAIN (aggr_init_expr);
2277 /* Keep iterating. */
2281 /* Emit all thunks to FN that should be emitted when FN is emitted. */
2284 emit_associated_thunks (fn)
2287 /* When we use vcall offsets, we emit thunks with the virtual
2288 functions to which they thunk. The whole point of vcall offsets
2289 is so that you can know statically the entire set of thunks that
2290 will ever be needed for a given virtual function, thereby
2291 enabling you to output all the thunks with the function itself. */
2292 if (vcall_offsets_in_vtable_p () && DECL_VIRTUAL_P (fn))
2297 for (binfo = TYPE_BINFO (DECL_CONTEXT (fn));
2299 binfo = TREE_CHAIN (binfo))
2300 for (v = BINFO_VIRTUALS (binfo); v; v = TREE_CHAIN (v))
2302 && (!integer_zerop (BV_DELTA (v))
2303 || BV_USE_VCALL_INDEX_P (v)))
2308 if (BV_USE_VCALL_INDEX_P (v))
2310 vcall_index = BV_VCALL_INDEX (v);
2311 my_friendly_assert (vcall_index != NULL_TREE, 20000621);
2314 vcall_index = NULL_TREE;
2316 thunk = make_thunk (build1 (ADDR_EXPR,
2317 vfunc_ptr_type_node,
2321 use_thunk (thunk, /*emit_p=*/1);
2326 /* Generate RTL for FN. */
2333 const char *saved_input_filename;
2335 /* When the parser calls us after finishing the body of a template
2336 function, we don't really want to expand the body. When we're
2337 processing an in-class definition of an inline function,
2338 PROCESSING_TEMPLATE_DECL will no longer be set here, so we have
2339 to look at the function itself. */
2340 if (processing_template_decl
2341 || (DECL_LANG_SPECIFIC (fn)
2342 && DECL_TEMPLATE_INFO (fn)
2343 && uses_template_parms (DECL_TI_ARGS (fn))))
2345 /* Normally, collection only occurs in rest_of_compilation. So,
2346 if we don't collect here, we never collect junk generated
2347 during the processing of templates until we hit a
2348 non-template function. */
2353 /* Replace AGGR_INIT_EXPRs with appropriate CALL_EXPRs. */
2354 walk_tree_without_duplicates (&DECL_SAVED_TREE (fn),
2355 simplify_aggr_init_exprs_r,
2358 /* If this is a constructor or destructor body, we have to clone it
2359 under the new ABI. */
2360 if (maybe_clone_body (fn))
2362 /* We don't want to process FN again, so pretend we've written
2363 it out, even though we haven't. */
2364 TREE_ASM_WRITTEN (fn) = 1;
2368 /* There's no reason to do any of the work here if we're only doing
2369 semantic analysis; this code just generates RTL. */
2370 if (flag_syntax_only)
2373 /* If possible, avoid generating RTL for this function. Instead,
2374 just record it as an inline function, and wait until end-of-file
2375 to decide whether to write it out or not. */
2376 if (/* We have to generate RTL if it's not an inline function. */
2377 (DECL_INLINE (fn) || DECL_COMDAT (fn))
2378 /* Or if we have to keep all inline functions anyhow. */
2379 && !flag_keep_inline_functions
2380 /* Or if we actually have a reference to the function. */
2381 && !DECL_NEEDED_P (fn)
2382 /* Or if this is a nested function. */
2383 && !decl_function_context (fn))
2385 /* Set DECL_EXTERNAL so that assemble_external will be called as
2386 necessary. We'll clear it again in finish_file. */
2387 if (!DECL_EXTERNAL (fn))
2389 DECL_NOT_REALLY_EXTERN (fn) = 1;
2390 DECL_EXTERNAL (fn) = 1;
2392 /* Remember this function. In finish_file we'll decide if
2393 we actually need to write this function out. */
2395 /* Let the back-end know that this funtion exists. */
2396 note_deferral_of_defined_inline_function (fn);
2400 /* Compute the appropriate object-file linkage for inline
2402 if (DECL_DECLARED_INLINE_P (fn))
2403 import_export_decl (fn);
2405 /* Emit any thunks that should be emitted at the same time as FN. */
2406 emit_associated_thunks (fn);
2408 timevar_push (TV_INTEGRATION);
2410 /* Optimize the body of the function before expanding it. We do not
2411 optimize thunks, as (1) the backend tries to optimize the call to
2412 the thunkee, (b) the tree based inliner breaks that optimization,
2413 (c) virtual functions are rarely inlineable, and (d)
2414 ASM_OUTPUT_MI_THUNK is there to DTRT anyway. */
2415 if (!DECL_THUNK_P (fn))
2416 optimize_function (fn);
2418 timevar_pop (TV_INTEGRATION);
2419 timevar_push (TV_EXPAND);
2421 /* Save the current file name and line number. When we expand the
2422 body of the function, we'll set LINENO and INPUT_FILENAME so that
2423 error-mesages come out in the right places. */
2424 saved_lineno = lineno;
2425 saved_input_filename = input_filename;
2426 lineno = DECL_SOURCE_LINE (fn);
2427 input_filename = DECL_SOURCE_FILE (fn);
2429 genrtl_start_function (fn);
2430 current_function_is_thunk = DECL_THUNK_P (fn);
2432 /* Expand the body. */
2433 expand_stmt (DECL_SAVED_TREE (fn));
2435 /* Statements should always be full-expressions at the outermost set
2436 of curly braces for a function. */
2437 my_friendly_assert (stmts_are_full_exprs_p (), 19990831);
2439 /* The outermost statement for a function contains the line number
2440 recorded when we finished processing the function. */
2441 lineno = STMT_LINENO (DECL_SAVED_TREE (fn));
2443 /* Generate code for the function. */
2444 genrtl_finish_function (fn);
2446 /* If possible, obliterate the body of the function so that it can
2447 be garbage collected. */
2448 if (dump_enabled_p (TDI_all))
2449 /* Keep the body; we're going to dump it. */
2451 else if (DECL_INLINE (fn) && flag_inline_trees)
2452 /* We might need the body of this function so that we can expand
2453 it inline somewhere else. */
2456 /* We don't need the body; blow it away. */
2457 DECL_SAVED_TREE (fn) = NULL_TREE;
2459 /* And restore the current source position. */
2460 lineno = saved_lineno;
2461 input_filename = saved_input_filename;
2462 extract_interface_info ();
2464 timevar_pop (TV_EXPAND);
2467 /* Start generating the RTL for FN. */
2470 genrtl_start_function (fn)
2475 /* Tell everybody what function we're processing. */
2476 current_function_decl = fn;
2477 /* Get the RTL machinery going for this function. */
2478 init_function_start (fn, DECL_SOURCE_FILE (fn), DECL_SOURCE_LINE (fn));
2479 /* Let everybody know that we're expanding this function, not doing
2480 semantic analysis. */
2483 /* Even though we're inside a function body, we still don't want to
2484 call expand_expr to calculate the size of a variable-sized array.
2485 We haven't necessarily assigned RTL to all variables yet, so it's
2486 not safe to try to expand expressions involving them. */
2487 immediate_size_expand = 0;
2488 cfun->x_dont_save_pending_sizes_p = 1;
2490 /* Let the user know we're compiling this function. */
2491 announce_function (fn);
2493 /* Initialize the per-function data. */
2494 my_friendly_assert (!DECL_PENDING_INLINE_P (fn), 20000911);
2495 if (DECL_SAVED_FUNCTION_DATA (fn))
2497 /* If we already parsed this function, and we're just expanding it
2498 now, restore saved state. */
2499 *cp_function_chain = *DECL_SAVED_FUNCTION_DATA (fn);
2501 /* This function is being processed in whole-function mode; we
2502 already did semantic analysis. */
2503 cfun->x_whole_function_mode_p = 1;
2505 /* If we decided that we didn't want to inline this function,
2506 make sure the back-end knows that. */
2507 if (!current_function_cannot_inline)
2508 current_function_cannot_inline = cp_function_chain->cannot_inline;
2510 /* We don't need the saved data anymore. */
2511 free (DECL_SAVED_FUNCTION_DATA (fn));
2512 DECL_SAVED_FUNCTION_DATA (fn) = NULL;
2515 /* Tell the cross-reference machinery that we're defining this
2517 GNU_xref_function (fn, DECL_ARGUMENTS (fn));
2519 /* Keep track of how many functions we're presently expanding. */
2522 /* Create a binding level for the parameters. */
2523 expand_start_bindings (2);
2524 /* Clear out any previously saved instructions for this function, in
2525 case it was defined more than once. */
2526 DECL_SAVED_INSNS (fn) = NULL;
2527 /* Go through the PARM_DECLs for this function to see if any need
2529 for (parm = DECL_ARGUMENTS (fn); parm; parm = TREE_CHAIN (parm))
2530 if (TREE_TYPE (parm) != error_mark_node
2531 && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TREE_TYPE (parm)))
2533 expand_function_start (fn, /*parms_have_cleanups=*/1);
2537 expand_function_start (fn, /*parms_have_cleanups=*/0);
2538 /* If this function is `main'. */
2539 if (DECL_MAIN_P (fn))
2540 expand_main_function ();
2541 /* Create a binding contour which can be used to catch
2542 cleanup-generated temporaries. */
2543 expand_start_bindings (2);
2546 /* Finish generating the RTL for FN. */
2549 genrtl_finish_function (fn)
2552 tree no_return_label = NULL_TREE;
2555 if (write_symbols != NO_DEBUG)
2557 /* Keep this code around in case we later want to control debug info
2558 based on whether a type is "used". (jason 1999-11-11) */
2560 tree ttype = target_type (fntype);
2563 if (IS_AGGR_TYPE (ttype))
2564 /* Let debugger know it should output info for this type. */
2565 note_debug_info_needed (ttype);
2567 for (parmdecl = DECL_ARGUMENTS (fndecl); parmdecl; parmdecl = TREE_CHAIN (parmdecl))
2569 ttype = target_type (TREE_TYPE (parmdecl));
2570 if (IS_AGGR_TYPE (ttype))
2571 /* Let debugger know it should output info for this type. */
2572 note_debug_info_needed (ttype);
2577 /* Clean house because we will need to reorder insns here. */
2578 do_pending_stack_adjust ();
2580 if (!dtor_label && !DECL_CONSTRUCTOR_P (fn)
2581 && return_label != NULL_RTX
2582 && current_function_return_value == NULL_TREE
2583 && ! DECL_NAME (DECL_RESULT (current_function_decl)))
2584 no_return_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
2586 /* If this function is supposed to return a value, ensure that
2587 we do not fall into the cleanups by mistake. The end of our
2588 function will look like this:
2590 user code (may have return stmt somewhere)
2591 goto no_return_label
2596 NOTE_INSN_FUNCTION_END
2600 If the user omits a return stmt in the USER CODE section, we
2601 will have a control path which reaches NOTE_INSN_FUNCTION_END.
2602 Otherwise, we won't. */
2603 if (no_return_label)
2605 DECL_CONTEXT (no_return_label) = fn;
2606 DECL_INITIAL (no_return_label) = error_mark_node;
2607 DECL_SOURCE_FILE (no_return_label) = input_filename;
2608 DECL_SOURCE_LINE (no_return_label) = lineno;
2609 expand_goto (no_return_label);
2614 /* Remove the binding contour which is used to catch
2615 cleanup-generated temporaries. */
2616 expand_end_bindings (0, 0, 0);
2619 /* Emit label at beginning of cleanup code for parameters. */
2620 emit_label (cleanup_label);
2623 /* Finish building code that will trigger warnings if users forget
2624 to make their functions return values. */
2626 emit_jump (return_label);
2627 if (no_return_label)
2629 /* We don't need to call `expand_*_return' here because we don't
2630 need any cleanups here--this path of code is only for error
2631 checking purposes. */
2632 expand_label (no_return_label);
2635 /* We hard-wired immediate_size_expand to zero in start_function.
2636 Expand_function_end will decrement this variable. So, we set the
2637 variable to one here, so that after the decrement it will remain
2639 immediate_size_expand = 1;
2641 /* Generate rtl for function exit. */
2642 expand_function_end (input_filename, lineno, 1);
2644 /* If this is a nested function (like a template instantiation that
2645 we're compiling in the midst of compiling something else), push a
2646 new GC context. That will keep local variables on the stack from
2647 being collected while we're doing the compilation of this
2649 if (function_depth > 1)
2650 ggc_push_context ();
2652 /* There's no need to defer outputting this function any more; we
2653 know we want to output it. */
2654 DECL_DEFER_OUTPUT (fn) = 0;
2656 /* Run the optimizers and output the assembler code for this
2658 rest_of_compilation (fn);
2660 /* Undo the call to ggc_push_context above. */
2661 if (function_depth > 1)
2664 if (DECL_SAVED_INSNS (fn) && ! TREE_ASM_WRITTEN (fn))
2666 /* Set DECL_EXTERNAL so that assemble_external will be called as
2667 necessary. We'll clear it again in finish_file. */
2668 if (! DECL_EXTERNAL (fn))
2669 DECL_NOT_REALLY_EXTERN (fn) = 1;
2670 DECL_EXTERNAL (fn) = 1;
2675 /* Keep this code around in case we later want to control debug info
2676 based on whether a type is "used". (jason 1999-11-11) */
2678 if (ctype && TREE_ASM_WRITTEN (fn))
2679 note_debug_info_needed (ctype);
2682 /* If this function is marked with the constructor attribute, add it
2683 to the list of functions to be called along with constructors
2684 from static duration objects. */
2685 if (DECL_STATIC_CONSTRUCTOR (fn))
2686 static_ctors = tree_cons (NULL_TREE, fn, static_ctors);
2688 /* If this function is marked with the destructor attribute, add it
2689 to the list of functions to be called along with destructors from
2690 static duration objects. */
2691 if (DECL_STATIC_DESTRUCTOR (fn))
2692 static_dtors = tree_cons (NULL_TREE, fn, static_dtors);
2696 /* If we don't need the RTL for this function anymore, stop pointing
2697 to it. That's especially important for LABEL_DECLs, since you
2698 can reach all the instructions in the function from the
2699 CODE_LABEL stored in the DECL_RTL for the LABEL_DECL. */
2700 if (!DECL_SAVED_INSNS (fn))
2704 /* Walk the BLOCK-tree, clearing DECL_RTL for LABEL_DECLs and
2705 non-static local variables. */
2706 walk_tree_without_duplicates (&DECL_SAVED_TREE (fn),
2710 /* Clear out the RTL for the arguments. */
2711 for (t = DECL_ARGUMENTS (fn); t; t = TREE_CHAIN (t))
2713 SET_DECL_RTL (t, NULL_RTX);
2714 DECL_INCOMING_RTL (t) = NULL_RTX;
2717 if (!(flag_inline_trees && DECL_INLINE (fn)))
2718 /* DECL_INITIAL must remain nonzero so we know this was an
2719 actual function definition. */
2720 DECL_INITIAL (fn) = error_mark_node;
2723 /* Let the error reporting routines know that we're outside a
2724 function. For a nested function, this value is used in
2725 pop_cp_function_context and then reset via pop_function_context. */
2726 current_function_decl = NULL_TREE;
2729 /* Clear out the DECL_RTL for the non-static variables in BLOCK and
2733 clear_decl_rtl (tp, walk_subtrees, data)
2735 int *walk_subtrees ATTRIBUTE_UNUSED;
2736 void *data ATTRIBUTE_UNUSED;
2738 if (nonstatic_local_decl_p (*tp))
2739 SET_DECL_RTL (*tp, NULL_RTX);
2744 /* Perform initialization related to this module. */
2747 init_cp_semantics ()
2749 lang_expand_stmt = cp_expand_stmt;