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
|
-- C3A0007.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 a call to a subprogram via an access-to-subprogram value
-- stored in a data structure will correctly dispatch according to the
-- tag of the class-wide parameter passed via that call.
--
-- TEST DESCRIPTION:
-- Declare an access to procedure type in a package specification.
-- Declare a root tagged type with the access to procedure type as a
-- component. Declare three primitive procedures for the type that
-- can be referred to by the access to procedure type. Use the access
-- to procedure type to initialize the component of a record.
--
-- Extend the root type with a record extension in another package
-- specification. Declare a new primitive procedure for the extension
-- (in addition to its three inherited subprograms).
--
-- In the main program, declare an operation for the root tagged type
-- which can be passed as an access value to change the initial value
-- of the component. Call the inherited operation indirectly by
-- dereferencing the access value to check on the initial value of the
-- extension. Call inherited operations indirectly by dereferencing
-- the access value to replace the initial value. Call the primitive
-- procedure indirectly by dereferencing the access value to modify the
-- extension.
--
-- type Button
-- procedure Push(Button)
-- procedure Set_Response(Button,Button_Response_Ptr)
-- procedure Default_Response(Button)
--
-- type Priority_Button (new Button)
-- procedures Push, Set_Response inherited
-- procedure Default_Response
-- procedure Set_Priority
--
--
-- CHANGE HISTORY:
-- 06 Dec 94 SAIC ACVC 2.0
--
--!
package C3A0007_0 is
Default_Call : Boolean := False;
type Button is tagged private;
type Button_Response_Ptr is access procedure
(B : in out Button'Class);
procedure Push (B : in out Button); -- to be inherited
procedure Set_Response (B : in out Button; -- to be inherited
R : in Button_Response_Ptr);
procedure Response (B : in out Button); -- to be inherited
private
procedure Default_Response(B: in out Button'Class);
type Button is tagged -- root tagged type
record
Action : Button_Response_Ptr
:= Default_Response'Access;
end record;
end C3A0007_0;
with C3A0007_0;
package C3A0007_1 is
type Priority_Button is new C3A0007_0.Button
with record
Priority : Integer := 0;
end record;
-- Inherits procedure Push from Button
-- Inherits procedure Set_Response from Button
-- Override procedure Response from Button
procedure Response (B : in out Priority_Button);
-- Primitive operation of the extension
procedure Set_Priority (B : in out Priority_Button);
end C3A0007_1;
with C3A0007_0;
package C3A0007_2 is
Emergency_Call : Boolean := False;
procedure Emergency (B : in out C3A0007_0.Button'Class);
end C3A0007_2;
-----------------------------------------------------------------------------
with TCTouch;
package body C3A0007_0 is
procedure Push (B : in out Button) is
begin
TCTouch.Touch( 'P' ); --------------------------------------------- P
-- Invoking subprogram designated by access value
B.Action (B);
end Push;
procedure Set_Response (B : in out Button;
R : in Button_Response_Ptr) is
begin
TCTouch.Touch( 'S' ); --------------------------------------------- S
-- Set procedure value in record
B.Action := R;
end Set_Response;
procedure Response (B : in out Button) is
begin
TCTouch.Touch( 'D' ); --------------------------------------------- D
Default_Call := True;
end Response;
procedure Default_Response (B : in out Button'Class) is
begin
TCTouch.Touch( 'C' ); --------------------------------------------- C
Response(B);
end Default_Response;
end C3A0007_0;
with TCTouch;
package body C3A0007_1 is
procedure Set_Priority (B : in out Priority_Button) is
begin
TCTouch.Touch( 's' ); --------------------------------------------- s
B.Priority := 1;
end Set_Priority;
procedure Response (B : in out Priority_Button) is
begin
TCTouch.Touch( 'd' ); --------------------------------------------- d
end Response;
end C3A0007_1;
with TCTouch;
package body C3A0007_2 is
procedure Emergency (B : in out C3A0007_0.Button'Class) is
begin
TCTouch.Touch( 'E' ); ------------------------------------------- E
Emergency_Call := True;
end Emergency;
end C3A0007_2;
-----------------------------------------------------------------------------
with Report;
with TCTouch;
with C3A0007_0;
with C3A0007_1;
with C3A0007_2;
procedure C3A0007 is
Pink_Button : C3A0007_0.Button;
Green_Button : C3A0007_1.Priority_Button;
begin
Report.Test ("C3A0007", "Check that a call to a subprogram via an "
& "access-to-subprogram value stored in a data "
& "structure will correctly dispatch according to "
& "the tag of the class-wide parameter passed "
& "via that call" );
-- Call inherited operation Push to set Default_Response value
-- in the extension.
C3A0007_1.Push (Green_Button);
TCTouch.Validate("PCd", "First Green Button Push");
TCTouch.Assert_Not(C3A0007_0.Default_Call,
"Incorrect Green Default_Response");
C3A0007_0.Push (Pink_Button);
TCTouch.Validate("PCD", "First Pink Button Push");
-- Call inherited operations Set_Response and Push to set
-- Emergency value in the extension.
C3A0007_1.Set_Response (Green_Button, C3A0007_2.Emergency'Access);
C3A0007_1.Push (Green_Button);
TCTouch.Validate("SPE", "Second Green Button Push");
TCTouch.Assert(C3A0007_2.Emergency_Call, "Incorrect Green Emergency");
C3A0007_0.Set_Response (Pink_Button, C3A0007_2.Emergency'Access);
C3A0007_0.Push (Pink_Button);
TCTouch.Validate("SPE", "Second Pink Button Push");
-- Call primitive operation to set priority value
-- in the extension.
C3A0007_1.Set_Priority (Green_Button);
TCTouch.Validate("s", "Green Button Priority");
TCTouch.Assert(Green_Button.Priority = 1, "Incorrect Set_Priority");
Report.Result;
end C3A0007;
|