]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Simplify expansion of positional aggregates
authorPiotr Trojanek <trojanek@adacore.com>
Thu, 16 Mar 2023 09:36:20 +0000 (10:36 +0100)
committerMarc Poulhiès <poulhies@adacore.com>
Fri, 26 May 2023 07:29:15 +0000 (09:29 +0200)
Code cleanup; semantics is unaffected.

gcc/ada/

* exp_aggr.adb (Build_Constrained_Type): Use List_Length to count
expressions in consecutive subaggregates.

gcc/ada/exp_aggr.adb

index bbc0f408abce0354db1e78ae6e7e58d95df50294..60449fbeb2d264593806a62a064021dd781869d1 100644 (file)
@@ -5837,7 +5837,6 @@ package body Exp_Aggr is
       procedure Build_Constrained_Type (Positional : Boolean) is
          Loc      : constant Source_Ptr := Sloc (N);
          Agg_Type : constant Entity_Id  := Make_Temporary (Loc, 'A');
-         Comp     : Node_Id;
          Decl     : Node_Id;
          Typ      : constant Entity_Id := Etype (N);
          Indexes  : constant List_Id   := New_List;
@@ -5853,19 +5852,14 @@ package body Exp_Aggr is
             Sub_Agg := N;
 
             for D in 1 .. Number_Dimensions (Typ) loop
-               Sub_Agg := First (Expressions (Sub_Agg));
-
-               Comp := Sub_Agg;
-               Num := 0;
-               while Present (Comp) loop
-                  Num := Num + 1;
-                  Next (Comp);
-               end loop;
+               Num := List_Length (Expressions (Sub_Agg));
 
                Append_To (Indexes,
                  Make_Range (Loc,
                    Low_Bound  => Make_Integer_Literal (Loc, 1),
                    High_Bound => Make_Integer_Literal (Loc, Num)));
+
+               Sub_Agg := First (Expressions (Sub_Agg));
             end loop;
 
          else