From: Gary Dismukes Date: Thu, 12 Dec 2019 10:02:38 +0000 (+0000) Subject: [Ada] Handling up-level references in protected entries and freeze nodes X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=182c8b7d2d43c71c92736bc37fe2a17545aa7776;p=gcc.git [Ada] Handling up-level references in protected entries and freeze nodes 2019-12-12 Gary Dismukes gcc/ada/ * exp_ch9.adb (Build_Protected_Entry): Analyze the block created to hold the declarations and statements of the protected entry body right after it's created, and then call Reset_Scopes_To on that block to reset the Scope of nested entities to the block scope. (Reset_Scope): Add handling for N_Freeze_Entity nodes, calling Reset_Scopes recursively on the Actions of such nodes. Also, for subprogram bodies that are encountered that might not have a separate declaration (such as type init procedures), reset the Scope of the subprogram's entity. From-SVN: r279289 --- diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index 9e271acd00e..f28fa45be5c 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,16 @@ +2019-12-12 Gary Dismukes + + * exp_ch9.adb (Build_Protected_Entry): Analyze the block created + to hold the declarations and statements of the protected entry + body right after it's created, and then call Reset_Scopes_To on + that block to reset the Scope of nested entities to the block + scope. + (Reset_Scope): Add handling for N_Freeze_Entity nodes, calling + Reset_Scopes recursively on the Actions of such nodes. Also, for + subprogram bodies that are encountered that might not have a + separate declaration (such as type init procedures), reset the + Scope of the subprogram's entity. + 2019-12-12 Justin Squirek * sem_attr.adb (Analyze_Attribute): Add error message for diff --git a/gcc/ada/exp_ch9.adb b/gcc/ada/exp_ch9.adb index 720c1a9a237..6e34de131ff 100644 --- a/gcc/ada/exp_ch9.adb +++ b/gcc/ada/exp_ch9.adb @@ -48,6 +48,7 @@ with Rident; use Rident; with Rtsfind; use Rtsfind; with Sem; use Sem; with Sem_Aux; use Sem_Aux; +with Sem_Ch5; use Sem_Ch5; with Sem_Ch6; use Sem_Ch6; with Sem_Ch8; use Sem_Ch8; with Sem_Ch9; use Sem_Ch9; @@ -3722,6 +3723,14 @@ package body Exp_Ch9 is Declarations => Decls, Handled_Statement_Sequence => Handled_Statement_Sequence (N))); + -- Analyze now and reset scopes for declarations so that Scope fields + -- currently denoting the entry will now denote the block scope. + + Analyze_Statements (Bod_Stmts); + + Reset_Scopes_To + (First (Bod_Stmts), Entity (Identifier (First (Bod_Stmts)))); + case Corresponding_Runtime_Package (Pid) is when System_Tasking_Protected_Objects_Entries => Append_To (Bod_Stmts, @@ -14977,7 +14986,27 @@ package body Exp_Ch9 is Next (Decl); end loop; + elsif Nkind (N) = N_Freeze_Entity then + + -- Scan the actions associated with a freeze node, which may + -- actually be declarations with entities that need to have + -- their scopes reset. + + Decl := First (Actions (N)); + while Present (Decl) loop + Reset_Scopes (Decl); + Next (Decl); + end loop; + elsif N /= Bod and then Nkind (N) in N_Proper_Body then + + -- A subprogram without a separate declaration may be encountered, + -- and we need to reset the subprogram's entity's scope. + + if Nkind (N) = N_Subprogram_Body then + Set_Scope (Defining_Entity (Specification (N)), E); + end if; + return Skip; end if;