home *** CD-ROM | disk | FTP | other *** search
/ Mega Top 1 / os2_top1.zip / os2_top1 / APPS / TEKST / FUNNEL_S / SOURCES / AS.H < prev    next >
C/C++ Source or Header  |  1992-05-27  |  6KB  |  120 lines

  1. /*##############################################################################
  2.  
  3. FUNNNELWEB COPYRIGHT
  4. ====================
  5. FunnelWeb is a literate-programming macro preprocessor.
  6.  
  7. Copyright (C) 1992 Ross N. Williams.
  8.  
  9.    Ross N. Williams
  10.    ross@spam.adelaide.edu.au
  11.    16 Lerwick Avenue, Hazelwood Park 5066, Australia.
  12.  
  13. This program is free software; you can redistribute it and/or modify
  14. it under the terms of Version 2 of the GNU General Public License as
  15. published by the Free Software Foundation.
  16.  
  17. This program is distributed WITHOUT ANY WARRANTY; without even the implied
  18. warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  19. See Version 2 of the GNU General Public License for more details.
  20.  
  21. You should have received a copy of Version 2 of the GNU General Public
  22. License along with this program. If not, you can FTP the license from
  23. prep.ai.mit.edu/pub/gnu/COPYING-2 or write to the Free Software
  24. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  25.  
  26. Section 2a of the license requires that all changes to this file be
  27. recorded prominently in this file. Please record all changes here.
  28.  
  29. Programmers:
  30.    RNW  Ross N. Williams  ross@spam.adelaide.edu.au
  31.  
  32. Changes:
  33.    07-May-1992  RNW  Program prepared for release under GNU GPL V2.
  34.  
  35. ##############################################################################*/
  36.  
  37.  
  38. /******************************************************************************/
  39. /*                                      AS.H                                  */
  40. /******************************************************************************/
  41. /*                                                                            */
  42. /* ASSERTION PACKAGE                                                          */
  43. /* =================                                                          */
  44. /* This package contains macros and functions that support assertions. An     */
  45. /* assertion is a boolean condition that is supposed always to be true at a   */
  46. /* particular point during program execution. An assertion statement tests    */
  47. /* such a condition and bombs the program if it is false; better to be        */
  48. /* alerted to such a condition rather than suffer and erroneous execution.    */
  49. /*                                                                            */
  50. /* Standard C supports asertions with the <assert.h> header file providing    */
  51. /* the "assert" macro. Unfortunately, this does not meet the needs of         */
  52. /* FunnelWeb for two reasons:                                                 */
  53. /*                                                                            */
  54. /* 1) Portability is emphasised in FunnelWeb and the assert macro is fairly   */
  55. /*    recent. Its only argument is the boolean condition, which means that    */
  56. /*    without the ANSI macros __FILE__ and __LINE__, the macro would be       */
  57. /*    unable to indicate where an assertion failure occurred, in a non-ANSI   */
  58. /*    environment.                                                            */
  59. /*                                                                            */
  60. /* 2) There is only one assert macro and it can be either on or off, the      */
  61. /*    implication being that in production code, it should be turned off. In  */
  62. /*    contrast, the execution speed of the assert macro will usually matter   */
  63. /*    only in a small portion of the code as, in most programs, a small       */
  64. /*    portion of the code accounts for most of the execution time. By having  */
  65. /*    two categories of assertion, we can leave most of the assertions turned */
  66. /*    on in the production program.                                           */
  67. /*                                                                            */
  68. /* This reasoning leads to the slightly different assertion facilty provided  */
  69. /* by this package. Here, there are two assertion routines/macros, HOT        */
  70. /* assertions for HOT code (code in a program hot spot) and COLD assertions   */
  71. /* for COLD code (not in a hot spot). Only the HOT assertions can be turned   */
  72. /* off.                                                                       */
  73. /*                                                                            */
  74. /******************************************************************************/
  75.  
  76. /* Ensure that the body of this header file is included at most once.         */
  77. #ifndef DONE_AS
  78. #define DONE_AS
  79.  
  80. /******************************************************************************/
  81.  
  82. #include "style.h"
  83.  
  84. /******************************************************************************/
  85.  
  86. /* The following #define determines whether hot assertions are to be turned   */
  87. /* on or off. Set to 0 for OFF and 1 for ON.                                  */
  88. /* Note: I have left hot assertions on in the production version as FunnelWeb */
  89. /*       doesn't go slowly enough to make me want to turn it off.             */
  90. #define AS_DOHOT 1
  91.  
  92. /******************************************************************************/
  93.  
  94. EXPORT void as_bomb P_((char *));
  95. /* This function writes out its argument string and then bombs the program.   */
  96. /* It should be called at any point where it has been determined that an      */
  97. /* illegal condition has been detected. The other assertion routines/macros   */
  98. /* call this function.                                                        */
  99.  
  100. /* The following two macros define hot and cold assertions. Be sure never to  */
  101. /* call them with arguments with side effects!                                */
  102. #define as_cold(e,s) {if (!(e)) as_bomb(s);}
  103.  
  104. #if AS_DOHOT
  105. #define as_hot(e,s)    {if (!(e)) as_bomb(s);}
  106. #define AS_HCODE(CODE) {CODE}
  107. #else
  108. #define as_hot(e,s)    ((void) 0)
  109. #define AS_HCODE(CODE) ((void) 0)
  110. #endif
  111.  
  112. /******************************************************************************/
  113.  
  114. /* For #ifndef preventing multiple inclusion of the body of this header file. */
  115. #endif
  116.  
  117. /******************************************************************************/
  118. /*                                     AS.H                                   */
  119. /******************************************************************************/
  120.