----------------------------------
procedure Save_References_In_Aggregate (N : Node_Id) is
- Nam : Node_Id;
Qual : Node_Id := Empty;
Typ : Entity_Id := Empty;
end;
end if;
- -- If the aggregate is an actual in a call, it has been
- -- resolved in the current context, to some local type. The
+ -- If the aggregate is an actual in a subprogram call, it has
+ -- been resolved in the current context to some local type. The
-- enclosing call may have been disambiguated by the aggregate,
-- and this disambiguation might fail at instantiation time
-- because the type to which the aggregate did resolve is not
-- preserved. In order to preserve some of this information,
-- wrap the aggregate in a qualified expression, using the id
-- of its type. For further disambiguation we qualify the type
- -- name with its scope (if visible and not hidden by a local
- -- homograph) because both id's will have corresponding
+ -- name with its scope recursively (if visible and not hidden
+ -- by a local homograph) because both will have corresponding
-- entities in an instance. This resolves most of the problems
-- with missing type information on aggregates in instances.
and then Present (Typ)
and then Comes_From_Source (Typ)
then
- Nam := Make_Identifier (Loc, Chars (Typ));
+ declare
+ function Qualify_Name (S, E : Entity_Id) return Node_Id is
+ (if E = S
+ then Make_Identifier (Loc, Chars (E))
+ else Make_Selected_Component (Loc,
+ Prefix => Qualify_Name (S, Scope (E)),
+ Selector_Name =>
+ Make_Identifier (Loc, Chars (E))));
+ -- Return the qualified name of E up to scope S
+
+ Nam : Node_Id;
+ S : Entity_Id;
- if Is_Immediately_Visible (Scope (Typ))
- and then
- (not In_Open_Scopes (Scope (Typ))
- or else Current_Entity (Scope (Typ)) = Scope (Typ))
- then
- Nam :=
- Make_Selected_Component (Loc,
- Prefix =>
- Make_Identifier (Loc, Chars (Scope (Typ))),
- Selector_Name => Nam);
- end if;
+ begin
+ S := Scope (Typ);
+ while not Is_Immediately_Visible (S) loop
+ S := Scope (S);
+ exit when Is_Generic_Unit (S);
+ end loop;
- Qual :=
- Make_Qualified_Expression (Loc,
- Subtype_Mark => Nam,
- Expression => Relocate_Node (N));
+ if not Is_Generic_Unit (S)
+ and then (not In_Open_Scopes (S)
+ or else Current_Entity (S) = S)
+ then
+ Nam := Qualify_Name (S, Typ);
+ else
+ Nam := Make_Identifier (Loc, Chars (Typ));
+ end if;
+
+ Qual :=
+ Make_Qualified_Expression (Loc,
+ Subtype_Mark => Nam,
+ Expression => Relocate_Node (N));
+ end;
end if;
-- For a full aggregate, if the type is global and a derived