OSDN Git Service

2011-12-02 Thomas Quinot <quinot@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / a-cofove.adb
index a0fddf9..3533c2a 100644 (file)
@@ -6,11 +6,7 @@
 --                                                                          --
 --                                 B o d y                                  --
 --                                                                          --
---          Copyright (C) 2010, Free Software Foundation, Inc.              --
---                                                                          --
--- This specification is derived from the Ada Reference Manual for use with --
--- GNAT. The copyright notice above, and the license provisions that follow --
--- apply solely to the  contents of the part following the private keyword. --
+--          Copyright (C) 2010-2011, 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- --
@@ -49,29 +45,7 @@ package body Ada.Containers.Formal_Vectors is
       LN : constant Count_Type := Length (Left);
       RN : constant Count_Type := Length (Right);
 
-      RFst : Count_Type;
-      RLst : Count_Type;
-      LFst : Count_Type;
-      LLst : Count_Type;
-
    begin
-
-      if Right.K = Plain then
-         RFst := 1;
-         RLst := RN;
-      else
-         RFst := Right.First;
-         RLst := Right.First + RN - 1;
-      end if;
-
-      if Left.K = Plain then
-         LFst := 1;
-         LLst := LN;
-      else
-         LFst := Left.First;
-         LLst := Left.First + LN - 1;
-      end if;
-
       if LN = 0 then
          if RN = 0 then
             return Empty_Vector;
@@ -79,26 +53,19 @@ package body Ada.Containers.Formal_Vectors is
 
          declare
             E : constant Elements_Array (1 .. Length (Right)) :=
-              Right.Plain.Elements (RFst .. RLst);
+                  Right.Elements (1 .. RN);
          begin
-            return (Length (Right),
-              new Plain_Vector'(Length (Right), E,
-                Last => Right.Plain.Last, others => <>),
-              others => <>);
+            return (Length (Right), E, Last => Right.Last, others => <>);
          end;
       end if;
 
       if RN = 0 then
          declare
             E : constant Elements_Array (1 .. Length (Left)) :=
-              Left.Plain.Elements (LFst .. LLst);
+                  Left.Elements (1 .. LN);
          begin
-            return (Length (Left),
-                    new Plain_Vector'(Length (Left), E,
-                          Last => Left.Plain.Last, others => <>),
-                    others => <>);
+            return (Length (Left), E, Last => Left.Last, others => <>);
          end;
-
       end if;
 
       declare
@@ -121,18 +88,13 @@ package body Ada.Containers.Formal_Vectors is
          declare
             Last : constant Index_Type := Index_Type (Last_As_Int);
 
-            LE : constant Elements_Array (1 .. Length (Left)) :=
-              Left.Plain.Elements (LFst .. LLst);
-
-            RE : Elements_Array renames Right.Plain.Elements (RFst .. RLst);
+            LE : constant Elements_Array (1 .. LN) := Left.Elements (1 .. LN);
+            RE : Elements_Array renames Right.Elements (1 .. RN);
 
             Capacity : constant Count_Type := Length (Left) + Length (Right);
 
          begin
-            return (Capacity,
-                    new Plain_Vector'(Capacity, LE & RE,
-                          Last => Last, others => <>),
-                    others => <>);
+            return (Capacity, LE & RE, Last => Last, others => <>);
          end;
       end;
    end "&";
@@ -140,15 +102,10 @@ package body Ada.Containers.Formal_Vectors is
    function "&" (Left  : Vector; Right : Element_Type) return Vector is
       LN          : constant Count_Type := Length (Left);
       Last_As_Int : Int'Base;
-      LFst        : Count_Type;
-      LLst        : Count_Type;
 
    begin
       if LN = 0 then
-         return (1,
-                 new Plain_Vector'(1, (1 .. 1 => Right),
-                       Index_Type'First, others => <>),
-                 others => <>);
+         return (1, (1 .. 1 => Right), Index_Type'First, others => <>);
       end if;
 
       if Int (Index_Type'First) > Int'Last - Int (LN) then
@@ -161,44 +118,25 @@ package body Ada.Containers.Formal_Vectors is
          raise Constraint_Error with "new length is out of range";
       end if;
 
-      if Left.K = Plain then
-         LFst := 1;
-         LLst := LN;
-      else
-         LFst := Left.First;
-         LLst := Left.First + LN - 1;
-      end if;
-
       declare
          Last : constant Index_Type := Index_Type (Last_As_Int);
-
-         LE : constant Elements_Array (1 .. LN) :=
-           Left.Plain.Elements (LFst .. LLst);
+         LE   : constant Elements_Array (1 .. LN) := Left.Elements (1 .. LN);
 
          Capacity : constant Count_Type := Length (Left) + 1;
 
       begin
-         return (Capacity,
-                 new Plain_Vector'(Capacity, LE & Right,
-                       Last => Last, others => <>),
-                 others => <>);
+         return (Capacity, LE & Right, Last => Last, others => <>);
       end;
-
    end "&";
 
    function "&" (Left  : Element_Type; Right : Vector) return Vector is
       RN          : constant Count_Type := Length (Right);
       Last_As_Int : Int'Base;
 
-      RFst : Count_Type;
-      RLst : Count_Type;
-
    begin
       if RN = 0 then
-         return (1,
-                 new Plain_Vector'(1, (1 .. 1 => Left),
-                       Index_Type'First, others => <>),
-                 others => <>);
+         return (1, (1 .. 1 => Left),
+                 Index_Type'First, others => <>);
       end if;
 
       if Int (Index_Type'First) > Int'Last - Int (RN) then
@@ -211,26 +149,12 @@ package body Ada.Containers.Formal_Vectors is
          raise Constraint_Error with "new length is out of range";
       end if;
 
-      if Right.K = Plain then
-         RFst := 1;
-         RLst := RN;
-      else
-         RFst := Right.First;
-         RLst := Right.First + RN - 1;
-      end if;
-
       declare
-         Last : constant Index_Type := Index_Type (Last_As_Int);
-
-         RE : Elements_Array renames Right.Plain.Elements (RFst .. RLst);
-
+         Last     : constant Index_Type := Index_Type (Last_As_Int);
+         RE       : Elements_Array renames Right.Elements (1 .. RN);
          Capacity : constant Count_Type := 1 + Length (Right);
-
       begin
-         return (Capacity,
-                 new Plain_Vector'(Capacity, Left & RE,
-                       Last => Last, others => <>),
-                 others => <>);
+         return (Capacity, Left & RE, Last => Last, others => <>);
       end;
    end "&";
 
@@ -242,12 +166,8 @@ package body Ada.Containers.Formal_Vectors is
 
       declare
          Last : constant Index_Type := Index_Type'First + 1;
-
       begin
-         return (2,
-                 new Plain_Vector'(2, (Left, Right),
-                       Last => Last, others => <>),
-                 others => <>);
+         return (2, (Left, Right), Last => Last, others => <>);
       end;
    end "&";
 
@@ -280,24 +200,15 @@ package body Ada.Containers.Formal_Vectors is
 
    procedure Append (Container : in out Vector; New_Item : Vector) is
    begin
-
-      if Container.K /= Plain then
-         raise Constraint_Error
-           with "Can't modify part of container";
-      end if;
-
       if Is_Empty (New_Item) then
          return;
       end if;
 
-      if Container.Plain.Last = Index_Type'Last then
+      if Container.Last = Index_Type'Last then
          raise Constraint_Error with "vector is already at its maximum length";
       end if;
 
-      Insert
-        (Container,
-         Container.Plain.Last + 1,
-         New_Item);
+      Insert (Container, Container.Last + 1, New_Item);
    end Append;
 
    procedure Append
@@ -306,27 +217,17 @@ package body Ada.Containers.Formal_Vectors is
       Count     : Count_Type := 1)
    is
    begin
