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
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
|
-- C460006.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 view conversion to a tagged type is permitted in the
-- prefix of a selected component, an object renaming declaration, and
-- (if the operand is a variable) on the left side of an assignment
-- statement. Check that such a renaming or assignment does not change
-- the tag of the operand.
--
-- Check that, for a view conversion of a tagged type, each
-- nondiscriminant component of the new view denotes the matching
-- component of the operand object. Check that reading the value of the
-- view yields the result of converting the value of the operand object
-- to the target subtype.
--
-- TEST DESCRIPTION:
-- The fact that the tag of an object is not changed is verified by
-- making calls to primitive operations which in turn make (re)dispatching
-- calls, and confirming that the proper bodies are executed.
--
-- Selected components are checked in three contexts: as the object name
-- in an object renaming declaration, as the left operand of an inequality
-- operation, and as the left side of an assignment statement.
--
-- View conversions of an object of a 2nd level type extension are
-- renamed as objects of an ancestor type and of a class-wide type. In
-- one case the operand of the conversion is itself a renaming of an
-- object.
--
-- View conversions of an object of a 2nd level type extension are
-- checked for equality with record aggregates of various ancestor types.
-- In one case, the view conversion is to a class-wide type, and it is
-- checked for equality with the result of a class-wide function with
-- the following structure:
--
-- function F return T'Class is
-- A : DDT := Expected_Value;
-- X : T'Class := T(A);
-- begin
-- return X;
--
-- end F;
--
-- ...
--
-- Var : DDT := Expected_Value;
--
-- if (T'Class(Var) /= F) then -- Condition should yield FALSE.
-- FAIL;
-- end if;
--
-- The view conversion to which X is initialized does not affect the
-- value or tag of the operand; the tag of X is that of type DDT (not T),
-- and the components are those of A. The result of this function
-- should equal the value of an object of type DDT initialized to the
-- same value as F.A.
--
-- To check that assignment to a view conversion does not change the tag
-- of the operand, an assignment is made to a conversion of an object,
-- and the object is then passed as an actual to a dispatching operation.
-- Conversions to both specific and class-wide types are checked.
--
--
-- CHANGE HISTORY:
-- 20 Jul 95 SAIC Initial prerelease version.
-- 24 Apr 96 SAIC Added type conversions.
--
--!
package C460006_0 is
type Call_ID_Kind is (None, Parent_Outer, Parent_Inner,
Child_Outer, Child_Inner,
Grandchild_Outer, Grandchild_Inner);
type Root_Type is abstract tagged record
First_Call : Call_ID_Kind := None;
Second_Call : Call_ID_Kind := None;
end record;
procedure Inner_Proc (X : in out Root_Type) is abstract;
procedure Outer_Proc (X : in out Root_Type) is abstract;
end C460006_0;
--==================================================================--
package C460006_0.C460006_1 is
type Parent_Type is new Root_Type with record
C1 : Integer := 0;
end record;
procedure Inner_Proc (X : in out Parent_Type);
procedure Outer_Proc (X : in out Parent_Type);
end C460006_0.C460006_1;
--==================================================================--
package body C460006_0.C460006_1 is
procedure Inner_Proc (X : in out Parent_Type) is
begin
X.Second_Call := Parent_Inner;
end Inner_Proc;
-------------------------------------------------
procedure Outer_Proc (X : in out Parent_Type) is
begin
X.First_Call := Parent_Outer;
Inner_Proc ( Parent_Type'Class(X) );
end Outer_Proc;
end C460006_0.C460006_1;
--==================================================================--
package C460006_0.C460006_1.C460006_2 is
type Child_Type is new Parent_Type with record
C2 : String(1 .. 5) := "-----";
end record;
procedure Inner_Proc (X : in out Child_Type);
procedure Outer_Proc (X : in out Child_Type);
end C460006_0.C460006_1.C460006_2;
--==================================================================--
package body C460006_0.C460006_1.C460006_2 is
procedure Inner_Proc (X : in out Child_Type) is
begin
X.Second_Call := Child_Inner;
end Inner_Proc;
-------------------------------------------------
procedure Outer_Proc (X : in out Child_Type) is
begin
X.First_Call := Child_Outer;
Inner_Proc ( Parent_Type'Class(X) );
end Outer_Proc;
end C460006_0.C460006_1.C460006_2;
--==================================================================--
package C460006_0.C460006_1.C460006_2.C460006_3 is
type Grandchild_Type is new Child_Type with record
C3: String(1 .. 5) := "-----";
end record;
procedure Inner_Proc (X : in out Grandchild_Type);
procedure Outer_Proc (X : in out Grandchild_Type);
function ClassWide_Func return Parent_Type'Class;
Grandchild_Value : constant Grandchild_Type := (First_Call => None,
Second_Call => None,
C1 => 15,
C2 => "Hello",
C3 => "World");
end C460006_0.C460006_1.C460006_2.C460006_3;
--==================================================================--
package body C460006_0.C460006_1.C460006_2.C460006_3 is
procedure Inner_Proc (X : in out Grandchild_Type) is
begin
X.Second_Call := Grandchild_Inner;
end Inner_Proc;
-------------------------------------------------
procedure Outer_Proc (X : in out Grandchild_Type) is
begin
X.First_Call := Grandchild_Outer;
Inner_Proc ( Parent_Type'Class(X) );
end Outer_Proc;
-------------------------------------------------
function ClassWide_Func return Parent_Type'Class is
A : Grandchild_Type := Grandchild_Value;
X : Parent_Type'Class := Parent_Type(A); -- Value of X is still that of A.
begin
return X;
end ClassWide_Func;
end C460006_0.C460006_1.C460006_2.C460006_3;
--==================================================================--
with C460006_0.C460006_1.C460006_2.C460006_3;
with Report;
procedure C460006 is
package Root_Package renames C460006_0;
package Parent_Package renames C460006_0.C460006_1;
package Child_Package renames C460006_0.C460006_1.C460006_2;
package Grandchild_Package renames C460006_0.C460006_1.C460006_2.C460006_3;
begin
Report.Test ("C460006", "Check that a view conversion to a tagged type " &
"is permitted in the prefix of a selected component, an " &
"object renaming declaration, and (if the operand is a " &
"variable) on the left side of an assignment statement. " &
"Check that such a renaming or assignment does not change " &
" the tag of the operand");
--
-- Check conversion as prefix of selected component:
--
Selected_Component_Subtest:
declare
use Root_Package, Parent_Package, Child_Package, Grandchild_Package;
Var : Grandchild_Type := Grandchild_Value;
CW_Var : Parent_Type'Class := Var;
Ren : Integer renames Parent_Type(Var).C1;
begin
if Ren /= 15 then
Report.Failed ("Wrong value: selected component in renaming");
end if;
if Child_Type(Var).C2 /= "Hello" then
Report.Failed ("Wrong value: selected component in IF");
end if;
Grandchild_Type(CW_Var).C3(2..4) := "eir";
if CW_Var /= Parent_Type'Class
(Grandchild_Type'(None, None, 15, "Hello", "Weird"))
then
Report.Failed ("Wrong value: selected component in assignment");
end if;
end Selected_Component_Subtest;
--
-- Check conversion in object renaming:
--
Object_Renaming_Subtest:
declare
use Root_Package, Parent_Package, Child_Package, Grandchild_Package;
Var : Grandchild_Type := Grandchild_Value;
Ren1 : Parent_Type renames Parent_Type(Var);
Ren2 : Child_Type renames Child_Type(Var);
Ren3 : Parent_Type'Class renames Parent_Type'Class(Var);
Ren4 : Parent_Type renames Parent_Type(Ren2); -- Rename of rename.
begin
Outer_Proc (Ren1);
if Ren1 /= (Parent_Outer, Grandchild_Inner, 15) then
Report.Failed ("Value or tag not preserved by object renaming: Ren1");
end if;
Outer_Proc (Ren2);
if Ren2 /= (Child_Outer, Grandchild_Inner, 15, "Hello") then
Report.Failed ("Value or tag not preserved by object renaming: Ren2");
end if;
Outer_Proc (Ren3);
if Ren3 /= Parent_Type'Class
(Grandchild_Type'(Grandchild_Outer,
Grandchild_Inner,
15,
"Hello",
"World"))
then
Report.Failed ("Value or tag not preserved by object renaming: Ren3");
end if;
Outer_Proc (Ren4);
if Ren4 /= (Parent_Outer, Grandchild_Inner, 15) then
Report.Failed ("Value or tag not preserved by object renaming: Ren4");
end if;
end Object_Renaming_Subtest;
--
-- Check reading view conversion, and conversion as left side of assignment:
--
View_Conversion_Subtest:
declare
use Root_Package, Parent_Package, Child_Package, Grandchild_Package;
Var : Grandchild_Type := Grandchild_Value;
Specific : Child_Type;
ClassWide : Parent_Type'Class := Var; -- Grandchild_Type tag.
begin
if Parent_Type(Var) /= (None, None, 15) then
Report.Failed ("View has wrong value: #1");
end if;
if Child_Type(Var) /= (None, None, 15, "Hello") then
Report.Failed ("View has wrong value: #2");
end if;
if Parent_Type'Class(Var) /= ClassWide_Func then
Report.Failed ("Upward view conversion did not preserve " &
"extension's components");
end if;
Parent_Type(Specific) := (None, None, 26); -- Assign to view.
Outer_Proc (Specific); -- Call dispatching op.
if Specific /= (Child_Outer, Child_Inner, 26, "-----") then
Report.Failed ("Value or tag not preserved by assignment: Specific");
end if;
Parent_Type(ClassWide) := (None, None, 44); -- Assign to view.
Outer_Proc (ClassWide); -- Call dispatching op.
if ClassWide /= Parent_Type'Class
(Grandchild_Type'(Grandchild_Outer,
Grandchild_Inner,
44,
"Hello",
"World"))
then
Report.Failed ("Value or tag not preserved by assignment: ClassWide");
end if;
end View_Conversion_Subtest;
Report.Result;
end C460006;
|