OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_BASE_LOGGING_H_ | 5 #ifndef V8_BASE_LOGGING_H_ |
6 #define V8_BASE_LOGGING_H_ | 6 #define V8_BASE_LOGGING_H_ |
7 | 7 |
8 #include <cstring> | 8 #include <cstring> |
9 #include <sstream> | 9 #include <sstream> |
10 #include <string> | 10 #include <string> |
11 | 11 |
| 12 #include "src/base/base-export.h" |
12 #include "src/base/build_config.h" | 13 #include "src/base/build_config.h" |
13 #include "src/base/compiler-specific.h" | 14 #include "src/base/compiler-specific.h" |
14 | 15 |
15 extern "C" PRINTF_FORMAT(3, 4) V8_NORETURN | 16 extern "C" PRINTF_FORMAT(3, 4) V8_NORETURN V8_BASE_EXPORT |
16 void V8_Fatal(const char* file, int line, const char* format, ...); | 17 void V8_Fatal(const char* file, int line, const char* format, ...); |
17 | 18 |
18 // The FATAL, UNREACHABLE and UNIMPLEMENTED macros are useful during | 19 // The FATAL, UNREACHABLE and UNIMPLEMENTED macros are useful during |
19 // development, but they should not be relied on in the final product. | 20 // development, but they should not be relied on in the final product. |
20 #ifdef DEBUG | 21 #ifdef DEBUG |
21 #define FATAL(msg) \ | 22 #define FATAL(msg) \ |
22 V8_Fatal(__FILE__, __LINE__, "%s", (msg)) | 23 V8_Fatal(__FILE__, __LINE__, "%s", (msg)) |
23 #define UNIMPLEMENTED() \ | 24 #define UNIMPLEMENTED() \ |
24 V8_Fatal(__FILE__, __LINE__, "unimplemented code") | 25 V8_Fatal(__FILE__, __LINE__, "unimplemented code") |
25 #define UNREACHABLE() \ | 26 #define UNREACHABLE() \ |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 template <typename Lhs, typename Rhs> | 81 template <typename Lhs, typename Rhs> |
81 std::string* MakeCheckOpString(Lhs const& lhs, Rhs const& rhs, | 82 std::string* MakeCheckOpString(Lhs const& lhs, Rhs const& rhs, |
82 char const* msg) { | 83 char const* msg) { |
83 std::ostringstream ss; | 84 std::ostringstream ss; |
84 ss << msg << " (" << lhs << " vs. " << rhs << ")"; | 85 ss << msg << " (" << lhs << " vs. " << rhs << ")"; |
85 return new std::string(ss.str()); | 86 return new std::string(ss.str()); |
86 } | 87 } |
87 | 88 |
88 // Commonly used instantiations of MakeCheckOpString<>. Explicitly instantiated | 89 // Commonly used instantiations of MakeCheckOpString<>. Explicitly instantiated |
89 // in logging.cc. | 90 // in logging.cc. |
90 #define DEFINE_MAKE_CHECK_OP_STRING(type) \ | 91 #define DEFINE_MAKE_CHECK_OP_STRING(type) \ |
91 extern template std::string* MakeCheckOpString<type, type>( \ | 92 extern template V8_BASE_EXPORT std::string* MakeCheckOpString<type, type>( \ |
92 type const&, type const&, char const*); | 93 type const&, type const&, char const*); |
93 DEFINE_MAKE_CHECK_OP_STRING(int) | 94 DEFINE_MAKE_CHECK_OP_STRING(int) |
94 DEFINE_MAKE_CHECK_OP_STRING(long) // NOLINT(runtime/int) | 95 DEFINE_MAKE_CHECK_OP_STRING(long) // NOLINT(runtime/int) |
95 DEFINE_MAKE_CHECK_OP_STRING(long long) // NOLINT(runtime/int) | 96 DEFINE_MAKE_CHECK_OP_STRING(long long) // NOLINT(runtime/int) |
96 DEFINE_MAKE_CHECK_OP_STRING(unsigned int) | 97 DEFINE_MAKE_CHECK_OP_STRING(unsigned int) |
97 DEFINE_MAKE_CHECK_OP_STRING(unsigned long) // NOLINT(runtime/int) | 98 DEFINE_MAKE_CHECK_OP_STRING(unsigned long) // NOLINT(runtime/int) |
98 DEFINE_MAKE_CHECK_OP_STRING(unsigned long long) // NOLINT(runtime/int) | 99 DEFINE_MAKE_CHECK_OP_STRING(unsigned long long) // NOLINT(runtime/int) |
99 DEFINE_MAKE_CHECK_OP_STRING(char const*) | 100 DEFINE_MAKE_CHECK_OP_STRING(char const*) |
100 DEFINE_MAKE_CHECK_OP_STRING(void const*) | 101 DEFINE_MAKE_CHECK_OP_STRING(void const*) |
101 #undef DEFINE_MAKE_CHECK_OP_STRING | 102 #undef DEFINE_MAKE_CHECK_OP_STRING |
102 | 103 |
103 | 104 |
104 // Helper functions for CHECK_OP macro. | 105 // Helper functions for CHECK_OP macro. |
105 // The (int, int) specialization works around the issue that the compiler | 106 // The (int, int) specialization works around the issue that the compiler |
106 // will not instantiate the template version of the function on values of | 107 // will not instantiate the template version of the function on values of |
107 // unnamed enum type - see comment below. | 108 // unnamed enum type - see comment below. |
108 // The (float, float) and (double, double) instantiations are explicitly | 109 // The (float, float) and (double, double) instantiations are explicitly |
109 // externialized to ensure proper 32/64-bit comparisons on x86. | 110 // externialized to ensure proper 32/64-bit comparisons on x86. |
110 #define DEFINE_CHECK_OP_IMPL(NAME, op) \ | 111 #define DEFINE_CHECK_OP_IMPL(NAME, op) \ |
111 template <typename Lhs, typename Rhs> \ | 112 template <typename Lhs, typename Rhs> \ |
112 V8_INLINE std::string* Check##NAME##Impl(Lhs const& lhs, Rhs const& rhs, \ | 113 V8_INLINE std::string* Check##NAME##Impl(Lhs const& lhs, Rhs const& rhs, \ |
113 char const* msg) { \ | 114 char const* msg) { \ |
114 return V8_LIKELY(lhs op rhs) ? nullptr : MakeCheckOpString(lhs, rhs, msg); \ | 115 return V8_LIKELY(lhs op rhs) ? nullptr : MakeCheckOpString(lhs, rhs, msg); \ |
115 } \ | 116 } \ |
116 V8_INLINE std::string* Check##NAME##Impl(int lhs, int rhs, \ | 117 V8_INLINE std::string* Check##NAME##Impl(int lhs, int rhs, \ |
117 char const* msg) { \ | 118 char const* msg) { \ |
118 return V8_LIKELY(lhs op rhs) ? nullptr : MakeCheckOpString(lhs, rhs, msg); \ | 119 return V8_LIKELY(lhs op rhs) ? nullptr : MakeCheckOpString(lhs, rhs, msg); \ |
119 } \ | 120 } \ |
120 extern template std::string* Check##NAME##Impl<float, float>( \ | 121 extern template V8_BASE_EXPORT std::string* Check##NAME##Impl<float, float>( \ |
121 float const& lhs, float const& rhs, char const* msg); \ | 122 float const& lhs, float const& rhs, char const* msg); \ |
122 extern template std::string* Check##NAME##Impl<double, double>( \ | 123 extern template V8_BASE_EXPORT std::string* \ |
123 double const& lhs, double const& rhs, char const* msg); | 124 Check##NAME##Impl<double, double>(double const& lhs, double const& rhs, \ |
| 125 char const* msg); |
124 DEFINE_CHECK_OP_IMPL(EQ, ==) | 126 DEFINE_CHECK_OP_IMPL(EQ, ==) |
125 DEFINE_CHECK_OP_IMPL(NE, !=) | 127 DEFINE_CHECK_OP_IMPL(NE, !=) |
126 DEFINE_CHECK_OP_IMPL(LE, <=) | 128 DEFINE_CHECK_OP_IMPL(LE, <=) |
127 DEFINE_CHECK_OP_IMPL(LT, < ) | 129 DEFINE_CHECK_OP_IMPL(LT, < ) |
128 DEFINE_CHECK_OP_IMPL(GE, >=) | 130 DEFINE_CHECK_OP_IMPL(GE, >=) |
129 DEFINE_CHECK_OP_IMPL(GT, > ) | 131 DEFINE_CHECK_OP_IMPL(GT, > ) |
130 #undef DEFINE_CHECK_OP_IMPL | 132 #undef DEFINE_CHECK_OP_IMPL |
131 | 133 |
132 #define CHECK_EQ(lhs, rhs) CHECK_OP(EQ, ==, lhs, rhs) | 134 #define CHECK_EQ(lhs, rhs) CHECK_OP(EQ, ==, lhs, rhs) |
133 #define CHECK_NE(lhs, rhs) CHECK_OP(NE, !=, lhs, rhs) | 135 #define CHECK_NE(lhs, rhs) CHECK_OP(NE, !=, lhs, rhs) |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 #define DCHECK_GT(v1, v2) ((void) 0) | 170 #define DCHECK_GT(v1, v2) ((void) 0) |
169 #define DCHECK_GE(v1, v2) ((void) 0) | 171 #define DCHECK_GE(v1, v2) ((void) 0) |
170 #define DCHECK_LT(v1, v2) ((void) 0) | 172 #define DCHECK_LT(v1, v2) ((void) 0) |
171 #define DCHECK_LE(v1, v2) ((void) 0) | 173 #define DCHECK_LE(v1, v2) ((void) 0) |
172 #define DCHECK_NULL(val) ((void) 0) | 174 #define DCHECK_NULL(val) ((void) 0) |
173 #define DCHECK_NOT_NULL(val) ((void) 0) | 175 #define DCHECK_NOT_NULL(val) ((void) 0) |
174 #define DCHECK_IMPLIES(v1, v2) ((void) 0) | 176 #define DCHECK_IMPLIES(v1, v2) ((void) 0) |
175 #endif | 177 #endif |
176 | 178 |
177 #endif // V8_BASE_LOGGING_H_ | 179 #endif // V8_BASE_LOGGING_H_ |
OLD | NEW |