summaryrefslogtreecommitdiff
path: root/gcc/testsuite/ada/acats/tests/c5/c57003a.ada
blob: 8ca95e52e6a57e5e610e8a64909df6f24872f6f0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
-- C57003A.ADA

--                             Grant of Unlimited Rights
--
--     Under contracts F33600-87-D-0337, F33600-84-D-0280, MDA903-79-C-0687,
--     F08630-91-C-0015, and DCA100-97-D-0025, the U.S. Government obtained 
--     unlimited rights in the software and documentation contained herein.
--     Unlimited rights are defined in DFAR 252.227-7013(a)(19).  By making 
--     this public release, the Government intends to confer upon all 
--     recipients unlimited rights  equal to those held by the Government.  
--     These rights include rights to use, duplicate, release or disclose the 
--     released technical data and computer software in whole or in part, in 
--     any manner and for any purpose whatsoever, and to have or permit others 
--     to do so.
--
--                                    DISCLAIMER
--
--     ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR
--     DISCLOSED ARE AS IS.  THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED 
--     WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE
--     SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE 
--     OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A
--     PARTICULAR PURPOSE OF SAID MATERIAL.
--*
-- CHECK THAT THE EXIT STATEMENT IS EVALUATED EACH TIME THROUGH A LOOP,
--    AND THAT IT IS EVALUATED CORRECTLY WHETHER POSITIONED AT THE
--    BEGINNING, MIDDLE, OR END OF THE LOOP.



