| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium 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 BASE_LOGGING_H_ | 5 #ifndef BASE_LOGGING_H_ |
| 6 #define BASE_LOGGING_H_ | 6 #define BASE_LOGGING_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <cassert> | 10 #include <cassert> |
| (...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 707 COMPACT_GOOGLE_LOG_EX_INFO(ClassName , ##__VA_ARGS__) | 707 COMPACT_GOOGLE_LOG_EX_INFO(ClassName , ##__VA_ARGS__) |
| 708 #define COMPACT_GOOGLE_LOG_DCHECK COMPACT_GOOGLE_LOG_INFO | 708 #define COMPACT_GOOGLE_LOG_DCHECK COMPACT_GOOGLE_LOG_INFO |
| 709 const LogSeverity LOG_DCHECK = LOG_INFO; | 709 const LogSeverity LOG_DCHECK = LOG_INFO; |
| 710 | 710 |
| 711 #endif // DCHECK_IS_ON() | 711 #endif // DCHECK_IS_ON() |
| 712 | 712 |
| 713 // DCHECK et al. make sure to reference |condition| regardless of | 713 // DCHECK et al. make sure to reference |condition| regardless of |
| 714 // whether DCHECKs are enabled; this is so that we don't get unused | 714 // whether DCHECKs are enabled; this is so that we don't get unused |
| 715 // variable warnings if the only use of a variable is in a DCHECK. | 715 // variable warnings if the only use of a variable is in a DCHECK. |
| 716 // This behavior is different from DLOG_IF et al. | 716 // This behavior is different from DLOG_IF et al. |
| 717 // |
| 718 // Note that the definition of the DCHECK macros depends on whether or not |
| 719 // DCHECK_IS_ON() is true. When DCHECK_IS_ON() is false, the macros use |
| 720 // EAT_STREAM_PARAMETERS to avoid expressions that would create temporaries. |
| 717 | 721 |
| 718 #if defined(_PREFAST_) && defined(OS_WIN) | 722 #if defined(_PREFAST_) && defined(OS_WIN) |
| 719 // See comments on the previous use of __analysis_assume. | 723 // See comments on the previous use of __analysis_assume. |
| 720 | 724 |
| 721 #define DCHECK(condition) \ | 725 #define DCHECK(condition) \ |
| 722 __analysis_assume(!!(condition)), \ | 726 __analysis_assume(!!(condition)), \ |
| 723 LAZY_STREAM(LOG_STREAM(DCHECK), false) \ | 727 LAZY_STREAM(LOG_STREAM(DCHECK), false) \ |
| 724 << "Check failed: " #condition ". " | 728 << "Check failed: " #condition ". " |
| 725 | 729 |
| 726 #define DPCHECK(condition) \ | 730 #define DPCHECK(condition) \ |
| 727 __analysis_assume(!!(condition)), \ | 731 __analysis_assume(!!(condition)), \ |
| 728 LAZY_STREAM(PLOG_STREAM(DCHECK), false) \ | 732 LAZY_STREAM(PLOG_STREAM(DCHECK), false) \ |
| 729 << "Check failed: " #condition ". " | 733 << "Check failed: " #condition ". " |
| 730 | 734 |
| 731 #else // _PREFAST_ | 735 #else // _PREFAST_ |
| 732 | 736 |
| 733 #define DCHECK(condition) \ | 737 #if DCHECK_IS_ON() |
| 734 LAZY_STREAM(LOG_STREAM(DCHECK), DCHECK_IS_ON() ? !(condition) : false) \ | 738 |
| 739 #define DCHECK(condition) \ |
| 740 LAZY_STREAM(LOG_STREAM(DCHECK), !(condition)) \ |
| 741 << "Check failed: " #condition ". " |
| 742 #define DPCHECK(condition) \ |
| 743 LAZY_STREAM(PLOG_STREAM(DCHECK), !(condition)) \ |
| 735 << "Check failed: " #condition ". " | 744 << "Check failed: " #condition ". " |
| 736 | 745 |
| 737 #define DPCHECK(condition) \ | 746 #else // DCHECK_IS_ON() |
| 738 LAZY_STREAM(PLOG_STREAM(DCHECK), DCHECK_IS_ON() ? !(condition) : false) \ | 747 |
| 739 << "Check failed: " #condition ". " | 748 #define DCHECK(condition) EAT_STREAM_PARAMETERS << !(condition) |
| 749 #define DPCHECK(condition) EAT_STREAM_PARAMETERS << !(condition) |
| 750 |
| 751 #endif // DCHECK_IS_ON() |
| 740 | 752 |
| 741 #endif // _PREFAST_ | 753 #endif // _PREFAST_ |
| 742 | 754 |
| 743 // Helper macro for binary operators. | 755 // Helper macro for binary operators. |
| 744 // Don't use this macro directly in your code, use DCHECK_EQ et al below. | 756 // Don't use this macro directly in your code, use DCHECK_EQ et al below. |
| 745 // The 'switch' is used to prevent the 'else' from being ambiguous when the | 757 // The 'switch' is used to prevent the 'else' from being ambiguous when the |
| 746 // macro is used in an 'if' clause such as: | 758 // macro is used in an 'if' clause such as: |
| 747 // if (a == 1) | 759 // if (a == 1) |
| 748 // DCHECK_EQ(2, a); | 760 // DCHECK_EQ(2, a); |
| 761 #if DCHECK_IS_ON() |
| 762 |
| 749 #define DCHECK_OP(name, op, val1, val2) \ | 763 #define DCHECK_OP(name, op, val1, val2) \ |
| 750 switch (0) case 0: default: \ | 764 switch (0) case 0: default: \ |
| 751 if (::logging::CheckOpResult true_if_passed = \ | 765 if (::logging::CheckOpResult true_if_passed = \ |
| 752 DCHECK_IS_ON() ? \ | 766 DCHECK_IS_ON() ? \ |
| 753 ::logging::Check##name##Impl((val1), (val2), \ | 767 ::logging::Check##name##Impl((val1), (val2), \ |
| 754 #val1 " " #op " " #val2) : nullptr) \ | 768 #val1 " " #op " " #val2) : nullptr) \ |
| 755 ; \ | 769 ; \ |
| 756 else \ | 770 else \ |
| 757 ::logging::LogMessage(__FILE__, __LINE__, ::logging::LOG_DCHECK, \ | 771 ::logging::LogMessage(__FILE__, __LINE__, ::logging::LOG_DCHECK, \ |
| 758 true_if_passed.message()).stream() | 772 true_if_passed.message()).stream() |
| 759 | 773 |
| 774 #else // DCHECK_IS_ON() |
| 775 |
| 776 // When DCHECKs aren't enabled, DCHECK_OP still needs to reference operator<< |
| 777 // overloads for |val1| and |val2| to avoid potential compiler warnings about |
| 778 // unused functions. For the same reason, it also compares |val1| and |val2| |
| 779 // using |op|. |
| 780 // |
| 781 // Note that the contract of DCHECK_EQ, etc is that arguments are only evaluated |
| 782 // once. Even though |val1| and |val2| appear twice in this version of the macro |
| 783 // expansion, this is OK, since the expression is never actually evaluated. |
| 784 #define DCHECK_OP(name, op, val1, val2) \ |
| 785 EAT_STREAM_PARAMETERS << (::logging::MakeCheckOpValueString( \ |
| 786 ::logging::g_swallow_stream, val1), \ |
| 787 ::logging::MakeCheckOpValueString( \ |
| 788 ::logging::g_swallow_stream, val2), \ |
| 789 (val1)op(val2)) |
| 790 |
| 791 #endif // DCHECK_IS_ON() |
| 792 |
| 760 // Equality/Inequality checks - compare two values, and log a | 793 // Equality/Inequality checks - compare two values, and log a |
| 761 // LOG_DCHECK message including the two values when the result is not | 794 // LOG_DCHECK message including the two values when the result is not |
| 762 // as expected. The values must have operator<<(ostream, ...) | 795 // as expected. The values must have operator<<(ostream, ...) |
| 763 // defined. | 796 // defined. |
| 764 // | 797 // |
| 765 // You may append to the error message like so: | 798 // You may append to the error message like so: |
| 766 // DCHECK_NE(1, 2) << "The world must be ending!"; | 799 // DCHECK_NE(1, 2) << "The world must be ending!"; |
| 767 // | 800 // |
| 768 // We are very careful to ensure that each argument is evaluated exactly | 801 // We are very careful to ensure that each argument is evaluated exactly |
| 769 // once, and that anything which is legal to pass as a function argument is | 802 // once, and that anything which is legal to pass as a function argument is |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1020 #elif NOTIMPLEMENTED_POLICY == 5 | 1053 #elif NOTIMPLEMENTED_POLICY == 5 |
| 1021 #define NOTIMPLEMENTED() do {\ | 1054 #define NOTIMPLEMENTED() do {\ |
| 1022 static bool logged_once = false;\ | 1055 static bool logged_once = false;\ |
| 1023 LOG_IF(ERROR, !logged_once) << NOTIMPLEMENTED_MSG;\ | 1056 LOG_IF(ERROR, !logged_once) << NOTIMPLEMENTED_MSG;\ |
| 1024 logged_once = true;\ | 1057 logged_once = true;\ |
| 1025 } while(0);\ | 1058 } while(0);\ |
| 1026 EAT_STREAM_PARAMETERS | 1059 EAT_STREAM_PARAMETERS |
| 1027 #endif | 1060 #endif |
| 1028 | 1061 |
| 1029 #endif // BASE_LOGGING_H_ | 1062 #endif // BASE_LOGGING_H_ |
| OLD | NEW |