Add tests for optional enum convenience constructors
This commit is contained in:
committed by
Ryan Hunt
parent
da550f53b2
commit
cabe1055c4
@@ -17,4 +17,52 @@ typedef struct {
|
|||||||
float y;
|
float y;
|
||||||
} B;
|
} B;
|
||||||
|
|
||||||
void root(A x, B y, C z);
|
enum F_Tag {
|
||||||
|
Foo,
|
||||||
|
Bar,
|
||||||
|
Baz,
|
||||||
|
};
|
||||||
|
typedef uint8_t F_Tag;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
F_Tag tag;
|
||||||
|
int16_t _0;
|
||||||
|
} Foo_Body;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
F_Tag tag;
|
||||||
|
uint8_t x;
|
||||||
|
int16_t y;
|
||||||
|
} Bar_Body;
|
||||||
|
|
||||||
|
typedef union {
|
||||||
|
F_Tag tag;
|
||||||
|
Foo_Body foo;
|
||||||
|
Bar_Body bar;
|
||||||
|
} F;
|
||||||
|
|
||||||
|
enum H_Tag {
|
||||||
|
Hello,
|
||||||
|
There,
|
||||||
|
Everyone,
|
||||||
|
};
|
||||||
|
typedef uint8_t H_Tag;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int16_t _0;
|
||||||
|
} Hello_Body;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint8_t x;
|
||||||
|
int16_t y;
|
||||||
|
} There_Body;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
H_Tag tag;
|
||||||
|
union {
|
||||||
|
Hello_Body hello;
|
||||||
|
There_Body there;
|
||||||
|
};
|
||||||
|
} H;
|
||||||
|
|
||||||
|
void root(A x, B y, C z, F f, H h);
|
||||||
|
|||||||
@@ -26,8 +26,124 @@ struct B {
|
|||||||
float y;
|
float y;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
union F {
|
||||||
|
enum class Tag : uint8_t {
|
||||||
|
Foo,
|
||||||
|
Bar,
|
||||||
|
Baz,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Foo_Body {
|
||||||
|
Tag tag;
|
||||||
|
int16_t _0;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Bar_Body {
|
||||||
|
Tag tag;
|
||||||
|
uint8_t x;
|
||||||
|
int16_t y;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct {
|
||||||
|
Tag tag;
|
||||||
|
};
|
||||||
|
Foo_Body foo;
|
||||||
|
Bar_Body bar;
|
||||||
|
|
||||||
|
static F Foo(int16_t const& a0) {
|
||||||
|
F result;
|
||||||
|
result.foo._0 = a0;
|
||||||
|
result.tag = Tag::Foo;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
static F Bar(uint8_t const& aX,
|
||||||
|
int16_t const& aY) {
|
||||||
|
F result;
|
||||||
|
result.bar.x = aX;
|
||||||
|
result.bar.y = aY;
|
||||||
|
result.tag = Tag::Bar;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
static F Baz() {
|
||||||
|
F result;
|
||||||
|
result.tag = Tag::Baz;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IsFoo() const {
|
||||||
|
return tag == Tag::Foo;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IsBar() const {
|
||||||
|
return tag == Tag::Bar;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IsBaz() const {
|
||||||
|
return tag == Tag::Baz;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct H {
|
||||||
|
enum class Tag : uint8_t {
|
||||||
|
Hello,
|
||||||
|
There,
|
||||||
|
Everyone,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Hello_Body {
|
||||||
|
int16_t _0;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct There_Body {
|
||||||
|
uint8_t x;
|
||||||
|
int16_t y;
|
||||||
|
};
|
||||||
|
|
||||||
|
Tag tag;
|
||||||
|
union {
|
||||||
|
Hello_Body hello;
|
||||||
|
There_Body there;
|
||||||
|
};
|
||||||
|
|
||||||
|
static H Hello(int16_t const& a0) {
|
||||||
|
H result;
|
||||||
|
result.hello._0 = a0;
|
||||||
|
result.tag = Tag::Hello;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
static H There(uint8_t const& aX,
|
||||||
|
int16_t const& aY) {
|
||||||
|
H result;
|
||||||
|
result.there.x = aX;
|
||||||
|
result.there.y = aY;
|
||||||
|
result.tag = Tag::There;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
static H Everyone() {
|
||||||
|
H result;
|
||||||
|
result.tag = Tag::Everyone;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IsHello() const {
|
||||||
|
return tag == Tag::Hello;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IsThere() const {
|
||||||
|
return tag == Tag::There;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IsEveryone() const {
|
||||||
|
return tag == Tag::Everyone;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
||||||
void root(A x, B y, C z);
|
void root(A x, B y, C z, F f, H h);
|
||||||
|
|
||||||
} // extern "C"
|
} // extern "C"
|
||||||
|
|||||||
@@ -17,4 +17,52 @@ typedef struct B {
|
|||||||
float y;
|
float y;
|
||||||
} B;
|
} B;
|
||||||
|
|
||||||
void root(A x, B y, C z);
|
enum F_Tag {
|
||||||
|
Foo,
|
||||||
|
Bar,
|
||||||
|
Baz,
|
||||||
|
};
|
||||||
|
typedef uint8_t F_Tag;
|
||||||
|
|
||||||
|
typedef struct Foo_Body {
|
||||||
|
F_Tag tag;
|
||||||
|
int16_t _0;
|
||||||
|
} Foo_Body;
|
||||||
|
|
||||||
|
typedef struct Bar_Body {
|
||||||
|
F_Tag tag;
|
||||||
|
uint8_t x;
|
||||||
|
int16_t y;
|
||||||
|
} Bar_Body;
|
||||||
|
|
||||||
|
typedef union F {
|
||||||
|
F_Tag tag;
|
||||||
|
Foo_Body foo;
|
||||||
|
Bar_Body bar;
|
||||||
|
} F;
|
||||||
|
|
||||||
|
enum H_Tag {
|
||||||
|
Hello,
|
||||||
|
There,
|
||||||
|
Everyone,
|
||||||
|
};
|
||||||
|
typedef uint8_t H_Tag;
|
||||||
|
|
||||||
|
typedef struct Hello_Body {
|
||||||
|
int16_t _0;
|
||||||
|
} Hello_Body;
|
||||||
|
|
||||||
|
typedef struct There_Body {
|
||||||
|
uint8_t x;
|
||||||
|
int16_t y;
|
||||||
|
} There_Body;
|
||||||
|
|
||||||
|
typedef struct H {
|
||||||
|
H_Tag tag;
|
||||||
|
union {
|
||||||
|
Hello_Body hello;
|
||||||
|
There_Body there;
|
||||||
|
};
|
||||||
|
} H;
|
||||||
|
|
||||||
|
void root(A x, B y, C z, F f, H h);
|
||||||
|
|||||||
@@ -17,4 +17,52 @@ struct B {
|
|||||||
float y;
|
float y;
|
||||||
};
|
};
|
||||||
|
|
||||||
void root(struct A x, struct B y, C z);
|
enum F_Tag {
|
||||||
|
Foo,
|
||||||
|
Bar,
|
||||||
|
Baz,
|
||||||
|
};
|
||||||
|
typedef uint8_t F_Tag;
|
||||||
|
|
||||||
|
struct Foo_Body {
|
||||||
|
F_Tag tag;
|
||||||
|
int16_t _0;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Bar_Body {
|
||||||
|
F_Tag tag;
|
||||||
|
uint8_t x;
|
||||||
|
int16_t y;
|
||||||
|
};
|
||||||
|
|
||||||
|
union F {
|
||||||
|
enum F_Tag tag;
|
||||||
|
struct Foo_Body foo;
|
||||||
|
struct Bar_Body bar;
|
||||||
|
};
|
||||||
|
|
||||||
|
enum H_Tag {
|
||||||
|
Hello,
|
||||||
|
There,
|
||||||
|
Everyone,
|
||||||
|
};
|
||||||
|
typedef uint8_t H_Tag;
|
||||||
|
|
||||||
|
struct Hello_Body {
|
||||||
|
int16_t _0;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct There_Body {
|
||||||
|
uint8_t x;
|
||||||
|
int16_t y;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct H {
|
||||||
|
enum H_Tag tag;
|
||||||
|
union {
|
||||||
|
struct Hello_Body hello;
|
||||||
|
struct There_Body there;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
void root(struct A x, struct B y, C z, union F f, struct H h);
|
||||||
|
|||||||
@@ -36,5 +36,8 @@ enum H {
|
|||||||
pub extern "C" fn root(
|
pub extern "C" fn root(
|
||||||
x: A,
|
x: A,
|
||||||
y: B,
|
y: B,
|
||||||
z: C
|
z: C,
|
||||||
|
f: F,
|
||||||
|
h: H,
|
||||||
) { }
|
) { }
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user