Skip to content

Commit

Permalink
Temporary commit at 8/29/2023, 6:40:16 PM
Browse files Browse the repository at this point in the history
Differential Revision: https://www.internalfb.com/diff/D48763820?entry_point=27

fbshipit-source-id: 09a22057cbc7aee245cc480fff3e22ef91ad2532
  • Loading branch information
NickGerleman authored and facebook-github-bot committed Aug 30, 2023
1 parent e478de4 commit e33e511
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 78 deletions.
30 changes: 15 additions & 15 deletions yoga/Yoga.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,15 @@

#include <yoga/Yoga.h>

#include "log.h"
#include <yoga/debug/Log.h>
#include <yoga/debug/NodeToString.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(
Expand Down Expand Up @@ -1005,8 +1004,8 @@ YOGA_EXPORT void YGNodePrint(
const YGPrintOptions options) {
const auto node = static_cast<yoga::Node*>(nodeRef);
std::string str;
facebook::yoga::YGNodeToString(str, node, options, 0);
Log::log(node, YGLogLevelDebug, nullptr, str.c_str());
yoga::nodeToString(str, node, options, 0);
yoga::log(node, YGLogLevelDebug, nullptr, str.c_str());
}
#endif

Expand Down Expand Up @@ -3939,15 +3938,15 @@ bool YGLayoutNodeInternal(
: layoutMarkerData.cachedMeasures) += 1;

