aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Poulhiès <poulhies@adacore.com>2024-02-27 13:47:27 +0100
committerMarc Poulhiès <poulhies@adacore.com>2024-05-16 10:49:34 +0200
commitf72988ac5ecfd56229374cbe76d867177ec5431d (patch)
treebfb3485ddbce6b4e1d40873954547c14d93ad97c
parent584ade0b82339d95463bc91c9fdd77579b16426a (diff)
downloadgcc-f72988ac5ecfd56229374cbe76d867177ec5431d.zip
gcc-f72988ac5ecfd56229374cbe76d867177ec5431d.tar.gz
gcc-f72988ac5ecfd56229374cbe76d867177ec5431d.tar.bz2
ada: Reset scope of top level object declaration during unnesting
When unnesting, the compiler gathers elaboration code and wraps it with a new dedicated procedure. While doing so, it resets the scopes of entities that are wrapped to point to this new procedure. This change also resets the scopes of N_Object_Declaration and N_Object_Renaming_Declaration nodes only if an elaboration procedure is needed. gcc/ada/ * exp_ch7.adb (Reset_Scopes_To_Block_Elab_Proc): also reset scope for object declarations.
-rw-r--r--gcc/ada/exp_ch7.adb31
1 files changed, 27 insertions, 4 deletions
diff --git a/gcc/ada/exp_ch7.adb b/gcc/ada/exp_ch7.adb
index 6d76572..f9738e1 100644
--- a/gcc/ada/exp_ch7.adb
+++ b/gcc/ada/exp_ch7.adb
@@ -3646,9 +3646,10 @@ package body Exp_Ch7 is
-- unnesting actions, which depend on proper setting of the Scope links
-- to determine the nesting level of each subprogram.
- -----------------------
- -- Find_Local_Scope --
- -----------------------
+ --------------------------------------
+ -- Reset_Scopes_To_Block_Elab_Proc --
+ --------------------------------------
+ Maybe_Reset_Scopes_For_Decl : constant Elist_Id := New_Elmt_List;
procedure Reset_Scopes_To_Block_Elab_Proc (L : List_Id) is
Id : Entity_Id;
@@ -3707,7 +3708,8 @@ package body Exp_Ch7 is
Next (Node);
end loop;
- -- Reset the Scope of a subprogram occurring at the top level
+ -- Reset the Scope of a subprogram and object declaration
+ -- occurring at the top level
when N_Subprogram_Body =>
Id := Defining_Entity (Stat);
@@ -3715,12 +3717,33 @@ package body Exp_Ch7 is
Set_Block_Elab_Proc;
Set_Scope (Id, Block_Elab_Proc);
+ when N_Object_Declaration
+ | N_Object_Renaming_Declaration =>
+ Id := Defining_Entity (Stat);
+ if No (Block_Elab_Proc) then
+ Append_Elmt (Id, Maybe_Reset_Scopes_For_Decl);
+ else
+ Set_Scope (Id, Block_Elab_Proc);
+ end if;
+
when others =>
null;
end case;
Next (Stat);
end loop;
+
+ -- If we are creating an Elab procedure, move all the gathered
+ -- declarations in its scope.
+
+ if Present (Block_Elab_Proc) then
+ while not Is_Empty_Elmt_List (Maybe_Reset_Scopes_For_Decl) loop
+ Set_Scope
+ (Elists.Node
+ (Last_Elmt (Maybe_Reset_Scopes_For_Decl)), Block_Elab_Proc);
+ Remove_Last_Elmt (Maybe_Reset_Scopes_For_Decl);
+ end loop;
+ end if;
end Reset_Scopes_To_Block_Elab_Proc;
-- Local variables