aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada/exp_aggr.adb
diff options
context:
space:
mode:
authorPiotr Trojanek <trojanek@adacore.com>2021-09-29 12:16:38 +0200
committerPierre-Marie de Rodat <derodat@adacore.com>2021-10-11 13:38:10 +0000
commitb52e15202c8a0ed1afeff92bba72fd2811c9dac1 (patch)
tree99d2ea49685beb1141507e2418bbda03c709a37f /gcc/ada/exp_aggr.adb
parent7dc58f3fc27ac9620b469dc56c44d55b7ee9d1a6 (diff)
downloadgcc-b52e15202c8a0ed1afeff92bba72fd2811c9dac1.zip
gcc-b52e15202c8a0ed1afeff92bba72fd2811c9dac1.tar.gz
gcc-b52e15202c8a0ed1afeff92bba72fd2811c9dac1.tar.bz2
[Ada] Simplify detection of record components with default initialization
gcc/ada/ * exp_aggr.adb (Has_Default_Init_Comps): Simplify.
Diffstat (limited to 'gcc/ada/exp_aggr.adb')
-rw-r--r--gcc/ada/exp_aggr.adb43
1 files changed, 19 insertions, 24 deletions
diff --git a/gcc/ada/exp_aggr.adb b/gcc/ada/exp_aggr.adb
index 06cdafd..187bb5f 100644
--- a/gcc/ada/exp_aggr.adb
+++ b/gcc/ada/exp_aggr.adb
@@ -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;