2015-05-12 Robert Dewar <dewar@adacore.com>
[official-gcc.git] / gcc / ada / exp_ch6.ads
blob5cbcc965cf444afdb6f9d3f868c2f4eddcb097a8
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-2015, 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_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);
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.
44 procedure Expand_Subprogram_Contract (N : Node_Id);
45 -- Expand the contracts of a subprogram body and its correspoding spec (if
46 -- any). This routine processes all [refined] pre- and postconditions as
47 -- well as Contract_Cases, invariants and predicates. N denotes the body of
48 -- the subprogram.
50 procedure Freeze_Subprogram (N : Node_Id);
51 -- generate the appropriate expansions related to Subprogram freeze
52 -- nodes (e.g. the filling of the corresponding Dispatch Table for
53 -- Primitive Operations)
55 -- The following type defines the various forms of allocation used for the
56 -- results of build-in-place function calls.
58 type BIP_Allocation_Form is
59 (Unspecified,
60 Caller_Allocation,
61 Secondary_Stack,
62 Global_Heap,
63 User_Storage_Pool);
65 type BIP_Formal_Kind is
66 -- Ada 2005 (AI-318-02): This type defines the kinds of implicit extra
67 -- formals created for build-in-place functions. The order of these
68 -- enumeration literals matches the order in which the formals are
69 -- declared. See Sem_Ch6.Create_Extra_Formals.
71 (BIP_Alloc_Form,
72 -- Present if result subtype is unconstrained or tagged. Indicates
73 -- whether the return object is allocated by the caller or callee, and
74 -- if the callee, whether to use the secondary stack or the heap. See
75 -- Create_Extra_Formals.
77 BIP_Storage_Pool,
78 -- Present if result subtype is unconstrained or tagged. If
79 -- BIP_Alloc_Form = User_Storage_Pool, this is a pointer to the pool
80 -- (of type access to Root_Storage_Pool'Class). Otherwise null.
82 BIP_Finalization_Master,
83 -- Present if result type needs finalization. Pointer to caller's
84 -- finalization master.
86 BIP_Task_Master,
87 -- Present if result type contains tasks. Master associated with
88 -- calling context.
90 BIP_Activation_Chain,
91 -- Present if result type contains tasks. Caller's activation chain
93 BIP_Object_Access);
94 -- Present for all build-in-place functions. Address at which to place
95 -- the return object, or null if BIP_Alloc_Form indicates allocated by
96 -- callee.
98 -- ??? We might also need to be able to pass in a constrained flag.
100 procedure Add_Extra_Actual_To_Call
101 (Subprogram_Call : Node_Id;
102 Extra_Formal : Entity_Id;
103 Extra_Actual : Node_Id);
104 -- Adds Extra_Actual as a named parameter association for the formal
105 -- Extra_Formal in Subprogram_Call.
107 function BIP_Formal_Suffix (Kind : BIP_Formal_Kind) return String;
108 -- Ada 2005 (AI-318-02): Returns a string to be used as the suffix of names
109 -- for build-in-place formal parameters of the given kind.
111 function Build_In_Place_Formal
112 (Func : Entity_Id;
113 Kind : BIP_Formal_Kind) return Entity_Id;
114 -- Ada 2005 (AI-318-02): Locates and returns the entity for the implicit
115 -- build-in-place formal parameter of the given kind associated with the
116 -- function Func, and returns its Entity_Id. It is a bug if not found; the
117 -- caller should ensure this is called only when the extra formal exists.
119 procedure Initialize;
120 -- Initialize internal tables
122 function Is_Build_In_Place_Function (E : Entity_Id) return Boolean;
123 -- Ada 2005 (AI-318-02): Returns True if E denotes a function, generic
124 -- function, or access-to-function type whose result must be built in
125 -- place; otherwise returns False. For Ada 2005, this is currently
126 -- restricted to the set of functions whose result subtype is an inherently
127 -- limited type. In Ada 95, this must be False for inherently limited
128 -- result types (but currently returns False for all Ada 95 functions).
129 -- Eventually we plan to support build-in-place for nonlimited types.
130 -- Build-in-place is usually more efficient for large things, and less
131 -- efficient for small things. However, we never use build-in-place if the
132 -- convention is other than Ada, because that would disturb mixed-language
133 -- programs. Note that for the non-inherently-limited cases, we must make
134 -- the same decision for Ada 95 and 2005, so that mixed-dialect programs
135 -- will work.
137 function Is_Build_In_Place_Function_Call (N : Node_Id) return Boolean;
138 -- Ada 2005 (AI-318-02): Returns True if N denotes a call to a function
139 -- that requires handling as a build-in-place call or is a qualified
140 -- expression applied to such a call; otherwise returns False.
142 function Is_Null_Procedure (Subp : Entity_Id) return Boolean;
143 -- Predicate to recognize stubbed procedures and null procedures, which
144 -- can be inlined unconditionally in all cases.
146 procedure Make_Build_In_Place_Call_In_Allocator
147 (Allocator : Node_Id;
148 Function_Call : Node_Id);
149 -- Ada 2005 (AI-318-02): Handle a call to a build-in-place function that
150 -- occurs as the expression initializing an allocator, by passing access
151 -- to the allocated object as an additional parameter of the function call.
152 -- A new access object is declared that is initialized to the result of the
153 -- allocator, passed to the function, and the allocator is rewritten to
154 -- refer to that access object. Function_Call must denote either an
155 -- N_Function_Call node for which Is_Build_In_Place_Call is True, or else
156 -- an N_Qualified_Expression node applied to such a function call.
158 procedure Make_Build_In_Place_Call_In_Anonymous_Context
159 (Function_Call : Node_Id);
160 -- Ada 2005 (AI-318-02): Handle a call to a build-in-place function that
161 -- occurs in a context that does not provide a separate object. A temporary
162 -- object is created to act as the return object and an access to the
163 -- temporary is passed as an additional parameter of the call. This occurs
164 -- in contexts such as subprogram call actuals and object renamings.
165 -- Function_Call must denote either an N_Function_Call node for which
166 -- Is_Build_In_Place_Call is True, or else an N_Qualified_Expression node
167 -- applied to such a function call.
169 procedure Make_Build_In_Place_Call_In_Assignment
170 (Assign : Node_Id;
171 Function_Call : Node_Id);
172 -- Ada 2005 (AI-318-02): Handle a call to a build-in-place function that
173 -- occurs as the right-hand side of an assignment statement by passing
174 -- access to the left-hand side as an additional parameter of the function
175 -- call. Assign must denote a N_Assignment_Statement. Function_Call must
176 -- denote either an N_Function_Call node for which Is_Build_In_Place_Call
177 -- is True, or an N_Qualified_Expression node applied to such a function
178 -- call.
180 procedure Make_Build_In_Place_Call_In_Object_Declaration
181 (Object_Decl : Node_Id;
182 Function_Call : Node_Id);
183 -- Ada 2005 (AI-318-02): Handle a call to a build-in-place function that
184 -- occurs as the expression initializing an object declaration by
185 -- passing access to the declared object as an additional parameter of the
186 -- function call. Function_Call must denote either an N_Function_Call node
187 -- for which Is_Build_In_Place_Call is True, or an N_Qualified_Expression
188 -- node applied to such a function call.
190 procedure Make_CPP_Constructor_Call_In_Allocator
191 (Allocator : Node_Id;
192 Function_Call : Node_Id);
193 -- Handle a call to a CPP constructor that occurs as the expression that
194 -- initializes an allocator, by passing access to the allocated object as
195 -- an additional parameter of the constructor call. A new access object is
196 -- declared that is initialized to the result of the allocator, passed to
197 -- the constructor, and the allocator is rewritten to refer to that access
198 -- object. Function_Call must denote a call to a CPP_Constructor function.
200 function Needs_BIP_Alloc_Form (Func_Id : Entity_Id) return Boolean;
201 -- Ada 2005 (AI-318-02): Return True if the function needs an implicit
202 -- BIP_Alloc_Form parameter (see type BIP_Formal_Kind).
204 function Needs_BIP_Finalization_Master (Func_Id : Entity_Id) return Boolean;
205 -- Ada 2005 (AI-318-02): Return True if the result subtype of function
206 -- Func_Id needs finalization actions.
208 function Needs_Result_Accessibility_Level
209 (Func_Id : Entity_Id) return Boolean;
210 -- Ada 2012 (AI05-0234): Return True if the function needs an implicit
211 -- parameter to identify the accessibility level of the function result
212 -- "determined by the point of call".
214 procedure Unnest_Subprograms;
215 -- Called to unnest subprograms. If we are in unnest subprogram mode, and
216 -- subprograms have been gathered in the Unest_Bodies table, this is the
217 -- call that causes them to be processed for unnesting.
219 end Exp_Ch6;