OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [gcc-4.5.1/] [gcc/] [testsuite/] [ada/] [acats/] [tests/] [c7/] [c761004.a] - Blame information for rev 294

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 294 jeremybenn
-- C761004.A
2
--
3
--                             Grant of Unlimited Rights
4
--
5
--     Under contracts F33600-87-D-0337, F33600-84-D-0280, MDA903-79-C-0687,
6
--     F08630-91-C-0015, and DCA100-97-D-0025, the U.S. Government obtained
7
--     unlimited rights in the software and documentation contained herein.
8
--     Unlimited rights are defined in DFAR 252.227-7013(a)(19).  By making
9
--     this public release, the Government intends to confer upon all
10
--     recipients unlimited rights  equal to those held by the Government.
11
--     These rights include rights to use, duplicate, release or disclose the
12
--     released technical data and computer software in whole or in part, in
13
--     any manner and for any purpose whatsoever, and to have or permit others
14
--     to do so.
15
--
16
--                                    DISCLAIMER
17
--
18
--     ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR
19
--     DISCLOSED ARE AS IS.  THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED
20
--     WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE
21
--     SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE
22
--     OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A
23
--     PARTICULAR PURPOSE OF SAID MATERIAL.
24
--*
25
--
26
-- OBJECTIVE:
27
--      Check that an object of a controlled type is finalized with the
28
--      enclosing master is complete.
29
--      Check that finalization occurs in the case where the master is
30
--      left by a transfer of control.
31
--      Specifically check for types where the derived types do not have
32
--      discriminants.
33
--
34
--      Check that finalization of controlled objects is
35
--      performed in the correct order.  In particular, check that if
36
--      multiple objects of controlled types are declared immediately
37
--      within the same declarative part then they are finalized in the
38
--      reverse order of their creation.
39
--
40
-- TEST DESCRIPTION:
41
--      This test checks these conditions for subprograms and
42
--      block statements; both variables and constants of controlled
43
--      types; cases of a controlled component of a record type, as
44
--      well as an array with controlled components.
45
--
46
--      The base controlled types used for the test are defined
47
--      with a character discriminant.  The initialize procedure for
48
--      the types will record the order of creation in a globally
49
--      accessible array, the finalize procedure for the types will call
50
--      TCTouch with that tag character.  The test can then check that
51
--      the order of finalization is indeed the reverse of the order of
52
--      creation (assuming that the implementation calls Initialize in
53
--      the order that the objects are created).
54
--
55
--
56
-- CHANGE HISTORY:
57
--      06 Dec 94   SAIC    ACVC 2.0
58
--      04 Nov 95   SAIC    Fixed bugs for ACVC 2.0.1
59
--
60
--!
61
 
62
package C761004_Support is
63
 
64
  function Pick_Char return Character;
65
  -- successive calls to Pick_Char return distinct characters which may
66
  -- be assigned to objects to track an order sequence.  These characters
67
  -- are then used in calls to TCTouch.Touch.
68
 
69
  procedure Validate(Initcount: Natural; Testnumber:Natural);
70
  -- does a little extra processing prior to calling TCTouch.Validate,
71
  -- specifically, it reverses the stored string of characters, and checks
72
  -- for a correct count.
73
 
74
  Inits_Order  : String(1..255);
75
  Inits_Called : Natural := 0;
76
 
77
end C761004_Support;
78
 
79
with Report;
80
with TCTouch;
81
package body C761004_Support is
82
  type Pick_Rotation is mod 52;
83
  type Pick_String is array(Pick_Rotation) of Character;
84
 
85
  From : constant Pick_String  := "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
86
                                & "abcdefghijklmnopqrstuvwxyz";
87
  Recent_Pick : Pick_Rotation := Pick_Rotation'Last;
88
 
89
  function Pick_Char return Character is
90
  begin
91
    Recent_Pick := Recent_Pick +1;
92
    return From(Recent_Pick);
93
  end Pick_Char;
94
 
95
  function Invert(S:String) return String is
