aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada/sem_aggr.adb
diff options
context:
space:
mode:
authorPiotr Trojanek <trojanek@adacore.com>2021-09-29 19:51:33 +0200
committerPierre-Marie de Rodat <derodat@adacore.com>2021-10-11 13:38:10 +0000
commit736f9bed34c0420063c3c01b520099711040d345 (patch)
tree04a4c86a4310cb786ef985599c6c33d2eaafefe7 /gcc/ada/sem_aggr.adb
parent1bafcab05cbff1cc98e3ca867b4474401eec729b (diff)
downloadgcc-736f9bed34c0420063c3c01b520099711040d345.zip
gcc-736f9bed34c0420063c3c01b520099711040d345.tar.gz
gcc-736f9bed34c0420063c3c01b520099711040d345.tar.bz2
[Ada] Move rewriting of boxes in aggregates from resolution to expansion
gcc/ada/ * exp_aggr.adb (Initialize_Record_Component): Add assertion about one of the parameters, so that illegal attempts to initialize record components with Empty node are detected early on. (Build_Record_Aggr_Code): Handle boxes in aggregate component associations just the components with no initialization in Build_Record_Init_Proc. * sem_aggr.adb (Resolve_Record_Aggregate): For components that require simple initialization carry boxes from resolution to expansion. * sem_util.adb (Needs_Simple_Initialization): Remove redundant paren.
Diffstat (limited to 'gcc/ada/sem_aggr.adb')
-rw-r--r--gcc/ada/sem_aggr.adb74
1 files changed, 6 insertions, 68 deletions
diff --git a/gcc/ada/sem_aggr.adb b/gcc/ada/sem_aggr.adb
index b51a3d0..527342f 100644
--- a/gcc/ada/sem_aggr.adb
+++ b/gcc/ada/sem_aggr.adb
@@ -5387,74 +5387,12 @@ package body Sem_Aggr is
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