-- EACH TEST IS A LOOP ON  J  WHERE THE EXIT CONDITIONS ARE TO EVALUATE
--    TO  'FALSE'  A CERTAIN NUMBER OF TIMES UNTIL, AT THE APPROPRIATE
--    TIME, ONE OF THEM EVALUATES TO  'TRUE'  AND CAUSES THE LOOP TO BE
--    EXITED.
--
--
--    THE TEST IS PERFORMED 30 TIMES FOR EACH OF THE FIRST TWO
--    DATA TYPES CONSIDERED ('INTEGER', USER-DEFINED ENUMERATION)
--    AND 26 TIMES FOR 'CHARACTER' (THUS 86 TIMES ALTOGETHER).
--
--
--    EACH DATA TYPE HAS ITS OWN SEPARATE SECTION OF CODE.  ALL SECTIONS
--    FOLLOW THE SAME TESTING ALGORITHM (MUTATIS MUTANDIS).  THE CALCU-
--    LATIONS WHICH KEEP TRACK OF THE FLOW OF CONTROL ARE ALL DONE IN
--    INTEGER ARITHMETIC.  THERE ARE THREE DATA TYPES, THUS THREE
--    SECTIONS.
--
--
--    FOR EACH DATA TYPE, THE 30 TESTS ARE DIVIDED INTO 3 "SEGMENTS"
--
--               << NOTE:  THE NUMBER OF SEGMENTS IS WRITTEN  " 3 "    ,
--                         THE NUMBER OF SECTIONS IS WRITTEN  "THREE" >>
--
--    (OF 10 TESTS EACH, EXCEPT 10,10,6 FOR 'CHARACTER'), NUMBERED
--     0 , 1 , 2  AND CORRESPONDING TO THE 3 SIGNIFICANTLY DIFFERENT
--    POSITIONS OF AN EXIT STATEMENT WITH RESPECT TO THE LOOP IT IS IN
--    ( "AT THE VERY TOP" , "AT THE VERY BOTTOM" , "ANYWHERE IN BETWEEN"
--    ).  AT THE BEGINNING OF EACH TEST, THE VARIABLE  WHICH_SEGMENT
--    IS UPDATED TO CONTAIN THE NEW VALUE OF THIS IDENTIFYING NUMBER
--    (FOR THE TEST ABOUT TO BEGIN):
--
--             EXIT AT THE TOP      ........   WHICH_SEGMENT = 0
--             EXIT FROM THE MIDDLE ........   WHICH_SEGMENT = 1
--             EXIT AT THE BOTTOM   ........   WHICH_SEGMENT = 2   .
--
--
--    WITHIN EACH SECTION, THE TESTS ARE NUMBERED  FROM  1  TO  30
--    (26 FOR 'CHARACTER').  THIS NUMBER IS STORED IN THE INTEGER
--    VARIABLE  INT_I  (EQUAL TO THE CURRENT VALUE OF THE OUTER-LOOP
--    INDEX WHEN THAT INDEX IS OF INTEGER TYPE), WHOSE APPROPRIATE VALUE
--    FOR EACH TEST IS SET AT THE BEGINNING OF THE TEST.
--
--
--    AS PART OF THE EVALUATION PROCESS, THE PROGRAM COMPUTES FOR EACH
--    TEST (I.E.  FOR EACH VALUE OF  I , OR OF  INT_I ) THE APPROPRIATE
--    NUMBER OF INNER-LOOP ITERATIONS REQUIRED BEFORE EXIT; THIS IS
--    THE EXPECTED VALUE OF  J  (EXPRESSED AS AN INTEGER IN THE RANGE
--     1..10 ) AND STORES IT IN  EXPECTED_J .  FOR EACH OF THE THREE
--    SECTIONS, THE TIME SEQUENCE OF THESE 30 VALUES IS
--
--             1   2   3   4   5   6   7   8   9  10     << SEGMENT 1 >>
--             6   6   7   7   8   8   9   9  10  10     << SEGMENT 2 >>
--             7   8   8   8   9   9   9  10  10  10     << SEGMENT 3 >>
--
--    (EACH SECTION GETS ALL 3 ROWS, NOT ONE ROW PER SECTION;
--    FOR 'CHARACTER', WHERE ONLY 26 VALUES ARE REQUIRED, THE LAST 4
--    VALUES ARE OMITTED).  THIS NUMBER IS COMPARED WITH THE ACTUAL
--    VALUE OF  J  (ACTUAL NUMBER OF INNER-LOOP ITERATIONS BEFORE THE
--    EXECUTION OF THE EXIT STATEMENT) AS SAVED JUST BEFORE THE EXIT
--    FROM THE LOOP (AGAIN IN THE FORM OF AN INTEGER IN THE RANGE
--     1..30 , IRRESPECTIVE OF THE DATA TYPE BEING TESTED),  I F
--    SUCH SAVED VALUE IS AVAILABLE.
--
--
--    THE ACTUAL VALUE OF INNER-LOOP ITERATIONS (AS SAVED IMMEDIATELY
--    BEFORE THE EXIT, AS OPPOSED TO A VALUE LEFT OVER FROM SOME
--    PREVIOUS ITERATION) IS AVAILABLE ONLY IF  WHICH_SEGMENT /= 0 ,
--    AND IS THEN STORED IN  SAVE_J .
--
--
--    FOR THE CASE  WHICH_SEGMENT = 0 , THE ITERATIONS ARE COUNTED IN
--    THE VARIABLE  COUNT , WHOSE VALUE AT THE COMPLETION OF THE
--    I-TH TEST ( I IN 1..10 ) MUST BE EQUAL TO  EXPECTED_J - 1 ,
--    AND THUS TO  I - 1  (METHODOLOGICALLY AS WELL AS COMPUTATIONALLY
--    THIS IS NO DIFFERENT FROM USING THE MOST RECENT VALUE OF  SAVE_J
--    WHEN A CURRENT ONE CANNOT BE OBTAINED).  AFTER BEING INCREMENTED
--    BY  1 ,  COUNT  IS CHECKED AGAINST  EXPECTED_J .
--
--
--    THIS CONCLUDES THE DESCRIPTION OF THE CASE  WHICH_SEGMENT = 0 ,
--    AND THUS OF THE ALGORITHM.  THE ONLY REASON FOR SPLITTING THE
--    CASE  WHICH_SEGMENT /= 0  INTO TWO IS THE DESIRE TO PROVIDE FOR
--    DISTINCT MESSAGES.



