summaryrefslogtreecommitdiff
path: root/gcc/testsuite/ada/acats/tests/cc/cc51b03.a
blob: 0cbeeb46f633d5ce2925af2cd2941f4297dc3079 (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
-- CC51B03.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 the attribute S'Definite, where S is an indefinite formal
--      private or derived type, returns true if the actual corresponding to
--      S is definite, and returns false otherwise.
--
-- TEST DESCRIPTION:
--      A definite subtype is any subtype which is not indefinite. An
--      indefinite subtype is either:
--         a) An unconstrained array subtype.
--         b) A subtype with unknown discriminants (this includes class-wide
--            types).
--         c) A subtype with unconstrained discriminants without defaults.
--
--      The possible forms of indefinite formal subtype are as follows:
--
--         Formal derived types:
--          X - Ancestor is an unconstrained array type
--          * - Ancestor is a discriminated record type without defaults
--          X - Ancestor is a discriminated tagged type
--          * - Ancestor type has unknown discriminants
--            - Formal type has an unknown discriminant part
--          * - Formal type has a known discriminant part
--
--         Formal private types:
--            - Formal type has an unknown discriminant part
--          * - Formal type has a known discriminant part
--
--      The formal subtypes preceded by an 'X' above are not covered, because
--      other rules prevent a definite subtype from being passed as an actual.
--      The formal subtypes preceded by an '*' above are not covered, because
--      'Definite is less likely to be used for these formals.
--
--      The following kinds of actuals are passed to various of the formal
--      types listed above:
--
--            - Undiscriminated type
--            - Type with defaulted discriminants
--            - Type with undefaulted discriminants
--            - Class-wide type
--
--      A typical usage of S'Definite might be algorithm selection in a
--      generic I/O package, e.g., the use of fixed-length or variable-length
--      records depending on whether the actual is definite or indefinite.
--      In such situations, S'Definite would appear in if conditions or other
--      contexts requiring a boolean expression. This test checks S'Definite
--      in such usage contexts but, for brevity, omits any surrounding
--      usage code.
--      
-- TEST FILES:
--      The following files comprise this test:
--
--         FC51B00.A
--      -> CC51B03.A
--
--
-- CHANGE HISTORY:
--      06 Dec 94   SAIC    ACVC 2.0
--
--!

with FC51B00;  -- Indefinite subtype declarations.
package CC51B03_0 is

   --
   -- Formal private type cases:
   --

   generic
      type Formal (<>) is private;              -- Formal has unknown
   package PrivateFormalUnknownDiscriminants is -- discriminant part.
      function Is_Definite return Boolean;
   end PrivateFormalUnknownDiscriminants;


   --
   -- Formal derived type cases:
   --

   generic
      type Formal (<>) is new FC51B00.Vector    -- Formal has an unknown disc.
        with private;                           -- part; ancestor is tagged.
   package TaggedAncestorUnknownDiscriminants is
      function Is_Definite return Boolean;
   end TaggedAncestorUnknownDiscriminants;


end CC51B03_0;


     --==================================================================--


package body CC51B03_0 is

   package body PrivateFormalUnknownDiscriminants is
      function Is_Definite return Boolean is
      begin
         if Formal'Definite then                -- Attribute used in "if"
            -- ...Execute algorithm #1...       -- condition inside subprogram.
            return True;
         else
            -- ...Execute algorithm #2...
            return False;
         end if;
      end Is_Definite;
   end PrivateFormalUnknownDiscriminants;


   package body TaggedAncestorUnknownDiscriminants is
      function Is_Definite return Boolean is
      begin
         return Formal'Definite;                -- Attribute used in return
      end Is_Definite;                          -- statement inside subprogram.
   end TaggedAncestorUnknownDiscriminants;


end CC51B03_0;


     --==================================================================--