-
-      if Container.K /= Plain then
-         raise Constraint_Error
-           with "Can't modify part of container";
-      end if;
-
       if Count = 0 then
          return;
       end if;
 
-      if Container.Plain.Last = Index_Type'Last then
+      if Container.Last = Index_Type'Last then
          raise Constraint_Error with "vector is already at its maximum length";
       end if;
 
       --  TODO: should check whether length > max capacity (cnt_t'last)  ???
 
-      Insert
-        (Container,
-         Container.Plain.Last + 1,
-         New_Item,
-         Count);
+      Insert (Container, Container.Last + 1, New_Item, Count);
    end Append;
 
    ------------
@@ -335,13 +236,8 @@ package body Ada.Containers.Formal_Vectors is
 
    procedure Assign (Target : in out Vector; Source : Vector) is
       LS : constant Count_Type := Length (Source);
-   begin
-
-      if Target.K /= Plain then
-         raise Constraint_Error
-           with "Can't modify part of container";
-      end if;
 
+   begin
       if Target'Address = Source'Address then
          return;
       end if;
@@ -352,16 +248,8 @@ package body Ada.Containers.Formal_Vectors is
 
       Target.Clear;
 
-      if Source.K = Plain then
-         Target.Plain.Elements (1 .. LS) :=
-           Source.Plain.Elements (1 .. LS);
-         Target.Plain.Last := Source.Plain.Last;
-      else
-         Target.Plain.Elements (1 .. LS) :=
-           Source.Plain.Elements (Source.First .. (Source.First + LS - 1));
-         Target.Plain.Last := Source.Last;
-      end if;
-
+      Target.Elements (1 .. LS) := Source.Elements (1 .. LS);
+      Target.Last := Source.Last;
    end Assign;
 
    --------------
@@ -370,7 +258,7 @@ package body Ada.Containers.Formal_Vectors is
 
    function Capacity (Container : Vector) return Capacity_Subtype is
    begin
-      return Container.Plain.Elements'Length;
+      return Container.Elements'Length;
    end Capacity;
 
    -----------
@@ -379,18 +267,12 @@ package body Ada.Containers.Formal_Vectors is
 
    procedure Clear (Container : in out Vector) is
    begin
-
-      if Container.K /= Plain then
-         raise Constraint_Error
-           with "Can't modify part of container";
-      end if;
-
-      if Container.Plain.Busy > 0 then
+      if Container.Busy > 0 then
          raise Program_Error with
            "attempt to tamper with elements (vector is busy)";
       end if;
 
-      Container.Plain.Last := No_Index;
+      Container.Last := No_Index;
    end Clear;
 
    --------------
@@ -419,25 +301,15 @@ package body Ada.Containers.Formal_Vectors is
    begin
       if Capacity = 0 then
          C := LS;
-
       elsif Capacity >= LS then
          C := Capacity;
-
       else
          raise Constraint_Error;
       end if;
 
-      return Target                   : Vector (C) do
-         if Source.K = Plain then
-            Target.Plain.Elements (1 .. LS) :=
-              Source.Plain.Elements (1 .. LS);
-            Target.Plain.Last := Source.Plain.Last;
-         else
-            Target.Plain.Elements (1 .. LS) :=
-              Source.Plain.Elements (Source.First .. (Source.First + LS - 1));
-            Target.Plain.Last := Source.Last;
-         end if;
-
+      return Target : Vector (C) do
+         Target.Elements (1 .. LS) := Source.Elements (1 .. LS);
+         Target.Last := Source.Last;
       end return;
    end Copy;
 
@@ -451,18 +323,12 @@ package body Ada.Containers.Formal_Vectors is
       Count     : Count_Type := 1)
    is
    begin
-
-      if Container.K /= Plain then
-         raise Constraint_Error
-           with "Can't modify part of container";
-      end if;
-
       if Index < Index_Type'First then
          raise Constraint_Error with "Index is out of range (too small)";
       end if;
 
-      if Index > Container.Plain.Last then
-         if Index > Container.Plain.Last + 1 then
+      if Index > Container.Last then
+         if Index > Container.Last + 1 then
             raise Constraint_Error with "Index is out of range (too large)";
          end if;
 
@@ -473,15 +339,14 @@ package body Ada.Containers.Formal_Vectors is
          return;
       end if;
 
