public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Pierre-Marie de Rodat <pmderodat@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-4683] [Ada] Simplify iteration of record components when expanding equality Date: Mon, 25 Oct 2021 15:09:12 +0000 (GMT) [thread overview] Message-ID: <20211025150912.00F3C3858433@sourceware.org> (raw) https://gcc.gnu.org/g:234815d4c38608eb1bff20f68d6dd4c233f07725 commit r12-4683-g234815d4c38608eb1bff20f68d6dd4c233f07725 Author: Piotr Trojanek <trojanek@adacore.com> Date: Mon Oct 11 14:09:42 2021 +0200 [Ada] Simplify iteration of record components when expanding equality gcc/ada/ * exp_ch4.adb (Expand_Composite_Equality): Fix style. (Element_To_Compare): Simplify loop. (Expand_Record_Equality): Adapt calls to Element_To_Compare. Diff: --- gcc/ada/exp_ch4.adb | 48 +++++++++++++++++++++--------------------------- 1 file changed, 21 insertions(+), 27 deletions(-) diff --git a/gcc/ada/exp_ch4.adb b/gcc/ada/exp_ch4.adb index 8dcfa85e756..3dd0cc4f1af 100644 --- a/gcc/ada/exp_ch4.adb +++ b/gcc/ada/exp_ch4.adb @@ -2583,7 +2583,7 @@ package body Exp_Ch4 is return Make_Function_Call (Loc, - Name => New_Occurrence_Of (Eq_Op, Loc), + Name => New_Occurrence_Of (Eq_Op, Loc), Parameter_Associations => New_List (Unchecked_Convert_To (Etype (First_Formal (Eq_Op)), Lhs), @@ -2606,7 +2606,7 @@ package body Exp_Ch4 is begin return Make_Function_Call (Loc, - Name => New_Occurrence_Of (Eq_Op, Loc), + Name => New_Occurrence_Of (Eq_Op, Loc), Parameter_Associations => New_List ( OK_Convert_To (T, Lhs), OK_Convert_To (T, Rhs))); @@ -13116,41 +13116,35 @@ package body Exp_Ch4 is ------------------------ function Element_To_Compare (C : Entity_Id) return Entity_Id is - Comp : Entity_Id; + Comp : Entity_Id := C; begin - Comp := C; - loop - -- Exit loop when the next element to be compared is found, or - -- there is no more such element. - - exit when No (Comp); - - exit when Ekind (Comp) in E_Discriminant | E_Component - and then not ( + while Present (Comp) loop + -- Skip inherited components - -- Skip inherited components + -- Note: for a tagged type, we always generate the "=" primitive + -- for the base type (not on the first subtype), so the test for + -- Comp /= Original_Record_Component (Comp) is True for inherited + -- components only. - -- Note: for a tagged type, we always generate the "=" primitive - -- for the base type (not on the first subtype), so the test for - -- Comp /= Original_Record_Component (Comp) is True for - -- inherited components only. - - (Is_Tagged_Type (Typ) + if (Is_Tagged_Type (Typ) and then Comp /= Original_Record_Component (Comp)) - -- Skip _Tag + -- Skip _Tag or else Chars (Comp) = Name_uTag - -- Skip interface elements (secondary tags???) - - or else Is_Interface (Etype (Comp))); + -- Skip interface elements (secondary tags???) - Next_Entity (Comp); + or else Is_Interface (Etype (Comp)) + then + Next_Component_Or_Discriminant (Comp); + else + return Comp; + end if; end loop; - return Comp; + return Empty; end Element_To_Compare; -- Start of processing for Expand_Record_Equality @@ -13166,7 +13160,7 @@ package body Exp_Ch4 is -- and then Lhs.Cmpn = Rhs.Cmpn Result := New_Occurrence_Of (Standard_True, Loc); - C := Element_To_Compare (First_Entity (Typ)); + C := Element_To_Compare (First_Component_Or_Discriminant (Typ)); while Present (C) loop declare New_Lhs : Node_Id; @@ -13224,7 +13218,7 @@ package body Exp_Ch4 is end; First_Time := False; - C := Element_To_Compare (Next_Entity (C)); + C := Element_To_Compare (Next_Component_Or_Discriminant (C)); end loop; return Result;
reply other threads:[~2021-10-25 15:09 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20211025150912.00F3C3858433@sourceware.org \ --to=pmderodat@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).