check_impl.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. // Copyright 2022 The Abseil Authors.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // https://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #ifndef ABSL_LOG_INTERNAL_CHECK_IMPL_H_
  15. #define ABSL_LOG_INTERNAL_CHECK_IMPL_H_
  16. #include "absl/base/optimization.h"
  17. #include "absl/log/internal/check_op.h"
  18. #include "absl/log/internal/conditions.h"
  19. #include "absl/log/internal/log_message.h"
  20. #include "absl/log/internal/strip.h"
  21. // CHECK
  22. #define ABSL_LOG_INTERNAL_CHECK_IMPL(condition, condition_text) \
  23. ABSL_LOG_INTERNAL_CONDITION_FATAL(STATELESS, \
  24. ABSL_PREDICT_FALSE(!(condition))) \
  25. ABSL_LOG_INTERNAL_CHECK(condition_text).InternalStream()
  26. #define ABSL_LOG_INTERNAL_QCHECK_IMPL(condition, condition_text) \
  27. ABSL_LOG_INTERNAL_CONDITION_QFATAL(STATELESS, \
  28. ABSL_PREDICT_FALSE(!(condition))) \
  29. ABSL_LOG_INTERNAL_QCHECK(condition_text).InternalStream()
  30. #define ABSL_LOG_INTERNAL_PCHECK_IMPL(condition, condition_text) \
  31. ABSL_LOG_INTERNAL_CHECK_IMPL(condition, condition_text).WithPerror()
  32. #ifndef NDEBUG
  33. #define ABSL_LOG_INTERNAL_DCHECK_IMPL(condition, condition_text) \
  34. ABSL_LOG_INTERNAL_CHECK_IMPL(condition, condition_text)
  35. #else
  36. #define ABSL_LOG_INTERNAL_DCHECK_IMPL(condition, condition_text) \
  37. ABSL_LOG_INTERNAL_CHECK_IMPL(true || (condition), "true")
  38. #endif
  39. // CHECK_EQ
  40. #define ABSL_LOG_INTERNAL_CHECK_EQ_IMPL(val1, val1_text, val2, val2_text) \
  41. ABSL_LOG_INTERNAL_CHECK_OP(Check_EQ, ==, val1, val1_text, val2, val2_text)
  42. #define ABSL_LOG_INTERNAL_CHECK_NE_IMPL(val1, val1_text, val2, val2_text) \
  43. ABSL_LOG_INTERNAL_CHECK_OP(Check_NE, !=, val1, val1_text, val2, val2_text)
  44. #define ABSL_LOG_INTERNAL_CHECK_LE_IMPL(val1, val1_text, val2, val2_text) \
  45. ABSL_LOG_INTERNAL_CHECK_OP(Check_LE, <=, val1, val1_text, val2, val2_text)
  46. #define ABSL_LOG_INTERNAL_CHECK_LT_IMPL(val1, val1_text, val2, val2_text) \
  47. ABSL_LOG_INTERNAL_CHECK_OP(Check_LT, <, val1, val1_text, val2, val2_text)
  48. #define ABSL_LOG_INTERNAL_CHECK_GE_IMPL(val1, val1_text, val2, val2_text) \
  49. ABSL_LOG_INTERNAL_CHECK_OP(Check_GE, >=, val1, val1_text, val2, val2_text)
  50. #define ABSL_LOG_INTERNAL_CHECK_GT_IMPL(val1, val1_text, val2, val2_text) \
  51. ABSL_LOG_INTERNAL_CHECK_OP(Check_GT, >, val1, val1_text, val2, val2_text)
  52. #define ABSL_LOG_INTERNAL_QCHECK_EQ_IMPL(val1, val1_text, val2, val2_text) \
  53. ABSL_LOG_INTERNAL_QCHECK_OP(Check_EQ, ==, val1, val1_text, val2, val2_text)
  54. #define ABSL_LOG_INTERNAL_QCHECK_NE_IMPL(val1, val1_text, val2, val2_text) \
  55. ABSL_LOG_INTERNAL_QCHECK_OP(Check_NE, !=, val1, val1_text, val2, val2_text)
  56. #define ABSL_LOG_INTERNAL_QCHECK_LE_IMPL(val1, val1_text, val2, val2_text) \
  57. ABSL_LOG_INTERNAL_QCHECK_OP(Check_LE, <=, val1, val1_text, val2, val2_text)
  58. #define ABSL_LOG_INTERNAL_QCHECK_LT_IMPL(val1, val1_text, val2, val2_text) \
  59. ABSL_LOG_INTERNAL_QCHECK_OP(Check_LT, <, val1, val1_text, val2, val2_text)
  60. #define ABSL_LOG_INTERNAL_QCHECK_GE_IMPL(val1, val1_text, val2, val2_text) \
  61. ABSL_LOG_INTERNAL_QCHECK_OP(Check_GE, >=, val1, val1_text, val2, val2_text)
  62. #define ABSL_LOG_INTERNAL_QCHECK_GT_IMPL(val1, val1_text, val2, val2_text) \
  63. ABSL_LOG_INTERNAL_QCHECK_OP(Check_GT, >, val1, val1_text, val2, val2_text)
  64. #ifndef NDEBUG
  65. #define ABSL_LOG_INTERNAL_DCHECK_EQ_IMPL(val1, val1_text, val2, val2_text) \
  66. ABSL_LOG_INTERNAL_CHECK_EQ_IMPL(val1, val1_text, val2, val2_text)
  67. #define ABSL_LOG_INTERNAL_DCHECK_NE_IMPL(val1, val1_text, val2, val2_text) \
  68. ABSL_LOG_INTERNAL_CHECK_NE_IMPL(val1, val1_text, val2, val2_text)
  69. #define ABSL_LOG_INTERNAL_DCHECK_LE_IMPL(val1, val1_text, val2, val2_text) \
  70. ABSL_LOG_INTERNAL_CHECK_LE_IMPL(val1, val1_text, val2, val2_text)
  71. #define ABSL_LOG_INTERNAL_DCHECK_LT_IMPL(val1, val1_text, val2, val2_text) \
  72. ABSL_LOG_INTERNAL_CHECK_LT_IMPL(val1, val1_text, val2, val2_text)
  73. #define ABSL_LOG_INTERNAL_DCHECK_GE_IMPL(val1, val1_text, val2, val2_text) \
  74. ABSL_LOG_INTERNAL_CHECK_GE_IMPL(val1, val1_text, val2, val2_text)
  75. #define ABSL_LOG_INTERNAL_DCHECK_GT_IMPL(val1, val1_text, val2, val2_text) \
  76. ABSL_LOG_INTERNAL_CHECK_GT_IMPL(val1, val1_text, val2, val2_text)
  77. #else // ndef NDEBUG
  78. #define ABSL_LOG_INTERNAL_DCHECK_EQ_IMPL(val1, val1_text, val2, val2_text) \
  79. ABSL_LOG_INTERNAL_DCHECK_NOP(val1, val2)
  80. #define ABSL_LOG_INTERNAL_DCHECK_NE_IMPL(val1, val1_text, val2, val2_text) \
  81. ABSL_LOG_INTERNAL_DCHECK_NOP(val1, val2)
  82. #define ABSL_LOG_INTERNAL_DCHECK_LE_IMPL(val1, val1_text, val2, val2_text) \
  83. ABSL_LOG_INTERNAL_DCHECK_NOP(val1, val2)
  84. #define ABSL_LOG_INTERNAL_DCHECK_LT_IMPL(val1, val1_text, val2, val2_text) \
  85. ABSL_LOG_INTERNAL_DCHECK_NOP(val1, val2)
  86. #define ABSL_LOG_INTERNAL_DCHECK_GE_IMPL(val1, val1_text, val2, val2_text) \
  87. ABSL_LOG_INTERNAL_DCHECK_NOP(val1, val2)
  88. #define ABSL_LOG_INTERNAL_DCHECK_GT_IMPL(val1, val1_text, val2, val2_text) \
  89. ABSL_LOG_INTERNAL_DCHECK_NOP(val1, val2)
  90. #endif // def NDEBUG
  91. // CHECK_OK
  92. #define ABSL_LOG_INTERNAL_CHECK_OK_IMPL(status, status_text) \
  93. ABSL_LOG_INTERNAL_CHECK_OK(status, status_text)
  94. #define ABSL_LOG_INTERNAL_QCHECK_OK_IMPL(status, status_text) \
  95. ABSL_LOG_INTERNAL_QCHECK_OK(status, status_text)
  96. #ifndef NDEBUG
  97. #define ABSL_LOG_INTERNAL_DCHECK_OK_IMPL(status, status_text) \
  98. ABSL_LOG_INTERNAL_CHECK_OK(status, status_text)
  99. #else
  100. #define ABSL_LOG_INTERNAL_DCHECK_OK_IMPL(status, status_text) \
  101. ABSL_LOG_INTERNAL_DCHECK_NOP(status, nullptr)
  102. #endif
  103. // CHECK_STREQ
  104. #define ABSL_LOG_INTERNAL_CHECK_STREQ_IMPL(s1, s1_text, s2, s2_text) \
  105. ABSL_LOG_INTERNAL_CHECK_STROP(strcmp, ==, true, s1, s1_text, s2, s2_text)
  106. #define ABSL_LOG_INTERNAL_CHECK_STRNE_IMPL(s1, s1_text, s2, s2_text) \
  107. ABSL_LOG_INTERNAL_CHECK_STROP(strcmp, !=, false, s1, s1_text, s2, s2_text)
  108. #define ABSL_LOG_INTERNAL_CHECK_STRCASEEQ_IMPL(s1, s1_text, s2, s2_text) \
  109. ABSL_LOG_INTERNAL_CHECK_STROP(strcasecmp, ==, true, s1, s1_text, s2, s2_text)
  110. #define ABSL_LOG_INTERNAL_CHECK_STRCASENE_IMPL(s1, s1_text, s2, s2_text) \
  111. ABSL_LOG_INTERNAL_CHECK_STROP(strcasecmp, !=, false, s1, s1_text, s2, s2_text)
  112. #define ABSL_LOG_INTERNAL_QCHECK_STREQ_IMPL(s1, s1_text, s2, s2_text) \
  113. ABSL_LOG_INTERNAL_QCHECK_STROP(strcmp, ==, true, s1, s1_text, s2, s2_text)
  114. #define ABSL_LOG_INTERNAL_QCHECK_STRNE_IMPL(s1, s1_text, s2, s2_text) \
  115. ABSL_LOG_INTERNAL_QCHECK_STROP(strcmp, !=, false, s1, s1_text, s2, s2_text)
  116. #define ABSL_LOG_INTERNAL_QCHECK_STRCASEEQ_IMPL(s1, s1_text, s2, s2_text) \
  117. ABSL_LOG_INTERNAL_QCHECK_STROP(strcasecmp, ==, true, s1, s1_text, s2, s2_text)
  118. #define ABSL_LOG_INTERNAL_QCHECK_STRCASENE_IMPL(s1, s1_text, s2, s2_text) \
  119. ABSL_LOG_INTERNAL_QCHECK_STROP(strcasecmp, !=, false, s1, s1_text, s2, \
  120. s2_text)
  121. #ifndef NDEBUG
  122. #define ABSL_LOG_INTERNAL_DCHECK_STREQ_IMPL(s1, s1_text, s2, s2_text) \
  123. ABSL_LOG_INTERNAL_CHECK_STREQ_IMPL(s1, s1_text, s2, s2_text)
  124. #define ABSL_LOG_INTERNAL_DCHECK_STRCASEEQ_IMPL(s1, s1_text, s2, s2_text) \
  125. ABSL_LOG_INTERNAL_CHECK_STRCASEEQ_IMPL(s1, s1_text, s2, s2_text)
  126. #define ABSL_LOG_INTERNAL_DCHECK_STRNE_IMPL(s1, s1_text, s2, s2_text) \
  127. ABSL_LOG_INTERNAL_CHECK_STRNE_IMPL(s1, s1_text, s2, s2_text)
  128. #define ABSL_LOG_INTERNAL_DCHECK_STRCASENE_IMPL(s1, s1_text, s2, s2_text) \
  129. ABSL_LOG_INTERNAL_CHECK_STRCASENE_IMPL(s1, s1_text, s2, s2_text)
  130. #else // ndef NDEBUG
  131. #define ABSL_LOG_INTERNAL_DCHECK_STREQ_IMPL(s1, s1_text, s2, s2_text) \
  132. ABSL_LOG_INTERNAL_DCHECK_NOP(s1, s2)
  133. #define ABSL_LOG_INTERNAL_DCHECK_STRCASEEQ_IMPL(s1, s1_text, s2, s2_text) \
  134. ABSL_LOG_INTERNAL_DCHECK_NOP(s1, s2)
  135. #define ABSL_LOG_INTERNAL_DCHECK_STRNE_IMPL(s1, s1_text, s2, s2_text) \
  136. ABSL_LOG_INTERNAL_DCHECK_NOP(s1, s2)
  137. #define ABSL_LOG_INTERNAL_DCHECK_STRCASENE_IMPL(s1, s1_text, s2, s2_text) \
  138. ABSL_LOG_INTERNAL_DCHECK_NOP(s1, s2)
  139. #endif // def NDEBUG
  140. #endif // ABSL_LOG_INTERNAL_CHECK_IMPL_H_