Init_Stmt : Node_Id;
begin
+ pragma Assert (Nkind (Init_Expr) in N_Subexpr);
+
-- Protect the initialization statements from aborts. Generate:
-- Abort_Defer;
With_Default_Init => True,
Constructor_Ref => Expression (Comp)));
+ elsif Box_Present (Comp)
+ and then Needs_Simple_Initialization (Etype (Selector))
+ then
+ Comp_Expr :=
+ Make_Selected_Component (Loc,
+ Prefix => New_Copy_Tree (Target),
+ Selector_Name => New_Occurrence_Of (Selector, Loc));
+
+ Initialize_Record_Component
+ (Rec_Comp => Comp_Expr,
+ Comp_Typ => Etype (Selector),
+ Init_Expr => Get_Simple_Init_Val
+ (Typ => Etype (Selector),
+ N => Comp,
+ Size =>
+ (if Known_Esize (Selector)
+ then Esize (Selector)
+ else Uint_0)),
+ Stmts => L);
+
-- Ada 2005 (AI-287): For each default-initialized component generate
-- a call to the corresponding IP subprogram if available.
Assoc_List => New_Assoc_List);
Set_Has_Self_Reference (N);
- -- A box-defaulted access component gets the value null. Also
- -- included are components of private types whose underlying
- -- type is an access type. In either case set the type of the
- -- literal, for subsequent use in semantic checks.
-
- elsif Present (Underlying_Type (Ctyp))
- and then Is_Access_Type (Underlying_Type (Ctyp))
- then
- -- If the component's type is private with an access type as
- -- its underlying type then we have to create an unchecked
- -- conversion to satisfy type checking.
-
- if Is_Private_Type (Ctyp) then
- declare
- Qual_Null : constant Node_Id :=
- Make_Qualified_Expression (Sloc (N),
- Subtype_Mark =>
- New_Occurrence_Of
- (Underlying_Type (Ctyp), Sloc (N)),
- Expression => Make_Null (Sloc (N)));
-
- Convert_Null : constant Node_Id :=
- Unchecked_Convert_To
- (Ctyp, Qual_Null);
-
- begin
- Analyze_And_Resolve (Convert_Null, Ctyp);
- Add_Association
- (Component => Component,
- Expr => Convert_Null,
- Assoc_List => New_Assoc_List);
- end;
-
- -- Otherwise the component type is non-private
-
- else
- Expr := Make_Null (Sloc (N));
- Set_Etype (Expr, Ctyp);
-
- Add_Association
- (Component => Component,
- Expr => Expr,
- Assoc_List => New_Assoc_List);
- end if;
-
- -- Ada 2012: If component is scalar with default value, use it
- -- by converting it to Ctyp, so that subtype constraints are
- -- checked.
-
- elsif Is_Scalar_Type (Ctyp)
- and then Has_Default_Aspect (Ctyp)
- then
- declare
- Conv : constant Node_Id :=
- Convert_To
- (Typ => Ctyp,
- Expr =>
- New_Copy_Tree
- (Default_Aspect_Value
- (First_Subtype (Underlying_Type (Ctyp)))));
-
- begin
- Analyze_And_Resolve (Conv, Ctyp);
- Add_Association
- (Component => Component,
- Expr => Conv,
- Assoc_List => New_Assoc_List);
- end;
+ elsif Needs_Simple_Initialization (Ctyp) then
+ Add_Association
+ (Component => Component,
+ Expr => Empty,
+ Assoc_List => New_Assoc_List,
+ Is_Box_Present => True);
elsif Has_Non_Null_Base_Init_Proc (Ctyp)
or else not Expander_Active