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 an explicit declaration in the private part of an instance
28 -- does not override an implicit declaration in the instance, unless the
29 -- corresponding explicit declaration in the generic overrides a
30 -- corresponding implicit declaration in the generic. Check for primitive
31 -- subprograms of tagged types.
34 -- Consider the following:
36 -- type Ancestor is tagged null record;
37 -- procedure R (X: in Ancestor);
40 -- type Formal is new Ancestor with private;
42 -- type T is new Formal with null record;
43 -- -- Implicit procedure R (X: in T);
44 -- procedure P (X: in T); -- (1)
46 -- procedure Q (X: in T); -- (2)
47 -- procedure R (X: in T); -- (3) Overrides implicit R in generic.
50 -- type Actual is new Ancestor with null record;
51 -- procedure P (X: in Actual);
52 -- procedure Q (X: in Actual);
53 -- procedure R (X: in Actual);
55 -- package Instance is new G (Formal => Actual);
57 -- In the instance, the copy of P at (1) overrides Actual's P, since it
58 -- is declared in the visible part of the instance. The copy of Q at (2)
59 -- does not override anything. The copy of R at (3) overrides Actual's
60 -- R, even though it is declared in the private part, because within
61 -- the generic the explicit declaration of R overrides an implicit
64 -- Thus, for calls involving a parameter with tag T:
65 -- - Calls to P will execute the body declared for T.
66 -- - Calls to Q from within Instance will execute the body declared
68 -- - Calls to Q from outside Instance will execute the body declared
70 -- - Calls to R will execute the body declared for T.
72 -- Verify this behavior for both dispatching and nondispatching calls to
77 -- 24 Feb 95 SAIC Initial prerelease version.
83 type TC_Body_Kind
is (Body_Of_Ancestor
, Body_In_Instance
,
84 Body_Of_Actual
, Initial_Value
);
86 type Camera
is tagged record
87 -- ... Camera components.
88 TC_Focus_Called
: TC_Body_Kind
:= Initial_Value
;
89 TC_Shutter_Called
: TC_Body_Kind
:= Initial_Value
;
92 procedure Focus
(C
: in out Camera
);
94 -- ...Other operations.
99 --==================================================================--
102 package body CC30002_0
is
104 procedure Focus
(C
: in out Camera
) is
106 -- Artificial for testing purposes.
107 C
.TC_Focus_Called
:= Body_Of_Ancestor
;
113 --==================================================================--
119 type Camera_Type
is new CC30002_0
.Camera
with private;
122 type Speed_Camera
is new Camera_Type
with record
124 -- ...Other components.
127 -- Implicit procedure Focus (C: in out Speed_Camera) declared in generic.
128 procedure Self_Test_NonDisp
(C
: in out Speed_Camera
);
129 procedure Self_Test_Disp
(C
: in out Speed_Camera
'Class);
133 -- The following explicit declaration of Set_Shutter_Speed does NOT override
134 -- a corresponding implicit declaration in the generic. Therefore, its copy
135 -- does NOT override the implicit declaration (inherited from the actual)
138 procedure Set_Shutter_Speed
(C
: in out Speed_Camera
);
140 -- The following explicit declaration of Focus DOES override a
141 -- corresponding implicit declaration (inherited from the parent) in the
142 -- generic. Therefore, its copy overrides the implicit declaration
143 -- (inherited from the actual) in the instance.
145 procedure Focus
(C
: in out Speed_Camera
); -- Overrides implicit Focus
150 --==================================================================--
153 package body CC30002_1
is
155 procedure Self_Test_NonDisp
(C
: in out Speed_Camera
) is
157 -- Nondispatching calls:
159 Set_Shutter_Speed
(C
);
160 end Self_Test_NonDisp
;
162 procedure Self_Test_Disp
(C
: in out Speed_Camera
'Class) is
164 -- Dispatching calls:
166 Set_Shutter_Speed
(C
);
169 procedure Set_Shutter_Speed
(C
: in out Speed_Camera
) is
171 -- Artificial for testing purposes.
172 C
.TC_Shutter_Called
:= Body_In_Instance
;
173 end Set_Shutter_Speed
;
175 procedure Focus
(C
: in out Speed_Camera
) is
177 -- Artificial for testing purposes.
178 C
.TC_Focus_Called
:= Body_In_Instance
;
184 --==================================================================--
190 type Aperture_Camera
is new CC30002_0
.Camera
with record
192 -- ...Other components.
195 procedure Set_Shutter_Speed
(C
: in out Aperture_Camera
);
196 procedure Focus
(C
: in out Aperture_Camera
);
201 --==================================================================--
204 package body CC30002_2
is
206 procedure Set_Shutter_Speed
(C
: in out Aperture_Camera
) is
209 -- Artificial for testing purposes.
210 C
.TC_Shutter_Called
:= Body_Of_Actual
;
211 end Set_Shutter_Speed
;
213 procedure Focus
(C
: in out Aperture_Camera
) is
216 -- Artificial for testing purposes.
217 C
.TC_Focus_Called
:= Body_Of_Actual
;
223 --==================================================================--
226 -- Instance declaration.
230 package CC30002_3
is new CC30002_1
(Camera_Type
=> CC30002_2
.Aperture_Camera
);
233 --==================================================================--
239 with CC30002_3
; -- Instance.
244 package Speed_Cameras
renames CC30002_3
;
248 TC_Camera1
: Speed_Cameras
.Speed_Camera
;
249 TC_Camera2
: Speed_Cameras
.Speed_Camera
'Class := TC_Camera1
;
250 TC_Camera3
: Speed_Cameras
.Speed_Camera
;
251 TC_Camera4
: Speed_Cameras
.Speed_Camera
;
254 Report
.Test
("CC30002", "Check that an explicit declaration in the " &
255 "private part of an instance does not override an implicit " &
256 "declaration in the instance, unless the corresponding " &
257 "explicit declaration in the generic overrides a " &
258 "corresponding implicit declaration in the generic. Check " &
259 "for primitive subprograms of tagged types");
262 -- Check non-dispatching calls outside instance:
265 -- Non-overriding primitive operation:
267 Speed_Cameras
.Set_Shutter_Speed
(TC_Camera1
);
268 if TC_Camera1
.TC_Shutter_Called
/= Body_Of_Actual
then
269 Report
.Failed
("Wrong body executed: non-dispatching call to " &
270 "Set_Shutter_Speed outside instance");
274 -- Overriding primitive operation:
276 Speed_Cameras
.Focus
(TC_Camera1
);
277 if TC_Camera1
.TC_Focus_Called
/= Body_In_Instance
then
278 Report
.Failed
("Wrong body executed: non-dispatching call to " &
279 "Focus outside instance");
284 -- Check dispatching calls outside instance:
287 -- Non-overriding primitive operation:
289 Speed_Cameras
.Set_Shutter_Speed
(TC_Camera2
);
290 if TC_Camera2
.TC_Shutter_Called
/= Body_Of_Actual
then
291 Report
.Failed
("Wrong body executed: dispatching call to " &
292 "Set_Shutter_Speed outside instance");
296 -- Overriding primitive operation:
298 Speed_Cameras
.Focus
(TC_Camera2
);
299 if TC_Camera2
.TC_Focus_Called
/= Body_In_Instance
then
300 Report
.Failed
("Wrong body executed: dispatching call to " &
301 "Focus outside instance");
307 -- Check non-dispatching calls within instance:
310 Speed_Cameras
.Self_Test_NonDisp
(TC_Camera3
);
312 -- Non-overriding primitive operation:
314 if TC_Camera3
.TC_Shutter_Called
/= Body_In_Instance
then
315 Report
.Failed
("Wrong body executed: non-dispatching call to " &
316 "Set_Shutter_Speed inside instance");
319 -- Overriding primitive operation:
321 if TC_Camera3
.TC_Focus_Called
/= Body_In_Instance
then
322 Report
.Failed
("Wrong body executed: non-dispatching call to " &
323 "Focus inside instance");
329 -- Check dispatching calls within instance:
332 Speed_Cameras
.Self_Test_Disp
(TC_Camera4
);
334 -- Non-overriding primitive operation:
336 if TC_Camera4
.TC_Shutter_Called
/= Body_In_Instance
then
337 Report
.Failed
("Wrong body executed: dispatching call to " &
338 "Set_Shutter_Speed inside instance");
341 -- Overriding primitive operation:
343 if TC_Camera4
.TC_Focus_Called
/= Body_In_Instance
then
344 Report
.Failed
("Wrong body executed: dispatching call to " &
345 "Focus inside instance");