-      if Container.Plain.Busy > 0 then
+      if Container.Busy > 0 then
          raise Program_Error with
            "attempt to tamper with elements (vector is busy)";
       end if;
 
       declare
          I_As_Int        : constant Int := Int (Index);
-         Old_Last_As_Int : constant Int :=
-                             Index_Type'Pos (Container.Plain.Last);
+         Old_Last_As_Int : constant Int := Index_Type'Pos (Container.Last);
 
          Count1 : constant Int'Base := Count_Type'Pos (Count);
          Count2 : constant Int'Base := Old_Last_As_Int - I_As_Int + 1;
@@ -491,11 +356,11 @@ package body Ada.Containers.Formal_Vectors is
 
       begin
          if J_As_Int > Old_Last_As_Int then
-            Container.Plain.Last := Index - 1;
+            Container.Last := Index - 1;
 
          else
             declare
-               EA : Elements_Array renames Container.Plain.Elements;
+               EA : Elements_Array renames Container.Elements;
 
                II : constant Int'Base := I_As_Int - Int (No_Index);
                I  : constant Count_Type := Count_Type (II);
@@ -512,7 +377,7 @@ package body Ada.Containers.Formal_Vectors is
 
             begin
                EA (I .. K) := EA (J .. Length (Container));
-               Container.Plain.Last := New_Last;
+               Container.Last := New_Last;
             end;
          end if;
       end;
@@ -524,17 +389,11 @@ package body Ada.Containers.Formal_Vectors is
       Count     : Count_Type := 1)
    is
    begin
-
-      if Container.K /= Plain then
-         raise Constraint_Error
-           with "Can't modify part of container";
-      end if;
-
       if not Position.Valid then
          raise Constraint_Error with "Position cursor has no element";
       end if;
 
-      if Position.Index > Container.Plain.Last then
+      if Position.Index > Container.Last then
          raise Program_Error with "Position index is out of range";
       end if;
 
@@ -551,12 +410,6 @@ package body Ada.Containers.Formal_Vectors is
       Count     : Count_Type := 1)
    is
    begin
-
-      if Container.K /= Plain then
-         raise Constraint_Error
-           with "Can't modify part of container";
-      end if;
-
       if Count = 0 then
          return;
       end if;
@@ -580,27 +433,21 @@ package body Ada.Containers.Formal_Vectors is
       Index : Int'Base;
 
    begin
-
-      if Container.K /= Plain then
-         raise Constraint_Error
-           with "Can't modify part of container";
-      end if;
-
       if Count = 0 then
          return;
       end if;
 
-      if Container.Plain.Busy > 0 then
+      if Container.Busy > 0 then
          raise Program_Error with
            "attempt to tamper with elements (vector is busy)";
       end if;
 
-      Index := Int'Base (Container.Plain.Last) - Int'Base (Count);
+      Index := Int'Base (Container.Last) - Int'Base (Count);
 
       if Index < Index_Type'Pos (Index_Type'First) then
-         Container.Plain.Last := No_Index;
+         Container.Last := No_Index;
       else
-         Container.Plain.Last := Index_Type (Index);
+         Container.Last := Index_Type (Index);
       end if;
    end Delete_Last;
 
@@ -613,21 +460,14 @@ package body Ada.Containers.Formal_Vectors is
       Index     : Index_Type) return Element_Type
    is
    begin
-      if Index > Container.Plain.Last then
+      if Index > Container.Last then
          raise Constraint_Error with "Index is out of range";
       end if;
 
       declare
          II : constant Int'Base := Int (Index) - Int (No_Index);
          I  : constant Count_Type := Count_Type (II);
-
       begin
-
-         if Container.K = Part and then
-           (I > Length (Container)) then
-            raise Constraint_Error with "Index is out of range";
-         end if;
-
          return Get_Element (Container, I);
       end;
    end Element;
@@ -637,6 +477,7 @@ package body Ada.Containers.Formal_Vectors is
       Position  : Cursor) return Element_Type
    is
       Lst : constant Index_Type := Last_Index (Container);
+
    begin
       if not Position.Valid then
          raise Constraint_Error with "Position cursor has no element";
@@ -649,9 +490,7 @@ package body Ada.Containers.Formal_Vectors is
       declare
          II : constant Int'Base := Int (Position.Index) - Int (No_Index);
          I  : constant Count_Type := Count_Type (II);
-
       begin
-
          return Get_Element (Container, I);
       end;
    end Element;
@@ -669,7 +508,6 @@ package body Ada.Containers.Formal_Vectors is
       Last : constant Index_Type := Last_Index (Container);
 
    begin
-
       if Position.Valid then
          if Position.Index > Last_Index (Container) then
             raise Program_Error with "Position index is out of range";
@@ -682,11 +520,11 @@ package body Ada.Containers.Formal_Vectors is
          if Get_Element (Container, K) = Item then
             return Cursor'(Index => J, others => <>);
          end if;
+
          K := K + 1;
       end loop;
 
       return No_Element;
-
    end Find;
 
    ----------------
@@ -708,6 +546,7 @@ package body Ada.Containers.Formal_Vectors is
          if Get_Element (Container, K) = Item then
             return Indx;
          end if;
+
          K := K + 1;
       end loop;
 
@@ -762,19 +601,19 @@ package body Ada.Containers.Formal_Vectors is
 
       function Is_Sorted (Container : Vector) return Boolean is
          Last : constant Index_Type := Last_Index (Container);
-      begin
 
-         if Container.Plain.Last <= Last then
+      begin
+         if Container.Last <= Last then
             return True;
          end if;
 
          declare
             L : constant Capacity_Subtype := Length (Container);
          begin
-
             for J in Count_Type range 1 .. L - 1 loop
-               if Get_Element (Container, J + 1)
-                 < Get_Element (Container, J) then
+               if Get_Element (Container, J + 1) <
+                  Get_Element (Container, J)
+               then
                   return False;
                end if;
             end loop;
@@ -790,14 +629,9 @@ package body Ada.Containers.Formal_Vectors is
       procedure Merge (Target, Source : in out Vector) is
       begin
 
-         if Target.K /= Plain or Source.K /= Plain then
-            raise Constraint_Error
-              with "Can't modify part of container";
-         end if;
-
          declare
