[Ada] Add empty constructors to the functional containers
authorJulien Bortolussi <bortolussi@adacore.com>
Thu, 14 Apr 2022 14:09:30 +0000 (16:09 +0200)
committerPierre-Marie de Rodat <derodat@adacore.com>
Mon, 30 May 2022 08:29:01 +0000 (08:29 +0000)
This patch adds empty constructors to the functional containers so that
we can use them in expression functions.

gcc/ada/

* libgnat/a-cofuma.ads, libgnat/a-cofuma.adb,
libgnat/a-cofuse.ads, libgnat/a-cofuse.adb,
libgnat/a-cofuve.ads, libgnat/a-cofuve.adb: Add empty
constructors.

gcc/ada/libgnat/a-cofuma.adb
gcc/ada/libgnat/a-cofuma.ads
gcc/ada/libgnat/a-cofuse.adb
gcc/ada/libgnat/a-cofuse.ads
gcc/ada/libgnat/a-cofuve.adb
gcc/ada/libgnat/a-cofuve.ads

index 080229d..0fcdbdc 100644 (file)
@@ -130,6 +130,13 @@ package body Ada.Containers.Functional_Maps with SPARK_Mode => Off is
       return True;
    end Elements_Equal_Except;
 
+   ---------------
+   -- Empty_Map --
+   ---------------
+
+   function Empty_Map return Map is
+      ((others =>  <>));
+
    ---------
    -- Get --
    ---------
index 3f61b63..f240e1e 100644 (file)
@@ -243,6 +243,14 @@ package Ada.Containers.Functional_Maps with SPARK_Mode is
          and Container <= Add'Result
          and Keys_Included_Except (Add'Result, Container, New_Key);
 
+   function Empty_Map return Map with
+   --  Return an empty Map
+
+     Global => null,
+     Post   =>
+       Length (Empty_Map'Result) = 0
+         and Is_Empty (Empty_Map'Result);
+
    function Remove
      (Container : Map;
       Key       : Key_Type) return Map
index 0157988..77adb1d 100644 (file)
@@ -63,6 +63,13 @@ package body Ada.Containers.Functional_Sets with SPARK_Mode => Off is
    function Contains (Container : Set; Item : Element_Type) return Boolean is
      (Find (Container.Content, Item) > 0);
 
+   ---------------
+   -- Empty_Set --
+   ---------------
+
+   function Empty_Set return Set is
+      ((others => <>));
+
    ---------------------
    -- Included_Except --
    ---------------------
index db88b9a..ce961aa 100644 (file)
@@ -215,6 +215,12 @@ package Ada.Containers.Functional_Sets with SPARK_Mode is
          and Container <= Add'Result
          and Included_Except (Add'Result, Container, Item);
 
+   function Empty_Set return Set with
+   --  Return an new empty set
+
+     Global => null,
+     Post   => Is_Empty (Empty_Set'Result);
+
    function Remove (Container : Set; Item : Element_Type) return Set with
    --  Return a new set containing all the elements of Container except E
 
index 06075b1..0d91da5 100644 (file)
@@ -118,6 +118,13 @@ package body Ada.Containers.Functional_Vectors with SPARK_Mode => Off is
       return False;
    end Contains;
 
+   --------------------
+   -- Empty_Sequence --
+   --------------------
+
+   function Empty_Sequence return Sequence is
+      ((others => <>));
+
    ------------------
    -- Equal_Except --
    ------------------
index ce3a3a4..f926a96 100644 (file)
@@ -343,6 +343,12 @@ package Ada.Containers.Functional_Vectors with SPARK_Mode is
    --  i.e. it does not contain pointers that could be used to alias mutable
    --  data).
 
+   function Empty_Sequence return Sequence with
+   --  Return an empty Sequence
+
+     Global => null,
+     Post   => Length (Empty_Sequence'Result) = 0;
+
    ---------------------------
    --  Iteration Primitives --
    ---------------------------