diff options
author | Eric Botcazou <ebotcazou@adacore.com> | 2022-02-28 15:27:27 +0100 |
---|---|---|
committer | Pierre-Marie de Rodat <derodat@adacore.com> | 2022-05-16 08:42:03 +0000 |
commit | 909ce3528c800676fbbebe1f9a0047d14378861e (patch) | |
tree | 1bf9a64c974a2716b5532be690c6534afa708a54 /gcc/ada/sem_ch6.adb | |
parent | 9a39b25f6f52f6eab159a096551e2576fa0890cd (diff) |
[Ada] Fix implementation issues with equality for untagged record types
This moves the implementation of AI12-0101 + AI05-0123 from the expander
to the semantic analyzer and completes the implementation of AI12-0413,
which are both binding interpretations in Ada 2012, fixing a few bugs in
the process and removing a fair amount of duplicated code throughout.
gcc/ada/
* einfo-utils.adb (Remove_Entity): Fix couple of oversights.
* exp_ch3.adb (Is_User_Defined_Equality): Delete.
(User_Defined_Eq): Call Get_User_Defined_Equality.
(Make_Eq_Body): Likewise.
(Predefined_Primitive_Eq_Body): Call Is_User_Defined_Equality.
* exp_ch4.adb (Build_Eq_Call): Call Get_User_Defined_Equality.
(Is_Equality): Delete.
(User_Defined_Primitive_Equality_Op): Likewise.
(Find_Aliased_Equality): Call Is_User_Defined_Equality.
(Expand_N_Op_Eq): Call Underlying_Type unconditionally.
Do not implement AI12-0101 + AI05-0123 here.
(Expand_Set_Membership): Call Resolve_Membership_Equality.
* exp_ch6.adb (Expand_Call_Helper): Remove obsolete code.
* sem_aux.ads (Is_Record_Or_Limited_Type): Delete.
* sem_aux.adb (Is_Record_Or_Limited_Type): Likewise.
* sem_ch4.ads (Nondispatching_Call_To_Abstract_Operation): Declare.
* sem_ch4.adb (Analyze_Call): Call Call_Abstract_Operation.
(Analyze_Membership_Op): Call Resolve_Membership_Equality.
(Nondispatching_Call_To_Abstract_Operation): New procedure.
(Remove_Abstract_Operations): Call it.
* sem_ch6.adb (Check_Untagged_Equality): Remove obsolete error and
call Is_User_Defined_Equality.
* sem_ch7.adb (Inspect_Untagged_Record_Completion): New procedure
implementing AI12-0101 + AI05-0123.
(Analyze_Package_Specification): Call it.
(Declare_Inherited_Private_Subprograms): Minor tweak.
(Uninstall_Declarations): Likewise.
* sem_disp.adb (Check_Direct_Call): Adjust to new implementation
of Is_User_Defined_Equality.
* sem_res.ads (Resolve_Membership_Equality): Declare.
* sem_res.adb (Resolve): Replace direct error handling with call to
Nondispatching_Call_To_Abstract_Operation
(Resolve_Call): Likewise.
(Resolve_Equality_Op): Likewise. mplement AI12-0413.
(Resolve_Membership_Equality): New procedure.
(Resolve_Membership_Op): Call Get_User_Defined_Equality.
* sem_util.ads (Get_User_Defined_Eq): Rename into...
(Get_User_Defined_Equality): ...this.
* sem_util.adb (Get_User_Defined_Eq): Rename into...
(Get_User_Defined_Equality): ...this. Call Is_User_Defined_Equality.
(Is_User_Defined_Equality): Also check the profile but remove tests
on Comes_From_Source and Parent.
* sinfo.ads (Generic_Parent_Type): Adjust field description.
* uintp.ads (Ubool): Invoke user-defined equality in predicate.
Diffstat (limited to 'gcc/ada/sem_ch6.adb')
-rw-r--r-- | gcc/ada/sem_ch6.adb | 35 |
1 files changed, 9 insertions, 26 deletions
diff --git a/gcc/ada/sem_ch6.adb b/gcc/ada/sem_ch6.adb index be093d6863f..dbcb2556fe3 100644 --- a/gcc/ada/sem_ch6.adb +++ b/gcc/ada/sem_ch6.adb @@ -190,14 +190,12 @@ package body Sem_Ch6 is -- in posting the warning message. procedure Check_Untagged_Equality (Eq_Op : Entity_Id); - -- In Ada 2012, a primitive equality operator on an untagged record type - -- must appear before the type is frozen, and have the same visibility as - -- that of the type. This procedure checks that this rule is met, and - -- otherwise emits an error on the subprogram declaration and a warning - -- on the earlier freeze point if it is easy to locate. In Ada 2012 mode, - -- this routine outputs errors (or warnings if -gnatd.E is set). In earlier - -- versions of Ada, warnings are output if Warn_On_Ada_2012_Incompatibility - -- is set, otherwise the call has no effect. + -- In Ada 2012, a primitive equality operator for an untagged record type + -- must appear before the type is frozen. This procedure checks that this + -- rule is met, and otherwise gives an error on the subprogram declaration + -- and a warning on the earlier freeze point if it is easy to pinpoint. In + -- earlier versions of Ada, the call has not effect, unless compatibility + -- warnings are requested by means of Warn_On_Ada_2012_Incompatibility. procedure Enter_Overloaded_Entity (S : Entity_Id); -- This procedure makes S, a new overloaded entity, into the first visible @@ -9511,12 +9509,12 @@ package body Sem_Ch6 is begin -- This check applies only if we have a subprogram declaration with an - -- untagged record type that is conformant to the predefined op. + -- untagged record type that is conformant to the predefined operator. if Nkind (Decl) /= N_Subprogram_Declaration or else not Is_Record_Type (Typ) or else Is_Tagged_Type (Typ) - or else Etype (Next_Formal (First_Formal (Eq_Op))) /= Typ + or else not Is_User_Defined_Equality (Eq_Op) then return; end if; @@ -9628,22 +9626,7 @@ package body Sem_Ch6 is end if; end if; - -- Here if type is not frozen yet. It is illegal to have a primitive - -- equality declared in the private part if the type is visible - -- (RM 4.5.2(9.8)). - - elsif not In_Same_List (Parent (Typ), Decl) - and then not Is_Limited_Type (Typ) - then - if Ada_Version >= Ada_2012 then - Error_Msg_N - ("equality operator appears too late<<", Eq_Op); - else - Error_Msg_N - ("equality operator appears too late (Ada 2012)?y?", Eq_Op); - end if; - - -- Finally check for AI12-0352: declaration of a user-defined primitive + -- Now check for AI12-0352: the declaration of a user-defined primitive -- equality operation for a record type T is illegal if it occurs after -- a type has been derived from T. |