Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/bindgen/ir/enumeration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,10 +494,12 @@ impl Source for Enum {
fn write<F: Write>(&self, config: &Config, out: &mut SourceWriter<F>) {
let size = self.repr.ty.map(|ty| match ty {
ReprType::USize => "uintptr_t",
ReprType::U64 => "uint64_t",
ReprType::U32 => "uint32_t",
ReprType::U16 => "uint16_t",
ReprType::U8 => "uint8_t",
ReprType::ISize => "intptr_t",
ReprType::I64 => "int64_t",
ReprType::I32 => "int32_t",
ReprType::I16 => "int16_t",
ReprType::I8 => "int8_t",
Expand Down
4 changes: 4 additions & 0 deletions src/bindgen/ir/repr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ pub enum ReprType {
U8,
U16,
U32,
U64,
USize,
I8,
I16,
I32,
I64,
ISize,
}

Expand Down Expand Up @@ -88,10 +90,12 @@ impl Repr {
("u8", None) => ReprType::U8,
("u16", None) => ReprType::U16,
("u32", None) => ReprType::U32,
("u64", None) => ReprType::U64,
("usize", None) => ReprType::USize,
("i8", None) => ReprType::I8,
("i16", None) => ReprType::I16,
("i32", None) => ReprType::I32,
("i64", None) => ReprType::I64,
("isize", None) => ReprType::ISize,
("C", None) => {
repr.style = ReprStyle::C;
Expand Down
114 changes: 61 additions & 53 deletions tests/expectations/both/enum.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,113 +9,97 @@ enum A {
a3,
a4 = 5,
};
typedef uint32_t A;
typedef uint64_t A;

enum B {
b1 = 0,
b2 = 2,
b3,
b4 = 5,
};
typedef uint16_t B;
typedef uint32_t B;

enum C {
c1 = 0,
c2 = 2,
c3,
c4 = 5,
};
typedef uint8_t C;
typedef uint16_t C;

enum D {
d1 = 0,
d2 = 2,
d3,
d4 = 5,
};
typedef uintptr_t D;
typedef uint8_t D;

enum E {
e1 = 0,
e2 = 2,
e3,
e4 = 5,
};
typedef intptr_t E;

typedef enum K {
k1,
k2,
k3,
k4,
} K;

enum L {
l1 = -1,
l2 = 0,
l3 = 1,
};
typedef int8_t L;
typedef uintptr_t E;

typedef struct I I;
enum F {
f1 = 0,
f2 = 2,
f3,
f4 = 5,
};
typedef intptr_t F;

typedef enum L {
l1,
l2,
l3,
l4,
} L;

enum M {
m1 = -1,
m2 = 0,
m3 = 1,
};
typedef int8_t M;

typedef struct J J;

typedef struct K K;

typedef struct Opaque Opaque;

enum F_Tag {
enum G_Tag {
Foo,
Bar,
Baz,
};
typedef uint8_t F_Tag;
typedef uint8_t G_Tag;

typedef struct Foo_Body {
F_Tag tag;
G_Tag tag;
int16_t _0;
} Foo_Body;

typedef struct Bar_Body {
F_Tag tag;
G_Tag tag;
uint8_t x;
int16_t y;
} Bar_Body;

typedef union F {
F_Tag tag;
typedef union G {
G_Tag tag;
Foo_Body foo;
Bar_Body bar;
} F;

typedef enum G_Tag {
G_Foo,
G_Bar,
G_Baz,
} G_Tag;

typedef struct G_Foo_Body {
int16_t _0;
} G_Foo_Body;

typedef struct G_Bar_Body {
uint8_t x;
int16_t y;
} G_Bar_Body;

typedef struct G {
G_Tag tag;
union {
G_Foo_Body foo;
G_Bar_Body bar;
};
} G;

enum H_Tag {
typedef enum H_Tag {
H_Foo,
H_Bar,
H_Baz,
};
typedef uint8_t H_Tag;
} H_Tag;

typedef struct H_Foo_Body {
int16_t _0;
Expand All @@ -134,4 +118,28 @@ typedef struct H {
};
} H;

void root(Opaque *o, A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k, L l);
enum I_Tag {
I_Foo,
I_Bar,
I_Baz,
};
typedef uint8_t I_Tag;

typedef struct I_Foo_Body {
int16_t _0;
} I_Foo_Body;

typedef struct I_Bar_Body {
uint8_t x;
int16_t y;
} I_Bar_Body;

typedef struct I {
I_Tag tag;
union {
I_Foo_Body foo;
I_Bar_Body bar;
};
} I;

void root(Opaque *o, A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k, L l, M m);
Loading