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-vmexta.adb < prev    next >
Text File  |  2000-07-19  |  6KB  |  165 lines

  1. ------------------------------------------------------------------------------
  2. --                                                                          --
  3. --                         GNAT COMPILER COMPONENTS                         --
  4. --                                                                          --
  5. --           S Y S T E M . V M S _ E X C E P T I O N _ T A B L E            --
  6. --                                                                          --
  7. --                                 B o d y                                  --
  8. --                                                                          --
  9. --                            $Revision: 1.5 $                              --
  10. --                                                                          --
  11. --          Copyright (C) 1997-1998, 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. --  This is an Alpha/VMS package.
  37.  
  38. with GNAT.HTable;
  39. pragma Elaborate_All (GNAT.HTable);
  40.  
  41. package body System.VMS_Exception_Table is
  42.  
  43.    use System.Standard_Library;
  44.  
  45.    type HTable_Headers is range 1 .. 37;
  46.  
  47.    type Exception_Code_Data;
  48.    type Exception_Code_Data_Ptr is access all Exception_Code_Data;
  49.  
  50.    --  The following record maps an imported VMS condition to an
  51.    --  Ada exception.
  52.  
  53.    type Exception_Code_Data is record
  54.       Code       : Natural;
  55.       Except     : Exception_Data_Ptr;
  56.       HTable_Ptr : Exception_Code_Data_Ptr;
  57.    end record;
  58.  
  59.    procedure Set_HT_Link
  60.      (T    : Exception_Code_Data_Ptr;
  61.       Next : Exception_Code_Data_Ptr);
  62.  
  63.    function Get_HT_Link (T : Exception_Code_Data_Ptr)
  64.      return Exception_Code_Data_Ptr;
  65.  
  66.    function Hash (F : Natural) return HTable_Headers;
  67.    function Get_Key (T : Exception_Code_Data_Ptr) return Natural;
  68.  
  69.    package Exception_Code_HTable is new GNAT.HTable.Static_HTable (
  70.      Header_Num => HTable_Headers,
  71.      Element    => Exception_Code_Data,
  72.      Elmt_Ptr   => Exception_Code_Data_Ptr,
  73.      Null_Ptr   => null,
  74.      Set_Next   => Set_HT_Link,
  75.      Next       => Get_HT_Link,
  76.      Key        => Natural,
  77.      Get_Key    => Get_Key,
  78.      Hash       => Hash,
  79.      Equal      => "=");
  80.  
  81.    ----------------------------
  82.    -- Register_VMS_Exception --
  83.    ----------------------------
  84.  
  85.    procedure Register_VMS_Exception (Code : Integer) is
  86.       --  Mask off lower 3 bits which are the severity
  87.  
  88.       Excode : Integer := (Code / 8) * 8;
  89.    begin
  90.  
  91.       --  This allocates an empty exception that gets filled in by
  92.       --  __gnat_error_handler when the exception is raised. Allocating
  93.       --  it here prevents having to allocate it each time the exception
  94.       --  is raised.
  95.  
  96.       if Exception_Code_HTable.Get (Excode) = null then
  97.          Exception_Code_HTable.Set
  98.            (new Exception_Code_Data'
  99.              (Excode,
  100.               new Exception_Data'(False, "VMS", 0, null, null, 0),
  101.               null));
  102.       end if;
  103.    end Register_VMS_Exception;
  104.  
  105.    -----------------
  106.    -- Set_HT_Link --
  107.    -----------------
  108.  
  109.    procedure Set_HT_Link
  110.      (T    : Exception_Code_Data_Ptr;
  111.       Next : Exception_Code_Data_Ptr)
  112.    is
  113.    begin
  114.       T.HTable_Ptr := Next;
  115.    end Set_HT_Link;
  116.  
  117.    -----------------
  118.    -- Get_HT_Link --
  119.    -----------------
  120.  
  121.    function  Get_HT_Link (T : Exception_Code_Data_Ptr)
  122.      return Exception_Code_Data_Ptr is
  123.    begin
  124.       return T.HTable_Ptr;
  125.    end Get_HT_Link;
  126.  
  127.    ----------
  128.    -- Hash --
  129.    ----------
  130.  
  131.    function Hash (F : Natural) return HTable_Headers is
  132.    begin
  133.       return HTable_Headers
  134.         (F mod Natural (HTable_Headers'Last - HTable_Headers'First + 1) + 1);
  135.    end Hash;
  136.  
  137.    -------------
  138.    -- Get_Key --
  139.    -------------
  140.  
  141.    function Get_Key (T : Exception_Code_Data_Ptr) return Natural is
  142.    begin
  143.       return T.Code;
  144.    end Get_Key;
  145.  
  146.    ---------------------
  147.    -- Coded_Exception --
  148.    ---------------------
  149.  
  150.    function Coded_Exception (X : Natural) return Exception_Data_Ptr is
  151.       Res : Exception_Code_Data_Ptr;
  152.  
  153.    begin
  154.       Res := Exception_Code_HTable.Get (X);
  155.  
  156.       if Res /= null  then
  157.          return Res.Except;
  158.       else
  159.          return null;
  160.       end if;
  161.  
  162.    end Coded_Exception;
  163.  
  164. end System.VMS_Exception_Table;
  165.