Skip to content

Commit

Permalink
ir: escape export_name while writing source of EnumVariant
Browse files Browse the repository at this point in the history
  • Loading branch information
TheKK authored and emilio committed Mar 9, 2020
1 parent e2b2c81 commit 5a4d74b
Show file tree
Hide file tree
Showing 9 changed files with 199 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/bindgen/ir/enumeration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,8 @@ impl Item for Enum {
}

for variant in &mut self.variants {
reserved::escape(&mut variant.export_name);

if let Some((ref mut field_name, ref mut body)) = variant.body {
body.rename_for_config(config);
reserved::escape(field_name);
Expand Down
24 changes: 23 additions & 1 deletion tests/expectations/both/reserved.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,26 @@ typedef struct E {
};
} E;

void root(A a, B b, C c, E e, int32_t namespace_, float float_);
enum F_Tag {
double_,
float_,
};
typedef uint8_t F_Tag;

typedef struct double_Body {
double _0;
} double_Body;

typedef struct float_Body {
float _0;
} float_Body;

typedef struct F {
F_Tag tag;
union {
double_Body double_;
float_Body float_;
};
} F;

void root(A a, B b, C c, E e, F f, int32_t namespace_, float float_);
30 changes: 29 additions & 1 deletion tests/expectations/both/reserved.compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,39 @@ typedef struct E {
};
} E;

enum F_Tag
#ifdef __cplusplus
: uint8_t
#endif // __cplusplus
{
double_,
float_,
};
#ifndef __cplusplus
typedef uint8_t F_Tag;
#endif // __cplusplus

typedef struct double_Body {
double _0;
} double_Body;

typedef struct float_Body {
float _0;
} float_Body;

typedef struct F {
F_Tag tag;
union {
double_Body double_;
float_Body float_;
};
} F;

#ifdef __cplusplus
extern "C" {
#endif // __cplusplus

void root(A a, B b, C c, E e, int32_t namespace_, float float_);
void root(A a, B b, C c, E e, F f, int32_t namespace_, float float_);

#ifdef __cplusplus
} // extern "C"
Expand Down
24 changes: 23 additions & 1 deletion tests/expectations/reserved.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,26 @@ typedef struct {
};
} E;

void root(A a, B b, C c, E e, int32_t namespace_, float float_);
enum F_Tag {
double_,
float_,
};
typedef uint8_t F_Tag;

typedef struct {
double _0;
} double_Body;

typedef struct {
float _0;
} float_Body;

typedef struct {
F_Tag tag;
union {
double_Body double_;
float_Body float_;
};
} F;

void root(A a, B b, C c, E e, F f, int32_t namespace_, float float_);
30 changes: 29 additions & 1 deletion tests/expectations/reserved.compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,39 @@ typedef struct {
};
} E;

enum F_Tag
#ifdef __cplusplus
: uint8_t
#endif // __cplusplus
{
double_,
float_,
};
#ifndef __cplusplus
typedef uint8_t F_Tag;
#endif // __cplusplus

typedef struct {
double _0;
} double_Body;

typedef struct {
float _0;
} float_Body;

typedef struct {
F_Tag tag;
union {
double_Body double_;
float_Body float_;
};
} F;

#ifdef __cplusplus
extern "C" {
#endif // __cplusplus

void root(A a, B b, C c, E e, int32_t namespace_, float float_);
void root(A a, B b, C c, E e, F f, int32_t namespace_, float float_);

#ifdef __cplusplus
} // extern "C"
Expand Down
23 changes: 22 additions & 1 deletion tests/expectations/reserved.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,29 @@ struct E {
};
};

struct F {
enum class Tag : uint8_t {
double_,
float_,
};

struct double_Body {
double _0;
};

struct float_Body {
float _0;
};

Tag tag;
union {
double_Body double_;
float_Body float_;
};
};

extern "C" {

void root(A a, B b, C c, E e, int32_t namespace_, float float_);
void root(A a, B b, C c, E e, F f, int32_t namespace_, float float_);

} // extern "C"
30 changes: 29 additions & 1 deletion tests/expectations/tag/reserved.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,32 @@ struct E {
};
};

void root(struct A a, struct B b, struct C c, struct E e, int32_t namespace_, float float_);
enum F_Tag {
double_,
float_,
};
typedef uint8_t F_Tag;

struct double_Body {
double _0;
};

struct float_Body {
float _0;
};

struct F {
F_Tag tag;
union {
struct double_Body double_;
struct float_Body float_;
};
};

void root(struct A a,
struct B b,
struct C c,
struct E e,
struct F f,
int32_t namespace_,
float float_);
36 changes: 35 additions & 1 deletion tests/expectations/tag/reserved.compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,45 @@ struct E {
};
};

enum F_Tag
#ifdef __cplusplus
: uint8_t
#endif // __cplusplus
{
double_,
float_,
};
#ifndef __cplusplus
typedef uint8_t F_Tag;
#endif // __cplusplus

struct double_Body {
double _0;
};

struct float_Body {
float _0;
};

struct F {
F_Tag tag;
union {
struct double_Body double_;
struct float_Body float_;
};
};

#ifdef __cplusplus
extern "C" {
#endif // __cplusplus

void root(struct A a, struct B b, struct C c, struct E e, int32_t namespace_, float float_);
void root(struct A a,
struct B b,
struct C c,
struct E e,
struct F f,
int32_t namespace_,
float float_);

#ifdef __cplusplus
} // extern "C"
Expand Down
7 changes: 7 additions & 0 deletions tests/rust/reserved.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,19 @@ enum E {
Float(f32),
}

#[repr(C, u8)]
enum F {
double(f64),
float(f32),
}

#[no_mangle]
pub extern "C" fn root(
a: A,
b: B,
c: C,
e: E,
f: F,
namespace: i32,
float: f32,
) { }

0 comments on commit 5a4d74b

Please sign in to comment.