10 Commits

Author SHA1 Message Date
Kartikaya Gupta
5f6b223237 Add ostream header to all generated .cpp files.
Ideally we'd just do this when we need it, but the ostream derivation
will be controlled by both global config and per-structure config, so
it's hard to know exactly when we need it and when we don't.
2020-10-01 12:22:51 +02:00
Emilio Cobos Álvarez
3527e0f1e3 Update expectation files 2020-07-31 16:22:48 +02:00
Arnav Singh
c6809b00fb
Emit documentation on constants (#471)
Fixes #403
2020-02-11 01:51:57 +01:00
Emilio Cobos Álvarez
230042b753 Implement more operators for bitflags. 2019-12-08 22:15:04 +01:00
Jaseem Abid
df347d984a Handle parenthesized literals like (1 << 5)
To keep things simple, this patch always adds a () around binary operations in
literals as suggested by @emilio here
https://github.com/eqrion/cbindgen/pull/425#discussion_r353740669

Some tests obviously had to be regenerated, those are included as well.
2019-12-08 12:34:59 +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
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
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
90d26107b8 bitflags: Derive more stuff for bitflags.
The static_cast is needed to avoid -Wnarrowing conversions, but I can also write
it like:

Foo ret;
ret.bits = bits | other.bits;
return ret;

if you prefer.
2019-03-06 14:14:02 -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