aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada/exp_ch3.adb
diff options
context:
space:
mode:
authorEd Schonberg <schonberg@adacore.com>2007-08-31 12:22:15 +0200
committerArnaud Charlet <charlet@gcc.gnu.org>2007-08-31 12:22:15 +0200
commit55d4e6c0909277e0cd19e05de382ac87895b0db8 (patch)
tree22fe6783590bb43ac3b19495cce6ab42ba9d18a0 /gcc/ada/exp_ch3.adb
parentf7d2a3f74ae12f8bfec0e273b5d405e4db73b0b7 (diff)
downloadgcc-55d4e6c0909277e0cd19e05de382ac87895b0db8.zip
gcc-55d4e6c0909277e0cd19e05de382ac87895b0db8.tar.gz
gcc-55d4e6c0909277e0cd19e05de382ac87895b0db8.tar.bz2
exp_ch3.adb (Build_Record_Init_Proc): If there is a static initialization aggregate for the type...
2007-08-31 Ed Schonberg <schonberg@adacore.com> * exp_ch3.adb (Build_Record_Init_Proc): If there is a static initialization aggregate for the type, generate itype references for thetypes of its (sub)components, to prevent out-of-scope errors in gigi. From-SVN: r127972
Diffstat (limited to 'gcc/ada/exp_ch3.adb')
-rw-r--r--gcc/ada/exp_ch3.adb70
1 files changed, 66 insertions, 4 deletions
diff --git a/gcc/ada/exp_ch3.adb b/gcc/ada/exp_ch3.adb
index be50512..9c933bb 100644
--- a/gcc/ada/exp_ch3.adb
+++ b/gcc/ada/exp_ch3.adb
@@ -3091,8 +3091,70 @@ package body Exp_Ch3 is
Set_Debug_Info_Off (Proc_Id);
end if;
- Set_Static_Initialization
- (Proc_Id, Build_Equivalent_Record_Aggregate (Rec_Type));
+ declare
+ Agg : constant Node_Id :=
+ Build_Equivalent_Record_Aggregate (Rec_Type);
+
+ procedure Collect_Itypes (Comp : Node_Id);
+ -- Generate references to itypes in the aggregate, because
+ -- the first use of the aggregate may be in a nested scope.
+
+ --------------------
+ -- Collect_Itypes --
+ --------------------
+
+ procedure Collect_Itypes (Comp : Node_Id) is
+ Ref : Node_Id;
+ Sub_Aggr : Node_Id;
+ Typ : Entity_Id;
+
+ begin
+ if Is_Array_Type (Etype (Comp))
+ and then Is_Itype (Etype (Comp))
+ then
+ Typ := Etype (Comp);
+ Ref := Make_Itype_Reference (Loc);
+ Set_Itype (Ref, Typ);
+ Append_Freeze_Action (Rec_Type, Ref);
+
+ Ref := Make_Itype_Reference (Loc);
+ Set_Itype (Ref, Etype (First_Index (Typ)));
+ Append_Freeze_Action (Rec_Type, Ref);
+
+ Sub_Aggr := First (Expressions (Comp));
+
+ -- Recurse on nested arrays
+
+ while Present (Sub_Aggr) loop
+ Collect_Itypes (Sub_Aggr);
+ Next (Sub_Aggr);
+ end loop;
+ end if;
+ end Collect_Itypes;
+
+ begin
+ -- If there is a static initialization aggregate for the type,
+ -- generate itype references for the types of its (sub)components,
+ -- to prevent out-of-scope errors in the resulting tree.
+ -- The aggregate may have been rewritten as a Raise node, in which
+ -- case there are no relevant itypes.
+
+ if Present (Agg)
+ and then Nkind (Agg) = N_Aggregate
+ then
+ Set_Static_Initialization (Proc_Id, Agg);
+
+ declare
+ Comp : Node_Id;
+ begin
+ Comp := First (Component_Associations (Agg));
+ while Present (Comp) loop
+ Collect_Itypes (Expression (Comp));
+ Next (Comp);
+ end loop;
+ end;
+ end if;
+ end;
end if;
end Build_Record_Init_Proc;
@@ -6779,9 +6841,9 @@ package body Exp_Ch3 is
Formal : Entity_Id;
Par_Formal : Entity_Id;
Formal_Node : Node_Id;
- Func_Spec : Node_Id;
- Func_Decl : Node_Id;
Func_Body : Node_Id;
+ Func_Decl : Node_Id;
+ Func_Spec : Node_Id;
Return_Stmt : Node_Id;
begin