-- RM 04/23/81
-- SPS 3/7/83

WITH REPORT;
PROCEDURE  C57003A  IS

     USE  REPORT ;

BEGIN

     TEST( "C57003A" , "TEST THAT THE EXIT STATEMENT IS EVALUATED" &
                       " EACH TIME THROUGH THE LOOP"               );

     DECLARE

          WHICH_SEGMENT  :  INTEGER RANGE 0..2   ;   -- BOUNDS ARE TIGHT
          SAVE_J         :  INTEGER RANGE 1..10  ;
          EXPECTED_J     :  INTEGER RANGE 1..10  ;
          COUNT          :  INTEGER RANGE 0..100     := 0 ;
          INT_I          :  INTEGER RANGE 1..30  ;

          TYPE  ENUM  IS    ( CHANGE_THE_ORIGIN_FROM_0_TO_1 ,

               A1 , A2 , A3 , A4 , A5 , A6 , A7 , A8 , A9 , A10 ,
               A11, A12, A13, A14, A15, A16, A17, A18, A19, A20 ,
               A21, A22, A23, A24, A25, A26, A27, A28, A29, A30 );

     BEGIN


          --------------------------------------------------------------
          -----------------------  INTEGER  ----------------------------


          FOR  I  IN  INTEGER RANGE 1..30  LOOP


               WHICH_SEGMENT  :=  ( I - 1 ) / 10        ;
               EXPECTED_J     :=  ( I + WHICH_SEGMENT ) /
                                  ( WHICH_SEGMENT + 1 ) ;

               COUNT  :=  0 ;


               FOR  J  IN  INTEGER RANGE 1..10  LOOP

                    --  J  NOT SAVED HERE (SO THAT 'EXIT' BE FIRST STMT)

                    EXIT WHEN  WHICH_SEGMENT = 0  AND
                               1*J >= I ;--COUNT+:=1 ON NXT LINE INSTEAD
                    COUNT := COUNT + 1 ;

                    NULL ;
                    NULL ;
                    NULL ;
                    SAVE_J := J ;
                    EXIT WHEN  WHICH_SEGMENT = 1  AND
                               2*J >= I ;

                    NULL ;
                    NULL ;
                    NULL ;
                    SAVE_J := J ;
                    EXIT WHEN  WHICH_SEGMENT = 2  AND
                               3*J >= I ;

               END LOOP;


               COUNT          :=  COUNT + 1             ;  -- SEE HEADER

               CASE  WHICH_SEGMENT  IS
                    WHEN  0  =>
                         IF  COUNT  /=  EXPECTED_J  THEN
                              FAILED( "WRONG COUNT; INT, EXIT AT TOP" );
                         END IF;
                    WHEN  1  =>                 -- WOULD WORK ALSO FOR 0
                         IF  SAVE_J  /=  EXPECTED_J  THEN
                              FAILED( "WRONG COUNT; I,EXIT AT MIDDLE" );
                         END IF;
                    WHEN  2  =>
                         IF  SAVE_J  /=  EXPECTED_J  THEN
                              FAILED( "WRONG COUNT; I,EXIT AT BOTTOM" );
                         END IF;
               END CASE;

          END LOOP;



          --------------------------------------------------------------
          ----------------------  CHARACTER  ---------------------------


          FOR  I  IN  CHARACTER RANGE 'A'..'Z'  LOOP

               INT_I  := CHARACTER'POS(I) - CHARACTER'POS('A') + 1;

               WHICH_SEGMENT  :=  ( INT_I - 1 ) / 10        ;
               EXPECTED_J     :=  ( INT_I + WHICH_SEGMENT ) /
                                  ( WHICH_SEGMENT + 1 )     ;

               COUNT  :=  0 ;


               FOR  J  IN  CHARACTER RANGE 'A'..'J'  LOOP

                    --  J  NOT SAVED HERE (SO THAT 'EXIT' BE FIRST STMT)

                    EXIT WHEN  WHICH_SEGMENT = 0  AND
                               J >= I ; -- COUNT+:=1 ON NXT LINE INSTEAD
                    COUNT := COUNT + 1 ;

                    NULL ;
                    NULL ;
                    NULL ;
                    SAVE_J := CHARACTER'POS(J) - CHARACTER'POS('A') + 1;
                    EXIT WHEN  WHICH_SEGMENT = 1  AND
                               2 * SAVE_J >= INT_I ;

                    NULL ;
                    NULL ;
                    NULL ;
                    EXIT WHEN  WHICH_SEGMENT = 2  AND
                               3 * SAVE_J >= INT_I ;

               END LOOP;


               COUNT          :=    COUNT + 1               ;

               CASE  WHICH_SEGMENT  IS
                    WHEN  0  =>
                         IF  COUNT  /=  EXPECTED_J  THEN
                              FAILED( "WRONG COUNT;CHAR, EXIT AT TOP" );
                         END IF;
                    WHEN  1  =>                 -- WOULD WORK ALSO FOR 0
                         IF  SAVE_J  /=  EXPECTED_J  THEN
                              FAILED( "WRONG COUNT; C,EXIT AT MIDDLE" );
                         END IF;
                    WHEN  2  =>
                         IF  SAVE_J  /=  EXPECTED_J  THEN
                              FAILED( "WRONG COUNT; C,EXIT AT BOTTOM" );
                         END IF;
               END CASE;

          END LOOP;



          --------------------------------------------------------------
          ---------------------  ENUMERATION  --------------------------


          FOR  I  IN  ENUM RANGE A1..A30  LOOP


               INT_I          :=    ENUM'POS(I) ;

               WHICH_SEGMENT  :=  ( INT_I - 1 ) / 10        ;
               EXPECTED_J     :=  ( INT_I + WHICH_SEGMENT ) /
                                  ( WHICH_SEGMENT + 1 )     ;

               COUNT  :=  0 ;


               FOR  J  IN  ENUM RANGE A1..A10  LOOP

                    --  J  NOT SAVED HERE (SO THAT 'EXIT' BE FIRST STMT)

                    EXIT WHEN  WHICH_SEGMENT = 0  AND
                               J >= I ; -- COUNT+:=1 ON NXT LINE INSTEAD
                    COUNT := COUNT + 1 ;

                    NULL ;
                    NULL ;
                    NULL ;
                    SAVE_J := ENUM'POS(J) ;
                    EXIT WHEN  WHICH_SEGMENT = 1  AND
                               2 * SAVE_J >= INT_I ;

                    NULL ;
                    NULL ;
                    NULL ;
                    EXIT WHEN  WHICH_SEGMENT = 2  AND
                               3 * SAVE_J >= INT_I ;

               END LOOP;


               COUNT          :=    COUNT + 1               ;

               CASE  WHICH_SEGMENT  IS
                    WHEN  0  =>
                         IF  COUNT  /=  EXPECTED_J  THEN
                              FAILED( "WRONG COUNT;ENUM, EXIT AT TOP" );
                         END IF;
                    WHEN  1  =>                 -- WOULD WORK ALSO FOR 0
                         IF  SAVE_J  /=  EXPECTED_J  THEN
                              FAILED( "WRONG COUNT; E,EXIT AT MIDDLE" );
                         END IF;
                    WHEN  2  =>
                         IF  SAVE_J  /=  EXPECTED_J  THEN
                              FAILED( "WRONG COUNT; E,EXIT AT BOTTOM" );
                         END IF;
               END CASE;

          END LOOP;

          --------------------------------------------------------------

     END ;


     RESULT ;


END  C57003A ;