| 1 |
-- CC51004.A |
| 2 |
-- |
| 3 |
-- Grant of Unlimited Rights |
| 4 |
-- |
| 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 |
| 14 |
-- to do so. |
| 15 |
-- |
| 16 |
-- DISCLAIMER |
| 17 |
-- |
| 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. |
| 24 |
--* |
| 25 |
-- |
| 26 |
-- OBJECTIVE: |
| 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. |
| 30 |
-- |
| 31 |
-- Check for the case where the ancestor type is a tagged type, and the |
| 32 |
-- formal derived type is declared in a generic subprogram. |
| 33 |
-- |
| 34 |
-- TEST DESCRIPTION: |
| 35 |
-- Define a discriminated tagged type in a package. Declare a |
| 36 |
-- library-level generic subprogram with a formal derived type using the |
| 37 |
-- tagged 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 |
-- tagged parameter. In the main program, declare tagged record objects |
| 41 |
-- with two different discriminant values. Derive an indefinite type from |
| 42 |
-- the tagged type with a new discriminant part. Instantiate the |
| 43 |
-- generic subprogram for the root tagged subtype and the derived subtype. |
| 44 |
-- Call the root subtype instance with actual parameters having the two |
| 45 |
-- discriminant values. Also call the derived subtype instance with an |
| 46 |
-- appropriate actual. |
| 47 |
-- |
| 48 |
-- |
| 49 |
-- CHANGE HISTORY: |
| 50 |
-- 06 Dec 94 SAIC ACVC 2.0 |
| 51 |
-- 05 Jan 94 SAIC Removed unknown discriminant part from formal |
| 52 |
-- derived type. Moved declaration of type |
| 53 |
-- New_Dbl_Sq from main subprogram to CC51004_0. |
| 54 |
-- 05 Nov 95 SAIC ACVC 2.0.1 fixes: Removed constrained subtype |
| 55 |
-- instantiation and associated declarations. |
| 56 |
-- Modified commentary. |
| 57 |
-- |
| 58 |
--! |
| 59 |
|
| 60 |
-- Simulate a fragment of a matrix manipulation application. |
| 61 |
|
| 62 |
package CC51004_0 is -- Matrix types. |
| 63 |
|
| 64 |
type Matrix is array (Natural range <>, Natural range <>) of Integer; |
| 65 |
|
| 66 |
type Square (Side : Natural) is record |
| 67 |
Mat : Matrix (1 .. Side, 1 .. Side); |
| 68 |
end record; |
| 69 |
|
| 70 |
type Sq_Type (Num1 : Natural) is tagged record |
| 71 |
One : Square (Num1); |
| 72 |
end record; |
| 73 |
|
| 74 |
-- Extended type with new discriminant part (which constrains parent): |
| 75 |
|
| 76 |
type New_Dbl_Sq (Num2 : Natural) is new Sq_Type(Num2) with record |
| 77 |
Two : Square (Num2); |
| 78 |
end record; |
| 79 |
|
| 80 |
end CC51004_0; |
| 81 |
|
| 82 |
|
| 83 |
-- No body for CC51004_0; |
| 84 |
|
| 85 |
|
| 86 |
--==================================================================-- |
| 87 |
|
| 88 |
|
| 89 |
with CC51004_0; -- Matrix types. |
| 90 |
generic -- Generic matrix "clear" operation. |
| 91 |
type Squares is new CC51004_0.Sq_Type with private; -- Indefinite |
| 92 |
procedure CC51004_1 (Sq : in out Squares); -- formal. |
| 93 |
|
| 94 |
|
| 95 |
--==================================================================-- |
| 96 |
|
| 97 |
|
| 98 |
procedure CC51004_1 (Sq : in out Squares) is |
| 99 |
begin |
| 100 |
for I in 1 .. Sq.Num1 loop -- Discriminants inherited from ancestor |
| 101 |
for J in 1 .. Sq.Num1 loop -- type (should work even for derived type |
| 102 |
-- declaring new discriminant part). |
| 103 |
Sq.One.Mat (I, J) := 0; -- Other components inherited from |
| 104 |
-- ancestor type. |
| 105 |
end loop; |
| 106 |
end loop; |
| 107 |
end CC51004_1; |
| 108 |
|
| 109 |
|
| 110 |
--==================================================================-- |
| 111 |
|
| 112 |
|
| 113 |
with CC51004_0; -- Matrix types. |
| 114 |
with CC51004_1; -- Generic double-matrix "clear" operation. |
| 115 |
|
| 116 |
with Report; |
| 117 |
procedure CC51004 is |
| 118 |
|
| 119 |
use CC51004_0; -- "/=" operator directly visible for Sq_Type. |
| 120 |
|
| 121 |
-- Matrices of root type: |
| 122 |
|
| 123 |
Mat_2x2 : Square(Side => 2) := (Side => 2, Mat => ( (1, 2), (3, 4) )); |
| 124 |
One_Mat_2x2 : Sq_Type(Num1 => 2) := (2, Mat_2x2); |
| 125 |
|
| 126 |
Zero_2x2 : constant Square(2) := (2, Mat => ( (0, 0), (0, 0) )); |
| 127 |
Expected_2x2 : constant Sq_Type(2) := (Num1 => 2, One => Zero_2x2); |
| 128 |
|
| 129 |
|
| 130 |
Mat_3x3 : Square(Side => 3) := (Side => 3, |
| 131 |
Mat => (1 => (5, 2, 7), |
| 132 |
others => (1 => 4, |
| 133 |
others => 9))); |
| 134 |
One_Mat_3x3 : Sq_Type(3) := (Num1 => 3, One => Mat_3x3); |
| 135 |
|
| 136 |
Zero_3x3 : constant Square(3) := (3, Mat => (others => (0,0,0))); |
| 137 |
Expected_3x3 : constant Sq_Type(Num1 => 3) := (3, Zero_3x3); |
| 138 |
|
| 139 |
|
| 140 |
New_Dbl_2x2 : New_Dbl_Sq(Num2 => 2) := (2, others => Mat_2x2); |
| 141 |
Expected_New_2x2 : constant New_Dbl_Sq := (2, Zero_2x2, Mat_2x2); |
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
-- Instantiations: |
| 146 |
|
| 147 |
procedure Clr_Mat is new CC51004_1 (Sq_Type); |
| 148 |
procedure Clr_New_Dbl is new CC51004_1 (New_Dbl_Sq); |
| 149 |
|
| 150 |
|
| 151 |
begin |
| 152 |
Report.Test ("CC51004", "Check that a formal derived tagged type " & |
| 153 |
"inherits components, including discriminants, " & |
| 154 |
"from its ancestor type"); |
| 155 |
|
| 156 |
-- Simulate use of matrix manipulation operations. |
| 157 |
|
| 158 |
|
| 159 |
Clr_Mat (One_Mat_2x2); |
| 160 |
|
| 161 |
if (One_Mat_2x2 /= Expected_2x2) then |
| 162 |
Report.Failed ("Wrong result root type (2x2 matrix)"); |
| 163 |
end if; |
| 164 |
|
| 165 |
|
| 166 |
Clr_Mat (One_Mat_3x3); |
| 167 |
|
| 168 |
if (One_Mat_3x3 /= Expected_3x3) then |
| 169 |
Report.Failed ("Wrong result root type (3x3 matrix)"); |
| 170 |
end if; |
| 171 |
|
| 172 |
|
| 173 |
Clr_New_Dbl (New_Dbl_2x2); |
| 174 |
|
| 175 |
if (New_Dbl_2x2 /= Expected_New_2x2) then |
| 176 |
Report.Failed ("Wrong result extended type (2x2 matrix)"); |
| 177 |
end if; |
| 178 |
|
| 179 |
|
| 180 |
Report.Result; |
| 181 |
end CC51004; |