PR target/60039
[official-gcc.git] / gcc / ada / exp_ch6.ads
blob8cdd6fa7d37cd6a4f47f5e34c41f3844c648135e
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- E X P _ C H 6 --
6 -- --
7 -- S p e c --
8 -- --
9 -- Copyright (C) 1992-2013, Free Software Foundation, Inc. --
10 -- --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
20 -- --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
23 -- --
24 ------------------------------------------------------------------------------
26 -- Expand routines for chapter 6 constructs
28 with Types; use Types;
30 package Exp_Ch6 is
32 procedure Expand_N_Extended_Return_Statement (N : Node_Id);
33 procedure Expand_N_Function_Call (N : Node_Id);
34 procedure Expand_N_Procedure_Call_Statement (N : Node_Id);
35 procedure Expand_N_Simple_Return_Statement (N : Node_Id);
36 procedure Expand_N_Subprogram_Body (N : Node_Id);
37 procedure Expand_N_Subprogram_Body_Stub (N : Node_Id);
38 procedure Expand_N_Subprogram_Declaration (N : Node_Id);
40 procedure Expand_Actuals (N : Node_Id; Subp : Entity_Id);
41 -- For each actual of an in-out or out parameter which is a numeric
42 -- (view) conversion of the form T (A), where A denotes a variable,
43 -- we insert the declaration:
45 -- Temp : T[ := T (A)];
47 -- prior to the call. Then we replace the actual with a reference to Temp,
48 -- and append the assignment:
50 -- A := TypeA (Temp);
52 -- after the call. Here TypeA is the actual type of variable A. For out
53 -- parameters, the initial declaration has no expression. If A is not an
54 -- entity name, we generate instead:
56 -- Var : TypeA renames A;
57 -- Temp : T := Var; -- omitting expression for out parameter.
58 -- ...
59 -- Var := TypeA (Temp);
61 -- For other in-out parameters, we emit the required constraint checks
62 -- before and/or after the call.
64 -- For all parameter modes, actuals that denote components and slices of
65 -- packed arrays are expanded into suitable temporaries.
67 -- For non-scalar objects that are possibly unaligned, add call by copy
68 -- code (copy in for IN and IN OUT, copy out for OUT and IN OUT).
70 procedure Expand_Call (N : Node_Id);
71 -- This procedure contains common processing for Expand_N_Function_Call,
72 -- Expand_N_Procedure_Statement, and Expand_N_Entry_Call.
74 procedure Expand_Subprogram_Contract
75 (N : Node_Id;
76 Spec_Id : Entity_Id;
77 Body_Id : Entity_Id);
78 -- Expand the contracts of a subprogram body and its correspoding spec (if
79 -- any). This routine processes all [refined] pre- and postconditions as
80 -- well as Contract_Cases, invariants and predicates. N is the body of the
81 -- subprogram. Spec_Id denotes the entity of its specification. Body_Id
82 -- denotes the entity of the subprogram body. This routine is not a "pure"
83 -- expansion mechanism as it is invoked during analysis and may perform
84 -- actions for generic subprograms or set up contract assertions for ASIS.
86 procedure Freeze_Subprogram (N : Node_Id);
87 -- generate the appropriate expansions related to Subprogram freeze
88 -- nodes (e.g. the filling of the corresponding Dispatch Table for
89 -- Primitive Operations)
91 -- The following type defines the various forms of allocation used for the
92 -- results of build-in-place function calls.
94 type BIP_Allocation_Form is
95 (Unspecified,
96 Caller_Allocation,
97 Secondary_Stack,
98 Global_Heap,
99 User_Storage_Pool);
101 type BIP_Formal_Kind is
102 -- Ada 2005 (AI-318-02): This type defines the kinds of implicit extra
103 -- formals created for build-in-place functions. The order of these
104 -- enumeration literals matches the order in which the formals are
105 -- declared. See Sem_Ch6.Create_Extra_Formals.
107 (BIP_Alloc_Form,
108 -- Present if result subtype is unconstrained or tagged. Indicates
109 -- whether the return object is allocated by the caller or callee, and
110 -- if the callee, whether to use the secondary stack or the heap. See
111 -- Create_Extra_Formals.
113 BIP_Storage_Pool,
114 -- Present if result subtype is unconstrained or tagged. If
115 -- BIP_Alloc_Form = User_Storage_Pool, this is a pointer to the pool
116 -- (of type access to Root_Storage_Pool'Class). Otherwise null.
118 BIP_Finalization_Master,
119 -- Present if result type needs finalization. Pointer to caller's
120 -- finalization master.
122 BIP_Task_Master,
123 -- Present if result type contains tasks. Master associated with
124 -- calling context.
126 BIP_Activation_Chain,
127 -- Present if result type contains tasks. Caller's activation chain
129 BIP_Object_Access);
130 -- Present for all build-in-place functions. Address at which to place
131 -- the return object, or null if BIP_Alloc_Form indicates allocated by
132 -- callee.
134 -- ??? We might also need to be able to pass in a constrained flag.
136 function BIP_Formal_Suffix (Kind : BIP_Formal_Kind) return String;
137 -- Ada 2005 (AI-318-02): Returns a string to be used as the suffix of names
138 -- for build-in-place formal parameters of the given kind.
140 function Build_In_Place_Formal
141 (Func : Entity_Id;
142 Kind : BIP_Formal_Kind) return Entity_Id;
143 -- Ada 2005 (AI-318-02): Locates and returns the entity for the implicit
144 -- build-in-place formal parameter of the given kind associated with the
145 -- function Func, and returns its Entity_Id. It is a bug if not found; the
146 -- caller should ensure this is called only when the extra formal exists.
148 function Is_Build_In_Place_Function (E : Entity_Id) return Boolean;
149 -- Ada 2005 (AI-318-02): Returns True if E denotes a function, generic
150 -- function, or access-to-function type whose result must be built in
151 -- place; otherwise returns False. For Ada 2005, this is currently
152 -- restricted to the set of functions whose result subtype is an inherently
153 -- limited type. In Ada 95, this must be False for inherently limited
154 -- result types (but currently returns False for all Ada 95 functions).
155 -- Eventually we plan to support build-in-place for nonlimited types.
156 -- Build-in-place is usually more efficient for large things, and less
157 -- efficient for small things. However, we never use build-in-place if the
158 -- convention is other than Ada, because that would disturb mixed-language
159 -- programs. Note that for the non-inherently-limited cases, we must make
160 -- the same decision for Ada 95 and 2005, so that mixed-dialect programs
161 -- will work.
163 function Is_Build_In_Place_Function_Call (N : Node_Id) return Boolean;
164 -- Ada 2005 (AI-318-02): Returns True if N denotes a call to a function
165 -- that requires handling as a build-in-place call or is a qualified
166 -- expression applied to such a call; otherwise returns False.
168 function Is_Null_Procedure (Subp : Entity_Id) return Boolean;
169 -- Predicate to recognize stubbed procedures and null procedures, which
170 -- can be inlined unconditionally in all cases.
172 procedure List_Inlining_Info;
173 -- Generate listing of calls inlined by the frontend plus listing of
174 -- calls to inline subprograms passed to the backend.
176 procedure Make_Build_In_Place_Call_In_Allocator
177 (Allocator : Node_Id;
178 Function_Call : Node_Id);
179 -- Ada 2005 (AI-318-02): Handle a call to a build-in-place function that
180 -- occurs as the expression initializing an allocator, by passing access
181 -- to the allocated object as an additional parameter of the function call.
182 -- A new access object is declared that is initialized to the result of the
183 -- allocator, passed to the function, and the allocator is rewritten to
184 -- refer to that access object. Function_Call must denote either an
185 -- N_Function_Call node for which Is_Build_In_Place_Call is True, or else
186 -- an N_Qualified_Expression node applied to such a function call.
188 procedure Make_Build_In_Place_Call_In_Anonymous_Context
189 (Function_Call : Node_Id);
190 -- Ada 2005 (AI-318-02): Handle a call to a build-in-place function that
191 -- occurs in a context that does not provide a separate object. A temporary
192 -- object is created to act as the return object and an access to the
193 -- temporary is passed as an additional parameter of the call. This occurs
194 -- in contexts such as subprogram call actuals and object renamings.
195 -- Function_Call must denote either an N_Function_Call node for which
196 -- Is_Build_In_Place_Call is True, or else an N_Qualified_Expression node
197 -- applied to such a function call.
199 procedure Make_Build_In_Place_Call_In_Assignment
200 (Assign : Node_Id;
201 Function_Call : Node_Id);
202 -- Ada 2005 (AI-318-02): Handle a call to a build-in-place function that
203 -- occurs as the right-hand side of an assignment statement by passing
204 -- access to the left-hand side as an additional parameter of the function
205 -- call. Assign must denote a N_Assignment_Statement. Function_Call must
206 -- denote either an N_Function_Call node for which Is_Build_In_Place_Call
207 -- is True, or an N_Qualified_Expression node applied to such a function
208 -- call.
210 procedure Make_Build_In_Place_Call_In_Object_Declaration
211 (Object_Decl : Node_Id;
212 Function_Call : Node_Id);
213 -- Ada 2005 (AI-318-02): Handle a call to a build-in-place function that
214 -- occurs as the expression initializing an object declaration by
215 -- passing access to the declared object as an additional parameter of the
216 -- function call. Function_Call must denote either an N_Function_Call node
217 -- for which Is_Build_In_Place_Call is True, or an N_Qualified_Expression
218 -- node applied to such a function call.
220 procedure Make_CPP_Constructor_Call_In_Allocator
221 (Allocator : Node_Id;
222 Function_Call : Node_Id);
223 -- Handle a call to a CPP constructor that occurs as the expression that
224 -- initializes an allocator, by passing access to the allocated object as
225 -- an additional parameter of the constructor call. A new access object is
226 -- declared that is initialized to the result of the allocator, passed to
227 -- the constructor, and the allocator is rewritten to refer to that access
228 -- object. Function_Call must denote a call to a CPP_Constructor function.
230 function Needs_BIP_Alloc_Form (Func_Id : Entity_Id) return Boolean;
231 -- Ada 2005 (AI-318-02): Return True if the function needs an implicit
232 -- BIP_Alloc_Form parameter (see type BIP_Formal_Kind).
234 function Needs_BIP_Finalization_Master (Func_Id : Entity_Id) return Boolean;
235 -- Ada 2005 (AI-318-02): Return True if the result subtype of function
236 -- Func_Id needs finalization actions.
238 function Needs_Result_Accessibility_Level
239 (Func_Id : Entity_Id) return Boolean;
240 -- Ada 2012 (AI05-0234): Return True if the function needs an implicit
241 -- parameter to identify the accessibility level of the function result
242 -- "determined by the point of call".
244 procedure Add_Extra_Actual_To_Call
245 (Subprogram_Call : Node_Id;
246 Extra_Formal : Entity_Id;
247 Extra_Actual : Node_Id);
248 -- Adds Extra_Actual as a named parameter association for the formal
249 -- Extra_Formal in Subprogram_Call.
251 end Exp_Ch6;