1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2015, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 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. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Atree
; use Atree
;
27 with Debug
; use Debug
;
28 with Elists
; use Elists
;
29 with Einfo
; use Einfo
;
30 with Exp_Disp
; use Exp_Disp
;
31 with Exp_Util
; use Exp_Util
;
32 with Exp_Ch7
; use Exp_Ch7
;
33 with Exp_Tss
; use Exp_Tss
;
34 with Errout
; use Errout
;
35 with Lib
.Xref
; use Lib
.Xref
;
36 with Namet
; use Namet
;
37 with Nlists
; use Nlists
;
38 with Nmake
; use Nmake
;
40 with Output
; use Output
;
41 with Restrict
; use Restrict
;
42 with Rident
; use Rident
;
44 with Sem_Aux
; use Sem_Aux
;
45 with Sem_Ch3
; use Sem_Ch3
;
46 with Sem_Ch6
; use Sem_Ch6
;
47 with Sem_Ch8
; use Sem_Ch8
;
48 with Sem_Eval
; use Sem_Eval
;
49 with Sem_Type
; use Sem_Type
;
50 with Sem_Util
; use Sem_Util
;
51 with Snames
; use Snames
;
52 with Sinfo
; use Sinfo
;
53 with Targparm
; use Targparm
;
54 with Tbuild
; use Tbuild
;
55 with Uintp
; use Uintp
;
57 package body Sem_Disp
is
59 -----------------------
60 -- Local Subprograms --
61 -----------------------
63 procedure Add_Dispatching_Operation
64 (Tagged_Type
: Entity_Id
;
66 -- Add New_Op in the list of primitive operations of Tagged_Type
68 function Check_Controlling_Type
70 Subp
: Entity_Id
) return Entity_Id
;
71 -- T is the tagged type of a formal parameter or the result of Subp.
72 -- If the subprogram has a controlling parameter or result that matches
73 -- the type, then returns the tagged type of that parameter or result
74 -- (returning the designated tagged type in the case of an access
75 -- parameter); otherwise returns empty.
77 function Find_Hidden_Overridden_Primitive
(S
: Entity_Id
) return Entity_Id
;
78 -- [Ada 2012:AI-0125] Find an inherited hidden primitive of the dispatching
79 -- type of S that has the same name of S, a type-conformant profile, an
80 -- original corresponding operation O that is a primitive of a visible
81 -- ancestor of the dispatching type of S and O is visible at the point of
82 -- of declaration of S. If the entity is found the Alias of S is set to the
83 -- original corresponding operation S and its Overridden_Operation is set
84 -- to the found entity; otherwise return Empty.
86 -- This routine does not search for non-hidden primitives since they are
87 -- covered by the normal Ada 2005 rules.
89 function Is_Inherited_Public_Operation
(Op
: Entity_Id
) return Boolean;
90 -- Check whether a primitive operation is inherited from an operation
91 -- declared in the visible part of its package.
93 -------------------------------
94 -- Add_Dispatching_Operation --
95 -------------------------------
97 procedure Add_Dispatching_Operation
98 (Tagged_Type
: Entity_Id
;
101 List
: constant Elist_Id
:= Primitive_Operations
(Tagged_Type
);
104 -- The dispatching operation may already be on the list, if it is the
105 -- wrapper for an inherited function of a null extension (see Exp_Ch3
106 -- for the construction of function wrappers). The list of primitive
107 -- operations must not contain duplicates.
109 Append_Unique_Elmt
(New_Op
, List
);
110 end Add_Dispatching_Operation
;
112 ---------------------------
113 -- Covers_Some_Interface --
114 ---------------------------
116 function Covers_Some_Interface
(Prim
: Entity_Id
) return Boolean is
117 Tagged_Type
: constant Entity_Id
:= Find_Dispatching_Type
(Prim
);
122 pragma Assert
(Is_Dispatching_Operation
(Prim
));
124 -- Although this is a dispatching primitive we must check if its
125 -- dispatching type is available because it may be the primitive
126 -- of a private type not defined as tagged in its partial view.
128 if Present
(Tagged_Type
) and then Has_Interfaces
(Tagged_Type
) then
130 -- If the tagged type is frozen then the internal entities associated
131 -- with interfaces are available in the list of primitives of the
132 -- tagged type and can be used to speed up this search.
134 if Is_Frozen
(Tagged_Type
) then
135 Elmt
:= First_Elmt
(Primitive_Operations
(Tagged_Type
));
136 while Present
(Elmt
) loop
139 if Present
(Interface_Alias
(E
))
140 and then Alias
(E
) = Prim
148 -- Otherwise we must collect all the interface primitives and check
149 -- if the Prim will override some interface primitive.
153 Ifaces_List
: Elist_Id
;
154 Iface_Elmt
: Elmt_Id
;
156 Iface_Prim
: Entity_Id
;
159 Collect_Interfaces
(Tagged_Type
, Ifaces_List
);
160 Iface_Elmt
:= First_Elmt
(Ifaces_List
);
161 while Present
(Iface_Elmt
) loop
162 Iface
:= Node
(Iface_Elmt
);
164 Elmt
:= First_Elmt
(Primitive_Operations
(Iface
));
165 while Present
(Elmt
) loop
166 Iface_Prim
:= Node
(Elmt
);
168 if Chars
(Iface
) = Chars
(Prim
)
169 and then Is_Interface_Conformant
170 (Tagged_Type
, Iface_Prim
, Prim
)
178 Next_Elmt
(Iface_Elmt
);
185 end Covers_Some_Interface
;
187 -------------------------------
188 -- Check_Controlling_Formals --
189 -------------------------------
191 procedure Check_Controlling_Formals
196 Ctrl_Type
: Entity_Id
;
199 Formal
:= First_Formal
(Subp
);
200 while Present
(Formal
) loop
201 Ctrl_Type
:= Check_Controlling_Type
(Etype
(Formal
), Subp
);
203 if Present
(Ctrl_Type
) then
205 -- When controlling type is concurrent and declared within a
206 -- generic or inside an instance use corresponding record type.
208 if Is_Concurrent_Type
(Ctrl_Type
)
209 and then Present
(Corresponding_Record_Type
(Ctrl_Type
))
211 Ctrl_Type
:= Corresponding_Record_Type
(Ctrl_Type
);
214 if Ctrl_Type
= Typ
then
215 Set_Is_Controlling_Formal
(Formal
);
217 -- Ada 2005 (AI-231): Anonymous access types that are used in
218 -- controlling parameters exclude null because it is necessary
219 -- to read the tag to dispatch, and null has no tag.
221 if Ekind
(Etype
(Formal
)) = E_Anonymous_Access_Type
then
222 Set_Can_Never_Be_Null
(Etype
(Formal
));
223 Set_Is_Known_Non_Null
(Etype
(Formal
));
226 -- Check that the parameter's nominal subtype statically
227 -- matches the first subtype.
229 if Ekind
(Etype
(Formal
)) = E_Anonymous_Access_Type
then
230 if not Subtypes_Statically_Match
231 (Typ
, Designated_Type
(Etype
(Formal
)))
234 ("parameter subtype does not match controlling type",
238 elsif not Subtypes_Statically_Match
(Typ
, Etype
(Formal
)) then
240 ("parameter subtype does not match controlling type",
244 if Present
(Default_Value
(Formal
)) then
246 -- In Ada 2005, access parameters can have defaults
248 if Ekind
(Etype
(Formal
)) = E_Anonymous_Access_Type
249 and then Ada_Version
< Ada_2005
252 ("default not allowed for controlling access parameter",
253 Default_Value
(Formal
));
255 elsif not Is_Tag_Indeterminate
(Default_Value
(Formal
)) then
257 ("default expression must be a tag indeterminate" &
258 " function call", Default_Value
(Formal
));
262 elsif Comes_From_Source
(Subp
) then
264 ("operation can be dispatching in only one type", Subp
);
268 Next_Formal
(Formal
);
271 if Ekind_In
(Subp
, E_Function
, E_Generic_Function
) then
272 Ctrl_Type
:= Check_Controlling_Type
(Etype
(Subp
), Subp
);
274 if Present
(Ctrl_Type
) then
275 if Ctrl_Type
= Typ
then
276 Set_Has_Controlling_Result
(Subp
);
278 -- Check that result subtype statically matches first subtype
279 -- (Ada 2005): Subp may have a controlling access result.
281 if Subtypes_Statically_Match
(Typ
, Etype
(Subp
))
282 or else (Ekind
(Etype
(Subp
)) = E_Anonymous_Access_Type
284 Subtypes_Statically_Match
285 (Typ
, Designated_Type
(Etype
(Subp
))))
291 ("result subtype does not match controlling type", Subp
);
294 elsif Comes_From_Source
(Subp
) then
296 ("operation can be dispatching in only one type", Subp
);
300 end Check_Controlling_Formals
;
302 ----------------------------
303 -- Check_Controlling_Type --
304 ----------------------------
306 function Check_Controlling_Type
308 Subp
: Entity_Id
) return Entity_Id
310 Tagged_Type
: Entity_Id
:= Empty
;
313 if Is_Tagged_Type
(T
) then
314 if Is_First_Subtype
(T
) then
317 Tagged_Type
:= Base_Type
(T
);
320 elsif Ekind
(T
) = E_Anonymous_Access_Type
321 and then Is_Tagged_Type
(Designated_Type
(T
))
323 if Ekind
(Designated_Type
(T
)) /= E_Incomplete_Type
then
324 if Is_First_Subtype
(Designated_Type
(T
)) then
325 Tagged_Type
:= Designated_Type
(T
);
327 Tagged_Type
:= Base_Type
(Designated_Type
(T
));
330 -- Ada 2005: an incomplete type can be tagged. An operation with an
331 -- access parameter of the type is dispatching.
333 elsif Scope
(Designated_Type
(T
)) = Current_Scope
then
334 Tagged_Type
:= Designated_Type
(T
);
336 -- Ada 2005 (AI-50217)
338 elsif From_Limited_With
(Designated_Type
(T
))
339 and then Has_Non_Limited_View
(Designated_Type
(T
))
340 and then Scope
(Designated_Type
(T
)) = Scope
(Subp
)
342 if Is_First_Subtype
(Non_Limited_View
(Designated_Type
(T
))) then
343 Tagged_Type
:= Non_Limited_View
(Designated_Type
(T
));
345 Tagged_Type
:= Base_Type
(Non_Limited_View
346 (Designated_Type
(T
)));
351 if No
(Tagged_Type
) or else Is_Class_Wide_Type
(Tagged_Type
) then
354 -- The dispatching type and the primitive operation must be defined in
355 -- the same scope, except in the case of internal operations and formal
356 -- abstract subprograms.
358 elsif ((Scope
(Subp
) = Scope
(Tagged_Type
) or else Is_Internal
(Subp
))
359 and then (not Is_Generic_Type
(Tagged_Type
)
360 or else not Comes_From_Source
(Subp
)))
362 (Is_Formal_Subprogram
(Subp
) and then Is_Abstract_Subprogram
(Subp
))
364 (Nkind
(Parent
(Parent
(Subp
))) = N_Subprogram_Renaming_Declaration
366 Present
(Corresponding_Formal_Spec
(Parent
(Parent
(Subp
))))
368 Is_Abstract_Subprogram
(Subp
))
375 end Check_Controlling_Type
;
377 ----------------------------
378 -- Check_Dispatching_Call --
379 ----------------------------
381 procedure Check_Dispatching_Call
(N
: Node_Id
) is
382 Loc
: constant Source_Ptr
:= Sloc
(N
);
385 Control
: Node_Id
:= Empty
;
387 Subp_Entity
: Entity_Id
;
388 Indeterm_Ancestor_Call
: Boolean := False;
389 Indeterm_Ctrl_Type
: Entity_Id
;
391 Static_Tag
: Node_Id
:= Empty
;
392 -- If a controlling formal has a statically tagged actual, the tag of
393 -- this actual is to be used for any tag-indeterminate actual.
395 procedure Check_Direct_Call
;
396 -- In the case when the controlling actual is a class-wide type whose
397 -- root type's completion is a task or protected type, the call is in
398 -- fact direct. This routine detects the above case and modifies the
401 procedure Check_Dispatching_Context
;
402 -- If the call is tag-indeterminate and the entity being called is
403 -- abstract, verify that the context is a call that will eventually
404 -- provide a tag for dispatching, or has provided one already.
406 -----------------------
407 -- Check_Direct_Call --
408 -----------------------
410 procedure Check_Direct_Call
is
411 Typ
: Entity_Id
:= Etype
(Control
);
413 function Is_User_Defined_Equality
(Id
: Entity_Id
) return Boolean;
414 -- Determine whether an entity denotes a user-defined equality
416 ------------------------------
417 -- Is_User_Defined_Equality --
418 ------------------------------
420 function Is_User_Defined_Equality
(Id
: Entity_Id
) return Boolean is
423 Ekind
(Id
) = E_Function
424 and then Chars
(Id
) = Name_Op_Eq
425 and then Comes_From_Source
(Id
)
427 -- Internally generated equalities have a full type declaration
430 and then Nkind
(Parent
(Id
)) = N_Function_Specification
;
431 end Is_User_Defined_Equality
;
433 -- Start of processing for Check_Direct_Call
436 -- Predefined primitives do not receive wrappers since they are built
437 -- from scratch for the corresponding record of synchronized types.
438 -- Equality is in general predefined, but is excluded from the check
439 -- when it is user-defined.
441 if Is_Predefined_Dispatching_Operation
(Subp_Entity
)
442 and then not Is_User_Defined_Equality
(Subp_Entity
)
447 if Is_Class_Wide_Type
(Typ
) then
448 Typ
:= Root_Type
(Typ
);
451 if Is_Private_Type
(Typ
) and then Present
(Full_View
(Typ
)) then
452 Typ
:= Full_View
(Typ
);
455 if Is_Concurrent_Type
(Typ
)
457 Present
(Corresponding_Record_Type
(Typ
))
459 Typ
:= Corresponding_Record_Type
(Typ
);
461 -- The concurrent record's list of primitives should contain a
462 -- wrapper for the entity of the call, retrieve it.
467 Wrapper_Found
: Boolean := False;
470 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
471 while Present
(Prim_Elmt
) loop
472 Prim
:= Node
(Prim_Elmt
);
474 if Is_Primitive_Wrapper
(Prim
)
475 and then Wrapped_Entity
(Prim
) = Subp_Entity
477 Wrapper_Found
:= True;
481 Next_Elmt
(Prim_Elmt
);
484 -- A primitive declared between two views should have a
485 -- corresponding wrapper.
487 pragma Assert
(Wrapper_Found
);
489 -- Modify the call by setting the proper entity
491 Set_Entity
(Name
(N
), Prim
);
494 end Check_Direct_Call
;
496 -------------------------------
497 -- Check_Dispatching_Context --
498 -------------------------------
500 procedure Check_Dispatching_Context
is
501 Subp
: constant Entity_Id
:= Entity
(Name
(N
));
502 Typ
: constant Entity_Id
:= Etype
(Subp
);
505 procedure Abstract_Context_Error
;
506 -- Error for abstract call dispatching on result is not dispatching
508 ----------------------------
509 -- Abstract_Context_Error --
510 ----------------------------
512 procedure Abstract_Context_Error
is
514 if Ekind
(Subp
) = E_Function
then
516 ("call to abstract function must be dispatching", N
);
518 -- This error can occur for a procedure in the case of a call to
519 -- an abstract formal procedure with a statically tagged operand.
523 ("call to abstract procedure must be dispatching",
526 end Abstract_Context_Error
;
528 -- Start of processing for Check_Dispatching_Context
531 if Is_Abstract_Subprogram
(Subp
)
532 and then No
(Controlling_Argument
(N
))
534 if Present
(Alias
(Subp
))
535 and then not Is_Abstract_Subprogram
(Alias
(Subp
))
536 and then No
(DTC_Entity
(Subp
))
538 -- Private overriding of inherited abstract operation, call is
541 Set_Entity
(Name
(N
), Alias
(Subp
));
544 -- An obscure special case: a null procedure may have a class-
545 -- wide pre/postcondition that includes a call to an abstract
546 -- subp. Calls within the expression may not have been rewritten
547 -- as dispatching calls yet, because the null body appears in
548 -- the current declarative part. The expression will be properly
549 -- rewritten/reanalyzed when the postcondition procedure is built.
551 -- Similarly, if this is a pre/postcondition for an abstract
552 -- subprogram, it may call another abstract function which is
553 -- a primitive of an abstract type. The call is non-dispatching
554 -- but will be legal in overridings of the operation.
556 elsif In_Spec_Expression
557 and then Is_Subprogram
(Current_Scope
)
559 ((Nkind
(Parent
(Current_Scope
)) = N_Procedure_Specification
560 and then Null_Present
(Parent
(Current_Scope
)))
561 or else Is_Abstract_Subprogram
(Current_Scope
))
565 elsif Ekind
(Current_Scope
) = E_Function
566 and then Nkind
(Unit_Declaration_Node
(Current_Scope
)) =
567 N_Generic_Subprogram_Declaration
572 -- We need to determine whether the context of the call
573 -- provides a tag to make the call dispatching. This requires
574 -- the call to be the actual in an enclosing call, and that
575 -- actual must be controlling. If the call is an operand of
576 -- equality, the other operand must not ve abstract.
578 if not Is_Tagged_Type
(Typ
)
580 (Ekind
(Typ
) = E_Anonymous_Access_Type
581 and then Is_Tagged_Type
(Designated_Type
(Typ
)))
583 Abstract_Context_Error
;
589 if Nkind
(Par
) = N_Parameter_Association
then
593 while Present
(Par
) loop
594 if Nkind_In
(Par
, N_Function_Call
,
595 N_Procedure_Call_Statement
)
596 and then Is_Entity_Name
(Name
(Par
))
603 -- Find formal for which call is the actual.
605 F
:= First_Formal
(Entity
(Name
(Par
)));
606 A
:= First_Actual
(Par
);
607 while Present
(F
) loop
608 if Is_Controlling_Formal
(F
)
609 and then (N
= A
or else Parent
(N
) = A
)
619 ("call to abstract function must be dispatching", N
);
623 -- For equalitiy operators, one of the operands must be
624 -- statically or dynamically tagged.
626 elsif Nkind_In
(Par
, N_Op_Eq
, N_Op_Ne
) then
627 if N
= Right_Opnd
(Par
)
628 and then Is_Tag_Indeterminate
(Left_Opnd
(Par
))
630 Abstract_Context_Error
;
632 elsif N
= Left_Opnd
(Par
)
633 and then Is_Tag_Indeterminate
(Right_Opnd
(Par
))
635 Abstract_Context_Error
;
640 elsif Nkind
(Par
) = N_Assignment_Statement
then
643 elsif Nkind
(Par
) = N_Qualified_Expression
644 or else Nkind
(Par
) = N_Unchecked_Type_Conversion
649 Abstract_Context_Error
;
655 end Check_Dispatching_Context
;
657 -- Start of processing for Check_Dispatching_Call
660 -- Find a controlling argument, if any
662 if Present
(Parameter_Associations
(N
)) then
663 Subp_Entity
:= Entity
(Name
(N
));
665 Actual
:= First_Actual
(N
);
666 Formal
:= First_Formal
(Subp_Entity
);
667 while Present
(Actual
) loop
668 Control
:= Find_Controlling_Arg
(Actual
);
669 exit when Present
(Control
);
671 -- Check for the case where the actual is a tag-indeterminate call
672 -- whose result type is different than the tagged type associated
673 -- with the containing call, but is an ancestor of the type.
675 if Is_Controlling_Formal
(Formal
)
676 and then Is_Tag_Indeterminate
(Actual
)
677 and then Base_Type
(Etype
(Actual
)) /= Base_Type
(Etype
(Formal
))
678 and then Is_Ancestor
(Etype
(Actual
), Etype
(Formal
))
680 Indeterm_Ancestor_Call
:= True;
681 Indeterm_Ctrl_Type
:= Etype
(Formal
);
683 -- If the formal is controlling but the actual is not, the type
684 -- of the actual is statically known, and may be used as the
685 -- controlling tag for some other tag-indeterminate actual.
687 elsif Is_Controlling_Formal
(Formal
)
688 and then Is_Entity_Name
(Actual
)
689 and then Is_Tagged_Type
(Etype
(Actual
))
691 Static_Tag
:= Actual
;
694 Next_Actual
(Actual
);
695 Next_Formal
(Formal
);
698 -- If the call doesn't have a controlling actual but does have an
699 -- indeterminate actual that requires dispatching treatment, then an
700 -- object is needed that will serve as the controlling argument for
701 -- a dispatching call on the indeterminate actual. This can only
702 -- occur in the unusual situation of a default actual given by
703 -- a tag-indeterminate call and where the type of the call is an
704 -- ancestor of the type associated with a containing call to an
705 -- inherited operation (see AI-239).
707 -- Rather than create an object of the tagged type, which would
708 -- be problematic for various reasons (default initialization,
709 -- discriminants), the tag of the containing call's associated
710 -- tagged type is directly used to control the dispatching.
713 and then Indeterm_Ancestor_Call
714 and then No
(Static_Tag
)
717 Make_Attribute_Reference
(Loc
,
718 Prefix
=> New_Occurrence_Of
(Indeterm_Ctrl_Type
, Loc
),
719 Attribute_Name
=> Name_Tag
);
724 if Present
(Control
) then
726 -- Verify that no controlling arguments are statically tagged
729 Write_Str
("Found Dispatching call");
734 Actual
:= First_Actual
(N
);
735 while Present
(Actual
) loop
736 if Actual
/= Control
then
738 if not Is_Controlling_Actual
(Actual
) then
739 null; -- Can be anything
741 elsif Is_Dynamically_Tagged
(Actual
) then
742 null; -- Valid parameter
744 elsif Is_Tag_Indeterminate
(Actual
) then
746 -- The tag is inherited from the enclosing call (the node
747 -- we are currently analyzing). Explicitly expand the
748 -- actual, since the previous call to Expand (from
749 -- Resolve_Call) had no way of knowing about the
750 -- required dispatching.
752 Propagate_Tag
(Control
, Actual
);
756 ("controlling argument is not dynamically tagged",
762 Next_Actual
(Actual
);
765 -- Mark call as a dispatching call
767 Set_Controlling_Argument
(N
, Control
);
768 Check_Restriction
(No_Dispatching_Calls
, N
);
770 -- The dispatching call may need to be converted into a direct
771 -- call in certain cases.
775 -- If there is a statically tagged actual and a tag-indeterminate
776 -- call to a function of the ancestor (such as that provided by a
777 -- default), then treat this as a dispatching call and propagate
778 -- the tag to the tag-indeterminate call(s).
780 elsif Present
(Static_Tag
) and then Indeterm_Ancestor_Call
then
782 Make_Attribute_Reference
(Loc
,
784 New_Occurrence_Of
(Etype
(Static_Tag
), Loc
),
785 Attribute_Name
=> Name_Tag
);
789 Actual
:= First_Actual
(N
);
790 Formal
:= First_Formal
(Subp_Entity
);
791 while Present
(Actual
) loop
792 if Is_Tag_Indeterminate
(Actual
)
793 and then Is_Controlling_Formal
(Formal
)
795 Propagate_Tag
(Control
, Actual
);
798 Next_Actual
(Actual
);
799 Next_Formal
(Formal
);
802 Check_Dispatching_Context
;
805 -- The call is not dispatching, so check that there aren't any
806 -- tag-indeterminate abstract calls left.
808 Actual
:= First_Actual
(N
);
809 while Present
(Actual
) loop
810 if Is_Tag_Indeterminate
(Actual
) then
812 -- Function call case
814 if Nkind
(Original_Node
(Actual
)) = N_Function_Call
then
815 Func
:= Entity
(Name
(Original_Node
(Actual
)));
817 -- If the actual is an attribute then it can't be abstract
818 -- (the only current case of a tag-indeterminate attribute
819 -- is the stream Input attribute).
822 Nkind
(Original_Node
(Actual
)) = N_Attribute_Reference
826 -- Only other possibility is a qualified expression whose
827 -- constituent expression is itself a call.
833 (Expression
(Original_Node
(Actual
)))));
836 if Present
(Func
) and then Is_Abstract_Subprogram
(Func
) then
838 ("call to abstract function must be dispatching", N
);
842 Next_Actual
(Actual
);
845 Check_Dispatching_Context
;
849 -- If dispatching on result, the enclosing call, if any, will
850 -- determine the controlling argument. Otherwise this is the
851 -- primitive operation of the root type.
853 Check_Dispatching_Context
;
855 end Check_Dispatching_Call
;
857 ---------------------------------
858 -- Check_Dispatching_Operation --
859 ---------------------------------
861 procedure Check_Dispatching_Operation
(Subp
, Old_Subp
: Entity_Id
) is
862 Tagged_Type
: Entity_Id
;
863 Has_Dispatching_Parent
: Boolean := False;
864 Body_Is_Last_Primitive
: Boolean := False;
865 Ovr_Subp
: Entity_Id
:= Empty
;
868 if not Ekind_In
(Subp
, E_Procedure
, E_Function
) then
872 Set_Is_Dispatching_Operation
(Subp
, False);
873 Tagged_Type
:= Find_Dispatching_Type
(Subp
);
875 -- Ada 2005 (AI-345): Use the corresponding record (if available).
876 -- Required because primitives of concurrent types are attached
877 -- to the corresponding record (not to the concurrent type).
879 if Ada_Version
>= Ada_2005
880 and then Present
(Tagged_Type
)
881 and then Is_Concurrent_Type
(Tagged_Type
)
882 and then Present
(Corresponding_Record_Type
(Tagged_Type
))
884 Tagged_Type
:= Corresponding_Record_Type
(Tagged_Type
);
887 -- (AI-345): The task body procedure is not a primitive of the tagged
890 if Present
(Tagged_Type
)
891 and then Is_Concurrent_Record_Type
(Tagged_Type
)
892 and then Present
(Corresponding_Concurrent_Type
(Tagged_Type
))
893 and then Is_Task_Type
(Corresponding_Concurrent_Type
(Tagged_Type
))
894 and then Subp
= Get_Task_Body_Procedure
895 (Corresponding_Concurrent_Type
(Tagged_Type
))
900 -- If Subp is derived from a dispatching operation then it should
901 -- always be treated as dispatching. In this case various checks
902 -- below will be bypassed. Makes sure that late declarations for
903 -- inherited private subprograms are treated as dispatching, even
904 -- if the associated tagged type is already frozen.
906 Has_Dispatching_Parent
:=
907 Present
(Alias
(Subp
))
908 and then Is_Dispatching_Operation
(Alias
(Subp
));
910 if No
(Tagged_Type
) then
912 -- Ada 2005 (AI-251): Check that Subp is not a primitive associated
913 -- with an abstract interface type unless the interface acts as a
914 -- parent type in a derivation. If the interface type is a formal
915 -- type then the operation is not primitive and therefore legal.
922 E
:= First_Entity
(Subp
);
923 while Present
(E
) loop
925 -- For an access parameter, check designated type
927 if Ekind
(Etype
(E
)) = E_Anonymous_Access_Type
then
928 Typ
:= Designated_Type
(Etype
(E
));
933 if Comes_From_Source
(Subp
)
934 and then Is_Interface
(Typ
)
935 and then not Is_Class_Wide_Type
(Typ
)
936 and then not Is_Derived_Type
(Typ
)
937 and then not Is_Generic_Type
(Typ
)
938 and then not In_Instance
940 Error_Msg_N
("??declaration of& is too late!", Subp
);
941 Error_Msg_NE
-- CODEFIX??
942 ("\??spec should appear immediately after declaration "
943 & "of & !", Subp
, Typ
);
950 -- In case of functions check also the result type
952 if Ekind
(Subp
) = E_Function
then
953 if Is_Access_Type
(Etype
(Subp
)) then
954 Typ
:= Designated_Type
(Etype
(Subp
));
959 -- The following should be better commented, especially since
960 -- we just added several new conditions here ???
962 if Comes_From_Source
(Subp
)
963 and then Is_Interface
(Typ
)
964 and then not Is_Class_Wide_Type
(Typ
)
965 and then not Is_Derived_Type
(Typ
)
966 and then not Is_Generic_Type
(Typ
)
967 and then not In_Instance
969 Error_Msg_N
("??declaration of& is too late!", Subp
);
971 ("\??spec should appear immediately after declaration "
972 & "of & !", Subp
, Typ
);
979 -- The subprograms build internally after the freezing point (such as
980 -- init procs, interface thunks, type support subprograms, and Offset
981 -- to top functions for accessing interface components in variable
982 -- size tagged types) are not primitives.
984 elsif Is_Frozen
(Tagged_Type
)
985 and then not Comes_From_Source
(Subp
)
986 and then not Has_Dispatching_Parent
988 -- Complete decoration of internally built subprograms that override
989 -- a dispatching primitive. These entities correspond with the
992 -- 1. Ada 2005 (AI-391): Wrapper functions built by the expander
993 -- to override functions of nonabstract null extensions. These
994 -- primitives were added to the list of primitives of the tagged
995 -- type by Make_Controlling_Function_Wrappers. However, attribute
996 -- Is_Dispatching_Operation must be set to true.
998 -- 2. Ada 2005 (AI-251): Wrapper procedures of null interface
1001 -- 3. Subprograms associated with stream attributes (built by
1002 -- New_Stream_Subprogram)
1004 if Present
(Old_Subp
)
1005 and then Present
(Overridden_Operation
(Subp
))
1006 and then Is_Dispatching_Operation
(Old_Subp
)
1009 ((Ekind
(Subp
) = E_Function
1010 and then Is_Dispatching_Operation
(Old_Subp
)
1011 and then Is_Null_Extension
(Base_Type
(Etype
(Subp
))))
1013 (Ekind
(Subp
) = E_Procedure
1014 and then Is_Dispatching_Operation
(Old_Subp
)
1015 and then Present
(Alias
(Old_Subp
))
1016 and then Is_Null_Interface_Primitive
1017 (Ultimate_Alias
(Old_Subp
)))
1018 or else Get_TSS_Name
(Subp
) = TSS_Stream_Read
1019 or else Get_TSS_Name
(Subp
) = TSS_Stream_Write
);
1021 Check_Controlling_Formals
(Tagged_Type
, Subp
);
1022 Override_Dispatching_Operation
(Tagged_Type
, Old_Subp
, Subp
);
1023 Set_Is_Dispatching_Operation
(Subp
);
1028 -- The operation may be a child unit, whose scope is the defining
1029 -- package, but which is not a primitive operation of the type.
1031 elsif Is_Child_Unit
(Subp
) then
1034 -- If the subprogram is not defined in a package spec, the only case
1035 -- where it can be a dispatching op is when it overrides an operation
1036 -- before the freezing point of the type.
1038 elsif ((not Is_Package_Or_Generic_Package
(Scope
(Subp
)))
1039 or else In_Package_Body
(Scope
(Subp
)))
1040 and then not Has_Dispatching_Parent
1042 if not Comes_From_Source
(Subp
)
1043 or else (Present
(Old_Subp
) and then not Is_Frozen
(Tagged_Type
))
1047 -- If the type is already frozen, the overriding is not allowed
1048 -- except when Old_Subp is not a dispatching operation (which can
1049 -- occur when Old_Subp was inherited by an untagged type). However,
1050 -- a body with no previous spec freezes the type *after* its
1051 -- declaration, and therefore is a legal overriding (unless the type
1052 -- has already been frozen). Only the first such body is legal.
1054 elsif Present
(Old_Subp
)
1055 and then Is_Dispatching_Operation
(Old_Subp
)
1057 if Comes_From_Source
(Subp
)
1059 (Nkind
(Unit_Declaration_Node
(Subp
)) = N_Subprogram_Body
1060 or else Nkind
(Unit_Declaration_Node
(Subp
)) in N_Body_Stub
)
1063 Subp_Body
: constant Node_Id
:= Unit_Declaration_Node
(Subp
);
1064 Decl_Item
: Node_Id
;
1067 -- ??? The checks here for whether the type has been frozen
1068 -- prior to the new body are not complete. It's not simple
1069 -- to check frozenness at this point since the body has
1070 -- already caused the type to be prematurely frozen in
1071 -- Analyze_Declarations, but we're forced to recheck this
1072 -- here because of the odd rule interpretation that allows
1073 -- the overriding if the type wasn't frozen prior to the
1074 -- body. The freezing action should probably be delayed
1075 -- until after the spec is seen, but that's a tricky
1076 -- change to the delicate freezing code.
1078 -- Look at each declaration following the type up until the
1079 -- new subprogram body. If any of the declarations is a body
1080 -- then the type has been frozen already so the overriding
1081 -- primitive is illegal.
1083 Decl_Item
:= Next
(Parent
(Tagged_Type
));
1084 while Present
(Decl_Item
)
1085 and then (Decl_Item
/= Subp_Body
)
1087 if Comes_From_Source
(Decl_Item
)
1088 and then (Nkind
(Decl_Item
) in N_Proper_Body
1089 or else Nkind
(Decl_Item
) in N_Body_Stub
)
1091 Error_Msg_N
("overriding of& is too late!", Subp
);
1093 ("\spec should appear immediately after the type!",
1101 -- If the subprogram doesn't follow in the list of
1102 -- declarations including the type then the type has
1103 -- definitely been frozen already and the body is illegal.
1105 if No
(Decl_Item
) then
1106 Error_Msg_N
("overriding of& is too late!", Subp
);
1108 ("\spec should appear immediately after the type!",
1111 elsif Is_Frozen
(Subp
) then
1113 -- The subprogram body declares a primitive operation.
1114 -- If the subprogram is already frozen, we must update
1115 -- its dispatching information explicitly here. The
1116 -- information is taken from the overridden subprogram.
1117 -- We must also generate a cross-reference entry because
1118 -- references to other primitives were already created
1119 -- when type was frozen.
1121 Body_Is_Last_Primitive
:= True;
1123 if Present
(DTC_Entity
(Old_Subp
)) then
1124 Set_DTC_Entity
(Subp
, DTC_Entity
(Old_Subp
));
1125 Set_DT_Position_Value
(Subp
, DT_Position
(Old_Subp
));
1127 if not Restriction_Active
(No_Dispatching_Calls
) then
1128 if Building_Static_DT
(Tagged_Type
) then
1130 -- If the static dispatch table has not been
1131 -- built then there is nothing else to do now;
1132 -- otherwise we notify that we cannot build the
1133 -- static dispatch table.
1135 if Has_Dispatch_Table
(Tagged_Type
) then
1137 ("overriding of& is too late for building "
1138 & " static dispatch tables!", Subp
);
1140 ("\spec should appear immediately after "
1141 & "the type!", Subp
);
1144 -- No code required to register primitives in VM
1147 elsif VM_Target
/= No_VM
then
1151 Insert_Actions_After
(Subp_Body
,
1152 Register_Primitive
(Sloc
(Subp_Body
),
1156 -- Indicate that this is an overriding operation,
1157 -- and replace the overridden entry in the list of
1158 -- primitive operations, which is used for xref
1159 -- generation subsequently.
1161 Generate_Reference
(Tagged_Type
, Subp
, 'P', False);
1162 Override_Dispatching_Operation
1163 (Tagged_Type
, Old_Subp
, Subp
);
1170 Error_Msg_N
("overriding of& is too late!", Subp
);
1172 ("\subprogram spec should appear immediately after the type!",
1176 -- If the type is not frozen yet and we are not in the overriding
1177 -- case it looks suspiciously like an attempt to define a primitive
1178 -- operation, which requires the declaration to be in a package spec
1179 -- (3.2.3(6)). Only report cases where the type and subprogram are
1180 -- in the same declaration list (by checking the enclosing parent
1181 -- declarations), to avoid spurious warnings on subprograms in
1182 -- instance bodies when the type is declared in the instance spec
1183 -- but hasn't been frozen by the instance body.
1185 elsif not Is_Frozen
(Tagged_Type
)
1186 and then In_Same_List
(Parent
(Tagged_Type
), Parent
(Parent
(Subp
)))
1189 ("??not dispatching (must be defined in a package spec)", Subp
);
1192 -- When the type is frozen, it is legitimate to define a new
1193 -- non-primitive operation.
1199 -- Now, we are sure that the scope is a package spec. If the subprogram
1200 -- is declared after the freezing point of the type that's an error
1202 elsif Is_Frozen
(Tagged_Type
) and then not Has_Dispatching_Parent
then
1203 Error_Msg_N
("this primitive operation is declared too late", Subp
);
1205 ("??no primitive operations for& after this line",
1206 Freeze_Node
(Tagged_Type
),
1211 Check_Controlling_Formals
(Tagged_Type
, Subp
);
1213 Ovr_Subp
:= Old_Subp
;
1215 -- [Ada 2012:AI-0125]: Search for inherited hidden primitive that may be
1216 -- overridden by Subp. This only applies to source subprograms, and
1217 -- their declaration must carry an explicit overriding indicator.
1220 and then Ada_Version
>= Ada_2012
1221 and then Comes_From_Source
(Subp
)
1223 Nkind
(Unit_Declaration_Node
(Subp
)) = N_Subprogram_Declaration
1225 Ovr_Subp
:= Find_Hidden_Overridden_Primitive
(Subp
);
1227 -- Verify that the proper overriding indicator has been supplied.
1229 if Present
(Ovr_Subp
)
1231 not Must_Override
(Specification
(Unit_Declaration_Node
(Subp
)))
1233 Error_Msg_NE
("missing overriding indicator for&", Subp
, Subp
);
1237 -- Now it should be a correct primitive operation, put it in the list
1239 if Present
(Ovr_Subp
) then
1241 -- If the type has interfaces we complete this check after we set
1242 -- attribute Is_Dispatching_Operation.
1244 Check_Subtype_Conformant
(Subp
, Ovr_Subp
);
1246 -- A primitive operation with the name of a primitive controlled
1247 -- operation does not override a non-visible overriding controlled
1248 -- operation, i.e. one declared in a private part when the full
1249 -- view of a type is controlled. Conversely, it will override a
1250 -- visible operation that may be declared in a partial view when
1251 -- the full view is controlled.
1253 if Nam_In
(Chars
(Subp
), Name_Initialize
, Name_Adjust
, Name_Finalize
)
1254 and then Is_Controlled
(Tagged_Type
)
1255 and then not Is_Visibly_Controlled
(Tagged_Type
)
1256 and then not Is_Inherited_Public_Operation
(Ovr_Subp
)
1258 Set_Overridden_Operation
(Subp
, Empty
);
1260 -- If the subprogram specification carries an overriding
1261 -- indicator, no need for the warning: it is either redundant,
1262 -- or else an error will be reported.
1264 if Nkind
(Parent
(Subp
)) = N_Procedure_Specification
1266 (Must_Override
(Parent
(Subp
))
1267 or else Must_Not_Override
(Parent
(Subp
)))
1271 -- Here we need the warning
1275 ("operation does not override inherited&??", Subp
, Subp
);
1279 Override_Dispatching_Operation
(Tagged_Type
, Ovr_Subp
, Subp
);
1281 -- Ada 2005 (AI-251): In case of late overriding of a primitive
1282 -- that covers abstract interface subprograms we must register it
1283 -- in all the secondary dispatch tables associated with abstract
1284 -- interfaces. We do this now only if not building static tables,
1285 -- nor when the expander is inactive (we avoid trying to register
1286 -- primitives in semantics-only mode, since the type may not have
1287 -- an associated dispatch table). Otherwise the patch code is
1288 -- emitted after those tables are built, to prevent access before
1289 -- elaboration in gigi.
1291 if Body_Is_Last_Primitive
and then Expander_Active
then
1293 Subp_Body
: constant Node_Id
:= Unit_Declaration_Node
(Subp
);
1298 Elmt
:= First_Elmt
(Primitive_Operations
(Tagged_Type
));
1299 while Present
(Elmt
) loop
1300 Prim
:= Node
(Elmt
);
1302 -- No code required to register primitives in VM targets
1304 if Present
(Alias
(Prim
))
1305 and then Present
(Interface_Alias
(Prim
))
1306 and then Alias
(Prim
) = Subp
1307 and then not Building_Static_DT
(Tagged_Type
)
1308 and then VM_Target
= No_VM
1310 Insert_Actions_After
(Subp_Body
,
1311 Register_Primitive
(Sloc
(Subp_Body
), Prim
=> Prim
));
1317 -- Redisplay the contents of the updated dispatch table
1319 if Debug_Flag_ZZ
then
1320 Write_Str
("Late overriding: ");
1321 Write_DT
(Tagged_Type
);
1327 -- If the tagged type is a concurrent type then we must be compiling
1328 -- with no code generation (we are either compiling a generic unit or
1329 -- compiling under -gnatc mode) because we have previously tested that
1330 -- no serious errors has been reported. In this case we do not add the
1331 -- primitive to the list of primitives of Tagged_Type but we leave the
1332 -- primitive decorated as a dispatching operation to be able to analyze
1333 -- and report errors associated with the Object.Operation notation.
1335 elsif Is_Concurrent_Type
(Tagged_Type
) then
1336 pragma Assert
(not Expander_Active
);
1338 -- Attach operation to list of primitives of the synchronized
1339 -- type itself, for ASIS use.
1341 Append_Elmt
(Subp
, Direct_Primitive_Operations
(Tagged_Type
));
1344 -- If no old subprogram, then we add this as a dispatching operation,
1345 -- but we avoid doing this if an error was posted, to prevent annoying
1348 elsif not Error_Posted
(Subp
) then
1349 Add_Dispatching_Operation
(Tagged_Type
, Subp
);
1352 Set_Is_Dispatching_Operation
(Subp
, True);
1354 -- Ada 2005 (AI-251): If the type implements interfaces we must check
1355 -- subtype conformance against all the interfaces covered by this
1358 if Present
(Ovr_Subp
)
1359 and then Has_Interfaces
(Tagged_Type
)
1362 Ifaces_List
: Elist_Id
;
1363 Iface_Elmt
: Elmt_Id
;
1364 Iface_Prim_Elmt
: Elmt_Id
;
1365 Iface_Prim
: Entity_Id
;
1366 Ret_Typ
: Entity_Id
;
1369 Collect_Interfaces
(Tagged_Type
, Ifaces_List
);
1371 Iface_Elmt
:= First_Elmt
(Ifaces_List
);
1372 while Present
(Iface_Elmt
) loop
1373 if not Is_Ancestor
(Node
(Iface_Elmt
), Tagged_Type
) then
1375 First_Elmt
(Primitive_Operations
(Node
(Iface_Elmt
)));
1376 while Present
(Iface_Prim_Elmt
) loop
1377 Iface_Prim
:= Node
(Iface_Prim_Elmt
);
1379 if Is_Interface_Conformant
1380 (Tagged_Type
, Iface_Prim
, Subp
)
1382 -- Handle procedures, functions whose return type
1383 -- matches, or functions not returning interfaces
1385 if Ekind
(Subp
) = E_Procedure
1386 or else Etype
(Iface_Prim
) = Etype
(Subp
)
1387 or else not Is_Interface
(Etype
(Iface_Prim
))
1389 Check_Subtype_Conformant
1391 Old_Id
=> Iface_Prim
,
1393 Skip_Controlling_Formals
=> True);
1395 -- Handle functions returning interfaces
1397 elsif Implements_Interface
1398 (Etype
(Subp
), Etype
(Iface_Prim
))
1400 -- Temporarily force both entities to return the
1401 -- same type. Required because Subtype_Conformant
1402 -- does not handle this case.
1404 Ret_Typ
:= Etype
(Iface_Prim
);
1405 Set_Etype
(Iface_Prim
, Etype
(Subp
));
1407 Check_Subtype_Conformant
1409 Old_Id
=> Iface_Prim
,
1411 Skip_Controlling_Formals
=> True);
1413 Set_Etype
(Iface_Prim
, Ret_Typ
);
1417 Next_Elmt
(Iface_Prim_Elmt
);
1421 Next_Elmt
(Iface_Elmt
);
1426 if not Body_Is_Last_Primitive
then
1427 Set_DT_Position_Value
(Subp
, No_Uint
);
1429 elsif Has_Controlled_Component
(Tagged_Type
)
1430 and then Nam_In
(Chars
(Subp
), Name_Initialize
,
1433 Name_Finalize_Address
)
1436 F_Node
: constant Node_Id
:= Freeze_Node
(Tagged_Type
);
1440 Old_Spec
: Entity_Id
;
1442 C_Names
: constant array (1 .. 4) of Name_Id
:=
1446 Name_Finalize_Address
);
1448 D_Names
: constant array (1 .. 4) of TSS_Name_Type
:=
1449 (TSS_Deep_Initialize
,
1452 TSS_Finalize_Address
);
1455 -- Remove previous controlled function which was constructed and
1456 -- analyzed when the type was frozen. This requires removing the
1457 -- body of the redefined primitive, as well as its specification
1458 -- if needed (there is no spec created for Deep_Initialize, see
1459 -- exp_ch3.adb). We must also dismantle the exception information
1460 -- that may have been generated for it when front end zero-cost
1461 -- tables are enabled.
1463 for J
in D_Names
'Range loop
1464 Old_P
:= TSS
(Tagged_Type
, D_Names
(J
));
1467 and then Chars
(Subp
) = C_Names
(J
)
1469 Old_Bod
:= Unit_Declaration_Node
(Old_P
);
1471 Set_Is_Eliminated
(Old_P
);
1472 Set_Scope
(Old_P
, Scope
(Current_Scope
));
1474 if Nkind
(Old_Bod
) = N_Subprogram_Body
1475 and then Present
(Corresponding_Spec
(Old_Bod
))
1477 Old_Spec
:= Corresponding_Spec
(Old_Bod
);
1478 Set_Has_Completion
(Old_Spec
, False);
1483 Build_Late_Proc
(Tagged_Type
, Chars
(Subp
));
1485 -- The new operation is added to the actions of the freeze node
1486 -- for the type, but this node has already been analyzed, so we
1487 -- must retrieve and analyze explicitly the new body.
1490 and then Present
(Actions
(F_Node
))
1492 Decl
:= Last
(Actions
(F_Node
));
1497 end Check_Dispatching_Operation
;
1499 ------------------------------------------
1500 -- Check_Operation_From_Incomplete_Type --
1501 ------------------------------------------
1503 procedure Check_Operation_From_Incomplete_Type
1507 Full
: constant Entity_Id
:= Full_View
(Typ
);
1508 Parent_Typ
: constant Entity_Id
:= Etype
(Full
);
1509 Old_Prim
: constant Elist_Id
:= Primitive_Operations
(Parent_Typ
);
1510 New_Prim
: constant Elist_Id
:= Primitive_Operations
(Full
);
1512 Prev
: Elmt_Id
:= No_Elmt
;
1514 function Derives_From
(Parent_Subp
: Entity_Id
) return Boolean;
1515 -- Check that Subp has profile of an operation derived from Parent_Subp.
1516 -- Subp must have a parameter or result type that is Typ or an access
1517 -- parameter or access result type that designates Typ.
1523 function Derives_From
(Parent_Subp
: Entity_Id
) return Boolean is
1527 if Chars
(Parent_Subp
) /= Chars
(Subp
) then
1531 -- Check that the type of controlling formals is derived from the
1532 -- parent subprogram's controlling formal type (or designated type
1533 -- if the formal type is an anonymous access type).
1535 F1
:= First_Formal
(Parent_Subp
);
1536 F2
:= First_Formal
(Subp
);
1537 while Present
(F1
) and then Present
(F2
) loop
1538 if Ekind
(Etype
(F1
)) = E_Anonymous_Access_Type
then
1539 if Ekind
(Etype
(F2
)) /= E_Anonymous_Access_Type
then
1541 elsif Designated_Type
(Etype
(F1
)) = Parent_Typ
1542 and then Designated_Type
(Etype
(F2
)) /= Full
1547 elsif Ekind
(Etype
(F2
)) = E_Anonymous_Access_Type
then
1550 elsif Etype
(F1
) = Parent_Typ
and then Etype
(F2
) /= Full
then
1558 -- Check that a controlling result type is derived from the parent
1559 -- subprogram's result type (or designated type if the result type
1560 -- is an anonymous access type).
1562 if Ekind
(Parent_Subp
) = E_Function
then
1563 if Ekind
(Subp
) /= E_Function
then
1566 elsif Ekind
(Etype
(Parent_Subp
)) = E_Anonymous_Access_Type
then
1567 if Ekind
(Etype
(Subp
)) /= E_Anonymous_Access_Type
then
1570 elsif Designated_Type
(Etype
(Parent_Subp
)) = Parent_Typ
1571 and then Designated_Type
(Etype
(Subp
)) /= Full
1576 elsif Ekind
(Etype
(Subp
)) = E_Anonymous_Access_Type
then
1579 elsif Etype
(Parent_Subp
) = Parent_Typ
1580 and then Etype
(Subp
) /= Full
1585 elsif Ekind
(Subp
) = E_Function
then
1589 return No
(F1
) and then No
(F2
);
1592 -- Start of processing for Check_Operation_From_Incomplete_Type
1595 -- The operation may override an inherited one, or may be a new one
1596 -- altogether. The inherited operation will have been hidden by the
1597 -- current one at the point of the type derivation, so it does not
1598 -- appear in the list of primitive operations of the type. We have to
1599 -- find the proper place of insertion in the list of primitive opera-
1600 -- tions by iterating over the list for the parent type.
1602 Op1
:= First_Elmt
(Old_Prim
);
1603 Op2
:= First_Elmt
(New_Prim
);
1604 while Present
(Op1
) and then Present
(Op2
) loop
1605 if Derives_From
(Node
(Op1
)) then
1608 -- Avoid adding it to the list of primitives if already there
1610 if Node
(Op2
) /= Subp
then
1611 Prepend_Elmt
(Subp
, New_Prim
);
1615 Insert_Elmt_After
(Subp
, Prev
);
1626 -- Operation is a new primitive
1628 Append_Elmt
(Subp
, New_Prim
);
1629 end Check_Operation_From_Incomplete_Type
;
1631 ---------------------------------------
1632 -- Check_Operation_From_Private_View --
1633 ---------------------------------------
1635 procedure Check_Operation_From_Private_View
(Subp
, Old_Subp
: Entity_Id
) is
1636 Tagged_Type
: Entity_Id
;
1639 if Is_Dispatching_Operation
(Alias
(Subp
)) then
1640 Set_Scope
(Subp
, Current_Scope
);
1641 Tagged_Type
:= Find_Dispatching_Type
(Subp
);
1643 -- Add Old_Subp to primitive operations if not already present
1645 if Present
(Tagged_Type
) and then Is_Tagged_Type
(Tagged_Type
) then
1646 Append_Unique_Elmt
(Old_Subp
, Primitive_Operations
(Tagged_Type
));
1648 -- If Old_Subp isn't already marked as dispatching then this is
1649 -- the case of an operation of an untagged private type fulfilled
1650 -- by a tagged type that overrides an inherited dispatching
1651 -- operation, so we set the necessary dispatching attributes here.
1653 if not Is_Dispatching_Operation
(Old_Subp
) then
1655 -- If the untagged type has no discriminants, and the full
1656 -- view is constrained, there will be a spurious mismatch of
1657 -- subtypes on the controlling arguments, because the tagged
1658 -- type is the internal base type introduced in the derivation.
1659 -- Use the original type to verify conformance, rather than the
1662 if not Comes_From_Source
(Tagged_Type
)
1663 and then Has_Discriminants
(Tagged_Type
)
1669 Formal
:= First_Formal
(Old_Subp
);
1670 while Present
(Formal
) loop
1671 if Tagged_Type
= Base_Type
(Etype
(Formal
)) then
1672 Tagged_Type
:= Etype
(Formal
);
1675 Next_Formal
(Formal
);
1679 if Tagged_Type
= Base_Type
(Etype
(Old_Subp
)) then
1680 Tagged_Type
:= Etype
(Old_Subp
);
1684 Check_Controlling_Formals
(Tagged_Type
, Old_Subp
);
1685 Set_Is_Dispatching_Operation
(Old_Subp
, True);
1686 Set_DT_Position_Value
(Old_Subp
, No_Uint
);
1689 -- If the old subprogram is an explicit renaming of some other
1690 -- entity, it is not overridden by the inherited subprogram.
1691 -- Otherwise, update its alias and other attributes.
1693 if Present
(Alias
(Old_Subp
))
1694 and then Nkind
(Unit_Declaration_Node
(Old_Subp
)) /=
1695 N_Subprogram_Renaming_Declaration
1697 Set_Alias
(Old_Subp
, Alias
(Subp
));
1699 -- The derived subprogram should inherit the abstractness of
1700 -- the parent subprogram (except in the case of a function
1701 -- returning the type). This sets the abstractness properly
1702 -- for cases where a private extension may have inherited an
1703 -- abstract operation, but the full type is derived from a
1704 -- descendant type and inherits a nonabstract version.
1706 if Etype
(Subp
) /= Tagged_Type
then
1707 Set_Is_Abstract_Subprogram
1708 (Old_Subp
, Is_Abstract_Subprogram
(Alias
(Subp
)));
1713 end Check_Operation_From_Private_View
;
1715 --------------------------
1716 -- Find_Controlling_Arg --
1717 --------------------------
1719 function Find_Controlling_Arg
(N
: Node_Id
) return Node_Id
is
1720 Orig_Node
: constant Node_Id
:= Original_Node
(N
);
1724 if Nkind
(Orig_Node
) = N_Qualified_Expression
then
1725 return Find_Controlling_Arg
(Expression
(Orig_Node
));
1728 -- Dispatching on result case. If expansion is disabled, the node still
1729 -- has the structure of a function call. However, if the function name
1730 -- is an operator and the call was given in infix form, the original
1731 -- node has no controlling result and we must examine the current node.
1733 if Nkind
(N
) = N_Function_Call
1734 and then Present
(Controlling_Argument
(N
))
1735 and then Has_Controlling_Result
(Entity
(Name
(N
)))
1737 return Controlling_Argument
(N
);
1739 -- If expansion is enabled, the call may have been transformed into
1740 -- an indirect call, and we need to recover the original node.
1742 elsif Nkind
(Orig_Node
) = N_Function_Call
1743 and then Present
(Controlling_Argument
(Orig_Node
))
1744 and then Has_Controlling_Result
(Entity
(Name
(Orig_Node
)))
1746 return Controlling_Argument
(Orig_Node
);
1748 -- Type conversions are dynamically tagged if the target type, or its
1749 -- designated type, are classwide. An interface conversion expands into
1750 -- a dereference, so test must be performed on the original node.
1752 elsif Nkind
(Orig_Node
) = N_Type_Conversion
1753 and then Nkind
(N
) = N_Explicit_Dereference
1754 and then Is_Controlling_Actual
(N
)
1757 Target_Type
: constant Entity_Id
:=
1758 Entity
(Subtype_Mark
(Orig_Node
));
1761 if Is_Class_Wide_Type
(Target_Type
) then
1764 elsif Is_Access_Type
(Target_Type
)
1765 and then Is_Class_Wide_Type
(Designated_Type
(Target_Type
))
1776 elsif Is_Controlling_Actual
(N
)
1778 (Nkind
(Parent
(N
)) = N_Qualified_Expression
1779 and then Is_Controlling_Actual
(Parent
(N
)))
1783 if Is_Access_Type
(Typ
) then
1785 -- In the case of an Access attribute, use the type of the prefix,
1786 -- since in the case of an actual for an access parameter, the
1787 -- attribute's type may be of a specific designated type, even
1788 -- though the prefix type is class-wide.
1790 if Nkind
(N
) = N_Attribute_Reference
then
1791 Typ
:= Etype
(Prefix
(N
));
1793 -- An allocator is dispatching if the type of qualified expression
1794 -- is class_wide, in which case this is the controlling type.
1796 elsif Nkind
(Orig_Node
) = N_Allocator
1797 and then Nkind
(Expression
(Orig_Node
)) = N_Qualified_Expression
1799 Typ
:= Etype
(Expression
(Orig_Node
));
1801 Typ
:= Designated_Type
(Typ
);
1805 if Is_Class_Wide_Type
(Typ
)
1807 (Nkind
(Parent
(N
)) = N_Qualified_Expression
1808 and then Is_Access_Type
(Etype
(N
))
1809 and then Is_Class_Wide_Type
(Designated_Type
(Etype
(N
))))
1816 end Find_Controlling_Arg
;
1818 ---------------------------
1819 -- Find_Dispatching_Type --
1820 ---------------------------
1822 function Find_Dispatching_Type
(Subp
: Entity_Id
) return Entity_Id
is
1823 A_Formal
: Entity_Id
;
1825 Ctrl_Type
: Entity_Id
;
1828 if Ekind_In
(Subp
, E_Function
, E_Procedure
)
1829 and then Present
(DTC_Entity
(Subp
))
1831 return Scope
(DTC_Entity
(Subp
));
1833 -- For subprograms internally generated by derivations of tagged types
1834 -- use the alias subprogram as a reference to locate the dispatching
1837 elsif not Comes_From_Source
(Subp
)
1838 and then Present
(Alias
(Subp
))
1839 and then Is_Dispatching_Operation
(Alias
(Subp
))
1841 if Ekind
(Alias
(Subp
)) = E_Function
1842 and then Has_Controlling_Result
(Alias
(Subp
))
1844 return Check_Controlling_Type
(Etype
(Subp
), Subp
);
1847 Formal
:= First_Formal
(Subp
);
1848 A_Formal
:= First_Formal
(Alias
(Subp
));
1849 while Present
(A_Formal
) loop
1850 if Is_Controlling_Formal
(A_Formal
) then
1851 return Check_Controlling_Type
(Etype
(Formal
), Subp
);
1854 Next_Formal
(Formal
);
1855 Next_Formal
(A_Formal
);
1858 pragma Assert
(False);
1865 Formal
:= First_Formal
(Subp
);
1866 while Present
(Formal
) loop
1867 Ctrl_Type
:= Check_Controlling_Type
(Etype
(Formal
), Subp
);
1869 if Present
(Ctrl_Type
) then
1873 Next_Formal
(Formal
);
1876 -- The subprogram may also be dispatching on result
1878 if Present
(Etype
(Subp
)) then
1879 return Check_Controlling_Type
(Etype
(Subp
), Subp
);
1883 pragma Assert
(not Is_Dispatching_Operation
(Subp
));
1885 end Find_Dispatching_Type
;
1887 --------------------------------------
1888 -- Find_Hidden_Overridden_Primitive --
1889 --------------------------------------
1891 function Find_Hidden_Overridden_Primitive
(S
: Entity_Id
) return Entity_Id
1893 Tag_Typ
: constant Entity_Id
:= Find_Dispatching_Type
(S
);
1895 Orig_Prim
: Entity_Id
;
1897 Vis_List
: Elist_Id
;
1900 -- This Ada 2012 rule applies only for type extensions or private
1901 -- extensions, where the parent type is not in a parent unit, and
1902 -- where an operation is never declared but still inherited.
1905 or else not Is_Record_Type
(Tag_Typ
)
1906 or else Etype
(Tag_Typ
) = Tag_Typ
1907 or else In_Open_Scopes
(Scope
(Etype
(Tag_Typ
)))
1912 -- Collect the list of visible ancestor of the tagged type
1914 Vis_List
:= Visible_Ancestors
(Tag_Typ
);
1916 Elmt
:= First_Elmt
(Primitive_Operations
(Tag_Typ
));
1917 while Present
(Elmt
) loop
1918 Prim
:= Node
(Elmt
);
1920 -- Find an inherited hidden dispatching primitive with the name of S
1921 -- and a type-conformant profile.
1923 if Present
(Alias
(Prim
))
1924 and then Is_Hidden
(Alias
(Prim
))
1925 and then Find_Dispatching_Type
(Alias
(Prim
)) /= Tag_Typ
1926 and then Primitive_Names_Match
(S
, Prim
)
1927 and then Type_Conformant
(S
, Prim
)
1930 Vis_Ancestor
: Elmt_Id
;
1934 -- The original corresponding operation of Prim must be an
1935 -- operation of a visible ancestor of the dispatching type S,
1936 -- and the original corresponding operation of S2 must be
1939 Orig_Prim
:= Original_Corresponding_Operation
(Prim
);
1941 if Orig_Prim
/= Prim
1942 and then Is_Immediately_Visible
(Orig_Prim
)
1944 Vis_Ancestor
:= First_Elmt
(Vis_List
);
1945 while Present
(Vis_Ancestor
) loop
1947 First_Elmt
(Primitive_Operations
(Node
(Vis_Ancestor
)));
1948 while Present
(Elmt
) loop
1949 if Node
(Elmt
) = Orig_Prim
then
1950 Set_Overridden_Operation
(S
, Prim
);
1951 Set_Alias
(Prim
, Orig_Prim
);
1958 Next_Elmt
(Vis_Ancestor
);
1968 end Find_Hidden_Overridden_Primitive
;
1970 ---------------------------------------
1971 -- Find_Primitive_Covering_Interface --
1972 ---------------------------------------
1974 function Find_Primitive_Covering_Interface
1975 (Tagged_Type
: Entity_Id
;
1976 Iface_Prim
: Entity_Id
) return Entity_Id
1982 pragma Assert
(Is_Interface
(Find_Dispatching_Type
(Iface_Prim
))
1983 or else (Present
(Alias
(Iface_Prim
))
1986 (Find_Dispatching_Type
(Ultimate_Alias
(Iface_Prim
)))));
1988 -- Search in the homonym chain. Done to speed up locating visible
1989 -- entities and required to catch primitives associated with the partial
1990 -- view of private types when processing the corresponding full view.
1992 E
:= Current_Entity
(Iface_Prim
);
1993 while Present
(E
) loop
1994 if Is_Subprogram
(E
)
1995 and then Is_Dispatching_Operation
(E
)
1996 and then Is_Interface_Conformant
(Tagged_Type
, Iface_Prim
, E
)
2004 -- Search in the list of primitives of the type. Required to locate
2005 -- the covering primitive if the covering primitive is not visible
2006 -- (for example, non-visible inherited primitive of private type).
2008 El
:= First_Elmt
(Primitive_Operations
(Tagged_Type
));
2009 while Present
(El
) loop
2012 -- Keep separate the management of internal entities that link
2013 -- primitives with interface primitives from tagged type primitives.
2015 if No
(Interface_Alias
(E
)) then
2016 if Present
(Alias
(E
)) then
2018 -- This interface primitive has not been covered yet
2020 if Alias
(E
) = Iface_Prim
then
2023 -- The covering primitive was inherited
2025 elsif Overridden_Operation
(Ultimate_Alias
(E
))
2032 -- Check if E covers the interface primitive (includes case in
2033 -- which E is an inherited private primitive).
2035 if Is_Interface_Conformant
(Tagged_Type
, Iface_Prim
, E
) then
2039 -- Use the internal entity that links the interface primitive with
2040 -- the covering primitive to locate the entity.
2042 elsif Interface_Alias
(E
) = Iface_Prim
then
2052 end Find_Primitive_Covering_Interface
;
2054 ---------------------------
2055 -- Inherited_Subprograms --
2056 ---------------------------
2058 function Inherited_Subprograms
2060 No_Interfaces
: Boolean := False;
2061 Interfaces_Only
: Boolean := False) return Subprogram_List
2063 Result
: Subprogram_List
(1 .. 6000);
2064 -- 6000 here is intended to be infinity. We could use an expandable
2065 -- table, but it would be awfully heavy, and there is no way that we
2066 -- could reasonably exceed this value.
2069 -- Number of entries in Result
2071 Parent_Op
: Entity_Id
;
2072 -- Traverses the Overridden_Operation chain
2074 procedure Store_IS
(E
: Entity_Id
);
2075 -- Stores E in Result if not already stored
2081 procedure Store_IS
(E
: Entity_Id
) is
2083 for J
in 1 .. N
loop
2084 if E
= Result
(J
) then
2093 -- Start of processing for Inherited_Subprograms
2096 pragma Assert
(not (No_Interfaces
and Interfaces_Only
));
2098 if Present
(S
) and then Is_Dispatching_Operation
(S
) then
2100 -- Deal with direct inheritance
2102 if not Interfaces_Only
then
2105 Parent_Op
:= Overridden_Operation
(Parent_Op
);
2106 exit when No
(Parent_Op
)
2110 Is_Interface
(Find_Dispatching_Type
(Parent_Op
)));
2112 if Is_Subprogram_Or_Generic_Subprogram
(Parent_Op
) then
2113 Store_IS
(Parent_Op
);
2118 -- Now deal with interfaces
2120 if not No_Interfaces
then
2122 Tag_Typ
: Entity_Id
;
2127 Tag_Typ
:= Find_Dispatching_Type
(S
);
2129 if Is_Concurrent_Type
(Tag_Typ
) then
2130 Tag_Typ
:= Corresponding_Record_Type
(Tag_Typ
);
2133 -- Search primitive operations of dispatching type
2135 if Present
(Tag_Typ
)
2136 and then Present
(Primitive_Operations
(Tag_Typ
))
2138 Elmt
:= First_Elmt
(Primitive_Operations
(Tag_Typ
));
2139 while Present
(Elmt
) loop
2140 Prim
:= Node
(Elmt
);
2142 -- The following test eliminates some odd cases in which
2143 -- Ekind (Prim) is Void, to be investigated further ???
2145 if not Is_Subprogram_Or_Generic_Subprogram
(Prim
) then
2148 -- For [generic] subprogram, look at interface alias
2150 elsif Present
(Interface_Alias
(Prim
))
2151 and then Alias
(Prim
) = S
2153 -- We have found a primitive covered by S
2155 Store_IS
(Interface_Alias
(Prim
));
2165 return Result
(1 .. N
);
2166 end Inherited_Subprograms
;
2168 ---------------------------
2169 -- Is_Dynamically_Tagged --
2170 ---------------------------
2172 function Is_Dynamically_Tagged
(N
: Node_Id
) return Boolean is
2174 if Nkind
(N
) = N_Error
then
2177 elsif Present
(Find_Controlling_Arg
(N
)) then
2180 -- Special cases: entities, and calls that dispatch on result
2182 elsif Is_Entity_Name
(N
) then
2183 return Is_Class_Wide_Type
(Etype
(N
));
2185 elsif Nkind
(N
) = N_Function_Call
2186 and then Is_Class_Wide_Type
(Etype
(N
))
2190 -- Otherwise check whether call has controlling argument
2195 end Is_Dynamically_Tagged
;
2197 ---------------------------------
2198 -- Is_Null_Interface_Primitive --
2199 ---------------------------------
2201 function Is_Null_Interface_Primitive
(E
: Entity_Id
) return Boolean is
2203 return Comes_From_Source
(E
)
2204 and then Is_Dispatching_Operation
(E
)
2205 and then Ekind
(E
) = E_Procedure
2206 and then Null_Present
(Parent
(E
))
2207 and then Is_Interface
(Find_Dispatching_Type
(E
));
2208 end Is_Null_Interface_Primitive
;
2210 -----------------------------------
2211 -- Is_Inherited_Public_Operation --
2212 -----------------------------------
2214 function Is_Inherited_Public_Operation
(Op
: Entity_Id
) return Boolean is
2215 Prim
: constant Entity_Id
:= Alias
(Op
);
2216 Scop
: constant Entity_Id
:= Scope
(Prim
);
2217 Pack_Decl
: Node_Id
;
2220 if Comes_From_Source
(Prim
) and then Ekind
(Scop
) = E_Package
then
2221 Pack_Decl
:= Unit_Declaration_Node
(Scop
);
2222 return Nkind
(Pack_Decl
) = N_Package_Declaration
2223 and then List_Containing
(Unit_Declaration_Node
(Prim
)) =
2224 Visible_Declarations
(Specification
(Pack_Decl
));
2229 end Is_Inherited_Public_Operation
;
2231 --------------------------
2232 -- Is_Tag_Indeterminate --
2233 --------------------------
2235 function Is_Tag_Indeterminate
(N
: Node_Id
) return Boolean is
2238 Orig_Node
: constant Node_Id
:= Original_Node
(N
);
2241 if Nkind
(Orig_Node
) = N_Function_Call
2242 and then Is_Entity_Name
(Name
(Orig_Node
))
2244 Nam
:= Entity
(Name
(Orig_Node
));
2246 if not Has_Controlling_Result
(Nam
) then
2249 -- The function may have a controlling result, but if the return type
2250 -- is not visibly tagged, then this is not tag-indeterminate.
2252 elsif Is_Access_Type
(Etype
(Nam
))
2253 and then not Is_Tagged_Type
(Designated_Type
(Etype
(Nam
)))
2257 -- An explicit dereference means that the call has already been
2258 -- expanded and there is no tag to propagate.
2260 elsif Nkind
(N
) = N_Explicit_Dereference
then
2263 -- If there are no actuals, the call is tag-indeterminate
2265 elsif No
(Parameter_Associations
(Orig_Node
)) then
2269 Actual
:= First_Actual
(Orig_Node
);
2270 while Present
(Actual
) loop
2271 if Is_Controlling_Actual
(Actual
)
2272 and then not Is_Tag_Indeterminate
(Actual
)
2274 -- One operand is dispatching
2279 Next_Actual
(Actual
);
2285 elsif Nkind
(Orig_Node
) = N_Qualified_Expression
then
2286 return Is_Tag_Indeterminate
(Expression
(Orig_Node
));
2288 -- Case of a call to the Input attribute (possibly rewritten), which is
2289 -- always tag-indeterminate except when its prefix is a Class attribute.
2291 elsif Nkind
(Orig_Node
) = N_Attribute_Reference
2293 Get_Attribute_Id
(Attribute_Name
(Orig_Node
)) = Attribute_Input
2294 and then Nkind
(Prefix
(Orig_Node
)) /= N_Attribute_Reference
2298 -- In Ada 2005, a function that returns an anonymous access type can be
2299 -- dispatching, and the dereference of a call to such a function can
2300 -- also be tag-indeterminate if the call itself is.
2302 elsif Nkind
(Orig_Node
) = N_Explicit_Dereference
2303 and then Ada_Version
>= Ada_2005
2305 return Is_Tag_Indeterminate
(Prefix
(Orig_Node
));
2310 end Is_Tag_Indeterminate
;
2312 ------------------------------------
2313 -- Override_Dispatching_Operation --
2314 ------------------------------------
2316 procedure Override_Dispatching_Operation
2317 (Tagged_Type
: Entity_Id
;
2318 Prev_Op
: Entity_Id
;
2320 Is_Wrapper
: Boolean := False)
2326 -- Diagnose failure to match No_Return in parent (Ada-2005, AI-414, but
2327 -- we do it unconditionally in Ada 95 now, since this is our pragma).
2329 if No_Return
(Prev_Op
) and then not No_Return
(New_Op
) then
2330 Error_Msg_N
("procedure & must have No_Return pragma", New_Op
);
2331 Error_Msg_N
("\since overridden procedure has No_Return", New_Op
);
2334 -- If there is no previous operation to override, the type declaration
2335 -- was malformed, and an error must have been emitted already.
2337 Elmt
:= First_Elmt
(Primitive_Operations
(Tagged_Type
));
2338 while Present
(Elmt
) and then Node
(Elmt
) /= Prev_Op
loop
2346 -- The location of entities that come from source in the list of
2347 -- primitives of the tagged type must follow their order of occurrence
2348 -- in the sources to fulfill the C++ ABI. If the overridden entity is a
2349 -- primitive of an interface that is not implemented by the parents of
2350 -- this tagged type (that is, it is an alias of an interface primitive
2351 -- generated by Derive_Interface_Progenitors), then we must append the
2352 -- new entity at the end of the list of primitives.
2354 if Present
(Alias
(Prev_Op
))
2355 and then Etype
(Tagged_Type
) /= Tagged_Type
2356 and then Is_Interface
(Find_Dispatching_Type
(Alias
(Prev_Op
)))
2357 and then not Is_Ancestor
(Find_Dispatching_Type
(Alias
(Prev_Op
)),
2358 Tagged_Type
, Use_Full_View
=> True)
2359 and then not Implements_Interface
2360 (Etype
(Tagged_Type
),
2361 Find_Dispatching_Type
(Alias
(Prev_Op
)))
2363 Remove_Elmt
(Primitive_Operations
(Tagged_Type
), Elmt
);
2364 Append_Elmt
(New_Op
, Primitive_Operations
(Tagged_Type
));
2366 -- The new primitive replaces the overridden entity. Required to ensure
2367 -- that overriding primitive is assigned the same dispatch table slot.
2370 Replace_Elmt
(Elmt
, New_Op
);
2373 if Ada_Version
>= Ada_2005
and then Has_Interfaces
(Tagged_Type
) then
2375 -- Ada 2005 (AI-251): Update the attribute alias of all the aliased
2376 -- entities of the overridden primitive to reference New_Op, and
2377 -- also propagate the proper value of Is_Abstract_Subprogram. Verify
2378 -- that the new operation is subtype conformant with the interface
2379 -- operations that it implements (for operations inherited from the
2380 -- parent itself, this check is made when building the derived type).
2382 -- Note: This code is executed with internally generated wrappers of
2383 -- functions with controlling result and late overridings.
2385 Elmt
:= First_Elmt
(Primitive_Operations
(Tagged_Type
));
2386 while Present
(Elmt
) loop
2387 Prim
:= Node
(Elmt
);
2389 if Prim
= New_Op
then
2392 -- Note: The check on Is_Subprogram protects the frontend against
2393 -- reading attributes in entities that are not yet fully decorated
2395 elsif Is_Subprogram
(Prim
)
2396 and then Present
(Interface_Alias
(Prim
))
2397 and then Alias
(Prim
) = Prev_Op
2399 Set_Alias
(Prim
, New_Op
);
2401 -- No further decoration needed yet for internally generated
2402 -- wrappers of controlling functions since (at this stage)
2403 -- they are not yet decorated.
2405 if not Is_Wrapper
then
2406 Check_Subtype_Conformant
(New_Op
, Prim
);
2408 Set_Is_Abstract_Subprogram
(Prim
,
2409 Is_Abstract_Subprogram
(New_Op
));
2411 -- Ensure that this entity will be expanded to fill the
2412 -- corresponding entry in its dispatch table.
2414 if not Is_Abstract_Subprogram
(Prim
) then
2415 Set_Has_Delayed_Freeze
(Prim
);
2424 if (not Is_Package_Or_Generic_Package
(Current_Scope
))
2425 or else not In_Private_Part
(Current_Scope
)
2427 -- Not a private primitive
2431 else pragma Assert
(Is_Inherited_Operation
(Prev_Op
));
2433 -- Make the overriding operation into an alias of the implicit one.
2434 -- In this fashion a call from outside ends up calling the new body
2435 -- even if non-dispatching, and a call from inside calls the over-
2436 -- riding operation because it hides the implicit one. To indicate
2437 -- that the body of Prev_Op is never called, set its dispatch table
2438 -- entity to Empty. If the overridden operation has a dispatching
2439 -- result, so does the overriding one.
2441 Set_Alias
(Prev_Op
, New_Op
);
2442 Set_DTC_Entity
(Prev_Op
, Empty
);
2443 Set_Has_Controlling_Result
(New_Op
, Has_Controlling_Result
(Prev_Op
));
2446 end Override_Dispatching_Operation
;
2452 procedure Propagate_Tag
(Control
: Node_Id
; Actual
: Node_Id
) is
2453 Call_Node
: Node_Id
;
2457 if Nkind
(Actual
) = N_Function_Call
then
2458 Call_Node
:= Actual
;
2460 elsif Nkind
(Actual
) = N_Identifier
2461 and then Nkind
(Original_Node
(Actual
)) = N_Function_Call
2463 -- Call rewritten as object declaration when stack-checking is
2464 -- enabled. Propagate tag to expression in declaration, which is
2467 Call_Node
:= Expression
(Parent
(Entity
(Actual
)));
2469 -- Ada 2005: If this is a dereference of a call to a function with a
2470 -- dispatching access-result, the tag is propagated when the dereference
2471 -- itself is expanded (see exp_ch6.adb) and there is nothing else to do.
2473 elsif Nkind
(Actual
) = N_Explicit_Dereference
2474 and then Nkind
(Original_Node
(Prefix
(Actual
))) = N_Function_Call
2478 -- When expansion is suppressed, an unexpanded call to 'Input can occur,
2479 -- and in that case we can simply return.
2481 elsif Nkind
(Actual
) = N_Attribute_Reference
then
2482 pragma Assert
(Attribute_Name
(Actual
) = Name_Input
);
2486 -- Only other possibilities are parenthesized or qualified expression,
2487 -- or an expander-generated unchecked conversion of a function call to
2488 -- a stream Input attribute.
2491 Call_Node
:= Expression
(Actual
);
2494 -- No action needed if the call has been already expanded
2496 if Is_Expanded_Dispatching_Call
(Call_Node
) then
2500 -- Do not set the Controlling_Argument if already set. This happens in
2501 -- the special case of _Input (see Exp_Attr, case Input).
2503 if No
(Controlling_Argument
(Call_Node
)) then
2504 Set_Controlling_Argument
(Call_Node
, Control
);
2507 Arg
:= First_Actual
(Call_Node
);
2508 while Present
(Arg
) loop
2509 if Is_Tag_Indeterminate
(Arg
) then
2510 Propagate_Tag
(Control
, Arg
);
2516 -- Expansion of dispatching calls is suppressed when VM_Target, because
2517 -- the VM back-ends directly handle the generation of dispatching calls
2518 -- and would have to undo any expansion to an indirect call.
2520 if Tagged_Type_Expansion
then
2522 Call_Typ
: constant Entity_Id
:= Etype
(Call_Node
);
2525 Expand_Dispatching_Call
(Call_Node
);
2527 -- If the controlling argument is an interface type and the type
2528 -- of Call_Node differs then we must add an implicit conversion to
2529 -- force displacement of the pointer to the object to reference
2530 -- the secondary dispatch table of the interface.
2532 if Is_Interface
(Etype
(Control
))
2533 and then Etype
(Control
) /= Call_Typ
2535 -- Cannot use Convert_To because the previous call to
2536 -- Expand_Dispatching_Call leaves decorated the Call_Node
2537 -- with the type of Control.
2540 Make_Type_Conversion
(Sloc
(Call_Node
),
2542 New_Occurrence_Of
(Etype
(Control
), Sloc
(Call_Node
)),
2543 Expression
=> Relocate_Node
(Call_Node
)));
2544 Set_Etype
(Call_Node
, Etype
(Control
));
2545 Set_Analyzed
(Call_Node
);
2547 Expand_Interface_Conversion
(Call_Node
);
2551 -- Expansion of a dispatching call results in an indirect call, which in
2552 -- turn causes current values to be killed (see Resolve_Call), so on VM
2553 -- targets we do the call here to ensure consistent warnings between VM
2554 -- and non-VM targets.
2557 Kill_Current_Values
;