1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2009, 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_Eval
; use Sem_Eval
;
48 with Sem_Type
; use Sem_Type
;
49 with Sem_Util
; use Sem_Util
;
50 with Snames
; use Snames
;
51 with Sinfo
; use Sinfo
;
52 with Tbuild
; use Tbuild
;
53 with Uintp
; use Uintp
;
55 package body Sem_Disp
is
57 -----------------------
58 -- Local Subprograms --
59 -----------------------
61 procedure Add_Dispatching_Operation
62 (Tagged_Type
: Entity_Id
;
64 -- Add New_Op in the list of primitive operations of Tagged_Type
66 function Check_Controlling_Type
68 Subp
: Entity_Id
) return Entity_Id
;
69 -- T is the tagged type of a formal parameter or the result of Subp.
70 -- If the subprogram has a controlling parameter or result that matches
71 -- the type, then returns the tagged type of that parameter or result
72 -- (returning the designated tagged type in the case of an access
73 -- parameter); otherwise returns empty.
75 -------------------------------
76 -- Add_Dispatching_Operation --
77 -------------------------------
79 procedure Add_Dispatching_Operation
80 (Tagged_Type
: Entity_Id
;
83 List
: constant Elist_Id
:= Primitive_Operations
(Tagged_Type
);
86 -- The dispatching operation may already be on the list, if it is the
87 -- wrapper for an inherited function of a null extension (see Exp_Ch3
88 -- for the construction of function wrappers). The list of primitive
89 -- operations must not contain duplicates.
91 Append_Unique_Elmt
(New_Op
, List
);
92 end Add_Dispatching_Operation
;
94 -------------------------------
95 -- Check_Controlling_Formals --
96 -------------------------------
98 procedure Check_Controlling_Formals
103 Ctrl_Type
: Entity_Id
;
106 Formal
:= First_Formal
(Subp
);
107 while Present
(Formal
) loop
108 Ctrl_Type
:= Check_Controlling_Type
(Etype
(Formal
), Subp
);
110 if Present
(Ctrl_Type
) then
112 -- When controlling type is concurrent and declared within a
113 -- generic or inside an instance use corresponding record type.
115 if Is_Concurrent_Type
(Ctrl_Type
)
116 and then Present
(Corresponding_Record_Type
(Ctrl_Type
))
118 Ctrl_Type
:= Corresponding_Record_Type
(Ctrl_Type
);
121 if Ctrl_Type
= Typ
then
122 Set_Is_Controlling_Formal
(Formal
);
124 -- Ada 2005 (AI-231): Anonymous access types that are used in
125 -- controlling parameters exclude null because it is necessary
126 -- to read the tag to dispatch, and null has no tag.
128 if Ekind
(Etype
(Formal
)) = E_Anonymous_Access_Type
then
129 Set_Can_Never_Be_Null
(Etype
(Formal
));
130 Set_Is_Known_Non_Null
(Etype
(Formal
));
133 -- Check that the parameter's nominal subtype statically
134 -- matches the first subtype.
136 if Ekind
(Etype
(Formal
)) = E_Anonymous_Access_Type
then
137 if not Subtypes_Statically_Match
138 (Typ
, Designated_Type
(Etype
(Formal
)))
141 ("parameter subtype does not match controlling type",
145 elsif not Subtypes_Statically_Match
(Typ
, Etype
(Formal
)) then
147 ("parameter subtype does not match controlling type",
151 if Present
(Default_Value
(Formal
)) then
153 -- In Ada 2005, access parameters can have defaults
155 if Ekind
(Etype
(Formal
)) = E_Anonymous_Access_Type
156 and then Ada_Version
< Ada_05
159 ("default not allowed for controlling access parameter",
160 Default_Value
(Formal
));
162 elsif not Is_Tag_Indeterminate
(Default_Value
(Formal
)) then
164 ("default expression must be a tag indeterminate" &
165 " function call", Default_Value
(Formal
));
169 elsif Comes_From_Source
(Subp
) then
171 ("operation can be dispatching in only one type", Subp
);
175 Next_Formal
(Formal
);
178 if Ekind
(Subp
) = E_Function
180 Ekind
(Subp
) = E_Generic_Function
182 Ctrl_Type
:= Check_Controlling_Type
(Etype
(Subp
), Subp
);
184 if Present
(Ctrl_Type
) then
185 if Ctrl_Type
= Typ
then
186 Set_Has_Controlling_Result
(Subp
);
188 -- Check that result subtype statically matches first subtype
189 -- (Ada 2005): Subp may have a controlling access result.
191 if Subtypes_Statically_Match
(Typ
, Etype
(Subp
))
192 or else (Ekind
(Etype
(Subp
)) = E_Anonymous_Access_Type
194 Subtypes_Statically_Match
195 (Typ
, Designated_Type
(Etype
(Subp
))))
201 ("result subtype does not match controlling type", Subp
);
204 elsif Comes_From_Source
(Subp
) then
206 ("operation can be dispatching in only one type", Subp
);
210 end Check_Controlling_Formals
;
212 ----------------------------
213 -- Check_Controlling_Type --
214 ----------------------------
216 function Check_Controlling_Type
218 Subp
: Entity_Id
) return Entity_Id
220 Tagged_Type
: Entity_Id
:= Empty
;
223 if Is_Tagged_Type
(T
) then
224 if Is_First_Subtype
(T
) then
227 Tagged_Type
:= Base_Type
(T
);
230 elsif Ekind
(T
) = E_Anonymous_Access_Type
231 and then Is_Tagged_Type
(Designated_Type
(T
))
233 if Ekind
(Designated_Type
(T
)) /= E_Incomplete_Type
then
234 if Is_First_Subtype
(Designated_Type
(T
)) then
235 Tagged_Type
:= Designated_Type
(T
);
237 Tagged_Type
:= Base_Type
(Designated_Type
(T
));
240 -- Ada 2005: an incomplete type can be tagged. An operation with an
241 -- access parameter of the type is dispatching.
243 elsif Scope
(Designated_Type
(T
)) = Current_Scope
then
244 Tagged_Type
:= Designated_Type
(T
);
246 -- Ada 2005 (AI-50217)
248 elsif From_With_Type
(Designated_Type
(T
))
249 and then Present
(Non_Limited_View
(Designated_Type
(T
)))
251 if Is_First_Subtype
(Non_Limited_View
(Designated_Type
(T
))) then
252 Tagged_Type
:= Non_Limited_View
(Designated_Type
(T
));
254 Tagged_Type
:= Base_Type
(Non_Limited_View
255 (Designated_Type
(T
)));
260 if No
(Tagged_Type
) or else Is_Class_Wide_Type
(Tagged_Type
) then
263 -- The dispatching type and the primitive operation must be defined in
264 -- the same scope, except in the case of internal operations and formal
265 -- abstract subprograms.
267 elsif ((Scope
(Subp
) = Scope
(Tagged_Type
) or else Is_Internal
(Subp
))
268 and then (not Is_Generic_Type
(Tagged_Type
)
269 or else not Comes_From_Source
(Subp
)))
271 (Is_Formal_Subprogram
(Subp
) and then Is_Abstract_Subprogram
(Subp
))
273 (Nkind
(Parent
(Parent
(Subp
))) = N_Subprogram_Renaming_Declaration
275 Present
(Corresponding_Formal_Spec
(Parent
(Parent
(Subp
))))
277 Is_Abstract_Subprogram
(Subp
))
284 end Check_Controlling_Type
;
286 ----------------------------
287 -- Check_Dispatching_Call --
288 ----------------------------
290 procedure Check_Dispatching_Call
(N
: Node_Id
) is
291 Loc
: constant Source_Ptr
:= Sloc
(N
);
294 Control
: Node_Id
:= Empty
;
296 Subp_Entity
: Entity_Id
;
297 Indeterm_Ancestor_Call
: Boolean := False;
298 Indeterm_Ctrl_Type
: Entity_Id
;
300 Static_Tag
: Node_Id
:= Empty
;
301 -- If a controlling formal has a statically tagged actual, the tag of
302 -- this actual is to be used for any tag-indeterminate actual.
304 procedure Check_Direct_Call
;
305 -- In the case when the controlling actual is a class-wide type whose
306 -- root type's completion is a task or protected type, the call is in
307 -- fact direct. This routine detects the above case and modifies the
310 procedure Check_Dispatching_Context
;
311 -- If the call is tag-indeterminate and the entity being called is
312 -- abstract, verify that the context is a call that will eventually
313 -- provide a tag for dispatching, or has provided one already.
315 -----------------------
316 -- Check_Direct_Call --
317 -----------------------
319 procedure Check_Direct_Call
is
320 Typ
: Entity_Id
:= Etype
(Control
);
322 function Is_User_Defined_Equality
(Id
: Entity_Id
) return Boolean;
323 -- Determine whether an entity denotes a user-defined equality
325 ------------------------------
326 -- Is_User_Defined_Equality --
327 ------------------------------
329 function Is_User_Defined_Equality
(Id
: Entity_Id
) return Boolean is
332 Ekind
(Id
) = E_Function
333 and then Chars
(Id
) = Name_Op_Eq
334 and then Comes_From_Source
(Id
)
336 -- Internally generated equalities have a full type declaration
339 and then Nkind
(Parent
(Id
)) = N_Function_Specification
;
340 end Is_User_Defined_Equality
;
342 -- Start of processing for Check_Direct_Call
345 -- Predefined primitives do not receive wrappers since they are built
346 -- from scratch for the corresponding record of synchronized types.
347 -- Equality is in general predefined, but is excluded from the check
348 -- when it is user-defined.
350 if Is_Predefined_Dispatching_Operation
(Subp_Entity
)
351 and then not Is_User_Defined_Equality
(Subp_Entity
)
356 if Is_Class_Wide_Type
(Typ
) then
357 Typ
:= Root_Type
(Typ
);
360 if Is_Private_Type
(Typ
) and then Present
(Full_View
(Typ
)) then
361 Typ
:= Full_View
(Typ
);
364 if Is_Concurrent_Type
(Typ
)
366 Present
(Corresponding_Record_Type
(Typ
))
368 Typ
:= Corresponding_Record_Type
(Typ
);
370 -- The concurrent record's list of primitives should contain a
371 -- wrapper for the entity of the call, retrieve it.
376 Wrapper_Found
: Boolean := False;
379 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
380 while Present
(Prim_Elmt
) loop
381 Prim
:= Node
(Prim_Elmt
);
383 if Is_Primitive_Wrapper
(Prim
)
384 and then Wrapped_Entity
(Prim
) = Subp_Entity
386 Wrapper_Found
:= True;
390 Next_Elmt
(Prim_Elmt
);
393 -- A primitive declared between two views should have a
394 -- corresponding wrapper.
396 pragma Assert
(Wrapper_Found
);
398 -- Modify the call by setting the proper entity
400 Set_Entity
(Name
(N
), Prim
);
403 end Check_Direct_Call
;
405 -------------------------------
406 -- Check_Dispatching_Context --
407 -------------------------------
409 procedure Check_Dispatching_Context
is
410 Subp
: constant Entity_Id
:= Entity
(Name
(N
));
414 if Is_Abstract_Subprogram
(Subp
)
415 and then No
(Controlling_Argument
(N
))
417 if Present
(Alias
(Subp
))
418 and then not Is_Abstract_Subprogram
(Alias
(Subp
))
419 and then No
(DTC_Entity
(Subp
))
421 -- Private overriding of inherited abstract operation, call is
424 Set_Entity
(Name
(N
), Alias
(Subp
));
429 while Present
(Par
) loop
430 if Nkind_In
(Par
, N_Function_Call
,
431 N_Procedure_Call_Statement
,
432 N_Assignment_Statement
,
435 and then Is_Tagged_Type
(Etype
(Subp
))
439 elsif Nkind
(Par
) = N_Qualified_Expression
440 or else Nkind
(Par
) = N_Unchecked_Type_Conversion
445 if Ekind
(Subp
) = E_Function
then
447 ("call to abstract function must be dispatching", N
);
449 -- This error can occur for a procedure in the case of a
450 -- call to an abstract formal procedure with a statically
455 ("call to abstract procedure must be dispatching",
464 end Check_Dispatching_Context
;
466 -- Start of processing for Check_Dispatching_Call
469 -- Find a controlling argument, if any
471 if Present
(Parameter_Associations
(N
)) then
472 Subp_Entity
:= Entity
(Name
(N
));
474 Actual
:= First_Actual
(N
);
475 Formal
:= First_Formal
(Subp_Entity
);
476 while Present
(Actual
) loop
477 Control
:= Find_Controlling_Arg
(Actual
);
478 exit when Present
(Control
);
480 -- Check for the case where the actual is a tag-indeterminate call
481 -- whose result type is different than the tagged type associated
482 -- with the containing call, but is an ancestor of the type.
484 if Is_Controlling_Formal
(Formal
)
485 and then Is_Tag_Indeterminate
(Actual
)
486 and then Base_Type
(Etype
(Actual
)) /= Base_Type
(Etype
(Formal
))
487 and then Is_Ancestor
(Etype
(Actual
), Etype
(Formal
))
489 Indeterm_Ancestor_Call
:= True;
490 Indeterm_Ctrl_Type
:= Etype
(Formal
);
492 -- If the formal is controlling but the actual is not, the type
493 -- of the actual is statically known, and may be used as the
494 -- controlling tag for some other tag-indeterminate actual.
496 elsif Is_Controlling_Formal
(Formal
)
497 and then Is_Entity_Name
(Actual
)
498 and then Is_Tagged_Type
(Etype
(Actual
))
500 Static_Tag
:= Actual
;
503 Next_Actual
(Actual
);
504 Next_Formal
(Formal
);
507 -- If the call doesn't have a controlling actual but does have an
508 -- indeterminate actual that requires dispatching treatment, then an
509 -- object is needed that will serve as the controlling argument for a
510 -- dispatching call on the indeterminate actual. This can only occur
511 -- in the unusual situation of a default actual given by a
512 -- tag-indeterminate call and where the type of the call is an
513 -- ancestor of the type associated with a containing call to an
514 -- inherited operation (see AI-239).
516 -- Rather than create an object of the tagged type, which would be
517 -- problematic for various reasons (default initialization,
518 -- discriminants), the tag of the containing call's associated tagged
519 -- type is directly used to control the dispatching.
522 and then Indeterm_Ancestor_Call
523 and then No
(Static_Tag
)
526 Make_Attribute_Reference
(Loc
,
527 Prefix
=> New_Occurrence_Of
(Indeterm_Ctrl_Type
, Loc
),
528 Attribute_Name
=> Name_Tag
);
533 if Present
(Control
) then
535 -- Verify that no controlling arguments are statically tagged
538 Write_Str
("Found Dispatching call");
543 Actual
:= First_Actual
(N
);
544 while Present
(Actual
) loop
545 if Actual
/= Control
then
547 if not Is_Controlling_Actual
(Actual
) then
548 null; -- Can be anything
550 elsif Is_Dynamically_Tagged
(Actual
) then
551 null; -- Valid parameter
553 elsif Is_Tag_Indeterminate
(Actual
) then
555 -- The tag is inherited from the enclosing call (the node
556 -- we are currently analyzing). Explicitly expand the
557 -- actual, since the previous call to Expand (from
558 -- Resolve_Call) had no way of knowing about the required
561 Propagate_Tag
(Control
, Actual
);
565 ("controlling argument is not dynamically tagged",
571 Next_Actual
(Actual
);
574 -- Mark call as a dispatching call
576 Set_Controlling_Argument
(N
, Control
);
577 Check_Restriction
(No_Dispatching_Calls
, N
);
579 -- The dispatching call may need to be converted into a direct
580 -- call in certain cases.
584 -- If there is a statically tagged actual and a tag-indeterminate
585 -- call to a function of the ancestor (such as that provided by a
586 -- default), then treat this as a dispatching call and propagate
587 -- the tag to the tag-indeterminate call(s).
589 elsif Present
(Static_Tag
) and then Indeterm_Ancestor_Call
then
591 Make_Attribute_Reference
(Loc
,
593 New_Occurrence_Of
(Etype
(Static_Tag
), Loc
),
594 Attribute_Name
=> Name_Tag
);
598 Actual
:= First_Actual
(N
);
599 Formal
:= First_Formal
(Subp_Entity
);
600 while Present
(Actual
) loop
601 if Is_Tag_Indeterminate
(Actual
)
602 and then Is_Controlling_Formal
(Formal
)
604 Propagate_Tag
(Control
, Actual
);
607 Next_Actual
(Actual
);
608 Next_Formal
(Formal
);
611 Check_Dispatching_Context
;
614 -- The call is not dispatching, so check that there aren't any
615 -- tag-indeterminate abstract calls left.
617 Actual
:= First_Actual
(N
);
618 while Present
(Actual
) loop
619 if Is_Tag_Indeterminate
(Actual
) then
621 -- Function call case
623 if Nkind
(Original_Node
(Actual
)) = N_Function_Call
then
624 Func
:= Entity
(Name
(Original_Node
(Actual
)));
626 -- If the actual is an attribute then it can't be abstract
627 -- (the only current case of a tag-indeterminate attribute
628 -- is the stream Input attribute).
631 Nkind
(Original_Node
(Actual
)) = N_Attribute_Reference
635 -- Only other possibility is a qualified expression whose
636 -- constituent expression is itself a call.
642 (Expression
(Original_Node
(Actual
)))));
645 if Present
(Func
) and then Is_Abstract_Subprogram
(Func
) then
647 "call to abstract function must be dispatching", N
);
651 Next_Actual
(Actual
);
654 Check_Dispatching_Context
;
658 -- If dispatching on result, the enclosing call, if any, will
659 -- determine the controlling argument. Otherwise this is the
660 -- primitive operation of the root type.
662 Check_Dispatching_Context
;
664 end Check_Dispatching_Call
;
666 ---------------------------------
667 -- Check_Dispatching_Operation --
668 ---------------------------------
670 procedure Check_Dispatching_Operation
(Subp
, Old_Subp
: Entity_Id
) is
671 Tagged_Type
: Entity_Id
;
672 Has_Dispatching_Parent
: Boolean := False;
673 Body_Is_Last_Primitive
: Boolean := False;
676 if Ekind
(Subp
) /= E_Procedure
and then Ekind
(Subp
) /= E_Function
then
680 Set_Is_Dispatching_Operation
(Subp
, False);
681 Tagged_Type
:= Find_Dispatching_Type
(Subp
);
685 if Ada_Version
= Ada_05
686 and then Present
(Tagged_Type
)
687 and then Is_Concurrent_Type
(Tagged_Type
)
689 -- Protect the frontend against previously detected errors
691 if No
(Corresponding_Record_Type
(Tagged_Type
)) then
695 Tagged_Type
:= Corresponding_Record_Type
(Tagged_Type
);
698 -- (AI-345): The task body procedure is not a primitive of the tagged
701 if Present
(Tagged_Type
)
702 and then Is_Concurrent_Record_Type
(Tagged_Type
)
703 and then Present
(Corresponding_Concurrent_Type
(Tagged_Type
))
704 and then Is_Task_Type
(Corresponding_Concurrent_Type
(Tagged_Type
))
705 and then Subp
= Get_Task_Body_Procedure
706 (Corresponding_Concurrent_Type
(Tagged_Type
))
711 -- If Subp is derived from a dispatching operation then it should
712 -- always be treated as dispatching. In this case various checks
713 -- below will be bypassed. Makes sure that late declarations for
714 -- inherited private subprograms are treated as dispatching, even
715 -- if the associated tagged type is already frozen.
717 Has_Dispatching_Parent
:=
718 Present
(Alias
(Subp
))
719 and then Is_Dispatching_Operation
(Alias
(Subp
));
721 if No
(Tagged_Type
) then
723 -- Ada 2005 (AI-251): Check that Subp is not a primitive associated
724 -- with an abstract interface type unless the interface acts as a
725 -- parent type in a derivation. If the interface type is a formal
726 -- type then the operation is not primitive and therefore legal.
733 E
:= First_Entity
(Subp
);
734 while Present
(E
) loop
736 -- For an access parameter, check designated type
738 if Ekind
(Etype
(E
)) = E_Anonymous_Access_Type
then
739 Typ
:= Designated_Type
(Etype
(E
));
744 if Comes_From_Source
(Subp
)
745 and then Is_Interface
(Typ
)
746 and then not Is_Class_Wide_Type
(Typ
)
747 and then not Is_Derived_Type
(Typ
)
748 and then not Is_Generic_Type
(Typ
)
749 and then not In_Instance
751 Error_Msg_N
("?declaration of& is too late!", Subp
);
753 ("\spec should appear immediately after declaration of &!",
761 -- In case of functions check also the result type
763 if Ekind
(Subp
) = E_Function
then
764 if Is_Access_Type
(Etype
(Subp
)) then
765 Typ
:= Designated_Type
(Etype
(Subp
));
770 if not Is_Class_Wide_Type
(Typ
)
771 and then Is_Interface
(Typ
)
772 and then not Is_Derived_Type
(Typ
)
774 Error_Msg_N
("?declaration of& is too late!", Subp
);
776 ("\spec should appear immediately after declaration of &!",
784 -- The subprograms build internally after the freezing point (such as
785 -- init procs, interface thunks, type support subprograms, and Offset
786 -- to top functions for accessing interface components in variable
787 -- size tagged types) are not primitives.
789 elsif Is_Frozen
(Tagged_Type
)
790 and then not Comes_From_Source
(Subp
)
791 and then not Has_Dispatching_Parent
793 -- Complete decoration if internally built subprograms that override
794 -- a dispatching primitive. These entities correspond with the
797 -- 1. Ada 2005 (AI-391): Wrapper functions built by the expander
798 -- to override functions of nonabstract null extensions. These
799 -- primitives were added to the list of primitives of the tagged
800 -- type by Make_Controlling_Function_Wrappers. However, attribute
801 -- Is_Dispatching_Operation must be set to true.
803 -- 2. Subprograms associated with stream attributes (built by
804 -- New_Stream_Subprogram)
806 if Present
(Old_Subp
)
807 and then Is_Overriding_Operation
(Subp
)
808 and then Is_Dispatching_Operation
(Old_Subp
)
811 ((Ekind
(Subp
) = E_Function
812 and then Is_Dispatching_Operation
(Old_Subp
)
813 and then Is_Null_Extension
(Base_Type
(Etype
(Subp
))))
814 or else Get_TSS_Name
(Subp
) = TSS_Stream_Read
815 or else Get_TSS_Name
(Subp
) = TSS_Stream_Write
);
817 Set_Is_Dispatching_Operation
(Subp
);
822 -- The operation may be a child unit, whose scope is the defining
823 -- package, but which is not a primitive operation of the type.
825 elsif Is_Child_Unit
(Subp
) then
828 -- If the subprogram is not defined in a package spec, the only case
829 -- where it can be a dispatching op is when it overrides an operation
830 -- before the freezing point of the type.
832 elsif ((not Is_Package_Or_Generic_Package
(Scope
(Subp
)))
833 or else In_Package_Body
(Scope
(Subp
)))
834 and then not Has_Dispatching_Parent
836 if not Comes_From_Source
(Subp
)
837 or else (Present
(Old_Subp
) and then not Is_Frozen
(Tagged_Type
))
841 -- If the type is already frozen, the overriding is not allowed
842 -- except when Old_Subp is not a dispatching operation (which can
843 -- occur when Old_Subp was inherited by an untagged type). However,
844 -- a body with no previous spec freezes the type *after* its
845 -- declaration, and therefore is a legal overriding (unless the type
846 -- has already been frozen). Only the first such body is legal.
848 elsif Present
(Old_Subp
)
849 and then Is_Dispatching_Operation
(Old_Subp
)
851 if Comes_From_Source
(Subp
)
853 (Nkind
(Unit_Declaration_Node
(Subp
)) = N_Subprogram_Body
854 or else Nkind
(Unit_Declaration_Node
(Subp
)) in N_Body_Stub
)
857 Subp_Body
: constant Node_Id
:= Unit_Declaration_Node
(Subp
);
861 -- ??? The checks here for whether the type has been
862 -- frozen prior to the new body are not complete. It's
863 -- not simple to check frozenness at this point since
864 -- the body has already caused the type to be prematurely
865 -- frozen in Analyze_Declarations, but we're forced to
866 -- recheck this here because of the odd rule interpretation
867 -- that allows the overriding if the type wasn't frozen
868 -- prior to the body. The freezing action should probably
869 -- be delayed until after the spec is seen, but that's
870 -- a tricky change to the delicate freezing code.
872 -- Look at each declaration following the type up until the
873 -- new subprogram body. If any of the declarations is a body
874 -- then the type has been frozen already so the overriding
875 -- primitive is illegal.
877 Decl_Item
:= Next
(Parent
(Tagged_Type
));
878 while Present
(Decl_Item
)
879 and then (Decl_Item
/= Subp_Body
)
881 if Comes_From_Source
(Decl_Item
)
882 and then (Nkind
(Decl_Item
) in N_Proper_Body
883 or else Nkind
(Decl_Item
) in N_Body_Stub
)
885 Error_Msg_N
("overriding of& is too late!", Subp
);
887 ("\spec should appear immediately after the type!",
895 -- If the subprogram doesn't follow in the list of
896 -- declarations including the type then the type has
897 -- definitely been frozen already and the body is illegal.
899 if No
(Decl_Item
) then
900 Error_Msg_N
("overriding of& is too late!", Subp
);
902 ("\spec should appear immediately after the type!",
905 elsif Is_Frozen
(Subp
) then
907 -- The subprogram body declares a primitive operation.
908 -- if the subprogram is already frozen, we must update
909 -- its dispatching information explicitly here. The
910 -- information is taken from the overridden subprogram.
911 -- We must also generate a cross-reference entry because
912 -- references to other primitives were already created
913 -- when type was frozen.
915 Body_Is_Last_Primitive
:= True;
917 if Present
(DTC_Entity
(Old_Subp
)) then
918 Set_DTC_Entity
(Subp
, DTC_Entity
(Old_Subp
));
919 Set_DT_Position
(Subp
, DT_Position
(Old_Subp
));
921 if not Restriction_Active
(No_Dispatching_Calls
) then
922 if Building_Static_DT
(Tagged_Type
) then
924 -- If the static dispatch table has not been
925 -- built then there is nothing else to do now;
926 -- otherwise we notify that we cannot build the
927 -- static dispatch table.
929 if Has_Dispatch_Table
(Tagged_Type
) then
931 ("overriding of& is too late for building" &
932 " static dispatch tables!", Subp
);
934 ("\spec should appear immediately after" &
939 Insert_Actions_After
(Subp_Body
,
940 Register_Primitive
(Sloc
(Subp_Body
),
944 -- Indicate that this is an overriding operation,
945 -- and replace the overriden entry in the list of
946 -- primitive operations, which is used for xref
947 -- generation subsequently.
949 Generate_Reference
(Tagged_Type
, Subp
, 'P', False);
950 Override_Dispatching_Operation
951 (Tagged_Type
, Old_Subp
, Subp
);
958 Error_Msg_N
("overriding of& is too late!", Subp
);
960 ("\subprogram spec should appear immediately after the type!",
964 -- If the type is not frozen yet and we are not in the overriding
965 -- case it looks suspiciously like an attempt to define a primitive
966 -- operation, which requires the declaration to be in a package spec
969 elsif not Is_Frozen
(Tagged_Type
) then
971 ("?not dispatching (must be defined in a package spec)", Subp
);
974 -- When the type is frozen, it is legitimate to define a new
975 -- non-primitive operation.
981 -- Now, we are sure that the scope is a package spec. If the subprogram
982 -- is declared after the freezing point of the type that's an error
984 elsif Is_Frozen
(Tagged_Type
) and then not Has_Dispatching_Parent
then
985 Error_Msg_N
("this primitive operation is declared too late", Subp
);
987 ("?no primitive operations for& after this line",
988 Freeze_Node
(Tagged_Type
),
993 Check_Controlling_Formals
(Tagged_Type
, Subp
);
995 -- Now it should be a correct primitive operation, put it in the list
997 if Present
(Old_Subp
) then
999 -- If the type has interfaces we complete this check after we set
1000 -- attribute Is_Dispatching_Operation.
1002 Check_Subtype_Conformant
(Subp
, Old_Subp
);
1004 if (Chars
(Subp
) = Name_Initialize
1005 or else Chars
(Subp
) = Name_Adjust
1006 or else Chars
(Subp
) = Name_Finalize
)
1007 and then Is_Controlled
(Tagged_Type
)
1008 and then not Is_Visibly_Controlled
(Tagged_Type
)
1010 Set_Is_Overriding_Operation
(Subp
, False);
1012 -- If the subprogram specification carries an overriding
1013 -- indicator, no need for the warning: it is either redundant,
1014 -- or else an error will be reported.
1016 if Nkind
(Parent
(Subp
)) = N_Procedure_Specification
1018 (Must_Override
(Parent
(Subp
))
1019 or else Must_Not_Override
(Parent
(Subp
)))
1023 -- Here we need the warning
1027 ("operation does not override inherited&?", Subp
, Subp
);
1031 Override_Dispatching_Operation
(Tagged_Type
, Old_Subp
, Subp
);
1032 Set_Is_Overriding_Operation
(Subp
);
1034 -- Ada 2005 (AI-251): In case of late overriding of a primitive
1035 -- that covers abstract interface subprograms we must register it
1036 -- in all the secondary dispatch tables associated with abstract
1037 -- interfaces. We do this now only if not building static tables.
1038 -- Otherwise the patch code is emitted after those tables are
1039 -- built, to prevent access_before_elaboration in gigi.
1041 if Body_Is_Last_Primitive
then
1043 Subp_Body
: constant Node_Id
:= Unit_Declaration_Node
(Subp
);
1048 Elmt
:= First_Elmt
(Primitive_Operations
(Tagged_Type
));
1049 while Present
(Elmt
) loop
1050 Prim
:= Node
(Elmt
);
1052 if Present
(Alias
(Prim
))
1053 and then Present
(Interface_Alias
(Prim
))
1054 and then Alias
(Prim
) = Subp
1055 and then not Building_Static_DT
(Tagged_Type
)
1057 Insert_Actions_After
(Subp_Body
,
1058 Register_Primitive
(Sloc
(Subp_Body
), Prim
=> Prim
));
1064 -- Redisplay the contents of the updated dispatch table
1066 if Debug_Flag_ZZ
then
1067 Write_Str
("Late overriding: ");
1068 Write_DT
(Tagged_Type
);
1074 -- If no old subprogram, then we add this as a dispatching operation,
1075 -- but we avoid doing this if an error was posted, to prevent annoying
1078 elsif not Error_Posted
(Subp
) then
1079 Add_Dispatching_Operation
(Tagged_Type
, Subp
);
1082 Set_Is_Dispatching_Operation
(Subp
, True);
1084 -- Ada 2005 (AI-251): If the type implements interfaces we must check
1085 -- subtype conformance against all the interfaces covered by this
1088 if Present
(Old_Subp
)
1089 and then Has_Interfaces
(Tagged_Type
)
1092 Ifaces_List
: Elist_Id
;
1093 Iface_Elmt
: Elmt_Id
;
1094 Iface_Prim_Elmt
: Elmt_Id
;
1095 Iface_Prim
: Entity_Id
;
1096 Ret_Typ
: Entity_Id
;
1099 Collect_Interfaces
(Tagged_Type
, Ifaces_List
);
1101 Iface_Elmt
:= First_Elmt
(Ifaces_List
);
1102 while Present
(Iface_Elmt
) loop
1103 if not Is_Ancestor
(Node
(Iface_Elmt
), Tagged_Type
) then
1105 First_Elmt
(Primitive_Operations
(Node
(Iface_Elmt
)));
1106 while Present
(Iface_Prim_Elmt
) loop
1107 Iface_Prim
:= Node
(Iface_Prim_Elmt
);
1109 if Is_Interface_Conformant
1110 (Tagged_Type
, Iface_Prim
, Subp
)
1112 -- Handle procedures, functions whose return type
1113 -- matches, or functions not returning interfaces
1115 if Ekind
(Subp
) = E_Procedure
1116 or else Etype
(Iface_Prim
) = Etype
(Subp
)
1117 or else not Is_Interface
(Etype
(Iface_Prim
))
1119 Check_Subtype_Conformant
1121 Old_Id
=> Iface_Prim
,
1123 Skip_Controlling_Formals
=> True);
1125 -- Handle functions returning interfaces
1127 elsif Implements_Interface
1128 (Etype
(Subp
), Etype
(Iface_Prim
))
1130 -- Temporarily force both entities to return the
1131 -- same type. Required because Subtype_Conformant
1132 -- does not handle this case.
1134 Ret_Typ
:= Etype
(Iface_Prim
);
1135 Set_Etype
(Iface_Prim
, Etype
(Subp
));
1137 Check_Subtype_Conformant
1139 Old_Id
=> Iface_Prim
,
1141 Skip_Controlling_Formals
=> True);
1143 Set_Etype
(Iface_Prim
, Ret_Typ
);
1147 Next_Elmt
(Iface_Prim_Elmt
);
1151 Next_Elmt
(Iface_Elmt
);
1156 if not Body_Is_Last_Primitive
then
1157 Set_DT_Position
(Subp
, No_Uint
);
1159 elsif Has_Controlled_Component
(Tagged_Type
)
1161 (Chars
(Subp
) = Name_Initialize
1163 Chars
(Subp
) = Name_Adjust
1165 Chars
(Subp
) = Name_Finalize
)
1168 F_Node
: constant Node_Id
:= Freeze_Node
(Tagged_Type
);
1172 Old_Spec
: Entity_Id
;
1174 C_Names
: constant array (1 .. 3) of Name_Id
:=
1179 D_Names
: constant array (1 .. 3) of TSS_Name_Type
:=
1180 (TSS_Deep_Initialize
,
1185 -- Remove previous controlled function which was constructed and
1186 -- analyzed when the type was frozen. This requires removing the
1187 -- body of the redefined primitive, as well as its specification
1188 -- if needed (there is no spec created for Deep_Initialize, see
1189 -- exp_ch3.adb). We must also dismantle the exception information
1190 -- that may have been generated for it when front end zero-cost
1191 -- tables are enabled.
1193 for J
in D_Names
'Range loop
1194 Old_P
:= TSS
(Tagged_Type
, D_Names
(J
));
1197 and then Chars
(Subp
) = C_Names
(J
)
1199 Old_Bod
:= Unit_Declaration_Node
(Old_P
);
1201 Set_Is_Eliminated
(Old_P
);
1202 Set_Scope
(Old_P
, Scope
(Current_Scope
));
1204 if Nkind
(Old_Bod
) = N_Subprogram_Body
1205 and then Present
(Corresponding_Spec
(Old_Bod
))
1207 Old_Spec
:= Corresponding_Spec
(Old_Bod
);
1208 Set_Has_Completion
(Old_Spec
, False);
1213 Build_Late_Proc
(Tagged_Type
, Chars
(Subp
));
1215 -- The new operation is added to the actions of the freeze node
1216 -- for the type, but this node has already been analyzed, so we
1217 -- must retrieve and analyze explicitly the new body.
1220 and then Present
(Actions
(F_Node
))
1222 Decl
:= Last
(Actions
(F_Node
));
1227 end Check_Dispatching_Operation
;
1229 ------------------------------------------
1230 -- Check_Operation_From_Incomplete_Type --
1231 ------------------------------------------
1233 procedure Check_Operation_From_Incomplete_Type
1237 Full
: constant Entity_Id
:= Full_View
(Typ
);
1238 Parent_Typ
: constant Entity_Id
:= Etype
(Full
);
1239 Old_Prim
: constant Elist_Id
:= Primitive_Operations
(Parent_Typ
);
1240 New_Prim
: constant Elist_Id
:= Primitive_Operations
(Full
);
1242 Prev
: Elmt_Id
:= No_Elmt
;
1244 function Derives_From
(Proc
: Entity_Id
) return Boolean;
1245 -- Check that Subp has the signature of an operation derived from Proc.
1246 -- Subp has an access parameter that designates Typ.
1252 function Derives_From
(Proc
: Entity_Id
) return Boolean is
1256 if Chars
(Proc
) /= Chars
(Subp
) then
1260 F1
:= First_Formal
(Proc
);
1261 F2
:= First_Formal
(Subp
);
1262 while Present
(F1
) and then Present
(F2
) loop
1263 if Ekind
(Etype
(F1
)) = E_Anonymous_Access_Type
then
1264 if Ekind
(Etype
(F2
)) /= E_Anonymous_Access_Type
then
1266 elsif Designated_Type
(Etype
(F1
)) = Parent_Typ
1267 and then Designated_Type
(Etype
(F2
)) /= Full
1272 elsif Ekind
(Etype
(F2
)) = E_Anonymous_Access_Type
then
1275 elsif Etype
(F1
) /= Etype
(F2
) then
1283 return No
(F1
) and then No
(F2
);
1286 -- Start of processing for Check_Operation_From_Incomplete_Type
1289 -- The operation may override an inherited one, or may be a new one
1290 -- altogether. The inherited operation will have been hidden by the
1291 -- current one at the point of the type derivation, so it does not
1292 -- appear in the list of primitive operations of the type. We have to
1293 -- find the proper place of insertion in the list of primitive opera-
1294 -- tions by iterating over the list for the parent type.
1296 Op1
:= First_Elmt
(Old_Prim
);
1297 Op2
:= First_Elmt
(New_Prim
);
1298 while Present
(Op1
) and then Present
(Op2
) loop
1299 if Derives_From
(Node
(Op1
)) then
1302 -- Avoid adding it to the list of primitives if already there!
1304 if Node
(Op2
) /= Subp
then
1305 Prepend_Elmt
(Subp
, New_Prim
);
1309 Insert_Elmt_After
(Subp
, Prev
);
1320 -- Operation is a new primitive
1322 Append_Elmt
(Subp
, New_Prim
);
1323 end Check_Operation_From_Incomplete_Type
;
1325 ---------------------------------------
1326 -- Check_Operation_From_Private_View --
1327 ---------------------------------------
1329 procedure Check_Operation_From_Private_View
(Subp
, Old_Subp
: Entity_Id
) is
1330 Tagged_Type
: Entity_Id
;
1333 if Is_Dispatching_Operation
(Alias
(Subp
)) then
1334 Set_Scope
(Subp
, Current_Scope
);
1335 Tagged_Type
:= Find_Dispatching_Type
(Subp
);
1337 -- Add Old_Subp to primitive operations if not already present
1339 if Present
(Tagged_Type
) and then Is_Tagged_Type
(Tagged_Type
) then
1340 Append_Unique_Elmt
(Old_Subp
, Primitive_Operations
(Tagged_Type
));
1342 -- If Old_Subp isn't already marked as dispatching then
1343 -- this is the case of an operation of an untagged private
1344 -- type fulfilled by a tagged type that overrides an
1345 -- inherited dispatching operation, so we set the necessary
1346 -- dispatching attributes here.
1348 if not Is_Dispatching_Operation
(Old_Subp
) then
1350 -- If the untagged type has no discriminants, and the full
1351 -- view is constrained, there will be a spurious mismatch
1352 -- of subtypes on the controlling arguments, because the tagged
1353 -- type is the internal base type introduced in the derivation.
1354 -- Use the original type to verify conformance, rather than the
1357 if not Comes_From_Source
(Tagged_Type
)
1358 and then Has_Discriminants
(Tagged_Type
)
1364 Formal
:= First_Formal
(Old_Subp
);
1365 while Present
(Formal
) loop
1366 if Tagged_Type
= Base_Type
(Etype
(Formal
)) then
1367 Tagged_Type
:= Etype
(Formal
);
1370 Next_Formal
(Formal
);
1374 if Tagged_Type
= Base_Type
(Etype
(Old_Subp
)) then
1375 Tagged_Type
:= Etype
(Old_Subp
);
1379 Check_Controlling_Formals
(Tagged_Type
, Old_Subp
);
1380 Set_Is_Dispatching_Operation
(Old_Subp
, True);
1381 Set_DT_Position
(Old_Subp
, No_Uint
);
1384 -- If the old subprogram is an explicit renaming of some other
1385 -- entity, it is not overridden by the inherited subprogram.
1386 -- Otherwise, update its alias and other attributes.
1388 if Present
(Alias
(Old_Subp
))
1389 and then Nkind
(Unit_Declaration_Node
(Old_Subp
)) /=
1390 N_Subprogram_Renaming_Declaration
1392 Set_Alias
(Old_Subp
, Alias
(Subp
));
1394 -- The derived subprogram should inherit the abstractness
1395 -- of the parent subprogram (except in the case of a function
1396 -- returning the type). This sets the abstractness properly
1397 -- for cases where a private extension may have inherited
1398 -- an abstract operation, but the full type is derived from
1399 -- a descendant type and inherits a nonabstract version.
1401 if Etype
(Subp
) /= Tagged_Type
then
1402 Set_Is_Abstract_Subprogram
1403 (Old_Subp
, Is_Abstract_Subprogram
(Alias
(Subp
)));
1408 end Check_Operation_From_Private_View
;
1410 --------------------------
1411 -- Find_Controlling_Arg --
1412 --------------------------
1414 function Find_Controlling_Arg
(N
: Node_Id
) return Node_Id
is
1415 Orig_Node
: constant Node_Id
:= Original_Node
(N
);
1419 if Nkind
(Orig_Node
) = N_Qualified_Expression
then
1420 return Find_Controlling_Arg
(Expression
(Orig_Node
));
1423 -- Dispatching on result case. If expansion is disabled, the node still
1424 -- has the structure of a function call. However, if the function name
1425 -- is an operator and the call was given in infix form, the original
1426 -- node has no controlling result and we must examine the current node.
1428 if Nkind
(N
) = N_Function_Call
1429 and then Present
(Controlling_Argument
(N
))
1430 and then Has_Controlling_Result
(Entity
(Name
(N
)))
1432 return Controlling_Argument
(N
);
1434 -- If expansion is enabled, the call may have been transformed into
1435 -- an indirect call, and we need to recover the original node.
1437 elsif Nkind
(Orig_Node
) = N_Function_Call
1438 and then Present
(Controlling_Argument
(Orig_Node
))
1439 and then Has_Controlling_Result
(Entity
(Name
(Orig_Node
)))
1441 return Controlling_Argument
(Orig_Node
);
1445 elsif Is_Controlling_Actual
(N
)
1447 (Nkind
(Parent
(N
)) = N_Qualified_Expression
1448 and then Is_Controlling_Actual
(Parent
(N
)))
1452 if Is_Access_Type
(Typ
) then
1454 -- In the case of an Access attribute, use the type of the prefix,
1455 -- since in the case of an actual for an access parameter, the
1456 -- attribute's type may be of a specific designated type, even
1457 -- though the prefix type is class-wide.
1459 if Nkind
(N
) = N_Attribute_Reference
then
1460 Typ
:= Etype
(Prefix
(N
));
1462 -- An allocator is dispatching if the type of qualified expression
1463 -- is class_wide, in which case this is the controlling type.
1465 elsif Nkind
(Orig_Node
) = N_Allocator
1466 and then Nkind
(Expression
(Orig_Node
)) = N_Qualified_Expression
1468 Typ
:= Etype
(Expression
(Orig_Node
));
1470 Typ
:= Designated_Type
(Typ
);
1474 if Is_Class_Wide_Type
(Typ
)
1476 (Nkind
(Parent
(N
)) = N_Qualified_Expression
1477 and then Is_Access_Type
(Etype
(N
))
1478 and then Is_Class_Wide_Type
(Designated_Type
(Etype
(N
))))
1485 end Find_Controlling_Arg
;
1487 ---------------------------
1488 -- Find_Dispatching_Type --
1489 ---------------------------
1491 function Find_Dispatching_Type
(Subp
: Entity_Id
) return Entity_Id
is
1492 A_Formal
: Entity_Id
;
1494 Ctrl_Type
: Entity_Id
;
1497 if Present
(DTC_Entity
(Subp
)) then
1498 return Scope
(DTC_Entity
(Subp
));
1500 -- For subprograms internally generated by derivations of tagged types
1501 -- use the alias subprogram as a reference to locate the dispatching
1504 elsif not Comes_From_Source
(Subp
)
1505 and then Present
(Alias
(Subp
))
1506 and then Is_Dispatching_Operation
(Alias
(Subp
))
1508 if Ekind
(Alias
(Subp
)) = E_Function
1509 and then Has_Controlling_Result
(Alias
(Subp
))
1511 return Check_Controlling_Type
(Etype
(Subp
), Subp
);
1514 Formal
:= First_Formal
(Subp
);
1515 A_Formal
:= First_Formal
(Alias
(Subp
));
1516 while Present
(A_Formal
) loop
1517 if Is_Controlling_Formal
(A_Formal
) then
1518 return Check_Controlling_Type
(Etype
(Formal
), Subp
);
1521 Next_Formal
(Formal
);
1522 Next_Formal
(A_Formal
);
1525 pragma Assert
(False);
1532 Formal
:= First_Formal
(Subp
);
1533 while Present
(Formal
) loop
1534 Ctrl_Type
:= Check_Controlling_Type
(Etype
(Formal
), Subp
);
1536 if Present
(Ctrl_Type
) then
1540 Next_Formal
(Formal
);
1543 -- The subprogram may also be dispatching on result
1545 if Present
(Etype
(Subp
)) then
1546 return Check_Controlling_Type
(Etype
(Subp
), Subp
);
1550 pragma Assert
(not Is_Dispatching_Operation
(Subp
));
1552 end Find_Dispatching_Type
;
1554 ---------------------------------------
1555 -- Find_Primitive_Covering_Interface --
1556 ---------------------------------------
1558 function Find_Primitive_Covering_Interface
1559 (Tagged_Type
: Entity_Id
;
1560 Iface_Prim
: Entity_Id
) return Entity_Id
1565 pragma Assert
(Is_Interface
(Find_Dispatching_Type
(Iface_Prim
))
1566 or else (Present
(Alias
(Iface_Prim
))
1569 (Find_Dispatching_Type
(Ultimate_Alias
(Iface_Prim
)))));
1571 E
:= Current_Entity
(Iface_Prim
);
1572 while Present
(E
) loop
1573 if Is_Subprogram
(E
)
1574 and then Is_Dispatching_Operation
(E
)
1575 and then Is_Interface_Conformant
(Tagged_Type
, Iface_Prim
, E
)
1584 end Find_Primitive_Covering_Interface
;
1586 ---------------------------
1587 -- Is_Dynamically_Tagged --
1588 ---------------------------
1590 function Is_Dynamically_Tagged
(N
: Node_Id
) return Boolean is
1592 if Nkind
(N
) = N_Error
then
1595 return Find_Controlling_Arg
(N
) /= Empty
;
1597 end Is_Dynamically_Tagged
;
1599 --------------------------
1600 -- Is_Tag_Indeterminate --
1601 --------------------------
1603 function Is_Tag_Indeterminate
(N
: Node_Id
) return Boolean is
1606 Orig_Node
: constant Node_Id
:= Original_Node
(N
);
1609 if Nkind
(Orig_Node
) = N_Function_Call
1610 and then Is_Entity_Name
(Name
(Orig_Node
))
1612 Nam
:= Entity
(Name
(Orig_Node
));
1614 if not Has_Controlling_Result
(Nam
) then
1617 -- An explicit dereference means that the call has already been
1618 -- expanded and there is no tag to propagate.
1620 elsif Nkind
(N
) = N_Explicit_Dereference
then
1623 -- If there are no actuals, the call is tag-indeterminate
1625 elsif No
(Parameter_Associations
(Orig_Node
)) then
1629 Actual
:= First_Actual
(Orig_Node
);
1630 while Present
(Actual
) loop
1631 if Is_Controlling_Actual
(Actual
)
1632 and then not Is_Tag_Indeterminate
(Actual
)
1634 return False; -- one operand is dispatching
1637 Next_Actual
(Actual
);
1643 elsif Nkind
(Orig_Node
) = N_Qualified_Expression
then
1644 return Is_Tag_Indeterminate
(Expression
(Orig_Node
));
1646 -- Case of a call to the Input attribute (possibly rewritten), which is
1647 -- always tag-indeterminate except when its prefix is a Class attribute.
1649 elsif Nkind
(Orig_Node
) = N_Attribute_Reference
1651 Get_Attribute_Id
(Attribute_Name
(Orig_Node
)) = Attribute_Input
1653 Nkind
(Prefix
(Orig_Node
)) /= N_Attribute_Reference
1657 -- In Ada 2005 a function that returns an anonymous access type can
1658 -- dispatching, and the dereference of a call to such a function
1659 -- is also tag-indeterminate.
1661 elsif Nkind
(Orig_Node
) = N_Explicit_Dereference
1662 and then Ada_Version
>= Ada_05
1664 return Is_Tag_Indeterminate
(Prefix
(Orig_Node
));
1669 end Is_Tag_Indeterminate
;
1671 ------------------------------------
1672 -- Override_Dispatching_Operation --
1673 ------------------------------------
1675 procedure Override_Dispatching_Operation
1676 (Tagged_Type
: Entity_Id
;
1677 Prev_Op
: Entity_Id
;
1684 -- Diagnose failure to match No_Return in parent (Ada-2005, AI-414, but
1685 -- we do it unconditionally in Ada 95 now, since this is our pragma!)
1687 if No_Return
(Prev_Op
) and then not No_Return
(New_Op
) then
1688 Error_Msg_N
("procedure & must have No_Return pragma", New_Op
);
1689 Error_Msg_N
("\since overridden procedure has No_Return", New_Op
);
1692 -- If there is no previous operation to override, the type declaration
1693 -- was malformed, and an error must have been emitted already.
1695 Elmt
:= First_Elmt
(Primitive_Operations
(Tagged_Type
));
1696 while Present
(Elmt
)
1697 and then Node
(Elmt
) /= Prev_Op
1706 Replace_Elmt
(Elmt
, New_Op
);
1708 if Ada_Version
>= Ada_05
1709 and then Has_Interfaces
(Tagged_Type
)
1711 -- Ada 2005 (AI-251): Update the attribute alias of all the aliased
1712 -- entities of the overridden primitive to reference New_Op, and also
1713 -- propagate the proper value of Is_Abstract_Subprogram. Verify
1714 -- that the new operation is subtype conformant with the interface
1715 -- operations that it implements (for operations inherited from the
1716 -- parent itself, this check is made when building the derived type).
1718 -- Note: This code is only executed in case of late overriding
1720 Elmt
:= First_Elmt
(Primitive_Operations
(Tagged_Type
));
1721 while Present
(Elmt
) loop
1722 Prim
:= Node
(Elmt
);
1724 if Prim
= New_Op
then
1727 -- Note: The check on Is_Subprogram protects the frontend against
1728 -- reading attributes in entities that are not yet fully decorated
1730 elsif Is_Subprogram
(Prim
)
1731 and then Present
(Interface_Alias
(Prim
))
1732 and then Alias
(Prim
) = Prev_Op
1733 and then Present
(Etype
(New_Op
))
1735 Set_Alias
(Prim
, New_Op
);
1736 Check_Subtype_Conformant
(New_Op
, Prim
);
1737 Set_Is_Abstract_Subprogram
(Prim
,
1738 Is_Abstract_Subprogram
(New_Op
));
1740 -- Ensure that this entity will be expanded to fill the
1741 -- corresponding entry in its dispatch table.
1743 if not Is_Abstract_Subprogram
(Prim
) then
1744 Set_Has_Delayed_Freeze
(Prim
);
1752 if (not Is_Package_Or_Generic_Package
(Current_Scope
))
1753 or else not In_Private_Part
(Current_Scope
)
1755 -- Not a private primitive
1759 else pragma Assert
(Is_Inherited_Operation
(Prev_Op
));
1761 -- Make the overriding operation into an alias of the implicit one.
1762 -- In this fashion a call from outside ends up calling the new body
1763 -- even if non-dispatching, and a call from inside calls the
1764 -- overriding operation because it hides the implicit one. To
1765 -- indicate that the body of Prev_Op is never called, set its
1766 -- dispatch table entity to Empty. If the overridden operation
1767 -- has a dispatching result, so does the overriding one.
1769 Set_Alias
(Prev_Op
, New_Op
);
1770 Set_DTC_Entity
(Prev_Op
, Empty
);
1771 Set_Has_Controlling_Result
(New_Op
, Has_Controlling_Result
(Prev_Op
));
1774 end Override_Dispatching_Operation
;
1780 procedure Propagate_Tag
(Control
: Node_Id
; Actual
: Node_Id
) is
1781 Call_Node
: Node_Id
;
1785 if Nkind
(Actual
) = N_Function_Call
then
1786 Call_Node
:= Actual
;
1788 elsif Nkind
(Actual
) = N_Identifier
1789 and then Nkind
(Original_Node
(Actual
)) = N_Function_Call
1791 -- Call rewritten as object declaration when stack-checking is
1792 -- enabled. Propagate tag to expression in declaration, which is
1795 Call_Node
:= Expression
(Parent
(Entity
(Actual
)));
1797 -- Ada 2005: If this is a dereference of a call to a function with a
1798 -- dispatching access-result, the tag is propagated when the dereference
1799 -- itself is expanded (see exp_ch6.adb) and there is nothing else to do.
1801 elsif Nkind
(Actual
) = N_Explicit_Dereference
1802 and then Nkind
(Original_Node
(Prefix
(Actual
))) = N_Function_Call
1806 -- Only other possibilities are parenthesized or qualified expression,
1807 -- or an expander-generated unchecked conversion of a function call to
1808 -- a stream Input attribute.
1811 Call_Node
:= Expression
(Actual
);
1814 -- Do not set the Controlling_Argument if already set. This happens in
1815 -- the special case of _Input (see Exp_Attr, case Input).
1817 if No
(Controlling_Argument
(Call_Node
)) then
1818 Set_Controlling_Argument
(Call_Node
, Control
);
1821 Arg
:= First_Actual
(Call_Node
);
1823 while Present
(Arg
) loop
1824 if Is_Tag_Indeterminate
(Arg
) then
1825 Propagate_Tag
(Control
, Arg
);
1831 -- Expansion of dispatching calls is suppressed when VM_Target, because
1832 -- the VM back-ends directly handle the generation of dispatching calls
1833 -- and would have to undo any expansion to an indirect call.
1835 if Tagged_Type_Expansion
then
1836 Expand_Dispatching_Call
(Call_Node
);
1838 -- Expansion of a dispatching call results in an indirect call, which in
1839 -- turn causes current values to be killed (see Resolve_Call), so on VM
1840 -- targets we do the call here to ensure consistent warnings between VM
1841 -- and non-VM targets.
1844 Kill_Current_Values
;