Format and run codegen

Reviewed By: dshahidehpour

Differential Revision: D4459455

fbshipit-source-id: fc1eca58fe897c8f4a2571638b4f7035d023b479
This commit is contained in:
Emil Sjolander 2017-01-26 13:36:39 -08:00 committed by Facebook Github Bot
parent 3a476a8321
commit 3d1c8694d0
5 changed files with 89 additions and 110 deletions

View File

@ -75,7 +75,8 @@ static void YGPrint(YGNodeRef node) {
static float YGJNIBaselineFunc(YGNodeRef node, float width, float height) { static float YGJNIBaselineFunc(YGNodeRef node, float width, float height) {
if (auto obj = YGNodeJobject(node)->lockLocal()) { if (auto obj = YGNodeJobject(node)->lockLocal()) {
static auto baselineFunc = findClassStatic("com/facebook/yoga/YogaNode")->getMethod<jfloat(jfloat, jfloat)>("baseline"); static auto baselineFunc = findClassStatic("com/facebook/yoga/YogaNode")
->getMethod<jfloat(jfloat, jfloat)>("baseline");
return baselineFunc(obj, width, height); return baselineFunc(obj, width, height);
} else { } else {
return height; return height;
@ -222,8 +223,11 @@ void jni_YGNodeSetHasMeasureFunc(alias_ref<jobject>, jlong nativePointer, jboole
YGNodeSetMeasureFunc(_jlong2YGNodeRef(nativePointer), hasMeasureFunc ? YGJNIMeasureFunc : NULL); YGNodeSetMeasureFunc(_jlong2YGNodeRef(nativePointer), hasMeasureFunc ? YGJNIMeasureFunc : NULL);
} }
void jni_YGNodeSetHasBaselineFunc(alias_ref<jobject>, jlong nativePointer, jboolean hasBaselineFunc) { void jni_YGNodeSetHasBaselineFunc(alias_ref<jobject>,
YGNodeSetBaselineFunc(_jlong2YGNodeRef(nativePointer), hasBaselineFunc ? YGJNIBaselineFunc : NULL); jlong nativePointer,
jboolean hasBaselineFunc) {
YGNodeSetBaselineFunc(_jlong2YGNodeRef(nativePointer),
hasBaselineFunc ? YGJNIBaselineFunc : NULL);
} }
jboolean jni_YGNodeHasNewLayout(alias_ref<jobject>, jlong nativePointer) { jboolean jni_YGNodeHasNewLayout(alias_ref<jobject>, jlong nativePointer) {

View File

@ -15,110 +15,89 @@ YG_EXTERN_C_BEGIN
#define YGFlexDirectionCount 4 #define YGFlexDirectionCount 4
typedef YG_ENUM_BEGIN(YGFlexDirection) { typedef YG_ENUM_BEGIN(YGFlexDirection) {
YGFlexDirectionColumn, YGFlexDirectionColumn, YGFlexDirectionColumnReverse, YGFlexDirectionRow,
YGFlexDirectionColumnReverse, YGFlexDirectionRowReverse,
YGFlexDirectionRow, }
YGFlexDirectionRowReverse, YG_ENUM_END(YGFlexDirection);
} YG_ENUM_END(YGFlexDirection);
#define YGMeasureModeCount 3 #define YGMeasureModeCount 3
typedef YG_ENUM_BEGIN(YGMeasureMode) { typedef YG_ENUM_BEGIN(YGMeasureMode) {
YGMeasureModeUndefined, YGMeasureModeUndefined, YGMeasureModeExactly, YGMeasureModeAtMost,
YGMeasureModeExactly, }
YGMeasureModeAtMost, YG_ENUM_END(YGMeasureMode);
} YG_ENUM_END(YGMeasureMode);
#define YGPrintOptionsCount 3 #define YGPrintOptionsCount 3
typedef YG_ENUM_BEGIN(YGPrintOptions) { typedef YG_ENUM_BEGIN(YGPrintOptions) {
YGPrintOptionsLayout = 1, YGPrintOptionsLayout = 1, YGPrintOptionsStyle = 2, YGPrintOptionsChildren = 4,
YGPrintOptionsStyle = 2, }
YGPrintOptionsChildren = 4, YG_ENUM_END(YGPrintOptions);
} YG_ENUM_END(YGPrintOptions);
#define YGEdgeCount 9 #define YGEdgeCount 9
typedef YG_ENUM_BEGIN(YGEdge) { typedef YG_ENUM_BEGIN(YGEdge) {
YGEdgeLeft, YGEdgeLeft, YGEdgeTop, YGEdgeRight, YGEdgeBottom, YGEdgeStart, YGEdgeEnd, YGEdgeHorizontal,
YGEdgeTop, YGEdgeVertical, YGEdgeAll,
YGEdgeRight, }
YGEdgeBottom, YG_ENUM_END(YGEdge);
YGEdgeStart,
YGEdgeEnd,
YGEdgeHorizontal,
YGEdgeVertical,
YGEdgeAll,
} YG_ENUM_END(YGEdge);
#define YGPositionTypeCount 2 #define YGPositionTypeCount 2
typedef YG_ENUM_BEGIN(YGPositionType) { typedef YG_ENUM_BEGIN(YGPositionType) {
YGPositionTypeRelative, YGPositionTypeRelative, YGPositionTypeAbsolute,
YGPositionTypeAbsolute, }
} YG_ENUM_END(YGPositionType); YG_ENUM_END(YGPositionType);
#define YGDimensionCount 2 #define YGDimensionCount 2
typedef YG_ENUM_BEGIN(YGDimension) { typedef YG_ENUM_BEGIN(YGDimension) {
YGDimensionWidth, YGDimensionWidth, YGDimensionHeight,
YGDimensionHeight, }
} YG_ENUM_END(YGDimension); YG_ENUM_END(YGDimension);
#define YGJustifyCount 5 #define YGJustifyCount 5
typedef YG_ENUM_BEGIN(YGJustify) { typedef YG_ENUM_BEGIN(YGJustify) {
YGJustifyFlexStart, YGJustifyFlexStart, YGJustifyCenter, YGJustifyFlexEnd, YGJustifySpaceBetween,
YGJustifyCenter, YGJustifySpaceAround,
YGJustifyFlexEnd, }
YGJustifySpaceBetween, YG_ENUM_END(YGJustify);
YGJustifySpaceAround,
} YG_ENUM_END(YGJustify);
#define YGDirectionCount 3 #define YGDirectionCount 3
typedef YG_ENUM_BEGIN(YGDirection) { typedef YG_ENUM_BEGIN(YGDirection) {
YGDirectionInherit, YGDirectionInherit, YGDirectionLTR, YGDirectionRTL,
YGDirectionLTR, }
YGDirectionRTL, YG_ENUM_END(YGDirection);
} YG_ENUM_END(YGDirection);
#define YGLogLevelCount 5 #define YGLogLevelCount 5
typedef YG_ENUM_BEGIN(YGLogLevel) { typedef YG_ENUM_BEGIN(YGLogLevel) {
YGLogLevelError, YGLogLevelError, YGLogLevelWarn, YGLogLevelInfo, YGLogLevelDebug, YGLogLevelVerbose,
YGLogLevelWarn, }
YGLogLevelInfo, YG_ENUM_END(YGLogLevel);
YGLogLevelDebug,
YGLogLevelVerbose,
} YG_ENUM_END(YGLogLevel);
#define YGWrapCount 2 #define YGWrapCount 2
typedef YG_ENUM_BEGIN(YGWrap) { typedef YG_ENUM_BEGIN(YGWrap) {
YGWrapNoWrap, YGWrapNoWrap, YGWrapWrap,
YGWrapWrap, }
} YG_ENUM_END(YGWrap); YG_ENUM_END(YGWrap);
#define YGOverflowCount 3 #define YGOverflowCount 3
typedef YG_ENUM_BEGIN(YGOverflow) { typedef YG_ENUM_BEGIN(YGOverflow) {
YGOverflowVisible, YGOverflowVisible, YGOverflowHidden, YGOverflowScroll,
YGOverflowHidden, }
YGOverflowScroll, YG_ENUM_END(YGOverflow);
} YG_ENUM_END(YGOverflow);
#define YGExperimentalFeatureCount 2 #define YGExperimentalFeatureCount 2
typedef YG_ENUM_BEGIN(YGExperimentalFeature) { typedef YG_ENUM_BEGIN(YGExperimentalFeature) {
YGExperimentalFeatureRounding, YGExperimentalFeatureRounding, YGExperimentalFeatureWebFlexBasis,
YGExperimentalFeatureWebFlexBasis, }
} YG_ENUM_END(YGExperimentalFeature); YG_ENUM_END(YGExperimentalFeature);
#define YGAlignCount 6 #define YGAlignCount 6
typedef YG_ENUM_BEGIN(YGAlign) { typedef YG_ENUM_BEGIN(YGAlign) {
YGAlignAuto, YGAlignAuto, YGAlignFlexStart, YGAlignCenter, YGAlignFlexEnd, YGAlignStretch, YGAlignBaseline,
YGAlignFlexStart, }
YGAlignCenter, YG_ENUM_END(YGAlign);
YGAlignFlexEnd,
YGAlignStretch,
YGAlignBaseline,
} YG_ENUM_END(YGAlign);
#define YGUnitCount 3 #define YGUnitCount 3
typedef YG_ENUM_BEGIN(YGUnit) { typedef YG_ENUM_BEGIN(YGUnit) {
YGUnitUndefined, YGUnitUndefined, YGUnitPixel, YGUnitPercent,
YGUnitPixel, }
YGUnitPercent, YG_ENUM_END(YGUnit);
} YG_ENUM_END(YGUnit);
YG_EXTERN_C_END YG_EXTERN_C_END

View File

@ -42,7 +42,8 @@
#endif #endif
#ifdef NS_ENUM #ifdef NS_ENUM
// Cannot use NSInteger as NSInteger has a different size than int (which is the default type of a enum). // Cannot use NSInteger as NSInteger has a different size than int (which is the default type of a
// enum).
// Therefor when linking the Yoga C library into obj-c the header is a missmatch for the Yoga ABI. // Therefor when linking the Yoga C library into obj-c the header is a missmatch for the Yoga ABI.
#define YG_ENUM_BEGIN(name) NS_ENUM(int, name) #define YG_ENUM_BEGIN(name) NS_ENUM(int, name)
#define YG_ENUM_END(name) #define YG_ENUM_END(name)

View File

@ -532,7 +532,7 @@ void YGNodeStyleSetFlex(const YGNodeRef node, const float flex) {
return node->layout.instanceName; \ return node->layout.instanceName; \
} }
#define YG_NODE_LAYOUT_RESOLVED_PROPERTY_IMPL(type, name, instanceName) \ #define YG_NODE_LAYOUT_RESOLVED_PROPERTY_IMPL(type, name, instanceName) \
type YGNodeLayoutGet##name(const YGNodeRef node, const YGEdge edge) { \ type YGNodeLayoutGet##name(const YGNodeRef node, const YGEdge edge) { \
YG_ASSERT(edge <= YGEdgeEnd, "Cannot get layout properties of multi-edge shorthands"); \ YG_ASSERT(edge <= YGEdgeEnd, "Cannot get layout properties of multi-edge shorthands"); \
\ \
@ -1436,7 +1436,8 @@ static void YGNodeAbsoluteLayoutChild(const YGNodeRef node,
// If the size of the parent is defined then try to constrain the absolute child to that size // If the size of the parent is defined then try to constrain the absolute child to that size
// as well. This allows text within the absolute child to wrap to the size of its parent. // as well. This allows text within the absolute child to wrap to the size of its parent.
// This is the same behavior as many browsers implement. // This is the same behavior as many browsers implement.
if (!isMainAxisRow && YGFloatIsUndefined(childWidth) && widthMode != YGMeasureModeUndefined && width > 0) { if (!isMainAxisRow && YGFloatIsUndefined(childWidth) && widthMode != YGMeasureModeUndefined &&
width > 0) {
childWidth = width; childWidth = width;
childWidthMeasureMode = YGMeasureModeAtMost; childWidthMeasureMode = YGMeasureModeAtMost;
} }
@ -1473,12 +1474,13 @@ static void YGNodeAbsoluteLayoutChild(const YGNodeRef node,
child->layout.measuredDimensions[dim[mainAxis]] - child->layout.measuredDimensions[dim[mainAxis]] -
YGNodeTrailingBorder(node, mainAxis) - YGNodeTrailingBorder(node, mainAxis) -
YGNodeTrailingPosition(child, mainAxis, width); YGNodeTrailingPosition(child, mainAxis, width);
} else if (!YGNodeIsLeadingPosDefined(child, mainAxis) && } else if (!YGNodeIsLeadingPosDefined(child, mainAxis) &&
node->style.justifyContent == YGJustifyCenter) { node->style.justifyContent == YGJustifyCenter) {
child->layout.position[leading[mainAxis]] = (node->layout.measuredDimensions[dim[mainAxis]] - child->layout.position[leading[mainAxis]] = (node->layout.measuredDimensions[dim[mainAxis]] -
child->layout.measuredDimensions[dim[mainAxis]]) / 2.0f; child->layout.measuredDimensions[dim[mainAxis]]) /
} else if (!YGNodeIsLeadingPosDefined(child, mainAxis) && 2.0f;
node->style.justifyContent == YGJustifyFlexEnd) { } else if (!YGNodeIsLeadingPosDefined(child, mainAxis) &&
node->style.justifyContent == YGJustifyFlexEnd) {
child->layout.position[leading[mainAxis]] = (node->layout.measuredDimensions[dim[mainAxis]] - child->layout.position[leading[mainAxis]] = (node->layout.measuredDimensions[dim[mainAxis]] -
child->layout.measuredDimensions[dim[mainAxis]]); child->layout.measuredDimensions[dim[mainAxis]]);
} }
@ -1489,12 +1491,14 @@ static void YGNodeAbsoluteLayoutChild(const YGNodeRef node,
child->layout.measuredDimensions[dim[crossAxis]] - child->layout.measuredDimensions[dim[crossAxis]] -
YGNodeTrailingBorder(node, crossAxis) - YGNodeTrailingBorder(node, crossAxis) -
YGNodeTrailingPosition(child, crossAxis, width); YGNodeTrailingPosition(child, crossAxis, width);
} else if (!YGNodeIsLeadingPosDefined(child, crossAxis) && } else if (!YGNodeIsLeadingPosDefined(child, crossAxis) &&
YGNodeAlignItem(node, child) == YGAlignCenter) { YGNodeAlignItem(node, child) == YGAlignCenter) {
child->layout.position[leading[crossAxis]] = (node->layout.measuredDimensions[dim[crossAxis]] - child->layout.position[leading[crossAxis]] =
child->layout.measuredDimensions[dim[crossAxis]]) / 2.0f; (node->layout.measuredDimensions[dim[crossAxis]] -
} else if (!YGNodeIsLeadingPosDefined(child, crossAxis) && child->layout.measuredDimensions[dim[crossAxis]]) /
YGNodeAlignItem(node, child) == YGAlignFlexEnd) { 2.0f;
} else if (!YGNodeIsLeadingPosDefined(child, crossAxis) &&
YGNodeAlignItem(node, child) == YGAlignFlexEnd) {
child->layout.position[leading[crossAxis]] = (node->layout.measuredDimensions[dim[crossAxis]] - child->layout.position[leading[crossAxis]] = (node->layout.measuredDimensions[dim[crossAxis]] -
child->layout.measuredDimensions[dim[crossAxis]]); child->layout.measuredDimensions[dim[crossAxis]]);
} }
@ -1767,34 +1771,24 @@ static void YGNodelayoutImpl(const YGNodeRef node,
node->layout.direction = direction; node->layout.direction = direction;
const YGFlexDirection flexRowDirection = YGFlexDirectionResolve(YGFlexDirectionRow, direction); const YGFlexDirection flexRowDirection = YGFlexDirectionResolve(YGFlexDirectionRow, direction);
const YGFlexDirection flexColumnDirection = YGFlexDirectionResolve(YGFlexDirectionColumn, direction); const YGFlexDirection flexColumnDirection =
YGFlexDirectionResolve(YGFlexDirectionColumn, direction);
node->layout.margin[YGEdgeStart] = node->layout.margin[YGEdgeStart] = YGNodeLeadingMargin(node, flexRowDirection, parentWidth);
YGNodeLeadingMargin(node, flexRowDirection, parentWidth); node->layout.margin[YGEdgeEnd] = YGNodeTrailingMargin(node, flexRowDirection, parentWidth);
node->layout.margin[YGEdgeEnd] = node->layout.margin[YGEdgeTop] = YGNodeLeadingMargin(node, flexColumnDirection, parentWidth);
YGNodeTrailingMargin(node, flexRowDirection, parentWidth); node->layout.margin[YGEdgeBottom] = YGNodeTrailingMargin(node, flexColumnDirection, parentWidth);
node->layout.margin[YGEdgeTop] =
YGNodeLeadingMargin(node, flexColumnDirection, parentWidth);
node->layout.margin[YGEdgeBottom] =
YGNodeTrailingMargin(node, flexColumnDirection, parentWidth);
node->layout.border[YGEdgeStart] = node->layout.border[YGEdgeStart] = YGNodeLeadingBorder(node, flexRowDirection);
YGNodeLeadingBorder(node, flexRowDirection); node->layout.border[YGEdgeEnd] = YGNodeTrailingBorder(node, flexRowDirection);
node->layout.border[YGEdgeEnd] = node->layout.border[YGEdgeTop] = YGNodeLeadingBorder(node, flexColumnDirection);
YGNodeTrailingBorder(node, flexRowDirection); node->layout.border[YGEdgeBottom] = YGNodeTrailingBorder(node, flexColumnDirection);
node->layout.border[YGEdgeTop] =
YGNodeLeadingBorder(node, flexColumnDirection);
node->layout.border[YGEdgeBottom] =
YGNodeTrailingBorder(node, flexColumnDirection);
node->layout.padding[YGEdgeStart] = node->layout.padding[YGEdgeStart] = YGNodeLeadingPadding(node, flexRowDirection, parentWidth);
YGNodeLeadingPadding(node, flexRowDirection, parentWidth); node->layout.padding[YGEdgeEnd] = YGNodeTrailingPadding(node, flexRowDirection, parentWidth);
node->layout.padding[YGEdgeEnd] = node->layout.padding[YGEdgeTop] = YGNodeLeadingPadding(node, flexColumnDirection, parentWidth);
YGNodeTrailingPadding(node, flexRowDirection, parentWidth);
node->layout.padding[YGEdgeTop] =
YGNodeLeadingPadding(node, flexColumnDirection, parentWidth);
node->layout.padding[YGEdgeBottom] = node->layout.padding[YGEdgeBottom] =
YGNodeTrailingPadding(node, flexColumnDirection, parentWidth); YGNodeTrailingPadding(node, flexColumnDirection, parentWidth);
if (node->measure) { if (node->measure) {
YGNodeWithMeasureFuncSetMeasuredDimensions( YGNodeWithMeasureFuncSetMeasuredDimensions(
@ -1998,8 +1992,9 @@ static void YGNodelayoutImpl(const YGNodeRef node,
if (child->style.positionType != YGPositionTypeAbsolute) { if (child->style.positionType != YGPositionTypeAbsolute) {
const float outerFlexBasis = const float outerFlexBasis =
fmaxf(YGValueResolve(&child->style.minDimensions[dim[mainAxis]], mainAxisParentSize), child->layout.computedFlexBasis) + fmaxf(YGValueResolve(&child->style.minDimensions[dim[mainAxis]], mainAxisParentSize),
YGNodeMarginForAxis(child, mainAxis, availableInnerWidth); child->layout.computedFlexBasis) +
YGNodeMarginForAxis(child, mainAxis, availableInnerWidth);
// If this is a multi-line flow and this item pushes us over the // If this is a multi-line flow and this item pushes us over the
// available size, we've // available size, we've

View File

@ -43,7 +43,7 @@ typedef struct YGValue {
YGUnit unit; YGUnit unit;
} YGValue; } YGValue;
static const YGValue YGValueUndefined = { YGUndefined, YGUnitUndefined }; static const YGValue YGValueUndefined = {YGUndefined, YGUnitUndefined};
typedef struct YGNode *YGNodeRef; typedef struct YGNode *YGNodeRef;
typedef YGSize (*YGMeasureFunc)(YGNodeRef node, typedef YGSize (*YGMeasureFunc)(YGNodeRef node,