-            TA : Elements_Array renames Target.Plain.Elements;
-            SA : Elements_Array renames Source.Plain.Elements;
+            TA : Elements_Array renames Target.Elements;
+            SA : Elements_Array renames Source.Elements;
 
             I, J : Count_Type;
 
@@ -812,17 +646,18 @@ package body Ada.Containers.Formal_Vectors is
                return;
             end if;
 
-            if Source.Plain.Last < Index_Type'First then
+            if Source.Last < Index_Type'First then
                return;
             end if;
 
             --  I think we're missing this check in a-convec.adb...  ???
-            if Target.Plain.Busy > 0 then
+
+            if Target.Busy > 0 then
                raise Program_Error with
                  "attempt to tamper with elements (vector is busy)";
             end if;
 
-            if Source.Plain.Busy > 0 then
+            if Source.Busy > 0 then
                raise Program_Error with
                  "attempt to tamper with elements (vector is busy)";
             end if;
@@ -838,12 +673,11 @@ package body Ada.Containers.Formal_Vectors is
 
                if I = 0 then
                   TA (1 .. J) := SA (1 .. Length (Source));
-                  Source.Plain.Last := No_Index;
+                  Source.Last := No_Index;
                   return;
                end if;
 
-               pragma Assert (I <= 1
-                              or else not (TA (I) < TA (I - 1)));
+               pragma Assert (I <= 1 or else not (TA (I) < TA (I - 1)));
 
                if SA (Length (Source)) < TA (I) then
                   TA (J) := TA (I);
@@ -851,7 +685,7 @@ package body Ada.Containers.Formal_Vectors is
 
                else
                   TA (J) := SA (Length (Source));
-                  Source.Plain.Last := Source.Plain.Last - 1;
+                  Source.Last := Source.Last - 1;
                end if;
 
                J := J - 1;
@@ -873,22 +707,16 @@ package body Ada.Containers.Formal_Vectors is
               "<"          => "<");
 
       begin
-
-         if Container.K /= Plain then
-            raise Constraint_Error
-              with "Can't modify part of container";
-         end if;
-
-         if Container.Plain.Last <= Index_Type'First then
+         if Container.Last <= Index_Type'First then
             return;
          end if;
 
-         if Container.Plain.Lock > 0 then
+         if Container.Lock > 0 then
             raise Program_Error with
               "attempt to tamper with cursors (vector is locked)";
          end if;
 
-         Sort (Container.Plain.Elements (1 .. Length (Container)));
+         Sort (Container.Elements (1 .. Length (Container)));
       end Sort;
 
    end Generic_Sorting;
@@ -899,13 +727,10 @@ package body Ada.Containers.Formal_Vectors is
 
    function Get_Element
      (Container : Vector;
-      Position  : Count_Type) return Element_Type is
+      Position  : Count_Type) return Element_Type
+   is
    begin
-      if Container.K = Plain then
-         return Container.Plain.Elements (Position);
-      end if;
-
-      return Container.Plain.Elements (Position + Container.First - 1);
+      return Container.Elements (Position);
    end Get_Element;
 
    -----------------
@@ -914,13 +739,14 @@ package body Ada.Containers.Formal_Vectors is
 
    function Has_Element
      (Container : Vector;
-      Position  : Cursor) return Boolean is
+      Position  : Cursor) return Boolean
+   is
    begin
       if not Position.Valid then
          return False;
+      else
+         return Position.Index <= Last_Index (Container);
       end if;
-
-      return Position.Index <= Last_Index (Container);
    end Has_Element;
 
    ------------
@@ -942,19 +768,13 @@ package body Ada.Containers.Formal_Vectors is
       Max_Length      : constant UInt := UInt (Container.Capacity);
 
    begin
-
-      if Container.K /= Plain then
-         raise Constraint_Error
-           with "Can't modify part of container";
-      end if;
-
       if Before < Index_Type'First then
          raise Constraint_Error with
            "Before index is out of range (too small)";
       end if;
 
-      if Before > Container.Plain.Last
-        and then Before > Container.Plain.Last + 1
+      if Before > Container.Last
+        and then Before > Container.Last + 1
       then
          raise Constraint_Error with
            "Before index is out of range (too large)";
@@ -965,7 +785,7 @@ package body Ada.Containers.Formal_Vectors is
       end if;
 
       declare
-         Old_Last_As_Int : constant Int := Int (Container.Plain.Last);
+         Old_Last_As_Int : constant Int := Int (Container.Last);
 
       begin
          if Old_Last_As_Int > Int'Last - N then
@@ -989,13 +809,13 @@ package body Ada.Containers.Formal_Vectors is
          --  Resolve issue of capacity vs. max index  ???
       end;
 
-      if Container.Plain.Busy > 0 then
+      if Container.Busy > 0 then
          raise Program_Error with
            "attempt to tamper with elements (vector is busy)";
       end if;
 
       declare
-         EA : Elements_Array renames Container.Plain.Elements;
+         EA : Elements_Array renames Container.Elements;
 
          BB : constant Int'Base := Int (Before) - Int (No_Index);
          B  : constant Count_Type := Count_Type (BB);
@@ -1004,11 +824,10 @@ package body Ada.Containers.Formal_Vectors is
          L  : constant Count_Type := Count_Type (LL);
 
       begin
-         if Before <= Container.Plain.Last then
+         if Before <= Container.Last then
             declare
                II : constant Int'Base := BB + N;
                I  : constant Count_Type := Count_Type (II);
-
             begin
                EA (I .. L) := EA (B .. Length (Container));
                EA (B .. I - 1) := (others => New_Item);
@@ -1019,7 +838,7 @@ package body Ada.Containers.Formal_Vectors is
          end if;
       end;
 
-      Container.Plain.Last := New_Last;
+      Container.Last := New_Last;
    end Insert;
 
    procedure Insert
@@ -1030,19 +849,13 @@ package body Ada.Containers.Formal_Vectors is
       N : constant Count_Type := Length (New_Item);
 
    begin
