1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
|
-- CC70A01.A
--
-- Grant of Unlimited Rights
--
-- Under contracts F33600-87-D-0337, F33600-84-D-0280, MDA903-79-C-0687,
-- F08630-91-C-0015, and DCA100-97-D-0025, the U.S. Government obtained
-- unlimited rights in the software and documentation contained herein.
-- Unlimited rights are defined in DFAR 252.227-7013(a)(19). By making
-- this public release, the Government intends to confer upon all
-- recipients unlimited rights equal to those held by the Government.
-- These rights include rights to use, duplicate, release or disclose the
-- released technical data and computer software in whole or in part, in
-- any manner and for any purpose whatsoever, and to have or permit others
-- to do so.
--
-- DISCLAIMER
--
-- ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR
-- DISCLOSED ARE AS IS. THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED
-- WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE
-- SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE
-- OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A
-- PARTICULAR PURPOSE OF SAID MATERIAL.
--*
--
-- OBJECTIVE:
-- Check that the visible part of a generic formal package includes the
-- first list of basic declarative items of the package specification.
-- Check for a generic package which declares a formal package with (<>)
-- as its actual part.
--
-- TEST DESCRIPTION:
-- The "first list of basic declarative items" of a package specification
-- is the visible part of the package. Thus, the declarations in the
-- visible part of the actual instance corresponding to a formal
-- package are available in the generic which declares the formal package.
--
-- Declare a generic package which simulates a complex integer abstraction
-- (foundation code).
--
-- Declare a second, library-level generic package which utilizes the
-- first generic package as a generic formal package (with a (<>)
-- actual_part). In the second generic package, declare objects, types,
-- and operations in terms of the objects, types, and operations declared
-- in the first generic package.
--
-- In the main program, instantiate the first generic package, then
-- instantiate the second generic package and pass the first instance
-- to it as a generic actual parameter. Check that the operations in
-- the second instance perform as expected.
--
--
-- CHANGE HISTORY:
-- 06 Dec 94 SAIC ACVC 2.0
--
--!
with FC70A00; -- Generic complex integer operations.
generic -- Generic complex matrix operations.
with package Complex_Package is new FC70A00 (<>);
package CC70A01_0 is
type Complex_Matrix_Type is -- 1st index is matrix
array (Positive range <>, Positive range <>) -- row, 2nd is column.
of Complex_Package.Complex_Type;
Dimension_Mismatch : exception;
function Identity_Matrix (Size : Positive) -- Create identity matrix
return Complex_Matrix_Type; -- of specified size.
function "*" (Left : Complex_Matrix_Type; -- Multiply two complex
Right : Complex_Matrix_Type) -- matrices.
return Complex_Matrix_Type;
end CC70A01_0;
--==================================================================--
package body CC70A01_0 is -- Generic complex matrix operations.
use Complex_Package;
--==============================================--
function Inner_Product (Left, Right : Complex_Matrix_Type;
Row, Column : Positive) -- Compute inner product
return Complex_Package.Complex_Type is -- for matrix-multiply.
Result : Complex_Type := Zero;
subtype Vector_Size is Positive range Left'Range(2);
begin -- Inner_Product.
for I in Vector_Size loop
Result := Result + -- Complex_Package."+".
(Left(Row, I) * Right(I, Column)); -- Complex_Package."*".
end loop;
return (Result);
end Inner_Product;
--==============================================--
function Identity_Matrix (Size : Positive) return Complex_Matrix_Type is
Result : Complex_Matrix_Type (1 .. Size, 1 .. Size) :=
(others => (others => Zero)); -- Zeroes everywhere...
begin
for I in 1 .. Size loop
Result (I, I) := One; -- Ones on the diagonal.
end loop;
return (Result);
end Identity_Matrix;
--==============================================--
function "*" (Left : Complex_Matrix_Type; Right : Complex_Matrix_Type)
return Complex_Matrix_Type is
subtype Rows is Positive range Left'Range(1);
subtype Columns is Positive range Right'Range(2);
Result : Complex_Matrix_Type(Rows, Columns);
begin
if Left'Length(2) /= Right'Length(1) then -- # columns of Left must
-- match # rows of Right.
raise Dimension_Mismatch;
else
for I in Rows loop
for J in Columns loop
Result(I, J) := Inner_Product (Left, Right, I, J);
end loop;
end loop;
return (Result);
end if;
end "*";
end CC70A01_0;
--==================================================================--
with Report;
with FC70A00; -- Generic complex integer operations.
with CC70A01_0; -- Generic complex matrix operations.
procedure CC70A01 is
type My_Integer is range -100 .. 100;
package My_Complex_Package is new FC70A00 (My_Integer);
package My_Matrix_Package is new CC70A01_0 (My_Complex_Package);
use My_Complex_Package, -- All user-defined
My_Matrix_Package; -- operators directly
-- visible.
subtype Matrix_2x2 is Complex_Matrix_Type (1 .. 2, 1 .. 2);
subtype Matrix_2x3 is Complex_Matrix_Type (1 .. 2, 1 .. 3);
function C (Real, Imag : My_Integer) return Complex_Type renames Complex;
begin -- Main program.
Report.Test ("CC70A01", "Check that the visible part of a generic " &
"formal package includes the first list of basic " &
"declarative items of the package specification. Check " &
"for a generic package where formal package has (<>) " &
"actual part");
declare
Identity_2x2 : Matrix_2x2 := Identity_Matrix (Size => 2);
Operand_2x3 : Matrix_2x3 := ( ( C(1, 2), C(3, 6), C(5, 1) ),
( C(0, 3), C(7, 9), C(3, 4) ) );
Result_2x3 : Matrix_2x3 := ( others => ( others => Zero ) );
begin
begin -- Block #1.
Result_2x3 := Identity_2x2 * Operand_2x3; -- Should return
-- Operand_2x3.
if (Result_2x3 /= Operand_2x3) then
Report.Failed ("Incorrect results from matrix multiplication");
end if;
exception
when others =>
Report.Failed ("Unexpected exception raised - Block #1");
end; -- Block #1.
begin -- Block #2.
Result_2x3 := Operand_2x3 * Identity_2x2; -- Can't multiply 2x3
-- by 2x2.
Report.Failed ("Exception Dimension_Mismatch not raised");
exception
when Dimension_Mismatch =>
null;
when others =>
Report.Failed ("Unexpected exception raised - Block #2");
end; -- Block #2.
end;
Report.Result;
end CC70A01;
|