OSDN Git Service

ada:
[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 the above
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 if the result type
97       --  is tagged. Indicates whether the return object is allocated by the
98       --  caller or callee, and if the callee, whether to use the secondary
99       --  stack or the heap. See Create_Extra_Formals.
100
101       BIP_Finalization_Master,
102       --  Present if result type needs finalization. Pointer to caller's
103       --  finalization master.
104
105       BIP_Master,
106       --  Present if result type contains tasks. Master associated with
107       --  calling context.
108
109       BIP_Activation_Chain,
110       --  Present if result type contains tasks. Caller's activation chain
111
112       BIP_Object_Access);
113       --  Present for all build-in-place functions. Address at which to place
114       --  the return object, or null if BIP_Alloc_Form indicates allocated by
115       --  callee.
116       --
117       --  ??? We also need to be able to pass in some way to access a user-
118       --  defined storage pool at some point. And perhaps a constrained flag.
119
120    function BIP_Formal_Suffix (Kind : BIP_Formal_Kind) return String;
121    --  Ada 2005 (AI-318-02): Returns a string to be used as the suffix of names
122    --  for build-in-place formal parameters of the given kind.
123
124    function Build_In_Place_Formal
125      (Func : Entity_Id;
126       Kind : BIP_Formal_Kind) return Entity_Id;
127    --  Ada 2005 (AI-318-02): Locates and returns the entity for the implicit
128    --  build-in-place formal parameter of the given kind associated with the
129    --  function Func, and returns its Entity_Id. It is a bug if not found; the
130    --  caller should ensure this is called only when the extra formal exists.
131
132    function Is_Build_In_Place_Function (E : Entity_Id) return Boolean;
133    --  Ada 2005 (AI-318-02): Returns True if E denotes a function, generic
134    --  function, or access-to-function type whose result must be built in
135    --  place; otherwise returns False. For Ada 2005, this is currently
136    --  restricted to the set of functions whose result subtype is an inherently
137    --  limited type. In Ada 95, this must be False for inherently limited
138    --  result types (but currently returns False for all Ada 95 functions).
139    --  Eventually we plan to support build-in-place for nonlimited types.
140    --  Build-in-place is usually more efficient for large things, and less
141    --  efficient for small things. However, we never use build-in-place if the
142    --  convention is other than Ada, because that would disturb mixed-language
143    --  programs. Note that for the non-inherently-limited cases, we must make
144    --  the same decision for Ada 95 and 2005, so that mixed-dialect programs
145    --  will work.
146
147    function Is_Build_In_Place_Function_Call (N : Node_Id) return Boolean;
148    --  Ada 2005 (AI-318-02): Returns True if N denotes a call to a function
149    --  that requires handling as a build-in-place call or is a qualified
150    --  expression applied to such a call; otherwise returns False.
151
152    function Is_Null_Procedure (Subp : Entity_Id) return Boolean;
153    --  Predicate to recognize stubbed procedures and null procedures, which
154    --  can be inlined unconditionally in all cases.
155
156    procedure Make_Build_In_Place_Call_In_Allocator
157      (Allocator     : Node_Id;
158       Function_Call : Node_Id);
159    --  Ada 2005 (AI-318-02): Handle a call to a build-in-place function that
160    --  occurs as the expression initializing an allocator, by passing access
161    --  to the allocated object as an additional parameter of the function call.
162    --  A new access object is declared that is initialized to the result of the
163    --  allocator, passed to the function, and the allocator is rewritten to
164    --  refer to that access object. Function_Call must denote either an
165    --  N_Function_Call node for which Is_Build_In_Place_Call is True, or else
166    --  an N_Qualified_Expression node applied to such a function call.
167
168    procedure Make_Build_In_Place_Call_In_Anonymous_Context
169      (Function_Call : Node_Id);
170    --  Ada 2005 (AI-318-02): Handle a call to a build-in-place function that
171    --  occurs in a context that does not provide a separate object. A temporary
172    --  object is created to act as the return object and an access to the
173    --  temporary is passed as an additional parameter of the call. This occurs
174    --  in contexts such as subprogram call actuals and object renamings.
175    --  Function_Call must denote either an N_Function_Call node for which
176    --  Is_Build_In_Place_Call is True, or else an N_Qualified_Expression node
177    --  applied to such a function call.
178
179    procedure Make_Build_In_Place_Call_In_Assignment
180      (Assign        : Node_Id;
181       Function_Call : Node_Id);
182    --  Ada 2005 (AI-318-02): Handle a call to a build-in-place function that
183    --  occurs as the right-hand side of an assignment statement by passing
184    --  access to the left-hand side as an additional parameter of the function
185    --  call. Assign must denote a N_Assignment_Statement. Function_Call must
186    --  denote either an N_Function_Call node for which Is_Build_In_Place_Call
187    --  is True, or an N_Qualified_Expression node applied to such a function
188    --  call.
189
190    procedure Make_Build_In_Place_Call_In_Object_Declaration
191      (Object_Decl   : Node_Id;
192       Function_Call : Node_Id);
193    --  Ada 2005 (AI-318-02): Handle a call to a build-in-place function that
194    --  occurs as the expression initializing an object declaration by
195    --  passing access to the declared object as an additional parameter of the
196    --  function call. Function_Call must denote either an N_Function_Call node
197    --  for which Is_Build_In_Place_Call is True, or an N_Qualified_Expression
198    --  node applied to such a function call.
199
200    function Needs_BIP_Finalization_Master (Func_Id : Entity_Id) return Boolean;
201    --  Ada 2005 (AI-318-02): Return True if the function needs an implicit
202    --  finalization master implicit parameter.
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_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".
213
214    procedure Add_Extra_Actual_To_Call
215      (Subprogram_Call : Node_Id;
216       Extra_Formal    : Entity_Id;
217       Extra_Actual    : Node_Id);
218    --  Adds Extra_Actual as a named parameter association for the formal
219    --  Extra_Formal in Subprogram_Call.
220
221 end Exp_Ch6;