-- Similar to previous one, for discriminated components constrained
-- by the discriminant of the enclosing object.
+ function Copy_And_Maybe_Dereference (N : Node_Id) return Node_Id;
+ -- Copy the subtree rooted at N and insert an explicit dereference if it
+ -- is of an access type.
+
-----------------------------------
-- Build_Actual_Array_Constraint --
-----------------------------------
if Denotes_Discriminant (Old_Lo) then
Lo :=
Make_Selected_Component (Loc,
- Prefix => New_Copy_Tree (P),
+ Prefix => Copy_And_Maybe_Dereference (P),
Selector_Name => New_Occurrence_Of (Entity (Old_Lo), Loc));
else
if Denotes_Discriminant (Old_Hi) then
Hi :=
Make_Selected_Component (Loc,
- Prefix => New_Copy_Tree (P),
+ Prefix => Copy_And_Maybe_Dereference (P),
Selector_Name => New_Occurrence_Of (Entity (Old_Hi), Loc));
else
while Present (D) loop
if Denotes_Discriminant (Node (D)) then
D_Val := Make_Selected_Component (Loc,
- Prefix => New_Copy_Tree (P),
+ Prefix => Copy_And_Maybe_Dereference (P),
Selector_Name => New_Occurrence_Of (Entity (Node (D)), Loc));
else
D_Val := New_Copy_Tree (D);
Set_Expression (D_Val,
Make_Selected_Component (Loc,
- Prefix => New_Copy_Tree (P),
+ Prefix => Copy_And_Maybe_Dereference (P),
Selector_Name =>
New_Occurrence_Of (Entity (Expression (D)), Loc)));
elsif Denotes_Discriminant (D) then
D_Val := Make_Selected_Component (Loc,
- Prefix => New_Copy_Tree (P),
+ Prefix => Copy_And_Maybe_Dereference (P),
Selector_Name => New_Occurrence_Of (Entity (D), Loc));
else
return Constraints;
end Build_Access_Record_Constraint;
+ --------------------------------
+ -- Copy_And_Maybe_Dereference --
+ --------------------------------
+
+ function Copy_And_Maybe_Dereference (N : Node_Id) return Node_Id is
+ New_N : constant Node_Id := New_Copy_Tree (N);
+
+ begin
+ if Is_Access_Type (Etype (New_N)) then
+ Insert_Explicit_Dereference (New_N);
+ end if;
+
+ return New_N;
+ end Copy_And_Maybe_Dereference;
+
-- Start of processing for Build_Actual_Subtype_Of_Component
begin