Skip to content

Commit

Permalink
Fixup Enum Generator
Browse files Browse the repository at this point in the history
Summary:
facebook/yoga#1116 adds a new enum. The enum generator is out of date with copyright header, and some codemods, but it also looks like there were manual changes, types added, etc since generation. I fixed up the script to incorporate generating the changes folks made manually, and also added an enum that was previously only added manually to the C ABI.

Changelog:
[General][Fixed] - Fixup Yoga Enum Generator

Reviewed By: yungsters

Differential Revision: D39922252

fbshipit-source-id: b678fa9a43a896873d8c434745bdaf3f16fd991f
  • Loading branch information
NickGerleman authored and facebook-github-bot committed Sep 30, 2022
1 parent 6cd3884 commit 5f9689a
Show file tree
Hide file tree
Showing 19 changed files with 102 additions and 54 deletions.
2 changes: 2 additions & 0 deletions ReactAndroid/src/main/java/com/facebook/yoga/YogaAlign.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* LICENSE file in the root directory of this source tree.
*/

// @generated by enums.py

package com.facebook.yoga;

public enum YogaAlign {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* LICENSE file in the root directory of this source tree.
*/

// @generated by enums.py

package com.facebook.yoga;

public enum YogaDimension {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* LICENSE file in the root directory of this source tree.
*/

// @generated by enums.py

package com.facebook.yoga;

public enum YogaDirection {
Expand Down
2 changes: 2 additions & 0 deletions ReactAndroid/src/main/java/com/facebook/yoga/YogaDisplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* LICENSE file in the root directory of this source tree.
*/

// @generated by enums.py

package com.facebook.yoga;

public enum YogaDisplay {
Expand Down
2 changes: 2 additions & 0 deletions ReactAndroid/src/main/java/com/facebook/yoga/YogaEdge.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* LICENSE file in the root directory of this source tree.
*/

// @generated by enums.py

package com.facebook.yoga;

public enum YogaEdge {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* LICENSE file in the root directory of this source tree.
*/

// @generated by enums.py

package com.facebook.yoga;

public enum YogaExperimentalFeature {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* LICENSE file in the root directory of this source tree.
*/

// @generated by enums.py

package com.facebook.yoga;

public enum YogaFlexDirection {
Expand Down
5 changes: 3 additions & 2 deletions ReactAndroid/src/main/java/com/facebook/yoga/YogaJustify.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* LICENSE file in the root directory of this source tree.
*/

// @generated by enums.py

package com.facebook.yoga;

public enum YogaJustify {
Expand Down Expand Up @@ -32,8 +34,7 @@ public static YogaJustify fromInt(int value) {
case 2: return FLEX_END;
case 3: return SPACE_BETWEEN;
case 4: return SPACE_AROUND;
case 5:
return SPACE_EVENLY;
case 5: return SPACE_EVENLY;
default: throw new IllegalArgumentException("Unknown enum value: " + value);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* LICENSE file in the root directory of this source tree.
*/

// @generated by enums.py

package com.facebook.yoga;

import com.facebook.proguard.annotations.DoNotStrip;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* LICENSE file in the root directory of this source tree.
*/

// @generated by enums.py

package com.facebook.yoga;

public enum YogaMeasureMode {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* LICENSE file in the root directory of this source tree.
*/

// @generated by enums.py

package com.facebook.yoga;

public enum YogaNodeType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* LICENSE file in the root directory of this source tree.
*/

// @generated by enums.py

package com.facebook.yoga;

public enum YogaOverflow {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* LICENSE file in the root directory of this source tree.
*/

// @generated by enums.py

package com.facebook.yoga;

public enum YogaPositionType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* LICENSE file in the root directory of this source tree.
*/

// @generated by enums.py

package com.facebook.yoga;

public enum YogaPrintOptions {
Expand Down
2 changes: 2 additions & 0 deletions ReactAndroid/src/main/java/com/facebook/yoga/YogaUnit.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* LICENSE file in the root directory of this source tree.
*/

// @generated by enums.py

package com.facebook.yoga;

public enum YogaUnit {
Expand Down
2 changes: 2 additions & 0 deletions ReactAndroid/src/main/java/com/facebook/yoga/YogaWrap.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* LICENSE file in the root directory of this source tree.
*/

// @generated by enums.py

package com.facebook.yoga;

public enum YogaWrap {
Expand Down
2 changes: 2 additions & 0 deletions ReactCommon/yoga/yoga/YGEnums.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* LICENSE file in the root directory of this source tree.
*/

// @generated by enums.py

#include "YGEnums.h"

const char* YGAlignToString(const YGAlign value) {
Expand Down
76 changes: 24 additions & 52 deletions ReactCommon/yoga/yoga/YGEnums.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,53 +5,13 @@
* LICENSE file in the root directory of this source tree.
*/

// @generated by enums.py

#pragma once
// clang-format: off

#include "YGMacros.h"

#ifdef __cplusplus
namespace facebook {
namespace yoga {
namespace enums {

template <typename T>
constexpr int count(); // can't use `= delete` due to a defect in clang < 3.9

namespace detail {
template <int... xs>
constexpr int n() {
return sizeof...(xs);
}
} // namespace detail

} // namespace enums
} // namespace yoga
} // namespace facebook
#endif

#define YG_ENUM_DECL(NAME, ...) \
typedef YG_ENUM_BEGIN(NAME){__VA_ARGS__} YG_ENUM_END(NAME); \
WIN_EXPORT const char* NAME##ToString(NAME);

#ifdef __cplusplus
#define YG_ENUM_SEQ_DECL(NAME, ...) \
YG_ENUM_DECL(NAME, __VA_ARGS__) \
YG_EXTERN_C_END \
namespace facebook { \
namespace yoga { \
namespace enums { \
template <> \
constexpr int count<NAME>() { \
return detail::n<__VA_ARGS__>(); \
} \
} \
} \
} \
YG_EXTERN_C_BEGIN
#else
#define YG_ENUM_SEQ_DECL YG_ENUM_DECL
#endif

YG_EXTERN_C_BEGIN

YG_ENUM_SEQ_DECL(
Expand All @@ -63,17 +23,23 @@ YG_ENUM_SEQ_DECL(
YGAlignStretch,
YGAlignBaseline,
YGAlignSpaceBetween,
YGAlignSpaceAround);
YGAlignSpaceAround)

YG_ENUM_SEQ_DECL(YGDimension, YGDimensionWidth, YGDimensionHeight)
YG_ENUM_SEQ_DECL(
YGDimension,
YGDimensionWidth,
YGDimensionHeight)

YG_ENUM_SEQ_DECL(
YGDirection,
YGDirectionInherit,
YGDirectionLTR,
YGDirectionRTL)

YG_ENUM_SEQ_DECL(YGDisplay, YGDisplayFlex, YGDisplayNone)
YG_ENUM_SEQ_DECL(
YGDisplay,
YGDisplayFlex,
YGDisplayNone)

YG_ENUM_SEQ_DECL(
YGEdge,
Expand All @@ -87,7 +53,9 @@ YG_ENUM_SEQ_DECL(
YGEdgeVertical,
YGEdgeAll)

YG_ENUM_SEQ_DECL(YGExperimentalFeature, YGExperimentalFeatureWebFlexBasis)
YG_ENUM_SEQ_DECL(
YGExperimentalFeature,
YGExperimentalFeatureWebFlexBasis)

YG_ENUM_SEQ_DECL(
YGFlexDirection,
Expand Down Expand Up @@ -120,7 +88,10 @@ YG_ENUM_SEQ_DECL(
YGMeasureModeExactly,
YGMeasureModeAtMost)

YG_ENUM_SEQ_DECL(YGNodeType, YGNodeTypeDefault, YGNodeTypeText)
YG_ENUM_SEQ_DECL(
YGNodeType,
YGNodeTypeDefault,
YGNodeTypeText)

YG_ENUM_SEQ_DECL(
YGOverflow,
Expand All @@ -147,9 +118,10 @@ YG_ENUM_SEQ_DECL(
YGUnitPercent,
YGUnitAuto)

YG_ENUM_SEQ_DECL(YGWrap, YGWrapNoWrap, YGWrapWrap, YGWrapWrapReverse)
YG_ENUM_SEQ_DECL(
YGWrap,
YGWrapNoWrap,
YGWrapWrap,
YGWrapWrapReverse)

YG_EXTERN_C_END

#undef YG_ENUM_DECL
#undef YG_ENUM_SEQ_DECL
43 changes: 43 additions & 0 deletions ReactCommon/yoga/yoga/YGMacros.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,49 @@
#define YG_ENUM_END(name) name
#endif

#ifdef __cplusplus
namespace facebook {
namespace yoga {
namespace enums {

template <typename T>
constexpr int count(); // can't use `= delete` due to a defect in clang < 3.9

namespace detail {
template <int... xs>
constexpr int n() {
return sizeof...(xs);
}
} // namespace detail

} // namespace enums
} // namespace yoga
} // namespace facebook
#endif

#define YG_ENUM_DECL(NAME, ...) \
typedef YG_ENUM_BEGIN(NAME){__VA_ARGS__} YG_ENUM_END(NAME); \
WIN_EXPORT const char* NAME##ToString(NAME);

#ifdef __cplusplus
#define YG_ENUM_SEQ_DECL(NAME, ...) \
YG_ENUM_DECL(NAME, __VA_ARGS__) \
YG_EXTERN_C_END \
namespace facebook { \
namespace yoga { \
namespace enums { \
template <> \
constexpr int count<NAME>() { \
return detail::n<__VA_ARGS__>(); \
} \
} \
} \
} \
YG_EXTERN_C_BEGIN
#else
#define YG_ENUM_SEQ_DECL YG_ENUM_DECL
#endif

#ifdef __GNUC__
#define YG_DEPRECATED __attribute__((deprecated))
#elif defined(_MSC_VER)
Expand Down

0 comments on commit 5f9689a

Please sign in to comment.