Transform the Count enum values into private constants #292

Closed
hartbit wants to merge 1 commits from private-count into master
4 changed files with 43 additions and 21 deletions
Showing only changes of commit ad3a2c68b7 - Show all commits

View File

@@ -111,9 +111,9 @@ def to_java_upper(symbol):
return out return out
root = os.path.dirname(__file__) root = os.path.dirname(os.path.abspath(__file__))
# write out C header # write out C headers
with open(root + '/yoga/YGEnums.h', 'w') as f: with open(root + '/yoga/YGEnums.h', 'w') as f:
f.write(LICENSE) f.write(LICENSE)
f.write('#pragma once\n\n') f.write('#pragma once\n\n')
@@ -126,11 +126,20 @@ with open(root + '/yoga/YGEnums.h', 'w') as f:
f.write(' YG%s%s = %d,\n' % (name, value[0], value[1])) f.write(' YG%s%s = %d,\n' % (name, value[0], value[1]))
else: else:
f.write(' YG%s%s,\n' % (name, value)) f.write(' YG%s%s,\n' % (name, value))
f.write(' YG%sCount,\n' % name)
f.write('} YG%s;\n' % name) f.write('} YG%s;\n' % name)
f.write('\n') f.write('\n')
f.write('YG_EXTERN_C_END\n') f.write('YG_EXTERN_C_END\n')
with open(root + '/yoga/YGEnums-Private.h', 'w') as f:
f.write(LICENSE)
f.write('#pragma once\n\n')
f.write('#include "YGMacros.h"\n\n')
f.write('YG_EXTERN_C_BEGIN\n\n')
for name, values in ENUMS.items():
f.write('#define YG%sCount %s\n' % (name, len(values)))
f.write('\n')
f.write('YG_EXTERN_C_END\n')
# write out java files # write out java files
for name, values in ENUMS.items(): for name, values in ENUMS.items():
with open(root + '/java/com/facebook/yoga/Yoga%s.java' % name, 'w') as f: with open(root + '/java/com/facebook/yoga/Yoga%s.java' % name, 'w') as f:

30
yoga/YGEnums-Private.h Normal file
View File