with FC51B00;
package CC51B03_1 is

   subtype Spin_Type is Natural range 0 .. 3;

   type Extended_Vector (Spin : Spin_Type) is   -- Tagged type with
     new FC51B00.Vector with null record;       -- discriminant (indefinite).
      

end CC51B03_1;


     --==================================================================--


with FC51B00;   -- Indefinite subtype declarations.
with CC51B03_0; -- Generic package declarations.
with CC51B03_1;

with Report;
procedure CC51B03 is

   --
   -- Instances for formal private type with unknown discriminants:
   --

   package PrivateFormal_UndiscriminatedTaggedActual is new
     CC51B03_0.PrivateFormalUnknownDiscriminants (FC51B00.Vector);

   package PrivateFormal_ClassWideActual is new
     CC51B03_0.PrivateFormalUnknownDiscriminants (FC51B00.Vector'Class);

   package PrivateFormal_DiscriminatedTaggedActual is new
     CC51B03_0.PrivateFormalUnknownDiscriminants (FC51B00.Square_Pair);

   package PrivateFormal_DiscriminatedUndefaultedRecordActual is new
     CC51B03_0.PrivateFormalUnknownDiscriminants (FC51B00.Square);


   subtype Length is Natural range 0 .. 20;
   type Message (Len : Length := 0) is record   -- Record type with defaulted
      Text : String (1 .. Len);                 -- discriminant (definite).
   end record;
      
   package PrivateFormal_DiscriminatedDefaultedRecordActual is new
     CC51B03_0.PrivateFormalUnknownDiscriminants (Message);


   --
   -- Instances for formal derived tagged type with unknown discriminants:
   --

   package DerivedFormal_UndiscriminatedTaggedActual is new
     CC51B03_0.TaggedAncestorUnknownDiscriminants (FC51B00.Vector);

   package DerivedFormal_ClassWideActual is new
     CC51B03_0.TaggedAncestorUnknownDiscriminants (FC51B00.Vector'Class);

   package DerivedFormal_DiscriminatedTaggedActual is new
     CC51B03_0.TaggedAncestorUnknownDiscriminants (CC51B03_1.Extended_Vector);


begin
   Report.Test ("CC51B03", "Check that S'Definite returns true if the " &
                "actual corresponding to S is definite, and false otherwise");


   if not PrivateFormal_UndiscriminatedTaggedActual.Is_Definite then
      Report.Failed ("Formal private/unknown discriminants: wrong " &
                     "result for undiscriminated tagged actual");
   end if;  

   if PrivateFormal_ClassWideActual.Is_Definite then
      Report.Failed ("Formal private/unknown discriminants: wrong " &
                     "result for class-wide actual");
   end if;  

   if PrivateFormal_DiscriminatedTaggedActual.Is_Definite then
      Report.Failed ("Formal private/unknown discriminants: wrong " &
                     "result for discriminated tagged actual");
   end if;  

   if PrivateFormal_DiscriminatedUndefaultedRecordActual.Is_Definite then
      Report.Failed ("Formal private/unknown discriminants: wrong result " &
                     "for record actual with undefaulted discriminants");
   end if;  

   if not PrivateFormal_DiscriminatedDefaultedRecordActual.Is_Definite then
      Report.Failed ("Formal private/unknown discriminants: wrong result " &
                     "for record actual with defaulted discriminants");
   end if;  


   if not DerivedFormal_UndiscriminatedTaggedActual.Is_Definite then
      Report.Failed ("Formal derived/unknown discriminants: wrong result " &
                     "for undiscriminated tagged actual");
   end if;  

   if DerivedFormal_ClassWideActual.Is_Definite then
      Report.Failed ("Formal derived/unknown discriminants: wrong result " &
                     "for class-wide actual");
   end if;  

   if DerivedFormal_DiscriminatedTaggedActual.Is_Definite then
      Report.Failed ("Formal derived/unknown discriminants: wrong result " &
                     "for discriminated tagged actual");
   end if;  


   Report.Result;
end CC51B03;