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 if the ancestor type of a formal derived type is a composite
28 -- type that is not an array type, the formal type inherits components,
29 -- including discriminants, from the ancestor type.
31 -- Check for the case where the ancestor type is a record type, and the
32 -- formal derived type is declared in a generic subprogram.
35 -- Define a discriminated record type in a package. Declare a
36 -- library-level generic subprogram with a formal derived type using the
37 -- record type as ancestor. Give the generic subprogram an in out
38 -- parameter of the formal derived type. Inside the generic, use the
39 -- discriminant component and modify the remaining components of the
40 -- record parameter. In the main program, declare record objects with two
41 -- different discriminant values. Derive an indefinite type from the
42 -- record type with a new discriminant part. Instantiate the generic
43 -- subprogram for the root record subtype and the derived subtype. Call
44 -- the root subtype instance with actual parameters having the two
45 -- discriminant values. Also call the derived subtype instance with
46 -- an appropriate actual.
50 -- 06 Dec 94 SAIC ACVC 2.0
51 -- 03 Jan 95 SAIC Removed unknown discriminant part from formal
53 -- 05 Nov 95 SAIC ACVC 2.0.1 fixes: Removed constrained subtype
54 -- instantiation and associated declarations.
55 -- Modified commentary.
60 -- Simulate a fragment of a matrix manipulation application.
62 package CC51003_0
is -- Matrix types.
64 type Matrix
is array (Natural range <>, Natural range <>) of Integer;
66 type Square
(Side
: Natural) is record
67 Mat
: Matrix
(1 .. Side
, 1 .. Side
);
70 type Double_Square
(Number
: Natural) is record
71 Left
: Square
(Number
);
72 Right
: Square
(Number
);
78 -- No body for CC51003_0;
81 --==================================================================--
84 with CC51003_0
; -- Matrix types.
85 generic -- Generic double-matrix "clear" operation.
86 type Dbl_Square
is new CC51003_0
.Double_Square
; -- Indefinite
87 procedure CC51003_1
(Dbl
: in out Dbl_Square
); -- formal.
90 --==================================================================--
93 procedure CC51003_1
(Dbl
: in out Dbl_Square
) is
95 for I
in 1 .. Dbl
.Number
loop -- Discriminants inherited from ancestor
96 for J
in 1 .. Dbl
.Number
loop -- type (should work even for derived type
97 -- declaring new discriminant part).
98 Dbl
.Left
.Mat
(I
, J
) := 0; -- Other components inherited from
99 Dbl
.Right
.Mat
(I
, J
) := 0; -- ancestor type.
106 --==================================================================--
109 with CC51003_0
; -- Matrix types.
110 with CC51003_1
; -- Generic double-matrix "clear" operation.
115 use CC51003_0
; -- "/=" operator directly visible for Double_Square.
117 -- Matrices of root type:
119 Mat_2x2
: Square
(Side
=> 2) := (Side
=> 2,
120 Mat
=> ( (1, 2), (3, 4) ));
121 Dbl_Mat_2x2
: Double_Square
(Number
=> 2) := (2, Mat_2x2
, Mat_2x2
);
124 Zero_2x2
: constant Square
(2) := (2, Mat
=> ( (0, 0), (0, 0) ));
125 Expected_2x2
: constant Double_Square
(2) := (Number
=> 2,
130 Mat_3x3
: Square
(Side
=> 3) := (Side
=> 3,
131 Mat
=> (1 => (1, 4, 9),
134 Dbl_Mat_3x3
: Double_Square
(3) := (Number
=> 3, others => Mat_3x3
);
137 Zero_3x3
: constant Square
(3) := (3, Mat
=> (others => (0,0,0)));
138 Expected_3x3
: constant Double_Square
(Number
=> 3) :=
139 (3, Zero_3x3
, Zero_3x3
);
142 -- Derived type with new discriminant part (which constrains parent):
144 type New_Dbl_Sq
(Num
: Natural) is new Double_Square
(Num
);
146 New_Dbl_2x2
: New_Dbl_Sq
(Num
=> 2) := (2, Mat_2x2
, Mat_2x2
);
147 Expected_New_2x2
: constant New_Dbl_Sq
:= (Num
=> 2, others => Zero_2x2
);
153 procedure Clr_Dbl
is new CC51003_1
(Double_Square
);
154 procedure Clr_New_Dbl
is new CC51003_1
(New_Dbl_Sq
);
158 Report
.Test
("CC51003", "Check that a formal derived record type " &
159 "inherits components, including discriminants, " &
160 "from its ancestor type");
162 -- Simulate use of matrix manipulation operations.
164 Clr_Dbl
(Dbl_Mat_2x2
);
166 if (Dbl_Mat_2x2
/= Expected_2x2
) then
167 Report
.Failed
("Wrong result for root type (2x2 matrix)");
171 Clr_Dbl
(Dbl_Mat_3x3
);
173 if (Dbl_Mat_3x3
/= Expected_3x3
) then
174 Report
.Failed
("Wrong result for root type (3x3 matrix)");
178 Clr_New_Dbl
(New_Dbl_2x2
);
180 if (New_Dbl_2x2
/= Expected_New_2x2
) then
181 Report
.Failed
("Wrong result for derived type (2x2 matrix)");