if (gPrintChanges && gPrintSkips) {
Log::log(
yoga::log(
node,
YGLogLevelVerbose,
nullptr,
"%s%d.{[skipped] ",
YGSpacer(depth),
depth);
node->print(layoutContext);
Log::log(
yoga::log(
node,
YGLogLevelVerbose,
nullptr,
Expand All @@ -3962,7 +3961,7 @@ bool YGLayoutNodeInternal(
}
} else {
if (gPrintChanges) {
Log::log(
yoga::log(
node,
YGLogLevelVerbose,
nullptr,
Expand All @@ -3971,7 +3970,7 @@ bool YGLayoutNodeInternal(
depth,
needToVisitNode ? "*" : "");
node->print(layoutContext);
Log::log(
yoga::log(
node,
YGLogLevelVerbose,
nullptr,
Expand Down Expand Up @@ -4001,7 +4000,7 @@ bool YGLayoutNodeInternal(
reason);

if (gPrintChanges) {
Log::log(
yoga::log(
node,
YGLogLevelVerbose,
nullptr,
Expand All @@ -4010,7 +4009,7 @@ bool YGLayoutNodeInternal(
depth,
needToVisitNode ? "*" : "");
node->print(layoutContext);
Log::log(
yoga::log(
node,
YGLogLevelVerbose,
nullptr,
Expand All @@ -4032,7 +4031,8 @@ bool YGLayoutNodeInternal(
}
if (layout->nextCachedMeasurementsIndex == YG_MAX_CACHED_RESULT_COUNT) {
if (gPrintChanges) {
Log::log(node, YGLogLevelVerbose, nullptr, "Out of cache entries!\n");
yoga::log(
node, YGLogLevelVerbose, nullptr, "Out of cache entries!\n");
}
layout->nextCachedMeasurementsIndex = 0;
}
Expand Down Expand Up @@ -4290,7 +4290,7 @@ YOGA_EXPORT void YGConfigSetLogger(const YGConfigRef config, YGLogger logger) {

void YGAssert(const bool condition, const char* message) {
if (!condition) {
Log::log(
yoga::log(
static_cast<yoga::Node*>(nullptr),
YGLogLevelFatal,
nullptr,
Expand All @@ -4305,7 +4305,7 @@ void YGAssertWithNode(
const bool condition,
const char* message) {
if (!condition) {
Log::log(
yoga::log(
static_cast<yoga::Node*>(node),
YGLogLevelFatal,
nullptr,
Expand All @@ -4320,7 +4320,7 @@ void YGAssertWithConfig(
const bool condition,
const char* message) {
if (!condition) {
Log::log(
yoga::log(
static_cast<yoga::Config*>(config),
YGLogLevelFatal,
nullptr,
Expand Down
14 changes: 5 additions & 9 deletions yoga/log.cpp → yoga/debug/Log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,9 @@
* LICENSE file in the root directory of this source tree.
*/

#include <yoga/Yoga.h>
#include <yoga/debug/Log.h>

#include "log.h"
#include <yoga/config/Config.h>
#include <yoga/node/Node.h>

namespace facebook::yoga::detail {
namespace facebook::yoga {

namespace {

Expand All @@ -29,7 +25,7 @@ void vlog(
}
} // namespace

YOGA_EXPORT void Log::log(
void log(
yoga::Node* node,
YGLogLevel level,
void* context,
Expand All @@ -47,7 +43,7 @@ YOGA_EXPORT void Log::log(
va_end(args);
}

void Log::log(
void log(
yoga::Config* config,
YGLogLevel level,
void* context,
Expand All @@ -59,4 +55,4 @@ void Log::log(
va_end(args);
}

} // namespace facebook::yoga::detail
} // namespace facebook::yoga
30 changes: 30 additions & 0 deletions yoga/debug/Log.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* 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
41 changes: 20 additions & 21 deletions yoga/YGNodePrint.cpp → yoga/debug/NodeToString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@

#include <yoga/YGEnums.h>

#include "YGNodePrint.h"
#include <yoga/debug/NodeToString.h>
#include <yoga/Yoga-internal.h>
#include <yoga/Utils.h>

namespace facebook::yoga {
typedef std::string string;

static void indent(string& base, uint32_t level) {
static void indent(std::string& base, uint32_t level) {
for (uint32_t i = 0; i < level; ++i) {
base.append(" ");
}
Expand All @@ -29,7 +28,7 @@ static bool areFourValuesEqual(const Style::Edges& four) {
YGValueEqual(four[0], four[3]);
}

static void appendFormattedString(string& str, const char* fmt, ...) {
static void appendFormattedString(std::string& str, const char* fmt, ...) {
va_list args;
va_start(args, fmt);
va_list argsCopy;
Expand All @@ -38,46 +37,46 @@ static void appendFormattedString(string& str, const char* fmt, ...) {
va_end(args);
vsnprintf(buf.data(), buf.size(), fmt, argsCopy);
va_end(argsCopy);
string result = string(buf.begin(), buf.end() - 1);
std::string result = std::string(buf.begin(), buf.end() - 1);
str.append(result);
}

static void appendFloatOptionalIfDefined(
string& base,
const string key,
std::string& base,
const std::string key,
const YGFloatOptional num) {
if (!num.isUndefined()) {
appendFormattedString(base, "%s: %g; ", key.c_str(), num.unwrap());
}
}

static void appendNumberIfNotUndefined(
string& base,
const string key,
std::string& base,
const std::string key,
const YGValue number) {
if (number.unit != YGUnitUndefined) {
if (number.unit == YGUnitAuto) {
base.append(key + ": auto; ");
} else {
string unit = number.unit == YGUnitPoint ? "px" : "%%";
std::string unit = number.unit == YGUnitPoint ? "px" : "%%";
appendFormattedString(
base, "%s: %g%s; ", key.c_str(), number.value, unit.c_str());
}
}
}

static void appendNumberIfNotAuto(
string& base,
const string& key,
std::string& base,
const std::string& key,
const YGValue number) {
if (number.unit != YGUnitAuto) {
appendNumberIfNotUndefined(base, key, number);
}
}

static void appendNumberIfNotZero(
string& base,
const string& str,
std::string& base,
const std::string& str,
const YGValue number) {
if (number.unit == YGUnitAuto) {
base.append(str + ": auto; ");
Expand All @@ -87,24 +86,24 @@ static void appendNumberIfNotZero(
}

static void appendEdges(
string& base,
const string& key,
std::string& base,
const std::string& key,
const Style::Edges& edges) {
if (areFourValuesEqual(edges)) {
auto edgeValue = yoga::Node::computeEdgeValueForColumn(
edges, YGEdgeLeft, CompactValue::ofZero());
appendNumberIfNotZero(base, key, edgeValue);
} else {
for (int edge = YGEdgeLeft; edge != YGEdgeAll; ++edge) {
string str = key + "-" + YGEdgeToString(static_cast<YGEdge>(edge));
std::string str = key + "-" + YGEdgeToString(static_cast<YGEdge>(edge));
appendNumberIfNotZero(base, str, edges[edge]);
}
}
}

static void appendEdgeIfNotUndefined(
string& base,
const string& str,
std::string& base,
const std::string& str,
const Style::Edges& edges,
const YGEdge edge) {
// TODO: this doesn't take RTL / YGEdgeStart / YGEdgeEnd into account
Expand All @@ -116,7 +115,7 @@ static void appendEdgeIfNotUndefined(
appendNumberIfNotUndefined(base, str, value);
}

void YGNodeToString(
void nodeToString(
std::string& str,
yoga::Node* node,
YGPrintOptions options,
Expand Down Expand Up @@ -232,7 +231,7 @@ void YGNodeToString(
if (options & YGPrintOptionsChildren && childCount > 0) {
for (uint32_t i = 0; i < childCount; i++) {
appendFormattedString(str, "\n");
YGNodeToString(str, node->getChild(i), options, level + 1);
nodeToString(str, node->getChild(i), options, level + 1);
}
appendFormattedString(str, "\n");
indent(str, level);
Expand Down
2 changes: 1 addition & 1 deletion yoga/YGNodePrint.h → yoga/debug/NodeToString.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

namespace facebook::yoga {

void YGNodeToString(
void nodeToString(
std::string& str,
yoga::Node* node,
YGPrintOptions options,
Expand Down
32 changes: 0 additions & 32 deletions yoga/log.h

This file was deleted.

0 comments on commit e33e511

Please sign in to comment.