OSDN Git Service

2010-10-18 Robert Dewar <dewar@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-2010, 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_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 the above
62    --  enumeration literals matches the order in which the formals are
63    --  declared. See Sem_Ch6.Create_Extra_Formals.
64      (BIP_Alloc_Form,
65       --  Present if result subtype is unconstrained, or if the result type
66       --  is tagged. Indicates whether the return object is allocated by the
67       --  caller or callee, and if the callee, whether to use the secondary
68       --  stack or the heap. See Create_Extra_Formals.
69       BIP_Final_List,
70       --  Present if result type needs finalization. Pointer to caller's
71       --  finalization list.
72       BIP_Master,
73       --  Present if result type contains tasks. Master associated with
74       --  calling context.
75       BIP_Activation_Chain,
76       --  Present if result type contains tasks. Caller's activation chain
77       BIP_Object_Access);
78       --  Present for all build-in-place functions. Address at which to place
79       --  the return object, or null if BIP_Alloc_Form indicates
80       --  allocated by callee.
81       --  ??? We also need to be able to pass in some way to access a
82       --  user-defined storage pool at some point. And perhaps a constrained
83       --  flag.
84
85    function BIP_Formal_Suffix (Kind : BIP_Formal_Kind) return String;
86    --  Ada 2005 (AI-318-02): Returns a string to be used as the suffix of names
87    --  for build-in-place formal parameters of the given kind.
88
89    function Build_In_Place_Formal
90      (Func : Entity_Id;
91       Kind : BIP_Formal_Kind) return Entity_Id;
92    --  Ada 2005 (AI-318-02): Locates and returns the entity for the implicit
93    --  build-in-place formal parameter of the given kind associated with the
94    --  function Func, and returns its Entity_Id. It is a bug if not found; the
95    --  caller should ensure this is called only when the extra formal exists.
96
97    function Is_Build_In_Place_Function (E : Entity_Id) return Boolean;
98    --  Ada 2005 (AI-318-02): Returns True if E denotes a function, generic
99    --  function, or access-to-function type whose result must be built in
100    --  place; otherwise returns False. For Ada 2005, this is currently
101    --  restricted to the set of functions whose result subtype is an inherently
102    --  limited type. In Ada 95, this must be False for inherently limited
103    --  result types (but currently returns False for all Ada 95 functions).
104    --  Eventually we plan to support build-in-place for nonlimited types.
105    --  Build-in-place is usually more efficient for large things, and less
106    --  efficient for small things. However, we never use build-in-place if the
107    --  convention is other than Ada, because that would disturb mixed-language
108    --  programs. Note that for the non-inherently-limited cases, we must make
109    --  the same decision for Ada 95 and 2005, so that mixed-dialect programs
110    --  will work.
111
112    function Is_Build_In_Place_Function_Call (N : Node_Id) return Boolean;
113    --  Ada 2005 (AI-318-02): Returns True if N denotes a call to a function
114    --  that requires handling as a build-in-place call or is a qualified
115    --  expression applied to such a call; otherwise returns False.
116
117    procedure Make_Build_In_Place_Call_In_Allocator
118      (Allocator     : Node_Id;
119       Function_Call : Node_Id);
120    --  Ada 2005 (AI-318-02): Handle a call to a build-in-place function that
121    --  occurs as the expression initializing an allocator, by passing access
122    --  to the allocated object as an additional parameter of the function call.
123    --  A new access object is declared that is initialized to the result of the
124    --  allocator, passed to the function, and the allocator is rewritten to
125    --  refer to that access object. Function_Call must denote either an
126    --  N_Function_Call node for which Is_Build_In_Place_Call is True, or else
127    --  an N_Qualified_Expression node applied to such a function call.
128
129    procedure Make_Build_In_Place_Call_In_Anonymous_Context
130      (Function_Call : Node_Id);
131    --  Ada 2005 (AI-318-02): Handle a call to a build-in-place function that
132    --  occurs in a context that does not provide a separate object. A temporary
133    --  object is created to act as the return object and an access to the
134    --  temporary is passed as an additional parameter of the call. This occurs
135    --  in contexts such as subprogram call actuals and object renamings.
136    --  Function_Call must denote either an N_Function_Call node for which
137    --  Is_Build_In_Place_Call is True, or else an N_Qualified_Expression node
138    --  applied to such a function call.
139
140    procedure Make_Build_In_Place_Call_In_Assignment
141      (Assign        : Node_Id;
142       Function_Call : Node_Id);
143    --  Ada 2005 (AI-318-02): Handle a call to a build-in-place function that
144    --  occurs as the right-hand side of an assignment statement by passing
145    --  access to the left-hand side as an additional parameter of the function
146    --  call. Assign must denote a N_Assignment_Statement. Function_Call must
147    --  denote either an N_Function_Call node for which Is_Build_In_Place_Call
148    --  is True, or an N_Qualified_Expression node applied to such a function
149    --  call.
150
151    procedure Make_Build_In_Place_Call_In_Object_Declaration
152      (Object_Decl   : Node_Id;
153       Function_Call : Node_Id);
154    --  Ada 2005 (AI-318-02): Handle a call to a build-in-place function that
155    --  occurs as the expression initializing an object declaration by
156    --  passing access to the declared object as an additional parameter of the
157    --  function call. Function_Call must denote either an N_Function_Call node
158    --  for which Is_Build_In_Place_Call is True, or an N_Qualified_Expression
159    --  node applied to such a function call.
160
161    function Needs_BIP_Final_List (E : Entity_Id) return Boolean;
162    --  ???pragma Precondition (Is_Build_In_Place_Function (E));
163    --  Ada 2005 (AI-318-02): Returns True if the function needs the
164    --  BIP_Final_List implicit parameter.
165
166 end Exp_Ch6;