2014-12-12 Marc Glisse <marc.glisse@inria.fr>
[official-gcc.git] / gcc / ada / a-cfinve.ads
blobb78633b4f8cc0674494af0fcbfd2d562b3c44750
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT LIBRARY COMPONENTS --
4 -- --
5 -- A D A . C O N T A I N E R S
6 -- . F O R M A L _ I N D E F I N I T E _ V E C T O R S --
7 -- --
8 -- S p e c --
9 -- --
10 -- Copyright (C) 2014, Free Software Foundation, Inc. --
11 -- --
12 -- This specification is derived from the Ada Reference Manual for use with --
13 -- GNAT. The copyright notice above, and the license provisions that follow --
14 -- apply solely to the contents of the part following the private keyword. --
15 -- --
16 -- GNAT is free software; you can redistribute it and/or modify it under --
17 -- terms of the GNU General Public License as published by the Free Soft- --
18 -- ware Foundation; either version 3, or (at your option) any later ver- --
19 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
20 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
21 -- or FITNESS FOR A PARTICULAR PURPOSE. --
22 -- --
23 -- As a special exception under Section 7 of GPL version 3, you are granted --
24 -- additional permissions described in the GCC Runtime Library Exception, --
25 -- version 3.1, as published by the Free Software Foundation. --
26 -- --
27 -- You should have received a copy of the GNU General Public License and --
28 -- a copy of the GCC Runtime Library Exception along with this program; --
29 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
30 -- <http://www.gnu.org/licenses/>. --
31 ------------------------------------------------------------------------------
33 -- Similar to Ada.Containers.Formal_Vectors. The main difference is that
34 -- Element_Type may be indefinite (but not an unconstrained array). In
35 -- addition, this is simplified by removing less-used functionality.
37 with Ada.Containers.Bounded_Holders;
38 with Ada.Containers.Formal_Vectors;
40 generic
41 type Index_Type is range <>;
42 type Element_Type (<>) is private;
43 Max_Size_In_Storage_Elements : Natural :=
44 Element_Type'Max_Size_In_Storage_Elements;
45 -- This has the same meaning as in Ada.Containers.Bounded_Holders, with the
46 -- same restrictions.
48 with function "=" (Left, Right : Element_Type) return Boolean is <>;
50 Bounded : Boolean := True;
51 -- If True, the containers are bounded; the initial capacity is the maximum
52 -- size, and heap allocation will be avoided. If False, the containers can
53 -- grow via heap allocation.
55 package Ada.Containers.Formal_Indefinite_Vectors with
56 SPARK_Mode => On
58 pragma Annotate (GNATprove, External_Axiomatization);
60 subtype Extended_Index is Index_Type'Base
61 range Index_Type'First - 1 ..
62 Index_Type'Min (Index_Type'Base'Last - 1, Index_Type'Last) + 1;
64 No_Index : constant Extended_Index := Extended_Index'First;
66 subtype Capacity_Range is
67 Count_Type range 0 .. Count_Type (Index_Type'Last - Index_Type'First + 1);
69 type Vector (Capacity : Capacity_Range) is limited private with
70 Default_Initial_Condition;
72 function Empty_Vector return Vector;
74 function "=" (Left, Right : Vector) return Boolean with
75 Global => null;
77 function To_Vector
78 (New_Item : Element_Type;
79 Length : Capacity_Range) return Vector
80 with
81 Global => null;
83 function Capacity (Container : Vector) return Capacity_Range with
84 Global => null;
86 procedure Reserve_Capacity
87 (Container : in out Vector;
88 Capacity : Capacity_Range)
89 with
90 Global => null,
91 Pre => (if Bounded then Capacity <= Container.Capacity);
93 function Length (Container : Vector) return Capacity_Range with
94 Global => null;
96 function Is_Empty (Container : Vector) return Boolean with
97 Global => null;
99 procedure Clear (Container : in out Vector) with
100 Global => null;
101 -- Note that this reclaims storage in the unbounded case. You need to call
102 -- this before a container goes out of scope in order to avoid storage
103 -- leaks.
105 procedure Assign (Target : in out Vector; Source : Vector) with
106 Global => null,
107 Pre => (if Bounded then Length (Source) <= Target.Capacity);
109 function Copy
110 (Source : Vector;
111 Capacity : Capacity_Range := 0) return Vector
112 with
113 Global => null,
114 Pre => (if Bounded then Length (Source) <= Capacity);
116 function Element
117 (Container : Vector;
118 Index : Index_Type) return Element_Type
119 with
120 Global => null,
121 Pre => Index in First_Index (Container) .. Last_Index (Container);
123 procedure Replace_Element
124 (Container : in out Vector;
125 Index : Index_Type;
126 New_Item : Element_Type)
127 with
128 Global => null,
129 Pre => Index in First_Index (Container) .. Last_Index (Container);
131 procedure Append
132 (Container : in out Vector;
133 New_Item : Vector)
134 with
135 Global => null,
136 Pre => (if Bounded then
137 Length (Container) + Length (New_Item) <= Container.Capacity);
139 procedure Append
140 (Container : in out Vector;
141 New_Item : Element_Type)
142 with
143 Global => null,
144 Pre => (if Bounded then
145 Length (Container) < Container.Capacity);
147 procedure Delete_Last
148 (Container : in out Vector)
149 with
150 Global => null;
152 procedure Reverse_Elements (Container : in out Vector) with
153 Global => null;
155 procedure Swap (Container : in out Vector; I, J : Index_Type) with
156 Global => null,
157 Pre => I in First_Index (Container) .. Last_Index (Container)
158 and then J in First_Index (Container) .. Last_Index (Container);
160 function First_Index (Container : Vector) return Index_Type with
161 Global => null;
163 function First_Element (Container : Vector) return Element_Type with
164 Global => null,
165 Pre => not Is_Empty (Container);
167 function Last_Index (Container : Vector) return Extended_Index with
168 Global => null;
170 function Last_Element (Container : Vector) return Element_Type with
171 Global => null,
172 Pre => not Is_Empty (Container);
174 function Find_Index
175 (Container : Vector;
176 Item : Element_Type;
177 Index : Index_Type := Index_Type'First) return Extended_Index
178 with
179 Global => null;
181 function Reverse_Find_Index
182 (Container : Vector;
183 Item : Element_Type;
184 Index : Index_Type := Index_Type'Last) return Extended_Index
185 with
186 Global => null;
188 function Contains
189 (Container : Vector;
190 Item : Element_Type) return Boolean
191 with
192 Global => null;
194 function Has_Element
195 (Container : Vector; Position : Extended_Index) return Boolean with
196 Global => null;
198 generic
199 with function "<" (Left, Right : Element_Type) return Boolean is <>;
200 package Generic_Sorting is
202 function Is_Sorted (Container : Vector) return Boolean with
203 Global => null;
205 procedure Sort (Container : in out Vector) with
206 Global => null;
208 end Generic_Sorting;
210 function First_To_Previous
211 (Container : Vector;
212 Current : Index_Type) return Vector
213 with
214 Ghost,
215 Global => null;
217 function Current_To_Last
218 (Container : Vector;
219 Current : Index_Type) return Vector
220 with
221 Ghost,
222 Global => null;
224 private
225 pragma SPARK_Mode (Off);
227 pragma Inline (First_Index);
228 pragma Inline (Last_Index);
229 pragma Inline (Element);
230 pragma Inline (First_Element);
231 pragma Inline (Last_Element);
232 pragma Inline (Replace_Element);
233 pragma Inline (Contains);
235 -- The implementation method is to instantiate Bounded_Holders to get a
236 -- definite type for Element_Type, and then use that Holder type to
237 -- instantiate Formal_Vectors. All the operations are just wrappers.
239 package Holders is new Bounded_Holders
240 (Element_Type, Max_Size_In_Storage_Elements, "=");
241 use Holders;
243 package Def is new Formal_Vectors (Index_Type, Holder, "=", Bounded);
244 use Def;
246 -- ????Assert that Def subtypes have the same range.
248 type Vector (Capacity : Capacity_Range) is limited record
249 V : Def.Vector (Capacity);
250 end record;
252 function Empty_Vector return Vector is
253 ((Capacity => 0, V => Def.Empty_Vector));
255 end Ada.Containers.Formal_Indefinite_Vectors;