with Atree; use Atree;
with Checks; use Checks;
with Debug; use Debug;
with Einfo; use Einfo;
with Elists; use Elists;
with Errout; use Errout;
with Exp_Util; use Exp_Util;
with Fname; use Fname;
with Itypes; use Itypes;
with Lib; use Lib;
with Lib.Xref; use Lib.Xref;
with Namet; use Namet;
with Nlists; use Nlists;
with Nmake; use Nmake;
with Opt; use Opt;
with Output; use Output;
with Restrict; use Restrict;
with Rident; use Rident;
with Sem; use Sem;
with Sem_Cat; use Sem_Cat;
with Sem_Ch3; use Sem_Ch3;
with Sem_Ch8; use Sem_Ch8;
with Sem_Dist; use Sem_Dist;
with Sem_Eval; use Sem_Eval;
with Sem_Res; use Sem_Res;
with Sem_Util; use Sem_Util;
with Sem_Type; use Sem_Type;
with Stand; use Stand;
with Sinfo; use Sinfo;
with Snames; use Snames;
with Tbuild; use Tbuild;
with GNAT.Spelling_Checker; use GNAT.Spelling_Checker;
package body Sem_Ch4 is
procedure Analyze_Expression (N : Node_Id);
procedure Analyze_Operator_Call (N : Node_Id; Op_Id : Entity_Id);
procedure Analyze_Overloaded_Selected_Component (N : Node_Id);
procedure Analyze_User_Defined_Binary_Op (N : Node_Id; Op_Id : Entity_Id);
procedure Analyze_User_Defined_Unary_Op (N : Node_Id; Op_Id : Entity_Id);
procedure Ambiguous_Operands (N : Node_Id);
procedure Analyze_One_Call
(N : Node_Id;
Nam : Entity_Id;
Report : Boolean;
Success : out Boolean);
procedure Check_Misspelled_Selector
(Prefix : Entity_Id;
Sel : Node_Id);
function Defined_In_Scope (T : Entity_Id; S : Entity_Id) return Boolean;
procedure Find_Arithmetic_Types
(L, R : Node_Id;
Op_Id : Entity_Id;
N : Node_Id);
procedure Find_Comparison_Types
(L, R : Node_Id;
Op_Id : Entity_Id;
N : Node_Id);
procedure Find_Concatenation_Types
(L, R : Node_Id;
Op_Id : Entity_Id;
N : Node_Id);
procedure Find_Equality_Types
(L, R : Node_Id;
Op_Id : Entity_Id;
N : Node_Id);
procedure Find_Boolean_Types
(L, R : Node_Id;
Op_Id : Entity_Id;
N : Node_Id);
procedure Find_Negation_Types
(R : Node_Id;
Op_Id : Entity_Id;
N : Node_Id);
procedure Find_Non_Universal_Interpretations
(N : Node_Id;
R : Node_Id;
Op_Id : Entity_Id;
T1 : Entity_Id);
procedure Find_Unary_Types
(R : Node_Id;
Op_Id : Entity_Id;
N : Node_Id);
procedure Check_Arithmetic_Pair
(T1, T2 : Entity_Id;
Op_Id : Entity_Id;
N : Node_Id);
procedure Diagnose_Call (N : Node_Id; Nam : Node_Id);
function Junk_Operand (N : Node_Id) return Boolean;
procedure Operator_Check (N : Node_Id);
procedure Process_Implicit_Dereference_Prefix
(E : Entity_Id;
P : Node_Id);
procedure Remove_Abstract_Operations (N : Node_Id);
function Try_Indexed_Call
(N : Node_Id;
Nam : Entity_Id;
Typ : Entity_Id) return Boolean;
function Try_Indirect_Call
(N : Node_Id;
Nam : Entity_Id;
Typ : Entity_Id) return Boolean;
function Try_Object_Operation (N : Node_Id) return Boolean;
procedure Ambiguous_Operands (N : Node_Id) is
procedure List_Operand_Interps (Opnd : Node_Id);
procedure List_Operand_Interps (Opnd : Node_Id) is
Nam : Node_Id;
Err : Node_Id := N;
begin
if Is_Overloaded (Opnd) then
if Nkind (Opnd) in N_Op then
Nam := Opnd;
elsif Nkind (Opnd) = N_Function_Call then
Nam := Name (Opnd);
else
return;
end if;
else
return;
end if;
if Opnd = Left_Opnd (N) then
Error_Msg_N
("\left operand has the following interpretations", N);
else
Error_Msg_N
("\right operand has the following interpretations", N);
Err := Opnd;
end if;
List_Interps (Nam, Err);
end List_Operand_Interps;
begin
if Nkind (N) = N_In
or else Nkind (N) = N_Not_In
then
Error_Msg_N ("ambiguous operands for membership", N);
elsif Nkind (N) = N_Op_Eq
or else Nkind (N) = N_Op_Ne
then
Error_Msg_N ("ambiguous operands for equality", N);
else
Error_Msg_N ("ambiguous operands for comparison", N);
end if;
if All_Errors_Mode then
List_Operand_Interps (Left_Opnd (N));
List_Operand_Interps (Right_Opnd (N));
else
Error_Msg_N ("\use -gnatf switch for details", N);
end if;
end Ambiguous_Operands;
procedure Analyze_Aggregate (N : Node_Id) is
begin
if No (Etype (N)) then
Set_Etype (N, Any_Composite);
end if;
end Analyze_Aggregate;
procedure Analyze_Allocator (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
Sav_Errs : constant Nat := Serious_Errors_Detected;
E : Node_Id := Expression (N);
Acc_Type : Entity_Id;
Type_Id : Entity_Id;
begin
Check_Restriction (No_Allocators, N);
if Nkind (E) = N_Qualified_Expression then
Acc_Type := Create_Itype (E_Allocator_Type, N);
Set_Etype (Acc_Type, Acc_Type);
Init_Size_Align (Acc_Type);
Find_Type (Subtype_Mark (E));
Type_Id := Entity (Subtype_Mark (E));
Check_Fully_Declared (Type_Id, N);
Set_Directly_Designated_Type (Acc_Type, Type_Id);
if Is_Limited_Type (Type_Id)
and then Comes_From_Source (N)
and then not In_Instance_Body
then
if Ada_Version >= Ada_05
and then Nkind (Expression (E)) = N_Aggregate
then
null;
else
Error_Msg_N ("initialization not allowed for limited types", N);
Explain_Limited_Type (Type_Id, N);
end if;
end if;
Analyze_And_Resolve (Expression (E), Type_Id);
if Is_Class_Wide_Type (Type_Id)
and then Base_Type (Etype (Expression (E))) /= Base_Type (Type_Id)
then
Wrong_Type (Expression (E), Type_Id);
end if;
Check_Non_Static_Context (Expression (E));
Set_Etype (E, Type_Id);
else
declare
Def_Id : Entity_Id;
begin
if Nkind (E) = N_Subtype_Indication then
Find_Type (Subtype_Mark (E));
if Is_Elementary_Type (Entity (Subtype_Mark (E))) then
if not (Ada_Version = Ada_83
and then Is_Access_Type (Entity (Subtype_Mark (E))))
then
Error_Msg_N ("constraint not allowed here", E);
if Nkind (Constraint (E))
= N_Index_Or_Discriminant_Constraint
then
Error_Msg_N
("\if qualified expression was meant, " &
"use apostrophe", Constraint (E));
end if;
end if;
Rewrite (E, New_Copy_Tree (Subtype_Mark (E)));
Analyze_Allocator (N);
return;
end if;
if Expander_Active then
Def_Id :=
Make_Defining_Identifier (Loc, New_Internal_Name ('S'));
Insert_Action (E,
Make_Subtype_Declaration (Loc,
Defining_Identifier => Def_Id,
Subtype_Indication => Relocate_Node (E)));
if Sav_Errs /= Serious_Errors_Detected
and then Nkind (Constraint (E))
= N_Index_Or_Discriminant_Constraint
then
Error_Msg_N
("if qualified expression was meant, " &
"use apostrophe!", Constraint (E));
end if;
E := New_Occurrence_Of (Def_Id, Loc);
Rewrite (Expression (N), E);
end if;
end if;
Type_Id := Process_Subtype (E, N);
Acc_Type := Create_Itype (E_Allocator_Type, N);
Set_Etype (Acc_Type, Acc_Type);
Init_Size_Align (Acc_Type);
Set_Directly_Designated_Type (Acc_Type, Type_Id);
Check_Fully_Declared (Type_Id, N);
if Can_Never_Be_Null (Type_Id) then
Error_Msg_N ("(Ada 2005) qualified expression required",
Expression (N));
end if;
if Is_Protected_Type (Type_Id) then
Check_Restriction (No_Protected_Type_Allocators, N);
end if;
if Is_Indefinite_Subtype (Type_Id)
and then Serious_Errors_Detected = Sav_Errs
then
if Is_Class_Wide_Type (Type_Id) then
Error_Msg_N
("initialization required in class-wide allocation", N);
else
Error_Msg_N
("initialization required in unconstrained allocation", N);
end if;
end if;
end;
end if;
if Is_Abstract (Type_Id) then
Error_Msg_N ("cannot allocate abstract object", E);
end if;
if Has_Task (Designated_Type (Acc_Type)) then
Check_Restriction (No_Tasking, N);
Check_Restriction (Max_Tasks, N);
Check_Restriction (No_Task_Allocators, N);
end if;
if Restrictions.Set (No_Streams) then
if Has_Stream (Designated_Type (Acc_Type)) then
Check_Restriction (No_Streams, N);
end if;
end if;
Set_Etype (N, Acc_Type);
if not Is_Library_Level_Entity (Acc_Type) then
Check_Restriction (No_Local_Allocators, N);
end if;
if Ada_Version >= Ada_05
and then (Null_Exclusion_Present (N)
or else Can_Never_Be_Null (Etype (N)))
then
Null_Exclusion_Static_Checks (N);
end if;
if Serious_Errors_Detected > Sav_Errs then
Set_Error_Posted (N);
Set_Etype (N, Any_Type);
end if;
end Analyze_Allocator;
procedure Analyze_Arithmetic_Op (N : Node_Id) is
L : constant Node_Id := Left_Opnd (N);
R : constant Node_Id := Right_Opnd (N);
Op_Id : Entity_Id;
begin
Candidate_Type := Empty;
Analyze_Expression (L);
Analyze_Expression (R);
Op_Id := Entity (N);
if Present (Op_Id) then
if Ekind (Op_Id) = E_Operator then
if (Nkind (N) = N_Op_Divide or else
Nkind (N) = N_Op_Mod or else
Nkind (N) = N_Op_Multiply or else
Nkind (N) = N_Op_Rem)
and then Treat_Fixed_As_Integer (N)
then
null;
else
Set_Etype (N, Any_Type);
Find_Arithmetic_Types (L, R, Op_Id, N);
end if;
else
Set_Etype (N, Any_Type);
Add_One_Interp (N, Op_Id, Etype (Op_Id));
end if;
else
Op_Id := Get_Name_Entity_Id (Chars (N));
Set_Etype (N, Any_Type);
while Present (Op_Id) loop
if Ekind (Op_Id) = E_Operator
and then Present (Next_Entity (First_Entity (Op_Id)))
then
Find_Arithmetic_Types (L, R, Op_Id, N);
elsif Is_Overloadable (Op_Id) then
Analyze_User_Defined_Binary_Op (N, Op_Id);
end if;
Op_Id := Homonym (Op_Id);
end loop;
end if;
Operator_Check (N);
end Analyze_Arithmetic_Op;
procedure Analyze_Call (N : Node_Id) is
Actuals : constant List_Id := Parameter_Associations (N);
Nam : Node_Id := Name (N);
X : Interp_Index;
It : Interp;
Nam_Ent : Entity_Id;
Success : Boolean := False;
function Name_Denotes_Function return Boolean;
function Name_Denotes_Function return Boolean is
begin
if Is_Entity_Name (Nam) then
return Ekind (Entity (Nam)) = E_Function;
elsif Nkind (Nam) = N_Selected_Component then
return Ekind (Entity (Selector_Name (Nam))) = E_Function;
else
return False;
end if;
end Name_Denotes_Function;
begin
Set_Etype (N, Any_Type);
if not Is_Overloaded (Nam) then
if Ekind (Etype (Nam)) = E_Subprogram_Type then
Nam_Ent := Etype (Nam);
elsif Is_Access_Type (Etype (Nam))
and then Ekind (Designated_Type (Etype (Nam))) = E_Subprogram_Type
and then not Name_Denotes_Function
then
Nam_Ent := Designated_Type (Etype (Nam));
Insert_Explicit_Dereference (Nam);
elsif Nkind (Nam) = N_Selected_Component then
Nam_Ent := Entity (Selector_Name (Nam));
if Ekind (Nam_Ent) /= E_Entry
and then Ekind (Nam_Ent) /= E_Entry_Family
and then Ekind (Nam_Ent) /= E_Function
and then Ekind (Nam_Ent) /= E_Procedure
then
Error_Msg_N ("name in call is not a callable entity", Nam);
Set_Etype (N, Any_Type);
return;
end if;
elsif Nkind (Nam) = N_Indexed_Component then
if Nkind (Prefix (Nam)) = N_Selected_Component then
Nam_Ent := Entity (Selector_Name (Prefix (Nam)));
else
Error_Msg_N ("name in call is not a callable entity", Nam);
Set_Etype (N, Any_Type);
return;
end if;
elsif not Is_Entity_Name (Nam) then
Error_Msg_N ("name in call is not a callable entity", Nam);
Set_Etype (N, Any_Type);
return;
else
Nam_Ent := Entity (Nam);
if not Is_Overloadable (Nam_Ent) then
declare
L : constant Boolean := Is_List_Member (N);
K : constant Node_Kind := Nkind (Parent (N));
begin
if L and then K not in N_Subexpr then
if Ekind (Entity (Nam)) = E_Generic_Procedure then
Error_Msg_NE
("must instantiate generic procedure& before call",
Nam, Entity (Nam));
else
Error_Msg_N
("procedure or entry name expected", Nam);
end if;
elsif not L
and then (K = N_Entry_Call_Alternative
or else K = N_Triggering_Alternative)
then
Error_Msg_N ("entry name expected", Nam);
else
Error_Msg_N ("invalid prefix in call", Nam);
end if;
return;
end;
end if;
end if;
Analyze_One_Call (N, Nam_Ent, True, Success);
else
if Nkind (Nam) = N_Selected_Component then
Nam := Selector_Name (Nam);
end if;
Get_First_Interp (Nam, X, It);
while Present (It.Nam) loop
Nam_Ent := It.Nam;
if Is_Access_Type (Nam_Ent) then
Nam_Ent := Designated_Type (Nam_Ent);
elsif Is_Access_Type (Etype (Nam_Ent))
and then not Is_Entity_Name (Nam)
and then Ekind (Designated_Type (Etype (Nam_Ent)))
= E_Subprogram_Type
then
Nam_Ent := Designated_Type (Etype (Nam_Ent));
end if;
Analyze_One_Call (N, Nam_Ent, False, Success);
if Success then
Set_Etype (Nam, It.Typ);
elsif Nkind (Name (N)) = N_Selected_Component
or else Nkind (Name (N)) = N_Function_Call
then
Remove_Interp (X);
end if;
Get_Next_Interp (X, It);
end loop;
if Nkind (Nam) = N_Function_Call then
Insert_Explicit_Dereference (Nam);
end if;
if Etype (N) = Any_Type then
Diagnose_Call (N, Nam);
if Nkind (N) = N_Procedure_Call_Statement
and then Is_Entity_Name (Nam)
and then Chars (Nam) = Name_Put
and then List_Length (Actuals) = 1
then
declare
Arg : constant Node_Id := First (Actuals);
Typ : Entity_Id;
begin
if Nkind (Arg) = N_Parameter_Association then
Typ := Etype (Explicit_Actual_Parameter (Arg));
else
Typ := Etype (Arg);
end if;
if Is_Signed_Integer_Type (Typ) then
Error_Msg_N
("possible missing instantiation of " &
"'Text_'I'O.'Integer_'I'O!", Nam);
elsif Is_Modular_Integer_Type (Typ) then
Error_Msg_N
("possible missing instantiation of " &
"'Text_'I'O.'Modular_'I'O!", Nam);
elsif Is_Floating_Point_Type (Typ) then
Error_Msg_N
("possible missing instantiation of " &
"'Text_'I'O.'Float_'I'O!", Nam);
elsif Is_Ordinary_Fixed_Point_Type (Typ) then
Error_Msg_N
("possible missing instantiation of " &
"'Text_'I'O.'Fixed_'I'O!", Nam);
elsif Is_Decimal_Fixed_Point_Type (Typ) then
Error_Msg_N
("possible missing instantiation of " &
"'Text_'I'O.'Decimal_'I'O!", Nam);
elsif Is_Enumeration_Type (Typ) then
Error_Msg_N
("possible missing instantiation of " &
"'Text_'I'O.'Enumeration_'I'O!", Nam);
end if;
end;
end if;
elsif not Is_Overloaded (N)
and then Is_Entity_Name (Nam)
then
Set_Entity_With_Style_Check (Nam, Entity (Nam));
Generate_Reference (Entity (Nam), Nam);
Set_Etype (Nam, Etype (Entity (Nam)));
else
Remove_Abstract_Operations (N);
end if;
End_Interp_List;
end if;
end Analyze_Call;
procedure Analyze_Comparison_Op (N : Node_Id) is
L : constant Node_Id := Left_Opnd (N);
R : constant Node_Id := Right_Opnd (N);
Op_Id : Entity_Id := Entity (N);
begin
Set_Etype (N, Any_Type);
Candidate_Type := Empty;
Analyze_Expression (L);
Analyze_Expression (R);
if Present (Op_Id) then
if Ekind (Op_Id) = E_Operator then
Find_Comparison_Types (L, R, Op_Id, N);
else
Add_One_Interp (N, Op_Id, Etype (Op_Id));
end if;
if Is_Overloaded (L) then
Set_Etype (L, Intersect_Types (L, R));
end if;
else
Op_Id := Get_Name_Entity_Id (Chars (N));
while Present (Op_Id) loop
if Ekind (Op_Id) = E_Operator then
Find_Comparison_Types (L, R, Op_Id, N);
else
Analyze_User_Defined_Binary_Op (N, Op_Id);
end if;
Op_Id := Homonym (Op_Id);
end loop;
end if;
Operator_Check (N);
end Analyze_Comparison_Op;
procedure Analyze_Concatenation (N : Node_Id) is
L : constant Node_Id := Left_Opnd (N);
R : constant Node_Id := Right_Opnd (N);
Op_Id : Entity_Id := Entity (N);
LT : Entity_Id;
RT : Entity_Id;
begin
Set_Etype (N, Any_Type);
Candidate_Type := Empty;
Analyze_Expression (L);
Analyze_Expression (R);
if Present (Op_Id) then
if Ekind (Op_Id) = E_Operator then
LT := Base_Type (Etype (L));
RT := Base_Type (Etype (R));
if Is_Array_Type (LT)
and then (RT = LT or else RT = Base_Type (Component_Type (LT)))
then
Add_One_Interp (N, Op_Id, LT);
elsif Is_Array_Type (RT)
and then LT = Base_Type (Component_Type (RT))
then
Add_One_Interp (N, Op_Id, RT);
elsif
(Root_Type (LT) = Standard_String
or else Scope (LT) /= Standard_Standard)
and then Etype (R) = Any_String
then
Add_One_Interp (N, Op_Id, LT);
elsif
(Root_Type (RT) = Standard_String
or else Scope (RT) /= Standard_Standard)
and then Etype (L) = Any_String
then
Add_One_Interp (N, Op_Id, RT);
elsif not Is_Generic_Type (Etype (Op_Id)) then
Add_One_Interp (N, Op_Id, Etype (Op_Id));
else
Set_Entity (N, Empty);
Analyze_Concatenation (N);
end if;
else
Add_One_Interp (N, Op_Id, Etype (Op_Id));
end if;
else
Op_Id := Get_Name_Entity_Id (Name_Op_Concat);
while Present (Op_Id) loop
if Ekind (Op_Id) = E_Operator then
Find_Concatenation_Types (L, R, Op_Id, N);
else
Analyze_User_Defined_Binary_Op (N, Op_Id);
end if;
Op_Id := Homonym (Op_Id);
end loop;
end if;
Operator_Check (N);
end Analyze_Concatenation;
procedure Analyze_Conditional_Expression (N : Node_Id) is
Condition : constant Node_Id := First (Expressions (N));
Then_Expr : constant Node_Id := Next (Condition);
Else_Expr : constant Node_Id := Next (Then_Expr);
begin
Analyze_Expression (Condition);
Analyze_Expression (Then_Expr);
Analyze_Expression (Else_Expr);
Set_Etype (N, Etype (Then_Expr));
end Analyze_Conditional_Expression;
procedure Analyze_Equality_Op (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
L : constant Node_Id := Left_Opnd (N);
R : constant Node_Id := Right_Opnd (N);
Op_Id : Entity_Id;
begin
Set_Etype (N, Any_Type);
Candidate_Type := Empty;
Analyze_Expression (L);
Analyze_Expression (R);
if Present (Entity (N)) then
Op_Id := Entity (N);
if Ekind (Op_Id) = E_Operator then
Add_One_Interp (N, Op_Id, Standard_Boolean);
else
Add_One_Interp (N, Op_Id, Etype (Op_Id));
end if;
if Is_Overloaded (L) then
if Ekind (Op_Id) = E_Operator then
Set_Etype (L, Intersect_Types (L, R));
else
Set_Etype (L, Etype (First_Formal (Op_Id)));
end if;
end if;
else
Op_Id := Get_Name_Entity_Id (Chars (N));
while Present (Op_Id) loop
if Ekind (Op_Id) = E_Operator then
Find_Equality_Types (L, R, Op_Id, N);
else
Analyze_User_Defined_Binary_Op (N, Op_Id);
end if;
Op_Id := Homonym (Op_Id);
end loop;
end if;
if Etype (N) = Any_Type
and then Nkind (N) = N_Op_Ne
then
Op_Id := Get_Name_Entity_Id (Name_Op_Eq);
while Present (Op_Id) loop
if Ekind (Op_Id) = E_Operator then
Find_Equality_Types (L, R, Op_Id, N);
else
Analyze_User_Defined_Binary_Op (N, Op_Id);
end if;
Op_Id := Homonym (Op_Id);
end loop;
if Etype (N) /= Any_Type then
Op_Id := Entity (N);
Rewrite (N,
Make_Op_Not (Loc,
Right_Opnd =>
Make_Op_Eq (Loc,
Left_Opnd => Relocate_Node (Left_Opnd (N)),
Right_Opnd => Relocate_Node (Right_Opnd (N)))));
Set_Entity (Right_Opnd (N), Op_Id);
Analyze (N);
end if;
end if;
Operator_Check (N);
end Analyze_Equality_Op;
procedure Analyze_Explicit_Dereference (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
P : constant Node_Id := Prefix (N);
T : Entity_Id;
I : Interp_Index;
It : Interp;
New_N : Node_Id;
function Is_Function_Type return Boolean;
function Is_Function_Type return Boolean is
I : Interp_Index;
It : Interp;
begin
if not Is_Overloaded (N) then
return Ekind (Base_Type (Etype (N))) = E_Subprogram_Type
and then Etype (Base_Type (Etype (N))) /= Standard_Void_Type;
else
Get_First_Interp (N, I, It);
while Present (It.Nam) loop
if Ekind (Base_Type (It.Typ)) /= E_Subprogram_Type
or else Etype (Base_Type (It.Typ)) = Standard_Void_Type
then
return False;
end if;
Get_Next_Interp (I, It);
end loop;
return True;
end if;
end Is_Function_Type;
begin
Analyze (P);
Set_Etype (N, Any_Type);
if Remote_AST_E_Dereference (P) then
return;
end if;
if not Is_Overloaded (P) then
if Is_Access_Type (Etype (P)) then
declare
DT : Entity_Id := Designated_Type (Etype (P));
begin
if Ekind (DT) = E_Private_Subtype
and then Is_For_Access_Subtype (DT)
then
DT := Base_Type (DT);
end if;
Set_Etype (N, DT);
end;
elsif Etype (P) /= Any_Type then
Error_Msg_N ("prefix of dereference must be an access type", N);
return;
end if;
else
Get_First_Interp (P, I, It);
while Present (It.Nam) loop
T := It.Typ;
if Is_Access_Type (T) then
Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
end if;
Get_Next_Interp (I, It);
end loop;
End_Interp_List;
if Etype (N) = Any_Type then
Error_Msg_N
("access type required in prefix of explicit dereference", P);
Set_Etype (N, Any_Type);
return;
end if;
end if;
if Is_Function_Type
and then Nkind (Parent (N)) /= N_Indexed_Component
and then (Nkind (Parent (N)) /= N_Function_Call
or else N /= Name (Parent (N)))
and then (Nkind (Parent (N)) /= N_Procedure_Call_Statement
or else N /= Name (Parent (N)))
and then Nkind (Parent (N)) /= N_Subprogram_Renaming_Declaration
and then (Nkind (Parent (N)) /= N_Attribute_Reference
or else
(Attribute_Name (Parent (N)) /= Name_Address
and then
Attribute_Name (Parent (N)) /= Name_Access))
then
New_N :=
Make_Function_Call (Loc,
Name => Make_Explicit_Dereference (Loc, P),
Parameter_Associations => New_List);
if Is_Overloaded (P) then
Get_First_Interp (P, I, It);
while Present (It.Nam) loop
T := It.Typ;
if No (First_Formal (Base_Type (Designated_Type (T)))) then
Set_Etype (P, T);
else
Remove_Interp (I);
end if;
Get_Next_Interp (I, It);
end loop;
end if;
Rewrite (N, New_N);
Analyze (N);
end if;
Validate_Remote_Access_To_Class_Wide_Type (N);
end Analyze_Explicit_Dereference;
procedure Analyze_Expression (N : Node_Id) is
begin
Analyze (N);
Check_Parameterless_Call (N);
end Analyze_Expression;
procedure Analyze_Indexed_Component_Form (N : Node_Id) is
P : constant Node_Id := Prefix (N);
Exprs : constant List_Id := Expressions (N);
Exp : Node_Id;
P_T : Entity_Id;
E : Node_Id;
U_N : Entity_Id;
procedure Process_Function_Call;
procedure Process_Indexed_Component;
procedure Process_Indexed_Component_Or_Slice;
procedure Process_Overloaded_Indexed_Component;
procedure Process_Function_Call is
Actual : Node_Id;
begin
Change_Node (N, N_Function_Call);
Set_Name (N, P);
Set_Parameter_Associations (N, Exprs);
Actual := First (Parameter_Associations (N));
while Present (Actual) loop
Analyze (Actual);
Check_Parameterless_Call (Actual);
Next_Actual (Actual);
end loop;
Analyze_Call (N);
end Process_Function_Call;
procedure Process_Indexed_Component is
Exp : Node_Id;
Array_Type : Entity_Id;
Index : Node_Id;
Pent : Entity_Id := Empty;
begin
Exp := First (Exprs);
if Is_Overloaded (P) then
Process_Overloaded_Indexed_Component;
else
Array_Type := Etype (P);
if Is_Entity_Name (P) then
Pent := Entity (P);
elsif Nkind (P) = N_Selected_Component
and then Is_Entity_Name (Selector_Name (P))
then
Pent := Entity (Selector_Name (P));
end if;
if Is_Access_Type (Array_Type) then
Array_Type := Designated_Type (Array_Type);
Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
Process_Implicit_Dereference_Prefix (Pent, P);
end if;
if Is_Array_Type (Array_Type) then
null;
elsif Present (Pent) and then Ekind (Pent) = E_Entry_Family then
Analyze (Exp);
Set_Etype (N, Any_Type);
if not Has_Compatible_Type
(Exp, Entry_Index_Type (Pent))
then
Error_Msg_N ("invalid index type in entry name", N);
elsif Present (Next (Exp)) then
Error_Msg_N ("too many subscripts in entry reference", N);
else
Set_Etype (N, Etype (P));
end if;
return;
elsif Is_Record_Type (Array_Type)
and then Remote_AST_I_Dereference (P)
then
return;
elsif Array_Type = Any_Type then
Set_Etype (N, Any_Type);
return;
else
if Nkind (Parent (N)) = N_Requeue_Statement
and then Present (Pent) and then Ekind (Pent) = E_Entry
then
Error_Msg_N
("REQUEUE does not permit parameters", First (Exprs));
elsif Is_Entity_Name (P)
and then Etype (P) = Standard_Void_Type
then
Error_Msg_NE ("incorrect use of&", P, Entity (P));
else
Error_Msg_N ("array type required in indexed component", P);
end if;
Set_Etype (N, Any_Type);
return;
end if;
Index := First_Index (Array_Type);
while Present (Index) and then Present (Exp) loop
if not Has_Compatible_Type (Exp, Etype (Index)) then
Wrong_Type (Exp, Etype (Index));
Set_Etype (N, Any_Type);
return;
end if;
Next_Index (Index);
Next (Exp);
end loop;
Set_Etype (N, Component_Type (Array_Type));
if Present (Index) then
Error_Msg_N
("too few subscripts in array reference", First (Exprs));
elsif Present (Exp) then
Error_Msg_N ("too many subscripts in array reference", Exp);
end if;
end if;
end Process_Indexed_Component;
procedure Process_Indexed_Component_Or_Slice is
begin
Exp := First (Exprs);
while Present (Exp) loop
Analyze_Expression (Exp);
Next (Exp);
end loop;
Exp := First (Exprs);
if No (Next (Exp))
and then Is_Entity_Name (Exp)
and then Is_Type (Entity (Exp))
then
Replace (N,
Make_Slice (Sloc (N),
Prefix => P,
Discrete_Range => New_Copy (Exp)));
Analyze (N);
else
Process_Indexed_Component;
end if;
end Process_Indexed_Component_Or_Slice;
procedure Process_Overloaded_Indexed_Component is
Exp : Node_Id;
I : Interp_Index;
It : Interp;
Typ : Entity_Id;
Index : Node_Id;
Found : Boolean;
begin
Set_Etype (N, Any_Type);
Get_First_Interp (P, I, It);
while Present (It.Nam) loop
Typ := It.Typ;
if Is_Access_Type (Typ) then
Typ := Designated_Type (Typ);
Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
end if;
if Is_Array_Type (Typ) then
Index := First_Index (Typ);
Found := True;
Exp := First (Exprs);
while Present (Index) and then Present (Exp) loop
if Has_Compatible_Type (Exp, Etype (Index)) then
null;
else
Found := False;
Remove_Interp (I);
exit;
end if;
Next_Index (Index);
Next (Exp);
end loop;
if Found and then No (Index) and then No (Exp) then
Add_One_Interp (N,
Etype (Component_Type (Typ)),
Etype (Component_Type (Typ)));
end if;
end if;
Get_Next_Interp (I, It);
end loop;
if Etype (N) = Any_Type then
Error_Msg_N ("no legal interpetation for indexed component", N);
Set_Is_Overloaded (N, False);
end if;
End_Interp_List;
end Process_Overloaded_Indexed_Component;
begin
Analyze (P);
if Nkind (N) = N_Function_Call
or else Nkind (N) = N_Procedure_Call_Statement
then
return;
end if;
pragma Assert (Nkind (N) = N_Indexed_Component);
P_T := Base_Type (Etype (P));
if Is_Entity_Name (P)
or else Nkind (P) = N_Operator_Symbol
then
U_N := Entity (P);
if Ekind (U_N) in Type_Kind then
E := Remove_Head (Exprs);
if Present (First (Exprs)) then
Error_Msg_N
("argument of type conversion must be single expression", N);
end if;
Change_Node (N, N_Type_Conversion);
Set_Subtype_Mark (N, P);
Set_Etype (N, U_N);
Set_Expression (N, E);
Analyze_Type_Conversion (N);
return;
end if;
if Is_Overloadable (U_N) then
Process_Function_Call;
elsif Ekind (Etype (P)) = E_Subprogram_Type
or else (Is_Access_Type (Etype (P))
and then
Ekind (Designated_Type (Etype (P))) = E_Subprogram_Type)
then
Process_Function_Call;
elsif Is_Generic_Subprogram (U_N) then
Error_Msg_N ("generic subprogram cannot be called", N);
Set_Etype (N, Any_Type);
return;
else
Process_Indexed_Component_Or_Slice;
end if;
else
if Ekind (P_T) = E_Subprogram_Type
or else (Is_Access_Type (P_T)
and then
Ekind (Designated_Type (P_T)) = E_Subprogram_Type)
then
Process_Function_Call;
elsif Nkind (P) = N_Selected_Component
and then Is_Overloadable (Entity (Selector_Name (P)))
then
Process_Function_Call;
else
Process_Indexed_Component_Or_Slice;
end if;
end if;
end Analyze_Indexed_Component_Form;
procedure Analyze_Logical_Op (N : Node_Id) is
L : constant Node_Id := Left_Opnd (N);
R : constant Node_Id := Right_Opnd (N);
Op_Id : Entity_Id := Entity (N);
begin
Set_Etype (N, Any_Type);
Candidate_Type := Empty;
Analyze_Expression (L);
Analyze_Expression (R);
if Present (Op_Id) then
if Ekind (Op_Id) = E_Operator then
Find_Boolean_Types (L, R, Op_Id, N);
else
Add_One_Interp (N, Op_Id, Etype (Op_Id));
end if;
else
Op_Id := Get_Name_Entity_Id (Chars (N));
while Present (Op_Id) loop
if Ekind (Op_Id) = E_Operator then
Find_Boolean_Types (L, R, Op_Id, N);
else
Analyze_User_Defined_Binary_Op (N, Op_Id);
end if;
Op_Id := Homonym (Op_Id);
end loop;
end if;
Operator_Check (N);
end Analyze_Logical_Op;
procedure Analyze_Membership_Op (N : Node_Id) is
L : constant Node_Id := Left_Opnd (N);
R : constant Node_Id := Right_Opnd (N);
Index : Interp_Index;
It : Interp;
Found : Boolean := False;
I_F : Interp_Index;
T_F : Entity_Id;
procedure Try_One_Interp (T1 : Entity_Id);
procedure Try_One_Interp (T1 : Entity_Id) is
begin
if Has_Compatible_Type (R, T1) then
if Found
and then Base_Type (T1) /= Base_Type (T_F)
then
It := Disambiguate (L, I_F, Index, Any_Type);
if It = No_Interp then
Ambiguous_Operands (N);
Set_Etype (L, Any_Type);
return;
else
T_F := It.Typ;
end if;
else
Found := True;
T_F := T1;
I_F := Index;
end if;
Set_Etype (L, T_F);
end if;
end Try_One_Interp;
begin
Analyze_Expression (L);
if Nkind (R) = N_Range
or else (Nkind (R) = N_Attribute_Reference
and then Attribute_Name (R) = Name_Range)
then
Analyze (R);
if not Is_Overloaded (L) then
Try_One_Interp (Etype (L));
else
Get_First_Interp (L, Index, It);
while Present (It.Typ) loop
Try_One_Interp (It.Typ);
Get_Next_Interp (Index, It);
end loop;
end if;
else
Find_Type (R);
if Is_Entity_Name (R) then
Check_Fully_Declared (Entity (R), R);
end if;
end if;
Set_Etype (N, Standard_Boolean);
end Analyze_Membership_Op;
procedure Analyze_Negation (N : Node_Id) is
R : constant Node_Id := Right_Opnd (N);
Op_Id : Entity_Id := Entity (N);
begin
Set_Etype (N, Any_Type);
Candidate_Type := Empty;
Analyze_Expression (R);
if Present (Op_Id) then
if Ekind (Op_Id) = E_Operator then
Find_Negation_Types (R, Op_Id, N);
else
Add_One_Interp (N, Op_Id, Etype (Op_Id));
end if;
else
Op_Id := Get_Name_Entity_Id (Chars (N));
while Present (Op_Id) loop
if Ekind (Op_Id) = E_Operator then
Find_Negation_Types (R, Op_Id, N);
else
Analyze_User_Defined_Unary_Op (N, Op_Id);
end if;
Op_Id := Homonym (Op_Id);
end loop;
end if;
Operator_Check (N);
end Analyze_Negation;
procedure Analyze_Null (N : Node_Id) is
begin
Set_Etype (N, Any_Access);
end Analyze_Null;
procedure Analyze_One_Call
(N : Node_Id;
Nam : Entity_Id;
Report : Boolean;
Success : out Boolean)
is
Actuals : constant List_Id := Parameter_Associations (N);
Prev_T : constant Entity_Id := Etype (N);
Formal : Entity_Id;
Actual : Node_Id;
Is_Indexed : Boolean := False;
Subp_Type : constant Entity_Id := Etype (Nam);
Norm_OK : Boolean;
procedure Indicate_Name_And_Type;
procedure Indicate_Name_And_Type is
begin
Add_One_Interp (N, Nam, Etype (Nam));
Success := True;
if not Is_Type (Nam) then
if Is_Entity_Name (Name (N))
or else Nkind (Name (N)) = N_Operator_Symbol
then
Set_Entity (Name (N), Nam);
elsif Nkind (Name (N)) = N_Selected_Component then
Set_Entity (Selector_Name (Name (N)), Nam);
end if;
end if;
if Debug_Flag_E and not Report then
Write_Str (" Overloaded call ");
Write_Int (Int (N));
Write_Str (" compatible with ");
Write_Int (Int (Nam));
Write_Eol;
end if;
end Indicate_Name_And_Type;
begin
Success := False;
if Needs_No_Actuals (Nam)
and then Present (Actuals)
then
if Is_Array_Type (Subp_Type) then
Is_Indexed := Try_Indexed_Call (N, Nam, Subp_Type);
elsif Is_Access_Type (Subp_Type)
and then Is_Array_Type (Designated_Type (Subp_Type))
then
Is_Indexed :=
Try_Indexed_Call (N, Nam, Designated_Type (Subp_Type));
elsif Is_Access_Type (Subp_Type)
and then Ekind (Designated_Type (Subp_Type)) = E_Subprogram_Type
then
Is_Indexed := Try_Indirect_Call (N, Nam, Subp_Type);
end if;
end if;
Normalize_Actuals (N, Nam, (Report and not Is_Indexed), Norm_OK);
if not Norm_OK then
if Debug_Flag_E then
Write_Str (" normalization fails in call ");
Write_Int (Int (N));
Write_Str (" with subprogram ");
Write_Int (Int (Nam));
Write_Eol;
end if;
elsif Nkind (N) = N_Function_Call
and then Is_Overloaded (Name (N))
and then Ekind (Nam) = E_Procedure
then
return;
elsif Nkind (N) = N_Procedure_Call_Statement
and then Is_Overloaded (Name (N))
and then Etype (Nam) /= Standard_Void_Type
then
return;
elsif not Present (Actuals) then
Indicate_Name_And_Type;
elsif Ekind (Nam) = E_Operator then
if Nkind (N) = N_Procedure_Call_Statement then
return;
end if;
Analyze_Operator_Call (N, Nam);
if Etype (N) /= Prev_T then
if Is_Overloaded (Name (N)) then
declare
I : Interp_Index;
It : Interp;
begin
Get_First_Interp (Name (N), I, It);
while Present (It.Nam) loop
if Ekind (It.Nam) /= E_Operator
and then Hides_Op (It.Nam, Nam)
and then
Has_Compatible_Type
(First_Actual (N), Etype (First_Formal (It.Nam)))
and then (No (Next_Actual (First_Actual (N)))
or else Has_Compatible_Type
(Next_Actual (First_Actual (N)),
Etype (Next_Formal (First_Formal (It.Nam)))))
then
Set_Etype (N, Prev_T);
return;
end if;
Get_Next_Interp (I, It);
end loop;
end;
end if;
Set_Entity (Name (N), Nam);
Success := True;
elsif Report and then Etype (N) = Any_Type then
Error_Msg_N ("incompatible arguments for operator", N);
end if;
else
Actual := First_Actual (N);
Formal := First_Formal (Nam);
while Present (Actual) and then Present (Formal) loop
if Nkind (Parent (Actual)) /= N_Parameter_Association
or else Chars (Selector_Name (Parent (Actual))) = Chars (Formal)
then
if Has_Compatible_Type (Actual, Etype (Formal)) then
Next_Actual (Actual);
Next_Formal (Formal);
else
if Debug_Flag_E then
Write_Str (" type checking fails in call ");
Write_Int (Int (N));
Write_Str (" with formal ");
Write_Int (Int (Formal));
Write_Str (" in subprogram ");
Write_Int (Int (Nam));
Write_Eol;
end if;
if Report and not Is_Indexed then
Wrong_Type (Actual, Etype (Formal));
if Nkind (Actual) = N_Op_Eq
and then Nkind (Left_Opnd (Actual)) = N_Identifier
then
Formal := First_Formal (Nam);
while Present (Formal) loop
if Chars (Left_Opnd (Actual)) = Chars (Formal) then
Error_Msg_N
("possible misspelling of `='>`!", Actual);
exit;
end if;
Next_Formal (Formal);
end loop;
end if;
if All_Errors_Mode then
Error_Msg_Sloc := Sloc (Nam);
if Is_Overloadable (Nam)
and then Present (Alias (Nam))
and then not Comes_From_Source (Nam)
then
Error_Msg_NE
(" =='> in call to &#(inherited)!", Actual, Nam);
elsif Ekind (Nam) = E_Subprogram_Type then
declare
Access_To_Subprogram_Typ :
constant Entity_Id :=
Defining_Identifier
(Associated_Node_For_Itype (Nam));
begin
Error_Msg_NE (
" =='> in call to dereference of &#!",
Actual, Access_To_Subprogram_Typ);
end;
else
Error_Msg_NE (" =='> in call to &#!", Actual, Nam);
end if;
end if;
end if;
return;
end if;
else
Next_Formal (Formal);
end if;
end loop;
Indicate_Name_And_Type;
end if;
end Analyze_One_Call;
procedure Analyze_Operator_Call (N : Node_Id; Op_Id : Entity_Id) is
Op_Name : constant Name_Id := Chars (Op_Id);
Act1 : constant Node_Id := First_Actual (N);
Act2 : constant Node_Id := Next_Actual (Act1);
begin
if Present (Act2) then
if Present (Next_Actual (Act2)) then
return;
elsif Op_Name = Name_Op_Add
or else Op_Name = Name_Op_Subtract
or else Op_Name = Name_Op_Multiply
or else Op_Name = Name_Op_Divide
or else Op_Name = Name_Op_Mod
or else Op_Name = Name_Op_Rem
or else Op_Name = Name_Op_Expon
then
Find_Arithmetic_Types (Act1, Act2, Op_Id, N);
elsif Op_Name = Name_Op_And
or else Op_Name = Name_Op_Or
or else Op_Name = Name_Op_Xor
then
Find_Boolean_Types (Act1, Act2, Op_Id, N);
elsif Op_Name = Name_Op_Lt
or else Op_Name = Name_Op_Le
or else Op_Name = Name_Op_Gt
or else Op_Name = Name_Op_Ge
then
Find_Comparison_Types (Act1, Act2, Op_Id, N);
elsif Op_Name = Name_Op_Eq
or else Op_Name = Name_Op_Ne
then
Find_Equality_Types (Act1, Act2, Op_Id, N);
elsif Op_Name = Name_Op_Concat then
Find_Concatenation_Types (Act1, Act2, Op_Id, N);
else
null;
end if;
else
if Op_Name = Name_Op_Subtract or else
Op_Name = Name_Op_Add or else
Op_Name = Name_Op_Abs
then
Find_Unary_Types (Act1, Op_Id, N);
elsif
Op_Name = Name_Op_Not
then
Find_Negation_Types (Act1, Op_Id, N);
else
null;
end if;
end if;
end Analyze_Operator_Call;
procedure Analyze_Overloaded_Selected_Component (N : Node_Id) is
Nam : constant Node_Id := Prefix (N);
Sel : constant Node_Id := Selector_Name (N);
Comp : Entity_Id;
I : Interp_Index;
It : Interp;
T : Entity_Id;
begin
Set_Etype (Sel, Any_Type);
Get_First_Interp (Nam, I, It);
while Present (It.Typ) loop
if Is_Access_Type (It.Typ) then
T := Designated_Type (It.Typ);
Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
else
T := It.Typ;
end if;
if Is_Record_Type (T) then
Comp := First_Entity (T);
while Present (Comp) loop
if Chars (Comp) = Chars (Sel)
and then Is_Visible_Component (Comp)
then
Set_Entity_With_Style_Check (Sel, Comp);
Generate_Reference (Comp, Sel);
Set_Etype (Sel, Etype (Comp));
Add_One_Interp (N, Etype (Comp), Etype (Comp));
Set_Etype (Nam, It.Typ);
end if;
Next_Entity (Comp);
end loop;
elsif Is_Concurrent_Type (T) then
Comp := First_Entity (T);
while Present (Comp)
and then Comp /= First_Private_Entity (T)
loop
if Chars (Comp) = Chars (Sel) then
if Is_Overloadable (Comp) then
Add_One_Interp (Sel, Comp, Etype (Comp));
else
Set_Entity_With_Style_Check (Sel, Comp);
Generate_Reference (Comp, Sel);
end if;
Set_Etype (Sel, Etype (Comp));
Set_Etype (N, Etype (Comp));
Set_Etype (Nam, It.Typ);
if Is_Access_Type (Etype (Nam)) then
Insert_Explicit_Dereference (Nam);
Error_Msg_NW
(Warn_On_Dereference, "?implicit dereference", N);
end if;
end if;
Next_Entity (Comp);
end loop;
Set_Is_Overloaded (N, Is_Overloaded (Sel));
end if;
Get_Next_Interp (I, It);
end loop;
if Etype (N) = Any_Type then
Error_Msg_NE ("undefined selector& for overloaded prefix", N, Sel);
Set_Entity (Sel, Any_Id);
Set_Etype (Sel, Any_Type);
end if;
end Analyze_Overloaded_Selected_Component;
procedure Analyze_Qualified_Expression (N : Node_Id) is
Mark : constant Entity_Id := Subtype_Mark (N);
T : Entity_Id;
begin
Set_Etype (N, Any_Type);
Find_Type (Mark);
T := Entity (Mark);
if T = Any_Type then
return;
end if;
Check_Fully_Declared (T, N);
Analyze_Expression (Expression (N));
Set_Etype (N, T);
end Analyze_Qualified_Expression;
procedure Analyze_Range (N : Node_Id) is
L : constant Node_Id := Low_Bound (N);
H : constant Node_Id := High_Bound (N);
I1, I2 : Interp_Index;
It1, It2 : Interp;
procedure Check_Common_Type (T1, T2 : Entity_Id);
procedure Check_High_Bound (T : Entity_Id);
procedure Check_Universal_Expression (N : Node_Id);
procedure Check_Common_Type (T1, T2 : Entity_Id) is
begin
if Covers (T1, T2) or else Covers (T2, T1) then
if T1 = Universal_Integer
or else T1 = Universal_Real
or else T1 = Any_Character
then
Add_One_Interp (N, Base_Type (T2), Base_Type (T2));
elsif T1 = T2 then
Add_One_Interp (N, T1, T1);
else
Add_One_Interp (N, Base_Type (T1), Base_Type (T1));
end if;
end if;
end Check_Common_Type;
procedure Check_High_Bound (T : Entity_Id) is
begin
if not Is_Overloaded (H) then
Check_Common_Type (T, Etype (H));
else
Get_First_Interp (H, I2, It2);
while Present (It2.Typ) loop
Check_Common_Type (T, It2.Typ);
Get_Next_Interp (I2, It2);
end loop;
end if;
end Check_High_Bound;
procedure Check_Universal_Expression (N : Node_Id) is
begin
if Etype (N) = Universal_Integer
and then Nkind (N) /= N_Integer_Literal
and then not Is_Entity_Name (N)
and then Nkind (N) /= N_Attribute_Reference
then
Error_Msg_N ("illegal bound in discrete range", N);
end if;
end Check_Universal_Expression;
begin
Set_Etype (N, Any_Type);
Analyze_Expression (L);
Analyze_Expression (H);
if Etype (L) = Any_Type or else Etype (H) = Any_Type then
return;
else
if not Is_Overloaded (L) then
Check_High_Bound (Etype (L));
else
Get_First_Interp (L, I1, It1);
while Present (It1.Typ) loop
Check_High_Bound (It1.Typ);
Get_Next_Interp (I1, It1);
end loop;
end if;
if Etype (N) = Any_Type then
Error_Msg_N ("incompatible types in range ", N);
end if;
end if;
if Ada_Version = Ada_83
and then
(Nkind (Parent (N)) = N_Loop_Parameter_Specification
or else Nkind (Parent (N)) = N_Constrained_Array_Definition)
then
Check_Universal_Expression (L);
Check_Universal_Expression (H);
end if;
end Analyze_Range;
procedure Analyze_Reference (N : Node_Id) is
P : constant Node_Id := Prefix (N);
Acc_Type : Entity_Id;
begin
Analyze (P);
Acc_Type := Create_Itype (E_Allocator_Type, N);
Set_Etype (Acc_Type, Acc_Type);
Init_Size_Align (Acc_Type);
Set_Directly_Designated_Type (Acc_Type, Etype (P));
Set_Etype (N, Acc_Type);
end Analyze_Reference;
procedure Analyze_Selected_Component (N : Node_Id) is
Name : constant Node_Id := Prefix (N);
Sel : constant Node_Id := Selector_Name (N);
Comp : Entity_Id;
Entity_List : Entity_Id;
Prefix_Type : Entity_Id;
Pent : Entity_Id := Empty;
Act_Decl : Node_Id;
In_Scope : Boolean;
Parent_N : Node_Id;
begin
Set_Etype (N, Any_Type);
if Is_Overloaded (Name) then
Analyze_Overloaded_Selected_Component (N);
return;
elsif Etype (Name) = Any_Type then
Set_Entity (Sel, Any_Id);
Set_Etype (Sel, Any_Type);
return;
else
if Nkind (Name) = N_Function_Call then
Resolve (Name);
end if;
Prefix_Type := Etype (Name);
end if;
if Is_Access_Type (Prefix_Type) then
if Is_Remote_Access_To_Class_Wide_Type (Prefix_Type)
and then Comes_From_Source (N)
then
Error_Msg_N
("invalid dereference of a remote access to class-wide value",
N);
else
Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
if Is_Entity_Name (Name) then
Pent := Entity (Name);
elsif Nkind (Name) = N_Selected_Component
and then Is_Entity_Name (Selector_Name (Name))
then
Pent := Entity (Selector_Name (Name));
end if;
Process_Implicit_Dereference_Prefix (Pent, Name);
end if;
Prefix_Type := Designated_Type (Prefix_Type);
end if;
if Ekind (Prefix_Type) = E_Private_Subtype then
Prefix_Type := Base_Type (Prefix_Type);
end if;
Entity_List := Prefix_Type;
if Is_Class_Wide_Type (Prefix_Type) then
Entity_List := Root_Type (Prefix_Type);
end if;
Comp := First_Entity (Entity_List);
if Nkind (Sel) = N_Identifier
and then Present (Original_Discriminant (Sel))
then
Comp := Find_Corresponding_Discriminant (Sel, Prefix_Type);
Set_Entity (Sel, Comp);
Rewrite (Selector_Name (N),
New_Occurrence_Of (Comp, Sloc (N)));
Set_Original_Discriminant (Selector_Name (N), Comp);
Set_Etype (N, Etype (Comp));
if Is_Access_Type (Etype (Name)) then
Insert_Explicit_Dereference (Name);
Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
end if;
elsif Is_Record_Type (Prefix_Type) then
while Present (Comp) loop
if Chars (Comp) = Chars (Sel)
and then Is_Visible_Component (Comp)
then
Set_Entity_With_Style_Check (Sel, Comp);
Generate_Reference (Comp, Sel);
Set_Etype (Sel, Etype (Comp));
if Ekind (Comp) = E_Discriminant then
if Is_Unchecked_Union (Base_Type (Prefix_Type)) then
Error_Msg_N
("cannot reference discriminant of Unchecked_Union",
Sel);
end if;
if Is_Generic_Type (Prefix_Type)
or else
Is_Generic_Type (Root_Type (Prefix_Type))
then
Set_Original_Discriminant (Sel, Comp);
end if;
end if;
Resolve (Name);
Parent_N := Parent (N);
if not Is_Packed (Etype (Comp))
and then
((Nkind (Parent_N) = N_Indexed_Component
and then Nkind (Name) /= N_Selected_Component)
or else
(Nkind (Parent_N) = N_Attribute_Reference
and then (Attribute_Name (Parent_N) = Name_First
or else
Attribute_Name (Parent_N) = Name_Last
or else
Attribute_Name (Parent_N) = Name_Length
or else
Attribute_Name (Parent_N) = Name_Range)))
then
Set_Etype (N, Etype (Comp));
else
Act_Decl :=
Build_Actual_Subtype_Of_Component (Etype (Comp), N);
Insert_Action (N, Act_Decl);
if No (Act_Decl) then
Set_Etype (N, Etype (Comp));
else
declare
Subt : constant Entity_Id :=
Defining_Identifier (Act_Decl);
begin
Set_Etype (Subt, Base_Type (Etype (Comp)));
Set_Ekind (Subt, Ekind (Etype (Comp)));
Set_Etype (N, Subt);
end;
end if;
end if;
return;
end if;
Next_Entity (Comp);
end loop;
if Ada_Version >= Ada_05
and then Is_Tagged_Type (Prefix_Type)
and then Try_Object_Operation (N)
then
return;
end if;
elsif Is_Private_Type (Prefix_Type) then
if No (Full_View (Prefix_Type)) then
Entity_List := Root_Type (Base_Type (Prefix_Type));
Comp := First_Entity (Entity_List);
end if;
while Present (Comp) loop
if Chars (Comp) = Chars (Sel) then
if Ekind (Comp) = E_Discriminant then
Set_Entity_With_Style_Check (Sel, Comp);
Generate_Reference (Comp, Sel);
Set_Etype (Sel, Etype (Comp));
Set_Etype (N, Etype (Comp));
if Is_Generic_Type (Prefix_Type)
or else
Is_Generic_Type (Root_Type (Prefix_Type))
then
Set_Original_Discriminant (Sel, Comp);
end if;
else
Error_Msg_NE
("invisible selector for }",
N, First_Subtype (Prefix_Type));
Set_Entity (Sel, Any_Id);
Set_Etype (N, Any_Type);
end if;
return;
end if;
Next_Entity (Comp);
end loop;
elsif Is_Concurrent_Type (Prefix_Type) then
Set_Etype (Sel, Any_Type);
In_Scope := In_Open_Scopes (Prefix_Type);
while Present (Comp) loop
if Chars (Comp) = Chars (Sel) then
if Is_Overloadable (Comp) then
Add_One_Interp (Sel, Comp, Etype (Comp));
elsif Ekind (Comp) = E_Discriminant
or else Ekind (Comp) = E_Entry_Family
or else (In_Scope
and then Is_Entity_Name (Name))
then
Set_Entity_With_Style_Check (Sel, Comp);
Generate_Reference (Comp, Sel);
else
goto Next_Comp;
end if;
Set_Etype (Sel, Etype (Comp));
Set_Etype (N, Etype (Comp));
if Ekind (Comp) = E_Discriminant then
Set_Original_Discriminant (Sel, Comp);
end if;
if Is_Access_Type (Etype (Name)) then
Insert_Explicit_Dereference (Name);
Error_Msg_NW
(Warn_On_Dereference, "?implicit dereference", N);
end if;
end if;
<<Next_Comp>>
Next_Entity (Comp);
exit when not In_Scope
and then
Comp = First_Private_Entity (Base_Type (Prefix_Type));
end loop;
Set_Is_Overloaded (N, Is_Overloaded (Sel));
else
Error_Msg_NE ("invalid prefix in selected component&", N, Sel);
end if;
if Etype (N) = Any_Type then
if Is_Concurrent_Type (Prefix_Type)
and then Is_Internal_Name (Chars (Prefix_Type))
and then not Is_Derived_Type (Prefix_Type)
and then Is_Entity_Name (Name)
then
Error_Msg_Node_2 := Entity (Name);
Error_Msg_NE ("no selector& for&", N, Sel);
Check_Misspelled_Selector (Entity_List, Sel);
elsif Is_Generic_Type (Prefix_Type)
and then Ekind (Prefix_Type) = E_Record_Type_With_Private
and then Prefix_Type /= Etype (Prefix_Type)
and then Is_Record_Type (Etype (Prefix_Type))
then
Set_Etype (Prefix (N), Etype (Prefix_Type));
Analyze_Selected_Component (N);
return;
elsif Ekind (Prefix_Type) = E_Record_Subtype_With_Private
and then Is_Generic_Actual_Type (Prefix_Type)
and then Present (Full_View (Prefix_Type))
then
declare
Comp : Entity_Id;
begin
Comp :=
First_Component (Generic_Parent_Type (Parent (Prefix_Type)));
while Present (Comp) loop
if Chars (Comp) = Chars (Sel) then
Set_Entity_With_Style_Check (Sel, Comp);
Set_Etype (Sel, Etype (Comp));
Set_Etype (N, Etype (Comp));
exit;
end if;
Next_Component (Comp);
end loop;
pragma Assert (Etype (N) /= Any_Type);
end;
else
if Ekind (Prefix_Type) = E_Record_Subtype then
Comp := First_Component (Base_Type (Prefix_Type));
while Present (Comp) loop
if Chars (Comp) = Chars (Sel)
and then Is_Visible_Component (Comp)
then
Set_Entity_With_Style_Check (Sel, Comp);
Generate_Reference (Comp, Sel);
Set_Etype (Sel, Etype (Comp));
Set_Etype (N, Etype (Comp));
Apply_Compile_Time_Constraint_Error
(N, "component not present in }?",
CE_Discriminant_Check_Failed,
Ent => Prefix_Type, Rep => False);
Set_Raises_Constraint_Error (N);
return;
end if;
Next_Component (Comp);
end loop;
end if;
Error_Msg_Node_2 := First_Subtype (Prefix_Type);
Error_Msg_NE ("no selector& for}", N, Sel);
Check_Misspelled_Selector (Entity_List, Sel);
end if;
Set_Entity (Sel, Any_Id);
Set_Etype (Sel, Any_Type);
end if;
end Analyze_Selected_Component;
procedure Analyze_Short_Circuit (N : Node_Id) is
L : constant Node_Id := Left_Opnd (N);
R : constant Node_Id := Right_Opnd (N);
Ind : Interp_Index;
It : Interp;
begin
Analyze_Expression (L);
Analyze_Expression (R);
Set_Etype (N, Any_Type);
if not Is_Overloaded (L) then
if Root_Type (Etype (L)) = Standard_Boolean
and then Has_Compatible_Type (R, Etype (L))
then
Add_One_Interp (N, Etype (L), Etype (L));
end if;
else
Get_First_Interp (L, Ind, It);
while Present (It.Typ) loop
if Root_Type (It.Typ) = Standard_Boolean
and then Has_Compatible_Type (R, It.Typ)
then
Add_One_Interp (N, It.Typ, It.Typ);
end if;
Get_Next_Interp (Ind, It);
end loop;
end if;
if Etype (N) = Any_Type then
Resolve (L, Standard_Boolean);
Resolve (R, Standard_Boolean);
Set_Etype (N, Standard_Boolean);
end if;
end Analyze_Short_Circuit;
procedure Analyze_Slice (N : Node_Id) is
P : constant Node_Id := Prefix (N);
D : constant Node_Id := Discrete_Range (N);
Array_Type : Entity_Id;
procedure Analyze_Overloaded_Slice;
procedure Analyze_Overloaded_Slice is
I : Interp_Index;
It : Interp;
Typ : Entity_Id;
begin
Set_Etype (N, Any_Type);
Get_First_Interp (P, I, It);
while Present (It.Nam) loop
Typ := It.Typ;
if Is_Access_Type (Typ) then
Typ := Designated_Type (Typ);
Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
end if;
if Is_Array_Type (Typ)
and then Number_Dimensions (Typ) = 1
and then Has_Compatible_Type (D, Etype (First_Index (Typ)))
then
Add_One_Interp (N, Typ, Typ);
end if;
Get_Next_Interp (I, It);
end loop;
if Etype (N) = Any_Type then
Error_Msg_N ("expect array type in prefix of slice", N);
end if;
end Analyze_Overloaded_Slice;
begin
Analyze (P);
Analyze (D);
if Is_Overloaded (P) then
Analyze_Overloaded_Slice;
else
Array_Type := Etype (P);
Set_Etype (N, Any_Type);
if Is_Access_Type (Array_Type) then
Array_Type := Designated_Type (Array_Type);
Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
end if;
if not Is_Array_Type (Array_Type) then
Wrong_Type (P, Any_Array);
elsif Number_Dimensions (Array_Type) > 1 then
Error_Msg_N
("type is not one-dimensional array in slice prefix", N);
elsif not
Has_Compatible_Type (D, Etype (First_Index (Array_Type)))
then
Wrong_Type (D, Etype (First_Index (Array_Type)));
else
Set_Etype (N, Array_Type);
end if;
end if;
end Analyze_Slice;
procedure Analyze_Type_Conversion (N : Node_Id) is
Expr : constant Node_Id := Expression (N);
T : Entity_Id;
begin
if Conversion_OK (N) then
Analyze (Expr);
return;
end if;
Find_Type (Subtype_Mark (N));
T := Entity (Subtype_Mark (N));
Set_Etype (N, T);
Check_Fully_Declared (T, N);
Analyze_Expression (Expr);
Validate_Remote_Type_Type_Conversion (N);
if not Comes_From_Source (N) then
return;
elsif Nkind (Expr) = N_Null then
Error_Msg_N ("argument of conversion cannot be null", N);
Error_Msg_N ("\use qualified expression instead", N);
Set_Etype (N, Any_Type);
elsif Nkind (Expr) = N_Aggregate then
Error_Msg_N ("argument of conversion cannot be aggregate", N);
Error_Msg_N ("\use qualified expression instead", N);
elsif Nkind (Expr) = N_Allocator then
Error_Msg_N ("argument of conversion cannot be an allocator", N);
Error_Msg_N ("\use qualified expression instead", N);
elsif Nkind (Expr) = N_String_Literal then
Error_Msg_N ("argument of conversion cannot be string literal", N);
Error_Msg_N ("\use qualified expression instead", N);
elsif Nkind (Expr) = N_Character_Literal then
if Ada_Version = Ada_83 then
Resolve (Expr, T);
else
Error_Msg_N ("argument of conversion cannot be character literal",
N);
Error_Msg_N ("\use qualified expression instead", N);
end if;
elsif Nkind (Expr) = N_Attribute_Reference
and then
(Attribute_Name (Expr) = Name_Access or else
Attribute_Name (Expr) = Name_Unchecked_Access or else
Attribute_Name (Expr) = Name_Unrestricted_Access)
then
Error_Msg_N ("argument of conversion cannot be access", N);
Error_Msg_N ("\use qualified expression instead", N);
end if;
end Analyze_Type_Conversion;
procedure Analyze_Unary_Op (N : Node_Id) is
R : constant Node_Id := Right_Opnd (N);
Op_Id : Entity_Id := Entity (N);
begin
Set_Etype (N, Any_Type);
Candidate_Type := Empty;
Analyze_Expression (R);
if Present (Op_Id) then
if Ekind (Op_Id) = E_Operator then
Find_Unary_Types (R, Op_Id, N);
else
Add_One_Interp (N, Op_Id, Etype (Op_Id));
end if;
else
Op_Id := Get_Name_Entity_Id (Chars (N));
while Present (Op_Id) loop
if Ekind (Op_Id) = E_Operator then
if No (Next_Entity (First_Entity (Op_Id))) then
Find_Unary_Types (R, Op_Id, N);
end if;
elsif Is_Overloadable (Op_Id) then
Analyze_User_Defined_Unary_Op (N, Op_Id);
end if;
Op_Id := Homonym (Op_Id);
end loop;
end if;
Operator_Check (N);
end Analyze_Unary_Op;
procedure Analyze_Unchecked_Expression (N : Node_Id) is
begin
Analyze (Expression (N), Suppress => All_Checks);
Set_Etype (N, Etype (Expression (N)));
Save_Interps (Expression (N), N);
end Analyze_Unchecked_Expression;
procedure Analyze_Unchecked_Type_Conversion (N : Node_Id) is
begin
Find_Type (Subtype_Mark (N));
Analyze_Expression (Expression (N));
Set_Etype (N, Entity (Subtype_Mark (N)));
end Analyze_Unchecked_Type_Conversion;
procedure Analyze_User_Defined_Binary_Op
(N : Node_Id;
Op_Id : Entity_Id)
is
begin
if Comes_From_Source (N) then
declare
F1 : constant Entity_Id := First_Formal (Op_Id);
F2 : constant Entity_Id := Next_Formal (F1);
begin
if Ekind (Op_Id) = E_Function
and then Present (F2)
and then (Is_Immediately_Visible (Op_Id)
or else Is_Potentially_Use_Visible (Op_Id))
and then Has_Compatible_Type (Left_Opnd (N), Etype (F1))
and then Has_Compatible_Type (Right_Opnd (N), Etype (F2))
then
Add_One_Interp (N, Op_Id, Etype (Op_Id));
if Debug_Flag_E then
Write_Str ("user defined operator ");
Write_Name (Chars (Op_Id));
Write_Str (" on node ");
Write_Int (Int (N));
Write_Eol;
end if;
end if;
end;
end if;
end Analyze_User_Defined_Binary_Op;
procedure Analyze_User_Defined_Unary_Op
(N : Node_Id;
Op_Id : Entity_Id)
is
begin
if Comes_From_Source (N) then
declare
F : constant Entity_Id := First_Formal (Op_Id);
begin
if Ekind (Op_Id) = E_Function
and then No (Next_Formal (F))
and then (Is_Immediately_Visible (Op_Id)
or else Is_Potentially_Use_Visible (Op_Id))
and then Has_Compatible_Type (Right_Opnd (N), Etype (F))
then
Add_One_Interp (N, Op_Id, Etype (Op_Id));
end if;
end;
end if;
end Analyze_User_Defined_Unary_Op;
procedure Check_Arithmetic_Pair
(T1, T2 : Entity_Id;
Op_Id : Entity_Id;
N : Node_Id)
is
Op_Name : constant Name_Id := Chars (Op_Id);
function Has_Fixed_Op (Typ : Entity_Id; Op : Entity_Id) return Boolean;
function Specific_Type (T1, T2 : Entity_Id) return Entity_Id;
function Has_Fixed_Op (Typ : Entity_Id; Op : Entity_Id) return Boolean is
Ent : Entity_Id;
F1 : Entity_Id;
F2 : Entity_Id;
begin
Ent := Next_Entity (Typ);
while Present (Ent) loop
if Chars (Ent) = Chars (Op) then
F1 := First_Formal (Ent);
F2 := Next_Formal (F1);
if (Etype (F1) = Typ
and then Is_Fixed_Point_Type (Etype (F2)))
or else
(Etype (F2) = Typ
and then Is_Fixed_Point_Type (Etype (F1)))
or else
(Etype (Ent) = Typ
and then Is_Fixed_Point_Type (Etype (F1))
and then Is_Fixed_Point_Type (Etype (F2)))
then
return True;
end if;
end if;
Next_Entity (Ent);
end loop;
return False;
end Has_Fixed_Op;
function Specific_Type (T1, T2 : Entity_Id) return Entity_Id is
begin
if T1 = Universal_Integer or else T1 = Universal_Real then
return Base_Type (T2);
else
return Base_Type (T1);
end if;
end Specific_Type;
begin
if Op_Name = Name_Op_Add or else Op_Name = Name_Op_Subtract then
if Is_Numeric_Type (T1)
and then Is_Numeric_Type (T2)
and then (Covers (T1, T2) or else Covers (T2, T1))
then
Add_One_Interp (N, Op_Id, Specific_Type (T1, T2));
end if;
elsif Op_Name = Name_Op_Multiply or else Op_Name = Name_Op_Divide then
if Is_Fixed_Point_Type (T1)
and then (Is_Fixed_Point_Type (T2)
or else T2 = Universal_Real)
then
if (Nkind (N) not in N_Op
or else not Treat_Fixed_As_Integer (N))
and then
(not (Ada_Version >= Ada_05 and then Has_Fixed_Op (T1, Op_Id))
or else Nkind (Parent (N)) = N_Type_Conversion)
then
Add_One_Interp (N, Op_Id, Universal_Fixed);
end if;
elsif Is_Fixed_Point_Type (T2)
and then (Nkind (N) not in N_Op
or else not Treat_Fixed_As_Integer (N))
and then T1 = Universal_Real
and then
(not (Ada_Version >= Ada_05 and then Has_Fixed_Op (T1, Op_Id))
or else Nkind (Parent (N)) = N_Type_Conversion)
then
Add_One_Interp (N, Op_Id, Universal_Fixed);
elsif Is_Numeric_Type (T1)
and then Is_Numeric_Type (T2)
and then (Covers (T1, T2) or else Covers (T2, T1))
then
Add_One_Interp (N, Op_Id, Specific_Type (T1, T2));
elsif Is_Fixed_Point_Type (T1)
and then (Base_Type (T2) = Base_Type (Standard_Integer)
or else T2 = Universal_Integer)
then
Add_One_Interp (N, Op_Id, T1);
elsif T2 = Universal_Real
and then Base_Type (T1) = Base_Type (Standard_Integer)
and then Op_Name = Name_Op_Multiply
then
Add_One_Interp (N, Op_Id, Any_Fixed);
elsif T1 = Universal_Real
and then Base_Type (T2) = Base_Type (Standard_Integer)
then
Add_One_Interp (N, Op_Id, Any_Fixed);
elsif Is_Fixed_Point_Type (T2)
and then (Base_Type (T1) = Base_Type (Standard_Integer)
or else T1 = Universal_Integer)
and then Op_Name = Name_Op_Multiply
then
Add_One_Interp (N, Op_Id, T2);
elsif T1 = Universal_Real and then T2 = Universal_Integer then
Add_One_Interp (N, Op_Id, T1);
elsif T2 = Universal_Real
and then T1 = Universal_Integer
and then Op_Name = Name_Op_Multiply
then
Add_One_Interp (N, Op_Id, T2);
end if;
elsif Op_Name = Name_Op_Mod or else Op_Name = Name_Op_Rem then
if Is_Integer_Type (T1)
and then (Covers (T1, T2) or else Covers (T2, T1))
then
Add_One_Interp (N, Op_Id, Specific_Type (T1, T2));
end if;
elsif Op_Name = Name_Op_Expon then
if Is_Numeric_Type (T1)
and then not Is_Fixed_Point_Type (T1)
and then (Base_Type (T2) = Base_Type (Standard_Integer)
or else T2 = Universal_Integer)
then
Add_One_Interp (N, Op_Id, Base_Type (T1));
end if;
else pragma Assert (Nkind (N) in N_Op_Shift);
if Is_Integer_Type (T1)
and then (Base_Type (T2) = Base_Type (Standard_Integer)
or else T2 = Universal_Integer)
then
Add_One_Interp (N, Op_Id, Base_Type (T1));
end if;
end if;
end Check_Arithmetic_Pair;
procedure Check_Misspelled_Selector
(Prefix : Entity_Id;
Sel : Node_Id)
is
Max_Suggestions : constant := 2;
Nr_Of_Suggestions : Natural := 0;
Suggestion_1 : Entity_Id := Empty;
Suggestion_2 : Entity_Id := Empty;
Comp : Entity_Id;
begin
if not (Is_Private_Type (Prefix) or else Is_Record_Type (Prefix)) then
return;
end if;
Get_Name_String (Chars (Sel));
declare
S : constant String (1 .. Name_Len) := Name_Buffer (1 .. Name_Len);
begin
Comp := First_Entity (Prefix);
while Nr_Of_Suggestions <= Max_Suggestions
and then Present (Comp)
loop
if Is_Visible_Component (Comp) then
Get_Name_String (Chars (Comp));
if Is_Bad_Spelling_Of (Name_Buffer (1 .. Name_Len), S) then
Nr_Of_Suggestions := Nr_Of_Suggestions + 1;
case Nr_Of_Suggestions is
when 1 => Suggestion_1 := Comp;
when 2 => Suggestion_2 := Comp;
when others => exit;
end case;
end if;
end if;
Comp := Next_Entity (Comp);
end loop;
if Nr_Of_Suggestions = 1 then
Error_Msg_NE ("\possible misspelling of&", Sel, Suggestion_1);
elsif Nr_Of_Suggestions = 2 then
Error_Msg_Node_2 := Suggestion_2;
Error_Msg_NE ("\possible misspelling of& or&",
Sel, Suggestion_1);
end if;
end;
end Check_Misspelled_Selector;
function Defined_In_Scope (T : Entity_Id; S : Entity_Id) return Boolean
is
S1 : constant Entity_Id := Scope (Base_Type (T));
begin
return S1 = S
or else (S1 = System_Aux_Id and then S = Scope (S1));
end Defined_In_Scope;
procedure Diagnose_Call (N : Node_Id; Nam : Node_Id) is
Actual : Node_Id;
X : Interp_Index;
It : Interp;
Success : Boolean;
Err_Mode : Boolean;
New_Nam : Node_Id;
Void_Interp_Seen : Boolean := False;
begin
if Ada_Version >= Ada_05 then
Actual := First_Actual (N);
while Present (Actual) loop
if not Analyzed (Etype (Actual))
and then From_With_Type (Etype (Actual))
then
Error_Msg_Qual_Level := 1;
Error_Msg_NE
("missing with_clause for scope of imported type&",
Actual, Etype (Actual));
Error_Msg_Qual_Level := 0;
end if;
Next_Actual (Actual);
end loop;
end if;
Error_Msg_N
("no candidate interpretations match the actuals:!", Nam);
Err_Mode := All_Errors_Mode;
All_Errors_Mode := True;
if Nkind (Parent (Nam)) = N_Selected_Component then
Set_Entity (Nam, Empty);
New_Nam := New_Copy_Tree (Parent (Nam));
Set_Is_Overloaded (New_Nam, False);
Set_Is_Overloaded (Selector_Name (New_Nam), False);
Set_Parent (New_Nam, Parent (Parent (Nam)));
Analyze_Selected_Component (New_Nam);
Get_First_Interp (Selector_Name (New_Nam), X, It);
else
Get_First_Interp (Nam, X, It);
end if;
while Present (It.Nam) loop
if Etype (It.Nam) = Standard_Void_Type then
Void_Interp_Seen := True;
end if;
Analyze_One_Call (N, It.Nam, True, Success);
Get_Next_Interp (X, It);
end loop;
if Nkind (N) = N_Function_Call then
Get_First_Interp (Nam, X, It);
while Present (It.Nam) loop
if Ekind (It.Nam) = E_Function
or else Ekind (It.Nam) = E_Operator
then
return;
else
Get_Next_Interp (X, It);
end if;
end loop;
Error_Msg_N
("\context requires function call, found procedure name", Nam);
if Nkind (Parent (N)) = N_Selected_Component
and then N = Prefix (Parent (N))
then
Error_Msg_N (
"\period should probably be semicolon", Parent (N));
end if;
elsif Nkind (N) = N_Procedure_Call_Statement
and then not Void_Interp_Seen
then
Error_Msg_N (
"\function name found in procedure call", Nam);
end if;
All_Errors_Mode := Err_Mode;
end Diagnose_Call;
procedure Find_Arithmetic_Types
(L, R : Node_Id;
Op_Id : Entity_Id;
N : Node_Id)
is
Index1 : Interp_Index;
Index2 : Interp_Index;
It1 : Interp;
It2 : Interp;
procedure Check_Right_Argument (T : Entity_Id);
procedure Check_Right_Argument (T : Entity_Id) is
begin
if not Is_Overloaded (R) then
Check_Arithmetic_Pair (T, Etype (R), Op_Id, N);
else
Get_First_Interp (R, Index2, It2);
while Present (It2.Typ) loop
Check_Arithmetic_Pair (T, It2.Typ, Op_Id, N);
Get_Next_Interp (Index2, It2);
end loop;
end if;
end Check_Right_Argument;
begin
if not Is_Overloaded (L) then
Check_Right_Argument (Etype (L));
else
Get_First_Interp (L, Index1, It1);
while Present (It1.Typ) loop
Check_Right_Argument (It1.Typ);
Get_Next_Interp (Index1, It1);
end loop;
end if;
end Find_Arithmetic_Types;
procedure Find_Boolean_Types
(L, R : Node_Id;
Op_Id : Entity_Id;
N : Node_Id)
is
Index : Interp_Index;
It : Interp;
procedure Check_Numeric_Argument (T : Entity_Id);
procedure Check_Numeric_Argument (T : Entity_Id) is
begin
if T = Universal_Integer then
Add_One_Interp (N, Op_Id, Any_Modular);
elsif Is_Modular_Integer_Type (T) then
Add_One_Interp (N, Op_Id, T);
end if;
end Check_Numeric_Argument;
begin
if not Is_Overloaded (L) then
if Etype (L) = Universal_Integer
or else Etype (L) = Any_Modular
then
if not Is_Overloaded (R) then
Check_Numeric_Argument (Etype (R));
else
Get_First_Interp (R, Index, It);
while Present (It.Typ) loop
Check_Numeric_Argument (It.Typ);
Get_Next_Interp (Index, It);
end loop;
end if;
elsif Valid_Boolean_Arg (Etype (L))
and then Has_Compatible_Type (R, Etype (L))
then
Add_One_Interp (N, Op_Id, Etype (L));
end if;
else
Get_First_Interp (L, Index, It);
while Present (It.Typ) loop
if Valid_Boolean_Arg (It.Typ)
and then Has_Compatible_Type (R, It.Typ)
then
Add_One_Interp (N, Op_Id, It.Typ);
end if;
Get_Next_Interp (Index, It);
end loop;
end if;
end Find_Boolean_Types;
procedure Find_Comparison_Types
(L, R : Node_Id;
Op_Id : Entity_Id;
N : Node_Id)
is
Index : Interp_Index;
It : Interp;
Found : Boolean := False;
I_F : Interp_Index;
T_F : Entity_Id;
Scop : Entity_Id := Empty;
procedure Try_One_Interp (T1 : Entity_Id);
procedure Try_One_Interp (T1 : Entity_Id) is
begin
if Present (Scop)
and then not Defined_In_Scope (T1, Scop)
and then T1 /= Universal_Integer
and then T1 /= Universal_Real
and then T1 /= Any_String
and then T1 /= Any_Composite
then
return;
end if;
if Valid_Comparison_Arg (T1)
and then Has_Compatible_Type (R, T1)
then
if Found
and then Base_Type (T1) /= Base_Type (T_F)
then
It := Disambiguate (L, I_F, Index, Any_Type);
if It = No_Interp then
Ambiguous_Operands (N);
Set_Etype (L, Any_Type);
return;
else
T_F := It.Typ;
end if;
else
Found := True;
T_F := T1;
I_F := Index;
end if;
Set_Etype (L, T_F);
Find_Non_Universal_Interpretations (N, R, Op_Id, T1);
end if;
end Try_One_Interp;
begin
if Nkind (L) = N_Aggregate
and then Nkind (R) /= N_Aggregate
then
Find_Comparison_Types (R, L, Op_Id, N);
return;
end if;
if Nkind (N) = N_Function_Call
and then Nkind (Name (N)) = N_Expanded_Name
then
Scop := Entity (Prefix (Name (N)));
if Ekind (Scop) = E_Package
and then Present (Renamed_Entity (Scop))
then
Scop := Renamed_Entity (Scop);
Set_Entity (Prefix (Name (N)), Scop);
end if;
end if;
if not Is_Overloaded (L) then
Try_One_Interp (Etype (L));
else
Get_First_Interp (L, Index, It);
while Present (It.Typ) loop
Try_One_Interp (It.Typ);
Get_Next_Interp (Index, It);
end loop;
end if;
end Find_Comparison_Types;
procedure Find_Non_Universal_Interpretations
(N : Node_Id;
R : Node_Id;
Op_Id : Entity_Id;
T1 : Entity_Id)
is
Index : Interp_Index;
It : Interp;
begin
if T1 = Universal_Integer
or else T1 = Universal_Real
then
if not Is_Overloaded (R) then
Add_One_Interp
(N, Op_Id, Standard_Boolean, Base_Type (Etype (R)));
else
Get_First_Interp (R, Index, It);
while Present (It.Typ) loop
if Covers (It.Typ, T1) then
Add_One_Interp
(N, Op_Id, Standard_Boolean, Base_Type (It.Typ));
end if;
Get_Next_Interp (Index, It);
end loop;
end if;
else
Add_One_Interp (N, Op_Id, Standard_Boolean, Base_Type (T1));
end if;
end Find_Non_Universal_Interpretations;
procedure Find_Concatenation_Types
(L, R : Node_Id;
Op_Id : Entity_Id;
N : Node_Id)
is
Op_Type : constant Entity_Id := Etype (Op_Id);
begin
if Is_Array_Type (Op_Type)
and then not Is_Limited_Type (Op_Type)
and then (Has_Compatible_Type (L, Op_Type)
or else
Has_Compatible_Type (L, Component_Type (Op_Type)))
and then (Has_Compatible_Type (R, Op_Type)
or else
Has_Compatible_Type (R, Component_Type (Op_Type)))
then
Add_One_Interp (N, Op_Id, Op_Type);
end if;
end Find_Concatenation_Types;
procedure Find_Equality_Types
(L, R : Node_Id;
Op_Id : Entity_Id;
N : Node_Id)
is
Index : Interp_Index;
It : Interp;
Found : Boolean := False;
I_F : Interp_Index;
T_F : Entity_Id;
Scop : Entity_Id := Empty;
procedure Try_One_Interp (T1 : Entity_Id);
procedure Try_One_Interp (T1 : Entity_Id) is
begin
if Present (Scop)
and then not Defined_In_Scope (T1, Scop)
and then T1 /= Universal_Integer
and then T1 /= Universal_Real
and then T1 /= Any_Access
and then T1 /= Any_String
and then T1 /= Any_Composite
and then (Ekind (T1) /= E_Access_Subprogram_Type
or else Comes_From_Source (T1))
then
return;
end if;
if Ada_Version < Ada_05
and then Ekind (T1) = E_Anonymous_Access_Type
then
return;
end if;
if T1 /= Standard_Void_Type
and then not Is_Limited_Type (T1)
and then not Is_Limited_Composite (T1)
and then Has_Compatible_Type (R, T1)
then
if Found
and then Base_Type (T1) /= Base_Type (T_F)
then
It := Disambiguate (L, I_F, Index, Any_Type);
if It = No_Interp then
Ambiguous_Operands (N);
Set_Etype (L, Any_Type);
return;
else
T_F := It.Typ;
end if;
else
Found := True;
T_F := T1;
I_F := Index;
end if;
if not Analyzed (L) then
Set_Etype (L, T_F);
end if;
Find_Non_Universal_Interpretations (N, R, Op_Id, T1);
if Etype (N) = Any_Type then
Found := False;
end if;
end if;
end Try_One_Interp;
begin
if Nkind (L) = N_Aggregate
and then Nkind (R) /= N_Aggregate
then
Find_Equality_Types (R, L, Op_Id, N);
return;
end if;
if Nkind (N) = N_Function_Call
and then Nkind (Name (N)) = N_Expanded_Name
then
Scop := Entity (Prefix (Name (N)));
if Ekind (Scop) = E_Package
and then Present (Renamed_Entity (Scop))
then
Scop := Renamed_Entity (Scop);
Set_Entity (Prefix (Name (N)), Scop);
end if;
end if;
if not Is_Overloaded (L) then
Try_One_Interp (Etype (L));
else
Get_First_Interp (L, Index, It);
while Present (It.Typ) loop
Try_One_Interp (It.Typ);
Get_Next_Interp (Index, It);
end loop;
end if;
end Find_Equality_Types;
procedure Find_Negation_Types
(R : Node_Id;
Op_Id : Entity_Id;
N : Node_Id)
is
Index : Interp_Index;
It : Interp;
begin
if not Is_Overloaded (R) then
if Etype (R) = Universal_Integer then
Add_One_Interp (N, Op_Id, Any_Modular);
elsif Valid_Boolean_Arg (Etype (R)) then
Add_One_Interp (N, Op_Id, Etype (R));
end if;
else
Get_First_Interp (R, Index, It);
while Present (It.Typ) loop
if Valid_Boolean_Arg (It.Typ) then
Add_One_Interp (N, Op_Id, It.Typ);
end if;
Get_Next_Interp (Index, It);
end loop;
end if;
end Find_Negation_Types;
procedure Find_Unary_Types
(R : Node_Id;
Op_Id : Entity_Id;
N : Node_Id)
is
Index : Interp_Index;
It : Interp;
begin
if not Is_Overloaded (R) then
if Is_Numeric_Type (Etype (R)) then
Add_One_Interp (N, Op_Id, Base_Type (Etype (R)));
end if;
else
Get_First_Interp (R, Index, It);
while Present (It.Typ) loop
if Is_Numeric_Type (It.Typ) then
Add_One_Interp (N, Op_Id, Base_Type (It.Typ));
end if;
Get_Next_Interp (Index, It);
end loop;
end if;
end Find_Unary_Types;
function Junk_Operand (N : Node_Id) return Boolean is
Enode : Node_Id;
begin
if Error_Posted (N) then
return False;
end if;
if Is_Entity_Name (N)
and then Present (Entity (N))
then
Enode := N;
elsif Nkind (N) = N_Function_Call
and then Is_Entity_Name (Name (N))
and then Present (Entity (Name (N)))
then
Enode := Name (N);
elsif Nkind (N) = N_Selected_Component
and then Present (Entity (Selector_Name (N)))
then
Enode := Selector_Name (N);
else
return False;
end if;
case Ekind (Entity (Enode)) is
when E_Package =>
Error_Msg_N
("package name cannot be used as operand", Enode);
when Generic_Unit_Kind =>
Error_Msg_N
("generic unit name cannot be used as operand", Enode);
when Type_Kind =>
Error_Msg_N
("subtype name cannot be used as operand", Enode);
when Entry_Kind =>
Error_Msg_N
("entry name cannot be used as operand", Enode);
when E_Procedure =>
Error_Msg_N
("procedure name cannot be used as operand", Enode);
when E_Exception =>
Error_Msg_N
("exception name cannot be used as operand", Enode);
when E_Block | E_Label | E_Loop =>
Error_Msg_N
("label name cannot be used as operand", Enode);
when others =>
return False;
end case;
return True;
end Junk_Operand;
procedure Operator_Check (N : Node_Id) is
begin
Remove_Abstract_Operations (N);
if Etype (N) = Any_Type then
declare
L : Node_Id;
R : Node_Id;
begin
R := Right_Opnd (N);
if Nkind (N) in N_Binary_Op then
L := Left_Opnd (N);
else
L := Empty;
end if;
if R = Error
or else Etype (R) = Any_Type
or else (Nkind (N) in N_Binary_Op and then Etype (L) = Any_Type)
then
return;
elsif Present (Candidate_Type)
and then (Nkind (N) /= N_Op_Concat
or else Is_Array_Type (Etype (L))
or else Is_Array_Type (Etype (R)))
then
if Nkind (N) = N_Op_Concat then
if Etype (L) /= Any_Composite
and then Is_Array_Type (Etype (L))
then
Candidate_Type := Etype (L);
elsif Etype (R) /= Any_Composite
and then Is_Array_Type (Etype (R))
then
Candidate_Type := Etype (R);
end if;
end if;
Error_Msg_NE
("operator for} is not directly visible!",
N, First_Subtype (Candidate_Type));
Error_Msg_N ("use clause would make operation legal!", N);
return;
elsif Junk_Operand (R)
or (Nkind (N) in N_Binary_Op and then Junk_Operand (L))
then
return;
elsif Nkind (N) = N_Op_And
or else
Nkind (N) = N_Op_Or
or else
Nkind (N) = N_Op_Xor
then
if Etype (L) = Standard_Boolean then
Resolve (R, Standard_Boolean);
return;
elsif Etype (R) = Standard_Boolean then
Resolve (L, Standard_Boolean);
return;
end if;
elsif Nkind (N) = N_Op_Add or else
Nkind (N) = N_Op_Divide or else
Nkind (N) = N_Op_Ge or else
Nkind (N) = N_Op_Gt or else
Nkind (N) = N_Op_Le or else
Nkind (N) = N_Op_Lt or else
Nkind (N) = N_Op_Mod or else
Nkind (N) = N_Op_Multiply or else
Nkind (N) = N_Op_Rem or else
Nkind (N) = N_Op_Subtract
then
if Is_Numeric_Type (Etype (L))
and then not Is_Numeric_Type (Etype (R))
then
Resolve (R, Etype (L));
return;
elsif Is_Numeric_Type (Etype (R))
and then not Is_Numeric_Type (Etype (L))
then
Resolve (L, Etype (R));
return;
end if;
elsif (Nkind (N) = N_Op_Eq or else
Nkind (N) = N_Op_Ne)
and then Ekind (Etype (L)) = E_Access_Attribute_Type
and then Ekind (Etype (R)) = E_Access_Attribute_Type
then
Error_Msg_N
("two access attributes cannot be compared directly", N);
Error_Msg_N
("\they must be converted to an explicit type for comparison",
N);
return;
elsif Nkind (N) = N_Op_Concat
and then Valid_Boolean_Arg (Etype (L))
and then Valid_Boolean_Arg (Etype (R))
then
Error_Msg_N ("invalid operands for concatenation", N);
Error_Msg_N ("\maybe AND was meant", N);
return;
elsif Nkind (N) = N_Op_Eq
and then Is_Entity_Name (L)
and then Nkind (Parent (Entity (L))) = N_Parameter_Specification
and then Nkind (Parameter_Type (Parent (Entity (L)))) =
N_Access_Definition
and then Nkind (R) = N_Null
then
Error_Msg_N ("access parameter is not allowed to be null", L);
Error_Msg_N ("\(call would raise Constraint_Error)", L);
return;
end if;
if Nkind (N) in N_Unary_Op then
Error_Msg_Node_2 := Etype (R);
Error_Msg_N ("operator& not defined for}", N);
return;
else
if Nkind (N) in N_Binary_Op then
if not Is_Overloaded (L)
and then not Is_Overloaded (R)
and then Base_Type (Etype (L)) = Base_Type (Etype (R))
then
Error_Msg_Node_2 := First_Subtype (Etype (R));
Error_Msg_N ("there is no applicable operator& for}", N);
else
Error_Msg_N ("invalid operand types for operator&", N);
if Nkind (N) /= N_Op_Concat then
Error_Msg_NE ("\left operand has}!", N, Etype (L));
Error_Msg_NE ("\right operand has}!", N, Etype (R));
end if;
end if;
end if;
end if;
end;
end if;
end Operator_Check;
procedure Process_Implicit_Dereference_Prefix
(E : Entity_Id;
P : Entity_Id)
is
Ref : Node_Id;
begin
if Operating_Mode = Check_Semantics and then Present (E) then
Ref := New_Reference_To (E, Sloc (P));
Set_Comes_From_Source (Ref, Comes_From_Source (P));
Generate_Reference (E, Ref);
end if;
end Process_Implicit_Dereference_Prefix;
procedure Remove_Abstract_Operations (N : Node_Id) is
I : Interp_Index;
It : Interp;
Abstract_Op : Entity_Id := Empty;
type Operand_Position is (First_Op, Second_Op);
Univ_Type : constant Entity_Id := Universal_Interpretation (N);
procedure Remove_Address_Interpretations (Op : Operand_Position);
procedure Remove_Address_Interpretations (Op : Operand_Position) is
Formal : Entity_Id;
begin
if Is_Overloaded (N) then
Get_First_Interp (N, I, It);
while Present (It.Nam) loop
Formal := First_Entity (It.Nam);
if Op = Second_Op then
Formal := Next_Entity (Formal);
end if;
if Is_Descendent_Of_Address (Etype (Formal)) then
Remove_Interp (I);
end if;
Get_Next_Interp (I, It);
end loop;
end if;
end Remove_Address_Interpretations;
begin
if Is_Overloaded (N) then
Get_First_Interp (N, I, It);
while Present (It.Nam) loop
if not Is_Type (It.Nam)
and then Is_Abstract (It.Nam)
and then not Is_Dispatching_Operation (It.Nam)
and then
(Ada_Version >= Ada_05
or else Is_Predefined_File_Name
(Unit_File_Name (Get_Source_Unit (It.Nam))))
then
Abstract_Op := It.Nam;
Remove_Interp (I);
exit;
end if;
Get_Next_Interp (I, It);
end loop;
if No (Abstract_Op) then
return;
elsif Nkind (N) in N_Op then
if Nkind (N) in N_Binary_Op then
declare
U1 : constant Boolean :=
Present (Universal_Interpretation (Right_Opnd (N)));
U2 : constant Boolean :=
Present (Universal_Interpretation (Left_Opnd (N)));
begin
if U1 and then not U2 then
Remove_Address_Interpretations (Second_Op);
elsif U2 and then not U1 then
Remove_Address_Interpretations (First_Op);
end if;
if not (U1 and U2) then
Get_First_Interp (N, I, It);
while Present (It.Nam) loop
if Scope (It.Nam) = Standard_Standard
and then Base_Type (It.Typ) =
Base_Type (Etype (Abstract_Op))
then
Remove_Interp (I);
end if;
Get_Next_Interp (I, It);
end loop;
elsif Is_Overloaded (N)
and then Present (Univ_Type)
then
Get_First_Interp (N, I, It);
while Present (It.Nam) loop
if Scope (It.Nam) = Standard_Standard then
Set_Etype (N, Univ_Type);
Set_Entity (N, It.Nam);
Set_Is_Overloaded (N, False);
exit;
end if;
Get_Next_Interp (I, It);
end loop;
end if;
end;
end if;
elsif Nkind (N) = N_Function_Call
and then
(Nkind (Name (N)) = N_Operator_Symbol
or else
(Nkind (Name (N)) = N_Expanded_Name
and then
Nkind (Selector_Name (Name (N))) = N_Operator_Symbol))
then
declare
Arg1 : constant Node_Id := First (Parameter_Associations (N));
U1 : constant Boolean :=
Present (Universal_Interpretation (Arg1));
U2 : constant Boolean :=
Present (Next (Arg1)) and then
Present (Universal_Interpretation (Next (Arg1)));
begin
if U1 and then not U2 then
Remove_Address_Interpretations (First_Op);
elsif U2 and then not U1 then
Remove_Address_Interpretations (Second_Op);
end if;
if not (U1 and U2) then
Get_First_Interp (N, I, It);
while Present (It.Nam) loop
if Scope (It.Nam) = Standard_Standard
and then It.Typ = Base_Type (Etype (Abstract_Op))
then
Remove_Interp (I);
end if;
Get_Next_Interp (I, It);
end loop;
end if;
end;
end if;
if Present (Abstract_Op) then
Get_First_Interp (N, I, It);
if No (It.Nam) then
Set_Etype (N, Any_Type);
Error_Msg_Sloc := Sloc (Abstract_Op);
Error_Msg_NE
("cannot call abstract operation& declared#", N, Abstract_Op);
end if;
end if;
end if;
end Remove_Abstract_Operations;
function Try_Indirect_Call
(N : Node_Id;
Nam : Entity_Id;
Typ : Entity_Id) return Boolean
is
Actual : Node_Id;
Formal : Entity_Id;
Call_OK : Boolean;
begin
Normalize_Actuals (N, Designated_Type (Typ), False, Call_OK);
Actual := First_Actual (N);
Formal := First_Formal (Designated_Type (Typ));
while Present (Actual)
and then Present (Formal)
loop
if not Has_Compatible_Type (Actual, Etype (Formal)) then
return False;
end if;
Next (Actual);
Next_Formal (Formal);
end loop;
if No (Actual) and then No (Formal) then
Add_One_Interp (N, Nam, Etype (Designated_Type (Typ)));
if not Is_Type (Nam)
and then Is_Entity_Name (Name (N))
then
Set_Entity (Name (N), Nam);
end if;
return True;
else
return False;
end if;
end Try_Indirect_Call;
function Try_Indexed_Call
(N : Node_Id;
Nam : Entity_Id;
Typ : Entity_Id) return Boolean
is
Actuals : constant List_Id := Parameter_Associations (N);
Actual : Node_Id;
Index : Entity_Id;
begin
Actual := First (Actuals);
Index := First_Index (Typ);
while Present (Actual)
and then Present (Index)
loop
if Nkind (Actual) = N_Parameter_Association then
return False;
end if;
if not Has_Compatible_Type (Actual, Etype (Index)) then
return False;
end if;
Next (Actual);
Next_Index (Index);
end loop;
if No (Actual) and then No (Index) then
Add_One_Interp (N, Nam, Component_Type (Typ));
if not Is_Type (Nam)
and then Is_Entity_Name (Name (N))
then
Set_Entity (Name (N), Nam);
end if;
return True;
else
return False;
end if;
end Try_Indexed_Call;
function Try_Object_Operation (N : Node_Id) return Boolean is
K : constant Node_Kind := Nkind (Parent (N));
Loc : constant Source_Ptr := Sloc (N);
Is_Subprg_Call : constant Boolean := K = N_Procedure_Call_Statement
or else K = N_Function_Call;
Obj : constant Node_Id := Prefix (N);
Subprog : constant Node_Id := Selector_Name (N);
Actual : Node_Id;
Call_Node : Node_Id;
Call_Node_Case : Node_Id := Empty;
First_Actual : Node_Id;
Node_To_Replace : Node_Id;
Obj_Type : Entity_Id := Etype (Obj);
procedure Complete_Object_Operation
(Call_Node : Node_Id;
Node_To_Replace : Node_Id;
Subprog : Node_Id);
procedure Transform_Object_Operation
(Call_Node : out Node_Id;
First_Actual : Node_Id;
Node_To_Replace : out Node_Id;
Subprog : Node_Id);
function Try_Class_Wide_Operation
(Call_Node : Node_Id;
Node_To_Replace : Node_Id) return Boolean;
function Try_Primitive_Operation
(Call_Node : Node_Id;
Node_To_Replace : Node_Id) return Boolean;
procedure Complete_Object_Operation
(Call_Node : Node_Id;
Node_To_Replace : Node_Id;
Subprog : Node_Id)
is
begin
Set_Name (Call_Node, New_Copy_Tree (Subprog));
Set_Analyzed (Call_Node, False);
Rewrite (Node_To_Replace, Call_Node);
Analyze (Node_To_Replace);
end Complete_Object_Operation;
procedure Transform_Object_Operation
(Call_Node : out Node_Id;
First_Actual : Node_Id;
Node_To_Replace : out Node_Id;
Subprog : Node_Id)
is
Actuals : List_Id;
Parent_Node : constant Node_Id := Parent (N);
begin
Actuals := New_List (New_Copy_Tree (First_Actual));
if (Nkind (Parent_Node) = N_Function_Call
or else
Nkind (Parent_Node) = N_Procedure_Call_Statement)
and then N /= First (Parameter_Associations (Parent_Node))
then
Node_To_Replace := Parent_Node;
declare
Actual : Node_Id;
begin
Actual := First (Parameter_Associations (Parent_Node));
while Present (Actual) loop
Append (New_Copy_Tree (Actual), Actuals);
Next (Actual);
end loop;
end;
if Nkind (Parent_Node) = N_Procedure_Call_Statement then
Call_Node :=
Make_Procedure_Call_Statement (Loc,
Name => New_Copy_Tree (Subprog),
Parameter_Associations => Actuals);
else
pragma Assert (Nkind (Parent_Node) = N_Function_Call);
Call_Node :=
Make_Function_Call (Loc,
Name => New_Copy_Tree (Subprog),
Parameter_Associations => Actuals);
end if;
else
Node_To_Replace := N;
Call_Node :=
Make_Function_Call (Loc,
Name => New_Copy_Tree (Subprog),
Parameter_Associations => Actuals);
end if;
end Transform_Object_Operation;
function Try_Class_Wide_Operation
(Call_Node : Node_Id;
Node_To_Replace : Node_Id) return Boolean
is
Anc_Type : Entity_Id;
Dummy : Node_Id;
Hom : Entity_Id;
Hom_Ref : Node_Id;
Success : Boolean;
begin
Anc_Type := Obj_Type;
loop
Hom := Current_Entity (Subprog);
while Present (Hom) loop
if (Ekind (Hom) = E_Procedure
or else
Ekind (Hom) = E_Function)
and then Present (First_Formal (Hom))
and then Etype (First_Formal (Hom)) =
Class_Wide_Type (Anc_Type)
then
Hom_Ref := New_Reference_To (Hom, Loc);
if Is_Access_Type (Etype (Obj))
and then Ekind (Etype (First_Formal (Hom))) =
E_Anonymous_Access_Type
then
if not Present (Call_Node_Case) then
Transform_Object_Operation (
Call_Node => Call_Node_Case,
First_Actual => Obj,
Node_To_Replace => Dummy,
Subprog => Subprog);
Set_Etype (Call_Node_Case, Any_Type);
Set_Parent (Call_Node_Case, Parent (Node_To_Replace));
end if;
Set_Name (Call_Node_Case, Hom_Ref);
Analyze_One_Call (
N => Call_Node_Case,
Nam => Hom,
Report => False,
Success => Success);
if Success then
Complete_Object_Operation (
Call_Node => Call_Node_Case,
Node_To_Replace => Node_To_Replace,
Subprog => Hom_Ref);
return True;
end if;
else
Set_Name (Call_Node, Hom_Ref);
Analyze_One_Call (
N => Call_Node,
Nam => Hom,
Report => False,
Success => Success);
if Success then
Complete_Object_Operation (
Call_Node => Call_Node,
Node_To_Replace => Node_To_Replace,
Subprog => Hom_Ref);
return True;
end if;
end if;
end if;
Hom := Homonym (Hom);
end loop;
exit when Etype (Anc_Type) = Anc_Type;
Anc_Type := Etype (Anc_Type);
end loop;
return False;
end Try_Class_Wide_Operation;
function Try_Primitive_Operation
(Call_Node : Node_Id;
Node_To_Replace : Node_Id) return Boolean
is
Dummy : Node_Id;
Elmt : Elmt_Id;
Prim_Op : Entity_Id;
Prim_Op_Ref : Node_Id;
Success : Boolean;
begin
Elmt := First_Elmt (Primitive_Operations (Obj_Type));
while Present (Elmt) loop
Prim_Op := Node (Elmt);
if Chars (Prim_Op) = Chars (Subprog)
and then Present (First_Formal (Prim_Op))
then
Prim_Op_Ref := New_Reference_To (Prim_Op, Loc);
if Is_Access_Type (Etype (Obj))
and then Ekind (Etype (First_Formal (Prim_Op))) =
E_Anonymous_Access_Type
then
if not Present (Call_Node_Case) then
Transform_Object_Operation (
Call_Node => Call_Node_Case,
First_Actual => Obj,
Node_To_Replace => Dummy,
Subprog => Subprog);
Set_Etype (Call_Node_Case, Any_Type);
Set_Parent (Call_Node_Case, Parent (Node_To_Replace));
end if;
Set_Name (Call_Node_Case, Prim_Op_Ref);
Analyze_One_Call (
N => Call_Node_Case,
Nam => Prim_Op,
Report => False,
Success => Success);
if Success then
Complete_Object_Operation (
Call_Node => Call_Node_Case,
Node_To_Replace => Node_To_Replace,
Subprog => Prim_Op_Ref);
return True;
end if;
else
Set_Name (Call_Node, Prim_Op_Ref);
Analyze_One_Call (
N => Call_Node,
Nam => Prim_Op,
Report => False,
Success => Success);
if Success then
Complete_Object_Operation (
Call_Node => Call_Node,
Node_To_Replace => Node_To_Replace,
Subprog => Prim_Op_Ref);
return True;
end if;
end if;
end if;
Next_Elmt (Elmt);
end loop;
return False;
end Try_Primitive_Operation;
begin
if Is_Access_Type (Obj_Type) then
Obj_Type := Designated_Type (Obj_Type);
end if;
if Ekind (Obj_Type) = E_Private_Subtype then
Obj_Type := Base_Type (Obj_Type);
end if;
if Is_Class_Wide_Type (Obj_Type) then
Obj_Type := Etype (Class_Wide_Type (Obj_Type));
end if;
if Is_Subprg_Call and then N = Name (Parent (N)) then
Actual := First (Parameter_Associations (Parent (N)));
while Present (Actual) loop
Analyze (Actual);
Check_Parameterless_Call (Actual);
Next (Actual);
end loop;
end if;
if Is_Access_Type (Etype (Obj)) then
First_Actual :=
Make_Explicit_Dereference (Sloc (Obj), Obj);
Set_Etype (First_Actual, Obj_Type);
else
First_Actual := Obj;
end if;
Transform_Object_Operation (
Call_Node => Call_Node,
First_Actual => First_Actual,
Node_To_Replace => Node_To_Replace,
Subprog => Subprog);
Set_Etype (Call_Node, Any_Type);
Set_Parent (Call_Node, Parent (Node_To_Replace));
return
Try_Primitive_Operation
(Call_Node => Call_Node,
Node_To_Replace => Node_To_Replace)
or else
Try_Class_Wide_Operation
(Call_Node => Call_Node,
Node_To_Replace => Node_To_Replace);
end Try_Object_Operation;
end Sem_Ch4;