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