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 formal package actual part may specify actual parameters
28 -- for a generic formal package. Check that these actual parameters may
29 -- be formal types, formal objects, and formal subprograms. Check that
30 -- the visible part of the generic formal package includes the first list
31 -- of basic declarative items of the package specification, and that if
32 -- the formal package actual part is (<>), it also includes the generic
33 -- formal part of the template for the formal package.
36 -- Declare a generic package which defines a "signature" for mathematical
37 -- groups. Declare a second generic package which defines a
38 -- two-dimensional matrix abstraction. Declare a third generic package
39 -- which provides mathematical group operations for two-dimensional
40 -- matrices. Provide this third generic with two formal parameters: (1)
41 -- a generic formal package with the second generic as template and a
42 -- (<>) actual part, and (2) a generic formal package with the first
43 -- generic as template and an actual part that takes a formal type,
44 -- object, and subprogram from the first formal package as actuals.
48 -- 06 Dec 94 SAIC ACVC 2.0
52 generic -- Mathematical group signature.
54 type Group_Type
is private;
56 Identity
: in Group_Type
;
58 with function Operation
(Left
, Right
: Group_Type
) return Group_Type
;
59 -- with function Inverse... (omitted for brevity).
63 function Power
(Left
: Group_Type
; Right
: Integer) return Group_Type
;
65 -- ... Other group operations.
70 --==================================================================--
73 package body CC70002_0
is
75 -- The implementation of Power is purely artificial; the validity of its
76 -- implementation in the context of the abstraction is irrelevant to the
77 -- feature being tested.
79 function Power
(Left
: Group_Type
; Right
: Integer) return Group_Type
is
80 Result
: Group_Type
:= Identity
;
82 Result
:= Operation
(Result
, Left
); -- All this really does is add
83 return Result
; -- one to each matrix element.
89 --==================================================================--
92 generic -- 2D matrix abstraction.
93 type Element_Type
is range <>;
95 type Abscissa
is range <>;
96 type Ordinate
is range <>;
98 type Matrix_2D
is array (Abscissa
, Ordinate
) of Element_Type
;
101 Add_Ident
: constant Matrix_2D
:= (Abscissa
=> (others => 1));
104 -- ... Other identity matrices.
107 function "+" (A
, B
: Matrix_2D
) return Matrix_2D
;
109 -- ... Other operations.
114 --==================================================================--
117 package body CC70002_1
is
119 function "+" (A
, B
: Matrix_2D
) return Matrix_2D
is
122 for I
in Abscissa
loop
123 for J
in Ordinate
loop
124 C
(I
,J
) := A
(I
,J
) + B
(I
,J
);
133 --==================================================================--
136 with CC70002_0
; -- Mathematical group signature.
137 with CC70002_1
; -- 2D matrix abstraction.
139 generic -- Mathematical 2D matrix addition group.
141 with package Matrix_Ops
is new CC70002_1
(<>);
143 -- Although the restriction of the formal package below to signatures
144 -- describing addition groups, and then only for 2D matrices, is rather
145 -- artificial in the context of this "application," the passing of types,
146 -- objects, and subprograms as actuals to a formal package is not.
148 with package Math_Sig
is new CC70002_0
149 (Group_Type
=> Matrix_Ops
.Matrix_2D
,
150 Identity
=> Matrix_Ops
.Add_Ident
,
151 Operation
=> Matrix_Ops
."+");
155 -- Add two matrices that are to be multiplied by coefficients:
156 -- [ ] = CA*[ ] + CB*[ ].
158 function Add_Matrices_With_Coefficients
(A
: Matrix_Ops
.Matrix_2D
;
160 B
: Matrix_Ops
.Matrix_2D
;
162 return Matrix_Ops
.Matrix_2D
;
164 -- ...Other operations.
169 --==================================================================--
172 package body CC70002_2
is
174 function Add_Matrices_With_Coefficients
(A
: Matrix_Ops
.Matrix_2D
;
176 B
: Matrix_Ops
.Matrix_2D
;
178 return Matrix_Ops
.Matrix_2D
is
179 Left
, Right
: Matrix_Ops
.Matrix_2D
;
181 Left
:= Math_Sig
.Power
(A
, CA
); -- Multiply 1st array by its coeff.
182 Right
:= Math_Sig
.Power
(B
, CB
); -- Multiply 2nd array by its coeff.
183 return (Matrix_Ops
."+" (Left
, Right
));-- Add these two arrays.
184 end Add_Matrices_With_Coefficients
;
189 --==================================================================--
192 with CC70002_0
; -- Mathematical group signature.
193 with CC70002_1
; -- 2D matrix abstraction.
194 with CC70002_2
; -- Mathematical 2D matrix addition group.
199 subtype Cell_Type
is Positive range 1 .. 3;
200 subtype Category_Type
is Positive range 1 .. 2;
202 type Data_Points
is new Natural range 0 .. 100;
204 type Table_Type
is array (Cell_Type
, Category_Type
) of Data_Points
;
206 package Data_Table_Support
is new CC70002_1
(Data_Points
,
211 package Data_Table_Addition_Group
is new CC70002_0
212 (Group_Type
=> Table_Type
,
213 Identity
=> Data_Table_Support
.Add_Ident
,
214 Operation
=> Data_Table_Support
."+");
216 package Table_Add_Ops
is new CC70002_2
217 (Data_Table_Support
, Data_Table_Addition_Group
);
220 Scores_Table
: Table_Type
:= ( ( 12, 0),
223 Expected
: Table_Type
:= ( ( 26, 2),
228 Report
.Test
("CC70002", "Check that a generic formal package actual " &
229 "part may specify formal objects, formal subprograms, " &
232 Scores_Table
:= Table_Add_Ops
.Add_Matrices_With_Coefficients
236 if (Scores_Table
/= Expected
) then
237 Report
.Failed
("Incorrect result for multi-dimensional array");