sem.ads, sem.adb (Preanalyze): New routine.
authorVincent Pucci <pucci@adacore.com>
Thu, 15 Mar 2012 09:11:57 +0000 (09:11 +0000)
committerArnaud Charlet <charlet@gcc.gnu.org>
Thu, 15 Mar 2012 09:11:57 +0000 (10:11 +0100)
2012-03-15  Vincent Pucci  <pucci@adacore.com>

* sem.ads, sem.adb (Preanalyze): New routine.
* sem_ch4.adb (Analyze_Quantified_Expression): Call to the
Preanalyze routine in Sem added.  Renaming of Needs_Expansion
into Need_Preanalysis.
* sem_ch6.adb (Preanalyze): Removed.

From-SVN: r185421

gcc/ada/ChangeLog
gcc/ada/sem.adb
gcc/ada/sem.ads
gcc/ada/sem_ch4.adb
gcc/ada/sem_ch6.adb

index 864c3dd3c92e39d83ac5f131a6cf5fa5c9a4fee3..1617c1a3e097c0662b92446b142a0e0749fdeb0d 100644 (file)
@@ -1,3 +1,11 @@
+2012-03-15  Vincent Pucci  <pucci@adacore.com>
+
+       * sem.ads, sem.adb (Preanalyze): New routine.
+       * sem_ch4.adb (Analyze_Quantified_Expression): Call to the
+       Preanalyze routine in Sem added.  Renaming of Needs_Expansion
+       into Need_Preanalysis.
+       * sem_ch6.adb (Preanalyze): Removed.
+
 2012-03-15  Robert Dewar  <dewar@adacore.com>
 
        * sem_ch4.adb (Analyze_Quantified_Expression): Add comment.
index fdd6ec3b6ed8f1acc3bc73a6141f52827f31c6cc..6966f45a8e9919df97ea98c88228d9f5fb97229e 100644 (file)
@@ -1288,6 +1288,23 @@ package body Sem is
       Scope_Stack.Release;
    end Lock;
 
+   ----------------
+   -- Preanalyze --
+   ----------------
+
+   procedure Preanalyze (N : Node_Id) is
+      Save_Full_Analysis : constant Boolean := Full_Analysis;
+
+   begin
+      Full_Analysis := False;
+      Expander_Mode_Save_And_Set (False);
+
+      Analyze (N);
+
+      Expander_Mode_Restore;
+      Full_Analysis := Save_Full_Analysis;
+   end Preanalyze;
+
    --------------------------------------
    -- Push_Global_Suppress_Stack_Entry --
    --------------------------------------
index 7dec90243a9089e8bd5b2e50d8535f609c435109..3fa25f90f97e1e7d36cff2ac97ad068a7444957a 100644 (file)
@@ -6,7 +6,7 @@
 --                                                                          --
 --                                 S p e c                                  --
 --                                                                          --
---          Copyright (C) 1992-2011, Free Software Foundation, Inc.         --
+--          Copyright (C) 1992-2012, Free Software Foundation, Inc.         --
 --                                                                          --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
@@ -644,6 +644,11 @@ package Sem is
    --  is False, then the status of the check can be determined simply by
    --  examining Scope_Checks (C), so this routine is not called in that case.
 
+   procedure Preanalyze (N : Node_Id);
+   --  Performs a pre-analysis of node N. During pre-analysis no expansion is
+   --  carried out for N or its children. For more info on pre-analysis read
+   --  the spec of Sem.
+
    generic
       with procedure Action (Item : Node_Id);
    procedure Walk_Library_Items;
index 5ab5d3fe475eb0a2a454eb0e112fc1749d7fbb11..ffc3a271c63824a25a48303237964f1819a3955e 100644 (file)
@@ -29,7 +29,6 @@ with Debug;    use Debug;
 with Einfo;    use Einfo;
 with Elists;   use Elists;
 with Errout;   use Errout;
-with Expander; use Expander;
 with Exp_Util; use Exp_Util;
 with Fname;    use Fname;
 with Itypes;   use Itypes;
@@ -3391,22 +3390,33 @@ package body Sem_Ch4 is
    -----------------------------------
 
    procedure Analyze_Quantified_Expression (N : Node_Id) is
