1-- CC70A02.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 the visible part of a generic formal package includes the 28-- first list of basic declarative items of the package specification. 29-- Check for a generic subprogram which declares a formal package with 30-- (<>) as its actual part. 31-- 32-- TEST DESCRIPTION: 33-- The "first list of basic declarative items" of a package specification 34-- is the visible part of the package. Thus, the declarations in the 35-- visible part of the actual instance corresponding to a formal 36-- package are available in the generic which declares the formal package. 37-- 38-- Declare a generic package which simulates a complex integer abstraction 39-- (foundation code). 40-- 41-- Declare a second generic package which defines a "signature" for 42-- mathematical groups. Declare a generic function within a package 43-- which utilizes the second generic package as a generic formal package 44-- (with a (<>) actual_part). 45-- 46-- In the main program, instantiate the first generic package, then 47-- instantiate the second generic package with objects, types, and 48-- operations declared in the first instance. 49-- 50-- Instantiate the generic function and pass the second instance 51-- to it as a generic actual parameter. Check that the instance of the 52-- generic function performs as expected. 53-- 54-- 55-- CHANGE HISTORY: 56-- 06 Dec 94 SAIC ACVC 2.0 57-- 58--! 59 60generic -- Mathematical group signature. 61 62 type Group_Type is private; 63 64 Identity : in Group_Type; 65 66 with function Operation (Left, Right : Group_Type) return Group_Type; 67 with function Inverse (Right : Group_Type) return Group_Type; 68 69package CC70A02_0 is end; 70 71-- No body for CC70A02_0. 72 73 74 --==================================================================-- 75 76 77with CC70A02_0; -- Mathematical group signature. 78 79package CC70A02_1 is -- Mathematical group operations. 80 81 -- -- 82 -- Generic formal package used here -- 83 -- -- 84 85 generic -- Powers for mathematical groups. 86 with package Group is new CC70A02_0 (<>); 87 function Power (Left : Group.Group_Type; Right : Integer) 88 return Group.Group_Type; 89 90 91end CC70A02_1; 92 93 94 --==================================================================-- 95 96 97package body CC70A02_1 is -- Mathematical group operations. 98 99 100 101 function Power (Left : Group.Group_Type; Right : Integer) 102 return Group.Group_Type is 103 Result : Group.Group_Type := Group.Identity; 104 begin 105 for I in 1 .. abs(Right) loop -- Repeat group operations 106 Result := Group.Operation (Result, Left); -- the specified number of 107 end loop; -- times. 108 109 if Right < 0 then -- If specified power is 110 return Group.Inverse (Result); -- negative, return the 111 else -- inverse of the result. 112 return Result; -- If it is zero, return 113 end if; -- the identity. 114 end Power; 115 116 117end CC70A02_1; 118 119 120 --==================================================================-- 121 122 123with Report; 124 125with FC70A00; -- Complex integer abstraction. 126with CC70A02_0; -- Mathematical group signature. 127with CC70A02_1; -- Mathematical group operations. 128 129procedure CC70A02 is 130 131 -- Declare an instance of complex integers: 132 133 type My_Integer is range -100 .. 100; 134 package Complex_Integers is new FC70A00 (My_Integer); 135 136 137 -- Define an addition group for complex integers: 138 139 package Complex_Addition_Group is new CC70A02_0 140 (Group_Type => Complex_Integers.Complex_Type, -- For complex integers... 141 Identity => Complex_Integers.Zero, -- Additive identity. 142 Operation => Complex_Integers."+", -- Additive operation. 143 Inverse => Complex_Integers."-"); -- Additive inverse. 144 145 function Complex_Multiplication is new -- Multiplication of a 146 CC70A02_1.Power(Complex_Addition_Group); -- complex integer by a 147 -- constant. 148 149 150 -- Define a multiplication group for complex integers: 151 152 package Complex_Multiplication_Group is new CC70A02_0 153 (Group_Type => Complex_Integers.Complex_Type, -- For complex integers... 154 Identity => Complex_Integers.One, -- Multiplicative identity. 155 Operation => Complex_Integers."*", -- Multiplicative oper. 156 Inverse => Complex_Integers.Reciprocal); -- Multiplicative inverse. 157 158 function Complex_Exponentiation is new -- Exponentiation of a 159 CC70A02_1.Power(Complex_Multiplication_Group); -- complex integer by a 160 -- constant. 161 162 use Complex_Integers; 163 164 165begin -- Main program. 166 167 Report.Test ("CC70A02", "Check that the visible part of a generic " & 168 "formal package includes the first list of basic " & 169 "declarative items of the package specification. Check " & 170 "for a generic subprogram where formal package has (<>) " & 171 "actual part"); 172 173 declare 174 Mult_Operand : constant Complex_Type := Complex ( -4, 9); 175 Exp_Operand : constant Complex_Type := Complex ( 0, -7); 176 177 Expected_Mult_Result : constant Complex_Type := Complex ( 28, -63); 178 Expected_Exp_Result : constant Complex_Type := Complex (-49, 0); 179 begin 180 181 if Complex_Multiplication (Mult_Operand, -7) /= Expected_Mult_Result then 182 Report.Failed ("Incorrect results from complex multiplication"); 183 end if; 184 185 if Complex_Exponentiation (Exp_Operand, 2) /= Expected_Exp_Result then 186 Report.Failed ("Incorrect results from complex exponentiation"); 187 end if; 188 189 end; 190 191 Report.Result; 192 193end CC70A02; 194