home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / adav313.zip / gnat-3_13p-os2-bin-20010916.zip / emx / gnatlib / s-exctab.adb < prev    next >
Text File  |  2000-07-19  |  7KB  |  193 lines

  1. ------------------------------------------------------------------------------
  2. --                                                                          --
  3. --                         GNAT COMPILER COMPONENTS                         --
  4. --                                                                          --
  5. --               S Y S T E M . E X C E P T I O N _ T A B L E                --
  6. --                                                                          --
  7. --                                 B o d y                                  --
  8. --                                                                          --
  9. --                            $Revision: 1.12 $
  10. --                                                                          --
  11. --          Copyright (C) 1996-2000 Free Software Foundation, Inc.          --
  12. --                                                                          --
  13. -- GNAT is free software;  you can  redistribute it  and/or modify it under --
  14. -- terms of the  GNU General Public License as published  by the Free Soft- --
  15. -- ware  Foundation;  either version 2,  or (at your option) any later ver- --
  16. -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
  17. -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
  18. -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
  19. -- for  more details.  You should have  received  a copy of the GNU General --
  20. -- Public License  distributed with GNAT;  see file COPYING.  If not, write --
  21. -- to  the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, --
  22. -- MA 02111-1307, USA.                                                      --
  23. --                                                                          --
  24. -- As a special exception,  if other files  instantiate  generics from this --
  25. -- unit, or you link  this unit with other files  to produce an executable, --
  26. -- this  unit  does not  by itself cause  the resulting  executable  to  be --
  27. -- covered  by the  GNU  General  Public  License.  This exception does not --
  28. -- however invalidate  any other reasons why  the executable file  might be --
  29. -- covered by the  GNU Public License.                                      --
  30. --                                                                          --
  31. -- GNAT was originally developed  by the GNAT team at  New York University. --
  32. -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
  33. --                                                                          --
  34. ------------------------------------------------------------------------------
  35.  
  36. with GNAT.HTable;
  37.  
  38. package body System.Exception_Table is
  39.  
  40.    use System.Standard_Library;
  41.  
  42.    type HTable_Headers is range 1 .. 37;
  43.  
  44.    procedure Set_HT_Link (T : Exception_Data_Ptr; Next : Exception_Data_Ptr);
  45.    function  Get_HT_Link (T : Exception_Data_Ptr) return Exception_Data_Ptr;
  46.  
  47.    function Hash (F : Big_String_Ptr) return HTable_Headers;
  48.    function Equal (A, B : Big_String_Ptr) return Boolean;
  49.    function Get_Key (T : Exception_Data_Ptr) return Big_String_Ptr;
  50.  
  51.    package Exception_HTable is new GNAT.HTable.Static_HTable (
  52.      Header_Num => HTable_Headers,
  53.      Element    => Exception_Data,
  54.      Elmt_Ptr   => Exception_Data_Ptr,
  55.      Null_Ptr   => null,
  56.      Set_Next   => Set_HT_Link,
  57.      Next       => Get_HT_Link,
  58.      Key        => Big_String_Ptr,
  59.      Get_Key    => Get_Key,
  60.      Hash       => Hash,
  61.      Equal      => Equal);
  62.  
  63.    -----------------
  64.    -- Set_HT_Link --
  65.    -----------------
  66.  
  67.    procedure Set_HT_Link
  68.      (T    : Exception_Data_Ptr;
  69.       Next : Exception_Data_Ptr)
  70.    is
  71.    begin
  72.       T.HTable_Ptr := Next;
  73.    end Set_HT_Link;
  74.  
  75.    -----------------
  76.    -- Get_HT_Link --
  77.    -----------------
  78.  
  79.    function  Get_HT_Link (T : Exception_Data_Ptr) return Exception_Data_Ptr is
  80.    begin
  81.       return T.HTable_Ptr;
  82.    end Get_HT_Link;
  83.  
  84.    ----------
  85.    -- Hash --
  86.    ----------
  87.  
  88.    function Hash (F : Big_String_Ptr) return HTable_Headers is
  89.       type S is mod 2**8;
  90.  
  91.       Size : constant S := S (HTable_Headers'Last - HTable_Headers'First + 1);
  92.       Tmp  : S := 0;
  93.       J    : Positive;
  94.  
  95.    begin
  96.       J := 1;
  97.       loop
  98.          if F (J) = ASCII.NUL then
  99.             return HTable_Headers'First + HTable_Headers'Base (Tmp mod Size);
  100.          else
  101.             Tmp := Tmp xor S (Character'Pos (F (J)));
  102.          end if;
  103.          J := J + 1;
  104.       end loop;
  105.    end Hash;
  106.  
  107.    -----------
  108.    -- Equal --
  109.    -----------
  110.  
  111.    function Equal (A, B : Big_String_Ptr) return Boolean is
  112.       J    : Integer := 1;
  113.  
  114.    begin
  115.       loop
  116.          if A (J) /= B (J) then
  117.             return False;
  118.  
  119.          elsif A (J) = ASCII.NUL then
  120.             return True;
  121.  
  122.          else
  123.             J := J + 1;
  124.          end if;
  125.       end loop;
  126.    end Equal;
  127.  
  128.    -------------
  129.    -- Get_Key --
  130.    -------------
  131.  
  132.    function Get_Key (T : Exception_Data_Ptr) return Big_String_Ptr is
  133.    begin
  134.       return T.Full_Name;
  135.    end Get_Key;
  136.  
  137.    type String_Ptr is access all String;
  138.  
  139.    ------------------------
  140.    -- Internal_Exception --
  141.    ------------------------
  142.  
  143.    function Internal_Exception (X : String) return Exception_Data_Ptr is
  144.       Copy     : aliased String (X'First .. X'Last + 1);
  145.       Res      : Exception_Data_Ptr;
  146.       Dyn_Copy : String_Ptr;
  147.  
  148.    begin
  149.       Copy (X'Range) := X;
  150.       Copy (Copy'Last) := ASCII.NUL;
  151.       Res := Exception_HTable.Get (To_Ptr (Copy'Address));
  152.  
  153.       --  If unknown exception, create it on the heap. This is a legitimate
  154.       --  situation in the distributed case when an exception is defined only
  155.       --  in a partition
  156.  
  157.       if Res = null  then
  158.          Dyn_Copy := new String'(Copy);
  159.  
  160.          Res :=
  161.            new Exception_Data'
  162.              (Not_Handled_By_Others => False,
  163.               Lang                  => "Ada",
  164.               Name_Length           => Copy'Length,
  165.               Full_Name             => To_Ptr (Dyn_Copy.all'Address),
  166.               HTable_Ptr            => null,
  167.               Import_Code           => 0);
  168.  
  169.          Register_Exception (Res);
  170.       end if;
  171.  
  172.       return Res;
  173.    end Internal_Exception;
  174.  
  175.    ------------------------
  176.    -- Register_Exception --
  177.    ------------------------
  178.  
  179.    procedure Register_Exception (X : Exception_Data_Ptr) is
  180.    begin
  181.       Exception_HTable.Set (X);
  182.    end Register_Exception;
  183.  
  184. begin
  185.    Register_Exception (Abort_Signal_Def'Access);
  186.    Register_Exception (Tasking_Error_Def'Access);
  187.    Register_Exception (Storage_Error_Def'Access);
  188.    Register_Exception (Program_Error_Def'Access);
  189.    Register_Exception (Numeric_Error_Def'Access);
  190.    Register_Exception (Constraint_Error_Def'Access);
  191.  
  192. end System.Exception_Table;
  193.