2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / gcc / testsuite / ada / acats / tests / c3 / c392011.a
blobc32ec77c0d0bc051457675b1debb760ea201e6f6
1 -- C392011.A
2 --
3 -- Grant of Unlimited Rights
4 --
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
14 -- to do so.
16 -- DISCLAIMER
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.
24 --*
26 -- OBJECTIVE:
27 -- Check that if a function call with a controlling result is itself
28 -- a controlling operand of an enclosing call on a dispatching operation,
29 -- then its controlling tag value is determined by the controlling tag
30 -- value of the enclosing call.
32 -- TEST DESCRIPTION:
33 -- The test builds and traverses a "ragged" list; a linked list which
34 -- contains data elements of three different types (all rooted at
35 -- Level_0'Class). The traversal of this list checks the objective
36 -- by calling the dispatching operation "Check" using an item from the
37 -- list, and calling the function create; thus causing the controlling
38 -- result of the function to be determined by evaluating the value of
39 -- the other controlling parameter to the two-parameter Check.
42 -- CHANGE HISTORY:
43 -- 22 SEP 95 SAIC Initial version
44 -- 23 APR 96 SAIC Corrected commentary, differentiated integer.
46 --!
48 ----------------------------------------------------------------- C392011_0
50 package C392011_0 is
52 type Level_0 is tagged record
53 Ch_Item : Character;
54 end record;
56 function Create return Level_0;
57 -- primitive dispatching function
59 procedure Check( Left, Right: in Level_0 );
60 -- has controlling parameters
62 end C392011_0;
64 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
66 with Report;
67 with TCTouch;
68 package body C392011_0 is
70 The_Character : Character := 'A';
72 function Create return Level_0 is
73 Created_Item_0 : constant Level_0 := ( Ch_Item => The_Character );
74 begin
75 The_Character := Character'Succ(The_Character);
76 TCTouch.Touch('A'); -- --- ---- ----- ---- --- -- --- ---- ----- ---- -- A
77 return Created_Item_0;
78 end Create;
80 procedure Check( Left, Right: in Level_0 ) is
81 begin
82 TCTouch.Touch('B'); -- --- ---- ----- ---- --- -- --- ---- ----- ---- -- B
83 end Check;
85 end C392011_0;
87 ----------------------------------------------------------------- C392011_1
89 with C392011_0;
90 package C392011_1 is
92 type Level_1 is new C392011_0.Level_0 with record
93 Int_Item : Integer;
94 end record;
96 -- note that Create becomes abstract upon this derivation hence:
98 function Create return Level_1;
100 procedure Check( Left, Right: in Level_1 );
102 end C392011_1;
104 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
106 with TCTouch;
107 package body C392011_1 is
109 Integer_1 : Integer := 0;
111 function Create return Level_1 is
112 Created_Item_1 : constant Level_1
113 := ( C392011_0.Create with Int_Item => Integer_1 );
114 -- note call to ^--------------^ -- A
115 begin
116 Integer_1 := Integer'Succ(Integer_1);
117 TCTouch.Touch('C'); -- --- ---- ----- ---- --- -- --- ---- ----- ---- -- C
118 return Created_Item_1;
119 end Create;
121 procedure Check( Left, Right: in Level_1 ) is
122 begin
123 TCTouch.Touch('D'); -- --- ---- ----- ---- --- -- --- ---- ----- ---- -- D
124 end Check;
126 end C392011_1;
128 ----------------------------------------------------------------- C392011_2
130 with C392011_1;
131 package C392011_2 is
133 type Level_2 is new C392011_1.Level_1 with record
134 Another_Int_Item : Integer;
135 end record;
137 -- note that Create becomes abstract upon this derivation hence:
139 function Create return Level_2;
141 procedure Check( Left, Right: in Level_2 );
143 end C392011_2;
145 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
147 with TCTouch;
148 package body C392011_2 is
150 Integer_2 : Integer := 100;
152 function Create return Level_2 is
153 Created_Item_2 : constant Level_2
154 := ( C392011_1.Create with Another_Int_Item => Integer_2 );
155 -- note call to ^--------------^ -- AC
156 begin
157 Integer_2 := Integer'Succ(Integer_2);
158 TCTouch.Touch('E'); -- --- ---- ----- ---- --- -- --- ---- ----- ---- -- E
159 return Created_Item_2;
160 end Create;
162 procedure Check( Left, Right: in Level_2 ) is
163 begin
164 TCTouch.Touch('F'); -- --- ---- ----- ---- --- -- --- ---- ----- ---- -- F
165 end Check;
167 end C392011_2;
169 ------------------------------------------------------- C392011_2.C392011_3
171 with C392011_0;
172 package C392011_2.C392011_3 is
174 type Wide_Reference is access all C392011_0.Level_0'Class;
176 type Ragged_Element;
178 type List_Pointer is access Ragged_Element;
180 type Ragged_Element is record
181 Data : Wide_Reference;
182 Next : List_Pointer;
183 end record;
185 procedure Build_List;
187 procedure Traverse_List;
189 end C392011_2.C392011_3;
191 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
193 package body C392011_2.C392011_3 is
195 The_List : List_Pointer;
197 procedure Build_List is
198 begin
200 -- build a list that looks like:
201 -- Level_2, Level_1, Level_2, Level_1, Level_0
203 -- the mechanism is to create each object, "pushing" the existing list
204 -- onto the end: cons( new_item, car, cdr )
206 The_List :=
207 new Ragged_Element'( new C392011_0.Level_0'(C392011_0.Create), null );
208 -- Level_0 >> A
210 The_List :=
211 new Ragged_Element'( new C392011_1.Level_1'(C392011_1.Create), The_List );
212 -- Level_1 -> Level_0 >> AC
214 The_List :=
215 new Ragged_Element'( new C392011_2.Level_2'(C392011_2.Create), The_List );
216 -- Level_2 -> Level_1 -> Level_0 >> ACE
218 The_List :=
219 new Ragged_Element'( new C392011_1.Level_1'(C392011_1.Create), The_List );
220 -- Level_1 -> Level_2 -> Level_1 -> Level_0 >> AC
222 The_List :=
223 new Ragged_Element'( new C392011_2.Level_2'(C392011_2.Create), The_List );
224 -- Level_2 -> Level_1 -> Level_2 -> Level_1 -> Level_0 >> ACE
226 end Build_List;
228 procedure Traverse_List is
230 Next_Item : List_Pointer := The_List;
232 -- Check that if a function call with a controlling result is itself
233 -- a controlling operand of an enclosing call on a dispatching operation,
234 -- then its controlling tag value is determined by the controlling tag
235 -- value of the enclosing call.
237 -- Level_2 -> Level_1 -> Level_2 -> Level_1 -> Level_0
239 begin
241 while Next_Item /= null loop -- here we go!
242 -- these calls better dispatch according to the value in the particular
243 -- list item; causing the call to create to dispatch accordingly.
244 -- why do it twice? To make sure order makes no difference
246 C392011_0.Check(Next_Item.Data.all, C392011_0.Create);
247 -- Create will touch first, then Check touches
249 C392011_0.Check(C392011_0.Create, Next_Item.Data.all);
251 -- Here's what's s'pos'd to 'appen:
252 -- Check( Lev_2, Create ) >> ACEF
253 -- Check( Create, Lev_2 ) >> ACEF
254 -- Check( Lev_1, Create ) >> ACD
255 -- Check( Create, Lev_1 ) >> ACD
256 -- Check( Lev_2, Create ) >> ACEF
257 -- Check( Create, Lev_2 ) >> ACEF
258 -- Check( Lev_1, Create ) >> ACD
259 -- Check( Create, Lev_1 ) >> ACD
260 -- Check( Lev_0, Create ) >> AB
261 -- Check( Create, Lev_0 ) >> AB
263 Next_Item := Next_Item.Next;
264 end loop;
265 end Traverse_List;
267 end C392011_2.C392011_3;
269 ------------------------------------------------------------------- C392011
271 with Report;
272 with TCTouch;
273 with C392011_2.C392011_3;
275 procedure C392011 is
277 begin -- Main test procedure.
279 Report.Test ("C392011", "Check that if a function call with a " &
280 "controlling result is itself a controlling " &
281 "operand of an enclosing call on a dispatching " &
282 "operation, then its controlling tag value is " &
283 "determined by the controlling tag value of " &
284 "the enclosing call" );
286 C392011_2.C392011_3.Build_List;
287 TCTouch.Validate( "A" & "AC" & "ACE" & "AC" & "ACE", "Build List" );
289 C392011_2.C392011_3.Traverse_List;
290 TCTouch.Validate( "ACEFACEF" &
291 "ACDACD" &
292 "ACEFACEF" &
293 "ACDACD" &
294 "ABAB",
295 "Traverse List" );
297 Report.Result;
299 end C392011;