-      Loc             : constant Source_Ptr := Sloc (N);
-      Ent             : constant Entity_Id :=
-                          New_Internal_Entity
-                            (E_Loop, Current_Scope, Sloc (N), 'L');
-      Needs_Expansion : constant Boolean :=
-                          Operating_Mode /= Check_Semantics
-                            and then not Alfa_Mode;
+      Loc : constant Source_Ptr := Sloc (N);
+      Ent : constant Entity_Id :=
+             New_Internal_Entity (E_Loop, Current_Scope, Sloc (N), 'L');
+
+      Need_Preanalysis : constant Boolean :=
+                           Operating_Mode /= Check_Semantics
+                             and then not Alfa_Mode;
 
       Iterator   : Node_Id;
       Original_N : Node_Id;
 
    begin
+      --  The approach in this procedure is very non-standard and at the
+      --  very least, extensive comments are required saying why this very
+      --  non-standard approach is needed???
+
+      --  Also general comments are needed in any case saying what is going
+      --  on here, since tree rewriting of this kind should normally be done
+      --  by the expander and not by the analyzer ??? Probably Ent, Iterator,
+      --  and Original_N, and Needs_Preanalysis, all need comments above ???
+
       --  Preserve the original node used for the expansion of the quantified
       --  expression.
 
-      if Needs_Expansion then
+      --  This is a very unusual use of Copy_Separate_Tree, needs looking at???
+
+      if Need_Preanalysis then
          Original_N := Copy_Separate_Tree (N);
       end if;
 
@@ -3416,6 +3426,9 @@ package body Sem_Ch4 is
 
       Check_SPARK_Restriction ("quantified expression is not allowed", N);
 
+      --  The following seems like expansion activity done at analysis
+      --  time, which seems weird ???
+
       if Present (Loop_Parameter_Specification (N)) then
          Iterator :=
            Make_Iteration_Scheme (Loc,
@@ -3443,21 +3456,21 @@ package body Sem_Ch4 is
          Set_Parent (Iterator_Specification (Iterator), Iterator);
       end if;
 
-      if Needs_Expansion then
+      if Need_Preanalysis then
 
          --  The full analysis will be performed during the expansion of the
          --  quantified expression, only a preanalysis of the condition needs
          --  to be done.
 
-         --  This is weird and irregular code for several reasons. First, doing
-         --  an Analyze with no Resolve is very suspicious, how can this be
-         --  right for the overloaded case ??? Second, doing two calls to
-         --  analyze on the same node is peculiar ??? Why can't we use the
-         --  normal Preanalyze calls here ???
+         --  This is strange for two reasons
 
-         Expander_Mode_Save_And_Set (False);
-         Analyze (Condition (N));
-         Expander_Mode_Restore;
+         --  First, there is almost no situation in which Preanalyze vs
+         --  Analyze should be conditioned on -gnatc mode (since error msgs
+         --  must be 100% unaffected by -gnatc). Seconed doing a Preanalyze
+         --  with no resolution almost certainly means that some messages are
+         --  either missed, or flagged differently in the two cases.
+
+         Preanalyze (Condition (N));
       else
          Analyze (Condition (N));
       end if;
@@ -3468,7 +3481,7 @@ package body Sem_Ch4 is
 
       --  Attach the original node to the iteration scheme created above
 
-      if Needs_Expansion then
+      if Need_Preanalysis then
          Set_Etype (Original_N, Standard_Boolean);
          Set_Parent (Iterator, Original_N);
       end if;
index a63cb7944b797455ea71d8cd55e1d4f333db193d..d9be307600d274edd9c4c8c706db94577ee150a0 100644 (file)
@@ -4280,11 +4280,6 @@ package body Sem_Ch6 is
       --  analysis of the non-inlined body will handle these pragmas properly).
       --  A new internal name is associated with Body_To_Inline.
 
-      procedure Preanalyze (N : Node_Id);
-      --  Performs a pre-analysis of node N. During pre-analysis no expansion
-      --  is carried out for N or its children. For more info on pre-analysis
-      --  read the spec of Sem.
-
       procedure Split_Unconstrained_Function
         (N       : Node_Id;
          Spec_Id : Entity_Id);
@@ -5059,23 +5054,6 @@ package body Sem_Ch6 is
          Set_Corresponding_Spec (Body_To_Inline, Empty);
       end Generate_Body_To_Inline;
 
-      ----------------
-      -- Preanalyze --
-      ----------------
-
-      procedure Preanalyze (N : Node_Id) is
-         Save_Full_Analysis : constant Boolean := Full_Analysis;
-
-      begin
-         Full_Analysis := False;
-         Expander_Mode_Save_And_Set (False);
-
-         Analyze (N);
-
-         Expander_Mode_Restore;
-         Full_Analysis := Save_Full_Analysis;
-      end Preanalyze;
-
       ----------------------------------
       -- Split_Unconstrained_Function --
       ----------------------------------