[Ada] Simplify detection of record components with default initialization
authorPiotr Trojanek <trojanek@adacore.com>
Wed, 29 Sep 2021 10:16:38 +0000 (12:16 +0200)
committerPierre-Marie de Rodat <derodat@adacore.com>
Mon, 11 Oct 2021 13:38:10 +0000 (13:38 +0000)
gcc/ada/

* exp_aggr.adb (Has_Default_Init_Comps): Simplify.

gcc/ada/exp_aggr.adb

index 06cdafd..187bb5f 100644 (file)
@@ -8897,46 +8897,41 @@ package body Exp_Aggr is
    ----------------------------
 
    function Has_Default_Init_Comps (N : Node_Id) return Boolean is
-      Comps : constant List_Id := Component_Associations (N);
-      C     : Node_Id;
+      Assoc : Node_Id;
       Expr  : Node_Id;
+      --  Component association and expression, respectively
 
    begin
       pragma Assert (Nkind (N) in N_Aggregate | N_Extension_Aggregate);
 
-      if No (Comps) then
-         return False;
-      end if;
-
       if Has_Self_Reference (N) then
          return True;
       end if;
 
-      --  Check if any direct component has default initialized components
+      Assoc := First (Component_Associations (N));
+      while Present (Assoc) loop
+         --  Each component association has either a box or an expression
 
-      C := First (Comps);
-      while Present (C) loop
-         if Box_Present (C) then
-            return True;
-         end if;
+         pragma Assert (Box_Present (Assoc) xor Present (Expression (Assoc)));
 
-         Next (C);
-      end loop;
+         --  Check if any direct component has default initialized components
 
-      --  Recursive call in case of aggregate expression
+         if Box_Present (Assoc) then
+            return True;
 
-      C := First (Comps);
-      while Present (C) loop
-         Expr := Expression (C);
+         --  Recursive call in case of aggregate expression
 
-         if Present (Expr)
-           and then Nkind (Expr) in N_Aggregate | N_Extension_Aggregate
-           and then Has_Default_Init_Comps (Expr)
-         then
-            return True;
+         else
+            Expr := Expression (Assoc);
+
+            if Nkind (Expr) in N_Aggregate | N_Extension_Aggregate
+              and then Has_Default_Init_Comps (Expr)
+            then
+               return True;
+            end if;
          end if;
 
-         Next (C);
+         Next (Assoc);
       end loop;
 
       return False;