From f0bef30daa7bb09357508c1d6dbc5512ecaeda6c Mon Sep 17 00:00:00 2001 From: Ingvar Stepanyan <me@rreverser.com> Date: Fri, 17 Nov 2017 01:19:41 +0000 Subject: [PATCH] Simplify opaque struct output in C There is no need for a separate forward struct declaration, just like in case with regular structures. --- src/bindgen/ir/opaque.rs | 2 -- tests/expectations/enum.c | 1 - tests/expectations/monomorph-1.c | 3 --- tests/expectations/monomorph-2.c | 2 -- tests/expectations/monomorph-3.c | 3 --- tests/expectations/simplify-option-ptr.c | 1 - tests/expectations/static.c | 1 - tests/expectations/std_lib.c | 3 --- tests/expectations/struct.c | 1 - tests/expectations/union.c | 1 - 10 files changed, 18 deletions(-) diff --git a/src/bindgen/ir/opaque.rs b/src/bindgen/ir/opaque.rs index 4870992..bf391ad 100644 --- a/src/bindgen/ir/opaque.rs +++ b/src/bindgen/ir/opaque.rs @@ -103,8 +103,6 @@ impl Source for OpaqueItem { self.documentation.write(config, out); if config.language == Language::C { - write!(out, "struct {};", self.name); - out.new_line(); write!(out, "typedef struct {} {};", self.name, self.name); } else { write!(out, "struct {};", self.name); diff --git a/tests/expectations/enum.c b/tests/expectations/enum.c index 109972a..6840677 100644 --- a/tests/expectations/enum.c +++ b/tests/expectations/enum.c @@ -42,7 +42,6 @@ enum E { }; typedef intptr_t E; -struct Opaque; typedef struct Opaque Opaque; void root(Opaque *o, A a, B b, C c, D d, E e); diff --git a/tests/expectations/monomorph-1.c b/tests/expectations/monomorph-1.c index d269ba2..4d3cef6 100644 --- a/tests/expectations/monomorph-1.c +++ b/tests/expectations/monomorph-1.c @@ -2,13 +2,10 @@ #include <stdlib.h> #include <stdbool.h> -struct Bar_Bar_f32; typedef struct Bar_Bar_f32 Bar_Bar_f32; -struct Bar_Foo_f32; typedef struct Bar_Foo_f32 Bar_Foo_f32; -struct Bar_f32; typedef struct Bar_f32 Bar_f32; typedef struct { diff --git a/tests/expectations/monomorph-2.c b/tests/expectations/monomorph-2.c index fa44ab2..a30558f 100644 --- a/tests/expectations/monomorph-2.c +++ b/tests/expectations/monomorph-2.c @@ -2,10 +2,8 @@ #include <stdlib.h> #include <stdbool.h> -struct A; typedef struct A A; -struct B; typedef struct B B; typedef struct { diff --git a/tests/expectations/monomorph-3.c b/tests/expectations/monomorph-3.c index 2c5bb4b..04a9ab3 100644 --- a/tests/expectations/monomorph-3.c +++ b/tests/expectations/monomorph-3.c @@ -2,13 +2,10 @@ #include <stdlib.h> #include <stdbool.h> -struct Bar_Bar_f32; typedef struct Bar_Bar_f32 Bar_Bar_f32; -struct Bar_Foo_f32; typedef struct Bar_Foo_f32 Bar_Foo_f32; -struct Bar_f32; typedef struct Bar_f32 Bar_f32; typedef union { diff --git a/tests/expectations/simplify-option-ptr.c b/tests/expectations/simplify-option-ptr.c index 404c25e..20d02a6 100644 --- a/tests/expectations/simplify-option-ptr.c +++ b/tests/expectations/simplify-option-ptr.c @@ -2,7 +2,6 @@ #include <stdlib.h> #include <stdbool.h> -struct Opaque; typedef struct Opaque Opaque; typedef struct { diff --git a/tests/expectations/static.c b/tests/expectations/static.c index 2266aa2..bb9ddd2 100644 --- a/tests/expectations/static.c +++ b/tests/expectations/static.c @@ -2,7 +2,6 @@ #include <stdlib.h> #include <stdbool.h> -struct Bar; typedef struct Bar Bar; typedef struct { diff --git a/tests/expectations/std_lib.c b/tests/expectations/std_lib.c index 8def5ba..09fe57c 100644 --- a/tests/expectations/std_lib.c +++ b/tests/expectations/std_lib.c @@ -2,13 +2,10 @@ #include <stdlib.h> #include <stdbool.h> -struct Option_i32; typedef struct Option_i32 Option_i32; -struct Result_i32__String; typedef struct Result_i32__String Result_i32__String; -struct Vec_String; typedef struct Vec_String Vec_String; void root(const Vec_String *a, const Option_i32 *b, const Result_i32__String *c); diff --git a/tests/expectations/struct.c b/tests/expectations/struct.c index 677a9ac..f4f33b4 100644 --- a/tests/expectations/struct.c +++ b/tests/expectations/struct.c @@ -2,7 +2,6 @@ #include <stdlib.h> #include <stdbool.h> -struct Opaque; typedef struct Opaque Opaque; typedef struct { diff --git a/tests/expectations/union.c b/tests/expectations/union.c index 07e1035..9ef8898 100644 --- a/tests/expectations/union.c +++ b/tests/expectations/union.c @@ -2,7 +2,6 @@ #include <stdlib.h> #include <stdbool.h> -struct Opaque; typedef struct Opaque Opaque; typedef union { -- GitLab