-
-      if Container.K /= Plain then
-         raise Constraint_Error
-           with "Can't modify part of container";
-      end if;
-
       if Before < Index_Type'First then
          raise Constraint_Error with
            "Before index is out of range (too small)";
       end if;
 
-      if Before > Container.Plain.Last
-        and then Before > Container.Plain.Last + 1
+      if Before > Container.Last
+        and then Before > Container.Last + 1
       then
          raise Constraint_Error with
            "Before index is out of range (too large)";
@@ -1060,37 +873,23 @@ package body Ada.Containers.Formal_Vectors is
 
          Dst_Last : constant Count_Type := Count_Type (Dst_Last_As_Int);
 
-         Src_Fst : Count_Type;
-         Src_Lst : Count_Type;
-
          BB : constant Int'Base := Int (Before) - Int (No_Index);
          B  : constant Count_Type := Count_Type (BB);
 
       begin
-
-         if Container.K = Plain then
-            Src_Fst := 1;
-            Src_Lst := N;
-         else
-            Src_Fst := New_Item.First;
-            Src_Lst := N + New_Item.First - 1;
-         end if;
-
          if Container'Address /= New_Item'Address then
-            Container.Plain.Elements (B .. Dst_Last) :=
-              New_Item.Plain.Elements (Src_Fst .. Src_Lst);
-
+            Container.Elements (B .. Dst_Last) := New_Item.Elements (1 .. N);
             return;
          end if;
 
          declare
-            Src : Elements_Array renames Container.Plain.Elements (1 .. B - 1);
+            Src : Elements_Array renames Container.Elements (1 .. B - 1);
 
             Index_As_Int : constant Int'Base := BB + Src'Length - 1;
 
             Index : constant Count_Type := Count_Type (Index_As_Int);
 
-            Dst : Elements_Array renames Container.Plain.Elements (B .. Index);
+            Dst : Elements_Array renames Container.Elements (B .. Index);
 
          begin
             Dst := Src;
@@ -1102,8 +901,7 @@ package body Ada.Containers.Formal_Vectors is
 
          declare
             Src : Elements_Array renames
-                    Container.Plain.Elements
-                      (Dst_Last + 1 .. Length (Container));
+                    Container.Elements (Dst_Last + 1 .. Length (Container));
 
             Index_As_Int : constant Int'Base :=
                              Dst_Last_As_Int - Src'Length + 1;
@@ -1111,7 +909,7 @@ package body Ada.Containers.Formal_Vectors is
             Index : constant Count_Type := Count_Type (Index_As_Int);
 
             Dst : Elements_Array renames
-                    Container.Plain.Elements (Index .. Dst_Last);
+                    Container.Elements (Index .. Dst_Last);
 
          begin
             Dst := Src;
@@ -1127,25 +925,19 @@ package body Ada.Containers.Formal_Vectors is
       Index : Index_Type'Base;
 
    begin
-
-      if Container.K /= Plain then
-         raise Constraint_Error
-           with "Can't modify part of container";
-      end if;
-
       if Is_Empty (New_Item) then
          return;
       end if;
 
       if not Before.Valid
-        or else Before.Index > Container.Plain.Last
+        or else Before.Index > Container.Last
       then
-         if Container.Plain.Last = Index_Type'Last then
+         if Container.Last = Index_Type'Last then
             raise Constraint_Error with
               "vector is already at its maximum length";
          end if;
 
-         Index := Container.Plain.Last + 1;
+         Index := Container.Last + 1;
 
       else
          Index := Before.Index;
@@ -1163,15 +955,9 @@ package body Ada.Containers.Formal_Vectors is
       Index : Index_Type'Base;
 
    begin
-
-      if Container.K /= Plain then
-         raise Constraint_Error
-           with "Can't modify part of container";
-      end if;
-
       if Is_Empty (New_Item) then
          if not Before.Valid
-           or else Before.Index > Container.Plain.Last
+           or else Before.Index > Container.Last
          then
             Position := No_Element;
          else
@@ -1182,14 +968,14 @@ package body Ada.Containers.Formal_Vectors is
       end if;
 
       if not Before.Valid
-        or else Before.Index > Container.Plain.Last
+        or else Before.Index > Container.Last
       then
-         if Container.Plain.Last = Index_Type'Last then
+         if Container.Last = Index_Type'Last then
             raise Constraint_Error with
               "vector is already at its maximum length";
          end if;
 
-         Index := Container.Plain.Last + 1;
+         Index := Container.Last + 1;
 
       else
          Index := Before.Index;
@@ -1209,25 +995,19 @@ package body Ada.Containers.Formal_Vectors is
       Index : Index_Type'Base;
 
    begin
-
-      if Container.K /= Plain then
-         raise Constraint_Error
-           with "Can't modify part of container";
-      end if;
-
       if Count = 0 then
          return;
       end if;
 
       if not Before.Valid
-        or else Before.Index > Container.Plain.Last
+        or else Before.Index > Container.Last
       then
-         if Container.Plain.Last = Index_Type'Last then
+         if Container.Last = Index_Type'Last then
             raise Constraint_Error with
               "vector is already at its maximum length";
          end if;
 
-         Index := Container.Plain.Last + 1;
+         Index := Container.Last + 1;
 
       else
          Index := Before.Index;
@@ -1246,15 +1026,9 @@ package body Ada.Containers.Formal_Vectors is
       Index : Index_Type'Base;
 
    begin
-
-      if Container.K /= Plain then
-         raise Constraint_Error
-           with "Can't modify part of container";
-      end if;
-
       if Count = 0 then
          if not Before.Valid
-           or else Before.Index > Container.Plain.Last
+           or else Before.Index > Container.Last
          then
             Position := No_Element;
          else
@@ -1265,14 +1039,14 @@ package body Ada.Containers.Formal_Vectors is
       end if;
 
       if not Before.Valid
-        or else Before.Index > Container.Plain.Last
+        or else Before.Index > Container.Last
       then
-         if Container.Plain.Last = Index_Type'Last then
+         if Container.Last = Index_Type'Last then
             raise Constraint_Error with
               "vector is already at its maximum length";
          end if;
 
