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 Adjust is called for the execution of a return
28 -- statement for a function returning a result of a (non-limited)
31 -- Check that Adjust is called when evaluating an aggregate
32 -- component association for a controlled component.
34 -- Check that Adjust is called for the assignment of the ancestor
35 -- expression of an extension aggregate when the type of the
36 -- aggregate is controlled.
39 -- A type is derived from Ada.Finalization.Controlled; the dispatching
40 -- procedure Adjust is defined for the new type. Structures and
41 -- subprograms to model the test objectives are used to check that
42 -- Adjust is called at the right time. For the sake of simplicity,
43 -- globally accessible data is used to check that the calls are made.
47 -- 06 DEC 94 SAIC ACVC 2.0
48 -- 14 OCT 95 SAIC Update and repair for ACVC 2.0.1
49 -- 05 APR 96 SAIC Add RM reference
50 -- 06 NOV 96 SAIC Reduce adjust requirement
51 -- 25 NOV 97 EDS Allowed zero calls to adjust at line 144
54 ---------------------------------------------------------------- C760007_0
56 with Ada
.Finalization
;
59 type Controlled
is new Ada
.Finalization
.Controlled
with record
60 TC_ID
: Natural := Natural'Last;
62 procedure Adjust
( Object
: in out Controlled
);
64 type Structure
is record
65 Controlled_Component
: Controlled
;
68 type Child
is new Controlled
with record
69 TC_XX
: Natural := Natural'Last;
71 procedure Adjust
( Object
: in out Child
);
73 Adjust_Count
: Natural := 0;
74 Child_Adjust_Count
: Natural := 0;
78 package body C760007_0
is
80 procedure Adjust
( Object
: in out Controlled
) is
82 Adjust_Count
:= Adjust_Count
+1;
85 procedure Adjust
( Object
: in out Child
) is
87 Child_Adjust_Count
:= Child_Adjust_Count
+1;
92 ------------------------------------------------------------------ C760007
98 procedure Check_Adjust_Count
(Message
: String;
100 Max
: Natural := 2) is
103 -- in order to allow for the anonymous objects referred to in
104 -- the reference manual, the check for calls to Adjust must be
105 -- in a range. This number must then be further adjusted
106 -- to allow for the optimization that does not call for an adjust
107 -- of an aggregate initial value built directly in the object
109 if C760007_0
.Adjust_Count
not in Min
..Max
then
110 Report
.Failed
(Message
111 & " = " & Natural'Image(C760007_0
.Adjust_Count
));
113 C760007_0
.Adjust_Count
:= 0;
114 end Check_Adjust_Count
;
116 procedure Check_Child_Adjust_Count
(Message
: String;
118 Max
: Natural := 2) is
122 if C760007_0
.Child_Adjust_Count
not in Min
..Max
then
123 Report
.Failed
(Message
124 & " = " & Natural'Image(C760007_0
.Child_Adjust_Count
));
126 C760007_0
.Child_Adjust_Count
:= 0;
127 end Check_Child_Adjust_Count
;
129 Object
: C760007_0
.Controlled
;
131 -- Check that Adjust is called for the execution of a return
132 -- statement for a function returning a result of a (non-limited)
133 -- controlled type or a result of a noncontrolled type with
134 -- controlled components.
136 procedure Subtest_1
is
137 function Create
return C760007_0
.Controlled
is
138 New_Object
: C760007_0
.Controlled
;
143 procedure Examine
( Thing
: in C760007_0
.Controlled
) is
145 Check_Adjust_Count
("Function call passed as parameter",0);
149 -- this assignment must call Adjust:
150 -- 1: on the value resulting from the function
151 -- ** unless this is optimized out by building the result directly
152 -- in the target object.
153 -- 2: on Object once it's been assigned
155 -- 1: for a anonymous object created in the evaluation of the function
156 -- 2: for a anonymous object created in the assignment operation
160 Check_Adjust_Count
("Function call",1,4);
166 -- Check that Adjust is called when evaluating an aggregate
167 -- component association for a controlled component.
169 procedure Subtest_2
is
170 S
: C760007_0
.Structure
;
172 procedure Examine
( Thing
: in C760007_0
.Structure
) is
174 Check_Adjust_Count
("Aggregate passed as parameter");
178 -- this assignment must call Adjust:
179 -- 1: on the value resulting from the aggregate
180 -- ** unless this is optimized out by building the result directly
181 -- in the target object.
182 -- 2: on Object once it's been assigned
184 -- 1: for a anonymous object created in the evaluation of the aggregate
185 -- 2: for a anonymous object created in the assignment operation
186 S
:= ( Controlled_Component
=> Object
);
187 Check_Adjust_Count
("Aggregate and Assignment", 1, 4);
189 Examine
( C760007_0
.Structure
'(Controlled_Component => Object) );
192 -- Check that Adjust is called for the assignment of the ancestor
193 -- expression of an extension aggregate when the type of the
194 -- aggregate is controlled.
196 procedure Subtest_3 is
197 Bambino : C760007_0.Child;
199 procedure Examine( Thing : in C760007_0.Child ) is
201 Check_Adjust_Count("Extension aggregate as parameter (ancestor)", 0, 2);
202 Check_Child_Adjust_Count("Extension aggregate as parameter", 0, 4);
206 -- implementation permissions make all of the following calls to adjust
208 -- these assignments may call Adjust:
209 -- 1: on the value resulting from the aggregate
210 -- 2: on Object once it's been assigned
211 -- 3: for a anonymous object created in the evaluation of the aggregate
212 -- 4: for a anonymous object created in the assignment operation
213 Bambino := ( Object with TC_XX => 10 );
214 Check_Adjust_Count("Ancestor (expression) part of aggregate", 0, 2);
215 Check_Child_Adjust_Count("Child aggregate assignment 1", 0, 4 );
217 Bambino := ( C760007_0.Controlled with TC_XX => 11 );
218 Check_Adjust_Count("Ancestor (subtype_mark) part of aggregate", 0, 2);
219 Check_Child_Adjust_Count("Child aggregate assignment 2", 0, 4 );
221 Examine( ( Object with TC_XX => 21 ) );
223 Examine( ( C760007_0.Controlled with TC_XX => 37 ) );
227 begin -- Main test procedure.
229 Report.Test ("C760007", "Check that Adjust is called for the " &
230 "execution of a return statement for a " &
231 "function returning a result containing a " &
232 "controlled type. Check that Adjust is " &
233 "called when evaluating an aggregate " &
234 "component association for a controlled " &
236 "Check that Adjust is called for the " &
237 "assignment of the ancestor expression of an " &
238 "extension aggregate when the type of the " &
239 "aggregate is controlled" );