From dc8479928c5aee4c6ad6fe4f59006fb604cee701 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Sun, 18 Sep 2016 09:38:01 +0900 Subject: Sources: Run clang-format on everything. --- src/common/logging/backend.cpp | 139 +++++++++++++++++----------------- src/common/logging/backend.h | 6 +- src/common/logging/filter.cpp | 7 +- src/common/logging/filter.h | 4 +- src/common/logging/log.h | 136 +++++++++++++++++---------------- src/common/logging/text_formatter.cpp | 52 ++++++++----- src/common/logging/text_formatter.h | 1 - 7 files changed, 181 insertions(+), 164 deletions(-) (limited to 'src/common/logging') diff --git a/src/common/logging/backend.cpp b/src/common/logging/backend.cpp index 0b2fabec9..b3d6598e4 100644 --- a/src/common/logging/backend.cpp +++ b/src/common/logging/backend.cpp @@ -16,73 +16,79 @@ namespace Log { /// Macro listing all log classes. Code should define CLS and SUB as desired before invoking this. -#define ALL_LOG_CLASSES() \ - CLS(Log) \ - CLS(Common) \ - SUB(Common, Filesystem) \ - SUB(Common, Memory) \ - CLS(Core) \ - SUB(Core, ARM11) \ - SUB(Core, Timing) \ - CLS(Config) \ - CLS(Debug) \ - SUB(Debug, Emulated) \ - SUB(Debug, GPU) \ - SUB(Debug, Breakpoint) \ - SUB(Debug, GDBStub) \ - CLS(Kernel) \ - SUB(Kernel, SVC) \ - CLS(Service) \ - SUB(Service, SRV) \ - SUB(Service, FRD) \ - SUB(Service, FS) \ - SUB(Service, ERR) \ - SUB(Service, APT) \ - SUB(Service, GSP) \ - SUB(Service, AC) \ - SUB(Service, AM) \ - SUB(Service, PTM) \ - SUB(Service, LDR) \ - SUB(Service, NDM) \ - SUB(Service, NIM) \ - SUB(Service, NWM) \ - SUB(Service, CAM) \ - SUB(Service, CECD) \ - SUB(Service, CFG) \ - SUB(Service, DSP) \ - SUB(Service, DLP) \ - SUB(Service, HID) \ - SUB(Service, SOC) \ - SUB(Service, IR) \ - SUB(Service, Y2R) \ - CLS(HW) \ - SUB(HW, Memory) \ - SUB(HW, LCD) \ - SUB(HW, GPU) \ - CLS(Frontend) \ - CLS(Render) \ - SUB(Render, Software) \ - SUB(Render, OpenGL) \ - CLS(Audio) \ - SUB(Audio, DSP) \ - SUB(Audio, Sink) \ - CLS(Loader) +#define ALL_LOG_CLASSES() \ + CLS(Log) \ + CLS(Common) \ + SUB(Common, Filesystem) \ + SUB(Common, Memory) \ + CLS(Core) \ + SUB(Core, ARM11) \ + SUB(Core, Timing) \ + CLS(Config) \ + CLS(Debug) \ + SUB(Debug, Emulated) \ + SUB(Debug, GPU) \ + SUB(Debug, Breakpoint) \ + SUB(Debug, GDBStub) \ + CLS(Kernel) \ + SUB(Kernel, SVC) \ + CLS(Service) \ + SUB(Service, SRV) \ + SUB(Service, FRD) \ + SUB(Service, FS) \ + SUB(Service, ERR) \ + SUB(Service, APT) \ + SUB(Service, GSP) \ + SUB(Service, AC) \ + SUB(Service, AM) \ + SUB(Service, PTM) \ + SUB(Service, LDR) \ + SUB(Service, NDM) \ + SUB(Service, NIM) \ + SUB(Service, NWM) \ + SUB(Service, CAM) \ + SUB(Service, CECD) \ + SUB(Service, CFG) \ + SUB(Service, DSP) \ + SUB(Service, DLP) \ + SUB(Service, HID) \ + SUB(Service, SOC) \ + SUB(Service, IR) \ + SUB(Service, Y2R) \ + CLS(HW) \ + SUB(HW, Memory) \ + SUB(HW, LCD) \ + SUB(HW, GPU) \ + CLS(Frontend) \ + CLS(Render) \ + SUB(Render, Software) \ + SUB(Render, OpenGL) \ + CLS(Audio) \ + SUB(Audio, DSP) \ + SUB(Audio, Sink) \ + CLS(Loader) // GetClassName is a macro defined by Windows.h, grrr... const char* GetLogClassName(Class log_class) { switch (log_class) { -#define CLS(x) case Class::x: return #x; -#define SUB(x, y) case Class::x##_##y: return #x "." #y; +#define CLS(x) \ + case Class::x: \ + return #x; +#define SUB(x, y) \ + case Class::x##_##y: \ + return #x "." #y; ALL_LOG_CLASSES() #undef CLS #undef SUB - case Class::Count: - UNREACHABLE(); + case Class::Count: + UNREACHABLE(); } } const char* GetLevelName(Level log_level) { -#define LVL(x) case Level::x: return #x +#define LVL(x) \ + case Level::x: \ + return #x switch (log_level) { LVL(Trace); LVL(Debug); @@ -90,15 +96,14 @@ const char* GetLevelName(Level log_level) { LVL(Warning); LVL(Error); LVL(Critical); - case Level::Count: - UNREACHABLE(); + case Level::Count: + UNREACHABLE(); } #undef LVL } -Entry CreateEntry(Class log_class, Level log_level, - const char* filename, unsigned int line_nr, const char* function, - const char* format, va_list args) { +Entry CreateEntry(Class log_class, Level log_level, const char* filename, unsigned int line_nr, + const char* function, const char* format, va_list args) { using std::chrono::steady_clock; using std::chrono::duration_cast; @@ -111,7 +116,8 @@ Entry CreateEntry(Class log_class, Level log_level, entry.log_class = log_class; entry.log_level = log_level; - snprintf(formatting_buffer.data(), formatting_buffer.size(), "%s:%s:%u", filename, function, line_nr); + snprintf(formatting_buffer.data(), formatting_buffer.size(), "%s:%s:%u", filename, function, + line_nr); entry.location = std::string(formatting_buffer.data()); vsnprintf(formatting_buffer.data(), formatting_buffer.size(), format, args); @@ -126,19 +132,16 @@ void SetFilter(Filter* new_filter) { filter = new_filter; } -void LogMessage(Class log_class, Level log_level, - const char* filename, unsigned int line_nr, const char* function, - const char* format, ...) { +void LogMessage(Class log_class, Level log_level, const char* filename, unsigned int line_nr, + const char* function, const char* format, ...) { if (filter != nullptr && !filter->CheckMessage(log_class, log_level)) return; va_list args; va_start(args, format); - Entry entry = CreateEntry(log_class, log_level, - filename, line_nr, function, format, args); + Entry entry = CreateEntry(log_class, log_level, filename, line_nr, function, format, args); va_end(args); PrintColoredMessage(entry); } - } diff --git a/src/common/logging/backend.h b/src/common/logging/backend.h index 795d42ebd..3fe88e4f6 100644 --- a/src/common/logging/backend.h +++ b/src/common/logging/backend.h @@ -44,10 +44,8 @@ const char* GetLogClassName(Class log_class); const char* GetLevelName(Level log_level); /// Creates a log entry by formatting the given source location, and message. -Entry CreateEntry(Class log_class, Level log_level, - const char* filename, unsigned int line_nr, const char* function, - const char* format, va_list args); +Entry CreateEntry(Class log_class, Level log_level, const char* filename, unsigned int line_nr, + const char* function, const char* format, va_list args); void SetFilter(Filter* filter); - } diff --git a/src/common/logging/filter.cpp b/src/common/logging/filter.cpp index 55cc8888a..186e0b621 100644 --- a/src/common/logging/filter.cpp +++ b/src/common/logging/filter.cpp @@ -4,8 +4,8 @@ #include -#include "common/logging/filter.h" #include "common/logging/backend.h" +#include "common/logging/filter.h" #include "common/string_util.h" namespace Log { @@ -63,11 +63,11 @@ static Class GetClassByName(const It begin, const It end) { } bool Filter::ParseFilterRule(const std::string::const_iterator begin, - const std::string::const_iterator end) { + const std::string::const_iterator end) { auto level_separator = std::find(begin, end, ':'); if (level_separator == end) { LOG_ERROR(Log, "Invalid log filter. Must specify a log level after `:`: %s", - std::string(begin, end).c_str()); + std::string(begin, end).c_str()); return false; } @@ -95,5 +95,4 @@ bool Filter::ParseFilterRule(const std::string::const_iterator begin, bool Filter::CheckMessage(Class log_class, Level level) const { return static_cast(level) >= static_cast(class_levels[static_cast(log_class)]); } - } diff --git a/src/common/logging/filter.h b/src/common/logging/filter.h index a2b4eca43..db526fead 100644 --- a/src/common/logging/filter.h +++ b/src/common/logging/filter.h @@ -42,7 +42,8 @@ public: * - `Service.FS:Trace` -- Sets the level of the Service.FS class to Trace. */ void ParseFilterString(const std::string& filter_str); - bool ParseFilterRule(const std::string::const_iterator start, const std::string::const_iterator end); + bool ParseFilterRule(const std::string::const_iterator start, + const std::string::const_iterator end); /// Matches class/level combination against the filter, returning true if it passed. bool CheckMessage(Class log_class, Level level) const; @@ -50,5 +51,4 @@ public: private: std::array class_levels; }; - } diff --git a/src/common/logging/log.h b/src/common/logging/log.h index c6910b1c7..a4b4750de 100644 --- a/src/common/logging/log.h +++ b/src/common/logging/log.h @@ -28,71 +28,73 @@ typedef u8 ClassType; /** * Specifies the sub-system that generated the log message. * - * @note If you add a new entry here, also add a corresponding one to `ALL_LOG_CLASSES` in backend.cpp. + * @note If you add a new entry here, also add a corresponding one to `ALL_LOG_CLASSES` in + * backend.cpp. */ enum class Class : ClassType { - Log, ///< Messages about the log system itself - Common, ///< Library routines - Common_Filesystem, ///< Filesystem interface library - Common_Memory, ///< Memory mapping and management functions - Core, ///< LLE emulation core - Core_ARM11, ///< ARM11 CPU core - Core_Timing, ///< CoreTiming functions - Config, ///< Emulator configuration (including commandline) - Debug, ///< Debugging tools - Debug_Emulated, ///< Debug messages from the emulated programs - Debug_GPU, ///< GPU debugging tools - Debug_Breakpoint, ///< Logging breakpoints and watchpoints - Debug_GDBStub, ///< GDB Stub - Kernel, ///< The HLE implementation of the CTR kernel - Kernel_SVC, ///< Kernel system calls - Service, ///< HLE implementation of system services. Each major service - /// should have its own subclass. - Service_SRV, ///< The SRV (Service Directory) implementation - Service_FRD, ///< The FRD (Friends) service - Service_FS, ///< The FS (Filesystem) service implementation - Service_ERR, ///< The ERR (Error) port implementation - Service_APT, ///< The APT (Applets) service - Service_GSP, ///< The GSP (GPU control) service - Service_AC, ///< The AC (WiFi status) service - Service_AM, ///< The AM (Application manager) service - Service_PTM, ///< The PTM (Power status & misc.) service - Service_LDR, ///< The LDR (3ds dll loader) service - Service_NDM, ///< The NDM (Network daemon manager) service - Service_NIM, ///< The NIM (Network interface manager) service - Service_NWM, ///< The NWM (Network wlan manager) service - Service_CAM, ///< The CAM (Camera) service - Service_CECD, ///< The CECD (StreetPass) service - Service_CFG, ///< The CFG (Configuration) service - Service_DSP, ///< The DSP (DSP control) service - Service_DLP, ///< The DLP (Download Play) service - Service_HID, ///< The HID (Human interface device) service - Service_SOC, ///< The SOC (Socket) service - Service_IR, ///< The IR service - Service_Y2R, ///< The Y2R (YUV to RGB conversion) service - HW, ///< Low-level hardware emulation - HW_Memory, ///< Memory-map and address translation - HW_LCD, ///< LCD register emulation - HW_GPU, ///< GPU control emulation - Frontend, ///< Emulator UI - Render, ///< Emulator video output and hardware acceleration - Render_Software, ///< Software renderer backend - Render_OpenGL, ///< OpenGL backend - Audio, ///< Audio emulation - Audio_DSP, ///< The HLE implementation of the DSP - Audio_Sink, ///< Emulator audio output backend - Loader, ///< ROM loader + Log, ///< Messages about the log system itself + Common, ///< Library routines + Common_Filesystem, ///< Filesystem interface library + Common_Memory, ///< Memory mapping and management functions + Core, ///< LLE emulation core + Core_ARM11, ///< ARM11 CPU core + Core_Timing, ///< CoreTiming functions + Config, ///< Emulator configuration (including commandline) + Debug, ///< Debugging tools + Debug_Emulated, ///< Debug messages from the emulated programs + Debug_GPU, ///< GPU debugging tools + Debug_Breakpoint, ///< Logging breakpoints and watchpoints + Debug_GDBStub, ///< GDB Stub + Kernel, ///< The HLE implementation of the CTR kernel + Kernel_SVC, ///< Kernel system calls + Service, ///< HLE implementation of system services. Each major service + /// should have its own subclass. + Service_SRV, ///< The SRV (Service Directory) implementation + Service_FRD, ///< The FRD (Friends) service + Service_FS, ///< The FS (Filesystem) service implementation + Service_ERR, ///< The ERR (Error) port implementation + Service_APT, ///< The APT (Applets) service + Service_GSP, ///< The GSP (GPU control) service + Service_AC, ///< The AC (WiFi status) service + Service_AM, ///< The AM (Application manager) service + Service_PTM, ///< The PTM (Power status & misc.) service + Service_LDR, ///< The LDR (3ds dll loader) service + Service_NDM, ///< The NDM (Network daemon manager) service + Service_NIM, ///< The NIM (Network interface manager) service + Service_NWM, ///< The NWM (Network wlan manager) service + Service_CAM, ///< The CAM (Camera) service + Service_CECD, ///< The CECD (StreetPass) service + Service_CFG, ///< The CFG (Configuration) service + Service_DSP, ///< The DSP (DSP control) service + Service_DLP, ///< The DLP (Download Play) service + Service_HID, ///< The HID (Human interface device) service + Service_SOC, ///< The SOC (Socket) service + Service_IR, ///< The IR service + Service_Y2R, ///< The Y2R (YUV to RGB conversion) service + HW, ///< Low-level hardware emulation + HW_Memory, ///< Memory-map and address translation + HW_LCD, ///< LCD register emulation + HW_GPU, ///< GPU control emulation + Frontend, ///< Emulator UI + Render, ///< Emulator video output and hardware acceleration + Render_Software, ///< Software renderer backend + Render_OpenGL, ///< OpenGL backend + Audio, ///< Audio emulation + Audio_DSP, ///< The HLE implementation of the DSP + Audio_Sink, ///< Emulator audio output backend + Loader, ///< ROM loader Count ///< Total number of logging classes }; /// Logs a message to the global logger. -void LogMessage(Class log_class, Level log_level, - const char* filename, unsigned int line_nr, const char* function, +void LogMessage(Class log_class, Level log_level, const char* filename, unsigned int line_nr, + const char* function, #ifdef _MSC_VER - _Printf_format_string_ + _Printf_format_string_ #endif - const char* format, ...) + const char* format, + ...) #ifdef __GNUC__ __attribute__((format(printf, 6, 7))) #endif @@ -100,17 +102,23 @@ void LogMessage(Class log_class, Level log_level, } // namespace Log -#define LOG_GENERIC(log_class, log_level, ...) \ +#define LOG_GENERIC(log_class, log_level, ...) \ ::Log::LogMessage(log_class, log_level, __FILE__, __LINE__, __func__, __VA_ARGS__) #ifdef _DEBUG -#define LOG_TRACE( log_class, ...) LOG_GENERIC(::Log::Class::log_class, ::Log::Level::Trace, __VA_ARGS__) +#define LOG_TRACE(log_class, ...) \ + LOG_GENERIC(::Log::Class::log_class, ::Log::Level::Trace, __VA_ARGS__) #else -#define LOG_TRACE( log_class, ...) (void(0)) +#define LOG_TRACE(log_class, ...) (void(0)) #endif -#define LOG_DEBUG( log_class, ...) LOG_GENERIC(::Log::Class::log_class, ::Log::Level::Debug, __VA_ARGS__) -#define LOG_INFO( log_class, ...) LOG_GENERIC(::Log::Class::log_class, ::Log::Level::Info, __VA_ARGS__) -#define LOG_WARNING( log_class, ...) LOG_GENERIC(::Log::Class::log_class, ::Log::Level::Warning, __VA_ARGS__) -#define LOG_ERROR( log_class, ...) LOG_GENERIC(::Log::Class::log_class, ::Log::Level::Error, __VA_ARGS__) -#define LOG_CRITICAL(log_class, ...) LOG_GENERIC(::Log::Class::log_class, ::Log::Level::Critical, __VA_ARGS__) +#define LOG_DEBUG(log_class, ...) \ + LOG_GENERIC(::Log::Class::log_class, ::Log::Level::Debug, __VA_ARGS__) +#define LOG_INFO(log_class, ...) \ + LOG_GENERIC(::Log::Class::log_class, ::Log::Level::Info, __VA_ARGS__) +#define LOG_WARNING(log_class, ...) \ + LOG_GENERIC(::Log::Class::log_class, ::Log::Level::Warning, __VA_ARGS__) +#define LOG_ERROR(log_class, ...) \ + LOG_GENERIC(::Log::Class::log_class, ::Log::Level::Error, __VA_ARGS__) +#define LOG_CRITICAL(log_class, ...) \ + LOG_GENERIC(::Log::Class::log_class, ::Log::Level::Critical, __VA_ARGS__) diff --git a/src/common/logging/text_formatter.cpp b/src/common/logging/text_formatter.cpp index de195b0f7..955358553 100644 --- a/src/common/logging/text_formatter.cpp +++ b/src/common/logging/text_formatter.cpp @@ -6,8 +6,8 @@ #include #ifdef _WIN32 -# define WIN32_LEAN_AND_MEAN -# include +#define WIN32_LEAN_AND_MEAN +#include #endif #include "common/logging/backend.h" @@ -44,15 +44,14 @@ const char* TrimSourcePath(const char* path, const char* root) { } void FormatLogMessage(const Entry& entry, char* out_text, size_t text_len) { - unsigned int time_seconds = static_cast(entry.timestamp.count() / 1000000); + unsigned int time_seconds = static_cast(entry.timestamp.count() / 1000000); unsigned int time_fractional = static_cast(entry.timestamp.count() % 1000000); const char* class_name = GetLogClassName(entry.log_class); const char* level_name = GetLevelName(entry.log_level); - snprintf(out_text, text_len, "[%4u.%06u] %s <%s> %s: %s", - time_seconds, time_fractional, class_name, level_name, - TrimSourcePath(entry.location.c_str()), entry.message.c_str()); + snprintf(out_text, text_len, "[%4u.%06u] %s <%s> %s: %s", time_seconds, time_fractional, + class_name, level_name, TrimSourcePath(entry.location.c_str()), entry.message.c_str()); } void PrintMessage(const Entry& entry) { @@ -72,38 +71,50 @@ void PrintColoredMessage(const Entry& entry) { WORD color = 0; switch (entry.log_level) { case Level::Trace: // Grey - color = FOREGROUND_INTENSITY; break; + color = FOREGROUND_INTENSITY; + break; case Level::Debug: // Cyan - color = FOREGROUND_GREEN | FOREGROUND_BLUE; break; + color = FOREGROUND_GREEN | FOREGROUND_BLUE; + break; case Level::Info: // Bright gray - color = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE; break; + color = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE; + break; case Level::Warning: // Bright yellow - color = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY; break; + color = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY; + break; case Level::Error: // Bright red - color = FOREGROUND_RED | FOREGROUND_INTENSITY; break; + color = FOREGROUND_RED | FOREGROUND_INTENSITY; + break; case Level::Critical: // Bright magenta - color = FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY; break; + color = FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY; + break; case Level::Count: UNREACHABLE(); } SetConsoleTextAttribute(console_handle, color); #else -# define ESC "\x1b" +#define ESC "\x1b" const char* color = ""; switch (entry.log_level) { case Level::Trace: // Grey - color = ESC "[1;30m"; break; + color = ESC "[1;30m"; + break; case Level::Debug: // Cyan - color = ESC "[0;36m"; break; + color = ESC "[0;36m"; + break; case Level::Info: // Bright gray - color = ESC "[0;37m"; break; + color = ESC "[0;37m"; + break; case Level::Warning: // Bright yellow - color = ESC "[1;33m"; break; + color = ESC "[1;33m"; + break; case Level::Error: // Bright red - color = ESC "[1;31m"; break; + color = ESC "[1;31m"; + break; case Level::Critical: // Bright magenta - color = ESC "[1;35m"; break; + color = ESC "[1;35m"; + break; case Level::Count: UNREACHABLE(); } @@ -117,8 +128,7 @@ void PrintColoredMessage(const Entry& entry) { SetConsoleTextAttribute(console_handle, original_info.wAttributes); #else fputs(ESC "[0m", stderr); -# undef ESC +#undef ESC #endif } - } diff --git a/src/common/logging/text_formatter.h b/src/common/logging/text_formatter.h index 5b82f043f..0da102bc6 100644 --- a/src/common/logging/text_formatter.h +++ b/src/common/logging/text_formatter.h @@ -28,5 +28,4 @@ void FormatLogMessage(const Entry& entry, char* out_text, size_t text_len); void PrintMessage(const Entry& entry); /// Prints the same message as `PrintMessage`, but colored acoording to the severity level. void PrintColoredMessage(const Entry& entry); - } -- cgit v1.2.3