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------------------------------------------------------------------------------
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 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   procedure Initialize;
121   --  Initialize internal tables
122
123   function Is_Build_In_Place_Function (E : Entity_Id) return Boolean;
124   --  Ada 2005 (AI-318-02): Returns True if E denotes a function, generic
125   --  function, or access-to-function type whose result must be built in
126   --  place; otherwise returns False. For Ada 2005, this is currently
127   --  restricted to the set of functions whose result subtype is an inherently
128   --  limited type. In Ada 95, this must be False for inherently limited
129   --  result types (but currently returns False for all Ada 95 functions).
130   --  Eventually we plan to support build-in-place for nonlimited types.
131   --  Build-in-place is usually more efficient for large things, and less
132   --  efficient for small things. However, we never use build-in-place if the
133   --  convention is other than Ada, because that would disturb mixed-language
134   --  programs. Note that for the non-inherently-limited cases, we must make
135   --  the same decision for Ada 95 and 2005, so that mixed-dialect programs
136   --  will work.
137
138   function Is_Build_In_Place_Function_Call (N : Node_Id) return Boolean;
139   --  Ada 2005 (AI-318-02): Returns True if N denotes a call to a function
140   --  that requires handling as a build-in-place call or is a qualified
141   --  expression applied to such a call; otherwise returns False.
142
143   function Is_Null_Procedure (Subp : Entity_Id) return Boolean;
144   --  Predicate to recognize stubbed procedures and null procedures, which
145   --  can be inlined unconditionally in all cases.
146
147   procedure Make_Build_In_Place_Call_In_Allocator
148     (Allocator     : Node_Id;
149      Function_Call : Node_Id);
150   --  Ada 2005 (AI-318-02): Handle a call to a build-in-place function that
151   --  occurs as the expression initializing an allocator, by passing access
152   --  to the allocated object as an additional parameter of the function call.
153   --  A new access object is declared that is initialized to the result of the
154   --  allocator, passed to the function, and the allocator is rewritten to
155   --  refer to that access object. Function_Call must denote either an
156   --  N_Function_Call node for which Is_Build_In_Place_Call is True, or else
157   --  an N_Qualified_Expression node applied to such a function call.
158
159   procedure Make_Build_In_Place_Call_In_Anonymous_Context
160     (Function_Call : Node_Id);
161   --  Ada 2005 (AI-318-02): Handle a call to a build-in-place function that
162   --  occurs in a context that does not provide a separate object. A temporary
163   --  object is created to act as the return object and an access to the
164   --  temporary is passed as an additional parameter of the call. This occurs
165   --  in contexts such as subprogram call actuals and object renamings.
166   --  Function_Call must denote either an N_Function_Call node for which
167   --  Is_Build_In_Place_Call is True, or else an N_Qualified_Expression node
168   --  applied to such a function call.
169
170   procedure Make_Build_In_Place_Call_In_Assignment
171     (Assign        : Node_Id;
172      Function_Call : Node_Id);
173   --  Ada 2005 (AI-318-02): Handle a call to a build-in-place function that
174   --  occurs as the right-hand side of an assignment statement by passing
175   --  access to the left-hand side as an additional parameter of the function
176   --  call. Assign must denote a N_Assignment_Statement. Function_Call must
177   --  denote either an N_Function_Call node for which Is_Build_In_Place_Call
178   --  is True, or an N_Qualified_Expression node applied to such a function
179   --  call.
180
181   procedure Make_Build_In_Place_Call_In_Object_Declaration
182     (Obj_Decl      : Node_Id;
183      Function_Call : Node_Id);
184   --  Ada 2005 (AI-318-02): Handle a call to a build-in-place function that
185   --  occurs as the expression initializing an object declaration by
186   --  passing access to the declared object as an additional parameter of the
187   --  function call. Function_Call must denote either an N_Function_Call node
188   --  for which Is_Build_In_Place_Call is True, or an N_Qualified_Expression
189   --  node applied to such a function call.
190
191   procedure Make_CPP_Constructor_Call_In_Allocator
192     (Allocator     : Node_Id;
193      Function_Call : Node_Id);
194   --  Handle a call to a CPP constructor that occurs as the expression that
195   --  initializes an allocator, by passing access to the allocated object as
196   --  an additional parameter of the constructor call. A new access object is
197   --  declared that is initialized to the result of the allocator, passed to
198   --  the constructor, and the allocator is rewritten to refer to that access
199   --  object. Function_Call must denote a call to a CPP_Constructor function.
200
201   function Needs_BIP_Alloc_Form (Func_Id : Entity_Id) return Boolean;
202   --  Ada 2005 (AI-318-02): Return True if the function needs an implicit
203   --  BIP_Alloc_Form parameter (see type BIP_Formal_Kind).
204
205   function Needs_BIP_Finalization_Master (Func_Id : Entity_Id) return Boolean;
206   --  Ada 2005 (AI-318-02): Return True if the result subtype of function
207   --  Func_Id needs finalization actions.
208
209   function Needs_Result_Accessibility_Level
210     (Func_Id : Entity_Id) return Boolean;
211   --  Ada 2012 (AI05-0234): Return True if the function needs an implicit
212   --  parameter to identify the accessibility level of the function result
213   --  "determined by the point of call".
214
215   procedure Unnest_Subprograms;
216   --  Called to unnest subprograms. If we are in unnest subprogram mode, and
217   --  subprograms have been gathered in the Unest_Bodies table, this is the
218   --  call that causes them to be processed for unnesting.
219
220end Exp_Ch6;
221