Revert D48763820: C++ Cleanup 4/N: Reorganize Log and YGNodePrint
Differential Revision: D48763820 Original commit changeset: 7e3ed7354497 Original Phabricator Diff: D48763820 fbshipit-source-id: 1bea996374f14481160aba8f87940c00e229aa69
This commit is contained in:
committed by
Facebook GitHub Bot
parent
4c0e89e492
commit
6ca56e87ce
@@ -11,13 +11,14 @@
|
||||
|
||||
#include <yoga/YGEnums.h>
|
||||
|
||||
#include <yoga/debug/NodeToString.h>
|
||||
#include "YGNodePrint.h"
|
||||
#include <yoga/Yoga-internal.h>
|
||||
#include <yoga/Utils.h>
|
||||
|
||||
namespace facebook::yoga {
|
||||
typedef std::string string;
|
||||
|
||||
static void indent(std::string& base, uint32_t level) {
|
||||
static void indent(string& base, uint32_t level) {
|
||||
for (uint32_t i = 0; i < level; ++i) {
|
||||
base.append(" ");
|
||||
}
|
||||
@@ -28,7 +29,7 @@ static bool areFourValuesEqual(const Style::Edges& four) {
|
||||
YGValueEqual(four[0], four[3]);
|
||||
}
|
||||
|
||||
static void appendFormattedString(std::string& str, const char* fmt, ...) {
|
||||
static void appendFormattedString(string& str, const char* fmt, ...) {
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
va_list argsCopy;
|
||||
@@ -37,13 +38,13 @@ static void appendFormattedString(std::string& str, const char* fmt, ...) {
|
||||
va_end(args);
|
||||
vsnprintf(buf.data(), buf.size(), fmt, argsCopy);
|
||||
va_end(argsCopy);
|
||||
std::string result = std::string(buf.begin(), buf.end() - 1);
|
||||
string result = string(buf.begin(), buf.end() - 1);
|
||||
str.append(result);
|
||||
}
|
||||
|
||||
static void appendFloatOptionalIfDefined(
|
||||
std::string& base,
|
||||
const std::string key,
|
||||
string& base,
|
||||
const string key,
|
||||
const YGFloatOptional num) {
|
||||
if (!num.isUndefined()) {
|
||||
appendFormattedString(base, "%s: %g; ", key.c_str(), num.unwrap());
|
||||
@@ -51,14 +52,14 @@ static void appendFloatOptionalIfDefined(
|
||||
}
|
||||
|
||||
static void appendNumberIfNotUndefined(
|
||||
std::string& base,
|
||||
const std::string key,
|
||||
string& base,
|
||||
const string key,
|
||||
const YGValue number) {
|
||||
if (number.unit != YGUnitUndefined) {
|
||||
if (number.unit == YGUnitAuto) {
|
||||
base.append(key + ": auto; ");
|
||||
} else {
|
||||
std::string unit = number.unit == YGUnitPoint ? "px" : "%%";
|
||||
string unit = number.unit == YGUnitPoint ? "px" : "%%";
|
||||
appendFormattedString(
|
||||
base, "%s: %g%s; ", key.c_str(), number.value, unit.c_str());
|
||||
}
|
||||
@@ -66,8 +67,8 @@ static void appendNumberIfNotUndefined(
|
||||
}
|
||||
|
||||
static void appendNumberIfNotAuto(
|
||||
std::string& base,
|
||||
const std::string& key,
|
||||
string& base,
|
||||
const string& key,
|
||||
const YGValue number) {
|
||||
if (number.unit != YGUnitAuto) {
|
||||
appendNumberIfNotUndefined(base, key, number);
|
||||
@@ -75,8 +76,8 @@ static void appendNumberIfNotAuto(
|
||||
}
|
||||
|
||||
static void appendNumberIfNotZero(
|
||||
std::string& base,
|
||||
const std::string& str,
|
||||
string& base,
|
||||
const string& str,
|
||||
const YGValue number) {
|
||||
if (number.unit == YGUnitAuto) {
|
||||
base.append(str + ": auto; ");
|
||||
@@ -86,8 +87,8 @@ static void appendNumberIfNotZero(
|
||||
}
|
||||
|
||||
static void appendEdges(
|
||||
std::string& base,
|
||||
const std::string& key,
|
||||
string& base,
|
||||
const string& key,
|
||||
const Style::Edges& edges) {
|
||||
if (areFourValuesEqual(edges)) {
|
||||
auto edgeValue = yoga::Node::computeEdgeValueForColumn(
|
||||
@@ -95,15 +96,15 @@ static void appendEdges(
|
||||
appendNumberIfNotZero(base, key, edgeValue);
|
||||
} else {
|
||||
for (int edge = YGEdgeLeft; edge != YGEdgeAll; ++edge) {
|
||||
std::string str = key + "-" + YGEdgeToString(static_cast<YGEdge>(edge));
|
||||
string str = key + "-" + YGEdgeToString(static_cast<YGEdge>(edge));
|
||||
appendNumberIfNotZero(base, str, edges[edge]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void appendEdgeIfNotUndefined(
|
||||
std::string& base,
|
||||
const std::string& str,
|
||||
string& base,
|
||||
const string& str,
|
||||
const Style::Edges& edges,
|
||||
const YGEdge edge) {
|
||||
// TODO: this doesn't take RTL / YGEdgeStart / YGEdgeEnd into account
|
||||
@@ -115,7 +116,7 @@ static void appendEdgeIfNotUndefined(
|
||||
appendNumberIfNotUndefined(base, str, value);
|
||||
}
|
||||
|
||||
void nodeToString(
|
||||
void YGNodeToString(
|
||||
std::string& str,
|
||||
yoga::Node* node,
|
||||
YGPrintOptions options,
|
||||
@@ -231,7 +232,7 @@ void nodeToString(
|
||||
if (options & YGPrintOptionsChildren && childCount > 0) {
|
||||
for (uint32_t i = 0; i < childCount; i++) {
|
||||
appendFormattedString(str, "\n");
|
||||
nodeToString(str, node->getChild(i), options, level + 1);
|
||||
YGNodeToString(str, node->getChild(i), options, level + 1);
|
||||
}
|
||||
appendFormattedString(str, "\n");
|
||||
indent(str, level);
|
@@ -16,7 +16,7 @@
|
||||
|
||||
namespace facebook::yoga {
|
||||
|
||||
void nodeToString(
|
||||
void YGNodeToString(
|
||||
std::string& str,
|
||||
yoga::Node* node,
|
||||
YGPrintOptions options,
|
@@ -13,15 +13,16 @@
|
||||
|
||||
#include <yoga/Yoga.h>
|
||||
|
||||
#include <yoga/debug/Log.h>
|
||||
#include <yoga/debug/NodeToString.h>
|
||||
#include "log.h"
|
||||
#include <yoga/Utils.h>
|
||||
#include <yoga/node/Node.h>
|
||||
#include "YGNodePrint.h"
|
||||
#include <yoga/Yoga-internal.h>
|
||||
#include "event/event.h"
|
||||
|
||||
using namespace facebook;
|
||||
using namespace facebook::yoga;
|
||||
using detail::Log;
|
||||
|
||||
#ifdef ANDROID
|
||||
static int YGAndroidLog(
|
||||
@@ -1004,8 +1005,8 @@ YOGA_EXPORT void YGNodePrint(
|
||||
const YGPrintOptions options) {
|
||||
const auto node = static_cast<yoga::Node*>(nodeRef);
|
||||
std::string str;
|
||||
yoga::nodeToString(str, node, options, 0);
|
||||
yoga::log(node, YGLogLevelDebug, nullptr, str.c_str());
|
||||
facebook::yoga::YGNodeToString(str, node, options, 0);
|
||||
Log::log(node, YGLogLevelDebug, nullptr, str.c_str());
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -3938,7 +3939,7 @@ bool YGLayoutNodeInternal(
|
||||
: layoutMarkerData.cachedMeasures) += 1;
|
||||
|
||||
if (gPrintChanges && gPrintSkips) {
|
||||
yoga::log(
|
||||
Log::log(
|
||||
node,
|
||||
YGLogLevelVerbose,
|
||||
nullptr,
|
||||
@@ -3946,7 +3947,7 @@ bool YGLayoutNodeInternal(
|
||||
YGSpacer(depth),
|
||||
depth);
|
||||
node->print(layoutContext);
|
||||
yoga::log(
|
||||
Log::log(
|
||||
node,
|
||||
YGLogLevelVerbose,
|
||||
nullptr,
|
||||
@@ -3961,7 +3962,7 @@ bool YGLayoutNodeInternal(
|
||||
}
|
||||
} else {
|
||||
if (gPrintChanges) {
|
||||
yoga::log(
|
||||
Log::log(
|
||||
node,
|
||||
YGLogLevelVerbose,
|
||||
nullptr,
|
||||
@@ -3970,7 +3971,7 @@ bool YGLayoutNodeInternal(
|
||||
depth,
|
||||
needToVisitNode ? "*" : "");
|
||||
node->print(layoutContext);
|
||||
yoga::log(
|
||||
Log::log(
|
||||
node,
|
||||
YGLogLevelVerbose,
|
||||
nullptr,
|
||||
@@ -4000,7 +4001,7 @@ bool YGLayoutNodeInternal(
|
||||
reason);
|
||||
|
||||
if (gPrintChanges) {
|
||||
yoga::log(
|
||||
Log::log(
|
||||
node,
|
||||
YGLogLevelVerbose,
|
||||
nullptr,
|
||||
@@ -4009,7 +4010,7 @@ bool YGLayoutNodeInternal(
|
||||
depth,
|
||||
needToVisitNode ? "*" : "");
|
||||
node->print(layoutContext);
|
||||
yoga::log(
|
||||
Log::log(
|
||||
node,
|
||||
YGLogLevelVerbose,
|
||||
nullptr,
|
||||
@@ -4031,8 +4032,7 @@ bool YGLayoutNodeInternal(
|
||||
}
|
||||
if (layout->nextCachedMeasurementsIndex == YG_MAX_CACHED_RESULT_COUNT) {
|
||||
if (gPrintChanges) {
|
||||
yoga::log(
|
||||
node, YGLogLevelVerbose, nullptr, "Out of cache entries!\n");
|
||||
Log::log(node, YGLogLevelVerbose, nullptr, "Out of cache entries!\n");
|
||||
}
|
||||
layout->nextCachedMeasurementsIndex = 0;
|
||||
}
|
||||
@@ -4290,7 +4290,7 @@ YOGA_EXPORT void YGConfigSetLogger(const YGConfigRef config, YGLogger logger) {
|
||||
|
||||
void YGAssert(const bool condition, const char* message) {
|
||||
if (!condition) {
|
||||
yoga::log(
|
||||
Log::log(
|
||||
static_cast<yoga::Node*>(nullptr),
|
||||
YGLogLevelFatal,
|
||||
nullptr,
|
||||
@@ -4305,7 +4305,7 @@ void YGAssertWithNode(
|
||||
const bool condition,
|
||||
const char* message) {
|
||||
if (!condition) {
|
||||
yoga::log(
|
||||
Log::log(
|
||||
static_cast<yoga::Node*>(node),
|
||||
YGLogLevelFatal,
|
||||
nullptr,
|
||||
@@ -4320,7 +4320,7 @@ void YGAssertWithConfig(
|
||||
const bool condition,
|
||||
const char* message) {
|
||||
if (!condition) {
|
||||
yoga::log(
|
||||
Log::log(
|
||||
static_cast<yoga::Config*>(config),
|
||||
YGLogLevelFatal,
|
||||
nullptr,
|
||||
|
@@ -1,30 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <yoga/YGEnums.h>
|
||||
#include <yoga/node/Node.h>
|
||||
#include <yoga/config/Config.h>
|
||||
|
||||
namespace facebook::yoga {
|
||||
|
||||
void log(
|
||||
yoga::Node* node,
|
||||
YGLogLevel level,
|
||||
void*,
|
||||
const char* message,
|
||||
...) noexcept;
|
||||
|
||||
void log(
|
||||
yoga::Config* config,
|
||||
YGLogLevel level,
|
||||
void*,
|
||||
const char* format,
|
||||
...) noexcept;
|
||||
|
||||
} // namespace facebook::yoga
|
@@ -5,9 +5,13 @@
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#include <yoga/debug/Log.h>
|
||||
#include <yoga/Yoga.h>
|
||||
|
||||
namespace facebook::yoga {
|
||||
#include "log.h"
|
||||
#include <yoga/config/Config.h>
|
||||
#include <yoga/node/Node.h>
|
||||
|
||||
namespace facebook::yoga::detail {
|
||||
|
||||
namespace {
|
||||
|
||||
@@ -25,7 +29,7 @@ void vlog(
|
||||
}
|
||||
} // namespace
|
||||
|
||||
void log(
|
||||
YOGA_EXPORT void Log::log(
|
||||
yoga::Node* node,
|
||||
YGLogLevel level,
|
||||
void* context,
|
||||
@@ -43,7 +47,7 @@ void log(
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void log(
|
||||
void Log::log(
|
||||
yoga::Config* config,
|
||||
YGLogLevel level,
|
||||
void* context,
|
||||
@@ -55,4 +59,4 @@ void log(
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
} // namespace facebook::yoga
|
||||
} // namespace facebook::yoga::detail
|
32
yoga/log.h
Normal file
32
yoga/log.h
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <yoga/YGEnums.h>
|
||||
#include <yoga/node/Node.h>
|
||||
#include <yoga/config/Config.h>
|
||||
|
||||
namespace facebook::yoga::detail {
|
||||
|
||||
struct Log {
|
||||
static void log(
|
||||
yoga::Node* node,
|
||||
YGLogLevel level,
|
||||
void*,
|
||||
const char* message,
|
||||
...) noexcept;
|
||||
|
||||
static void log(
|
||||
yoga::Config* config,
|
||||
YGLogLevel level,
|
||||
void*,
|
||||
const char* format,
|
||||
...) noexcept;
|
||||
};
|
||||
|
||||
} // namespace facebook::yoga::detail
|
Reference in New Issue
Block a user