1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
|
-- CC30002.A
--
-- Grant of Unlimited Rights
--
-- Under contracts F33600-87-D-0337, F33600-84-D-0280, MDA903-79-C-0687,
-- F08630-91-C-0015, and DCA100-97-D-0025, the U.S. Government obtained
-- unlimited rights in the software and documentation contained herein.
-- Unlimited rights are defined in DFAR 252.227-7013(a)(19). By making
-- this public release, the Government intends to confer upon all
-- recipients unlimited rights equal to those held by the Government.
-- These rights include rights to use, duplicate, release or disclose the
-- released technical data and computer software in whole or in part, in
-- any manner and for any purpose whatsoever, and to have or permit others
-- to do so.
--
-- DISCLAIMER
--
-- ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR
-- DISCLOSED ARE AS IS. THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED
-- WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE
-- SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE
-- OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A
-- PARTICULAR PURPOSE OF SAID MATERIAL.
--*
--
-- OBJECTIVE:
-- Check that an explicit declaration in the private part of an instance
-- does not override an implicit declaration in the instance, unless the
-- corresponding explicit declaration in the generic overrides a
-- corresponding implicit declaration in the generic. Check for primitive
-- subprograms of tagged types.
--
-- TEST DESCRIPTION:
-- Consider the following:
--
-- type Ancestor is tagged null record;
-- procedure R (X: in Ancestor);
--
-- generic
-- type Formal is new Ancestor with private;
-- package G is
-- type T is new Formal with null record;
-- -- Implicit procedure R (X: in T);
-- procedure P (X: in T); -- (1)
-- private
-- procedure Q (X: in T); -- (2)
-- procedure R (X: in T); -- (3) Overrides implicit R in generic.
-- end G;
--
-- type Actual is new Ancestor with null record;
-- procedure P (X: in Actual);
-- procedure Q (X: in Actual);
-- procedure R (X: in Actual);
--
-- package Instance is new G (Formal => Actual);
--
-- In the instance, the copy of P at (1) overrides Actual's P, since it
-- is declared in the visible part of the instance. The copy of Q at (2)
-- does not override anything. The copy of R at (3) overrides Actual's
-- R, even though it is declared in the private part, because within
-- the generic the explicit declaration of R overrides an implicit
-- declaration.
--
-- Thus, for calls involving a parameter with tag T:
-- - Calls to P will execute the body declared for T.
-- - Calls to Q from within Instance will execute the body declared
-- for T.
-- - Calls to Q from outside Instance will execute the body declared
-- for Actual.
-- - Calls to R will execute the body declared for T.
--
-- Verify this behavior for both dispatching and nondispatching calls to
-- Q and R.
--
--
-- CHANGE HISTORY:
-- 24 Feb 95 SAIC Initial prerelease version.
--
--!
package CC30002_0 is
type TC_Body_Kind is (Body_Of_Ancestor, Body_In_Instance,
Body_Of_Actual, Initial_Value);
type Camera is tagged record
-- ... Camera components.
TC_Focus_Called : TC_Body_Kind := Initial_Value;
TC_Shutter_Called : TC_Body_Kind := Initial_Value;
end record;
procedure Focus (C: in out Camera);
-- ...Other operations.
end CC30002_0;
--==================================================================--
package body CC30002_0 is
procedure Focus (C: in out Camera) is
begin
-- Artificial for testing purposes.
C.TC_Focus_Called := Body_Of_Ancestor;
end Focus;
end CC30002_0;
--==================================================================--
with CC30002_0;
use CC30002_0;
generic
type Camera_Type is new CC30002_0.Camera with private;
package CC30002_1 is
type Speed_Camera is new Camera_Type with record
Diag_Code: Positive;
-- ...Other components.
end record;
-- Implicit procedure Focus (C: in out Speed_Camera) declared in generic.
procedure Self_Test_NonDisp (C: in out Speed_Camera);
procedure Self_Test_Disp (C: in out Speed_Camera'Class);
private
-- The following explicit declaration of Set_Shutter_Speed does NOT override
-- a corresponding implicit declaration in the generic. Therefore, its copy
-- does NOT override the implicit declaration (inherited from the actual)
-- in the instance.
procedure Set_Shutter_Speed (C: in out Speed_Camera);
-- The following explicit declaration of Focus DOES override a
-- corresponding implicit declaration (inherited from the parent) in the
-- generic. Therefore, its copy overrides the implicit declaration
-- (inherited from the actual) in the instance.
procedure Focus (C: in out Speed_Camera); -- Overrides implicit Focus
-- in generic.
end CC30002_1;
--==================================================================--
package body CC30002_1 is
procedure Self_Test_NonDisp (C: in out Speed_Camera) is
begin
-- Nondispatching calls:
Focus (C);
Set_Shutter_Speed (C);
end Self_Test_NonDisp;
procedure Self_Test_Disp (C: in out Speed_Camera'Class) is
begin
-- Dispatching calls:
Focus (C);
Set_Shutter_Speed (C);
end Self_Test_Disp;
procedure Set_Shutter_Speed (C: in out Speed_Camera) is
begin
-- Artificial for testing purposes.
C.TC_Shutter_Called := Body_In_Instance;
end Set_Shutter_Speed;
procedure Focus (C: in out Speed_Camera) is
begin
-- Artificial for testing purposes.
C.TC_Focus_Called := Body_In_Instance;
end Focus;
end CC30002_1;
--==================================================================--
with CC30002_0;
package CC30002_2 is
type Aperture_Camera is new CC30002_0.Camera with record
FStop: Natural;
-- ...Other components.
end record;
procedure Set_Shutter_Speed (C: in out Aperture_Camera);
procedure Focus (C: in out Aperture_Camera);
end CC30002_2;
--==================================================================--
package body CC30002_2 is
procedure Set_Shutter_Speed (C: in out Aperture_Camera) is
use CC30002_0;
begin
-- Artificial for testing purposes.
C.TC_Shutter_Called := Body_Of_Actual;
end Set_Shutter_Speed;
procedure Focus (C: in out Aperture_Camera) is
use CC30002_0;
begin
-- Artificial for testing purposes.
C.TC_Focus_Called := Body_Of_Actual;
end Focus;
end CC30002_2;
--==================================================================--
-- Instance declaration.
with CC30002_1;
with CC30002_2;
package CC30002_3 is new CC30002_1 (Camera_Type => CC30002_2.Aperture_Camera);
--==================================================================--
with CC30002_0;
with CC30002_1;
with CC30002_2;
with CC30002_3; -- Instance.
with Report;
procedure CC30002 is
package Speed_Cameras renames CC30002_3;
use CC30002_0;
TC_Camera1: Speed_Cameras.Speed_Camera;
TC_Camera2: Speed_Cameras.Speed_Camera'Class := TC_Camera1;
TC_Camera3: Speed_Cameras.Speed_Camera;
TC_Camera4: Speed_Cameras.Speed_Camera;
begin
Report.Test ("CC30002", "Check that an explicit declaration in the " &
"private part of an instance does not override an implicit " &
"declaration in the instance, unless the corresponding " &
"explicit declaration in the generic overrides a " &
"corresponding implicit declaration in the generic. Check " &
"for primitive subprograms of tagged types");
--
-- Check non-dispatching calls outside instance:
--
-- Non-overriding primitive operation:
Speed_Cameras.Set_Shutter_Speed (TC_Camera1);
if TC_Camera1.TC_Shutter_Called /= Body_Of_Actual then
Report.Failed ("Wrong body executed: non-dispatching call to " &
"Set_Shutter_Speed outside instance");
end if;
-- Overriding primitive operation:
Speed_Cameras.Focus (TC_Camera1);
if TC_Camera1.TC_Focus_Called /= Body_In_Instance then
Report.Failed ("Wrong body executed: non-dispatching call to " &
"Focus outside instance");
end if;
--
-- Check dispatching calls outside instance:
--
-- Non-overriding primitive operation:
Speed_Cameras.Set_Shutter_Speed (TC_Camera2);
if TC_Camera2.TC_Shutter_Called /= Body_Of_Actual then
Report.Failed ("Wrong body executed: dispatching call to " &
"Set_Shutter_Speed outside instance");
end if;
-- Overriding primitive operation:
Speed_Cameras.Focus (TC_Camera2);
if TC_Camera2.TC_Focus_Called /= Body_In_Instance then
Report.Failed ("Wrong body executed: dispatching call to " &
"Focus outside instance");
end if;
--
-- Check non-dispatching calls within instance:
--
Speed_Cameras.Self_Test_NonDisp (TC_Camera3);
-- Non-overriding primitive operation:
if TC_Camera3.TC_Shutter_Called /= Body_In_Instance then
Report.Failed ("Wrong body executed: non-dispatching call to " &
"Set_Shutter_Speed inside instance");
end if;
-- Overriding primitive operation:
if TC_Camera3.TC_Focus_Called /= Body_In_Instance then
Report.Failed ("Wrong body executed: non-dispatching call to " &
"Focus inside instance");
end if;
--
-- Check dispatching calls within instance:
--
Speed_Cameras.Self_Test_Disp (TC_Camera4);
-- Non-overriding primitive operation:
if TC_Camera4.TC_Shutter_Called /= Body_In_Instance then
Report.Failed ("Wrong body executed: dispatching call to " &
"Set_Shutter_Speed inside instance");
end if;
-- Overriding primitive operation:
if TC_Camera4.TC_Focus_Called /= Body_In_Instance then
Report.Failed ("Wrong body executed: dispatching call to " &
"Focus inside instance");
end if;
Report.Result;
end CC30002;
|