diff --git a/src/bindgen/dependencies.rs b/src/bindgen/dependencies.rs index 6a987381..26501c9c 100644 --- a/src/bindgen/dependencies.rs +++ b/src/bindgen/dependencies.rs @@ -5,7 +5,10 @@ use std::cmp::Ordering; use std::collections::HashSet; -use crate::bindgen::ir::{ItemContainer, Path}; +use crate::bindgen::{ + ir::{ItemContainer, Path}, + library::Library, +}; /// A dependency list is used for gathering what order to output the types. #[derive(Default)] @@ -22,6 +25,25 @@ impl Dependencies { } } + pub fn add(&mut self, library: &Library, path: &Path) { + let Some(items) = library.get_items(path) else { + warn!( + "Can't find {path}. This usually means that this type was incompatible or not found." + ); + return; + }; + if self.items.contains(path) { + return; + } + self.items.insert(path.clone()); + for item in &items { + item.deref().add_dependencies(library, self); + } + for item in items { + self.order.push(item); + } + } + pub fn sort(&mut self) { // Sort untagged enums and opaque structs into their own layers because they don't // depend on each other or anything else. @@ -29,7 +51,7 @@ impl Dependencies { (ItemContainer::Enum(x), ItemContainer::Enum(y)) if x.tag.is_none() && y.tag.is_none() => { - x.path.cmp(&y.path) + Ordering::Equal } (ItemContainer::Enum(x), _) if x.tag.is_none() => Ordering::Less, (_, ItemContainer::Enum(x)) if x.tag.is_none() => Ordering::Greater, diff --git a/src/bindgen/ir/constant.rs b/src/bindgen/ir/constant.rs index 283d66d7..918daaed 100644 --- a/src/bindgen/ir/constant.rs +++ b/src/bindgen/ir/constant.rs @@ -117,7 +117,27 @@ pub enum Literal { } impl Literal { - fn replace_self_with(&mut self, self_ty: &Path) { + pub fn add_dependencies(&self, library: &Library, out: &mut Dependencies) { + self.visit(&mut |lit| { + match lit { + Literal::Struct { + ref path, + export_name: _, + fields: _, + } + | Literal::Path { + associated_to: Some((ref path, _)), + name: _, + } => { + out.add(library, path); + } + _ => {} + } + true + }); + } + + pub fn replace_self_with(&mut self, self_ty: &Path) { match *self { Literal::PostfixUnaryOp { ref mut value, .. } => { value.replace_self_with(self_ty); @@ -579,6 +599,7 @@ impl Item for Constant { fn add_dependencies(&self, library: &Library, out: &mut Dependencies) { self.ty.add_dependencies(library, out); + self.value.add_dependencies(library, out); } fn export_name(&self) -> &str { diff --git a/src/bindgen/ir/enumeration.rs b/src/bindgen/ir/enumeration.rs index 642007a5..f0af34bc 100644 --- a/src/bindgen/ir/enumeration.rs +++ b/src/bindgen/ir/enumeration.rs @@ -105,7 +105,11 @@ impl EnumVariant { config: &Config, ) -> Result { let discriminant = match variant.discriminant { - Some((_, ref expr)) => Some(Literal::load(expr)?), + Some((_, ref expr)) => { + let mut discriminant = Literal::load(expr)?; + discriminant.replace_self_with(self_path); + Some(discriminant) + } None => None, }; @@ -258,6 +262,9 @@ impl EnumVariant { if let VariantBody::Body { ref body, .. } = self.body { body.add_dependencies(library, out); } + if let Some(ref d) = self.discriminant { + d.add_dependencies(library, out); + } } fn resolve_declaration_types(&mut self, resolver: &DeclarationTypeResolver) { diff --git a/src/bindgen/ir/ty.rs b/src/bindgen/ir/ty.rs index f0b9b8a5..d54620b5 100644 --- a/src/bindgen/ir/ty.rs +++ b/src/bindgen/ir/ty.rs @@ -701,23 +701,7 @@ impl Type { } let path = generic.path(); if !generic_params.iter().any(|param| param.name() == path) { - if let Some(items) = library.get_items(path) { - if !out.items.contains(path) { - out.items.insert(path.clone()); - - for item in &items { - item.deref().add_dependencies(library, out); - } - for item in items { - out.order.push(item); - } - } - } else { - warn!( - "Can't find {path}. This usually means that this type was incompatible or \ - not found." - ); - } + out.add(library, path); } } Type::Primitive(_) => {} diff --git a/tests/expectations-symbols/enum_self_flags.c.sym b/tests/expectations-symbols/enum_self_flags.c.sym new file mode 100644 index 00000000..f018156f --- /dev/null +++ b/tests/expectations-symbols/enum_self_flags.c.sym @@ -0,0 +1,3 @@ +{ +root; +}; \ No newline at end of file diff --git a/tests/expectations/cfg.c b/tests/expectations/cfg.c index 8d79e5c0..c5d3d116 100644 --- a/tests/expectations/cfg.c +++ b/tests/expectations/cfg.c @@ -12,22 +12,22 @@ DEF M_32 = 0 #include #include -#if (defined(PLATFORM_WIN) || defined(M_32)) -enum BarType { +#if (defined(PLATFORM_UNIX) && defined(X11)) +enum FooType { A, B, C, }; -typedef uint32_t BarType; +typedef uint32_t FooType; #endif -#if (defined(PLATFORM_UNIX) && defined(X11)) -enum FooType { +#if (defined(PLATFORM_WIN) || defined(M_32)) +enum BarType { A, B, C, }; -typedef uint32_t FooType; +typedef uint32_t BarType; #endif typedef struct { diff --git a/tests/expectations/cfg.compat.c b/tests/expectations/cfg.compat.c index 741ec089..9532f71a 100644 --- a/tests/expectations/cfg.compat.c +++ b/tests/expectations/cfg.compat.c @@ -12,8 +12,8 @@ DEF M_32 = 0 #include #include -#if (defined(PLATFORM_WIN) || defined(M_32)) -enum BarType +#if (defined(PLATFORM_UNIX) && defined(X11)) +enum FooType #ifdef __cplusplus : uint32_t #endif // __cplusplus @@ -23,12 +23,12 @@ enum BarType C, }; #ifndef __cplusplus -typedef uint32_t BarType; +typedef uint32_t FooType; #endif // __cplusplus #endif -#if (defined(PLATFORM_UNIX) && defined(X11)) -enum FooType +#if (defined(PLATFORM_WIN) || defined(M_32)) +enum BarType #ifdef __cplusplus : uint32_t #endif // __cplusplus @@ -38,7 +38,7 @@ enum FooType C, }; #ifndef __cplusplus -typedef uint32_t FooType; +typedef uint32_t BarType; #endif // __cplusplus #endif diff --git a/tests/expectations/cfg.cpp b/tests/expectations/cfg.cpp index c9038c63..13063484 100644 --- a/tests/expectations/cfg.cpp +++ b/tests/expectations/cfg.cpp @@ -13,16 +13,16 @@ DEF M_32 = 0 #include #include -#if (defined(PLATFORM_WIN) || defined(M_32)) -enum class BarType : uint32_t { +#if (defined(PLATFORM_UNIX) && defined(X11)) +enum class FooType : uint32_t { A, B, C, }; #endif -#if (defined(PLATFORM_UNIX) && defined(X11)) -enum class FooType : uint32_t { +#if (defined(PLATFORM_WIN) || defined(M_32)) +enum class BarType : uint32_t { A, B, C, diff --git a/tests/expectations/cfg.pyx b/tests/expectations/cfg.pyx index d551d182..a1012cc1 100644 --- a/tests/expectations/cfg.pyx +++ b/tests/expectations/cfg.pyx @@ -15,19 +15,19 @@ cdef extern from *: cdef extern from *: - IF (PLATFORM_WIN or M_32): + IF (PLATFORM_UNIX and X11): cdef enum: A, B, C, - ctypedef uint32_t BarType; + ctypedef uint32_t FooType; - IF (PLATFORM_UNIX and X11): + IF (PLATFORM_WIN or M_32): cdef enum: A, B, C, - ctypedef uint32_t FooType; + ctypedef uint32_t BarType; ctypedef struct Flags: uint8_t _0; diff --git a/tests/expectations/cfg_both.c b/tests/expectations/cfg_both.c index afd2abad..71e7e8a4 100644 --- a/tests/expectations/cfg_both.c +++ b/tests/expectations/cfg_both.c @@ -12,22 +12,22 @@ DEF M_32 = 0 #include #include -#if (defined(PLATFORM_WIN) || defined(M_32)) -enum BarType { +#if (defined(PLATFORM_UNIX) && defined(X11)) +enum FooType { A, B, C, }; -typedef uint32_t BarType; +typedef uint32_t FooType; #endif -#if (defined(PLATFORM_UNIX) && defined(X11)) -enum FooType { +#if (defined(PLATFORM_WIN) || defined(M_32)) +enum BarType { A, B, C, }; -typedef uint32_t FooType; +typedef uint32_t BarType; #endif typedef struct Flags { diff --git a/tests/expectations/cfg_both.compat.c b/tests/expectations/cfg_both.compat.c index 84fdb0b2..bedee0d7 100644 --- a/tests/expectations/cfg_both.compat.c +++ b/tests/expectations/cfg_both.compat.c @@ -12,8 +12,8 @@ DEF M_32 = 0 #include #include -#if (defined(PLATFORM_WIN) || defined(M_32)) -enum BarType +#if (defined(PLATFORM_UNIX) && defined(X11)) +enum FooType #ifdef __cplusplus : uint32_t #endif // __cplusplus @@ -23,12 +23,12 @@ enum BarType C, }; #ifndef __cplusplus -typedef uint32_t BarType; +typedef uint32_t FooType; #endif // __cplusplus #endif -#if (defined(PLATFORM_UNIX) && defined(X11)) -enum FooType +#if (defined(PLATFORM_WIN) || defined(M_32)) +enum BarType #ifdef __cplusplus : uint32_t #endif // __cplusplus @@ -38,7 +38,7 @@ enum FooType C, }; #ifndef __cplusplus -typedef uint32_t FooType; +typedef uint32_t BarType; #endif // __cplusplus #endif diff --git a/tests/expectations/cfg_tag.c b/tests/expectations/cfg_tag.c index 3a5a54a4..96ccf90c 100644 --- a/tests/expectations/cfg_tag.c +++ b/tests/expectations/cfg_tag.c @@ -12,22 +12,22 @@ DEF M_32 = 0 #include #include -#if (defined(PLATFORM_WIN) || defined(M_32)) -enum BarType { +#if (defined(PLATFORM_UNIX) && defined(X11)) +enum FooType { A, B, C, }; -typedef uint32_t BarType; +typedef uint32_t FooType; #endif -#if (defined(PLATFORM_UNIX) && defined(X11)) -enum FooType { +#if (defined(PLATFORM_WIN) || defined(M_32)) +enum BarType { A, B, C, }; -typedef uint32_t FooType; +typedef uint32_t BarType; #endif struct Flags { diff --git a/tests/expectations/cfg_tag.compat.c b/tests/expectations/cfg_tag.compat.c index e9098b4f..ec879c68 100644 --- a/tests/expectations/cfg_tag.compat.c +++ b/tests/expectations/cfg_tag.compat.c @@ -12,8 +12,8 @@ DEF M_32 = 0 #include #include -#if (defined(PLATFORM_WIN) || defined(M_32)) -enum BarType +#if (defined(PLATFORM_UNIX) && defined(X11)) +enum FooType #ifdef __cplusplus : uint32_t #endif // __cplusplus @@ -23,12 +23,12 @@ enum BarType C, }; #ifndef __cplusplus -typedef uint32_t BarType; +typedef uint32_t FooType; #endif // __cplusplus #endif -#if (defined(PLATFORM_UNIX) && defined(X11)) -enum FooType +#if (defined(PLATFORM_WIN) || defined(M_32)) +enum BarType #ifdef __cplusplus : uint32_t #endif // __cplusplus @@ -38,7 +38,7 @@ enum FooType C, }; #ifndef __cplusplus -typedef uint32_t FooType; +typedef uint32_t BarType; #endif // __cplusplus #endif diff --git a/tests/expectations/cfg_tag.pyx b/tests/expectations/cfg_tag.pyx index e8e31594..b3c89a11 100644 --- a/tests/expectations/cfg_tag.pyx +++ b/tests/expectations/cfg_tag.pyx @@ -15,19 +15,19 @@ cdef extern from *: cdef extern from *: - IF (PLATFORM_WIN or M_32): + IF (PLATFORM_UNIX and X11): cdef enum: A, B, C, - ctypedef uint32_t BarType; + ctypedef uint32_t FooType; - IF (PLATFORM_UNIX and X11): + IF (PLATFORM_WIN or M_32): cdef enum: A, B, C, - ctypedef uint32_t FooType; + ctypedef uint32_t BarType; cdef struct Flags: uint8_t _0; diff --git a/tests/expectations/enum_self_flags.c b/tests/expectations/enum_self_flags.c new file mode 100644 index 00000000..7285d300 --- /dev/null +++ b/tests/expectations/enum_self_flags.c @@ -0,0 +1,92 @@ +#if 0 +''' ' +#endif + +// FIXME: Mis-generated in C mode with enum.prefix_with_name = false, and in +// C++ mode with it set to true... +#if defined(__cplusplus) && !defined(CBINDGEN_CPP_COMPAT) + + +#include +#include +#include +#include + +#define AXIS_SHIFT 3 + +#define SELF_WM_SHIFT 6 + +#define SELF_WM (1 << 6) + +/** + * Specifies which tracks(s) on the axis that the position-area span occupies. + * Represented as 3 bits: start, center, end track. + */ +enum PositionAreaTrack { + /** + * First track + */ + Start = 1, + /** + * First and center. + */ + SpanStart = 3, + /** + * Last track. + */ + End = 4, + /** + * Last and center. + */ + SpanEnd = 6, + /** + * Center track. + */ + Center = 2, + /** + * All tracks + */ + SpanAll = 7, +}; +typedef uint8_t PositionAreaTrack; + +/** + * A three-bit value that represents the axis in which position-area operates on. + * Represented as 3 bits: axis type (physical or logical), direction type (physical or logical), + * axis value. + */ +enum PositionAreaAxis { + Horizontal = 0, + Vertical = 1, + X = 2, + Y = 3, + Inline = 6, + Block = 7, +}; +typedef uint8_t PositionAreaAxis; + +/** + * Possible values for the `position-area` property's keywords. + * Represented by [0z xxx yyy], where z means "self wm resolution", xxx is the type (as in + * PositionAreaAxis and yyy is the PositionAreaTrack + * https://drafts.csswg.org/css-anchor-position-1/#propdef-position-area + */ +enum PositionAreaKeyword { + None = 0, + Center = (uint8_t)PositionAreaTrack_Center, + SpanAll = (uint8_t)PositionAreaTrack_SpanAll, + Start = (uint8_t)PositionAreaTrack_Start, + End = (uint8_t)PositionAreaTrack_End, + SpanStart = (uint8_t)PositionAreaTrack_SpanStart, + SpanEnd = (uint8_t)PositionAreaTrack_SpanEnd, + Top = (((uint8_t)PositionAreaAxis_Vertical << AXIS_SHIFT) | (uint8_t)PositionAreaTrack_Start), + Bottom = (((uint8_t)PositionAreaAxis_Vertical << AXIS_SHIFT) | (uint8_t)PositionAreaTrack_End), +}; +typedef uint8_t PositionAreaKeyword; + +void root(PositionAreaKeyword, PositionAreaTrack, PositionAreaAxis); + +#endif +#if 0 +' ''' +#endif diff --git a/tests/expectations/enum_self_flags.compat.c b/tests/expectations/enum_self_flags.compat.c new file mode 100644 index 00000000..69fc0ae2 --- /dev/null +++ b/tests/expectations/enum_self_flags.compat.c @@ -0,0 +1,118 @@ +#if 0 +''' ' +#endif + +// FIXME: Mis-generated in C mode with enum.prefix_with_name = false, and in +// C++ mode with it set to true... +#if defined(__cplusplus) && !defined(CBINDGEN_CPP_COMPAT) + + +#include +#include +#include +#include + +#define AXIS_SHIFT 3 + +#define SELF_WM_SHIFT 6 + +#define SELF_WM (1 << 6) + +/** + * Specifies which tracks(s) on the axis that the position-area span occupies. + * Represented as 3 bits: start, center, end track. + */ +enum PositionAreaTrack +#ifdef __cplusplus + : uint8_t +#endif // __cplusplus + { + /** + * First track + */ + Start = 1, + /** + * First and center. + */ + SpanStart = 3, + /** + * Last track. + */ + End = 4, + /** + * Last and center. + */ + SpanEnd = 6, + /** + * Center track. + */ + Center = 2, + /** + * All tracks + */ + SpanAll = 7, +}; +#ifndef __cplusplus +typedef uint8_t PositionAreaTrack; +#endif // __cplusplus + +/** + * A three-bit value that represents the axis in which position-area operates on. + * Represented as 3 bits: axis type (physical or logical), direction type (physical or logical), + * axis value. + */ +enum PositionAreaAxis +#ifdef __cplusplus + : uint8_t +#endif // __cplusplus + { + Horizontal = 0, + Vertical = 1, + X = 2, + Y = 3, + Inline = 6, + Block = 7, +}; +#ifndef __cplusplus +typedef uint8_t PositionAreaAxis; +#endif // __cplusplus + +/** + * Possible values for the `position-area` property's keywords. + * Represented by [0z xxx yyy], where z means "self wm resolution", xxx is the type (as in + * PositionAreaAxis and yyy is the PositionAreaTrack + * https://drafts.csswg.org/css-anchor-position-1/#propdef-position-area + */ +enum PositionAreaKeyword +#ifdef __cplusplus + : uint8_t +#endif // __cplusplus + { + None = 0, + Center = (uint8_t)PositionAreaTrack_Center, + SpanAll = (uint8_t)PositionAreaTrack_SpanAll, + Start = (uint8_t)PositionAreaTrack_Start, + End = (uint8_t)PositionAreaTrack_End, + SpanStart = (uint8_t)PositionAreaTrack_SpanStart, + SpanEnd = (uint8_t)PositionAreaTrack_SpanEnd, + Top = (((uint8_t)PositionAreaAxis_Vertical << AXIS_SHIFT) | (uint8_t)PositionAreaTrack_Start), + Bottom = (((uint8_t)PositionAreaAxis_Vertical << AXIS_SHIFT) | (uint8_t)PositionAreaTrack_End), +}; +#ifndef __cplusplus +typedef uint8_t PositionAreaKeyword; +#endif // __cplusplus + +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus + +void root(PositionAreaKeyword, PositionAreaTrack, PositionAreaAxis); + +#ifdef __cplusplus +} // extern "C" +#endif // __cplusplus + +#endif +#if 0 +' ''' +#endif diff --git a/tests/expectations/enum_self_flags.cpp b/tests/expectations/enum_self_flags.cpp new file mode 100644 index 00000000..46186c21 --- /dev/null +++ b/tests/expectations/enum_self_flags.cpp @@ -0,0 +1,76 @@ +#if 0 +''' ' +#endif + +// FIXME: Mis-generated in C mode with enum.prefix_with_name = false, and in +// C++ mode with it set to true... +#if defined(__cplusplus) && !defined(CBINDGEN_CPP_COMPAT) + + +#include +#include +#include +#include +#include + +constexpr static const uintptr_t AXIS_SHIFT = 3; + +constexpr static const uintptr_t SELF_WM_SHIFT = 6; + +constexpr static const uint8_t SELF_WM = (1 << 6); + +/// Specifies which tracks(s) on the axis that the position-area span occupies. +/// Represented as 3 bits: start, center, end track. +enum class PositionAreaTrack : uint8_t { + /// First track + Start = 1, + /// First and center. + SpanStart = 3, + /// Last track. + End = 4, + /// Last and center. + SpanEnd = 6, + /// Center track. + Center = 2, + /// All tracks + SpanAll = 7, +}; + +/// A three-bit value that represents the axis in which position-area operates on. +/// Represented as 3 bits: axis type (physical or logical), direction type (physical or logical), +/// axis value. +enum class PositionAreaAxis : uint8_t { + Horizontal = 0, + Vertical = 1, + X = 2, + Y = 3, + Inline = 6, + Block = 7, +}; + +/// Possible values for the `position-area` property's keywords. +/// Represented by [0z xxx yyy], where z means "self wm resolution", xxx is the type (as in +/// PositionAreaAxis and yyy is the PositionAreaTrack +/// https://drafts.csswg.org/css-anchor-position-1/#propdef-position-area +enum class PositionAreaKeyword : uint8_t { + None = 0, + Center = (uint8_t)PositionAreaTrack::Center, + SpanAll = (uint8_t)PositionAreaTrack::SpanAll, + Start = (uint8_t)PositionAreaTrack::Start, + End = (uint8_t)PositionAreaTrack::End, + SpanStart = (uint8_t)PositionAreaTrack::SpanStart, + SpanEnd = (uint8_t)PositionAreaTrack::SpanEnd, + Top = (((uint8_t)PositionAreaAxis::Vertical << AXIS_SHIFT) | (uint8_t)PositionAreaTrack::Start), + Bottom = (((uint8_t)PositionAreaAxis::Vertical << AXIS_SHIFT) | (uint8_t)PositionAreaTrack::End), +}; + +extern "C" { + +void root(PositionAreaKeyword, PositionAreaTrack, PositionAreaAxis); + +} // extern "C" + +#endif +#if 0 +' ''' +#endif diff --git a/tests/expectations/enum_self_flags.pyx b/tests/expectations/enum_self_flags.pyx new file mode 100644 index 00000000..0f65b97b --- /dev/null +++ b/tests/expectations/enum_self_flags.pyx @@ -0,0 +1,74 @@ +#if 0 +''' ' +#endif + +// FIXME: Mis-generated in C mode with enum.prefix_with_name = false, and in +// C++ mode with it set to true... +#if defined(__cplusplus) && !defined(CBINDGEN_CPP_COMPAT) + + +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 *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + const uintptr_t AXIS_SHIFT # = 3 + + const uintptr_t SELF_WM_SHIFT # = 6 + + const uint8_t SELF_WM # = (1 << 6) + + # Specifies which tracks(s) on the axis that the position-area span occupies. + # Represented as 3 bits: start, center, end track. + cdef enum: + # First track + Start # = 1, + # First and center. + SpanStart # = 3, + # Last track. + End # = 4, + # Last and center. + SpanEnd # = 6, + # Center track. + Center # = 2, + # All tracks + SpanAll # = 7, + ctypedef uint8_t PositionAreaTrack; + + # A three-bit value that represents the axis in which position-area operates on. + # Represented as 3 bits: axis type (physical or logical), direction type (physical or logical), + # axis value. + cdef enum: + Horizontal # = 0, + Vertical # = 1, + X # = 2, + Y # = 3, + Inline # = 6, + Block # = 7, + ctypedef uint8_t PositionAreaAxis; + + # Possible values for the `position-area` property's keywords. + # Represented by [0z xxx yyy], where z means "self wm resolution", xxx is the type (as in + # PositionAreaAxis and yyy is the PositionAreaTrack + # https://drafts.csswg.org/css-anchor-position-1/#propdef-position-area + cdef enum: + None # = 0, + Center # = PositionAreaTrack_Center, + SpanAll # = PositionAreaTrack_SpanAll, + Start # = PositionAreaTrack_Start, + End # = PositionAreaTrack_End, + SpanStart # = PositionAreaTrack_SpanStart, + SpanEnd # = PositionAreaTrack_SpanEnd, + Top # = ((PositionAreaAxis_Vertical << AXIS_SHIFT) | PositionAreaTrack_Start), + Bottom # = ((PositionAreaAxis_Vertical << AXIS_SHIFT) | PositionAreaTrack_End), + ctypedef uint8_t PositionAreaKeyword; + + void root(PositionAreaKeyword, PositionAreaTrack, PositionAreaAxis); + +#endif +#if 0 +' ''' +#endif diff --git a/tests/expectations/size_types.c b/tests/expectations/size_types.c index b3b64c0f..5ed52f56 100644 --- a/tests/expectations/size_types.c +++ b/tests/expectations/size_types.c @@ -4,16 +4,16 @@ #include #include -enum IE { - IV, -}; -typedef ptrdiff_t IE; - enum UE { UV, }; typedef size_t UE; +enum IE { + IV, +}; +typedef ptrdiff_t IE; + typedef size_t Usize; typedef ptrdiff_t Isize; diff --git a/tests/expectations/size_types.compat.c b/tests/expectations/size_types.compat.c index 4ca5273c..58428612 100644 --- a/tests/expectations/size_types.compat.c +++ b/tests/expectations/size_types.compat.c @@ -4,26 +4,26 @@ #include #include -enum IE +enum UE #ifdef __cplusplus - : ptrdiff_t + : size_t #endif // __cplusplus { - IV, + UV, }; #ifndef __cplusplus -typedef ptrdiff_t IE; +typedef size_t UE; #endif // __cplusplus -enum UE +enum IE #ifdef __cplusplus - : size_t + : ptrdiff_t #endif // __cplusplus { - UV, + IV, }; #ifndef __cplusplus -typedef size_t UE; +typedef ptrdiff_t IE; #endif // __cplusplus typedef size_t Usize; diff --git a/tests/expectations/size_types.cpp b/tests/expectations/size_types.cpp index ce7b41cc..1b3cc5c5 100644 --- a/tests/expectations/size_types.cpp +++ b/tests/expectations/size_types.cpp @@ -5,14 +5,14 @@ #include #include -enum class IE : ptrdiff_t { - IV, -}; - enum class UE : size_t { UV, }; +enum class IE : ptrdiff_t { + IV, +}; + using Usize = size_t; using Isize = ptrdiff_t; diff --git a/tests/expectations/size_types.pyx b/tests/expectations/size_types.pyx index c08b7c65..656dfc4d 100644 --- a/tests/expectations/size_types.pyx +++ b/tests/expectations/size_types.pyx @@ -6,14 +6,14 @@ cdef extern from *: cdef extern from *: - cdef enum: - IV, - ctypedef ptrdiff_t IE; - cdef enum: UV, ctypedef size_t UE; + cdef enum: + IV, + ctypedef ptrdiff_t IE; + ctypedef size_t Usize; ctypedef ptrdiff_t Isize; diff --git a/tests/rust/enum_self_flags.rs b/tests/rust/enum_self_flags.rs new file mode 100644 index 00000000..ac6ab189 --- /dev/null +++ b/tests/rust/enum_self_flags.rs @@ -0,0 +1,65 @@ +/// A three-bit value that represents the axis in which position-area operates on. +/// Represented as 3 bits: axis type (physical or logical), direction type (physical or logical), +/// axis value. +#[repr(u8)] +#[derive(Clone, Copy, Debug, Eq, PartialEq)] +#[allow(missing_docs)] +pub enum PositionAreaAxis { + Horizontal = 0b000, + Vertical = 0b001, + + X = 0b010, + Y = 0b011, + + Inline = 0b110, + Block = 0b111, +} + +/// Specifies which tracks(s) on the axis that the position-area span occupies. +/// Represented as 3 bits: start, center, end track. +#[repr(u8)] +#[derive(Clone, Copy, Debug, Eq, PartialEq)] +pub enum PositionAreaTrack { + /// First track + Start = 0b001, + /// First and center. + SpanStart = 0b011, + /// Last track. + End = 0b100, + /// Last and center. + SpanEnd = 0b110, + /// Center track. + Center = 0b010, + /// All tracks + SpanAll = 0b111, +} + +pub const AXIS_SHIFT: usize = 3; +pub const SELF_WM_SHIFT: usize = 6; +pub const SELF_WM: u8 = 1u8 << 6; + +#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)] +#[allow(missing_docs)] +#[repr(u8)] +/// Possible values for the `position-area` property's keywords. +/// Represented by [0z xxx yyy], where z means "self wm resolution", xxx is the type (as in +/// PositionAreaAxis and yyy is the PositionAreaTrack +/// https://drafts.csswg.org/css-anchor-position-1/#propdef-position-area +pub enum PositionAreaKeyword { + #[default] + None = 0, + + Center = PositionAreaTrack::Center as u8, + SpanAll = PositionAreaTrack::SpanAll as u8, + + Start = PositionAreaTrack::Start as u8, + End = PositionAreaTrack::End as u8, + SpanStart = PositionAreaTrack::SpanStart as u8, + SpanEnd = PositionAreaTrack::SpanEnd as u8, + + Top = ((PositionAreaAxis::Vertical as u8) << AXIS_SHIFT) | PositionAreaTrack::Start as u8, + Bottom = ((PositionAreaAxis::Vertical as u8) << AXIS_SHIFT) | PositionAreaTrack::End as u8, +} + +#[no_mangle] +extern "C" fn root(_: PositionAreaKeyword, _: PositionAreaTrack, _: PositionAreaAxis) {} diff --git a/tests/rust/enum_self_flags.toml b/tests/rust/enum_self_flags.toml new file mode 100644 index 00000000..32077b79 --- /dev/null +++ b/tests/rust/enum_self_flags.toml @@ -0,0 +1,23 @@ +header = """ +#if 0 +''' ' +#endif + +// FIXME: Mis-generated in C mode with enum.prefix_with_name = false, and in +// C++ mode with it set to true... +#if defined(__cplusplus) && !defined(CBINDGEN_CPP_COMPAT) +""" + +trailer = """ +#endif +#if 0 +' ''' +#endif +""" + +[enum] +enum_class = true +# prefix_with_name = true + +[struct] +associated_constants_in_body = true diff --git a/tests/tests.rs b/tests/tests.rs index edf90b2c..459c3cf5 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -135,6 +135,7 @@ fn compile( language: Language, style: Option