summaryrefslogtreecommitdiff
path: root/gcc/ada/exp_ch3.adb
diff options
context:
space:
mode:
authorcharlet <charlet@138bc75d-0d04-0410-961f-82ee72b054a4>2007-08-31 10:22:15 +0000
committercharlet <charlet@138bc75d-0d04-0410-961f-82ee72b054a4>2007-08-31 10:22:15 +0000
commit80ca8679fa6ddf096e5ebe91c3351ec5c9b6e433 (patch)
tree22fe6783590bb43ac3b19495cce6ab42ba9d18a0 /gcc/ada/exp_ch3.adb
parentebe17e851e0b55887cbfe8a61605741108e4bdd2 (diff)
downloadgcc-80ca8679fa6ddf096e5ebe91c3351ec5c9b6e433.tar.gz
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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@127972 138bc75d-0d04-0410-961f-82ee72b054a4
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 be5051265a5..9c933bb2dc3 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