2014-10-31 Vasiliy Fofanov <fofanov@adacore.com>
[official-gcc.git] / gcc / ada / a-cfinve.ads
blob19cc166f2684778b8cac335bdb99639e09588952
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 is
56 pragma Annotate (GNATprove, External_Axiomatization);
58 subtype Extended_Index is Index_Type'Base
59 range Index_Type'First - 1 ..
60 Index_Type'Min (Index_Type'Base'Last - 1, Index_Type'Last) + 1;
62 No_Index : constant Extended_Index := Extended_Index'First;
64 subtype Capacity_Range is
65 Count_Type range 0 .. Count_Type (Index_Type'Last - Index_Type'First + 1);
67 type Vector (Capacity : Capacity_Range) is limited private with
68 Default_Initial_Condition;
70 function Empty_Vector return Vector;
72 function "=" (Left, Right : Vector) return Boolean with
73 Global => null;
75 function To_Vector
76 (New_Item : Element_Type;
77 Length : Capacity_Range) return Vector
78 with
79 Global => null;
81 function Capacity (Container : Vector) return Capacity_Range with
82 Global => null;
84 procedure Reserve_Capacity
85 (Container : in out Vector;
86 Capacity : Capacity_Range)
87 with
88 Global => null,
89 Pre => (if Bounded then Capacity <= Container.Capacity);
91 function Length (Container : Vector) return Capacity_Range with
92 Global => null;
94 function Is_Empty (Container : Vector) return Boolean with
95 Global => null;
97 procedure Clear (Container : in out Vector) with
98 Global => null;
99 -- Note that this reclaims storage in the unbounded case. You need to call
100 -- this before a container goes out of scope in order to avoid storage
101 -- leaks.
103 procedure Assign (Target : in out Vector; Source : Vector) with
104 Global => null,
105 Pre => (if Bounded then Length (Source) <= Target.Capacity);
107 function Copy
108 (Source : Vector;
109 Capacity : Capacity_Range := 0) return Vector
110 with
111 Global => null,
112 Pre => (if Bounded then Length (Source) <= Capacity);
114 function Element
115 (Container : Vector;
116 Index : Index_Type) return Element_Type
117 with
118 Global => null,
119 Pre => Index in First_Index (Container) .. Last_Index (Container);
121 procedure Replace_Element
122 (Container : in out Vector;
123 Index : Index_Type;
124 New_Item : Element_Type)
125 with
126 Global => null,
127 Pre => Index in First_Index (Container) .. Last_Index (Container);
129 procedure Append
130 (Container : in out Vector;
131 New_Item : Vector)
132 with
133 Global => null,
134 Pre => (if Bounded then
135 Length (Container) + Length (New_Item) <= Container.Capacity);
137 procedure Append
138 (Container : in out Vector;
139 New_Item : Element_Type)
140 with
141 Global => null,
142 Pre => (if Bounded then
143 Length (Container) < Container.Capacity);
145 procedure Delete_Last
146 (Container : in out Vector)
147 with
148 Global => null;
150 procedure Reverse_Elements (Container : in out Vector) with
151 Global => null;
153 procedure Swap (Container : in out Vector; I, J : Index_Type) with
154 Global => null,
155 Pre => I in First_Index (Container) .. Last_Index (Container)
156 and then J in First_Index (Container) .. Last_Index (Container);
158 function First_Index (Container : Vector) return Index_Type with
159 Global => null;
161 function First_Element (Container : Vector) return Element_Type with
162 Global => null,
163 Pre => not Is_Empty (Container);
165 function Last_Index (Container : Vector) return Extended_Index with
166 Global => null;
168 function Last_Element (Container : Vector) return Element_Type with
169 Global => null,
170 Pre => not Is_Empty (Container);
172 function Find_Index
173 (Container : Vector;
174 Item : Element_Type;
175 Index : Index_Type := Index_Type'First) return Extended_Index
176 with
177 Global => null;
179 function Reverse_Find_Index
180 (Container : Vector;
181 Item : Element_Type;
182 Index : Index_Type := Index_Type'Last) return Extended_Index
183 with
184 Global => null;
186 function Contains
187 (Container : Vector;
188 Item : Element_Type) return Boolean
189 with
190 Global => null;
192 function Has_Element
193 (Container : Vector; Position : Extended_Index) return Boolean with
194 Global => null;
196 generic
197 with function "<" (Left, Right : Element_Type) return Boolean is <>;
198 package Generic_Sorting is
200 function Is_Sorted (Container : Vector) return Boolean with
201 Global => null;
203 procedure Sort (Container : in out Vector) with
204 Global => null;
206 end Generic_Sorting;
208 function First_To_Previous
209 (Container : Vector;
210 Current : Index_Type) return Vector
211 with
212 Global => null;
213 function Current_To_Last
214 (Container : Vector;
215 Current : Index_Type) return Vector
216 with
217 Global => null;
219 private
221 pragma Inline (First_Index);
222 pragma Inline (Last_Index);
223 pragma Inline (Element);
224 pragma Inline (First_Element);
225 pragma Inline (Last_Element);
226 pragma Inline (Replace_Element);
227 pragma Inline (Contains);
229 -- The implementation method is to instantiate Bounded_Holders to get a
230 -- definite type for Element_Type, and then use that Holder type to
231 -- instantiate Formal_Vectors. All the operations are just wrappers.
233 package Holders is new Bounded_Holders
234 (Element_Type, Max_Size_In_Storage_Elements, "=");
235 use Holders;
237 package Def is new Formal_Vectors (Index_Type, Holder, "=", Bounded);
238 use Def;
240 -- ????Assert that Def subtypes have the same range.
242 type Vector (Capacity : Capacity_Range) is limited record
243 V : Def.Vector (Capacity);
244 end record;
246 function Empty_Vector return Vector is
247 ((Capacity => 0, V => Def.Empty_Vector));
249 end Ada.Containers.Formal_Indefinite_Vectors;