-- --
-- B o d y --
-- --
--- Copyright (C) 1992-2011, Free Software Foundation, Inc. --
+-- Copyright (C) 1992-2015, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
with Sem_Aux; use Sem_Aux;
with Sem_Ch3; use Sem_Ch3;
with Sem_Ch6; use Sem_Ch6;
+with Sem_Ch8; use Sem_Ch8;
with Sem_Eval; use Sem_Eval;
with Sem_Type; use Sem_Type;
with Sem_Util; use Sem_Util;
-- This routine does not search for non-hidden primitives since they are
-- covered by the normal Ada 2005 rules.
+ function Is_Inherited_Public_Operation (Op : Entity_Id) return Boolean;
+ -- Check whether a primitive operation is inherited from an operation
+ -- declared in the visible part of its package.
+
-------------------------------
-- Add_Dispatching_Operation --
-------------------------------
while Present (Elmt) loop
Iface_Prim := Node (Elmt);
- if Chars (E) = Chars (Prim)
+ if Chars (Iface) = Chars (Prim)
and then Is_Interface_Conformant
(Tagged_Type, Iface_Prim, Prim)
then
-- Ada 2005 (AI-50217)
- elsif From_With_Type (Designated_Type (T))
+ elsif From_Limited_With (Designated_Type (T))
and then Present (Non_Limited_View (Designated_Type (T)))
+ and then Scope (Designated_Type (T)) = Scope (Subp)
then
if Is_First_Subtype (Non_Limited_View (Designated_Type (T))) then
Tagged_Type := Non_Limited_View (Designated_Type (T));
procedure Check_Dispatching_Context is
Subp : constant Entity_Id := Entity (Name (N));
+ Typ : constant Entity_Id := Etype (Subp);
Par : Node_Id;
+ procedure Abstract_Context_Error;
+ -- Error for abstract call dispatching on result is not dispatching
+
+ ----------------------------
+ -- Abstract_Context_Error --
+ ----------------------------
+
+ procedure Abstract_Context_Error is
+ begin
+ if Ekind (Subp) = E_Function then
+ Error_Msg_N
+ ("call to abstract function must be dispatching", N);
+
+ -- This error can occur for a procedure in the case of a call to
+ -- an abstract formal procedure with a statically tagged operand.
+
+ else
+ Error_Msg_N
+ ("call to abstract procedure must be dispatching",
+ N);
+ end if;
+ end Abstract_Context_Error;
+
+ -- Start of processing for Check_Dispatching_Context
+
begin
if Is_Abstract_Subprogram (Subp)
and then No (Controlling_Argument (N))
Set_Entity (Name (N), Alias (Subp));
return;
+ -- An obscure special case: a null procedure may have a class-
+ -- wide pre/postcondition that includes a call to an abstract
+ -- subp. Calls within the expression may not have been rewritten
+ -- as dispatching calls yet, because the null body appears in
+ -- the current declarative part. The expression will be properly
+ -- rewritten/reanalyzed when the postcondition procedure is built.
+
+ -- Similarly, if this is a pre/postcondition for an abstract
+ -- subprogram, it may call another abstract function which is
+ -- a primitive of an abstract type. The call is non-dispatching
+ -- but will be legal in overridings of the operation.
+
+ elsif In_Spec_Expression
+ and then Is_Subprogram (Current_Scope)
+ and then
+ ((Nkind (Parent (Current_Scope)) = N_Procedure_Specification
+ and then Null_Present (Parent (Current_Scope)))
+ or else Is_Abstract_Subprogram (Current_Scope))
+ then
+ null;
+
+ elsif Ekind (Current_Scope) = E_Function
+ and then Nkind (Unit_Declaration_Node (Current_Scope)) =
+ N_Generic_Subprogram_Declaration
+ then
+ null;
+
else
+ -- We need to determine whether the context of the call
+ -- provides a tag to make the call dispatching. This requires
+ -- the call to be the actual in an enclosing call, and that
+ -- actual must be controlling. If the call is an operand of
+ -- equality, the other operand must not ve abstract.
+
+ if not Is_Tagged_Type (Typ)
+ and then not
+ (Ekind (Typ) = E_Anonymous_Access_Type
+ and then Is_Tagged_Type (Designated_Type (Typ)))
+ then
+ Abstract_Context_Error;
+ return;
+ end if;
+
Par := Parent (N);
+
+ if Nkind (Par) = N_Parameter_Association then
+ Par := Parent (Par);
+ end if;
+
while Present (Par) loop
if Nkind_In (Par, N_Function_Call,
- N_Procedure_Call_Statement,
- N_Assignment_Statement,
- N_Op_Eq,
- N_Op_Ne)
- and then Is_Tagged_Type (Etype (Subp))
+ N_Procedure_Call_Statement)
+ and then Is_Entity_Name (Name (Par))
then
- return;
+ declare
+ A : Node_Id;
+ F : Entity_Id;
+
+ begin
+ -- Find formal for which call is the actual.
+
+ F := First_Formal (Entity (Name (Par)));
+ A := First_Actual (Par);
+ while Present (F) loop
+ if Is_Controlling_Formal (F)
+ and then (N = A or else Parent (N) = A)
+ then
+ return;
+ end if;
- elsif Nkind (Par) = N_Qualified_Expression
- or else Nkind (Par) = N_Unchecked_Type_Conversion
- then
- Par := Parent (Par);
+ Next_Formal (F);
+ Next_Actual (A);
+ end loop;
- else
- if Ekind (Subp) = E_Function then
Error_Msg_N
("call to abstract function must be dispatching", N);
+ return;
+ end;
- -- This error can occur for a procedure in the case of a
- -- call to an abstract formal procedure with a statically
- -- tagged operand.
+ -- For equalitiy operators, one of the operands must be
+ -- statically or dynamically tagged.
- else
- Error_Msg_N
- ("call to abstract procedure must be dispatching",
- N);
+ elsif Nkind_In (Par, N_Op_Eq, N_Op_Ne) then
+ if N = Right_Opnd (Par)
+ and then Is_Tag_Indeterminate (Left_Opnd (Par))
+ then
+ Abstract_Context_Error;
+
+ elsif N = Left_Opnd (Par)
+ and then Is_Tag_Indeterminate (Right_Opnd (Par))
+ then
+ Abstract_Context_Error;
end if;
return;
+
+ elsif Nkind (Par) = N_Assignment_Statement then
+ return;
+
+ elsif Nkind (Par) = N_Qualified_Expression
+ or else Nkind (Par) = N_Unchecked_Type_Conversion
+ then
+ Par := Parent (Par);
+
+ else
+ Abstract_Context_Error;
+ return;
end if;
end loop;
end if;
-- If the call doesn't have a controlling actual but does have an
-- indeterminate actual that requires dispatching treatment, then an
- -- object is needed that will serve as the controlling argument for a
- -- dispatching call on the indeterminate actual. This can only occur
- -- in the unusual situation of a default actual given by a
- -- tag-indeterminate call and where the type of the call is an
+ -- object is needed that will serve as the controlling argument for
+ -- a dispatching call on the indeterminate actual. This can only
+ -- occur in the unusual situation of a default actual given by
+ -- a tag-indeterminate call and where the type of the call is an
-- ancestor of the type associated with a containing call to an
-- inherited operation (see AI-239).
- -- Rather than create an object of the tagged type, which would be
- -- problematic for various reasons (default initialization,
- -- discriminants), the tag of the containing call's associated tagged
- -- type is directly used to control the dispatching.
+ -- Rather than create an object of the tagged type, which would
+ -- be problematic for various reasons (default initialization,
+ -- discriminants), the tag of the containing call's associated
+ -- tagged type is directly used to control the dispatching.
if No (Control)
and then Indeterm_Ancestor_Call
-- The tag is inherited from the enclosing call (the node
-- we are currently analyzing). Explicitly expand the
-- actual, since the previous call to Expand (from
- -- Resolve_Call) had no way of knowing about the required
- -- dispatching.
+ -- Resolve_Call) had no way of knowing about the
+ -- required dispatching.
Propagate_Tag (Control, Actual);
Tagged_Type := Find_Dispatching_Type (Subp);
-- Ada 2005 (AI-345): Use the corresponding record (if available).
- -- Required because primitives of concurrent types are be attached
+ -- Required because primitives of concurrent types are attached
-- to the corresponding record (not to the concurrent type).
if Ada_Version >= Ada_2005
and then not Is_Generic_Type (Typ)
and then not In_Instance
then
- Error_Msg_N ("?declaration of& is too late!", Subp);
+ Error_Msg_N ("??declaration of& is too late!", Subp);
Error_Msg_NE -- CODEFIX??
- ("\spec should appear immediately after declaration of &!",
- Subp, Typ);
+ ("\??spec should appear immediately after declaration "
+ & "of & !", Subp, Typ);
exit;
end if;
and then not Is_Generic_Type (Typ)
and then not In_Instance
then
- Error_Msg_N ("?declaration of& is too late!", Subp);
+ Error_Msg_N ("??declaration of& is too late!", Subp);
Error_Msg_NE
- ("\spec should appear immediately after declaration of &!",
- Subp, Typ);
+ ("\??spec should appear immediately after declaration "
+ & "of & !", Subp, Typ);
end if;
end if;
end;
Decl_Item : Node_Id;
begin
- -- ??? The checks here for whether the type has been
- -- frozen prior to the new body are not complete. It's
- -- not simple to check frozenness at this point since
- -- the body has already caused the type to be prematurely
- -- frozen in Analyze_Declarations, but we're forced to
- -- recheck this here because of the odd rule interpretation
- -- that allows the overriding if the type wasn't frozen
- -- prior to the body. The freezing action should probably
- -- be delayed until after the spec is seen, but that's
- -- a tricky change to the delicate freezing code.
+ -- ??? The checks here for whether the type has been frozen
+ -- prior to the new body are not complete. It's not simple
+ -- to check frozenness at this point since the body has
+ -- already caused the type to be prematurely frozen in
+ -- Analyze_Declarations, but we're forced to recheck this
+ -- here because of the odd rule interpretation that allows
+ -- the overriding if the type wasn't frozen prior to the
+ -- body. The freezing action should probably be delayed
+ -- until after the spec is seen, but that's a tricky
+ -- change to the delicate freezing code.
-- Look at each declaration following the type up until the
-- new subprogram body. If any of the declarations is a body
elsif Is_Frozen (Subp) then
-- The subprogram body declares a primitive operation.
- -- if the subprogram is already frozen, we must update
+ -- If the subprogram is already frozen, we must update
-- its dispatching information explicitly here. The
-- information is taken from the overridden subprogram.
-- We must also generate a cross-reference entry because
if Present (DTC_Entity (Old_Subp)) then
Set_DTC_Entity (Subp, DTC_Entity (Old_Subp));
- Set_DT_Position (Subp, DT_Position (Old_Subp));
+ Set_DT_Position_Value (Subp, DT_Position (Old_Subp));
if not Restriction_Active (No_Dispatching_Calls) then
if Building_Static_DT (Tagged_Type) then
if Has_Dispatch_Table (Tagged_Type) then
Error_Msg_N
- ("overriding of& is too late for building" &
- " static dispatch tables!", Subp);
+ ("overriding of& is too late for building "
+ & " static dispatch tables!", Subp);
Error_Msg_N
- ("\spec should appear immediately after" &
- " the type!", Subp);
+ ("\spec should appear immediately after "
+ & "the type!", Subp);
end if;
-- No code required to register primitives in VM
-- (3.2.3(6)). Only report cases where the type and subprogram are
-- in the same declaration list (by checking the enclosing parent
-- declarations), to avoid spurious warnings on subprograms in
- -- instance bodies when the type is declared in the instance spec but
- -- hasn't been frozen by the instance body.
+ -- instance bodies when the type is declared in the instance spec
+ -- but hasn't been frozen by the instance body.
elsif not Is_Frozen (Tagged_Type)
and then In_Same_List (Parent (Tagged_Type), Parent (Parent (Subp)))
then
Error_Msg_N
- ("?not dispatching (must be defined in a package spec)", Subp);
+ ("??not dispatching (must be defined in a package spec)", Subp);
return;
-- When the type is frozen, it is legitimate to define a new
elsif Is_Frozen (Tagged_Type) and then not Has_Dispatching_Parent then
Error_Msg_N ("this primitive operation is declared too late", Subp);
Error_Msg_NE
- ("?no primitive operations for& after this line",
+ ("??no primitive operations for& after this line",
Freeze_Node (Tagged_Type),
Tagged_Type);
return;
Ovr_Subp := Old_Subp;
-- [Ada 2012:AI-0125]: Search for inherited hidden primitive that may be
- -- overridden by Subp
+ -- overridden by Subp. This only applies to source subprograms, and
+ -- their declaration must carry an explicit overriding indicator.
if No (Ovr_Subp)
and then Ada_Version >= Ada_2012
+ and then Comes_From_Source (Subp)
+ and then
+ Nkind (Unit_Declaration_Node (Subp)) = N_Subprogram_Declaration
then
Ovr_Subp := Find_Hidden_Overridden_Primitive (Subp);
+
+ -- Verify that the proper overriding indicator has been supplied.
+
+ if Present (Ovr_Subp)
+ and then
+ not Must_Override (Specification (Unit_Declaration_Node (Subp)))
+ then
+ Error_Msg_NE ("missing overriding indicator for&", Subp, Subp);
+ end if;
end if;
-- Now it should be a correct primitive operation, put it in the list
Check_Subtype_Conformant (Subp, Ovr_Subp);
- if (Chars (Subp) = Name_Initialize
- or else Chars (Subp) = Name_Adjust
- or else Chars (Subp) = Name_Finalize)
+ -- A primitive operation with the name of a primitive controlled
+ -- operation does not override a non-visible overriding controlled
+ -- operation, i.e. one declared in a private part when the full
+ -- view of a type is controlled. Conversely, it will override a
+ -- visible operation that may be declared in a partial view when
+ -- the full view is controlled.
+
+ if Nam_In (Chars (Subp), Name_Initialize, Name_Adjust, Name_Finalize)
and then Is_Controlled (Tagged_Type)
and then not Is_Visibly_Controlled (Tagged_Type)
+ and then not Is_Inherited_Public_Operation (Ovr_Subp)
then
Set_Overridden_Operation (Subp, Empty);
else
Error_Msg_NE
- ("operation does not override inherited&?", Subp, Subp);
+ ("operation does not override inherited&??", Subp, Subp);
end if;
else
-- emitted after those tables are built, to prevent access before
-- elaboration in gigi.
- if Body_Is_Last_Primitive and then Full_Expander_Active then
+ if Body_Is_Last_Primitive and then Expander_Active then
declare
Subp_Body : constant Node_Id := Unit_Declaration_Node (Subp);
Elmt : Elmt_Id;
end if;
if not Body_Is_Last_Primitive then
- Set_DT_Position (Subp, No_Uint);
+ Set_DT_Position_Value (Subp, No_Uint);
elsif Has_Controlled_Component (Tagged_Type)
- and then
- (Chars (Subp) = Name_Initialize or else
- Chars (Subp) = Name_Adjust or else
- Chars (Subp) = Name_Finalize or else
- Chars (Subp) = Name_Finalize_Address)
+ and then Nam_In (Chars (Subp), Name_Initialize,
+ Name_Adjust,
+ Name_Finalize,
+ Name_Finalize_Address)
then
declare
F_Node : constant Node_Id := Freeze_Node (Tagged_Type);
if Derives_From (Node (Op1)) then
if No (Prev) then
- -- Avoid adding it to the list of primitives if already there!
+ -- Avoid adding it to the list of primitives if already there
if Node (Op2) /= Subp then
Prepend_Elmt (Subp, New_Prim);
Check_Controlling_Formals (Tagged_Type, Old_Subp);
Set_Is_Dispatching_Operation (Old_Subp, True);
- Set_DT_Position (Old_Subp, No_Uint);
+ Set_DT_Position_Value (Old_Subp, No_Uint);
end if;
-- If the old subprogram is an explicit renaming of some other
then
Set_Alias (Old_Subp, Alias (Subp));
- -- The derived subprogram should inherit the abstractness
- -- of the parent subprogram (except in the case of a function
+ -- The derived subprogram should inherit the abstractness of
+ -- the parent subprogram (except in the case of a function
-- returning the type). This sets the abstractness properly
- -- for cases where a private extension may have inherited
- -- an abstract operation, but the full type is derived from
- -- a descendant type and inherits a nonabstract version.
+ -- for cases where a private extension may have inherited an
+ -- abstract operation, but the full type is derived from a
+ -- descendant type and inherits a nonabstract version.
if Etype (Subp) /= Tagged_Type then
Set_Is_Abstract_Subprogram
Ctrl_Type : Entity_Id;
begin
- if Present (DTC_Entity (Subp)) then
+ if Ekind_In (Subp, E_Function, E_Procedure)
+ and then Present (DTC_Entity (Subp))
+ then
return Scope (DTC_Entity (Subp));
-- For subprograms internally generated by derivations of tagged types
Vis_List : Elist_Id;
begin
- -- This Ada 2012 rule is valid only for type extensions or private
- -- extensions.
+ -- This Ada 2012 rule applies only for type extensions or private
+ -- extensions, where the parent type is not in a parent unit, and
+ -- where an operation is never declared but still inherited.
if No (Tag_Typ)
or else not Is_Record_Type (Tag_Typ)
or else Etype (Tag_Typ) = Tag_Typ
+ or else In_Open_Scopes (Scope (Etype (Tag_Typ)))
then
return Empty;
end if;
E := Homonym (E);
end loop;
- -- Search in the list of primitives of the type. Required to locate the
- -- covering primitive if the covering primitive is not visible (for
- -- example, non-visible inherited primitive of private type).
+ -- Search in the list of primitives of the type. Required to locate
+ -- the covering primitive if the covering primitive is not visible
+ -- (for example, non-visible inherited primitive of private type).
El := First_Elmt (Primitive_Operations (Tagged_Type));
while Present (El) loop
-- Inherited_Subprograms --
---------------------------
- function Inherited_Subprograms (S : Entity_Id) return Subprogram_List is
+ function Inherited_Subprograms
+ (S : Entity_Id;
+ No_Interfaces : Boolean := False;
+ Interfaces_Only : Boolean := False) return Subprogram_List
+ is
Result : Subprogram_List (1 .. 6000);
-- 6000 here is intended to be infinity. We could use an expandable
-- table, but it would be awfully heavy, and there is no way that we
-- Start of processing for Inherited_Subprograms
begin
+ pragma Assert (not (No_Interfaces and Interfaces_Only));
+
if Present (S) and then Is_Dispatching_Operation (S) then
-- Deal with direct inheritance
- Parent_Op := S;
- loop
- Parent_Op := Overridden_Operation (Parent_Op);
- exit when No (Parent_Op);
-
- if Is_Subprogram (Parent_Op)
- or else Is_Generic_Subprogram (Parent_Op)
- then
- Store_IS (Parent_Op);
- end if;
- end loop;
+ if not Interfaces_Only then
+ Parent_Op := S;
+ loop
+ Parent_Op := Overridden_Operation (Parent_Op);
+ exit when No (Parent_Op)
+ or else
+ (No_Interfaces
+ and then
+ Is_Interface (Find_Dispatching_Type (Parent_Op)));
+
+ if Is_Subprogram_Or_Generic_Subprogram (Parent_Op) then
+ Store_IS (Parent_Op);
+ end if;
+ end loop;
+ end if;
-- Now deal with interfaces
- declare
- Tag_Typ : Entity_Id;
- Prim : Entity_Id;
- Elmt : Elmt_Id;
+ if not No_Interfaces then
+ declare
+ Tag_Typ : Entity_Id;
+ Prim : Entity_Id;
+ Elmt : Elmt_Id;
- begin
- Tag_Typ := Find_Dispatching_Type (S);
+ begin
+ Tag_Typ := Find_Dispatching_Type (S);
- if Is_Concurrent_Type (Tag_Typ) then
- Tag_Typ := Corresponding_Record_Type (Tag_Typ);
- end if;
+ if Is_Concurrent_Type (Tag_Typ) then
+ Tag_Typ := Corresponding_Record_Type (Tag_Typ);
+ end if;
- -- Search primitive operations of dispatching type
+ -- Search primitive operations of dispatching type
- if Present (Tag_Typ)
- and then Present (Primitive_Operations (Tag_Typ))
- then
- Elmt := First_Elmt (Primitive_Operations (Tag_Typ));
- while Present (Elmt) loop
- Prim := Node (Elmt);
+ if Present (Tag_Typ)
+ and then Present (Primitive_Operations (Tag_Typ))
+ then
+ Elmt := First_Elmt (Primitive_Operations (Tag_Typ));
+ while Present (Elmt) loop
+ Prim := Node (Elmt);
- -- The following test eliminates some odd cases in which
- -- Ekind (Prim) is Void, to be investigated further ???
+ -- The following test eliminates some odd cases in which
+ -- Ekind (Prim) is Void, to be investigated further ???
- if not (Is_Subprogram (Prim)
- or else
- Is_Generic_Subprogram (Prim))
- then
- null;
+ if not Is_Subprogram_Or_Generic_Subprogram (Prim) then
+ null;
-- For [generic] subprogram, look at interface alias
- elsif Present (Interface_Alias (Prim))
- and then Alias (Prim) = S
- then
- -- We have found a primitive covered by S
+ elsif Present (Interface_Alias (Prim))
+ and then Alias (Prim) = S
+ then
+ -- We have found a primitive covered by S
- Store_IS (Interface_Alias (Prim));
- end if;
+ Store_IS (Interface_Alias (Prim));
+ end if;
- Next_Elmt (Elmt);
- end loop;
- end if;
- end;
+ Next_Elmt (Elmt);
+ end loop;
+ end if;
+ end;
+ end if;
end if;
return Result (1 .. N);
begin
if Nkind (N) = N_Error then
return False;
+
+ elsif Present (Find_Controlling_Arg (N)) then
+ return True;
+
+ -- Special cases: entities, and calls that dispatch on result
+
+ elsif Is_Entity_Name (N) then
+ return Is_Class_Wide_Type (Etype (N));
+
+ elsif Nkind (N) = N_Function_Call
+ and then Is_Class_Wide_Type (Etype (N))
+ then
+ return True;
+
+ -- Otherwise check whether call has controlling argument
+
else
- return Find_Controlling_Arg (N) /= Empty;
+ return False;
end if;
end Is_Dynamically_Tagged;
and then Is_Interface (Find_Dispatching_Type (E));
end Is_Null_Interface_Primitive;
+ -----------------------------------
+ -- Is_Inherited_Public_Operation --
+ -----------------------------------
+
+ function Is_Inherited_Public_Operation (Op : Entity_Id) return Boolean is
+ Prim : constant Entity_Id := Alias (Op);
+ Scop : constant Entity_Id := Scope (Prim);
+ Pack_Decl : Node_Id;
+
+ begin
+ if Comes_From_Source (Prim) and then Ekind (Scop) = E_Package then
+ Pack_Decl := Unit_Declaration_Node (Scop);
+ return Nkind (Pack_Decl) = N_Package_Declaration
+ and then List_Containing (Unit_Declaration_Node (Prim)) =
+ Visible_Declarations (Specification (Pack_Decl));
+
+ else
+ return False;
+ end if;
+ end Is_Inherited_Public_Operation;
+
--------------------------
-- Is_Tag_Indeterminate --
--------------------------
elsif Nkind (Orig_Node) = N_Attribute_Reference
and then
Get_Attribute_Id (Attribute_Name (Orig_Node)) = Attribute_Input
- and then
- Nkind (Prefix (Orig_Node)) /= N_Attribute_Reference
+ and then Nkind (Prefix (Orig_Node)) /= N_Attribute_Reference
then
return True;
procedure Override_Dispatching_Operation
(Tagged_Type : Entity_Id;
Prev_Op : Entity_Id;
- New_Op : Entity_Id)
+ New_Op : Entity_Id;
+ Is_Wrapper : Boolean := False)
is
Elmt : Elmt_Id;
Prim : Node_Id;
begin
-- Diagnose failure to match No_Return in parent (Ada-2005, AI-414, but
- -- we do it unconditionally in Ada 95 now, since this is our pragma!)
+ -- we do it unconditionally in Ada 95 now, since this is our pragma).
if No_Return (Prev_Op) and then not No_Return (New_Op) then
Error_Msg_N ("procedure & must have No_Return pragma", New_Op);
-- was malformed, and an error must have been emitted already.
Elmt := First_Elmt (Primitive_Operations (Tagged_Type));
- while Present (Elmt)
- and then Node (Elmt) /= Prev_Op
- loop
+ while Present (Elmt) and then Node (Elmt) /= Prev_Op loop
Next_Elmt (Elmt);
end loop;
Replace_Elmt (Elmt, New_Op);
end if;
- if Ada_Version >= Ada_2005
- and then Has_Interfaces (Tagged_Type)
- then
+ if Ada_Version >= Ada_2005 and then Has_Interfaces (Tagged_Type) then
+
-- Ada 2005 (AI-251): Update the attribute alias of all the aliased
- -- entities of the overridden primitive to reference New_Op, and also
- -- propagate the proper value of Is_Abstract_Subprogram. Verify
+ -- entities of the overridden primitive to reference New_Op, and
+ -- also propagate the proper value of Is_Abstract_Subprogram. Verify
-- that the new operation is subtype conformant with the interface
-- operations that it implements (for operations inherited from the
-- parent itself, this check is made when building the derived type).
- -- Note: This code is only executed in case of late overriding
+ -- Note: This code is executed with internally generated wrappers of
+ -- functions with controlling result and late overridings.
Elmt := First_Elmt (Primitive_Operations (Tagged_Type));
while Present (Elmt) loop
elsif Is_Subprogram (Prim)
and then Present (Interface_Alias (Prim))
and then Alias (Prim) = Prev_Op
- and then Present (Etype (New_Op))
then
Set_Alias (Prim, New_Op);
- Check_Subtype_Conformant (New_Op, Prim);
- Set_Is_Abstract_Subprogram (Prim,
- Is_Abstract_Subprogram (New_Op));
- -- Ensure that this entity will be expanded to fill the
- -- corresponding entry in its dispatch table.
+ -- No further decoration needed yet for internally generated
+ -- wrappers of controlling functions since (at this stage)
+ -- they are not yet decorated.
+
+ if not Is_Wrapper then
+ Check_Subtype_Conformant (New_Op, Prim);
- if not Is_Abstract_Subprogram (Prim) then
- Set_Has_Delayed_Freeze (Prim);
+ Set_Is_Abstract_Subprogram (Prim,
+ Is_Abstract_Subprogram (New_Op));
+
+ -- Ensure that this entity will be expanded to fill the
+ -- corresponding entry in its dispatch table.
+
+ if not Is_Abstract_Subprogram (Prim) then
+ Set_Has_Delayed_Freeze (Prim);
+ end if;
end if;
end if;
Call_Node := Expression (Actual);
end if;
+ -- No action needed if the call has been already expanded
+
+ if Is_Expanded_Dispatching_Call (Call_Node) then
+ return;
+ end if;
+
-- Do not set the Controlling_Argument if already set. This happens in
-- the special case of _Input (see Exp_Attr, case Input).
Set_Etype (Call_Node, Etype (Control));
Set_Analyzed (Call_Node);
- Expand_Interface_Conversion (Call_Node, Is_Static => False);
+ Expand_Interface_Conversion (Call_Node);
end if;
end;