annotate gcc/testsuite/ada/acats/tests/cc/cc50a01.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 -- CC50A01.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 a formal parameter of a library-level generic unit may be
kono
parents:
diff changeset
28 -- a formal tagged private type. Check that a nonlimited tagged type may
kono
parents:
diff changeset
29 -- be passed as an actual. Check that if the formal type is indefinite,
kono
parents:
diff changeset
30 -- both indefinite and definite types may be passed as actuals.
kono
parents:
diff changeset
31 --
kono
parents:
diff changeset
32 -- TEST DESCRIPTION:
kono
parents:
diff changeset
33 -- The generic package declares a formal tagged private type (this can
kono
parents:
diff changeset
34 -- be considered the parent "mixin" class). This type is extended in
kono
parents:
diff changeset
35 -- the generic to provide support for stacks of items of any nonlimited
kono
parents:
diff changeset
36 -- tagged type. Stacks are modeled as singly linked lists, with the list
kono
parents:
diff changeset
37 -- nodes being objects of the extended type.
kono
parents:
diff changeset
38 --
kono
parents:
diff changeset
39 -- A generic testing procedure pushes items onto a stack, and pops them
kono
parents:
diff changeset
40 -- back off, verifying the state of the stack at various points along the
kono
parents:
diff changeset
41 -- way. The push and pop routines exercise functionality important to
kono
parents:
diff changeset
42 -- tagged types, such as type conversion toward the root of the derivation
kono
parents:
diff changeset
43 -- class and extension aggregates.
kono
parents:
diff changeset
44 --
kono
parents:
diff changeset
45 -- The formal tagged private type has an unknown discriminant part, and
kono
parents:
diff changeset
46 -- is thus indefinite. This allows both definite and indefinite types
kono
parents:
diff changeset
47 -- to be passed as actuals. For tagged types, definite implies
kono
parents:
diff changeset
48 -- nondiscriminated, and indefinite implies discriminated (with known
kono
parents:
diff changeset
49 -- or unknown discriminants).
kono
parents:
diff changeset
50 --
kono
parents:
diff changeset
51 -- TEST FILES:
kono
parents:
diff changeset
52 -- This test consists of the following files:
kono
parents:
diff changeset
53 --
kono
parents:
diff changeset
54 -- FC50A00.A
kono
parents:
diff changeset
55 -- -> CC50A01.A
kono
parents:
diff changeset
56 --
kono
parents:
diff changeset
57 --
kono
parents:
diff changeset
58 -- CHANGE HISTORY:
kono
parents:
diff changeset
59 -- 06 Dec 94 SAIC ACVC 2.0
kono
parents:
diff changeset
60 -- 21 Nov 95 SAIC ACVC 2.0.1 fixes: Moved instantiations of
kono
parents:
diff changeset
61 -- BC50A01_0 to library level.
kono
parents:
diff changeset
62 -- 11 Aug 96 SAIC ACVC 2.1: Updated prologue. Added pragma
kono
parents:
diff changeset
63 -- Elaborate to context clauses for CC50A01_2 & _3.
kono
parents:
diff changeset
64 --
kono
parents:
diff changeset
65 --!
kono
parents:
diff changeset
66
kono
parents:
diff changeset
67 with FC50A00; -- Tagged (actual) type declarations.
kono
parents:
diff changeset
68 generic -- Generic stack abstraction.
kono
parents:
diff changeset
69
kono
parents:
diff changeset
70 type Item (<>) is tagged private; -- Formal tagged private type.
kono
parents:
diff changeset
71 TC_Default_Value : Item; -- Needed in View_Top (see
kono
parents:
diff changeset
72 -- below).
kono
parents:
diff changeset
73 package CC50A01_0 is
kono
parents:
diff changeset
74
kono
parents:
diff changeset
75 type Stack is private;
kono
parents:
diff changeset
76
kono
parents:
diff changeset
77 -- Note that because the actual type corresponding to Item may be
kono
parents:
diff changeset
78 -- unconstrained, the functions of removing the top item from the stack and
kono
parents:
diff changeset
79 -- returning the value of the top item of the stack have been separated into
kono
parents:
diff changeset
80 -- Pop and View_Top, respectively. This is necessary because otherwise the
kono
parents:
diff changeset
81 -- returned value would have to be an out parameter of Pop, which would
kono
parents:
diff changeset
82 -- require the user (in the unconstrained case) to create an uninitialized
kono
parents:
diff changeset
83 -- unconstrained object to serve as the actual, which is illegal.
kono
parents:
diff changeset
84
kono
parents:
diff changeset
85 procedure Push (I : in Item; S : in out Stack);
kono
parents:
diff changeset
86 procedure Pop (S : in out Stack);
kono
parents:
diff changeset
87 function View_Top (S : Stack) return Item;
kono
parents:
diff changeset
88
kono
parents:
diff changeset
89 function Size_Of (S : Stack) return Natural;
kono
parents:
diff changeset
90
kono
parents:
diff changeset
91 private
kono
parents:
diff changeset
92
kono
parents:
diff changeset
93 type Stack_Item;
kono
parents:
diff changeset
94 type Stack_Ptr is access Stack_Item;
kono
parents:
diff changeset
95
kono
parents:
diff changeset
96 type Stack_Item is new Item with record -- Extends formal type.
kono
parents:
diff changeset
97 Next : Stack_Ptr := null;
kono
parents:
diff changeset
98 end record;
kono
parents:
diff changeset
99
kono
parents:
diff changeset
100 type Stack is record
kono
parents:
diff changeset
101 Top : Stack_Ptr := null;
kono
parents:
diff changeset
102 Size : Natural := 0;
kono
parents:
diff changeset
103 end record;
kono
parents:
diff changeset
104
kono
parents:
diff changeset
105 end CC50A01_0;
kono
parents:
diff changeset
106
kono
parents:
diff changeset
107
kono
parents:
diff changeset
108 --==================================================================--
kono
parents:
diff changeset
109
kono
parents:
diff changeset
110
kono
parents:
diff changeset
111 package body CC50A01_0 is
kono
parents:
diff changeset
112
kono
parents:
diff changeset
113 -- Link NewItem in at the top of the stack (the extension aggregate within
kono
parents:
diff changeset
114 -- the allocator initializes the inherited portion of NewItem to equal I,
kono
parents:
diff changeset
115 -- and NewItem.Next to point to what S.Top points to).
kono
parents:
diff changeset
116
kono
parents:
diff changeset
117 procedure Push (I : in Item; S : in out Stack) is
kono
parents:
diff changeset
118 NewItem : Stack_Ptr;
kono
parents:
diff changeset
119 begin
kono
parents:
diff changeset
120 NewItem := new Stack_Item'(I with S.Top); -- Extension aggregate.
kono
parents:
diff changeset
121 S.Top := NewItem;
kono
parents:
diff changeset
122 S.Size := S.Size + 1;
kono
parents:
diff changeset
123 end Push;
kono
parents:
diff changeset
124
kono
parents:
diff changeset
125
kono
parents:
diff changeset
126 -- Remove item from top of stack. This procedure only updates the state of
kono
parents:
diff changeset
127 -- the stack; it does not return the value of the popped item. Hence, in
kono
parents:
diff changeset
128 -- order to accomplish a "true" pop, both View_Top and Pop must be called
kono
parents:
diff changeset
129 -- consecutively.
kono
parents:
diff changeset
130 --
kono
parents:
diff changeset
131 -- If the stack is empty, the Pop is ignored (for simplicity; in a true
kono
parents:
diff changeset
132 -- application this might be treated as an error condition).
kono
parents:
diff changeset
133
kono
parents:
diff changeset
134 procedure Pop (S : in out Stack) is
kono
parents:
diff changeset
135 begin
kono
parents:
diff changeset
136 if S.Top = null then -- Stack is empty.
kono
parents:
diff changeset
137 null;
kono
parents:
diff changeset
138 -- Raise exception.
kono
parents:
diff changeset
139 else
kono
parents:
diff changeset
140 S.Top := S.Top.Next;
kono
parents:
diff changeset
141 S.Size := S.Size - 1;
kono
parents:
diff changeset
142 -- Deallocate discarded node.
kono
parents:
diff changeset
143 end if;
kono
parents:
diff changeset
144 end Pop;
kono
parents:
diff changeset
145
kono
parents:
diff changeset
146
kono
parents:
diff changeset
147 -- Return the value of the top item on the stack. This procedure only
kono
parents:
diff changeset
148 -- returns the value; it does not remove the top item from the stack.
kono
parents:
diff changeset
149 -- Hence, in order to accomplish a "true" pop, both View_Top and Pop must
kono
parents:
diff changeset
150 -- be called consecutively.
kono
parents:
diff changeset
151 --
kono
parents:
diff changeset
152 -- Since items on the stack are of a type (Stack_Item) derived from Item,
kono
parents:
diff changeset
153 -- which is a (tagged) private type, type conversion toward the root is the
kono
parents:
diff changeset
154 -- only way to get a value of type Item for return to the caller.
kono
parents:
diff changeset
155 --
kono
parents:
diff changeset
156 -- If the stack is empty, View_Top returns a pre-specified default value.
kono
parents:
diff changeset
157 -- (In a true application, an exception might be raised instead).
kono
parents:
diff changeset
158
kono
parents:
diff changeset
159 function View_Top (S : Stack) return Item is
kono
parents:
diff changeset
160 begin
kono
parents:
diff changeset
161 if S.Top = null then -- Stack is empty.
kono
parents:
diff changeset
162 return TC_Default_Value; -- Testing artifice.
kono
parents:
diff changeset
163 -- Raise exception.
kono
parents:
diff changeset
164 else
kono
parents:
diff changeset
165 return Item(S.Top.all); -- Type conversion.
kono
parents:
diff changeset
166 end if;
kono
parents:
diff changeset
167 end View_Top;
kono
parents:
diff changeset
168
kono
parents:
diff changeset
169
kono
parents:
diff changeset
170 function Size_Of (S : Stack) return Natural is
kono
parents:
diff changeset
171 begin
kono
parents:
diff changeset
172 return (S.Size);
kono
parents:
diff changeset
173 end Size_Of;
kono
parents:
diff changeset
174
kono
parents:
diff changeset
175
kono
parents:
diff changeset
176 end CC50A01_0;
kono
parents:
diff changeset
177
kono
parents:
diff changeset
178
kono
parents:
diff changeset
179 --==================================================================--
kono
parents:
diff changeset
180
kono
parents:
diff changeset
181
kono
parents:
diff changeset
182 -- The formal package Stacker below is needed to gain access to the
kono
parents:
diff changeset
183 -- appropriate version of the "generic" type Stack. It is provided with an
kono
parents:
diff changeset
184 -- explicit actual part in order to restrict the packages that can be passed
kono
parents:
diff changeset
185 -- as actuals to those which have been instantiated with the same actuals
kono
parents:
diff changeset
186 -- which this generic procedure has been instantiated with.
kono
parents:
diff changeset
187
kono
parents:
diff changeset
188 with CC50A01_0; -- Generic stack abstraction.
kono
parents:
diff changeset
189 generic
kono
parents:
diff changeset
190 type Item_Type (<>) is tagged private; -- Formal tagged private type.
kono
parents:
diff changeset
191 Default : Item_Type;
kono
parents:
diff changeset
192 with package Stacker is new CC50A01_0 (Item_Type, Default);
kono
parents:
diff changeset
193 procedure CC50A01_1 (S : in out Stacker.Stack; I : in Item_Type);
kono
parents:
diff changeset
194
kono
parents:
diff changeset
195
kono
parents:
diff changeset
196 --==================================================================--
kono
parents:
diff changeset
197
kono
parents:
diff changeset
198 --
kono
parents:
diff changeset
199 -- This generic procedure performs all of the testing of the
kono
parents:
diff changeset
200 -- stack abstraction.
kono
parents:
diff changeset
201 --
kono
parents:
diff changeset
202
kono
parents:
diff changeset
203 with Report;
kono
parents:
diff changeset
204 procedure CC50A01_1 (S : in out Stacker.Stack; I : in Item_Type) is
kono
parents:
diff changeset
205 begin
kono
parents:
diff changeset
206 Stacker.Push (I, S); -- Push onto empty stack.
kono
parents:
diff changeset
207 Stacker.Push (I, S); -- Push onto nonempty stack.
kono
parents:
diff changeset
208
kono
parents:
diff changeset
209 if Stacker.Size_Of (S) /= 2 then
kono
parents:
diff changeset
210 Report.Failed (" Wrong stack size after 2 Pushes");
kono
parents:
diff changeset
211 end if;
kono
parents:
diff changeset
212
kono
parents:
diff changeset
213 -- Calls to View_Top must initialize a declared object of type Item_Type
kono
parents:
diff changeset
214 -- because the type may be unconstrained.
kono
parents:
diff changeset
215
kono
parents:
diff changeset
216 declare
kono
parents:
diff changeset
217 Buffer1 : Item_Type := Stacker.View_Top (S);
kono
parents:
diff changeset
218 begin
kono
parents:
diff changeset
219 Stacker.Pop (S); -- Pop item off nonempty stack.
kono
parents:
diff changeset
220 if Buffer1 /= I then
kono
parents:
diff changeset
221 Report.Failed (" Wrong stack item value after 1st Pop");
kono
parents:
diff changeset
222 end if;
kono
parents:
diff changeset
223 end;
kono
parents:
diff changeset
224
kono
parents:
diff changeset
225 declare
kono
parents:
diff changeset
226 Buffer2 : Item_Type := Stacker.View_Top (S);
kono
parents:
diff changeset
227 begin
kono
parents:
diff changeset
228 Stacker.Pop (S); -- Pop last item off stack.
kono
parents:
diff changeset
229 if Buffer2 /= I then
kono
parents:
diff changeset
230 Report.Failed (" Wrong stack item value after 2nd Pop");
kono
parents:
diff changeset
231 end if;
kono
parents:
diff changeset
232 end;
kono
parents:
diff changeset
233
kono
parents:
diff changeset
234 if Stacker.Size_Of (S) /= 0 then
kono
parents:
diff changeset
235 Report.Failed (" Wrong stack size after 2 Pops");
kono
parents:
diff changeset
236 end if;
kono
parents:
diff changeset
237
kono
parents:
diff changeset
238 declare
kono
parents:
diff changeset
239 Buffer3 : Item_Type := Stacker.View_Top (S);
kono
parents:
diff changeset
240 begin
kono
parents:
diff changeset
241 if Buffer3 /= Default then
kono
parents:
diff changeset
242 Report.Failed (" Wrong result after Pop of empty stack");
kono
parents:
diff changeset
243 end if;
kono
parents:
diff changeset
244 Stacker.Pop (S); -- Pop off empty stack.
kono
parents:
diff changeset
245 end;
kono
parents:
diff changeset
246
kono
parents:
diff changeset
247 end CC50A01_1;
kono
parents:
diff changeset
248
kono
parents:
diff changeset
249
kono
parents:
diff changeset
250 --==================================================================--
kono
parents:
diff changeset
251
kono
parents:
diff changeset
252
kono
parents:
diff changeset
253 with FC50A00;
kono
parents:
diff changeset
254
kono
parents:
diff changeset
255 with CC50A01_0;
kono
parents:
diff changeset
256 pragma Elaborate (CC50A01_0);
kono
parents:
diff changeset
257
kono
parents:
diff changeset
258 package CC50A01_2 is new CC50A01_0 (FC50A00.Count_Type,
kono
parents:
diff changeset
259 FC50A00.TC_Default_Count);
kono
parents:
diff changeset
260
kono
parents:
diff changeset
261
kono
parents:
diff changeset
262 --==================================================================--
kono
parents:
diff changeset
263
kono
parents:
diff changeset
264
kono
parents:
diff changeset
265 with FC50A00;
kono
parents:
diff changeset
266
kono
parents:
diff changeset
267 with CC50A01_0;
kono
parents:
diff changeset
268 pragma Elaborate (CC50A01_0);
kono
parents:
diff changeset
269
kono
parents:
diff changeset
270 package CC50A01_3 is new CC50A01_0 (FC50A00.Person_Type,
kono
parents:
diff changeset
271 FC50A00.TC_Default_Person);
kono
parents:
diff changeset
272
kono
parents:
diff changeset
273
kono
parents:
diff changeset
274 --==================================================================--
kono
parents:
diff changeset
275
kono
parents:
diff changeset
276
kono
parents:
diff changeset
277 with FC50A00; -- Tagged (actual) type declarations.
kono
parents:
diff changeset
278 with CC50A01_0; -- Generic stack abstraction.
kono
parents:
diff changeset
279 with CC50A01_1; -- Generic stack testing procedure.
kono
parents:
diff changeset
280 with CC50A01_2;
kono
parents:
diff changeset
281 with CC50A01_3;
kono
parents:
diff changeset
282
kono
parents:
diff changeset
283 with Report;
kono
parents:
diff changeset
284 procedure CC50A01 is
kono
parents:
diff changeset
285
kono
parents:
diff changeset
286 package Count_Stacks renames CC50A01_2;
kono
parents:
diff changeset
287 package Person_Stacks renames CC50A01_3;
kono
parents:
diff changeset
288
kono
parents:
diff changeset
289
kono
parents:
diff changeset
290 procedure TC_Count_Test is new CC50A01_1 (FC50A00.Count_Type,
kono
parents:
diff changeset
291 FC50A00.TC_Default_Count,
kono
parents:
diff changeset
292 Count_Stacks);
kono
parents:
diff changeset
293 Count_Stack : Count_Stacks.Stack;
kono
parents:
diff changeset
294
kono
parents:
diff changeset
295
kono
parents:
diff changeset
296 procedure TC_Person_Test is new CC50A01_1 (FC50A00.Person_Type,
kono
parents:
diff changeset
297 FC50A00.TC_Default_Person,
kono
parents:
diff changeset
298 Person_Stacks);
kono
parents:
diff changeset
299 Person_Stack : Person_Stacks.Stack;
kono
parents:
diff changeset
300
kono
parents:
diff changeset
301 begin
kono
parents:
diff changeset
302 Report.Test ("CC50A01", "Check that a formal parameter of a " &
kono
parents:
diff changeset
303 "library-level generic unit may be a formal tagged " &
kono
parents:
diff changeset
304 "private type");
kono
parents:
diff changeset
305
kono
parents:
diff changeset
306 Report.Comment ("Testing definite tagged type..");
kono
parents:
diff changeset
307 TC_Count_Test (Count_Stack, FC50A00.TC_Count_Item);
kono
parents:
diff changeset
308
kono
parents:
diff changeset
309 Report.Comment ("Testing indefinite tagged type..");
kono
parents:
diff changeset
310 TC_Person_Test (Person_Stack, FC50A00.TC_Person_Item);
kono
parents:
diff changeset
311
kono
parents:
diff changeset
312 Report.Result;
kono
parents:
diff changeset
313 end CC50A01;