annotate gcc/testsuite/ada/acats/tests/c3/c390010.a @ 111:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 -- C390010.A
kono
parents:
diff changeset
2 --
kono
parents:
diff changeset
3 -- Grant of Unlimited Rights
kono
parents:
diff changeset
4 --
kono
parents:
diff changeset
5 -- Under contracts F33600-87-D-0337, F33600-84-D-0280, MDA903-79-C-0687,
kono
parents:
diff changeset
6 -- F08630-91-C-0015, and DCA100-97-D-0025, the U.S. Government obtained
kono
parents:
diff changeset
7 -- unlimited rights in the software and documentation contained herein.
kono
parents:
diff changeset
8 -- Unlimited rights are defined in DFAR 252.227-7013(a)(19). By making
kono
parents:
diff changeset
9 -- this public release, the Government intends to confer upon all
kono
parents:
diff changeset
10 -- recipients unlimited rights equal to those held by the Government.
kono
parents:
diff changeset
11 -- These rights include rights to use, duplicate, release or disclose the
kono
parents:
diff changeset
12 -- released technical data and computer software in whole or in part, in
kono
parents:
diff changeset
13 -- any manner and for any purpose whatsoever, and to have or permit others
kono
parents:
diff changeset
14 -- to do so.
kono
parents:
diff changeset
15 --
kono
parents:
diff changeset
16 -- DISCLAIMER
kono
parents:
diff changeset
17 --
kono
parents:
diff changeset
18 -- ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR
kono
parents:
diff changeset
19 -- DISCLOSED ARE AS IS. THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED
kono
parents:
diff changeset
20 -- WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE
kono
parents:
diff changeset
21 -- SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE
kono
parents:
diff changeset
22 -- OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A
kono
parents:
diff changeset
23 -- PARTICULAR PURPOSE OF SAID MATERIAL.
kono
parents:
diff changeset
24 --*
kono
parents:
diff changeset
25 --
kono
parents:
diff changeset
26 -- OBJECTIVE:
kono
parents:
diff changeset
27 -- Check that if S is a subtype of a tagged type T, and if S is
kono
parents:
diff changeset
28 -- constrained, then the allowable values of S'Class are only those
kono
parents:
diff changeset
29 -- that, when converted to T, belong to S.
kono
parents:
diff changeset
30 --
kono
parents:
diff changeset
31 -- TEST DESCRIPTION:
kono
parents:
diff changeset
32 -- This test defines a small tagged hierarchy of discriminated tagged
kono
parents:
diff changeset
33 -- records, and constrained subtypes of those tagged record types.
kono
parents:
diff changeset
34 -- It then uses access to the classwide of the constrained subtype
kono
parents:
diff changeset
35 -- to check the objective.
kono
parents:
diff changeset
36 --
kono
parents:
diff changeset
37 --
kono
parents:
diff changeset
38 -- CHANGE HISTORY:
kono
parents:
diff changeset
39 -- 09 APR 96 SAIC Initial version
kono
parents:
diff changeset
40 -- 03 NOV 96 SAIC Revised for 2.1 release
kono
parents:
diff changeset
41 -- 31 DEC 97 EDS Restored use of intermediate access variable
kono
parents:
diff changeset
42 -- to eliminate raising of Program_Error
kono
parents:
diff changeset
43 -- 13 SEP 99 RLB Repaired previous change to avoid premature
kono
parents:
diff changeset
44 -- subtype check.
kono
parents:
diff changeset
45 -- 28 JUN 02 RLB Added pragma Elaborate_All (Report);.
kono
parents:
diff changeset
46 --!
kono
parents:
diff changeset
47
kono
parents:
diff changeset
48 ----------------------------------------------------------------- C390010_0
kono
parents:
diff changeset
49
kono
parents:
diff changeset
50 with Report; pragma Elaborate_All (Report);
kono
parents:
diff changeset
51 package C390010_0 is
kono
parents:
diff changeset
52
kono
parents:
diff changeset
53 -- the defined subprograms will allow checking the placement of
kono
parents:
diff changeset
54 -- constraint_checks
kono
parents:
diff changeset
55
kono
parents:
diff changeset
56 -- define a discriminated tagged type, and a constrained subtype of
kono
parents:
diff changeset
57 -- that type:
kono
parents:
diff changeset
58
kono
parents:
diff changeset
59 type Discr_Tag_Record( Disc: Boolean ) is tagged record
kono
parents:
diff changeset
60 FieldA : Character := 'A';
kono
parents:
diff changeset
61 case Disc is
kono
parents:
diff changeset
62 when True => FieldB : Character := 'B';
kono
parents:
diff changeset
63 when False => FieldC : Character := 'C';
kono
parents:
diff changeset
64 end case;
kono
parents:
diff changeset
65 end record;
kono
parents:
diff changeset
66
kono
parents:
diff changeset
67 procedure Dispatching_Op( DTO : in out Discr_Tag_Record );
kono
parents:
diff changeset
68
kono
parents:
diff changeset
69 Authentic : Boolean := Report.Ident_Bool( True );
kono
parents:
diff changeset
70
kono
parents:
diff changeset
71 subtype True_Record is Discr_Tag_Record( Authentic );
kono
parents:
diff changeset
72
kono
parents:
diff changeset
73
kono
parents:
diff changeset
74 -- derive a type, "passing through" one discriminant, adding one
kono
parents:
diff changeset
75 -- discriminant, and a constrained subtype of THAT type:
kono
parents:
diff changeset
76
kono
parents:
diff changeset
77 type Derived_Record( Disc1, Disc2: Boolean ) is
kono
parents:
diff changeset
78 new Discr_Tag_Record( Disc1 ) with record
kono
parents:
diff changeset
79 FieldD : Character := 'D';
kono
parents:
diff changeset
80 case Disc2 is
kono
parents:
diff changeset
81 when True => FieldE : Character := 'E';
kono
parents:
diff changeset
82 when False => FieldF : Character := 'F';
kono
parents:
diff changeset
83 end case;
kono
parents:
diff changeset
84 end record;
kono
parents:
diff changeset
85
kono
parents:
diff changeset
86 procedure Dispatching_Op( DR : in out Derived_Record );
kono
parents:
diff changeset
87
kono
parents:
diff changeset
88 subtype True_True_Derived is Derived_Record( Authentic, Authentic );
kono
parents:
diff changeset
89
kono
parents:
diff changeset
90
kono
parents:
diff changeset
91 -- now, define an access to classwide type, using the classwide from the
kono
parents:
diff changeset
92 -- constrained subtype of the root (or parent) type:
kono
parents:
diff changeset
93
kono
parents:
diff changeset
94 type Subtype_Parent_Class_Access is access all True_Record'Class;
kono
parents:
diff changeset
95 type Parent_Class_Access is access all Discr_Tag_Record'Class;
kono
parents:
diff changeset
96
kono
parents:
diff changeset
97 procedure PCW_Op( SPCA : in Subtype_Parent_Class_Access );
kono
parents:
diff changeset
98
kono
parents:
diff changeset
99 end C390010_0;
kono
parents:
diff changeset
100
kono
parents:
diff changeset
101 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- C390010_0
kono
parents:
diff changeset
102
kono
parents:
diff changeset
103 with Report;
kono
parents:
diff changeset
104 with TCTouch;
kono
parents:
diff changeset
105 package body C390010_0 is
kono
parents:
diff changeset
106
kono
parents:
diff changeset
107 procedure Dispatching_Op( DTO : in out Discr_Tag_Record ) is
kono
parents:
diff changeset
108 begin
kono
parents:
diff changeset
109 TCTouch.Touch('1'); --------------------------------------------------- 1
kono
parents:
diff changeset
110 if DTO.Disc then
kono
parents:
diff changeset
111 TCTouch.Touch(DTO.FieldB); ------------------------------------------ B
kono
parents:
diff changeset
112 else
kono
parents:
diff changeset
113 TCTouch.Touch(DTO.FieldC); ------------------------------------------ C
kono
parents:
diff changeset
114 end if;
kono
parents:
diff changeset
115 end Dispatching_Op;
kono
parents:
diff changeset
116
kono
parents:
diff changeset
117
kono
parents:
diff changeset
118 procedure Dispatching_Op( DR : in out Derived_Record ) is
kono
parents:
diff changeset
119 begin
kono
parents:
diff changeset
120 TCTouch.Touch('2'); --------------------------------------------------- 2
kono
parents:
diff changeset
121 if DR.Disc1 then
kono
parents:
diff changeset
122 TCTouch.Touch(DR.FieldB); ------------------------------------------ B
kono
parents:
diff changeset
123 else
kono
parents:
diff changeset
124 TCTouch.Touch(DR.FieldC); ------------------------------------------ C
kono
parents:
diff changeset
125 end if;
kono
parents:
diff changeset
126 if DR.Disc2 then
kono
parents:
diff changeset
127 TCTouch.Touch(DR.FieldE); ------------------------------------------ E
kono
parents:
diff changeset
128 else
kono
parents:
diff changeset
129 TCTouch.Touch(DR.FieldF); ------------------------------------------ F
kono
parents:
diff changeset
130 end if;
kono
parents:
diff changeset
131 end Dispatching_Op;
kono
parents:
diff changeset
132
kono
parents:
diff changeset
133 procedure PCW_Op( SPCA : in Subtype_Parent_Class_Access ) is
kono
parents:
diff changeset
134 begin
kono
parents:
diff changeset
135
kono
parents:
diff changeset
136 -- the following line is the "heart" of this test, objects of all types
kono
parents:
diff changeset
137 -- covered by the classwide type will be passed to this subprogram in
kono
parents:
diff changeset
138 -- the execution of the test.
kono
parents:
diff changeset
139 if SPCA.Disc then
kono
parents:
diff changeset
140 TCTouch.Touch(SPCA.FieldB); ------------------------------------------ B
kono
parents:
diff changeset
141 else
kono
parents:
diff changeset
142 TCTouch.Touch(SPCA.FieldC); ------------------------------------------ C
kono
parents:
diff changeset
143 end if;
kono
parents:
diff changeset
144
kono
parents:
diff changeset
145 Dispatching_Op( SPCA.all ); -- check that this dispatches correctly,
kono
parents:
diff changeset
146 -- with discriminants correctly represented
kono
parents:
diff changeset
147
kono
parents:
diff changeset
148 end PCW_Op;
kono
parents:
diff changeset
149
kono
parents:
diff changeset
150 end C390010_0;
kono
parents:
diff changeset
151
kono
parents:
diff changeset
152 ------------------------------------------------------------------- C390010
kono
parents:
diff changeset
153
kono
parents:
diff changeset
154 with Report;
kono
parents:
diff changeset
155 with TCTouch;
kono
parents:
diff changeset
156 with C390010_0;
kono
parents:
diff changeset
157 procedure C390010 is
kono
parents:
diff changeset
158
kono
parents:
diff changeset
159 package CP renames C390010_0;
kono
parents:
diff changeset
160
kono
parents:
diff changeset
161 procedure Check_Element( Item : access CP.Discr_Tag_Record'Class ) is
kono
parents:
diff changeset
162 begin
kono
parents:
diff changeset
163
kono
parents:
diff changeset
164 -- the implicit conversion from the general access parameter to the more
kono
parents:
diff changeset
165 -- constrained subtype access type in the following call should cause
kono
parents:
diff changeset
166 -- Constraint_Error in the cases where the object is not correctly
kono
parents:
diff changeset
167 -- constrained
kono
parents:
diff changeset
168
kono
parents:
diff changeset
169 CP.PCW_Op( Item.all'Access );
kono
parents:
diff changeset
170
kono
parents:
diff changeset
171 exception
kono
parents:
diff changeset
172 when Constraint_Error => TCTouch.Touch('X'); -------------------------- X
kono
parents:
diff changeset
173 when others => Report.Failed("Unanticipated exception in Check_Element");
kono
parents:
diff changeset
174
kono
parents:
diff changeset
175 end Check_Element;
kono
parents:
diff changeset
176
kono
parents:
diff changeset
177 An_Item : CP.Parent_Class_Access;
kono
parents:
diff changeset
178
kono
parents:
diff changeset
179 begin -- Main test procedure.
kono
parents:
diff changeset
180
kono
parents:
diff changeset
181 Report.Test ("C390010", "Check that if S is a subtype of a tagged type " &
kono
parents:
diff changeset
182 "T, and if S is constrained, then the allowable " &
kono
parents:
diff changeset
183 "values of S'Class are only those that, when " &
kono
parents:
diff changeset
184 "converted to T, belong to S" );
kono
parents:
diff changeset
185
kono
parents:
diff changeset
186 An_Item := new CP.Discr_Tag_Record(True);
kono
parents:
diff changeset
187 Check_Element( An_Item );
kono
parents:
diff changeset
188 TCTouch.Validate("B1B","Case 1");
kono
parents:
diff changeset
189
kono
parents:
diff changeset
190 An_Item := new CP.Discr_Tag_Record(False);
kono
parents:
diff changeset
191 Check_Element( An_Item );
kono
parents:
diff changeset
192 TCTouch.Validate("X","Case 2");
kono
parents:
diff changeset
193
kono
parents:
diff changeset
194 An_Item := new CP.True_Record;
kono
parents:
diff changeset
195 Check_Element( An_Item );
kono
parents:
diff changeset
196 TCTouch.Validate("B1B","Case 3");
kono
parents:
diff changeset
197
kono
parents:
diff changeset
198 An_Item := new CP.Derived_Record(False, False);
kono
parents:
diff changeset
199 Check_Element( An_Item );
kono
parents:
diff changeset
200 TCTouch.Validate("X","Case 4");
kono
parents:
diff changeset
201
kono
parents:
diff changeset
202 An_Item := new CP.Derived_Record(False, True);
kono
parents:
diff changeset
203 Check_Element( An_Item );
kono
parents:
diff changeset
204 TCTouch.Validate("X","Case 5");
kono
parents:
diff changeset
205
kono
parents:
diff changeset
206 An_Item := new CP.Derived_Record(True, False);
kono
parents:
diff changeset
207 Check_Element( An_Item );
kono
parents:
diff changeset
208 TCTouch.Validate("B2BF","Case 6");
kono
parents:
diff changeset
209
kono
parents:
diff changeset
210 An_Item := new CP.True_True_Derived;
kono
parents:
diff changeset
211 Check_Element( An_Item );
kono
parents:
diff changeset
212 TCTouch.Validate("B2BE","Case 7");
kono
parents:
diff changeset
213
kono
parents:
diff changeset
214 Report.Result;
kono
parents:
diff changeset
215
kono
parents:
diff changeset
216 end C390010;