parent
770f352375
commit
5b418d968c
src/bindgen
tests
@ -559,6 +559,10 @@ impl StructConfig {
|
|||||||
pub struct EnumConfig {
|
pub struct EnumConfig {
|
||||||
/// The rename rule to apply to the name of enum variants
|
/// The rename rule to apply to the name of enum variants
|
||||||
pub rename_variants: RenameRule,
|
pub rename_variants: RenameRule,
|
||||||
|
/// The rename rule to apply to the names of the union fields in C/C++
|
||||||
|
/// generated from the Rust enum. Applied before rename_variants
|
||||||
|
/// rename rule. Defaults to SnakeCase.
|
||||||
|
pub rename_variant_name_fields: RenameRule,
|
||||||
/// Whether to add a `Sentinel` value at the end of every enum
|
/// Whether to add a `Sentinel` value at the end of every enum
|
||||||
/// This is useful in Gecko for IPC serialization
|
/// This is useful in Gecko for IPC serialization
|
||||||
pub add_sentinel: bool,
|
pub add_sentinel: bool,
|
||||||
@ -600,6 +604,7 @@ impl Default for EnumConfig {
|
|||||||
fn default() -> EnumConfig {
|
fn default() -> EnumConfig {
|
||||||
EnumConfig {
|
EnumConfig {
|
||||||
rename_variants: RenameRule::None,
|
rename_variants: RenameRule::None,
|
||||||
|
rename_variant_name_fields: RenameRule::SnakeCase,
|
||||||
add_sentinel: false,
|
add_sentinel: false,
|
||||||
prefix_with_name: false,
|
prefix_with_name: false,
|
||||||
derive_helper_methods: false,
|
derive_helper_methods: false,
|
||||||
|
@ -149,11 +149,16 @@ impl EnumVariant {
|
|||||||
if let Some(b) = enum_annotations.bool("derive-ostream") {
|
if let Some(b) = enum_annotations.bool("derive-ostream") {
|
||||||
annotations.add_default("derive-ostream", AnnotationValue::Bool(b));
|
annotations.add_default("derive-ostream", AnnotationValue::Bool(b));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let body_rule = enum_annotations
|
||||||
|
.parse_atom::<RenameRule>("rename-variant-name-fields")
|
||||||
|
.unwrap_or(config.enumeration.rename_variant_name_fields);
|
||||||
|
|
||||||
let body = match variant.fields {
|
let body = match variant.fields {
|
||||||
syn::Fields::Unit => VariantBody::Empty(annotations),
|
syn::Fields::Unit => VariantBody::Empty(annotations),
|
||||||
syn::Fields::Named(ref fields) => {
|
syn::Fields::Named(ref fields) => {
|
||||||
let path = Path::new(format!("{}_Body", variant.ident));
|
let path = Path::new(format!("{}_Body", variant.ident));
|
||||||
let name = RenameRule::SnakeCase
|
let name = body_rule
|
||||||
.apply(
|
.apply(
|
||||||
&variant.ident.unraw().to_string(),
|
&variant.ident.unraw().to_string(),
|
||||||
IdentifierType::StructMember,
|
IdentifierType::StructMember,
|
||||||
@ -179,7 +184,7 @@ impl EnumVariant {
|
|||||||
}
|
}
|
||||||
syn::Fields::Unnamed(ref fields) => {
|
syn::Fields::Unnamed(ref fields) => {
|
||||||
let path = Path::new(format!("{}_Body", variant.ident));
|
let path = Path::new(format!("{}_Body", variant.ident));
|
||||||
let name = RenameRule::SnakeCase
|
let name = body_rule
|
||||||
.apply(
|
.apply(
|
||||||
&variant.ident.unraw().to_string(),
|
&variant.ident.unraw().to_string(),
|
||||||
IdentifierType::StructMember,
|
IdentifierType::StructMember,
|
||||||
|
@ -204,6 +204,27 @@ typedef struct Q {
|
|||||||
};
|
};
|
||||||
} Q;
|
} Q;
|
||||||
|
|
||||||
|
typedef enum R_Tag {
|
||||||
|
IRFoo,
|
||||||
|
IRBar,
|
||||||
|
IRBaz,
|
||||||
|
} R_Tag;
|
||||||
|
|
||||||
|
typedef struct IRBar_Body {
|
||||||
|
uint8_t x;
|
||||||
|
int16_t y;
|
||||||
|
} IRBar_Body;
|
||||||
|
|
||||||
|
typedef struct R {
|
||||||
|
R_Tag tag;
|
||||||
|
union {
|
||||||
|
struct {
|
||||||
|
int16_t IRFoo;
|
||||||
|
};
|
||||||
|
IRBar_Body IRBar;
|
||||||
|
};
|
||||||
|
} R;
|
||||||
|
|
||||||
void root(struct Opaque *opaque,
|
void root(struct Opaque *opaque,
|
||||||
A a,
|
A a,
|
||||||
B b,
|
B b,
|
||||||
@ -221,7 +242,8 @@ void root(struct Opaque *opaque,
|
|||||||
enum N n,
|
enum N n,
|
||||||
O o,
|
O o,
|
||||||
struct P p,
|
struct P p,
|
||||||
struct Q q);
|
struct Q q,
|
||||||
|
struct R r);
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
''' '
|
''' '
|
||||||
|
@ -270,6 +270,27 @@ typedef struct Q {
|
|||||||
};
|
};
|
||||||
} Q;
|
} Q;
|
||||||
|
|
||||||
|
typedef enum R_Tag {
|
||||||
|
IRFoo,
|
||||||
|
IRBar,
|
||||||
|
IRBaz,
|
||||||
|
} R_Tag;
|
||||||
|
|
||||||
|
typedef struct IRBar_Body {
|
||||||
|
uint8_t x;
|
||||||
|
int16_t y;
|
||||||
|
} IRBar_Body;
|
||||||
|
|
||||||
|
typedef struct R {
|
||||||
|
R_Tag tag;
|
||||||
|
union {
|
||||||
|
struct {
|
||||||
|
int16_t IRFoo;
|
||||||
|
};
|
||||||
|
IRBar_Body IRBar;
|
||||||
|
};
|
||||||
|
} R;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif // __cplusplus
|
#endif // __cplusplus
|
||||||
@ -291,7 +312,8 @@ void root(struct Opaque *opaque,
|
|||||||
enum N n,
|
enum N n,
|
||||||
O o,
|
O o,
|
||||||
struct P p,
|
struct P p,
|
||||||
struct Q q);
|
struct Q q,
|
||||||
|
struct R r);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
} // extern "C"
|
} // extern "C"
|
||||||
|
@ -204,6 +204,27 @@ typedef struct {
|
|||||||
};
|
};
|
||||||
} Q;
|
} Q;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
IRFoo,
|
||||||
|
IRBar,
|
||||||
|
IRBaz,
|
||||||
|
} R_Tag;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint8_t x;
|
||||||
|
int16_t y;
|
||||||
|
} IRBar_Body;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
R_Tag tag;
|
||||||
|
union {
|
||||||
|
struct {
|
||||||
|
int16_t IRFoo;
|
||||||
|
};
|
||||||
|
IRBar_Body IRBar;
|
||||||
|
};
|
||||||
|
} R;
|
||||||
|
|
||||||
void root(Opaque *opaque,
|
void root(Opaque *opaque,
|
||||||
A a,
|
A a,
|
||||||
B b,
|
B b,
|
||||||
@ -221,7 +242,8 @@ void root(Opaque *opaque,
|
|||||||
N n,
|
N n,
|
||||||
O o,
|
O o,
|
||||||
P p,
|
P p,
|
||||||
Q q);
|
Q q,
|
||||||
|
R r);
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
''' '
|
''' '
|
||||||
|
@ -270,6 +270,27 @@ typedef struct {
|
|||||||
};
|
};
|
||||||
} Q;
|
} Q;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
IRFoo,
|
||||||
|
IRBar,
|
||||||
|
IRBaz,
|
||||||
|
} R_Tag;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint8_t x;
|
||||||
|
int16_t y;
|
||||||
|
} IRBar_Body;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
R_Tag tag;
|
||||||
|
union {
|
||||||
|
struct {
|
||||||
|
int16_t IRFoo;
|
||||||
|
};
|
||||||
|
IRBar_Body IRBar;
|
||||||
|
};
|
||||||
|
} R;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif // __cplusplus
|
#endif // __cplusplus
|
||||||
@ -291,7 +312,8 @@ void root(Opaque *opaque,
|
|||||||
N n,
|
N n,
|
||||||
O o,
|
O o,
|
||||||
P p,
|
P p,
|
||||||
Q q);
|
Q q,
|
||||||
|
R r);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
} // extern "C"
|
} // extern "C"
|
||||||
|
@ -208,6 +208,29 @@ struct Q {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct R {
|
||||||
|
enum class Tag {
|
||||||
|
IRFoo,
|
||||||
|
IRBar,
|
||||||
|
IRBaz,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct IRFoo_Body {
|
||||||
|
int16_t _0;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct IRBar_Body {
|
||||||
|
uint8_t x;
|
||||||
|
int16_t y;
|
||||||
|
};
|
||||||
|
|
||||||
|
Tag tag;
|
||||||
|
union {
|
||||||
|
IRFoo_Body IRFoo;
|
||||||
|
IRBar_Body IRBar;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
||||||
void root(Opaque *opaque,
|
void root(Opaque *opaque,
|
||||||
@ -227,7 +250,8 @@ void root(Opaque *opaque,
|
|||||||
N n,
|
N n,
|
||||||
O o,
|
O o,
|
||||||
P p,
|
P p,
|
||||||
Q q);
|
Q q,
|
||||||
|
R r);
|
||||||
|
|
||||||
} // extern "C"
|
} // extern "C"
|
||||||
|
|
||||||
|
@ -165,6 +165,20 @@ cdef extern from *:
|
|||||||
uint32_t *ok;
|
uint32_t *ok;
|
||||||
uint32_t err;
|
uint32_t err;
|
||||||
|
|
||||||
|
ctypedef enum R_Tag:
|
||||||
|
IRFoo,
|
||||||
|
IRBar,
|
||||||
|
IRBaz,
|
||||||
|
|
||||||
|
ctypedef struct IRBar_Body:
|
||||||
|
uint8_t x;
|
||||||
|
int16_t y;
|
||||||
|
|
||||||
|
ctypedef struct R:
|
||||||
|
R_Tag tag;
|
||||||
|
int16_t IRFoo;
|
||||||
|
IRBar_Body IRBar;
|
||||||
|
|
||||||
void root(Opaque *opaque,
|
void root(Opaque *opaque,
|
||||||
A a,
|
A a,
|
||||||
B b,
|
B b,
|
||||||
@ -182,7 +196,8 @@ cdef extern from *:
|
|||||||
N n,
|
N n,
|
||||||
O o,
|
O o,
|
||||||
P p,
|
P p,
|
||||||
Q q);
|
Q q,
|
||||||
|
R r);
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
''' '
|
''' '
|
||||||
|
@ -204,6 +204,27 @@ struct Q {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum R_Tag {
|
||||||
|
IRFoo,
|
||||||
|
IRBar,
|
||||||
|
IRBaz,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct IRBar_Body {
|
||||||
|
uint8_t x;
|
||||||
|
int16_t y;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct R {
|
||||||
|
enum R_Tag tag;
|
||||||
|
union {
|
||||||
|
struct {
|
||||||
|
int16_t IRFoo;
|
||||||
|
};
|
||||||
|
struct IRBar_Body IRBar;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
void root(struct Opaque *opaque,
|
void root(struct Opaque *opaque,
|
||||||
A a,
|
A a,
|
||||||
B b,
|
B b,
|
||||||
@ -221,7 +242,8 @@ void root(struct Opaque *opaque,
|
|||||||
enum N n,
|
enum N n,
|
||||||
O o,
|
O o,
|
||||||
struct P p,
|
struct P p,
|
||||||
struct Q q);
|
struct Q q,
|
||||||
|
struct R r);
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
''' '
|
''' '
|
||||||
|
@ -270,6 +270,27 @@ struct Q {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum R_Tag {
|
||||||
|
IRFoo,
|
||||||
|
IRBar,
|
||||||
|
IRBaz,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct IRBar_Body {
|
||||||
|
uint8_t x;
|
||||||
|
int16_t y;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct R {
|
||||||
|
enum R_Tag tag;
|
||||||
|
union {
|
||||||
|
struct {
|
||||||
|
int16_t IRFoo;
|
||||||
|
};
|
||||||
|
struct IRBar_Body IRBar;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif // __cplusplus
|
#endif // __cplusplus
|
||||||
@ -291,7 +312,8 @@ void root(struct Opaque *opaque,
|
|||||||
enum N n,
|
enum N n,
|
||||||
O o,
|
O o,
|
||||||
struct P p,
|
struct P p,
|
||||||
struct Q q);
|
struct Q q,
|
||||||
|
struct R r);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
} // extern "C"
|
} // extern "C"
|
||||||
|
@ -165,6 +165,20 @@ cdef extern from *:
|
|||||||
uint32_t *ok;
|
uint32_t *ok;
|
||||||
uint32_t err;
|
uint32_t err;
|
||||||
|
|
||||||
|
cdef enum R_Tag:
|
||||||
|
IRFoo,
|
||||||
|
IRBar,
|
||||||
|
IRBaz,
|
||||||
|
|
||||||
|
cdef struct IRBar_Body:
|
||||||
|
uint8_t x;
|
||||||
|
int16_t y;
|
||||||
|
|
||||||
|
cdef struct R:
|
||||||
|
R_Tag tag;
|
||||||
|
int16_t IRFoo;
|
||||||
|
IRBar_Body IRBar;
|
||||||
|
|
||||||
void root(Opaque *opaque,
|
void root(Opaque *opaque,
|
||||||
A a,
|
A a,
|
||||||
B b,
|
B b,
|
||||||
@ -182,7 +196,8 @@ cdef extern from *:
|
|||||||
N n,
|
N n,
|
||||||
O o,
|
O o,
|
||||||
P p,
|
P p,
|
||||||
Q q);
|
Q q,
|
||||||
|
R r);
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
''' '
|
''' '
|
||||||
|
@ -133,6 +133,14 @@ enum Q {
|
|||||||
Err(u32),
|
Err(u32),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// cbindgen:rename-variant-name-fields=None
|
||||||
|
#[repr(C)]
|
||||||
|
enum R {
|
||||||
|
IRFoo(i16),
|
||||||
|
IRBar { x: u8, y: i16 },
|
||||||
|
IRBaz,
|
||||||
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn root(
|
pub extern "C" fn root(
|
||||||
opaque: *mut Opaque,
|
opaque: *mut Opaque,
|
||||||
@ -153,5 +161,6 @@ pub extern "C" fn root(
|
|||||||
o: O,
|
o: O,
|
||||||
p: P,
|
p: P,
|
||||||
q: Q,
|
q: Q,
|
||||||
|
r: R,
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user