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 separate protected unit declared in a non-generic child
28 -- unit of a private parent have the same visibility into its parent,
29 -- its siblings, and packages on which its parent depends as is available
30 -- at the point of their declaration.
33 -- A scenario is created that demonstrates the potential of having all
34 -- members of one family to take out a transportation. The restriction
35 -- is depend on each member to determine who can get a car, a clunker,
36 -- or a bicycle. If no transportation is available, that member has to
39 -- Declare a package with location for each family member. Declare
40 -- a public parent package. Declare a private child package. Declare a
41 -- public grandchild of this private package. Declare a protected unit
42 -- as a subunit in a public grandchild package. This subunit has
43 -- visibility into it's parent body ancestor and its sibling.
45 -- Declare another public parent package. The body of this package has
46 -- visibility into its private sibling's descendants.
48 -- In the main program, "with"s the parent package. Check that the
49 -- protected subunit performs as expected.
53 -- 06 Dec 94 SAIC ACVC 2.0
54 -- 16 Nov 95 SAIC Update and repair for ACVC 2.0.1
60 type Location
is (School
, Work
, Beach
, Home
);
61 type Family
is (Father
, Mother
, Teen
);
62 Destination
: array (Family
) of Location
;
64 -- Other type definitions and procedure declarations in real application.
68 -- No bodies required for CA13001_0.
70 --==================================================================--
76 type Transportation
is (Bicycle
, Clunker
, New_Car
);
77 type Key_Type
is private;
78 Walking
: boolean := false;
80 -- Other type definitions and procedure declarations in real application.
84 is range Transportation
'pos(Bicycle
) .. Transportation
'pos(New_Car
);
88 -- No bodies required for CA13001_1.
90 --==================================================================--
94 private package CA13001_1
.CA13001_2
is
98 In_Use
: boolean := false;
100 Vehicles
: array (Transportation
) of Transport
;
102 -- Other type definitions and procedure declarations in real application.
104 end CA13001_1
.CA13001_2
;
106 -- No bodies required for CA13001_1.CA13001_2.
108 --==================================================================--
110 -- Public grandchild of a private parent.
112 package CA13001_1
.CA13001_2
.CA13001_3
is
114 Flat_Tire
: array (Transportation
) of boolean := (others => false);
116 -- Other type definitions and procedure declarations in real application.
118 end CA13001_1
.CA13001_2
.CA13001_3
;
120 -- No bodies required for CA13001_1.CA13001_2.CA13001_3.
122 --==================================================================--
124 -- Context clauses required for visibility needed by a separate subunit.
129 -- Public grandchild of a private parent.
131 package CA13001_1
.CA13001_2
.CA13001_4
is
135 Available
: boolean := false;
137 type Keys_Array
is array (Transportation
) of Transit
;
138 Fuel
: array (Transportation
) of boolean := (others => true);
140 protected Family_Transportation
is
142 procedure Get_Vehicle
(Who
: in Family
;
144 procedure Return_Vehicle
(Tr
: in Transportation
);
145 function TC_Verify
(What
: Transportation
) return boolean;
150 end Family_Transportation
;
152 end CA13001_1
.CA13001_2
.CA13001_4
;
154 --==================================================================--
156 -- Context clause required for visibility needed by a separate subunit.
158 with CA13001_1
.CA13001_2
.CA13001_3
; -- Public sibling.
160 package body CA13001_1
.CA13001_2
.CA13001_4
is
162 protected body Family_Transportation
is separate;
164 end CA13001_1
.CA13001_2
.CA13001_4
;
166 --==================================================================--
168 separate (CA13001_1
.CA13001_2
.CA13001_4
)
169 protected body Family_Transportation
is
171 procedure Get_Vehicle
(Who
: in Family
;
172 Key
: out Key_Type
) is
175 when Father|Mother
=>
176 -- Drive new car to work
178 -- Reference package with'ed by the subunit parent's body.
179 if Destination
(Who
) = Work
then
181 -- Reference type declared in the private parent of the subunit
183 -- Reference type declared in the visible part of the
184 -- subunit parent's body.
185 if not Vehicles
(New_Car
).In_Use
and Fuel
(New_Car
)
187 -- Reference type declared in the public sibling of the
188 -- subunit parent's body.
189 and not CA13001_1
.CA13001_2
.CA13001_3
.Flat_Tire
(New_Car
) then
190 Vehicles
(New_Car
).In_Use
:= true;
192 -- Reference type declared in the private part of the
193 -- protected subunit.
194 Keys
(New_Car
).Available
:= false;
195 Key
:= Transportation
'pos(New_Car
);
197 -- Reference type declared in the grandparent of the subunit
202 -- Drive clunker to other destinations.
204 if not Vehicles
(Clunker
).In_Use
and Fuel
(Clunker
) and not
205 CA13001_1
.CA13001_2
.CA13001_3
.Flat_Tire
(Clunker
) then
206 Vehicles
(Clunker
).In_Use
:= true;
207 Keys
(Clunker
).Available
:= false;
208 Key
:= Transportation
'pos(Clunker
);
211 Key
:= Transportation
'pos(Bicycle
);
217 if not Vehicles
(Clunker
).In_Use
and Fuel
(Clunker
) and not
218 CA13001_1
.CA13001_2
.CA13001_3
.Flat_Tire
(Clunker
) then
219 Vehicles
(Clunker
).In_Use
:= true;
220 Keys
(Clunker
).Available
:= false;
221 Key
:= Transportation
'pos(Clunker
);
224 Key
:= Transportation
'pos(Bicycle
);
230 ----------------------------------------------------------------
232 -- Any family member can bring back the transportation with the key.
234 procedure Return_Vehicle
(Tr
: in Transportation
) is
236 Vehicles
(Tr
).In_Use
:= false;
237 Keys
(Tr
).Available
:= true;
240 ----------------------------------------------------------------
242 function TC_Verify
(What
: Transportation
) return boolean is
244 return Keys
(What
).Available
;
247 end Family_Transportation
;
249 --==================================================================--
256 package CA13001_1
.CA13001_5
is
258 -- In a real application, tasks could be used to demonstrate
259 -- a family transportation scenario, i.e., each member of
260 -- a family can take a vehicle out concurrently, then return
261 -- them at the same time. For the purposes of the test, family
262 -- transportation happens sequentially.
264 procedure Provide_Transportation
(Who
: in Family
;
265 Get_Key
: out Key_Type
;
266 Get_Veh
: out boolean);
267 procedure Return_Transportation
(What
: in Transportation
;
268 Rt_Veh
: out boolean);
270 end CA13001_1
.CA13001_5
;
272 --==================================================================--
274 with CA13001_1
.CA13001_2
.CA13001_4
; -- Public grandchild of a private parent,
275 -- implicitly with CA13001_1.CA13001_2.
276 package body CA13001_1
.CA13001_5
is
278 package Transportation_Pkg
renames CA13001_1
.CA13001_2
.CA13001_4
;
279 use Transportation_Pkg
;
281 -- These two validation subprograms provide the capability to check the
282 -- components defined in the private packages from within the client
285 procedure Provide_Transportation
(Who
: in Family
;
286 Get_Key
: out Key_Type
;
287 Get_Veh
: out boolean) is
289 -- Goto work, school, or to the beach.
290 Family_Transportation
.Get_Vehicle
(Who
, Get_Key
);
291 if not Family_Transportation
.TC_Verify
292 (Transportation
'Val(Get_Key
)) then
298 end Provide_Transportation
;
300 ----------------------------------------------------------------
302 procedure Return_Transportation
(What
: in Transportation
;
303 Rt_Veh
: out boolean) is
305 Family_Transportation
.Return_Vehicle
(What
);
306 if Family_Transportation
.TC_Verify
(What
) and
307 not CA13001_1
.CA13001_2
.Vehicles
(What
).In_Use
then
313 end Return_Transportation
;
315 end CA13001_1
.CA13001_5
;
317 --==================================================================--
320 with CA13001_1
.CA13001_5
; -- Implicitly with parent, CA13001_1.
325 Mommy
: CA13001_0
.Family
:= CA13001_0
.Mother
;
326 Daddy
: CA13001_0
.Family
:= CA13001_0
.Father
;
327 BG
: CA13001_0
.Family
:= CA13001_0
.Teen
;
328 BG_Clunker
: CA13001_1
.Transportation
:= CA13001_1
.Clunker
;
329 Get_Key
: CA13001_1
.Key_Type
;
330 Get_Transit
: boolean := false;
331 Return_Transit
: boolean := false;
334 Report
.Test
("CA13001", "Check that a protected subunit declared in " &
335 "a child unit of a private parent have the same visibility " &
336 "into its parent, its parent's siblings, and packages on " &
337 "which its parent depends");
339 -- Get transportation for mother to go to work.
340 CA13001_0
.Destination
(CA13001_0
.Mother
) := CA13001_0
.Work
;
341 CA13001_1
.CA13001_5
.Provide_Transportation
(Mommy
, Get_Key
, Get_Transit
);
342 if not Get_Transit
then
343 Report
.Failed
("Failed to get mother transportation");
346 -- Get transportation for teen to go to school.
347 CA13001_0
.Destination
(CA13001_0
.Teen
) := CA13001_0
.School
;
348 Get_Transit
:= false;
349 CA13001_1
.CA13001_5
.Provide_Transportation
(BG
, Get_Key
, Get_Transit
);
350 if not Get_Transit
then
351 Report
.Failed
("Failed to get teen transportation");
354 -- Get transportation for father to go to the beach.
355 CA13001_0
.Destination
(CA13001_0
.Father
) := CA13001_0
.Beach
;
356 Get_Transit
:= false;
357 CA13001_1
.CA13001_5
.Provide_Transportation
(Daddy
, Get_Key
, Get_Transit
);
358 if Get_Transit
and not CA13001_1
.Walking
then
359 Report
.Failed
("Failed to make daddy to walk to the beach");
362 -- Return the clunker.
363 CA13001_1
.CA13001_5
.Return_Transportation
(BG_Clunker
, Return_Transit
);
364 if not Return_Transit
then
365 Report
.Failed
("Failed to get back the clunker");