[Ada] Fix scope computation for loop statements
authorEd Schonberg <schonberg@adacore.com>
Tue, 21 Aug 2018 14:47:50 +0000 (14:47 +0000)
committerPierre-Marie de Rodat <pmderodat@gcc.gnu.org>
Tue, 21 Aug 2018 14:47:50 +0000 (14:47 +0000)
2018-08-21  Ed Schonberg  <schonberg@adacore.com>

gcc/ada/

* sem_ch13.adb (Build_Predicate_Functioss): Apply
Reset_Quantified_Variables_Scope after predicate function has
been analyzed, so that the scope can be reset on the generated
loop statements that have replaced the quantified expressions.

From-SVN: r263729

gcc/ada/ChangeLog
gcc/ada/sem_ch13.adb

index a89911a..48974e7 100644 (file)
@@ -1,3 +1,10 @@
+2018-08-21  Ed Schonberg  <schonberg@adacore.com>
+
+       * sem_ch13.adb (Build_Predicate_Functioss): Apply
+       Reset_Quantified_Variables_Scope after predicate function has
+       been analyzed, so that the scope can be reset on the generated
+       loop statements that have replaced the quantified expressions.
+
 2018-08-21  Bob Duff  <duff@adacore.com>
 
        * einfo.ads, einfo.adb (Private_View, Shadow_Entities): Remove
index 28a3dd8..1a12622 100644 (file)
@@ -8754,7 +8754,6 @@ package body Sem_Ch13 is
       --  Case where predicates are present
 
       if Present (Expr) then
-
          --  Test for raise expression present
 
          Test_REs (Expr);
@@ -8856,6 +8855,42 @@ package body Sem_Ch13 is
 
             Insert_After_And_Analyze (N, FBody);
 
+            --  The defining identifier of a quantified expression carries the
+            --  scope in which the type appears, but when unnesting we need
+            --  to indicate that its proper scope is the constructed predicate
+            --  function. The quantified expressions have been converted into
+            --  loops during analysis and expansion.
+
+            declare
+               function Reset_Quantified_Variable_Scope (N : Node_Id)
+                 return Traverse_Result;
+
+               procedure Reset_Quantified_Variables_Scope is
+                 new Traverse_Proc (Reset_Quantified_Variable_Scope);
+
+               -------------------------------------
+               -- Reset_Quantified_Variable_Scope --
+               -------------------------------------
+
+               function Reset_Quantified_Variable_Scope (N : Node_Id)
+                 return Traverse_Result
+               is
+               begin
+                  if Nkind_In (N, N_Iterator_Specification,
+                                  N_Loop_Parameter_Specification)
+                  then
+                     Set_Scope (Defining_Identifier (N),
+                       Predicate_Function (Typ));
+                  end if;
+                  return OK;
+               end Reset_Quantified_Variable_Scope;
+
+            begin
+               if Unnest_Subprogram_Mode then
+                  Reset_Quantified_Variables_Scope (Expr);
+               end if;
+            end;
+
             --  within a generic unit, prevent a double analysis of the body
             --  which will not be marked analyzed yet. This will happen when
             --  the freeze node is created during the preanalysis of an
@@ -8972,6 +9007,8 @@ package body Sem_Ch13 is
 
                Insert_Before_And_Analyze (N, FDecl);
                Insert_After_And_Analyze  (N, FBody);
+
+               --  Should quantified expressions be handled here as well ???
             end;
          end if;