1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2007, Free Software Foundation, Inc. --
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 2, 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 COPYING. If not, write --
19 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
27 -- Expand routines for chapter 6 constructs
29 with Types
; use Types
;
33 procedure Expand_N_Function_Call
(N
: Node_Id
);
34 procedure Expand_N_Subprogram_Body
(N
: Node_Id
);
35 procedure Expand_N_Subprogram_Body_Stub
(N
: Node_Id
);
36 procedure Expand_N_Subprogram_Declaration
(N
: Node_Id
);
37 procedure Expand_N_Procedure_Call_Statement
(N
: Node_Id
);
39 procedure Expand_Call
(N
: Node_Id
);
40 -- This procedure contains common processing for Expand_N_Function_Call,
41 -- Expand_N_Procedure_Statement, and Expand_N_Entry_Call.
43 procedure Freeze_Subprogram
(N
: Node_Id
);
44 -- generate the appropriate expansions related to Subprogram freeze
45 -- nodes (e. g. the filling of the corresponding Dispatch Table for
46 -- Primitive Operations)
48 -- The following type defines the various forms of allocation used for the
49 -- results of build-in-place function calls.
51 type BIP_Allocation_Form
is
58 type BIP_Formal_Kind
is
59 -- Ada 2005 (AI-318-02): This type defines the kinds of implicit extra
60 -- formals created for build-in-place functions. The order of the above
61 -- enumeration literals matches the order in which the formals are
62 -- declared. See Sem_Ch6.Create_Extra_Formals.
64 -- Present if result subtype is unconstrained, or if the result type
65 -- is tagged. Indicates whether the return object is allocated by the
66 -- caller or callee, and if the callee, whether to use the secondary
67 -- stack or the heap. See Create_Extra_Formals.
69 -- Present if result type has controlled parts. Pointer to caller's
72 -- Present if result type contains tasks. Master associated with
75 -- Present if result type contains tasks. Caller's activation chain.
77 -- Present for all build-in-place functions. Address at which to place
78 -- the return object, or null if BIP_Alloc_Form indicates
79 -- allocated by callee.
80 -- ??? We also need to be able to pass in some way to access a
81 -- user-defined storage pool at some point. And perhaps a constrained
84 function BIP_Formal_Suffix
(Kind
: BIP_Formal_Kind
) return String;
85 -- Ada 2005 (AI-318-02): Returns a string to be used as the suffix of names
86 -- for build-in-place formal parameters of the given kind.
88 function Build_In_Place_Formal
90 Kind
: BIP_Formal_Kind
) return Entity_Id
;
91 -- Ada 2005 (AI-318-02): Locates and returns the entity for the implicit
92 -- build-in-place formal parameter of the given kind associated with the
93 -- function Func, and returns its Entity_Id. It is a bug if not found; the
94 -- caller should ensure this is called only when the extra formal exists.
96 function Is_Build_In_Place_Function
(E
: Entity_Id
) return Boolean;
97 -- Ada 2005 (AI-318-02): Returns True if E denotes a function, generic
98 -- function, or access-to-function type whose result must be built in
99 -- place; otherwise returns False. For Ada 2005, this is currently
100 -- restricted to the set of functions whose result subtype is an inherently
101 -- limited type. In Ada 95, this must be False for inherently limited
102 -- result types (but currently returns False for all Ada 95 functions).
103 -- Eventually we plan to support build-in-place for nonlimited types.
104 -- Build-in-place is usually more efficient for large things, and less
105 -- efficient for small things. However, we never use build-in-place if the
106 -- convention is other than Ada, because that would disturb mixed-language
107 -- programs. Note that for the non-inherently-limited cases, we must make
108 -- the same decision for Ada 95 and 2005, so that mixed-dialect programs
111 function Is_Build_In_Place_Function_Call
(N
: Node_Id
) return Boolean;
112 -- Ada 2005 (AI-318-02): Returns True if N denotes a call to a function
113 -- that requires handling as a build-in-place call or is a qualified
114 -- expression applied to such a call; otherwise returns False.
116 function Is_Build_In_Place_Function_Return
(N
: Node_Id
) return Boolean;
117 -- Ada 2005 (AI-318-02): Returns True if N is an N_Return_Statement or
118 -- N_Extended_Return_Statement and it applies to a build-in-place function
119 -- or generic function.
121 procedure Make_Build_In_Place_Call_In_Allocator
122 (Allocator
: Node_Id
;
123 Function_Call
: Node_Id
);
124 -- Ada 2005 (AI-318-02): Handle a call to a build-in-place function that
125 -- occurs as the expression initializing an allocator, by passing access
126 -- to the allocated object as an additional parameter of the function call.
127 -- A new access object is declared that is initialized to the result of the
128 -- allocator, passed to the function, and the allocator is rewritten to
129 -- refer to that access object. Function_Call must denote either an
130 -- N_Function_Call node for which Is_Build_In_Place_Call is True, or else
131 -- an N_Qualified_Expression node applied to such a function call.
133 procedure Make_Build_In_Place_Call_In_Anonymous_Context
134 (Function_Call
: Node_Id
);
135 -- Ada 2005 (AI-318-02): Handle a call to a build-in-place function that
136 -- occurs in a context that does not provide a separate object. A temporary
137 -- object is created to act as the return object and an access to the
138 -- temporary is passed as an additional parameter of the call. This occurs
139 -- in contexts such as subprogram call actuals and object renamings.
140 -- Function_Call must denote either an N_Function_Call node for which
141 -- Is_Build_In_Place_Call is True, or else an N_Qualified_Expression node
142 -- applied to such a function call.
144 procedure Make_Build_In_Place_Call_In_Assignment
146 Function_Call
: Node_Id
);
147 -- Ada 2005 (AI-318-02): Handle a call to a build-in-place function that
148 -- occurs as the right-hand side of an assignment statement by passing
149 -- access to the left-hand side as an additional parameter of the function
150 -- call. Assign must denote a N_Assignment_Statement. Function_Call must
151 -- denote either an N_Function_Call node for which Is_Build_In_Place_Call
152 -- is True, or an N_Qualified_Expression node applied to such a function
155 procedure Make_Build_In_Place_Call_In_Object_Declaration
156 (Object_Decl
: Node_Id
;
157 Function_Call
: Node_Id
);
158 -- Ada 2005 (AI-318-02): Handle a call to a build-in-place function that
159 -- occurs as the expression initializing an object declaration by
160 -- passing access to the declared object as an additional parameter of the
161 -- function call. Function_Call must denote either an N_Function_Call node
162 -- for which Is_Build_In_Place_Call is True, or an N_Qualified_Expression
163 -- node applied to such a function call.