From cb8266620596222b1cd9dbe6551cc1e3e8bb7f72 Mon Sep 17 00:00:00 2001 From: oblique Date: Tue, 17 Sep 2019 21:44:34 +0300 Subject: Add `disable_nested_struct_naming` option (#1610) The following structs have different names for C and C++. In case of C they are visible as `foo` and `bar`. In case of C++ they are visible as `foo` and `foo::bar`. By default bindgen follows C++ naming to avoid generating duplicate names. With this option the following structs will be named as `foo` and `bar` instead of `foo` and `foo_bar`. ``` struct foo { struct bar { } b; }; ``` In case of an unnamed definition we build the canonical name from the inner most named definition. For example the following will generate `baz__bindgen_ty_1`: ``` struct foo { struct bar { struct baz { struct { } u; } z; } b; }; ``` This option should be used only for C headers. It is needed in some rare situations where user used another code generator that already mangled nested definitions. A real life example is [asn1c] with `-fcompound-names` option. [asn1c]: https://github.com/vlm/asn1c --- tests/headers/disable-nested-struct-naming.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 tests/headers/disable-nested-struct-naming.h (limited to 'tests/headers/disable-nested-struct-naming.h') diff --git a/tests/headers/disable-nested-struct-naming.h b/tests/headers/disable-nested-struct-naming.h new file mode 100644 index 00000000..0e4fccb6 --- /dev/null +++ b/tests/headers/disable-nested-struct-naming.h @@ -0,0 +1,24 @@ +// bindgen-flags: --disable-nested-struct-naming + +struct foo { + struct bar1 { + int x1; + struct { + int x2; + struct { + int x3; + struct bar4 { + int x4; + } b4; + } b3; + } b2; + } b1; +}; + +struct { + struct { + struct baz { + int x; + } b; + } anon2; +} anon1; -- cgit v1.2.3