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-2012, 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_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: 44 -- 45 -- Temp : T[ := T (A)]; 46 -- 47 -- prior to the call. Then we replace the actual with a reference to Temp, 48 -- and append the assignment: 49 -- 50 -- A := TypeA (Temp); 51 -- 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: 55 -- 56 -- Var : TypeA renames A; 57 -- Temp : T := Var; -- omitting expression for out parameter. 58 -- ... 59 -- Var := TypeA (Temp); 60 -- 61 -- For other in-out parameters, we emit the required constraint checks 62 -- before and/or after the call. 63 -- 64 -- For all parameter modes, actuals that denote components and slices of 65 -- packed arrays are expanded into suitable temporaries. 66 -- 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). 69 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. 73 74 procedure Freeze_Subprogram (N : Node_Id); 75 -- generate the appropriate expansions related to Subprogram freeze 76 -- nodes (e.g. the filling of the corresponding Dispatch Table for 77 -- Primitive Operations) 78 79 -- The following type defines the various forms of allocation used for the 80 -- results of build-in-place function calls. 81 82 type BIP_Allocation_Form is 83 (Unspecified, 84 Caller_Allocation, 85 Secondary_Stack, 86 Global_Heap, 87 User_Storage_Pool); 88 89 type BIP_Formal_Kind is 90 -- Ada 2005 (AI-318-02): This type defines the kinds of implicit extra 91 -- formals created for build-in-place functions. The order of these 92 -- enumeration literals matches the order in which the formals are 93 -- declared. See Sem_Ch6.Create_Extra_Formals. 94 95 (BIP_Alloc_Form, 96 -- Present if result subtype is unconstrained or tagged. Indicates 97 -- whether the return object is allocated by the caller or callee, and 98 -- if the callee, whether to use the secondary stack or the heap. See 99 -- Create_Extra_Formals. 100 101 BIP_Storage_Pool, 102 -- Present if result subtype is unconstrained or tagged. If 103 -- BIP_Alloc_Form = User_Storage_Pool, this is a pointer to the pool 104 -- (of type access to Root_Storage_Pool'Class). Otherwise null. 105 106 BIP_Finalization_Master, 107 -- Present if result type needs finalization. Pointer to caller's 108 -- finalization master. 109 110 BIP_Task_Master, 111 -- Present if result type contains tasks. Master associated with 112 -- calling context. 113 114 BIP_Activation_Chain, 115 -- Present if result type contains tasks. Caller's activation chain 116 117 BIP_Object_Access); 118 -- Present for all build-in-place functions. Address at which to place 119 -- the return object, or null if BIP_Alloc_Form indicates allocated by 120 -- callee. 121 -- 122 -- ??? We might also need to be able to pass in a constrained flag. 123 124 function BIP_Formal_Suffix (Kind : BIP_Formal_Kind) return String; 125 -- Ada 2005 (AI-318-02): Returns a string to be used as the suffix of names 126 -- for build-in-place formal parameters of the given kind. 127 128 function Build_In_Place_Formal 129 (Func : Entity_Id; 130 Kind : BIP_Formal_Kind) return Entity_Id; 131 -- Ada 2005 (AI-318-02): Locates and returns the entity for the implicit 132 -- build-in-place formal parameter of the given kind associated with the 133 -- function Func, and returns its Entity_Id. It is a bug if not found; the 134 -- caller should ensure this is called only when the extra formal exists. 135 136 function Is_Build_In_Place_Function (E : Entity_Id) return Boolean; 137 -- Ada 2005 (AI-318-02): Returns True if E denotes a function, generic 138 -- function, or access-to-function type whose result must be built in 139 -- place; otherwise returns False. For Ada 2005, this is currently 140 -- restricted to the set of functions whose result subtype is an inherently 141 -- limited type. In Ada 95, this must be False for inherently limited 142 -- result types (but currently returns False for all Ada 95 functions). 143 -- Eventually we plan to support build-in-place for nonlimited types. 144 -- Build-in-place is usually more efficient for large things, and less 145 -- efficient for small things. However, we never use build-in-place if the 146 -- convention is other than Ada, because that would disturb mixed-language 147 -- programs. Note that for the non-inherently-limited cases, we must make 148 -- the same decision for Ada 95 and 2005, so that mixed-dialect programs 149 -- will work. 150 151 function Is_Build_In_Place_Function_Call (N : Node_Id) return Boolean; 152 -- Ada 2005 (AI-318-02): Returns True if N denotes a call to a function 153 -- that requires handling as a build-in-place call or is a qualified 154 -- expression applied to such a call; otherwise returns False. 155 156 function Is_Null_Procedure (Subp : Entity_Id) return Boolean; 157 -- Predicate to recognize stubbed procedures and null procedures, which 158 -- can be inlined unconditionally in all cases. 159 160 procedure List_Inlining_Info; 161 -- Generate listing of calls inlined by the frontend plus listing of 162 -- calls to inline subprograms passed to the backend. 163 164 procedure Make_Build_In_Place_Call_In_Allocator 165 (Allocator : Node_Id; 166 Function_Call : Node_Id); 167 -- Ada 2005 (AI-318-02): Handle a call to a build-in-place function that 168 -- occurs as the expression initializing an allocator, by passing access 169 -- to the allocated object as an additional parameter of the function call. 170 -- A new access object is declared that is initialized to the result of the 171 -- allocator, passed to the function, and the allocator is rewritten to 172 -- refer to that access object. Function_Call must denote either an 173 -- N_Function_Call node for which Is_Build_In_Place_Call is True, or else 174 -- an N_Qualified_Expression node applied to such a function call. 175 176 procedure Make_Build_In_Place_Call_In_Anonymous_Context 177 (Function_Call : Node_Id); 178 -- Ada 2005 (AI-318-02): Handle a call to a build-in-place function that 179 -- occurs in a context that does not provide a separate object. A temporary 180 -- object is created to act as the return object and an access to the 181 -- temporary is passed as an additional parameter of the call. This occurs 182 -- in contexts such as subprogram call actuals and object renamings. 183 -- Function_Call must denote either an N_Function_Call node for which 184 -- Is_Build_In_Place_Call is True, or else an N_Qualified_Expression node 185 -- applied to such a function call. 186 187 procedure Make_Build_In_Place_Call_In_Assignment 188 (Assign : Node_Id; 189 Function_Call : Node_Id); 190 -- Ada 2005 (AI-318-02): Handle a call to a build-in-place function that 191 -- occurs as the right-hand side of an assignment statement by passing 192 -- access to the left-hand side as an additional parameter of the function 193 -- call. Assign must denote a N_Assignment_Statement. Function_Call must 194 -- denote either an N_Function_Call node for which Is_Build_In_Place_Call 195 -- is True, or an N_Qualified_Expression node applied to such a function 196 -- call. 197 198 procedure Make_Build_In_Place_Call_In_Object_Declaration 199 (Object_Decl : Node_Id; 200 Function_Call : Node_Id); 201 -- Ada 2005 (AI-318-02): Handle a call to a build-in-place function that 202 -- occurs as the expression initializing an object declaration by 203 -- passing access to the declared object as an additional parameter of the 204 -- function call. Function_Call must denote either an N_Function_Call node 205 -- for which Is_Build_In_Place_Call is True, or an N_Qualified_Expression 206 -- node applied to such a function call. 207 208 procedure Make_CPP_Constructor_Call_In_Allocator 209 (Allocator : Node_Id; 210 Function_Call : Node_Id); 211 -- Handle a call to a CPP constructor that occurs as the expression that 212 -- initializes an allocator, by passing access to the allocated object as 213 -- an additional parameter of the constructor call. A new access object is 214 -- declared that is initialized to the result of the allocator, passed to 215 -- the constructor, and the allocator is rewritten to refer to that access 216 -- object. Function_Call must denote a call to a CPP_Constructor function. 217 218 function Needs_BIP_Alloc_Form (Func_Id : Entity_Id) return Boolean; 219 -- Ada 2005 (AI-318-02): Return True if the function needs an implicit 220 -- BIP_Alloc_Form parameter (see type BIP_Formal_Kind). 221 222 function Needs_BIP_Finalization_Master (Func_Id : Entity_Id) return Boolean; 223 -- Ada 2005 (AI-318-02): Return True if the result subtype of function 224 -- Func_Id needs finalization actions. 225 226 function Needs_Result_Accessibility_Level 227 (Func_Id : Entity_Id) return Boolean; 228 -- Ada 2012 (AI05-0234): Return True if the function needs an implicit 229 -- parameter to identify the accessibility level of the function result 230 -- "determined by the point of call". 231 232 procedure Add_Extra_Actual_To_Call 233 (Subprogram_Call : Node_Id; 234 Extra_Formal : Entity_Id; 235 Extra_Actual : Node_Id); 236 -- Adds Extra_Actual as a named parameter association for the formal 237 -- Extra_Formal in Subprogram_Call. 238 239end Exp_Ch6; 240