aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/ada/acats/tests/c3/c393a03.a
blob: 90106f4bf444bb04937f91323e974a0914d885a4 (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
-- C393A03.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 a non-abstract primitive subprogram of an abstract
--      type can be called as a dispatching operation and that the body
--      of this subprogram can make a dispatching call to an abstract
--      operation of the corresponding abstract type. 
--
-- TEST DESCRIPTION:
--      This test expands on the class family defined in foundation F393A00
--      by deriving a new abstract type from the root abstract type "Object".
--      The subprograms defined for the new abstract type are then
--      appropriately overridden, and the test ultimately calls various
--      mixtures of these subprograms to check that the dispatching occurs
--      correctly.
--
-- TEST FILES:
--      The following files comprise this test:
--
--         F393A00.A   (foundation code)
--         C393A03.A
--
--
-- CHANGE HISTORY:
--      06 Dec 94   SAIC    ACVC 2.0
--      19 Dec 94   SAIC    Removed ARM references from objective text.
--      23 Oct 95   SAIC    Fixed bugs for ACVC 2.0.1
--
--!

------------------------------------------------------------------- C393A03_0

with F393A00_1;
package C393A03_0 is

  type Counting_Object is abstract new F393A00_1.Object with private;
  -- inherits Initialize, Swap (abstract) and Create (abstract)

  procedure Bump ( A_Counter: in out Counting_Object );
  procedure Clear( A_Counter: in out Counting_Object ) is abstract;
  procedure Zero ( A_Counter: in out Counting_Object );
  function  Value( A_Counter: Counting_Object'Class ) return Natural;

private

  type Counting_Object is abstract new F393A00_1.Object with
    record
      Tally : Natural :=0;
    end record;

end C393A03_0;

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

with F393A00_0;
package body C393A03_0 is

  procedure Bump ( A_Counter: in out Counting_Object ) is
  begin
    F393A00_0.TC_Touch('A');
    A_Counter.Tally := A_Counter.Tally +1;
  end Bump;

  procedure Zero ( A_Counter: in out Counting_Object ) is
  begin
    F393A00_0.TC_Touch('B');

 -- dispatching call to abstract operation of Counting_Object
    Clear( Counting_Object'Class(A_Counter) );

    A_Counter.Tally := 0;

  end Zero;

  function  Value( A_Counter: Counting_Object'Class ) return Natural is
  begin
    F393A00_0.TC_Touch('C');
    return A_Counter.Tally;
  end Value;

end C393A03_0;

------------------------------------------------------------------- C393A03_1

with C393A03_0;
package C393A03_1 is

  type Modular_Object is new C393A03_0.Counting_Object with private;
  -- inherits Initialize, Bump, Zero and Value,
  -- inherits abstract Swap, Create and Clear

  procedure Swap( A,B: in out Modular_Object );
  procedure Clear( It: in out Modular_Object );
  procedure Set_Max( It : in out Modular_Object; Value : Natural );
  function  Create return Modular_Object;

private

  type Modular_Object is new C393A03_0.Counting_Object with
    record
      Max_Value : Natural;
    end record;

end C393A03_1;

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

with F393A00_0;
package body C393A03_1 is

  procedure Swap( A,B: in out Modular_Object ) is
    T : constant Modular_Object := B;
  begin
    F393A00_0.TC_Touch('1');
    B := A;
    A := T;
  end Swap;

  procedure Clear( It: in out Modular_Object ) is
  begin
    F393A00_0.TC_Touch('2');
    null;
  end Clear;

  procedure Set_Max( It : in out Modular_Object; Value : Natural ) is
  begin
    F393A00_0.TC_Touch('3');
    It.Max_Value := Value;
  end Set_Max;

  function  Create return Modular_Object is
    AMO : Modular_Object;
  begin
    F393A00_0.TC_Touch('4');
    AMO.Max_Value := Natural'Last;
    return AMO;
  end Create;

end C393A03_1;

--------------------------------------------------------------------- C393A03

with Report;
with F393A00_0;
with F393A00_1;
with C393A03_0;
with C393A03_1;
procedure C393A03 is

  A_Thing       : C393A03_1.Modular_Object;
  Another_Thing : C393A03_1.Modular_Object;

  procedure Initialize( It: in out C393A03_0.Counting_Object'Class ) is
  begin
    C393A03_0.Initialize( It );  -- dispatch to inherited procedure
  end Initialize;

  procedure Bump( It: in out C393A03_0.Counting_Object'Class ) is
  begin
    C393A03_0.Bump( It ); -- dispatch to non-abstract procedure
  end Bump;

  procedure Set_Max( It  : in out C393A03_1.Modular_Object'Class;
                     Val : Natural) is
  begin
    C393A03_1.Set_Max( It, Val ); -- dispatch to non-abstract procedure
  end Set_Max;

  procedure Swap( A, B  : in out C393A03_0.Counting_Object'Class ) is
  begin
    C393A03_0.Swap( A, B ); -- dispatch to inherited abstract procedure
  end Swap;

  procedure Zero( It: in out C393A03_0.Counting_Object'Class ) is
  begin
    C393A03_0.Zero( It ); -- dispatch to non-abstract procedure
  end Zero;

begin  -- Main test procedure.

   Report.Test ("C393A03", "Check that a non-abstract primitive subprogram "
			 & "of an abstract type can be called as a "
			 & "dispatching operation and that the body of this "
			 & "subprogram can make a dispatching call to an "
			 & "abstract operation of the corresponding "
			 & "abstract type" );

   A_Thing := C393A03_1.Create; -- Max_Value = Natural'Last
   F393A00_0.TC_Validate( "4", "Overridden primitive layer 2");

   Initialize( A_Thing );
   Initialize( Another_Thing );
   F393A00_0.TC_Validate( "aa", "Non-abstract primitive layer 0");
   
   Bump( A_Thing ); -- Tally = 1
   F393A00_0.TC_Validate( "A", "Non-abstract primitive layer 1");

   Set_Max( A_Thing, 42 ); -- Max_Value = 42
   F393A00_0.TC_Validate( "3", "Non-abstract normal layer 2");

   if not F393A00_1.Initialized( A_Thing ) then
     Report.Failed("Initialize didn't");
   end if;
   F393A00_0.TC_Validate( "b", "Class-wide layer 0");

   Swap( A_Thing, Another_Thing );
   F393A00_0.TC_Validate( "1", "Overridden abstract layer 2");

   Zero( A_Thing );
   F393A00_0.TC_Validate( "B2", "Non-abstract layer 0, calls dispatch");

   if C393A03_0.Value( A_Thing ) /= 0 then
     Report.Failed("Zero didn't");
   end if;
   F393A00_0.TC_Validate( "C", "Class-wide normal layer 2");

   Report.Result;

end C393A03;