Commit Graph

92 Commits

Author SHA1 Message Date
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
Emilio Cobos Álvarez 7619be86bd ir: Add support for #[must_use]. (#307) 2019-03-27 00:47:21 +01:00
Emilio Cobos Álvarez c6131722dc config: Add an option to make explicit renaming override the prefix setting.
This is useful for opaque types or types cbindgen doesn't otherwise understand.
2019-03-26 13:24:19 -05:00
Ralf Biedert 51aff0a119 Add more documentation style options (#305)
* Ignoring IDE files.

* Addresses issue #302, also amends #59 insofar that vanilla C-style now does not prefix individual lines with `*` anymore.

* Removed Javadoc reference.

* Renamed `Doxylight` to `Doxy` and changed C default to that.

* Added documentation.

* Changed enum name and applied `fmt`.

* Fixed comment.

* Fixed match.
2019-03-24 20:56:17 +01:00
Emilio Cobos Álvarez e14f782743 constant: Handle Self in associated constants.
WebRender used to do this and it's not hard to handle.
2019-03-12 10:19:49 -05:00
Emilio Cobos Álvarez 61b3de43a3 constant: Don't generate constants for structs that don't exist or are not safe. 2019-03-06 14:14:02 -06:00
Emilio Cobos Álvarez f35cc28b95 Test the custom assert macro. 2019-03-05 11:06:01 -06:00
Emilio Cobos Álvarez dea102d6c8 bindgen: Allow to auto-generate asserted casts for tagged enums.
This fixes one of my pet-peeves. Without this patch, I need to add them manually
using the raw body stuff, or along the code that accesses the struct member,
none of those being ideal.
2019-03-05 11:06:01 -06:00
Emilio Cobos Álvarez 011b584d7e parser: Make bitflags expansion opt-in.
Otherwise we may break code that does its own bitflags parsing.

In particular, this will prevent Gecko builds from breaking due to:

  https://searchfox.org/mozilla-central/rev/92d11a33250a8e368c8ca3e962e15ca67117f765/gfx/webrender_bindings/webrender_ffi.h#67

(Which should go away once we start opting-in).
2019-03-05 11:02:48 -06:00
Emilio Cobos Álvarez 80da1f59aa Allow to generate associated constants in the body of C++ structs.
Opt-in since it uses a C++17 feature, but this allow exactly the same usage in
C++ and Rust, which I think is nice.

This also fixes constants of transparent structs in general, since the initial
version of this patch broke a test (associated constants in enums), so I added a
test for that too.
2019-02-23 17:58:22 -08:00
Emilio Cobos Álvarez 9761df66c2 tests: Add a test that exercises all the previous patches. 2019-02-23 15:38:34 -08:00
Elichai Turkel b4887febca Added tests for specific includes without default 2019-02-06 10:49:19 -06:00
Emilio Cobos Álvarez bc67e076d1 parser: Properly skip associated constants on unsupported types.
This fixes a crash when running cbindgen 0.7.0 on the style crate.
2019-01-25 18:52:31 -06:00
Emilio Cobos Álvarez 0a6324f4e6 config: Allow to output user-defined stuff in the struct body. 2019-01-22 18:50:12 -06:00
Joshua Groves 8c3e26424d Handle enum associated constants and reduce memory usage 2019-01-11 09:23:02 -06:00
Joshua Groves 0de44edd88 Remove member name from transparent associated constants 2019-01-11 09:23:02 -06:00
Jeff Muizelaar 42b4290c64 Manually copy arrays
C++ arrays can't be assigned. We detect this situation and manually copy
over the elements.
2019-01-03 16:06:33 -06:00
Dan Robertson 304f752c06 Add support for VaList functions 2019-01-03 09:46:55 -06:00
Emilio Cobos Álvarez e08fb32d74 ir: Add support for negative enum discriminants.
Pretty straight-forward, but it bit me today :)
2018-11-26 09:57:34 -06:00
Ryan Hunt 032af08579 Escape reserved C/C++ keywords from struct fields and function arguments 2018-11-26 09:54:03 -06:00
IGI-111 9861755b05 Add tests for nested struct literals 2018-11-05 08:59:44 -06:00
IGI-111 e35ea840d3 Propagate prefixes to struct literals
Fix #238

This ensures that constants of a struct type have their type and the
type of their underlying value expressions renamed in the case of a
prefix.
2018-11-05 08:59:44 -06:00
Mrmaxmeier 49ccb0e3c1 enumerate wildcard arguments 2018-11-05 08:54:07 -06:00