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, 2002 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
31 #include "tree-inline.h"
43 /* There routines provide a modular interface to perform many parsing
44 operations. They may therefore be used during actual parsing, or
45 during template instantiation, which may be regarded as a
46 degenerate form of parsing. Since the current g++ parser is
47 lacking in several respects, and will be reimplemented, we are
48 attempting to move most code that is not directly related to
49 parsing into this file; that will make implementing the new parser
50 much easier since it will be able to make use of these routines. */
52 static tree maybe_convert_cond PARAMS ((tree));
53 static tree simplify_aggr_init_exprs_r PARAMS ((tree *, int *, void *));
54 static void deferred_type_access_control PARAMS ((void));
55 static void emit_associated_thunks PARAMS ((tree));
56 static void genrtl_try_block PARAMS ((tree));
57 static void genrtl_eh_spec_block PARAMS ((tree));
58 static void genrtl_handler 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->base.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 ANON_AGGR_TYPE_P (node);
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)
206 tree expr_type = NULL_TREE;;
208 if (expr != NULL_TREE)
210 if (!processing_template_decl
211 && !(stmts_are_full_exprs_p ())
212 && ((TREE_CODE (TREE_TYPE (expr)) == ARRAY_TYPE
214 || TREE_CODE (TREE_TYPE (expr)) == FUNCTION_TYPE))
215 expr = default_conversion (expr);
217 /* Remember the type of the expression. */
218 expr_type = TREE_TYPE (expr);
220 if (stmts_are_full_exprs_p ())
221 expr = convert_to_void (expr, "statement");
223 r = add_stmt (build_stmt (EXPR_STMT, expr));
228 /* This was an expression-statement, so we save the type of the
230 last_expr_type = expr_type;
236 /* Begin an if-statement. Returns a newly created IF_STMT if
244 r = build_stmt (IF_STMT, NULL_TREE, NULL_TREE, NULL_TREE);
249 /* Process the COND of an if-statement, which may be given by
253 finish_if_stmt_cond (cond, if_stmt)
257 cond = maybe_convert_cond (cond);
258 FINISH_COND (cond, if_stmt, IF_COND (if_stmt));
261 /* Finish the then-clause of an if-statement, which may be given by
265 finish_then_clause (if_stmt)
268 RECHAIN_STMTS (if_stmt, THEN_CLAUSE (if_stmt));
273 /* Begin the else-clause of an if-statement. */
280 /* Finish the else-clause of an if-statement, which may be given by
284 finish_else_clause (if_stmt)
287 RECHAIN_STMTS (if_stmt, ELSE_CLAUSE (if_stmt));
290 /* Finish an if-statement. */
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 /* Begin a while-statement. Returns a newly created WHILE_STMT if
319 r = build_stmt (WHILE_STMT, NULL_TREE, NULL_TREE);
325 /* Process the COND of a while-statement, which may be given by
329 finish_while_stmt_cond (cond, while_stmt)
333 cond = maybe_convert_cond (cond);
334 FINISH_COND (cond, while_stmt, WHILE_COND (while_stmt));
338 /* Finish a while-statement, which may be given by WHILE_STMT. */
341 finish_while_stmt (while_stmt)
345 RECHAIN_STMTS (while_stmt, WHILE_BODY (while_stmt));
349 /* Begin a do-statement. Returns a newly created DO_STMT if
355 tree r = build_stmt (DO_STMT, NULL_TREE, NULL_TREE);
360 /* Finish the body of a do-statement, which may be given by DO_STMT. */
363 finish_do_body (do_stmt)
366 RECHAIN_STMTS (do_stmt, DO_BODY (do_stmt));
369 /* Finish a do-statement, which may be given by DO_STMT, and whose
370 COND is as indicated. */
373 finish_do_stmt (cond, do_stmt)
377 cond = maybe_convert_cond (cond);
378 DO_COND (do_stmt) = cond;
382 /* Finish a return-statement. The EXPRESSION returned, if any, is as
386 finish_return_stmt (expr)
391 if (!processing_template_decl)
392 expr = check_return_expr (expr);
393 if (!processing_template_decl)
395 if (DECL_DESTRUCTOR_P (current_function_decl))
397 /* Similarly, all destructors must run destructors for
398 base-classes before returning. So, all returns in a
399 destructor get sent to the DTOR_LABEL; finish_function emits
400 code to return a value there. */
401 return finish_goto_stmt (dtor_label);
404 r = add_stmt (build_stmt (RETURN_STMT, expr));
410 /* Begin a for-statement. Returns a new FOR_STMT if appropriate. */
417 r = build_stmt (FOR_STMT, NULL_TREE, NULL_TREE,
418 NULL_TREE, NULL_TREE);
419 NEW_FOR_SCOPE_P (r) = flag_new_for_scope > 0;
420 if (NEW_FOR_SCOPE_P (r))
423 note_level_for_for ();
430 /* Finish the for-init-statement of a for-statement, which may be
431 given by FOR_STMT. */
434 finish_for_init_stmt (for_stmt)
437 if (last_tree != for_stmt)
438 RECHAIN_STMTS (for_stmt, FOR_INIT_STMT (for_stmt));
442 /* Finish the COND of a for-statement, which may be given by
446 finish_for_cond (cond, for_stmt)
450 cond = maybe_convert_cond (cond);
451 FINISH_COND (cond, for_stmt, FOR_COND (for_stmt));
455 /* Finish the increment-EXPRESSION in a for-statement, which may be
456 given by FOR_STMT. */
459 finish_for_expr (expr, for_stmt)
463 FOR_EXPR (for_stmt) = expr;
466 /* Finish the body of a for-statement, which may be given by
467 FOR_STMT. The increment-EXPR for the loop must be
471 finish_for_stmt (for_stmt)
474 /* Pop the scope for the body of the loop. */
476 RECHAIN_STMTS (for_stmt, FOR_BODY (for_stmt));
477 if (NEW_FOR_SCOPE_P (for_stmt))
482 /* Finish a break-statement. */
487 return add_stmt (build_break_stmt ());
490 /* Finish a continue-statement. */
493 finish_continue_stmt ()
495 return add_stmt (build_continue_stmt ());
498 /* Begin a switch-statement. Returns a new SWITCH_STMT if
505 r = build_stmt (SWITCH_STMT, NULL_TREE, NULL_TREE, NULL_TREE);
511 /* Finish the cond of a switch-statement. */
514 finish_switch_cond (cond, switch_stmt)
518 tree orig_type = NULL;
519 if (!processing_template_decl)
523 /* Convert the condition to an integer or enumeration type. */
524 cond = build_expr_type_conversion (WANT_INT | WANT_ENUM, cond, 1);
525 if (cond == NULL_TREE)
527 error ("switch quantity not an integer");
528 cond = error_mark_node;
530 orig_type = TREE_TYPE (cond);
531 if (cond != error_mark_node)
533 cond = default_conversion (cond);
534 cond = fold (build1 (CLEANUP_POINT_EXPR, TREE_TYPE (cond), cond));
537 if (cond != error_mark_node)
539 index = get_unwidened (cond, NULL_TREE);
540 /* We can't strip a conversion from a signed type to an unsigned,
541 because if we did, int_fits_type_p would do the wrong thing
542 when checking case values for being in range,
543 and it's too hard to do the right thing. */
544 if (TREE_UNSIGNED (TREE_TYPE (cond))
545 == TREE_UNSIGNED (TREE_TYPE (index)))
549 FINISH_COND (cond, switch_stmt, SWITCH_COND (switch_stmt));
550 SWITCH_TYPE (switch_stmt) = orig_type;
551 push_switch (switch_stmt);
554 /* Finish the body of a switch-statement, which may be given by
555 SWITCH_STMT. The COND to switch on is indicated. */
558 finish_switch_stmt (switch_stmt)
561 RECHAIN_STMTS (switch_stmt, SWITCH_BODY (switch_stmt));
567 /* Generate the RTL for T, which is a TRY_BLOCK. */
575 expand_eh_region_start ();
576 expand_stmt (TRY_STMTS (t));
577 expand_eh_region_end_cleanup (TRY_HANDLERS (t));
581 if (!FN_TRY_BLOCK_P (t))
582 emit_line_note (input_filename, lineno);
584 expand_eh_region_start ();
585 expand_stmt (TRY_STMTS (t));
587 if (FN_TRY_BLOCK_P (t))
589 expand_start_all_catch ();
590 in_function_try_handler = 1;
591 expand_stmt (TRY_HANDLERS (t));
592 in_function_try_handler = 0;
593 expand_end_all_catch ();
597 expand_start_all_catch ();
598 expand_stmt (TRY_HANDLERS (t));
599 expand_end_all_catch ();
604 /* Generate the RTL for T, which is an EH_SPEC_BLOCK. */
607 genrtl_eh_spec_block (t)
610 expand_eh_region_start ();
611 expand_stmt (EH_SPEC_STMTS (t));
612 expand_eh_region_end_allowed (EH_SPEC_RAISES (t),
613 build_call (call_unexpected_node,
614 tree_cons (NULL_TREE,
619 /* Begin a try-block. Returns a newly-created TRY_BLOCK if
625 tree r = build_stmt (TRY_BLOCK, NULL_TREE, NULL_TREE);
630 /* Likewise, for a function-try-block. */
633 begin_function_try_block ()
635 tree r = build_stmt (TRY_BLOCK, NULL_TREE, NULL_TREE);
636 FN_TRY_BLOCK_P (r) = 1;
641 /* Finish a try-block, which may be given by TRY_BLOCK. */
644 finish_try_block (try_block)
647 RECHAIN_STMTS (try_block, TRY_STMTS (try_block));
650 /* Finish the body of a cleanup try-block, which may be given by
654 finish_cleanup_try_block (try_block)
657 RECHAIN_STMTS (try_block, TRY_STMTS (try_block));
660 /* Finish an implicitly generated try-block, with a cleanup is given
664 finish_cleanup (cleanup, try_block)
668 TRY_HANDLERS (try_block) = cleanup;
669 CLEANUP_P (try_block) = 1;
672 /* Likewise, for a function-try-block. */
675 finish_function_try_block (try_block)
678 if (TREE_CHAIN (try_block)
679 && TREE_CODE (TREE_CHAIN (try_block)) == CTOR_INITIALIZER)
681 /* Chain the compound statement after the CTOR_INITIALIZER. */
682 TREE_CHAIN (TREE_CHAIN (try_block)) = last_tree;
683 /* And make the CTOR_INITIALIZER the body of the try-block. */
684 RECHAIN_STMTS (try_block, TRY_STMTS (try_block));
687 RECHAIN_STMTS (try_block, TRY_STMTS (try_block));
688 in_function_try_handler = 1;
691 /* Finish a handler-sequence for a try-block, which may be given by
695 finish_handler_sequence (try_block)
698 RECHAIN_STMTS (try_block, TRY_HANDLERS (try_block));
699 check_handlers (TRY_HANDLERS (try_block));
702 /* Likewise, for a function-try-block. */
705 finish_function_handler_sequence (try_block)
708 in_function_try_handler = 0;
709 RECHAIN_STMTS (try_block, TRY_HANDLERS (try_block));
710 check_handlers (TRY_HANDLERS (try_block));
713 /* Generate the RTL for T, which is a HANDLER. */
719 genrtl_do_pushlevel ();
720 if (!processing_template_decl)
721 expand_start_catch (HANDLER_TYPE (t));
722 expand_stmt (HANDLER_BODY (t));
723 if (!processing_template_decl)
727 /* Begin a handler. Returns a HANDLER if appropriate. */
733 r = build_stmt (HANDLER, NULL_TREE, NULL_TREE);
735 /* Create a binding level for the eh_info and the exception object
738 note_level_for_catch ();
742 /* Finish the handler-parameters for a handler, which may be given by
743 HANDLER. DECL is the declaration for the catch parameter, or NULL
744 if this is a `catch (...)' clause. */
747 finish_handler_parms (decl, handler)
751 tree type = NULL_TREE;
752 if (processing_template_decl)
756 decl = pushdecl (decl);
757 decl = push_template_decl (decl);
758 add_decl_stmt (decl);
759 RECHAIN_STMTS (handler, HANDLER_PARMS (handler));
760 type = TREE_TYPE (decl);
764 type = expand_start_catch_block (decl);
766 HANDLER_TYPE (handler) = type;
769 /* Finish a handler, which may be given by HANDLER. The BLOCKs are
770 the return value from the matching call to finish_handler_parms. */
773 finish_handler (handler)
776 if (!processing_template_decl)
777 expand_end_catch_block ();
779 RECHAIN_STMTS (handler, HANDLER_BODY (handler));
782 /* Begin a compound-statement. If HAS_NO_SCOPE is non-zero, the
783 compound-statement does not define a scope. Returns a new
784 COMPOUND_STMT if appropriate. */
787 begin_compound_stmt (has_no_scope)
793 r = build_stmt (COMPOUND_STMT, NULL_TREE);
795 if (last_tree && TREE_CODE (last_tree) == TRY_BLOCK)
800 COMPOUND_STMT_NO_SCOPE (r) = 1;
802 last_expr_type = NULL_TREE;
808 note_level_for_try ();
811 /* Normally, we try hard to keep the BLOCK for a
812 statement-expression. But, if it's a statement-expression with
813 a scopeless block, there's nothing to keep, and we don't want
814 to accidentally keep a block *inside* the scopeless block. */
820 /* Finish a compound-statement, which may be given by COMPOUND_STMT.
821 If HAS_NO_SCOPE is non-zero, the compound statement does not define
825 finish_compound_stmt (has_no_scope, compound_stmt)
837 RECHAIN_STMTS (compound_stmt, COMPOUND_BODY (compound_stmt));
839 /* When we call finish_stmt we will lose LAST_EXPR_TYPE. But, since
840 the precise purpose of that variable is store the type of the
841 last expression statement within the last compound statement, we
842 preserve the value. */
850 /* Finish an asm-statement, whose components are a CV_QUALIFIER, a
851 STRING, some OUTPUT_OPERANDS, some INPUT_OPERANDS, and some
855 finish_asm_stmt (cv_qualifier, string, output_operands,
856 input_operands, clobbers)
859 tree output_operands;
866 if (cv_qualifier != NULL_TREE
867 && cv_qualifier != ridpointers[(int) RID_VOLATILE])
869 warning ("%s qualifier ignored on asm",
870 IDENTIFIER_POINTER (cv_qualifier));
871 cv_qualifier = NULL_TREE;
874 if (!processing_template_decl)
880 for (t = input_operands; t; t = TREE_CHAIN (t))
882 tree converted_operand
883 = decay_conversion (TREE_VALUE (t));
885 /* If the type of the operand hasn't been determined (e.g.,
886 because it involves an overloaded function), then issue
887 an error message. There's no context available to
888 resolve the overloading. */
889 if (TREE_TYPE (converted_operand) == unknown_type_node)
891 error ("type of asm operand `%E' could not be determined",
893 converted_operand = error_mark_node;
895 TREE_VALUE (t) = converted_operand;
898 ninputs = list_length (input_operands);
899 noutputs = list_length (output_operands);
901 for (i = 0, t = output_operands; t; t = TREE_CHAIN (t), ++i)
906 const char *constraint;
909 constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t)));
910 operand = TREE_VALUE (output_operands);
912 if (!parse_output_constraint (&constraint,
913 i, ninputs, noutputs,
918 /* By marking the type as erroneous, we will not try to
919 process this operand again in expand_asm_operands. */
920 TREE_TYPE (operand) = error_mark_node;
924 /* If the operand is a DECL that is going to end up in
925 memory, assume it is addressable. This is a bit more
926 conservative than it would ideally be; the exact test is
927 buried deep in expand_asm_operands and depends on the
928 DECL_RTL for the OPERAND -- which we don't have at this
930 if (!allows_reg && DECL_P (operand))
931 cxx_mark_addressable (operand);
935 r = build_stmt (ASM_STMT, cv_qualifier, string,
936 output_operands, input_operands,
941 /* Finish a label with the indicated NAME. */
944 finish_label_stmt (name)
947 tree decl = define_label (input_filename, lineno, name);
948 add_stmt (build_stmt (LABEL_STMT, decl));
951 /* Finish a series of declarations for local labels. G++ allows users
952 to declare "local" labels, i.e., labels with scope. This extension
953 is useful when writing code involving statement-expressions. */
956 finish_label_decl (name)
959 tree decl = declare_local_label (name);
960 add_decl_stmt (decl);
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 /* If the current scope exits with an exception, run CLEANUP. */
976 finish_eh_cleanup (cleanup)
979 tree r = build_stmt (CLEANUP_STMT, NULL_TREE, cleanup);
980 CLEANUP_EH_ONLY (r) = 1;
984 /* Generate the RTL for a RETURN_INIT. */
987 genrtl_named_return_value ()
989 tree decl = DECL_RESULT (current_function_decl);
991 /* If this named return value comes in a register, put it in a
993 if (DECL_REGISTER (decl))
995 /* Note that the mode of the old DECL_RTL may be wider than the
996 mode of DECL_RESULT, depending on the calling conventions for
997 the processor. For example, on the Alpha, a 32-bit integer
998 is returned in a DImode register -- the DECL_RESULT has
999 SImode but the DECL_RTL for the DECL_RESULT has DImode. So,
1000 here, we use the mode the back-end has already assigned for
1001 the return value. */
1002 SET_DECL_RTL (decl, gen_reg_rtx (GET_MODE (DECL_RTL (decl))));
1003 if (TREE_ADDRESSABLE (decl))
1004 put_var_into_stack (decl);
1007 emit_local_var (decl);
1010 /* Bind a name and initialization to the return value of
1011 the current function. */
1014 finish_named_return_value (return_id, init)
1015 tree return_id, init;
1017 tree decl = DECL_RESULT (current_function_decl);
1019 /* Give this error as many times as there are occurrences, so that
1020 users can use Emacs compilation buffers to find and fix all such
1023 pedwarn ("ISO C++ does not permit named return values");
1024 cp_deprecated ("the named return value extension");
1026 if (return_id != NULL_TREE)
1028 if (DECL_NAME (decl) == NULL_TREE)
1029 DECL_NAME (decl) = return_id;
1032 error ("return identifier `%D' already in place", return_id);
1037 /* Can't let this happen for constructors. */
1038 if (DECL_CONSTRUCTOR_P (current_function_decl))
1040 error ("can't redefine default return value for constructors");
1044 /* If we have a named return value, put that in our scope as well. */
1045 if (DECL_NAME (decl) != NULL_TREE)
1047 /* Let `cp_finish_decl' know that this initializer is ok. */
1048 DECL_INITIAL (decl) = init;
1049 if (doing_semantic_analysis_p ())
1051 if (!processing_template_decl)
1053 cp_finish_decl (decl, init, NULL_TREE, 0);
1054 add_stmt (build_stmt (RETURN_INIT, NULL_TREE, NULL_TREE));
1057 add_stmt (build_stmt (RETURN_INIT, return_id, init));
1060 /* Don't use tree-inlining for functions with named return values.
1061 That doesn't work properly because we don't do any translation of
1062 the RETURN_INITs when they are copied. */
1063 DECL_UNINLINABLE (current_function_decl) = 1;
1066 /* Begin processing a mem-initializer-list. */
1069 begin_mem_initializers ()
1071 if (! DECL_CONSTRUCTOR_P (current_function_decl))
1072 error ("only constructors take base initializers");
1075 /* The INIT_LIST is a list of mem-initializers, in the order they were
1076 written by the user. The TREE_VALUE of each node is a list of
1077 initializers for a particular subobject. The TREE_PURPOSE is a
1078 FIELD_DECL is the initializer is for a non-static data member, and
1079 a class type if the initializer is for a base class. */
1082 finish_mem_initializers (init_list)
1085 tree member_init_list;
1086 tree base_init_list;
1087 tree last_base_warned_about;
1091 member_init_list = NULL_TREE;
1092 base_init_list = NULL_TREE;
1093 last_base_warned_about = NULL_TREE;
1095 for (init = init_list; init; init = next)
1097 next = TREE_CHAIN (init);
1098 if (TREE_CODE (TREE_PURPOSE (init)) == FIELD_DECL)
1100 TREE_CHAIN (init) = member_init_list;
1101 member_init_list = init;
1103 /* We're running through the initializers from right to left
1104 as we process them here. So, if we see a data member
1105 initializer after we see a base initializer, that
1106 actually means that the base initializer preceded the
1107 data member initializer. */
1108 if (warn_reorder && last_base_warned_about != base_init_list)
1112 for (base = base_init_list;
1113 base != last_base_warned_about;
1114 base = TREE_CHAIN (base))
1116 warning ("base initializer for `%T'",
1117 TREE_PURPOSE (base));
1118 warning (" will be re-ordered to precede member initializations");
1121 last_base_warned_about = base_init_list;
1126 TREE_CHAIN (init) = base_init_list;
1127 base_init_list = init;
1131 if (processing_template_decl)
1132 add_stmt (build_min_nt (CTOR_INITIALIZER,
1133 member_init_list, base_init_list));
1135 emit_base_init (member_init_list, base_init_list);
1138 /* Returns the stack of SCOPE_STMTs for the current function. */
1141 current_scope_stmt_stack ()
1143 return &cfun->language->base.x_scope_stmt_stack;
1146 /* Finish a parenthesized expression EXPR. */
1149 finish_parenthesized_expr (expr)
1152 if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (TREE_CODE (expr))))
1153 /* This inhibits warnings in c_common_truthvalue_conversion. */
1154 C_SET_EXP_ORIGINAL_CODE (expr, ERROR_MARK);
1156 if (TREE_CODE (expr) == OFFSET_REF)
1157 /* [expr.unary.op]/3 The qualified id of a pointer-to-member must not be
1158 enclosed in parentheses. */
1159 PTRMEM_OK_P (expr) = 0;
1163 /* Begin a statement-expression. The value returned must be passed to
1164 finish_stmt_expr. */
1169 /* If we're outside a function, we won't have a statement-tree to
1170 work with. But, if we see a statement-expression we need to
1172 if (! cfun && !last_tree)
1173 begin_stmt_tree (&scope_chain->x_saved_tree);
1175 keep_next_level (1);
1176 /* If we're building a statement tree, then the upcoming compound
1177 statement will be chained onto the tree structure, starting at
1178 last_tree. We return last_tree so that we can later unhook the
1179 compound statement. */
1183 /* Used when beginning a statement-expression outside function scope.
1184 For example, when handling a file-scope initializer, we use this
1188 begin_global_stmt_expr ()
1190 if (! cfun && !last_tree)
1191 begin_stmt_tree (&scope_chain->x_saved_tree);
1193 keep_next_level (1);
1195 return last_tree ? last_tree : expand_start_stmt_expr(/*has_scope=*/1);
1198 /* Finish the STMT_EXPR last begun with begin_global_stmt_expr. */
1201 finish_global_stmt_expr (stmt_expr)
1204 stmt_expr = expand_end_stmt_expr (stmt_expr);
1207 && TREE_CHAIN (scope_chain->x_saved_tree) == NULL_TREE)
1208 finish_stmt_tree (&scope_chain->x_saved_tree);
1213 /* Finish a statement-expression. RTL_EXPR should be the value
1214 returned by the previous begin_stmt_expr; EXPR is the
1215 statement-expression. Returns an expression representing the
1216 statement-expression. */
1219 finish_stmt_expr (rtl_expr)
1224 /* If the last thing in the statement-expression was not an
1225 expression-statement, then it has type `void'. */
1226 if (!last_expr_type)
1227 last_expr_type = void_type_node;
1228 result = build_min (STMT_EXPR, last_expr_type, last_tree);
1229 TREE_SIDE_EFFECTS (result) = 1;
1231 /* Remove the compound statement from the tree structure; it is
1232 now saved in the STMT_EXPR. */
1233 last_tree = rtl_expr;
1234 TREE_CHAIN (last_tree) = NULL_TREE;
1236 /* If we created a statement-tree for this statement-expression,
1239 && TREE_CHAIN (scope_chain->x_saved_tree) == NULL_TREE)
1240 finish_stmt_tree (&scope_chain->x_saved_tree);
1245 /* Finish a call to FN with ARGS. Returns a representation of the
1249 finish_call_expr (fn, args, koenig)
1258 if (TREE_CODE (fn) == BIT_NOT_EXPR)
1259 fn = build_x_unary_op (BIT_NOT_EXPR, TREE_OPERAND (fn, 0));
1260 else if (TREE_CODE (fn) != TEMPLATE_ID_EXPR)
1261 fn = do_identifier (fn, 2, args);
1263 result = build_x_function_call (fn, args, current_class_ref);
1265 if (TREE_CODE (result) == CALL_EXPR
1266 && (! TREE_TYPE (result)
1267 || TREE_CODE (TREE_TYPE (result)) != VOID_TYPE))
1268 result = require_complete_type (result);
1273 /* Finish a call to a postfix increment or decrement or EXPR. (Which
1274 is indicated by CODE, which should be POSTINCREMENT_EXPR or
1275 POSTDECREMENT_EXPR.) */
1278 finish_increment_expr (expr, code)
1280 enum tree_code code;
1282 /* If we get an OFFSET_REF, turn it into what it really means (e.g.,
1283 a COMPONENT_REF). This way if we've got, say, a reference to a
1284 static member that's being operated on, we don't end up trying to
1285 find a member operator for the class it's in. */
1287 if (TREE_CODE (expr) == OFFSET_REF)
1288 expr = resolve_offset_ref (expr);
1289 return build_x_unary_op (code, expr);
1292 /* Finish a use of `this'. Returns an expression for `this'. */
1299 if (current_class_ptr)
1301 result = current_class_ptr;
1303 else if (current_function_decl
1304 && DECL_STATIC_FUNCTION_P (current_function_decl))
1306 error ("`this' is unavailable for static member functions");
1307 result = error_mark_node;
1311 if (current_function_decl)
1312 error ("invalid use of `this' in non-member function");
1314 error ("invalid use of `this' at top level");
1315 result = error_mark_node;
1321 /* Finish a member function call using OBJECT and ARGS as arguments to
1322 FN. Returns an expression for the call. */
1325 finish_object_call_expr (fn, object, args)
1331 /* This is a future direction of this code, but because
1332 build_x_function_call cannot always undo what is done in
1333 build_component_ref entirely yet, we cannot do this. */
1335 tree real_fn = build_component_ref (object, fn, NULL_TREE, 1);
1336 return finish_call_expr (real_fn, args);
1338 if (DECL_DECLARES_TYPE_P (fn))
1340 if (processing_template_decl)
1341 /* This can happen on code like:
1344 template <class T> void f(T t) {
1348 We just grab the underlying IDENTIFIER. */
1349 fn = DECL_NAME (fn);
1352 error ("calling type `%T' like a method", fn);
1353 return error_mark_node;
1357 return build_method_call (object, fn, args, NULL_TREE, LOOKUP_NORMAL);
1361 /* Finish a qualified member function call using OBJECT and ARGS as
1362 arguments to FN. Returns an expression for the call. */
1365 finish_qualified_object_call_expr (fn, object, args)
1370 return build_scoped_method_call (object, TREE_OPERAND (fn, 0),
1371 TREE_OPERAND (fn, 1), args);
1374 /* Finish a pseudo-destructor call expression of OBJECT, with SCOPE
1375 being the scope, if any, of DESTRUCTOR. Returns an expression for
1379 finish_pseudo_destructor_call_expr (object, scope, destructor)
1384 if (processing_template_decl)
1385 return build_min_nt (PSEUDO_DTOR_EXPR, object, scope, destructor);
1387 if (scope && scope != destructor)
1388 error ("destructor specifier `%T::~%T()' must have matching names",
1391 if ((scope == NULL_TREE || IDENTIFIER_GLOBAL_VALUE (destructor))
1392 && (TREE_CODE (TREE_TYPE (object)) !=
1393 TREE_CODE (TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (destructor)))))
1394 error ("`%E' is not of type `%T'", object, destructor);
1396 return cp_convert (void_type_node, object);
1399 /* Finish a call to a globally qualified member function FN using
1400 ARGS. Returns an expression for the call. */
1403 finish_qualified_call_expr (fn, args)
1407 if (processing_template_decl)
1408 return build_min_nt (CALL_EXPR, fn, args, NULL_TREE);
1410 return build_member_call (TREE_OPERAND (fn, 0),
1411 TREE_OPERAND (fn, 1),
1415 /* Finish an expression of the form CODE EXPR. */
1418 finish_unary_op_expr (code, expr)
1419 enum tree_code code;
1422 tree result = build_x_unary_op (code, expr);
1423 /* Inside a template, build_x_unary_op does not fold the
1424 expression. So check whether the result is folded before
1425 setting TREE_NEGATED_INT. */
1426 if (code == NEGATE_EXPR && TREE_CODE (expr) == INTEGER_CST
1427 && TREE_CODE (result) == INTEGER_CST
1428 && !TREE_UNSIGNED (TREE_TYPE (result))
1429 && INT_CST_LT (result, integer_zero_node))
1430 TREE_NEGATED_INT (result) = 1;
1431 overflow_warning (result);
1435 /* Finish an id-expression. */
1438 finish_id_expr (expr)
1441 if (TREE_CODE (expr) == IDENTIFIER_NODE)
1442 expr = do_identifier (expr, 1, NULL_TREE);
1444 if (TREE_TYPE (expr) == error_mark_node)
1445 expr = error_mark_node;
1449 /* Return the declaration for the function-name variable indicated by
1453 finish_fname (tree id)
1457 decl = fname_decl (C_RID_CODE (id), id);
1458 if (processing_template_decl)
1459 decl = build_min_nt (LOOKUP_EXPR, DECL_NAME (decl));
1463 static tree current_type_lookups;
1465 /* Perform deferred access control for types used in the type of a
1469 deferred_type_access_control ()
1471 tree lookup = type_lookups;
1473 if (lookup == error_mark_node)
1476 for (; lookup; lookup = TREE_CHAIN (lookup))
1477 enforce_access (TREE_PURPOSE (lookup), TREE_VALUE (lookup));
1481 decl_type_access_control (decl)
1486 if (type_lookups == error_mark_node)
1489 save_fn = current_function_decl;
1491 if (decl && TREE_CODE (decl) == FUNCTION_DECL)
1492 current_function_decl = decl;
1494 deferred_type_access_control ();
1496 current_function_decl = save_fn;
1498 /* Now strip away the checks for the current declarator; they were
1499 added to type_lookups after typed_declspecs saved the copy that
1500 ended up in current_type_lookups. */
1501 type_lookups = current_type_lookups;
1505 save_type_access_control (lookups)
1508 current_type_lookups = lookups;
1511 /* Reset the deferred access control. */
1514 reset_type_access_control ()
1516 type_lookups = NULL_TREE;
1517 current_type_lookups = NULL_TREE;
1520 /* Begin a function definition declared with DECL_SPECS, ATTRIBUTES,
1521 and DECLARATOR. Returns non-zero if the function-declaration is
1525 begin_function_definition (decl_specs, attributes, declarator)
1530 if (!start_function (decl_specs, declarator, attributes, SF_DEFAULT))
1533 deferred_type_access_control ();
1534 type_lookups = error_mark_node;
1536 /* The things we're about to see are not directly qualified by any
1537 template headers we've seen thus far. */
1538 reset_specialization ();
1543 /* Begin a constructor declarator of the form `SCOPE::NAME'. Returns
1547 begin_constructor_declarator (scope, name)
1551 tree result = build_nt (SCOPE_REF, scope, name);
1552 enter_scope_of (result);
1556 /* Finish an init-declarator. Returns a DECL. */
1559 finish_declarator (declarator, declspecs, attributes,
1560 prefix_attributes, initialized)
1564 tree prefix_attributes;
1567 return start_decl (declarator, declspecs, initialized, attributes,
1571 /* Finish a translation unit. */
1574 finish_translation_unit ()
1576 /* In case there were missing closebraces,
1577 get us back to the global binding level. */
1579 while (current_namespace != global_namespace)
1582 /* Do file scope __FUNCTION__ et al. */
1583 finish_fname_decls ();
1588 /* Finish a template type parameter, specified as AGGR IDENTIFIER.
1589 Returns the parameter. */
1592 finish_template_type_parm (aggr, identifier)
1596 if (aggr != class_type_node)
1598 pedwarn ("template type parameters must use the keyword `class' or `typename'");
1599 aggr = class_type_node;
1602 return build_tree_list (aggr, identifier);
1605 /* Finish a template template parameter, specified as AGGR IDENTIFIER.
1606 Returns the parameter. */
1609 finish_template_template_parm (aggr, identifier)
1613 tree decl = build_decl (TYPE_DECL, identifier, NULL_TREE);
1614 tree tmpl = build_lang_decl (TEMPLATE_DECL, identifier, NULL_TREE);
1615 DECL_TEMPLATE_PARMS (tmpl) = current_template_parms;
1616 DECL_TEMPLATE_RESULT (tmpl) = decl;
1617 DECL_ARTIFICIAL (decl) = 1;
1618 end_template_decl ();
1620 my_friendly_assert (DECL_TEMPLATE_PARMS (tmpl), 20010110);
1622 return finish_template_type_parm (aggr, tmpl);
1625 /* ARGUMENT is the default-argument value for a template template
1626 parameter. If ARGUMENT is invalid, issue error messages and return
1627 the ERROR_MARK_NODE. Otherwise, ARGUMENT itself is returned. */
1630 check_template_template_default_arg (tree argument)
1632 if (TREE_CODE (argument) != TEMPLATE_DECL
1633 && TREE_CODE (argument) != TEMPLATE_TEMPLATE_PARM
1634 && TREE_CODE (argument) != TYPE_DECL
1635 && TREE_CODE (argument) != UNBOUND_CLASS_TEMPLATE)
1637 error ("invalid default template argument");
1638 return error_mark_node;
1644 /* Finish a parameter list, indicated by PARMS. If ELLIPSIS is
1645 non-zero, the parameter list was terminated by a `...'. */
1648 finish_parmlist (parms, ellipsis)
1654 /* We mark the PARMS as a parmlist so that declarator processing can
1655 disambiguate certain constructs. */
1656 TREE_PARMLIST (parms) = 1;
1657 /* We do not append void_list_node here, but leave it to grokparms
1659 PARMLIST_ELLIPSIS_P (parms) = ellipsis;
1664 /* Begin a class definition, as indicated by T. */
1667 begin_class_definition (t)
1670 if (t == error_mark_node)
1671 return error_mark_node;
1673 /* Check the bases are accessible. */
1674 decl_type_access_control (TYPE_NAME (t));
1675 reset_type_access_control ();
1677 if (processing_template_parmlist)
1679 error ("definition of `%#T' inside template parameter list", t);
1680 return error_mark_node;
1683 /* In a definition of a member class template, we will get here with
1684 an implicit typename. */
1685 if (IMPLICIT_TYPENAME_P (t))
1687 /* A non-implicit typename comes from code like:
1689 template <typename T> struct A {
1690 template <typename U> struct A<T>::B ...
1692 This is erroneous. */
1693 else if (TREE_CODE (t) == TYPENAME_TYPE)
1695 error ("invalid definition of qualified type `%T'", t);
1696 t = error_mark_node;
1699 if (t == error_mark_node || ! IS_AGGR_TYPE (t))
1701 t = make_aggr_type (RECORD_TYPE);
1702 pushtag (make_anon_name (), t, 0);
1705 /* If we generated a partial instantiation of this type, but now
1706 we're seeing a real definition, we're actually looking at a
1707 partial specialization. Consider:
1709 template <class T, class U>
1715 template <class T, class U>
1718 typename X<Y<T, U> >::A a;
1721 template <class T, class U>
1726 We have to undo the effects of the previous partial
1728 if (PARTIAL_INSTANTIATION_P (t))
1732 /* Unfortunately, when we're not in pedantic mode, we
1733 attempt to actually fill in some of the fields of the
1734 partial instantiation, in order to support the implicit
1735 typename extension. Clear those fields now, in
1736 preparation for the definition here. The fields cleared
1737 here must match those set in instantiate_class_template.
1738 Look for a comment mentioning begin_class_definition
1740 TYPE_BINFO_BASETYPES (t) = NULL_TREE;
1741 TYPE_FIELDS (t) = NULL_TREE;
1742 TYPE_METHODS (t) = NULL_TREE;
1743 CLASSTYPE_TAGS (t) = NULL_TREE;
1744 CLASSTYPE_VBASECLASSES (t) = NULL_TREE;
1745 TYPE_SIZE (t) = NULL_TREE;
1748 /* This isn't a partial instantiation any more. */
1749 PARTIAL_INSTANTIATION_P (t) = 0;
1751 /* If this type was already complete, and we see another definition,
1753 else if (COMPLETE_TYPE_P (t))
1754 duplicate_tag_error (t);
1756 /* Update the location of the decl. */
1757 DECL_SOURCE_FILE (TYPE_NAME (t)) = input_filename;
1758 DECL_SOURCE_LINE (TYPE_NAME (t)) = lineno;
1760 if (TYPE_BEING_DEFINED (t))
1762 t = make_aggr_type (TREE_CODE (t));
1763 pushtag (TYPE_IDENTIFIER (t), t, 0);
1765 maybe_process_partial_specialization (t);
1767 TYPE_BEING_DEFINED (t) = 1;
1768 TYPE_PACKED (t) = flag_pack_struct;
1769 /* Reset the interface data, at the earliest possible
1770 moment, as it might have been set via a class foo;
1772 if (! TYPE_ANONYMOUS_P (t))
1774 CLASSTYPE_INTERFACE_ONLY (t) = interface_only;
1775 SET_CLASSTYPE_INTERFACE_UNKNOWN_X
1776 (t, interface_unknown);
1778 reset_specialization();
1780 /* Make a declaration for this class in its own scope. */
1781 build_self_reference ();
1786 /* Finish the member declaration given by DECL. */
1789 finish_member_declaration (decl)
1792 if (decl == error_mark_node || decl == NULL_TREE)
1795 if (decl == void_type_node)
1796 /* The COMPONENT was a friend, not a member, and so there's
1797 nothing for us to do. */
1800 /* We should see only one DECL at a time. */
1801 my_friendly_assert (TREE_CHAIN (decl) == NULL_TREE, 0);
1803 /* Set up access control for DECL. */
1805 = (current_access_specifier == access_private_node);
1806 TREE_PROTECTED (decl)
1807 = (current_access_specifier == access_protected_node);
1808 if (TREE_CODE (decl) == TEMPLATE_DECL)
1810 TREE_PRIVATE (DECL_TEMPLATE_RESULT (decl)) = TREE_PRIVATE (decl);
1811 TREE_PROTECTED (DECL_TEMPLATE_RESULT (decl)) = TREE_PROTECTED (decl);
1814 /* Mark the DECL as a member of the current class. */
1815 DECL_CONTEXT (decl) = current_class_type;
1819 A C language linkage is ignored for the names of class members
1820 and the member function type of class member functions. */
1821 if (DECL_LANG_SPECIFIC (decl) && DECL_LANGUAGE (decl) == lang_c)
1822 SET_DECL_LANGUAGE (decl, lang_cplusplus);
1824 /* Put functions on the TYPE_METHODS list and everything else on the
1825 TYPE_FIELDS list. Note that these are built up in reverse order.
1826 We reverse them (to obtain declaration order) in finish_struct. */
1827 if (TREE_CODE (decl) == FUNCTION_DECL
1828 || DECL_FUNCTION_TEMPLATE_P (decl))
1830 /* We also need to add this function to the
1831 CLASSTYPE_METHOD_VEC. */
1832 add_method (current_class_type, decl, /*error_p=*/0);
1834 TREE_CHAIN (decl) = TYPE_METHODS (current_class_type);
1835 TYPE_METHODS (current_class_type) = decl;
1839 /* All TYPE_DECLs go at the end of TYPE_FIELDS. Ordinary fields
1840 go at the beginning. The reason is that lookup_field_1
1841 searches the list in order, and we want a field name to
1842 override a type name so that the "struct stat hack" will
1843 work. In particular:
1845 struct S { enum E { }; int E } s;
1848 is legal. In addition, the FIELD_DECLs must be maintained in
1849 declaration order so that class layout works as expected.
1850 However, we don't need that order until class layout, so we
1851 save a little time by putting FIELD_DECLs on in reverse order
1852 here, and then reversing them in finish_struct_1. (We could
1853 also keep a pointer to the correct insertion points in the
1856 if (TREE_CODE (decl) == TYPE_DECL)
1857 TYPE_FIELDS (current_class_type)
1858 = chainon (TYPE_FIELDS (current_class_type), decl);
1861 TREE_CHAIN (decl) = TYPE_FIELDS (current_class_type);
1862 TYPE_FIELDS (current_class_type) = decl;
1865 /* Enter the DECL into the scope of the class. */
1866 if (TREE_CODE (decl) != USING_DECL)
1867 pushdecl_class_level (decl);
1871 /* Finish a class definition T with the indicate ATTRIBUTES. If SEMI,
1872 the definition is immediately followed by a semicolon. Returns the
1876 finish_class_definition (t, attributes, semi, pop_scope_p)
1882 if (t == error_mark_node)
1883 return error_mark_node;
1885 /* finish_struct nukes this anyway; if finish_exception does too,
1888 note_got_semicolon (t);
1890 /* If we got any attributes in class_head, xref_tag will stick them in
1891 TREE_TYPE of the type. Grab them now. */
1892 attributes = chainon (TYPE_ATTRIBUTES (t), attributes);
1893 TYPE_ATTRIBUTES (t) = NULL_TREE;
1895 if (TREE_CODE (t) == ENUMERAL_TYPE)
1899 t = finish_struct (t, attributes);
1901 note_got_semicolon (t);
1905 check_for_missing_semicolon (t);
1907 pop_scope (CP_DECL_CONTEXT (TYPE_MAIN_DECL (t)));
1908 if (current_scope () == current_function_decl)
1909 do_pending_defargs ();
1914 /* Finish processing the default argument expressions cached during
1915 the processing of a class definition. */
1918 begin_inline_definitions ()
1920 if (current_scope () == current_function_decl)
1921 do_pending_inlines ();
1924 /* Finish processing the declaration of a member class template
1925 TYPES whose template parameters are given by PARMS. */
1928 finish_member_class_template (types)
1933 /* If there are declared, but undefined, partial specializations
1934 mixed in with the typespecs they will not yet have passed through
1935 maybe_process_partial_specialization, so we do that here. */
1936 for (t = types; t != NULL_TREE; t = TREE_CHAIN (t))
1937 if (IS_AGGR_TYPE_CODE (TREE_CODE (TREE_VALUE (t))))
1938 maybe_process_partial_specialization (TREE_VALUE (t));
1940 note_list_got_semicolon (types);
1941 grok_x_components (types);
1942 if (TYPE_CONTEXT (TREE_VALUE (types)) != current_class_type)
1943 /* The component was in fact a friend declaration. We avoid
1944 finish_member_template_decl performing certain checks by
1948 finish_member_template_decl (types);
1950 /* As with other component type declarations, we do
1951 not store the new DECL on the list of
1956 /* Finish processing a complete template declaration. The PARMS are
1957 the template parameters. */
1960 finish_template_decl (parms)
1964 end_template_decl ();
1966 end_specialization ();
1969 /* Finish processing a template-id (which names a type) of the form
1970 NAME < ARGS >. Return the TYPE_DECL for the type named by the
1971 template-id. If ENTERING_SCOPE is non-zero we are about to enter
1972 the scope of template-id indicated. */
1975 finish_template_type (name, args, entering_scope)
1982 decl = lookup_template_class (name, args,
1983 NULL_TREE, NULL_TREE,
1984 entering_scope, /*complain=*/1);
1985 if (decl != error_mark_node)
1986 decl = TYPE_STUB_DECL (decl);
1991 /* SR is a SCOPE_REF node. Enter the scope of SR, whether it is a
1992 namespace scope or a class scope. */
1998 tree scope = TREE_OPERAND (sr, 0);
2000 if (TREE_CODE (scope) == NAMESPACE_DECL)
2002 push_decl_namespace (scope);
2003 TREE_COMPLEXITY (sr) = -1;
2005 else if (scope != current_class_type)
2007 if (TREE_CODE (scope) == TYPENAME_TYPE)
2009 /* In a declarator for a template class member, the scope will
2010 get here as an implicit typename, a TYPENAME_TYPE with a type. */
2011 scope = TREE_TYPE (scope);
2012 TREE_OPERAND (sr, 0) = scope;
2014 push_nested_class (scope, 3);
2015 TREE_COMPLEXITY (sr) = current_class_depth;
2019 /* Finish processing a BASE_CLASS with the indicated ACCESS_SPECIFIER.
2020 Return a TREE_LIST containing the ACCESS_SPECIFIER and the
2021 BASE_CLASS, or NULL_TREE if an error occurred. The
2022 ACCESS_SPECIFIER is one of
2023 access_{default,public,protected_private}[_virtual]_node.*/
2026 finish_base_specifier (access_specifier, base_class)
2027 tree access_specifier;
2032 if (base_class == error_mark_node)
2034 error ("invalid base-class specification");
2037 else if (! is_aggr_type (base_class, 1))
2041 if (cp_type_quals (base_class) != 0)
2043 error ("base class `%T' has cv qualifiers", base_class);
2044 base_class = TYPE_MAIN_VARIANT (base_class);
2046 result = build_tree_list (access_specifier, base_class);
2052 /* Called when multiple declarators are processed. If that is not
2053 premitted in this context, an error is issued. */
2056 check_multiple_declarators ()
2060 In a template-declaration, explicit specialization, or explicit
2061 instantiation the init-declarator-list in the declaration shall
2062 contain at most one declarator.
2064 We don't just use PROCESSING_TEMPLATE_DECL for the first
2065 condition since that would disallow the perfectly legal code,
2066 like `template <class T> struct S { int i, j; };'. */
2067 if (at_function_scope_p ())
2068 /* It's OK to write `template <class T> void f() { int i, j;}'. */
2071 if (PROCESSING_REAL_TEMPLATE_DECL_P ()
2072 || processing_explicit_instantiation
2073 || processing_specialization)
2074 error ("multiple declarators in template declaration");
2077 /* Implement the __typeof keyword: Return the type of EXPR, suitable for
2078 use as a type-specifier. */
2081 finish_typeof (expr)
2084 if (processing_template_decl)
2088 t = make_aggr_type (TYPEOF_TYPE);
2089 TYPE_FIELDS (t) = expr;
2094 if (TREE_CODE (expr) == OFFSET_REF)
2095 expr = resolve_offset_ref (expr);
2097 return TREE_TYPE (expr);
2100 /* Compute the value of the `sizeof' operator. */
2106 if (processing_template_decl)
2107 return build_min_nt (SIZEOF_EXPR, t);
2109 return TYPE_P (t) ? cxx_sizeof (t) : expr_sizeof (t);
2112 /* Implement the __alignof keyword: Return the minimum required
2113 alignment of T, measured in bytes. */
2119 if (processing_template_decl)
2120 return build_min_nt (ALIGNOF_EXPR, t);
2122 return TYPE_P (t) ? cxx_alignof (t) : c_alignof_expr (t);
2125 /* Generate RTL for the statement T, and its substatements, and any
2126 other statements at its nesting level. */
2132 switch (TREE_CODE (t))
2135 genrtl_try_block (t);
2139 genrtl_eh_spec_block (t);
2147 genrtl_named_return_value ();
2159 /* Called from expand_body via walk_tree. Replace all AGGR_INIT_EXPRs
2160 will equivalent CALL_EXPRs. */
2163 simplify_aggr_init_exprs_r (tp, walk_subtrees, data)
2165 int *walk_subtrees ATTRIBUTE_UNUSED;
2166 void *data ATTRIBUTE_UNUSED;
2168 tree aggr_init_expr;
2174 int copy_from_buffer_p;
2176 aggr_init_expr = *tp;
2177 /* We don't need to walk into types; there's nothing in a type that
2178 needs simplification. (And, furthermore, there are places we
2179 actively don't want to go. For example, we don't want to wander
2180 into the default arguments for a FUNCTION_DECL that appears in a
2182 if (TYPE_P (aggr_init_expr))
2187 /* Only AGGR_INIT_EXPRs are interesting. */
2188 else if (TREE_CODE (aggr_init_expr) != AGGR_INIT_EXPR)
2191 /* Form an appropriate CALL_EXPR. */
2192 fn = TREE_OPERAND (aggr_init_expr, 0);
2193 args = TREE_OPERAND (aggr_init_expr, 1);
2194 slot = TREE_OPERAND (aggr_init_expr, 2);
2195 type = TREE_TYPE (aggr_init_expr);
2196 if (AGGR_INIT_VIA_CTOR_P (aggr_init_expr))
2198 /* Replace the first argument with the address of the third
2199 argument to the AGGR_INIT_EXPR. */
2200 cxx_mark_addressable (slot);
2201 args = tree_cons (NULL_TREE,
2203 build_pointer_type (TREE_TYPE (slot)),
2207 call_expr = build (CALL_EXPR,
2208 TREE_TYPE (TREE_TYPE (TREE_TYPE (fn))),
2209 fn, args, NULL_TREE);
2210 TREE_SIDE_EFFECTS (call_expr) = 1;
2212 /* If we're using the non-reentrant PCC calling convention, then we
2213 need to copy the returned value out of the static buffer into the
2215 copy_from_buffer_p = 0;
2216 #ifdef PCC_STATIC_STRUCT_RETURN
2217 if (!AGGR_INIT_VIA_CTOR_P (aggr_init_expr) && aggregate_value_p (type))
2219 int old_ac = flag_access_control;
2221 flag_access_control = 0;
2222 call_expr = build_aggr_init (slot, call_expr,
2223 DIRECT_BIND | LOOKUP_ONLYCONVERTING);
2224 flag_access_control = old_ac;
2225 copy_from_buffer_p = 1;
2229 /* If this AGGR_INIT_EXPR indicates the value returned by a
2230 function, then we want to use the value of the initialized
2231 location as the result. */
2232 if (AGGR_INIT_VIA_CTOR_P (aggr_init_expr) || copy_from_buffer_p)
2234 call_expr = build (COMPOUND_EXPR, type,
2236 TREE_SIDE_EFFECTS (call_expr) = 1;
2239 /* Replace the AGGR_INIT_EXPR with the CALL_EXPR. */
2240 TREE_CHAIN (call_expr) = TREE_CHAIN (aggr_init_expr);
2243 /* Keep iterating. */
2247 /* Emit all thunks to FN that should be emitted when FN is emitted. */
2250 emit_associated_thunks (fn)
2253 /* When we use vcall offsets, we emit thunks with the virtual
2254 functions to which they thunk. The whole point of vcall offsets
2255 is so that you can know statically the entire set of thunks that
2256 will ever be needed for a given virtual function, thereby
2257 enabling you to output all the thunks with the function itself. */
2258 if (DECL_VIRTUAL_P (fn))
2263 for (binfo = TYPE_BINFO (DECL_CONTEXT (fn));
2265 binfo = TREE_CHAIN (binfo))
2266 for (v = BINFO_VIRTUALS (binfo); v; v = TREE_CHAIN (v))
2268 && (!integer_zerop (BV_DELTA (v))
2269 || BV_USE_VCALL_INDEX_P (v)))
2274 if (BV_USE_VCALL_INDEX_P (v))
2276 vcall_index = BV_VCALL_INDEX (v);
2277 my_friendly_assert (vcall_index != NULL_TREE, 20000621);
2280 vcall_index = NULL_TREE;
2282 thunk = make_thunk (build1 (ADDR_EXPR,
2283 vfunc_ptr_type_node,
2287 use_thunk (thunk, /*emit_p=*/1);
2292 /* Generate RTL for FN. */
2299 const char *saved_input_filename;
2301 /* When the parser calls us after finishing the body of a template
2302 function, we don't really want to expand the body. When we're
2303 processing an in-class definition of an inline function,
2304 PROCESSING_TEMPLATE_DECL will no longer be set here, so we have
2305 to look at the function itself. */
2306 if (processing_template_decl
2307 || (DECL_LANG_SPECIFIC (fn)
2308 && DECL_TEMPLATE_INFO (fn)
2309 && uses_template_parms (DECL_TI_ARGS (fn))))
2311 /* Normally, collection only occurs in rest_of_compilation. So,
2312 if we don't collect here, we never collect junk generated
2313 during the processing of templates until we hit a
2314 non-template function. */
2319 /* Replace AGGR_INIT_EXPRs with appropriate CALL_EXPRs. */
2320 walk_tree_without_duplicates (&DECL_SAVED_TREE (fn),
2321 simplify_aggr_init_exprs_r,
2324 /* If this is a constructor or destructor body, we have to clone
2326 if (maybe_clone_body (fn))
2328 /* We don't want to process FN again, so pretend we've written
2329 it out, even though we haven't. */
2330 TREE_ASM_WRITTEN (fn) = 1;
2334 /* There's no reason to do any of the work here if we're only doing
2335 semantic analysis; this code just generates RTL. */
2336 if (flag_syntax_only)
2339 /* If possible, avoid generating RTL for this function. Instead,
2340 just record it as an inline function, and wait until end-of-file
2341 to decide whether to write it out or not. */
2342 if (/* We have to generate RTL if it's not an inline function. */
2343 (DECL_INLINE (fn) || DECL_COMDAT (fn))
2344 /* Or if we have to emit code for inline functions anyhow. */
2345 && !flag_keep_inline_functions
2346 /* Or if we actually have a reference to the function. */
2347 && !DECL_NEEDED_P (fn))
2349 /* Set DECL_EXTERNAL so that assemble_external will be called as
2350 necessary. We'll clear it again in finish_file. */
2351 if (!DECL_EXTERNAL (fn))
2353 DECL_NOT_REALLY_EXTERN (fn) = 1;
2354 DECL_EXTERNAL (fn) = 1;
2356 /* Remember this function. In finish_file we'll decide if
2357 we actually need to write this function out. */
2359 /* Let the back-end know that this function exists. */
2360 (*debug_hooks->deferred_inline_function) (fn);
2364 /* Compute the appropriate object-file linkage for inline
2366 if (DECL_DECLARED_INLINE_P (fn))
2367 import_export_decl (fn);
2369 /* If FN is external, then there's no point in generating RTL for
2370 it. This situation can arise with an inline function under
2371 `-fexternal-templates'; we instantiate the function, even though
2372 we're not planning on emitting it, in case we get a chance to
2374 if (DECL_EXTERNAL (fn))
2377 timevar_push (TV_INTEGRATION);
2379 /* Optimize the body of the function before expanding it. */
2380 optimize_function (fn);
2382 timevar_pop (TV_INTEGRATION);
2383 timevar_push (TV_EXPAND);
2385 /* Save the current file name and line number. When we expand the
2386 body of the function, we'll set LINENO and INPUT_FILENAME so that
2387 error-mesages come out in the right places. */
2388 saved_lineno = lineno;
2389 saved_input_filename = input_filename;
2390 lineno = DECL_SOURCE_LINE (fn);
2391 input_filename = DECL_SOURCE_FILE (fn);
2393 genrtl_start_function (fn);
2394 current_function_is_thunk = DECL_THUNK_P (fn);
2396 /* Expand the body. */
2397 expand_stmt (DECL_SAVED_TREE (fn));
2399 /* Statements should always be full-expressions at the outermost set
2400 of curly braces for a function. */
2401 my_friendly_assert (stmts_are_full_exprs_p (), 19990831);
2403 /* The outermost statement for a function contains the line number
2404 recorded when we finished processing the function. */
2405 lineno = STMT_LINENO (DECL_SAVED_TREE (fn));
2407 /* Generate code for the function. */
2408 genrtl_finish_function (fn);
2410 /* If possible, obliterate the body of the function so that it can
2411 be garbage collected. */
2412 if (dump_enabled_p (TDI_all))
2413 /* Keep the body; we're going to dump it. */
2415 else if (DECL_INLINE (fn) && flag_inline_trees)
2416 /* We might need the body of this function so that we can expand
2417 it inline somewhere else. */
2420 /* We don't need the body; blow it away. */
2421 DECL_SAVED_TREE (fn) = NULL_TREE;
2423 /* And restore the current source position. */
2424 lineno = saved_lineno;
2425 input_filename = saved_input_filename;
2426 extract_interface_info ();
2428 timevar_pop (TV_EXPAND);
2430 /* Emit any thunks that should be emitted at the same time as FN. */
2431 emit_associated_thunks (fn);
2434 /* Helper function for walk_tree, used by finish_function to override all
2435 the RETURN_STMTs and pertinent CLEANUP_STMTs for the named return
2436 value optimization. */
2439 nullify_returns_r (tp, walk_subtrees, data)
2444 tree nrv = (tree) data;
2446 /* No need to walk into types. There wouldn't be any need to walk into
2447 non-statements, except that we have to consider STMT_EXPRs. */
2450 else if (TREE_CODE (*tp) == RETURN_STMT)
2451 RETURN_EXPR (*tp) = NULL_TREE;
2452 else if (TREE_CODE (*tp) == CLEANUP_STMT
2453 && CLEANUP_DECL (*tp) == nrv)
2454 CLEANUP_EH_ONLY (*tp) = 1;
2456 /* Keep iterating. */
2460 /* Start generating the RTL for FN. */
2463 genrtl_start_function (fn)
2466 /* Tell everybody what function we're processing. */
2467 current_function_decl = fn;
2468 /* Get the RTL machinery going for this function. */
2469 init_function_start (fn, DECL_SOURCE_FILE (fn), DECL_SOURCE_LINE (fn));
2470 /* Let everybody know that we're expanding this function, not doing
2471 semantic analysis. */
2474 /* Even though we're inside a function body, we still don't want to
2475 call expand_expr to calculate the size of a variable-sized array.
2476 We haven't necessarily assigned RTL to all variables yet, so it's
2477 not safe to try to expand expressions involving them. */
2478 immediate_size_expand = 0;
2479 cfun->x_dont_save_pending_sizes_p = 1;
2481 /* Let the user know we're compiling this function. */
2482 announce_function (fn);
2484 /* Initialize the per-function data. */
2485 my_friendly_assert (!DECL_PENDING_INLINE_P (fn), 20000911);
2486 if (DECL_SAVED_FUNCTION_DATA (fn))
2488 /* If we already parsed this function, and we're just expanding it
2489 now, restore saved state. */
2490 *cp_function_chain = *DECL_SAVED_FUNCTION_DATA (fn);
2492 /* This function is being processed in whole-function mode; we
2493 already did semantic analysis. */
2494 cfun->x_whole_function_mode_p = 1;
2496 /* If we decided that we didn't want to inline this function,
2497 make sure the back-end knows that. */
2498 if (!current_function_cannot_inline)
2499 current_function_cannot_inline = cp_function_chain->cannot_inline;
2501 /* We don't need the saved data anymore. Unless this is an inline
2502 function; we need the named return value info for
2503 cp_copy_res_decl_for_inlining. */
2504 if (! DECL_INLINE (fn))
2505 DECL_SAVED_FUNCTION_DATA (fn) = NULL;
2508 /* Keep track of how many functions we're presently expanding. */
2511 /* Create a binding level for the parameters. */
2512 expand_function_start (fn, /*parms_have_cleanups=*/0);
2513 /* If this function is `main'. */
2514 if (DECL_MAIN_P (fn))
2515 expand_main_function ();
2517 /* Give our named return value the same RTL as our RESULT_DECL. */
2518 if (current_function_return_value)
2519 COPY_DECL_RTL (DECL_RESULT (fn), current_function_return_value);
2522 /* Finish generating the RTL for FN. */
2525 genrtl_finish_function (fn)
2531 if (write_symbols != NO_DEBUG)
2533 /* Keep this code around in case we later want to control debug info
2534 based on whether a type is "used". (jason 1999-11-11) */
2536 tree ttype = target_type (fntype);
2539 if (IS_AGGR_TYPE (ttype))
2540 /* Let debugger know it should output info for this type. */
2541 note_debug_info_needed (ttype);
2543 for (parmdecl = DECL_ARGUMENTS (fndecl); parmdecl; parmdecl = TREE_CHAIN (parmdecl))
2545 ttype = target_type (TREE_TYPE (parmdecl));
2546 if (IS_AGGR_TYPE (ttype))
2547 /* Let debugger know it should output info for this type. */
2548 note_debug_info_needed (ttype);
2553 /* Clean house because we will need to reorder insns here. */
2554 do_pending_stack_adjust ();
2556 /* If we have a named return value, we need to force a return so that
2557 the return register is USEd. */
2558 if (DECL_NAME (DECL_RESULT (fn)))
2559 emit_jump (return_label);
2561 /* We hard-wired immediate_size_expand to zero in start_function.
2562 Expand_function_end will decrement this variable. So, we set the
2563 variable to one here, so that after the decrement it will remain
2565 immediate_size_expand = 1;
2567 /* Generate rtl for function exit. */
2568 expand_function_end (input_filename, lineno, 0);
2570 /* If this is a nested function (like a template instantiation that
2571 we're compiling in the midst of compiling something else), push a
2572 new GC context. That will keep local variables on the stack from
2573 being collected while we're doing the compilation of this
2575 if (function_depth > 1)
2576 ggc_push_context ();
2578 /* There's no need to defer outputting this function any more; we
2579 know we want to output it. */
2580 DECL_DEFER_OUTPUT (fn) = 0;
2582 /* Run the optimizers and output the assembler code for this
2584 rest_of_compilation (fn);
2586 /* Undo the call to ggc_push_context above. */
2587 if (function_depth > 1)
2591 /* Keep this code around in case we later want to control debug info
2592 based on whether a type is "used". (jason 1999-11-11) */
2594 if (ctype && TREE_ASM_WRITTEN (fn))
2595 note_debug_info_needed (ctype);
2598 /* If this function is marked with the constructor attribute, add it
2599 to the list of functions to be called along with constructors
2600 from static duration objects. */
2601 if (DECL_STATIC_CONSTRUCTOR (fn))
2602 static_ctors = tree_cons (NULL_TREE, fn, static_ctors);
2604 /* If this function is marked with the destructor attribute, add it
2605 to the list of functions to be called along with destructors from
2606 static duration objects. */
2607 if (DECL_STATIC_DESTRUCTOR (fn))
2608 static_dtors = tree_cons (NULL_TREE, fn, static_dtors);
2612 /* In C++, we should never be saving RTL for the function. */
2613 my_friendly_assert (!DECL_SAVED_INSNS (fn), 20010903);
2615 /* Since we don't need the RTL for this function anymore, stop
2616 pointing to it. That's especially important for LABEL_DECLs,
2617 since you can reach all the instructions in the function from the
2618 CODE_LABEL stored in the DECL_RTL for the LABEL_DECL. Walk the
2619 BLOCK-tree, clearing DECL_RTL for LABEL_DECLs and non-static
2621 walk_tree_without_duplicates (&DECL_SAVED_TREE (fn),
2625 /* Clear out the RTL for the arguments. */
2626 for (t = DECL_ARGUMENTS (fn); t; t = TREE_CHAIN (t))
2628 SET_DECL_RTL (t, NULL_RTX);
2629 DECL_INCOMING_RTL (t) = NULL_RTX;
2632 if (!(flag_inline_trees && DECL_INLINE (fn)))
2633 /* DECL_INITIAL must remain nonzero so we know this was an
2634 actual function definition. */
2635 DECL_INITIAL (fn) = error_mark_node;
2637 /* Let the error reporting routines know that we're outside a
2638 function. For a nested function, this value is used in
2639 pop_cp_function_context and then reset via pop_function_context. */
2640 current_function_decl = NULL_TREE;
2643 /* Clear out the DECL_RTL for the non-static variables in BLOCK and
2647 clear_decl_rtl (tp, walk_subtrees, data)
2649 int *walk_subtrees ATTRIBUTE_UNUSED;
2650 void *data ATTRIBUTE_UNUSED;
2652 if (nonstatic_local_decl_p (*tp))
2653 SET_DECL_RTL (*tp, NULL_RTX);
2658 /* Perform initialization related to this module. */
2661 init_cp_semantics ()
2663 lang_expand_stmt = cp_expand_stmt;