-         Index := Container.Plain.Last + 1;
+         Index := Container.Last + 1;
 
       else
          Index := Before.Index;
@@ -1303,7 +1077,6 @@ package body Ada.Containers.Formal_Vectors is
    is
       New_Item : Element_Type;  -- Default-initialized value
       pragma Warnings (Off, New_Item);
-
    begin
       Insert (Container, Before, New_Item, Position, Count);
    end Insert;
@@ -1326,19 +1099,13 @@ package body Ada.Containers.Formal_Vectors is
       Max_Length      : constant UInt := UInt (Count_Type'Last);
 
    begin
-
-      if Container.K /= Plain then
-         raise Constraint_Error
-           with "Can't modify part of container";
-      end if;
-
       if Before < Index_Type'First then
          raise Constraint_Error with
            "Before index is out of range (too small)";
       end if;
 
-      if Before > Container.Plain.Last
-        and then Before > Container.Plain.Last + 1
+      if Before > Container.Last
+        and then Before > Container.Last + 1
       then
          raise Constraint_Error with
            "Before index is out of range (too large)";
@@ -1349,7 +1116,7 @@ package body Ada.Containers.Formal_Vectors is
       end if;
 
       declare
-         Old_Last_As_Int : constant Int := Int (Container.Plain.Last);
+         Old_Last_As_Int : constant Int := Int (Container.Last);
 
       begin
          if Old_Last_As_Int > Int'Last - N then
@@ -1373,13 +1140,13 @@ package body Ada.Containers.Formal_Vectors is
          --  Resolve issue of capacity vs. max index  ???
       end;
 
-      if Container.Plain.Busy > 0 then
+      if Container.Busy > 0 then
          raise Program_Error with
            "attempt to tamper with elements (vector is busy)";
       end if;
 
       declare
-         EA : Elements_Array renames Container.Plain.Elements;
+         EA : Elements_Array renames Container.Elements;
 
          BB : constant Int'Base := Int (Before) - Int (No_Index);
          B  : constant Count_Type := Count_Type (BB);
@@ -1388,18 +1155,17 @@ package body Ada.Containers.Formal_Vectors is
          L  : constant Count_Type := Count_Type (LL);
 
       begin
-         if Before <= Container.Plain.Last then
+         if Before <= Container.Last then
             declare
                II : constant Int'Base := BB + N;
                I  : constant Count_Type := Count_Type (II);
-
             begin
                EA (I .. L) := EA (B .. Length (Container));
             end;
          end if;
       end;
 
-      Container.Plain.Last := New_Last;
+      Container.Last := New_Last;
    end Insert_Space;
 
    procedure Insert_Space
@@ -1411,15 +1177,9 @@ package body Ada.Containers.Formal_Vectors is
       Index : Index_Type'Base;
 
    begin
-
-      if Container.K /= Plain then
-         raise Constraint_Error
-           with "Can't modify part of container";
-      end if;
-
       if Count = 0 then
          if not Before.Valid
-           or else Before.Index > Container.Plain.Last
+           or else Before.Index > Container.Last
          then
             Position := No_Element;
          else
@@ -1430,14 +1190,14 @@ package body Ada.Containers.Formal_Vectors is
       end if;
 
       if not Before.Valid
-        or else Before.Index > Container.Plain.Last
+        or else Before.Index > Container.Last
       then
-         if Container.Plain.Last = Index_Type'Last then
+         if Container.Last = Index_Type'Last then
             raise Constraint_Error with
               "vector is already at its maximum length";
          end if;
 
-         Index := Container.Plain.Last + 1;
+         Index := Container.Last + 1;
 
       else
          Index := Before.Index;
@@ -1467,7 +1227,7 @@ package body Ada.Containers.Formal_Vectors is
         not null access procedure (Container : Vector; Position : Cursor))
    is
       V : Vector renames Container'Unrestricted_Access.all;
-      B : Natural renames V.Plain.Busy;
+      B : Natural renames V.Busy;
 
    begin
       B := B + 1;
@@ -1517,11 +1277,7 @@ package body Ada.Containers.Formal_Vectors is
 
    function Last_Index (Container : Vector) return Extended_Index is
    begin
-      if Container.K = Plain then
-         return Container.Plain.Last;
-      else
-         return Container.Last;
-      end if;
+      return Container.Last;
    end Last_Index;
 
    ------------
@@ -1542,26 +1298,21 @@ package body Ada.Containers.Formal_Vectors is
    ----------
 
    function Left (Container : Vector; Position : Cursor) return Vector is
-      Fst : Count_Type;
-   begin
-      if Container.K = Plain then
-         Fst := 1;
-      else
-         Fst := Container.First;
-      end if;
+      C : Vector (Container.Capacity) := Copy (Container, Container.Capacity);
 
-      if not Position.Valid then
-         return (Container.Capacity, Container.Plain, Part, Fst,
-                 Last_Index (Container));
+   begin
+      if Position = No_Element then
+         return C;
       end if;
 
-      if Position.Index > Last_Index (Container) then
-         raise Constraint_Error with
-           "Before index is out of range (too large)";
+      if not Has_Element (Container, Position) then
+         raise Constraint_Error;
       end if;
 
-      return (Container.Capacity, Container.Plain, Part, Fst,
-              (Position.Index - 1));
+      while C.Last /= Position.Index - 1 loop
+         Delete_Last (C);
+      end loop;
+      return C;
    end Left;
 
    ----------
@@ -1576,21 +1327,16 @@ package body Ada.Containers.Formal_Vectors is
 
    begin
 
-      if Target.K /= Plain or Source.K /= Plain then
-         raise Constraint_Error
-           with "Can't modify part of container";
-      end if;
-
       if Target'Address = Source'Address then
          return;
       end if;
 
-      if Target.Plain.Busy > 0 then
+      if Target.Busy > 0 then
          raise Program_Error with
            "attempt to tamper with elements (Target is busy)";
       end if;
 
-      if Source.Plain.Busy > 0 then
+      if Source.Busy > 0 then
          raise Program_Error with
            "attempt to tamper with elements (Source is busy)";
       end if;
