Debian Codegraph @

gcc/testsuite/ada/acats/tests/c6/c620001.a

raw
1 -- C620001.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 -- OBJECTIVE:
26 -- Check that elementary parameters are passed by copy.
27 --
28 -- Part 1: Integer, float, and access types, procedures and functions.
29 --
30 -- TEST DESCRIPTION:
31 -- Subtests are:
32 -- (A) Scalar parameters to procedures.
33 -- (B) Scalar parameters to functions.
34 -- (C) Access parameters to procedures.
35 -- (D) Access parameters to functions.
36 --
37 -- For the procedure examples, we pass array elements indexed by dynamically
38 -- determined indexes. Doing this side-steps the check of 6.4.1(6.15/3) and
39 -- makes the test more realistic.
40 --
41 -- To completely test this objective, we should also try in out and out
42 -- parameters for functions (Ada 2012), in/in out/out parameters for
43 -- task and protected entries, and a variety of different scalar types
44 -- (enumeration, modular, fixed, decimal).
45 --
46 -- CHANGE HISTORY:
47 -- 14 Jan 1980 DAS Created test.
48 -- 26 Oct 1982 SPS
49 -- 25 May 1984 CPP
50 -- 29 Oct 1985 EG Eliminate the use of Numeric_Error in the test.
51 -- 14 Mar 2014 RLB Revised so test cases are legal for Ada 2012, modernized
52 -- objective, converted to modern format, added float cases.
53
54 with Report;
55 procedure C620001 is
56
57 use Report;
58
59 begin
60 Test ("C620001", "Check that elementary parameters are passed by copy");
61
62 --------------------------------------------------
63
64 declare -- (A)
65
66 I,J,K : Natural := Report.Ident_Int(1); -- Index values.
67 Arr : array (1 .. 4) of Integer;
68 E : exception;
69
70 procedure P (PI : in Integer;
71 PO : out Integer;
72 PIO : in out Integer) is
73
74 Tmp : Integer;
75
76 begin
77
78 Tmp := PI; -- Save value of PI at procedure entry.
79
80 PO := 10;
81 if (PI /= Tmp) then
82 Failed ("Assignement to scalar out " &
83 "parameter changes the value of " &
84 "input parameter");
85 Tmp := PI; -- Reset Tmp for next case.
86 end if;
87
88 PIO := PIO + 100;
89 if (PI /= Tmp) then
90 Failed ("Assignment to scalar in out " &
91 "parameter changes the value of " &
92 "inputparameter");
93 Tmp := PI; -- Reset Tmp for next case.
94 end if;
95
96 Arr(I) := Arr(I) + 1;
97 if (PI /= Tmp) then
98 Failed ("Assignment to scalar actual " &
99 "parameter changes the value of " &
100 "input parameter");
101 end if;
102
103 raise E; -- Check exception handling.
104 end P;
105
106 begin -- (A)
107 Arr := (others => 0);
108 P (Arr(I), Arr(J), Arr(K));
109 Failed ("Exception not raised - A");
110 exception
111 when E =>
112 if (Arr(I) /= 1) then
113 case Arr(I) is
114 when 11 =>
115 Failed ("Out actual scalar parameter " &
116 "changed global value");
117 when 101 =>
118 Failed ("In out actual scalar " &
119 "parameter changed global value");
120 when 111 =>
121 Failed ("Out and in out actual scalar " &
122 "parameters changed global " &
123 "value");
124 when others =>
125 Failed ("Uundetermined change to global " &
126 "value");
127 end case;
128 end if;
129 when others =>
130 Failed ("Wrong exception raised - A");
131 end; -- (A)
132
133 --------------------------------------------------
134
135 declare -- (B)
136
137 I,J : Integer;
138
139 function F (FI : in Integer) return Integer is
140
141 Tmp : Integer := FI;
142
143 begin
144
145 I := I + 1;
146 if (FI /= Tmp) then
147 Failed ("Assignment to scalar actual function " &
148 "parameter changes the value of " &
149 "input parameter");
150 end if;
151
152 return (100);
153 end F;
154
155 begin -- (B)
156 I := 100;
157 J := F (I);
158 end; -- (B)
159
160 --------------------------------------------------
161
162 declare -- (C)
163
164 type Acctype is access Integer;
165
166 I,J,K : Natural := Report.Ident_Int(2); -- Index values.
167 Arr : array (1 .. 5) of Acctype;
168 E : exception;
169
170 procedure P (PI : in Acctype;
171 PO : out Acctype;
172 PIO : in out Acctype) is
173
174 Tmp : Acctype;
175
176 begin
177
178 Tmp := PI; -- Save value of PI at procedure entry.
179
180 Arr(I) := new Integer'(101);
181 if (PI /= Tmp) then
182 Failed ("Assignment to access actual " &
183 "parameter changes the value of " &
184 "input parameter");
185 Tmp := PI; -- Reset Tmp for next case.
186 end if;
187
188 PO := new Integer'(1);
189 if (PI /= Tmp) then
190 Failed ("Assignment to access out " &
191 "parameter changes the value of " &
192 "input parameter");
193 Tmp := PI; -- Reset Tmp for next case.
194 end if;
195
196 PIO := new Integer'(10);
197 if (PI /= Tmp) then
198 Failed ("Assignment to access in out " &
199 "parameter changes the value of " &
200 "input parameter");
201 end if;
202
203 raise E; -- Check exception handling.
204 end P;
205
206 begin -- (C)
207 Arr(I) := new Integer'(100);
208 P (Arr(I), Arr(J), Arr(K));
209 Failed ("Exception not raised - C");
210 exception
211 when E =>
212 if (Arr(I).all /= 101) then
213 Failed ("Out or in out actual procedure " &
214 "parameter value changed despite " &
215 "raised exception");
216 end if;
217 when others =>
218 Failed ("Wrong exception raised - C");
219 end; -- (C)
220
221 --------------------------------------------------
222
223 declare -- (D)
224
225 Type Acctype is access Integer;
226
227 I,J : Acctype;
228
229 function F (FI : in Acctype) return Acctype is
230
231 Tmp : Acctype := FI;
232
233 begin
234
235 I := new Integer;
236 if (FI /= Tmp) then
237 Failed ("Assignment to access actual function " &
238 "parameter changes the value of " &
239 "Input parameter");
240 end if;
241
242 return null;
243 end F;
244
245 begin -- (D)
246 I := null;
247 J := F(I);
248 end; -- (D)
249
250 --------------------------------------------------
251
252 declare -- (E)
253
254 I,J,K : Natural := Report.Ident_Int(3); -- Index values.
255 Arr : array (1 .. 3) of Float;
256 E : exception;
257
258 procedure P (PI : in Float;
259 PO : out Float;
260 PIO : in out Float) is
261
262 Tmp : Float;
263
264 begin
265
266 Tmp := PI; -- Save value of PI at procedure entry.
267
268 PO := 0.5;
269 if (PI /= Tmp) then
270 Failed ("Assignement to float out " &
271 "parameter changes the value of " &
272 "input parameter");
273 Tmp := PI; -- Reset Tmp for next case.
274 end if;
275
276 PIO := PIO + 0.25;
277 if (PI /= Tmp) then
278 Failed ("Assignment to float in out " &
279 "parameter changes the value of " &
280 "inputparameter");
281 Tmp := PI; -- Reset Tmp for next case.
282 end if;
283
284 Arr(I) := Arr(I) + 1.0;
285 if (PI /= Tmp) then
286 Failed ("Assignment to float actual " &
287 "parameter changes the value of " &
288 "input parameter");
289 end if;
290
291 raise E; -- Check exception handling.
292 end P;
293
294 begin -- (E)
295 Arr := (others => 0.0);
296 P (Arr(I), Arr(J), Arr(K));
297 Failed ("Exception not raised - E");
298 exception
299 when E =>
300 if (Arr(I) /= 1.0) then
301 Failed ("Out or in out actual procedure " &
302 "parameter value changed despite " &
303 "raised exception");
304 end if;
305 when others =>
306 Failed ("Wrong exception raised - E");
307 end; -- (E)
308
309 --------------------------------------------------
310
311 declare -- (F)
312
313 I,J : Float;
314
315 function F (FI : in Float) return Float is
316
317 Tmp : Float := FI;
318
319 begin
320
321 I := I + 1.0;
322 if (FI /= Tmp) then
323 Failed ("Assignment to float actual function " &
324 "parameter changes the value of " &
325 "input parameter");
326 end if;
327
328 return 100.0;
329 end F;
330
331 begin -- (F)
332 I := 100.0;
333 J := F (I);
334 end; -- (F)
335
336 --------------------------------------------------
337
338 Result;
339
340 end C620001;