webengine/osswebengine/JavaScriptCore/wtf/Assertions.h
changeset 0 dd21522fd290
equal deleted inserted replaced
-1:000000000000 0:dd21522fd290
       
     1 /* -*- mode: c++; c-basic-offset: 4 -*- */
       
     2 /*
       
     3  * Copyright (C) 2003, 2006, 2007 Apple Inc.  All rights reserved.
       
     4  *
       
     5  * Redistribution and use in source and binary forms, with or without
       
     6  * modification, are permitted provided that the following conditions
       
     7  * are met:
       
     8  * 1. Redistributions of source code must retain the above copyright
       
     9  *    notice, this list of conditions and the following disclaimer.
       
    10  * 2. Redistributions in binary form must reproduce the above copyright
       
    11  *    notice, this list of conditions and the following disclaimer in the
       
    12  *    documentation and/or other materials provided with the distribution.
       
    13  *
       
    14  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
       
    15  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
       
    16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
       
    17  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
       
    18  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
       
    19  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
       
    20  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
       
    21  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
       
    22  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
       
    23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
       
    24  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
       
    25  */
       
    26 
       
    27 #ifndef WTF_Assertions_h
       
    28 #define WTF_Assertions_h
       
    29 
       
    30 /*
       
    31    no namespaces because this file has to be includable from C and Objective-C
       
    32 
       
    33    Note, this file uses many GCC extensions, but it should be compatible with
       
    34    C, Objective C, C++, and Objective C++.
       
    35 
       
    36    For non-debug builds, everything is disabled by default.
       
    37    Defining any of the symbols explicitly prevents this from having any effect.
       
    38 */
       
    39 
       
    40 #include "Platform.h"
       
    41 
       
    42 #if COMPILER(MSVC)
       
    43 #include <stddef.h>
       
    44 #else
       
    45 #if !PLATFORM(SYMBIAN)
       
    46 #include <inttypes.h>
       
    47 #endif
       
    48 #endif
       
    49 
       
    50 #ifdef NDEBUG
       
    51 #define ASSERTIONS_DISABLED_DEFAULT 1
       
    52 #else
       
    53 #define ASSERTIONS_DISABLED_DEFAULT 0
       
    54 #endif
       
    55 
       
    56 #ifndef ASSERT_DISABLED
       
    57 #define ASSERT_DISABLED ASSERTIONS_DISABLED_DEFAULT
       
    58 #endif
       
    59 
       
    60 #ifndef ASSERT_ARG_DISABLED
       
    61 #define ASSERT_ARG_DISABLED ASSERTIONS_DISABLED_DEFAULT
       
    62 #endif
       
    63 
       
    64 #ifndef FATAL_DISABLED
       
    65 #define FATAL_DISABLED ASSERTIONS_DISABLED_DEFAULT
       
    66 #endif
       
    67 
       
    68 #ifndef ERROR_DISABLED
       
    69 #define ERROR_DISABLED ASSERTIONS_DISABLED_DEFAULT
       
    70 #endif
       
    71 
       
    72 #ifndef LOG_DISABLED
       
    73 #define LOG_DISABLED ASSERTIONS_DISABLED_DEFAULT
       
    74 #endif
       
    75 
       
    76 #if COMPILER(GCC)
       
    77 #define WTF_PRETTY_FUNCTION __PRETTY_FUNCTION__
       
    78 #else
       
    79 #define WTF_PRETTY_FUNCTION __FUNCTION__
       
    80 #endif
       
    81 
       
    82 /* These helper functions are always declared, but not necessarily always defined if the corresponding function is disabled. */
       
    83 
       
    84 #ifdef __cplusplus
       
    85 extern "C" {
       
    86 #endif
       
    87 
       
    88 typedef enum { WTFLogChannelOff, WTFLogChannelOn } WTFLogChannelState;
       
    89 
       
    90 typedef struct {
       
    91     unsigned mask;
       
    92     const char *defaultName;
       
    93     WTFLogChannelState state;
       
    94 } WTFLogChannel;
       
    95 
       
    96 void WTFReportAssertionFailure(const char* file, int line, const char* function, const char* assertion);
       
    97 void WTFReportAssertionFailureWithMessage(const char* file, int line, const char* function, const char* assertion, const char* format, ...);
       
    98 void WTFReportArgumentAssertionFailure(const char* file, int line, const char* function, const char* argName, const char* assertion);
       
    99 void WTFReportFatalError(const char* file, int line, const char* function, const char* format, ...) ;
       
   100 void WTFReportError(const char* file, int line, const char* function, const char* format, ...);
       
   101 void WTFLog(WTFLogChannel* channel, const char* format, ...);
       
   102 void WTFLogVerbose(const char* file, int line, const char* function, WTFLogChannel* channel, const char* format, ...);
       
   103 
       
   104 #ifdef __cplusplus
       
   105 }
       
   106 #endif
       
   107 
       
   108 /* CRASH -- gets us into the debugger or the crash reporter -- signals are ignored by the crash reporter so we must do better */
       
   109 
       
   110 #ifndef CRASH
       
   111 #define CRASH() *(int *)(uintptr_t)0xbbadbeef = 0
       
   112 #endif
       
   113 
       
   114 /* ASSERT, ASSERT_WITH_MESSAGE, ASSERT_NOT_REACHED */
       
   115 
       
   116 #if PLATFORM(WIN_OS)
       
   117 /* FIXME: Change to use something other than ASSERT to avoid this conflict with win32. */
       
   118 #undef ASSERT
       
   119 #endif
       
   120 
       
   121 #if PLATFORM(SYMBIAN)
       
   122 #undef ASSERT
       
   123 #define ASSERT(assertion) ((void)0)
       
   124 //#define ASSERT(assertion) ((void)0)
       
   125 #define ASSERT_WITH_MESSAGE(assertion, arg...) ((void)0)
       
   126 #define ASSERT_NOT_REACHED() ((void)0)
       
   127 #define FATAL(arg...) ((void)0)
       
   128 #define LOG_ERROR(arg...) ((void)0)
       
   129 #define LOG(channel, arg...) ((void)0)
       
   130 #define ASSERT_ARG(argName, assertion) ((void)0)
       
   131 #define COMPILE_ASSERT(exp, name) typedef int dummy##name [(exp) ? 1 : -1];
       
   132 
       
   133 #else
       
   134 
       
   135 #if ASSERT_DISABLED
       
   136 
       
   137 #define ASSERT(assertion) ((void)0)
       
   138 #define ASSERT_WITH_MESSAGE(assertion, ...) ((void)0)
       
   139 #define ASSERT_NOT_REACHED() ((void)0)
       
   140 
       
   141 #else
       
   142 
       
   143 #define ASSERT(assertion) do \
       
   144     if (!(assertion)) { \
       
   145         WTFReportAssertionFailure(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, #assertion); \
       
   146         CRASH(); \
       
   147     } \
       
   148 while (0)
       
   149 #define ASSERT_WITH_MESSAGE(assertion, ...) do \
       
   150     if (!(assertion)) { \
       
   151         WTFReportAssertionFailureWithMessage(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, #assertion, __VA_ARGS__); \
       
   152         CRASH(); \
       
   153     } \
       
   154 while (0)
       
   155 #define ASSERT_NOT_REACHED() do { \
       
   156     WTFReportAssertionFailure(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, 0); \
       
   157     CRASH(); \
       
   158 } while (0)
       
   159 
       
   160 #endif
       
   161 
       
   162 /* ASSERT_ARG */
       
   163 
       
   164 #if ASSERT_ARG_DISABLED
       
   165 
       
   166 #define ASSERT_ARG(argName, assertion) ((void)0)
       
   167 
       
   168 #else
       
   169 
       
   170 #define ASSERT_ARG(argName, assertion) do \
       
   171     if (!(assertion)) { \
       
   172         WTFReportArgumentAssertionFailure(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, #argName, #assertion); \
       
   173         CRASH(); \
       
   174     } \
       
   175 while (0)
       
   176 
       
   177 #endif
       
   178 
       
   179 /* COMPILE_ASSERT */
       
   180 #ifndef COMPILE_ASSERT
       
   181 #define COMPILE_ASSERT(exp, name) typedef int dummy##name [(exp) ? 1 : -1];
       
   182 #endif
       
   183 
       
   184 /* FATAL */
       
   185 
       
   186 #if FATAL_DISABLED
       
   187 #define FATAL(...) ((void)0)
       
   188 #else
       
   189 #define FATAL(...) do { \
       
   190     WTFReportFatalError(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, __VA_ARGS__); \
       
   191     CRASH(); \
       
   192 } while (0)
       
   193 #endif
       
   194 
       
   195 /* LOG_ERROR */
       
   196 
       
   197 #if ERROR_DISABLED
       
   198 #define LOG_ERROR(...) ((void)0)
       
   199 #else
       
   200 #define LOG_ERROR(...) WTFReportError(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, __VA_ARGS__)
       
   201 #endif
       
   202 
       
   203 /* LOG */
       
   204 
       
   205 #if LOG_DISABLED
       
   206 #define LOG(channel, ...) ((void)0)
       
   207 #else
       
   208 #define LOG(channel, ...) WTFLog(&JOIN_LOG_CHANNEL_WITH_PREFIX(LOG_CHANNEL_PREFIX, channel), __VA_ARGS__)
       
   209 #define JOIN_LOG_CHANNEL_WITH_PREFIX(prefix, channel) JOIN_LOG_CHANNEL_WITH_PREFIX_LEVEL_2(prefix, channel)
       
   210 #define JOIN_LOG_CHANNEL_WITH_PREFIX_LEVEL_2(prefix, channel) prefix ## channel
       
   211 #endif
       
   212 
       
   213 /* LOG_VERBOSE */
       
   214 
       
   215 #if LOG_DISABLED
       
   216 #define LOG_VERBOSE(channel, ...) ((void)0)
       
   217 #else
       
   218 #define LOG_VERBOSE(channel, ...) WTFLogVerbose(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, &JOIN_LOG_CHANNEL_WITH_PREFIX(LOG_CHANNEL_PREFIX, channel), __VA_ARGS__)
       
   219 #endif
       
   220 #endif
       
   221 
       
   222 #endif // WTF_Assertions_h