aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorPiotr Trojanek <trojanek@adacore.com>2021-10-11 14:09:42 +0200
committerPierre-Marie de Rodat <derodat@adacore.com>2021-10-25 15:07:21 +0000
commit234815d4c38608eb1bff20f68d6dd4c233f07725 (patch)
tree4482c5b47a65106c5ae59021979efd7550606382 /gcc
parent1ddc39479b999841e0b0e994a47bf3cec8a4e54e (diff)
downloadgcc-234815d4c38608eb1bff20f68d6dd4c233f07725.zip
gcc-234815d4c38608eb1bff20f68d6dd4c233f07725.tar.gz
gcc-234815d4c38608eb1bff20f68d6dd4c233f07725.tar.bz2
[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.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ada/exp_ch4.adb48
1 files changed, 21 insertions, 27 deletions
diff --git a/gcc/ada/exp_ch4.adb b/gcc/ada/exp_ch4.adb
index 8dcfa85..3dd0cc4 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;