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 a view conversion to a tagged type is permitted in the
28 -- prefix of a selected component, an object renaming declaration, and
29 -- (if the operand is a variable) on the left side of an assignment
30 -- statement. Check that such a renaming or assignment does not change
31 -- the tag of the operand.
33 -- Check that, for a view conversion of a tagged type, each
34 -- nondiscriminant component of the new view denotes the matching
35 -- component of the operand object. Check that reading the value of the
36 -- view yields the result of converting the value of the operand object
37 -- to the target subtype.
40 -- The fact that the tag of an object is not changed is verified by
41 -- making calls to primitive operations which in turn make (re)dispatching
42 -- calls, and confirming that the proper bodies are executed.
44 -- Selected components are checked in three contexts: as the object name
45 -- in an object renaming declaration, as the left operand of an inequality
46 -- operation, and as the left side of an assignment statement.
48 -- View conversions of an object of a 2nd level type extension are
49 -- renamed as objects of an ancestor type and of a class-wide type. In
50 -- one case the operand of the conversion is itself a renaming of an
53 -- View conversions of an object of a 2nd level type extension are
54 -- checked for equality with record aggregates of various ancestor types.
55 -- In one case, the view conversion is to a class-wide type, and it is
56 -- checked for equality with the result of a class-wide function with
57 -- the following structure:
59 -- function F return T'Class is
60 -- A : DDT := Expected_Value;
61 -- X : T'Class := T(A);
69 -- Var : DDT := Expected_Value;
71 -- if (T'Class(Var) /= F) then -- Condition should yield FALSE.
75 -- The view conversion to which X is initialized does not affect the
76 -- value or tag of the operand; the tag of X is that of type DDT (not T),
77 -- and the components are those of A. The result of this function
78 -- should equal the value of an object of type DDT initialized to the
81 -- To check that assignment to a view conversion does not change the tag
82 -- of the operand, an assignment is made to a conversion of an object,
83 -- and the object is then passed as an actual to a dispatching operation.
84 -- Conversions to both specific and class-wide types are checked.
88 -- 20 Jul 95 SAIC Initial prerelease version.
89 -- 24 Apr 96 SAIC Added type conversions.
95 type Call_ID_Kind
is (None
, Parent_Outer
, Parent_Inner
,
96 Child_Outer
, Child_Inner
,
97 Grandchild_Outer
, Grandchild_Inner
);
99 type Root_Type
is abstract tagged record
100 First_Call
: Call_ID_Kind
:= None
;
101 Second_Call
: Call_ID_Kind
:= None
;
104 procedure Inner_Proc
(X
: in out Root_Type
) is abstract;
105 procedure Outer_Proc
(X
: in out Root_Type
) is abstract;
110 --==================================================================--
113 package C460006_0
.C460006_1
is
115 type Parent_Type
is new Root_Type
with record
119 procedure Inner_Proc
(X
: in out Parent_Type
);
120 procedure Outer_Proc
(X
: in out Parent_Type
);
122 end C460006_0
.C460006_1
;
125 --==================================================================--
128 package body C460006_0
.C460006_1
is
130 procedure Inner_Proc
(X
: in out Parent_Type
) is
132 X
.Second_Call
:= Parent_Inner
;
135 -------------------------------------------------
136 procedure Outer_Proc
(X
: in out Parent_Type
) is
138 X
.First_Call
:= Parent_Outer
;
139 Inner_Proc
( Parent_Type
'Class(X
) );
142 end C460006_0
.C460006_1
;
145 --==================================================================--
148 package C460006_0
.C460006_1
.C460006_2
is
150 type Child_Type
is new Parent_Type
with record
151 C2
: String(1 .. 5) := "-----";
154 procedure Inner_Proc
(X
: in out Child_Type
);
155 procedure Outer_Proc
(X
: in out Child_Type
);
157 end C460006_0
.C460006_1
.C460006_2
;
160 --==================================================================--
163 package body C460006_0
.C460006_1
.C460006_2
is
165 procedure Inner_Proc
(X
: in out Child_Type
) is
167 X
.Second_Call
:= Child_Inner
;
170 -------------------------------------------------
171 procedure Outer_Proc
(X
: in out Child_Type
) is
173 X
.First_Call
:= Child_Outer
;
174 Inner_Proc
( Parent_Type
'Class(X
) );
177 end C460006_0
.C460006_1
.C460006_2
;
180 --==================================================================--
183 package C460006_0
.C460006_1
.C460006_2
.C460006_3
is
185 type Grandchild_Type
is new Child_Type
with record
186 C3
: String(1 .. 5) := "-----";
189 procedure Inner_Proc
(X
: in out Grandchild_Type
);
190 procedure Outer_Proc
(X
: in out Grandchild_Type
);
193 function ClassWide_Func
return Parent_Type
'Class;
196 Grandchild_Value
: constant Grandchild_Type
:= (First_Call
=> None
,
202 end C460006_0
.C460006_1
.C460006_2
.C460006_3
;
205 --==================================================================--
208 package body C460006_0
.C460006_1
.C460006_2
.C460006_3
is
210 procedure Inner_Proc
(X
: in out Grandchild_Type
) is
212 X
.Second_Call
:= Grandchild_Inner
;
215 -------------------------------------------------
216 procedure Outer_Proc
(X
: in out Grandchild_Type
) is
218 X
.First_Call
:= Grandchild_Outer
;
219 Inner_Proc
( Parent_Type
'Class(X
) );
222 -------------------------------------------------
223 function ClassWide_Func
return Parent_Type
'Class is
224 A
: Grandchild_Type
:= Grandchild_Value
;
225 X
: Parent_Type
'Class := Parent_Type
(A
); -- Value of X is still that of A.
230 end C460006_0
.C460006_1
.C460006_2
.C460006_3
;
233 --==================================================================--
236 with C460006_0
.C460006_1
.C460006_2
.C460006_3
;
241 package Root_Package
renames C460006_0
;
242 package Parent_Package
renames C460006_0
.C460006_1
;
243 package Child_Package
renames C460006_0
.C460006_1
.C460006_2
;
244 package Grandchild_Package
renames C460006_0
.C460006_1
.C460006_2
.C460006_3
;
247 Report
.Test
("C460006", "Check that a view conversion to a tagged type " &
248 "is permitted in the prefix of a selected component, an " &
249 "object renaming declaration, and (if the operand is a " &
250 "variable) on the left side of an assignment statement. " &
251 "Check that such a renaming or assignment does not change " &
252 " the tag of the operand");
256 -- Check conversion as prefix of selected component:
259 Selected_Component_Subtest
:
261 use Root_Package
, Parent_Package
, Child_Package
, Grandchild_Package
;
263 Var
: Grandchild_Type
:= Grandchild_Value
;
264 CW_Var
: Parent_Type
'Class := Var
;
266 Ren
: Integer renames Parent_Type
(Var
).C1
;
270 Report
.Failed
("Wrong value: selected component in renaming");
273 if Child_Type
(Var
).C2
/= "Hello" then
274 Report
.Failed
("Wrong value: selected component in IF");
277 Grandchild_Type
(CW_Var
).C3
(2..4) := "eir";
278 if CW_Var
/= Parent_Type
'Class
279 (Grandchild_Type
'(None, None, 15, "Hello", "Weird"))
281 Report.Failed ("Wrong value: selected component in assignment");
283 end Selected_Component_Subtest;
287 -- Check conversion in object renaming:
290 Object_Renaming_Subtest:
292 use Root_Package, Parent_Package, Child_Package, Grandchild_Package;
294 Var : Grandchild_Type := Grandchild_Value;
295 Ren1 : Parent_Type renames Parent_Type(Var);
296 Ren2 : Child_Type renames Child_Type(Var);
297 Ren3 : Parent_Type'Class renames Parent_Type'Class(Var);
298 Ren4 : Parent_Type renames Parent_Type(Ren2); -- Rename of rename.
301 if Ren1 /= (Parent_Outer, Grandchild_Inner, 15) then
302 Report.Failed ("Value or tag not preserved by object renaming: Ren1");
306 if Ren2 /= (Child_Outer, Grandchild_Inner, 15, "Hello") then
307 Report.Failed ("Value or tag not preserved by object renaming: Ren2");
311 if Ren3 /= Parent_Type'Class
312 (Grandchild_Type'(Grandchild_Outer
,
318 Report
.Failed
("Value or tag not preserved by object renaming: Ren3");
322 if Ren4
/= (Parent_Outer
, Grandchild_Inner
, 15) then
323 Report
.Failed
("Value or tag not preserved by object renaming: Ren4");
325 end Object_Renaming_Subtest
;
329 -- Check reading view conversion, and conversion as left side of assignment:
332 View_Conversion_Subtest
:
334 use Root_Package
, Parent_Package
, Child_Package
, Grandchild_Package
;
336 Var
: Grandchild_Type
:= Grandchild_Value
;
337 Specific
: Child_Type
;
338 ClassWide
: Parent_Type
'Class := Var
; -- Grandchild_Type tag.
340 if Parent_Type
(Var
) /= (None
, None
, 15) then
341 Report
.Failed
("View has wrong value: #1");
344 if Child_Type
(Var
) /= (None
, None
, 15, "Hello") then
345 Report
.Failed
("View has wrong value: #2");
348 if Parent_Type
'Class(Var
) /= ClassWide_Func
then
349 Report
.Failed
("Upward view conversion did not preserve " &
350 "extension's components");
354 Parent_Type
(Specific
) := (None
, None
, 26); -- Assign to view.
355 Outer_Proc
(Specific
); -- Call dispatching op.
357 if Specific
/= (Child_Outer
, Child_Inner
, 26, "-----") then
358 Report
.Failed
("Value or tag not preserved by assignment: Specific");
362 Parent_Type
(ClassWide
) := (None
, None
, 44); -- Assign to view.
363 Outer_Proc
(ClassWide
); -- Call dispatching op.
365 if ClassWide
/= Parent_Type
'Class
366 (Grandchild_Type
'(Grandchild_Outer,
372 Report.Failed ("Value or tag not preserved by assignment: ClassWide");
374 end View_Conversion_Subtest;