Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C++ style enums 5/N: LogLevel #39447

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/react-native/ReactCommon/yoga/yoga/YGEnums.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

// @generated by enums.py

// clang-format off
#include <yoga/YGEnums.h>

const char* YGAlignToString(const YGAlign value) {
Expand Down
5 changes: 1 addition & 4 deletions packages/react-native/ReactCommon/yoga/yoga/YGEnums.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@
*/

// @generated by enums.py

// clang-format off
#pragma once
#include <yoga/YGMacros.h>

// clang-format off


YG_EXTERN_C_BEGIN

YG_ENUM_SEQ_DECL(
Expand Down
15 changes: 8 additions & 7 deletions packages/react-native/ReactCommon/yoga/yoga/Yoga.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ void YGNodeSetHasNewLayout(YGNodeRef node, bool hasNewLayout) {
}

YGNodeType YGNodeGetNodeType(YGNodeConstRef node) {
return resolveRef(node)->getNodeType();
return unscopedEnum(resolveRef(node)->getNodeType());
}

void YGNodeSetNodeType(YGNodeRef node, YGNodeType nodeType) {
return resolveRef(node)->setNodeType(nodeType);
return resolveRef(node)->setNodeType(scopedEnum(nodeType));
}

bool YGNodeIsDirty(YGNodeConstRef node) {
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -851,13 +851,14 @@ void YGConfigSetExperimentalFeatureEnabled(
const YGConfigRef config,
const YGExperimentalFeature feature,
const bool enabled) {
resolveRef(config)->setExperimentalFeatureEnabled(feature, enabled);
resolveRef(config)->setExperimentalFeatureEnabled(
scopedEnum(feature), enabled);
}

bool YGConfigIsExperimentalFeatureEnabled(
const YGConfigConstRef config,
const YGExperimentalFeature feature) {
return resolveRef(config)->isExperimentalFeatureEnabled(feature);
return resolveRef(config)->isExperimentalFeatureEnabled(scopedEnum(feature));
}

void YGConfigSetUseWebDefaults(const YGConfigRef config, const bool enabled) {
Expand All @@ -877,11 +878,11 @@ void* YGConfigGetContext(const YGConfigConstRef config) {
}

void YGConfigSetErrata(YGConfigRef config, YGErrata errata) {
resolveRef(config)->setErrata(errata);
resolveRef(config)->setErrata(scopedEnum(errata));
}

YGErrata YGConfigGetErrata(YGConfigConstRef config) {
return resolveRef(config)->getErrata();
return unscopedEnum(resolveRef(config)->getErrata());
}

void YGConfigSetCloneNodeFunc(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ static void computeFlexBasisForChild(
if (!resolvedFlexBasis.isUndefined() && !yoga::isUndefined(mainAxisSize)) {
if (child->getLayout().computedFlexBasis.isUndefined() ||
(child->getConfig()->isExperimentalFeatureEnabled(
YGExperimentalFeatureWebFlexBasis) &&
ExperimentalFeature::WebFlexBasis) &&
child->getLayout().computedFlexBasisGeneration != generationCount)) {
const FloatOptional paddingAndBorder =
FloatOptional(paddingAndBorderForAxis(child, mainAxis, ownerWidth));
Expand Down Expand Up @@ -479,7 +479,7 @@ static void layoutAbsoluteChild(
leadingEdge(mainAxis));
} else if (
node->getConfig()->isExperimentalFeatureEnabled(
YGExperimentalFeatureAbsolutePercentageAgainstPaddingEdge) &&
ExperimentalFeature::AbsolutePercentageAgainstPaddingEdge) &&
child->isLeadingPositionDefined(mainAxis)) {
child->setLayoutPosition(
child->getLeadingPosition(
Expand Down Expand Up @@ -526,7 +526,7 @@ static void layoutAbsoluteChild(
leadingEdge(crossAxis));
} else if (
node->getConfig()->isExperimentalFeatureEnabled(
YGExperimentalFeatureAbsolutePercentageAgainstPaddingEdge) &&
ExperimentalFeature::AbsolutePercentageAgainstPaddingEdge) &&
child->isLeadingPositionDefined(crossAxis)) {
child->setLayoutPosition(
child->getLeadingPosition(
Expand Down Expand Up @@ -1755,7 +1755,7 @@ static void calculateLayoutImpl(
availableInnerMainDim = maxInnerMainDim;
} else {
bool useLegacyStretchBehaviour =
node->hasErrata(YGErrataStretchFlexBasis);
node->hasErrata(Errata::StretchFlexBasis);

if (!useLegacyStretchBehaviour &&
((!yoga::isUndefined(flexLine.layout.totalFlexGrowFactors) &&
Expand Down Expand Up @@ -2323,7 +2323,7 @@ static void calculateLayoutImpl(
}
const bool absolutePercentageAgainstPaddingEdge =
node->getConfig()->isExperimentalFeatureEnabled(
YGExperimentalFeatureAbsolutePercentageAgainstPaddingEdge);
ExperimentalFeature::AbsolutePercentageAgainstPaddingEdge);

layoutAbsoluteChild(
node,
Expand Down Expand Up @@ -2526,14 +2526,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),
Expand All @@ -2547,15 +2547,15 @@ bool calculateLayoutInternal(
if (gPrintChanges) {
yoga::log(
node,
YGLogLevelVerbose,
LogLevel::Verbose,
"%s%d.{%s",
spacerWithLength(depth),
depth,
needToVisitNode ? "*" : "");
node->print();
yoga::log(
node,
YGLogLevelVerbose,
LogLevel::Verbose,
"wm: %s, hm: %s, aw: %f ah: %f %s\n",
measureModeName(widthMeasureMode, performLayout),
measureModeName(heightMeasureMode, performLayout),
Expand All @@ -2582,15 +2582,15 @@ bool calculateLayoutInternal(
if (gPrintChanges) {
yoga::log(
node,
YGLogLevelVerbose,
LogLevel::Verbose,
"%s%d.}%s",
spacerWithLength(depth),
depth,
needToVisitNode ? "*" : "");
node->print();
yoga::log(
node,
YGLogLevelVerbose,
LogLevel::Verbose,
"wm: %s, hm: %s, d: (%f, %f) %s\n",
measureModeName(widthMeasureMode, performLayout),
measureModeName(heightMeasureMode, performLayout),
Expand All @@ -2609,7 +2609,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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ void roundLayoutResultsToPixelGrid(
if (pointScaleFactor != 0.0f) {
// If a node has a custom measure function we never want to round down its
// size as this could lead to unwanted text truncation.
const bool textRounding = node->getNodeType() == YGNodeTypeText;
const bool textRounding = node->getNodeType() == NodeType::Text;

node->setLayoutPosition(
roundValueToPixelGrid(nodeLeft, pointScaleFactor, false, textRounding),
Expand Down
26 changes: 13 additions & 13 deletions packages/react-native/ReactCommon/yoga/yoga/config/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,37 +41,37 @@ bool Config::shouldPrintTree() const {
}

void Config::setExperimentalFeatureEnabled(
YGExperimentalFeature feature,
ExperimentalFeature feature,
bool enabled) {
experimentalFeatures_.set(feature, enabled);
experimentalFeatures_.set(static_cast<size_t>(feature), enabled);
}

bool Config::isExperimentalFeatureEnabled(YGExperimentalFeature feature) const {
return experimentalFeatures_.test(feature);
bool Config::isExperimentalFeatureEnabled(ExperimentalFeature feature) const {
return experimentalFeatures_.test(static_cast<size_t>(feature));
}

EnumBitset<YGExperimentalFeature> Config::getEnabledExperiments() const {
ExperimentalFeatureSet Config::getEnabledExperiments() const {
return experimentalFeatures_;
}

void Config::setErrata(YGErrata errata) {
void Config::setErrata(Errata errata) {
errata_ = errata;
}

void Config::addErrata(YGErrata errata) {
void Config::addErrata(Errata errata) {
errata_ |= errata;
}

void Config::removeErrata(YGErrata errata) {
void Config::removeErrata(Errata errata) {
errata_ &= (~errata);
}

YGErrata Config::getErrata() const {
Errata Config::getErrata() const {
return errata_;
}

bool Config::hasErrata(YGErrata errata) const {
return (errata_ & errata) != YGErrataNone;
bool Config::hasErrata(Errata errata) const {
return (errata_ & errata) != Errata::None;
}

void Config::setPointScaleFactor(float pointScaleFactor) {
Expand All @@ -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) {
Expand Down
32 changes: 18 additions & 14 deletions packages/react-native/ReactCommon/yoga/yoga/config/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@

#pragma once

#include <bitset>

#include <yoga/Yoga.h>
#include <yoga/bits/EnumBitset.h>
#include <yoga/enums/Errata.h>
#include <yoga/enums/ExperimentalFeature.h>
#include <yoga/enums/LogLevel.h>

// Tag struct used to form the opaque YGConfigRef for the public C API
struct YGConfig {};
Expand All @@ -18,6 +22,8 @@ namespace facebook::yoga {
class Config;
class Node;

using ExperimentalFeatureSet = std::bitset<ordinalCount<ExperimentalFeature>()>;

// Whether moving a node from an old to new config should dirty previously
// calculated layout results.
bool configUpdateInvalidatesLayout(
Expand All @@ -43,17 +49,15 @@ class YG_EXPORT Config : public ::YGConfig {
void setShouldPrintTree(bool printTree);
bool shouldPrintTree() const;

void setExperimentalFeatureEnabled(
YGExperimentalFeature feature,
bool enabled);
bool isExperimentalFeatureEnabled(YGExperimentalFeature feature) const;
EnumBitset<YGExperimentalFeature> getEnabledExperiments() const;
void setExperimentalFeatureEnabled(ExperimentalFeature feature, bool enabled);
bool isExperimentalFeatureEnabled(ExperimentalFeature feature) const;
ExperimentalFeatureSet getEnabledExperiments() const;

void setErrata(YGErrata errata);
void addErrata(YGErrata errata);
void removeErrata(YGErrata errata);
YGErrata getErrata() const;
bool hasErrata(YGErrata errata) const;
void setErrata(Errata errata);
void addErrata(Errata errata);
void removeErrata(Errata errata);
Errata getErrata() const;
bool hasErrata(Errata errata) const;

void setPointScaleFactor(float pointScaleFactor);
float getPointScaleFactor() const;
Expand All @@ -64,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;

Expand All @@ -79,8 +83,8 @@ class YG_EXPORT Config : public ::YGConfig {
YGLogger logger_;

ConfigFlags flags_{};
EnumBitset<YGExperimentalFeature> experimentalFeatures_{};
YGErrata errata_ = YGErrataNone;
ExperimentalFeatureSet experimentalFeatures_{};
Errata errata_ = Errata::None;
float pointScaleFactor_ = 1.0f;
void* context_ = nullptr;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand All @@ -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);
}
}
Expand All @@ -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);
}
}
Expand Down
10 changes: 5 additions & 5 deletions packages/react-native/ReactCommon/yoga/yoga/debug/Log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand All @@ -50,7 +50,7 @@ void log(

void log(
const yoga::Config* config,
YGLogLevel level,
LogLevel level,
const char* format,
...) noexcept {
va_list args;
Expand Down
Loading