diff options
author | Ian Lance Taylor <iant@golang.org> | 2021-09-13 10:37:49 -0700 |
---|---|---|
committer | Ian Lance Taylor <iant@golang.org> | 2021-09-13 10:37:49 -0700 |
commit | e252b51ccde010cbd2a146485d8045103cd99533 (patch) | |
tree | e060f101cdc32bf5e520de8e5275db9d4236b74c /gcc/ada/sem_ch4.adb | |
parent | f10c7c4596dda99d2ee872c995ae4aeda65adbdf (diff) | |
parent | 104c05c5284b7822d770ee51a7d91946c7e56d50 (diff) | |
download | gcc-e252b51ccde010cbd2a146485d8045103cd99533.zip gcc-e252b51ccde010cbd2a146485d8045103cd99533.tar.gz gcc-e252b51ccde010cbd2a146485d8045103cd99533.tar.bz2 |
Merge from trunk revision 104c05c5284b7822d770ee51a7d91946c7e56d50.
Diffstat (limited to 'gcc/ada/sem_ch4.adb')
-rw-r--r-- | gcc/ada/sem_ch4.adb | 214 |
1 files changed, 139 insertions, 75 deletions
diff --git a/gcc/ada/sem_ch4.adb b/gcc/ada/sem_ch4.adb index 7a8c261..c052022 100644 --- a/gcc/ada/sem_ch4.adb +++ b/gcc/ada/sem_ch4.adb @@ -6,7 +6,7 @@ -- -- -- B o d y -- -- -- --- Copyright (C) 1992-2020, Free Software Foundation, Inc. -- +-- Copyright (C) 1992-2021, 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- -- @@ -23,44 +23,48 @@ -- -- ------------------------------------------------------------------------------ -with Aspects; use Aspects; -with Atree; use Atree; -with Debug; use Debug; -with Einfo; use Einfo; -with Elists; use Elists; -with Errout; use Errout; -with Exp_Util; use Exp_Util; -with Itypes; use Itypes; -with Lib; use Lib; -with Lib.Xref; use Lib.Xref; -with Namet; use Namet; -with Namet.Sp; use Namet.Sp; -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_Aux; use Sem_Aux; -with Sem_Case; use Sem_Case; -with Sem_Cat; use Sem_Cat; -with Sem_Ch3; use Sem_Ch3; -with Sem_Ch6; use Sem_Ch6; -with Sem_Ch8; use Sem_Ch8; -with Sem_Dim; use Sem_Dim; -with Sem_Disp; use Sem_Disp; -with Sem_Dist; use Sem_Dist; -with Sem_Eval; use Sem_Eval; -with Sem_Res; use Sem_Res; -with Sem_Type; use Sem_Type; -with Sem_Util; use Sem_Util; -with Sem_Warn; use Sem_Warn; -with Stand; use Stand; -with Sinfo; use Sinfo; -with Snames; use Snames; -with Tbuild; use Tbuild; -with Uintp; use Uintp; +with Aspects; use Aspects; +with Atree; use Atree; +with Debug; use Debug; +with Einfo; use Einfo; +with Einfo.Entities; use Einfo.Entities; +with Einfo.Utils; use Einfo.Utils; +with Elists; use Elists; +with Errout; use Errout; +with Exp_Util; use Exp_Util; +with Itypes; use Itypes; +with Lib; use Lib; +with Lib.Xref; use Lib.Xref; +with Namet; use Namet; +with Namet.Sp; use Namet.Sp; +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_Aux; use Sem_Aux; +with Sem_Case; use Sem_Case; +with Sem_Cat; use Sem_Cat; +with Sem_Ch3; use Sem_Ch3; +with Sem_Ch6; use Sem_Ch6; +with Sem_Ch8; use Sem_Ch8; +with Sem_Dim; use Sem_Dim; +with Sem_Disp; use Sem_Disp; +with Sem_Dist; use Sem_Dist; +with Sem_Eval; use Sem_Eval; +with Sem_Res; use Sem_Res; +with Sem_Type; use Sem_Type; +with Sem_Util; use Sem_Util; +with Sem_Warn; use Sem_Warn; +with Stand; use Stand; +with Sinfo; use Sinfo; +with Sinfo.Nodes; use Sinfo.Nodes; +with Sinfo.Utils; use Sinfo.Utils; +with Snames; use Snames; +with Tbuild; use Tbuild; +with Uintp; use Uintp; package body Sem_Ch4 is @@ -599,12 +603,8 @@ package body Sem_Ch4 is Type_Id := Entity (E); if Is_Tagged_Type (Type_Id) - and then Has_Discriminants (Type_Id) + and then Has_Defaulted_Discriminants (Type_Id) and then not Is_Constrained (Type_Id) - and then - Present - (Discriminant_Default_Value - (First_Discriminant (Type_Id))) then declare Constr : constant List_Id := New_List; @@ -612,19 +612,17 @@ package body Sem_Ch4 is Discr : Entity_Id := First_Discriminant (Type_Id); begin - if Present (Discriminant_Default_Value (Discr)) then - while Present (Discr) loop - Append (Discriminant_Default_Value (Discr), Constr); - Next_Discriminant (Discr); - end loop; + while Present (Discr) loop + Append (Discriminant_Default_Value (Discr), Constr); + Next_Discriminant (Discr); + end loop; - Rewrite (E, - Make_Subtype_Indication (Loc, - Subtype_Mark => New_Occurrence_Of (Type_Id, Loc), - Constraint => - Make_Index_Or_Discriminant_Constraint (Loc, - Constraints => Constr))); - end if; + Rewrite (E, + Make_Subtype_Indication (Loc, + Subtype_Mark => New_Occurrence_Of (Type_Id, Loc), + Constraint => + Make_Index_Or_Discriminant_Constraint (Loc, + Constraints => Constr))); end; end if; end if; @@ -1467,8 +1465,6 @@ package body Sem_Ch4 is else Remove_Abstract_Operations (N); end if; - - End_Interp_List; end if; -- Check the accessibility level for actuals for explicitly aliased @@ -2278,9 +2274,12 @@ package body Sem_Ch4 is procedure Analyze_Expression_With_Actions (N : Node_Id) is procedure Check_Action_OK (A : Node_Id); - -- Check that the action is something that is allows as a declare_item - -- of a declare_expression, except the checks are suppressed for - -- generated code. + -- Check that the action A is allowed as a declare_item of a declare + -- expression if N and A come from source. + + --------------------- + -- Check_Action_OK -- + --------------------- procedure Check_Action_OK (A : Node_Id) is begin @@ -2324,7 +2323,7 @@ package body Sem_Ch4 is Error_Msg_N ("object renaming or constant declaration expected", A); end Check_Action_OK; - A : Node_Id; + A : Node_Id; EWA_Scop : Entity_Id; -- Start of processing for Analyze_Expression_With_Actions @@ -2793,8 +2792,6 @@ package body Sem_Ch4 is Error_Msg_N ("no legal interpretation for indexed component", N); Set_Is_Overloaded (N, False); end if; - - End_Interp_List; end Process_Overloaded_Indexed_Component; -- Start of processing for Analyze_Indexed_Component_Form @@ -4345,8 +4342,7 @@ package body Sem_Ch4 is or else Covers (T1 => T2, T2 => T1) then - if T1 = Universal_Integer - or else T1 = Universal_Real + if Is_Universal_Numeric_Type (T1) or else T1 = Any_Character then Add_One_Interp (N, Base_Type (T2), Base_Type (T2)); @@ -4416,7 +4412,7 @@ package body Sem_Ch4 is -- If result is Any_Type, then we did not find a compatible pair if Etype (N) = Any_Type then - Error_Msg_N ("incompatible types in range ", N); + Error_Msg_N ("incompatible types in range", N); end if; end if; @@ -5006,8 +5002,11 @@ package body Sem_Ch4 is -- Ada 2005 (AI05-0030): In the case of dispatching requeue, the -- selected component should resolve to a name. + -- Extension feature: Also support calls with prefixed views for + -- untagged record types. + if Ada_Version >= Ada_2005 - and then Is_Tagged_Type (Prefix_Type) + and then (Is_Tagged_Type (Prefix_Type) or else Extensions_Allowed) and then not Is_Concurrent_Type (Prefix_Type) then if Nkind (Parent (N)) = N_Generic_Association @@ -5080,6 +5079,15 @@ package body Sem_Ch4 is Next_Entity (Comp); end loop; + -- Extension feature: Also support calls with prefixed views for + -- untagged private types. + + if Extensions_Allowed then + if Try_Object_Operation (N) then + return; + end if; + end if; + elsif Is_Concurrent_Type (Prefix_Type) then -- Find visible operation with given name. For a protected type, @@ -5299,7 +5307,7 @@ package body Sem_Ch4 is Set_Parent (Par, Parent (Parent (N))); if Try_Object_Operation - (Sinfo.Name (Par), CW_Test_Only => True) + (Sinfo.Nodes.Name (Par), CW_Test_Only => True) then return; end if; @@ -5332,6 +5340,14 @@ package body Sem_Ch4 is Set_Is_Overloaded (N, Is_Overloaded (Sel)); + -- Extension feature: Also support calls with prefixed views for + -- untagged types. + + elsif Extensions_Allowed + and then Try_Object_Operation (N) + then + return; + else -- Invalid prefix @@ -5455,9 +5471,9 @@ package body Sem_Ch4 is Apply_Compile_Time_Constraint_Error (N, "component not present in }??", CE_Discriminant_Check_Failed, - Ent => Prefix_Type); - - Set_Raises_Constraint_Error (N); + Ent => Prefix_Type, + Emit_Message => + SPARK_Mode = On or not In_Instance_Not_Visible); return; end if; @@ -5972,7 +5988,7 @@ package body Sem_Ch4 is function Specific_Type (T1, T2 : Entity_Id) return Entity_Id is begin - if T1 = Universal_Integer or else T1 = Universal_Real then + if Is_Universal_Numeric_Type (T1) then return Base_Type (T2); else return Base_Type (T1); @@ -9542,7 +9558,15 @@ package body Sem_Ch4 is -- type, this is not a prefixed call. Restore the previous type as -- the current one is not a legal candidate. - if not Is_Tagged_Type (Obj_Type) + -- Extension feature: Calls with prefixed views are also supported + -- for untagged types, so skip the early return when extensions are + -- enabled, unless the type doesn't have a primitive operations list + -- (such as in the case of predefined types). + + if (not Is_Tagged_Type (Obj_Type) + and then + (not Extensions_Allowed + or else not Present (Primitive_Operations (Obj_Type)))) or else Is_Incomplete_Type (Obj_Type) then Obj_Type := Prev_Obj_Type; @@ -9560,6 +9584,36 @@ package body Sem_Ch4 is Try_Primitive_Operation (Call_Node => New_Call_Node, Node_To_Replace => Node_To_Replace); + + -- Extension feature: In the case where the prefix is of an + -- access type, and a primitive wasn't found for the designated + -- type, then if the access type has primitives we attempt a + -- prefixed call using one of its primitives. (It seems that + -- this isn't quite right to give preference to the designated + -- type in the case where both the access and designated types + -- have homographic prefixed-view operations that could result + -- in an ambiguity, but handling properly may be tricky. ???) + + if Extensions_Allowed + and then not Prim_Result + and then Is_Named_Access_Type (Prev_Obj_Type) + and then Present (Direct_Primitive_Operations (Prev_Obj_Type)) + then + -- Temporarily reset Obj_Type to the original access type + + Obj_Type := Prev_Obj_Type; + + Prim_Result := + Try_Primitive_Operation + (Call_Node => New_Call_Node, + Node_To_Replace => Node_To_Replace); + + -- Restore Obj_Type to the designated type (is this really + -- necessary, or should it only be done when Prim_Result is + -- still False?). + + Obj_Type := Designated_Type (Obj_Type); + end if; end if; -- Check if there is a class-wide subprogram covering the @@ -9899,7 +9953,7 @@ package body Sem_Ch4 is -- be the corresponding record of a synchronized type. return Obj_Type = Typ - or else Base_Type (Obj_Type) = Typ + or else Base_Type (Obj_Type) = Base_Type (Typ) or else Corr_Type = Typ -- Object may be of a derived type whose parent has unknown @@ -10212,6 +10266,16 @@ package body Sem_Ch4 is Report => True, Success => Success, Skip_First => True); + + -- The error may hot have been reported yet for overloaded + -- prefixed calls, depending on the non-matching candidate, + -- in which case provide a concise error now. + + if Serious_Errors_Detected = 0 then + Error_Msg_NE + ("cannot resolve prefixed call to primitive operation of&", + N, Entity (Obj)); + end if; end if; -- No need for further errors |