OSDN Git Service

* gcc-interface/trans.c (Subprogram_Body_to_gnu): Pop the stack of
[pf3gnuchains/gcc-fork.git] / gcc / ada / a-rbtgbo.adb
index 4442d5c..d665713 100644 (file)
@@ -59,13 +59,18 @@ package body Ada.Containers.Red_Black_Trees.Generic_Bounded_Operations is
            "attempt to tamper with cursors (container is busy)";
       end if;
 
-      Tree.First := 0;
-      Tree.Last := 0;
-      Tree.Root := 0;
+      --  The lock status (which monitors "element tampering") always implies
+      --  that the busy status (which monitors "cursor tampering") is set too;
+      --  this is a representation invariant. Thus if the busy bit is not set,
+      --  then the lock bit must not be set either.
+
+      pragma Assert (Tree.Lock = 0);
+
+      Tree.First  := 0;
+      Tree.Last   := 0;
+      Tree.Root   := 0;
       Tree.Length := 0;
-      --  Tree.Busy
-      --  Tree.Lock
-      Tree.Free := -1;
+      Tree.Free   := -1;
    end Clear_Tree;
 
    ------------------
@@ -76,8 +81,7 @@ package body Ada.Containers.Red_Black_Trees.Generic_Bounded_Operations is
      (Tree : in out Tree_Type'Class;
       Node : Count_Type)
    is
-
-      --  CLR p274
+      --  CLR p. 274
 
       X : Count_Type;
       W : Count_Type;
@@ -143,7 +147,7 @@ package body Ada.Containers.Red_Black_Trees.Generic_Bounded_Operations is
             end if;
 
             if (Left (N (W))  = 0 or else Color (N (Left (N (W)))) = Black)
-                  and then
+                 and then
                (Right (N (W)) = 0 or else Color (N (Right (N (W)))) = Black)
             then
                Set_Color (N (W), Red);
@@ -187,7 +191,7 @@ package body Ada.Containers.Red_Black_Trees.Generic_Bounded_Operations is
      (Tree : in out Tree_Type'Class;
       Node : Count_Type)
    is
-      --  CLR p273
+      --  CLR p273
 
       X, Y : Count_Type;
 
@@ -203,9 +207,9 @@ package body Ada.Containers.Red_Black_Trees.Generic_Bounded_Operations is
       end if;
 
       pragma Assert (Tree.Length > 0);
-      pragma Assert (Tree.Root /= 0);
+      pragma Assert (Tree.Root  /= 0);
       pragma Assert (Tree.First /= 0);
