]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
[Ada] Allow for of iteration on formal vectors
authorpmderodat <pmderodat@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 21 Aug 2019 08:31:11 +0000 (08:31 +0000)
committerpmderodat <pmderodat@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 21 Aug 2019 08:31:11 +0000 (08:31 +0000)
2019-08-21  Claire Dross  <dross@adacore.com>

gcc/ada/

* libgnat/a-cofove.ads (Vector): Add an Iterable aspect to allow
iteration.
(Iter_First, Iter_Next): Primitives used for iteration.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@274789 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ada/ChangeLog
gcc/ada/libgnat/a-cofove.ads

index abe3524816d00dae0804a09cb52ecaeab4a7d470..1b7a09dc57eb8c81fe7b6f8c36651bdc65060d2b 100644 (file)
@@ -1,3 +1,9 @@
+2019-08-21  Claire Dross  <dross@adacore.com>
+
+       * libgnat/a-cofove.ads (Vector): Add an Iterable aspect to allow
+       iteration.
+       (Iter_First, Iter_Next): Primitives used for iteration.
+
 2019-08-21  Yannick Moy  <moy@adacore.com>
 
        * sem_ch3.adb (Analyze_Subtype_Declaration): Inherit RM_Size
index b23c6613bf0321dc72048e97c58391663f607191..5fb3bc941d18461c0110418a0cda8d02a4175e1b 100644 (file)
@@ -70,7 +70,11 @@ is
    subtype Capacity_Range is Count_Type range 0 .. Last_Count;
 
    type Vector (Capacity : Capacity_Range) is private with
-     Default_Initial_Condition => Is_Empty (Vector);
+     Default_Initial_Condition => Is_Empty (Vector),
+     Iterable => (First       => Iter_First,
+                  Has_Element => Iter_Has_Element,
+                  Next        => Iter_Next,
+                  Element     => Element);
 
    function Length (Container : Vector) return Capacity_Range with
      Global => null,
@@ -173,6 +177,7 @@ is
         Ghost,
         Global => null,
         Post   => M.Length (Model'Result) = Length (Container);
+      pragma Annotate (GNATprove, Iterable_For_Proof, "Model", Model);
 
       function Element
         (S : M.Sequence;
@@ -859,6 +864,30 @@ is
                    Model (Target)'Old);
    end Generic_Sorting;
 
+   ---------------------------
+   --  Iteration Primitives --
+   ---------------------------
+
+   function Iter_First (Container : Vector) return Extended_Index with
+     Global => null;
+
+   function Iter_Has_Element
+     (Container : Vector;
+      Position  : Extended_Index) return Boolean
+   with
+     Global => null,
+     Post   =>
+       Iter_Has_Element'Result =
+         (Position in Index_Type'First .. Last_Index (Container));
+   pragma Annotate (GNATprove, Inline_For_Proof, Iter_Has_Element);
+
+   function Iter_Next
+     (Container : Vector;
+      Position  : Extended_Index) return Extended_Index
+   with
+     Global => null,
+     Pre    => Iter_Has_Element (Container, Position);
+
 private
    pragma SPARK_Mode (Off);
 
@@ -882,4 +911,22 @@ private
    function Empty_Vector return Vector is
      ((Capacity => 0, others => <>));
 
+   function Iter_First (Container : Vector) return Extended_Index is
+     (Index_Type'First);
+
+   function Iter_Next
+     (Container : Vector;
+      Position  : Extended_Index) return Extended_Index
+   is
+     (if Position = Extended_Index'Last then
+         Extended_Index'First
+      else
+         Extended_Index'Succ (Position));
+
+   function Iter_Has_Element
+     (Container : Vector;
+      Position  : Extended_Index) return Boolean
+   is
+     (Position in Index_Type'First .. Container.Last);
+
 end Ada.Containers.Formal_Vectors;