@@ -0,0 +1,30 @@
/**
* Copyright (c) 2014-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
#pragma once
#include "YGMacros.h"
YG_EXTERN_C_BEGIN
#define YGFlexDirectionCount 4
#define YGMeasureModeCount 3
#define YGPrintOptionsCount 3
#define YGEdgeCount 9
#define YGPositionTypeCount 2
#define YGDimensionCount 2
#define YGJustifyCount 5
#define YGDirectionCount 3
#define YGLogLevelCount 5
#define YGWrapCount 2
#define YGOverflowCount 3
#define YGExperimentalFeatureCount 2
#define YGAlignCount 5
YG_EXTERN_C_END

View File

@@ -18,21 +18,18 @@ typedef enum YGFlexDirection {
YGFlexDirectionColumnReverse, YGFlexDirectionColumnReverse,
YGFlexDirectionRow, YGFlexDirectionRow,
YGFlexDirectionRowReverse, YGFlexDirectionRowReverse,
YGFlexDirectionCount,
} YGFlexDirection; } YGFlexDirection;
typedef enum YGMeasureMode { typedef enum YGMeasureMode {
YGMeasureModeUndefined, YGMeasureModeUndefined,
YGMeasureModeExactly, YGMeasureModeExactly,
YGMeasureModeAtMost, YGMeasureModeAtMost,
YGMeasureModeCount,
} YGMeasureMode; } YGMeasureMode;
typedef enum YGPrintOptions { typedef enum YGPrintOptions {
YGPrintOptionsLayout = 1, YGPrintOptionsLayout = 1,
YGPrintOptionsStyle = 2, YGPrintOptionsStyle = 2,
YGPrintOptionsChildren = 4, YGPrintOptionsChildren = 4,
YGPrintOptionsCount,
} YGPrintOptions; } YGPrintOptions;
typedef enum YGEdge { typedef enum YGEdge {
@@ -45,19 +42,16 @@ typedef enum YGEdge {
YGEdgeHorizontal, YGEdgeHorizontal,
YGEdgeVertical, YGEdgeVertical,
YGEdgeAll, YGEdgeAll,
YGEdgeCount,
} YGEdge; } YGEdge;
typedef enum YGPositionType { typedef enum YGPositionType {
YGPositionTypeRelative, YGPositionTypeRelative,
YGPositionTypeAbsolute, YGPositionTypeAbsolute,
YGPositionTypeCount,
} YGPositionType; } YGPositionType;
typedef enum YGDimension { typedef enum YGDimension {
YGDimensionWidth, YGDimensionWidth,
YGDimensionHeight, YGDimensionHeight,
YGDimensionCount,
} YGDimension; } YGDimension;
typedef enum YGJustify { typedef enum YGJustify {
@@ -66,14 +60,12 @@ typedef enum YGJustify {
YGJustifyFlexEnd, YGJustifyFlexEnd,
YGJustifySpaceBetween, YGJustifySpaceBetween,
YGJustifySpaceAround, YGJustifySpaceAround,
YGJustifyCount,
} YGJustify; } YGJustify;
typedef enum YGDirection { typedef enum YGDirection {
YGDirectionInherit, YGDirectionInherit,
YGDirectionLTR, YGDirectionLTR,
YGDirectionRTL, YGDirectionRTL,
YGDirectionCount,
} YGDirection; } YGDirection;
typedef enum YGLogLevel { typedef enum YGLogLevel {
@@ -82,26 +74,22 @@ typedef enum YGLogLevel {
YGLogLevelInfo, YGLogLevelInfo,
YGLogLevelDebug, YGLogLevelDebug,
YGLogLevelVerbose, YGLogLevelVerbose,
YGLogLevelCount,
} YGLogLevel; } YGLogLevel;
typedef enum YGWrap { typedef enum YGWrap {
YGWrapNoWrap, YGWrapNoWrap,
YGWrapWrap, YGWrapWrap,
YGWrapCount,
} YGWrap; } YGWrap;
typedef enum YGOverflow { typedef enum YGOverflow {
YGOverflowVisible, YGOverflowVisible,
YGOverflowHidden, YGOverflowHidden,
YGOverflowScroll, YGOverflowScroll,
YGOverflowCount,
} YGOverflow; } YGOverflow;
typedef enum YGExperimentalFeature { typedef enum YGExperimentalFeature {
YGExperimentalFeatureRounding, YGExperimentalFeatureRounding,
YGExperimentalFeatureWebFlexBasis, YGExperimentalFeatureWebFlexBasis,
YGExperimentalFeatureCount,
} YGExperimentalFeature; } YGExperimentalFeature;
typedef enum YGAlign { typedef enum YGAlign {
@@ -110,7 +98,6 @@ typedef enum YGAlign {
YGAlignCenter, YGAlignCenter,
YGAlignFlexEnd, YGAlignFlexEnd,
YGAlignStretch, YGAlignStretch,
YGAlignCount,
} YGAlign; } YGAlign;
YG_EXTERN_C_END YG_EXTERN_C_END

View File

@@ -11,6 +11,7 @@
#include "YGNodeList.h" #include "YGNodeList.h"
#include "Yoga.h" #include "Yoga.h"
#include "YGEnums-Private.h"
#ifdef _MSC_VER #ifdef _MSC_VER
#include <float.h> #include <float.h>
@@ -950,8 +951,6 @@ static void YGConstrainMaxSizeForMode(const float maxSize, YGMeasureMode *mode,
*size = maxSize; *size = maxSize;
} }
break; break;
case YGMeasureModeCount:
break;
} }
} }
@@ -1934,7 +1933,6 @@ static void YGNodelayoutImpl(const YGNodeRef node,
leadingMainDim = betweenMainDim / 2; leadingMainDim = betweenMainDim / 2;
break; break;
case YGJustifyFlexStart: case YGJustifyFlexStart:
case YGJustifyCount:
break; break;
} }
@@ -2127,7 +2125,6 @@ static void YGNodelayoutImpl(const YGNodeRef node,
break; break;
case YGAlignAuto: case YGAlignAuto:
case YGAlignFlexStart: case YGAlignFlexStart:
case YGAlignCount:
break; break;
} }
@@ -2187,7 +2184,6 @@ static void YGNodelayoutImpl(const YGNodeRef node,
break; break;
} }
case YGAlignAuto: case YGAlignAuto:
case YGAlignCount:
break; break;
} }
} }