| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| #ifndef ABSL_LOG_INTERNAL_CHECK_OP_H_ |
| #define ABSL_LOG_INTERNAL_CHECK_OP_H_ |
|
|
| #include <stdint.h> |
|
|
| #include <ostream> |
| #include <sstream> |
| #include <string> |
| #include <utility> |
|
|
| #include "absl/base/attributes.h" |
| #include "absl/base/config.h" |
| #include "absl/base/optimization.h" |
| #include "absl/log/internal/nullguard.h" |
| #include "absl/log/internal/nullstream.h" |
| #include "absl/log/internal/strip.h" |
|
|
| |
| |
| #ifdef ABSL_MIN_LOG_LEVEL |
| #define ABSL_LOG_INTERNAL_STRIP_STRING_LITERAL(literal) \ |
| (::absl::LogSeverity::kFatal >= \ |
| static_cast<::absl::LogSeverity>(ABSL_MIN_LOG_LEVEL) \ |
| ? (literal) \ |
| : "") |
| #else |
| #define ABSL_LOG_INTERNAL_STRIP_STRING_LITERAL(literal) (literal) |
| #endif |
|
|
| #ifdef NDEBUG |
| |
| |
| |
| #define ABSL_LOG_INTERNAL_DCHECK_NOP(x, y) \ |
| while (false && ((void)(x), (void)(y), 0)) \ |
| ::absl::log_internal::NullStream().InternalStream() |
| #endif |
|
|
| #define ABSL_LOG_INTERNAL_CHECK_OP(name, op, val1, val1_text, val2, val2_text) \ |
| while ( \ |
| ::std::string* absl_log_internal_check_op_result ABSL_ATTRIBUTE_UNUSED = \ |
| ::absl::log_internal::name##Impl( \ |
| ::absl::log_internal::GetReferenceableValue(val1), \ |
| ::absl::log_internal::GetReferenceableValue(val2), \ |
| ABSL_LOG_INTERNAL_STRIP_STRING_LITERAL(val1_text \ |
| " " #op " " val2_text))) \ |
| ABSL_LOG_INTERNAL_CONDITION_FATAL(STATELESS, true) \ |
| ABSL_LOG_INTERNAL_CHECK(*absl_log_internal_check_op_result).InternalStream() |
| #define ABSL_LOG_INTERNAL_QCHECK_OP(name, op, val1, val1_text, val2, \ |
| val2_text) \ |
| while (::std::string* absl_log_internal_qcheck_op_result = \ |
| ::absl::log_internal::name##Impl( \ |
| ::absl::log_internal::GetReferenceableValue(val1), \ |
| ::absl::log_internal::GetReferenceableValue(val2), \ |
| ABSL_LOG_INTERNAL_STRIP_STRING_LITERAL( \ |
| val1_text " " #op " " val2_text))) \ |
| ABSL_LOG_INTERNAL_CONDITION_QFATAL(STATELESS, true) \ |
| ABSL_LOG_INTERNAL_QCHECK(*absl_log_internal_qcheck_op_result).InternalStream() |
| #define ABSL_LOG_INTERNAL_CHECK_STROP(func, op, expected, s1, s1_text, s2, \ |
| s2_text) \ |
| while (::std::string* absl_log_internal_check_strop_result = \ |
| ::absl::log_internal::Check##func##expected##Impl( \ |
| (s1), (s2), \ |
| ABSL_LOG_INTERNAL_STRIP_STRING_LITERAL(s1_text " " #op \ |
| " " s2_text))) \ |
| ABSL_LOG_INTERNAL_CONDITION_FATAL(STATELESS, true) \ |
| ABSL_LOG_INTERNAL_CHECK(*absl_log_internal_check_strop_result) \ |
| .InternalStream() |
| #define ABSL_LOG_INTERNAL_QCHECK_STROP(func, op, expected, s1, s1_text, s2, \ |
| s2_text) \ |
| while (::std::string* absl_log_internal_qcheck_strop_result = \ |
| ::absl::log_internal::Check##func##expected##Impl( \ |
| (s1), (s2), \ |
| ABSL_LOG_INTERNAL_STRIP_STRING_LITERAL(s1_text " " #op \ |
| " " s2_text))) \ |
| ABSL_LOG_INTERNAL_CONDITION_QFATAL(STATELESS, true) \ |
| ABSL_LOG_INTERNAL_QCHECK(*absl_log_internal_qcheck_strop_result) \ |
| .InternalStream() |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| #define ABSL_LOG_INTERNAL_CHECK_OK(val, val_text) \ |
| for (::std::pair<const ::absl::Status*, ::std::string*> \ |
| absl_log_internal_check_ok_goo; \ |
| absl_log_internal_check_ok_goo.first = \ |
| ::absl::log_internal::AsStatus(val), \ |
| absl_log_internal_check_ok_goo.second = \ |
| ABSL_PREDICT_TRUE(absl_log_internal_check_ok_goo.first->ok()) \ |
| ? nullptr \ |
| : ::absl::status_internal::MakeCheckFailString( \ |
| absl_log_internal_check_ok_goo.first, \ |
| ABSL_LOG_INTERNAL_STRIP_STRING_LITERAL(val_text \ |
| " is OK")), \ |
| !ABSL_PREDICT_TRUE(absl_log_internal_check_ok_goo.first->ok());) \ |
| ABSL_LOG_INTERNAL_CONDITION_FATAL(STATELESS, true) \ |
| ABSL_LOG_INTERNAL_CHECK(*absl_log_internal_check_ok_goo.second) \ |
| .InternalStream() |
| #define ABSL_LOG_INTERNAL_QCHECK_OK(val, val_text) \ |
| for (::std::pair<const ::absl::Status*, ::std::string*> \ |
| absl_log_internal_qcheck_ok_goo; \ |
| absl_log_internal_qcheck_ok_goo.first = \ |
| ::absl::log_internal::AsStatus(val), \ |
| absl_log_internal_qcheck_ok_goo.second = \ |
| ABSL_PREDICT_TRUE(absl_log_internal_qcheck_ok_goo.first->ok()) \ |
| ? nullptr \ |
| : ::absl::status_internal::MakeCheckFailString( \ |
| absl_log_internal_qcheck_ok_goo.first, \ |
| ABSL_LOG_INTERNAL_STRIP_STRING_LITERAL(val_text \ |
| " is OK")), \ |
| !ABSL_PREDICT_TRUE(absl_log_internal_qcheck_ok_goo.first->ok());) \ |
| ABSL_LOG_INTERNAL_CONDITION_QFATAL(STATELESS, true) \ |
| ABSL_LOG_INTERNAL_QCHECK(*absl_log_internal_qcheck_ok_goo.second) \ |
| .InternalStream() |
|
|
| namespace absl { |
| ABSL_NAMESPACE_BEGIN |
|
|
| class Status; |
| template <typename T> |
| class StatusOr; |
|
|
| namespace status_internal { |
| ABSL_ATTRIBUTE_PURE_FUNCTION std::string* MakeCheckFailString( |
| const absl::Status* status, const char* prefix); |
| } |
|
|
| namespace log_internal { |
|
|
| |
| |
| |
| inline const absl::Status* AsStatus(const absl::Status& s) { return &s; } |
| template <typename T> |
| const absl::Status* AsStatus(const absl::StatusOr<T>& s) { |
| return &s.status(); |
| } |
|
|
| |
| |
| class CheckOpMessageBuilder final { |
| public: |
| |
| explicit CheckOpMessageBuilder(const char* exprtext); |
| ~CheckOpMessageBuilder() = default; |
| |
| std::ostream& ForVar1() { return stream_; } |
| |
| std::ostream& ForVar2(); |
| |
| std::string* NewString(); |
|
|
| private: |
| std::ostringstream stream_; |
| }; |
|
|
| |
| |
| template <typename T> |
| inline void MakeCheckOpValueString(std::ostream& os, const T& v) { |
| os << log_internal::NullGuard<T>::Guard(v); |
| } |
|
|
| |
| void MakeCheckOpValueString(std::ostream& os, char v); |
| void MakeCheckOpValueString(std::ostream& os, signed char v); |
| void MakeCheckOpValueString(std::ostream& os, unsigned char v); |
| void MakeCheckOpValueString(std::ostream& os, const void* p); |
|
|
| namespace detect_specialization { |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| int64_t operator<<(std::ostream&, short value); |
| int64_t operator<<(std::ostream&, unsigned short value); |
| int64_t operator<<(std::ostream&, int value); |
| int64_t operator<<(std::ostream&, unsigned int value); |
| int64_t operator<<(std::ostream&, long value); |
| uint64_t operator<<(std::ostream&, unsigned long value); |
| int64_t operator<<(std::ostream&, long long value); |
| uint64_t operator<<(std::ostream&, unsigned long long value); |
| float operator<<(std::ostream&, float value); |
| double operator<<(std::ostream&, double value); |
| long double operator<<(std::ostream&, long double value); |
| bool operator<<(std::ostream&, bool value); |
| const void* operator<<(std::ostream&, const void* value); |
| const void* operator<<(std::ostream&, std::nullptr_t); |
|
|
| |
| |
| |
| |
| |
| template <typename Traits> |
| char operator<<(std::basic_ostream<char, Traits>&, char); |
| template <typename Traits> |
| signed char operator<<(std::basic_ostream<char, Traits>&, signed char); |
| template <typename Traits> |
| unsigned char operator<<(std::basic_ostream<char, Traits>&, unsigned char); |
| template <typename Traits> |
| const char* operator<<(std::basic_ostream<char, Traits>&, const char*); |
| template <typename Traits> |
| const signed char* operator<<(std::basic_ostream<char, Traits>&, |
| const signed char*); |
| template <typename Traits> |
| const unsigned char* operator<<(std::basic_ostream<char, Traits>&, |
| const unsigned char*); |
|
|
| |
| |
| |
| template <typename T, typename = decltype(std::declval<std::ostream&>() |
| << std::declval<const T&>())> |
| const T& Detect(int); |
|
|
| |
| |
| |
| |
| template <typename T> |
| decltype(detect_specialization::operator<<(std::declval<std::ostream&>(), |
| std::declval<const T&>())) |
| Detect(char); |
|
|
| } |
|
|
| template <typename T> |
| using CheckOpStreamType = decltype(detect_specialization::Detect<T>(0)); |
|
|
| |
| template <typename T1, typename T2> |
| ABSL_ATTRIBUTE_RETURNS_NONNULL std::string* MakeCheckOpString( |
| T1 v1, T2 v2, const char* exprtext) ABSL_ATTRIBUTE_NOINLINE; |
|
|
| template <typename T1, typename T2> |
| std::string* MakeCheckOpString(T1 v1, T2 v2, const char* exprtext) { |
| CheckOpMessageBuilder comb(exprtext); |
| MakeCheckOpValueString(comb.ForVar1(), v1); |
| MakeCheckOpValueString(comb.ForVar2(), v2); |
| return comb.NewString(); |
| } |
|
|
| |
| |
| #define ABSL_LOG_INTERNAL_DEFINE_MAKE_CHECK_OP_STRING_EXTERN(x) \ |
| extern template std::string* MakeCheckOpString(x, x, const char*) |
| ABSL_LOG_INTERNAL_DEFINE_MAKE_CHECK_OP_STRING_EXTERN(bool); |
| ABSL_LOG_INTERNAL_DEFINE_MAKE_CHECK_OP_STRING_EXTERN(int64_t); |
| ABSL_LOG_INTERNAL_DEFINE_MAKE_CHECK_OP_STRING_EXTERN(uint64_t); |
| ABSL_LOG_INTERNAL_DEFINE_MAKE_CHECK_OP_STRING_EXTERN(float); |
| ABSL_LOG_INTERNAL_DEFINE_MAKE_CHECK_OP_STRING_EXTERN(double); |
| ABSL_LOG_INTERNAL_DEFINE_MAKE_CHECK_OP_STRING_EXTERN(char); |
| ABSL_LOG_INTERNAL_DEFINE_MAKE_CHECK_OP_STRING_EXTERN(unsigned char); |
| ABSL_LOG_INTERNAL_DEFINE_MAKE_CHECK_OP_STRING_EXTERN(const std::string&); |
| ABSL_LOG_INTERNAL_DEFINE_MAKE_CHECK_OP_STRING_EXTERN(const absl::string_view&); |
| ABSL_LOG_INTERNAL_DEFINE_MAKE_CHECK_OP_STRING_EXTERN(const char*); |
| ABSL_LOG_INTERNAL_DEFINE_MAKE_CHECK_OP_STRING_EXTERN(const signed char*); |
| ABSL_LOG_INTERNAL_DEFINE_MAKE_CHECK_OP_STRING_EXTERN(const unsigned char*); |
| ABSL_LOG_INTERNAL_DEFINE_MAKE_CHECK_OP_STRING_EXTERN(const void*); |
| #undef ABSL_LOG_INTERNAL_DEFINE_MAKE_CHECK_OP_STRING_EXTERN |
|
|
| |
| |
| |
| #ifdef ABSL_MIN_LOG_LEVEL |
| #define ABSL_LOG_INTERNAL_CHECK_OP_IMPL_RESULT(U1, U2, v1, v2, exprtext) \ |
| ((::absl::LogSeverity::kFatal >= \ |
| static_cast<::absl::LogSeverity>(ABSL_MIN_LOG_LEVEL)) \ |
| ? MakeCheckOpString<U1, U2>(v1, v2, exprtext) \ |
| : new std::string()) |
| #else |
| #define ABSL_LOG_INTERNAL_CHECK_OP_IMPL_RESULT(U1, U2, v1, v2, exprtext) \ |
| MakeCheckOpString<U1, U2>(v1, v2, exprtext) |
| #endif |
|
|
| |
| |
| |
| |
| #define ABSL_LOG_INTERNAL_CHECK_OP_IMPL(name, op) \ |
| template <typename T1, typename T2> \ |
| inline constexpr ::std::string* name##Impl(const T1& v1, const T2& v2, \ |
| const char* exprtext) { \ |
| using U1 = CheckOpStreamType<T1>; \ |
| using U2 = CheckOpStreamType<T2>; \ |
| return ABSL_PREDICT_TRUE(v1 op v2) \ |
| ? nullptr \ |
| : ABSL_LOG_INTERNAL_CHECK_OP_IMPL_RESULT(U1, U2, v1, v2, \ |
| exprtext); \ |
| } \ |
| inline constexpr ::std::string* name##Impl(int v1, int v2, \ |
| const char* exprtext) { \ |
| return name##Impl<int, int>(v1, v2, exprtext); \ |
| } |
|
|
| ABSL_LOG_INTERNAL_CHECK_OP_IMPL(Check_EQ, ==) |
| ABSL_LOG_INTERNAL_CHECK_OP_IMPL(Check_NE, !=) |
| ABSL_LOG_INTERNAL_CHECK_OP_IMPL(Check_LE, <=) |
| ABSL_LOG_INTERNAL_CHECK_OP_IMPL(Check_LT, <) |
| ABSL_LOG_INTERNAL_CHECK_OP_IMPL(Check_GE, >=) |
| ABSL_LOG_INTERNAL_CHECK_OP_IMPL(Check_GT, >) |
| #undef ABSL_LOG_INTERNAL_CHECK_OP_IMPL_RESULT |
| #undef ABSL_LOG_INTERNAL_CHECK_OP_IMPL |
|
|
| std::string* CheckstrcmptrueImpl(const char* s1, const char* s2, |
| const char* exprtext); |
| std::string* CheckstrcmpfalseImpl(const char* s1, const char* s2, |
| const char* exprtext); |
| std::string* CheckstrcasecmptrueImpl(const char* s1, const char* s2, |
| const char* exprtext); |
| std::string* CheckstrcasecmpfalseImpl(const char* s1, const char* s2, |
| const char* exprtext); |
|
|
| |
| |
| |
| |
| |
| |
| template <typename T> |
| inline constexpr const T& GetReferenceableValue(const T& t) { |
| return t; |
| } |
| inline constexpr char GetReferenceableValue(char t) { return t; } |
| inline constexpr unsigned char GetReferenceableValue(unsigned char t) { |
| return t; |
| } |
| inline constexpr signed char GetReferenceableValue(signed char t) { return t; } |
| inline constexpr short GetReferenceableValue(short t) { return t; } |
| inline constexpr unsigned short GetReferenceableValue( |
| unsigned short t) { |
| return t; |
| } |
| inline constexpr int GetReferenceableValue(int t) { return t; } |
| inline constexpr unsigned int GetReferenceableValue(unsigned int t) { |
| return t; |
| } |
| inline constexpr long GetReferenceableValue(long t) { return t; } |
| inline constexpr unsigned long GetReferenceableValue( |
| unsigned long t) { |
| return t; |
| } |
| inline constexpr long long GetReferenceableValue(long long t) { |
| return t; |
| } |
| inline constexpr unsigned long long GetReferenceableValue( |
| unsigned long long t) { |
| return t; |
| } |
|
|
| } |
| ABSL_NAMESPACE_END |
| } |
|
|
| #endif |
|
|