annotate gcc/testsuite/ada/acats/tests/c3/c3a0013.a @ 111:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 -- C3A0013.A
kono
parents:
diff changeset
2 --
kono
parents:
diff changeset
3 -- Grant of Unlimited Rights
kono
parents:
diff changeset
4 --
kono
parents:
diff changeset
5 -- Under contracts F33600-87-D-0337, F33600-84-D-0280, MDA903-79-C-0687,
kono
parents:
diff changeset
6 -- F08630-91-C-0015, and DCA100-97-D-0025, the U.S. Government obtained
kono
parents:
diff changeset
7 -- unlimited rights in the software and documentation contained herein.
kono
parents:
diff changeset
8 -- Unlimited rights are defined in DFAR 252.227-7013(a)(19). By making
kono
parents:
diff changeset
9 -- this public release, the Government intends to confer upon all
kono
parents:
diff changeset
10 -- recipients unlimited rights equal to those held by the Government.
kono
parents:
diff changeset
11 -- These rights include rights to use, duplicate, release or disclose the
kono
parents:
diff changeset
12 -- released technical data and computer software in whole or in part, in
kono
parents:
diff changeset
13 -- any manner and for any purpose whatsoever, and to have or permit others
kono
parents:
diff changeset
14 -- to do so.
kono
parents:
diff changeset
15 --
kono
parents:
diff changeset
16 -- DISCLAIMER
kono
parents:
diff changeset
17 --
kono
parents:
diff changeset
18 -- ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR
kono
parents:
diff changeset
19 -- DISCLOSED ARE AS IS. THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED
kono
parents:
diff changeset
20 -- WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE
kono
parents:
diff changeset
21 -- SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE
kono
parents:
diff changeset
22 -- OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A
kono
parents:
diff changeset
23 -- PARTICULAR PURPOSE OF SAID MATERIAL.
kono
parents:
diff changeset
24 --*
kono
parents:
diff changeset
25 --
kono
parents:
diff changeset
26 -- OBJECTIVE:
kono
parents:
diff changeset
27 -- Check that a general access type object may reference allocated
kono
parents:
diff changeset
28 -- pool objects as well as aliased objects. (3,4)
kono
parents:
diff changeset
29 -- Check that formal parameters of tagged types are implicitly
kono
parents:
diff changeset
30 -- defined as aliased; check that the 'Access of these formal
kono
parents:
diff changeset
31 -- parameters designates the correct object with the correct
kono
parents:
diff changeset
32 -- tag. (5)
kono
parents:
diff changeset
33 -- Check that the current instance of a limited type is defined as
kono
parents:
diff changeset
34 -- aliased. (5)
kono
parents:
diff changeset
35 --
kono
parents:
diff changeset
36 -- TEST DESCRIPTION:
kono
parents:
diff changeset
37 -- This test takes from the hierarchy defined in C390003; making
kono
parents:
diff changeset
38 -- the root type Vehicle limited private. It also shifts the
kono
parents:
diff changeset
39 -- abstraction to include the notion of a transmission, an object
kono
parents:
diff changeset
40 -- which is contained within any vehicle. Using an access
kono
parents:
diff changeset
41 -- discriminant, any subprogram which operates on a transmission
kono
parents:
diff changeset
42 -- may also reference the vehicle in which it is installed.
kono
parents:
diff changeset
43 --
kono
parents:
diff changeset
44 -- Class Hierarchy:
kono
parents:
diff changeset
45 -- Vehicle Transmission
kono
parents:
diff changeset
46 -- / \
kono
parents:
diff changeset
47 -- Truck Car
kono
parents:
diff changeset
48 --
kono
parents:
diff changeset
49 -- Contains:
kono
parents:
diff changeset
50 -- Vehicle( Transmission )
kono
parents:
diff changeset
51 --
kono
parents:
diff changeset
52 --
kono
parents:
diff changeset
53 --
kono
parents:
diff changeset
54 -- CHANGE HISTORY:
kono
parents:
diff changeset
55 -- 06 Dec 94 SAIC ACVC 2.0
kono
parents:
diff changeset
56 -- 16 Dec 94 SAIC Fixed accessibility problems
kono
parents:
diff changeset
57 --
kono
parents:
diff changeset
58 --!
kono
parents:
diff changeset
59
kono
parents:
diff changeset
60 package C3A0013_1 is
kono
parents:
diff changeset
61 type Vehicle is tagged limited private;
kono
parents:
diff changeset
62 type Vehicle_ID is access all Vehicle'Class;
kono
parents:
diff changeset
63
kono
parents:
diff changeset
64 -- Constructors
kono
parents:
diff changeset
65 procedure Create ( It : in out Vehicle;
kono
parents:
diff changeset
66 Wheels : Natural := 4 );
kono
parents:
diff changeset
67 -- Modifiers
kono
parents:
diff changeset
68 procedure Accelerate ( It : in out Vehicle );
kono
parents:
diff changeset
69 procedure Decelerate ( It : in out Vehicle );
kono
parents:
diff changeset
70 procedure Up_Shift ( It : in out Vehicle );
kono
parents:
diff changeset
71 procedure Stop ( It : in out Vehicle );
kono
parents:
diff changeset
72
kono
parents:
diff changeset
73 -- Selectors
kono
parents:
diff changeset
74 function Speed ( It : Vehicle ) return Natural;
kono
parents:
diff changeset
75 function Wheels ( It : Vehicle ) return Natural;
kono
parents:
diff changeset
76 function Gear_Factor( It : Vehicle ) return Natural;
kono
parents:
diff changeset
77
kono
parents:
diff changeset
78 -- TC_Ops
kono
parents:
diff changeset
79 procedure TC_Validate( It : in out Vehicle; Speed_Trap : Natural );
kono
parents:
diff changeset
80
kono
parents:
diff changeset
81 -- dispatching procedure used to check tag correctness
kono
parents:
diff changeset
82 procedure TC_Validate( It : Vehicle;
kono
parents:
diff changeset
83 TC_ID : Character);
kono
parents:
diff changeset
84
kono
parents:
diff changeset
85 private
kono
parents:
diff changeset
86
kono
parents:
diff changeset
87 type Transmission(Within: access Vehicle'Class) is limited record
kono
parents:
diff changeset
88 Engaged : Boolean := False;
kono
parents:
diff changeset
89 Gear : Integer range -1..5 := 0;
kono
parents:
diff changeset
90 end record;
kono
parents:
diff changeset
91
kono
parents:
diff changeset
92 -- Current instance of a limited type is defined as aliased
kono
parents:
diff changeset
93
kono
parents:
diff changeset
94 type Vehicle is tagged limited record
kono
parents:
diff changeset
95 Wheels: Natural;
kono
parents:
diff changeset
96 Speed : Natural;
kono
parents:
diff changeset
97 Power_Train: Transmission( Vehicle'Access );
kono
parents:
diff changeset
98 end record;
kono
parents:
diff changeset
99 end C3A0013_1;
kono
parents:
diff changeset
100
kono
parents:
diff changeset
101 with C3A0013_1;
kono
parents:
diff changeset
102 package C3A0013_2 is
kono
parents:
diff changeset
103 type Car is new C3A0013_1.Vehicle with private;
kono
parents:
diff changeset
104 procedure TC_Validate( It : Car;
kono
parents:
diff changeset
105 TC_ID : Character);
kono
parents:
diff changeset
106 function Gear_Factor( It : Car ) return Natural;
kono
parents:
diff changeset
107 private
kono
parents:
diff changeset
108 type Car is new C3A0013_1.Vehicle with record
kono
parents:
diff changeset
109 Displacement : Natural;
kono
parents:
diff changeset
110 end record;
kono
parents:
diff changeset
111 end C3A0013_2;
kono
parents:
diff changeset
112
kono
parents:
diff changeset
113 with C3A0013_1;
kono
parents:
diff changeset
114 package C3A0013_3 is
kono
parents:
diff changeset
115 type Truck is new C3A0013_1.Vehicle with private;
kono
parents:
diff changeset
116 procedure TC_Validate( It : Truck;
kono
parents:
diff changeset
117 TC_ID : Character);
kono
parents:
diff changeset
118 function Gear_Factor( It : Truck ) return Natural;
kono
parents:
diff changeset
119 private
kono
parents:
diff changeset
120 type Truck is new C3A0013_1.Vehicle with record
kono
parents:
diff changeset
121 Displacement : Natural;
kono
parents:
diff changeset
122 end record;
kono
parents:
diff changeset
123 end C3A0013_3;
kono
parents:
diff changeset
124
kono
parents:
diff changeset
125 with Report;
kono
parents:
diff changeset
126 package body C3A0013_1 is
kono
parents:
diff changeset
127
kono
parents:
diff changeset
128 procedure Create ( It : in out Vehicle;
kono
parents:
diff changeset
129 Wheels : Natural := 4 ) is
kono
parents:
diff changeset
130 begin
kono
parents:
diff changeset
131 It.Wheels := Wheels;
kono
parents:
diff changeset
132 It.Speed := 0;
kono
parents:
diff changeset
133 end Create;
kono
parents:
diff changeset
134
kono
parents:
diff changeset
135 procedure Accelerate( It : in out Vehicle ) is
kono
parents:
diff changeset
136 begin
kono
parents:
diff changeset
137 It.Speed := It.Speed + Gear_Factor( It.Power_Train.Within.all );
kono
parents:
diff changeset
138 end Accelerate;
kono
parents:
diff changeset
139
kono
parents:
diff changeset
140 procedure Decelerate( It : in out Vehicle ) is
kono
parents:
diff changeset
141 begin
kono
parents:
diff changeset
142 It.Speed := It.Speed - Gear_Factor( It.Power_Train.Within.all );
kono
parents:
diff changeset
143 end Decelerate;
kono
parents:
diff changeset
144
kono
parents:
diff changeset
145 procedure Stop ( It : in out Vehicle ) is
kono
parents:
diff changeset
146 begin
kono
parents:
diff changeset
147 It.Speed := 0;
kono
parents:
diff changeset
148 It.Power_Train.Engaged := False;
kono
parents:
diff changeset
149 end Stop;
kono
parents:
diff changeset
150
kono
parents:
diff changeset
151 function Gear_Factor( It : Vehicle ) return Natural is
kono
parents:
diff changeset
152 begin
kono
parents:
diff changeset
153 return It.Power_Train.Gear;
kono
parents:
diff changeset
154 end Gear_Factor;
kono
parents:
diff changeset
155
kono
parents:
diff changeset
156 function Speed ( It : Vehicle ) return Natural is
kono
parents:
diff changeset
157 begin
kono
parents:
diff changeset
158 return It.Speed;
kono
parents:
diff changeset
159 end Speed;
kono
parents:
diff changeset
160
kono
parents:
diff changeset
161 function Wheels ( It : Vehicle ) return Natural is
kono
parents:
diff changeset
162 begin
kono
parents:
diff changeset
163 return It.Wheels;
kono
parents:
diff changeset
164 end Wheels;
kono
parents:
diff changeset
165
kono
parents:
diff changeset
166 -- formal tagged parameters are implicitly aliased
kono
parents:
diff changeset
167
kono
parents:
diff changeset
168 procedure TC_Validate( It : in out Vehicle; Speed_Trap : Natural ) is
kono
parents:
diff changeset
169 License: Vehicle_ID := It'Unchecked_Access;
kono
parents:
diff changeset
170 begin
kono
parents:
diff changeset
171 if Speed( License.all ) /= Speed_Trap then
kono
parents:
diff changeset
172 Report.Failed("Speed Trap: expected: " & Natural'Image(Speed_Trap));
kono
parents:
diff changeset
173 end if;
kono
parents:
diff changeset
174 end TC_Validate;
kono
parents:
diff changeset
175
kono
parents:
diff changeset
176 procedure TC_Validate( It : Vehicle;
kono
parents:
diff changeset
177 TC_ID : Character) is
kono
parents:
diff changeset
178 begin
kono
parents:
diff changeset
179 if TC_ID /= 'V' then
kono
parents:
diff changeset
180 Report.Failed("Dispatched to Vehicle");
kono
parents:
diff changeset
181 end if;
kono
parents:
diff changeset
182 if Wheels( It ) /= 1 then
kono
parents:
diff changeset
183 Report.Failed("Not a Vehicle");
kono
parents:
diff changeset
184 end if;
kono
parents:
diff changeset
185 end TC_Validate;
kono
parents:
diff changeset
186
kono
parents:
diff changeset
187 procedure Up_Shift( It: in out Vehicle ) is
kono
parents:
diff changeset
188 begin
kono
parents:
diff changeset
189 It.Power_Train.Gear := It.Power_Train.Gear +1;
kono
parents:
diff changeset
190 It.Power_Train.Engaged := True;
kono
parents:
diff changeset
191 Accelerate( It );
kono
parents:
diff changeset
192 end Up_Shift;
kono
parents:
diff changeset
193 end C3A0013_1;
kono
parents:
diff changeset
194
kono
parents:
diff changeset
195 with Report;
kono
parents:
diff changeset
196 package body C3A0013_2 is
kono
parents:
diff changeset
197
kono
parents:
diff changeset
198 procedure TC_Validate( It : Car;
kono
parents:
diff changeset
199 TC_ID : Character ) is
kono
parents:
diff changeset
200 begin
kono
parents:
diff changeset
201 if TC_ID /= 'C' then
kono
parents:
diff changeset
202 Report.Failed("Dispatched to Car");
kono
parents:
diff changeset
203 end if;
kono
parents:
diff changeset
204 if Wheels( It ) /= 4 then
kono
parents:
diff changeset
205 Report.Failed("Not a Car");
kono
parents:
diff changeset
206 end if;
kono
parents:
diff changeset
207 end TC_Validate;
kono
parents:
diff changeset
208
kono
parents:
diff changeset
209 function Gear_Factor( It : Car ) return Natural is
kono
parents:
diff changeset
210 begin
kono
parents:
diff changeset
211 return C3A0013_1.Gear_Factor( C3A0013_1.Vehicle( It ) )*2;
kono
parents:
diff changeset
212 end Gear_Factor;
kono
parents:
diff changeset
213
kono
parents:
diff changeset
214 end C3A0013_2;
kono
parents:
diff changeset
215
kono
parents:
diff changeset
216 with Report;
kono
parents:
diff changeset
217 package body C3A0013_3 is
kono
parents:
diff changeset
218
kono
parents:
diff changeset
219 procedure TC_Validate( It : Truck;
kono
parents:
diff changeset
220 TC_ID : Character) is
kono
parents:
diff changeset
221 begin
kono
parents:
diff changeset
222 if TC_ID /= 'T' then
kono
parents:
diff changeset
223 Report.Failed("Dispatched to Truck");
kono
parents:
diff changeset
224 end if;
kono
parents:
diff changeset
225 if Wheels( It ) /= 3 then
kono
parents:
diff changeset
226 Report.Failed("Not a Truck");
kono
parents:
diff changeset
227 end if;
kono
parents:
diff changeset
228 end TC_Validate;
kono
parents:
diff changeset
229
kono
parents:
diff changeset
230 function Gear_Factor( It : Truck ) return Natural is
kono
parents:
diff changeset
231 begin
kono
parents:
diff changeset
232 return C3A0013_1.Gear_Factor( C3A0013_1.Vehicle( It ) )*3;
kono
parents:
diff changeset
233 end Gear_Factor;
kono
parents:
diff changeset
234
kono
parents:
diff changeset
235 end C3A0013_3;
kono
parents:
diff changeset
236
kono
parents:
diff changeset
237 package C3A0013_4 is
kono
parents:
diff changeset
238 procedure Perform_Tests;
kono
parents:
diff changeset
239 end C3A0013_4;
kono
parents:
diff changeset
240
kono
parents:
diff changeset
241 with Report;
kono
parents:
diff changeset
242 with C3A0013_1;
kono
parents:
diff changeset
243 with C3A0013_2;
kono
parents:
diff changeset
244 with C3A0013_3;
kono
parents:
diff changeset
245 package body C3A0013_4 is
kono
parents:
diff changeset
246 package Root renames C3A0013_1;
kono
parents:
diff changeset
247 package Cars renames C3A0013_2;
kono
parents:
diff changeset
248 package Trucks renames C3A0013_3;
kono
parents:
diff changeset
249
kono
parents:
diff changeset
250 type Car_Pool is array(1..4) of aliased Cars.Car;
kono
parents:
diff changeset
251 Commuters : Car_Pool;
kono
parents:
diff changeset
252
kono
parents:
diff changeset
253 My_Car : aliased Cars.Car;
kono
parents:
diff changeset
254 Company_Car : Root.Vehicle_ID;
kono
parents:
diff changeset
255 Repair_Shop : Root.Vehicle_ID;
kono
parents:
diff changeset
256
kono
parents:
diff changeset
257 The_Vehicle : Root.Vehicle;
kono
parents:
diff changeset
258 The_Car : Cars.Car;
kono
parents:
diff changeset
259 The_Truck : Trucks.Truck;
kono
parents:
diff changeset
260
kono
parents:
diff changeset
261 procedure TC_Dispatch( Ptr : Root.Vehicle_ID;
kono
parents:
diff changeset
262 Char : Character ) is
kono
parents:
diff changeset
263 begin
kono
parents:
diff changeset
264 Root.TC_Validate( Ptr.all, Char );
kono
parents:
diff changeset
265 end TC_Dispatch;
kono
parents:
diff changeset
266
kono
parents:
diff changeset
267 procedure TC_Check_Formal_Access( Item: in out Root.Vehicle'Class;
kono
parents:
diff changeset
268 Char: Character) is
kono
parents:
diff changeset
269 begin
kono
parents:
diff changeset
270 TC_Dispatch( Item'Unchecked_Access, Char );
kono
parents:
diff changeset
271 end TC_Check_Formal_Access;
kono
parents:
diff changeset
272
kono
parents:
diff changeset
273 procedure Perform_Tests is
kono
parents:
diff changeset
274 begin -- Main test procedure.
kono
parents:
diff changeset
275
kono
parents:
diff changeset
276 for Lane in Commuters'Range loop
kono
parents:
diff changeset
277 Cars.Create( Commuters(Lane) );
kono
parents:
diff changeset
278 for Excitement in 1..Lane loop
kono
parents:
diff changeset
279 Cars.Up_Shift( Commuters(Lane) );
kono
parents:
diff changeset
280 end loop;
kono
parents:
diff changeset
281 end loop;
kono
parents:
diff changeset
282
kono
parents:
diff changeset
283 Cars.Create( My_Car );
kono
parents:
diff changeset
284 Cars.Up_Shift( My_Car );
kono
parents:
diff changeset
285 Cars.TC_Validate( My_Car, 2 );
kono
parents:
diff changeset
286
kono
parents:
diff changeset
287 Root.Create( The_Vehicle, 1 );
kono
parents:
diff changeset
288 Cars.Create( The_Car , 4 );
kono
parents:
diff changeset
289 Trucks.Create( The_Truck, 3 );
kono
parents:
diff changeset
290
kono
parents:
diff changeset
291 TC_Check_Formal_Access( The_Vehicle, 'V' );
kono
parents:
diff changeset
292 TC_Check_Formal_Access( The_Car, 'C' );
kono
parents:
diff changeset
293 TC_Check_Formal_Access( The_Truck, 'T' );
kono
parents:
diff changeset
294
kono
parents:
diff changeset
295 Root.Up_Shift( The_Vehicle );
kono
parents:
diff changeset
296 Cars.Up_Shift( The_Car );
kono
parents:
diff changeset
297 Trucks.Up_Shift( The_Truck );
kono
parents:
diff changeset
298
kono
parents:
diff changeset
299 Root.TC_Validate( The_Vehicle, 1 );
kono
parents:
diff changeset
300 Cars.TC_Validate( The_Car, 2 );
kono
parents:
diff changeset
301 Trucks.TC_Validate( The_Truck, 3 );
kono
parents:
diff changeset
302
kono
parents:
diff changeset
303 -- general access type may reference allocated objects
kono
parents:
diff changeset
304
kono
parents:
diff changeset
305 Company_Car := new Cars.Car;
kono
parents:
diff changeset
306 Root.Create( Company_Car.all );
kono
parents:
diff changeset
307 Root.Up_Shift( Company_Car.all );
kono
parents:
diff changeset
308 Root.Up_Shift( Company_Car.all );
kono
parents:
diff changeset
309 Root.TC_Validate( Company_Car.all, 6 );
kono
parents:
diff changeset
310
kono
parents:
diff changeset
311 -- general access type may reference aliased objects
kono
parents:
diff changeset
312
kono
parents:
diff changeset
313 Repair_Shop := My_Car'Access;
kono
parents:
diff changeset
314 Root.TC_Validate( Repair_Shop.all, 2 );
kono
parents:
diff changeset
315
kono
parents:
diff changeset
316 -- general access type may reference aliased objects
kono
parents:
diff changeset
317
kono
parents:
diff changeset
318 Construction: declare
kono
parents:
diff changeset
319 type Speed_List is array(Commuters'Range) of Natural;
kono
parents:
diff changeset
320 Accelerations : constant Speed_List := (2, 6, 12, 20);
kono
parents:
diff changeset
321 begin
kono
parents:
diff changeset
322 for Rotation in Commuters'Range loop
kono
parents:
diff changeset
323 Repair_Shop := Commuters(Rotation)'Access;
kono
parents:
diff changeset
324 Root.TC_Validate( Repair_Shop.all, Accelerations(Rotation) );
kono
parents:
diff changeset
325 end loop;
kono
parents:
diff changeset
326 end Construction;
kono
parents:
diff changeset
327
kono
parents:
diff changeset
328 end Perform_Tests;
kono
parents:
diff changeset
329
kono
parents:
diff changeset
330 end C3A0013_4;
kono
parents:
diff changeset
331
kono
parents:
diff changeset
332 with C3A0013_4;
kono
parents:
diff changeset
333 with Report;
kono
parents:
diff changeset
334 procedure C3A0013 is
kono
parents:
diff changeset
335 begin
kono
parents:
diff changeset
336
kono
parents:
diff changeset
337 Report.Test ("C3A0013", "Check general access types. Check aliased "
kono
parents:
diff changeset
338 & "nature of formal tagged type parameters. "
kono
parents:
diff changeset
339 & "Check aliased nature of the current "
kono
parents:
diff changeset
340 & "instance of a limited type. Check the "
kono
parents:
diff changeset
341 & "constraining of actual subtypes for "
kono
parents:
diff changeset
342 & "discriminated objects" );
kono
parents:
diff changeset
343
kono
parents:
diff changeset
344 C3A0013_4.Perform_Tests;
kono
parents:
diff changeset
345
kono
parents:
diff changeset
346 Report.Result;
kono
parents:
diff changeset
347 end C3A0013;