aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada/sem_util.adb
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/ada/sem_util.adb')
-rw-r--r--gcc/ada/sem_util.adb104
1 files changed, 104 insertions, 0 deletions
diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb
index 35b0888..1146b9d 100644
--- a/gcc/ada/sem_util.adb
+++ b/gcc/ada/sem_util.adb
@@ -9046,6 +9046,110 @@ package body Sem_Util is
end if;
end Has_Enabled_Property;
+ -------------------------------------
+ -- Has_Full_Default_Initialization --
+ -------------------------------------
+
+ function Has_Full_Default_Initialization (Typ : Entity_Id) return Boolean is
+ Arg : Node_Id;
+ Comp : Entity_Id;
+ Prag : Node_Id;
+
+ begin
+ -- A private type and its full view is fully default initialized when it
+ -- is subject to pragma Default_Initial_Condition without an argument or
+ -- with a non-null argument. Since any type may act as the full view of
+ -- a private type, this check must be performed prior to the specialized
+ -- tests below.
+
+ if Has_Default_Init_Cond (Typ)
+ or else Has_Inherited_Default_Init_Cond (Typ)
+ then
+ Prag := Get_Pragma (Typ, Pragma_Default_Initial_Condition);
+
+ -- Pragma Default_Initial_Condition must be present if one of the
+ -- related entity flags is set.
+
+ pragma Assert (Present (Prag));
+ Arg := First (Pragma_Argument_Associations (Prag));
+
+ -- A non-null argument guarantees full default initialization
+
+ if Present (Arg) then
+ return Nkind (Arg) /= N_Null;
+
+ -- Otherwise the missing argument defaults the pragma to "True" which
+ -- is considered a non-null argument (see above).
+
+ else
+ return True;
+ end if;
+ end if;
+
+ -- A scalar type is fully default initialized if it is subject to aspect
+ -- Default_Value.
+
+ if Is_Scalar_Type (Typ) then
+ return Has_Default_Aspect (Typ);
+
+ -- An array type is fully default initialized if its element type is
+ -- scalar and the array type carries aspect Default_Component_Value or
+ -- the element type is fully default initialized.
+
+ elsif Is_Array_Type (Typ) then
+ return
+ Has_Default_Aspect (Typ)
+ or else Has_Full_Default_Initialization (Component_Type (Typ));
+
+ -- A protected type, record type or type extension is fully default
+ -- initialized if all its components either carry an initialization
+ -- expression or have a type that is fully default initialized. The
+ -- parent type of a type extension must be fully default initialized.
+
+ elsif Is_Record_Type (Typ) or else Is_Protected_Type (Typ) then
+
+ -- Inspect all entities defined in the scope of the type, looking for
+ -- uninitialized components.
+
+ Comp := First_Entity (Typ);
+ while Present (Comp) loop
+ if Ekind (Comp) = E_Component
+ and then Comes_From_Source (Comp)
+ and then No (Expression (Parent (Comp)))
+ and then not Has_Full_Default_Initialization (Etype (Comp))
+ then
+ return False;
+ end if;
+
+ Next_Entity (Comp);
+ end loop;
+
+ -- Ensure that the parent type of a type extension is fully default
+ -- initialized.
+
+ if Etype (Typ) /= Typ
+ and then not Has_Full_Default_Initialization (Etype (Typ))
+ then
+ return False;
+ end if;
+
+ -- If we get here, then all components and parent portion are fully
+ -- default initialized.
+
+ return True;
+
+ -- A task type is fully default initialized by default
+
+ elsif Is_Task_Type (Typ) then
+ return True;
+
+ -- Otherwise the type is not fully default initialized
+
+ else
+ return False;
+ end if;
+ end Has_Full_Default_Initialization;
+
--------------------
-- Has_Infinities --
--------------------