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 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.
49
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)
54
55   --  The following type defines the various forms of allocation used for the
56   --  results of build-in-place function calls.
57
58   type BIP_Allocation_Form is
59     (Unspecified,
60      Caller_Allocation,
61      Secondary_Stack,
62      Global_Heap,
63      User_Storage_Pool);
64
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.
70
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.
76
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.
81
82      BIP_Finalization_Master,
83      --  Present if result type needs finalization. Pointer to caller's
84      --  finalization master.
85
86      BIP_Task_Master,
87      --  Present if result type contains tasks. Master associated with
88      --  calling context.
89
90      BIP_Activation_Chain,
91      --  Present if result type contains tasks. Caller's activation chain
92
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.
97      --
98      --  ??? We might also need to be able to pass in a constrained flag.
99
100   function BIP_Formal_Suffix (Kind : BIP_Formal_Kind) return String;
101   --  Ada 2005 (AI-318-02): Returns a string to be used as the suffix of names
102   --  for build-in-place formal parameters of the given kind.
103
104   function Build_In_Place_Formal
105     (Func : Entity_Id;
106      Kind : BIP_Formal_Kind) return Entity_Id;
107   --  Ada 2005 (AI-318-02): Locates and returns the entity for the implicit
108   --  build-in-place formal parameter of the given kind associated with the
109   --  function Func, and returns its Entity_Id. It is a bug if not found; the
110   --  caller should ensure this is called only when the extra formal exists.
111
112   function Is_Build_In_Place_Function (E : Entity_Id) return Boolean;
113   --  Ada 2005 (AI-318-02): Returns True if E denotes a function, generic
114   --  function, or access-to-function type whose result must be built in
115   --  place; otherwise returns False. For Ada 2005, this is currently
116   --  restricted to the set of functions whose result subtype is an inherently
117   --  limited type. In Ada 95, this must be False for inherently limited
118   --  result types (but currently returns False for all Ada 95 functions).
119   --  Eventually we plan to support build-in-place for nonlimited types.
120   --  Build-in-place is usually more efficient for large things, and less
121   --  efficient for small things. However, we never use build-in-place if the
122   --  convention is other than Ada, because that would disturb mixed-language
123   --  programs. Note that for the non-inherently-limited cases, we must make
124   --  the same decision for Ada 95 and 2005, so that mixed-dialect programs
125   --  will work.
126
127   function Is_Build_In_Place_Function_Call (N : Node_Id) return Boolean;
128   --  Ada 2005 (AI-318-02): Returns True if N denotes a call to a function
129   --  that requires handling as a build-in-place call or is a qualified
130   --  expression applied to such a call; otherwise returns False.
131
132   function Is_Null_Procedure (Subp : Entity_Id) return Boolean;
133   --  Predicate to recognize stubbed procedures and null procedures, which
134   --  can be inlined unconditionally in all cases.
135
136   procedure Make_Build_In_Place_Call_In_Allocator
137     (Allocator     : Node_Id;
138      Function_Call : Node_Id);
139   --  Ada 2005 (AI-318-02): Handle a call to a build-in-place function that
140   --  occurs as the expression initializing an allocator, by passing access
141   --  to the allocated object as an additional parameter of the function call.
142   --  A new access object is declared that is initialized to the result of the
143   --  allocator, passed to the function, and the allocator is rewritten to
144   --  refer to that access object. Function_Call must denote either an
145   --  N_Function_Call node for which Is_Build_In_Place_Call is True, or else
146   --  an N_Qualified_Expression node applied to such a function call.
147
148   procedure Make_Build_In_Place_Call_In_Anonymous_Context
149     (Function_Call : Node_Id);
150   --  Ada 2005 (AI-318-02): Handle a call to a build-in-place function that
151   --  occurs in a context that does not provide a separate object. A temporary
152   --  object is created to act as the return object and an access to the
153   --  temporary is passed as an additional parameter of the call. This occurs
154   --  in contexts such as subprogram call actuals and object renamings.
155   --  Function_Call must denote either an N_Function_Call node for which
156   --  Is_Build_In_Place_Call is True, or else an N_Qualified_Expression node
157   --  applied to such a function call.
158
159   procedure Make_Build_In_Place_Call_In_Assignment
160     (Assign        : Node_Id;
161      Function_Call : Node_Id);
162   --  Ada 2005 (AI-318-02): Handle a call to a build-in-place function that
163   --  occurs as the right-hand side of an assignment statement by passing
164   --  access to the left-hand side as an additional parameter of the function
165   --  call. Assign must denote a N_Assignment_Statement. Function_Call must
166   --  denote either an N_Function_Call node for which Is_Build_In_Place_Call
167   --  is True, or an N_Qualified_Expression node applied to such a function
168   --  call.
169
170   procedure Make_Build_In_Place_Call_In_Object_Declaration
171     (Object_Decl   : 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 expression initializing an object declaration by
175   --  passing access to the declared object as an additional parameter of the
176   --  function call. Function_Call must denote either an N_Function_Call node
177   --  for which Is_Build_In_Place_Call is True, or an N_Qualified_Expression
178   --  node applied to such a function call.
179
180   procedure Make_CPP_Constructor_Call_In_Allocator
181     (Allocator     : Node_Id;
182      Function_Call : Node_Id);
183   --  Handle a call to a CPP constructor that occurs as the expression that
184   --  initializes an allocator, by passing access to the allocated object as
185   --  an additional parameter of the constructor call. A new access object is
186   --  declared that is initialized to the result of the allocator, passed to
187   --  the constructor, and the allocator is rewritten to refer to that access
188   --  object. Function_Call must denote a call to a CPP_Constructor function.
189
190   function Needs_BIP_Alloc_Form (Func_Id : Entity_Id) return Boolean;
191   --  Ada 2005 (AI-318-02): Return True if the function needs an implicit
192   --  BIP_Alloc_Form parameter (see type BIP_Formal_Kind).
193
194   function Needs_BIP_Finalization_Master (Func_Id : Entity_Id) return Boolean;
195   --  Ada 2005 (AI-318-02): Return True if the result subtype of function
196   --  Func_Id needs finalization actions.
197
198   function Needs_Result_Accessibility_Level
199     (Func_Id : Entity_Id) return Boolean;
200   --  Ada 2012 (AI05-0234): Return True if the function needs an implicit
201   --  parameter to identify the accessibility level of the function result
202   --  "determined by the point of call".
203
204   procedure Add_Extra_Actual_To_Call
205     (Subprogram_Call : Node_Id;
206      Extra_Formal    : Entity_Id;
207      Extra_Actual    : Node_Id);
208   --  Adds Extra_Actual as a named parameter association for the formal
209   --  Extra_Formal in Subprogram_Call.
210
211end Exp_Ch6;
212