1 |
281 |
jeremybenn |
------------------------------------------------------------------------------
|
2 |
|
|
-- --
|
3 |
|
|
-- GNAT COMPILER COMPONENTS --
|
4 |
|
|
-- --
|
5 |
|
|
-- A D A . F I N A L I Z A T I O N . L I S T _ C O N T R O L L E R --
|
6 |
|
|
-- --
|
7 |
|
|
-- B o d y --
|
8 |
|
|
-- --
|
9 |
|
|
-- Copyright (C) 1992-2009, Free Software Foundation, Inc. --
|
10 |
|
|
-- --
|
11 |
|
|
-- GNAT is free software; you can redistribute it and/or modify it under --
|
12 |
|
|
-- terms of the GNU General Public License as published by the Free Soft- --
|
13 |
|
|
-- ware Foundation; either version 3, or (at your option) any later ver- --
|
14 |
|
|
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
|
15 |
|
|
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
|
16 |
|
|
-- or FITNESS FOR A PARTICULAR PURPOSE. --
|
17 |
|
|
-- --
|
18 |
|
|
-- As a special exception under Section 7 of GPL version 3, you are granted --
|
19 |
|
|
-- additional permissions described in the GCC Runtime Library Exception, --
|
20 |
|
|
-- version 3.1, as published by the Free Software Foundation. --
|
21 |
|
|
-- --
|
22 |
|
|
-- You should have received a copy of the GNU General Public License and --
|
23 |
|
|
-- a copy of the GCC Runtime Library Exception along with this program; --
|
24 |
|
|
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
|
25 |
|
|
-- <http://www.gnu.org/licenses/>. --
|
26 |
|
|
-- --
|
27 |
|
|
-- GNAT was originally developed by the GNAT team at New York University. --
|
28 |
|
|
-- Extensive contributions were provided by Ada Core Technologies Inc. --
|
29 |
|
|
-- --
|
30 |
|
|
------------------------------------------------------------------------------
|
31 |
|
|
|
32 |
|
|
with System.Finalization_Implementation;
|
33 |
|
|
package body Ada.Finalization.List_Controller is
|
34 |
|
|
|
35 |
|
|
package SFI renames System.Finalization_Implementation;
|
36 |
|
|
|
37 |
|
|
--------------
|
38 |
|
|
-- Finalize --
|
39 |
|
|
--------------
|
40 |
|
|
|
41 |
|
|
procedure Finalize (Object : in out List_Controller) is
|
42 |
|
|
use type SFR.Finalizable_Ptr;
|
43 |
|
|
|
44 |
|
|
Last_Ptr : constant SFR.Finalizable_Ptr := Object.Last'Unchecked_Access;
|
45 |
|
|
|
46 |
|
|
begin
|
47 |
|
|
-- First take note of the fact that finalization of this collection has
|
48 |
|
|
-- started.
|
49 |
|
|
|
50 |
|
|
Object.F := SFI.Collection_Finalization_Started;
|
51 |
|
|
|
52 |
|
|
-- Then finalize all the objects. Note that finalization can call
|
53 |
|
|
-- Unchecked_Deallocation on other objects in the same collection,
|
54 |
|
|
-- which will cause them to be removed from the list if we have not
|
55 |
|
|
-- gotten to them yet. However, allocation in the collection will raise
|
56 |
|
|
-- Program_Error, due to the above Collection_Finalization_Started.
|
57 |
|
|
|
58 |
|
|
while Object.First.Next /= Last_Ptr loop
|
59 |
|
|
SFI.Finalize_One (Object.First.Next.all);
|
60 |
|
|
end loop;
|
61 |
|
|
end Finalize;
|
62 |
|
|
|
63 |
|
|
procedure Finalize (Object : in out Simple_List_Controller) is
|
64 |
|
|
begin
|
65 |
|
|
SFI.Finalize_List (Object.F);
|
66 |
|
|
Object.F := null;
|
67 |
|
|
end Finalize;
|
68 |
|
|
|
69 |
|
|
----------------
|
70 |
|
|
-- Initialize --
|
71 |
|
|
----------------
|
72 |
|
|
|
73 |
|
|
procedure Initialize (Object : in out List_Controller) is
|
74 |
|
|
begin
|
75 |
|
|
Object.F := Object.First'Unchecked_Access;
|
76 |
|
|
Object.First.Next := Object.Last 'Unchecked_Access;
|
77 |
|
|
Object.Last.Prev := Object.First'Unchecked_Access;
|
78 |
|
|
end Initialize;
|
79 |
|
|
|
80 |
|
|
end Ada.Finalization.List_Controller;
|