From: Piotr Trojanek Date: Wed, 29 Sep 2021 10:16:38 +0000 (+0200) Subject: [Ada] Simplify detection of record components with default initialization X-Git-Tag: basepoints/gcc-13~4018 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b52e15202c8a0ed1afeff92bba72fd2811c9dac1;p=thirdparty%2Fgcc.git [Ada] Simplify detection of record components with default initialization gcc/ada/ * exp_aggr.adb (Has_Default_Init_Comps): Simplify. --- diff --git a/gcc/ada/exp_aggr.adb b/gcc/ada/exp_aggr.adb index 06cdafda4187..187bb5f47b66 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;