1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2013, 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 -------------------------------
90 -- Add_Dispatching_Operation --
91 -------------------------------
93 procedure Add_Dispatching_Operation
94 (Tagged_Type
: Entity_Id
;
97 List
: constant Elist_Id
:= Primitive_Operations
(Tagged_Type
);
100 -- The dispatching operation may already be on the list, if it is the
101 -- wrapper for an inherited function of a null extension (see Exp_Ch3
102 -- for the construction of function wrappers). The list of primitive
103 -- operations must not contain duplicates.
105 Append_Unique_Elmt
(New_Op
, List
);
106 end Add_Dispatching_Operation
;
108 ---------------------------
109 -- Covers_Some_Interface --
110 ---------------------------
112 function Covers_Some_Interface
(Prim
: Entity_Id
) return Boolean is
113 Tagged_Type
: constant Entity_Id
:= Find_Dispatching_Type
(Prim
);
118 pragma Assert
(Is_Dispatching_Operation
(Prim
));
120 -- Although this is a dispatching primitive we must check if its
121 -- dispatching type is available because it may be the primitive
122 -- of a private type not defined as tagged in its partial view.
124 if Present
(Tagged_Type
) and then Has_Interfaces
(Tagged_Type
) then
126 -- If the tagged type is frozen then the internal entities associated
127 -- with interfaces are available in the list of primitives of the
128 -- tagged type and can be used to speed up this search.
130 if Is_Frozen
(Tagged_Type
) then
131 Elmt
:= First_Elmt
(Primitive_Operations
(Tagged_Type
));
132 while Present
(Elmt
) loop
135 if Present
(Interface_Alias
(E
))
136 and then Alias
(E
) = Prim
144 -- Otherwise we must collect all the interface primitives and check
145 -- if the Prim will override some interface primitive.
149 Ifaces_List
: Elist_Id
;
150 Iface_Elmt
: Elmt_Id
;
152 Iface_Prim
: Entity_Id
;
155 Collect_Interfaces
(Tagged_Type
, Ifaces_List
);
156 Iface_Elmt
:= First_Elmt
(Ifaces_List
);
157 while Present
(Iface_Elmt
) loop
158 Iface
:= Node
(Iface_Elmt
);
160 Elmt
:= First_Elmt
(Primitive_Operations
(Iface
));
161 while Present
(Elmt
) loop
162 Iface_Prim
:= Node
(Elmt
);
164 if Chars
(Iface
) = Chars
(Prim
)
165 and then Is_Interface_Conformant
166 (Tagged_Type
, Iface_Prim
, Prim
)
174 Next_Elmt
(Iface_Elmt
);
181 end Covers_Some_Interface
;
183 -------------------------------
184 -- Check_Controlling_Formals --
185 -------------------------------
187 procedure Check_Controlling_Formals
192 Ctrl_Type
: Entity_Id
;
195 Formal
:= First_Formal
(Subp
);
196 while Present
(Formal
) loop
197 Ctrl_Type
:= Check_Controlling_Type
(Etype
(Formal
), Subp
);
199 if Present
(Ctrl_Type
) then
201 -- When controlling type is concurrent and declared within a
202 -- generic or inside an instance use corresponding record type.
204 if Is_Concurrent_Type
(Ctrl_Type
)
205 and then Present
(Corresponding_Record_Type
(Ctrl_Type
))
207 Ctrl_Type
:= Corresponding_Record_Type
(Ctrl_Type
);
210 if Ctrl_Type
= Typ
then
211 Set_Is_Controlling_Formal
(Formal
);
213 -- Ada 2005 (AI-231): Anonymous access types that are used in
214 -- controlling parameters exclude null because it is necessary
215 -- to read the tag to dispatch, and null has no tag.
217 if Ekind
(Etype
(Formal
)) = E_Anonymous_Access_Type
then
218 Set_Can_Never_Be_Null
(Etype
(Formal
));
219 Set_Is_Known_Non_Null
(Etype
(Formal
));
222 -- Check that the parameter's nominal subtype statically
223 -- matches the first subtype.
225 if Ekind
(Etype
(Formal
)) = E_Anonymous_Access_Type
then
226 if not Subtypes_Statically_Match
227 (Typ
, Designated_Type
(Etype
(Formal
)))
230 ("parameter subtype does not match controlling type",
234 elsif not Subtypes_Statically_Match
(Typ
, Etype
(Formal
)) then
236 ("parameter subtype does not match controlling type",
240 if Present
(Default_Value
(Formal
)) then
242 -- In Ada 2005, access parameters can have defaults
244 if Ekind
(Etype
(Formal
)) = E_Anonymous_Access_Type
245 and then Ada_Version
< Ada_2005
248 ("default not allowed for controlling access parameter",
249 Default_Value
(Formal
));
251 elsif not Is_Tag_Indeterminate
(Default_Value
(Formal
)) then
253 ("default expression must be a tag indeterminate" &
254 " function call", Default_Value
(Formal
));
258 elsif Comes_From_Source
(Subp
) then
260 ("operation can be dispatching in only one type", Subp
);
264 Next_Formal
(Formal
);
267 if Ekind_In
(Subp
, E_Function
, E_Generic_Function
) then
268 Ctrl_Type
:= Check_Controlling_Type
(Etype
(Subp
), Subp
);
270 if Present
(Ctrl_Type
) then
271 if Ctrl_Type
= Typ
then
272 Set_Has_Controlling_Result
(Subp
);
274 -- Check that result subtype statically matches first subtype
275 -- (Ada 2005): Subp may have a controlling access result.
277 if Subtypes_Statically_Match
(Typ
, Etype
(Subp
))
278 or else (Ekind
(Etype
(Subp
)) = E_Anonymous_Access_Type
280 Subtypes_Statically_Match
281 (Typ
, Designated_Type
(Etype
(Subp
))))
287 ("result subtype does not match controlling type", Subp
);
290 elsif Comes_From_Source
(Subp
) then
292 ("operation can be dispatching in only one type", Subp
);
296 end Check_Controlling_Formals
;
298 ----------------------------
299 -- Check_Controlling_Type --
300 ----------------------------
302 function Check_Controlling_Type
304 Subp
: Entity_Id
) return Entity_Id
306 Tagged_Type
: Entity_Id
:= Empty
;
309 if Is_Tagged_Type
(T
) then
310 if Is_First_Subtype
(T
) then
313 Tagged_Type
:= Base_Type
(T
);
316 elsif Ekind
(T
) = E_Anonymous_Access_Type
317 and then Is_Tagged_Type
(Designated_Type
(T
))
319 if Ekind
(Designated_Type
(T
)) /= E_Incomplete_Type
then
320 if Is_First_Subtype
(Designated_Type
(T
)) then
321 Tagged_Type
:= Designated_Type
(T
);
323 Tagged_Type
:= Base_Type
(Designated_Type
(T
));
326 -- Ada 2005: an incomplete type can be tagged. An operation with an
327 -- access parameter of the type is dispatching.
329 elsif Scope
(Designated_Type
(T
)) = Current_Scope
then
330 Tagged_Type
:= Designated_Type
(T
);
332 -- Ada 2005 (AI-50217)
334 elsif From_Limited_With
(Designated_Type
(T
))
335 and then Present
(Non_Limited_View
(Designated_Type
(T
)))
336 and then Scope
(Designated_Type
(T
)) = Scope
(Subp
)
338 if Is_First_Subtype
(Non_Limited_View
(Designated_Type
(T
))) then
339 Tagged_Type
:= Non_Limited_View
(Designated_Type
(T
));
341 Tagged_Type
:= Base_Type
(Non_Limited_View
342 (Designated_Type
(T
)));
347 if No
(Tagged_Type
) or else Is_Class_Wide_Type
(Tagged_Type
) then
350 -- The dispatching type and the primitive operation must be defined in
351 -- the same scope, except in the case of internal operations and formal
352 -- abstract subprograms.
354 elsif ((Scope
(Subp
) = Scope
(Tagged_Type
) or else Is_Internal
(Subp
))
355 and then (not Is_Generic_Type
(Tagged_Type
)
356 or else not Comes_From_Source
(Subp
)))
358 (Is_Formal_Subprogram
(Subp
) and then Is_Abstract_Subprogram
(Subp
))
360 (Nkind
(Parent
(Parent
(Subp
))) = N_Subprogram_Renaming_Declaration
362 Present
(Corresponding_Formal_Spec
(Parent
(Parent
(Subp
))))
364 Is_Abstract_Subprogram
(Subp
))
371 end Check_Controlling_Type
;
373 ----------------------------
374 -- Check_Dispatching_Call --
375 ----------------------------
377 procedure Check_Dispatching_Call
(N
: Node_Id
) is
378 Loc
: constant Source_Ptr
:= Sloc
(N
);
381 Control
: Node_Id
:= Empty
;
383 Subp_Entity
: Entity_Id
;
384 Indeterm_Ancestor_Call
: Boolean := False;
385 Indeterm_Ctrl_Type
: Entity_Id
;
387 Static_Tag
: Node_Id
:= Empty
;
388 -- If a controlling formal has a statically tagged actual, the tag of
389 -- this actual is to be used for any tag-indeterminate actual.
391 procedure Check_Direct_Call
;
392 -- In the case when the controlling actual is a class-wide type whose
393 -- root type's completion is a task or protected type, the call is in
394 -- fact direct. This routine detects the above case and modifies the
397 procedure Check_Dispatching_Context
;
398 -- If the call is tag-indeterminate and the entity being called is
399 -- abstract, verify that the context is a call that will eventually
400 -- provide a tag for dispatching, or has provided one already.
402 -----------------------
403 -- Check_Direct_Call --
404 -----------------------
406 procedure Check_Direct_Call
is
407 Typ
: Entity_Id
:= Etype
(Control
);
409 function Is_User_Defined_Equality
(Id
: Entity_Id
) return Boolean;
410 -- Determine whether an entity denotes a user-defined equality
412 ------------------------------
413 -- Is_User_Defined_Equality --
414 ------------------------------
416 function Is_User_Defined_Equality
(Id
: Entity_Id
) return Boolean is
419 Ekind
(Id
) = E_Function
420 and then Chars
(Id
) = Name_Op_Eq
421 and then Comes_From_Source
(Id
)
423 -- Internally generated equalities have a full type declaration
426 and then Nkind
(Parent
(Id
)) = N_Function_Specification
;
427 end Is_User_Defined_Equality
;
429 -- Start of processing for Check_Direct_Call
432 -- Predefined primitives do not receive wrappers since they are built
433 -- from scratch for the corresponding record of synchronized types.
434 -- Equality is in general predefined, but is excluded from the check
435 -- when it is user-defined.
437 if Is_Predefined_Dispatching_Operation
(Subp_Entity
)
438 and then not Is_User_Defined_Equality
(Subp_Entity
)
443 if Is_Class_Wide_Type
(Typ
) then
444 Typ
:= Root_Type
(Typ
);
447 if Is_Private_Type
(Typ
) and then Present
(Full_View
(Typ
)) then
448 Typ
:= Full_View
(Typ
);
451 if Is_Concurrent_Type
(Typ
)
453 Present
(Corresponding_Record_Type
(Typ
))
455 Typ
:= Corresponding_Record_Type
(Typ
);
457 -- The concurrent record's list of primitives should contain a
458 -- wrapper for the entity of the call, retrieve it.
463 Wrapper_Found
: Boolean := False;
466 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
467 while Present
(Prim_Elmt
) loop
468 Prim
:= Node
(Prim_Elmt
);
470 if Is_Primitive_Wrapper
(Prim
)
471 and then Wrapped_Entity
(Prim
) = Subp_Entity
473 Wrapper_Found
:= True;
477 Next_Elmt
(Prim_Elmt
);
480 -- A primitive declared between two views should have a
481 -- corresponding wrapper.
483 pragma Assert
(Wrapper_Found
);
485 -- Modify the call by setting the proper entity
487 Set_Entity
(Name
(N
), Prim
);
490 end Check_Direct_Call
;
492 -------------------------------
493 -- Check_Dispatching_Context --
494 -------------------------------
496 procedure Check_Dispatching_Context
is
497 Subp
: constant Entity_Id
:= Entity
(Name
(N
));
498 Typ
: constant Entity_Id
:= Etype
(Subp
);
501 procedure Abstract_Context_Error
;
502 -- Error for abstract call dispatching on result is not dispatching
504 ----------------------------
505 -- Abstract_Context_Error --
506 ----------------------------
508 procedure Abstract_Context_Error
is
510 if Ekind
(Subp
) = E_Function
then
512 ("call to abstract function must be dispatching", N
);
514 -- This error can occur for a procedure in the case of a call to
515 -- an abstract formal procedure with a statically tagged operand.
519 ("call to abstract procedure must be dispatching",
522 end Abstract_Context_Error
;
524 -- Start of processing for Check_Dispatching_Context
527 if Is_Abstract_Subprogram
(Subp
)
528 and then No
(Controlling_Argument
(N
))
530 if Present
(Alias
(Subp
))
531 and then not Is_Abstract_Subprogram
(Alias
(Subp
))
532 and then No
(DTC_Entity
(Subp
))
534 -- Private overriding of inherited abstract operation, call is
537 Set_Entity
(Name
(N
), Alias
(Subp
));
540 -- An obscure special case: a null procedure may have a class-
541 -- wide pre/postcondition that includes a call to an abstract
542 -- subp. Calls within the expression may not have been rewritten
543 -- as dispatching calls yet, because the null body appears in
544 -- the current declarative part. The expression will be properly
545 -- rewritten/reanalyzed when the postcondition procedure is built.
547 -- Similarly, if this is a pre/postcondition for an abstract
548 -- subprogram, it may call another abstract function which is
549 -- a primitive of an abstract type. The call is non-dispatching
550 -- but will be legal in overridings of the operation.
552 elsif In_Spec_Expression
553 and then Is_Subprogram
(Current_Scope
)
555 ((Nkind
(Parent
(Current_Scope
)) = N_Procedure_Specification
556 and then Null_Present
(Parent
(Current_Scope
)))
557 or else Is_Abstract_Subprogram
(Current_Scope
))
562 -- We need to determine whether the context of the call
563 -- provides a tag to make the call dispatching. This requires
564 -- the call to be the actual in an enclosing call, and that
565 -- actual must be controlling. If the call is an operand of
566 -- equality, the other operand must not ve abstract.
568 if not Is_Tagged_Type
(Typ
)
570 (Ekind
(Typ
) = E_Anonymous_Access_Type
571 and then Is_Tagged_Type
(Designated_Type
(Typ
)))
573 Abstract_Context_Error
;
579 if Nkind
(Par
) = N_Parameter_Association
then
583 while Present
(Par
) loop
584 if Nkind_In
(Par
, N_Function_Call
,
585 N_Procedure_Call_Statement
)
586 and then Is_Entity_Name
(Name
(Par
))
593 -- Find formal for which call is the actual.
595 F
:= First_Formal
(Entity
(Name
(Par
)));
596 A
:= First_Actual
(Par
);
597 while Present
(F
) loop
598 if Is_Controlling_Formal
(F
)
599 and then (N
= A
or else Parent
(N
) = A
)
609 ("call to abstract function must be dispatching", N
);
613 -- For equalitiy operators, one of the operands must be
614 -- statically or dynamically tagged.
616 elsif Nkind_In
(Par
, N_Op_Eq
, N_Op_Ne
) then
617 if N
= Right_Opnd
(Par
)
618 and then Is_Tag_Indeterminate
(Left_Opnd
(Par
))
620 Abstract_Context_Error
;
622 elsif N
= Left_Opnd
(Par
)
623 and then Is_Tag_Indeterminate
(Right_Opnd
(Par
))
625 Abstract_Context_Error
;
630 elsif Nkind
(Par
) = N_Assignment_Statement
then
633 elsif Nkind
(Par
) = N_Qualified_Expression
634 or else Nkind
(Par
) = N_Unchecked_Type_Conversion
639 Abstract_Context_Error
;
645 end Check_Dispatching_Context
;
647 -- Start of processing for Check_Dispatching_Call
650 -- Find a controlling argument, if any
652 if Present
(Parameter_Associations
(N
)) then
653 Subp_Entity
:= Entity
(Name
(N
));
655 Actual
:= First_Actual
(N
);
656 Formal
:= First_Formal
(Subp_Entity
);
657 while Present
(Actual
) loop
658 Control
:= Find_Controlling_Arg
(Actual
);
659 exit when Present
(Control
);
661 -- Check for the case where the actual is a tag-indeterminate call
662 -- whose result type is different than the tagged type associated
663 -- with the containing call, but is an ancestor of the type.
665 if Is_Controlling_Formal
(Formal
)
666 and then Is_Tag_Indeterminate
(Actual
)
667 and then Base_Type
(Etype
(Actual
)) /= Base_Type
(Etype
(Formal
))
668 and then Is_Ancestor
(Etype
(Actual
), Etype
(Formal
))
670 Indeterm_Ancestor_Call
:= True;
671 Indeterm_Ctrl_Type
:= Etype
(Formal
);
673 -- If the formal is controlling but the actual is not, the type
674 -- of the actual is statically known, and may be used as the
675 -- controlling tag for some other tag-indeterminate actual.
677 elsif Is_Controlling_Formal
(Formal
)
678 and then Is_Entity_Name
(Actual
)
679 and then Is_Tagged_Type
(Etype
(Actual
))
681 Static_Tag
:= Actual
;
684 Next_Actual
(Actual
);
685 Next_Formal
(Formal
);
688 -- If the call doesn't have a controlling actual but does have an
689 -- indeterminate actual that requires dispatching treatment, then an
690 -- object is needed that will serve as the controlling argument for
691 -- a dispatching call on the indeterminate actual. This can only
692 -- occur in the unusual situation of a default actual given by
693 -- a tag-indeterminate call and where the type of the call is an
694 -- ancestor of the type associated with a containing call to an
695 -- inherited operation (see AI-239).
697 -- Rather than create an object of the tagged type, which would
698 -- be problematic for various reasons (default initialization,
699 -- discriminants), the tag of the containing call's associated
700 -- tagged type is directly used to control the dispatching.
703 and then Indeterm_Ancestor_Call
704 and then No
(Static_Tag
)
707 Make_Attribute_Reference
(Loc
,
708 Prefix
=> New_Occurrence_Of
(Indeterm_Ctrl_Type
, Loc
),
709 Attribute_Name
=> Name_Tag
);
714 if Present
(Control
) then
716 -- Verify that no controlling arguments are statically tagged
719 Write_Str
("Found Dispatching call");
724 Actual
:= First_Actual
(N
);
725 while Present
(Actual
) loop
726 if Actual
/= Control
then
728 if not Is_Controlling_Actual
(Actual
) then
729 null; -- Can be anything
731 elsif Is_Dynamically_Tagged
(Actual
) then
732 null; -- Valid parameter
734 elsif Is_Tag_Indeterminate
(Actual
) then
736 -- The tag is inherited from the enclosing call (the node
737 -- we are currently analyzing). Explicitly expand the
738 -- actual, since the previous call to Expand (from
739 -- Resolve_Call) had no way of knowing about the
740 -- required dispatching.
742 Propagate_Tag
(Control
, Actual
);
746 ("controlling argument is not dynamically tagged",
752 Next_Actual
(Actual
);
755 -- Mark call as a dispatching call
757 Set_Controlling_Argument
(N
, Control
);
758 Check_Restriction
(No_Dispatching_Calls
, N
);
760 -- The dispatching call may need to be converted into a direct
761 -- call in certain cases.
765 -- If there is a statically tagged actual and a tag-indeterminate
766 -- call to a function of the ancestor (such as that provided by a
767 -- default), then treat this as a dispatching call and propagate
768 -- the tag to the tag-indeterminate call(s).
770 elsif Present
(Static_Tag
) and then Indeterm_Ancestor_Call
then
772 Make_Attribute_Reference
(Loc
,
774 New_Occurrence_Of
(Etype
(Static_Tag
), Loc
),
775 Attribute_Name
=> Name_Tag
);
779 Actual
:= First_Actual
(N
);
780 Formal
:= First_Formal
(Subp_Entity
);
781 while Present
(Actual
) loop
782 if Is_Tag_Indeterminate
(Actual
)
783 and then Is_Controlling_Formal
(Formal
)
785 Propagate_Tag
(Control
, Actual
);
788 Next_Actual
(Actual
);
789 Next_Formal
(Formal
);
792 Check_Dispatching_Context
;
795 -- The call is not dispatching, so check that there aren't any
796 -- tag-indeterminate abstract calls left.
798 Actual
:= First_Actual
(N
);
799 while Present
(Actual
) loop
800 if Is_Tag_Indeterminate
(Actual
) then
802 -- Function call case
804 if Nkind
(Original_Node
(Actual
)) = N_Function_Call
then
805 Func
:= Entity
(Name
(Original_Node
(Actual
)));
807 -- If the actual is an attribute then it can't be abstract
808 -- (the only current case of a tag-indeterminate attribute
809 -- is the stream Input attribute).
812 Nkind
(Original_Node
(Actual
)) = N_Attribute_Reference
816 -- Only other possibility is a qualified expression whose
817 -- constituent expression is itself a call.
823 (Expression
(Original_Node
(Actual
)))));
826 if Present
(Func
) and then Is_Abstract_Subprogram
(Func
) then
828 ("call to abstract function must be dispatching", N
);
832 Next_Actual
(Actual
);
835 Check_Dispatching_Context
;
839 -- If dispatching on result, the enclosing call, if any, will
840 -- determine the controlling argument. Otherwise this is the
841 -- primitive operation of the root type.
843 Check_Dispatching_Context
;
845 end Check_Dispatching_Call
;
847 ---------------------------------
848 -- Check_Dispatching_Operation --
849 ---------------------------------
851 procedure Check_Dispatching_Operation
(Subp
, Old_Subp
: Entity_Id
) is
852 Tagged_Type
: Entity_Id
;
853 Has_Dispatching_Parent
: Boolean := False;
854 Body_Is_Last_Primitive
: Boolean := False;
855 Ovr_Subp
: Entity_Id
:= Empty
;
858 if not Ekind_In
(Subp
, E_Procedure
, E_Function
) then
862 Set_Is_Dispatching_Operation
(Subp
, False);
863 Tagged_Type
:= Find_Dispatching_Type
(Subp
);
865 -- Ada 2005 (AI-345): Use the corresponding record (if available).
866 -- Required because primitives of concurrent types are attached
867 -- to the corresponding record (not to the concurrent type).
869 if Ada_Version
>= Ada_2005
870 and then Present
(Tagged_Type
)
871 and then Is_Concurrent_Type
(Tagged_Type
)
872 and then Present
(Corresponding_Record_Type
(Tagged_Type
))
874 Tagged_Type
:= Corresponding_Record_Type
(Tagged_Type
);
877 -- (AI-345): The task body procedure is not a primitive of the tagged
880 if Present
(Tagged_Type
)
881 and then Is_Concurrent_Record_Type
(Tagged_Type
)
882 and then Present
(Corresponding_Concurrent_Type
(Tagged_Type
))
883 and then Is_Task_Type
(Corresponding_Concurrent_Type
(Tagged_Type
))
884 and then Subp
= Get_Task_Body_Procedure
885 (Corresponding_Concurrent_Type
(Tagged_Type
))
890 -- If Subp is derived from a dispatching operation then it should
891 -- always be treated as dispatching. In this case various checks
892 -- below will be bypassed. Makes sure that late declarations for
893 -- inherited private subprograms are treated as dispatching, even
894 -- if the associated tagged type is already frozen.
896 Has_Dispatching_Parent
:=
897 Present
(Alias
(Subp
))
898 and then Is_Dispatching_Operation
(Alias
(Subp
));
900 if No
(Tagged_Type
) then
902 -- Ada 2005 (AI-251): Check that Subp is not a primitive associated
903 -- with an abstract interface type unless the interface acts as a
904 -- parent type in a derivation. If the interface type is a formal
905 -- type then the operation is not primitive and therefore legal.
912 E
:= First_Entity
(Subp
);
913 while Present
(E
) loop
915 -- For an access parameter, check designated type
917 if Ekind
(Etype
(E
)) = E_Anonymous_Access_Type
then
918 Typ
:= Designated_Type
(Etype
(E
));
923 if Comes_From_Source
(Subp
)
924 and then Is_Interface
(Typ
)
925 and then not Is_Class_Wide_Type
(Typ
)
926 and then not Is_Derived_Type
(Typ
)
927 and then not Is_Generic_Type
(Typ
)
928 and then not In_Instance
930 Error_Msg_N
("??declaration of& is too late!", Subp
);
931 Error_Msg_NE
-- CODEFIX??
932 ("\??spec should appear immediately after declaration "
933 & "of & !", Subp
, Typ
);
940 -- In case of functions check also the result type
942 if Ekind
(Subp
) = E_Function
then
943 if Is_Access_Type
(Etype
(Subp
)) then
944 Typ
:= Designated_Type
(Etype
(Subp
));
949 -- The following should be better commented, especially since
950 -- we just added several new conditions here ???
952 if Comes_From_Source
(Subp
)
953 and then Is_Interface
(Typ
)
954 and then not Is_Class_Wide_Type
(Typ
)
955 and then not Is_Derived_Type
(Typ
)
956 and then not Is_Generic_Type
(Typ
)
957 and then not In_Instance
959 Error_Msg_N
("??declaration of& is too late!", Subp
);
961 ("\??spec should appear immediately after declaration "
962 & "of & !", Subp
, Typ
);
969 -- The subprograms build internally after the freezing point (such as
970 -- init procs, interface thunks, type support subprograms, and Offset
971 -- to top functions for accessing interface components in variable
972 -- size tagged types) are not primitives.
974 elsif Is_Frozen
(Tagged_Type
)
975 and then not Comes_From_Source
(Subp
)
976 and then not Has_Dispatching_Parent
978 -- Complete decoration of internally built subprograms that override
979 -- a dispatching primitive. These entities correspond with the
982 -- 1. Ada 2005 (AI-391): Wrapper functions built by the expander
983 -- to override functions of nonabstract null extensions. These
984 -- primitives were added to the list of primitives of the tagged
985 -- type by Make_Controlling_Function_Wrappers. However, attribute
986 -- Is_Dispatching_Operation must be set to true.
988 -- 2. Ada 2005 (AI-251): Wrapper procedures of null interface
991 -- 3. Subprograms associated with stream attributes (built by
992 -- New_Stream_Subprogram)
994 if Present
(Old_Subp
)
995 and then Present
(Overridden_Operation
(Subp
))
996 and then Is_Dispatching_Operation
(Old_Subp
)
999 ((Ekind
(Subp
) = E_Function
1000 and then Is_Dispatching_Operation
(Old_Subp
)
1001 and then Is_Null_Extension
(Base_Type
(Etype
(Subp
))))
1003 (Ekind
(Subp
) = E_Procedure
1004 and then Is_Dispatching_Operation
(Old_Subp
)
1005 and then Present
(Alias
(Old_Subp
))
1006 and then Is_Null_Interface_Primitive
1007 (Ultimate_Alias
(Old_Subp
)))
1008 or else Get_TSS_Name
(Subp
) = TSS_Stream_Read
1009 or else Get_TSS_Name
(Subp
) = TSS_Stream_Write
);
1011 Check_Controlling_Formals
(Tagged_Type
, Subp
);
1012 Override_Dispatching_Operation
(Tagged_Type
, Old_Subp
, Subp
);
1013 Set_Is_Dispatching_Operation
(Subp
);
1018 -- The operation may be a child unit, whose scope is the defining
1019 -- package, but which is not a primitive operation of the type.
1021 elsif Is_Child_Unit
(Subp
) then
1024 -- If the subprogram is not defined in a package spec, the only case
1025 -- where it can be a dispatching op is when it overrides an operation
1026 -- before the freezing point of the type.
1028 elsif ((not Is_Package_Or_Generic_Package
(Scope
(Subp
)))
1029 or else In_Package_Body
(Scope
(Subp
)))
1030 and then not Has_Dispatching_Parent
1032 if not Comes_From_Source
(Subp
)
1033 or else (Present
(Old_Subp
) and then not Is_Frozen
(Tagged_Type
))
1037 -- If the type is already frozen, the overriding is not allowed
1038 -- except when Old_Subp is not a dispatching operation (which can
1039 -- occur when Old_Subp was inherited by an untagged type). However,
1040 -- a body with no previous spec freezes the type *after* its
1041 -- declaration, and therefore is a legal overriding (unless the type
1042 -- has already been frozen). Only the first such body is legal.
1044 elsif Present
(Old_Subp
)
1045 and then Is_Dispatching_Operation
(Old_Subp
)
1047 if Comes_From_Source
(Subp
)
1049 (Nkind
(Unit_Declaration_Node
(Subp
)) = N_Subprogram_Body
1050 or else Nkind
(Unit_Declaration_Node
(Subp
)) in N_Body_Stub
)
1053 Subp_Body
: constant Node_Id
:= Unit_Declaration_Node
(Subp
);
1054 Decl_Item
: Node_Id
;
1057 -- ??? The checks here for whether the type has been frozen
1058 -- prior to the new body are not complete. It's not simple
1059 -- to check frozenness at this point since the body has
1060 -- already caused the type to be prematurely frozen in
1061 -- Analyze_Declarations, but we're forced to recheck this
1062 -- here because of the odd rule interpretation that allows
1063 -- the overriding if the type wasn't frozen prior to the
1064 -- body. The freezing action should probably be delayed
1065 -- until after the spec is seen, but that's a tricky
1066 -- change to the delicate freezing code.
1068 -- Look at each declaration following the type up until the
1069 -- new subprogram body. If any of the declarations is a body
1070 -- then the type has been frozen already so the overriding
1071 -- primitive is illegal.
1073 Decl_Item
:= Next
(Parent
(Tagged_Type
));
1074 while Present
(Decl_Item
)
1075 and then (Decl_Item
/= Subp_Body
)
1077 if Comes_From_Source
(Decl_Item
)
1078 and then (Nkind
(Decl_Item
) in N_Proper_Body
1079 or else Nkind
(Decl_Item
) in N_Body_Stub
)
1081 Error_Msg_N
("overriding of& is too late!", Subp
);
1083 ("\spec should appear immediately after the type!",
1091 -- If the subprogram doesn't follow in the list of
1092 -- declarations including the type then the type has
1093 -- definitely been frozen already and the body is illegal.
1095 if No
(Decl_Item
) then
1096 Error_Msg_N
("overriding of& is too late!", Subp
);
1098 ("\spec should appear immediately after the type!",
1101 elsif Is_Frozen
(Subp
) then
1103 -- The subprogram body declares a primitive operation.
1104 -- If the subprogram is already frozen, we must update
1105 -- its dispatching information explicitly here. The
1106 -- information is taken from the overridden subprogram.
1107 -- We must also generate a cross-reference entry because
1108 -- references to other primitives were already created
1109 -- when type was frozen.
1111 Body_Is_Last_Primitive
:= True;
1113 if Present
(DTC_Entity
(Old_Subp
)) then
1114 Set_DTC_Entity
(Subp
, DTC_Entity
(Old_Subp
));
1115 Set_DT_Position
(Subp
, DT_Position
(Old_Subp
));
1117 if not Restriction_Active
(No_Dispatching_Calls
) then
1118 if Building_Static_DT
(Tagged_Type
) then
1120 -- If the static dispatch table has not been
1121 -- built then there is nothing else to do now;
1122 -- otherwise we notify that we cannot build the
1123 -- static dispatch table.
1125 if Has_Dispatch_Table
(Tagged_Type
) then
1127 ("overriding of& is too late for building "
1128 & " static dispatch tables!", Subp
);
1130 ("\spec should appear immediately after "
1131 & "the type!", Subp
);
1134 -- No code required to register primitives in VM
1137 elsif VM_Target
/= No_VM
then
1141 Insert_Actions_After
(Subp_Body
,
1142 Register_Primitive
(Sloc
(Subp_Body
),
1146 -- Indicate that this is an overriding operation,
1147 -- and replace the overridden entry in the list of
1148 -- primitive operations, which is used for xref
1149 -- generation subsequently.
1151 Generate_Reference
(Tagged_Type
, Subp
, 'P', False);
1152 Override_Dispatching_Operation
1153 (Tagged_Type
, Old_Subp
, Subp
);
1160 Error_Msg_N
("overriding of& is too late!", Subp
);
1162 ("\subprogram spec should appear immediately after the type!",
1166 -- If the type is not frozen yet and we are not in the overriding
1167 -- case it looks suspiciously like an attempt to define a primitive
1168 -- operation, which requires the declaration to be in a package spec
1169 -- (3.2.3(6)). Only report cases where the type and subprogram are
1170 -- in the same declaration list (by checking the enclosing parent
1171 -- declarations), to avoid spurious warnings on subprograms in
1172 -- instance bodies when the type is declared in the instance spec
1173 -- but hasn't been frozen by the instance body.
1175 elsif not Is_Frozen
(Tagged_Type
)
1176 and then In_Same_List
(Parent
(Tagged_Type
), Parent
(Parent
(Subp
)))
1179 ("??not dispatching (must be defined in a package spec)", Subp
);
1182 -- When the type is frozen, it is legitimate to define a new
1183 -- non-primitive operation.
1189 -- Now, we are sure that the scope is a package spec. If the subprogram
1190 -- is declared after the freezing point of the type that's an error
1192 elsif Is_Frozen
(Tagged_Type
) and then not Has_Dispatching_Parent
then
1193 Error_Msg_N
("this primitive operation is declared too late", Subp
);
1195 ("??no primitive operations for& after this line",
1196 Freeze_Node
(Tagged_Type
),
1201 Check_Controlling_Formals
(Tagged_Type
, Subp
);
1203 Ovr_Subp
:= Old_Subp
;
1205 -- [Ada 2012:AI-0125]: Search for inherited hidden primitive that may be
1206 -- overridden by Subp. This only applies to source subprograms, and
1207 -- their declaration must carry an explicit overriding indicator.
1210 and then Ada_Version
>= Ada_2012
1211 and then Comes_From_Source
(Subp
)
1213 Nkind
(Unit_Declaration_Node
(Subp
)) = N_Subprogram_Declaration
1215 Ovr_Subp
:= Find_Hidden_Overridden_Primitive
(Subp
);
1217 -- Verify that the proper overriding indicator has been supplied.
1219 if Present
(Ovr_Subp
)
1221 not Must_Override
(Specification
(Unit_Declaration_Node
(Subp
)))
1223 Error_Msg_NE
("missing overriding indicator for&", Subp
, Subp
);
1227 -- Now it should be a correct primitive operation, put it in the list
1229 if Present
(Ovr_Subp
) then
1231 -- If the type has interfaces we complete this check after we set
1232 -- attribute Is_Dispatching_Operation.
1234 Check_Subtype_Conformant
(Subp
, Ovr_Subp
);
1236 if Nam_In
(Chars
(Subp
), Name_Initialize
, Name_Adjust
, Name_Finalize
)
1237 and then Is_Controlled
(Tagged_Type
)
1238 and then not Is_Visibly_Controlled
(Tagged_Type
)
1240 Set_Overridden_Operation
(Subp
, Empty
);
1242 -- If the subprogram specification carries an overriding
1243 -- indicator, no need for the warning: it is either redundant,
1244 -- or else an error will be reported.
1246 if Nkind
(Parent
(Subp
)) = N_Procedure_Specification
1248 (Must_Override
(Parent
(Subp
))
1249 or else Must_Not_Override
(Parent
(Subp
)))
1253 -- Here we need the warning
1257 ("operation does not override inherited&??", Subp
, Subp
);
1261 Override_Dispatching_Operation
(Tagged_Type
, Ovr_Subp
, Subp
);
1263 -- Ada 2005 (AI-251): In case of late overriding of a primitive
1264 -- that covers abstract interface subprograms we must register it
1265 -- in all the secondary dispatch tables associated with abstract
1266 -- interfaces. We do this now only if not building static tables,
1267 -- nor when the expander is inactive (we avoid trying to register
1268 -- primitives in semantics-only mode, since the type may not have
1269 -- an associated dispatch table). Otherwise the patch code is
1270 -- emitted after those tables are built, to prevent access before
1271 -- elaboration in gigi.
1273 if Body_Is_Last_Primitive
and then Expander_Active
then
1275 Subp_Body
: constant Node_Id
:= Unit_Declaration_Node
(Subp
);
1280 Elmt
:= First_Elmt
(Primitive_Operations
(Tagged_Type
));
1281 while Present
(Elmt
) loop
1282 Prim
:= Node
(Elmt
);
1284 -- No code required to register primitives in VM targets
1286 if Present
(Alias
(Prim
))
1287 and then Present
(Interface_Alias
(Prim
))
1288 and then Alias
(Prim
) = Subp
1289 and then not Building_Static_DT
(Tagged_Type
)
1290 and then VM_Target
= No_VM
1292 Insert_Actions_After
(Subp_Body
,
1293 Register_Primitive
(Sloc
(Subp_Body
), Prim
=> Prim
));
1299 -- Redisplay the contents of the updated dispatch table
1301 if Debug_Flag_ZZ
then
1302 Write_Str
("Late overriding: ");
1303 Write_DT
(Tagged_Type
);
1309 -- If the tagged type is a concurrent type then we must be compiling
1310 -- with no code generation (we are either compiling a generic unit or
1311 -- compiling under -gnatc mode) because we have previously tested that
1312 -- no serious errors has been reported. In this case we do not add the
1313 -- primitive to the list of primitives of Tagged_Type but we leave the
1314 -- primitive decorated as a dispatching operation to be able to analyze
1315 -- and report errors associated with the Object.Operation notation.
1317 elsif Is_Concurrent_Type
(Tagged_Type
) then
1318 pragma Assert
(not Expander_Active
);
1321 -- If no old subprogram, then we add this as a dispatching operation,
1322 -- but we avoid doing this if an error was posted, to prevent annoying
1325 elsif not Error_Posted
(Subp
) then
1326 Add_Dispatching_Operation
(Tagged_Type
, Subp
);
1329 Set_Is_Dispatching_Operation
(Subp
, True);
1331 -- Ada 2005 (AI-251): If the type implements interfaces we must check
1332 -- subtype conformance against all the interfaces covered by this
1335 if Present
(Ovr_Subp
)
1336 and then Has_Interfaces
(Tagged_Type
)
1339 Ifaces_List
: Elist_Id
;
1340 Iface_Elmt
: Elmt_Id
;
1341 Iface_Prim_Elmt
: Elmt_Id
;
1342 Iface_Prim
: Entity_Id
;
1343 Ret_Typ
: Entity_Id
;
1346 Collect_Interfaces
(Tagged_Type
, Ifaces_List
);
1348 Iface_Elmt
:= First_Elmt
(Ifaces_List
);
1349 while Present
(Iface_Elmt
) loop
1350 if not Is_Ancestor
(Node
(Iface_Elmt
), Tagged_Type
) then
1352 First_Elmt
(Primitive_Operations
(Node
(Iface_Elmt
)));
1353 while Present
(Iface_Prim_Elmt
) loop
1354 Iface_Prim
:= Node
(Iface_Prim_Elmt
);
1356 if Is_Interface_Conformant
1357 (Tagged_Type
, Iface_Prim
, Subp
)
1359 -- Handle procedures, functions whose return type
1360 -- matches, or functions not returning interfaces
1362 if Ekind
(Subp
) = E_Procedure
1363 or else Etype
(Iface_Prim
) = Etype
(Subp
)
1364 or else not Is_Interface
(Etype
(Iface_Prim
))
1366 Check_Subtype_Conformant
1368 Old_Id
=> Iface_Prim
,
1370 Skip_Controlling_Formals
=> True);
1372 -- Handle functions returning interfaces
1374 elsif Implements_Interface
1375 (Etype
(Subp
), Etype
(Iface_Prim
))
1377 -- Temporarily force both entities to return the
1378 -- same type. Required because Subtype_Conformant
1379 -- does not handle this case.
1381 Ret_Typ
:= Etype
(Iface_Prim
);
1382 Set_Etype
(Iface_Prim
, Etype
(Subp
));
1384 Check_Subtype_Conformant
1386 Old_Id
=> Iface_Prim
,
1388 Skip_Controlling_Formals
=> True);
1390 Set_Etype
(Iface_Prim
, Ret_Typ
);
1394 Next_Elmt
(Iface_Prim_Elmt
);
1398 Next_Elmt
(Iface_Elmt
);
1403 if not Body_Is_Last_Primitive
then
1404 Set_DT_Position
(Subp
, No_Uint
);
1406 elsif Has_Controlled_Component
(Tagged_Type
)
1407 and then Nam_In
(Chars
(Subp
), Name_Initialize
,
1410 Name_Finalize_Address
)
1413 F_Node
: constant Node_Id
:= Freeze_Node
(Tagged_Type
);
1417 Old_Spec
: Entity_Id
;
1419 C_Names
: constant array (1 .. 4) of Name_Id
:=
1423 Name_Finalize_Address
);
1425 D_Names
: constant array (1 .. 4) of TSS_Name_Type
:=
1426 (TSS_Deep_Initialize
,
1429 TSS_Finalize_Address
);
1432 -- Remove previous controlled function which was constructed and
1433 -- analyzed when the type was frozen. This requires removing the
1434 -- body of the redefined primitive, as well as its specification
1435 -- if needed (there is no spec created for Deep_Initialize, see
1436 -- exp_ch3.adb). We must also dismantle the exception information
1437 -- that may have been generated for it when front end zero-cost
1438 -- tables are enabled.
1440 for J
in D_Names
'Range loop
1441 Old_P
:= TSS
(Tagged_Type
, D_Names
(J
));
1444 and then Chars
(Subp
) = C_Names
(J
)
1446 Old_Bod
:= Unit_Declaration_Node
(Old_P
);
1448 Set_Is_Eliminated
(Old_P
);
1449 Set_Scope
(Old_P
, Scope
(Current_Scope
));
1451 if Nkind
(Old_Bod
) = N_Subprogram_Body
1452 and then Present
(Corresponding_Spec
(Old_Bod
))
1454 Old_Spec
:= Corresponding_Spec
(Old_Bod
);
1455 Set_Has_Completion
(Old_Spec
, False);
1460 Build_Late_Proc
(Tagged_Type
, Chars
(Subp
));
1462 -- The new operation is added to the actions of the freeze node
1463 -- for the type, but this node has already been analyzed, so we
1464 -- must retrieve and analyze explicitly the new body.
1467 and then Present
(Actions
(F_Node
))
1469 Decl
:= Last
(Actions
(F_Node
));
1474 end Check_Dispatching_Operation
;
1476 ------------------------------------------
1477 -- Check_Operation_From_Incomplete_Type --
1478 ------------------------------------------
1480 procedure Check_Operation_From_Incomplete_Type
1484 Full
: constant Entity_Id
:= Full_View
(Typ
);
1485 Parent_Typ
: constant Entity_Id
:= Etype
(Full
);
1486 Old_Prim
: constant Elist_Id
:= Primitive_Operations
(Parent_Typ
);
1487 New_Prim
: constant Elist_Id
:= Primitive_Operations
(Full
);
1489 Prev
: Elmt_Id
:= No_Elmt
;
1491 function Derives_From
(Parent_Subp
: Entity_Id
) return Boolean;
1492 -- Check that Subp has profile of an operation derived from Parent_Subp.
1493 -- Subp must have a parameter or result type that is Typ or an access
1494 -- parameter or access result type that designates Typ.
1500 function Derives_From
(Parent_Subp
: Entity_Id
) return Boolean is
1504 if Chars
(Parent_Subp
) /= Chars
(Subp
) then
1508 -- Check that the type of controlling formals is derived from the
1509 -- parent subprogram's controlling formal type (or designated type
1510 -- if the formal type is an anonymous access type).
1512 F1
:= First_Formal
(Parent_Subp
);
1513 F2
:= First_Formal
(Subp
);
1514 while Present
(F1
) and then Present
(F2
) loop
1515 if Ekind
(Etype
(F1
)) = E_Anonymous_Access_Type
then
1516 if Ekind
(Etype
(F2
)) /= E_Anonymous_Access_Type
then
1518 elsif Designated_Type
(Etype
(F1
)) = Parent_Typ
1519 and then Designated_Type
(Etype
(F2
)) /= Full
1524 elsif Ekind
(Etype
(F2
)) = E_Anonymous_Access_Type
then
1527 elsif Etype
(F1
) = Parent_Typ
and then Etype
(F2
) /= Full
then
1535 -- Check that a controlling result type is derived from the parent
1536 -- subprogram's result type (or designated type if the result type
1537 -- is an anonymous access type).
1539 if Ekind
(Parent_Subp
) = E_Function
then
1540 if Ekind
(Subp
) /= E_Function
then
1543 elsif Ekind
(Etype
(Parent_Subp
)) = E_Anonymous_Access_Type
then
1544 if Ekind
(Etype
(Subp
)) /= E_Anonymous_Access_Type
then
1547 elsif Designated_Type
(Etype
(Parent_Subp
)) = Parent_Typ
1548 and then Designated_Type
(Etype
(Subp
)) /= Full
1553 elsif Ekind
(Etype
(Subp
)) = E_Anonymous_Access_Type
then
1556 elsif Etype
(Parent_Subp
) = Parent_Typ
1557 and then Etype
(Subp
) /= Full
1562 elsif Ekind
(Subp
) = E_Function
then
1566 return No
(F1
) and then No
(F2
);
1569 -- Start of processing for Check_Operation_From_Incomplete_Type
1572 -- The operation may override an inherited one, or may be a new one
1573 -- altogether. The inherited operation will have been hidden by the
1574 -- current one at the point of the type derivation, so it does not
1575 -- appear in the list of primitive operations of the type. We have to
1576 -- find the proper place of insertion in the list of primitive opera-
1577 -- tions by iterating over the list for the parent type.
1579 Op1
:= First_Elmt
(Old_Prim
);
1580 Op2
:= First_Elmt
(New_Prim
);
1581 while Present
(Op1
) and then Present
(Op2
) loop
1582 if Derives_From
(Node
(Op1
)) then
1585 -- Avoid adding it to the list of primitives if already there
1587 if Node
(Op2
) /= Subp
then
1588 Prepend_Elmt
(Subp
, New_Prim
);
1592 Insert_Elmt_After
(Subp
, Prev
);
1603 -- Operation is a new primitive
1605 Append_Elmt
(Subp
, New_Prim
);
1606 end Check_Operation_From_Incomplete_Type
;
1608 ---------------------------------------
1609 -- Check_Operation_From_Private_View --
1610 ---------------------------------------
1612 procedure Check_Operation_From_Private_View
(Subp
, Old_Subp
: Entity_Id
) is
1613 Tagged_Type
: Entity_Id
;
1616 if Is_Dispatching_Operation
(Alias
(Subp
)) then
1617 Set_Scope
(Subp
, Current_Scope
);
1618 Tagged_Type
:= Find_Dispatching_Type
(Subp
);
1620 -- Add Old_Subp to primitive operations if not already present
1622 if Present
(Tagged_Type
) and then Is_Tagged_Type
(Tagged_Type
) then
1623 Append_Unique_Elmt
(Old_Subp
, Primitive_Operations
(Tagged_Type
));
1625 -- If Old_Subp isn't already marked as dispatching then this is
1626 -- the case of an operation of an untagged private type fulfilled
1627 -- by a tagged type that overrides an inherited dispatching
1628 -- operation, so we set the necessary dispatching attributes here.
1630 if not Is_Dispatching_Operation
(Old_Subp
) then
1632 -- If the untagged type has no discriminants, and the full
1633 -- view is constrained, there will be a spurious mismatch of
1634 -- subtypes on the controlling arguments, because the tagged
1635 -- type is the internal base type introduced in the derivation.
1636 -- Use the original type to verify conformance, rather than the
1639 if not Comes_From_Source
(Tagged_Type
)
1640 and then Has_Discriminants
(Tagged_Type
)
1646 Formal
:= First_Formal
(Old_Subp
);
1647 while Present
(Formal
) loop
1648 if Tagged_Type
= Base_Type
(Etype
(Formal
)) then
1649 Tagged_Type
:= Etype
(Formal
);
1652 Next_Formal
(Formal
);
1656 if Tagged_Type
= Base_Type
(Etype
(Old_Subp
)) then
1657 Tagged_Type
:= Etype
(Old_Subp
);
1661 Check_Controlling_Formals
(Tagged_Type
, Old_Subp
);
1662 Set_Is_Dispatching_Operation
(Old_Subp
, True);
1663 Set_DT_Position
(Old_Subp
, No_Uint
);
1666 -- If the old subprogram is an explicit renaming of some other
1667 -- entity, it is not overridden by the inherited subprogram.
1668 -- Otherwise, update its alias and other attributes.
1670 if Present
(Alias
(Old_Subp
))
1671 and then Nkind
(Unit_Declaration_Node
(Old_Subp
)) /=
1672 N_Subprogram_Renaming_Declaration
1674 Set_Alias
(Old_Subp
, Alias
(Subp
));
1676 -- The derived subprogram should inherit the abstractness of
1677 -- the parent subprogram (except in the case of a function
1678 -- returning the type). This sets the abstractness properly
1679 -- for cases where a private extension may have inherited an
1680 -- abstract operation, but the full type is derived from a
1681 -- descendant type and inherits a nonabstract version.
1683 if Etype
(Subp
) /= Tagged_Type
then
1684 Set_Is_Abstract_Subprogram
1685 (Old_Subp
, Is_Abstract_Subprogram
(Alias
(Subp
)));
1690 end Check_Operation_From_Private_View
;
1692 --------------------------
1693 -- Find_Controlling_Arg --
1694 --------------------------
1696 function Find_Controlling_Arg
(N
: Node_Id
) return Node_Id
is
1697 Orig_Node
: constant Node_Id
:= Original_Node
(N
);
1701 if Nkind
(Orig_Node
) = N_Qualified_Expression
then
1702 return Find_Controlling_Arg
(Expression
(Orig_Node
));
1705 -- Dispatching on result case. If expansion is disabled, the node still
1706 -- has the structure of a function call. However, if the function name
1707 -- is an operator and the call was given in infix form, the original
1708 -- node has no controlling result and we must examine the current node.
1710 if Nkind
(N
) = N_Function_Call
1711 and then Present
(Controlling_Argument
(N
))
1712 and then Has_Controlling_Result
(Entity
(Name
(N
)))
1714 return Controlling_Argument
(N
);
1716 -- If expansion is enabled, the call may have been transformed into
1717 -- an indirect call, and we need to recover the original node.
1719 elsif Nkind
(Orig_Node
) = N_Function_Call
1720 and then Present
(Controlling_Argument
(Orig_Node
))
1721 and then Has_Controlling_Result
(Entity
(Name
(Orig_Node
)))
1723 return Controlling_Argument
(Orig_Node
);
1725 -- Type conversions are dynamically tagged if the target type, or its
1726 -- designated type, are classwide. An interface conversion expands into
1727 -- a dereference, so test must be performed on the original node.
1729 elsif Nkind
(Orig_Node
) = N_Type_Conversion
1730 and then Nkind
(N
) = N_Explicit_Dereference
1731 and then Is_Controlling_Actual
(N
)
1734 Target_Type
: constant Entity_Id
:=
1735 Entity
(Subtype_Mark
(Orig_Node
));
1738 if Is_Class_Wide_Type
(Target_Type
) then
1741 elsif Is_Access_Type
(Target_Type
)
1742 and then Is_Class_Wide_Type
(Designated_Type
(Target_Type
))
1753 elsif Is_Controlling_Actual
(N
)
1755 (Nkind
(Parent
(N
)) = N_Qualified_Expression
1756 and then Is_Controlling_Actual
(Parent
(N
)))
1760 if Is_Access_Type
(Typ
) then
1762 -- In the case of an Access attribute, use the type of the prefix,
1763 -- since in the case of an actual for an access parameter, the
1764 -- attribute's type may be of a specific designated type, even
1765 -- though the prefix type is class-wide.
1767 if Nkind
(N
) = N_Attribute_Reference
then
1768 Typ
:= Etype
(Prefix
(N
));
1770 -- An allocator is dispatching if the type of qualified expression
1771 -- is class_wide, in which case this is the controlling type.
1773 elsif Nkind
(Orig_Node
) = N_Allocator
1774 and then Nkind
(Expression
(Orig_Node
)) = N_Qualified_Expression
1776 Typ
:= Etype
(Expression
(Orig_Node
));
1778 Typ
:= Designated_Type
(Typ
);
1782 if Is_Class_Wide_Type
(Typ
)
1784 (Nkind
(Parent
(N
)) = N_Qualified_Expression
1785 and then Is_Access_Type
(Etype
(N
))
1786 and then Is_Class_Wide_Type
(Designated_Type
(Etype
(N
))))
1793 end Find_Controlling_Arg
;
1795 ---------------------------
1796 -- Find_Dispatching_Type --
1797 ---------------------------
1799 function Find_Dispatching_Type
(Subp
: Entity_Id
) return Entity_Id
is
1800 A_Formal
: Entity_Id
;
1802 Ctrl_Type
: Entity_Id
;
1805 if Ekind_In
(Subp
, E_Function
, E_Procedure
)
1806 and then Present
(DTC_Entity
(Subp
))
1808 return Scope
(DTC_Entity
(Subp
));
1810 -- For subprograms internally generated by derivations of tagged types
1811 -- use the alias subprogram as a reference to locate the dispatching
1814 elsif not Comes_From_Source
(Subp
)
1815 and then Present
(Alias
(Subp
))
1816 and then Is_Dispatching_Operation
(Alias
(Subp
))
1818 if Ekind
(Alias
(Subp
)) = E_Function
1819 and then Has_Controlling_Result
(Alias
(Subp
))
1821 return Check_Controlling_Type
(Etype
(Subp
), Subp
);
1824 Formal
:= First_Formal
(Subp
);
1825 A_Formal
:= First_Formal
(Alias
(Subp
));
1826 while Present
(A_Formal
) loop
1827 if Is_Controlling_Formal
(A_Formal
) then
1828 return Check_Controlling_Type
(Etype
(Formal
), Subp
);
1831 Next_Formal
(Formal
);
1832 Next_Formal
(A_Formal
);
1835 pragma Assert
(False);
1842 Formal
:= First_Formal
(Subp
);
1843 while Present
(Formal
) loop
1844 Ctrl_Type
:= Check_Controlling_Type
(Etype
(Formal
), Subp
);
1846 if Present
(Ctrl_Type
) then
1850 Next_Formal
(Formal
);
1853 -- The subprogram may also be dispatching on result
1855 if Present
(Etype
(Subp
)) then
1856 return Check_Controlling_Type
(Etype
(Subp
), Subp
);
1860 pragma Assert
(not Is_Dispatching_Operation
(Subp
));
1862 end Find_Dispatching_Type
;
1864 --------------------------------------
1865 -- Find_Hidden_Overridden_Primitive --
1866 --------------------------------------
1868 function Find_Hidden_Overridden_Primitive
(S
: Entity_Id
) return Entity_Id
1870 Tag_Typ
: constant Entity_Id
:= Find_Dispatching_Type
(S
);
1872 Orig_Prim
: Entity_Id
;
1874 Vis_List
: Elist_Id
;
1877 -- This Ada 2012 rule applies only for type extensions or private
1878 -- extensions, where the parent type is not in a parent unit, and
1879 -- where an operation is never declared but still inherited.
1882 or else not Is_Record_Type
(Tag_Typ
)
1883 or else Etype
(Tag_Typ
) = Tag_Typ
1884 or else In_Open_Scopes
(Scope
(Etype
(Tag_Typ
)))
1889 -- Collect the list of visible ancestor of the tagged type
1891 Vis_List
:= Visible_Ancestors
(Tag_Typ
);
1893 Elmt
:= First_Elmt
(Primitive_Operations
(Tag_Typ
));
1894 while Present
(Elmt
) loop
1895 Prim
:= Node
(Elmt
);
1897 -- Find an inherited hidden dispatching primitive with the name of S
1898 -- and a type-conformant profile.
1900 if Present
(Alias
(Prim
))
1901 and then Is_Hidden
(Alias
(Prim
))
1902 and then Find_Dispatching_Type
(Alias
(Prim
)) /= Tag_Typ
1903 and then Primitive_Names_Match
(S
, Prim
)
1904 and then Type_Conformant
(S
, Prim
)
1907 Vis_Ancestor
: Elmt_Id
;
1911 -- The original corresponding operation of Prim must be an
1912 -- operation of a visible ancestor of the dispatching type S,
1913 -- and the original corresponding operation of S2 must be
1916 Orig_Prim
:= Original_Corresponding_Operation
(Prim
);
1918 if Orig_Prim
/= Prim
1919 and then Is_Immediately_Visible
(Orig_Prim
)
1921 Vis_Ancestor
:= First_Elmt
(Vis_List
);
1922 while Present
(Vis_Ancestor
) loop
1924 First_Elmt
(Primitive_Operations
(Node
(Vis_Ancestor
)));
1925 while Present
(Elmt
) loop
1926 if Node
(Elmt
) = Orig_Prim
then
1927 Set_Overridden_Operation
(S
, Prim
);
1928 Set_Alias
(Prim
, Orig_Prim
);
1935 Next_Elmt
(Vis_Ancestor
);
1945 end Find_Hidden_Overridden_Primitive
;
1947 ---------------------------------------
1948 -- Find_Primitive_Covering_Interface --
1949 ---------------------------------------
1951 function Find_Primitive_Covering_Interface
1952 (Tagged_Type
: Entity_Id
;
1953 Iface_Prim
: Entity_Id
) return Entity_Id
1959 pragma Assert
(Is_Interface
(Find_Dispatching_Type
(Iface_Prim
))
1960 or else (Present
(Alias
(Iface_Prim
))
1963 (Find_Dispatching_Type
(Ultimate_Alias
(Iface_Prim
)))));
1965 -- Search in the homonym chain. Done to speed up locating visible
1966 -- entities and required to catch primitives associated with the partial
1967 -- view of private types when processing the corresponding full view.
1969 E
:= Current_Entity
(Iface_Prim
);
1970 while Present
(E
) loop
1971 if Is_Subprogram
(E
)
1972 and then Is_Dispatching_Operation
(E
)
1973 and then Is_Interface_Conformant
(Tagged_Type
, Iface_Prim
, E
)
1981 -- Search in the list of primitives of the type. Required to locate
1982 -- the covering primitive if the covering primitive is not visible
1983 -- (for example, non-visible inherited primitive of private type).
1985 El
:= First_Elmt
(Primitive_Operations
(Tagged_Type
));
1986 while Present
(El
) loop
1989 -- Keep separate the management of internal entities that link
1990 -- primitives with interface primitives from tagged type primitives.
1992 if No
(Interface_Alias
(E
)) then
1993 if Present
(Alias
(E
)) then
1995 -- This interface primitive has not been covered yet
1997 if Alias
(E
) = Iface_Prim
then
2000 -- The covering primitive was inherited
2002 elsif Overridden_Operation
(Ultimate_Alias
(E
))
2009 -- Check if E covers the interface primitive (includes case in
2010 -- which E is an inherited private primitive).
2012 if Is_Interface_Conformant
(Tagged_Type
, Iface_Prim
, E
) then
2016 -- Use the internal entity that links the interface primitive with
2017 -- the covering primitive to locate the entity.
2019 elsif Interface_Alias
(E
) = Iface_Prim
then
2029 end Find_Primitive_Covering_Interface
;
2031 ---------------------------
2032 -- Inherited_Subprograms --
2033 ---------------------------
2035 function Inherited_Subprograms
(S
: Entity_Id
) return Subprogram_List
is
2036 Result
: Subprogram_List
(1 .. 6000);
2037 -- 6000 here is intended to be infinity. We could use an expandable
2038 -- table, but it would be awfully heavy, and there is no way that we
2039 -- could reasonably exceed this value.
2042 -- Number of entries in Result
2044 Parent_Op
: Entity_Id
;
2045 -- Traverses the Overridden_Operation chain
2047 procedure Store_IS
(E
: Entity_Id
);
2048 -- Stores E in Result if not already stored
2054 procedure Store_IS
(E
: Entity_Id
) is
2056 for J
in 1 .. N
loop
2057 if E
= Result
(J
) then
2066 -- Start of processing for Inherited_Subprograms
2069 if Present
(S
) and then Is_Dispatching_Operation
(S
) then
2071 -- Deal with direct inheritance
2075 Parent_Op
:= Overridden_Operation
(Parent_Op
);
2076 exit when No
(Parent_Op
);
2078 if Is_Subprogram
(Parent_Op
)
2079 or else Is_Generic_Subprogram
(Parent_Op
)
2081 Store_IS
(Parent_Op
);
2085 -- Now deal with interfaces
2088 Tag_Typ
: Entity_Id
;
2093 Tag_Typ
:= Find_Dispatching_Type
(S
);
2095 if Is_Concurrent_Type
(Tag_Typ
) then
2096 Tag_Typ
:= Corresponding_Record_Type
(Tag_Typ
);
2099 -- Search primitive operations of dispatching type
2101 if Present
(Tag_Typ
)
2102 and then Present
(Primitive_Operations
(Tag_Typ
))
2104 Elmt
:= First_Elmt
(Primitive_Operations
(Tag_Typ
));
2105 while Present
(Elmt
) loop
2106 Prim
:= Node
(Elmt
);
2108 -- The following test eliminates some odd cases in which
2109 -- Ekind (Prim) is Void, to be investigated further ???
2111 if not (Is_Subprogram
(Prim
)
2113 Is_Generic_Subprogram
(Prim
))
2117 -- For [generic] subprogram, look at interface alias
2119 elsif Present
(Interface_Alias
(Prim
))
2120 and then Alias
(Prim
) = S
2122 -- We have found a primitive covered by S
2124 Store_IS
(Interface_Alias
(Prim
));
2133 return Result
(1 .. N
);
2134 end Inherited_Subprograms
;
2136 ---------------------------
2137 -- Is_Dynamically_Tagged --
2138 ---------------------------
2140 function Is_Dynamically_Tagged
(N
: Node_Id
) return Boolean is
2142 if Nkind
(N
) = N_Error
then
2145 return Find_Controlling_Arg
(N
) /= Empty
;
2147 end Is_Dynamically_Tagged
;
2149 ---------------------------------
2150 -- Is_Null_Interface_Primitive --
2151 ---------------------------------
2153 function Is_Null_Interface_Primitive
(E
: Entity_Id
) return Boolean is
2155 return Comes_From_Source
(E
)
2156 and then Is_Dispatching_Operation
(E
)
2157 and then Ekind
(E
) = E_Procedure
2158 and then Null_Present
(Parent
(E
))
2159 and then Is_Interface
(Find_Dispatching_Type
(E
));
2160 end Is_Null_Interface_Primitive
;
2162 --------------------------
2163 -- Is_Tag_Indeterminate --
2164 --------------------------
2166 function Is_Tag_Indeterminate
(N
: Node_Id
) return Boolean is
2169 Orig_Node
: constant Node_Id
:= Original_Node
(N
);
2172 if Nkind
(Orig_Node
) = N_Function_Call
2173 and then Is_Entity_Name
(Name
(Orig_Node
))
2175 Nam
:= Entity
(Name
(Orig_Node
));
2177 if not Has_Controlling_Result
(Nam
) then
2180 -- The function may have a controlling result, but if the return type
2181 -- is not visibly tagged, then this is not tag-indeterminate.
2183 elsif Is_Access_Type
(Etype
(Nam
))
2184 and then not Is_Tagged_Type
(Designated_Type
(Etype
(Nam
)))
2188 -- An explicit dereference means that the call has already been
2189 -- expanded and there is no tag to propagate.
2191 elsif Nkind
(N
) = N_Explicit_Dereference
then
2194 -- If there are no actuals, the call is tag-indeterminate
2196 elsif No
(Parameter_Associations
(Orig_Node
)) then
2200 Actual
:= First_Actual
(Orig_Node
);
2201 while Present
(Actual
) loop
2202 if Is_Controlling_Actual
(Actual
)
2203 and then not Is_Tag_Indeterminate
(Actual
)
2205 -- One operand is dispatching
2210 Next_Actual
(Actual
);
2216 elsif Nkind
(Orig_Node
) = N_Qualified_Expression
then
2217 return Is_Tag_Indeterminate
(Expression
(Orig_Node
));
2219 -- Case of a call to the Input attribute (possibly rewritten), which is
2220 -- always tag-indeterminate except when its prefix is a Class attribute.
2222 elsif Nkind
(Orig_Node
) = N_Attribute_Reference
2224 Get_Attribute_Id
(Attribute_Name
(Orig_Node
)) = Attribute_Input
2226 Nkind
(Prefix
(Orig_Node
)) /= N_Attribute_Reference
2230 -- In Ada 2005, a function that returns an anonymous access type can be
2231 -- dispatching, and the dereference of a call to such a function can
2232 -- also be tag-indeterminate if the call itself is.
2234 elsif Nkind
(Orig_Node
) = N_Explicit_Dereference
2235 and then Ada_Version
>= Ada_2005
2237 return Is_Tag_Indeterminate
(Prefix
(Orig_Node
));
2242 end Is_Tag_Indeterminate
;
2244 ------------------------------------
2245 -- Override_Dispatching_Operation --
2246 ------------------------------------
2248 procedure Override_Dispatching_Operation
2249 (Tagged_Type
: Entity_Id
;
2250 Prev_Op
: Entity_Id
;
2252 Is_Wrapper
: Boolean := False)
2258 -- Diagnose failure to match No_Return in parent (Ada-2005, AI-414, but
2259 -- we do it unconditionally in Ada 95 now, since this is our pragma).
2261 if No_Return
(Prev_Op
) and then not No_Return
(New_Op
) then
2262 Error_Msg_N
("procedure & must have No_Return pragma", New_Op
);
2263 Error_Msg_N
("\since overridden procedure has No_Return", New_Op
);
2266 -- If there is no previous operation to override, the type declaration
2267 -- was malformed, and an error must have been emitted already.
2269 Elmt
:= First_Elmt
(Primitive_Operations
(Tagged_Type
));
2270 while Present
(Elmt
)
2271 and then Node
(Elmt
) /= Prev_Op
2280 -- The location of entities that come from source in the list of
2281 -- primitives of the tagged type must follow their order of occurrence
2282 -- in the sources to fulfill the C++ ABI. If the overridden entity is a
2283 -- primitive of an interface that is not implemented by the parents of
2284 -- this tagged type (that is, it is an alias of an interface primitive
2285 -- generated by Derive_Interface_Progenitors), then we must append the
2286 -- new entity at the end of the list of primitives.
2288 if Present
(Alias
(Prev_Op
))
2289 and then Etype
(Tagged_Type
) /= Tagged_Type
2290 and then Is_Interface
(Find_Dispatching_Type
(Alias
(Prev_Op
)))
2291 and then not Is_Ancestor
(Find_Dispatching_Type
(Alias
(Prev_Op
)),
2292 Tagged_Type
, Use_Full_View
=> True)
2293 and then not Implements_Interface
2294 (Etype
(Tagged_Type
),
2295 Find_Dispatching_Type
(Alias
(Prev_Op
)))
2297 Remove_Elmt
(Primitive_Operations
(Tagged_Type
), Elmt
);
2298 Append_Elmt
(New_Op
, Primitive_Operations
(Tagged_Type
));
2300 -- The new primitive replaces the overridden entity. Required to ensure
2301 -- that overriding primitive is assigned the same dispatch table slot.
2304 Replace_Elmt
(Elmt
, New_Op
);
2307 if Ada_Version
>= Ada_2005
2308 and then Has_Interfaces
(Tagged_Type
)
2310 -- Ada 2005 (AI-251): Update the attribute alias of all the aliased
2311 -- entities of the overridden primitive to reference New_Op, and
2312 -- also propagate the proper value of Is_Abstract_Subprogram. Verify
2313 -- that the new operation is subtype conformant with the interface
2314 -- operations that it implements (for operations inherited from the
2315 -- parent itself, this check is made when building the derived type).
2317 -- Note: This code is executed with internally generated wrappers of
2318 -- functions with controlling result and late overridings.
2320 Elmt
:= First_Elmt
(Primitive_Operations
(Tagged_Type
));
2321 while Present
(Elmt
) loop
2322 Prim
:= Node
(Elmt
);
2324 if Prim
= New_Op
then
2327 -- Note: The check on Is_Subprogram protects the frontend against
2328 -- reading attributes in entities that are not yet fully decorated
2330 elsif Is_Subprogram
(Prim
)
2331 and then Present
(Interface_Alias
(Prim
))
2332 and then Alias
(Prim
) = Prev_Op
2334 Set_Alias
(Prim
, New_Op
);
2336 -- No further decoration needed yet for internally generated
2337 -- wrappers of controlling functions since (at this stage)
2338 -- they are not yet decorated.
2340 if not Is_Wrapper
then
2341 Check_Subtype_Conformant
(New_Op
, Prim
);
2343 Set_Is_Abstract_Subprogram
(Prim
,
2344 Is_Abstract_Subprogram
(New_Op
));
2346 -- Ensure that this entity will be expanded to fill the
2347 -- corresponding entry in its dispatch table.
2349 if not Is_Abstract_Subprogram
(Prim
) then
2350 Set_Has_Delayed_Freeze
(Prim
);
2359 if (not Is_Package_Or_Generic_Package
(Current_Scope
))
2360 or else not In_Private_Part
(Current_Scope
)
2362 -- Not a private primitive
2366 else pragma Assert
(Is_Inherited_Operation
(Prev_Op
));
2368 -- Make the overriding operation into an alias of the implicit one.
2369 -- In this fashion a call from outside ends up calling the new body
2370 -- even if non-dispatching, and a call from inside calls the over-
2371 -- riding operation because it hides the implicit one. To indicate
2372 -- that the body of Prev_Op is never called, set its dispatch table
2373 -- entity to Empty. If the overridden operation has a dispatching
2374 -- result, so does the overriding one.
2376 Set_Alias
(Prev_Op
, New_Op
);
2377 Set_DTC_Entity
(Prev_Op
, Empty
);
2378 Set_Has_Controlling_Result
(New_Op
, Has_Controlling_Result
(Prev_Op
));
2381 end Override_Dispatching_Operation
;
2387 procedure Propagate_Tag
(Control
: Node_Id
; Actual
: Node_Id
) is
2388 Call_Node
: Node_Id
;
2392 if Nkind
(Actual
) = N_Function_Call
then
2393 Call_Node
:= Actual
;
2395 elsif Nkind
(Actual
) = N_Identifier
2396 and then Nkind
(Original_Node
(Actual
)) = N_Function_Call
2398 -- Call rewritten as object declaration when stack-checking is
2399 -- enabled. Propagate tag to expression in declaration, which is
2402 Call_Node
:= Expression
(Parent
(Entity
(Actual
)));
2404 -- Ada 2005: If this is a dereference of a call to a function with a
2405 -- dispatching access-result, the tag is propagated when the dereference
2406 -- itself is expanded (see exp_ch6.adb) and there is nothing else to do.
2408 elsif Nkind
(Actual
) = N_Explicit_Dereference
2409 and then Nkind
(Original_Node
(Prefix
(Actual
))) = N_Function_Call
2413 -- When expansion is suppressed, an unexpanded call to 'Input can occur,
2414 -- and in that case we can simply return.
2416 elsif Nkind
(Actual
) = N_Attribute_Reference
then
2417 pragma Assert
(Attribute_Name
(Actual
) = Name_Input
);
2421 -- Only other possibilities are parenthesized or qualified expression,
2422 -- or an expander-generated unchecked conversion of a function call to
2423 -- a stream Input attribute.
2426 Call_Node
:= Expression
(Actual
);
2429 -- No action needed if the call has been already expanded
2431 if Is_Expanded_Dispatching_Call
(Call_Node
) then
2435 -- Do not set the Controlling_Argument if already set. This happens in
2436 -- the special case of _Input (see Exp_Attr, case Input).
2438 if No
(Controlling_Argument
(Call_Node
)) then
2439 Set_Controlling_Argument
(Call_Node
, Control
);
2442 Arg
:= First_Actual
(Call_Node
);
2443 while Present
(Arg
) loop
2444 if Is_Tag_Indeterminate
(Arg
) then
2445 Propagate_Tag
(Control
, Arg
);
2451 -- Expansion of dispatching calls is suppressed when VM_Target, because
2452 -- the VM back-ends directly handle the generation of dispatching calls
2453 -- and would have to undo any expansion to an indirect call.
2455 if Tagged_Type_Expansion
then
2457 Call_Typ
: constant Entity_Id
:= Etype
(Call_Node
);
2460 Expand_Dispatching_Call
(Call_Node
);
2462 -- If the controlling argument is an interface type and the type
2463 -- of Call_Node differs then we must add an implicit conversion to
2464 -- force displacement of the pointer to the object to reference
2465 -- the secondary dispatch table of the interface.
2467 if Is_Interface
(Etype
(Control
))
2468 and then Etype
(Control
) /= Call_Typ
2470 -- Cannot use Convert_To because the previous call to
2471 -- Expand_Dispatching_Call leaves decorated the Call_Node
2472 -- with the type of Control.
2475 Make_Type_Conversion
(Sloc
(Call_Node
),
2477 New_Occurrence_Of
(Etype
(Control
), Sloc
(Call_Node
)),
2478 Expression
=> Relocate_Node
(Call_Node
)));
2479 Set_Etype
(Call_Node
, Etype
(Control
));
2480 Set_Analyzed
(Call_Node
);
2482 Expand_Interface_Conversion
(Call_Node
);
2486 -- Expansion of a dispatching call results in an indirect call, which in
2487 -- turn causes current values to be killed (see Resolve_Call), so on VM
2488 -- targets we do the call here to ensure consistent warnings between VM
2489 -- and non-VM targets.
2492 Kill_Current_Values
;