From 274df6ffb098aae5d22cbc0ba21c2481000de008 Mon Sep 17 00:00:00 2001 From: Nick Gerleman Date: Thu, 14 Sep 2023 17:22:28 -0700 Subject: [PATCH] C++ style enums 5/N: LogLevel (#1387) Summary: Pull Request resolved: https://github.com/facebook/yoga/pull/1387 X-link: https://github.com/facebook/react-native/pull/39447 This converts usages of YGLogLevel to LogLevel Reviewed By: rozele Differential Revision: D49270695 fbshipit-source-id: 91e02e92fc93c6c03a1f01914d281499335e2e69 --- yoga/Yoga.cpp | 2 +- yoga/algorithm/CalculateLayout.cpp | 14 +++++++------- yoga/config/Config.cpp | 4 ++-- yoga/config/Config.h | 3 ++- yoga/debug/AssertFatal.cpp | 6 +++--- yoga/debug/Log.cpp | 10 +++++----- yoga/debug/Log.h | 8 ++++---- 7 files changed, 24 insertions(+), 23 deletions(-) diff --git a/yoga/Yoga.cpp b/yoga/Yoga.cpp index 63678fa63d..f144c1508b 100644 --- a/yoga/Yoga.cpp +++ b/yoga/Yoga.cpp @@ -805,7 +805,7 @@ void YGNodePrint(const YGNodeConstRef nodeRef, const YGPrintOptions options) { const auto node = resolveRef(nodeRef); std::string str; yoga::nodeToString(str, node, options, 0); - yoga::log(node, YGLogLevelDebug, str.c_str()); + yoga::log(node, LogLevel::Debug, str.c_str()); } #endif diff --git a/yoga/algorithm/CalculateLayout.cpp b/yoga/algorithm/CalculateLayout.cpp index d67741734c..31710a4be9 100644 --- a/yoga/algorithm/CalculateLayout.cpp +++ b/yoga/algorithm/CalculateLayout.cpp @@ -2527,14 +2527,14 @@ bool calculateLayoutInternal( if (gPrintChanges && gPrintSkips) { yoga::log( node, - YGLogLevelVerbose, + LogLevel::Verbose, "%s%d.{[skipped] ", spacerWithLength(depth), depth); node->print(); yoga::log( node, - YGLogLevelVerbose, + LogLevel::Verbose, "wm: %s, hm: %s, aw: %f ah: %f => d: (%f, %f) %s\n", measureModeName(widthMeasureMode, performLayout), measureModeName(heightMeasureMode, performLayout), @@ -2548,7 +2548,7 @@ bool calculateLayoutInternal( if (gPrintChanges) { yoga::log( node, - YGLogLevelVerbose, + LogLevel::Verbose, "%s%d.{%s", spacerWithLength(depth), depth, @@ -2556,7 +2556,7 @@ bool calculateLayoutInternal( node->print(); yoga::log( node, - YGLogLevelVerbose, + LogLevel::Verbose, "wm: %s, hm: %s, aw: %f ah: %f %s\n", measureModeName(widthMeasureMode, performLayout), measureModeName(heightMeasureMode, performLayout), @@ -2583,7 +2583,7 @@ bool calculateLayoutInternal( if (gPrintChanges) { yoga::log( node, - YGLogLevelVerbose, + LogLevel::Verbose, "%s%d.}%s", spacerWithLength(depth), depth, @@ -2591,7 +2591,7 @@ bool calculateLayoutInternal( node->print(); yoga::log( node, - YGLogLevelVerbose, + LogLevel::Verbose, "wm: %s, hm: %s, d: (%f, %f) %s\n", measureModeName(widthMeasureMode, performLayout), measureModeName(heightMeasureMode, performLayout), @@ -2610,7 +2610,7 @@ bool calculateLayoutInternal( if (layout->nextCachedMeasurementsIndex == LayoutResults::MaxCachedMeasurements) { if (gPrintChanges) { - yoga::log(node, YGLogLevelVerbose, "Out of cache entries!\n"); + yoga::log(node, LogLevel::Verbose, "Out of cache entries!\n"); } layout->nextCachedMeasurementsIndex = 0; } diff --git a/yoga/config/Config.cpp b/yoga/config/Config.cpp index 85f715bcd8..721588ee0a 100644 --- a/yoga/config/Config.cpp +++ b/yoga/config/Config.cpp @@ -96,10 +96,10 @@ void Config::setLogger(YGLogger logger) { void Config::log( const yoga::Node* node, - YGLogLevel logLevel, + LogLevel logLevel, const char* format, va_list args) const { - logger_(this, node, logLevel, format, args); + logger_(this, node, unscopedEnum(logLevel), format, args); } void Config::setCloneNodeCallback(YGCloneNodeFunc cloneNode) { diff --git a/yoga/config/Config.h b/yoga/config/Config.h index e910ea04bc..227aa598bf 100644 --- a/yoga/config/Config.h +++ b/yoga/config/Config.h @@ -12,6 +12,7 @@ #include #include #include +#include // Tag struct used to form the opaque YGConfigRef for the public C API struct YGConfig {}; @@ -67,7 +68,7 @@ class YG_EXPORT Config : public ::YGConfig { void setLogger(YGLogger logger); void log( const yoga::Node* node, - YGLogLevel logLevel, + LogLevel logLevel, const char* format, va_list args) const; diff --git a/yoga/debug/AssertFatal.cpp b/yoga/debug/AssertFatal.cpp index d83c8cc56e..2388a74453 100644 --- a/yoga/debug/AssertFatal.cpp +++ b/yoga/debug/AssertFatal.cpp @@ -22,7 +22,7 @@ namespace facebook::yoga { void assertFatal(const bool condition, const char* message) { if (!condition) { - yoga::log(YGLogLevelFatal, "%s\n", message); + yoga::log(LogLevel::Fatal, "%s\n", message); fatalWithMessage(message); } } @@ -32,7 +32,7 @@ void assertFatalWithNode( const bool condition, const char* message) { if (!condition) { - yoga::log(node, YGLogLevelFatal, "%s\n", message); + yoga::log(node, LogLevel::Fatal, "%s\n", message); fatalWithMessage(message); } } @@ -42,7 +42,7 @@ void assertFatalWithConfig( const bool condition, const char* message) { if (!condition) { - yoga::log(config, YGLogLevelFatal, "%s\n", message); + yoga::log(config, LogLevel::Fatal, "%s\n", message); fatalWithMessage(message); } } diff --git a/yoga/debug/Log.cpp b/yoga/debug/Log.cpp index c16547ae34..9b525d8a8e 100644 --- a/yoga/debug/Log.cpp +++ b/yoga/debug/Log.cpp @@ -18,18 +18,18 @@ namespace { void vlog( const yoga::Config* config, const yoga::Node* node, - YGLogLevel level, + LogLevel level, const char* format, va_list args) { if (config == nullptr) { - getDefaultLogger()(nullptr, node, level, format, args); + getDefaultLogger()(nullptr, node, unscopedEnum(level), format, args); } else { config->log(node, level, format, args); } } } // namespace -void log(YGLogLevel level, const char* format, ...) noexcept { +void log(LogLevel level, const char* format, ...) noexcept { va_list args; va_start(args, format); vlog(nullptr, nullptr, level, format, args); @@ -38,7 +38,7 @@ void log(YGLogLevel level, const char* format, ...) noexcept { void log( const yoga::Node* node, - YGLogLevel level, + LogLevel level, const char* format, ...) noexcept { va_list args; @@ -50,7 +50,7 @@ void log( void log( const yoga::Config* config, - YGLogLevel level, + LogLevel level, const char* format, ...) noexcept { va_list args; diff --git a/yoga/debug/Log.h b/yoga/debug/Log.h index 59a8b2e0db..94dc0e0ced 100644 --- a/yoga/debug/Log.h +++ b/yoga/debug/Log.h @@ -9,23 +9,23 @@ #include -#include #include +#include #include namespace facebook::yoga { -void log(YGLogLevel level, const char* format, ...) noexcept; +void log(LogLevel level, const char* format, ...) noexcept; void log( const yoga::Node* node, - YGLogLevel level, + LogLevel level, const char* message, ...) noexcept; void log( const yoga::Config* config, - YGLogLevel level, + LogLevel level, const char* format, ...) noexcept;