Fixup Enum Generator

Summary:
https://github.com/facebook/yoga/pull/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
This commit is contained in:
Nick Gerleman
2022-09-29 22:25:24 -07:00
committed by Facebook GitHub Bot
parent fd180de774
commit 5a18ccdbe2
41 changed files with 320 additions and 162 deletions

View File

@@ -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) {

View File

@@ -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(
@@ -63,9 +23,12 @@ 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,
@@ -73,7 +36,10 @@ YG_ENUM_SEQ_DECL(
YGDirectionLTR,
YGDirectionRTL)
YG_ENUM_SEQ_DECL(YGDisplay, YGDisplayFlex, YGDisplayNone)
YG_ENUM_SEQ_DECL(
YGDisplay,
YGDisplayFlex,
YGDisplayNone)
YG_ENUM_SEQ_DECL(
YGEdge,
@@ -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,
@@ -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,
@@ -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

View File

@@ -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)