home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / lang / ada / gnat-3.05- / gnat-3 / gnat-3.05-i486-linux-elf-bin / rts / s-assert.adb < prev    next >
Encoding:
Text File  |  1996-06-07  |  4.5 KB  |  87 lines

  1. ------------------------------------------------------------------------------
  2. --                                                                          --
  3. --                          GNAT RUNTIME COMPONENTS                         --
  4. --                                                                          --
  5. --                     S Y S T E M . A S S E R T I O N S                    --
  6. --                                                                          --
  7. --                                 B o d y                                  --
  8. --                                                                          --
  9. --                            $Revision: 1.5 $                              --
  10. --                                                                          --
  11. --   Copyright (C) 1992,1993,1994,1995,1996 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. --  Note: it would be much simpler to use Ada.Exceptions.Raise_Exception,
  37. --  but that would drag in a lot of the runtime, and especially in the
  38. --  compiler itself, which uses assertions, we do not want these extra
  39. --  units included indirectly as a result of using assertions. The result
  40. --  is that we duplicate subtantial chunks of Ada.Exceptions in this unit.
  41.  
  42. with System;
  43. with System.Task_Specific_Data; use System.Task_Specific_Data;
  44. with System.Standard_Library;
  45. with Unchecked_Conversion;
  46.  
  47. package body System.Assertions is
  48.  
  49.    type Buffer_Ptr is access System.Standard_Library.Exception_Message_Buffer;
  50.    --  A thin pointer to String
  51.  
  52.    function To_Buffer_Ptr is
  53.      new Unchecked_Conversion (System.Address, Buffer_Ptr);
  54.    --  Conversion from address to string access for exception msg manipulation
  55.  
  56.    --------------------------
  57.    -- Raise_Assert_Failure --
  58.    --------------------------
  59.  
  60.    procedure Raise_Assert_Failure (Msg : String) is
  61.    begin
  62.       --  Set message in place with negative length. There is a special
  63.       --  arrangement with regard to negative lengths. When a negative
  64.       --  length is set, then the next call to set the length to zero
  65.       --  (which will happen when the exception is raised using the
  66.       --  normal assert statement), results in negating the length so
  67.       --  it now has the proper positive value.
  68.  
  69.       Set_Message_Length (-Msg'Length);
  70.       To_Buffer_Ptr (Get_Message_Addr).all (1 .. Msg'Length) := Msg;
  71.  
  72.       --  The following is for back compatibility with the bootstrap
  73.       --  path, and can be removed later on.
  74.  
  75.       Assert_Msg (1 .. Msg'Length) := Msg;
  76.       Assert_Msg_Length := Msg'Length;
  77.  
  78.       --  Now raise the actual exception. This looks like a raise with no
  79.       --  message, but because of the special handling for negative lengths
  80.       --  as set above, this acts as a raise with message.
  81.  
  82.       raise Assert_Failure;
  83.  
  84.    end Raise_Assert_Failure;
  85.  
  86. end System.Assertions;
  87.