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 S is a subtype of a tagged type T, and if S is
28 -- constrained, then the allowable values of S'Class are only those
29 -- that, when converted to T, belong to S.
32 -- This test defines a small tagged hierarchy of discriminated tagged
33 -- records, and constrained subtypes of those tagged record types.
34 -- It then uses access to the classwide of the constrained subtype
35 -- to check the objective.
39 -- 09 APR 96 SAIC Initial version
40 -- 03 NOV 96 SAIC Revised for 2.1 release
41 -- 31 DEC 97 EDS Restored use of intermediate access variable
42 -- to eliminate raising of Program_Error
43 -- 13 SEP 99 RLB Repaired previous change to avoid premature
45 -- 28 JUN 02 RLB Added pragma Elaborate_All (Report);.
48 ----------------------------------------------------------------- C390010_0
50 with Report
; pragma Elaborate_All
(Report
);
53 -- the defined subprograms will allow checking the placement of
56 -- define a discriminated tagged type, and a constrained subtype of
59 type Discr_Tag_Record
( Disc
: Boolean ) is tagged record
60 FieldA
: Character := 'A';
62 when True => FieldB
: Character := 'B';
63 when False => FieldC
: Character := 'C';
67 procedure Dispatching_Op
( DTO
: in out Discr_Tag_Record
);
69 Authentic
: Boolean := Report
.Ident_Bool
( True );
71 subtype True_Record
is Discr_Tag_Record
( Authentic
);
74 -- derive a type, "passing through" one discriminant, adding one
75 -- discriminant, and a constrained subtype of THAT type:
77 type Derived_Record
( Disc1
, Disc2
: Boolean ) is
78 new Discr_Tag_Record
( Disc1
) with record
79 FieldD
: Character := 'D';
81 when True => FieldE
: Character := 'E';
82 when False => FieldF
: Character := 'F';
86 procedure Dispatching_Op
( DR
: in out Derived_Record
);
88 subtype True_True_Derived
is Derived_Record
( Authentic
, Authentic
);
91 -- now, define an access to classwide type, using the classwide from the
92 -- constrained subtype of the root (or parent) type:
94 type Subtype_Parent_Class_Access
is access all True_Record
'Class;
95 type Parent_Class_Access
is access all Discr_Tag_Record
'Class;
97 procedure PCW_Op
( SPCA
: in Subtype_Parent_Class_Access
);
101 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- C390010_0
105 package body C390010_0
is
107 procedure Dispatching_Op
( DTO
: in out Discr_Tag_Record
) is
109 TCTouch
.Touch
('1'); --------------------------------------------------- 1
111 TCTouch
.Touch
(DTO
.FieldB
); ------------------------------------------ B
113 TCTouch
.Touch
(DTO
.FieldC
); ------------------------------------------ C
118 procedure Dispatching_Op
( DR
: in out Derived_Record
) is
120 TCTouch
.Touch
('2'); --------------------------------------------------- 2
122 TCTouch
.Touch
(DR
.FieldB
); ------------------------------------------ B
124 TCTouch
.Touch
(DR
.FieldC
); ------------------------------------------ C
127 TCTouch
.Touch
(DR
.FieldE
); ------------------------------------------ E
129 TCTouch
.Touch
(DR
.FieldF
); ------------------------------------------ F
133 procedure PCW_Op
( SPCA
: in Subtype_Parent_Class_Access
) is
136 -- the following line is the "heart" of this test, objects of all types
137 -- covered by the classwide type will be passed to this subprogram in
138 -- the execution of the test.
140 TCTouch
.Touch
(SPCA
.FieldB
); ------------------------------------------ B
142 TCTouch
.Touch
(SPCA
.FieldC
); ------------------------------------------ C
145 Dispatching_Op
( SPCA
.all ); -- check that this dispatches correctly,
146 -- with discriminants correctly represented
152 ------------------------------------------------------------------- C390010
159 package CP
renames C390010_0
;
161 procedure Check_Element
( Item
: access CP
.Discr_Tag_Record
'Class ) is
164 -- the implicit conversion from the general access parameter to the more
165 -- constrained subtype access type in the following call should cause
166 -- Constraint_Error in the cases where the object is not correctly
169 CP
.PCW_Op
( Item
.all'Access );
172 when Constraint_Error
=> TCTouch
.Touch
('X'); -------------------------- X
173 when others => Report
.Failed
("Unanticipated exception in Check_Element");
177 An_Item
: CP
.Parent_Class_Access
;
179 begin -- Main test procedure.
181 Report
.Test
("C390010", "Check that if S is a subtype of a tagged type " &
182 "T, and if S is constrained, then the allowable " &
183 "values of S'Class are only those that, when " &
184 "converted to T, belong to S" );
186 An_Item
:= new CP
.Discr_Tag_Record
(True);
187 Check_Element
( An_Item
);
188 TCTouch
.Validate
("B1B","Case 1");
190 An_Item
:= new CP
.Discr_Tag_Record
(False);
191 Check_Element
( An_Item
);
192 TCTouch
.Validate
("X","Case 2");
194 An_Item
:= new CP
.True_Record
;
195 Check_Element
( An_Item
);
196 TCTouch
.Validate
("B1B","Case 3");
198 An_Item
:= new CP
.Derived_Record
(False, False);
199 Check_Element
( An_Item
);
200 TCTouch
.Validate
("X","Case 4");
202 An_Item
:= new CP
.Derived_Record
(False, True);
203 Check_Element
( An_Item
);
204 TCTouch
.Validate
("X","Case 5");
206 An_Item
:= new CP
.Derived_Record
(True, False);
207 Check_Element
( An_Item
);
208 TCTouch
.Validate
("B2BF","Case 6");
210 An_Item
:= new CP
.True_True_Derived
;
211 Check_Element
( An_Item
);
212 TCTouch
.Validate
("B2BE","Case 7");