MATCH: Improve `A CMP 0 ? A : -A` set of patterns to use bitwise_equal_p.
[official-gcc.git] / gcc / ada / exp_ch6.ads
blob7b7620733778c3fa33672208c299ddd2d0f11936
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-2023, 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 procedure Apply_CW_Accessibility_Check (Exp : Node_Id; Func : Entity_Id);
103 -- Ada 2005 (AI95-344): If the result type is class-wide, insert a check
104 -- that the level of the return expression's underlying type is not deeper
105 -- than the level of the master enclosing the function. Always generate the
106 -- check when the type of the return expression is class-wide, when it's a
107 -- type conversion, or when it's a formal parameter. Otherwise suppress the
108 -- check in the case where the return expression has a specific type whose
109 -- level is known not to be statically deeper than the result type of the
110 -- function.
112 function BIP_Formal_Suffix (Kind : BIP_Formal_Kind) return String;
113 -- Ada 2005 (AI-318-02): Returns a string to be used as the suffix of names
114 -- for build-in-place formal parameters of the given kind.
116 function BIP_Suffix_Kind (E : Entity_Id) return BIP_Formal_Kind;
117 -- Ada 2005 (AI-318-02): Returns the kind of the given BIP extra formal.
119 function Build_In_Place_Formal
120 (Func : Entity_Id;
121 Kind : BIP_Formal_Kind) return Entity_Id;
122 -- Ada 2005 (AI-318-02): Locates and returns the entity for the implicit
123 -- build-in-place formal parameter of the given kind associated with the
124 -- function Func, and returns its Entity_Id. It is a bug if not found; the
125 -- caller should ensure this is called only when the extra formal exists.
127 function Build_Procedure_Body_Form
128 (Func_Id : Entity_Id; Func_Body : Node_Id) return Node_Id;
129 -- Create a procedure body which emulates the behavior of function Func_Id.
130 -- Func_Body is the root of the body of the function before its analysis.
131 -- The returned node is the root of the procedure body which will replace
132 -- the original function body, which is not needed for the C program.
134 function Has_BIP_Extra_Formal
135 (E : Entity_Id;
136 Kind : BIP_Formal_Kind;
137 Must_Be_Frozen : Boolean := True) return Boolean;
138 -- Given a subprogram, subprogram type, entry or entry family, return True
139 -- if E has the BIP extra formal associated with Kind. In general this
140 -- subprogram must be invoked with a frozen entity or a subprogram type of
141 -- a dispatching call since we can only rely on the availability of extra
142 -- formals on these entities; this requirement can be relaxed using the
143 -- formal Must_Be_Frozen in scenarios where we know that the entity has
144 -- the extra formals.
146 procedure Install_Class_Preconditions_Check (Call_Node : Node_Id);
147 -- Install check of class-wide preconditions on the caller.
149 function Is_Build_In_Place_Entity (E : Entity_Id) return Boolean;
150 -- Ada 2005 (AI-318-02): Returns True if E is a BIP entity.
152 function Is_Build_In_Place_Function (E : Entity_Id) return Boolean;
153 -- Ada 2005 (AI-318-02): Returns True if E denotes a function, generic
154 -- function, or access-to-function type for which
155 -- Is_Build_In_Place_Result_Type is True. However, we never use
156 -- build-in-place if the convention is other than Ada, because that would
157 -- disturb mixed-language programs.
159 function Is_Build_In_Place_Function_Call (N : Node_Id) return Boolean;
160 -- Ada 2005 (AI-318-02): Returns True if N denotes a call to a function
161 -- that requires handling as a build-in-place call (possibly qualified or
162 -- converted); that is, BIP function calls, and calls to functions with
163 -- inherited BIP formals.
165 function Is_Build_In_Place_Result_Type (Typ : Entity_Id) return Boolean;
166 -- Ada 2005 (AI-318-02): Returns True if functions returning the type use
167 -- build-in-place protocols. For inherently limited types, this must be
168 -- True in >= Ada 2005 and must be False in Ada 95.
170 function Is_Build_In_Place_Return_Object (E : Entity_Id) return Boolean;
171 -- Ada 2005 (AI-318-02): Return True if E is a return object of a function
172 -- that uses build-in-place protocols.
174 function Is_By_Reference_Return_Object (E : Entity_Id) return Boolean;
175 -- Return True if E is a return object of a function whose return type is
176 -- required to be passed by reference, as defined in (RM 6.2(4-9)).
178 function Is_Null_Procedure (Subp : Entity_Id) return Boolean;
179 -- Predicate to recognize stubbed procedures and null procedures, which
180 -- can be inlined unconditionally in all cases.
182 function Is_Secondary_Stack_Return_Object (E : Entity_Id) return Boolean;
183 -- Return True if E is a return object of a function whose return type is
184 -- returned on the secondary stack.
186 function Is_Special_Return_Object (E : Entity_Id) return Boolean;
187 -- Return True if E is the return object of a function and is handled in a
188 -- special way by the expander. In most cases, return objects are handled
189 -- like any other variables or constants but, in a few special cases, they
190 -- are further expanded into more elaborate constructs, whose common goal
191 -- is to elide the copy operation associated with the return.
193 procedure Make_Build_In_Place_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 -- A new access object is declared that is initialized to the result of the
200 -- allocator, passed to the function, and the allocator is rewritten to
201 -- refer to that access object. Function_Call must denote either an
202 -- N_Function_Call node for which Is_Build_In_Place_Call is True, or else
203 -- an N_Qualified_Expression node applied to such a function call.
205 procedure Make_Build_In_Place_Call_In_Anonymous_Context
206 (Function_Call : Node_Id);
207 -- Ada 2005 (AI-318-02): Handle a call to a build-in-place function that
208 -- occurs in a context that does not provide a separate object. A temporary
209 -- object is created to act as the return object and an access to the
210 -- temporary is passed as an additional parameter of the call. This occurs
211 -- in contexts such as subprogram call actuals and object renamings.
212 -- Function_Call must denote either an N_Function_Call node for which
213 -- Is_Build_In_Place_Call is True, or else an N_Qualified_Expression node
214 -- applied to such a function call.
216 procedure Make_Build_In_Place_Call_In_Assignment
217 (Assign : 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 right-hand side of an assignment statement by passing
221 -- access to the left-hand side as an additional parameter of the function
222 -- call. Assign must denote a N_Assignment_Statement. Function_Call must
223 -- denote either an N_Function_Call node for which Is_Build_In_Place_Call
224 -- is True, or an N_Qualified_Expression node applied to such a function
225 -- call.
227 procedure Make_Build_In_Place_Call_In_Object_Declaration
228 (Obj_Decl : Node_Id;
229 Function_Call : Node_Id);
230 -- Ada 2005 (AI-318-02): Handle a call to a build-in-place function that
231 -- occurs as the expression initializing an object declaration by
232 -- passing access to the declared object as an additional parameter of the
233 -- function call. Function_Call must denote either an N_Function_Call node
234 -- for which Is_Build_In_Place_Call is True, or an N_Qualified_Expression
235 -- node applied to such a function call.
237 procedure Make_Build_In_Place_Iface_Call_In_Allocator
238 (Allocator : Node_Id;
239 Function_Call : Node_Id);
240 -- Ada 2005 (AI-318-02): Handle a call to a build-in-place function that
241 -- occurs as the expression initializing an allocator, by passing access
242 -- to the allocated object as an additional parameter of the function call.
243 -- Function_Call must denote an expression containing a BIP function call
244 -- and an enclosing call to Ada.Tags.Displace to displace the pointer to
245 -- the returned BIP object to reference the secondary dispatch table of
246 -- an interface.
248 procedure Make_Build_In_Place_Iface_Call_In_Anonymous_Context
249 (Function_Call : Node_Id);
250 -- Ada 2005 (AI-318-02): Handle a call to a build-in-place function that
251 -- occurs in a context that does not provide a separate object. A temporary
252 -- object is created to act as the return object and an access to the
253 -- temporary is passed as an additional parameter of the call. This occurs
254 -- in contexts such as subprogram call actuals and object renamings.
255 -- Function_Call must denote an expression containing a BIP function call
256 -- and an enclosing call to Ada.Tags.Displace to displace the pointer to
257 -- the returned BIP object to reference the secondary dispatch table of
258 -- an interface.
260 procedure Make_Build_In_Place_Iface_Call_In_Object_Declaration
261 (Obj_Decl : Node_Id;
262 Function_Call : Node_Id);
263 -- Ada 2005 (AI-318-02): Handle a call to a build-in-place function that
264 -- occurs as the expression initializing an object declaration by passing
265 -- access to the declared object as an additional parameter of the function
266 -- call. Function_Call must denote an expression containing a BIP function
267 -- call and an enclosing call to Ada.Tags.Displace to displace the pointer
268 -- to the returned BIP object to reference the secondary dispatch table of
269 -- an interface.
271 procedure Make_CPP_Constructor_Call_In_Allocator
272 (Allocator : Node_Id;
273 Function_Call : Node_Id);
274 -- Handle a call to a CPP constructor that occurs as the expression that
275 -- initializes an allocator, by passing access to the allocated object as
276 -- an additional parameter of the constructor call. A new access object is
277 -- declared that is initialized to the result of the allocator, passed to
278 -- the constructor, and the allocator is rewritten to refer to that access
279 -- object. Function_Call must denote a call to a CPP_Constructor function.
281 function Might_Have_Tasks (Typ : Entity_Id) return Boolean;
282 -- Return True when type Typ has tasks or when it is a limited class-wide
283 -- type (or subtype), since it might have task components.
285 function Needs_BIP_Alloc_Form (Func_Id : Entity_Id) return Boolean;
286 -- Ada 2005 (AI-318-02): Return True if the function needs an implicit
287 -- BIP_Alloc_Form parameter (see type BIP_Formal_Kind).
289 function Needs_BIP_Finalization_Master (Func_Id : Entity_Id) return Boolean;
290 -- Ada 2005 (AI-318-02): Return True if the result subtype of function
291 -- Func_Id might need finalization actions. This includes build-in-place
292 -- functions with tagged result types, since they can be invoked via
293 -- dispatching calls, and descendant types may require finalization.
295 function Needs_BIP_Task_Actuals (Func_Id : Entity_Id) return Boolean;
296 -- Return True if the function returns an object of a type that has tasks.
298 function Unqual_BIP_Iface_Function_Call (Expr : Node_Id) return Node_Id;
299 -- Return the inner BIP function call removing any qualification from Expr
300 -- including qualified expressions, type conversions, references, unchecked
301 -- conversions and calls to displace the pointer to the object, if Expr is
302 -- an expression containing a call displacing the pointer to the BIP object
303 -- to reference the secondary dispatch table of an interface; otherwise
304 -- return Empty.
306 procedure Validate_Subprogram_Calls (N : Node_Id);
307 -- Check that the number of actuals (including extra actuals) of calls in
308 -- the subtree N match their corresponding formals; check also that the
309 -- names of BIP extra actuals and formals match.
311 private
312 pragma Inline (Is_Build_In_Place_Return_Object);
314 end Exp_Ch6;