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 |
|
|
-- S p e c --
|
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_Root;
|
33 |
|
|
|
34 |
|
|
package Ada.Finalization.List_Controller is
|
35 |
|
|
pragma Elaborate_Body;
|
36 |
|
|
|
37 |
|
|
package SFR renames System.Finalization_Root;
|
38 |
|
|
|
39 |
|
|
----------------------------
|
40 |
|
|
-- Simple_List_Controller --
|
41 |
|
|
----------------------------
|
42 |
|
|
|
43 |
|
|
type Simple_List_Controller is new Ada.Finalization.Limited_Controlled
|
44 |
|
|
with record
|
45 |
|
|
F : SFR.Finalizable_Ptr;
|
46 |
|
|
end record;
|
47 |
|
|
-- Used by the compiler to carry a list of temporary objects that
|
48 |
|
|
-- needs to be finalized after having being used. This list is
|
49 |
|
|
-- embedded in a controlled type so that if an exception is raised
|
50 |
|
|
-- while those temporaries are still in use, they will be reclaimed
|
51 |
|
|
-- by the normal finalization mechanism.
|
52 |
|
|
|
53 |
|
|
overriding procedure Finalize (Object : in out Simple_List_Controller);
|
54 |
|
|
|
55 |
|
|
---------------------
|
56 |
|
|
-- List_Controller --
|
57 |
|
|
---------------------
|
58 |
|
|
|
59 |
|
|
-- Management of a bidirectional linked heterogeneous list of
|
60 |
|
|
-- dynamically Allocated objects. To simplify the management of the
|
61 |
|
|
-- linked list, the First and Last elements are statically part of the
|
62 |
|
|
-- original List controller:
|
63 |
|
|
--
|
64 |
|
|
-- +------------+
|
65 |
|
|
-- | --|-->--
|
66 |
|
|
-- +------------+
|
67 |
|
|
-- |--<-- | record with ctrl components
|
68 |
|
|
-- |------------| +----------+
|
69 |
|
|
-- +--|-- L | | |
|
70 |
|
|
-- | |------------| | |
|
71 |
|
|
-- | |+--------+ | +--------+ |+--------+|
|
72 |
|
|
-- +->|| prev | F|---<---|-- |----<---||-- ||--<--+
|
73 |
|
|
-- ||--------| i| |--------| ||--------|| |
|
74 |
|
|
-- || next | r|--->---| --|---->---|| --||--------+
|
75 |
|
|
-- |+--------+ s| |--------| ||--------|| | |
|
76 |
|
|
-- | t| | ctrl | || || | |
|
77 |
|
|
-- | | : : |+--------+| | |
|
78 |
|
|
-- | | : object : |rec | | |
|
79 |
|
|
-- | | : : |controller| | |
|
80 |
|
|
-- | | | | | | | v
|
81 |
|
|
-- |+--------+ | +--------+ +----------+ | |
|
82 |
|
|
-- || prev -|-L|--------------------->--------------------+ |
|
83 |
|
|
-- ||--------| a| |
|
84 |
|
|
-- || next | s|-------------------<-------------------------+
|
85 |
|
|
-- |+--------+ t|
|
86 |
|
|
-- | |
|
87 |
|
|
-- +------------+
|
88 |
|
|
|
89 |
|
|
type List_Controller is new Ada.Finalization.Limited_Controlled
|
90 |
|
|
with record
|
91 |
|
|
F : SFR.Finalizable_Ptr;
|
92 |
|
|
First,
|
93 |
|
|
Last : aliased SFR.Root_Controlled;
|
94 |
|
|
end record;
|
95 |
|
|
-- Controls the chains of dynamically allocated controlled
|
96 |
|
|
-- objects makes sure that they get finalized upon exit from
|
97 |
|
|
-- the access type that defined them
|
98 |
|
|
|
99 |
|
|
overriding procedure Initialize (Object : in out List_Controller);
|
100 |
|
|
overriding procedure Finalize (Object : in out List_Controller);
|
101 |
|
|
|
102 |
|
|
end Ada.Finalization.List_Controller;
|