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 a general access type object may reference allocated
28 -- pool objects as well as aliased objects. (3,4)
29 -- Check that formal parameters of tagged types are implicitly
30 -- defined as aliased; check that the 'Access of these formal
31 -- parameters designates the correct object with the correct
33 -- Check that the current instance of a limited type is defined as
37 -- This test takes from the hierarchy defined in C390003; making
38 -- the root type Vehicle limited private. It also shifts the
39 -- abstraction to include the notion of a transmission, an object
40 -- which is contained within any vehicle. Using an access
41 -- discriminant, any subprogram which operates on a transmission
42 -- may also reference the vehicle in which it is installed.
45 -- Vehicle Transmission
50 -- Vehicle( Transmission )
55 -- 06 Dec 94 SAIC ACVC 2.0
56 -- 16 Dec 94 SAIC Fixed accessibility problems
61 type Vehicle
is tagged limited private;
62 type Vehicle_ID
is access all Vehicle
'Class;
65 procedure Create
( It
: in out Vehicle
;
66 Wheels
: Natural := 4 );
68 procedure Accelerate
( It
: in out Vehicle
);
69 procedure Decelerate
( It
: in out Vehicle
);
70 procedure Up_Shift
( It
: in out Vehicle
);
71 procedure Stop
( It
: in out Vehicle
);
74 function Speed
( It
: Vehicle
) return Natural;
75 function Wheels
( It
: Vehicle
) return Natural;
76 function Gear_Factor
( It
: Vehicle
) return Natural;
79 procedure TC_Validate
( It
: in out Vehicle
; Speed_Trap
: Natural );
81 -- dispatching procedure used to check tag correctness
82 procedure TC_Validate
( It
: Vehicle
;
87 type Transmission
(Within
: access Vehicle
'Class) is limited record
88 Engaged
: Boolean := False;
89 Gear
: Integer range -1..5 := 0;
92 -- Current instance of a limited type is defined as aliased
94 type Vehicle
is tagged limited record
97 Power_Train
: Transmission
( Vehicle
'Access );
103 type Car
is new C3A0013_1
.Vehicle
with private;
104 procedure TC_Validate
( It
: Car
;
106 function Gear_Factor
( It
: Car
) return Natural;
108 type Car
is new C3A0013_1
.Vehicle
with record
109 Displacement
: Natural;
115 type Truck
is new C3A0013_1
.Vehicle
with private;
116 procedure TC_Validate
( It
: Truck
;
118 function Gear_Factor
( It
: Truck
) return Natural;
120 type Truck
is new C3A0013_1
.Vehicle
with record
121 Displacement
: Natural;
126 package body C3A0013_1
is
128 procedure Create
( It
: in out Vehicle
;
129 Wheels
: Natural := 4 ) is
135 procedure Accelerate
( It
: in out Vehicle
) is
137 It
.Speed
:= It
.Speed
+ Gear_Factor
( It
.Power_Train
.Within
.all );
140 procedure Decelerate
( It
: in out Vehicle
) is
142 It
.Speed
:= It
.Speed
- Gear_Factor
( It
.Power_Train
.Within
.all );
145 procedure Stop
( It
: in out Vehicle
) is
148 It
.Power_Train
.Engaged
:= False;
151 function Gear_Factor
( It
: Vehicle
) return Natural is
153 return It
.Power_Train
.Gear
;
156 function Speed
( It
: Vehicle
) return Natural is
161 function Wheels
( It
: Vehicle
) return Natural is
166 -- formal tagged parameters are implicitly aliased
168 procedure TC_Validate
( It
: in out Vehicle
; Speed_Trap
: Natural ) is
169 License
: Vehicle_ID
:= It
'Unchecked_Access;
171 if Speed
( License
.all ) /= Speed_Trap
then
172 Report
.Failed
("Speed Trap: expected: " & Natural'Image(Speed_Trap
));
176 procedure TC_Validate
( It
: Vehicle
;
177 TC_ID
: Character) is
180 Report
.Failed
("Dispatched to Vehicle");
182 if Wheels
( It
) /= 1 then
183 Report
.Failed
("Not a Vehicle");
187 procedure Up_Shift
( It
: in out Vehicle
) is
189 It
.Power_Train
.Gear
:= It
.Power_Train
.Gear
+1;
190 It
.Power_Train
.Engaged
:= True;
196 package body C3A0013_2
is
198 procedure TC_Validate
( It
: Car
;
199 TC_ID
: Character ) is
202 Report
.Failed
("Dispatched to Car");
204 if Wheels
( It
) /= 4 then
205 Report
.Failed
("Not a Car");
209 function Gear_Factor
( It
: Car
) return Natural is
211 return C3A0013_1
.Gear_Factor
( C3A0013_1
.Vehicle
( It
) )*2;
217 package body C3A0013_3
is
219 procedure TC_Validate
( It
: Truck
;
220 TC_ID
: Character) is
223 Report
.Failed
("Dispatched to Truck");
225 if Wheels
( It
) /= 3 then
226 Report
.Failed
("Not a Truck");
230 function Gear_Factor
( It
: Truck
) return Natural is
232 return C3A0013_1
.Gear_Factor
( C3A0013_1
.Vehicle
( It
) )*3;
238 procedure Perform_Tests
;
245 package body C3A0013_4
is
246 package Root
renames C3A0013_1
;
247 package Cars
renames C3A0013_2
;
248 package Trucks
renames C3A0013_3
;
250 type Car_Pool
is array(1..4) of aliased Cars
.Car
;
251 Commuters
: Car_Pool
;
253 My_Car
: aliased Cars
.Car
;
254 Company_Car
: Root
.Vehicle_ID
;
255 Repair_Shop
: Root
.Vehicle_ID
;
257 The_Vehicle
: Root
.Vehicle
;
259 The_Truck
: Trucks
.Truck
;
261 procedure TC_Dispatch
( Ptr
: Root
.Vehicle_ID
;
262 Char
: Character ) is
264 Root
.TC_Validate
( Ptr
.all, Char
);
267 procedure TC_Check_Formal_Access
( Item
: in out Root
.Vehicle
'Class;
270 TC_Dispatch
( Item
'Unchecked_Access, Char
);
271 end TC_Check_Formal_Access
;
273 procedure Perform_Tests
is
274 begin -- Main test procedure.
276 for Lane
in Commuters
'Range loop
277 Cars
.Create
( Commuters
(Lane
) );
278 for Excitement
in 1..Lane
loop
279 Cars
.Up_Shift
( Commuters
(Lane
) );
283 Cars
.Create
( My_Car
);
284 Cars
.Up_Shift
( My_Car
);
285 Cars
.TC_Validate
( My_Car
, 2 );
287 Root
.Create
( The_Vehicle
, 1 );
288 Cars
.Create
( The_Car
, 4 );
289 Trucks
.Create
( The_Truck
, 3 );
291 TC_Check_Formal_Access
( The_Vehicle
, 'V' );
292 TC_Check_Formal_Access
( The_Car
, 'C' );
293 TC_Check_Formal_Access
( The_Truck
, 'T' );
295 Root
.Up_Shift
( The_Vehicle
);
296 Cars
.Up_Shift
( The_Car
);
297 Trucks
.Up_Shift
( The_Truck
);
299 Root
.TC_Validate
( The_Vehicle
, 1 );
300 Cars
.TC_Validate
( The_Car
, 2 );
301 Trucks
.TC_Validate
( The_Truck
, 3 );
303 -- general access type may reference allocated objects
305 Company_Car
:= new Cars
.Car
;
306 Root
.Create
( Company_Car
.all );
307 Root
.Up_Shift
( Company_Car
.all );
308 Root
.Up_Shift
( Company_Car
.all );
309 Root
.TC_Validate
( Company_Car
.all, 6 );
311 -- general access type may reference aliased objects
313 Repair_Shop
:= My_Car
'Access;
314 Root
.TC_Validate
( Repair_Shop
.all, 2 );
316 -- general access type may reference aliased objects
318 Construction
: declare
319 type Speed_List
is array(Commuters
'Range) of Natural;
320 Accelerations
: constant Speed_List
:= (2, 6, 12, 20);
322 for Rotation
in Commuters
'Range loop
323 Repair_Shop
:= Commuters
(Rotation
)'Access;
324 Root
.TC_Validate
( Repair_Shop
.all, Accelerations
(Rotation
) );
337 Report
.Test
("C3A0013", "Check general access types. Check aliased "
338 & "nature of formal tagged type parameters. "
339 & "Check aliased nature of the current "
340 & "instance of a limited type. Check the "
341 & "constraining of actual subtypes for "
342 & "discriminated objects" );
344 C3A0013_4
.Perform_Tests
;