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 if the operand type of a type conversion is class-wide,
28 -- Constraint_Error is raised if the tag of the operand does not
29 -- identify a specific type that is covered by or descended from the
33 -- View conversions of class-wide operands to specific types are
34 -- placed on the right and left sides of assignment statements, and
35 -- conversions of class-wide operands to class-wide types are used
36 -- as actual parameters to dispatching operations. In all cases, a
37 -- check is made that Constraint_Error is raised if the tag of the
38 -- operand does not identify a specific type covered by or descended
39 -- from the target type, and not raised otherwise.
41 -- A specific type is descended from itself and from those types it is
42 -- directly or indirectly derived from. A specific type is covered by
43 -- itself and each class-wide type to whose class it belongs.
45 -- A class-wide type T'Class is descended from T and those types which
46 -- T is descended from. A class-wide type is covered by each class-wide
47 -- type to whose class it belongs.
51 -- 19 Jul 95 SAIC Initial prerelease version.
52 -- 18 Apr 96 SAIC ACVC 2.1: Added a check for correct tag.
57 type Tag_Type
is tagged record
61 procedure Proc
(X
: in out Tag_Type
);
64 type DTag_Type
is new Tag_Type
with record
68 procedure Proc
(X
: in out DTag_Type
);
71 type DDTag_Type
is new DTag_Type
with record
75 procedure Proc
(X
: in out DDTag_Type
);
77 procedure NewProc
(X
: in DDTag_Type
);
79 function CWFunc
(X
: Tag_Type
'Class) return Tag_Type
'Class;
84 --==================================================================--
87 package body C460004_0
is
89 procedure Proc
(X
: in out Tag_Type
) is
94 -----------------------------------------
95 procedure Proc
(X
: in out DTag_Type
) is
101 -----------------------------------------
102 procedure Proc
(X
: in out DDTag_Type
) is
104 Proc
( DTag_Type
(X
) );
108 -----------------------------------------
109 procedure NewProc
(X
: in DDTag_Type
) is
115 Report
.Failed
("Unexpected exception in NewProc");
118 -----------------------------------------
119 function CWFunc
(X
: Tag_Type
'Class) return Tag_Type
'Class is
120 Y
: Tag_Type
'Class := X
;
129 --==================================================================--
138 Tag_Type_Init
: constant Tag_Type
:= (C1
=> 0);
139 DTag_Type_Init
: constant DTag_Type
:= (Tag_Type_Init
with "Hello");
140 DDTag_Type_Init
: constant DDTag_Type
:= (DTag_Type_Init
with "World");
142 Tag_Type_Value
: constant Tag_Type
:= (C1
=> 25);
143 DTag_Type_Value
: constant DTag_Type
:= (Tag_Type_Value
with "Earth");
144 DDTag_Type_Value
: constant DDTag_Type
:= (DTag_Type_Value
with "Orbit");
148 Report
.Test
("C460004", "Check that for a view conversion of a " &
149 "class-wide operand, Constraint_Error is raised if the " &
150 "tag of the operand does not identify a specific type " &
151 "covered by or descended from the target type");
154 -- View conversion to specific type:
158 procedure CW_Proc
(P
: Tag_Type
'Class) is
159 Target
: Tag_Type
:= Tag_Type_Init
;
161 Target
:= Tag_Type
(P
);
162 if (Target
/= Tag_Type_Value
) then
163 Report
.Failed
("Target has wrong value: #01");
166 when Constraint_Error
=>
167 Report
.Failed
("Constraint_Error raised: #01");
169 Report
.Failed
("Unexpected exception: #01");
173 CW_Proc
(DDTag_Type_Value
);
176 ----------------------------------------------------------------------
179 Target
: DTag_Type
:= DTag_Type_Init
;
181 Target
:= DTag_Type
(CWFunc
(DDTag_Type_Value
));
182 if (Target
/= DTag_Type_Value
) then
183 Report
.Failed
("Target has wrong value: #02");
186 when Constraint_Error
=> Report
.Failed
("Constraint_Error raised: #02");
187 when others => Report
.Failed
("Unexpected exception: #02");
190 ----------------------------------------------------------------------
195 Target
:= DDTag_Type
(CWFunc
(Tag_Type_Value
));
196 -- CWFunc returns a Tag_Type; its tag is preserved through
197 -- the view conversion. Constraint_Error should be raised.
199 Report
.Failed
("Constraint_Error not raised: #03");
202 when Constraint_Error
=> null; -- expected exception
203 when others => Report
.Failed
("Unexpected exception: #03");
206 ----------------------------------------------------------------------
209 procedure CW_Proc
(P
: Tag_Type
'Class) is
211 NewProc
(DDTag_Type
(P
));
212 Report
.Failed
("Constraint_Error not raised: #04");
215 when Constraint_Error
=> null; -- expected exception
216 when others => Report
.Failed
("Unexpected exception: #04");
220 CW_Proc
(DTag_Type_Value
);
223 ----------------------------------------------------------------------
226 procedure CW_Proc
(P
: Tag_Type
'Class) is
227 Target
: DDTag_Type
:= DDTag_Type_Init
;
229 Target
:= DDTag_Type
(P
);
230 if (Target
/= DDTag_Type_Value
) then
231 Report
.Failed
("Target has wrong value: #05");
235 when Constraint_Error
=>
236 Report
.Failed
("Constraint_Error raised: #05");
238 => Report
.Failed
("Unexpected exception: #05");
242 CW_Proc
(DDTag_Type_Value
);
247 -- View conversion to class-wide type:
251 procedure CW_Proc
(P
: Tag_Type
'Class) is
252 Operand
: Tag_Type
'Class := P
;
254 Proc
( DTag_Type
'Class(Operand
) );
255 Report
.Failed
("Constraint_Error not raised: #06");
258 when Constraint_Error
=> null; -- expected exception
259 when others => Report
.Failed
("Unexpected exception: #06");
263 CW_Proc
(Tag_Type_Init
);
266 ----------------------------------------------------------------------
269 procedure CW_Proc
(P
: Tag_Type
'Class) is
270 Operand
: Tag_Type
'Class := P
;
272 Proc
( DDTag_Type
'Class(Operand
) );
273 Report
.Failed
("Constraint_Error not raised: #07");
276 when Constraint_Error
=> null; -- expected exception
277 when others => Report
.Failed
("Unexpected exception: #07");
281 CW_Proc
(Tag_Type_Init
);
284 ----------------------------------------------------------------------
287 procedure CW_Proc
(P
: Tag_Type
'Class) is
288 Operand
: Tag_Type
'Class := P
;
290 Proc
( DTag_Type
'Class(Operand
) );
291 if Operand
not in DTag_Type
then
292 Report
.Failed
("Operand has wrong tag: #08");
293 elsif (Operand
/= Tag_Type
'Class (DTag_Type_Value
)) then
294 Report
.Failed
("Operand has wrong value: #08");
298 when Constraint_Error
=>
299 Report
.Failed
("Constraint_Error raised: #08");
301 Report
.Failed
("Unexpected exception: #08");
305 CW_Proc
(DTag_Type_Init
);
308 ----------------------------------------------------------------------
311 procedure CW_Proc
(P
: Tag_Type
'Class) is
312 Operand
: Tag_Type
'Class := P
;
314 Proc
( Tag_Type
'Class(Operand
) );
315 if Operand
not in DDTag_Type
then
316 Report
.Failed
("Operand has wrong tag: #09");
317 elsif (Operand
/= Tag_Type
'Class (DDTag_Type_Value
)) then
318 Report
.Failed
("Operand has wrong value: #09");
322 when Constraint_Error
=>
323 Report
.Failed
("Constraint_Error raised: #09");
325 Report
.Failed
("Unexpected exception: #09");
329 CW_Proc
(DDTag_Type_Init
);