1 : // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 : // Redistribution and use in source and binary forms, with or without
3 : // modification, are permitted provided that the following conditions are
4 : // met:
5 : //
6 : // * Redistributions of source code must retain the above copyright
7 : // notice, this list of conditions and the following disclaimer.
8 : // * Redistributions in binary form must reproduce the above
9 : // copyright notice, this list of conditions and the following
10 : // disclaimer in the documentation and/or other materials provided
11 : // with the distribution.
12 : // * Neither the name of Google Inc. nor the names of its
13 : // contributors may be used to endorse or promote products derived
14 : // from this software without specific prior written permission.
15 : //
16 : // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 : // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 : // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 : // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 : // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 : // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 : // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 : // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 : // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 : // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 : // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 :
28 : #ifndef V8_CHECKS_H_
29 : #define V8_CHECKS_H_
30 :
31 : #include <string.h>
32 :
33 : extern "C" void V8_Fatal(const char* file, int line, const char* format, ...);
34 :
35 : // The FATAL, UNREACHABLE and UNIMPLEMENTED macros are useful during
36 : // development, but they should not be relied on in the final product.
37 :
38 : #ifdef DEBUG
39 : #define FATAL(msg) \
40 : V8_Fatal(__FILE__, __LINE__, "%s", (msg))
41 : #define UNIMPLEMENTED() \
42 : V8_Fatal(__FILE__, __LINE__, "unimplemented code")
43 : #define UNREACHABLE() \
44 : V8_Fatal(__FILE__, __LINE__, "unreachable code")
45 : #else
46 : #define FATAL(msg) \
47 : V8_Fatal("", 0, "%s", (msg))
48 : #define UNIMPLEMENTED() \
49 : V8_Fatal("", 0, "unimplemented code")
50 : #define UNREACHABLE() ((void) 0)
51 : #endif
52 :
53 : // Used by the CHECK macro -- should not be called directly.
54 12487740 : static inline void CheckHelper(const char* file,
55 : int line,
56 : const char* source,
57 : bool condition) {
58 12487740 : if (!condition)
59 0 : V8_Fatal(file, line, source);
60 12487740 : }
61 :
62 :
63 : // The CHECK macro checks that the given condition is true; if not, it
64 : // prints a message to stderr and aborts.
65 : #define CHECK(condition) ::CheckHelper(__FILE__, __LINE__, #condition, condition)
66 :
67 :
68 : // Helper function used by the CHECK_EQ function when given int
69 : // arguments. Should not be called directly.
70 : static inline void CheckEqualsHelper(const char* file, int line,
71 : const char* expected_source, int expected,
72 : const char* value_source, int value) {
73 : if (expected != value) {
74 : V8_Fatal(file, line,
75 : "CHECK_EQ(%s, %s) failed\n# Expected: %i\n# Found: %i",
76 : expected_source, value_source, expected, value);
77 : }
78 : }
79 :
80 :
81 : #define CHECK_EQ(expected, value) CheckEqualsHelper(__FILE__, __LINE__, \
82 : #expected, expected, #value, value)
83 :
84 :
85 : // The ASSERT macro is equivalent to CHECK except that it only
86 : // generates code in debug builds.
87 : #ifdef DEBUG
88 : #define ASSERT(condition) CHECK(condition)
89 : #else
90 : #define ASSERT(condition) ((void) 0)
91 : #endif
92 :
93 : #endif // V8_CHECKS_H_
|