aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.9/gcc/testsuite/ada/acats/tests/c3/c380004.a
blob: f83728b5f480346cad970b469b94cbe1bd1e62f9 (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
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
-- C380004.A
--
--                             Grant of Unlimited Rights
--
--     The Ada Conformity Assessment Authority (ACAA) holds unlimited
--     rights in the software and documentation contained herein. Unlimited
--     rights are the same as those granted by the U.S. Government for older
--     parts of the Ada Conformity Assessment Test Suite, and are defined
--     in DFAR 252.227-7013(a)(19). By making this public release, the ACAA
--     intends to confer upon all recipients unlimited rights equal to those
--     held by the ACAA. 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 ACAA 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.
--*
--
-- OBJECTIVE:
--    Check that per-object expressions are evaluated as specified for entry
--    families and protected components.  (Defect Report 8652/0002,
--    as reflected in Technical Corrigendum 1, RM95 3.6(22/1), 3.8(18/1), and
--    9.5.2(22/1)).
--
-- CHANGE HISTORY:
--     9 FEB 2001   PHL   Initial version.
--    29 JUN 2002   RLB   Readied for release.
--
--!
with Report;
use Report;
procedure C380004 is

    type Rec (D1, D2 : Positive) is
        record
            null;
        end record;

    F1_Poe : Integer;

    function Chk (Poe : Integer; Value : Integer; Message : String)
                 return Boolean is
    begin
        if Poe /= Value then
            Failed (Message & ": Poe is " & Integer'Image (Poe));
        end if;
        return True;
    end Chk;

    function F1 return Integer is
    begin
        F1_Poe := F1_Poe - Ident_Int (1);
        return F1_Poe;
    end F1;

    generic
        type T is limited private;
        with function Is_Ok (X : T;
                             Param1 : Integer;
                             Param2 : Integer;
                             Param3 : Integer) return Boolean;
    procedure Check;

    procedure Check is
    begin

        declare
            type Poe is new T;
            Chk1 : Boolean := Chk (F1_Poe, 17, "F1 evaluated");
            X : Poe;             -- F1 evaluated
            Y : Poe;             -- F1 evaluated
            Chk2 : Boolean := Chk (F1_Poe, 15, "F1 not evaluated");
        begin
            if not Is_Ok (T (X), 16, 16, 17) or
               not Is_Ok (T (Y), 15, 15, 17) then
                Failed ("Discriminant values not correct - 0");
            end if;
        end;

        declare
            type Poe is new T;
        begin
            begin
                declare
                    X : Poe;
                begin
                    if not Is_Ok (T (X), 14, 14, 17) then
                        Failed ("Discriminant values not correct - 1");
                    end if;
                end;
            exception
                when others =>
                    Failed ("Unexpected exception - 1");
            end;

            declare
                type Acc_Poe is access Poe;
                X : Acc_Poe;
            begin
                X := new Poe;
                begin
                    if not Is_Ok (T (X.all), 13, 13, 17) then
                        Failed ("Discriminant values not correct - 2");
                    end if;
                end;
            exception
                when others =>
                    Failed ("Unexpected exception raised - 2");
            end;

            declare
                subtype Spoe is Poe;
                X : Spoe;
            begin
                if not Is_Ok (T (X), 12, 12, 17) then
                    Failed ("Discriminant values not correct - 3");
                end if;
            exception
                when others =>
                    Failed ("Unexpected exception raised - 3");
            end;

            declare
                type Arr is array (1 .. 2) of Poe;
                X : Arr;
            begin
                if Is_Ok (T (X (1)), 11, 11, 17) and then
                   Is_Ok (T (X (2)), 10, 10, 17) then
                    null;
                elsif Is_Ok (T (X (2)), 11, 11, 17) and then
                      Is_Ok (T (X (1)), 10, 10, 17) then
                    null;
                else
                    Failed ("Discriminant values not correct - 4");
                end if;
            exception
                when others =>
                    Failed ("Unexpected exception raised - 4");
            end;

            declare
                type Nrec is
                    record
                        C1, C2 : Poe;
                    end record;
                X : Nrec;
            begin
                if Is_Ok (T (X.C1), 8, 8, 17) and then
                   Is_Ok (T (X.C2), 9, 9, 17) then
                    null;
                elsif Is_Ok (T (X.C2), 8, 8, 17) and then
                      Is_Ok (T (X.C1), 9, 9, 17) then
                    null;
                else
                    Failed ("Discriminant values not correct - 5");
                end if;
            exception
                when others =>
                    Failed ("Unexpected exception raised - 5");
            end;

            declare
                type Drec is new Poe;
                X : Drec;
            begin
                if not Is_Ok (T (X), 7, 7, 17) then
                    Failed ("Discriminant values not correct - 6");
                end if;
            exception
                when others =>
                    Failed ("Unexpected exception raised - 6");
            end;
        end;
    end Check;


begin
    Test ("C380004",
          "Check evaluation of discriminant expressions " &
             "when the constraint depends on a discriminant, " &
             "and the discriminants have defaults - discriminant-dependent" &
             "entry families and protected components");


    Comment ("Discriminant-dependent entry families for task types");

    F1_Poe := 18;

    declare
        task type Poe (D3 : Positive := F1) is
            entry E (D3 .. F1);    -- F1 evaluated
            entry Is_Ok (D3 : Integer;
                         E_First : Integer;
                         E_Last : Integer;
                         Ok : out Boolean);
        end Poe;
        task body Poe is
        begin
            loop
                select
                    accept Is_Ok (D3 : Integer;
                                  E_First : Integer;
                                  E_Last : Integer;
                                  Ok : out Boolean) do
                        declare
                            Cnt : Natural;
                        begin
                            if Poe.D3 = D3 then
                                -- Can't think of a better way to check the
                                -- bounds of the entry family.
                                begin
                                    Cnt := E (E_First)'Count;
                                    Cnt := E (E_Last)'Count;
                                exception
                                    when Constraint_Error =>
                                        Ok := False;
                                        return;
                                end;
                                begin
                                    Cnt := E (E_First - 1)'Count;
                                    Ok := False;
                                    return;
                                exception
                                    when Constraint_Error =>
                                        null;
                                    when others =>
                                        Ok := False;
                                        return;
                                end;
                                begin
                                    Cnt := E (E_Last + 1)'Count;
                                    Ok := False;
                                    return;
                                exception
                                    when Constraint_Error =>
                                        null;
                                    when others =>
                                        Ok := False;
                                        return;
                                end;
                                Ok := True;
                            else
                                Ok := False;
                                return;
                            end if;
                        end;
                    end Is_Ok;
                or
                    terminate;
                end select;
            end loop;
        end Poe;

        function Is_Ok
                    (C : Poe; D3 : Integer; E_First : Integer; E_Last : Integer)
                    return Boolean is
            Ok : Boolean;
        begin
            C.Is_Ok (D3, E_First, E_Last, Ok);
            return Ok;
        end Is_Ok;

        procedure Chk is new Check (Poe, Is_Ok);

    begin
        Chk;
    end;


    Comment ("Discriminant-dependent entry families for protected types");

    F1_Poe := 18;

    declare
        protected type Poe (D3 : Integer := F1) is
            entry E (D3 .. F1);    -- F1 evaluated
            function Is_Ok (D3 : Integer; E_First : Integer; E_Last : Integer)
                           return Boolean;
        end Poe;
        protected body Poe is
            entry E (for I in D3 .. F1) when True is
            begin
                null;
            end E;
            function Is_Ok (D3 : Integer; E_First : Integer; E_Last : Integer)
                           return Boolean is
                Cnt : Natural;
            begin
                if Poe.D3 = D3 then
                    -- Can't think of a better way to check the
                    -- bounds of the entry family.
                    begin
                        Cnt := E (E_First)'Count;
                        Cnt := E (E_Last)'Count;
                    exception
                        when Constraint_Error =>
                            return False;
                    end;
                    begin
                        Cnt := E (E_First - 1)'Count;
                        return False;
                    exception
                        when Constraint_Error =>
                            null;
                        when others =>
                            return False;
                    end;
                    begin
                        Cnt := E (E_Last + 1)'Count;
                        return False;
                    exception
                        when Constraint_Error =>
                            null;
                        when others =>
                            return False;
                    end;
                    return True;
                else
                    return False;
                end if;
            end Is_Ok;
        end Poe;

        function Is_Ok
                    (C : Poe; D3 : Integer; E_First : Integer; E_Last : Integer)
                    return Boolean is
        begin
            return C.Is_Ok (D3, E_First, E_Last);
        end Is_Ok;

        procedure Chk is new Check (Poe, Is_Ok);

    begin
        Chk;
    end;

    Comment ("Protected components");

    F1_Poe := 18;

    declare
        protected type Poe (D3 : Integer := F1) is
            function C1_D1 return Integer;
            function C1_D2 return Integer;
        private
            C1 : Rec (D3, F1);    -- F1 evaluated
        end Poe;
        protected body Poe is
            function C1_D1 return Integer is
            begin
                return C1.D1;
            end C1_D1;
            function C1_D2 return Integer is
            begin
                return C1.D2;
            end C1_D2;
        end Poe;

        function Is_Ok (C : Poe; D3 : Integer; C1_D1 : Integer; C1_D2 : Integer)
                       return Boolean is
        begin
            return C.D3 = D3 and C.C1_D1 = C1_D1 and C.C1_D2 = C1_D2;
        end Is_Ok;

        procedure Chk is new Check (Poe, Is_Ok);

    begin
        Chk;
    end;

    Result;

exception
    when others =>
        Failed ("Unexpected exception");
        Result;

end C380004;