3 -- Grant of Unlimited Rights
5 -- Under contracts F33600-87-D-0337, F33600-84-D-0280, MDA903-79-C-0687,
6 -- F08630-91-C-0015, and DCA100-97-D-0025, the U.S. Government obtained
7 -- unlimited rights in the software and documentation contained herein.
8 -- Unlimited rights are defined in DFAR 252.227-7013(a)(19). By making
9 -- this public release, the Government intends to confer upon all
10 -- recipients unlimited rights equal to those held by the Government.
11 -- These rights include rights to use, duplicate, release or disclose the
12 -- released technical data and computer software in whole or in part, in
13 -- any manner and for any purpose whatsoever, and to have or permit others
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 modular types may be used as array indices.
29 -- Check that if aliased appears in the component_definition of an
30 -- array_type that each component of the array is aliased.
32 -- Check that references to aliased array objects produce correct
33 -- results, and that out-of-bounds indexing correctly produces
37 -- This test defines several array types and subtypes indexed by modular
38 -- types; some aliased some not, some with aliased components, some not.
40 -- It then checks that assignments move the correct data.
44 -- 28 SEP 95 SAIC Initial version
45 -- 23 APR 96 SAIC Doc fixes, fixed constrained/unconstrained conflict
46 -- 13 FEB 97 PWB.CTA Removed illegal declarations and affected code
49 ------------------------------------------------------------------- C360002
55 Verbose
: Boolean := Report
.Ident_Bool
( False );
57 type Mod_128
is mod 128;
59 function Ident_128
( I
: Integer ) return Mod_128
is
61 return Mod_128
( Report
.Ident_Int
( I
) );
64 type Unconstrained_Array
65 is array( Mod_128
range <> ) of Integer;
67 type Unconstrained_Array_Aliased
68 is array( Mod_128
range <> ) of aliased Integer;
70 type Access_All_Unconstrained_Array
71 is access all Unconstrained_Array
;
73 type Access_All_Unconstrained_Array_Aliased
74 is access all Unconstrained_Array_Aliased
;
77 is Unconstrained_Array
(01..10);
80 is Unconstrained_Array
(11..20);
82 subtype Array_Aliased_01_10
83 is Unconstrained_Array_Aliased
(01..10);
85 subtype Array_Aliased_11_20
86 is Unconstrained_Array_Aliased
(11..20);
88 subtype Access_All_01_10_Array
89 is Access_All_Unconstrained_Array
(01..10);
91 subtype Access_All_01_10_Array_Aliased
92 is Access_All_Unconstrained_Array_Aliased
(01..10);
94 subtype Access_All_11_20_Array
95 is Access_All_Unconstrained_Array
(11..20);
97 subtype Access_All_11_20_Array_Aliased
98 is Access_All_Unconstrained_Array_Aliased
(11..20);
101 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
103 -- these 'filler' functions create unique values for every element that
104 -- is used and/or tested in this test.
106 Well_Bottom
: Integer := 0;
108 function Filler
( Size
: Mod_128
) return Unconstrained_Array
is
109 It
: Unconstrained_Array
( 0..Size
-1 );
111 for Eyes
in It
'Range loop
112 It
(Eyes
) := Integer( Eyes
) + Well_Bottom
;
114 Well_Bottom
:= Well_Bottom
+ It
'Length;
118 function Filler
( Size
: Mod_128
) return Unconstrained_Array_Aliased
is
119 It
: Unconstrained_Array_Aliased
( 0..Size
-1 );
121 for Ayes
in It
'Range loop
122 It
(Ayes
) := Integer( Ayes
) + Well_Bottom
;
124 Well_Bottom
:= Well_Bottom
+ It
'Length;
128 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
130 An_Integer
: Integer;
132 type AAI
is access all Integer;
134 An_Integer_Access
: AAI
;
136 Array_Item_01_10
: Array_01_10
:= Filler
(10); -- 0..9
138 Array_Item_11_20
: Array_11_20
:= Filler
(10); -- 10..19 (sliding)
140 Array_Aliased_Item_01_10
: Array_Aliased_01_10
:= Filler
(10); -- 20..29
142 Array_Aliased_Item_11_20
: Array_Aliased_11_20
:= Filler
(10); -- 30..39
144 Aliased_Array_Item_01_10
: aliased Array_01_10
:= Filler
(10); -- 40..49
146 Aliased_Array_Item_11_20
: aliased Array_11_20
:= Filler
(10); -- 50..59
148 Aliased_Array_Aliased_Item_01_10
: aliased Array_Aliased_01_10
149 := Filler
(10); -- 60..69
151 Aliased_Array_Aliased_Item_11_20
: aliased Array_Aliased_11_20
152 := Filler
(10); -- 70..79
154 Check_Item
: Access_All_Unconstrained_Array
;
156 Check_Aliased_Item
: Access_All_Unconstrained_Array_Aliased
;
158 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
160 procedure Fail
( Message
: String; CI
, SB
: Integer ) is
162 Report
.Failed
("Wrong value passed " & Message
);
164 Report
.Comment
("got" & Integer'Image(CI
) &
165 " should be" & Integer'Image(SB
) );
169 procedure Check_Array_01_10
( Checked_Item
: Array_01_10
;
170 Low_SB
: Integer ) is
172 for Index
in Checked_Item
'Range loop
173 if (Checked_Item
(Index
) /= (Low_SB
+Integer(Index
)-1)) then
174 Fail
("unaliased 1..10", Checked_Item
(Index
),
175 (Low_SB
+Integer(Index
)-1));
178 end Check_Array_01_10
;
180 procedure Check_Array_11_20
( Checked_Item
: Array_11_20
;
181 Low_SB
: Integer ) is
183 for Index
in Checked_Item
'Range loop
184 if (Checked_Item
(Index
) /= (Low_SB
+Integer(Index
)-11)) then
185 Fail
("unaliased 11..20", Checked_Item
(Index
),
186 (Low_SB
+Integer(Index
)-11));
189 end Check_Array_11_20
;
191 procedure Check_Single_Integer
( The_Integer
, SB
: Integer;
192 Message
: String ) is
194 if The_Integer
/= SB
then
195 Report
.Failed
("Wrong integer value for " & Message
);
197 end Check_Single_Integer
;
199 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
201 begin -- Main test procedure.
203 Report
.Test
("C360002", "Check that modular types may be used as array " &
204 "indices. Check that if aliased appears in " &
205 "the component_definition of an array_type that " &
206 "each component of the array is aliased. Check " &
207 "that references to aliased array objects " &
208 "produce correct results, and that out of bound " &
209 "references to aliased objects correctly " &
210 "produce Constraint_Error" );
211 -- start with checks that the Filler assignments produced the expected
212 -- result. This is a "case 0" test to check that nothing REALLY surprising
215 Check_Array_01_10
( Array_Item_01_10
, 0 );
216 Check_Array_11_20
( Array_Item_11_20
, 10 );
218 -- check that having the variable aliased makes no difference
219 Check_Array_01_10
( Aliased_Array_Item_01_10
, 40 );
220 Check_Array_11_20
( Aliased_Array_Item_11_20
, 50 );
222 -- now check that conversion between array types where the only
223 -- difference in the definitions is that the components are aliased works
225 Check_Array_01_10
( Unconstrained_Array
( Array_Aliased_Item_01_10
), 20 );
226 Check_Array_11_20
( Unconstrained_Array
( Array_Aliased_Item_11_20
), 30 );
228 -- check that conversion of an aliased object with aliased components
231 Check_Array_01_10
( Unconstrained_Array
( Aliased_Array_Aliased_Item_01_10
),
233 Check_Array_11_20
( Unconstrained_Array
( Aliased_Array_Aliased_Item_11_20
),
236 -- check that the bounds will slide
238 Check_Array_01_10
( Array_01_10
( Array_Item_11_20
), 10 );
239 Check_Array_11_20
( Array_11_20
( Array_Item_01_10
), 0 );
241 -- point at some of the components and check them
243 An_Integer_Access
:= Array_Aliased_Item_01_10
(5)'Access;
245 Check_Single_Integer
( An_Integer_Access
.all, 24,
246 "Aliased component 'Access");
248 An_Integer_Access
:= Aliased_Array_Aliased_Item_01_10
(7)'Access;
250 Check_Single_Integer
( An_Integer_Access
.all, 66,
251 "Aliased Aliased component 'Access");
253 -- check some assignments
255 Array_Item_01_10
:= Aliased_Array_Item_01_10
;
256 Check_Array_01_10
( Array_Item_01_10
, 40 );
258 Aliased_Array_Item_01_10
:= Aliased_Array_Item_11_20
(11..20);
259 Check_Array_01_10
( Aliased_Array_Item_01_10
, 50 );
261 Aliased_Array_Aliased_Item_11_20
(11..20)
262 := Aliased_Array_Aliased_Item_01_10
;
263 Check_Array_11_20
( Unconstrained_Array
( Aliased_Array_Aliased_Item_11_20
),