1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 /** 8 * Macros used to log restyle events. 9 */ 10 11 #ifndef mozilla_RestyleLogging_h 12 #define mozilla_RestyleLogging_h 13 14 #include "mozilla/AutoRestore.h" 15 16 #ifdef DEBUG 17 #ifdef MOZ_OLD_STYLE 18 #define RESTYLE_LOGGING 19 #endif 20 #endif 21 22 #ifdef RESTYLE_LOGGING 23 #define LOG_RESTYLE_VAR2(prefix_, suffix_) prefix_##suffix_ 24 #define LOG_RESTYLE_VAR(prefix_, suffix_) LOG_RESTYLE_VAR2(prefix_, suffix_) 25 #define LOG_RESTYLE_DEPTH LOG_RESTYLE_VAR(restyle_depth_, __LINE__) 26 #define LOG_RESTYLE_IF(object_, cond_, message_, ...) \ 27 PR_BEGIN_MACRO \ 28 if (object_->ShouldLogRestyle() && (cond_)) { \ 29 nsCString line; \ 30 for (int32_t LOG_RESTYLE_VAR(rs_depth_, __LINE__) = 0; \ 31 LOG_RESTYLE_VAR(rs_depth_, __LINE__) < object_->LoggingDepth(); \ 32 LOG_RESTYLE_VAR(rs_depth_, __LINE__)++) { \ 33 line.AppendLiteral(" "); \ 34 } \ 35 line.AppendPrintf(message_, ##__VA_ARGS__); \ 36 printf_stderr("%s\n", line.get()); \ 37 } \ 38 PR_END_MACRO 39 #define LOG_RESTYLE(message_, ...) \ 40 LOG_RESTYLE_IF(this, true, message_, ##__VA_ARGS__) 41 // Beware that LOG_RESTYLE_INDENT is two statements not wrapped in a block. 42 #define LOG_RESTYLE_INDENT() \ 43 AutoRestore<int32_t> LOG_RESTYLE_VAR(ar_depth_, __LINE__)(LoggingDepth()); \ 44 ++LoggingDepth(); 45 #else 46 #define LOG_RESTYLE_IF(cond_, message_, ...) /* nothing */ 47 #define LOG_RESTYLE(message_, ...) /* nothing */ 48 #define LOG_RESTYLE_INDENT() /* nothing */ 49 #endif 50 51 #endif /* mozilla_RestyleLogging_h */ 52