From 5a4d74b9118928946dd10a49c4891a2610c55437 Mon Sep 17 00:00:00 2001 From: TheKK Date: Thu, 5 Mar 2020 13:33:50 +0800 Subject: [PATCH] ir: escape export_name while writing source of EnumVariant --- src/bindgen/ir/enumeration.rs | 2 ++ tests/expectations/both/reserved.c | 24 ++++++++++++++- tests/expectations/both/reserved.compat.c | 30 ++++++++++++++++++- tests/expectations/reserved.c | 24 ++++++++++++++- tests/expectations/reserved.compat.c | 30 ++++++++++++++++++- tests/expectations/reserved.cpp | 23 ++++++++++++++- tests/expectations/tag/reserved.c | 30 ++++++++++++++++++- tests/expectations/tag/reserved.compat.c | 36 ++++++++++++++++++++++- tests/rust/reserved.rs | 7 +++++ 9 files changed, 199 insertions(+), 7 deletions(-) diff --git a/src/bindgen/ir/enumeration.rs b/src/bindgen/ir/enumeration.rs index 7ff57c2..49a272b 100644 --- a/src/bindgen/ir/enumeration.rs +++ b/src/bindgen/ir/enumeration.rs @@ -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); diff --git a/tests/expectations/both/reserved.c b/tests/expectations/both/reserved.c index 129ea2b..3909b0e 100644 --- a/tests/expectations/both/reserved.c +++ b/tests/expectations/both/reserved.c @@ -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_); diff --git a/tests/expectations/both/reserved.compat.c b/tests/expectations/both/reserved.compat.c index 5c52f1e..59f5c04 100644 --- a/tests/expectations/both/reserved.compat.c +++ b/tests/expectations/both/reserved.compat.c @@ -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" diff --git a/tests/expectations/reserved.c b/tests/expectations/reserved.c index 6aba4c3..aa78bef 100644 --- a/tests/expectations/reserved.c +++ b/tests/expectations/reserved.c @@ -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_); diff --git a/tests/expectations/reserved.compat.c b/tests/expectations/reserved.compat.c index ae551d5..c15ff98 100644 --- a/tests/expectations/reserved.compat.c +++ b/tests/expectations/reserved.compat.c @@ -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" diff --git a/tests/expectations/reserved.cpp b/tests/expectations/reserved.cpp index 3394147..24c337a 100644 --- a/tests/expectations/reserved.cpp +++ b/tests/expectations/reserved.cpp @@ -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" diff --git a/tests/expectations/tag/reserved.c b/tests/expectations/tag/reserved.c index 53ff8e7..abda999 100644 --- a/tests/expectations/tag/reserved.c +++ b/tests/expectations/tag/reserved.c @@ -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_); diff --git a/tests/expectations/tag/reserved.compat.c b/tests/expectations/tag/reserved.compat.c index ab17d8b..bd1267f 100644 --- a/tests/expectations/tag/reserved.compat.c +++ b/tests/expectations/tag/reserved.compat.c @@ -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" diff --git a/tests/rust/reserved.rs b/tests/rust/reserved.rs index 3d55ac0..df9d9a5 100644 --- a/tests/rust/reserved.rs +++ b/tests/rust/reserved.rs @@ -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, ) { }