Skip to content
Snippets Groups Projects
Commit cb690aa1 authored by Marc Poulhiès's avatar Marc Poulhiès Committed by Marc Poulhiès
Browse files

ada: Also reset scope for some nested declaration

When changing the scope for entities found in the entry body that is
mutated into a procedure, the compiler needs to look deeper than only
the top level entities as expansion may produce object declarations
which scopes are also the entry. For example, the tree after expansion
may look like:

  procedure This_Is_An_Entry_Proc is
     ...
     O1 : Typ := do
       TMP1 : OTyp := ...;
       ...
     in TMP1;

O1's scope needs to be reset to This_Is_An_Entry_Proc, but so does
TMP1's scope.

This change also fix a small oversight where
N_Implicit_Label_Declaration scope must be reset and its content
skipped.

gcc/ada/

	* exp_ch9.adb (Reset_Scopes_To): Adjust comment.
	(Reset_Scopes_To.Reset_Scope): Adjust the scope reset for object
	declaration. In particular, visit the children nodes if any. Also
	extend the handling of other declarations to
	N_Implicit_Label_Declaration.
parent 905ab329
No related branches found
No related tags found
No related merge requests found
...@@ -489,7 +489,8 @@ package body Exp_Ch9 is ...@@ -489,7 +489,8 @@ package body Exp_Ch9 is
-- <actualN> := P.<formalN>; -- <actualN> := P.<formalN>;
   
procedure Reset_Scopes_To (Bod : Node_Id; E : Entity_Id); procedure Reset_Scopes_To (Bod : Node_Id; E : Entity_Id);
-- Reset the scope of declarations and blocks at the top level of Bod to -- Reset the scope of declarations and blocks at the top level of Bod and
-- of nested object declarations with scope pointing to the entry entity to
-- be E. Bod is either a block or a subprogram body. Used after expanding -- be E. Bod is either a block or a subprogram body. Used after expanding
-- various kinds of entry bodies into their corresponding constructs. This -- various kinds of entry bodies into their corresponding constructs. This
-- is needed during unnesting to determine whether a body generated for an -- is needed during unnesting to determine whether a body generated for an
...@@ -14868,12 +14869,34 @@ package body Exp_Ch9 is ...@@ -14868,12 +14869,34 @@ package body Exp_Ch9 is
Set_Scope (Entity (Identifier (N)), E); Set_Scope (Entity (Identifier (N)), E);
return Skip; return Skip;
   
-- Reset scope for object declaration which scope is the task entry.
--
-- Also look inside the declaration (in particular in the expression
-- if present) because we may have expanded to something like:
-- O1 : Typ := do
-- TMP1 : OTyp := ...;
-- ...
-- in TMP1;
-- And the scope for TMP1 is Scope (O1). We need to look inside the
-- declaration to also reset such scope.
elsif Nkind (N) = N_Object_Declaration then
if Present (Scope (Defining_Entity (N)))
and then Ekind (Scope (Defining_Entity (N)))
in E_Entry | E_Entry_Family
then
Set_Scope (Defining_Entity (N), E);
end if;
-- Ditto for a package declaration or a full type declaration, etc. -- Ditto for a package declaration or a full type declaration, etc.
   
elsif (Nkind (N) = N_Package_Declaration elsif (Nkind (N) = N_Package_Declaration
and then N /= Specification (N)) and then N /= Specification (N))
or else Nkind (N) in N_Declaration or else Nkind (N) in N_Declaration
or else Nkind (N) in N_Renaming_Declaration or else Nkind (N) in N_Renaming_Declaration
or else Nkind (N) in N_Implicit_Label_Declaration
then then
Set_Scope (Defining_Entity (N), E); Set_Scope (Defining_Entity (N), E);
return Skip; return Skip;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment