diff --git a/src/bindgen/ir/constant.rs b/src/bindgen/ir/constant.rs index 50bee829..283d66d7 100644 --- a/src/bindgen/ir/constant.rs +++ b/src/bindgen/ir/constant.rs @@ -636,13 +636,16 @@ impl Constant { debug_assert!(config.structure.associated_constants_in_body); debug_assert!(config.constant.allow_static_const); + let condition = self.cfg.to_condition(config); + condition.write_before(config, out); if let Type::Ptr { is_const: true, .. } = self.ty { out.write("static "); } else { out.write("static const "); } language_backend.write_type(out, &self.ty); - write!(out, " {};", self.export_name()) + write!(out, " {};", self.export_name()); + condition.write_after(config, out); } pub fn write( diff --git a/tests/expectations/associated_in_body.c b/tests/expectations/associated_in_body.c index e41971a7..cf09b172 100644 --- a/tests/expectations/associated_in_body.c +++ b/tests/expectations/associated_in_body.c @@ -1,3 +1,10 @@ +#if 0 +DEF PLATFORM_UNIX = 0 +DEF PLATFORM_WIN = 0 +#endif +#define PLATFORM_UNIX 1 + + #include #include #include @@ -34,6 +41,12 @@ typedef struct { #define StyleAlignFlags_FLEX_START (StyleAlignFlags){ .bits = (uint8_t)(1 << 3) } #define StyleAlignFlags_MIXED (StyleAlignFlags){ .bits = (uint8_t)(((1 << 4) | (StyleAlignFlags_FLEX_START).bits) | (StyleAlignFlags_END).bits) } #define StyleAlignFlags_MIXED_SELF (StyleAlignFlags){ .bits = (uint8_t)(((1 << 5) | (StyleAlignFlags_FLEX_START).bits) | (StyleAlignFlags_END).bits) } +#if defined(PLATFORM_WIN) +#define StyleAlignFlags_PLATFORM_BIT (StyleAlignFlags){ .bits = (uint8_t)(1 << 6) } +#endif +#if defined(PLATFORM_UNIX) +#define StyleAlignFlags_PLATFORM_BIT (StyleAlignFlags){ .bits = (uint8_t)(1 << 7) } +#endif /** * An arbitrary identifier for a native (OS compositor) surface diff --git a/tests/expectations/associated_in_body.compat.c b/tests/expectations/associated_in_body.compat.c index 095ed216..26b11bb1 100644 --- a/tests/expectations/associated_in_body.compat.c +++ b/tests/expectations/associated_in_body.compat.c @@ -1,3 +1,10 @@ +#if 0 +DEF PLATFORM_UNIX = 0 +DEF PLATFORM_WIN = 0 +#endif +#define PLATFORM_UNIX 1 + + #include #include #include @@ -34,6 +41,12 @@ typedef struct { #define StyleAlignFlags_FLEX_START (StyleAlignFlags){ .bits = (uint8_t)(1 << 3) } #define StyleAlignFlags_MIXED (StyleAlignFlags){ .bits = (uint8_t)(((1 << 4) | (StyleAlignFlags_FLEX_START).bits) | (StyleAlignFlags_END).bits) } #define StyleAlignFlags_MIXED_SELF (StyleAlignFlags){ .bits = (uint8_t)(((1 << 5) | (StyleAlignFlags_FLEX_START).bits) | (StyleAlignFlags_END).bits) } +#if defined(PLATFORM_WIN) +#define StyleAlignFlags_PLATFORM_BIT (StyleAlignFlags){ .bits = (uint8_t)(1 << 6) } +#endif +#if defined(PLATFORM_UNIX) +#define StyleAlignFlags_PLATFORM_BIT (StyleAlignFlags){ .bits = (uint8_t)(1 << 7) } +#endif /** * An arbitrary identifier for a native (OS compositor) surface diff --git a/tests/expectations/associated_in_body.cpp b/tests/expectations/associated_in_body.cpp index 29f6bd68..363be013 100644 --- a/tests/expectations/associated_in_body.cpp +++ b/tests/expectations/associated_in_body.cpp @@ -1,3 +1,10 @@ +#if 0 +DEF PLATFORM_UNIX = 0 +DEF PLATFORM_WIN = 0 +#endif +#define PLATFORM_UNIX 1 + + #include #include #include @@ -45,6 +52,12 @@ struct StyleAlignFlags { static const StyleAlignFlags FLEX_START; static const StyleAlignFlags MIXED; static const StyleAlignFlags MIXED_SELF; +#if defined(PLATFORM_WIN) + static const StyleAlignFlags PLATFORM_BIT; +#endif +#if defined(PLATFORM_UNIX) + static const StyleAlignFlags PLATFORM_BIT; +#endif }; /// 'auto' constexpr inline const StyleAlignFlags StyleAlignFlags::AUTO = StyleAlignFlags{ @@ -75,6 +88,16 @@ constexpr inline const StyleAlignFlags StyleAlignFlags::MIXED = StyleAlignFlags{ constexpr inline const StyleAlignFlags StyleAlignFlags::MIXED_SELF = StyleAlignFlags{ /* .bits = */ (uint8_t)(((1 << 5) | (StyleAlignFlags::FLEX_START).bits) | (StyleAlignFlags::END).bits) }; +#if defined(PLATFORM_WIN) +constexpr inline const StyleAlignFlags StyleAlignFlags::PLATFORM_BIT = StyleAlignFlags{ + /* .bits = */ (uint8_t)(1 << 6) +}; +#endif +#if defined(PLATFORM_UNIX) +constexpr inline const StyleAlignFlags StyleAlignFlags::PLATFORM_BIT = StyleAlignFlags{ + /* .bits = */ (uint8_t)(1 << 7) +}; +#endif /// An arbitrary identifier for a native (OS compositor) surface struct StyleNativeSurfaceId { diff --git a/tests/expectations/associated_in_body.pyx b/tests/expectations/associated_in_body.pyx index f6b20bcd..ae48cb54 100644 --- a/tests/expectations/associated_in_body.pyx +++ b/tests/expectations/associated_in_body.pyx @@ -1,3 +1,10 @@ +#if 0 +DEF PLATFORM_UNIX = 0 +DEF PLATFORM_WIN = 0 +#endif +#define PLATFORM_UNIX 1 + + from libc.stdint cimport int8_t, int16_t, int32_t, int64_t, intptr_t from libc.stdint cimport uint8_t, uint16_t, uint32_t, uint64_t, uintptr_t cdef extern from *: @@ -24,6 +31,10 @@ cdef extern from *: const StyleAlignFlags StyleAlignFlags_FLEX_START # = { (1 << 3) } const StyleAlignFlags StyleAlignFlags_MIXED # = { (((1 << 4) | (StyleAlignFlags_FLEX_START).bits) | (StyleAlignFlags_END).bits) } const StyleAlignFlags StyleAlignFlags_MIXED_SELF # = { (((1 << 5) | (StyleAlignFlags_FLEX_START).bits) | (StyleAlignFlags_END).bits) } + IF PLATFORM_WIN: + const StyleAlignFlags StyleAlignFlags_PLATFORM_BIT # = { (1 << 6) } + IF PLATFORM_UNIX: + const StyleAlignFlags StyleAlignFlags_PLATFORM_BIT # = { (1 << 7) } # An arbitrary identifier for a native (OS compositor) surface ctypedef struct StyleNativeSurfaceId: diff --git a/tests/expectations/associated_in_body_both.c b/tests/expectations/associated_in_body_both.c index c06a066a..c32c956e 100644 --- a/tests/expectations/associated_in_body_both.c +++ b/tests/expectations/associated_in_body_both.c @@ -1,3 +1,10 @@ +#if 0 +DEF PLATFORM_UNIX = 0 +DEF PLATFORM_WIN = 0 +#endif +#define PLATFORM_UNIX 1 + + #include #include #include @@ -34,6 +41,12 @@ typedef struct StyleAlignFlags { #define StyleAlignFlags_FLEX_START (StyleAlignFlags){ .bits = (uint8_t)(1 << 3) } #define StyleAlignFlags_MIXED (StyleAlignFlags){ .bits = (uint8_t)(((1 << 4) | (StyleAlignFlags_FLEX_START).bits) | (StyleAlignFlags_END).bits) } #define StyleAlignFlags_MIXED_SELF (StyleAlignFlags){ .bits = (uint8_t)(((1 << 5) | (StyleAlignFlags_FLEX_START).bits) | (StyleAlignFlags_END).bits) } +#if defined(PLATFORM_WIN) +#define StyleAlignFlags_PLATFORM_BIT (StyleAlignFlags){ .bits = (uint8_t)(1 << 6) } +#endif +#if defined(PLATFORM_UNIX) +#define StyleAlignFlags_PLATFORM_BIT (StyleAlignFlags){ .bits = (uint8_t)(1 << 7) } +#endif /** * An arbitrary identifier for a native (OS compositor) surface diff --git a/tests/expectations/associated_in_body_both.compat.c b/tests/expectations/associated_in_body_both.compat.c index 3187ea3f..48894683 100644 --- a/tests/expectations/associated_in_body_both.compat.c +++ b/tests/expectations/associated_in_body_both.compat.c @@ -1,3 +1,10 @@ +#if 0 +DEF PLATFORM_UNIX = 0 +DEF PLATFORM_WIN = 0 +#endif +#define PLATFORM_UNIX 1 + + #include #include #include @@ -34,6 +41,12 @@ typedef struct StyleAlignFlags { #define StyleAlignFlags_FLEX_START (StyleAlignFlags){ .bits = (uint8_t)(1 << 3) } #define StyleAlignFlags_MIXED (StyleAlignFlags){ .bits = (uint8_t)(((1 << 4) | (StyleAlignFlags_FLEX_START).bits) | (StyleAlignFlags_END).bits) } #define StyleAlignFlags_MIXED_SELF (StyleAlignFlags){ .bits = (uint8_t)(((1 << 5) | (StyleAlignFlags_FLEX_START).bits) | (StyleAlignFlags_END).bits) } +#if defined(PLATFORM_WIN) +#define StyleAlignFlags_PLATFORM_BIT (StyleAlignFlags){ .bits = (uint8_t)(1 << 6) } +#endif +#if defined(PLATFORM_UNIX) +#define StyleAlignFlags_PLATFORM_BIT (StyleAlignFlags){ .bits = (uint8_t)(1 << 7) } +#endif /** * An arbitrary identifier for a native (OS compositor) surface diff --git a/tests/expectations/associated_in_body_tag.c b/tests/expectations/associated_in_body_tag.c index f0bc16f9..4068cdd4 100644 --- a/tests/expectations/associated_in_body_tag.c +++ b/tests/expectations/associated_in_body_tag.c @@ -1,3 +1,10 @@ +#if 0 +DEF PLATFORM_UNIX = 0 +DEF PLATFORM_WIN = 0 +#endif +#define PLATFORM_UNIX 1 + + #include #include #include @@ -34,6 +41,12 @@ struct StyleAlignFlags { #define StyleAlignFlags_FLEX_START (StyleAlignFlags){ .bits = (uint8_t)(1 << 3) } #define StyleAlignFlags_MIXED (StyleAlignFlags){ .bits = (uint8_t)(((1 << 4) | (StyleAlignFlags_FLEX_START).bits) | (StyleAlignFlags_END).bits) } #define StyleAlignFlags_MIXED_SELF (StyleAlignFlags){ .bits = (uint8_t)(((1 << 5) | (StyleAlignFlags_FLEX_START).bits) | (StyleAlignFlags_END).bits) } +#if defined(PLATFORM_WIN) +#define StyleAlignFlags_PLATFORM_BIT (StyleAlignFlags){ .bits = (uint8_t)(1 << 6) } +#endif +#if defined(PLATFORM_UNIX) +#define StyleAlignFlags_PLATFORM_BIT (StyleAlignFlags){ .bits = (uint8_t)(1 << 7) } +#endif /** * An arbitrary identifier for a native (OS compositor) surface diff --git a/tests/expectations/associated_in_body_tag.compat.c b/tests/expectations/associated_in_body_tag.compat.c index 7f4c486d..7e894452 100644 --- a/tests/expectations/associated_in_body_tag.compat.c +++ b/tests/expectations/associated_in_body_tag.compat.c @@ -1,3 +1,10 @@ +#if 0 +DEF PLATFORM_UNIX = 0 +DEF PLATFORM_WIN = 0 +#endif +#define PLATFORM_UNIX 1 + + #include #include #include @@ -34,6 +41,12 @@ struct StyleAlignFlags { #define StyleAlignFlags_FLEX_START (StyleAlignFlags){ .bits = (uint8_t)(1 << 3) } #define StyleAlignFlags_MIXED (StyleAlignFlags){ .bits = (uint8_t)(((1 << 4) | (StyleAlignFlags_FLEX_START).bits) | (StyleAlignFlags_END).bits) } #define StyleAlignFlags_MIXED_SELF (StyleAlignFlags){ .bits = (uint8_t)(((1 << 5) | (StyleAlignFlags_FLEX_START).bits) | (StyleAlignFlags_END).bits) } +#if defined(PLATFORM_WIN) +#define StyleAlignFlags_PLATFORM_BIT (StyleAlignFlags){ .bits = (uint8_t)(1 << 6) } +#endif +#if defined(PLATFORM_UNIX) +#define StyleAlignFlags_PLATFORM_BIT (StyleAlignFlags){ .bits = (uint8_t)(1 << 7) } +#endif /** * An arbitrary identifier for a native (OS compositor) surface diff --git a/tests/expectations/associated_in_body_tag.pyx b/tests/expectations/associated_in_body_tag.pyx index 86697bdf..93ff7155 100644 --- a/tests/expectations/associated_in_body_tag.pyx +++ b/tests/expectations/associated_in_body_tag.pyx @@ -1,3 +1,10 @@ +#if 0 +DEF PLATFORM_UNIX = 0 +DEF PLATFORM_WIN = 0 +#endif +#define PLATFORM_UNIX 1 + + from libc.stdint cimport int8_t, int16_t, int32_t, int64_t, intptr_t from libc.stdint cimport uint8_t, uint16_t, uint32_t, uint64_t, uintptr_t cdef extern from *: @@ -24,6 +31,10 @@ cdef extern from *: const StyleAlignFlags StyleAlignFlags_FLEX_START # = { (1 << 3) } const StyleAlignFlags StyleAlignFlags_MIXED # = { (((1 << 4) | (StyleAlignFlags_FLEX_START).bits) | (StyleAlignFlags_END).bits) } const StyleAlignFlags StyleAlignFlags_MIXED_SELF # = { (((1 << 5) | (StyleAlignFlags_FLEX_START).bits) | (StyleAlignFlags_END).bits) } + IF PLATFORM_WIN: + const StyleAlignFlags StyleAlignFlags_PLATFORM_BIT # = { (1 << 6) } + IF PLATFORM_UNIX: + const StyleAlignFlags StyleAlignFlags_PLATFORM_BIT # = { (1 << 7) } # An arbitrary identifier for a native (OS compositor) surface cdef struct StyleNativeSurfaceId: diff --git a/tests/expectations/cfg.c b/tests/expectations/cfg.c index 800b518f..8d79e5c0 100644 --- a/tests/expectations/cfg.c +++ b/tests/expectations/cfg.c @@ -4,6 +4,7 @@ DEF PLATFORM_WIN = 0 DEF X11 = 0 DEF M_32 = 0 #endif +#define PLATFORM_UNIX 1 #include @@ -29,9 +30,30 @@ enum FooType { typedef uint32_t FooType; #endif +typedef struct { + uint8_t _0; +} Flags; +/** + * none + */ +#define Flags_NONE (Flags){ ._0 = (uint8_t)0 } +#if defined(PLATFORM_WIN) +#define Flags_A (Flags){ ._0 = (uint8_t)(1 << 0) } +#endif +#if defined(PLATFORM_UNIX) +#define Flags_A (Flags){ ._0 = (uint8_t)(1 << 1) } +#endif +#if defined(PLATFORM_WIN) +#define Flags_B (Flags){ ._0 = (uint8_t)((Flags_A)._0 | (1 << 3)) } +#endif +#if defined(PLATFORM_UNIX) +#define Flags_B (Flags){ ._0 = (uint8_t)((Flags_A)._0 | (1 << 4)) } +#endif + #if (defined(PLATFORM_UNIX) && defined(X11)) typedef struct { FooType ty; + Flags flags; int32_t x; float y; } FooHandle; diff --git a/tests/expectations/cfg.compat.c b/tests/expectations/cfg.compat.c index 6a457435..741ec089 100644 --- a/tests/expectations/cfg.compat.c +++ b/tests/expectations/cfg.compat.c @@ -4,6 +4,7 @@ DEF PLATFORM_WIN = 0 DEF X11 = 0 DEF M_32 = 0 #endif +#define PLATFORM_UNIX 1 #include @@ -41,9 +42,30 @@ typedef uint32_t FooType; #endif // __cplusplus #endif +typedef struct { + uint8_t _0; +} Flags; +/** + * none + */ +#define Flags_NONE (Flags){ ._0 = (uint8_t)0 } +#if defined(PLATFORM_WIN) +#define Flags_A (Flags){ ._0 = (uint8_t)(1 << 0) } +#endif +#if defined(PLATFORM_UNIX) +#define Flags_A (Flags){ ._0 = (uint8_t)(1 << 1) } +#endif +#if defined(PLATFORM_WIN) +#define Flags_B (Flags){ ._0 = (uint8_t)((Flags_A)._0 | (1 << 3)) } +#endif +#if defined(PLATFORM_UNIX) +#define Flags_B (Flags){ ._0 = (uint8_t)((Flags_A)._0 | (1 << 4)) } +#endif + #if (defined(PLATFORM_UNIX) && defined(X11)) typedef struct { FooType ty; + Flags flags; int32_t x; float y; } FooHandle; diff --git a/tests/expectations/cfg.cpp b/tests/expectations/cfg.cpp index 1eed9afd..c9038c63 100644 --- a/tests/expectations/cfg.cpp +++ b/tests/expectations/cfg.cpp @@ -4,6 +4,7 @@ DEF PLATFORM_WIN = 0 DEF X11 = 0 DEF M_32 = 0 #endif +#define PLATFORM_UNIX 1 #include @@ -28,19 +29,84 @@ enum class FooType : uint32_t { }; #endif +struct Flags { + uint8_t _0; + + constexpr explicit operator bool() const { + return !!_0; + } + constexpr Flags operator~() const { + return Flags { static_cast(~_0) }; + } + constexpr Flags operator|(const Flags& other) const { + return Flags { static_cast(this->_0 | other._0) }; + } + Flags& operator|=(const Flags& other) { + *this = (*this | other); + return *this; + } + constexpr Flags operator&(const Flags& other) const { + return Flags { static_cast(this->_0 & other._0) }; + } + Flags& operator&=(const Flags& other) { + *this = (*this & other); + return *this; + } + constexpr Flags operator^(const Flags& other) const { + return Flags { static_cast(this->_0 ^ other._0) }; + } + Flags& operator^=(const Flags& other) { + *this = (*this ^ other); + return *this; + } + bool operator==(const Flags& other) const { + return _0 == other._0; + } + bool operator!=(const Flags& other) const { + return _0 != other._0; + } +}; +/// none +constexpr static const Flags Flags_NONE = Flags{ + /* ._0 = */ (uint8_t)0 +}; +#if defined(PLATFORM_WIN) +constexpr static const Flags Flags_A = Flags{ + /* ._0 = */ (uint8_t)(1 << 0) +}; +#endif +#if defined(PLATFORM_UNIX) +constexpr static const Flags Flags_A = Flags{ + /* ._0 = */ (uint8_t)(1 << 1) +}; +#endif +#if defined(PLATFORM_WIN) +constexpr static const Flags Flags_B = Flags{ + /* ._0 = */ (uint8_t)((Flags_A)._0 | (1 << 3)) +}; +#endif +#if defined(PLATFORM_UNIX) +constexpr static const Flags Flags_B = Flags{ + /* ._0 = */ (uint8_t)((Flags_A)._0 | (1 << 4)) +}; +#endif + #if (defined(PLATFORM_UNIX) && defined(X11)) struct FooHandle { FooType ty; + Flags flags; int32_t x; float y; bool operator==(const FooHandle& other) const { return ty == other.ty && + flags == other.flags && x == other.x && y == other.y; } bool operator!=(const FooHandle& other) const { return ty != other.ty || + flags != other.flags || x != other.x || y != other.y; } diff --git a/tests/expectations/cfg.pyx b/tests/expectations/cfg.pyx index 803fd7a7..d551d182 100644 --- a/tests/expectations/cfg.pyx +++ b/tests/expectations/cfg.pyx @@ -4,6 +4,7 @@ DEF PLATFORM_WIN = 0 DEF X11 = 0 DEF M_32 = 0 #endif +#define PLATFORM_UNIX 1 from libc.stdint cimport int8_t, int16_t, int32_t, int64_t, intptr_t @@ -28,9 +29,23 @@ cdef extern from *: C, ctypedef uint32_t FooType; + ctypedef struct Flags: + uint8_t _0; + # none + const Flags Flags_NONE # = { 0 } + IF PLATFORM_WIN: + const Flags Flags_A # = { (1 << 0) } + IF PLATFORM_UNIX: + const Flags Flags_A # = { (1 << 1) } + IF PLATFORM_WIN: + const Flags Flags_B # = { ((Flags_A)._0 | (1 << 3)) } + IF PLATFORM_UNIX: + const Flags Flags_B # = { ((Flags_A)._0 | (1 << 4)) } + IF (PLATFORM_UNIX and X11): ctypedef struct FooHandle: FooType ty; + Flags flags; int32_t x; float y; diff --git a/tests/expectations/cfg_both.c b/tests/expectations/cfg_both.c index 55fcc894..afd2abad 100644 --- a/tests/expectations/cfg_both.c +++ b/tests/expectations/cfg_both.c @@ -4,6 +4,7 @@ DEF PLATFORM_WIN = 0 DEF X11 = 0 DEF M_32 = 0 #endif +#define PLATFORM_UNIX 1 #include @@ -29,9 +30,30 @@ enum FooType { typedef uint32_t FooType; #endif +typedef struct Flags { + uint8_t _0; +} Flags; +/** + * none + */ +#define Flags_NONE (Flags){ ._0 = (uint8_t)0 } +#if defined(PLATFORM_WIN) +#define Flags_A (Flags){ ._0 = (uint8_t)(1 << 0) } +#endif +#if defined(PLATFORM_UNIX) +#define Flags_A (Flags){ ._0 = (uint8_t)(1 << 1) } +#endif +#if defined(PLATFORM_WIN) +#define Flags_B (Flags){ ._0 = (uint8_t)((Flags_A)._0 | (1 << 3)) } +#endif +#if defined(PLATFORM_UNIX) +#define Flags_B (Flags){ ._0 = (uint8_t)((Flags_A)._0 | (1 << 4)) } +#endif + #if (defined(PLATFORM_UNIX) && defined(X11)) typedef struct FooHandle { FooType ty; + struct Flags flags; int32_t x; float y; } FooHandle; diff --git a/tests/expectations/cfg_both.compat.c b/tests/expectations/cfg_both.compat.c index 000b03d4..84fdb0b2 100644 --- a/tests/expectations/cfg_both.compat.c +++ b/tests/expectations/cfg_both.compat.c @@ -4,6 +4,7 @@ DEF PLATFORM_WIN = 0 DEF X11 = 0 DEF M_32 = 0 #endif +#define PLATFORM_UNIX 1 #include @@ -41,9 +42,30 @@ typedef uint32_t FooType; #endif // __cplusplus #endif +typedef struct Flags { + uint8_t _0; +} Flags; +/** + * none + */ +#define Flags_NONE (Flags){ ._0 = (uint8_t)0 } +#if defined(PLATFORM_WIN) +#define Flags_A (Flags){ ._0 = (uint8_t)(1 << 0) } +#endif +#if defined(PLATFORM_UNIX) +#define Flags_A (Flags){ ._0 = (uint8_t)(1 << 1) } +#endif +#if defined(PLATFORM_WIN) +#define Flags_B (Flags){ ._0 = (uint8_t)((Flags_A)._0 | (1 << 3)) } +#endif +#if defined(PLATFORM_UNIX) +#define Flags_B (Flags){ ._0 = (uint8_t)((Flags_A)._0 | (1 << 4)) } +#endif + #if (defined(PLATFORM_UNIX) && defined(X11)) typedef struct FooHandle { FooType ty; + struct Flags flags; int32_t x; float y; } FooHandle; diff --git a/tests/expectations/cfg_tag.c b/tests/expectations/cfg_tag.c index f9cad7b5..3a5a54a4 100644 --- a/tests/expectations/cfg_tag.c +++ b/tests/expectations/cfg_tag.c @@ -4,6 +4,7 @@ DEF PLATFORM_WIN = 0 DEF X11 = 0 DEF M_32 = 0 #endif +#define PLATFORM_UNIX 1 #include @@ -29,9 +30,30 @@ enum FooType { typedef uint32_t FooType; #endif +struct Flags { + uint8_t _0; +}; +/** + * none + */ +#define Flags_NONE (Flags){ ._0 = (uint8_t)0 } +#if defined(PLATFORM_WIN) +#define Flags_A (Flags){ ._0 = (uint8_t)(1 << 0) } +#endif +#if defined(PLATFORM_UNIX) +#define Flags_A (Flags){ ._0 = (uint8_t)(1 << 1) } +#endif +#if defined(PLATFORM_WIN) +#define Flags_B (Flags){ ._0 = (uint8_t)((Flags_A)._0 | (1 << 3)) } +#endif +#if defined(PLATFORM_UNIX) +#define Flags_B (Flags){ ._0 = (uint8_t)((Flags_A)._0 | (1 << 4)) } +#endif + #if (defined(PLATFORM_UNIX) && defined(X11)) struct FooHandle { FooType ty; + struct Flags flags; int32_t x; float y; }; diff --git a/tests/expectations/cfg_tag.compat.c b/tests/expectations/cfg_tag.compat.c index cfe66ffd..e9098b4f 100644 --- a/tests/expectations/cfg_tag.compat.c +++ b/tests/expectations/cfg_tag.compat.c @@ -4,6 +4,7 @@ DEF PLATFORM_WIN = 0 DEF X11 = 0 DEF M_32 = 0 #endif +#define PLATFORM_UNIX 1 #include @@ -41,9 +42,30 @@ typedef uint32_t FooType; #endif // __cplusplus #endif +struct Flags { + uint8_t _0; +}; +/** + * none + */ +#define Flags_NONE (Flags){ ._0 = (uint8_t)0 } +#if defined(PLATFORM_WIN) +#define Flags_A (Flags){ ._0 = (uint8_t)(1 << 0) } +#endif +#if defined(PLATFORM_UNIX) +#define Flags_A (Flags){ ._0 = (uint8_t)(1 << 1) } +#endif +#if defined(PLATFORM_WIN) +#define Flags_B (Flags){ ._0 = (uint8_t)((Flags_A)._0 | (1 << 3)) } +#endif +#if defined(PLATFORM_UNIX) +#define Flags_B (Flags){ ._0 = (uint8_t)((Flags_A)._0 | (1 << 4)) } +#endif + #if (defined(PLATFORM_UNIX) && defined(X11)) struct FooHandle { FooType ty; + struct Flags flags; int32_t x; float y; }; diff --git a/tests/expectations/cfg_tag.pyx b/tests/expectations/cfg_tag.pyx index 6a0d44d7..e8e31594 100644 --- a/tests/expectations/cfg_tag.pyx +++ b/tests/expectations/cfg_tag.pyx @@ -4,6 +4,7 @@ DEF PLATFORM_WIN = 0 DEF X11 = 0 DEF M_32 = 0 #endif +#define PLATFORM_UNIX 1 from libc.stdint cimport int8_t, int16_t, int32_t, int64_t, intptr_t @@ -28,9 +29,23 @@ cdef extern from *: C, ctypedef uint32_t FooType; + cdef struct Flags: + uint8_t _0; + # none + const Flags Flags_NONE # = { 0 } + IF PLATFORM_WIN: + const Flags Flags_A # = { (1 << 0) } + IF PLATFORM_UNIX: + const Flags Flags_A # = { (1 << 1) } + IF PLATFORM_WIN: + const Flags Flags_B # = { ((Flags_A)._0 | (1 << 3)) } + IF PLATFORM_UNIX: + const Flags Flags_B # = { ((Flags_A)._0 | (1 << 4)) } + IF (PLATFORM_UNIX and X11): cdef struct FooHandle: FooType ty; + Flags flags; int32_t x; float y; diff --git a/tests/rust/associated_in_body.rs b/tests/rust/associated_in_body.rs index 8c76a13c..b17312fd 100644 --- a/tests/rust/associated_in_body.rs +++ b/tests/rust/associated_in_body.rs @@ -18,6 +18,10 @@ bitflags! { const FLEX_START = 1 << 3; const MIXED = 1 << 4 | AlignFlags::FLEX_START.bits | AlignFlags::END.bits; const MIXED_SELF = 1 << 5 | AlignFlags::FLEX_START.bits | AlignFlags::END.bits; + #[cfg(windows)] + const PLATFORM_BIT = 1 << 6; + #[cfg(unix)] + const PLATFORM_BIT = 1 << 7; } } diff --git a/tests/rust/associated_in_body.toml b/tests/rust/associated_in_body.toml index a52609b5..03d191e2 100644 --- a/tests/rust/associated_in_body.toml +++ b/tests/rust/associated_in_body.toml @@ -1,3 +1,11 @@ +header = """ +#if 0 +DEF PLATFORM_UNIX = 0 +DEF PLATFORM_WIN = 0 +#endif +#define PLATFORM_UNIX 1 +""" + [struct] associated_constants_in_body = true @@ -9,3 +17,7 @@ prefix = "Style" # Just ensuring they play well together :) [const] allow_constexpr = true + +[defines] +"unix" = "PLATFORM_UNIX" +"windows" = "PLATFORM_WIN" diff --git a/tests/rust/cfg.rs b/tests/rust/cfg.rs index 0efe3546..b42c1d1a 100644 --- a/tests/rust/cfg.rs +++ b/tests/rust/cfg.rs @@ -6,10 +6,30 @@ enum FooType { C, } + +#[repr(C)] +pub struct Flags(u8); +bitflags! { + impl Flags: u8 { + /// none + const NONE = 0; + #[cfg(windows)] + const A = 1 << 0; + #[cfg(unix)] + const A = 1 << 1; + + #[cfg(windows)] + const B = Self::A.bits() | (1 << 3); + #[cfg(unix)] + const B = Self::A.bits() | (1 << 4); + } +} + #[cfg(all(unix, x11))] #[repr(C)] struct FooHandle { ty: FooType, + flags: Flags, x: i32, y: f32, } diff --git a/tests/rust/cfg.toml b/tests/rust/cfg.toml index 4d6c4caa..5359645e 100644 --- a/tests/rust/cfg.toml +++ b/tests/rust/cfg.toml @@ -5,6 +5,7 @@ DEF PLATFORM_WIN = 0 DEF X11 = 0 DEF M_32 = 0 #endif +#define PLATFORM_UNIX 1 """ [defines] @@ -23,3 +24,6 @@ private_default_tagged_enum_constructor = true [struct] derive_eq = true derive_neq = true + +[macro_expansion] +bitflags = true