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 a generic formal package is an instance. Specifically,
28 -- check that a generic formal package may be passed as an actual
29 -- parameter in an instantiation of a generic package. Check that the
30 -- visible part of the generic formal package includes the first list of
31 -- basic declarative items of the package specification.
34 -- A generic formal package is a package, and is an instance.
36 -- Declare a list type in a generic package for lists of elements of any
37 -- nonlimited type (foundation code). Declare a second generic package
38 -- which declares operations for the list type, and parameterize it with
39 -- a generic formal package with the list-type package as template
40 -- (foundation code). Declare a third generic package which declares
41 -- additional operations for the list type, and parameterize it just like
42 -- the second generic package. Declare an instance of the second generic
43 -- in the spec of the third generic, passing the formal package as the
47 -- The following files comprise this test:
54 -- 06 Dec 94 SAIC ACVC 2.0
58 with FC70C00_0
; -- List abstraction.
59 with FC70C00_1
; -- Basic list operations.
61 with package Lists
is new FC70C00_0
(<>);
62 package CC70C01_0
is -- Additional list operations.
64 -- Instantiate a generic package (FC70C00_1) with a generic formal package
65 -- (Lists). This ensures that the package passed as an actual corresponding
66 -- to Lists is the same one passed as an actual to FC70C00_1. Thus, all list
67 -- operations from both FC70C00_1 and this package operate on lists of the
70 package Basic_List_Ops
is new FC70C00_1
(Lists
);
73 End_of_List_Reached
: exception;
76 -- Read from current element and advance "current" pointer.
77 procedure Read_Element
(L
: in out Lists
.List_Type
;
78 E
: out Lists
.Element_Type
);
80 -- Add element to end of list.
81 procedure Add_Element
(L
: in out Lists
.List_Type
;
82 E
: in Lists
.Element_Type
);
87 --==================================================================--
90 package body CC70C01_0
is
92 procedure Read_Element
(L
: in out Lists
.List_Type
;
93 E
: out Lists
.Element_Type
) is
95 if Basic_List_Ops
.End_Of_List
(L
) then -- Use of op from the previous
96 raise End_Of_List_Reached
; -- generic package.
98 E
:= L
.Current
.Item
; -- Retrieve current element.
99 L
.Current
:= L
.Current
.Next
; -- Advance "current" pointer.
104 procedure Add_Element
(L
: in out Lists
.List_Type
;
105 E
: in Lists
.Element_Type
) is
106 New_Node
: Lists
.Node_Pointer
:= new Lists
.Node_Type
'(E, null);
107 use type Lists.Node_Pointer;
109 if L.First = null then -- No elements in list, so add new
110 L.First := New_Node; -- element at beginning of list.
112 L.Last.Next := New_Node; -- Add new element at end of list.
114 L.Last := New_Node; -- Set last-in-list pointer.
121 --==================================================================--
124 with FC70C00_0; -- Generic list abstraction.
125 with CC70C01_0; -- Additional generic list operations.
130 type Points is range 0 .. 100; -- Discrete type.
132 package Lists_of_Points is new FC70C00_0 (Points); -- Points lists.
134 package Points_List_Ops is new -- Points-list ops.
135 CC70C01_0 (Lists_Of_Points);
137 Scores : Lists_of_Points.List_Type; -- List of points.
140 -- Begin test code declarations: -----------------------
142 type TC_Score_Array is array (1 .. 3) of Points;
144 TC_List_Values : constant TC_Score_Array := (23, 15, 0);
146 TC_Correct_List_Values : Boolean := False;
149 procedure TC_Initialize_List (L : in out Lists_Of_Points.List_Type) is
150 begin -- Initial list contains 3 scores
151 for I in TC_Score_Array'Range loop -- with the values 23, 15, and 0.
152 Points_List_Ops.Add_Element (L, TC_List_Values(I));
154 end TC_Initialize_List;
157 procedure TC_Verify_List (L : in out Lists_Of_Points.List_Type;
158 Expected : in TC_Score_Array;
160 Actual : TC_Score_Array;
162 Points_List_Ops.Basic_List_Ops.Reset (L);
163 for I in TC_Score_Array'Range loop
164 Points_List_Ops.Read_Element (L, Actual(I));
166 OK := (Actual = Expected);
169 -- End test code declarations. -------------------------
174 Report.Test ("CC70C01", "Check that a generic formal package may be " &
175 "passed as an actual in an instantiation of a generic " &
178 TC_Initialize_List (Scores);
179 TC_Verify_List (Scores, TC_List_Values, TC_Correct_List_Values);
181 if not TC_Correct_List_Values then
182 Report.Failed ("List contains incorrect values");