summaryrefslogtreecommitdiff
path: root/gcc/testsuite/ada/acats/tests/c6/c641001.a
blob: 84ee58a7ed57646c5d15f2247f66cdb1f233f5b6 (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
-- C641001.A
--
--                             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.
--*
--
-- OBJECTIVE:
--      Check that actual parameters passed by reference are view converted
--      to the nominal subtype of the formal parameter.
--
-- TEST DESCRIPTION:
--      Check that sliding is allowed for formal parameters, especially
--      check cases that would have caused errors in Ada'83.
--      Check that length check for a formal parameter (esp out mode)
--      is performed before the call, not after.
--
--  notes: 6.2; by reference ::= tagged, task, protected,
--                       limited (nonprivate), or composite containing such
--         4.6; view conversion
--
--
-- CHANGE HISTORY:
--      26 JAN 96   SAIC   Initial version
--      04 NOV 96   SAIC   Commentary revision for release 2.1
--      27 FEB 97   PWB.CTA Corrected reference to the wrong string
--!

----------------------------------------------------------------- C641001_0

package C641001_0 is

  subtype String_10 is String(1..10);

  procedure Check_String_10( S : out String_10; Start, Stop: Natural );

  procedure Check_Illegal_Slice_Reference( Slice_Passed : in out String;
                                           Index: Natural );

  type Tagged_Data(Bound: Natural) is tagged record
    Data_Item : String(1..Bound) := (others => '*');
  end record;

  type Tag_List is array(Natural range <>) of Tagged_Data(5);

  subtype Tag_List_10 is Tag_List(1..10);

  procedure Check_Tag_Slice( TL : in out Tag_List_10 );

  procedure Check_Out_Tagged_Data( Formal : out Tagged_Data );

end C641001_0;

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

with Report;
with TCTouch;
package body C641001_0 is

  String_Data : constant String := "1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ";

  procedure Check_String_10( S : out String_10; Start, Stop: Natural ) is
  begin
    if S'Length /= 10 then
      Report.Failed("Length check not performed prior to execution");
    end if;
    S := String_Data(Start..Stop);
  exception
    when others => Report.Failed("Exception encountered in Check_String_10");
  end Check_String_10;

  procedure Check_Illegal_Slice_Reference( Slice_Passed : in out String;
                                           Index: Natural ) is
  begin
    -- essentially "do-nothing" for optimization foilage...
    if Slice_Passed(Index) in Character then
    -- Intent is    ^^^^^  should raise Constraint_Error
      Report.Failed("Illegal Slice provided legal character");
    else
      Report.Failed("Illegal Slice provided illegal character");
    end if;
  exception
    when Constraint_Error =>
      null; -- expected case
    when others =>
      Report.Failed("Wrong exception in Check_Illegal_Slice_Reference");
  end Check_Illegal_Slice_Reference;

  procedure Check_Tag_Slice( TL : in out Tag_List_10 ) is
    -- if the view conversion is not performed, one of the following checks
    -- will fail (given data passed as 0..9 and then 2..11)
  begin
    Check_Under_Index:  -- index 0 should raise C_E
    begin
      TCTouch.Assert( TL(Report.Ident_Int(0)).Data_Item = "*****",
                      "Index 0 (illegal); bad data" );
      Report.Failed("Index 0 did not raise Constraint_Error");
    exception
      when Constraint_Error =>
        null; -- expected case
      when others =>
        Report.Failed("Wrong exception in Check_Under_Index ");
    end Check_Under_Index;

    Check_Over_Index:  -- index 11 should raise C_E
    begin
      TCTouch.Assert( TL(Report.Ident_Int(11)).Data_Item = "*****",
                      "Index 11 (illegal); bad data" );
      Report.Failed("Index 11 did not raise Constraint_Error");
    exception
      when Constraint_Error =>
        null; -- expected case
      when others =>
        Report.Failed("Wrong exception in Check_Over_Index ");
    end Check_Over_Index;

  end Check_Tag_Slice;

  procedure Check_Out_Tagged_Data( Formal : out Tagged_Data ) is
  begin
    TCTouch.Assert( Formal.Data_Item = "*****", "out formal data bad" );
    Formal.Data_Item(1) := '!';
  end Check_Out_Tagged_Data;

end C641001_0;

------------------------------------------------------------------- C641001

with Report;
with TCTouch;
with C641001_0;
procedure C641001 is

  function II( I: Integer ) return Integer renames Report.Ident_Int;
        -- ^^ name chosen to allow embedding in calls

  A_String_10 : C641001_0.String_10;
  Slicable    : String(1..40);
  Tag_Slices  : C641001_0.Tag_List(0..11);

  Global_Data : String(1..26) := "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

  procedure Check_Out_Sliding( Lo1, Hi1, Lo2, Hi2 : Natural ) is

    subtype One_Constrained_String is String(Lo1..Hi1);   -- 1  5
    subtype Two_Constrained_String is String(Lo2..Hi2);   -- 6 10

    procedure Out_Param( Param : out One_Constrained_String ) is
    begin
      Param := Report.Ident_Str( Global_Data(Lo2..Hi2) );
    end Out_Param;
    Object : Two_Constrained_String;
  begin
    Out_Param( Object );
    if Object /= Report.Ident_Str( Global_Data(Lo2..Hi2) ) then
      Report.Failed("Bad result in Check_Out_Sliding");
    end if;
  exception
    when others => Report.Failed("Exception in Check_Out_Sliding");
  end Check_Out_Sliding;

  procedure Check_Dynamic_Subtype_Cases(F_Lower,F_Upper: Natural;
                                        A_Lower,A_Upper: Natural) is

    subtype Dyn_String is String(F_Lower..F_Upper);

    procedure Check_Dyn_Subtype_Formal_Out( Param : out Dyn_String ) is
    begin
      Param := Global_Data(11..20);
    end Check_Dyn_Subtype_Formal_Out;

    procedure Check_Dyn_Subtype_Formal_In( Param : in Dyn_String ) is
    begin
      if Param /= Global_Data(11..20) then
        Report.Failed("Dynamic case, data mismatch");
      end if;
    end Check_Dyn_Subtype_Formal_In;

    Stuff: String(A_Lower..A_Upper);

  begin
    Check_Dyn_Subtype_Formal_Out( Stuff );
    Check_Dyn_Subtype_Formal_In( Stuff );
  end Check_Dynamic_Subtype_Cases;

begin  -- Main test procedure.

  Report.Test ("C641001", "Check that actual parameters passed by " &
                          "reference are view converted to the nominal " &
                          "subtype of the formal parameter" );

  -- non error cases for string slices

  C641001_0.Check_String_10( A_String_10, 1, 10 );
  TCTouch.Assert( A_String_10 = "1234567890", "Nominal case" );

  C641001_0.Check_String_10( A_String_10, 11, 20 );
  TCTouch.Assert( A_String_10 = "ABCDEFGHIJ", "Sliding to subtype" );

  C641001_0.Check_String_10( Slicable(1..10), 1, 10 );
  TCTouch.Assert( Slicable(1..10) = "1234567890", "Slice, no sliding" );

  C641001_0.Check_String_10( Slicable(1..10), 21, 30 );
  TCTouch.Assert( Slicable(1..10) = "KLMNOPQRST", "Sliding to slice" );

  C641001_0.Check_String_10( Slicable(11..20), 11, 20 );
  TCTouch.Assert( Slicable(11..20) = "ABCDEFGHIJ", "Sliding to same" );

  C641001_0.Check_String_10( Slicable(21..30), 11, 20 );
  TCTouch.Assert( Slicable(21..30) = "ABCDEFGHIJ", "Sliding up" );

  -- error cases for string slices

  C641001_0.Check_Illegal_Slice_Reference( Slicable(21..30), 20 );

  C641001_0.Check_Illegal_Slice_Reference( Slicable(1..15), Slicable'Last );

  -- checks for view converting actuals to formals

  -- catch low bound fault
  C641001_0.Check_Tag_Slice( Tag_Slices(II(0)..9) );     -- II ::= Ident_Int
  TCTouch.Assert( Tag_Slices'First = 0, "Tag_Slices'First = 0" );
  TCTouch.Assert( Tag_Slices'Last = 11, "Tag_Slices'Last = 11" );

  -- catch high bound fault
  C641001_0.Check_Tag_Slice( Tag_Slices(2..II(11)) );
  TCTouch.Assert( Tag_Slices'First = 0, "Tag_Slices'First = 0" );
  TCTouch.Assert( Tag_Slices'Last = 11, "Tag_Slices'Last = 11" );

  Check_Formal_Association_Check:
  begin
    C641001_0.Check_String_10( Slicable, 1, 10 ); -- catch length fault
    Report.Failed("Exception not raised at Check_Formal_Association_Check");
  exception
    when Constraint_Error =>
      null; -- expected case
    when others =>
      Report.Failed("Wrong exception at Check_Formal_Association_Check");
  end Check_Formal_Association_Check;

  -- check for constrained actual, unconstrained formal
  C641001_0.Check_Out_Tagged_Data( Tag_Slices(5) );
  TCTouch.Assert( Tag_Slices(5).Data_Item = "!****",
                  "formal out returned bad result" );

  -- additional checks for out mode formal parameters, dynamic subtypes

  Check_Out_Sliding( II(1),II(5), II(6),II(10) );

  Check_Out_Sliding( 21,25, 6,10 );

  Check_Dynamic_Subtype_Cases(F_Lower => II(1), F_Upper => II(10),
                              A_Lower => II(1), A_Upper => II(10));

  Check_Dynamic_Subtype_Cases(F_Lower => II(21), F_Upper => II(30),
                              A_Lower => II( 1), A_Upper => II(10));

  Check_Dynamic_Subtype_Cases(F_Lower => II( 1), F_Upper => II(10),
                              A_Lower => II(21), A_Upper => II(30));

  Report.Result;

end C641001;