96
    T: String(1..S'Length);
97
    TI: Positive := 1;
98
  begin
99
    for SI in reverse S'Range loop
100
      T(TI) := S(SI);
101
      TI := TI +1;
102
    end loop;
103
    return T;
104
  end Invert;
105
 
106
  procedure Validate(Initcount: Natural; Testnumber:Natural) is
107
    Number : constant String := Natural'Image(Testnumber);
108
  begin
109
    if Inits_Called /= Initcount then
110
      Report.Failed("Wrong number of inits, Subtest " & Number);
111
      TCTouch.Flush;
112
    else
113
      TCTouch.Validate(
114
        Invert(Inits_Order(1..Inits_Called)),
115
               "Subtest " & Number, True);
116
    end if;
117
  end Validate;
118
 
119
end C761004_Support;
120
 
121
----------------------------------------------------------------- C761004_0
122
 
123
with Ada.Finalization;
124
package C761004_0 is
125
  type Global is new Ada.Finalization.Controlled with record
126
    Tag : Character;
127
  end record;
128
  procedure Initialize( It: in out Global );
129
  procedure Finalize  ( It: in out Global );
130
 
131
  type Second is new Ada.Finalization.Limited_Controlled with record
132
    Tag : Character;
133
  end record;
134
  procedure Initialize( It: in out Second );
135
  procedure Finalize  ( It: in out Second );
136
 
137
end C761004_0;
138
 
139
with TCTouch;
140
with C761004_Support;
141
package body C761004_0 is
142
 
143
  package Sup renames C761004_Support;
144
 
145
  procedure Initialize( It: in out Global ) is
146
  begin
147
    Sup.Inits_Called := Sup.Inits_Called +1;
148
    It.Tag := Sup.Pick_Char;
149
    Sup.Inits_Order(Sup.Inits_Called) := It.Tag;
150
  end Initialize;
151
 
152
  procedure Finalize( It: in out Global ) is
153
  begin
154
    TCTouch.Touch(It.Tag);  --------------------------------------------- Tag
155
  end Finalize;
156
 
157
  procedure Initialize( It: in out Second ) is
158
  begin
159
    Sup.Inits_Called := Sup.Inits_Called +1;
160
    It.Tag := Sup.Pick_Char;
161
    Sup.Inits_Order(Sup.Inits_Called) := It.Tag;
162
  end Initialize;
163
 
164
  procedure Finalize( It: in out Second ) is
165
  begin
166
    TCTouch.Touch(It.Tag);  --------------------------------------------- Tag
167
  end Finalize;
168
end C761004_0;
169
 
170
------------------------------------------------------------------- C761004
171
 
172
with Report;
173
with TCTouch;
174
with C761004_0;
175
with C761004_Support;
176
with Ada.Finalization; -- needed to be able to create extension aggregates
177
procedure C761004 is
178
 
179
  Verbose : constant Boolean := False;
180
 
181
  package Sup renames C761004_Support;
182
 
183
  -- Subtest 1, general case.  Check that several objects declared in a
184
  -- subprogram are created, and finalized in opposite order.
185
 
186
  Subtest_1_Expected_Inits : constant := 3;
187
 
188
  procedure Subtest_1 is
189
    Item_1 : C761004_0.Global;
190
    Item_2, Item_3 : C761004_0.Global;
191
 begin
192
    if Item_2.Tag = Item_3.Tag then  -- not germane to the test
193
      Report.Failed("Duplicate tag");-- but helps prevent code elimination
194
    end if;
195
  end Subtest_1;
196
 
197
  -- Subtest 2, extension of the general case.  Check that several objects
198
  -- created identically on the stack (via a recursive procedure) are
199
  -- finalized in the opposite order of their creation.
200
  Subtest_2_Expected_Inits : constant := 12;
201
  User_Exception : exception;
202
 
203
  procedure Subtest_2 is
204
 
205
    Item_1 : C761004_0.Global;
206
 
207
    -- combine recursion and exit by exception:
208
 
209
    procedure Nested(Recurs: Natural) is
210
      Item_3 : C761004_0.Global;
211
    begin
212
      if Verbose then
213
        Report.Comment("going in: " & Item_3.Tag);
214
      end if;
215
      if Recurs = 1 then
216
        raise User_Exception;
217
      else
218
        Nested(Recurs -1);
219
      end if;
220
    end Nested;
221
 
222
    Item_2 : C761004_0.Global;
223
 
224
  begin
225
    Nested(10);
226
  end Subtest_2;
227
 
228
  -- subtest 3, check the case of objects embedded in structures:
229
  -- an array
230
  -- a record
231
  Subtest_3_Expected_Inits : constant := 3;
232
  procedure Subtest_3 is
233
    type G_List is array(Positive range <>) of C761004_0.Global;
234
    type Pandoras_Box is record
235
      G : G_List(1..1);
236
    end record;
237
 
238
    procedure Nested(Recursions: Natural) is
239
      Merlin : Pandoras_Box;
240
    begin
241
      if Recursions > 1 then
242
        Nested(Recursions-1);
243
      else
244
        TCTouch.Validate("","Final Nested call");
245
      end if;
246
    end Nested;
247
 
248
  begin
249
    Nested(3);
250
  end Subtest_3;
251
 
252
  -- subtest 4, check the case of objects embedded in structures:
253
  -- an array
254
  -- a record
255
  Subtest_4_Expected_Inits : constant := 3;
256
  procedure Subtest_4 is
257
    type S_List is array(Positive range <>) of C761004_0.Second;
258
    type Pandoras_Box is record
259
      S : S_List(1..1);
260
    end record;
261
 
262
    procedure Nested(Recursions: Natural) is
263
      Merlin : Pandoras_Box;
264
    begin
265
      if Recursions > 1 then
266
        Nested(Recursions-1);
267
      else
268
        TCTouch.Validate("","Final Nested call");
269
      end if;
270
    end Nested;
271
 
272
  begin
273
    Nested(3);
274
  end Subtest_4;
275
 
276
begin  -- Main test procedure.
277
 
278
  Report.Test ("C761004", "Check that an object of a controlled type "
279
                        & "is finalized when the enclosing master is "
280
                        & "complete, left by a transfer of control, "
281
                        & "and performed in the correct order" );
282
 
283
  Subtest_1;
284
  Sup.Validate(Subtest_1_Expected_Inits,1);
285
 
286
  Subtest_2_Frame: begin
287
    Sup.Inits_Called := 0;
288
    Subtest_2;
289
  exception
290
    when User_Exception => null;
291
    when others => Report.Failed("Wrong Exception, Subtest 2");
292
  end Subtest_2_Frame;
293
  Sup.Validate(Subtest_2_Expected_Inits,2);
294
 
295
  Sup.Inits_Called := 0;
296
  Subtest_3;
297
  Sup.Validate(Subtest_3_Expected_Inits,3);
298
 
299
  Sup.Inits_Called := 0;
300
  Subtest_4;
301
  Sup.Validate(Subtest_4_Expected_Inits,4);
302
 
303
  Report.Result;
304
 
305
end C761004;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.