annotate gcc/ada/exp_ch6.ads @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents 84e7813d76e9
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 ------------------------------------------------------------------------------
kono
parents:
diff changeset
2 -- --
kono
parents:
diff changeset
3 -- GNAT COMPILER COMPONENTS --
kono
parents:
diff changeset
4 -- --
kono
parents:
diff changeset
5 -- E X P _ C H 6 --
kono
parents:
diff changeset
6 -- --
kono
parents:
diff changeset
7 -- S p e c --
kono
parents:
diff changeset
8 -- --
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
9 -- Copyright (C) 1992-2019, Free Software Foundation, Inc. --
111
kono
parents:
diff changeset
10 -- --
kono
parents:
diff changeset
11 -- GNAT is free software; you can redistribute it and/or modify it under --
kono
parents:
diff changeset
12 -- terms of the GNU General Public License as published by the Free Soft- --
kono
parents:
diff changeset
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
kono
parents:
diff changeset
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
kono
parents:
diff changeset
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
kono
parents:
diff changeset
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
kono
parents:
diff changeset
17 -- for more details. You should have received a copy of the GNU General --
kono
parents:
diff changeset
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
kono
parents:
diff changeset
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
kono
parents:
diff changeset
20 -- --
kono
parents:
diff changeset
21 -- GNAT was originally developed by the GNAT team at New York University. --
kono
parents:
diff changeset
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
kono
parents:
diff changeset
23 -- --
kono
parents:
diff changeset
24 ------------------------------------------------------------------------------
kono
parents:
diff changeset
25
kono
parents:
diff changeset
26 -- Expand routines for chapter 6 constructs
kono
parents:
diff changeset
27
kono
parents:
diff changeset
28 with Types; use Types;
kono
parents:
diff changeset
29
kono
parents:
diff changeset
30 package Exp_Ch6 is
kono
parents:
diff changeset
31
kono
parents:
diff changeset
32 procedure Expand_N_Extended_Return_Statement (N : Node_Id);
kono
parents:
diff changeset
33 procedure Expand_N_Function_Call (N : Node_Id);
kono
parents:
diff changeset
34 procedure Expand_N_Procedure_Call_Statement (N : Node_Id);
kono
parents:
diff changeset
35 procedure Expand_N_Simple_Return_Statement (N : Node_Id);
kono
parents:
diff changeset
36 procedure Expand_N_Subprogram_Body (N : Node_Id);
kono
parents:
diff changeset
37 procedure Expand_N_Subprogram_Body_Stub (N : Node_Id);
kono
parents:
diff changeset
38 procedure Expand_N_Subprogram_Declaration (N : Node_Id);
kono
parents:
diff changeset
39
kono
parents:
diff changeset
40 procedure Expand_Call (N : Node_Id);
kono
parents:
diff changeset
41 -- This procedure contains common processing for Expand_N_Function_Call,
kono
parents:
diff changeset
42 -- Expand_N_Procedure_Statement, and Expand_N_Entry_Call.
kono
parents:
diff changeset
43
kono
parents:
diff changeset
44 procedure Freeze_Subprogram (N : Node_Id);
kono
parents:
diff changeset
45 -- generate the appropriate expansions related to Subprogram freeze
kono
parents:
diff changeset
46 -- nodes (e.g. the filling of the corresponding Dispatch Table for
kono
parents:
diff changeset
47 -- Primitive Operations)
kono
parents:
diff changeset
48
kono
parents:
diff changeset
49 -- The following type defines the various forms of allocation used for the
kono
parents:
diff changeset
50 -- results of build-in-place function calls.
kono
parents:
diff changeset
51
kono
parents:
diff changeset
52 type BIP_Allocation_Form is
kono
parents:
diff changeset
53 (Unspecified,
kono
parents:
diff changeset
54 Caller_Allocation,
kono
parents:
diff changeset
55 Secondary_Stack,
kono
parents:
diff changeset
56 Global_Heap,
kono
parents:
diff changeset
57 User_Storage_Pool);
kono
parents:
diff changeset
58
kono
parents:
diff changeset
59 type BIP_Formal_Kind is
kono
parents:
diff changeset
60 -- Ada 2005 (AI-318-02): This type defines the kinds of implicit extra
kono
parents:
diff changeset
61 -- formals created for build-in-place functions. The order of these
kono
parents:
diff changeset
62 -- enumeration literals matches the order in which the formals are
kono
parents:
diff changeset
63 -- declared. See Sem_Ch6.Create_Extra_Formals.
kono
parents:
diff changeset
64
kono
parents:
diff changeset
65 (BIP_Alloc_Form,
kono
parents:
diff changeset
66 -- Present if result subtype is unconstrained or tagged. Indicates
kono
parents:
diff changeset
67 -- whether the return object is allocated by the caller or callee, and
kono
parents:
diff changeset
68 -- if the callee, whether to use the secondary stack or the heap. See
kono
parents:
diff changeset
69 -- Create_Extra_Formals.
kono
parents:
diff changeset
70
kono
parents:
diff changeset
71 BIP_Storage_Pool,
kono
parents:
diff changeset
72 -- Present if result subtype is unconstrained or tagged. If
kono
parents:
diff changeset
73 -- BIP_Alloc_Form = User_Storage_Pool, this is a pointer to the pool
kono
parents:
diff changeset
74 -- (of type access to Root_Storage_Pool'Class). Otherwise null.
kono
parents:
diff changeset
75
kono
parents:
diff changeset
76 BIP_Finalization_Master,
kono
parents:
diff changeset
77 -- Present if result type needs finalization. Pointer to caller's
kono
parents:
diff changeset
78 -- finalization master.
kono
parents:
diff changeset
79
kono
parents:
diff changeset
80 BIP_Task_Master,
kono
parents:
diff changeset
81 -- Present if result type contains tasks. Master associated with
kono
parents:
diff changeset
82 -- calling context.
kono
parents:
diff changeset
83
kono
parents:
diff changeset
84 BIP_Activation_Chain,
kono
parents:
diff changeset
85 -- Present if result type contains tasks. Caller's activation chain
kono
parents:
diff changeset
86
kono
parents:
diff changeset
87 BIP_Object_Access);
kono
parents:
diff changeset
88 -- Present for all build-in-place functions. Address at which to place
kono
parents:
diff changeset
89 -- the return object, or null if BIP_Alloc_Form indicates allocated by
kono
parents:
diff changeset
90 -- callee.
kono
parents:
diff changeset
91 --
kono
parents:
diff changeset
92 -- ??? We might also need to be able to pass in a constrained flag.
kono
parents:
diff changeset
93
kono
parents:
diff changeset
94 procedure Add_Extra_Actual_To_Call
kono
parents:
diff changeset
95 (Subprogram_Call : Node_Id;
kono
parents:
diff changeset
96 Extra_Formal : Entity_Id;
kono
parents:
diff changeset
97 Extra_Actual : Node_Id);
kono
parents:
diff changeset
98 -- Adds Extra_Actual as a named parameter association for the formal
kono
parents:
diff changeset
99 -- Extra_Formal in Subprogram_Call.
kono
parents:
diff changeset
100
kono
parents:
diff changeset
101 function BIP_Formal_Suffix (Kind : BIP_Formal_Kind) return String;
kono
parents:
diff changeset
102 -- Ada 2005 (AI-318-02): Returns a string to be used as the suffix of names
kono
parents:
diff changeset
103 -- for build-in-place formal parameters of the given kind.
kono
parents:
diff changeset
104
kono
parents:
diff changeset
105 function Build_In_Place_Formal
kono
parents:
diff changeset
106 (Func : Entity_Id;
kono
parents:
diff changeset
107 Kind : BIP_Formal_Kind) return Entity_Id;
kono
parents:
diff changeset
108 -- Ada 2005 (AI-318-02): Locates and returns the entity for the implicit
kono
parents:
diff changeset
109 -- build-in-place formal parameter of the given kind associated with the
kono
parents:
diff changeset
110 -- function Func, and returns its Entity_Id. It is a bug if not found; the
kono
parents:
diff changeset
111 -- caller should ensure this is called only when the extra formal exists.
kono
parents:
diff changeset
112
kono
parents:
diff changeset
113 function Build_Procedure_Body_Form
kono
parents:
diff changeset
114 (Func_Id : Entity_Id; Func_Body : Node_Id) return Node_Id;
kono
parents:
diff changeset
115 -- Create a procedure body which emulates the behavior of function Func_Id.
kono
parents:
diff changeset
116 -- Func_Body is the root of the body of the function before its analysis.
kono
parents:
diff changeset
117 -- The returned node is the root of the procedure body which will replace
kono
parents:
diff changeset
118 -- the original function body, which is not needed for the C program.
kono
parents:
diff changeset
119
kono
parents:
diff changeset
120 function Is_Build_In_Place_Result_Type (Typ : Entity_Id) return Boolean;
kono
parents:
diff changeset
121 -- Ada 2005 (AI-318-02): Returns True if functions returning the type use
kono
parents:
diff changeset
122 -- build-in-place protocols. For inherently limited types, this must be
kono
parents:
diff changeset
123 -- True in >= Ada 2005, and must be False in Ada 95. For other types, it
kono
parents:
diff changeset
124 -- can be True or False, and the decision should be based on efficiency,
kono
parents:
diff changeset
125 -- and should be the same for all language versions, so that mixed-dialect
kono
parents:
diff changeset
126 -- programs will work.
kono
parents:
diff changeset
127 --
kono
parents:
diff changeset
128 -- For inherently limited types in Ada 2005, True means that calls will
kono
parents:
diff changeset
129 -- actually be build-in-place in all cases. For other types, build-in-place
kono
parents:
diff changeset
130 -- will be used when possible, but we need to make a copy at the call site
kono
parents:
diff changeset
131 -- in some cases, notably assignment statements.
kono
parents:
diff changeset
132
kono
parents:
diff changeset
133 function Is_Build_In_Place_Function (E : Entity_Id) return Boolean;
kono
parents:
diff changeset
134 -- Ada 2005 (AI-318-02): Returns True if E denotes a function, generic
kono
parents:
diff changeset
135 -- function, or access-to-function type for which
kono
parents:
diff changeset
136 -- Is_Build_In_Place_Result_Type is True. However, we never use
kono
parents:
diff changeset
137 -- build-in-place if the convention is other than Ada, because that would
kono
parents:
diff changeset
138 -- disturb mixed-language programs.
kono
parents:
diff changeset
139
kono
parents:
diff changeset
140 function Is_Build_In_Place_Function_Call (N : Node_Id) return Boolean;
kono
parents:
diff changeset
141 -- Ada 2005 (AI-318-02): Returns True if N denotes a call to a function
kono
parents:
diff changeset
142 -- that requires handling as a build-in-place call (possibly qualified or
kono
parents:
diff changeset
143 -- converted).
kono
parents:
diff changeset
144
kono
parents:
diff changeset
145 function Is_Null_Procedure (Subp : Entity_Id) return Boolean;
kono
parents:
diff changeset
146 -- Predicate to recognize stubbed procedures and null procedures, which
kono
parents:
diff changeset
147 -- can be inlined unconditionally in all cases.
kono
parents:
diff changeset
148
kono
parents:
diff changeset
149 procedure Make_Build_In_Place_Call_In_Allocator
kono
parents:
diff changeset
150 (Allocator : Node_Id;
kono
parents:
diff changeset
151 Function_Call : Node_Id);
kono
parents:
diff changeset
152 -- Ada 2005 (AI-318-02): Handle a call to a build-in-place function that
kono
parents:
diff changeset
153 -- occurs as the expression initializing an allocator, by passing access
kono
parents:
diff changeset
154 -- to the allocated object as an additional parameter of the function call.
kono
parents:
diff changeset
155 -- A new access object is declared that is initialized to the result of the
kono
parents:
diff changeset
156 -- allocator, passed to the function, and the allocator is rewritten to
kono
parents:
diff changeset
157 -- refer to that access object. Function_Call must denote either an
kono
parents:
diff changeset
158 -- N_Function_Call node for which Is_Build_In_Place_Call is True, or else
kono
parents:
diff changeset
159 -- an N_Qualified_Expression node applied to such a function call.
kono
parents:
diff changeset
160
kono
parents:
diff changeset
161 procedure Make_Build_In_Place_Call_In_Anonymous_Context
kono
parents:
diff changeset
162 (Function_Call : Node_Id);
kono
parents:
diff changeset
163 -- Ada 2005 (AI-318-02): Handle a call to a build-in-place function that
kono
parents:
diff changeset
164 -- occurs in a context that does not provide a separate object. A temporary
kono
parents:
diff changeset
165 -- object is created to act as the return object and an access to the
kono
parents:
diff changeset
166 -- temporary is passed as an additional parameter of the call. This occurs
kono
parents:
diff changeset
167 -- in contexts such as subprogram call actuals and object renamings.
kono
parents:
diff changeset
168 -- Function_Call must denote either an N_Function_Call node for which
kono
parents:
diff changeset
169 -- Is_Build_In_Place_Call is True, or else an N_Qualified_Expression node
kono
parents:
diff changeset
170 -- applied to such a function call.
kono
parents:
diff changeset
171
kono
parents:
diff changeset
172 procedure Make_Build_In_Place_Call_In_Assignment
kono
parents:
diff changeset
173 (Assign : Node_Id;
kono
parents:
diff changeset
174 Function_Call : Node_Id);
kono
parents:
diff changeset
175 -- Ada 2005 (AI-318-02): Handle a call to a build-in-place function that
kono
parents:
diff changeset
176 -- occurs as the right-hand side of an assignment statement by passing
kono
parents:
diff changeset
177 -- access to the left-hand side as an additional parameter of the function
kono
parents:
diff changeset
178 -- call. Assign must denote a N_Assignment_Statement. Function_Call must
kono
parents:
diff changeset
179 -- denote either an N_Function_Call node for which Is_Build_In_Place_Call
kono
parents:
diff changeset
180 -- is True, or an N_Qualified_Expression node applied to such a function
kono
parents:
diff changeset
181 -- call.
kono
parents:
diff changeset
182
kono
parents:
diff changeset
183 procedure Make_Build_In_Place_Call_In_Object_Declaration
kono
parents:
diff changeset
184 (Obj_Decl : Node_Id;
kono
parents:
diff changeset
185 Function_Call : Node_Id);
kono
parents:
diff changeset
186 -- Ada 2005 (AI-318-02): Handle a call to a build-in-place function that
kono
parents:
diff changeset
187 -- occurs as the expression initializing an object declaration by
kono
parents:
diff changeset
188 -- passing access to the declared object as an additional parameter of the
kono
parents:
diff changeset
189 -- function call. Function_Call must denote either an N_Function_Call node
kono
parents:
diff changeset
190 -- for which Is_Build_In_Place_Call is True, or an N_Qualified_Expression
kono
parents:
diff changeset
191 -- node applied to such a function call.
kono
parents:
diff changeset
192
kono
parents:
diff changeset
193 procedure Make_Build_In_Place_Iface_Call_In_Allocator
kono
parents:
diff changeset
194 (Allocator : Node_Id;
kono
parents:
diff changeset
195 Function_Call : Node_Id);
kono
parents:
diff changeset
196 -- Ada 2005 (AI-318-02): Handle a call to a build-in-place function that
kono
parents:
diff changeset
197 -- occurs as the expression initializing an allocator, by passing access
kono
parents:
diff changeset
198 -- to the allocated object as an additional parameter of the function call.
kono
parents:
diff changeset
199 -- Function_Call must denote an expression containing a BIP function call
kono
parents:
diff changeset
200 -- and an enclosing call to Ada.Tags.Displace to displace the pointer to
kono
parents:
diff changeset
201 -- the returned BIP object to reference the secondary dispatch table of
kono
parents:
diff changeset
202 -- an interface.
kono
parents:
diff changeset
203
kono
parents:
diff changeset
204 procedure Make_Build_In_Place_Iface_Call_In_Anonymous_Context
kono
parents:
diff changeset
205 (Function_Call : Node_Id);
kono
parents:
diff changeset
206 -- Ada 2005 (AI-318-02): Handle a call to a build-in-place function that
kono
parents:
diff changeset
207 -- occurs in a context that does not provide a separate object. A temporary
kono
parents:
diff changeset
208 -- object is created to act as the return object and an access to the
kono
parents:
diff changeset
209 -- temporary is passed as an additional parameter of the call. This occurs
kono
parents:
diff changeset
210 -- in contexts such as subprogram call actuals and object renamings.
kono
parents:
diff changeset
211 -- Function_Call must denote an expression containing a BIP function call
kono
parents:
diff changeset
212 -- and an enclosing call to Ada.Tags.Displace to displace the pointer to
kono
parents:
diff changeset
213 -- the returned BIP object to reference the secondary dispatch table of
kono
parents:
diff changeset
214 -- an interface.
kono
parents:
diff changeset
215
kono
parents:
diff changeset
216 procedure Make_Build_In_Place_Iface_Call_In_Object_Declaration
kono
parents:
diff changeset
217 (Obj_Decl : Node_Id;
kono
parents:
diff changeset
218 Function_Call : Node_Id);
kono
parents:
diff changeset
219 -- Ada 2005 (AI-318-02): Handle a call to a build-in-place function that
kono
parents:
diff changeset
220 -- occurs as the expression initializing an object declaration by passing
kono
parents:
diff changeset
221 -- access to the declared object as an additional parameter of the function
kono
parents:
diff changeset
222 -- call. Function_Call must denote an expression containing a BIP function
kono
parents:
diff changeset
223 -- call and an enclosing call to Ada.Tags.Displace to displace the pointer
kono
parents:
diff changeset
224 -- to the returned BIP object to reference the secondary dispatch table of
kono
parents:
diff changeset
225 -- an interface.
kono
parents:
diff changeset
226
kono
parents:
diff changeset
227 procedure Make_CPP_Constructor_Call_In_Allocator
kono
parents:
diff changeset
228 (Allocator : Node_Id;
kono
parents:
diff changeset
229 Function_Call : Node_Id);
kono
parents:
diff changeset
230 -- Handle a call to a CPP constructor that occurs as the expression that
kono
parents:
diff changeset
231 -- initializes an allocator, by passing access to the allocated object as
kono
parents:
diff changeset
232 -- an additional parameter of the constructor call. A new access object is
kono
parents:
diff changeset
233 -- declared that is initialized to the result of the allocator, passed to
kono
parents:
diff changeset
234 -- the constructor, and the allocator is rewritten to refer to that access
kono
parents:
diff changeset
235 -- object. Function_Call must denote a call to a CPP_Constructor function.
kono
parents:
diff changeset
236
kono
parents:
diff changeset
237 function Needs_BIP_Alloc_Form (Func_Id : Entity_Id) return Boolean;
kono
parents:
diff changeset
238 -- Ada 2005 (AI-318-02): Return True if the function needs an implicit
kono
parents:
diff changeset
239 -- BIP_Alloc_Form parameter (see type BIP_Formal_Kind).
kono
parents:
diff changeset
240
kono
parents:
diff changeset
241 function Needs_BIP_Finalization_Master (Func_Id : Entity_Id) return Boolean;
kono
parents:
diff changeset
242 -- Ada 2005 (AI-318-02): Return True if the result subtype of function
kono
parents:
diff changeset
243 -- Func_Id might need finalization actions. This includes build-in-place
kono
parents:
diff changeset
244 -- functions with tagged result types, since they can be invoked via
kono
parents:
diff changeset
245 -- dispatching calls, and descendant types may require finalization.
kono
parents:
diff changeset
246
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
247 function Needs_BIP_Task_Actuals (Func_Id : Entity_Id) return Boolean;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
248 -- Return True if the function returns an object of a type that has tasks.
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
249
111
kono
parents:
diff changeset
250 function Needs_Result_Accessibility_Level
kono
parents:
diff changeset
251 (Func_Id : Entity_Id) return Boolean;
kono
parents:
diff changeset
252 -- Ada 2012 (AI05-0234): Return True if the function needs an implicit
kono
parents:
diff changeset
253 -- parameter to identify the accessibility level of the function result
kono
parents:
diff changeset
254 -- "determined by the point of call".
kono
parents:
diff changeset
255
kono
parents:
diff changeset
256 function Unqual_BIP_Iface_Function_Call (Expr : Node_Id) return Node_Id;
kono
parents:
diff changeset
257 -- Return the inner BIP function call removing any qualification from Expr
kono
parents:
diff changeset
258 -- including qualified expressions, type conversions, references, unchecked
kono
parents:
diff changeset
259 -- conversions and calls to displace the pointer to the object, if Expr is
kono
parents:
diff changeset
260 -- an expression containing a call displacing the pointer to the BIP object
kono
parents:
diff changeset
261 -- to reference the secondary dispatch table of an interface; otherwise
kono
parents:
diff changeset
262 -- return Empty.
kono
parents:
diff changeset
263
kono
parents:
diff changeset
264 end Exp_Ch6;