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, in an instance, each implicit declaration of a primitive
28 -- subprogram of a formal (nontagged) derived type declares a view of
29 -- the corresponding primitive subprogram of the ancestor type, even if
30 -- the subprogram has been overridden for the actual type. Check that for
31 -- a formal derived type with no discriminant part, if the ancestor
32 -- subtype is an unconstrained scalar subtype then the actual may be
33 -- either constrained or unconstrained.
36 -- The formal derived type has no discriminant part, but the ancestor
37 -- subtype is unconstrained, making the formal type unconstrained. Since
38 -- the ancestor subtype is a scalar subtype (not an access or composite
39 -- subtype), the actual may be either constrained or unconstrained.
41 -- Declare a root type of a class as an unconstrained scalar (use floating
42 -- point). Declare a primitive subprogram of the root type. Declare a
43 -- generic package which has a formal derived type with the scalar root
44 -- type as ancestor. Inside the generic, declare an operation which calls
45 -- the ancestor type's primitive subprogram. Derive both constrained and
46 -- unconstrained types from the root type and override the primitive
47 -- subprogram for each. Declare a constrained subtype of the unconstrained
48 -- derivative. Instantiate the generic package for the derived types and
49 -- the subtype and call the "generic" operation for each one. Confirm that
50 -- in all cases the root type's implementation of the primitive
51 -- subprogram is called.
55 -- 06 Dec 94 SAIC ACVC 2.0
59 package CC51006_0
is -- Weight class.
61 type Weight_Type
is digits 3; -- Root type of class (unconstrained).
63 function Weight_To_String
(Wt
: Weight_Type
) return String;
65 -- ... Other operations.
70 --==================================================================--
73 package body CC51006_0
is
75 -- The implementations of the operations below are purely artificial; the
76 -- validity of their implementations in the context of the abstraction is
77 -- irrelevant to the feature being tested.
79 function Weight_To_String
(Wt
: Weight_Type
) return String is
81 if Wt
> 0.0 then -- Always true for this test.
82 return ("Root type's implementation called");
84 return ("Unexpected result ");
91 --==================================================================--
94 with CC51006_0
; -- Weight class.
95 generic -- Generic weight operations.
96 type Weight
is new CC51006_0
.Weight_Type
;
99 procedure Output_Weight
(Wt
: in Weight
; TC_Return
: out String);
101 -- ... Other operations.
106 --==================================================================--
109 package body CC51006_1
is
112 -- The implementation of this procedure is purely artificial, and contains
113 -- an artificial parameter for testing purposes: the procedure returns the
114 -- weight string to the caller.
116 procedure Output_Weight
(Wt
: in Weight
; TC_Return
: out String) is
118 TC_Return
:= Weight_To_String
(Wt
); -- Should always call root type's
119 end Output_Weight
; -- implementation.
125 --==================================================================--
128 with CC51006_0
; -- Weight class.
130 package CC51006_2
is -- Extensions to weight class.
132 type Grams
is new Weight_Type
; -- Unconstrained
135 function Weight_To_String
(Wt
: Grams
) return String; -- Overrides root
138 subtype Milligrams
is Grams
-- Constrained
139 range 0.0 .. 0.999; -- subtype (of der.).
141 type Pounds
is new Weight_Type
-- Constrained
142 range 0.0 .. 500.0; -- derivative.
144 function Weight_To_String
(Wt
: Pounds
) return String; -- Overrides root
150 --==================================================================--
153 package body CC51006_2
is
155 -- The implementations of the operations below are purely artificial; the
156 -- validity of their implementations in the context of the abstraction is
157 -- irrelevant to the feature being tested.
159 function Weight_To_String
(Wt
: Grams
) return String is
161 return ("GRAMS: Should never be called ");
162 end Weight_To_String
;
165 function Weight_To_String
(Wt
: Pounds
) return String is
167 return ("POUNDS: Should never be called ");
168 end Weight_To_String
;
173 --==================================================================--
176 with CC51006_1
; -- Generic weight operations.
177 with CC51006_2
; -- Extensions to weight class.
182 package Metric_Wts_G
is new CC51006_1
(CC51006_2
.Grams
); -- Unconstr.
183 package Metric_Wts_MG
is new CC51006_1
(CC51006_2
.Milligrams
); -- Constr.
184 package US_Wts
is new CC51006_1
(CC51006_2
.Pounds
); -- Constr.
186 Gms
: CC51006_2
.Grams
:= 113.451;
187 Mgm
: CC51006_2
.Milligrams
:= 0.549;
188 Lbs
: CC51006_2
.Pounds
:= 24.52;
191 subtype TC_Buffers
is String (1 .. 33);
193 TC_Expected
: constant TC_Buffers
:= "Root type's implementation called";
194 TC_Buffer
: TC_Buffers
;
197 Report
.Test
("CC51006", "Check that, in an instance, each implicit " &
198 "declaration of a primitive subprogram of a formal " &
199 "(nontagged) type declares a view of the corresponding " &
200 "primitive subprogram of the ancestor type");
203 Metric_Wts_G
.Output_Weight
(Gms
, TC_Buffer
);
205 if TC_Buffer
/= TC_Expected
then
206 Report
.Failed
("Root operation not called for unconstrained derivative");
210 Metric_Wts_MG
.Output_Weight
(Mgm
, TC_Buffer
);
212 if TC_Buffer
/= TC_Expected
then
213 Report
.Failed
("Root operation not called for constrained subtype");
217 US_Wts
.Output_Weight
(Lbs
, TC_Buffer
);
219 if TC_Buffer
/= TC_Expected
then
220 Report
.Failed
("Root operation not called for constrained derivative");