@@ -1603,11 +1349,11 @@ package body Ada.Containers.Formal_Vectors is
       --  We could also write this as a loop, and incrementally
       --  copy elements from source to target.
 
-      Target.Plain.Last := No_Index;  -- in case array assignment files
-      Target.Plain.Elements (1 .. N) := Source.Plain.Elements (1 .. N);
+      Target.Last := No_Index;  -- in case array assignment files
+      Target.Elements (1 .. N) := Source.Elements (1 .. N);
 
-      Target.Plain.Last := Source.Plain.Last;
-      Source.Plain.Last := No_Index;
+      Target.Last := Source.Last;
+      Source.Last := No_Index;
    end Move;
 
    ----------
@@ -1707,8 +1453,8 @@ package body Ada.Containers.Formal_Vectors is
       Process   : not null access procedure (Element : Element_Type))
    is
       V : Vector renames Container'Unrestricted_Access.all;
-      B : Natural renames V.Plain.Busy;
-      L : Natural renames V.Plain.Lock;
+      B : Natural renames V.Busy;
+      L : Natural renames V.Lock;
 
    begin
       if Index > Last_Index (Container) then
@@ -1774,8 +1520,8 @@ package body Ada.Containers.Formal_Vectors is
 
       for J in Count_Type range 1 .. Length loop
          Last := Last + 1;
-         Element_Type'Read (Stream, Container.Plain.Elements (J));
-         Container.Plain.Last := Last;
+         Element_Type'Read (Stream, Container.Elements (J));
+         Container.Last := Last;
       end loop;
    end Read;
 
@@ -1797,16 +1543,12 @@ package body Ada.Containers.Formal_Vectors is
       New_Item  : Element_Type)
    is
    begin
-      if Container.K /= Plain then
-         raise Constraint_Error
-           with "Can't modify part of container";
-      end if;
 
-      if Index > Container.Plain.Last then
+      if Index > Container.Last then
          raise Constraint_Error with "Index is out of range";
       end if;
 
-      if Container.Plain.Lock > 0 then
+      if Container.Lock > 0 then
          raise Program_Error with
            "attempt to tamper with cursors (vector is locked)";
       end if;
@@ -1816,7 +1558,7 @@ package body Ada.Containers.Formal_Vectors is
          I  : constant Count_Type := Count_Type (II);
 
       begin
-         Container.Plain.Elements (I) := New_Item;
+         Container.Elements (I) := New_Item;
       end;
    end Replace_Element;
 
@@ -1826,20 +1568,16 @@ package body Ada.Containers.Formal_Vectors is
       New_Item  : Element_Type)
    is
    begin
-      if Container.K /= Plain then
-         raise Constraint_Error
-           with "Can't modify part of container";
-      end if;
 
       if not Position.Valid then
          raise Constraint_Error with "Position cursor has no element";
       end if;
 
-      if Position.Index > Container.Plain.Last then
+      if Position.Index > Container.Last then
          raise Constraint_Error with "Position cursor is out of range";
       end if;
 
-      if Container.Plain.Lock > 0 then
+      if Container.Lock > 0 then
          raise Program_Error with
            "attempt to tamper with cursors (vector is locked)";
       end if;
@@ -1847,9 +1585,8 @@ package body Ada.Containers.Formal_Vectors is
       declare
          II : constant Int'Base := Int (Position.Index) - Int (No_Index);
          I  : constant Count_Type := Count_Type (II);
-
       begin
-         Container.Plain.Elements (I) := New_Item;
+         Container.Elements (I) := New_Item;
       end;
    end Replace_Element;
 
@@ -1862,11 +1599,6 @@ package body Ada.Containers.Formal_Vectors is
       Capacity  : Capacity_Subtype)
    is
    begin
-      if Container.K /= Plain then
-         raise Constraint_Error
-           with "Can't modify part of container";
-      end if;
-
       if Capacity > Container.Capacity then
          raise Constraint_Error;  -- ???
       end if;
@@ -1878,23 +1610,18 @@ package body Ada.Containers.Formal_Vectors is
 
    procedure Reverse_Elements (Container : in out Vector) is
    begin
-      if Container.K /= Plain then
-         raise Constraint_Error
-           with "Can't modify part of container";
-      end if;
-
       if Length (Container) <= 1 then
          return;
       end if;
 
-      if Container.Plain.Lock > 0 then
+      if Container.Lock > 0 then
          raise Program_Error with
            "attempt to tamper with cursors (vector is locked)";
       end if;
 
       declare
          I, J : Count_Type;
-         E    : Elements_Array renames Container.Plain.Elements;
+         E    : Elements_Array renames Container.Elements;
 
       begin
          I := 1;
@@ -1902,7 +1629,6 @@ package body Ada.Containers.Formal_Vectors is
          while I < J loop
             declare
                EI : constant Element_Type := E (I);
-
             begin
                E (I) := E (J);
                E (J) := EI;
@@ -1927,7 +1653,6 @@ package body Ada.Containers.Formal_Vectors is
       K    : Count_Type;
 
    begin
-
       if not Position.Valid
         or else Position.Index > Last_Index (Container)
       then
@@ -1941,6 +1666,7 @@ package body Ada.Containers.Formal_Vectors is
          if Get_Element (Container, K) = Item then
             return (True, Indx);
          end if;
+
          K := K - 1;
       end loop;
 
@@ -1971,6 +1697,7 @@ package body Ada.Containers.Formal_Vectors is
          if Get_Element (Container, K) = Item then
             return Indx;
          end if;
+
          K := K - 1;
       end loop;
 
@@ -1983,11 +1710,11 @@ package body Ada.Containers.Formal_Vectors is
 
    procedure Reverse_Iterate
      (Container : Vector;
-      Process   :
-        not null access procedure (Container : Vector; Position : Cursor))
+      Process   : not null access procedure (Container : Vector;
+                                             Position : Cursor))
    is
       V : Vector renames Container'Unrestricted_Access.all;
-      B : Natural renames V.Plain.Busy;
+      B : Natural renames V.Busy;
 
    begin
       B := B + 1;
