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
|
-- C640001.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 the prefix of a subprogram call with an actual parameter
-- part may be an implicit dereference of an access-to-subprogram value.
-- Check that, for an access-to-subprogram type whose designated profile
-- contains parameters of a tagged generic formal type, an access-to-
-- subprogram value may designate dispatching and non-dispatching
-- operations, and that dereferences of such a value call the appropriate
-- subprogram.
--
-- TEST DESCRIPTION:
-- The test declares a tagged type (Table) with a dispatching operation
-- (Clear), as well as a derivative (Table2) which overrides that
-- operation. A subprogram with the same name and profile as Clear is
-- declared in a separate package -- it is therefore not a dispatching
-- operation of Table. For the purposes of the test, each version of Clear
-- modifies the components of its parameter in a unique way.
--
-- Additionally, an operation (Reset) of type Table is declared which
-- makes a re-dispatching call to Clear, i.e.,
--
-- procedure Reset (A: in out Table) is
-- begin
-- ...
-- Clear (Table'Class(A)); -- Re-dispatch based on tag of actual.
-- ...
-- end Reset;
--
-- An access-to-subprogram type is declared within a generic package,
-- with a designated profile which declares a parameter of a generic
-- formal tagged private type.
--
-- The generic is instantiated with type Table. The instance defines an
-- array of access-to-subprogram values (which represents a table of
-- operations to be performed sequentially on a single operand).
-- Access values designating the dispatching version of Clear, the
-- non-dispatching version of Clear, and Reset (which re-dispatches to
-- Clear) are placed in this array.
--
-- In the instance, each subprogram in the array is called by implicitly
-- dereferencing the corresponding access value. For the dispatching and
-- non-dispatching versions of Clear, the actual parameter passed is of
-- type Table. For Reset, the actual parameter passed is a view conversion
-- of an object of type Table2 to type Table, i.e., Table(Table2_Obj).
-- Since the tag of the operand never changes, the call to Clear within
-- Reset should execute Table2's version of Clear.
--
-- The main program verifies that the appropriate version of Clear is
-- called in each case, by checking that the components of the actual are
-- updated as expected.
--
--
-- CHANGE HISTORY:
-- 06 Dec 94 SAIC ACVC 2.0
--
--!
package C640001_0 is
-- Data type artificial for testing purposes.
Row_Len : constant := 10;
T : constant Boolean := True;
F : constant Boolean := False;
type Row_Type is array (1 .. Row_Len) of Boolean;
function Is_True (A : in Row_Type) return Boolean;
function Is_False (A : in Row_Type) return Boolean;
Init : constant Row_Type := (T, F, T, F, T, F, T, F, T, F);
type Table is tagged record -- Tagged type.
Row1 : Row_Type := Init;
Row2 : Row_Type := Init;
end record;
procedure Clear (A : in out Table); -- Dispatching operation.
procedure Reset (A : in out Table); -- Re-dispatching operation.
-- ...Other operations.
type Table2 is new Table with null record; -- Extension of Table (but
-- structurally identical).
procedure Clear (A : in out Table2); -- Overrides parent's op.
-- ...Other operations.
end C640001_0;
--===================================================================--
package body C640001_0 is
function Is_True (A : in Row_Type) return Boolean is
begin
for I in A'Range loop
if A(I) /= True then -- Return true if all elements
return False; -- of A are True.
end if;
end loop;
return True;
end Is_True;
function Is_False (A : in Row_Type) return Boolean is
begin
return A = Row_Type'(others => False); -- Return true if all elements
end Is_False; -- of A are False.
procedure Clear (A : in out Table) is
begin
for I in Row_Type'Range loop -- This version of Clear sets
A.Row1(I) := False; -- the elements of Row1 only
end loop; -- to False.
end Clear;
procedure Reset (A : in out Table) is
begin
Clear (Table'Class(A)); -- Redispatch to appropriate
-- ... Other "reset" activities. -- version of Clear.
end Reset;
procedure Clear (A : in out Table2) is
begin
for I in Row_Type'Range loop -- This version of Clear sets
A.Row1(I) := True; -- the elements of Row1 only
end loop; -- to True.
end Clear;
end C640001_0;
--===================================================================--
with C640001_0;
package C640001_1 is
procedure Clear (T : in out C640001_0.Table); -- Non-dispatching operation.
end C640001_1;
--===================================================================--
package body C640001_1 is
procedure Clear (T : in out C640001_0.Table) is
begin
for I in C640001_0.Row_Type'Range loop -- This version of Clear sets
T.Row2(I) := True; -- the elements of Row2 only
end loop; -- to True.
end Clear;
end C640001_1;
--===================================================================--
-- This unit represents a support package for table-driven processing of
-- data objects. Process_Operand performs a set of operations are performed
-- sequentially on a single operand. Note that parameters are provided to
-- specify which subset of operations in the operations table are to be
-- performed (ordinarily these might be omitted, but the test requires that
-- each operation be called individually for a single operand).
generic
type Tag is tagged private;
package C640001_2 is
type Proc_Ptr is access procedure (P: in out Tag);
type Op_List is private;
procedure Add_Op (Op : in Proc_Ptr; -- Add operation to
List : in out Op_List); -- to list of ops.
procedure Process_Operand (Operand : in out Tag; -- Execute a subset
List : in Op_List; -- of a list of
First_Op : in Positive; -- operations using
Last_Op : in Positive); -- a given operand.
-- ...Other operations.
private
type Op_Array is array (1 .. 3) of Proc_Ptr;
type Op_List is record
Top : Natural := 0;
Ops : Op_Array;
end record;
end C640001_2;
--===================================================================--
package body C640001_2 is
procedure Add_Op (Op : in Proc_Ptr;
List : in out Op_List) is
begin
List.Top := List.Top + 1; -- Artificial; no Constraint_Error protection.
List.Ops(List.Top) := Op;
end Add_Op;
procedure Process_Operand (Operand : in out Tag;
List : in Op_List;
First_Op : in Positive;
Last_Op : in Positive) is
begin
for I in First_Op .. Last_Op loop
List.Ops(I)(Operand); -- Implicit dereference of an
end loop; -- access-to-subprogram value.
end Process_Operand;
end C640001_2;
--===================================================================--
with C640001_0;
with C640001_1;
with C640001_2;
with Report;
procedure C640001 is
package Table_Support is new C640001_2 (C640001_0.Table);
Sub_Ptr : Table_Support.Proc_Ptr;
My_List : Table_Support.Op_List;
My_Table1 : C640001_0.Table; -- Initial values of both Row1 &
-- Row2 are (T,F,T,F,T,F,T,F,T,F).
My_Table2 : C640001_0.Table2; -- Initial values of both Row1 &
-- Row2 are (T,F,T,F,T,F,T,F,T,F).
begin
Report.Test ("C640001", "Check that, for an access-to-subprogram type " &
"whose designated profile contains parameters " &
"of a tagged generic formal type, an access-" &
"to-subprogram value may designate dispatching " &
"and non-dispatching operations");
--
-- Add subprogram access values to list:
--
Sub_Ptr := C640001_0.Clear'Access; -- Designates dispatching op.
Table_Support.Add_Op (Sub_Ptr, My_List); -- (1st operation on My_List).
Sub_Ptr := C640001_1.Clear'Access; -- Designates non-dispatching op.
Table_Support.Add_Op (Sub_Ptr, My_List); -- (2nd operation on My_List).
Sub_Ptr := C640001_0.Reset'Access; -- Designates re-dispatching op.
Table_Support.Add_Op (Sub_Ptr, My_List); -- (3rd operation on My_List).
--
-- Call dispatching operation:
--
Table_Support.Process_Operand (My_Table1, My_List, 1, 1); -- Call 1st op.
if not C640001_0.Is_False (My_Table1.Row1) then
Report.Failed ("Wrong result after calling dispatching operation");
end if;
--
-- Call non-dispatching operation:
--
Table_Support.Process_Operand (My_Table1, My_List, 2, 2); -- Call 2nd op.
if not C640001_0.Is_True (My_Table1.Row2) then
Report.Failed ("Wrong result after calling non-dispatching operation");
end if;
--
-- Call re-dispatching operation:
--
Table_Support.Process_Operand (C640001_0.Table(My_Table2), -- View conv.
My_List, 3, 3); -- Call 3rd op.
if not C640001_0.Is_True (My_Table2.Row1) then
Report.Failed ("Wrong result after calling re-dispatching operation");
end if;
Report.Result;
end C640001;
|