1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
5 -- S Y S T E M . E X C E P T I O N _ T A B L E --
9 -- Copyright (C) 1996-2003 Free Software Foundation, Inc. --
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 2, 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. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
22 -- As a special exception, if other files instantiate generics from this --
23 -- unit, or you link this unit with other files to produce an executable, --
24 -- this unit does not by itself cause the resulting executable to be --
25 -- covered by the GNU General Public License. This exception does not --
26 -- however invalidate any other reasons why the executable file might be --
27 -- covered by the GNU Public License. --
29 -- GNAT was originally developed by the GNAT team at New York University. --
30 -- Extensive contributions were provided by Ada Core Technologies Inc. --
32 ------------------------------------------------------------------------------
35 with System
.Soft_Links
; use System
.Soft_Links
;
37 package body System
.Exception_Table
is
39 use System
.Standard_Library
;
41 type HTable_Headers
is range 1 .. 37;
43 procedure Set_HT_Link
(T
: Exception_Data_Ptr
; Next
: Exception_Data_Ptr
);
44 function Get_HT_Link
(T
: Exception_Data_Ptr
) return Exception_Data_Ptr
;
46 function Hash
(F
: Big_String_Ptr
) return HTable_Headers
;
47 function Equal
(A
, B
: Big_String_Ptr
) return Boolean;
48 function Get_Key
(T
: Exception_Data_Ptr
) return Big_String_Ptr
;
50 package Exception_HTable
is new System
.HTable
.Static_HTable
(
51 Header_Num
=> HTable_Headers
,
52 Element
=> Exception_Data
,
53 Elmt_Ptr
=> Exception_Data_Ptr
,
55 Set_Next
=> Set_HT_Link
,
57 Key
=> Big_String_Ptr
,
66 function Equal
(A
, B
: Big_String_Ptr
) return Boolean is
71 if A
(J
) /= B
(J
) then
74 elsif A
(J
) = ASCII
.NUL
then
87 function Get_HT_Link
(T
: Exception_Data_Ptr
) return Exception_Data_Ptr
is
96 function Get_Key
(T
: Exception_Data_Ptr
) return Big_String_Ptr
is
101 -------------------------------
102 -- Get_Registered_Exceptions --
103 -------------------------------
105 procedure Get_Registered_Exceptions
106 (List
: out Exception_Data_Array
;
109 Data
: Exception_Data_Ptr
:= Exception_HTable
.Get_First
;
113 Last
:= List
'First - 1;
115 while Last
< List
'Last and then Data
/= null loop
118 Data
:= Exception_HTable
.Get_Next
;
122 end Get_Registered_Exceptions
;
128 function Hash
(F
: Big_String_Ptr
) return HTable_Headers
is
131 Size
: constant S
:= S
(HTable_Headers
'Last - HTable_Headers
'First + 1);
138 if F
(J
) = ASCII
.NUL
then
139 return HTable_Headers
'First + HTable_Headers
'Base (Tmp
mod Size
);
141 Tmp
:= Tmp
xor S
(Character'Pos (F
(J
)));
147 ------------------------
148 -- Internal_Exception --
149 ------------------------
151 function Internal_Exception
153 Create_If_Not_Exist
: Boolean := True) return Exception_Data_Ptr
155 type String_Ptr
is access all String;
157 Copy
: aliased String (X
'First .. X
'Last + 1);
158 Res
: Exception_Data_Ptr
;
159 Dyn_Copy
: String_Ptr
;
163 Copy
(Copy
'Last) := ASCII
.NUL
;
164 Res
:= Exception_HTable
.Get
(To_Ptr
(Copy
'Address));
166 -- If unknown exception, create it on the heap. This is a legitimate
167 -- situation in the distributed case when an exception is defined only
170 if Res
= null and then Create_If_Not_Exist
then
171 Dyn_Copy
:= new String'(Copy);
175 (Not_Handled_By_Others
=> False,
177 Name_Length
=> Copy
'Length,
178 Full_Name
=> To_Ptr
(Dyn_Copy
.all'Address),
183 Register_Exception
(Res
);
187 end Internal_Exception
;
189 ------------------------
190 -- Register_Exception --
191 ------------------------
193 procedure Register_Exception
(X
: Exception_Data_Ptr
) is
195 Exception_HTable
.Set
(X
);
196 end Register_Exception
;
198 ---------------------------------
199 -- Registered_Exceptions_Count --
200 ---------------------------------
202 function Registered_Exceptions_Count
return Natural is
203 Count
: Natural := 0;
204 Data
: Exception_Data_Ptr
:= Exception_HTable
.Get_First
;
207 -- We need to lock the runtime in the meantime, to avoid concurrent
208 -- access since we have only one iterator.
212 while Data
/= null loop
214 Data
:= Exception_HTable
.Get_Next
;
219 end Registered_Exceptions_Count
;
225 procedure Set_HT_Link
226 (T
: Exception_Data_Ptr
;
227 Next
: Exception_Data_Ptr
)
230 T
.HTable_Ptr
:= Next
;
233 -- Register the standard exceptions at elaboration time
236 Register_Exception
(Abort_Signal_Def
'Access);
237 Register_Exception
(Tasking_Error_Def
'Access);
238 Register_Exception
(Storage_Error_Def
'Access);
239 Register_Exception
(Program_Error_Def
'Access);
240 Register_Exception
(Numeric_Error_Def
'Access);
241 Register_Exception
(Constraint_Error_Def
'Access);
243 end System
.Exception_Table
;