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, for an implicitly declared dispatching operation that is
28 -- overridden, the body executed is the body for the overriding
29 -- subprogram, even if the overriding occurs in a private part.
31 -- Check for the case where the overriding operations are declared in a
32 -- public child unit of the package declaring the parent type, and the
33 -- descendant type is a private extension.
35 -- Check for both dispatching and nondispatching calls.
42 -- type Root is tagged ...
43 -- procedure Vis_Op (P: Root);
45 -- procedure Pri_Op (P: Root);
48 -- package Parent.Child is
49 -- type Derived is new Root with private;
50 -- -- Implicit Vis_Op (P: Derived) declared here.
52 -- procedure Pri_Op (P: Derived); -- (A)
55 -- type Derived is new Root with record...
56 -- -- Implicit Pri_Op (P: Derived) declared here.
58 -- procedure Vis_Op (P: Derived); -- (B)
62 -- Type Derived inherits both Vis_Op and Pri_Op from the ancestor type
63 -- Root. Note, however, that Vis_Op is implicitly declared in the visible
64 -- part, whereas Pri_Op is implicitly declared in the private part
65 -- (inherited subprograms for a private extension are implicitly declared
66 -- after the private_extension_declaration if the corresponding
67 -- declaration from the ancestor is visible at that place; otherwise the
68 -- inherited subprogram is not declared for the private extension,
69 -- although it might be for the full type).
71 -- Even though Root's version of Pri_Op hasn't been implicitly declared
72 -- for Derived at the time Derived's version of Pri_Op has been
73 -- explicitly declared, the explicit Pri_Op still overrides the implicit
75 -- Also, even though the explicit Vis_Op for Derived is declared in the
76 -- private part it still overrides the implicit version declared in the
77 -- visible part. Calls with tag Derived will execute (A) and (B).
81 -- 06 Dec 94 SAIC ACVC 2.0
82 -- 26 Nov 96 SAIC Improved for ACVC 2.1
88 type Remote_Camera
is tagged private;
90 type Depth_Of_Field
is range 5 .. 100;
91 type Shutter_Speed
is (One
, Two_Fifty
, Four_Hundred
, Thousand
);
92 type Aperture
is (Eight
, Sixteen
, Thirty_Two
);
94 -- ...Other declarations.
96 procedure Focus
(Cam
: in out Remote_Camera
;
97 Depth
: in Depth_Of_Field
);
99 procedure Self_Test
(C
: in out Remote_Camera
'Class);
101 -- ...Other operations.
103 function TC_Get_Depth
(C
: Remote_Camera
) return Depth_Of_Field
;
104 function TC_Get_Speed
(C
: Remote_Camera
) return Shutter_Speed
;
108 type Remote_Camera
is tagged record
109 DOF
: Depth_Of_Field
:= 10;
110 Shutter
: Shutter_Speed
:= One
;
111 FStop
: Aperture
:= Eight
;
114 procedure Set_Shutter_Speed
(C
: in out Remote_Camera
;
115 Speed
: in Shutter_Speed
);
117 -- For the basic remote camera, shutter speed might be set as a function of
118 -- focus perhaps, thus it is declared as a private operation (usable
119 -- only internally within the abstraction).
121 function Set_Aperture
(C
: Remote_Camera
) return Aperture
;
126 --==================================================================--
129 package body C392005_0
is
131 procedure Focus
(Cam
: in out Remote_Camera
;
132 Depth
: in Depth_Of_Field
) is
134 -- Artificial for testing purposes.
138 -----------------------------------------------------------
139 procedure Set_Shutter_Speed
(C
: in out Remote_Camera
;
140 Speed
: in Shutter_Speed
) is
142 -- Artificial for testing purposes.
143 C
.Shutter
:= Thousand
;
144 end Set_Shutter_Speed
;
146 -----------------------------------------------------------
147 function Set_Aperture
(C
: Remote_Camera
) return Aperture
is
149 -- Artificial for testing purposes.
153 -----------------------------------------------------------
154 procedure Self_Test
(C
: in out Remote_Camera
'Class) is
155 TC_Dummy_Depth
: constant Depth_Of_Field
:= 23;
156 TC_Dummy_Speed
: constant Shutter_Speed
:= Four_Hundred
;
159 -- Test focus at various depths:
160 Focus
(C
, TC_Dummy_Depth
);
161 -- ...Additional calls to Focus.
163 -- Test various shutter speeds:
164 Set_Shutter_Speed
(C
, TC_Dummy_Speed
);
165 -- ...Additional calls to Set_Shutter_Speed.
169 -----------------------------------------------------------
170 function TC_Get_Depth
(C
: Remote_Camera
) return Depth_Of_Field
is
175 -----------------------------------------------------------
176 function TC_Get_Speed
(C
: Remote_Camera
) return Shutter_Speed
is
183 --==================================================================--
186 package C392005_0
.C392005_1
is
188 type Auto_Speed
is new Remote_Camera
with private;
191 -- procedure Focus (C : in out Auto_Speed; -- Implicitly declared
192 -- Depth : in Depth_Of_Field) -- here.
194 -- For the improved remote camera, shutter speed can be set manually,
195 -- so it is declared as a public operation.
197 -- The order of declarations for Set_Aperture and Set_Shutter_Speed are
198 -- reversed from the original declarations to trap potential compiler
199 -- problems related to subprogram ordering.
201 function Set_Aperture
(C
: Auto_Speed
) return Aperture
; -- Overrides
204 procedure Set_Shutter_Speed
(C
: in out Auto_Speed
; -- Overrides
205 Speed
: in Shutter_Speed
);-- inherited op.
207 -- Set_Shutter_Speed and Set_Aperture override the operations inherited
208 -- from the parent, even though the inherited operations are not implicitly
209 -- declared until the private part below.
211 type New_Camera
is private;
213 function TC_Get_Aper
(C
: New_Camera
) return Aperture
;
215 -- ...Other operations.
218 type Film_Speed
is (One_Hundred
, Two_Hundred
, Four_Hundred
);
220 type Auto_Speed
is new Remote_Camera
with record
224 -- procedure Set_Shutter_Speed (C : in out Auto_Speed; -- Implicitly
225 -- Speed : in Shutter_Speed) -- declared
228 -- function Set_Aperture (C : Auto_Speed) return Aperture; -- Implicitly
231 procedure Focus
(C
: in out Auto_Speed
; -- Overrides
232 Depth
: in Depth_Of_Field
); -- inherited op.
234 -- For the improved remote camera, perhaps the focusing algorithm is
235 -- different, so the original Focus operation is overridden here.
237 Auto_Camera
: Auto_Speed
;
239 type New_Camera
is record
240 Aper
: Aperture
:= Set_Aperture
(Auto_Camera
); -- Calls the overridden,
241 end record; -- not the inherited op.
243 end C392005_0
.C392005_1
;
246 --==================================================================--
249 package body C392005_0
.C392005_1
is
251 procedure Focus
(C
: in out Auto_Speed
;
252 Depth
: in Depth_Of_Field
) is
254 -- Artificial for testing purposes.
258 ---------------------------------------------------------------
259 procedure Set_Shutter_Speed
(C
: in out Auto_Speed
;
260 Speed
: in Shutter_Speed
) is
262 -- Artificial for testing purposes.
263 C
.Shutter
:= Two_Fifty
;
264 end Set_Shutter_Speed
;
266 -----------------------------------------------------------
267 function Set_Aperture
(C
: Auto_Speed
) return Aperture
is
269 -- Artificial for testing purposes.
273 -----------------------------------------------------------
274 function TC_Get_Aper
(C
: New_Camera
) return Aperture
is
279 end C392005_0
.C392005_1
;
282 --==================================================================--
285 with C392005_0
.C392005_1
;
290 Basic_Camera
: C392005_0
.Remote_Camera
;
291 Auto_Camera1
: C392005_0
.C392005_1
.Auto_Speed
;
292 Auto_Camera2
: C392005_0
.C392005_1
.Auto_Speed
;
293 Auto_Depth
: C392005_0
.Depth_Of_Field
:= 67;
294 New_Camera1
: C392005_0
.C392005_1
.New_Camera
;
295 TC_Expected_Basic_Depth
: constant C392005_0
.Depth_Of_Field
:= 46;
296 TC_Expected_Auto_Depth
: constant C392005_0
.Depth_Of_Field
:= 57;
297 TC_Expected_Basic_Speed
: constant C392005_0
.Shutter_Speed
298 := C392005_0
.Thousand
;
299 TC_Expected_Auto_Speed
: constant C392005_0
.Shutter_Speed
300 := C392005_0
.Two_Fifty
;
301 TC_Expected_New_Aper
: constant C392005_0
.Aperture
302 := C392005_0
.Sixteen
;
304 use type C392005_0
.Depth_Of_Field
;
305 use type C392005_0
.Shutter_Speed
;
306 use type C392005_0
.Aperture
;
309 Report
.Test
("C392005", "Dispatching for overridden primitive " &
310 "subprograms: private extension declared in child unit, " &
311 "parent is tagged private whose full view is tagged record");
313 -- Call the class-wide operation for Remote_Camera'Class, which itself makes
314 -- dispatching calls to Focus and Set_Shutter_Speed:
317 -- For an object of type Remote_Camera, the dispatching calls should
318 -- dispatch to the bodies declared for the root type:
320 C392005_0
.Self_Test
(Basic_Camera
);
322 if C392005_0
.TC_Get_Depth
(Basic_Camera
) /= TC_Expected_Basic_Depth
323 or else C392005_0
.TC_Get_Speed
(Basic_Camera
) /= TC_Expected_Basic_Speed
325 Report
.Failed
("Calls dispatched incorrectly for root type");
329 -- For an object of type Auto_Speed, the dispatching calls should
330 -- dispatch to the bodies declared for the derived type:
332 C392005_0
.Self_Test
(Auto_Camera1
);
334 if C392005_0
.C392005_1
.TC_Get_Depth
(Auto_Camera1
) /= TC_Expected_Auto_Depth
337 C392005_0
.C392005_1
.TC_Get_Speed
(Auto_Camera1
) /= TC_Expected_Auto_Speed
339 Report
.Failed
("Calls dispatched incorrectly for derived type");
342 -- For an object of type Auto_Speed, a non-dispatching call to Focus should
344 -- execute the body declared for the derived type (even through it is
345 -- declared in the private part).
347 C392005_0
.C392005_1
.Focus
(Auto_Camera2
, Auto_Depth
);
349 if C392005_0
.C392005_1
.TC_Get_Depth
(Auto_Camera2
) /= TC_Expected_Auto_Depth
352 Report
.Failed
("Non-dispatching call to privately overriding " &
353 "subprogram executed the wrong body");
356 -- For an object of type New_Camera, the initialization using Set_Ap
357 -- should execute the overridden body, not the inherited one.
359 if C392005_0
.C392005_1
.TC_Get_Aper
(New_Camera1
) /= TC_Expected_New_Aper
361 Report
.Failed
("Non-dispatching call to visible overriding " &
362 "subprogram executed the wrong body");