return Result;
end if;
- Scop := Enclosing_Declaration (Scop);
- if Present (Scop) then
- Scop := Parent (Scop);
+ declare
+ Saved_Scope : constant Node_Id := Scop;
+ begin
+ Scop := Enclosing_Declaration (Scop);
if Present (Scop) then
- -- For a subprogram associated with a type, we don't care
- -- where the type was frozen; continue from the type.
-
- if Nkind (Scop) = N_Freeze_Entity then
- Scop := Scope (Entity (Scop));
- elsif Nkind (Parent (Scop)) = N_Freeze_Entity then
- Scop := Scope (Entity (Parent (Scop)));
- else
- Scop := Find_Enclosing_Scope (Scop);
+ Scop := Parent (Scop);
+ if Present (Scop) then
+ -- For a subprogram associated with a type, we don't care
+ -- where the type was frozen; continue from the type.
+
+ if Nkind (Scop) = N_Freeze_Entity then
+ Scop := Scope (Entity (Scop));
+ elsif Nkind (Parent (Scop)) = N_Freeze_Entity then
+ Scop := Scope (Entity (Parent (Scop)));
+ elsif Present (Scope (Saved_Scope)) then
+ Scop := Scope (Saved_Scope);
+ else
+ Scop := Find_Enclosing_Scope (Scop);
+ end if;
end if;
end if;
- end if;
+ end;
end loop;
return Empty;