[multiple changes]
authorArnaud Charlet <charlet@gcc.gnu.org>
Mon, 8 Jul 2013 07:47:39 +0000 (09:47 +0200)
committerArnaud Charlet <charlet@gcc.gnu.org>
Mon, 8 Jul 2013 07:47:39 +0000 (09:47 +0200)
2013-07-08  Javier Miranda  <miranda@adacore.com>

* sem_ch8.adb (Save_Scope_Stack): Adding documentation.
(Restore_Scope_Stack): Remove the elements of the list when the
visibility of each entity is restored.

2013-07-08  Robert Dewar  <dewar@adacore.com>

* exp_ch9.adb, sem.ads, sem_util.adb: Minor reformatting.

From-SVN: r200756

gcc/ada/ChangeLog
gcc/ada/exp_ch9.adb
gcc/ada/sem.ads
gcc/ada/sem_ch8.adb
gcc/ada/sem_util.adb

index 0fa4a2e6a3b4bcb6a74c354ac7bb8ebf3e601186..c7f9f39a178dcad03fa6327fa0a7dce32db8c245 100644 (file)
@@ -1,3 +1,13 @@
+2013-07-08  Javier Miranda  <miranda@adacore.com>
+
+       * sem_ch8.adb (Save_Scope_Stack): Adding documentation.
+       (Restore_Scope_Stack): Remove the elements of the list when the
+       visibility of each entity is restored.
+
+2013-07-08  Robert Dewar  <dewar@adacore.com>
+
+       * exp_ch9.adb, sem.ads, sem_util.adb: Minor reformatting.
+
 2013-07-08  Robert Dewar  <dewar@adacore.com>
 
        * sem_ch8.adb, sem_ch8.ads: Minor reformatting.
index 20a346ceec2cb385eaea5163f2e62cc39547ca25..59c5b2d62ce5604c7d10a45318cb7bf622f05f79 100644 (file)
@@ -3347,7 +3347,7 @@ package body Exp_Ch9 is
             if Known_Static_Esize (Comp_Type) then
                Typ_Size := UI_To_Int (Esize (Comp_Type));
 
-            --  If the Esize (Object_Size) is unknown at compile-time, look at
+            --  If the Esize (Object_Size) is unknown at compile time, look at
             --  the RM_Size (Value_Size) since it may have been set by an
             --  explicit representation clause.
 
index 545aadc6a53dcddca09e8fa28f297742cc495d82..57d5d9110580a79ff9e0fd582816576c12fc706b 100644 (file)
@@ -562,7 +562,7 @@ package Sem is
    --  Note: for integer and real literals, the analyzer sets the flag to
    --  indicate that the result is a static expression. If the expander
    --  generates a literal that does NOT correspond to a static expression,
-   --  e.g. by folding an expression whose value is known at compile-time,
+   --  e.g. by folding an expression whose value is known at compile time,
    --  but is not technically static, then the caller should reset the
    --  Is_Static_Expression flag after analyzing but before resolving.
    --
index c0795b7f7688e357d68a89a21b38173eeb7f3b11..c5d2e9925d2f5936392d4bc2be36a46728c43e04 100644 (file)
@@ -7662,16 +7662,18 @@ package body Sem_Ch8 is
       Elmt    : Elmt_Id;
 
    begin
-      --  Restore visibility of previous scope stack, if any
+      --  Restore visibility of previous scope stack, if any, using the list
+      --  we saved (we use Remove, since this list will not be used again).
 
-      --  Should use Remove_Elmt, so that elements can be reused ???
-
-      Elmt := First_Elmt (List);
-      while Present (Elmt) loop
+      loop
+         Elmt := Last_Elmt (List);
+         exit when Elmt = No_Elmt;
          Set_Is_Immediately_Visible (Node (Elmt));
-         Next_Elmt (Elmt);
+         Remove_Last_Elmt (List);
       end loop;
 
+      --  Restore use clauses
+
       if SS_Last >= Scope_Stack.First
         and then Scope_Stack.Table (SS_Last).Entity /= Standard_Standard
         and then Handle_Use
@@ -7684,6 +7686,34 @@ package body Sem_Ch8 is
    -- Save_Scope_Stack --
    ----------------------
 
+   --  Save_Scope_Stack/Restore_Scope_Stack were originally designed to avoid
+   --  consuming any memory. That is, Save_Scope_Stack took care of removing
+   --  from immediate visibility entities and Restore_Scope_Stack took care
+   --  of restoring their visibility analyzing the context of each entity. The
+   --  problem of such approach is that it was fragile and caused unexpected
+   --  visibility problems, and indeed one test was found where there was a
+   --  real problem.
+
+   --  Furthermore, the following experiment was carried out:
+
+   --    - Save_Scope_Stack was modified to store in an Elist1 all those
+   --      entities whose attribute Is_Immediately_Visible is modified
+   --      from True to False.
+
+   --    - Restore_Scope_Stack was modified to store in another Elist2
+   --      all the entities whose attribute Is_Immediately_Visible is
+   --      modified from False to True.
+
+   --    - Extra code was added to verify that all the elements of Elist1
+   --      are found in Elist2
+
+   --  This test show that there may be more occurrences of this problem which
+   --  have not yet been detected. As a result, we replaced that approach by
+   --  the current one in which Save_Scope_Stack returns the list of entities
+   --  whose visibility is changed, and that list is passed to Restore_Scope
+   --  Stack to undo that change. This approach is simpler and safer, although
+   --  it consumes more memory.
+
    function Save_Scope_Stack (Handle_Use : Boolean := True) return Elist_Id is
       Result  : constant Elist_Id := New_Elmt_List;
       E       : Entity_Id;
@@ -7698,8 +7728,6 @@ package body Sem_Ch8 is
       -- Remove_From_Visibility --
       ----------------------------
 
-      --  Need comment on why we do this instead of old approach???
-
       procedure Remove_From_Visibility (E : Entity_Id) is
       begin
          if Is_Immediately_Visible (E) then
index c914703f8941514f08ba9f8590a9669751327e6e..623d3c4f8e87e44eda7f856bb619f8113a0e6039 100644 (file)
@@ -14144,9 +14144,8 @@ package body Sem_Util is
       if Known_Static_Esize (Typ) then
          Size := UI_To_Int (Esize (Typ));
 
-      --  If the Esize (Object_Size) is unknown at compile-time, look at the
-      --  RM_Size (Value_Size) since it may have been set by an explicit rep
-      --  item.
+      --  If the Esize (Object_Size) is unknown at compile time, look at the
+      --  RM_Size (Value_Size) which may have been set by an explicit rep item.
 
       elsif Known_Static_RM_Size (Typ) then
          Size := UI_To_Int (RM_Size (Typ));