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,
7 2003 Free Software Foundation, Inc.
8 Written by Mark Mitchell (mmitchell@usa.net) based on code found
9 formerly in parse.y and pt.c.
11 This file is part of GCC.
13 GCC is free software; you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2, or (at your option)
18 GCC is distributed in the hope that it will be useful, but
19 WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with GCC; see the file COPYING. If not, write to the Free
25 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
30 #include "coretypes.h"
34 #include "tree-inline.h"
45 /* There routines provide a modular interface to perform many parsing
46 operations. They may therefore be used during actual parsing, or
47 during template instantiation, which may be regarded as a
48 degenerate form of parsing. Since the current g++ parser is
49 lacking in several respects, and will be reimplemented, we are
50 attempting to move most code that is not directly related to
51 parsing into this file; that will make implementing the new parser
52 much easier since it will be able to make use of these routines. */
54 static tree maybe_convert_cond
PARAMS ((tree
));
55 static tree simplify_aggr_init_exprs_r
PARAMS ((tree
*, int *, void *));
56 static void emit_associated_thunks
PARAMS ((tree
));
57 static void genrtl_try_block
PARAMS ((tree
));
58 static void genrtl_eh_spec_block
PARAMS ((tree
));
59 static void genrtl_handler
PARAMS ((tree
));
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 /* Data for deferred access checking. */
83 static GTY(()) deferred_access
*deferred_access_stack
;
84 static GTY(()) deferred_access
*deferred_access_free_list
;
86 /* Save the current deferred access states and start deferred
87 access checking iff DEFER_P is true. */
89 void push_deferring_access_checks (bool deferring_p
)
93 /* Recycle previously used free store if available. */
94 if (deferred_access_free_list
)
96 d
= deferred_access_free_list
;
97 deferred_access_free_list
= d
->next
;
100 d
= (deferred_access
*) ggc_alloc (sizeof (deferred_access
));
102 d
->next
= deferred_access_stack
;
103 d
->deferred_access_checks
= NULL_TREE
;
104 d
->deferring_access_checks_p
= deferring_p
;
105 deferred_access_stack
= d
;
108 /* Resume deferring access checks again after we stopped doing
111 void resume_deferring_access_checks (void)
113 deferred_access_stack
->deferring_access_checks_p
= true;
116 /* Stop deferring access checks. */
118 void stop_deferring_access_checks (void)
120 deferred_access_stack
->deferring_access_checks_p
= false;
123 /* Discard the current deferred access checks and restore the
126 void pop_deferring_access_checks (void)
128 deferred_access
*d
= deferred_access_stack
;
129 deferred_access_stack
= d
->next
;
131 /* Remove references to access checks TREE_LIST. */
132 d
->deferred_access_checks
= NULL_TREE
;
134 /* Store in free list for later use. */
135 d
->next
= deferred_access_free_list
;
136 deferred_access_free_list
= d
;
139 /* Returns a TREE_LIST representing the deferred checks.
140 The TREE_PURPOSE of each node is the type through which the
141 access occurred; the TREE_VALUE is the declaration named.
144 tree
get_deferred_access_checks (void)
146 return deferred_access_stack
->deferred_access_checks
;
149 /* Take current deferred checks and combine with the
150 previous states if we also defer checks previously.
151 Otherwise perform checks now. */
153 void pop_to_parent_deferring_access_checks (void)
155 tree deferred_check
= get_deferred_access_checks ();
156 deferred_access
*d1
= deferred_access_stack
;
157 deferred_access
*d2
= deferred_access_stack
->next
;
158 deferred_access
*d3
= deferred_access_stack
->next
->next
;
160 /* Temporary swap the order of the top two states, just to make
161 sure the garbage collector will not reclaim the memory during
163 deferred_access_stack
= d2
;
167 for ( ; deferred_check
; deferred_check
= TREE_CHAIN (deferred_check
))
168 /* Perform deferred check if required. */
169 perform_or_defer_access_check (TREE_PURPOSE (deferred_check
),
170 TREE_VALUE (deferred_check
));
172 deferred_access_stack
= d1
;
175 pop_deferring_access_checks ();
178 /* Perform the deferred access checks. */
180 void perform_deferred_access_checks (void)
183 for (deferred_check
= deferred_access_stack
->deferred_access_checks
;
185 deferred_check
= TREE_CHAIN (deferred_check
))
187 enforce_access (TREE_PURPOSE (deferred_check
),
188 TREE_VALUE (deferred_check
));
190 /* No more deferred checks. */
191 deferred_access_stack
->deferred_access_checks
= NULL_TREE
;
194 /* Defer checking the accessibility of DECL, when looked up in
197 void perform_or_defer_access_check (tree class_type
, tree decl
)
201 /* If we are not supposed to defer access checks, just check now. */
202 if (!deferred_access_stack
->deferring_access_checks_p
)
204 enforce_access (class_type
, decl
);
208 /* See if we are already going to perform this check. */
209 for (check
= deferred_access_stack
->deferred_access_checks
;
211 check
= TREE_CHAIN (check
))
212 if (TREE_VALUE (check
) == decl
213 && same_type_p (TREE_PURPOSE (check
), class_type
))
215 /* If not, record the check. */
216 deferred_access_stack
->deferred_access_checks
217 = tree_cons (class_type
, decl
,
218 deferred_access_stack
->deferred_access_checks
);
221 /* Returns nonzero if the current statement is a full expression,
222 i.e. temporaries created during that statement should be destroyed
223 at the end of the statement. */
226 stmts_are_full_exprs_p ()
228 return current_stmt_tree ()->stmts_are_full_exprs_p
;
231 /* Returns the stmt_tree (if any) to which statements are currently
232 being added. If there is no active statement-tree, NULL is
239 ? &cfun
->language
->base
.x_stmt_tree
240 : &scope_chain
->x_stmt_tree
);
243 /* Nonzero if TYPE is an anonymous union or struct type. We have to use a
244 flag for this because "A union for which objects or pointers are
245 declared is not an anonymous union" [class.union]. */
248 anon_aggr_type_p (node
)
251 return ANON_AGGR_TYPE_P (node
);
254 /* Finish a scope. */
259 tree block
= NULL_TREE
;
261 if (stmts_are_full_exprs_p ())
263 tree scope_stmts
= NULL_TREE
;
265 block
= poplevel (kept_level_p (), 1, 0);
266 if (!processing_template_decl
)
268 /* This needs to come after the poplevel so that partial scopes
269 are properly nested. */
270 scope_stmts
= add_scope_stmt (/*begin_p=*/0, /*partial_p=*/0);
273 SCOPE_STMT_BLOCK (TREE_PURPOSE (scope_stmts
)) = block
;
274 SCOPE_STMT_BLOCK (TREE_VALUE (scope_stmts
)) = block
;
282 /* Begin a new scope. */
285 do_pushlevel (scope_kind sk
)
287 if (stmts_are_full_exprs_p ())
289 if (!processing_template_decl
)
290 add_scope_stmt (/*begin_p=*/1, /*partial_p=*/0);
295 /* Finish a goto-statement. */
298 finish_goto_stmt (destination
)
301 if (TREE_CODE (destination
) == IDENTIFIER_NODE
)
302 destination
= lookup_label (destination
);
304 /* We warn about unused labels with -Wunused. That means we have to
305 mark the used labels as used. */
306 if (TREE_CODE (destination
) == LABEL_DECL
)
307 TREE_USED (destination
) = 1;
309 if (TREE_CODE (destination
) != LABEL_DECL
)
310 /* We don't inline calls to functions with computed gotos.
311 Those functions are typically up to some funny business,
312 and may be depending on the labels being at particular
313 addresses, or some such. */
314 DECL_UNINLINABLE (current_function_decl
) = 1;
316 check_goto (destination
);
318 return add_stmt (build_stmt (GOTO_STMT
, destination
));
321 /* COND is the condition-expression for an if, while, etc.,
322 statement. Convert it to a boolean value, if appropriate. */
325 maybe_convert_cond (cond
)
328 /* Empty conditions remain empty. */
332 /* Wait until we instantiate templates before doing conversion. */
333 if (processing_template_decl
)
336 /* Do the conversion. */
337 cond
= convert_from_reference (cond
);
338 return condition_conversion (cond
);
341 /* Finish an expression-statement, whose EXPRESSION is as indicated. */
344 finish_expr_stmt (expr
)
348 tree expr_type
= NULL_TREE
;;
350 if (expr
!= NULL_TREE
)
352 if (!processing_template_decl
353 && !(stmts_are_full_exprs_p ())
354 && ((TREE_CODE (TREE_TYPE (expr
)) == ARRAY_TYPE
356 || TREE_CODE (TREE_TYPE (expr
)) == FUNCTION_TYPE
))
357 expr
= default_conversion (expr
);
359 /* Remember the type of the expression. */
360 expr_type
= TREE_TYPE (expr
);
362 if (stmts_are_full_exprs_p ())
363 expr
= convert_to_void (expr
, "statement");
365 r
= add_stmt (build_stmt (EXPR_STMT
, expr
));
370 /* This was an expression-statement, so we save the type of the
372 last_expr_type
= expr_type
;
378 /* Begin an if-statement. Returns a newly created IF_STMT if
385 do_pushlevel (sk_block
);
386 r
= build_stmt (IF_STMT
, NULL_TREE
, NULL_TREE
, NULL_TREE
);
391 /* Process the COND of an if-statement, which may be given by
395 finish_if_stmt_cond (cond
, if_stmt
)
399 cond
= maybe_convert_cond (cond
);
400 FINISH_COND (cond
, if_stmt
, IF_COND (if_stmt
));
403 /* Finish the then-clause of an if-statement, which may be given by
407 finish_then_clause (if_stmt
)
410 RECHAIN_STMTS (if_stmt
, THEN_CLAUSE (if_stmt
));
414 /* Begin the else-clause of an if-statement. */
421 /* Finish the else-clause of an if-statement, which may be given by
425 finish_else_clause (if_stmt
)
428 RECHAIN_STMTS (if_stmt
, ELSE_CLAUSE (if_stmt
));
431 /* Finish an if-statement. */
440 /* Begin a while-statement. Returns a newly created WHILE_STMT if
447 r
= build_stmt (WHILE_STMT
, NULL_TREE
, NULL_TREE
);
449 do_pushlevel (sk_block
);
453 /* Process the COND of a while-statement, which may be given by
457 finish_while_stmt_cond (cond
, while_stmt
)
461 cond
= maybe_convert_cond (cond
);
462 if (processing_template_decl
)
463 /* Don't mess with condition decls in a template. */
464 FINISH_COND (cond
, while_stmt
, WHILE_COND (while_stmt
));
465 else if (getdecls () == NULL_TREE
)
466 /* It was a simple condition; install it. */
467 WHILE_COND (while_stmt
) = cond
;
470 /* If there was a declaration in the condition, we can't leave it
474 while (true) { A x = 42; if (!x) break; } */
476 WHILE_COND (while_stmt
) = boolean_true_node
;
478 if_stmt
= begin_if_stmt ();
479 cond
= build_unary_op (TRUTH_NOT_EXPR
, cond
, 0);
480 finish_if_stmt_cond (cond
, if_stmt
);
481 finish_break_stmt ();
482 finish_then_clause (if_stmt
);
487 /* Finish a while-statement, which may be given by WHILE_STMT. */
490 finish_while_stmt (while_stmt
)
494 RECHAIN_STMTS (while_stmt
, WHILE_BODY (while_stmt
));
498 /* Begin a do-statement. Returns a newly created DO_STMT if
504 tree r
= build_stmt (DO_STMT
, NULL_TREE
, NULL_TREE
);
509 /* Finish the body of a do-statement, which may be given by DO_STMT. */
512 finish_do_body (do_stmt
)
515 RECHAIN_STMTS (do_stmt
, DO_BODY (do_stmt
));
518 /* Finish a do-statement, which may be given by DO_STMT, and whose
519 COND is as indicated. */
522 finish_do_stmt (cond
, do_stmt
)
526 cond
= maybe_convert_cond (cond
);
527 DO_COND (do_stmt
) = cond
;
531 /* Finish a return-statement. The EXPRESSION returned, if any, is as
535 finish_return_stmt (expr
)
540 expr
= check_return_expr (expr
);
541 if (!processing_template_decl
)
543 if (DECL_DESTRUCTOR_P (current_function_decl
))
545 /* Similarly, all destructors must run destructors for
546 base-classes before returning. So, all returns in a
547 destructor get sent to the DTOR_LABEL; finish_function emits
548 code to return a value there. */
549 return finish_goto_stmt (dtor_label
);
552 r
= add_stmt (build_stmt (RETURN_STMT
, expr
));
558 /* Begin a for-statement. Returns a new FOR_STMT if appropriate. */
565 r
= build_stmt (FOR_STMT
, NULL_TREE
, NULL_TREE
,
566 NULL_TREE
, NULL_TREE
);
567 NEW_FOR_SCOPE_P (r
) = flag_new_for_scope
> 0;
568 if (NEW_FOR_SCOPE_P (r
))
569 do_pushlevel (sk_for
);
575 /* Finish the for-init-statement of a for-statement, which may be
576 given by FOR_STMT. */
579 finish_for_init_stmt (for_stmt
)
582 if (last_tree
!= for_stmt
)
583 RECHAIN_STMTS (for_stmt
, FOR_INIT_STMT (for_stmt
));
584 do_pushlevel (sk_block
);
587 /* Finish the COND of a for-statement, which may be given by
591 finish_for_cond (cond
, for_stmt
)
595 cond
= maybe_convert_cond (cond
);
596 if (processing_template_decl
)
597 /* Don't mess with condition decls in a template. */
598 FINISH_COND (cond
, for_stmt
, FOR_COND (for_stmt
));
599 else if (getdecls () == NULL_TREE
)
600 /* It was a simple condition; install it. */
601 FOR_COND (for_stmt
) = cond
;
604 /* If there was a declaration in the condition, we can't leave it
606 for (; A x = 42;) { }
608 for (;;) { A x = 42; if (!x) break; } */
610 FOR_COND (for_stmt
) = NULL_TREE
;
612 if_stmt
= begin_if_stmt ();
613 cond
= build_unary_op (TRUTH_NOT_EXPR
, cond
, 0);
614 finish_if_stmt_cond (cond
, if_stmt
);
615 finish_break_stmt ();
616 finish_then_clause (if_stmt
);
621 /* Finish the increment-EXPRESSION in a for-statement, which may be
622 given by FOR_STMT. */
625 finish_for_expr (expr
, for_stmt
)
629 FOR_EXPR (for_stmt
) = expr
;
632 /* Finish the body of a for-statement, which may be given by
633 FOR_STMT. The increment-EXPR for the loop must be
637 finish_for_stmt (for_stmt
)
640 /* Pop the scope for the body of the loop. */
642 RECHAIN_STMTS (for_stmt
, FOR_BODY (for_stmt
));
643 if (NEW_FOR_SCOPE_P (for_stmt
))
648 /* Finish a break-statement. */
653 return add_stmt (build_break_stmt ());
656 /* Finish a continue-statement. */
659 finish_continue_stmt ()
661 return add_stmt (build_continue_stmt ());
664 /* Begin a switch-statement. Returns a new SWITCH_STMT if
671 do_pushlevel (sk_block
);
672 r
= build_stmt (SWITCH_STMT
, NULL_TREE
, NULL_TREE
, NULL_TREE
);
677 /* Finish the cond of a switch-statement. */
680 finish_switch_cond (cond
, switch_stmt
)
684 tree orig_type
= NULL
;
685 if (!processing_template_decl
)
689 /* Convert the condition to an integer or enumeration type. */
690 cond
= build_expr_type_conversion (WANT_INT
| WANT_ENUM
, cond
, true);
691 if (cond
== NULL_TREE
)
693 error ("switch quantity not an integer");
694 cond
= error_mark_node
;
696 orig_type
= TREE_TYPE (cond
);
697 if (cond
!= error_mark_node
)
699 cond
= default_conversion (cond
);
700 cond
= fold (build1 (CLEANUP_POINT_EXPR
, TREE_TYPE (cond
), cond
));
703 if (cond
!= error_mark_node
)
705 index
= get_unwidened (cond
, NULL_TREE
);
706 /* We can't strip a conversion from a signed type to an unsigned,
707 because if we did, int_fits_type_p would do the wrong thing
708 when checking case values for being in range,
709 and it's too hard to do the right thing. */
710 if (TREE_UNSIGNED (TREE_TYPE (cond
))
711 == TREE_UNSIGNED (TREE_TYPE (index
)))
715 FINISH_COND (cond
, switch_stmt
, SWITCH_COND (switch_stmt
));
716 SWITCH_TYPE (switch_stmt
) = orig_type
;
717 push_switch (switch_stmt
);
720 /* Finish the body of a switch-statement, which may be given by
721 SWITCH_STMT. The COND to switch on is indicated. */
724 finish_switch_stmt (switch_stmt
)
727 RECHAIN_STMTS (switch_stmt
, SWITCH_BODY (switch_stmt
));
733 /* Generate the RTL for T, which is a TRY_BLOCK. */
741 expand_eh_region_start ();
742 expand_stmt (TRY_STMTS (t
));
743 expand_eh_region_end_cleanup (TRY_HANDLERS (t
));
747 if (!FN_TRY_BLOCK_P (t
))
748 emit_line_note (input_filename
, input_line
);
750 expand_eh_region_start ();
751 expand_stmt (TRY_STMTS (t
));
753 if (FN_TRY_BLOCK_P (t
))
755 expand_start_all_catch ();
756 in_function_try_handler
= 1;
757 expand_stmt (TRY_HANDLERS (t
));
758 in_function_try_handler
= 0;
759 expand_end_all_catch ();
763 expand_start_all_catch ();
764 expand_stmt (TRY_HANDLERS (t
));
765 expand_end_all_catch ();
770 /* Generate the RTL for T, which is an EH_SPEC_BLOCK. */
773 genrtl_eh_spec_block (t
)
776 expand_eh_region_start ();
777 expand_stmt (EH_SPEC_STMTS (t
));
778 expand_eh_region_end_allowed (EH_SPEC_RAISES (t
),
779 build_call (call_unexpected_node
,
780 tree_cons (NULL_TREE
,
785 /* Begin a try-block. Returns a newly-created TRY_BLOCK if
791 tree r
= build_stmt (TRY_BLOCK
, NULL_TREE
, NULL_TREE
);
796 /* Likewise, for a function-try-block. */
799 begin_function_try_block ()
801 tree r
= build_stmt (TRY_BLOCK
, NULL_TREE
, NULL_TREE
);
802 FN_TRY_BLOCK_P (r
) = 1;
807 /* Finish a try-block, which may be given by TRY_BLOCK. */
810 finish_try_block (try_block
)
813 RECHAIN_STMTS (try_block
, TRY_STMTS (try_block
));
816 /* Finish the body of a cleanup try-block, which may be given by
820 finish_cleanup_try_block (try_block
)
823 RECHAIN_STMTS (try_block
, TRY_STMTS (try_block
));
826 /* Finish an implicitly generated try-block, with a cleanup is given
830 finish_cleanup (cleanup
, try_block
)
834 TRY_HANDLERS (try_block
) = cleanup
;
835 CLEANUP_P (try_block
) = 1;
838 /* Likewise, for a function-try-block. */
841 finish_function_try_block (try_block
)
844 if (TREE_CHAIN (try_block
)
845 && TREE_CODE (TREE_CHAIN (try_block
)) == CTOR_INITIALIZER
)
847 /* Chain the compound statement after the CTOR_INITIALIZER. */
848 TREE_CHAIN (TREE_CHAIN (try_block
)) = last_tree
;
849 /* And make the CTOR_INITIALIZER the body of the try-block. */
850 RECHAIN_STMTS (try_block
, TRY_STMTS (try_block
));
853 RECHAIN_STMTS (try_block
, TRY_STMTS (try_block
));
854 in_function_try_handler
= 1;
857 /* Finish a handler-sequence for a try-block, which may be given by
861 finish_handler_sequence (try_block
)
864 RECHAIN_STMTS (try_block
, TRY_HANDLERS (try_block
));
865 check_handlers (TRY_HANDLERS (try_block
));
868 /* Likewise, for a function-try-block. */
871 finish_function_handler_sequence (try_block
)
874 in_function_try_handler
= 0;
875 RECHAIN_STMTS (try_block
, TRY_HANDLERS (try_block
));
876 check_handlers (TRY_HANDLERS (try_block
));
879 /* Generate the RTL for T, which is a HANDLER. */
885 genrtl_do_pushlevel ();
886 if (!processing_template_decl
)
887 expand_start_catch (HANDLER_TYPE (t
));
888 expand_stmt (HANDLER_BODY (t
));
889 if (!processing_template_decl
)
893 /* Begin a handler. Returns a HANDLER if appropriate. */
899 r
= build_stmt (HANDLER
, NULL_TREE
, NULL_TREE
);
901 /* Create a binding level for the eh_info and the exception object
903 do_pushlevel (sk_catch
);
907 /* Finish the handler-parameters for a handler, which may be given by
908 HANDLER. DECL is the declaration for the catch parameter, or NULL
909 if this is a `catch (...)' clause. */
912 finish_handler_parms (decl
, handler
)
916 tree type
= NULL_TREE
;
917 if (processing_template_decl
)
921 decl
= pushdecl (decl
);
922 decl
= push_template_decl (decl
);
923 add_decl_stmt (decl
);
924 RECHAIN_STMTS (handler
, HANDLER_PARMS (handler
));
925 type
= TREE_TYPE (decl
);
929 type
= expand_start_catch_block (decl
);
931 HANDLER_TYPE (handler
) = type
;
934 /* Finish a handler, which may be given by HANDLER. The BLOCKs are
935 the return value from the matching call to finish_handler_parms. */
938 finish_handler (handler
)
941 if (!processing_template_decl
)
942 expand_end_catch_block ();
944 RECHAIN_STMTS (handler
, HANDLER_BODY (handler
));
947 /* Begin a compound-statement. If HAS_NO_SCOPE is nonzero, the
948 compound-statement does not define a scope. Returns a new
949 COMPOUND_STMT if appropriate. */
952 begin_compound_stmt (has_no_scope
)
958 r
= build_stmt (COMPOUND_STMT
, NULL_TREE
);
960 if (last_tree
&& TREE_CODE (last_tree
) == TRY_BLOCK
)
965 COMPOUND_STMT_NO_SCOPE (r
) = 1;
967 last_expr_type
= NULL_TREE
;
970 do_pushlevel (is_try
? sk_try
: sk_block
);
972 /* Normally, we try hard to keep the BLOCK for a
973 statement-expression. But, if it's a statement-expression with
974 a scopeless block, there's nothing to keep, and we don't want
975 to accidentally keep a block *inside* the scopeless block. */
981 /* Finish a compound-statement, which may be given by COMPOUND_STMT.
982 If HAS_NO_SCOPE is nonzero, the compound statement does not define
986 finish_compound_stmt (has_no_scope
, compound_stmt
)
998 RECHAIN_STMTS (compound_stmt
, COMPOUND_BODY (compound_stmt
));
1000 /* When we call finish_stmt we will lose LAST_EXPR_TYPE. But, since
1001 the precise purpose of that variable is store the type of the
1002 last expression statement within the last compound statement, we
1003 preserve the value. */
1011 /* Finish an asm-statement, whose components are a CV_QUALIFIER, a
1012 STRING, some OUTPUT_OPERANDS, some INPUT_OPERANDS, and some
1016 finish_asm_stmt (cv_qualifier
, string
, output_operands
,
1017 input_operands
, clobbers
)
1020 tree output_operands
;
1021 tree input_operands
;
1027 if (cv_qualifier
!= NULL_TREE
1028 && cv_qualifier
!= ridpointers
[(int) RID_VOLATILE
])
1030 warning ("%s qualifier ignored on asm",
1031 IDENTIFIER_POINTER (cv_qualifier
));
1032 cv_qualifier
= NULL_TREE
;
1035 if (!processing_template_decl
)
1041 for (t
= input_operands
; t
; t
= TREE_CHAIN (t
))
1043 tree converted_operand
1044 = decay_conversion (TREE_VALUE (t
));
1046 /* If the type of the operand hasn't been determined (e.g.,
1047 because it involves an overloaded function), then issue
1048 an error message. There's no context available to
1049 resolve the overloading. */
1050 if (TREE_TYPE (converted_operand
) == unknown_type_node
)
1052 error ("type of asm operand `%E' could not be determined",
1054 converted_operand
= error_mark_node
;
1056 TREE_VALUE (t
) = converted_operand
;
1059 ninputs
= list_length (input_operands
);
1060 noutputs
= list_length (output_operands
);
1062 for (i
= 0, t
= output_operands
; t
; t
= TREE_CHAIN (t
), ++i
)
1067 const char *constraint
;
1070 constraint
= TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t
)));
1071 operand
= TREE_VALUE (t
);
1073 if (!parse_output_constraint (&constraint
,
1074 i
, ninputs
, noutputs
,
1079 /* By marking this operand as erroneous, we will not try
1080 to process this operand again in expand_asm_operands. */
1081 TREE_VALUE (t
) = error_mark_node
;
1085 /* If the operand is a DECL that is going to end up in
1086 memory, assume it is addressable. This is a bit more
1087 conservative than it would ideally be; the exact test is
1088 buried deep in expand_asm_operands and depends on the
1089 DECL_RTL for the OPERAND -- which we don't have at this
1091 if (!allows_reg
&& DECL_P (operand
))
1092 cxx_mark_addressable (operand
);
1096 r
= build_stmt (ASM_STMT
, cv_qualifier
, string
,
1097 output_operands
, input_operands
,
1099 return add_stmt (r
);
1102 /* Finish a label with the indicated NAME. */
1105 finish_label_stmt (name
)
1108 tree decl
= define_label (input_filename
, input_line
, name
);
1109 return add_stmt (build_stmt (LABEL_STMT
, decl
));
1112 /* Finish a series of declarations for local labels. G++ allows users
1113 to declare "local" labels, i.e., labels with scope. This extension
1114 is useful when writing code involving statement-expressions. */
1117 finish_label_decl (name
)
1120 tree decl
= declare_local_label (name
);
1121 add_decl_stmt (decl
);
1124 /* When DECL goes out of scope, make sure that CLEANUP is executed. */
1127 finish_decl_cleanup (decl
, cleanup
)
1131 add_stmt (build_stmt (CLEANUP_STMT
, decl
, cleanup
));
1134 /* If the current scope exits with an exception, run CLEANUP. */
1137 finish_eh_cleanup (cleanup
)
1140 tree r
= build_stmt (CLEANUP_STMT
, NULL_TREE
, cleanup
);
1141 CLEANUP_EH_ONLY (r
) = 1;
1145 /* The MEM_INITS is a list of mem-initializers, in reverse of the
1146 order they were written by the user. Each node is as for
1147 emit_mem_initializers. */
1150 finish_mem_initializers (tree mem_inits
)
1152 /* Reorder the MEM_INITS so that they are in the order they appeared
1153 in the source program. */
1154 mem_inits
= nreverse (mem_inits
);
1156 if (processing_template_decl
)
1157 add_stmt (build_min_nt (CTOR_INITIALIZER
, mem_inits
));
1159 emit_mem_initializers (mem_inits
);
1162 /* Returns the stack of SCOPE_STMTs for the current function. */
1165 current_scope_stmt_stack ()
1167 return &cfun
->language
->base
.x_scope_stmt_stack
;
1170 /* Finish a parenthesized expression EXPR. */
1173 finish_parenthesized_expr (expr
)
1176 if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (TREE_CODE (expr
))))
1177 /* This inhibits warnings in c_common_truthvalue_conversion. */
1178 C_SET_EXP_ORIGINAL_CODE (expr
, ERROR_MARK
);
1180 if (TREE_CODE (expr
) == OFFSET_REF
)
1181 /* [expr.unary.op]/3 The qualified id of a pointer-to-member must not be
1182 enclosed in parentheses. */
1183 PTRMEM_OK_P (expr
) = 0;
1187 /* Finish a reference to a non-static data member (DECL) that is not
1188 preceded by `.' or `->'. */
1191 finish_non_static_data_member (tree decl
, tree qualifying_scope
)
1193 my_friendly_assert (TREE_CODE (decl
) == FIELD_DECL
, 20020909);
1195 if (current_class_ptr
== NULL_TREE
)
1197 if (current_function_decl
1198 && DECL_STATIC_FUNCTION_P (current_function_decl
))
1199 cp_error_at ("invalid use of member `%D' in static member function",
1202 cp_error_at ("invalid use of non-static data member `%D'", decl
);
1203 error ("from this location");
1205 return error_mark_node
;
1207 TREE_USED (current_class_ptr
) = 1;
1208 if (processing_template_decl
)
1209 return build_min (COMPONENT_REF
, TREE_TYPE (decl
),
1210 current_class_ref
, DECL_NAME (decl
));
1213 tree access_type
= current_class_type
;
1214 tree object
= current_class_ref
;
1216 while (!DERIVED_FROM_P (context_for_name_lookup (decl
), access_type
))
1218 access_type
= TYPE_CONTEXT (access_type
);
1219 while (DECL_P (access_type
))
1220 access_type
= DECL_CONTEXT (access_type
);
1223 enforce_access (access_type
, decl
);
1225 /* If the data member was named `C::M', convert `*this' to `C'
1227 if (qualifying_scope
)
1229 tree binfo
= NULL_TREE
;
1230 object
= build_scoped_ref (object
, qualifying_scope
,
1234 return build_class_member_access_expr (object
, decl
,
1235 /*access_path=*/NULL_TREE
,
1236 /*preserve_reference=*/false);
1240 /* Begin a statement-expression. The value returned must be passed to
1241 finish_stmt_expr. */
1246 /* If we're outside a function, we won't have a statement-tree to
1247 work with. But, if we see a statement-expression we need to
1249 if (! cfun
&& !last_tree
)
1250 begin_stmt_tree (&scope_chain
->x_saved_tree
);
1252 keep_next_level (1);
1253 /* If we're building a statement tree, then the upcoming compound
1254 statement will be chained onto the tree structure, starting at
1255 last_tree. We return last_tree so that we can later unhook the
1256 compound statement. */
1260 /* Used when beginning a statement-expression outside function scope.
1261 For example, when handling a file-scope initializer, we use this
1265 begin_global_stmt_expr ()
1267 if (! cfun
&& !last_tree
)
1268 begin_stmt_tree (&scope_chain
->x_saved_tree
);
1270 keep_next_level (1);
1272 return last_tree
? last_tree
: expand_start_stmt_expr(/*has_scope=*/1);
1275 /* Finish the STMT_EXPR last begun with begin_global_stmt_expr. */
1278 finish_global_stmt_expr (stmt_expr
)
1281 stmt_expr
= expand_end_stmt_expr (stmt_expr
);
1284 && TREE_CHAIN (scope_chain
->x_saved_tree
) == NULL_TREE
)
1285 finish_stmt_tree (&scope_chain
->x_saved_tree
);
1290 /* Finish a statement-expression. RTL_EXPR should be the value
1291 returned by the previous begin_stmt_expr; EXPR is the
1292 statement-expression. Returns an expression representing the
1293 statement-expression. */
1296 finish_stmt_expr (rtl_expr
)
1301 /* If the last thing in the statement-expression was not an
1302 expression-statement, then it has type `void'. */
1303 if (!last_expr_type
)
1304 last_expr_type
= void_type_node
;
1305 result
= build_min (STMT_EXPR
, last_expr_type
, last_tree
);
1306 TREE_SIDE_EFFECTS (result
) = 1;
1308 /* Remove the compound statement from the tree structure; it is
1309 now saved in the STMT_EXPR. */
1310 last_tree
= rtl_expr
;
1311 TREE_CHAIN (last_tree
) = NULL_TREE
;
1313 /* If we created a statement-tree for this statement-expression,
1316 && TREE_CHAIN (scope_chain
->x_saved_tree
) == NULL_TREE
)
1317 finish_stmt_tree (&scope_chain
->x_saved_tree
);
1322 /* Generate an expression for `FN (ARGS)'.
1324 If DISALLOW_VIRTUAL is true, the call to FN will be not generated
1325 as a virtual call, even if FN is virtual. (This flag is set when
1326 encountering an expression where the function name is explicitly
1327 qualified. For example a call to `X::f' never generates a virtual
1330 Returns code for the call. */
1333 finish_call_expr (tree fn
, tree args
, bool disallow_virtual
)
1335 if (fn
== error_mark_node
|| args
== error_mark_node
)
1336 return error_mark_node
;
1338 if (processing_template_decl
)
1339 return build_nt (CALL_EXPR
, fn
, args
, NULL_TREE
);
1341 /* ARGS should be a list of arguments. */
1342 my_friendly_assert (!args
|| TREE_CODE (args
) == TREE_LIST
,
1345 /* A reference to a member function will appear as an overloaded
1346 function (rather than a BASELINK) if an unqualified name was used
1348 if (!BASELINK_P (fn
) && is_overloaded_fn (fn
))
1352 if (TREE_CODE (fn
) == TEMPLATE_ID_EXPR
)
1353 f
= get_first_fn (TREE_OPERAND (fn
, 0));
1355 f
= get_first_fn (fn
);
1356 if (DECL_FUNCTION_MEMBER_P (f
))
1358 tree type
= currently_open_derived_class (DECL_CONTEXT (f
));
1359 fn
= build_baselink (TYPE_BINFO (type
),
1361 fn
, /*optype=*/NULL_TREE
);
1365 if (BASELINK_P (fn
))
1369 /* A call to a member function. From [over.call.func]:
1371 If the keyword this is in scope and refers to the class of
1372 that member function, or a derived class thereof, then the
1373 function call is transformed into a qualified function call
1374 using (*this) as the postfix-expression to the left of the
1375 . operator.... [Otherwise] a contrived object of type T
1376 becomes the implied object argument.
1378 This paragraph is unclear about this situation:
1380 struct A { void f(); };
1381 struct B : public A {};
1382 struct C : public A { void g() { B::f(); }};
1384 In particular, for `B::f', this paragraph does not make clear
1385 whether "the class of that member function" refers to `A' or
1386 to `B'. We believe it refers to `B'. */
1387 if (current_class_type
1388 && DERIVED_FROM_P (BINFO_TYPE (BASELINK_ACCESS_BINFO (fn
)),
1390 && current_class_ref
)
1391 object
= current_class_ref
;
1394 tree representative_fn
;
1396 representative_fn
= BASELINK_FUNCTIONS (fn
);
1397 if (TREE_CODE (representative_fn
) == TEMPLATE_ID_EXPR
)
1398 representative_fn
= TREE_OPERAND (representative_fn
, 0);
1399 representative_fn
= get_first_fn (representative_fn
);
1400 object
= build_dummy_object (DECL_CONTEXT (representative_fn
));
1403 return build_new_method_call (object
, fn
, args
, NULL_TREE
,
1405 ? LOOKUP_NONVIRTUAL
: 0));
1407 else if (is_overloaded_fn (fn
))
1408 /* A call to a namespace-scope function. */
1409 return build_new_function_call (fn
, args
);
1410 else if (TREE_CODE (fn
) == PSEUDO_DTOR_EXPR
)
1415 error ("arguments to destructor are not allowed");
1416 /* Mark the pseudo-destructor call as having side-effects so
1417 that we do not issue warnings about its use. */
1418 result
= build1 (NOP_EXPR
,
1420 TREE_OPERAND (fn
, 0));
1421 TREE_SIDE_EFFECTS (result
) = 1;
1424 else if (CLASS_TYPE_P (TREE_TYPE (fn
)))
1426 /* If the "function" is really an object of class type, it might
1427 have an overloaded `operator ()'. */
1429 result
= build_new_op (CALL_EXPR
, LOOKUP_NORMAL
, fn
, args
, NULL_TREE
);
1434 /* A call where the function is unknown. */
1435 return build_function_call (fn
, args
);
1438 /* Finish a call to a postfix increment or decrement or EXPR. (Which
1439 is indicated by CODE, which should be POSTINCREMENT_EXPR or
1440 POSTDECREMENT_EXPR.) */
1443 finish_increment_expr (expr
, code
)
1445 enum tree_code code
;
1447 /* If we get an OFFSET_REF, turn it into what it really means (e.g.,
1448 a COMPONENT_REF). This way if we've got, say, a reference to a
1449 static member that's being operated on, we don't end up trying to
1450 find a member operator for the class it's in. */
1452 if (TREE_CODE (expr
) == OFFSET_REF
)
1453 expr
= resolve_offset_ref (expr
);
1454 return build_x_unary_op (code
, expr
);
1457 /* Finish a use of `this'. Returns an expression for `this'. */
1464 if (current_class_ptr
)
1466 result
= current_class_ptr
;
1468 else if (current_function_decl
1469 && DECL_STATIC_FUNCTION_P (current_function_decl
))
1471 error ("`this' is unavailable for static member functions");
1472 result
= error_mark_node
;
1476 if (current_function_decl
)
1477 error ("invalid use of `this' in non-member function");
1479 error ("invalid use of `this' at top level");
1480 result
= error_mark_node
;
1486 /* Finish a member function call using OBJECT and ARGS as arguments to
1487 FN. Returns an expression for the call. */
1490 finish_object_call_expr (fn
, object
, args
)
1495 if (DECL_DECLARES_TYPE_P (fn
))
1497 if (processing_template_decl
)
1498 /* This can happen on code like:
1501 template <class T> void f(T t) {
1505 We just grab the underlying IDENTIFIER. */
1506 fn
= DECL_NAME (fn
);
1509 error ("calling type `%T' like a method", fn
);
1510 return error_mark_node
;
1514 if (processing_template_decl
)
1515 return build_nt (CALL_EXPR
,
1516 build_nt (COMPONENT_REF
, object
, fn
),
1520 return build_method_call (object
, fn
, args
, NULL_TREE
, LOOKUP_NORMAL
);
1522 return build_new_method_call (object
, fn
, args
, NULL_TREE
, LOOKUP_NORMAL
);
1525 /* Finish a qualified member function call using OBJECT and ARGS as
1526 arguments to FN. Returns an expression for the call. */
1529 finish_qualified_object_call_expr (fn
, object
, args
)
1534 return build_scoped_method_call (object
, TREE_OPERAND (fn
, 0),
1535 TREE_OPERAND (fn
, 1), args
);
1538 /* Finish a pseudo-destructor expression. If SCOPE is NULL, the
1539 expression was of the form `OBJECT.~DESTRUCTOR' where DESTRUCTOR is
1540 the TYPE for the type given. If SCOPE is non-NULL, the expression
1541 was of the form `OBJECT.SCOPE::~DESTRUCTOR'. */
1544 finish_pseudo_destructor_expr (object
, scope
, destructor
)
1549 if (destructor
== error_mark_node
)
1550 return error_mark_node
;
1552 my_friendly_assert (TYPE_P (destructor
), 20010905);
1554 if (!processing_template_decl
)
1556 if (scope
== error_mark_node
)
1558 error ("invalid qualifying scope in pseudo-destructor name");
1559 return error_mark_node
;
1562 if (!same_type_p (TREE_TYPE (object
), destructor
))
1564 error ("`%E' is not of type `%T'", object
, destructor
);
1565 return error_mark_node
;
1569 return build (PSEUDO_DTOR_EXPR
, void_type_node
, object
, scope
, destructor
);
1572 /* Finish an expression of the form CODE EXPR. */
1575 finish_unary_op_expr (code
, expr
)
1576 enum tree_code code
;
1579 tree result
= build_x_unary_op (code
, expr
);
1580 /* Inside a template, build_x_unary_op does not fold the
1581 expression. So check whether the result is folded before
1582 setting TREE_NEGATED_INT. */
1583 if (code
== NEGATE_EXPR
&& TREE_CODE (expr
) == INTEGER_CST
1584 && TREE_CODE (result
) == INTEGER_CST
1585 && !TREE_UNSIGNED (TREE_TYPE (result
))
1586 && INT_CST_LT (result
, integer_zero_node
))
1587 TREE_NEGATED_INT (result
) = 1;
1588 overflow_warning (result
);
1592 /* Finish a compound-literal expression. TYPE is the type to which
1593 the INITIALIZER_LIST is being cast. */
1596 finish_compound_literal (type
, initializer_list
)
1598 tree initializer_list
;
1600 tree compound_literal
;
1602 /* Build a CONSTRUCTOR for the INITIALIZER_LIST. */
1603 compound_literal
= build_constructor (NULL_TREE
, initializer_list
);
1604 /* Mark it as a compound-literal. */
1605 TREE_HAS_CONSTRUCTOR (compound_literal
) = 1;
1606 if (processing_template_decl
)
1607 TREE_TYPE (compound_literal
) = type
;
1610 /* Check the initialization. */
1611 compound_literal
= digest_init (type
, compound_literal
, NULL
);
1612 /* If the TYPE was an array type with an unknown bound, then we can
1613 figure out the dimension now. For example, something like:
1617 implies that the array has two elements. */
1618 if (TREE_CODE (type
) == ARRAY_TYPE
&& !COMPLETE_TYPE_P (type
))
1619 complete_array_type (type
, compound_literal
, 1);
1622 return compound_literal
;
1625 /* Return the declaration for the function-name variable indicated by
1629 finish_fname (tree id
)
1633 decl
= fname_decl (C_RID_CODE (id
), id
);
1634 if (processing_template_decl
)
1635 decl
= build_min_nt (LOOKUP_EXPR
, DECL_NAME (decl
));
1639 /* Begin a function definition declared with DECL_SPECS, ATTRIBUTES,
1640 and DECLARATOR. Returns nonzero if the function-declaration is
1644 begin_function_definition (decl_specs
, attributes
, declarator
)
1649 if (!start_function (decl_specs
, declarator
, attributes
, SF_DEFAULT
))
1652 /* The things we're about to see are not directly qualified by any
1653 template headers we've seen thus far. */
1654 reset_specialization ();
1659 /* Finish an init-declarator. Returns a DECL. */
1662 finish_declarator (declarator
, declspecs
, attributes
,
1663 prefix_attributes
, initialized
)
1667 tree prefix_attributes
;
1670 return start_decl (declarator
, declspecs
, initialized
, attributes
,
1674 /* Finish a translation unit. */
1677 finish_translation_unit ()
1679 /* In case there were missing closebraces,
1680 get us back to the global binding level. */
1682 while (current_namespace
!= global_namespace
)
1685 /* Do file scope __FUNCTION__ et al. */
1686 finish_fname_decls ();
1689 /* Finish a template type parameter, specified as AGGR IDENTIFIER.
1690 Returns the parameter. */
1693 finish_template_type_parm (aggr
, identifier
)
1697 if (aggr
!= class_type_node
)
1699 pedwarn ("template type parameters must use the keyword `class' or `typename'");
1700 aggr
= class_type_node
;
1703 return build_tree_list (aggr
, identifier
);
1706 /* Finish a template template parameter, specified as AGGR IDENTIFIER.
1707 Returns the parameter. */
1710 finish_template_template_parm (aggr
, identifier
)
1714 tree decl
= build_decl (TYPE_DECL
, identifier
, NULL_TREE
);
1715 tree tmpl
= build_lang_decl (TEMPLATE_DECL
, identifier
, NULL_TREE
);
1716 DECL_TEMPLATE_PARMS (tmpl
) = current_template_parms
;
1717 DECL_TEMPLATE_RESULT (tmpl
) = decl
;
1718 DECL_ARTIFICIAL (decl
) = 1;
1719 end_template_decl ();
1721 my_friendly_assert (DECL_TEMPLATE_PARMS (tmpl
), 20010110);
1723 return finish_template_type_parm (aggr
, tmpl
);
1726 /* ARGUMENT is the default-argument value for a template template
1727 parameter. If ARGUMENT is invalid, issue error messages and return
1728 the ERROR_MARK_NODE. Otherwise, ARGUMENT itself is returned. */
1731 check_template_template_default_arg (tree argument
)
1733 if (TREE_CODE (argument
) != TEMPLATE_DECL
1734 && TREE_CODE (argument
) != TEMPLATE_TEMPLATE_PARM
1735 && TREE_CODE (argument
) != TYPE_DECL
1736 && TREE_CODE (argument
) != UNBOUND_CLASS_TEMPLATE
)
1738 error ("invalid default template argument");
1739 return error_mark_node
;
1745 /* Finish a parameter list, indicated by PARMS. If ELLIPSIS is
1746 nonzero, the parameter list was terminated by a `...'. */
1749 finish_parmlist (parms
, ellipsis
)
1755 /* We mark the PARMS as a parmlist so that declarator processing can
1756 disambiguate certain constructs. */
1757 TREE_PARMLIST (parms
) = 1;
1758 /* We do not append void_list_node here, but leave it to grokparms
1760 PARMLIST_ELLIPSIS_P (parms
) = ellipsis
;
1765 /* Begin a class definition, as indicated by T. */
1768 begin_class_definition (t
)
1771 if (t
== error_mark_node
)
1772 return error_mark_node
;
1774 if (processing_template_parmlist
)
1776 error ("definition of `%#T' inside template parameter list", t
);
1777 return error_mark_node
;
1779 /* A non-implicit typename comes from code like:
1781 template <typename T> struct A {
1782 template <typename U> struct A<T>::B ...
1784 This is erroneous. */
1785 else if (TREE_CODE (t
) == TYPENAME_TYPE
)
1787 error ("invalid definition of qualified type `%T'", t
);
1788 t
= error_mark_node
;
1791 if (t
== error_mark_node
|| ! IS_AGGR_TYPE (t
))
1793 t
= make_aggr_type (RECORD_TYPE
);
1794 pushtag (make_anon_name (), t
, 0);
1797 /* If this type was already complete, and we see another definition,
1799 if (COMPLETE_TYPE_P (t
))
1801 error ("redefinition of `%#T'", t
);
1802 cp_error_at ("previous definition of `%#T'", t
);
1803 return error_mark_node
;
1806 /* Update the location of the decl. */
1807 DECL_SOURCE_LOCATION (TYPE_NAME (t
)) = input_location
;
1809 if (TYPE_BEING_DEFINED (t
))
1811 t
= make_aggr_type (TREE_CODE (t
));
1812 pushtag (TYPE_IDENTIFIER (t
), t
, 0);
1814 maybe_process_partial_specialization (t
);
1815 pushclass (t
, true);
1816 TYPE_BEING_DEFINED (t
) = 1;
1817 TYPE_PACKED (t
) = flag_pack_struct
;
1818 /* Reset the interface data, at the earliest possible
1819 moment, as it might have been set via a class foo;
1821 if (! TYPE_ANONYMOUS_P (t
))
1823 CLASSTYPE_INTERFACE_ONLY (t
) = interface_only
;
1824 SET_CLASSTYPE_INTERFACE_UNKNOWN_X
1825 (t
, interface_unknown
);
1827 reset_specialization();
1829 /* Make a declaration for this class in its own scope. */
1830 build_self_reference ();
1835 /* Finish the member declaration given by DECL. */
1838 finish_member_declaration (decl
)
1841 if (decl
== error_mark_node
|| decl
== NULL_TREE
)
1844 if (decl
== void_type_node
)
1845 /* The COMPONENT was a friend, not a member, and so there's
1846 nothing for us to do. */
1849 /* We should see only one DECL at a time. */
1850 my_friendly_assert (TREE_CHAIN (decl
) == NULL_TREE
, 0);
1852 /* Set up access control for DECL. */
1854 = (current_access_specifier
== access_private_node
);
1855 TREE_PROTECTED (decl
)
1856 = (current_access_specifier
== access_protected_node
);
1857 if (TREE_CODE (decl
) == TEMPLATE_DECL
)
1859 TREE_PRIVATE (DECL_TEMPLATE_RESULT (decl
)) = TREE_PRIVATE (decl
);
1860 TREE_PROTECTED (DECL_TEMPLATE_RESULT (decl
)) = TREE_PROTECTED (decl
);
1863 /* Mark the DECL as a member of the current class. */
1864 DECL_CONTEXT (decl
) = current_class_type
;
1868 A C language linkage is ignored for the names of class members
1869 and the member function type of class member functions. */
1870 if (DECL_LANG_SPECIFIC (decl
) && DECL_LANGUAGE (decl
) == lang_c
)
1871 SET_DECL_LANGUAGE (decl
, lang_cplusplus
);
1873 maybe_add_class_template_decl_list (current_class_type
, decl
, /*friend_p=*/0);
1875 /* Put functions on the TYPE_METHODS list and everything else on the
1876 TYPE_FIELDS list. Note that these are built up in reverse order.
1877 We reverse them (to obtain declaration order) in finish_struct. */
1878 if (TREE_CODE (decl
) == FUNCTION_DECL
1879 || DECL_FUNCTION_TEMPLATE_P (decl
))
1881 /* We also need to add this function to the
1882 CLASSTYPE_METHOD_VEC. */
1883 add_method (current_class_type
, decl
, /*error_p=*/0);
1885 TREE_CHAIN (decl
) = TYPE_METHODS (current_class_type
);
1886 TYPE_METHODS (current_class_type
) = decl
;
1890 /* All TYPE_DECLs go at the end of TYPE_FIELDS. Ordinary fields
1891 go at the beginning. The reason is that lookup_field_1
1892 searches the list in order, and we want a field name to
1893 override a type name so that the "struct stat hack" will
1894 work. In particular:
1896 struct S { enum E { }; int E } s;
1899 is valid. In addition, the FIELD_DECLs must be maintained in
1900 declaration order so that class layout works as expected.
1901 However, we don't need that order until class layout, so we
1902 save a little time by putting FIELD_DECLs on in reverse order
1903 here, and then reversing them in finish_struct_1. (We could
1904 also keep a pointer to the correct insertion points in the
1907 if (TREE_CODE (decl
) == TYPE_DECL
)
1908 TYPE_FIELDS (current_class_type
)
1909 = chainon (TYPE_FIELDS (current_class_type
), decl
);
1912 TREE_CHAIN (decl
) = TYPE_FIELDS (current_class_type
);
1913 TYPE_FIELDS (current_class_type
) = decl
;
1916 /* Enter the DECL into the scope of the class. */
1917 if (TREE_CODE (decl
) != USING_DECL
)
1918 pushdecl_class_level (decl
);
1922 /* Finish a class definition T with the indicate ATTRIBUTES. If SEMI,
1923 the definition is immediately followed by a semicolon. Returns the
1927 finish_class_definition (t
, attributes
, semi
, pop_scope_p
)
1933 if (t
== error_mark_node
)
1934 return error_mark_node
;
1936 /* finish_struct nukes this anyway; if finish_exception does too,
1939 note_got_semicolon (t
);
1941 /* If we got any attributes in class_head, xref_tag will stick them in
1942 TREE_TYPE of the type. Grab them now. */
1943 attributes
= chainon (TYPE_ATTRIBUTES (t
), attributes
);
1944 TYPE_ATTRIBUTES (t
) = NULL_TREE
;
1946 if (TREE_CODE (t
) == ENUMERAL_TYPE
)
1950 t
= finish_struct (t
, attributes
);
1952 note_got_semicolon (t
);
1956 pop_scope (CP_DECL_CONTEXT (TYPE_MAIN_DECL (t
)));
1961 /* Finish processing the declaration of a member class template
1962 TYPES whose template parameters are given by PARMS. */
1965 finish_member_class_template (types
)
1970 /* If there are declared, but undefined, partial specializations
1971 mixed in with the typespecs they will not yet have passed through
1972 maybe_process_partial_specialization, so we do that here. */
1973 for (t
= types
; t
!= NULL_TREE
; t
= TREE_CHAIN (t
))
1974 if (IS_AGGR_TYPE_CODE (TREE_CODE (TREE_VALUE (t
))))
1975 maybe_process_partial_specialization (TREE_VALUE (t
));
1977 note_list_got_semicolon (types
);
1978 grok_x_components (types
);
1979 if (TYPE_CONTEXT (TREE_VALUE (types
)) != current_class_type
)
1980 /* The component was in fact a friend declaration. We avoid
1981 finish_member_template_decl performing certain checks by
1985 finish_member_template_decl (types
);
1987 /* As with other component type declarations, we do
1988 not store the new DECL on the list of
1993 /* Finish processing a complete template declaration. The PARMS are
1994 the template parameters. */
1997 finish_template_decl (parms
)
2001 end_template_decl ();
2003 end_specialization ();
2006 /* Finish processing a template-id (which names a type) of the form
2007 NAME < ARGS >. Return the TYPE_DECL for the type named by the
2008 template-id. If ENTERING_SCOPE is nonzero we are about to enter
2009 the scope of template-id indicated. */
2012 finish_template_type (name
, args
, entering_scope
)
2019 decl
= lookup_template_class (name
, args
,
2020 NULL_TREE
, NULL_TREE
,
2021 entering_scope
, /*complain=*/1);
2022 if (decl
!= error_mark_node
)
2023 decl
= TYPE_STUB_DECL (decl
);
2028 /* Finish processing a BASE_CLASS with the indicated ACCESS_SPECIFIER.
2029 Return a TREE_LIST containing the ACCESS_SPECIFIER and the
2030 BASE_CLASS, or NULL_TREE if an error occurred. The
2031 ACCESS_SPECIFIER is one of
2032 access_{default,public,protected_private}[_virtual]_node.*/
2035 finish_base_specifier (tree base
, tree access
, bool virtual_p
)
2039 if (base
== error_mark_node
)
2041 error ("invalid base-class specification");
2044 else if (! is_aggr_type (base
, 1))
2048 if (cp_type_quals (base
) != 0)
2050 error ("base class `%T' has cv qualifiers", base
);
2051 base
= TYPE_MAIN_VARIANT (base
);
2053 result
= build_tree_list (access
, base
);
2054 TREE_VIA_VIRTUAL (result
) = virtual_p
;
2060 /* Called when multiple declarators are processed. If that is not
2061 premitted in this context, an error is issued. */
2064 check_multiple_declarators ()
2068 In a template-declaration, explicit specialization, or explicit
2069 instantiation the init-declarator-list in the declaration shall
2070 contain at most one declarator.
2072 We don't just use PROCESSING_TEMPLATE_DECL for the first
2073 condition since that would disallow the perfectly valid code,
2074 like `template <class T> struct S { int i, j; };'. */
2075 if (at_function_scope_p ())
2076 /* It's OK to write `template <class T> void f() { int i, j;}'. */
2079 if (PROCESSING_REAL_TEMPLATE_DECL_P ()
2080 || processing_explicit_instantiation
2081 || processing_specialization
)
2082 error ("multiple declarators in template declaration");
2085 /* Implement the __typeof keyword: Return the type of EXPR, suitable for
2086 use as a type-specifier. */
2089 finish_typeof (expr
)
2094 if (processing_template_decl
)
2096 type
= make_aggr_type (TYPEOF_TYPE
);
2097 TYPE_FIELDS (type
) = expr
;
2102 if (TREE_CODE (expr
) == OFFSET_REF
)
2103 expr
= resolve_offset_ref (expr
);
2105 type
= TREE_TYPE (expr
);
2107 if (!type
|| type
== unknown_type_node
)
2109 error ("type of `%E' is unknown", expr
);
2110 return error_mark_node
;
2116 /* Compute the value of the `sizeof' operator. */
2122 return TYPE_P (t
) ? cxx_sizeof (t
) : expr_sizeof (t
);
2125 /* Implement the __alignof keyword: Return the minimum required
2126 alignment of T, measured in bytes. */
2132 if (processing_template_decl
)
2133 return build_min (ALIGNOF_EXPR
, size_type_node
, t
);
2135 return TYPE_P (t
) ? cxx_alignof (t
) : c_alignof_expr (t
);
2138 /* Generate RTL for the statement T, and its substatements, and any
2139 other statements at its nesting level. */
2145 switch (TREE_CODE (t
))
2148 genrtl_try_block (t
);
2152 genrtl_eh_spec_block (t
);
2168 /* Called from expand_body via walk_tree. Replace all AGGR_INIT_EXPRs
2169 will equivalent CALL_EXPRs. */
2172 simplify_aggr_init_exprs_r (tp
, walk_subtrees
, data
)
2174 int *walk_subtrees ATTRIBUTE_UNUSED
;
2175 void *data ATTRIBUTE_UNUSED
;
2177 tree aggr_init_expr
;
2183 enum style_t
{ ctor
, arg
, pcc
} style
;
2185 aggr_init_expr
= *tp
;
2186 /* We don't need to walk into types; there's nothing in a type that
2187 needs simplification. (And, furthermore, there are places we
2188 actively don't want to go. For example, we don't want to wander
2189 into the default arguments for a FUNCTION_DECL that appears in a
2191 if (TYPE_P (aggr_init_expr
))
2196 /* Only AGGR_INIT_EXPRs are interesting. */
2197 else if (TREE_CODE (aggr_init_expr
) != AGGR_INIT_EXPR
)
2200 /* Form an appropriate CALL_EXPR. */
2201 fn
= TREE_OPERAND (aggr_init_expr
, 0);
2202 args
= TREE_OPERAND (aggr_init_expr
, 1);
2203 slot
= TREE_OPERAND (aggr_init_expr
, 2);
2204 type
= TREE_TYPE (aggr_init_expr
);
2206 if (AGGR_INIT_VIA_CTOR_P (aggr_init_expr
))
2208 #ifdef PCC_STATIC_STRUCT_RETURN
2212 else if (TREE_ADDRESSABLE (type
))
2215 /* We shouldn't build an AGGR_INIT_EXPR if we don't need any special
2216 handling. See build_cplus_new. */
2219 if (style
== ctor
|| style
== arg
)
2221 /* Pass the address of the slot. If this is a constructor, we
2222 replace the first argument; otherwise, we tack on a new one. */
2224 args
= TREE_CHAIN (args
);
2226 cxx_mark_addressable (slot
);
2227 args
= tree_cons (NULL_TREE
,
2229 build_pointer_type (TREE_TYPE (slot
)),
2234 call_expr
= build (CALL_EXPR
,
2235 TREE_TYPE (TREE_TYPE (TREE_TYPE (fn
))),
2236 fn
, args
, NULL_TREE
);
2237 TREE_SIDE_EFFECTS (call_expr
) = 1;
2240 /* Tell the backend that we've added our return slot to the argument
2242 CALL_EXPR_HAS_RETURN_SLOT_ADDR (call_expr
) = 1;
2243 else if (style
== pcc
)
2245 /* If we're using the non-reentrant PCC calling convention, then we
2246 need to copy the returned value out of the static buffer into the
2248 int old_ac
= flag_access_control
;
2250 flag_access_control
= 0;
2251 call_expr
= build_aggr_init (slot
, call_expr
,
2252 DIRECT_BIND
| LOOKUP_ONLYCONVERTING
);
2253 flag_access_control
= old_ac
;
2256 /* We want to use the value of the initialized location as the
2258 call_expr
= build (COMPOUND_EXPR
, type
,
2261 /* Replace the AGGR_INIT_EXPR with the CALL_EXPR. */
2262 TREE_CHAIN (call_expr
) = TREE_CHAIN (aggr_init_expr
);
2265 /* Keep iterating. */
2269 /* Emit all thunks to FN that should be emitted when FN is emitted. */
2272 emit_associated_thunks (fn
)
2275 /* When we use vcall offsets, we emit thunks with the virtual
2276 functions to which they thunk. The whole point of vcall offsets
2277 is so that you can know statically the entire set of thunks that
2278 will ever be needed for a given virtual function, thereby
2279 enabling you to output all the thunks with the function itself. */
2280 if (DECL_VIRTUAL_P (fn
))
2284 for (thunk
= DECL_THUNKS (fn
); thunk
; thunk
= TREE_CHAIN (thunk
))
2286 use_thunk (thunk
, /*emit_p=*/1);
2287 if (DECL_RESULT_THUNK_P (thunk
))
2291 for (probe
= DECL_THUNKS (thunk
);
2292 probe
; probe
= TREE_CHAIN (probe
))
2293 use_thunk (probe
, /*emit_p=*/1);
2299 /* Generate RTL for FN. */
2305 location_t saved_loc
;
2306 tree saved_function
;
2308 /* When the parser calls us after finishing the body of a template
2309 function, we don't really want to expand the body. When we're
2310 processing an in-class definition of an inline function,
2311 PROCESSING_TEMPLATE_DECL will no longer be set here, so we have
2312 to look at the function itself. */
2313 if (processing_template_decl
2314 || (DECL_LANG_SPECIFIC (fn
)
2315 && DECL_TEMPLATE_INFO (fn
)
2316 && uses_template_parms (DECL_TI_ARGS (fn
))))
2318 /* Normally, collection only occurs in rest_of_compilation. So,
2319 if we don't collect here, we never collect junk generated
2320 during the processing of templates until we hit a
2321 non-template function. */
2326 /* Replace AGGR_INIT_EXPRs with appropriate CALL_EXPRs. */
2327 walk_tree_without_duplicates (&DECL_SAVED_TREE (fn
),
2328 simplify_aggr_init_exprs_r
,
2331 /* If this is a constructor or destructor body, we have to clone
2333 if (maybe_clone_body (fn
))
2335 /* We don't want to process FN again, so pretend we've written
2336 it out, even though we haven't. */
2337 TREE_ASM_WRITTEN (fn
) = 1;
2341 /* There's no reason to do any of the work here if we're only doing
2342 semantic analysis; this code just generates RTL. */
2343 if (flag_syntax_only
)
2346 /* If possible, avoid generating RTL for this function. Instead,
2347 just record it as an inline function, and wait until end-of-file
2348 to decide whether to write it out or not. */
2349 if (/* We have to generate RTL if it's not an inline function. */
2350 (DECL_INLINE (fn
) || DECL_COMDAT (fn
))
2351 /* Or if we have to emit code for inline functions anyhow. */
2352 && !flag_keep_inline_functions
2353 /* Or if we actually have a reference to the function. */
2354 && !DECL_NEEDED_P (fn
))
2356 /* Set DECL_EXTERNAL so that assemble_external will be called as
2357 necessary. We'll clear it again in finish_file. */
2358 if (!DECL_EXTERNAL (fn
))
2360 DECL_NOT_REALLY_EXTERN (fn
) = 1;
2361 DECL_EXTERNAL (fn
) = 1;
2363 /* Remember this function. In finish_file we'll decide if
2364 we actually need to write this function out. */
2366 /* Let the back-end know that this function exists. */
2367 (*debug_hooks
->deferred_inline_function
) (fn
);
2371 /* Compute the appropriate object-file linkage for inline
2373 if (DECL_DECLARED_INLINE_P (fn
))
2374 import_export_decl (fn
);
2376 /* If FN is external, then there's no point in generating RTL for
2377 it. This situation can arise with an inline function under
2378 `-fexternal-templates'; we instantiate the function, even though
2379 we're not planning on emitting it, in case we get a chance to
2381 if (DECL_EXTERNAL (fn
))
2384 /* Save the current file name and line number. When we expand the
2385 body of the function, we'll set INPUT_LOCATION so that
2386 error-mesages come out in the right places. */
2387 saved_loc
= input_location
;
2388 saved_function
= current_function_decl
;
2389 input_location
= DECL_SOURCE_LOCATION (fn
);
2390 current_function_decl
= fn
;
2392 timevar_push (TV_INTEGRATION
);
2394 /* Optimize the body of the function before expanding it. */
2395 optimize_function (fn
);
2397 timevar_pop (TV_INTEGRATION
);
2398 timevar_push (TV_EXPAND
);
2400 genrtl_start_function (fn
);
2401 current_function_is_thunk
= DECL_THUNK_P (fn
);
2403 /* Expand the body. */
2404 expand_stmt (DECL_SAVED_TREE (fn
));
2406 /* Statements should always be full-expressions at the outermost set
2407 of curly braces for a function. */
2408 my_friendly_assert (stmts_are_full_exprs_p (), 19990831);
2410 /* The outermost statement for a function contains the line number
2411 recorded when we finished processing the function. */
2412 input_line
= STMT_LINENO (DECL_SAVED_TREE (fn
));
2414 /* Generate code for the function. */
2415 genrtl_finish_function (fn
);
2417 /* If possible, obliterate the body of the function so that it can
2418 be garbage collected. */
2419 if (dump_enabled_p (TDI_all
))
2420 /* Keep the body; we're going to dump it. */
2422 else if (DECL_INLINE (fn
) && flag_inline_trees
)
2423 /* We might need the body of this function so that we can expand
2424 it inline somewhere else. */
2427 /* We don't need the body; blow it away. */
2428 DECL_SAVED_TREE (fn
) = NULL_TREE
;
2430 /* And restore the current source position. */
2431 current_function_decl
= saved_function
;
2432 input_location
= saved_loc
;
2433 extract_interface_info ();
2435 timevar_pop (TV_EXPAND
);
2437 /* Emit any thunks that should be emitted at the same time as FN. */
2438 emit_associated_thunks (fn
);
2441 /* Helper function for walk_tree, used by finish_function to override all
2442 the RETURN_STMTs and pertinent CLEANUP_STMTs for the named return
2443 value optimization. */
2446 nullify_returns_r (tp
, walk_subtrees
, data
)
2451 tree nrv
= (tree
) data
;
2453 /* No need to walk into types. There wouldn't be any need to walk into
2454 non-statements, except that we have to consider STMT_EXPRs. */
2457 else if (TREE_CODE (*tp
) == RETURN_STMT
)
2458 RETURN_STMT_EXPR (*tp
) = NULL_TREE
;
2459 else if (TREE_CODE (*tp
) == CLEANUP_STMT
2460 && CLEANUP_DECL (*tp
) == nrv
)
2461 CLEANUP_EH_ONLY (*tp
) = 1;
2463 /* Keep iterating. */
2467 /* Start generating the RTL for FN. */
2470 genrtl_start_function (fn
)
2473 /* Tell everybody what function we're processing. */
2474 current_function_decl
= fn
;
2475 /* Get the RTL machinery going for this function. */
2476 init_function_start (fn
, DECL_SOURCE_FILE (fn
), DECL_SOURCE_LINE (fn
));
2477 /* Let everybody know that we're expanding this function, not doing
2478 semantic analysis. */
2481 /* Even though we're inside a function body, we still don't want to
2482 call expand_expr to calculate the size of a variable-sized array.
2483 We haven't necessarily assigned RTL to all variables yet, so it's
2484 not safe to try to expand expressions involving them. */
2485 immediate_size_expand
= 0;
2486 cfun
->x_dont_save_pending_sizes_p
= 1;
2488 /* Let the user know we're compiling this function. */
2489 announce_function (fn
);
2491 /* Initialize the per-function data. */
2492 my_friendly_assert (!DECL_PENDING_INLINE_P (fn
), 20000911);
2493 if (DECL_SAVED_FUNCTION_DATA (fn
))
2495 /* If we already parsed this function, and we're just expanding it
2496 now, restore saved state. */
2497 *cp_function_chain
= *DECL_SAVED_FUNCTION_DATA (fn
);
2499 /* This function is being processed in whole-function mode; we
2500 already did semantic analysis. */
2501 cfun
->x_whole_function_mode_p
= 1;
2503 /* If we decided that we didn't want to inline this function,
2504 make sure the back-end knows that. */
2505 if (!current_function_cannot_inline
)
2506 current_function_cannot_inline
= cp_function_chain
->cannot_inline
;
2508 /* We don't need the saved data anymore. Unless this is an inline
2509 function; we need the named return value info for
2510 cp_copy_res_decl_for_inlining. */
2511 if (! DECL_INLINE (fn
))
2512 DECL_SAVED_FUNCTION_DATA (fn
) = NULL
;
2515 /* Keep track of how many functions we're presently expanding. */
2518 /* Create a binding level for the parameters. */
2519 expand_function_start (fn
, /*parms_have_cleanups=*/0);
2520 /* If this function is `main'. */
2521 if (DECL_MAIN_P (fn
))
2522 expand_main_function ();
2524 /* Give our named return value the same RTL as our RESULT_DECL. */
2525 if (current_function_return_value
)
2526 COPY_DECL_RTL (DECL_RESULT (fn
), current_function_return_value
);
2529 /* Finish generating the RTL for FN. */
2532 genrtl_finish_function (fn
)
2538 if (write_symbols
!= NO_DEBUG
)
2540 /* Keep this code around in case we later want to control debug info
2541 based on whether a type is "used". (jason 1999-11-11) */
2543 tree ttype
= target_type (fntype
);
2546 if (IS_AGGR_TYPE (ttype
))
2547 /* Let debugger know it should output info for this type. */
2548 note_debug_info_needed (ttype
);
2550 for (parmdecl
= DECL_ARGUMENTS (fndecl
); parmdecl
; parmdecl
= TREE_CHAIN (parmdecl
))
2552 ttype
= target_type (TREE_TYPE (parmdecl
));
2553 if (IS_AGGR_TYPE (ttype
))
2554 /* Let debugger know it should output info for this type. */
2555 note_debug_info_needed (ttype
);
2560 /* Clean house because we will need to reorder insns here. */
2561 do_pending_stack_adjust ();
2563 /* If we have a named return value, we need to force a return so that
2564 the return register is USEd. */
2565 if (DECL_NAME (DECL_RESULT (fn
)))
2566 emit_jump (return_label
);
2568 /* We hard-wired immediate_size_expand to zero in start_function.
2569 Expand_function_end will decrement this variable. So, we set the
2570 variable to one here, so that after the decrement it will remain
2572 immediate_size_expand
= 1;
2574 /* Generate rtl for function exit. */
2575 expand_function_end (input_filename
, input_line
, 0);
2577 /* If this is a nested function (like a template instantiation that
2578 we're compiling in the midst of compiling something else), push a
2579 new GC context. That will keep local variables on the stack from
2580 being collected while we're doing the compilation of this
2582 if (function_depth
> 1)
2583 ggc_push_context ();
2585 /* There's no need to defer outputting this function any more; we
2586 know we want to output it. */
2587 DECL_DEFER_OUTPUT (fn
) = 0;
2589 /* Run the optimizers and output the assembler code for this
2591 rest_of_compilation (fn
);
2593 /* Undo the call to ggc_push_context above. */
2594 if (function_depth
> 1)
2598 /* Keep this code around in case we later want to control debug info
2599 based on whether a type is "used". (jason 1999-11-11) */
2601 if (ctype
&& TREE_ASM_WRITTEN (fn
))
2602 note_debug_info_needed (ctype
);
2605 /* If this function is marked with the constructor attribute, add it
2606 to the list of functions to be called along with constructors
2607 from static duration objects. */
2608 if (DECL_STATIC_CONSTRUCTOR (fn
))
2609 static_ctors
= tree_cons (NULL_TREE
, fn
, static_ctors
);
2611 /* If this function is marked with the destructor attribute, add it
2612 to the list of functions to be called along with destructors from
2613 static duration objects. */
2614 if (DECL_STATIC_DESTRUCTOR (fn
))
2615 static_dtors
= tree_cons (NULL_TREE
, fn
, static_dtors
);
2619 /* In C++, we should never be saving RTL for the function. */
2620 my_friendly_assert (!DECL_SAVED_INSNS (fn
), 20010903);
2622 /* Since we don't need the RTL for this function anymore, stop
2623 pointing to it. That's especially important for LABEL_DECLs,
2624 since you can reach all the instructions in the function from the
2625 CODE_LABEL stored in the DECL_RTL for the LABEL_DECL. Walk the
2626 BLOCK-tree, clearing DECL_RTL for LABEL_DECLs and non-static
2628 walk_tree_without_duplicates (&DECL_SAVED_TREE (fn
),
2632 /* Clear out the RTL for the arguments. */
2633 for (t
= DECL_ARGUMENTS (fn
); t
; t
= TREE_CHAIN (t
))
2635 SET_DECL_RTL (t
, NULL_RTX
);
2636 DECL_INCOMING_RTL (t
) = NULL_RTX
;
2639 if (!(flag_inline_trees
&& DECL_INLINE (fn
)))
2640 /* DECL_INITIAL must remain nonzero so we know this was an
2641 actual function definition. */
2642 DECL_INITIAL (fn
) = error_mark_node
;
2644 /* Let the error reporting routines know that we're outside a
2645 function. For a nested function, this value is used in
2646 pop_cp_function_context and then reset via pop_function_context. */
2647 current_function_decl
= NULL_TREE
;
2650 /* Clear out the DECL_RTL for the non-static variables in BLOCK and
2654 clear_decl_rtl (tp
, walk_subtrees
, data
)
2656 int *walk_subtrees ATTRIBUTE_UNUSED
;
2657 void *data ATTRIBUTE_UNUSED
;
2659 if (nonstatic_local_decl_p (*tp
))
2660 SET_DECL_RTL (*tp
, NULL_RTX
);
2665 /* Perform initialization related to this module. */
2668 init_cp_semantics ()
2670 lang_expand_stmt
= cp_expand_stmt
;
2673 #include "gt-cp-semantics.h"