214 Commits

Author SHA1 Message Date
Vadim Petrochenkov f3d5a20363 Support sort_by for constants
Also support a global default for `sort_by` affecting both functions and constants.
2020-10-05 19:57:33 +02:00
Vadim Petrochenkov 6439e6df56 Support constants with arbitrary types 2020-10-05 10:52:05 +02:00
Emilio Cobos Álvarez d1d97d4482 enumeration: Only propagate derive_ostream annotation if not present.
It seems reasonable to want to derive it for a variant, but want to
provide your own for the containing enum or such, for example.
2020-10-01 18:14:12 +02:00
Kartikaya Gupta 2be47c88e6 Add support for tagged enums that turn into structs.
This happens when the tags are separated. In this case the output is slightly
different since the tag is not part of the struct body, so we need the top-level
serializer to write the tag type.
2020-10-01 12:22:51 +02:00
Kartikaya Gupta c5c17403b4 Add support for tagged enums that turn into unions. 2020-10-01 12:22:51 +02:00
Kartikaya Gupta 12149d4071 Add option for ostream serializer for structures and untagged enums
Tagged enums will be handled in later patches.
2020-10-01 12:22:51 +02:00
Emilio Cobos Álvarez 1fc4cb0724 test: Ensure Option<Box<T>> reduces to *T.
Co-Authored-by: Ivan Enderlin <ivan@mnt.io>
2020-09-29 13:40:07 +02:00
Emilio Cobos Álvarez 5d1217c7c0 tests: Instead of adding skip_cpp as a feature, make the tests work with C++ 2020-09-29 13:36:46 +02:00
Ivan Enderlin 4ce324cd2d feat: Simplify Box<T> to *T for C only. 2020-09-29 13:36:46 +02:00
Ivan Enderlin eefce50c6d test: Skip CPP for the manuallydrop and maybeuninit test cases. 2020-09-29 13:36:46 +02:00
Ivan Enderlin af6d2e3fbb test: test MaybeUninit as a simplified type. 2020-09-29 13:36:45 +02:00
Ivan Enderlin 79bb38abda test: Test ManuallyDrop as a simplified type. 2020-09-29 13:17:04 +02:00
Emilio Cobos Álvarez 18110669fc Add docs, move mangling configuration to its own place, add integration tests. 2020-09-22 12:54:55 +02:00
Luni-4 07c3aed03e Add ptrs-as-arrays tests 2020-09-07 20:53:09 +02:00
Tom Solberg 3ca0e75ed9 Add support for specifying line ending style (#568) 2020-08-26 15:28:17 +02:00
Emilio Cobos Álvarez d652d29ae2 ir: Be less strict when instantiating opaque types.
There are two situations where we can legitimately end up with a
different number of template params.

Fixes #532.
Fixes #527.
2020-08-15 13:40:54 +02:00
Nick Wilcox 6fc7c77b0f remove duplicated code, correct test names, change config param 2020-08-05 15:09:28 +02:00
Nick Wilcox 41b7866c14 Add support for an optional attribute on pointers whose nullability can be inferred from the Rust type. 2020-08-05 15:09:28 +02:00
Kartikaya Gupta 977d95b0ff Add failing scenario to test
A u32 bitflags structure should allow a 1<<31 value. However, with
current cbindgen this produces a compiler error with latest clang, because
1<<31 is treated as a signed value (-2147483648) which cannot be narrowed
back into a uint32_t without a cast.
2020-07-31 16:22:48 +02:00
Emilio Cobos Álvarez 5eae0bc07b function: Add support for wildcards in arguments.
We don't support unnamed arguments, and we give a terrible error
("Parameter has an unsupported type.") when you use them.

They're very simple to implement so we should just do it.
2020-07-25 13:50:11 +02:00
mexus a94d6e2c9b Support "never" return type 2020-07-24 22:39:08 +02:00
Luni-4 274c9743ca Add tests 2020-07-14 16:59:54 +02:00
Hayes Neuman bb00d1c4a8 Support renaming for constants with casts, and properly order them in the output. 2020-05-26 23:21:28 +02:00
Hayes Neuman 967c378308 Support casts in constants 2020-05-26 23:21:28 +02:00
Emilio Cobos Álvarez b04aa7e699 parser: Introduce cbindgen:ignore comment annotation, to allow ignoring items or modules. 2020-05-15 15:43:54 +02:00
Emilio Cobos Álvarez a05a223704 tests: Add tests for attribute annotations. 2020-05-01 00:30:40 +02:00
Luca Barbato 1a824c04f2 Add support for verbatim content after includes
Let the user add raw C code in the generated header after the include
blocks.

It matches what bindgen provides with the raw_lines option.
2020-04-22 01:50:16 +02:00
Vincent Tavernier 1ed32adafb Add Rust 2015 edition test for nested modules 2020-04-17 14:22:00 +02:00
Vincent Tavernier 60d60aaf0d Fix #254
By checking the recursion depth in the crate we are currently parsing,
we can decide on the right module directory to find submodules in. The
added `mod_2018` test fails without the changes to `parser.rs`.
2020-04-17 14:22:00 +02:00
Vincent Tavernier ea6ea24740 Fix #381
As noted by @Benlitz, Cargo metadata supports directly specifying the
target name instead of using the `#[cfg]` syntax. We can support this by
manually creating the `syn::NestedMeta` node from the target name seen
as a string literal.
2020-04-17 14:11:06 +02:00
Igor Sadchenko 6fce1ccc4b Review fixes. Add parameter skip_warning_as_error to skip threat a warning as an error 2020-04-14 19:03:55 +02:00
Igor Sadchenko 4baadb049d Review fixes 2020-04-14 19:03:55 +02:00
Igor Sadchenko 275b36fb09 Added pragma once option. Issue #510 2020-04-14 19:03:55 +02:00
Emilio Cobos Álvarez 33d9ecf11f Handle mangling pointers.
Ugly, but better than crashing.

Closes #506.
Closes #453.
2020-04-10 15:22:16 +02:00
Emilio Cobos Álvarez ec1631f3e4 Allow excluding monomorph structs in C mode.
Fixes #500.
2020-04-01 11:45:53 +02:00
Emilio Cobos Álvarez c265a7562a parser: Don't panic when finding associated constants to a primitive.
We don't handle it, but no reason to panic.

Fixes #493
2020-03-21 17:23:02 +01:00
Joe Devietti 6218281443 updated constant_big test case with large negative numbers 2020-03-11 09:58:10 -04:00
Joe Devietti 7101465403 avoid gcc warning by appending ULL suffix to integer literals that are too big to fit in a signed 64-bit integer 2020-03-09 23:11:51 -04:00
TheKK 5a4d74b911 ir: escape export_name while writing source of EnumVariant 2020-03-09 15:58:56 +01:00
TheKK e2b2c81221 ir: escape tagged union's field name 2020-03-09 15:58:56 +01:00
Emilio Cobos Álvarez c3442809b9 tests: Add tests for cell and refcell. 2020-03-09 01:49:14 +01:00
Emilio Cobos Álvarez 3483359374 remove a test which was causing CI to go red. 2020-03-03 21:14:06 +01:00
Emilio Cobos Álvarez b6c2f3c59d constant: Fix the interaction of allow_constexpr and inline consts. 2020-03-03 21:10:47 +01:00
AlaskanEmily 462871695d Add option to output constexpr generated constant primitive values
This is controlled by the [const] allow_constexpr option, similar to the
allow_static_const option.

It's only applied to primitives currently.
2020-03-03 20:46:12 +01:00
TheKK 61e55ce4d9 ir: write declaration of global variable like struct fields 2020-02-25 21:06:43 +01:00
Emilio Cobos Álvarez 69b3d20a92 Add tests for #475. 2020-02-22 14:17:00 +01:00
Arnav Singh c6809b00fb Emit documentation on constants (#471)
Fixes #403
2020-02-11 01:51:57 +01:00
Emilio Cobos Álvarez 5c2fab7919 ir: Minor fix for conditions around enums. 2020-02-08 23:21:42 +01:00
Emilio Cobos Álvarez 854172561a ir: Handle cfg in enum variants. 2020-02-02 18:29:29 +01:00
Andreas Dinter 723e690027 Add test cases for 'sort_by' option 2020-01-27 16:03:12 +01:00