OSDN Git Service

2011-12-05 Bob Duff <duff@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / exp_ch6.ads
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-2011, 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
28 with Types; use Types;
29
30 package 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 Make_Build_In_Place_Call_In_Allocator
161      (Allocator     : Node_Id;
162       Function_Call : Node_Id);
163    --  Ada 2005 (AI-318-02): Handle a call to a build-in-place function that
164    --  occurs as the expression initializing an allocator, by passing access
165    --  to the allocated object as an additional parameter of the function call.
166    --  A new access object is declared that is initialized to the result of the
167    --  allocator, passed to the function, and the allocator is rewritten to
168    --  refer to that access object. Function_Call must denote either an
169    --  N_Function_Call node for which Is_Build_In_Place_Call is True, or else
170    --  an N_Qualified_Expression node applied to such a function call.
171
172    procedure Make_Build_In_Place_Call_In_Anonymous_Context
173      (Function_Call : Node_Id);
174    --  Ada 2005 (AI-318-02): Handle a call to a build-in-place function that
175    --  occurs in a context that does not provide a separate object. A temporary
176    --  object is created to act as the return object and an access to the
177    --  temporary is passed as an additional parameter of the call. This occurs
178    --  in contexts such as subprogram call actuals and object renamings.
179    --  Function_Call must denote either an N_Function_Call node for which
180    --  Is_Build_In_Place_Call is True, or else an N_Qualified_Expression node
181    --  applied to such a function call.
182
183    procedure Make_Build_In_Place_Call_In_Assignment
184      (Assign        : Node_Id;
185       Function_Call : Node_Id);
186    --  Ada 2005 (AI-318-02): Handle a call to a build-in-place function that
187    --  occurs as the right-hand side of an assignment statement by passing
188    --  access to the left-hand side as an additional parameter of the function
189    --  call. Assign must denote a N_Assignment_Statement. Function_Call must
190    --  denote either an N_Function_Call node for which Is_Build_In_Place_Call
191    --  is True, or an N_Qualified_Expression node applied to such a function
192    --  call.
193
194    procedure Make_Build_In_Place_Call_In_Object_Declaration
195      (Object_Decl   : Node_Id;
196       Function_Call : Node_Id);
197    --  Ada 2005 (AI-318-02): Handle a call to a build-in-place function that
198    --  occurs as the expression initializing an object declaration by
199    --  passing access to the declared object as an additional parameter of the
200    --  function call. Function_Call must denote either an N_Function_Call node
201    --  for which Is_Build_In_Place_Call is True, or an N_Qualified_Expression
202    --  node applied to such a function call.
203
204    function Needs_BIP_Alloc_Form (Func_Id : Entity_Id) return Boolean;
205    --  Ada 2005 (AI-318-02): Return True if the function needs an implicit
206    --  BIP_Alloc_Form parameter (see type BIP_Formal_Kind).
207
208    function Needs_BIP_Finalization_Master (Func_Id : Entity_Id) return Boolean;
209    --  Ada 2005 (AI-318-02): Return True if the result subtype of function
210    --  Func_Id needs finalization actions.
211
212    function Needs_Result_Accessibility_Level
213      (Func_Id : Entity_Id) return Boolean;
214    --  Ada 2012 (AI05-0234): Return True if the function needs an implicit
215    --  parameter to identify the accessibility level of the function result
216    --  "determined by the point of call".
217
218    procedure Add_Extra_Actual_To_Call
219      (Subprogram_Call : Node_Id;
220       Extra_Formal    : Entity_Id;
221       Extra_Actual    : Node_Id);
222    --  Adds Extra_Actual as a named parameter association for the formal
223    --  Extra_Formal in Subprogram_Call.
224
225 end Exp_Ch6;