3 -- Grant of Unlimited Rights
5 -- The Ada Conformity Assessment Authority (ACAA) holds unlimited
6 -- rights in the software and documentation contained herein. Unlimited
7 -- rights are the same as those granted by the U.S. Government for older
8 -- parts of the Ada Conformity Assessment Test Suite, and are defined
9 -- in DFAR 252.227-7013(a)(19). By making this public release, the ACAA
10 -- intends to confer upon all recipients unlimited rights equal to those
11 -- held by the ACAA. These rights include rights to use, duplicate,
12 -- release or disclose the released technical data and computer software
13 -- in whole or in part, in any manner and for any purpose whatsoever, and
14 -- to have or permit others to do so.
18 -- ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR
19 -- DISCLOSED ARE AS IS. THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED
20 -- WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE
21 -- SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE
22 -- OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A
23 -- PARTICULAR PURPOSE OF SAID MATERIAL.
27 -- Check that a derived access type has the same storage pool as its
28 -- parent. (Defect Report 8652/0012, Technical Corrigendum 3.10(7/1)).
31 -- 24 JAN 2001 PHL Initial version.
32 -- 29 JUN 2001 RLB Reformatted for ACATS.
35 with System
.Storage_Elements
;
36 use System
.Storage_Elements
;
37 with System
.Storage_Pools
;
38 use System
.Storage_Pools
;
41 type Pool
(Storage_Size
: Storage_Count
) is new Root_Storage_Pool
with
43 First_Free
: Storage_Count
:= 1;
44 Contents
: Storage_Array
(1 .. Storage_Size
);
47 procedure Allocate
(Pool
: in out C3A0015_0
.Pool
;
48 Storage_Address
: out System
.Address
;
49 Size_In_Storage_Elements
: in Storage_Count
;
50 Alignment
: in Storage_Count
);
52 procedure Deallocate
(Pool
: in out C3A0015_0
.Pool
;
53 Storage_Address
: in System
.Address
;
54 Size_In_Storage_Elements
: in Storage_Count
;
55 Alignment
: in Storage_Count
);
57 function Storage_Size
(Pool
: in C3A0015_0
.Pool
) return Storage_Count
;
61 package body C3A0015_0
is
65 procedure Allocate
(Pool
: in out C3A0015_0
.Pool
;
66 Storage_Address
: out System
.Address
;
67 Size_In_Storage_Elements
: in Storage_Count
;
68 Alignment
: in Storage_Count
) is
69 Unaligned_Address
: constant System
.Address
:=
70 Pool
.Contents
(Pool
.First_Free
)'Address;
71 Unalignment
: Storage_Count
;
73 Unalignment
:= Unaligned_Address
mod Alignment
;
74 if Unalignment
= 0 then
75 Storage_Address
:= Unaligned_Address
;
76 Pool
.First_Free
:= Pool
.First_Free
+ Size_In_Storage_Elements
;
79 Pool
.Contents
(Pool
.First_Free
+ Alignment
- Unalignment
)'
81 Pool.First_Free := Pool.First_Free + Size_In_Storage_Elements +
82 Alignment - Unalignment;
86 procedure Deallocate (Pool : in out C3A0015_0.Pool;
87 Storage_Address : in System.Address;
88 Size_In_Storage_Elements : in Storage_Count;
89 Alignment : in Storage_Count) is
91 if Storage_Address + Size_In_Storage_Elements =
92 Pool.Contents (Pool.First_Free)'Address then
93 -- Only deallocate if the block is at the end.
94 Pool.First_Free := Pool.First_Free - Size_In_Storage_Elements;
98 function Storage_Size (Pool : in C3A0015_0.Pool) return Storage_Count is
100 return Pool.Storage_Size;
107 with Ada.Unchecked_Deallocation;
110 with System.Storage_Elements;
111 use System.Storage_Elements;
115 type Standard_Pool is access Float;
116 type Derived_Standard_Pool is new Standard_Pool;
117 type Derived_Derived_Standard_Pool is new Derived_Standard_Pool;
119 type User_Defined_Pool is access Integer;
120 type Derived_User_Defined_Pool is new User_Defined_Pool;
121 type Derived_Derived_User_Defined_Pool is new Derived_User_Defined_Pool;
123 My_Pool : C3A0015_0.Pool (1024);
124 for User_Defined_Pool'Storage_Pool use My_Pool;
127 type Designated is private;
129 type Acc is access Designated;
130 type Derived_Acc is new Acc;
131 procedure Check (Subtest : String; User_Defined_Pool : Boolean);
133 procedure Check (Subtest : String; User_Defined_Pool : Boolean) is
135 procedure Deallocate is
136 new Ada.Unchecked_Deallocation (Object => Designated,
138 procedure Deallocate is
139 new Ada.Unchecked_Deallocation (Object => Designated,
140 Name => Derived_Acc);
142 First_Free : Storage_Count;
146 if User_Defined_Pool then
147 First_Free := My_Pool.First_Free;
149 X := new Designated'(Value
);
150 if User_Defined_Pool
and then First_Free
>= My_Pool
.First_Free
then
152 " - Allocation didn't consume storage in the pool - 1");
154 First_Free
:= My_Pool
.First_Free
;
157 Y
:= Derived_Acc
(X
);
158 if User_Defined_Pool
and then First_Free
/= My_Pool
.First_Free
then
160 " - Conversion did consume storage in the pool - 1");
162 if Y
.all /= Value
then
164 " - Incorrect allocation/conversion of access values - 1");
168 if User_Defined_Pool
and then First_Free
<= My_Pool
.First_Free
then
170 " - Deallocation didn't release storage from the pool - 1");
172 First_Free
:= My_Pool
.First_Free
;
175 Y
:= new Designated
'(Value);
176 if User_Defined_Pool and then First_Free >= My_Pool.First_Free then
178 " - Allocation didn't consume storage in the pool - 2");
180 First_Free := My_Pool.First_Free;
184 if User_Defined_Pool and then First_Free /= My_Pool.First_Free then
186 " - Conversion did consume storage in the pool - 2");
188 if X.all /= Value then
190 " - Incorrect allocation/conversion of access values - 2");
194 if User_Defined_Pool and then First_Free <= My_Pool.First_Free then
196 " - Deallocation didn't release storage from the pool - 2");
200 Failed (Subtest & " - Exception " & Exception_Name (E) &
201 " raised - " & Exception_Message (E));
206 Test ("C3A0015", "Check that a dervied access type has the same " &
207 "storage pool as its parent");
209 Comment ("Access types using the standard storage pool");
214 new Check (Designated => Float,
216 Acc => Standard_Pool,
217 Derived_Acc => Derived_Standard_Pool);
219 new Check (Designated => Float,
221 Acc => Standard_Pool,
222 Derived_Acc => Derived_Derived_Standard_Pool);
224 new Check (Designated => Float,
226 Acc => Derived_Standard_Pool,
227 Derived_Acc => Derived_Derived_Standard_Pool);
229 Check1 ("Standard_Pool/Derived_Standard_Pool",
230 User_Defined_Pool => False);
231 Check2 ("Standard_Pool/Derived_Derived_Standard_Pool",
232 User_Defined_Pool => False);
233 Check3 ("Derived_Standard_Pool/Derived_Derived_Standard_Pool",
234 User_Defined_Pool => False);
237 Comment ("Access types using a user-defined storage pool");
242 new Check (Designated => Integer,
244 Acc => User_Defined_Pool,
245 Derived_Acc => Derived_User_Defined_Pool);
247 new Check (Designated => Integer,
249 Acc => User_Defined_Pool,
250 Derived_Acc => Derived_Derived_User_Defined_Pool);
252 new Check (Designated => Integer,
254 Acc => Derived_User_Defined_Pool,
255 Derived_Acc => Derived_Derived_User_Defined_Pool);
257 Check1 ("User_Defined_Pool/Derived_User_Defined_Pool",
258 User_Defined_Pool => True);
259 Check2 ("User_Defined_Pool/Derived_Derived_User_Defined_Pool",
260 User_Defined_Pool => True);
262 ("Derived_User_Defined_Pool/Derived_Derived_User_Defined_Pool",
263 User_Defined_Pool => True);