Daily bump.
[official-gcc.git] / gcc / ada / exp_ch6.ads
blob196f7e6d9414c711d258153c479b9fa8ec78ee5e
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-2021, 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_Return_When_Statement (N : Node_Id);
36 procedure Expand_N_Simple_Return_Statement (N : Node_Id);
37 procedure Expand_N_Subprogram_Body (N : Node_Id);
38 procedure Expand_N_Subprogram_Body_Stub (N : Node_Id);
39 procedure Expand_N_Subprogram_Declaration (N : Node_Id);
41 procedure Expand_Call (N : Node_Id);
42 -- This procedure contains common processing for Expand_N_Function_Call,
43 -- Expand_N_Procedure_Statement, and Expand_N_Entry_Call.
45 procedure Freeze_Subprogram (N : Node_Id);
46 -- generate the appropriate expansions related to Subprogram freeze
47 -- nodes (e.g. the filling of the corresponding Dispatch Table for
48 -- Primitive Operations)
50 -- The following type defines the various forms of allocation used for the
51 -- results of build-in-place function calls.
53 type BIP_Allocation_Form is
54 (Unspecified,
55 Caller_Allocation,
56 Secondary_Stack,
57 Global_Heap,
58 User_Storage_Pool);
60 type BIP_Formal_Kind is
61 -- Ada 2005 (AI-318-02): This type defines the kinds of implicit extra
62 -- formals created for build-in-place functions. The order of these
63 -- enumeration literals matches the order in which the formals are
64 -- declared. See Sem_Ch6.Create_Extra_Formals.
66 (BIP_Alloc_Form,
67 -- Present if result subtype is unconstrained or tagged. Indicates
68 -- whether the return object is allocated by the caller or callee, and
69 -- if the callee, whether to use the secondary stack or the heap. See
70 -- Create_Extra_Formals.
72 BIP_Storage_Pool,
73 -- Present if result subtype is unconstrained or tagged. If
74 -- BIP_Alloc_Form = User_Storage_Pool, this is a pointer to the pool
75 -- (of type access to Root_Storage_Pool'Class). Otherwise null.
77 BIP_Finalization_Master,
78 -- Present if result type needs finalization. Pointer to caller's
79 -- finalization master.
81 BIP_Task_Master,
82 -- Present if result type contains tasks. Master associated with
83 -- calling context.
85 BIP_Activation_Chain,
86 -- Present if result type contains tasks. Caller's activation chain
88 BIP_Object_Access);
89 -- Present for all build-in-place functions. Address at which to place
90 -- the return object, or null if BIP_Alloc_Form indicates allocated by
91 -- callee.
93 -- ??? We might also need to be able to pass in a constrained flag.
95 procedure Add_Extra_Actual_To_Call
96 (Subprogram_Call : Node_Id;
97 Extra_Formal : Entity_Id;
98 Extra_Actual : Node_Id);
99 -- Adds Extra_Actual as a named parameter association for the formal
100 -- Extra_Formal in Subprogram_Call.
102 function BIP_Formal_Suffix (Kind : BIP_Formal_Kind) return String;
103 -- Ada 2005 (AI-318-02): Returns a string to be used as the suffix of names
104 -- for build-in-place formal parameters of the given kind.
106 function BIP_Suffix_Kind (E : Entity_Id) return BIP_Formal_Kind;
107 -- Ada 2005 (AI-318-02): Returns the kind of the given BIP extra formal.
109 function Build_In_Place_Formal
110 (Func : Entity_Id;
111 Kind : BIP_Formal_Kind) return Entity_Id;
112 -- Ada 2005 (AI-318-02): Locates and returns the entity for the implicit
113 -- build-in-place formal parameter of the given kind associated with the
114 -- function Func, and returns its Entity_Id. It is a bug if not found; the
115 -- caller should ensure this is called only when the extra formal exists.
117 function Build_Procedure_Body_Form
118 (Func_Id : Entity_Id; Func_Body : Node_Id) return Node_Id;
119 -- Create a procedure body which emulates the behavior of function Func_Id.
120 -- Func_Body is the root of the body of the function before its analysis.
121 -- The returned node is the root of the procedure body which will replace
122 -- the original function body, which is not needed for the C program.
124 procedure Install_Class_Preconditions_Check (Call_Node : Node_Id);
125 -- Install check of class-wide preconditions on the caller.
127 function Is_Build_In_Place_Entity (E : Entity_Id) return Boolean;
128 -- Ada 2005 (AI-318-02): Returns True if E is a BIP entity.
130 function Is_Build_In_Place_Result_Type (Typ : Entity_Id) return Boolean;
131 -- Ada 2005 (AI-318-02): Returns True if functions returning the type use
132 -- build-in-place protocols. For inherently limited types, this must be
133 -- True in >= Ada 2005, and must be False in Ada 95. For other types, it
134 -- can be True or False, and the decision should be based on efficiency,
135 -- and should be the same for all language versions, so that mixed-dialect
136 -- programs will work.
138 -- For inherently limited types in Ada 2005, True means that calls will
139 -- actually be build-in-place in all cases. For other types, build-in-place
140 -- will be used when possible, but we need to make a copy in some
141 -- cases. For example, for "X := F(...);" if F can see X, or if F can
142 -- propagate exceptions, we need to store its result in a temp in general,
143 -- and copy the temp into X. Also, for "return Global_Var;" Global_Var
144 -- needs to be copied into the function result object.
146 function Is_Build_In_Place_Function (E : Entity_Id) return Boolean;
147 -- Ada 2005 (AI-318-02): Returns True if E denotes a function, generic
148 -- function, or access-to-function type for which
149 -- Is_Build_In_Place_Result_Type is True. However, we never use
150 -- build-in-place if the convention is other than Ada, because that would
151 -- disturb mixed-language programs.
153 function Is_Build_In_Place_Function_Call (N : Node_Id) return Boolean;
154 -- Ada 2005 (AI-318-02): Returns True if N denotes a call to a function
155 -- that requires handling as a build-in-place call (possibly qualified or
156 -- converted).
158 function Is_Null_Procedure (Subp : Entity_Id) return Boolean;
159 -- Predicate to recognize stubbed procedures and null procedures, which
160 -- can be inlined unconditionally in all cases.
162 procedure Make_Build_In_Place_Call_In_Allocator
163 (Allocator : Node_Id;
164 Function_Call : Node_Id);
165 -- Ada 2005 (AI-318-02): Handle a call to a build-in-place function that
166 -- occurs as the expression initializing an allocator, by passing access
167 -- to the allocated object as an additional parameter of the function call.
168 -- A new access object is declared that is initialized to the result of the
169 -- allocator, passed to the function, and the allocator is rewritten to
170 -- refer to that access object. Function_Call must denote either an
171 -- N_Function_Call node for which Is_Build_In_Place_Call is True, or else
172 -- an N_Qualified_Expression node applied to such a function call.
174 procedure Make_Build_In_Place_Call_In_Anonymous_Context
175 (Function_Call : Node_Id);
176 -- Ada 2005 (AI-318-02): Handle a call to a build-in-place function that
177 -- occurs in a context that does not provide a separate object. A temporary
178 -- object is created to act as the return object and an access to the
179 -- temporary is passed as an additional parameter of the call. This occurs
180 -- in contexts such as subprogram call actuals and object renamings.
181 -- Function_Call must denote either an N_Function_Call node for which
182 -- Is_Build_In_Place_Call is True, or else an N_Qualified_Expression node
183 -- applied to such a function call.
185 procedure Make_Build_In_Place_Call_In_Assignment
186 (Assign : Node_Id;
187 Function_Call : Node_Id);
188 -- Ada 2005 (AI-318-02): Handle a call to a build-in-place function that
189 -- occurs as the right-hand side of an assignment statement by passing
190 -- access to the left-hand side as an additional parameter of the function
191 -- call. Assign must denote a N_Assignment_Statement. Function_Call must
192 -- denote either an N_Function_Call node for which Is_Build_In_Place_Call
193 -- is True, or an N_Qualified_Expression node applied to such a function
194 -- call.
196 procedure Make_Build_In_Place_Call_In_Object_Declaration
197 (Obj_Decl : Node_Id;
198 Function_Call : Node_Id);
199 -- Ada 2005 (AI-318-02): Handle a call to a build-in-place function that
200 -- occurs as the expression initializing an object declaration by
201 -- passing access to the declared object as an additional parameter of the
202 -- function call. Function_Call must denote either an N_Function_Call node
203 -- for which Is_Build_In_Place_Call is True, or an N_Qualified_Expression
204 -- node applied to such a function call.
206 procedure Make_Build_In_Place_Iface_Call_In_Allocator
207 (Allocator : Node_Id;
208 Function_Call : Node_Id);
209 -- Ada 2005 (AI-318-02): Handle a call to a build-in-place function that
210 -- occurs as the expression initializing an allocator, by passing access
211 -- to the allocated object as an additional parameter of the function call.
212 -- Function_Call must denote an expression containing a BIP function call
213 -- and an enclosing call to Ada.Tags.Displace to displace the pointer to
214 -- the returned BIP object to reference the secondary dispatch table of
215 -- an interface.
217 procedure Make_Build_In_Place_Iface_Call_In_Anonymous_Context
218 (Function_Call : Node_Id);
219 -- Ada 2005 (AI-318-02): Handle a call to a build-in-place function that
220 -- occurs in a context that does not provide a separate object. A temporary
221 -- object is created to act as the return object and an access to the
222 -- temporary is passed as an additional parameter of the call. This occurs
223 -- in contexts such as subprogram call actuals and object renamings.
224 -- Function_Call must denote an expression containing a BIP function call
225 -- and an enclosing call to Ada.Tags.Displace to displace the pointer to
226 -- the returned BIP object to reference the secondary dispatch table of
227 -- an interface.
229 procedure Make_Build_In_Place_Iface_Call_In_Object_Declaration
230 (Obj_Decl : Node_Id;
231 Function_Call : Node_Id);
232 -- Ada 2005 (AI-318-02): Handle a call to a build-in-place function that
233 -- occurs as the expression initializing an object declaration by passing
234 -- access to the declared object as an additional parameter of the function
235 -- call. Function_Call must denote an expression containing a BIP function
236 -- call and an enclosing call to Ada.Tags.Displace to displace the pointer
237 -- to the returned BIP object to reference the secondary dispatch table of
238 -- an interface.
240 procedure Make_CPP_Constructor_Call_In_Allocator
241 (Allocator : Node_Id;
242 Function_Call : Node_Id);
243 -- Handle a call to a CPP constructor that occurs as the expression that
244 -- initializes an allocator, by passing access to the allocated object as
245 -- an additional parameter of the constructor call. A new access object is
246 -- declared that is initialized to the result of the allocator, passed to
247 -- the constructor, and the allocator is rewritten to refer to that access
248 -- object. Function_Call must denote a call to a CPP_Constructor function.
250 function Might_Have_Tasks (Typ : Entity_Id) return Boolean;
251 -- Return True when type Typ has tasks or when it is a limited class-wide
252 -- type (or subtype), since it might have task components.
254 function Needs_BIP_Alloc_Form (Func_Id : Entity_Id) return Boolean;
255 -- Ada 2005 (AI-318-02): Return True if the function needs an implicit
256 -- BIP_Alloc_Form parameter (see type BIP_Formal_Kind).
258 function Needs_BIP_Finalization_Master (Func_Id : Entity_Id) return Boolean;
259 -- Ada 2005 (AI-318-02): Return True if the result subtype of function
260 -- Func_Id might need finalization actions. This includes build-in-place
261 -- functions with tagged result types, since they can be invoked via
262 -- dispatching calls, and descendant types may require finalization.
264 function Needs_BIP_Task_Actuals (Func_Id : Entity_Id) return Boolean;
265 -- Return True if the function returns an object of a type that has tasks.
267 function Unqual_BIP_Iface_Function_Call (Expr : Node_Id) return Node_Id;
268 -- Return the inner BIP function call removing any qualification from Expr
269 -- including qualified expressions, type conversions, references, unchecked
270 -- conversions and calls to displace the pointer to the object, if Expr is
271 -- an expression containing a call displacing the pointer to the BIP object
272 -- to reference the secondary dispatch table of an interface; otherwise
273 -- return Empty.
275 end Exp_Ch6;