C++ Cleanup 9/N: YGAssert (#1353)
Summary: X-link: https://github.com/facebook/react-native/pull/39201 Pull Request resolved: https://github.com/facebook/yoga/pull/1353 ## This diff This moves and renames `YGAssert`, and removes it from the public API, since external users should not need to call into internal Yoga assert functions, and the current API prevents us from making this a macro later to include the condition in the message. ## This stack The organization of the C++ internals of Yoga are in need of attention. 1. Some of the C++ internals are namespaced, but others not. 2. Some of the namespaces include `detail`, but are meant to be used outside of the translation unit (FB Clang Tidy rules warn on any usage of these) 2. Most of the files are in a flat hierarchy, except for event tracing in its own folder 3. Some files and functions begin with YG, others don’t 4. Some functions are uppercase, others are not 5. Almost all of the interesting logic is in Yoga.cpp, and the file is too large to reason about 6. There are multiple grab bag files where folks put random functions they need in (Utils, BitUtils, Yoga-Internal.h) 7. There is no clear indication from file structure or type naming what is private vs not 8. Handles like `YGNodeRef` and `YGConfigRef` can be used to access internals just by importing headers This stack does some much needed spring cleaning: 1. All non-public headers and C++ implementation details are in separate folders from the root level `yoga`. This will give us room to split up logic and add more files without too large a flat hierarchy 3. All private C++ internals are under the `facebook::yoga` namespace. Details namespaces are only ever used within the same header, as they are intended 4. Utils files are split 5. Most C++ internals drop the YG prefix 6. Most C++ internal function names are all lower camel case 7. We start to split up Yoga.cpp 8. Every header beginning with YG or at the top-level directory is public and C only, with the exception of Yoga-Internal.h which has non-public functions for bindings 9. It is not possible to use private APIs without static casting handles to internal classes This will give us more leeway to continue splitting monolithic files, and consistent guidelines for style in new files as well. These changes should not be breaking to any project using only public Yoga headers. This includes every usage of Yoga in fbsource except for RN Fabric which is currently tied to internals. This refactor should make that boundary clearer. Reviewed By: rshest Differential Revision: D48769809 fbshipit-source-id: b5480ac54781bc01b00c158b07d2d751fac87d37
This commit is contained in:
committed by
Facebook GitHub Bot
parent
7be985d97c
commit
7d8b9176fd
@@ -10,13 +10,15 @@
|
||||
|
||||
#include <yoga/algorithm/FlexDirection.h>
|
||||
#include <yoga/algorithm/ResolveValue.h>
|
||||
#include <yoga/debug/AssertFatal.h>
|
||||
#include <yoga/node/Node.h>
|
||||
#include <yoga/numeric/Comparison.h>
|
||||
|
||||
namespace facebook::yoga {
|
||||
|
||||
Node::Node(yoga::Config* config) : config_{config} {
|
||||
YGAssert(config != nullptr, "Attempting to construct Node with null config");
|
||||
yoga::assertFatal(
|
||||
config != nullptr, "Attempting to construct Node with null config");
|
||||
|
||||
flags_.hasNewLayout = true;
|
||||
if (config->useWebDefaults()) {
|
||||
@@ -234,7 +236,7 @@ void Node::setMeasureFunc(decltype(Node::measure_) measureFunc) {
|
||||
// places in Litho
|
||||
setNodeType(YGNodeTypeDefault);
|
||||
} else {
|
||||
YGAssertWithNode(
|
||||
yoga::assertFatalWithNode(
|
||||
this,
|
||||
children_.size() == 0,
|
||||
"Cannot set measure function: Nodes with measure functions cannot have "
|
||||
@@ -274,8 +276,9 @@ void Node::insertChild(Node* child, uint32_t index) {
|
||||
}
|
||||
|
||||
void Node::setConfig(yoga::Config* config) {
|
||||
YGAssert(config != nullptr, "Attempting to set a null config on a Node");
|
||||
YGAssertWithConfig(
|
||||
yoga::assertFatal(
|
||||
config != nullptr, "Attempting to set a null config on a Node");
|
||||
yoga::assertFatalWithConfig(
|
||||
config,
|
||||
config->useWebDefaults() == config_->useWebDefaults(),
|
||||
"UseWebDefaults may not be changed after constructing a Node");
|
||||
@@ -592,11 +595,11 @@ FloatOptional Node::getTrailingPaddingAndBorder(
|
||||
}
|
||||
|
||||
void Node::reset() {
|
||||
YGAssertWithNode(
|
||||
yoga::assertFatalWithNode(
|
||||
this,
|
||||
children_.size() == 0,
|
||||
"Cannot reset a node which still has children attached");
|
||||
YGAssertWithNode(
|
||||
yoga::assertFatalWithNode(
|
||||
this, owner_ == nullptr, "Cannot reset a node still attached to a owner");
|
||||
|
||||
*this = Node{getConfig()};
|
||||
|
Reference in New Issue
Block a user