@@ -2010,27 +1737,23 @@ package body Ada.Containers.Formal_Vectors is
    -----------
 
    function Right (Container : Vector; Position : Cursor) return Vector is
-      Fst : Count_Type;
-   begin
-      if Container.K = Plain then
-         Fst := 1;
-      else
-         Fst := Container.First;
-      end if;
+      C : Vector (Container.Capacity) := Copy (Container, Container.Capacity);
 
-      if not Position.Valid then
-         return (Container.Capacity, Container.Plain, Part, Fst, No_Index);
+   begin
+      if Position = No_Element then
+         Clear (C);
+         return C;
       end if;
 
-      if Position.Index > Last_Index (Container) then
-         raise Constraint_Error with
-           "Position index is out of range (too large)";
+      if not Has_Element (Container, Position) then
+         raise Constraint_Error;
       end if;
 
-      Fst := Fst + Count_Type (Int (Position.Index) - Int (No_Index)) - 1;
+      while C.Last /= Container.Last - Position.Index + 1 loop
+         Delete_First (C);
+      end loop;
 
-      return (Container.Capacity, Container.Plain, Part, Fst,
-              (Last_Index (Container) - Position.Index + 1));
+      return C;
    end Right;
 
    ----------------
@@ -2042,16 +1765,11 @@ package body Ada.Containers.Formal_Vectors is
       Length    : Capacity_Subtype)
    is
    begin
-      if Container.K /= Plain then
-         raise Constraint_Error
-           with "Can't modify part of container";
-      end if;
-
       if Length = Formal_Vectors.Length (Container) then
          return;
       end if;
 
-      if Container.Plain.Busy > 0 then
+      if Container.Busy > 0 then
          raise Program_Error with
            "attempt to tamper with elements (vector is busy)";
       end if;
@@ -2064,7 +1782,7 @@ package body Ada.Containers.Formal_Vectors is
          Last_As_Int : constant Int'Base :=
                          Int (Index_Type'First) + Int (Length) - 1;
       begin
-         Container.Plain.Last := Index_Type'Base (Last_As_Int);
+         Container.Last := Index_Type'Base (Last_As_Int);
       end;
    end Set_Length;
 
@@ -2074,16 +1792,11 @@ package body Ada.Containers.Formal_Vectors is
 
    procedure Swap (Container : in out Vector; I, J : Index_Type) is
    begin
-      if Container.K /= Plain then
-         raise Constraint_Error
-           with "Can't modify part of container";
-      end if;
-
-      if I > Container.Plain.Last then
+      if I > Container.Last then
          raise Constraint_Error with "I index is out of range";
       end if;
 
-      if J > Container.Plain.Last then
+      if J > Container.Last then
          raise Constraint_Error with "J index is out of range";
       end if;
 
@@ -2091,7 +1804,7 @@ package body Ada.Containers.Formal_Vectors is
          return;
       end if;
 
-      if Container.Plain.Lock > 0 then
+      if Container.Lock > 0 then
          raise Program_Error with
            "attempt to tamper with cursors (vector is locked)";
       end if;
@@ -2100,8 +1813,8 @@ package body Ada.Containers.Formal_Vectors is
          II : constant Int'Base := Int (I) - Int (No_Index);
          JJ : constant Int'Base := Int (J) - Int (No_Index);
 
-         EI : Element_Type renames Container.Plain.Elements (Count_Type (II));
-         EJ : Element_Type renames Container.Plain.Elements (Count_Type (JJ));
+         EI : Element_Type renames Container.Elements (Count_Type (II));
+         EJ : Element_Type renames Container.Elements (Count_Type (JJ));
 
          EI_Copy : constant Element_Type := EI;
 
@@ -2113,11 +1826,6 @@ package body Ada.Containers.Formal_Vectors is
 
    procedure Swap (Container : in out Vector; I, J : Cursor) is
    begin
-      if Container.K /= Plain then
-         raise Constraint_Error
-           with "Can't modify part of container";
-      end if;
-
       if not I.Valid then
          raise Constraint_Error with "I cursor has no element";
       end if;
@@ -2180,9 +1888,7 @@ package body Ada.Containers.Formal_Vectors is
 
          Last := Index_Type (Last_As_Int);
 
-         return (Length,
-                 new Plain_Vector'(Length, (others => <>), Last => Last,
-                                   others => <>),
+         return (Length, (others => <>), Last => Last,
                  others => <>);
       end;
    end To_Vector;
@@ -2208,9 +1914,7 @@ package body Ada.Containers.Formal_Vectors is
 
          Last := Index_Type (Last_As_Int);
 
-         return (Length,
-                 new Plain_Vector'(Length, (others => New_Item), Last => Last,
-                                   others => <>),
+         return (Length, (others => New_Item), Last => Last,
                  others => <>);
       end;
    end To_Vector;
@@ -2224,16 +1928,12 @@ package body Ada.Containers.Formal_Vectors is
       Index     : Index_Type;
       Process   : not null access procedure (Element : in out Element_Type))
    is
-      B : Natural renames Container.Plain.Busy;
-      L : Natural renames Container.Plain.Lock;
+      B : Natural renames Container.Busy;
+      L : Natural renames Container.Lock;
 
    begin
-      if Container.K /= Plain then
-         raise Constraint_Error
-           with "Can't modify part of container";
-      end if;
 
-      if Index > Container.Plain.Last then
+      if Index > Container.Last then
          raise Constraint_Error with "Index is out of range";
       end if;
 
@@ -2245,7 +1945,7 @@ package body Ada.Containers.Formal_Vectors is
          I  : constant Count_Type := Count_Type (II);
 
       begin
-         Process (Container.Plain.Elements (I));
+         Process (Container.Elements (I));
       exception
          when others =>
             L := L - 1;
@@ -2282,7 +1982,7 @@ package body Ada.Containers.Formal_Vectors is
       Count_Type'Base'Write (Stream, Length (Container));
 
       for J in 1 .. Length (Container) loop
-         Element_Type'Write (Stream, Container.Plain.Elements (J));
+         Element_Type'Write (Stream, Container.Elements (J));
       end loop;
    end Write;