214 Commits

Author SHA1 Message Date
John VanEnk 8048748419 Add a test that demonstrates Style::Tag can emit structures with incorrect sizes in C. 2020-01-26 04:43:27 +01:00
Emilio Cobos Álvarez ec18611e58 bindings: Don't add stray newline in trailer. 2020-01-26 01:54:55 +01:00
Emilio Cobos Álvarez e0d4bc17a5 Make sentinel variant respect regular config
Like enum.prefix_with_name, or documentation style.

Fixes https://github.com/eqrion/cbindgen/issues/458
2020-01-24 15:24:25 +01:00
John VanEnk e8ff3f9b61 Use a magic value other than 42
Shifting a literal (which is an int when a suffix is not present)
generates a warning because the only possible result is 0, and the
programmer probably didn't intend to do that.

Change the shift to a value less than 32. The test exhibiting the
warning wasn't aiming to test integer promotion rules, so I've opted
to change the constant.
2020-01-24 11:22:39 +01:00
yingrueil 8a5662b4a7 Add support for handling line break in document attribute 2020-01-20 14:34:14 +01:00
Emilio Cobos Álvarez ff8e5d591d ir: Add support for Self on struct and union fields. 2020-01-16 21:07:34 +01:00
Emilio Cobos Álvarez 44d7cb4214 ir: Add support for Self in enum variant bodies. 2020-01-16 15:45:05 +01:00
Elliott Mahler 5b227c1062 Add [export.pre_body] to config (#452) 2020-01-13 14:26:21 +01:00
Emilio Cobos Álvarez 688407c7c9 ir: simplify a bit the previous patch. 2020-01-12 16:54:30 +01:00
Alastair Daivis cf406e9640 Support 'swift_name' attributes on generated functions
Fixes #420
2020-01-12 16:18:17 +01:00
Bas Zalmstra 8fabbfa4b5 Fix for finding dependency version in lockfile v2
With lockfile v2 a version is not required for dependencies if the lock
file only contains a single entry for a specified crate.  However, without
a version present, at a later stage, a dependant crate will not be found
in the metadata cache which causes the dependency to be ignored completely.
This commit tries to infer the version of dependant crates when the
version specifier is missing from the contents of the lockfile.
2020-01-09 10:42:03 +01:00
Alastair Daivis 9df58e7ecd Add support for the export_name function attribute 2020-01-07 21:44:17 +01:00
Emilio Cobos Álvarez b912c04a7d Add a test for expanding dependencies with Cargo.lock v2, with both conflicting and non-conflicting deps. 2019-12-29 12:56:49 +01:00
Evan Shaw 6a9066f7cd Add enum_class option
This option allows specifying that a C++ enum should be emitted with
plain `enum` rather than `enum class`. It's true that `enum class` should
generally be preferred, but sometimes there's existing code which is
already using plain `enum`, and porting that code to Rust becomes easier when
`cbindgen` can emit plain `enum`.

This option can be overridden on a per-enum basis using a `cbindgen:` annotation.

It defaults to true for two reasons:

* Backward compatibility.
* `enum class` is probably actually what you want, in general.
2019-12-29 12:55:59 +01:00
Aleksa Sarai 8c66c0c1dc tests: enum: add #[repr(u64)] test
Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
2019-12-22 14:06:12 +01:00
Emilio Cobos Álvarez 48f1038918 enum: Add an option to generate copy-assignments.
And recommend its usage if copy-constructors are being generated, as otherwise
C++ in its whole glory would do a bitwise copy, which is not really what you
want if you have constructors / destructors around.
2019-12-16 13:20:02 +01:00
Aleksa Sarai f23d4ee6e8 tests: add tests for #[repr(packed)] and #[repr(align(...))]
The tests are very straightforward, and effecitvely are just ensuring
that the formatting works correctly and is included in all of the
important cases.

It's also very important to ensure we do not generate laid-out structs
for layouts which we cannot reasonably represent in C (such as in cases
where we weren't told what annotation to use for packed and
specifically-aligned structures). Thus, add some tests to verify that
this is the case.

Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
2019-12-15 11:52:23 +01:00
Jaseem Abid e0fe4e4c44 Add tests for expressions like (0 << SHIFT) | BOOL
Fixes https://github.com/eqrion/cbindgen/issues/412
2019-12-08 12:34:59 +01:00
Adrian Wong 8a7fbbe1ff Add test for char to char32_t mapping 2019-12-02 19:55:04 +01:00
Gyusun Yeom 3f9e54b775 Initialize struct literal with list-initializer for C++11 standard (#401)
* Emit struct literal with list-initializer when language is Cxx

* Update test results

* Add test case - struct literal order

* Memoize struct field names

* Specify struct type at front of initializer
2019-11-17 19:28:40 +01:00
Adrian Wong 087d36f32a Map char to char32_t
Rust's `char` is 32 bits wide, but `wchar_t` on Windows is 16.
Avoid truncation by mapping `char` to `char32_t`.
2019-10-04 10:39:31 +02:00
Volker Mische 7f3b8f4dcd Add tests for parser fix
The tests are based on https://github.com/vmx/cbindgen-expand-dep-bug
2019-09-21 22:42:17 +09:00
Rasmus Eneman f1433bd3b9 Rename using => using_namespaces 2019-09-02 21:50:10 +02:00
Rasmus Eneman 4bd7b07d2f Add support for adding "using namespace" statements 2019-09-02 21:50:10 +02:00
Emilio Cobos Álvarez bdc560d18a Add tests for private_default_tagged_enum_constructor. 2019-08-25 17:05:22 +02:00
Bruno Kirschner 1450e39d8f Preserve indentation on comments.
As indentation is a very handy way to structure comments and increase
their readability as much of it as possible should be preserved.

This removes any trimming of leading white spaces and ensures that
any cbindgen annotations are still recognized afterwards.

... fixes #184
2019-08-08 14:07:04 +02:00
Bruno Kirschner 47e831753b Avoid trimming non whitespace characters.
Rustc already removes all leading `/` symbols during the conversion
from doc-comments into annotations. Any additional trimming of non
whitespace characters just reduces the formatting flexibility of a
comment.

... fixes #374
2019-08-08 14:07:04 +02:00
Bruno Kirschner b4b82a500c Preserve empty lines in doc comments.
This required two changes in parallel.

As a first and obvious step it removes a check that skipped emptys
lines during documentation loading, but it was also necessary to
refactore the `get_comment_lines()` utility method as a second step.

This second refactoring was necessary as each line in a doc comment
is trimmed and transformed in its own doc attribute. The attribute
of an empty line therefore contains an empty string as value. If we
now call `lines()` on such an empty string we end up with an empty
iterator as the method is internally configured to ignore trailing
empty lines.
2019-08-03 17:38:59 +02:00
Emilio Cobos Álvarez 5f8e027290 rename to extra_bindings per IRC discussion. 2019-06-25 21:33:19 +02:00
Emilio Cobos Álvarez 16b2a25442 Turn the option into a whitelist rather than an on / off switch. 2019-06-25 21:28:12 +02:00
Emilio Cobos Álvarez 0bcd54f9c3 Add an option to generate consts / globals / fn from parsed dependencies.
This is a limitation that may not be useful if you're using it to parse known
dependencies.
2019-06-25 21:28:11 +02:00
Emilio Cobos Álvarez 2a7496c81b Properly indent a test. 2019-06-16 22:02:26 -07:00
Gyusun Yeom 583ed40c20 Add test - custom header with no_includes 2019-06-08 19:27:58 +09:00
Gyusun Yeom f29a525202 Add test - include_guard with no_includes config 2019-06-08 19:27:58 +09:00
Emilio Cobos Álvarez 5861271d8e ir: Add the ability to automatically derive copy-constructors for tagged enums. 2019-05-10 20:37:12 +02:00
Emilio Cobos Álvarez b2e224354b Use placement new for constructing in tagged unions' helper methods.
Using operator= is not quite sound in presence of destructors and operator
overloading.

It's perfectly fine to assume that the left-hand-side of an operator= expression
is valid memory, however we're using uninitialized memory here, that may not be
the case.

Use placement new to properly construct tagged unions. I don't need this with
any urgency, but it's the right thing to do in presence of complex types, and
the current code seems a bomb waiting to explode :)
2019-05-10 18:15:39 +02:00
Emilio Cobos Álvarez 68b6a7da4f Merge pull request #332 from Gankro/rust-2018-2
First implementation of Rust 2018 modules.
2019-05-02 23:39:40 +02:00
Emilio Cobos Álvarez cec3803350 Merge pull request #333 from emilio/tagged-union-dtor
ir: Add the possibility to auto-generate destructors of tagged unions.
2019-05-02 23:38:43 +02:00
Emilio Cobos Álvarez 49c056aef4 Make it more similar to the other options. 2019-05-02 19:59:02 +02:00
Emilio Cobos Álvarez a4ce6c8105 Test both repr(u8) and repr(C, u8). 2019-05-02 19:43:23 +02:00
Alexis Beingessner 8d24de12a4 Make crate name resolution test case even more complicated (no extern in nested crate case) 2019-05-02 11:52:27 -04:00
Emilio Cobos Álvarez 8c0028e5f1 ir: Add the possibility to auto-generate destructors of tagged unions.
This trades the ABI-safety (making the struct potentially unsafe to pass by
value), thus the opt-in rather than auto-generating it.

The TL;DR is that I need a way to share types that contain boxed slices from the
style system. That's fine when they're inside regular structs, since C++ does
the right thing, but for unions you need to make it explicit like this.

The actual Gecko setup will hook into the leak logging machinery to avoid silly
leaks and such of course.
2019-05-02 16:03:26 +02:00
Alexis Beingessner 6e7dead9d9 Add test for package renaming 2019-04-29 15:05:49 -05:00
Axel Nennker 87007649c8 fix #205 Negative literals (#323)
* fix #205

Signed-off-by: Axel Nennker <axel.nennker@telekom.de>

* remove comment

Signed-off-by: Axel Nennker <axel.nennker@telekom.de>
2019-04-19 15:45:16 +02:00
Ingvar Stepanyan 8ea3b2d25f Respect visibility of constants (#314)
Fixes #123:
 - Adds visibility check for module-level constants.
 - Adds visibility check for associated constants.
 - Fixes bitflags expansion to produce public associated constants (as the real expansion does).
2019-04-16 11:25:23 +02:00
Axel Nennker 7a8b3d9944 check char constant length
Signed-off-by: Axel Nennker <axel.nennker@telekom.de>
2019-04-15 15:56:36 +02:00
Axel Nennker 19483c21bc heart char constant in tests
Signed-off-by: Axel Nennker <axel.nennker@telekom.de>
2019-04-15 12:30:05 +02:00
Axel Nennker 58e85439c5 escape chars
Signed-off-by: Axel Nennker <axel.nennker@telekom.de>
2019-04-15 07:57:09 +02:00
Ingvar Stepanyan 944ecb958e Add C99 doc comment style
In modern C (post-C99) it's common to just use `// double-slash comments`, but currently cbindgen provides only `/* block-comment */` and `/// triple-slash comment` variants.
2019-04-14 16:20:07 +02:00
Axel Nennker 19fd975b6f test for char const
Signed-off-by: Axel Nennker <axel.nennker@telekom.de>
2019-04-13 23:46:51 +02:00