-      pragma Assert (Tree.Last /= 0);
+      pragma Assert (Tree.Last  /= 0);
       pragma Assert (Parent (N (Tree.Root)) = 0);
 
       pragma Assert ((Tree.Length > 1)
@@ -330,12 +334,13 @@ package body Ada.Containers.Red_Black_Trees.Generic_Bounded_Operations is
                   Set_Right (N (Parent (N (Z))), Y);
                end if;
 
-               Set_Left (N (Y), Left (N (Z)));
+               Set_Left   (N (Y), Left (N (Z)));
                Set_Parent (N (Left (N (Y))), Y);
-               Set_Right (N (Y), Z);
+               Set_Right  (N (Y), Z);
+
                Set_Parent (N (Z), Y);
-               Set_Left (N (Z), 0);
-               Set_Right (N (Z), 0);
+               Set_Left   (N (Z), 0);
+               Set_Right  (N (Z), 0);
 
                declare
                   Y_Color : constant Color_Type := Color (N (Y));
@@ -417,13 +422,13 @@ package body Ada.Containers.Red_Black_Trees.Generic_Bounded_Operations is
       pragma Assert (Parent (N (Y)) /= Z);
 
       Y_Parent : constant Count_Type := Parent (N (Y));
-      Y_Color  : constant Color_Type  := Color (N (Y));
+      Y_Color  : constant Color_Type := Color (N (Y));
 
    begin
       Set_Parent (N (Y), Parent (N (Z)));
-      Set_Left (N (Y), Left (N (Z)));
-      Set_Right (N (Y), Right (N (Z)));
-      Set_Color (N (Y), Color (N (Z)));
+      Set_Left   (N (Y), Left   (N (Z)));
+      Set_Right  (N (Y), Right  (N (Z)));
+      Set_Color  (N (Y), Color  (N (Z)));
 
       if Tree.Root = Z then
          Tree.Root := Y;
@@ -443,9 +448,9 @@ package body Ada.Containers.Red_Black_Trees.Generic_Bounded_Operations is
       end if;
 
       Set_Parent (N (Z), Y_Parent);
-      Set_Color (N (Z), Y_Color);
-      Set_Left (N (Z), 0);
-      Set_Right (N (Z), 0);
+      Set_Color  (N (Z), Y_Color);
+      Set_Left   (N (Z), 0);
+      Set_Right  (N (Z), 0);
    end Delete_Swap;
 
    ----------
@@ -526,11 +531,10 @@ package body Ada.Containers.Red_Black_Trees.Generic_Bounded_Operations is
          --  node onto the head of the free store.
 
          --  ???
-         --  See the comments above for an optimization opportunity. If
-         --  the next link for a node on the free store is negative, then
-         --  this means the remaining nodes on the free store are
-         --  physically contiguous, starting as the absolute value of
-         --  that index value.
+         --  See the comments above for an optimization opportunity. If the
+         --  next link for a node on the free store is negative, then this
+         --  means the remaining nodes on the free store are physically
+         --  contiguous, starting as the absolute value of that index value.
 
          Tree.Free := abs Tree.Free;
 
@@ -587,9 +591,14 @@ package body Ada.Containers.Red_Black_Trees.Generic_Bounded_Operations is
          Tree.Free := Tree.Free - 1;
       end if;
 
+      --  When a node is allocated from the free store, its pointer components
+      --  (the links to other nodes in the tree) must also be initialized (to
+      --  0, the equivalent of null). This simplifies the post-allocation
+      --  handling of nodes inserted into terminal positions.
+
       Set_Parent (N (Node), Parent => 0);
-      Set_Left (N (Node), Left => 0);
-      Set_Right (N (Node), Right => 0);
+      Set_Left   (N (Node), Left   => 0);
+      Set_Right  (N (Node), Right  => 0);
    end Generic_Allocate;
 
    -------------------
@@ -687,9 +696,9 @@ package body Ada.Containers.Red_Black_Trees.Generic_Bounded_Operations is
 
       Set_Color (N (Node), Black);
 
-      Tree.Root := Node;
-      Tree.First := Node;
-      Tree.Last := Node;
+      Tree.Root   := Node;
+      Tree.First  := Node;
+      Tree.Last   := Node;
       Tree.Length := 1;
 
       for J in Count_Type range 2 .. Len loop
@@ -747,8 +756,7 @@ package body Ada.Containers.Red_Black_Trees.Generic_Bounded_Operations is
       procedure Process (Node : Count_Type);
       pragma Inline (Process);
 
-      procedure Iterate is
-         new Generic_Iteration (Process);
+      procedure Iterate is new Generic_Iteration (Process);
 
       -------------
       -- Process --
@@ -771,7 +779,7 @@ package body Ada.Containers.Red_Black_Trees.Generic_Bounded_Operations is
    -----------------
 
    procedure Left_Rotate (Tree : in out Tree_Type'Class; X : Count_Type) is
-      --  CLR p266
+      --  CLR p266
 
       N : Nodes_Type renames Tree.Nodes;
 
@@ -796,7 +804,7 @@ package body Ada.Containers.Red_Black_Trees.Generic_Bounded_Operations is
          Set_Right (N (Parent (N (X))), Y);
       end if;
 
-      Set_Left (N (Y), X);
+      Set_Left   (N (Y), X);
       Set_Parent (N (X), Y);
    end Left_Rotate;
 
@@ -808,7 +816,7 @@ package body Ada.Containers.Red_Black_Trees.Generic_Bounded_Operations is
      (Tree : Tree_Type'Class;
       Node : Count_Type) return Count_Type
    is
-      --  CLR p248
+      --  CLR p248
 
       X : Count_Type := Node;
       Y : Count_Type;
@@ -833,7 +841,7 @@ package body Ada.Containers.Red_Black_Trees.Generic_Bounded_Operations is
      (Tree : Tree_Type'Class;
       Node : Count_Type) return Count_Type
    is
-      --  CLR p248
+      --  CLR p248
 
       X : Count_Type := Node;
       Y : Count_Type;
@@ -859,7 +867,7 @@ package body Ada.Containers.Red_Black_Trees.Generic_Bounded_Operations is
       Node : Count_Type) return Count_Type
    is
    begin
-      --  CLR p249
+      --  CLR p249
 
       if Node = 0 then
          return 0;
@@ -926,7 +934,7 @@ package body Ada.Containers.Red_Black_Trees.Generic_Bounded_Operations is
      (Tree : in out Tree_Type'Class;
       Node : Count_Type)
    is
-      --  CLR p.268
+      --  CLR p. 268
 
       N : Nodes_Type renames Tree.Nodes;
 
@@ -1014,7 +1022,7 @@ package body Ada.Containers.Red_Black_Trees.Generic_Bounded_Operations is
          Set_Right (N (Parent (N (Y))), X);
       end if;
 
-      Set_Right (N (X), Y);
+      Set_Right  (N (X), Y);
       Set_Parent (N (Y), X);
    end Right_Rotate;