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, for the type determined by the subtype mark of a use type
28 -- clause, the declaration of each primitive operator is use-visible
29 -- within the scope of the clause, even if explicit operators with the
30 -- same names as the type's operators are declared for the subtype. Check
31 -- that a call to such an operator executes the body of the type's
35 -- A type may declare a primitive operator, and a subtype of that type
36 -- may overload the operator. If a use type clause names the subtype,
37 -- it is the primitive operator of the type (not the subtype) which
38 -- is made directly visible, and the primitive operator may be called
39 -- unambiguously. Such a call executes the body of the type's operation.
41 -- In a package, declare a type for which a predefined operator is
42 -- overridden. In another package, declare a subtype of the type in the
43 -- previous package. Declare another version of the predefined operator
46 -- The main program declares objects of both the type and the explicit
47 -- subtype, and uses the "**" operator for both. In all cases, the
48 -- operator declared for the 1st subtype should be the one executed,
49 -- since it is the primitive operators of the *type* that are made
50 -- visible; the operators which were declared for the explicit subtype
51 -- are not primitive operators of the type, since they were declared in
52 -- a separate package from the original type.
56 -- 06 Dec 94 SAIC ACVC 2.0
57 -- 23 Sep 99 RLB Added test case where operator made visible is
58 -- not visible by selection (as in AI-00122).
63 -- Usage scenario: the predefined operators for a floating point type
64 -- are overridden in order to take advantage of improved algorithms.
66 type Precision_Float
is new Float range -100.0 .. 100.0;
67 -- Implicit: function "**" (Left: Precision_Float; Right: Integer'Base)
68 -- return Precision_Float;
70 function "**" (Left
: Precision_Float
; Right
: Integer'Base)
71 return Precision_Float
;
72 -- Overrides predefined operator.
74 function "+" (Right
: Precision_Float
)
75 return Precision_Float
;
76 -- Overrides predefined operator.
78 -- ... Other overridden operations.
80 TC_Expected
: constant Precision_Float
:= 68.0;
85 --==================================================================--
87 package body C840001_0
is
89 function "**" (Left
: Precision_Float
; Right
: Integer'Base)
90 return Precision_Float
is
92 -- ... Utilize desired algorithm.
93 return (TC_Expected
); -- Artificial for testing purposes.
96 function "+" (Right
: Precision_Float
)
97 return Precision_Float
is
98 -- Overrides predefined operator.
106 --==================================================================--
108 -- Take advantage of some even better algorithms designed for positive
109 -- floating point values.
114 subtype Precision_Pos_Float
is C840001_0
.Precision_Float
117 -- This is not a new type, so it has no primitives of it own. However, it
118 -- can declare another version of the operator and call it as long as both it
119 -- and the corresponding operator of the 1st subtype are not directly visible
120 -- in the same place.
122 function "**" (Left
: Precision_Pos_Float
; Right
: Natural'Base)
123 return Precision_Pos_Float
; -- Accepts only positive exponent.
128 --==================================================================--
130 package body C840001_1
is
132 function "**" (Left
: Precision_Pos_Float
; Right
: Natural'Base)
133 return Precision_Pos_Float
is
135 -- ... Utilize some other algorithms.
136 return 57.0; -- Artificial for testing purposes.
142 --==================================================================--
146 procedure C840001_2
is
148 -- Note that C840001_0 and it's contents is not visible in any form here.
150 TC_Operand
: C840001_1
.Precision_Pos_Float
:= 41.0;
152 TC_Operand2
: C840001_1
.Precision_Pos_Float
;
154 use type C840001_1
.Precision_Pos_Float
;
155 -- Makes the operators of its parent type directly visible, even though
156 -- the parent type and operators are not otherwise visible at all.
160 TC_Operand2
:= +TC_Operand
; -- Overridden operator is visible and called.
162 if TC_Operand2
/= 82.0 then -- Predefined equality.
163 Report
.Failed
("3rd test: type's overridden operation not called for " &
164 "operand of 1st subtype");
166 if TC_Operand
+ 3.0 >= TC_Operand2
- 13.0 then -- Various predefined operators.
167 Report
.Failed
("3rd test: wrong result from predefined operators");
172 --==================================================================--
184 Report
.Test
("C840001", "Check that, for the type determined by the " &
185 "subtype mark of a use type clause, the declaration of " &
186 "each primitive operator is use-visible within the scope " &
187 "of the clause, even if explicit operators with the same " &
188 "names as the type's operators are declared for the subtype");
191 Use_Type_Precision_Pos_Float
:
193 TC_Operand
: C840001_0
.Precision_Float
194 := C840001_0
.Precision_Float
(-2.0);
195 TC_Positive_Operand
: C840001_1
.Precision_Pos_Float
:= 6.0;
197 TC_Actual_Type
: C840001_0
.Precision_Float
;
198 TC_Actual_Subtype
: C840001_1
.Precision_Pos_Float
;
200 use type C840001_1
.Precision_Pos_Float
;
201 -- Both calls to "**" should return 68.0 (that is, Precision_Float's
202 -- operation should be called).
206 TC_Actual_Type
:= TC_Operand
**2;
208 if C840001_0
."/="(TC_Actual_Type
, C840001_0
.TC_Expected
) then
209 Report
.Failed
("1st block: type's operation not called for " &
210 "operand of 1st subtype");
213 TC_Actual_Subtype
:= TC_Positive_Operand
**2;
215 if not (C840001_0
."="
216 (TC_Actual_Subtype
, C840001_0
.TC_Expected
)) then
217 Report
.Failed
("1st block: type's operation not called for " &
218 "operand of explicit subtype");
221 end Use_Type_Precision_Pos_Float
;
223 Use_Type_Precision_Float
:
225 TC_Operand
: C840001_0
.Precision_Float
226 := C840001_0
.Precision_Float
(4.0);
227 TC_Positive_Operand
: C840001_1
.Precision_Pos_Float
:= 7.0;
229 TC_Actual_Type
: C840001_0
.Precision_Float
;
230 TC_Actual_Subtype
: C840001_1
.Precision_Pos_Float
;
232 use type C840001_0
.Precision_Float
;
233 -- Again, both calls to "**" should return 68.0.
237 TC_Actual_Type
:= TC_Operand
**2;
239 if C840001_0
."/="(TC_Actual_Type
, C840001_0
.TC_Expected
) then
240 Report
.Failed
("2nd block: type's operation not called for " &
241 "operand of 1st subtype");
244 TC_Actual_Subtype
:= TC_Positive_Operand
**2;
246 if not C840001_0
."=" (TC_Actual_Subtype
, C840001_0
.TC_Expected
) then
247 Report
.Failed
("2nd block: type's operation not called for " &
248 "operand of explicit subtype");
251 end Use_Type_Precision_Float
;
253 C840001_2
; -- 3rd test.