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-2020, 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------------------------------------------------------------------------------ 25 26-- Expand routines for chapter 6 constructs 27 28with Types; use Types; 29 30package 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 BIP_Suffix_Kind (E : Entity_Id) return BIP_Formal_Kind; 106 -- Ada 2005 (AI-318-02): Returns the kind of the given BIP extra formal. 107 108 function Build_In_Place_Formal 109 (Func : Entity_Id; 110 Kind : BIP_Formal_Kind) return Entity_Id; 111 -- Ada 2005 (AI-318-02): Locates and returns the entity for the implicit 112 -- build-in-place formal parameter of the given kind associated with the 113 -- function Func, and returns its Entity_Id. It is a bug if not found; the 114 -- caller should ensure this is called only when the extra formal exists. 115 116 function Build_Procedure_Body_Form 117 (Func_Id : Entity_Id; Func_Body : Node_Id) return Node_Id; 118 -- Create a procedure body which emulates the behavior of function Func_Id. 119 -- Func_Body is the root of the body of the function before its analysis. 120 -- The returned node is the root of the procedure body which will replace 121 -- the original function body, which is not needed for the C program. 122 123 function Is_Build_In_Place_Entity (E : Entity_Id) return Boolean; 124 -- Ada 2005 (AI-318-02): Returns True if E is a BIP entity. 125 126 function Is_Build_In_Place_Result_Type (Typ : Entity_Id) return Boolean; 127 -- Ada 2005 (AI-318-02): Returns True if functions returning the type use 128 -- build-in-place protocols. For inherently limited types, this must be 129 -- True in >= Ada 2005, and must be False in Ada 95. For other types, it 130 -- can be True or False, and the decision should be based on efficiency, 131 -- and should be the same for all language versions, so that mixed-dialect 132 -- programs will work. 133 -- 134 -- For inherently limited types in Ada 2005, True means that calls will 135 -- actually be build-in-place in all cases. For other types, build-in-place 136 -- will be used when possible, but we need to make a copy at the call site 137 -- in some cases, notably assignment statements. 138 139 function Is_Build_In_Place_Function (E : Entity_Id) return Boolean; 140 -- Ada 2005 (AI-318-02): Returns True if E denotes a function, generic 141 -- function, or access-to-function type for which 142 -- Is_Build_In_Place_Result_Type is True. However, we never use 143 -- build-in-place if the convention is other than Ada, because that would 144 -- disturb mixed-language programs. 145 146 function Is_Build_In_Place_Function_Call (N : Node_Id) return Boolean; 147 -- Ada 2005 (AI-318-02): Returns True if N denotes a call to a function 148 -- that requires handling as a build-in-place call (possibly qualified or 149 -- converted). 150 151 function Is_Null_Procedure (Subp : Entity_Id) return Boolean; 152 -- Predicate to recognize stubbed procedures and null procedures, which 153 -- can be inlined unconditionally in all cases. 154 155 procedure Make_Build_In_Place_Call_In_Allocator 156 (Allocator : Node_Id; 157 Function_Call : Node_Id); 158 -- Ada 2005 (AI-318-02): Handle a call to a build-in-place function that 159 -- occurs as the expression initializing an allocator, by passing access 160 -- to the allocated object as an additional parameter of the function call. 161 -- A new access object is declared that is initialized to the result of the 162 -- allocator, passed to the function, and the allocator is rewritten to 163 -- refer to that access object. Function_Call must denote either an 164 -- N_Function_Call node for which Is_Build_In_Place_Call is True, or else 165 -- an N_Qualified_Expression node applied to such a function call. 166 167 procedure Make_Build_In_Place_Call_In_Anonymous_Context 168 (Function_Call : Node_Id); 169 -- Ada 2005 (AI-318-02): Handle a call to a build-in-place function that 170 -- occurs in a context that does not provide a separate object. A temporary 171 -- object is created to act as the return object and an access to the 172 -- temporary is passed as an additional parameter of the call. This occurs 173 -- in contexts such as subprogram call actuals and object renamings. 174 -- Function_Call must denote either an N_Function_Call node for which 175 -- Is_Build_In_Place_Call is True, or else an N_Qualified_Expression node 176 -- applied to such a function call. 177 178 procedure Make_Build_In_Place_Call_In_Assignment 179 (Assign : Node_Id; 180 Function_Call : Node_Id); 181 -- Ada 2005 (AI-318-02): Handle a call to a build-in-place function that 182 -- occurs as the right-hand side of an assignment statement by passing 183 -- access to the left-hand side as an additional parameter of the function 184 -- call. Assign must denote a N_Assignment_Statement. Function_Call must 185 -- denote either an N_Function_Call node for which Is_Build_In_Place_Call 186 -- is True, or an N_Qualified_Expression node applied to such a function 187 -- call. 188 189 procedure Make_Build_In_Place_Call_In_Object_Declaration 190 (Obj_Decl : Node_Id; 191 Function_Call : Node_Id); 192 -- Ada 2005 (AI-318-02): Handle a call to a build-in-place function that 193 -- occurs as the expression initializing an object declaration by 194 -- passing access to the declared object as an additional parameter of the 195 -- function call. Function_Call must denote either an N_Function_Call node 196 -- for which Is_Build_In_Place_Call is True, or an N_Qualified_Expression 197 -- node applied to such a function call. 198 199 procedure Make_Build_In_Place_Iface_Call_In_Allocator 200 (Allocator : 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 expression initializing an allocator, by passing access 204 -- to the allocated object as an additional parameter of the function call. 205 -- Function_Call must denote an expression containing a BIP function call 206 -- and an enclosing call to Ada.Tags.Displace to displace the pointer to 207 -- the returned BIP object to reference the secondary dispatch table of 208 -- an interface. 209 210 procedure Make_Build_In_Place_Iface_Call_In_Anonymous_Context 211 (Function_Call : Node_Id); 212 -- Ada 2005 (AI-318-02): Handle a call to a build-in-place function that 213 -- occurs in a context that does not provide a separate object. A temporary 214 -- object is created to act as the return object and an access to the 215 -- temporary is passed as an additional parameter of the call. This occurs 216 -- in contexts such as subprogram call actuals and object renamings. 217 -- Function_Call must denote an expression containing a BIP function call 218 -- and an enclosing call to Ada.Tags.Displace to displace the pointer to 219 -- the returned BIP object to reference the secondary dispatch table of 220 -- an interface. 221 222 procedure Make_Build_In_Place_Iface_Call_In_Object_Declaration 223 (Obj_Decl : Node_Id; 224 Function_Call : Node_Id); 225 -- Ada 2005 (AI-318-02): Handle a call to a build-in-place function that 226 -- occurs as the expression initializing an object declaration by passing 227 -- access to the declared object as an additional parameter of the function 228 -- call. Function_Call must denote an expression containing a BIP function 229 -- call and an enclosing call to Ada.Tags.Displace to displace the pointer 230 -- to the returned BIP object to reference the secondary dispatch table of 231 -- an interface. 232 233 procedure Make_CPP_Constructor_Call_In_Allocator 234 (Allocator : Node_Id; 235 Function_Call : Node_Id); 236 -- Handle a call to a CPP constructor that occurs as the expression that 237 -- initializes an allocator, by passing access to the allocated object as 238 -- an additional parameter of the constructor call. A new access object is 239 -- declared that is initialized to the result of the allocator, passed to 240 -- the constructor, and the allocator is rewritten to refer to that access 241 -- object. Function_Call must denote a call to a CPP_Constructor function. 242 243 function Might_Have_Tasks (Typ : Entity_Id) return Boolean; 244 -- Return True when type Typ has tasks or when it is a limited class-wide 245 -- type (or subtype), since it might have task components. 246 247 function Needs_BIP_Alloc_Form (Func_Id : Entity_Id) return Boolean; 248 -- Ada 2005 (AI-318-02): Return True if the function needs an implicit 249 -- BIP_Alloc_Form parameter (see type BIP_Formal_Kind). 250 251 function Needs_BIP_Finalization_Master (Func_Id : Entity_Id) return Boolean; 252 -- Ada 2005 (AI-318-02): Return True if the result subtype of function 253 -- Func_Id might need finalization actions. This includes build-in-place 254 -- functions with tagged result types, since they can be invoked via 255 -- dispatching calls, and descendant types may require finalization. 256 257 function Needs_BIP_Task_Actuals (Func_Id : Entity_Id) return Boolean; 258 -- Return True if the function returns an object of a type that has tasks. 259 260 function Unqual_BIP_Iface_Function_Call (Expr : Node_Id) return Node_Id; 261 -- Return the inner BIP function call removing any qualification from Expr 262 -- including qualified expressions, type conversions, references, unchecked 263 -- conversions and calls to displace the pointer to the object, if Expr is 264 -- an expression containing a call displacing the pointer to the BIP object 265 -- to reference the secondary dispatch table of an interface; otherwise 266 -- return Empty. 267 268end Exp_Ch6; 269