annotate gcc/ada/sem_disp.adb @ 143:76e1cf5455ef

add cbc_gc test
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sun, 23 Dec 2018 19:24:05 +0900
parents 84e7813d76e9
children 1830386684a0
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 -- S E M _ D I S P --
kono
parents:
diff changeset
6 -- --
kono
parents:
diff changeset
7 -- B o d y --
kono
parents:
diff changeset
8 -- --
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
9 -- Copyright (C) 1992-2018, 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 with Atree; use Atree;
kono
parents:
diff changeset
27 with Debug; use Debug;
kono
parents:
diff changeset
28 with Elists; use Elists;
kono
parents:
diff changeset
29 with Einfo; use Einfo;
kono
parents:
diff changeset
30 with Exp_Disp; use Exp_Disp;
kono
parents:
diff changeset
31 with Exp_Util; use Exp_Util;
kono
parents:
diff changeset
32 with Exp_Ch7; use Exp_Ch7;
kono
parents:
diff changeset
33 with Exp_Tss; use Exp_Tss;
kono
parents:
diff changeset
34 with Errout; use Errout;
kono
parents:
diff changeset
35 with Lib.Xref; use Lib.Xref;
kono
parents:
diff changeset
36 with Namet; use Namet;
kono
parents:
diff changeset
37 with Nlists; use Nlists;
kono
parents:
diff changeset
38 with Nmake; use Nmake;
kono
parents:
diff changeset
39 with Opt; use Opt;
kono
parents:
diff changeset
40 with Output; use Output;
kono
parents:
diff changeset
41 with Restrict; use Restrict;
kono
parents:
diff changeset
42 with Rident; use Rident;
kono
parents:
diff changeset
43 with Sem; use Sem;
kono
parents:
diff changeset
44 with Sem_Aux; use Sem_Aux;
kono
parents:
diff changeset
45 with Sem_Ch3; use Sem_Ch3;
kono
parents:
diff changeset
46 with Sem_Ch6; use Sem_Ch6;
kono
parents:
diff changeset
47 with Sem_Ch8; use Sem_Ch8;
kono
parents:
diff changeset
48 with Sem_Eval; use Sem_Eval;
kono
parents:
diff changeset
49 with Sem_Type; use Sem_Type;
kono
parents:
diff changeset
50 with Sem_Util; use Sem_Util;
kono
parents:
diff changeset
51 with Snames; use Snames;
kono
parents:
diff changeset
52 with Sinfo; use Sinfo;
kono
parents:
diff changeset
53 with Tbuild; use Tbuild;
kono
parents:
diff changeset
54 with Uintp; use Uintp;
kono
parents:
diff changeset
55 with Warnsw; use Warnsw;
kono
parents:
diff changeset
56
kono
parents:
diff changeset
57 package body Sem_Disp is
kono
parents:
diff changeset
58
kono
parents:
diff changeset
59 -----------------------
kono
parents:
diff changeset
60 -- Local Subprograms --
kono
parents:
diff changeset
61 -----------------------
kono
parents:
diff changeset
62
kono
parents:
diff changeset
63 procedure Add_Dispatching_Operation
kono
parents:
diff changeset
64 (Tagged_Type : Entity_Id;
kono
parents:
diff changeset
65 New_Op : Entity_Id);
kono
parents:
diff changeset
66 -- Add New_Op in the list of primitive operations of Tagged_Type
kono
parents:
diff changeset
67
kono
parents:
diff changeset
68 function Check_Controlling_Type
kono
parents:
diff changeset
69 (T : Entity_Id;
kono
parents:
diff changeset
70 Subp : Entity_Id) return Entity_Id;
kono
parents:
diff changeset
71 -- T is the tagged type of a formal parameter or the result of Subp.
kono
parents:
diff changeset
72 -- If the subprogram has a controlling parameter or result that matches
kono
parents:
diff changeset
73 -- the type, then returns the tagged type of that parameter or result
kono
parents:
diff changeset
74 -- (returning the designated tagged type in the case of an access
kono
parents:
diff changeset
75 -- parameter); otherwise returns empty.
kono
parents:
diff changeset
76
kono
parents:
diff changeset
77 function Find_Hidden_Overridden_Primitive (S : Entity_Id) return Entity_Id;
kono
parents:
diff changeset
78 -- [Ada 2012:AI-0125] Find an inherited hidden primitive of the dispatching
kono
parents:
diff changeset
79 -- type of S that has the same name of S, a type-conformant profile, an
kono
parents:
diff changeset
80 -- original corresponding operation O that is a primitive of a visible
kono
parents:
diff changeset
81 -- ancestor of the dispatching type of S and O is visible at the point of
kono
parents:
diff changeset
82 -- of declaration of S. If the entity is found the Alias of S is set to the
kono
parents:
diff changeset
83 -- original corresponding operation S and its Overridden_Operation is set
kono
parents:
diff changeset
84 -- to the found entity; otherwise return Empty.
kono
parents:
diff changeset
85 --
kono
parents:
diff changeset
86 -- This routine does not search for non-hidden primitives since they are
kono
parents:
diff changeset
87 -- covered by the normal Ada 2005 rules.
kono
parents:
diff changeset
88
kono
parents:
diff changeset
89 function Is_Inherited_Public_Operation (Op : Entity_Id) return Boolean;
kono
parents:
diff changeset
90 -- Check whether a primitive operation is inherited from an operation
kono
parents:
diff changeset
91 -- declared in the visible part of its package.
kono
parents:
diff changeset
92
kono
parents:
diff changeset
93 -------------------------------
kono
parents:
diff changeset
94 -- Add_Dispatching_Operation --
kono
parents:
diff changeset
95 -------------------------------
kono
parents:
diff changeset
96
kono
parents:
diff changeset
97 procedure Add_Dispatching_Operation
kono
parents:
diff changeset
98 (Tagged_Type : Entity_Id;
kono
parents:
diff changeset
99 New_Op : Entity_Id)
kono
parents:
diff changeset
100 is
kono
parents:
diff changeset
101 List : constant Elist_Id := Primitive_Operations (Tagged_Type);
kono
parents:
diff changeset
102
kono
parents:
diff changeset
103 begin
kono
parents:
diff changeset
104 -- The dispatching operation may already be on the list, if it is the
kono
parents:
diff changeset
105 -- wrapper for an inherited function of a null extension (see Exp_Ch3
kono
parents:
diff changeset
106 -- for the construction of function wrappers). The list of primitive
kono
parents:
diff changeset
107 -- operations must not contain duplicates.
kono
parents:
diff changeset
108
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
109 -- The Default_Initial_Condition and invariant procedures are not added
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
110 -- to the list of primitives even when they are generated for a tagged
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
111 -- type. These routines must not be targets of dispatching calls and
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
112 -- therefore must not appear in the dispatch table because they already
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
113 -- utilize class-wide-precondition semantics to handle inheritance and
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
114 -- overriding.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
115
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
116 if Is_Suitable_Primitive (New_Op) then
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
117 Append_Unique_Elmt (New_Op, List);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
118 end if;
111
kono
parents:
diff changeset
119 end Add_Dispatching_Operation;
kono
parents:
diff changeset
120
kono
parents:
diff changeset
121 --------------------------
kono
parents:
diff changeset
122 -- Covered_Interface_Op --
kono
parents:
diff changeset
123 --------------------------
kono
parents:
diff changeset
124
kono
parents:
diff changeset
125 function Covered_Interface_Op (Prim : Entity_Id) return Entity_Id is
kono
parents:
diff changeset
126 Tagged_Type : constant Entity_Id := Find_Dispatching_Type (Prim);
kono
parents:
diff changeset
127 Elmt : Elmt_Id;
kono
parents:
diff changeset
128 E : Entity_Id;
kono
parents:
diff changeset
129
kono
parents:
diff changeset
130 begin
kono
parents:
diff changeset
131 pragma Assert (Is_Dispatching_Operation (Prim));
kono
parents:
diff changeset
132
kono
parents:
diff changeset
133 -- Although this is a dispatching primitive we must check if its
kono
parents:
diff changeset
134 -- dispatching type is available because it may be the primitive
kono
parents:
diff changeset
135 -- of a private type not defined as tagged in its partial view.
kono
parents:
diff changeset
136
kono
parents:
diff changeset
137 if Present (Tagged_Type) and then Has_Interfaces (Tagged_Type) then
kono
parents:
diff changeset
138
kono
parents:
diff changeset
139 -- If the tagged type is frozen then the internal entities associated
kono
parents:
diff changeset
140 -- with interfaces are available in the list of primitives of the
kono
parents:
diff changeset
141 -- tagged type and can be used to speed up this search.
kono
parents:
diff changeset
142
kono
parents:
diff changeset
143 if Is_Frozen (Tagged_Type) then
kono
parents:
diff changeset
144 Elmt := First_Elmt (Primitive_Operations (Tagged_Type));
kono
parents:
diff changeset
145 while Present (Elmt) loop
kono
parents:
diff changeset
146 E := Node (Elmt);
kono
parents:
diff changeset
147
kono
parents:
diff changeset
148 if Present (Interface_Alias (E))
kono
parents:
diff changeset
149 and then Alias (E) = Prim
kono
parents:
diff changeset
150 then
kono
parents:
diff changeset
151 return Interface_Alias (E);
kono
parents:
diff changeset
152 end if;
kono
parents:
diff changeset
153
kono
parents:
diff changeset
154 Next_Elmt (Elmt);
kono
parents:
diff changeset
155 end loop;
kono
parents:
diff changeset
156
kono
parents:
diff changeset
157 -- Otherwise we must collect all the interface primitives and check
kono
parents:
diff changeset
158 -- if the Prim overrides (implements) some interface primitive.
kono
parents:
diff changeset
159
kono
parents:
diff changeset
160 else
kono
parents:
diff changeset
161 declare
kono
parents:
diff changeset
162 Ifaces_List : Elist_Id;
kono
parents:
diff changeset
163 Iface_Elmt : Elmt_Id;
kono
parents:
diff changeset
164 Iface : Entity_Id;
kono
parents:
diff changeset
165 Iface_Prim : Entity_Id;
kono
parents:
diff changeset
166
kono
parents:
diff changeset
167 begin
kono
parents:
diff changeset
168 Collect_Interfaces (Tagged_Type, Ifaces_List);
kono
parents:
diff changeset
169 Iface_Elmt := First_Elmt (Ifaces_List);
kono
parents:
diff changeset
170 while Present (Iface_Elmt) loop
kono
parents:
diff changeset
171 Iface := Node (Iface_Elmt);
kono
parents:
diff changeset
172
kono
parents:
diff changeset
173 Elmt := First_Elmt (Primitive_Operations (Iface));
kono
parents:
diff changeset
174 while Present (Elmt) loop
kono
parents:
diff changeset
175 Iface_Prim := Node (Elmt);
kono
parents:
diff changeset
176
kono
parents:
diff changeset
177 if Chars (Iface_Prim) = Chars (Prim)
kono
parents:
diff changeset
178 and then Is_Interface_Conformant
kono
parents:
diff changeset
179 (Tagged_Type, Iface_Prim, Prim)
kono
parents:
diff changeset
180 then
kono
parents:
diff changeset
181 return Iface_Prim;
kono
parents:
diff changeset
182 end if;
kono
parents:
diff changeset
183
kono
parents:
diff changeset
184 Next_Elmt (Elmt);
kono
parents:
diff changeset
185 end loop;
kono
parents:
diff changeset
186
kono
parents:
diff changeset
187 Next_Elmt (Iface_Elmt);
kono
parents:
diff changeset
188 end loop;
kono
parents:
diff changeset
189 end;
kono
parents:
diff changeset
190 end if;
kono
parents:
diff changeset
191 end if;
kono
parents:
diff changeset
192
kono
parents:
diff changeset
193 return Empty;
kono
parents:
diff changeset
194 end Covered_Interface_Op;
kono
parents:
diff changeset
195
kono
parents:
diff changeset
196 -------------------------------
kono
parents:
diff changeset
197 -- Check_Controlling_Formals --
kono
parents:
diff changeset
198 -------------------------------
kono
parents:
diff changeset
199
kono
parents:
diff changeset
200 procedure Check_Controlling_Formals
kono
parents:
diff changeset
201 (Typ : Entity_Id;
kono
parents:
diff changeset
202 Subp : Entity_Id)
kono
parents:
diff changeset
203 is
kono
parents:
diff changeset
204 Formal : Entity_Id;
kono
parents:
diff changeset
205 Ctrl_Type : Entity_Id;
kono
parents:
diff changeset
206
kono
parents:
diff changeset
207 begin
kono
parents:
diff changeset
208 Formal := First_Formal (Subp);
kono
parents:
diff changeset
209 while Present (Formal) loop
kono
parents:
diff changeset
210 Ctrl_Type := Check_Controlling_Type (Etype (Formal), Subp);
kono
parents:
diff changeset
211
kono
parents:
diff changeset
212 if Present (Ctrl_Type) then
kono
parents:
diff changeset
213
kono
parents:
diff changeset
214 -- When controlling type is concurrent and declared within a
kono
parents:
diff changeset
215 -- generic or inside an instance use corresponding record type.
kono
parents:
diff changeset
216
kono
parents:
diff changeset
217 if Is_Concurrent_Type (Ctrl_Type)
kono
parents:
diff changeset
218 and then Present (Corresponding_Record_Type (Ctrl_Type))
kono
parents:
diff changeset
219 then
kono
parents:
diff changeset
220 Ctrl_Type := Corresponding_Record_Type (Ctrl_Type);
kono
parents:
diff changeset
221 end if;
kono
parents:
diff changeset
222
kono
parents:
diff changeset
223 if Ctrl_Type = Typ then
kono
parents:
diff changeset
224 Set_Is_Controlling_Formal (Formal);
kono
parents:
diff changeset
225
kono
parents:
diff changeset
226 -- Ada 2005 (AI-231): Anonymous access types that are used in
kono
parents:
diff changeset
227 -- controlling parameters exclude null because it is necessary
kono
parents:
diff changeset
228 -- to read the tag to dispatch, and null has no tag.
kono
parents:
diff changeset
229
kono
parents:
diff changeset
230 if Ekind (Etype (Formal)) = E_Anonymous_Access_Type then
kono
parents:
diff changeset
231 Set_Can_Never_Be_Null (Etype (Formal));
kono
parents:
diff changeset
232 Set_Is_Known_Non_Null (Etype (Formal));
kono
parents:
diff changeset
233 end if;
kono
parents:
diff changeset
234
kono
parents:
diff changeset
235 -- Check that the parameter's nominal subtype statically
kono
parents:
diff changeset
236 -- matches the first subtype.
kono
parents:
diff changeset
237
kono
parents:
diff changeset
238 if Ekind (Etype (Formal)) = E_Anonymous_Access_Type then
kono
parents:
diff changeset
239 if not Subtypes_Statically_Match
kono
parents:
diff changeset
240 (Typ, Designated_Type (Etype (Formal)))
kono
parents:
diff changeset
241 then
kono
parents:
diff changeset
242 Error_Msg_N
kono
parents:
diff changeset
243 ("parameter subtype does not match controlling type",
kono
parents:
diff changeset
244 Formal);
kono
parents:
diff changeset
245 end if;
kono
parents:
diff changeset
246
kono
parents:
diff changeset
247 -- Within a predicate function, the formal may be a subtype
kono
parents:
diff changeset
248 -- of a tagged type, given that the predicate is expressed
kono
parents:
diff changeset
249 -- in terms of the subtype.
kono
parents:
diff changeset
250
kono
parents:
diff changeset
251 elsif not Subtypes_Statically_Match (Typ, Etype (Formal))
kono
parents:
diff changeset
252 and then not Is_Predicate_Function (Subp)
kono
parents:
diff changeset
253 then
kono
parents:
diff changeset
254 Error_Msg_N
kono
parents:
diff changeset
255 ("parameter subtype does not match controlling type",
kono
parents:
diff changeset
256 Formal);
kono
parents:
diff changeset
257 end if;
kono
parents:
diff changeset
258
kono
parents:
diff changeset
259 if Present (Default_Value (Formal)) then
kono
parents:
diff changeset
260
kono
parents:
diff changeset
261 -- In Ada 2005, access parameters can have defaults
kono
parents:
diff changeset
262
kono
parents:
diff changeset
263 if Ekind (Etype (Formal)) = E_Anonymous_Access_Type
kono
parents:
diff changeset
264 and then Ada_Version < Ada_2005
kono
parents:
diff changeset
265 then
kono
parents:
diff changeset
266 Error_Msg_N
kono
parents:
diff changeset
267 ("default not allowed for controlling access parameter",
kono
parents:
diff changeset
268 Default_Value (Formal));
kono
parents:
diff changeset
269
kono
parents:
diff changeset
270 elsif not Is_Tag_Indeterminate (Default_Value (Formal)) then
kono
parents:
diff changeset
271 Error_Msg_N
kono
parents:
diff changeset
272 ("default expression must be a tag indeterminate" &
kono
parents:
diff changeset
273 " function call", Default_Value (Formal));
kono
parents:
diff changeset
274 end if;
kono
parents:
diff changeset
275 end if;
kono
parents:
diff changeset
276
kono
parents:
diff changeset
277 elsif Comes_From_Source (Subp) then
kono
parents:
diff changeset
278 Error_Msg_N
kono
parents:
diff changeset
279 ("operation can be dispatching in only one type", Subp);
kono
parents:
diff changeset
280 end if;
kono
parents:
diff changeset
281 end if;
kono
parents:
diff changeset
282
kono
parents:
diff changeset
283 Next_Formal (Formal);
kono
parents:
diff changeset
284 end loop;
kono
parents:
diff changeset
285
kono
parents:
diff changeset
286 if Ekind_In (Subp, E_Function, E_Generic_Function) then
kono
parents:
diff changeset
287 Ctrl_Type := Check_Controlling_Type (Etype (Subp), Subp);
kono
parents:
diff changeset
288
kono
parents:
diff changeset
289 if Present (Ctrl_Type) then
kono
parents:
diff changeset
290 if Ctrl_Type = Typ then
kono
parents:
diff changeset
291 Set_Has_Controlling_Result (Subp);
kono
parents:
diff changeset
292
kono
parents:
diff changeset
293 -- Check that result subtype statically matches first subtype
kono
parents:
diff changeset
294 -- (Ada 2005): Subp may have a controlling access result.
kono
parents:
diff changeset
295
kono
parents:
diff changeset
296 if Subtypes_Statically_Match (Typ, Etype (Subp))
kono
parents:
diff changeset
297 or else (Ekind (Etype (Subp)) = E_Anonymous_Access_Type
kono
parents:
diff changeset
298 and then
kono
parents:
diff changeset
299 Subtypes_Statically_Match
kono
parents:
diff changeset
300 (Typ, Designated_Type (Etype (Subp))))
kono
parents:
diff changeset
301 then
kono
parents:
diff changeset
302 null;
kono
parents:
diff changeset
303
kono
parents:
diff changeset
304 else
kono
parents:
diff changeset
305 Error_Msg_N
kono
parents:
diff changeset
306 ("result subtype does not match controlling type", Subp);
kono
parents:
diff changeset
307 end if;
kono
parents:
diff changeset
308
kono
parents:
diff changeset
309 elsif Comes_From_Source (Subp) then
kono
parents:
diff changeset
310 Error_Msg_N
kono
parents:
diff changeset
311 ("operation can be dispatching in only one type", Subp);
kono
parents:
diff changeset
312 end if;
kono
parents:
diff changeset
313 end if;
kono
parents:
diff changeset
314 end if;
kono
parents:
diff changeset
315 end Check_Controlling_Formals;
kono
parents:
diff changeset
316
kono
parents:
diff changeset
317 ----------------------------
kono
parents:
diff changeset
318 -- Check_Controlling_Type --
kono
parents:
diff changeset
319 ----------------------------
kono
parents:
diff changeset
320
kono
parents:
diff changeset
321 function Check_Controlling_Type
kono
parents:
diff changeset
322 (T : Entity_Id;
kono
parents:
diff changeset
323 Subp : Entity_Id) return Entity_Id
kono
parents:
diff changeset
324 is
kono
parents:
diff changeset
325 Tagged_Type : Entity_Id := Empty;
kono
parents:
diff changeset
326
kono
parents:
diff changeset
327 begin
kono
parents:
diff changeset
328 if Is_Tagged_Type (T) then
kono
parents:
diff changeset
329 if Is_First_Subtype (T) then
kono
parents:
diff changeset
330 Tagged_Type := T;
kono
parents:
diff changeset
331 else
kono
parents:
diff changeset
332 Tagged_Type := Base_Type (T);
kono
parents:
diff changeset
333 end if;
kono
parents:
diff changeset
334
kono
parents:
diff changeset
335 -- If the type is incomplete, it may have been declared without a
kono
parents:
diff changeset
336 -- Tagged indication, but the full view may be tagged, in which case
kono
parents:
diff changeset
337 -- that is the controlling type of the subprogram. This is one of the
kono
parents:
diff changeset
338 -- approx. 579 places in the language where a lookahead would help.
kono
parents:
diff changeset
339
kono
parents:
diff changeset
340 elsif Ekind (T) = E_Incomplete_Type
kono
parents:
diff changeset
341 and then Present (Full_View (T))
kono
parents:
diff changeset
342 and then Is_Tagged_Type (Full_View (T))
kono
parents:
diff changeset
343 then
kono
parents:
diff changeset
344 Set_Is_Tagged_Type (T);
kono
parents:
diff changeset
345 Tagged_Type := Full_View (T);
kono
parents:
diff changeset
346
kono
parents:
diff changeset
347 elsif Ekind (T) = E_Anonymous_Access_Type
kono
parents:
diff changeset
348 and then Is_Tagged_Type (Designated_Type (T))
kono
parents:
diff changeset
349 then
kono
parents:
diff changeset
350 if Ekind (Designated_Type (T)) /= E_Incomplete_Type then
kono
parents:
diff changeset
351 if Is_First_Subtype (Designated_Type (T)) then
kono
parents:
diff changeset
352 Tagged_Type := Designated_Type (T);
kono
parents:
diff changeset
353 else
kono
parents:
diff changeset
354 Tagged_Type := Base_Type (Designated_Type (T));
kono
parents:
diff changeset
355 end if;
kono
parents:
diff changeset
356
kono
parents:
diff changeset
357 -- Ada 2005: an incomplete type can be tagged. An operation with an
kono
parents:
diff changeset
358 -- access parameter of the type is dispatching.
kono
parents:
diff changeset
359
kono
parents:
diff changeset
360 elsif Scope (Designated_Type (T)) = Current_Scope then
kono
parents:
diff changeset
361 Tagged_Type := Designated_Type (T);
kono
parents:
diff changeset
362
kono
parents:
diff changeset
363 -- Ada 2005 (AI-50217)
kono
parents:
diff changeset
364
kono
parents:
diff changeset
365 elsif From_Limited_With (Designated_Type (T))
kono
parents:
diff changeset
366 and then Has_Non_Limited_View (Designated_Type (T))
kono
parents:
diff changeset
367 and then Scope (Designated_Type (T)) = Scope (Subp)
kono
parents:
diff changeset
368 then
kono
parents:
diff changeset
369 if Is_First_Subtype (Non_Limited_View (Designated_Type (T))) then
kono
parents:
diff changeset
370 Tagged_Type := Non_Limited_View (Designated_Type (T));
kono
parents:
diff changeset
371 else
kono
parents:
diff changeset
372 Tagged_Type := Base_Type (Non_Limited_View
kono
parents:
diff changeset
373 (Designated_Type (T)));
kono
parents:
diff changeset
374 end if;
kono
parents:
diff changeset
375 end if;
kono
parents:
diff changeset
376 end if;
kono
parents:
diff changeset
377
kono
parents:
diff changeset
378 if No (Tagged_Type) or else Is_Class_Wide_Type (Tagged_Type) then
kono
parents:
diff changeset
379 return Empty;
kono
parents:
diff changeset
380
kono
parents:
diff changeset
381 -- The dispatching type and the primitive operation must be defined in
kono
parents:
diff changeset
382 -- the same scope, except in the case of internal operations and formal
kono
parents:
diff changeset
383 -- abstract subprograms.
kono
parents:
diff changeset
384
kono
parents:
diff changeset
385 elsif ((Scope (Subp) = Scope (Tagged_Type) or else Is_Internal (Subp))
kono
parents:
diff changeset
386 and then (not Is_Generic_Type (Tagged_Type)
kono
parents:
diff changeset
387 or else not Comes_From_Source (Subp)))
kono
parents:
diff changeset
388 or else
kono
parents:
diff changeset
389 (Is_Formal_Subprogram (Subp) and then Is_Abstract_Subprogram (Subp))
kono
parents:
diff changeset
390 or else
kono
parents:
diff changeset
391 (Nkind (Parent (Parent (Subp))) = N_Subprogram_Renaming_Declaration
kono
parents:
diff changeset
392 and then
kono
parents:
diff changeset
393 Present (Corresponding_Formal_Spec (Parent (Parent (Subp))))
kono
parents:
diff changeset
394 and then
kono
parents:
diff changeset
395 Is_Abstract_Subprogram (Subp))
kono
parents:
diff changeset
396 then
kono
parents:
diff changeset
397 return Tagged_Type;
kono
parents:
diff changeset
398
kono
parents:
diff changeset
399 else
kono
parents:
diff changeset
400 return Empty;
kono
parents:
diff changeset
401 end if;
kono
parents:
diff changeset
402 end Check_Controlling_Type;
kono
parents:
diff changeset
403
kono
parents:
diff changeset
404 ----------------------------
kono
parents:
diff changeset
405 -- Check_Dispatching_Call --
kono
parents:
diff changeset
406 ----------------------------
kono
parents:
diff changeset
407
kono
parents:
diff changeset
408 procedure Check_Dispatching_Call (N : Node_Id) is
kono
parents:
diff changeset
409 Loc : constant Source_Ptr := Sloc (N);
kono
parents:
diff changeset
410 Actual : Node_Id;
kono
parents:
diff changeset
411 Formal : Entity_Id;
kono
parents:
diff changeset
412 Control : Node_Id := Empty;
kono
parents:
diff changeset
413 Func : Entity_Id;
kono
parents:
diff changeset
414 Subp_Entity : Entity_Id;
kono
parents:
diff changeset
415 Indeterm_Ancestor_Call : Boolean := False;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
416 Indeterm_Ctrl_Type : Entity_Id := Empty; -- init to avoid warning
111
kono
parents:
diff changeset
417
kono
parents:
diff changeset
418 Static_Tag : Node_Id := Empty;
kono
parents:
diff changeset
419 -- If a controlling formal has a statically tagged actual, the tag of
kono
parents:
diff changeset
420 -- this actual is to be used for any tag-indeterminate actual.
kono
parents:
diff changeset
421
kono
parents:
diff changeset
422 procedure Check_Direct_Call;
kono
parents:
diff changeset
423 -- In the case when the controlling actual is a class-wide type whose
kono
parents:
diff changeset
424 -- root type's completion is a task or protected type, the call is in
kono
parents:
diff changeset
425 -- fact direct. This routine detects the above case and modifies the
kono
parents:
diff changeset
426 -- call accordingly.
kono
parents:
diff changeset
427
kono
parents:
diff changeset
428 procedure Check_Dispatching_Context (Call : Node_Id);
kono
parents:
diff changeset
429 -- If the call is tag-indeterminate and the entity being called is
kono
parents:
diff changeset
430 -- abstract, verify that the context is a call that will eventually
kono
parents:
diff changeset
431 -- provide a tag for dispatching, or has provided one already.
kono
parents:
diff changeset
432
kono
parents:
diff changeset
433 -----------------------
kono
parents:
diff changeset
434 -- Check_Direct_Call --
kono
parents:
diff changeset
435 -----------------------
kono
parents:
diff changeset
436
kono
parents:
diff changeset
437 procedure Check_Direct_Call is
kono
parents:
diff changeset
438 Typ : Entity_Id := Etype (Control);
kono
parents:
diff changeset
439 begin
kono
parents:
diff changeset
440 -- Predefined primitives do not receive wrappers since they are built
kono
parents:
diff changeset
441 -- from scratch for the corresponding record of synchronized types.
kono
parents:
diff changeset
442 -- Equality is in general predefined, but is excluded from the check
kono
parents:
diff changeset
443 -- when it is user-defined.
kono
parents:
diff changeset
444
kono
parents:
diff changeset
445 if Is_Predefined_Dispatching_Operation (Subp_Entity)
kono
parents:
diff changeset
446 and then not Is_User_Defined_Equality (Subp_Entity)
kono
parents:
diff changeset
447 then
kono
parents:
diff changeset
448 return;
kono
parents:
diff changeset
449 end if;
kono
parents:
diff changeset
450
kono
parents:
diff changeset
451 if Is_Class_Wide_Type (Typ) then
kono
parents:
diff changeset
452 Typ := Root_Type (Typ);
kono
parents:
diff changeset
453 end if;
kono
parents:
diff changeset
454
kono
parents:
diff changeset
455 if Is_Private_Type (Typ) and then Present (Full_View (Typ)) then
kono
parents:
diff changeset
456 Typ := Full_View (Typ);
kono
parents:
diff changeset
457 end if;
kono
parents:
diff changeset
458
kono
parents:
diff changeset
459 if Is_Concurrent_Type (Typ)
kono
parents:
diff changeset
460 and then
kono
parents:
diff changeset
461 Present (Corresponding_Record_Type (Typ))
kono
parents:
diff changeset
462 then
kono
parents:
diff changeset
463 Typ := Corresponding_Record_Type (Typ);
kono
parents:
diff changeset
464
kono
parents:
diff changeset
465 -- The concurrent record's list of primitives should contain a
kono
parents:
diff changeset
466 -- wrapper for the entity of the call, retrieve it.
kono
parents:
diff changeset
467
kono
parents:
diff changeset
468 declare
kono
parents:
diff changeset
469 Prim : Entity_Id;
kono
parents:
diff changeset
470 Prim_Elmt : Elmt_Id;
kono
parents:
diff changeset
471 Wrapper_Found : Boolean := False;
kono
parents:
diff changeset
472
kono
parents:
diff changeset
473 begin
kono
parents:
diff changeset
474 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
kono
parents:
diff changeset
475 while Present (Prim_Elmt) loop
kono
parents:
diff changeset
476 Prim := Node (Prim_Elmt);
kono
parents:
diff changeset
477
kono
parents:
diff changeset
478 if Is_Primitive_Wrapper (Prim)
kono
parents:
diff changeset
479 and then Wrapped_Entity (Prim) = Subp_Entity
kono
parents:
diff changeset
480 then
kono
parents:
diff changeset
481 Wrapper_Found := True;
kono
parents:
diff changeset
482 exit;
kono
parents:
diff changeset
483 end if;
kono
parents:
diff changeset
484
kono
parents:
diff changeset
485 Next_Elmt (Prim_Elmt);
kono
parents:
diff changeset
486 end loop;
kono
parents:
diff changeset
487
kono
parents:
diff changeset
488 -- A primitive declared between two views should have a
kono
parents:
diff changeset
489 -- corresponding wrapper.
kono
parents:
diff changeset
490
kono
parents:
diff changeset
491 pragma Assert (Wrapper_Found);
kono
parents:
diff changeset
492
kono
parents:
diff changeset
493 -- Modify the call by setting the proper entity
kono
parents:
diff changeset
494
kono
parents:
diff changeset
495 Set_Entity (Name (N), Prim);
kono
parents:
diff changeset
496 end;
kono
parents:
diff changeset
497 end if;
kono
parents:
diff changeset
498 end Check_Direct_Call;
kono
parents:
diff changeset
499
kono
parents:
diff changeset
500 -------------------------------
kono
parents:
diff changeset
501 -- Check_Dispatching_Context --
kono
parents:
diff changeset
502 -------------------------------
kono
parents:
diff changeset
503
kono
parents:
diff changeset
504 procedure Check_Dispatching_Context (Call : Node_Id) is
kono
parents:
diff changeset
505 Subp : constant Entity_Id := Entity (Name (Call));
kono
parents:
diff changeset
506
kono
parents:
diff changeset
507 procedure Abstract_Context_Error;
kono
parents:
diff changeset
508 -- Error for abstract call dispatching on result is not dispatching
kono
parents:
diff changeset
509
kono
parents:
diff changeset
510 ----------------------------
kono
parents:
diff changeset
511 -- Abstract_Context_Error --
kono
parents:
diff changeset
512 ----------------------------
kono
parents:
diff changeset
513
kono
parents:
diff changeset
514 procedure Abstract_Context_Error is
kono
parents:
diff changeset
515 begin
kono
parents:
diff changeset
516 if Ekind (Subp) = E_Function then
kono
parents:
diff changeset
517 Error_Msg_N
kono
parents:
diff changeset
518 ("call to abstract function must be dispatching", N);
kono
parents:
diff changeset
519
kono
parents:
diff changeset
520 -- This error can occur for a procedure in the case of a call to
kono
parents:
diff changeset
521 -- an abstract formal procedure with a statically tagged operand.
kono
parents:
diff changeset
522
kono
parents:
diff changeset
523 else
kono
parents:
diff changeset
524 Error_Msg_N
kono
parents:
diff changeset
525 ("call to abstract procedure must be dispatching", N);
kono
parents:
diff changeset
526 end if;
kono
parents:
diff changeset
527 end Abstract_Context_Error;
kono
parents:
diff changeset
528
kono
parents:
diff changeset
529 -- Local variables
kono
parents:
diff changeset
530
kono
parents:
diff changeset
531 Scop : constant Entity_Id := Current_Scope_No_Loops;
kono
parents:
diff changeset
532 Typ : constant Entity_Id := Etype (Subp);
kono
parents:
diff changeset
533 Par : Node_Id;
kono
parents:
diff changeset
534
kono
parents:
diff changeset
535 -- Start of processing for Check_Dispatching_Context
kono
parents:
diff changeset
536
kono
parents:
diff changeset
537 begin
kono
parents:
diff changeset
538 -- If the called subprogram is a private overriding, replace it
kono
parents:
diff changeset
539 -- with its alias, which has the correct body. Verify that the
kono
parents:
diff changeset
540 -- two subprograms have the same controlling type (this is not the
kono
parents:
diff changeset
541 -- case for an inherited subprogram that has become abstract).
kono
parents:
diff changeset
542
kono
parents:
diff changeset
543 if Is_Abstract_Subprogram (Subp)
kono
parents:
diff changeset
544 and then No (Controlling_Argument (Call))
kono
parents:
diff changeset
545 then
kono
parents:
diff changeset
546 if Present (Alias (Subp))
kono
parents:
diff changeset
547 and then not Is_Abstract_Subprogram (Alias (Subp))
kono
parents:
diff changeset
548 and then No (DTC_Entity (Subp))
kono
parents:
diff changeset
549 and then Find_Dispatching_Type (Subp) =
kono
parents:
diff changeset
550 Find_Dispatching_Type (Alias (Subp))
kono
parents:
diff changeset
551 then
kono
parents:
diff changeset
552 -- Private overriding of inherited abstract operation, call is
kono
parents:
diff changeset
553 -- legal.
kono
parents:
diff changeset
554
kono
parents:
diff changeset
555 Set_Entity (Name (N), Alias (Subp));
kono
parents:
diff changeset
556 return;
kono
parents:
diff changeset
557
kono
parents:
diff changeset
558 -- An obscure special case: a null procedure may have a class-
kono
parents:
diff changeset
559 -- wide pre/postcondition that includes a call to an abstract
kono
parents:
diff changeset
560 -- subp. Calls within the expression may not have been rewritten
kono
parents:
diff changeset
561 -- as dispatching calls yet, because the null body appears in
kono
parents:
diff changeset
562 -- the current declarative part. The expression will be properly
kono
parents:
diff changeset
563 -- rewritten/reanalyzed when the postcondition procedure is built.
kono
parents:
diff changeset
564
kono
parents:
diff changeset
565 -- Similarly, if this is a pre/postcondition for an abstract
kono
parents:
diff changeset
566 -- subprogram, it may call another abstract function which is
kono
parents:
diff changeset
567 -- a primitive of an abstract type. The call is non-dispatching
kono
parents:
diff changeset
568 -- but will be legal in overridings of the operation.
kono
parents:
diff changeset
569
kono
parents:
diff changeset
570 elsif (Is_Subprogram (Scop)
kono
parents:
diff changeset
571 or else Chars (Scop) = Name_Postcondition)
kono
parents:
diff changeset
572 and then
kono
parents:
diff changeset
573 (Is_Abstract_Subprogram (Scop)
kono
parents:
diff changeset
574 or else
kono
parents:
diff changeset
575 (Nkind (Parent (Scop)) = N_Procedure_Specification
kono
parents:
diff changeset
576 and then Null_Present (Parent (Scop))))
kono
parents:
diff changeset
577 then
kono
parents:
diff changeset
578 null;
kono
parents:
diff changeset
579
kono
parents:
diff changeset
580 elsif Ekind (Current_Scope) = E_Function
kono
parents:
diff changeset
581 and then Nkind (Unit_Declaration_Node (Scop)) =
kono
parents:
diff changeset
582 N_Generic_Subprogram_Declaration
kono
parents:
diff changeset
583 then
kono
parents:
diff changeset
584 null;
kono
parents:
diff changeset
585
kono
parents:
diff changeset
586 else
kono
parents:
diff changeset
587 -- We need to determine whether the context of the call
kono
parents:
diff changeset
588 -- provides a tag to make the call dispatching. This requires
kono
parents:
diff changeset
589 -- the call to be the actual in an enclosing call, and that
kono
parents:
diff changeset
590 -- actual must be controlling. If the call is an operand of
kono
parents:
diff changeset
591 -- equality, the other operand must not ve abstract.
kono
parents:
diff changeset
592
kono
parents:
diff changeset
593 if not Is_Tagged_Type (Typ)
kono
parents:
diff changeset
594 and then not
kono
parents:
diff changeset
595 (Ekind (Typ) = E_Anonymous_Access_Type
kono
parents:
diff changeset
596 and then Is_Tagged_Type (Designated_Type (Typ)))
kono
parents:
diff changeset
597 then
kono
parents:
diff changeset
598 Abstract_Context_Error;
kono
parents:
diff changeset
599 return;
kono
parents:
diff changeset
600 end if;
kono
parents:
diff changeset
601
kono
parents:
diff changeset
602 Par := Parent (Call);
kono
parents:
diff changeset
603
kono
parents:
diff changeset
604 if Nkind (Par) = N_Parameter_Association then
kono
parents:
diff changeset
605 Par := Parent (Par);
kono
parents:
diff changeset
606 end if;
kono
parents:
diff changeset
607
kono
parents:
diff changeset
608 if Nkind (Par) = N_Qualified_Expression
kono
parents:
diff changeset
609 or else Nkind (Par) = N_Unchecked_Type_Conversion
kono
parents:
diff changeset
610 then
kono
parents:
diff changeset
611 Par := Parent (Par);
kono
parents:
diff changeset
612 end if;
kono
parents:
diff changeset
613
kono
parents:
diff changeset
614 if Nkind_In (Par, N_Function_Call, N_Procedure_Call_Statement)
kono
parents:
diff changeset
615 and then Is_Entity_Name (Name (Par))
kono
parents:
diff changeset
616 then
kono
parents:
diff changeset
617 declare
kono
parents:
diff changeset
618 Enc_Subp : constant Entity_Id := Entity (Name (Par));
kono
parents:
diff changeset
619 A : Node_Id;
kono
parents:
diff changeset
620 F : Entity_Id;
kono
parents:
diff changeset
621 Control : Entity_Id;
kono
parents:
diff changeset
622 Ret_Type : Entity_Id;
kono
parents:
diff changeset
623
kono
parents:
diff changeset
624 begin
kono
parents:
diff changeset
625 -- Find controlling formal that can provide tag for the
kono
parents:
diff changeset
626 -- tag-indeterminate actual. The corresponding actual
kono
parents:
diff changeset
627 -- must be the corresponding class-wide type.
kono
parents:
diff changeset
628
kono
parents:
diff changeset
629 F := First_Formal (Enc_Subp);
kono
parents:
diff changeset
630 A := First_Actual (Par);
kono
parents:
diff changeset
631
kono
parents:
diff changeset
632 -- Find controlling type of call. Dereference if function
kono
parents:
diff changeset
633 -- returns an access type.
kono
parents:
diff changeset
634
kono
parents:
diff changeset
635 Ret_Type := Etype (Call);
kono
parents:
diff changeset
636 if Is_Access_Type (Etype (Call)) then
kono
parents:
diff changeset
637 Ret_Type := Designated_Type (Ret_Type);
kono
parents:
diff changeset
638 end if;
kono
parents:
diff changeset
639
kono
parents:
diff changeset
640 while Present (F) loop
kono
parents:
diff changeset
641 Control := Etype (A);
kono
parents:
diff changeset
642
kono
parents:
diff changeset
643 if Is_Access_Type (Control) then
kono
parents:
diff changeset
644 Control := Designated_Type (Control);
kono
parents:
diff changeset
645 end if;
kono
parents:
diff changeset
646
kono
parents:
diff changeset
647 if Is_Controlling_Formal (F)
kono
parents:
diff changeset
648 and then not (Call = A or else Parent (Call) = A)
kono
parents:
diff changeset
649 and then Control = Class_Wide_Type (Ret_Type)
kono
parents:
diff changeset
650 then
kono
parents:
diff changeset
651 return;
kono
parents:
diff changeset
652 end if;
kono
parents:
diff changeset
653
kono
parents:
diff changeset
654 Next_Formal (F);
kono
parents:
diff changeset
655 Next_Actual (A);
kono
parents:
diff changeset
656 end loop;
kono
parents:
diff changeset
657
kono
parents:
diff changeset
658 if Nkind (Par) = N_Function_Call
kono
parents:
diff changeset
659 and then Is_Tag_Indeterminate (Par)
kono
parents:
diff changeset
660 then
kono
parents:
diff changeset
661 -- The parent may be an actual of an enclosing call
kono
parents:
diff changeset
662
kono
parents:
diff changeset
663 Check_Dispatching_Context (Par);
kono
parents:
diff changeset
664 return;
kono
parents:
diff changeset
665
kono
parents:
diff changeset
666 else
kono
parents:
diff changeset
667 Error_Msg_N
kono
parents:
diff changeset
668 ("call to abstract function must be dispatching",
kono
parents:
diff changeset
669 Call);
kono
parents:
diff changeset
670 return;
kono
parents:
diff changeset
671 end if;
kono
parents:
diff changeset
672 end;
kono
parents:
diff changeset
673
kono
parents:
diff changeset
674 -- For equality operators, one of the operands must be
kono
parents:
diff changeset
675 -- statically or dynamically tagged.
kono
parents:
diff changeset
676
kono
parents:
diff changeset
677 elsif Nkind_In (Par, N_Op_Eq, N_Op_Ne) then
kono
parents:
diff changeset
678 if N = Right_Opnd (Par)
kono
parents:
diff changeset
679 and then Is_Tag_Indeterminate (Left_Opnd (Par))
kono
parents:
diff changeset
680 then
kono
parents:
diff changeset
681 Abstract_Context_Error;
kono
parents:
diff changeset
682
kono
parents:
diff changeset
683 elsif N = Left_Opnd (Par)
kono
parents:
diff changeset
684 and then Is_Tag_Indeterminate (Right_Opnd (Par))
kono
parents:
diff changeset
685 then
kono
parents:
diff changeset
686 Abstract_Context_Error;
kono
parents:
diff changeset
687 end if;
kono
parents:
diff changeset
688
kono
parents:
diff changeset
689 return;
kono
parents:
diff changeset
690
kono
parents:
diff changeset
691 -- The left-hand side of an assignment provides the tag
kono
parents:
diff changeset
692
kono
parents:
diff changeset
693 elsif Nkind (Par) = N_Assignment_Statement then
kono
parents:
diff changeset
694 return;
kono
parents:
diff changeset
695
kono
parents:
diff changeset
696 else
kono
parents:
diff changeset
697 Abstract_Context_Error;
kono
parents:
diff changeset
698 end if;
kono
parents:
diff changeset
699 end if;
kono
parents:
diff changeset
700 end if;
kono
parents:
diff changeset
701 end Check_Dispatching_Context;
kono
parents:
diff changeset
702
kono
parents:
diff changeset
703 -- Start of processing for Check_Dispatching_Call
kono
parents:
diff changeset
704
kono
parents:
diff changeset
705 begin
kono
parents:
diff changeset
706 -- Find a controlling argument, if any
kono
parents:
diff changeset
707
kono
parents:
diff changeset
708 if Present (Parameter_Associations (N)) then
kono
parents:
diff changeset
709 Subp_Entity := Entity (Name (N));
kono
parents:
diff changeset
710
kono
parents:
diff changeset
711 Actual := First_Actual (N);
kono
parents:
diff changeset
712 Formal := First_Formal (Subp_Entity);
kono
parents:
diff changeset
713 while Present (Actual) loop
kono
parents:
diff changeset
714 Control := Find_Controlling_Arg (Actual);
kono
parents:
diff changeset
715 exit when Present (Control);
kono
parents:
diff changeset
716
kono
parents:
diff changeset
717 -- Check for the case where the actual is a tag-indeterminate call
kono
parents:
diff changeset
718 -- whose result type is different than the tagged type associated
kono
parents:
diff changeset
719 -- with the containing call, but is an ancestor of the type.
kono
parents:
diff changeset
720
kono
parents:
diff changeset
721 if Is_Controlling_Formal (Formal)
kono
parents:
diff changeset
722 and then Is_Tag_Indeterminate (Actual)
kono
parents:
diff changeset
723 and then Base_Type (Etype (Actual)) /= Base_Type (Etype (Formal))
kono
parents:
diff changeset
724 and then Is_Ancestor (Etype (Actual), Etype (Formal))
kono
parents:
diff changeset
725 then
kono
parents:
diff changeset
726 Indeterm_Ancestor_Call := True;
kono
parents:
diff changeset
727 Indeterm_Ctrl_Type := Etype (Formal);
kono
parents:
diff changeset
728
kono
parents:
diff changeset
729 -- If the formal is controlling but the actual is not, the type
kono
parents:
diff changeset
730 -- of the actual is statically known, and may be used as the
kono
parents:
diff changeset
731 -- controlling tag for some other tag-indeterminate actual.
kono
parents:
diff changeset
732
kono
parents:
diff changeset
733 elsif Is_Controlling_Formal (Formal)
kono
parents:
diff changeset
734 and then Is_Entity_Name (Actual)
kono
parents:
diff changeset
735 and then Is_Tagged_Type (Etype (Actual))
kono
parents:
diff changeset
736 then
kono
parents:
diff changeset
737 Static_Tag := Actual;
kono
parents:
diff changeset
738 end if;
kono
parents:
diff changeset
739
kono
parents:
diff changeset
740 Next_Actual (Actual);
kono
parents:
diff changeset
741 Next_Formal (Formal);
kono
parents:
diff changeset
742 end loop;
kono
parents:
diff changeset
743
kono
parents:
diff changeset
744 -- If the call doesn't have a controlling actual but does have an
kono
parents:
diff changeset
745 -- indeterminate actual that requires dispatching treatment, then an
kono
parents:
diff changeset
746 -- object is needed that will serve as the controlling argument for
kono
parents:
diff changeset
747 -- a dispatching call on the indeterminate actual. This can occur
kono
parents:
diff changeset
748 -- in the unusual situation of a default actual given by a tag-
kono
parents:
diff changeset
749 -- indeterminate call and where the type of the call is an ancestor
kono
parents:
diff changeset
750 -- of the type associated with a containing call to an inherited
kono
parents:
diff changeset
751 -- operation (see AI-239).
kono
parents:
diff changeset
752
kono
parents:
diff changeset
753 -- Rather than create an object of the tagged type, which would
kono
parents:
diff changeset
754 -- be problematic for various reasons (default initialization,
kono
parents:
diff changeset
755 -- discriminants), the tag of the containing call's associated
kono
parents:
diff changeset
756 -- tagged type is directly used to control the dispatching.
kono
parents:
diff changeset
757
kono
parents:
diff changeset
758 if No (Control)
kono
parents:
diff changeset
759 and then Indeterm_Ancestor_Call
kono
parents:
diff changeset
760 and then No (Static_Tag)
kono
parents:
diff changeset
761 then
kono
parents:
diff changeset
762 Control :=
kono
parents:
diff changeset
763 Make_Attribute_Reference (Loc,
kono
parents:
diff changeset
764 Prefix => New_Occurrence_Of (Indeterm_Ctrl_Type, Loc),
kono
parents:
diff changeset
765 Attribute_Name => Name_Tag);
kono
parents:
diff changeset
766
kono
parents:
diff changeset
767 Analyze (Control);
kono
parents:
diff changeset
768 end if;
kono
parents:
diff changeset
769
kono
parents:
diff changeset
770 if Present (Control) then
kono
parents:
diff changeset
771
kono
parents:
diff changeset
772 -- Verify that no controlling arguments are statically tagged
kono
parents:
diff changeset
773
kono
parents:
diff changeset
774 if Debug_Flag_E then
kono
parents:
diff changeset
775 Write_Str ("Found Dispatching call");
kono
parents:
diff changeset
776 Write_Int (Int (N));
kono
parents:
diff changeset
777 Write_Eol;
kono
parents:
diff changeset
778 end if;
kono
parents:
diff changeset
779
kono
parents:
diff changeset
780 Actual := First_Actual (N);
kono
parents:
diff changeset
781 while Present (Actual) loop
kono
parents:
diff changeset
782 if Actual /= Control then
kono
parents:
diff changeset
783
kono
parents:
diff changeset
784 if not Is_Controlling_Actual (Actual) then
kono
parents:
diff changeset
785 null; -- Can be anything
kono
parents:
diff changeset
786
kono
parents:
diff changeset
787 elsif Is_Dynamically_Tagged (Actual) then
kono
parents:
diff changeset
788 null; -- Valid parameter
kono
parents:
diff changeset
789
kono
parents:
diff changeset
790 elsif Is_Tag_Indeterminate (Actual) then
kono
parents:
diff changeset
791
kono
parents:
diff changeset
792 -- The tag is inherited from the enclosing call (the node
kono
parents:
diff changeset
793 -- we are currently analyzing). Explicitly expand the
kono
parents:
diff changeset
794 -- actual, since the previous call to Expand (from
kono
parents:
diff changeset
795 -- Resolve_Call) had no way of knowing about the
kono
parents:
diff changeset
796 -- required dispatching.
kono
parents:
diff changeset
797
kono
parents:
diff changeset
798 Propagate_Tag (Control, Actual);
kono
parents:
diff changeset
799
kono
parents:
diff changeset
800 else
kono
parents:
diff changeset
801 Error_Msg_N
kono
parents:
diff changeset
802 ("controlling argument is not dynamically tagged",
kono
parents:
diff changeset
803 Actual);
kono
parents:
diff changeset
804 return;
kono
parents:
diff changeset
805 end if;
kono
parents:
diff changeset
806 end if;
kono
parents:
diff changeset
807
kono
parents:
diff changeset
808 Next_Actual (Actual);
kono
parents:
diff changeset
809 end loop;
kono
parents:
diff changeset
810
kono
parents:
diff changeset
811 -- Mark call as a dispatching call
kono
parents:
diff changeset
812
kono
parents:
diff changeset
813 Set_Controlling_Argument (N, Control);
kono
parents:
diff changeset
814 Check_Restriction (No_Dispatching_Calls, N);
kono
parents:
diff changeset
815
kono
parents:
diff changeset
816 -- The dispatching call may need to be converted into a direct
kono
parents:
diff changeset
817 -- call in certain cases.
kono
parents:
diff changeset
818
kono
parents:
diff changeset
819 Check_Direct_Call;
kono
parents:
diff changeset
820
kono
parents:
diff changeset
821 -- If there is a statically tagged actual and a tag-indeterminate
kono
parents:
diff changeset
822 -- call to a function of the ancestor (such as that provided by a
kono
parents:
diff changeset
823 -- default), then treat this as a dispatching call and propagate
kono
parents:
diff changeset
824 -- the tag to the tag-indeterminate call(s).
kono
parents:
diff changeset
825
kono
parents:
diff changeset
826 elsif Present (Static_Tag) and then Indeterm_Ancestor_Call then
kono
parents:
diff changeset
827 Control :=
kono
parents:
diff changeset
828 Make_Attribute_Reference (Loc,
kono
parents:
diff changeset
829 Prefix =>
kono
parents:
diff changeset
830 New_Occurrence_Of (Etype (Static_Tag), Loc),
kono
parents:
diff changeset
831 Attribute_Name => Name_Tag);
kono
parents:
diff changeset
832
kono
parents:
diff changeset
833 Analyze (Control);
kono
parents:
diff changeset
834
kono
parents:
diff changeset
835 Actual := First_Actual (N);
kono
parents:
diff changeset
836 Formal := First_Formal (Subp_Entity);
kono
parents:
diff changeset
837 while Present (Actual) loop
kono
parents:
diff changeset
838 if Is_Tag_Indeterminate (Actual)
kono
parents:
diff changeset
839 and then Is_Controlling_Formal (Formal)
kono
parents:
diff changeset
840 then
kono
parents:
diff changeset
841 Propagate_Tag (Control, Actual);
kono
parents:
diff changeset
842 end if;
kono
parents:
diff changeset
843
kono
parents:
diff changeset
844 Next_Actual (Actual);
kono
parents:
diff changeset
845 Next_Formal (Formal);
kono
parents:
diff changeset
846 end loop;
kono
parents:
diff changeset
847
kono
parents:
diff changeset
848 Check_Dispatching_Context (N);
kono
parents:
diff changeset
849
kono
parents:
diff changeset
850 elsif Nkind (N) /= N_Function_Call then
kono
parents:
diff changeset
851
kono
parents:
diff changeset
852 -- The call is not dispatching, so check that there aren't any
kono
parents:
diff changeset
853 -- tag-indeterminate abstract calls left among its actuals.
kono
parents:
diff changeset
854
kono
parents:
diff changeset
855 Actual := First_Actual (N);
kono
parents:
diff changeset
856 while Present (Actual) loop
kono
parents:
diff changeset
857 if Is_Tag_Indeterminate (Actual) then
kono
parents:
diff changeset
858
kono
parents:
diff changeset
859 -- Function call case
kono
parents:
diff changeset
860
kono
parents:
diff changeset
861 if Nkind (Original_Node (Actual)) = N_Function_Call then
kono
parents:
diff changeset
862 Func := Entity (Name (Original_Node (Actual)));
kono
parents:
diff changeset
863
kono
parents:
diff changeset
864 -- If the actual is an attribute then it can't be abstract
kono
parents:
diff changeset
865 -- (the only current case of a tag-indeterminate attribute
kono
parents:
diff changeset
866 -- is the stream Input attribute).
kono
parents:
diff changeset
867
kono
parents:
diff changeset
868 elsif Nkind (Original_Node (Actual)) = N_Attribute_Reference
kono
parents:
diff changeset
869 then
kono
parents:
diff changeset
870 Func := Empty;
kono
parents:
diff changeset
871
kono
parents:
diff changeset
872 -- Ditto if it is an explicit dereference
kono
parents:
diff changeset
873
kono
parents:
diff changeset
874 elsif Nkind (Original_Node (Actual)) = N_Explicit_Dereference
kono
parents:
diff changeset
875 then
kono
parents:
diff changeset
876 Func := Empty;
kono
parents:
diff changeset
877
kono
parents:
diff changeset
878 -- Only other possibility is a qualified expression whose
kono
parents:
diff changeset
879 -- constituent expression is itself a call.
kono
parents:
diff changeset
880
kono
parents:
diff changeset
881 else
kono
parents:
diff changeset
882 Func :=
kono
parents:
diff changeset
883 Entity (Name (Original_Node
kono
parents:
diff changeset
884 (Expression (Original_Node (Actual)))));
kono
parents:
diff changeset
885 end if;
kono
parents:
diff changeset
886
kono
parents:
diff changeset
887 if Present (Func) and then Is_Abstract_Subprogram (Func) then
kono
parents:
diff changeset
888 Error_Msg_N
kono
parents:
diff changeset
889 ("call to abstract function must be dispatching",
kono
parents:
diff changeset
890 Actual);
kono
parents:
diff changeset
891 end if;
kono
parents:
diff changeset
892 end if;
kono
parents:
diff changeset
893
kono
parents:
diff changeset
894 Next_Actual (Actual);
kono
parents:
diff changeset
895 end loop;
kono
parents:
diff changeset
896
kono
parents:
diff changeset
897 Check_Dispatching_Context (N);
kono
parents:
diff changeset
898 return;
kono
parents:
diff changeset
899
kono
parents:
diff changeset
900 elsif Nkind (Parent (N)) in N_Subexpr then
kono
parents:
diff changeset
901 Check_Dispatching_Context (N);
kono
parents:
diff changeset
902
kono
parents:
diff changeset
903 elsif Nkind (Parent (N)) = N_Assignment_Statement
kono
parents:
diff changeset
904 and then Is_Class_Wide_Type (Etype (Name (Parent (N))))
kono
parents:
diff changeset
905 then
kono
parents:
diff changeset
906 return;
kono
parents:
diff changeset
907
kono
parents:
diff changeset
908 elsif Is_Abstract_Subprogram (Subp_Entity) then
kono
parents:
diff changeset
909 Check_Dispatching_Context (N);
kono
parents:
diff changeset
910 return;
kono
parents:
diff changeset
911 end if;
kono
parents:
diff changeset
912
kono
parents:
diff changeset
913 else
kono
parents:
diff changeset
914 -- If dispatching on result, the enclosing call, if any, will
kono
parents:
diff changeset
915 -- determine the controlling argument. Otherwise this is the
kono
parents:
diff changeset
916 -- primitive operation of the root type.
kono
parents:
diff changeset
917
kono
parents:
diff changeset
918 Check_Dispatching_Context (N);
kono
parents:
diff changeset
919 end if;
kono
parents:
diff changeset
920 end Check_Dispatching_Call;
kono
parents:
diff changeset
921
kono
parents:
diff changeset
922 ---------------------------------
kono
parents:
diff changeset
923 -- Check_Dispatching_Operation --
kono
parents:
diff changeset
924 ---------------------------------
kono
parents:
diff changeset
925
kono
parents:
diff changeset
926 procedure Check_Dispatching_Operation (Subp, Old_Subp : Entity_Id) is
kono
parents:
diff changeset
927 procedure Warn_On_Late_Primitive_After_Private_Extension
kono
parents:
diff changeset
928 (Typ : Entity_Id;
kono
parents:
diff changeset
929 Prim : Entity_Id);
kono
parents:
diff changeset
930 -- Prim is a dispatching primitive of the tagged type Typ. Warn on Prim
kono
parents:
diff changeset
931 -- if it is a public primitive defined after some private extension of
kono
parents:
diff changeset
932 -- the tagged type.
kono
parents:
diff changeset
933
kono
parents:
diff changeset
934 ----------------------------------------------------
kono
parents:
diff changeset
935 -- Warn_On_Late_Primitive_After_Private_Extension --
kono
parents:
diff changeset
936 ----------------------------------------------------
kono
parents:
diff changeset
937
kono
parents:
diff changeset
938 procedure Warn_On_Late_Primitive_After_Private_Extension
kono
parents:
diff changeset
939 (Typ : Entity_Id;
kono
parents:
diff changeset
940 Prim : Entity_Id)
kono
parents:
diff changeset
941 is
kono
parents:
diff changeset
942 E : Entity_Id;
kono
parents:
diff changeset
943
kono
parents:
diff changeset
944 begin
kono
parents:
diff changeset
945 if Warn_On_Late_Primitives
kono
parents:
diff changeset
946 and then Comes_From_Source (Prim)
kono
parents:
diff changeset
947 and then Has_Private_Extension (Typ)
kono
parents:
diff changeset
948 and then Is_Package_Or_Generic_Package (Current_Scope)
kono
parents:
diff changeset
949 and then not In_Private_Part (Current_Scope)
kono
parents:
diff changeset
950 then
kono
parents:
diff changeset
951 E := Next_Entity (Typ);
kono
parents:
diff changeset
952
kono
parents:
diff changeset
953 while E /= Prim loop
kono
parents:
diff changeset
954 if Ekind (E) = E_Record_Type_With_Private
kono
parents:
diff changeset
955 and then Etype (E) = Typ
kono
parents:
diff changeset
956 then
kono
parents:
diff changeset
957 Error_Msg_Name_1 := Chars (Typ);
kono
parents:
diff changeset
958 Error_Msg_Name_2 := Chars (E);
kono
parents:
diff changeset
959 Error_Msg_Sloc := Sloc (E);
kono
parents:
diff changeset
960 Error_Msg_N
kono
parents:
diff changeset
961 ("?j?primitive of type % defined after private extension "
kono
parents:
diff changeset
962 & "% #?", Prim);
kono
parents:
diff changeset
963 Error_Msg_Name_1 := Chars (Prim);
kono
parents:
diff changeset
964 Error_Msg_Name_2 := Chars (E);
kono
parents:
diff changeset
965 Error_Msg_N
kono
parents:
diff changeset
966 ("\spec of % should appear before declaration of type %!",
kono
parents:
diff changeset
967 Prim);
kono
parents:
diff changeset
968 exit;
kono
parents:
diff changeset
969 end if;
kono
parents:
diff changeset
970
kono
parents:
diff changeset
971 Next_Entity (E);
kono
parents:
diff changeset
972 end loop;
kono
parents:
diff changeset
973 end if;
kono
parents:
diff changeset
974 end Warn_On_Late_Primitive_After_Private_Extension;
kono
parents:
diff changeset
975
kono
parents:
diff changeset
976 -- Local variables
kono
parents:
diff changeset
977
kono
parents:
diff changeset
978 Body_Is_Last_Primitive : Boolean := False;
kono
parents:
diff changeset
979 Has_Dispatching_Parent : Boolean := False;
kono
parents:
diff changeset
980 Ovr_Subp : Entity_Id := Empty;
kono
parents:
diff changeset
981 Tagged_Type : Entity_Id;
kono
parents:
diff changeset
982
kono
parents:
diff changeset
983 -- Start of processing for Check_Dispatching_Operation
kono
parents:
diff changeset
984
kono
parents:
diff changeset
985 begin
kono
parents:
diff changeset
986 if not Ekind_In (Subp, E_Function, E_Procedure) then
kono
parents:
diff changeset
987 return;
kono
parents:
diff changeset
988
kono
parents:
diff changeset
989 -- The Default_Initial_Condition procedure is not a primitive subprogram
kono
parents:
diff changeset
990 -- even if it relates to a tagged type. This routine is not meant to be
kono
parents:
diff changeset
991 -- inherited or overridden.
kono
parents:
diff changeset
992
kono
parents:
diff changeset
993 elsif Is_DIC_Procedure (Subp) then
kono
parents:
diff changeset
994 return;
kono
parents:
diff changeset
995
kono
parents:
diff changeset
996 -- The "partial" and "full" type invariant procedures are not primitive
kono
parents:
diff changeset
997 -- subprograms even if they relate to a tagged type. These routines are
kono
parents:
diff changeset
998 -- not meant to be inherited or overridden.
kono
parents:
diff changeset
999
kono
parents:
diff changeset
1000 elsif Is_Invariant_Procedure (Subp)
kono
parents:
diff changeset
1001 or else Is_Partial_Invariant_Procedure (Subp)
kono
parents:
diff changeset
1002 then
kono
parents:
diff changeset
1003 return;
kono
parents:
diff changeset
1004 end if;
kono
parents:
diff changeset
1005
kono
parents:
diff changeset
1006 Set_Is_Dispatching_Operation (Subp, False);
kono
parents:
diff changeset
1007 Tagged_Type := Find_Dispatching_Type (Subp);
kono
parents:
diff changeset
1008
kono
parents:
diff changeset
1009 -- Ada 2005 (AI-345): Use the corresponding record (if available).
kono
parents:
diff changeset
1010 -- Required because primitives of concurrent types are attached
kono
parents:
diff changeset
1011 -- to the corresponding record (not to the concurrent type).
kono
parents:
diff changeset
1012
kono
parents:
diff changeset
1013 if Ada_Version >= Ada_2005
kono
parents:
diff changeset
1014 and then Present (Tagged_Type)
kono
parents:
diff changeset
1015 and then Is_Concurrent_Type (Tagged_Type)
kono
parents:
diff changeset
1016 and then Present (Corresponding_Record_Type (Tagged_Type))
kono
parents:
diff changeset
1017 then
kono
parents:
diff changeset
1018 Tagged_Type := Corresponding_Record_Type (Tagged_Type);
kono
parents:
diff changeset
1019 end if;
kono
parents:
diff changeset
1020
kono
parents:
diff changeset
1021 -- (AI-345): The task body procedure is not a primitive of the tagged
kono
parents:
diff changeset
1022 -- type
kono
parents:
diff changeset
1023
kono
parents:
diff changeset
1024 if Present (Tagged_Type)
kono
parents:
diff changeset
1025 and then Is_Concurrent_Record_Type (Tagged_Type)
kono
parents:
diff changeset
1026 and then Present (Corresponding_Concurrent_Type (Tagged_Type))
kono
parents:
diff changeset
1027 and then Is_Task_Type (Corresponding_Concurrent_Type (Tagged_Type))
kono
parents:
diff changeset
1028 and then Subp = Get_Task_Body_Procedure
kono
parents:
diff changeset
1029 (Corresponding_Concurrent_Type (Tagged_Type))
kono
parents:
diff changeset
1030 then
kono
parents:
diff changeset
1031 return;
kono
parents:
diff changeset
1032 end if;
kono
parents:
diff changeset
1033
kono
parents:
diff changeset
1034 -- If Subp is derived from a dispatching operation then it should
kono
parents:
diff changeset
1035 -- always be treated as dispatching. In this case various checks
kono
parents:
diff changeset
1036 -- below will be bypassed. Makes sure that late declarations for
kono
parents:
diff changeset
1037 -- inherited private subprograms are treated as dispatching, even
kono
parents:
diff changeset
1038 -- if the associated tagged type is already frozen.
kono
parents:
diff changeset
1039
kono
parents:
diff changeset
1040 Has_Dispatching_Parent :=
kono
parents:
diff changeset
1041 Present (Alias (Subp))
kono
parents:
diff changeset
1042 and then Is_Dispatching_Operation (Alias (Subp));
kono
parents:
diff changeset
1043
kono
parents:
diff changeset
1044 if No (Tagged_Type) then
kono
parents:
diff changeset
1045
kono
parents:
diff changeset
1046 -- Ada 2005 (AI-251): Check that Subp is not a primitive associated
kono
parents:
diff changeset
1047 -- with an abstract interface type unless the interface acts as a
kono
parents:
diff changeset
1048 -- parent type in a derivation. If the interface type is a formal
kono
parents:
diff changeset
1049 -- type then the operation is not primitive and therefore legal.
kono
parents:
diff changeset
1050
kono
parents:
diff changeset
1051 declare
kono
parents:
diff changeset
1052 E : Entity_Id;
kono
parents:
diff changeset
1053 Typ : Entity_Id;
kono
parents:
diff changeset
1054
kono
parents:
diff changeset
1055 begin
kono
parents:
diff changeset
1056 E := First_Entity (Subp);
kono
parents:
diff changeset
1057 while Present (E) loop
kono
parents:
diff changeset
1058
kono
parents:
diff changeset
1059 -- For an access parameter, check designated type
kono
parents:
diff changeset
1060
kono
parents:
diff changeset
1061 if Ekind (Etype (E)) = E_Anonymous_Access_Type then
kono
parents:
diff changeset
1062 Typ := Designated_Type (Etype (E));
kono
parents:
diff changeset
1063 else
kono
parents:
diff changeset
1064 Typ := Etype (E);
kono
parents:
diff changeset
1065 end if;
kono
parents:
diff changeset
1066
kono
parents:
diff changeset
1067 if Comes_From_Source (Subp)
kono
parents:
diff changeset
1068 and then Is_Interface (Typ)
kono
parents:
diff changeset
1069 and then not Is_Class_Wide_Type (Typ)
kono
parents:
diff changeset
1070 and then not Is_Derived_Type (Typ)
kono
parents:
diff changeset
1071 and then not Is_Generic_Type (Typ)
kono
parents:
diff changeset
1072 and then not In_Instance
kono
parents:
diff changeset
1073 then
kono
parents:
diff changeset
1074 Error_Msg_N ("??declaration of& is too late!", Subp);
kono
parents:
diff changeset
1075 Error_Msg_NE -- CODEFIX??
kono
parents:
diff changeset
1076 ("\??spec should appear immediately after declaration of "
kono
parents:
diff changeset
1077 & "& !", Subp, Typ);
kono
parents:
diff changeset
1078 exit;
kono
parents:
diff changeset
1079 end if;
kono
parents:
diff changeset
1080
kono
parents:
diff changeset
1081 Next_Entity (E);
kono
parents:
diff changeset
1082 end loop;
kono
parents:
diff changeset
1083
kono
parents:
diff changeset
1084 -- In case of functions check also the result type
kono
parents:
diff changeset
1085
kono
parents:
diff changeset
1086 if Ekind (Subp) = E_Function then
kono
parents:
diff changeset
1087 if Is_Access_Type (Etype (Subp)) then
kono
parents:
diff changeset
1088 Typ := Designated_Type (Etype (Subp));
kono
parents:
diff changeset
1089 else
kono
parents:
diff changeset
1090 Typ := Etype (Subp);
kono
parents:
diff changeset
1091 end if;
kono
parents:
diff changeset
1092
kono
parents:
diff changeset
1093 -- The following should be better commented, especially since
kono
parents:
diff changeset
1094 -- we just added several new conditions here ???
kono
parents:
diff changeset
1095
kono
parents:
diff changeset
1096 if Comes_From_Source (Subp)
kono
parents:
diff changeset
1097 and then Is_Interface (Typ)
kono
parents:
diff changeset
1098 and then not Is_Class_Wide_Type (Typ)
kono
parents:
diff changeset
1099 and then not Is_Derived_Type (Typ)
kono
parents:
diff changeset
1100 and then not Is_Generic_Type (Typ)
kono
parents:
diff changeset
1101 and then not In_Instance
kono
parents:
diff changeset
1102 then
kono
parents:
diff changeset
1103 Error_Msg_N ("??declaration of& is too late!", Subp);
kono
parents:
diff changeset
1104 Error_Msg_NE
kono
parents:
diff changeset
1105 ("\??spec should appear immediately after declaration of "
kono
parents:
diff changeset
1106 & "& !", Subp, Typ);
kono
parents:
diff changeset
1107 end if;
kono
parents:
diff changeset
1108 end if;
kono
parents:
diff changeset
1109 end;
kono
parents:
diff changeset
1110
kono
parents:
diff changeset
1111 return;
kono
parents:
diff changeset
1112
kono
parents:
diff changeset
1113 -- The subprograms build internally after the freezing point (such as
kono
parents:
diff changeset
1114 -- init procs, interface thunks, type support subprograms, and Offset
kono
parents:
diff changeset
1115 -- to top functions for accessing interface components in variable
kono
parents:
diff changeset
1116 -- size tagged types) are not primitives.
kono
parents:
diff changeset
1117
kono
parents:
diff changeset
1118 elsif Is_Frozen (Tagged_Type)
kono
parents:
diff changeset
1119 and then not Comes_From_Source (Subp)
kono
parents:
diff changeset
1120 and then not Has_Dispatching_Parent
kono
parents:
diff changeset
1121 then
kono
parents:
diff changeset
1122 -- Complete decoration of internally built subprograms that override
kono
parents:
diff changeset
1123 -- a dispatching primitive. These entities correspond with the
kono
parents:
diff changeset
1124 -- following cases:
kono
parents:
diff changeset
1125
kono
parents:
diff changeset
1126 -- 1. Ada 2005 (AI-391): Wrapper functions built by the expander
kono
parents:
diff changeset
1127 -- to override functions of nonabstract null extensions. These
kono
parents:
diff changeset
1128 -- primitives were added to the list of primitives of the tagged
kono
parents:
diff changeset
1129 -- type by Make_Controlling_Function_Wrappers. However, attribute
kono
parents:
diff changeset
1130 -- Is_Dispatching_Operation must be set to true.
kono
parents:
diff changeset
1131
kono
parents:
diff changeset
1132 -- 2. Ada 2005 (AI-251): Wrapper procedures of null interface
kono
parents:
diff changeset
1133 -- primitives.
kono
parents:
diff changeset
1134
kono
parents:
diff changeset
1135 -- 3. Subprograms associated with stream attributes (built by
kono
parents:
diff changeset
1136 -- New_Stream_Subprogram)
kono
parents:
diff changeset
1137
kono
parents:
diff changeset
1138 -- 4. Wrapper built for inherited operations with inherited class-
kono
parents:
diff changeset
1139 -- wide conditions, where the conditions include calls to other
kono
parents:
diff changeset
1140 -- overridden primitives. The wrappers include checks on these
kono
parents:
diff changeset
1141 -- modified conditions. (AI12-113).
kono
parents:
diff changeset
1142
kono
parents:
diff changeset
1143 if Present (Old_Subp)
kono
parents:
diff changeset
1144 and then Present (Overridden_Operation (Subp))
kono
parents:
diff changeset
1145 and then Is_Dispatching_Operation (Old_Subp)
kono
parents:
diff changeset
1146 then
kono
parents:
diff changeset
1147 pragma Assert
kono
parents:
diff changeset
1148 ((Ekind (Subp) = E_Function
kono
parents:
diff changeset
1149 and then Is_Dispatching_Operation (Old_Subp)
kono
parents:
diff changeset
1150 and then Is_Null_Extension (Base_Type (Etype (Subp))))
kono
parents:
diff changeset
1151
kono
parents:
diff changeset
1152 or else
kono
parents:
diff changeset
1153 (Ekind (Subp) = E_Procedure
kono
parents:
diff changeset
1154 and then Is_Dispatching_Operation (Old_Subp)
kono
parents:
diff changeset
1155 and then Present (Alias (Old_Subp))
kono
parents:
diff changeset
1156 and then Is_Null_Interface_Primitive
kono
parents:
diff changeset
1157 (Ultimate_Alias (Old_Subp)))
kono
parents:
diff changeset
1158
kono
parents:
diff changeset
1159 or else Get_TSS_Name (Subp) = TSS_Stream_Read
kono
parents:
diff changeset
1160 or else Get_TSS_Name (Subp) = TSS_Stream_Write
kono
parents:
diff changeset
1161
kono
parents:
diff changeset
1162 or else Present (Contract (Overridden_Operation (Subp))));
kono
parents:
diff changeset
1163
kono
parents:
diff changeset
1164 Check_Controlling_Formals (Tagged_Type, Subp);
kono
parents:
diff changeset
1165 Override_Dispatching_Operation (Tagged_Type, Old_Subp, Subp);
kono
parents:
diff changeset
1166 Set_Is_Dispatching_Operation (Subp);
kono
parents:
diff changeset
1167 end if;
kono
parents:
diff changeset
1168
kono
parents:
diff changeset
1169 return;
kono
parents:
diff changeset
1170
kono
parents:
diff changeset
1171 -- The operation may be a child unit, whose scope is the defining
kono
parents:
diff changeset
1172 -- package, but which is not a primitive operation of the type.
kono
parents:
diff changeset
1173
kono
parents:
diff changeset
1174 elsif Is_Child_Unit (Subp) then
kono
parents:
diff changeset
1175 return;
kono
parents:
diff changeset
1176
kono
parents:
diff changeset
1177 -- If the subprogram is not defined in a package spec, the only case
kono
parents:
diff changeset
1178 -- where it can be a dispatching op is when it overrides an operation
kono
parents:
diff changeset
1179 -- before the freezing point of the type.
kono
parents:
diff changeset
1180
kono
parents:
diff changeset
1181 elsif ((not Is_Package_Or_Generic_Package (Scope (Subp)))
kono
parents:
diff changeset
1182 or else In_Package_Body (Scope (Subp)))
kono
parents:
diff changeset
1183 and then not Has_Dispatching_Parent
kono
parents:
diff changeset
1184 then
kono
parents:
diff changeset
1185 if not Comes_From_Source (Subp)
kono
parents:
diff changeset
1186 or else (Present (Old_Subp) and then not Is_Frozen (Tagged_Type))
kono
parents:
diff changeset
1187 then
kono
parents:
diff changeset
1188 null;
kono
parents:
diff changeset
1189
kono
parents:
diff changeset
1190 -- If the type is already frozen, the overriding is not allowed
kono
parents:
diff changeset
1191 -- except when Old_Subp is not a dispatching operation (which can
kono
parents:
diff changeset
1192 -- occur when Old_Subp was inherited by an untagged type). However,
kono
parents:
diff changeset
1193 -- a body with no previous spec freezes the type *after* its
kono
parents:
diff changeset
1194 -- declaration, and therefore is a legal overriding (unless the type
kono
parents:
diff changeset
1195 -- has already been frozen). Only the first such body is legal.
kono
parents:
diff changeset
1196
kono
parents:
diff changeset
1197 elsif Present (Old_Subp)
kono
parents:
diff changeset
1198 and then Is_Dispatching_Operation (Old_Subp)
kono
parents:
diff changeset
1199 then
kono
parents:
diff changeset
1200 if Comes_From_Source (Subp)
kono
parents:
diff changeset
1201 and then
kono
parents:
diff changeset
1202 (Nkind (Unit_Declaration_Node (Subp)) = N_Subprogram_Body
kono
parents:
diff changeset
1203 or else Nkind (Unit_Declaration_Node (Subp)) in N_Body_Stub)
kono
parents:
diff changeset
1204 then
kono
parents:
diff changeset
1205 declare
kono
parents:
diff changeset
1206 Subp_Body : constant Node_Id := Unit_Declaration_Node (Subp);
kono
parents:
diff changeset
1207 Decl_Item : Node_Id;
kono
parents:
diff changeset
1208
kono
parents:
diff changeset
1209 begin
kono
parents:
diff changeset
1210 -- ??? The checks here for whether the type has been frozen
kono
parents:
diff changeset
1211 -- prior to the new body are not complete. It's not simple
kono
parents:
diff changeset
1212 -- to check frozenness at this point since the body has
kono
parents:
diff changeset
1213 -- already caused the type to be prematurely frozen in
kono
parents:
diff changeset
1214 -- Analyze_Declarations, but we're forced to recheck this
kono
parents:
diff changeset
1215 -- here because of the odd rule interpretation that allows
kono
parents:
diff changeset
1216 -- the overriding if the type wasn't frozen prior to the
kono
parents:
diff changeset
1217 -- body. The freezing action should probably be delayed
kono
parents:
diff changeset
1218 -- until after the spec is seen, but that's a tricky
kono
parents:
diff changeset
1219 -- change to the delicate freezing code.
kono
parents:
diff changeset
1220
kono
parents:
diff changeset
1221 -- Look at each declaration following the type up until the
kono
parents:
diff changeset
1222 -- new subprogram body. If any of the declarations is a body
kono
parents:
diff changeset
1223 -- then the type has been frozen already so the overriding
kono
parents:
diff changeset
1224 -- primitive is illegal.
kono
parents:
diff changeset
1225
kono
parents:
diff changeset
1226 Decl_Item := Next (Parent (Tagged_Type));
kono
parents:
diff changeset
1227 while Present (Decl_Item)
kono
parents:
diff changeset
1228 and then (Decl_Item /= Subp_Body)
kono
parents:
diff changeset
1229 loop
kono
parents:
diff changeset
1230 if Comes_From_Source (Decl_Item)
kono
parents:
diff changeset
1231 and then (Nkind (Decl_Item) in N_Proper_Body
kono
parents:
diff changeset
1232 or else Nkind (Decl_Item) in N_Body_Stub)
kono
parents:
diff changeset
1233 then
kono
parents:
diff changeset
1234 Error_Msg_N ("overriding of& is too late!", Subp);
kono
parents:
diff changeset
1235 Error_Msg_N
kono
parents:
diff changeset
1236 ("\spec should appear immediately after the type!",
kono
parents:
diff changeset
1237 Subp);
kono
parents:
diff changeset
1238 exit;
kono
parents:
diff changeset
1239 end if;
kono
parents:
diff changeset
1240
kono
parents:
diff changeset
1241 Next (Decl_Item);
kono
parents:
diff changeset
1242 end loop;
kono
parents:
diff changeset
1243
kono
parents:
diff changeset
1244 -- If the subprogram doesn't follow in the list of
kono
parents:
diff changeset
1245 -- declarations including the type then the type has
kono
parents:
diff changeset
1246 -- definitely been frozen already and the body is illegal.
kono
parents:
diff changeset
1247
kono
parents:
diff changeset
1248 if No (Decl_Item) then
kono
parents:
diff changeset
1249 Error_Msg_N ("overriding of& is too late!", Subp);
kono
parents:
diff changeset
1250 Error_Msg_N
kono
parents:
diff changeset
1251 ("\spec should appear immediately after the type!",
kono
parents:
diff changeset
1252 Subp);
kono
parents:
diff changeset
1253
kono
parents:
diff changeset
1254 elsif Is_Frozen (Subp) then
kono
parents:
diff changeset
1255
kono
parents:
diff changeset
1256 -- The subprogram body declares a primitive operation.
kono
parents:
diff changeset
1257 -- If the subprogram is already frozen, we must update
kono
parents:
diff changeset
1258 -- its dispatching information explicitly here. The
kono
parents:
diff changeset
1259 -- information is taken from the overridden subprogram.
kono
parents:
diff changeset
1260 -- We must also generate a cross-reference entry because
kono
parents:
diff changeset
1261 -- references to other primitives were already created
kono
parents:
diff changeset
1262 -- when type was frozen.
kono
parents:
diff changeset
1263
kono
parents:
diff changeset
1264 Body_Is_Last_Primitive := True;
kono
parents:
diff changeset
1265
kono
parents:
diff changeset
1266 if Present (DTC_Entity (Old_Subp)) then
kono
parents:
diff changeset
1267 Set_DTC_Entity (Subp, DTC_Entity (Old_Subp));
kono
parents:
diff changeset
1268 Set_DT_Position_Value (Subp, DT_Position (Old_Subp));
kono
parents:
diff changeset
1269
kono
parents:
diff changeset
1270 if not Restriction_Active (No_Dispatching_Calls) then
kono
parents:
diff changeset
1271 if Building_Static_DT (Tagged_Type) then
kono
parents:
diff changeset
1272
kono
parents:
diff changeset
1273 -- If the static dispatch table has not been
kono
parents:
diff changeset
1274 -- built then there is nothing else to do now;
kono
parents:
diff changeset
1275 -- otherwise we notify that we cannot build the
kono
parents:
diff changeset
1276 -- static dispatch table.
kono
parents:
diff changeset
1277
kono
parents:
diff changeset
1278 if Has_Dispatch_Table (Tagged_Type) then
kono
parents:
diff changeset
1279 Error_Msg_N
kono
parents:
diff changeset
1280 ("overriding of& is too late for building "
kono
parents:
diff changeset
1281 & " static dispatch tables!", Subp);
kono
parents:
diff changeset
1282 Error_Msg_N
kono
parents:
diff changeset
1283 ("\spec should appear immediately after "
kono
parents:
diff changeset
1284 & "the type!", Subp);
kono
parents:
diff changeset
1285 end if;
kono
parents:
diff changeset
1286
kono
parents:
diff changeset
1287 -- No code required to register primitives in VM
kono
parents:
diff changeset
1288 -- targets
kono
parents:
diff changeset
1289
kono
parents:
diff changeset
1290 elsif not Tagged_Type_Expansion then
kono
parents:
diff changeset
1291 null;
kono
parents:
diff changeset
1292
kono
parents:
diff changeset
1293 else
kono
parents:
diff changeset
1294 Insert_Actions_After (Subp_Body,
kono
parents:
diff changeset
1295 Register_Primitive (Sloc (Subp_Body),
kono
parents:
diff changeset
1296 Prim => Subp));
kono
parents:
diff changeset
1297 end if;
kono
parents:
diff changeset
1298
kono
parents:
diff changeset
1299 -- Indicate that this is an overriding operation,
kono
parents:
diff changeset
1300 -- and replace the overridden entry in the list of
kono
parents:
diff changeset
1301 -- primitive operations, which is used for xref
kono
parents:
diff changeset
1302 -- generation subsequently.
kono
parents:
diff changeset
1303
kono
parents:
diff changeset
1304 Generate_Reference (Tagged_Type, Subp, 'P', False);
kono
parents:
diff changeset
1305 Override_Dispatching_Operation
kono
parents:
diff changeset
1306 (Tagged_Type, Old_Subp, Subp);
kono
parents:
diff changeset
1307 end if;
kono
parents:
diff changeset
1308 end if;
kono
parents:
diff changeset
1309 end if;
kono
parents:
diff changeset
1310 end;
kono
parents:
diff changeset
1311
kono
parents:
diff changeset
1312 else
kono
parents:
diff changeset
1313 Error_Msg_N ("overriding of& is too late!", Subp);
kono
parents:
diff changeset
1314 Error_Msg_N
kono
parents:
diff changeset
1315 ("\subprogram spec should appear immediately after the type!",
kono
parents:
diff changeset
1316 Subp);
kono
parents:
diff changeset
1317 end if;
kono
parents:
diff changeset
1318
kono
parents:
diff changeset
1319 -- If the type is not frozen yet and we are not in the overriding
kono
parents:
diff changeset
1320 -- case it looks suspiciously like an attempt to define a primitive
kono
parents:
diff changeset
1321 -- operation, which requires the declaration to be in a package spec
kono
parents:
diff changeset
1322 -- (3.2.3(6)). Only report cases where the type and subprogram are
kono
parents:
diff changeset
1323 -- in the same declaration list (by checking the enclosing parent
kono
parents:
diff changeset
1324 -- declarations), to avoid spurious warnings on subprograms in
kono
parents:
diff changeset
1325 -- instance bodies when the type is declared in the instance spec
kono
parents:
diff changeset
1326 -- but hasn't been frozen by the instance body.
kono
parents:
diff changeset
1327
kono
parents:
diff changeset
1328 elsif not Is_Frozen (Tagged_Type)
kono
parents:
diff changeset
1329 and then In_Same_List (Parent (Tagged_Type), Parent (Parent (Subp)))
kono
parents:
diff changeset
1330 then
kono
parents:
diff changeset
1331 Error_Msg_N
kono
parents:
diff changeset
1332 ("??not dispatching (must be defined in a package spec)", Subp);
kono
parents:
diff changeset
1333 return;
kono
parents:
diff changeset
1334
kono
parents:
diff changeset
1335 -- When the type is frozen, it is legitimate to define a new
kono
parents:
diff changeset
1336 -- non-primitive operation.
kono
parents:
diff changeset
1337
kono
parents:
diff changeset
1338 else
kono
parents:
diff changeset
1339 return;
kono
parents:
diff changeset
1340 end if;
kono
parents:
diff changeset
1341
kono
parents:
diff changeset
1342 -- Now, we are sure that the scope is a package spec. If the subprogram
kono
parents:
diff changeset
1343 -- is declared after the freezing point of the type that's an error
kono
parents:
diff changeset
1344
kono
parents:
diff changeset
1345 elsif Is_Frozen (Tagged_Type) and then not Has_Dispatching_Parent then
kono
parents:
diff changeset
1346 Error_Msg_N ("this primitive operation is declared too late", Subp);
kono
parents:
diff changeset
1347 Error_Msg_NE
kono
parents:
diff changeset
1348 ("??no primitive operations for& after this line",
kono
parents:
diff changeset
1349 Freeze_Node (Tagged_Type),
kono
parents:
diff changeset
1350 Tagged_Type);
kono
parents:
diff changeset
1351 return;
kono
parents:
diff changeset
1352 end if;
kono
parents:
diff changeset
1353
kono
parents:
diff changeset
1354 Check_Controlling_Formals (Tagged_Type, Subp);
kono
parents:
diff changeset
1355
kono
parents:
diff changeset
1356 Ovr_Subp := Old_Subp;
kono
parents:
diff changeset
1357
kono
parents:
diff changeset
1358 -- [Ada 2012:AI-0125]: Search for inherited hidden primitive that may be
kono
parents:
diff changeset
1359 -- overridden by Subp. This only applies to source subprograms, and
kono
parents:
diff changeset
1360 -- their declaration must carry an explicit overriding indicator.
kono
parents:
diff changeset
1361
kono
parents:
diff changeset
1362 if No (Ovr_Subp)
kono
parents:
diff changeset
1363 and then Ada_Version >= Ada_2012
kono
parents:
diff changeset
1364 and then Comes_From_Source (Subp)
kono
parents:
diff changeset
1365 and then
kono
parents:
diff changeset
1366 Nkind (Unit_Declaration_Node (Subp)) = N_Subprogram_Declaration
kono
parents:
diff changeset
1367 then
kono
parents:
diff changeset
1368 Ovr_Subp := Find_Hidden_Overridden_Primitive (Subp);
kono
parents:
diff changeset
1369
kono
parents:
diff changeset
1370 -- Verify that the proper overriding indicator has been supplied.
kono
parents:
diff changeset
1371
kono
parents:
diff changeset
1372 if Present (Ovr_Subp)
kono
parents:
diff changeset
1373 and then
kono
parents:
diff changeset
1374 not Must_Override (Specification (Unit_Declaration_Node (Subp)))
kono
parents:
diff changeset
1375 then
kono
parents:
diff changeset
1376 Error_Msg_NE ("missing overriding indicator for&", Subp, Subp);
kono
parents:
diff changeset
1377 end if;
kono
parents:
diff changeset
1378 end if;
kono
parents:
diff changeset
1379
kono
parents:
diff changeset
1380 -- Now it should be a correct primitive operation, put it in the list
kono
parents:
diff changeset
1381
kono
parents:
diff changeset
1382 if Present (Ovr_Subp) then
kono
parents:
diff changeset
1383
kono
parents:
diff changeset
1384 -- If the type has interfaces we complete this check after we set
kono
parents:
diff changeset
1385 -- attribute Is_Dispatching_Operation.
kono
parents:
diff changeset
1386
kono
parents:
diff changeset
1387 Check_Subtype_Conformant (Subp, Ovr_Subp);
kono
parents:
diff changeset
1388
kono
parents:
diff changeset
1389 -- A primitive operation with the name of a primitive controlled
kono
parents:
diff changeset
1390 -- operation does not override a non-visible overriding controlled
kono
parents:
diff changeset
1391 -- operation, i.e. one declared in a private part when the full
kono
parents:
diff changeset
1392 -- view of a type is controlled. Conversely, it will override a
kono
parents:
diff changeset
1393 -- visible operation that may be declared in a partial view when
kono
parents:
diff changeset
1394 -- the full view is controlled.
kono
parents:
diff changeset
1395
kono
parents:
diff changeset
1396 if Nam_In (Chars (Subp), Name_Initialize, Name_Adjust, Name_Finalize)
kono
parents:
diff changeset
1397 and then Is_Controlled (Tagged_Type)
kono
parents:
diff changeset
1398 and then not Is_Visibly_Controlled (Tagged_Type)
kono
parents:
diff changeset
1399 and then not Is_Inherited_Public_Operation (Ovr_Subp)
kono
parents:
diff changeset
1400 then
kono
parents:
diff changeset
1401 Set_Overridden_Operation (Subp, Empty);
kono
parents:
diff changeset
1402
kono
parents:
diff changeset
1403 -- If the subprogram specification carries an overriding
kono
parents:
diff changeset
1404 -- indicator, no need for the warning: it is either redundant,
kono
parents:
diff changeset
1405 -- or else an error will be reported.
kono
parents:
diff changeset
1406
kono
parents:
diff changeset
1407 if Nkind (Parent (Subp)) = N_Procedure_Specification
kono
parents:
diff changeset
1408 and then
kono
parents:
diff changeset
1409 (Must_Override (Parent (Subp))
kono
parents:
diff changeset
1410 or else Must_Not_Override (Parent (Subp)))
kono
parents:
diff changeset
1411 then
kono
parents:
diff changeset
1412 null;
kono
parents:
diff changeset
1413
kono
parents:
diff changeset
1414 -- Here we need the warning
kono
parents:
diff changeset
1415
kono
parents:
diff changeset
1416 else
kono
parents:
diff changeset
1417 Error_Msg_NE
kono
parents:
diff changeset
1418 ("operation does not override inherited&??", Subp, Subp);
kono
parents:
diff changeset
1419 end if;
kono
parents:
diff changeset
1420
kono
parents:
diff changeset
1421 else
kono
parents:
diff changeset
1422 Override_Dispatching_Operation (Tagged_Type, Ovr_Subp, Subp);
kono
parents:
diff changeset
1423
kono
parents:
diff changeset
1424 -- Ada 2005 (AI-251): In case of late overriding of a primitive
kono
parents:
diff changeset
1425 -- that covers abstract interface subprograms we must register it
kono
parents:
diff changeset
1426 -- in all the secondary dispatch tables associated with abstract
kono
parents:
diff changeset
1427 -- interfaces. We do this now only if not building static tables,
kono
parents:
diff changeset
1428 -- nor when the expander is inactive (we avoid trying to register
kono
parents:
diff changeset
1429 -- primitives in semantics-only mode, since the type may not have
kono
parents:
diff changeset
1430 -- an associated dispatch table). Otherwise the patch code is
kono
parents:
diff changeset
1431 -- emitted after those tables are built, to prevent access before
kono
parents:
diff changeset
1432 -- elaboration in gigi.
kono
parents:
diff changeset
1433
kono
parents:
diff changeset
1434 if Body_Is_Last_Primitive and then Expander_Active then
kono
parents:
diff changeset
1435 declare
kono
parents:
diff changeset
1436 Subp_Body : constant Node_Id := Unit_Declaration_Node (Subp);
kono
parents:
diff changeset
1437 Elmt : Elmt_Id;
kono
parents:
diff changeset
1438 Prim : Node_Id;
kono
parents:
diff changeset
1439
kono
parents:
diff changeset
1440 begin
kono
parents:
diff changeset
1441 Elmt := First_Elmt (Primitive_Operations (Tagged_Type));
kono
parents:
diff changeset
1442 while Present (Elmt) loop
kono
parents:
diff changeset
1443 Prim := Node (Elmt);
kono
parents:
diff changeset
1444
kono
parents:
diff changeset
1445 -- No code required to register primitives in VM targets
kono
parents:
diff changeset
1446
kono
parents:
diff changeset
1447 if Present (Alias (Prim))
kono
parents:
diff changeset
1448 and then Present (Interface_Alias (Prim))
kono
parents:
diff changeset
1449 and then Alias (Prim) = Subp
kono
parents:
diff changeset
1450 and then not Building_Static_DT (Tagged_Type)
kono
parents:
diff changeset
1451 and then Tagged_Type_Expansion
kono
parents:
diff changeset
1452 then
kono
parents:
diff changeset
1453 Insert_Actions_After (Subp_Body,
kono
parents:
diff changeset
1454 Register_Primitive (Sloc (Subp_Body), Prim => Prim));
kono
parents:
diff changeset
1455 end if;
kono
parents:
diff changeset
1456
kono
parents:
diff changeset
1457 Next_Elmt (Elmt);
kono
parents:
diff changeset
1458 end loop;
kono
parents:
diff changeset
1459
kono
parents:
diff changeset
1460 -- Redisplay the contents of the updated dispatch table
kono
parents:
diff changeset
1461
kono
parents:
diff changeset
1462 if Debug_Flag_ZZ then
kono
parents:
diff changeset
1463 Write_Str ("Late overriding: ");
kono
parents:
diff changeset
1464 Write_DT (Tagged_Type);
kono
parents:
diff changeset
1465 end if;
kono
parents:
diff changeset
1466 end;
kono
parents:
diff changeset
1467 end if;
kono
parents:
diff changeset
1468 end if;
kono
parents:
diff changeset
1469
kono
parents:
diff changeset
1470 -- If the tagged type is a concurrent type then we must be compiling
kono
parents:
diff changeset
1471 -- with no code generation (we are either compiling a generic unit or
kono
parents:
diff changeset
1472 -- compiling under -gnatc mode) because we have previously tested that
kono
parents:
diff changeset
1473 -- no serious errors has been reported. In this case we do not add the
kono
parents:
diff changeset
1474 -- primitive to the list of primitives of Tagged_Type but we leave the
kono
parents:
diff changeset
1475 -- primitive decorated as a dispatching operation to be able to analyze
kono
parents:
diff changeset
1476 -- and report errors associated with the Object.Operation notation.
kono
parents:
diff changeset
1477
kono
parents:
diff changeset
1478 elsif Is_Concurrent_Type (Tagged_Type) then
kono
parents:
diff changeset
1479 pragma Assert (not Expander_Active);
kono
parents:
diff changeset
1480
kono
parents:
diff changeset
1481 -- Attach operation to list of primitives of the synchronized type
kono
parents:
diff changeset
1482 -- itself, for ASIS use.
kono
parents:
diff changeset
1483
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1484 Add_Dispatching_Operation (Tagged_Type, Subp);
111
kono
parents:
diff changeset
1485
kono
parents:
diff changeset
1486 -- If no old subprogram, then we add this as a dispatching operation,
kono
parents:
diff changeset
1487 -- but we avoid doing this if an error was posted, to prevent annoying
kono
parents:
diff changeset
1488 -- cascaded errors.
kono
parents:
diff changeset
1489
kono
parents:
diff changeset
1490 elsif not Error_Posted (Subp) then
kono
parents:
diff changeset
1491 Add_Dispatching_Operation (Tagged_Type, Subp);
kono
parents:
diff changeset
1492 end if;
kono
parents:
diff changeset
1493
kono
parents:
diff changeset
1494 Set_Is_Dispatching_Operation (Subp, True);
kono
parents:
diff changeset
1495
kono
parents:
diff changeset
1496 -- Ada 2005 (AI-251): If the type implements interfaces we must check
kono
parents:
diff changeset
1497 -- subtype conformance against all the interfaces covered by this
kono
parents:
diff changeset
1498 -- primitive.
kono
parents:
diff changeset
1499
kono
parents:
diff changeset
1500 if Present (Ovr_Subp)
kono
parents:
diff changeset
1501 and then Has_Interfaces (Tagged_Type)
kono
parents:
diff changeset
1502 then
kono
parents:
diff changeset
1503 declare
kono
parents:
diff changeset
1504 Ifaces_List : Elist_Id;
kono
parents:
diff changeset
1505 Iface_Elmt : Elmt_Id;
kono
parents:
diff changeset
1506 Iface_Prim_Elmt : Elmt_Id;
kono
parents:
diff changeset
1507 Iface_Prim : Entity_Id;
kono
parents:
diff changeset
1508 Ret_Typ : Entity_Id;
kono
parents:
diff changeset
1509
kono
parents:
diff changeset
1510 begin
kono
parents:
diff changeset
1511 Collect_Interfaces (Tagged_Type, Ifaces_List);
kono
parents:
diff changeset
1512
kono
parents:
diff changeset
1513 Iface_Elmt := First_Elmt (Ifaces_List);
kono
parents:
diff changeset
1514 while Present (Iface_Elmt) loop
kono
parents:
diff changeset
1515 if not Is_Ancestor (Node (Iface_Elmt), Tagged_Type) then
kono
parents:
diff changeset
1516 Iface_Prim_Elmt :=
kono
parents:
diff changeset
1517 First_Elmt (Primitive_Operations (Node (Iface_Elmt)));
kono
parents:
diff changeset
1518 while Present (Iface_Prim_Elmt) loop
kono
parents:
diff changeset
1519 Iface_Prim := Node (Iface_Prim_Elmt);
kono
parents:
diff changeset
1520
kono
parents:
diff changeset
1521 if Is_Interface_Conformant
kono
parents:
diff changeset
1522 (Tagged_Type, Iface_Prim, Subp)
kono
parents:
diff changeset
1523 then
kono
parents:
diff changeset
1524 -- Handle procedures, functions whose return type
kono
parents:
diff changeset
1525 -- matches, or functions not returning interfaces
kono
parents:
diff changeset
1526
kono
parents:
diff changeset
1527 if Ekind (Subp) = E_Procedure
kono
parents:
diff changeset
1528 or else Etype (Iface_Prim) = Etype (Subp)
kono
parents:
diff changeset
1529 or else not Is_Interface (Etype (Iface_Prim))
kono
parents:
diff changeset
1530 then
kono
parents:
diff changeset
1531 Check_Subtype_Conformant
kono
parents:
diff changeset
1532 (New_Id => Subp,
kono
parents:
diff changeset
1533 Old_Id => Iface_Prim,
kono
parents:
diff changeset
1534 Err_Loc => Subp,
kono
parents:
diff changeset
1535 Skip_Controlling_Formals => True);
kono
parents:
diff changeset
1536
kono
parents:
diff changeset
1537 -- Handle functions returning interfaces
kono
parents:
diff changeset
1538
kono
parents:
diff changeset
1539 elsif Implements_Interface
kono
parents:
diff changeset
1540 (Etype (Subp), Etype (Iface_Prim))
kono
parents:
diff changeset
1541 then
kono
parents:
diff changeset
1542 -- Temporarily force both entities to return the
kono
parents:
diff changeset
1543 -- same type. Required because Subtype_Conformant
kono
parents:
diff changeset
1544 -- does not handle this case.
kono
parents:
diff changeset
1545
kono
parents:
diff changeset
1546 Ret_Typ := Etype (Iface_Prim);
kono
parents:
diff changeset
1547 Set_Etype (Iface_Prim, Etype (Subp));
kono
parents:
diff changeset
1548
kono
parents:
diff changeset
1549 Check_Subtype_Conformant
kono
parents:
diff changeset
1550 (New_Id => Subp,
kono
parents:
diff changeset
1551 Old_Id => Iface_Prim,
kono
parents:
diff changeset
1552 Err_Loc => Subp,
kono
parents:
diff changeset
1553 Skip_Controlling_Formals => True);
kono
parents:
diff changeset
1554
kono
parents:
diff changeset
1555 Set_Etype (Iface_Prim, Ret_Typ);
kono
parents:
diff changeset
1556 end if;
kono
parents:
diff changeset
1557 end if;
kono
parents:
diff changeset
1558
kono
parents:
diff changeset
1559 Next_Elmt (Iface_Prim_Elmt);
kono
parents:
diff changeset
1560 end loop;
kono
parents:
diff changeset
1561 end if;
kono
parents:
diff changeset
1562
kono
parents:
diff changeset
1563 Next_Elmt (Iface_Elmt);
kono
parents:
diff changeset
1564 end loop;
kono
parents:
diff changeset
1565 end;
kono
parents:
diff changeset
1566 end if;
kono
parents:
diff changeset
1567
kono
parents:
diff changeset
1568 if not Body_Is_Last_Primitive then
kono
parents:
diff changeset
1569 Set_DT_Position_Value (Subp, No_Uint);
kono
parents:
diff changeset
1570
kono
parents:
diff changeset
1571 elsif Has_Controlled_Component (Tagged_Type)
kono
parents:
diff changeset
1572 and then Nam_In (Chars (Subp), Name_Initialize,
kono
parents:
diff changeset
1573 Name_Adjust,
kono
parents:
diff changeset
1574 Name_Finalize,
kono
parents:
diff changeset
1575 Name_Finalize_Address)
kono
parents:
diff changeset
1576 then
kono
parents:
diff changeset
1577 declare
kono
parents:
diff changeset
1578 F_Node : constant Node_Id := Freeze_Node (Tagged_Type);
kono
parents:
diff changeset
1579 Decl : Node_Id;
kono
parents:
diff changeset
1580 Old_P : Entity_Id;
kono
parents:
diff changeset
1581 Old_Bod : Node_Id;
kono
parents:
diff changeset
1582 Old_Spec : Entity_Id;
kono
parents:
diff changeset
1583
kono
parents:
diff changeset
1584 C_Names : constant array (1 .. 4) of Name_Id :=
kono
parents:
diff changeset
1585 (Name_Initialize,
kono
parents:
diff changeset
1586 Name_Adjust,
kono
parents:
diff changeset
1587 Name_Finalize,
kono
parents:
diff changeset
1588 Name_Finalize_Address);
kono
parents:
diff changeset
1589
kono
parents:
diff changeset
1590 D_Names : constant array (1 .. 4) of TSS_Name_Type :=
kono
parents:
diff changeset
1591 (TSS_Deep_Initialize,
kono
parents:
diff changeset
1592 TSS_Deep_Adjust,
kono
parents:
diff changeset
1593 TSS_Deep_Finalize,
kono
parents:
diff changeset
1594 TSS_Finalize_Address);
kono
parents:
diff changeset
1595
kono
parents:
diff changeset
1596 begin
kono
parents:
diff changeset
1597 -- Remove previous controlled function which was constructed and
kono
parents:
diff changeset
1598 -- analyzed when the type was frozen. This requires removing the
kono
parents:
diff changeset
1599 -- body of the redefined primitive, as well as its specification
kono
parents:
diff changeset
1600 -- if needed (there is no spec created for Deep_Initialize, see
kono
parents:
diff changeset
1601 -- exp_ch3.adb). We must also dismantle the exception information
kono
parents:
diff changeset
1602 -- that may have been generated for it when front end zero-cost
kono
parents:
diff changeset
1603 -- tables are enabled.
kono
parents:
diff changeset
1604
kono
parents:
diff changeset
1605 for J in D_Names'Range loop
kono
parents:
diff changeset
1606 Old_P := TSS (Tagged_Type, D_Names (J));
kono
parents:
diff changeset
1607
kono
parents:
diff changeset
1608 if Present (Old_P)
kono
parents:
diff changeset
1609 and then Chars (Subp) = C_Names (J)
kono
parents:
diff changeset
1610 then
kono
parents:
diff changeset
1611 Old_Bod := Unit_Declaration_Node (Old_P);
kono
parents:
diff changeset
1612 Remove (Old_Bod);
kono
parents:
diff changeset
1613 Set_Is_Eliminated (Old_P);
kono
parents:
diff changeset
1614 Set_Scope (Old_P, Scope (Current_Scope));
kono
parents:
diff changeset
1615
kono
parents:
diff changeset
1616 if Nkind (Old_Bod) = N_Subprogram_Body
kono
parents:
diff changeset
1617 and then Present (Corresponding_Spec (Old_Bod))
kono
parents:
diff changeset
1618 then
kono
parents:
diff changeset
1619 Old_Spec := Corresponding_Spec (Old_Bod);
kono
parents:
diff changeset
1620 Set_Has_Completion (Old_Spec, False);
kono
parents:
diff changeset
1621 end if;
kono
parents:
diff changeset
1622 end if;
kono
parents:
diff changeset
1623 end loop;
kono
parents:
diff changeset
1624
kono
parents:
diff changeset
1625 Build_Late_Proc (Tagged_Type, Chars (Subp));
kono
parents:
diff changeset
1626
kono
parents:
diff changeset
1627 -- The new operation is added to the actions of the freeze node
kono
parents:
diff changeset
1628 -- for the type, but this node has already been analyzed, so we
kono
parents:
diff changeset
1629 -- must retrieve and analyze explicitly the new body.
kono
parents:
diff changeset
1630
kono
parents:
diff changeset
1631 if Present (F_Node)
kono
parents:
diff changeset
1632 and then Present (Actions (F_Node))
kono
parents:
diff changeset
1633 then
kono
parents:
diff changeset
1634 Decl := Last (Actions (F_Node));
kono
parents:
diff changeset
1635 Analyze (Decl);
kono
parents:
diff changeset
1636 end if;
kono
parents:
diff changeset
1637 end;
kono
parents:
diff changeset
1638 end if;
kono
parents:
diff changeset
1639
kono
parents:
diff changeset
1640 -- For similarity with record extensions, in Ada 9X the language should
kono
parents:
diff changeset
1641 -- have disallowed adding visible operations to a tagged type after
kono
parents:
diff changeset
1642 -- deriving a private extension from it. Report a warning if this
kono
parents:
diff changeset
1643 -- primitive is defined after a private extension of Tagged_Type.
kono
parents:
diff changeset
1644
kono
parents:
diff changeset
1645 Warn_On_Late_Primitive_After_Private_Extension (Tagged_Type, Subp);
kono
parents:
diff changeset
1646 end Check_Dispatching_Operation;
kono
parents:
diff changeset
1647
kono
parents:
diff changeset
1648 ------------------------------------------
kono
parents:
diff changeset
1649 -- Check_Operation_From_Incomplete_Type --
kono
parents:
diff changeset
1650 ------------------------------------------
kono
parents:
diff changeset
1651
kono
parents:
diff changeset
1652 procedure Check_Operation_From_Incomplete_Type
kono
parents:
diff changeset
1653 (Subp : Entity_Id;
kono
parents:
diff changeset
1654 Typ : Entity_Id)
kono
parents:
diff changeset
1655 is
kono
parents:
diff changeset
1656 Full : constant Entity_Id := Full_View (Typ);
kono
parents:
diff changeset
1657 Parent_Typ : constant Entity_Id := Etype (Full);
kono
parents:
diff changeset
1658 Old_Prim : constant Elist_Id := Primitive_Operations (Parent_Typ);
kono
parents:
diff changeset
1659 New_Prim : constant Elist_Id := Primitive_Operations (Full);
kono
parents:
diff changeset
1660 Op1, Op2 : Elmt_Id;
kono
parents:
diff changeset
1661 Prev : Elmt_Id := No_Elmt;
kono
parents:
diff changeset
1662
kono
parents:
diff changeset
1663 function Derives_From (Parent_Subp : Entity_Id) return Boolean;
kono
parents:
diff changeset
1664 -- Check that Subp has profile of an operation derived from Parent_Subp.
kono
parents:
diff changeset
1665 -- Subp must have a parameter or result type that is Typ or an access
kono
parents:
diff changeset
1666 -- parameter or access result type that designates Typ.
kono
parents:
diff changeset
1667
kono
parents:
diff changeset
1668 ------------------
kono
parents:
diff changeset
1669 -- Derives_From --
kono
parents:
diff changeset
1670 ------------------
kono
parents:
diff changeset
1671
kono
parents:
diff changeset
1672 function Derives_From (Parent_Subp : Entity_Id) return Boolean is
kono
parents:
diff changeset
1673 F1, F2 : Entity_Id;
kono
parents:
diff changeset
1674
kono
parents:
diff changeset
1675 begin
kono
parents:
diff changeset
1676 if Chars (Parent_Subp) /= Chars (Subp) then
kono
parents:
diff changeset
1677 return False;
kono
parents:
diff changeset
1678 end if;
kono
parents:
diff changeset
1679
kono
parents:
diff changeset
1680 -- Check that the type of controlling formals is derived from the
kono
parents:
diff changeset
1681 -- parent subprogram's controlling formal type (or designated type
kono
parents:
diff changeset
1682 -- if the formal type is an anonymous access type).
kono
parents:
diff changeset
1683
kono
parents:
diff changeset
1684 F1 := First_Formal (Parent_Subp);
kono
parents:
diff changeset
1685 F2 := First_Formal (Subp);
kono
parents:
diff changeset
1686 while Present (F1) and then Present (F2) loop
kono
parents:
diff changeset
1687 if Ekind (Etype (F1)) = E_Anonymous_Access_Type then
kono
parents:
diff changeset
1688 if Ekind (Etype (F2)) /= E_Anonymous_Access_Type then
kono
parents:
diff changeset
1689 return False;
kono
parents:
diff changeset
1690 elsif Designated_Type (Etype (F1)) = Parent_Typ
kono
parents:
diff changeset
1691 and then Designated_Type (Etype (F2)) /= Full
kono
parents:
diff changeset
1692 then
kono
parents:
diff changeset
1693 return False;
kono
parents:
diff changeset
1694 end if;
kono
parents:
diff changeset
1695
kono
parents:
diff changeset
1696 elsif Ekind (Etype (F2)) = E_Anonymous_Access_Type then
kono
parents:
diff changeset
1697 return False;
kono
parents:
diff changeset
1698
kono
parents:
diff changeset
1699 elsif Etype (F1) = Parent_Typ and then Etype (F2) /= Full then
kono
parents:
diff changeset
1700 return False;
kono
parents:
diff changeset
1701 end if;
kono
parents:
diff changeset
1702
kono
parents:
diff changeset
1703 Next_Formal (F1);
kono
parents:
diff changeset
1704 Next_Formal (F2);
kono
parents:
diff changeset
1705 end loop;
kono
parents:
diff changeset
1706
kono
parents:
diff changeset
1707 -- Check that a controlling result type is derived from the parent
kono
parents:
diff changeset
1708 -- subprogram's result type (or designated type if the result type
kono
parents:
diff changeset
1709 -- is an anonymous access type).
kono
parents:
diff changeset
1710
kono
parents:
diff changeset
1711 if Ekind (Parent_Subp) = E_Function then
kono
parents:
diff changeset
1712 if Ekind (Subp) /= E_Function then
kono
parents:
diff changeset
1713 return False;
kono
parents:
diff changeset
1714
kono
parents:
diff changeset
1715 elsif Ekind (Etype (Parent_Subp)) = E_Anonymous_Access_Type then
kono
parents:
diff changeset
1716 if Ekind (Etype (Subp)) /= E_Anonymous_Access_Type then
kono
parents:
diff changeset
1717 return False;
kono
parents:
diff changeset
1718
kono
parents:
diff changeset
1719 elsif Designated_Type (Etype (Parent_Subp)) = Parent_Typ
kono
parents:
diff changeset
1720 and then Designated_Type (Etype (Subp)) /= Full
kono
parents:
diff changeset
1721 then
kono
parents:
diff changeset
1722 return False;
kono
parents:
diff changeset
1723 end if;
kono
parents:
diff changeset
1724
kono
parents:
diff changeset
1725 elsif Ekind (Etype (Subp)) = E_Anonymous_Access_Type then
kono
parents:
diff changeset
1726 return False;
kono
parents:
diff changeset
1727
kono
parents:
diff changeset
1728 elsif Etype (Parent_Subp) = Parent_Typ
kono
parents:
diff changeset
1729 and then Etype (Subp) /= Full
kono
parents:
diff changeset
1730 then
kono
parents:
diff changeset
1731 return False;
kono
parents:
diff changeset
1732 end if;
kono
parents:
diff changeset
1733
kono
parents:
diff changeset
1734 elsif Ekind (Subp) = E_Function then
kono
parents:
diff changeset
1735 return False;
kono
parents:
diff changeset
1736 end if;
kono
parents:
diff changeset
1737
kono
parents:
diff changeset
1738 return No (F1) and then No (F2);
kono
parents:
diff changeset
1739 end Derives_From;
kono
parents:
diff changeset
1740
kono
parents:
diff changeset
1741 -- Start of processing for Check_Operation_From_Incomplete_Type
kono
parents:
diff changeset
1742
kono
parents:
diff changeset
1743 begin
kono
parents:
diff changeset
1744 -- The operation may override an inherited one, or may be a new one
kono
parents:
diff changeset
1745 -- altogether. The inherited operation will have been hidden by the
kono
parents:
diff changeset
1746 -- current one at the point of the type derivation, so it does not
kono
parents:
diff changeset
1747 -- appear in the list of primitive operations of the type. We have to
kono
parents:
diff changeset
1748 -- find the proper place of insertion in the list of primitive opera-
kono
parents:
diff changeset
1749 -- tions by iterating over the list for the parent type.
kono
parents:
diff changeset
1750
kono
parents:
diff changeset
1751 Op1 := First_Elmt (Old_Prim);
kono
parents:
diff changeset
1752 Op2 := First_Elmt (New_Prim);
kono
parents:
diff changeset
1753 while Present (Op1) and then Present (Op2) loop
kono
parents:
diff changeset
1754 if Derives_From (Node (Op1)) then
kono
parents:
diff changeset
1755 if No (Prev) then
kono
parents:
diff changeset
1756
kono
parents:
diff changeset
1757 -- Avoid adding it to the list of primitives if already there
kono
parents:
diff changeset
1758
kono
parents:
diff changeset
1759 if Node (Op2) /= Subp then
kono
parents:
diff changeset
1760 Prepend_Elmt (Subp, New_Prim);
kono
parents:
diff changeset
1761 end if;
kono
parents:
diff changeset
1762
kono
parents:
diff changeset
1763 else
kono
parents:
diff changeset
1764 Insert_Elmt_After (Subp, Prev);
kono
parents:
diff changeset
1765 end if;
kono
parents:
diff changeset
1766
kono
parents:
diff changeset
1767 return;
kono
parents:
diff changeset
1768 end if;
kono
parents:
diff changeset
1769
kono
parents:
diff changeset
1770 Prev := Op2;
kono
parents:
diff changeset
1771 Next_Elmt (Op1);
kono
parents:
diff changeset
1772 Next_Elmt (Op2);
kono
parents:
diff changeset
1773 end loop;
kono
parents:
diff changeset
1774
kono
parents:
diff changeset
1775 -- Operation is a new primitive
kono
parents:
diff changeset
1776
kono
parents:
diff changeset
1777 Append_Elmt (Subp, New_Prim);
kono
parents:
diff changeset
1778 end Check_Operation_From_Incomplete_Type;
kono
parents:
diff changeset
1779
kono
parents:
diff changeset
1780 ---------------------------------------
kono
parents:
diff changeset
1781 -- Check_Operation_From_Private_View --
kono
parents:
diff changeset
1782 ---------------------------------------
kono
parents:
diff changeset
1783
kono
parents:
diff changeset
1784 procedure Check_Operation_From_Private_View (Subp, Old_Subp : Entity_Id) is
kono
parents:
diff changeset
1785 Tagged_Type : Entity_Id;
kono
parents:
diff changeset
1786
kono
parents:
diff changeset
1787 begin
kono
parents:
diff changeset
1788 if Is_Dispatching_Operation (Alias (Subp)) then
kono
parents:
diff changeset
1789 Set_Scope (Subp, Current_Scope);
kono
parents:
diff changeset
1790 Tagged_Type := Find_Dispatching_Type (Subp);
kono
parents:
diff changeset
1791
kono
parents:
diff changeset
1792 -- Add Old_Subp to primitive operations if not already present
kono
parents:
diff changeset
1793
kono
parents:
diff changeset
1794 if Present (Tagged_Type) and then Is_Tagged_Type (Tagged_Type) then
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1795 Add_Dispatching_Operation (Tagged_Type, Old_Subp);
111
kono
parents:
diff changeset
1796
kono
parents:
diff changeset
1797 -- If Old_Subp isn't already marked as dispatching then this is
kono
parents:
diff changeset
1798 -- the case of an operation of an untagged private type fulfilled
kono
parents:
diff changeset
1799 -- by a tagged type that overrides an inherited dispatching
kono
parents:
diff changeset
1800 -- operation, so we set the necessary dispatching attributes here.
kono
parents:
diff changeset
1801
kono
parents:
diff changeset
1802 if not Is_Dispatching_Operation (Old_Subp) then
kono
parents:
diff changeset
1803
kono
parents:
diff changeset
1804 -- If the untagged type has no discriminants, and the full
kono
parents:
diff changeset
1805 -- view is constrained, there will be a spurious mismatch of
kono
parents:
diff changeset
1806 -- subtypes on the controlling arguments, because the tagged
kono
parents:
diff changeset
1807 -- type is the internal base type introduced in the derivation.
kono
parents:
diff changeset
1808 -- Use the original type to verify conformance, rather than the
kono
parents:
diff changeset
1809 -- base type.
kono
parents:
diff changeset
1810
kono
parents:
diff changeset
1811 if not Comes_From_Source (Tagged_Type)
kono
parents:
diff changeset
1812 and then Has_Discriminants (Tagged_Type)
kono
parents:
diff changeset
1813 then
kono
parents:
diff changeset
1814 declare
kono
parents:
diff changeset
1815 Formal : Entity_Id;
kono
parents:
diff changeset
1816
kono
parents:
diff changeset
1817 begin
kono
parents:
diff changeset
1818 Formal := First_Formal (Old_Subp);
kono
parents:
diff changeset
1819 while Present (Formal) loop
kono
parents:
diff changeset
1820 if Tagged_Type = Base_Type (Etype (Formal)) then
kono
parents:
diff changeset
1821 Tagged_Type := Etype (Formal);
kono
parents:
diff changeset
1822 end if;
kono
parents:
diff changeset
1823
kono
parents:
diff changeset
1824 Next_Formal (Formal);
kono
parents:
diff changeset
1825 end loop;
kono
parents:
diff changeset
1826 end;
kono
parents:
diff changeset
1827
kono
parents:
diff changeset
1828 if Tagged_Type = Base_Type (Etype (Old_Subp)) then
kono
parents:
diff changeset
1829 Tagged_Type := Etype (Old_Subp);
kono
parents:
diff changeset
1830 end if;
kono
parents:
diff changeset
1831 end if;
kono
parents:
diff changeset
1832
kono
parents:
diff changeset
1833 Check_Controlling_Formals (Tagged_Type, Old_Subp);
kono
parents:
diff changeset
1834 Set_Is_Dispatching_Operation (Old_Subp, True);
kono
parents:
diff changeset
1835 Set_DT_Position_Value (Old_Subp, No_Uint);
kono
parents:
diff changeset
1836 end if;
kono
parents:
diff changeset
1837
kono
parents:
diff changeset
1838 -- If the old subprogram is an explicit renaming of some other
kono
parents:
diff changeset
1839 -- entity, it is not overridden by the inherited subprogram.
kono
parents:
diff changeset
1840 -- Otherwise, update its alias and other attributes.
kono
parents:
diff changeset
1841
kono
parents:
diff changeset
1842 if Present (Alias (Old_Subp))
kono
parents:
diff changeset
1843 and then Nkind (Unit_Declaration_Node (Old_Subp)) /=
kono
parents:
diff changeset
1844 N_Subprogram_Renaming_Declaration
kono
parents:
diff changeset
1845 then
kono
parents:
diff changeset
1846 Set_Alias (Old_Subp, Alias (Subp));
kono
parents:
diff changeset
1847
kono
parents:
diff changeset
1848 -- The derived subprogram should inherit the abstractness of
kono
parents:
diff changeset
1849 -- the parent subprogram (except in the case of a function
kono
parents:
diff changeset
1850 -- returning the type). This sets the abstractness properly
kono
parents:
diff changeset
1851 -- for cases where a private extension may have inherited an
kono
parents:
diff changeset
1852 -- abstract operation, but the full type is derived from a
kono
parents:
diff changeset
1853 -- descendant type and inherits a nonabstract version.
kono
parents:
diff changeset
1854
kono
parents:
diff changeset
1855 if Etype (Subp) /= Tagged_Type then
kono
parents:
diff changeset
1856 Set_Is_Abstract_Subprogram
kono
parents:
diff changeset
1857 (Old_Subp, Is_Abstract_Subprogram (Alias (Subp)));
kono
parents:
diff changeset
1858 end if;
kono
parents:
diff changeset
1859 end if;
kono
parents:
diff changeset
1860 end if;
kono
parents:
diff changeset
1861 end if;
kono
parents:
diff changeset
1862 end Check_Operation_From_Private_View;
kono
parents:
diff changeset
1863
kono
parents:
diff changeset
1864 --------------------------
kono
parents:
diff changeset
1865 -- Find_Controlling_Arg --
kono
parents:
diff changeset
1866 --------------------------
kono
parents:
diff changeset
1867
kono
parents:
diff changeset
1868 function Find_Controlling_Arg (N : Node_Id) return Node_Id is
kono
parents:
diff changeset
1869 Orig_Node : constant Node_Id := Original_Node (N);
kono
parents:
diff changeset
1870 Typ : Entity_Id;
kono
parents:
diff changeset
1871
kono
parents:
diff changeset
1872 begin
kono
parents:
diff changeset
1873 if Nkind (Orig_Node) = N_Qualified_Expression then
kono
parents:
diff changeset
1874 return Find_Controlling_Arg (Expression (Orig_Node));
kono
parents:
diff changeset
1875 end if;
kono
parents:
diff changeset
1876
kono
parents:
diff changeset
1877 -- Dispatching on result case. If expansion is disabled, the node still
kono
parents:
diff changeset
1878 -- has the structure of a function call. However, if the function name
kono
parents:
diff changeset
1879 -- is an operator and the call was given in infix form, the original
kono
parents:
diff changeset
1880 -- node has no controlling result and we must examine the current node.
kono
parents:
diff changeset
1881
kono
parents:
diff changeset
1882 if Nkind (N) = N_Function_Call
kono
parents:
diff changeset
1883 and then Present (Controlling_Argument (N))
kono
parents:
diff changeset
1884 and then Has_Controlling_Result (Entity (Name (N)))
kono
parents:
diff changeset
1885 then
kono
parents:
diff changeset
1886 return Controlling_Argument (N);
kono
parents:
diff changeset
1887
kono
parents:
diff changeset
1888 -- If expansion is enabled, the call may have been transformed into
kono
parents:
diff changeset
1889 -- an indirect call, and we need to recover the original node.
kono
parents:
diff changeset
1890
kono
parents:
diff changeset
1891 elsif Nkind (Orig_Node) = N_Function_Call
kono
parents:
diff changeset
1892 and then Present (Controlling_Argument (Orig_Node))
kono
parents:
diff changeset
1893 and then Has_Controlling_Result (Entity (Name (Orig_Node)))
kono
parents:
diff changeset
1894 then
kono
parents:
diff changeset
1895 return Controlling_Argument (Orig_Node);
kono
parents:
diff changeset
1896
kono
parents:
diff changeset
1897 -- Type conversions are dynamically tagged if the target type, or its
kono
parents:
diff changeset
1898 -- designated type, are classwide. An interface conversion expands into
kono
parents:
diff changeset
1899 -- a dereference, so test must be performed on the original node.
kono
parents:
diff changeset
1900
kono
parents:
diff changeset
1901 elsif Nkind (Orig_Node) = N_Type_Conversion
kono
parents:
diff changeset
1902 and then Nkind (N) = N_Explicit_Dereference
kono
parents:
diff changeset
1903 and then Is_Controlling_Actual (N)
kono
parents:
diff changeset
1904 then
kono
parents:
diff changeset
1905 declare
kono
parents:
diff changeset
1906 Target_Type : constant Entity_Id :=
kono
parents:
diff changeset
1907 Entity (Subtype_Mark (Orig_Node));
kono
parents:
diff changeset
1908
kono
parents:
diff changeset
1909 begin
kono
parents:
diff changeset
1910 if Is_Class_Wide_Type (Target_Type) then
kono
parents:
diff changeset
1911 return N;
kono
parents:
diff changeset
1912
kono
parents:
diff changeset
1913 elsif Is_Access_Type (Target_Type)
kono
parents:
diff changeset
1914 and then Is_Class_Wide_Type (Designated_Type (Target_Type))
kono
parents:
diff changeset
1915 then
kono
parents:
diff changeset
1916 return N;
kono
parents:
diff changeset
1917
kono
parents:
diff changeset
1918 else
kono
parents:
diff changeset
1919 return Empty;
kono
parents:
diff changeset
1920 end if;
kono
parents:
diff changeset
1921 end;
kono
parents:
diff changeset
1922
kono
parents:
diff changeset
1923 -- Normal case
kono
parents:
diff changeset
1924
kono
parents:
diff changeset
1925 elsif Is_Controlling_Actual (N)
kono
parents:
diff changeset
1926 or else
kono
parents:
diff changeset
1927 (Nkind (Parent (N)) = N_Qualified_Expression
kono
parents:
diff changeset
1928 and then Is_Controlling_Actual (Parent (N)))
kono
parents:
diff changeset
1929 then
kono
parents:
diff changeset
1930 Typ := Etype (N);
kono
parents:
diff changeset
1931
kono
parents:
diff changeset
1932 if Is_Access_Type (Typ) then
kono
parents:
diff changeset
1933
kono
parents:
diff changeset
1934 -- In the case of an Access attribute, use the type of the prefix,
kono
parents:
diff changeset
1935 -- since in the case of an actual for an access parameter, the
kono
parents:
diff changeset
1936 -- attribute's type may be of a specific designated type, even
kono
parents:
diff changeset
1937 -- though the prefix type is class-wide.
kono
parents:
diff changeset
1938
kono
parents:
diff changeset
1939 if Nkind (N) = N_Attribute_Reference then
kono
parents:
diff changeset
1940 Typ := Etype (Prefix (N));
kono
parents:
diff changeset
1941
kono
parents:
diff changeset
1942 -- An allocator is dispatching if the type of qualified expression
kono
parents:
diff changeset
1943 -- is class_wide, in which case this is the controlling type.
kono
parents:
diff changeset
1944
kono
parents:
diff changeset
1945 elsif Nkind (Orig_Node) = N_Allocator
kono
parents:
diff changeset
1946 and then Nkind (Expression (Orig_Node)) = N_Qualified_Expression
kono
parents:
diff changeset
1947 then
kono
parents:
diff changeset
1948 Typ := Etype (Expression (Orig_Node));
kono
parents:
diff changeset
1949 else
kono
parents:
diff changeset
1950 Typ := Designated_Type (Typ);
kono
parents:
diff changeset
1951 end if;
kono
parents:
diff changeset
1952 end if;
kono
parents:
diff changeset
1953
kono
parents:
diff changeset
1954 if Is_Class_Wide_Type (Typ)
kono
parents:
diff changeset
1955 or else
kono
parents:
diff changeset
1956 (Nkind (Parent (N)) = N_Qualified_Expression
kono
parents:
diff changeset
1957 and then Is_Access_Type (Etype (N))
kono
parents:
diff changeset
1958 and then Is_Class_Wide_Type (Designated_Type (Etype (N))))
kono
parents:
diff changeset
1959 then
kono
parents:
diff changeset
1960 return N;
kono
parents:
diff changeset
1961 end if;
kono
parents:
diff changeset
1962 end if;
kono
parents:
diff changeset
1963
kono
parents:
diff changeset
1964 return Empty;
kono
parents:
diff changeset
1965 end Find_Controlling_Arg;
kono
parents:
diff changeset
1966
kono
parents:
diff changeset
1967 ---------------------------
kono
parents:
diff changeset
1968 -- Find_Dispatching_Type --
kono
parents:
diff changeset
1969 ---------------------------
kono
parents:
diff changeset
1970
kono
parents:
diff changeset
1971 function Find_Dispatching_Type (Subp : Entity_Id) return Entity_Id is
kono
parents:
diff changeset
1972 A_Formal : Entity_Id;
kono
parents:
diff changeset
1973 Formal : Entity_Id;
kono
parents:
diff changeset
1974 Ctrl_Type : Entity_Id;
kono
parents:
diff changeset
1975
kono
parents:
diff changeset
1976 begin
kono
parents:
diff changeset
1977 if Ekind_In (Subp, E_Function, E_Procedure)
kono
parents:
diff changeset
1978 and then Present (DTC_Entity (Subp))
kono
parents:
diff changeset
1979 then
kono
parents:
diff changeset
1980 return Scope (DTC_Entity (Subp));
kono
parents:
diff changeset
1981
kono
parents:
diff changeset
1982 -- For subprograms internally generated by derivations of tagged types
kono
parents:
diff changeset
1983 -- use the alias subprogram as a reference to locate the dispatching
kono
parents:
diff changeset
1984 -- type of Subp.
kono
parents:
diff changeset
1985
kono
parents:
diff changeset
1986 elsif not Comes_From_Source (Subp)
kono
parents:
diff changeset
1987 and then Present (Alias (Subp))
kono
parents:
diff changeset
1988 and then Is_Dispatching_Operation (Alias (Subp))
kono
parents:
diff changeset
1989 then
kono
parents:
diff changeset
1990 if Ekind (Alias (Subp)) = E_Function
kono
parents:
diff changeset
1991 and then Has_Controlling_Result (Alias (Subp))
kono
parents:
diff changeset
1992 then
kono
parents:
diff changeset
1993 return Check_Controlling_Type (Etype (Subp), Subp);
kono
parents:
diff changeset
1994
kono
parents:
diff changeset
1995 else
kono
parents:
diff changeset
1996 Formal := First_Formal (Subp);
kono
parents:
diff changeset
1997 A_Formal := First_Formal (Alias (Subp));
kono
parents:
diff changeset
1998 while Present (A_Formal) loop
kono
parents:
diff changeset
1999 if Is_Controlling_Formal (A_Formal) then
kono
parents:
diff changeset
2000 return Check_Controlling_Type (Etype (Formal), Subp);
kono
parents:
diff changeset
2001 end if;
kono
parents:
diff changeset
2002
kono
parents:
diff changeset
2003 Next_Formal (Formal);
kono
parents:
diff changeset
2004 Next_Formal (A_Formal);
kono
parents:
diff changeset
2005 end loop;
kono
parents:
diff changeset
2006
kono
parents:
diff changeset
2007 pragma Assert (False);
kono
parents:
diff changeset
2008 return Empty;
kono
parents:
diff changeset
2009 end if;
kono
parents:
diff changeset
2010
kono
parents:
diff changeset
2011 -- General case
kono
parents:
diff changeset
2012
kono
parents:
diff changeset
2013 else
kono
parents:
diff changeset
2014 Formal := First_Formal (Subp);
kono
parents:
diff changeset
2015 while Present (Formal) loop
kono
parents:
diff changeset
2016 Ctrl_Type := Check_Controlling_Type (Etype (Formal), Subp);
kono
parents:
diff changeset
2017
kono
parents:
diff changeset
2018 if Present (Ctrl_Type) then
kono
parents:
diff changeset
2019 return Ctrl_Type;
kono
parents:
diff changeset
2020 end if;
kono
parents:
diff changeset
2021
kono
parents:
diff changeset
2022 Next_Formal (Formal);
kono
parents:
diff changeset
2023 end loop;
kono
parents:
diff changeset
2024
kono
parents:
diff changeset
2025 -- The subprogram may also be dispatching on result
kono
parents:
diff changeset
2026
kono
parents:
diff changeset
2027 if Present (Etype (Subp)) then
kono
parents:
diff changeset
2028 return Check_Controlling_Type (Etype (Subp), Subp);
kono
parents:
diff changeset
2029 end if;
kono
parents:
diff changeset
2030 end if;
kono
parents:
diff changeset
2031
kono
parents:
diff changeset
2032 pragma Assert (not Is_Dispatching_Operation (Subp));
kono
parents:
diff changeset
2033 return Empty;
kono
parents:
diff changeset
2034 end Find_Dispatching_Type;
kono
parents:
diff changeset
2035
kono
parents:
diff changeset
2036 --------------------------------------
kono
parents:
diff changeset
2037 -- Find_Hidden_Overridden_Primitive --
kono
parents:
diff changeset
2038 --------------------------------------
kono
parents:
diff changeset
2039
kono
parents:
diff changeset
2040 function Find_Hidden_Overridden_Primitive (S : Entity_Id) return Entity_Id
kono
parents:
diff changeset
2041 is
kono
parents:
diff changeset
2042 Tag_Typ : constant Entity_Id := Find_Dispatching_Type (S);
kono
parents:
diff changeset
2043 Elmt : Elmt_Id;
kono
parents:
diff changeset
2044 Orig_Prim : Entity_Id;
kono
parents:
diff changeset
2045 Prim : Entity_Id;
kono
parents:
diff changeset
2046 Vis_List : Elist_Id;
kono
parents:
diff changeset
2047
kono
parents:
diff changeset
2048 begin
kono
parents:
diff changeset
2049 -- This Ada 2012 rule applies only for type extensions or private
kono
parents:
diff changeset
2050 -- extensions, where the parent type is not in a parent unit, and
kono
parents:
diff changeset
2051 -- where an operation is never declared but still inherited.
kono
parents:
diff changeset
2052
kono
parents:
diff changeset
2053 if No (Tag_Typ)
kono
parents:
diff changeset
2054 or else not Is_Record_Type (Tag_Typ)
kono
parents:
diff changeset
2055 or else Etype (Tag_Typ) = Tag_Typ
kono
parents:
diff changeset
2056 or else In_Open_Scopes (Scope (Etype (Tag_Typ)))
kono
parents:
diff changeset
2057 then
kono
parents:
diff changeset
2058 return Empty;
kono
parents:
diff changeset
2059 end if;
kono
parents:
diff changeset
2060
kono
parents:
diff changeset
2061 -- Collect the list of visible ancestor of the tagged type
kono
parents:
diff changeset
2062
kono
parents:
diff changeset
2063 Vis_List := Visible_Ancestors (Tag_Typ);
kono
parents:
diff changeset
2064
kono
parents:
diff changeset
2065 Elmt := First_Elmt (Primitive_Operations (Tag_Typ));
kono
parents:
diff changeset
2066 while Present (Elmt) loop
kono
parents:
diff changeset
2067 Prim := Node (Elmt);
kono
parents:
diff changeset
2068
kono
parents:
diff changeset
2069 -- Find an inherited hidden dispatching primitive with the name of S
kono
parents:
diff changeset
2070 -- and a type-conformant profile.
kono
parents:
diff changeset
2071
kono
parents:
diff changeset
2072 if Present (Alias (Prim))
kono
parents:
diff changeset
2073 and then Is_Hidden (Alias (Prim))
kono
parents:
diff changeset
2074 and then Find_Dispatching_Type (Alias (Prim)) /= Tag_Typ
kono
parents:
diff changeset
2075 and then Primitive_Names_Match (S, Prim)
kono
parents:
diff changeset
2076 and then Type_Conformant (S, Prim)
kono
parents:
diff changeset
2077 then
kono
parents:
diff changeset
2078 declare
kono
parents:
diff changeset
2079 Vis_Ancestor : Elmt_Id;
kono
parents:
diff changeset
2080 Elmt : Elmt_Id;
kono
parents:
diff changeset
2081
kono
parents:
diff changeset
2082 begin
kono
parents:
diff changeset
2083 -- The original corresponding operation of Prim must be an
kono
parents:
diff changeset
2084 -- operation of a visible ancestor of the dispatching type S,
kono
parents:
diff changeset
2085 -- and the original corresponding operation of S2 must be
kono
parents:
diff changeset
2086 -- visible.
kono
parents:
diff changeset
2087
kono
parents:
diff changeset
2088 Orig_Prim := Original_Corresponding_Operation (Prim);
kono
parents:
diff changeset
2089
kono
parents:
diff changeset
2090 if Orig_Prim /= Prim
kono
parents:
diff changeset
2091 and then Is_Immediately_Visible (Orig_Prim)
kono
parents:
diff changeset
2092 then
kono
parents:
diff changeset
2093 Vis_Ancestor := First_Elmt (Vis_List);
kono
parents:
diff changeset
2094 while Present (Vis_Ancestor) loop
kono
parents:
diff changeset
2095 Elmt :=
kono
parents:
diff changeset
2096 First_Elmt (Primitive_Operations (Node (Vis_Ancestor)));
kono
parents:
diff changeset
2097 while Present (Elmt) loop
kono
parents:
diff changeset
2098 if Node (Elmt) = Orig_Prim then
kono
parents:
diff changeset
2099 Set_Overridden_Operation (S, Prim);
kono
parents:
diff changeset
2100 Set_Alias (Prim, Orig_Prim);
kono
parents:
diff changeset
2101 return Prim;
kono
parents:
diff changeset
2102 end if;
kono
parents:
diff changeset
2103
kono
parents:
diff changeset
2104 Next_Elmt (Elmt);
kono
parents:
diff changeset
2105 end loop;
kono
parents:
diff changeset
2106
kono
parents:
diff changeset
2107 Next_Elmt (Vis_Ancestor);
kono
parents:
diff changeset
2108 end loop;
kono
parents:
diff changeset
2109 end if;
kono
parents:
diff changeset
2110 end;
kono
parents:
diff changeset
2111 end if;
kono
parents:
diff changeset
2112
kono
parents:
diff changeset
2113 Next_Elmt (Elmt);
kono
parents:
diff changeset
2114 end loop;
kono
parents:
diff changeset
2115
kono
parents:
diff changeset
2116 return Empty;
kono
parents:
diff changeset
2117 end Find_Hidden_Overridden_Primitive;
kono
parents:
diff changeset
2118
kono
parents:
diff changeset
2119 ---------------------------------------
kono
parents:
diff changeset
2120 -- Find_Primitive_Covering_Interface --
kono
parents:
diff changeset
2121 ---------------------------------------
kono
parents:
diff changeset
2122
kono
parents:
diff changeset
2123 function Find_Primitive_Covering_Interface
kono
parents:
diff changeset
2124 (Tagged_Type : Entity_Id;
kono
parents:
diff changeset
2125 Iface_Prim : Entity_Id) return Entity_Id
kono
parents:
diff changeset
2126 is
kono
parents:
diff changeset
2127 E : Entity_Id;
kono
parents:
diff changeset
2128 El : Elmt_Id;
kono
parents:
diff changeset
2129
kono
parents:
diff changeset
2130 begin
kono
parents:
diff changeset
2131 pragma Assert (Is_Interface (Find_Dispatching_Type (Iface_Prim))
kono
parents:
diff changeset
2132 or else (Present (Alias (Iface_Prim))
kono
parents:
diff changeset
2133 and then
kono
parents:
diff changeset
2134 Is_Interface
kono
parents:
diff changeset
2135 (Find_Dispatching_Type (Ultimate_Alias (Iface_Prim)))));
kono
parents:
diff changeset
2136
kono
parents:
diff changeset
2137 -- Search in the homonym chain. Done to speed up locating visible
kono
parents:
diff changeset
2138 -- entities and required to catch primitives associated with the partial
kono
parents:
diff changeset
2139 -- view of private types when processing the corresponding full view.
kono
parents:
diff changeset
2140
kono
parents:
diff changeset
2141 E := Current_Entity (Iface_Prim);
kono
parents:
diff changeset
2142 while Present (E) loop
kono
parents:
diff changeset
2143 if Is_Subprogram (E)
kono
parents:
diff changeset
2144 and then Is_Dispatching_Operation (E)
kono
parents:
diff changeset
2145 and then Is_Interface_Conformant (Tagged_Type, Iface_Prim, E)
kono
parents:
diff changeset
2146 then
kono
parents:
diff changeset
2147 return E;
kono
parents:
diff changeset
2148 end if;
kono
parents:
diff changeset
2149
kono
parents:
diff changeset
2150 E := Homonym (E);
kono
parents:
diff changeset
2151 end loop;
kono
parents:
diff changeset
2152
kono
parents:
diff changeset
2153 -- Search in the list of primitives of the type. Required to locate
kono
parents:
diff changeset
2154 -- the covering primitive if the covering primitive is not visible
kono
parents:
diff changeset
2155 -- (for example, non-visible inherited primitive of private type).
kono
parents:
diff changeset
2156
kono
parents:
diff changeset
2157 El := First_Elmt (Primitive_Operations (Tagged_Type));
kono
parents:
diff changeset
2158 while Present (El) loop
kono
parents:
diff changeset
2159 E := Node (El);
kono
parents:
diff changeset
2160
kono
parents:
diff changeset
2161 -- Keep separate the management of internal entities that link
kono
parents:
diff changeset
2162 -- primitives with interface primitives from tagged type primitives.
kono
parents:
diff changeset
2163
kono
parents:
diff changeset
2164 if No (Interface_Alias (E)) then
kono
parents:
diff changeset
2165 if Present (Alias (E)) then
kono
parents:
diff changeset
2166
kono
parents:
diff changeset
2167 -- This interface primitive has not been covered yet
kono
parents:
diff changeset
2168
kono
parents:
diff changeset
2169 if Alias (E) = Iface_Prim then
kono
parents:
diff changeset
2170 return E;
kono
parents:
diff changeset
2171
kono
parents:
diff changeset
2172 -- The covering primitive was inherited
kono
parents:
diff changeset
2173
kono
parents:
diff changeset
2174 elsif Overridden_Operation (Ultimate_Alias (E))
kono
parents:
diff changeset
2175 = Iface_Prim
kono
parents:
diff changeset
2176 then
kono
parents:
diff changeset
2177 return E;
kono
parents:
diff changeset
2178 end if;
kono
parents:
diff changeset
2179 end if;
kono
parents:
diff changeset
2180
kono
parents:
diff changeset
2181 -- Check if E covers the interface primitive (includes case in
kono
parents:
diff changeset
2182 -- which E is an inherited private primitive).
kono
parents:
diff changeset
2183
kono
parents:
diff changeset
2184 if Is_Interface_Conformant (Tagged_Type, Iface_Prim, E) then
kono
parents:
diff changeset
2185 return E;
kono
parents:
diff changeset
2186 end if;
kono
parents:
diff changeset
2187
kono
parents:
diff changeset
2188 -- Use the internal entity that links the interface primitive with
kono
parents:
diff changeset
2189 -- the covering primitive to locate the entity.
kono
parents:
diff changeset
2190
kono
parents:
diff changeset
2191 elsif Interface_Alias (E) = Iface_Prim then
kono
parents:
diff changeset
2192 return Alias (E);
kono
parents:
diff changeset
2193 end if;
kono
parents:
diff changeset
2194
kono
parents:
diff changeset
2195 Next_Elmt (El);
kono
parents:
diff changeset
2196 end loop;
kono
parents:
diff changeset
2197
kono
parents:
diff changeset
2198 -- Not found
kono
parents:
diff changeset
2199
kono
parents:
diff changeset
2200 return Empty;
kono
parents:
diff changeset
2201 end Find_Primitive_Covering_Interface;
kono
parents:
diff changeset
2202
kono
parents:
diff changeset
2203 ---------------------------
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2204 -- Inheritance_Utilities --
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2205 ---------------------------
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2206
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2207 package body Inheritance_Utilities is
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2208
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2209 ---------------------------
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2210 -- Inherited_Subprograms --
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2211 ---------------------------
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2212
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2213 function Inherited_Subprograms
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2214 (S : Entity_Id;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2215 No_Interfaces : Boolean := False;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2216 Interfaces_Only : Boolean := False;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2217 One_Only : Boolean := False) return Subprogram_List
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2218 is
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2219 Result : Subprogram_List (1 .. 6000);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2220 -- 6000 here is intended to be infinity. We could use an expandable
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2221 -- table, but it would be awfully heavy, and there is no way that we
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2222 -- could reasonably exceed this value.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2223
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2224 N : Nat := 0;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2225 -- Number of entries in Result
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2226
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2227 Parent_Op : Entity_Id;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2228 -- Traverses the Overridden_Operation chain
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2229
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2230 procedure Store_IS (E : Entity_Id);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2231 -- Stores E in Result if not already stored
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2232
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2233 --------------
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2234 -- Store_IS --
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2235 --------------
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2236
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2237 procedure Store_IS (E : Entity_Id) is
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2238 begin
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2239 for J in 1 .. N loop
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2240 if E = Result (J) then
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2241 return;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2242 end if;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2243 end loop;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2244
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2245 N := N + 1;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2246 Result (N) := E;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2247 end Store_IS;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2248
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2249 -- Start of processing for Inherited_Subprograms
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2250
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2251 begin
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2252 pragma Assert (not (No_Interfaces and Interfaces_Only));
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2253
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2254 -- When used from backends, visibility can be handled differently
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2255 -- resulting in no dispatching type being found.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2256
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2257 if Present (S)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2258 and then Is_Dispatching_Operation (S)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2259 and then Present (Find_DT (S))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2260 then
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2261 -- Deal with direct inheritance
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2262
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2263 if not Interfaces_Only then
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2264 Parent_Op := S;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2265 loop
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2266 Parent_Op := Overridden_Operation (Parent_Op);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2267 exit when No (Parent_Op)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2268 or else (No_Interfaces
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2269 and then Is_Interface (Find_DT (Parent_Op)));
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2270
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2271 if Is_Subprogram_Or_Generic_Subprogram (Parent_Op) then
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2272 Store_IS (Parent_Op);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2273
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2274 if One_Only then
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2275 goto Done;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2276 end if;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2277 end if;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2278 end loop;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2279 end if;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2280
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2281 -- Now deal with interfaces
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2282
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2283 if not No_Interfaces then
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2284 declare
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2285 Tag_Typ : Entity_Id;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2286 Prim : Entity_Id;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2287 Elmt : Elmt_Id;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2288
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2289 begin
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2290 Tag_Typ := Find_DT (S);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2291
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2292 -- In the presence of limited views there may be no visible
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2293 -- dispatching type. Primitives will be inherited when non-
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2294 -- limited view is frozen.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2295
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2296 if No (Tag_Typ) then
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2297 return Result (1 .. 0);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2298 end if;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2299
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2300 if Is_Concurrent_Type (Tag_Typ) then
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2301 Tag_Typ := Corresponding_Record_Type (Tag_Typ);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2302 end if;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2303
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2304 -- Search primitive operations of dispatching type
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2305
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2306 if Present (Tag_Typ)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2307 and then Present (Primitive_Operations (Tag_Typ))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2308 then
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2309 Elmt := First_Elmt (Primitive_Operations (Tag_Typ));
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2310 while Present (Elmt) loop
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2311 Prim := Node (Elmt);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2312
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2313 -- The following test eliminates some odd cases in
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2314 -- which Ekind (Prim) is Void, to be investigated
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2315 -- further ???
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2316
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2317 if not Is_Subprogram_Or_Generic_Subprogram (Prim) then
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2318 null;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2319
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2320 -- For [generic] subprogram, look at interface
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2321 -- alias.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2322
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2323 elsif Present (Interface_Alias (Prim))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2324 and then Alias (Prim) = S
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2325 then
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2326 -- We have found a primitive covered by S
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2327
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2328 Store_IS (Interface_Alias (Prim));
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2329
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2330 if One_Only then
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2331 goto Done;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2332 end if;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2333 end if;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2334
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2335 Next_Elmt (Elmt);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2336 end loop;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2337 end if;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2338 end;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2339 end if;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2340 end if;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2341
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2342 <<Done>>
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2343
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2344 return Result (1 .. N);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2345 end Inherited_Subprograms;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2346
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2347 ------------------------------
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2348 -- Is_Overriding_Subprogram --
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2349 ------------------------------
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2350
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2351 function Is_Overriding_Subprogram (E : Entity_Id) return Boolean is
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2352 Inherited : constant Subprogram_List :=
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2353 Inherited_Subprograms (E, One_Only => True);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2354 begin
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2355 return Inherited'Length > 0;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2356 end Is_Overriding_Subprogram;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2357 end Inheritance_Utilities;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2358
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2359 --------------------------------
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2360 -- Inheritance_Utilities_Inst --
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2361 --------------------------------
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2362
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2363 package Inheritance_Utilities_Inst is new
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2364 Inheritance_Utilities (Find_Dispatching_Type);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2365
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2366 ---------------------------
111
kono
parents:
diff changeset
2367 -- Inherited_Subprograms --
kono
parents:
diff changeset
2368 ---------------------------
kono
parents:
diff changeset
2369
kono
parents:
diff changeset
2370 function Inherited_Subprograms
kono
parents:
diff changeset
2371 (S : Entity_Id;
kono
parents:
diff changeset
2372 No_Interfaces : Boolean := False;
kono
parents:
diff changeset
2373 Interfaces_Only : Boolean := False;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2374 One_Only : Boolean := False) return Subprogram_List renames
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2375 Inheritance_Utilities_Inst.Inherited_Subprograms;
111
kono
parents:
diff changeset
2376
kono
parents:
diff changeset
2377 ---------------------------
kono
parents:
diff changeset
2378 -- Is_Dynamically_Tagged --
kono
parents:
diff changeset
2379 ---------------------------
kono
parents:
diff changeset
2380
kono
parents:
diff changeset
2381 function Is_Dynamically_Tagged (N : Node_Id) return Boolean is
kono
parents:
diff changeset
2382 begin
kono
parents:
diff changeset
2383 if Nkind (N) = N_Error then
kono
parents:
diff changeset
2384 return False;
kono
parents:
diff changeset
2385
kono
parents:
diff changeset
2386 elsif Present (Find_Controlling_Arg (N)) then
kono
parents:
diff changeset
2387 return True;
kono
parents:
diff changeset
2388
kono
parents:
diff changeset
2389 -- Special cases: entities, and calls that dispatch on result
kono
parents:
diff changeset
2390
kono
parents:
diff changeset
2391 elsif Is_Entity_Name (N) then
kono
parents:
diff changeset
2392 return Is_Class_Wide_Type (Etype (N));
kono
parents:
diff changeset
2393
kono
parents:
diff changeset
2394 elsif Nkind (N) = N_Function_Call
kono
parents:
diff changeset
2395 and then Is_Class_Wide_Type (Etype (N))
kono
parents:
diff changeset
2396 then
kono
parents:
diff changeset
2397 return True;
kono
parents:
diff changeset
2398
kono
parents:
diff changeset
2399 -- Otherwise check whether call has controlling argument
kono
parents:
diff changeset
2400
kono
parents:
diff changeset
2401 else
kono
parents:
diff changeset
2402 return False;
kono
parents:
diff changeset
2403 end if;
kono
parents:
diff changeset
2404 end Is_Dynamically_Tagged;
kono
parents:
diff changeset
2405
kono
parents:
diff changeset
2406 ---------------------------------
kono
parents:
diff changeset
2407 -- Is_Null_Interface_Primitive --
kono
parents:
diff changeset
2408 ---------------------------------
kono
parents:
diff changeset
2409
kono
parents:
diff changeset
2410 function Is_Null_Interface_Primitive (E : Entity_Id) return Boolean is
kono
parents:
diff changeset
2411 begin
kono
parents:
diff changeset
2412 return Comes_From_Source (E)
kono
parents:
diff changeset
2413 and then Is_Dispatching_Operation (E)
kono
parents:
diff changeset
2414 and then Ekind (E) = E_Procedure
kono
parents:
diff changeset
2415 and then Null_Present (Parent (E))
kono
parents:
diff changeset
2416 and then Is_Interface (Find_Dispatching_Type (E));
kono
parents:
diff changeset
2417 end Is_Null_Interface_Primitive;
kono
parents:
diff changeset
2418
kono
parents:
diff changeset
2419 -----------------------------------
kono
parents:
diff changeset
2420 -- Is_Inherited_Public_Operation --
kono
parents:
diff changeset
2421 -----------------------------------
kono
parents:
diff changeset
2422
kono
parents:
diff changeset
2423 function Is_Inherited_Public_Operation (Op : Entity_Id) return Boolean is
kono
parents:
diff changeset
2424 Pack_Decl : Node_Id;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2425 Prim : Entity_Id := Op;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2426 Scop : Entity_Id := Prim;
111
kono
parents:
diff changeset
2427
kono
parents:
diff changeset
2428 begin
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2429 -- Locate the ultimate non-hidden alias entity
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2430
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2431 while Present (Alias (Prim)) and then not Is_Hidden (Alias (Prim)) loop
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2432 pragma Assert (Alias (Prim) /= Prim);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2433 Prim := Alias (Prim);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2434 Scop := Scope (Prim);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2435 end loop;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2436
111
kono
parents:
diff changeset
2437 if Comes_From_Source (Prim) and then Ekind (Scop) = E_Package then
kono
parents:
diff changeset
2438 Pack_Decl := Unit_Declaration_Node (Scop);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2439
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2440 return
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2441 Nkind (Pack_Decl) = N_Package_Declaration
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2442 and then List_Containing (Unit_Declaration_Node (Prim)) =
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2443 Visible_Declarations (Specification (Pack_Decl));
111
kono
parents:
diff changeset
2444
kono
parents:
diff changeset
2445 else
kono
parents:
diff changeset
2446 return False;
kono
parents:
diff changeset
2447 end if;
kono
parents:
diff changeset
2448 end Is_Inherited_Public_Operation;
kono
parents:
diff changeset
2449
kono
parents:
diff changeset
2450 ------------------------------
kono
parents:
diff changeset
2451 -- Is_Overriding_Subprogram --
kono
parents:
diff changeset
2452 ------------------------------
kono
parents:
diff changeset
2453
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2454 function Is_Overriding_Subprogram (E : Entity_Id) return Boolean renames
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2455 Inheritance_Utilities_Inst.Is_Overriding_Subprogram;
111
kono
parents:
diff changeset
2456
kono
parents:
diff changeset
2457 --------------------------
kono
parents:
diff changeset
2458 -- Is_Tag_Indeterminate --
kono
parents:
diff changeset
2459 --------------------------
kono
parents:
diff changeset
2460
kono
parents:
diff changeset
2461 function Is_Tag_Indeterminate (N : Node_Id) return Boolean is
kono
parents:
diff changeset
2462 Nam : Entity_Id;
kono
parents:
diff changeset
2463 Actual : Node_Id;
kono
parents:
diff changeset
2464 Orig_Node : constant Node_Id := Original_Node (N);
kono
parents:
diff changeset
2465
kono
parents:
diff changeset
2466 begin
kono
parents:
diff changeset
2467 if Nkind (Orig_Node) = N_Function_Call
kono
parents:
diff changeset
2468 and then Is_Entity_Name (Name (Orig_Node))
kono
parents:
diff changeset
2469 then
kono
parents:
diff changeset
2470 Nam := Entity (Name (Orig_Node));
kono
parents:
diff changeset
2471
kono
parents:
diff changeset
2472 if not Has_Controlling_Result (Nam) then
kono
parents:
diff changeset
2473 return False;
kono
parents:
diff changeset
2474
kono
parents:
diff changeset
2475 -- The function may have a controlling result, but if the return type
kono
parents:
diff changeset
2476 -- is not visibly tagged, then this is not tag-indeterminate.
kono
parents:
diff changeset
2477
kono
parents:
diff changeset
2478 elsif Is_Access_Type (Etype (Nam))
kono
parents:
diff changeset
2479 and then not Is_Tagged_Type (Designated_Type (Etype (Nam)))
kono
parents:
diff changeset
2480 then
kono
parents:
diff changeset
2481 return False;
kono
parents:
diff changeset
2482
kono
parents:
diff changeset
2483 -- An explicit dereference means that the call has already been
kono
parents:
diff changeset
2484 -- expanded and there is no tag to propagate.
kono
parents:
diff changeset
2485
kono
parents:
diff changeset
2486 elsif Nkind (N) = N_Explicit_Dereference then
kono
parents:
diff changeset
2487 return False;
kono
parents:
diff changeset
2488
kono
parents:
diff changeset
2489 -- If there are no actuals, the call is tag-indeterminate
kono
parents:
diff changeset
2490
kono
parents:
diff changeset
2491 elsif No (Parameter_Associations (Orig_Node)) then
kono
parents:
diff changeset
2492 return True;
kono
parents:
diff changeset
2493
kono
parents:
diff changeset
2494 else
kono
parents:
diff changeset
2495 Actual := First_Actual (Orig_Node);
kono
parents:
diff changeset
2496 while Present (Actual) loop
kono
parents:
diff changeset
2497 if Is_Controlling_Actual (Actual)
kono
parents:
diff changeset
2498 and then not Is_Tag_Indeterminate (Actual)
kono
parents:
diff changeset
2499 then
kono
parents:
diff changeset
2500 -- One operand is dispatching
kono
parents:
diff changeset
2501
kono
parents:
diff changeset
2502 return False;
kono
parents:
diff changeset
2503 end if;
kono
parents:
diff changeset
2504
kono
parents:
diff changeset
2505 Next_Actual (Actual);
kono
parents:
diff changeset
2506 end loop;
kono
parents:
diff changeset
2507
kono
parents:
diff changeset
2508 return True;
kono
parents:
diff changeset
2509 end if;
kono
parents:
diff changeset
2510
kono
parents:
diff changeset
2511 elsif Nkind (Orig_Node) = N_Qualified_Expression then
kono
parents:
diff changeset
2512 return Is_Tag_Indeterminate (Expression (Orig_Node));
kono
parents:
diff changeset
2513
kono
parents:
diff changeset
2514 -- Case of a call to the Input attribute (possibly rewritten), which is
kono
parents:
diff changeset
2515 -- always tag-indeterminate except when its prefix is a Class attribute.
kono
parents:
diff changeset
2516
kono
parents:
diff changeset
2517 elsif Nkind (Orig_Node) = N_Attribute_Reference
kono
parents:
diff changeset
2518 and then
kono
parents:
diff changeset
2519 Get_Attribute_Id (Attribute_Name (Orig_Node)) = Attribute_Input
kono
parents:
diff changeset
2520 and then Nkind (Prefix (Orig_Node)) /= N_Attribute_Reference
kono
parents:
diff changeset
2521 then
kono
parents:
diff changeset
2522 return True;
kono
parents:
diff changeset
2523
kono
parents:
diff changeset
2524 -- In Ada 2005, a function that returns an anonymous access type can be
kono
parents:
diff changeset
2525 -- dispatching, and the dereference of a call to such a function can
kono
parents:
diff changeset
2526 -- also be tag-indeterminate if the call itself is.
kono
parents:
diff changeset
2527
kono
parents:
diff changeset
2528 elsif Nkind (Orig_Node) = N_Explicit_Dereference
kono
parents:
diff changeset
2529 and then Ada_Version >= Ada_2005
kono
parents:
diff changeset
2530 then
kono
parents:
diff changeset
2531 return Is_Tag_Indeterminate (Prefix (Orig_Node));
kono
parents:
diff changeset
2532
kono
parents:
diff changeset
2533 else
kono
parents:
diff changeset
2534 return False;
kono
parents:
diff changeset
2535 end if;
kono
parents:
diff changeset
2536 end Is_Tag_Indeterminate;
kono
parents:
diff changeset
2537
kono
parents:
diff changeset
2538 ------------------------------------
kono
parents:
diff changeset
2539 -- Override_Dispatching_Operation --
kono
parents:
diff changeset
2540 ------------------------------------
kono
parents:
diff changeset
2541
kono
parents:
diff changeset
2542 procedure Override_Dispatching_Operation
kono
parents:
diff changeset
2543 (Tagged_Type : Entity_Id;
kono
parents:
diff changeset
2544 Prev_Op : Entity_Id;
kono
parents:
diff changeset
2545 New_Op : Entity_Id;
kono
parents:
diff changeset
2546 Is_Wrapper : Boolean := False)
kono
parents:
diff changeset
2547 is
kono
parents:
diff changeset
2548 Elmt : Elmt_Id;
kono
parents:
diff changeset
2549 Prim : Node_Id;
kono
parents:
diff changeset
2550
kono
parents:
diff changeset
2551 begin
kono
parents:
diff changeset
2552 -- Diagnose failure to match No_Return in parent (Ada-2005, AI-414, but
kono
parents:
diff changeset
2553 -- we do it unconditionally in Ada 95 now, since this is our pragma).
kono
parents:
diff changeset
2554
kono
parents:
diff changeset
2555 if No_Return (Prev_Op) and then not No_Return (New_Op) then
kono
parents:
diff changeset
2556 Error_Msg_N ("procedure & must have No_Return pragma", New_Op);
kono
parents:
diff changeset
2557 Error_Msg_N ("\since overridden procedure has No_Return", New_Op);
kono
parents:
diff changeset
2558 end if;
kono
parents:
diff changeset
2559
kono
parents:
diff changeset
2560 -- If there is no previous operation to override, the type declaration
kono
parents:
diff changeset
2561 -- was malformed, and an error must have been emitted already.
kono
parents:
diff changeset
2562
kono
parents:
diff changeset
2563 Elmt := First_Elmt (Primitive_Operations (Tagged_Type));
kono
parents:
diff changeset
2564 while Present (Elmt) and then Node (Elmt) /= Prev_Op loop
kono
parents:
diff changeset
2565 Next_Elmt (Elmt);
kono
parents:
diff changeset
2566 end loop;
kono
parents:
diff changeset
2567
kono
parents:
diff changeset
2568 if No (Elmt) then
kono
parents:
diff changeset
2569 return;
kono
parents:
diff changeset
2570 end if;
kono
parents:
diff changeset
2571
kono
parents:
diff changeset
2572 -- The location of entities that come from source in the list of
kono
parents:
diff changeset
2573 -- primitives of the tagged type must follow their order of occurrence
kono
parents:
diff changeset
2574 -- in the sources to fulfill the C++ ABI. If the overridden entity is a
kono
parents:
diff changeset
2575 -- primitive of an interface that is not implemented by the parents of
kono
parents:
diff changeset
2576 -- this tagged type (that is, it is an alias of an interface primitive
kono
parents:
diff changeset
2577 -- generated by Derive_Interface_Progenitors), then we must append the
kono
parents:
diff changeset
2578 -- new entity at the end of the list of primitives.
kono
parents:
diff changeset
2579
kono
parents:
diff changeset
2580 if Present (Alias (Prev_Op))
kono
parents:
diff changeset
2581 and then Etype (Tagged_Type) /= Tagged_Type
kono
parents:
diff changeset
2582 and then Is_Interface (Find_Dispatching_Type (Alias (Prev_Op)))
kono
parents:
diff changeset
2583 and then not Is_Ancestor (Find_Dispatching_Type (Alias (Prev_Op)),
kono
parents:
diff changeset
2584 Tagged_Type, Use_Full_View => True)
kono
parents:
diff changeset
2585 and then not Implements_Interface
kono
parents:
diff changeset
2586 (Etype (Tagged_Type),
kono
parents:
diff changeset
2587 Find_Dispatching_Type (Alias (Prev_Op)))
kono
parents:
diff changeset
2588 then
kono
parents:
diff changeset
2589 Remove_Elmt (Primitive_Operations (Tagged_Type), Elmt);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2590 Add_Dispatching_Operation (Tagged_Type, New_Op);
111
kono
parents:
diff changeset
2591
kono
parents:
diff changeset
2592 -- The new primitive replaces the overridden entity. Required to ensure
kono
parents:
diff changeset
2593 -- that overriding primitive is assigned the same dispatch table slot.
kono
parents:
diff changeset
2594
kono
parents:
diff changeset
2595 else
kono
parents:
diff changeset
2596 Replace_Elmt (Elmt, New_Op);
kono
parents:
diff changeset
2597 end if;
kono
parents:
diff changeset
2598
kono
parents:
diff changeset
2599 if Ada_Version >= Ada_2005 and then Has_Interfaces (Tagged_Type) then
kono
parents:
diff changeset
2600
kono
parents:
diff changeset
2601 -- Ada 2005 (AI-251): Update the attribute alias of all the aliased
kono
parents:
diff changeset
2602 -- entities of the overridden primitive to reference New_Op, and
kono
parents:
diff changeset
2603 -- also propagate the proper value of Is_Abstract_Subprogram. Verify
kono
parents:
diff changeset
2604 -- that the new operation is subtype conformant with the interface
kono
parents:
diff changeset
2605 -- operations that it implements (for operations inherited from the
kono
parents:
diff changeset
2606 -- parent itself, this check is made when building the derived type).
kono
parents:
diff changeset
2607
kono
parents:
diff changeset
2608 -- Note: This code is executed with internally generated wrappers of
kono
parents:
diff changeset
2609 -- functions with controlling result and late overridings.
kono
parents:
diff changeset
2610
kono
parents:
diff changeset
2611 Elmt := First_Elmt (Primitive_Operations (Tagged_Type));
kono
parents:
diff changeset
2612 while Present (Elmt) loop
kono
parents:
diff changeset
2613 Prim := Node (Elmt);
kono
parents:
diff changeset
2614
kono
parents:
diff changeset
2615 if Prim = New_Op then
kono
parents:
diff changeset
2616 null;
kono
parents:
diff changeset
2617
kono
parents:
diff changeset
2618 -- Note: The check on Is_Subprogram protects the frontend against
kono
parents:
diff changeset
2619 -- reading attributes in entities that are not yet fully decorated
kono
parents:
diff changeset
2620
kono
parents:
diff changeset
2621 elsif Is_Subprogram (Prim)
kono
parents:
diff changeset
2622 and then Present (Interface_Alias (Prim))
kono
parents:
diff changeset
2623 and then Alias (Prim) = Prev_Op
kono
parents:
diff changeset
2624 then
kono
parents:
diff changeset
2625 Set_Alias (Prim, New_Op);
kono
parents:
diff changeset
2626
kono
parents:
diff changeset
2627 -- No further decoration needed yet for internally generated
kono
parents:
diff changeset
2628 -- wrappers of controlling functions since (at this stage)
kono
parents:
diff changeset
2629 -- they are not yet decorated.
kono
parents:
diff changeset
2630
kono
parents:
diff changeset
2631 if not Is_Wrapper then
kono
parents:
diff changeset
2632 Check_Subtype_Conformant (New_Op, Prim);
kono
parents:
diff changeset
2633
kono
parents:
diff changeset
2634 Set_Is_Abstract_Subprogram (Prim,
kono
parents:
diff changeset
2635 Is_Abstract_Subprogram (New_Op));
kono
parents:
diff changeset
2636
kono
parents:
diff changeset
2637 -- Ensure that this entity will be expanded to fill the
kono
parents:
diff changeset
2638 -- corresponding entry in its dispatch table.
kono
parents:
diff changeset
2639
kono
parents:
diff changeset
2640 if not Is_Abstract_Subprogram (Prim) then
kono
parents:
diff changeset
2641 Set_Has_Delayed_Freeze (Prim);
kono
parents:
diff changeset
2642 end if;
kono
parents:
diff changeset
2643 end if;
kono
parents:
diff changeset
2644 end if;
kono
parents:
diff changeset
2645
kono
parents:
diff changeset
2646 Next_Elmt (Elmt);
kono
parents:
diff changeset
2647 end loop;
kono
parents:
diff changeset
2648 end if;
kono
parents:
diff changeset
2649
kono
parents:
diff changeset
2650 if (not Is_Package_Or_Generic_Package (Current_Scope))
kono
parents:
diff changeset
2651 or else not In_Private_Part (Current_Scope)
kono
parents:
diff changeset
2652 then
kono
parents:
diff changeset
2653 -- Not a private primitive
kono
parents:
diff changeset
2654
kono
parents:
diff changeset
2655 null;
kono
parents:
diff changeset
2656
kono
parents:
diff changeset
2657 else pragma Assert (Is_Inherited_Operation (Prev_Op));
kono
parents:
diff changeset
2658
kono
parents:
diff changeset
2659 -- Make the overriding operation into an alias of the implicit one.
kono
parents:
diff changeset
2660 -- In this fashion a call from outside ends up calling the new body
kono
parents:
diff changeset
2661 -- even if non-dispatching, and a call from inside calls the over-
kono
parents:
diff changeset
2662 -- riding operation because it hides the implicit one. To indicate
kono
parents:
diff changeset
2663 -- that the body of Prev_Op is never called, set its dispatch table
kono
parents:
diff changeset
2664 -- entity to Empty. If the overridden operation has a dispatching
kono
parents:
diff changeset
2665 -- result, so does the overriding one.
kono
parents:
diff changeset
2666
kono
parents:
diff changeset
2667 Set_Alias (Prev_Op, New_Op);
kono
parents:
diff changeset
2668 Set_DTC_Entity (Prev_Op, Empty);
kono
parents:
diff changeset
2669 Set_Has_Controlling_Result (New_Op, Has_Controlling_Result (Prev_Op));
kono
parents:
diff changeset
2670 return;
kono
parents:
diff changeset
2671 end if;
kono
parents:
diff changeset
2672 end Override_Dispatching_Operation;
kono
parents:
diff changeset
2673
kono
parents:
diff changeset
2674 -------------------
kono
parents:
diff changeset
2675 -- Propagate_Tag --
kono
parents:
diff changeset
2676 -------------------
kono
parents:
diff changeset
2677
kono
parents:
diff changeset
2678 procedure Propagate_Tag (Control : Node_Id; Actual : Node_Id) is
kono
parents:
diff changeset
2679 Call_Node : Node_Id;
kono
parents:
diff changeset
2680 Arg : Node_Id;
kono
parents:
diff changeset
2681
kono
parents:
diff changeset
2682 begin
kono
parents:
diff changeset
2683 if Nkind (Actual) = N_Function_Call then
kono
parents:
diff changeset
2684 Call_Node := Actual;
kono
parents:
diff changeset
2685
kono
parents:
diff changeset
2686 elsif Nkind (Actual) = N_Identifier
kono
parents:
diff changeset
2687 and then Nkind (Original_Node (Actual)) = N_Function_Call
kono
parents:
diff changeset
2688 then
kono
parents:
diff changeset
2689 -- Call rewritten as object declaration when stack-checking is
kono
parents:
diff changeset
2690 -- enabled. Propagate tag to expression in declaration, which is
kono
parents:
diff changeset
2691 -- original call.
kono
parents:
diff changeset
2692
kono
parents:
diff changeset
2693 Call_Node := Expression (Parent (Entity (Actual)));
kono
parents:
diff changeset
2694
kono
parents:
diff changeset
2695 -- Ada 2005: If this is a dereference of a call to a function with a
kono
parents:
diff changeset
2696 -- dispatching access-result, the tag is propagated when the dereference
kono
parents:
diff changeset
2697 -- itself is expanded (see exp_ch6.adb) and there is nothing else to do.
kono
parents:
diff changeset
2698
kono
parents:
diff changeset
2699 elsif Nkind (Actual) = N_Explicit_Dereference
kono
parents:
diff changeset
2700 and then Nkind (Original_Node (Prefix (Actual))) = N_Function_Call
kono
parents:
diff changeset
2701 then
kono
parents:
diff changeset
2702 return;
kono
parents:
diff changeset
2703
kono
parents:
diff changeset
2704 -- When expansion is suppressed, an unexpanded call to 'Input can occur,
kono
parents:
diff changeset
2705 -- and in that case we can simply return.
kono
parents:
diff changeset
2706
kono
parents:
diff changeset
2707 elsif Nkind (Actual) = N_Attribute_Reference then
kono
parents:
diff changeset
2708 pragma Assert (Attribute_Name (Actual) = Name_Input);
kono
parents:
diff changeset
2709
kono
parents:
diff changeset
2710 return;
kono
parents:
diff changeset
2711
kono
parents:
diff changeset
2712 -- Only other possibilities are parenthesized or qualified expression,
kono
parents:
diff changeset
2713 -- or an expander-generated unchecked conversion of a function call to
kono
parents:
diff changeset
2714 -- a stream Input attribute.
kono
parents:
diff changeset
2715
kono
parents:
diff changeset
2716 else
kono
parents:
diff changeset
2717 Call_Node := Expression (Actual);
kono
parents:
diff changeset
2718 end if;
kono
parents:
diff changeset
2719
kono
parents:
diff changeset
2720 -- No action needed if the call has been already expanded
kono
parents:
diff changeset
2721
kono
parents:
diff changeset
2722 if Is_Expanded_Dispatching_Call (Call_Node) then
kono
parents:
diff changeset
2723 return;
kono
parents:
diff changeset
2724 end if;
kono
parents:
diff changeset
2725
kono
parents:
diff changeset
2726 -- Do not set the Controlling_Argument if already set. This happens in
kono
parents:
diff changeset
2727 -- the special case of _Input (see Exp_Attr, case Input).
kono
parents:
diff changeset
2728
kono
parents:
diff changeset
2729 if No (Controlling_Argument (Call_Node)) then
kono
parents:
diff changeset
2730 Set_Controlling_Argument (Call_Node, Control);
kono
parents:
diff changeset
2731 end if;
kono
parents:
diff changeset
2732
kono
parents:
diff changeset
2733 Arg := First_Actual (Call_Node);
kono
parents:
diff changeset
2734 while Present (Arg) loop
kono
parents:
diff changeset
2735 if Is_Tag_Indeterminate (Arg) then
kono
parents:
diff changeset
2736 Propagate_Tag (Control, Arg);
kono
parents:
diff changeset
2737 end if;
kono
parents:
diff changeset
2738
kono
parents:
diff changeset
2739 Next_Actual (Arg);
kono
parents:
diff changeset
2740 end loop;
kono
parents:
diff changeset
2741
kono
parents:
diff changeset
2742 -- Expansion of dispatching calls is suppressed on VM targets, because
kono
parents:
diff changeset
2743 -- the VM back-ends directly handle the generation of dispatching calls
kono
parents:
diff changeset
2744 -- and would have to undo any expansion to an indirect call.
kono
parents:
diff changeset
2745
kono
parents:
diff changeset
2746 if Tagged_Type_Expansion then
kono
parents:
diff changeset
2747 declare
kono
parents:
diff changeset
2748 Call_Typ : constant Entity_Id := Etype (Call_Node);
kono
parents:
diff changeset
2749
kono
parents:
diff changeset
2750 begin
kono
parents:
diff changeset
2751 Expand_Dispatching_Call (Call_Node);
kono
parents:
diff changeset
2752
kono
parents:
diff changeset
2753 -- If the controlling argument is an interface type and the type
kono
parents:
diff changeset
2754 -- of Call_Node differs then we must add an implicit conversion to
kono
parents:
diff changeset
2755 -- force displacement of the pointer to the object to reference
kono
parents:
diff changeset
2756 -- the secondary dispatch table of the interface.
kono
parents:
diff changeset
2757
kono
parents:
diff changeset
2758 if Is_Interface (Etype (Control))
kono
parents:
diff changeset
2759 and then Etype (Control) /= Call_Typ
kono
parents:
diff changeset
2760 then
kono
parents:
diff changeset
2761 -- Cannot use Convert_To because the previous call to
kono
parents:
diff changeset
2762 -- Expand_Dispatching_Call leaves decorated the Call_Node
kono
parents:
diff changeset
2763 -- with the type of Control.
kono
parents:
diff changeset
2764
kono
parents:
diff changeset
2765 Rewrite (Call_Node,
kono
parents:
diff changeset
2766 Make_Type_Conversion (Sloc (Call_Node),
kono
parents:
diff changeset
2767 Subtype_Mark =>
kono
parents:
diff changeset
2768 New_Occurrence_Of (Etype (Control), Sloc (Call_Node)),
kono
parents:
diff changeset
2769 Expression => Relocate_Node (Call_Node)));
kono
parents:
diff changeset
2770 Set_Etype (Call_Node, Etype (Control));
kono
parents:
diff changeset
2771 Set_Analyzed (Call_Node);
kono
parents:
diff changeset
2772
kono
parents:
diff changeset
2773 Expand_Interface_Conversion (Call_Node);
kono
parents:
diff changeset
2774 end if;
kono
parents:
diff changeset
2775 end;
kono
parents:
diff changeset
2776
kono
parents:
diff changeset
2777 -- Expansion of a dispatching call results in an indirect call, which in
kono
parents:
diff changeset
2778 -- turn causes current values to be killed (see Resolve_Call), so on VM
kono
parents:
diff changeset
2779 -- targets we do the call here to ensure consistent warnings between VM
kono
parents:
diff changeset
2780 -- and non-VM targets.
kono
parents:
diff changeset
2781
kono
parents:
diff changeset
2782 else
kono
parents:
diff changeset
2783 Kill_Current_Values;
kono
parents:
diff changeset
2784 end if;
kono
parents:
diff changeset
2785 end Propagate_Tag;
kono
parents:
diff changeset
2786
kono
parents:
diff changeset
2787 end Sem_Disp;