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