Commit Graph

41 Commits

Author SHA1 Message Date
Emilio Cobos Álvarez dad36fef3d Test the interaction between include and prefix configurations.
This broke mozilla-central once, hopefully not twice :)
2018-11-05 08:46:56 -06:00
IGI-111 436eaea8bf Add associated constant prefix (#234)
Fix for #232
This adds a type prefix for associated constants to avoid namespace
collisions. It also adds error invocation in the rare but existing
cases where an collisions still happens in the constant namespace.
2018-10-24 12:10:09 -05:00
IGI-111 d32127e3d7 Fix #229
Place constants back inside namespace and add a test to make sure they
are namespaced correctly.
2018-10-24 11:50:03 -05:00
Emilio Cobos Álvarez ab9e3b814c ir: Fix generic enums with untagged bodies.
Boris hit this because he used #[repr(C)] instead of #[repr(u8)].

We were incorrectly writing the generic arguments twice for those.

I missed this difference in #219.

Fixes #225.
2018-10-17 14:11:37 -05:00
Emilio Cobos Álvarez 5ac196d3ef ty: Add support for simplifying NonNull<T>.
I want this to move around slices and boxes across the style system, while
preserving the option size optimizations when they're fully in a repr(Rust)
data-structure.

This is sound because NonNull is repr(transparent):

  https://doc.rust-lang.org/src/core/ptr.rs.html#2847

I renamed simplify_option_to_ptr to simplify_standard_types because that's what
it does now.

ABI-wise for NonNull<T> it's guaranteed via repr(transparent). For
Option<NonNull<T>> it is as well, though I've asked in #rustc to confirm.

The LLVM IR of:

```
pub extern "C" fn foo(ptr: Option<::std::ptr::NonNull<i32>>) {}
```

is:

```
define void @foo(i32*) unnamed_addr #0 !dbg !310 {
start:
  %ptr = alloca i32*, align 8
	store i32* %0, i32** %ptr, align 8
	call void @llvm.dbg.declare(metadata i32** %ptr, metadata !327, metadata
	!DIExpression()), !dbg !328
	ret void, !dbg !329
}
```

Which is the same as for:

```
pub extern "C" fn foo(ptr: ::std::ptr::NonNull<i32>) {}
```

Except without the nonnull annotation.

And the same as for:

```
pub extern "C" fn foo(ptr: *mut i32) {}
```
2018-10-17 09:24:22 -05:00
Emilio Cobos Álvarez 43f6f7108e Add support for generic enums.
Going to need this if I ever aim to generate TransformOperation bindings and
remove a bunch of slow and ugly Gecko code:

  https://searchfox.org/mozilla-central/rev/80ac71c1c54af788b32e851192dfd2de2ec18e18/servo/components/style/values/generics/transform.rs#189

With the caveat that I'll need to remove the options, but I can manage to do
that.

This also fixes a bunch of renaming bugs that I found while at it.

This patch has the gotcha that we need to remove the assertion of no-underscores
in mangled names... But I think it should be fine, and I'd rather not do a more
breaking change.

You can generate conflicting names in C using enum variants with the same name
as a struct regardless, for example, so I don't think this is terribly
important.
2018-10-16 16:19:06 -05:00
Mrmaxmeier 161d83c0b1 add lifetime_arg test 2018-10-16 15:50:23 -05:00
Emilio Cobos Álvarez 15d7cb8904 Fix tagged enum's interactions with prefixing. 2018-10-04 10:08:25 -05:00
konstin 8faf7011ae Add no_includes option 2018-10-01 16:53:09 -05:00
IGI-111 110c3e481c Add support for associated constants and struct literals (#170)
* handle associated constants and struct literals

This aims to fix #100 by adding parsing support for associated constants, and
struct literal expressions.

It duplicates some of the parsing for constants, but sadly ImplItemConst and
ImplConst (as well as their children) don't share a common trait
that would allow for genericity.

It also uses the same namespace for both constants and associated
constants, which could cause conflicts in valid Rust with shared const names in
different scopes.

The struct literals use the standard C99 syntax. Do mind that the
limitations on literal expressions still apply.

* added test cases

* fix formatting
2018-10-01 16:37:51 -05:00
Vincent Esche 5e6d58dfe3 Added support for #[repr(transparent)] 2018-08-28 16:35:04 -05:00
Emilio Cobos Álvarez 52270a23af Apply renaming rules to the generated eq/neq impls. 2018-08-17 23:15:50 -05:00
Emilio Cobos Álvarez 1e4b90bb1a Honor derive_eq / derive_neq for unions. 2018-08-17 23:15:50 -05:00
Vincent Esche 68a22aac3c Added test mod_attr project
Added impl of `fmt::Display` for `Cfg`

Added  `fn matched_defines(…)` for filtering for matches in `[defines]`

Changes semantic of `has_defines` from `∀` to `∃` (i.e. all -> one or more)

Changed `write_before` to use `matched_defines`

Added logging of warning for omitted `#[cfg(…)]`s

Added expectations for `mod_attr` test project

Renamed function arguments in `mod_attr` test project

Rustfmt

Introduced `Condition` type to ensure correct API usage of `Cfg`

Merged `Condition::Boolean` and `Condition::Named` into `Condition::Define`

Removed `DefineConfig` and `MissingDefineBehavior`.

(Was getting a bit ahead of myself with these.)

Rustfmt
2018-08-17 23:15:16 -05:00
Vincent Esche b07046d28a Fixed missing prefix for named consts in [T; <Const>] types 2018-08-14 00:47:35 -05:00
Basile Clement 33c45a26bb Add ability to specify features to use for macro expansion
Currently, `cbindgen` uses the `--all-features` flag when expanding a
dependent crate. However, this may not be desirable in a number of
cases:

 - Some C APIs may be gated by a feature flag and would not be present
   in the final cdylib depending on the features provided (for instance
   one could want to have the ability to build a "debug" version of the
   library which provides extra unstable hooks). In such cases, a
   programmatic `cbindgen` call in a build script would want to use only
   the features that will get used in the current build.

 - Some features may bring in large dependencies and/or potentially
   increase compilation time without affecting the FFI surface, and it
   would be faster and more efficient to disable them when running
   `cbindgen`.

 - Some features may require external libraries and/or hardware (e.g.
   dependencies on GPU libraries such as CUDA) that may not be available
   on the current machine without affecting the FFI surface.

To alleviate this problem, this PR adds an extended version of the
`parse.expand` configuration key, allowing control over the features
used when expanding in a way similar to the way cargo handles extended
dependencies (although note that there is a single version of each key,
since the features refer to the features of the current crate). So for
instance instead of writing `expand = ["euclid"]` one would write:

```
[parse.expand]
crates = ["euclid"]
```

which is equivalent to:

```
[parse.expand]
crates = ["euclid"]
all_features = false
default_features = true
features = ["feature1", "feature2"]
```

Note that `all_features` is set to `false` by default in order to match
cargo's behavior.

For backwards compatibility, the old syntax `expand = ["euclid"]` is
still supported and is equivalent to:

```
[parse.expand]
crates = ["euclid"]
all_features = true
default_features = true
features = null
```

In this case, `all_features` is set to `true` in order to match the
previous behavior of cbindgen.
2018-07-31 08:31:43 -05:00
Basile Clement ba589a868e Use Cargo.lock from workspace root
cbindgen currently assumes that the `Cargo.lock` is in directly in the
crate directory as a sibling to `Cargo.toml`; however that is usually
not the case inside a workspace.

Instead, this PR extracts the workspace root from the output of `cargo
metadata` [1] (already used to get a list of packages) and uses the
`Cargo.lock` from there.

 1. This is available since Rust 1.24; see rust-lang/cargo#4940
2018-07-30 22:02:56 -05:00
Emilio Cobos Álvarez 5da9ae98d3 Basic item_types test. 2018-07-25 13:54:10 -05:00
Ryan Hunt d192544c7f Add two parsing only tests for #164 and #169 2018-05-31 10:46:28 -05:00
Alexis Beingessner cabe1055c4 Add tests for optional enum convenience constructors 2018-04-25 13:40:58 -05:00
Alexis Beingessner da550f53b2 Implement optional convenience constructors for tagged enums 2018-04-25 13:40:58 -05:00
Johan Anderholm 3a9bb17e8a Modify test to run all three styles for C. 2018-03-27 10:05:45 -05:00
Ryan Hunt cf3529fa84 Don't use extern crate aliases when searching for dependencies 2018-03-14 14:40:40 -05:00
Dan Robertson 0c9c32ecdb Improve module path parsing
If a module has a path attribute use this as the module path to parse.
2018-03-14 13:42:18 -05:00
Dan Robertson 22fa8b0824 Ensure that a constants cfg is preserved
When writing out constants the cfg attribute is not written out around
the defined constant.
2018-03-12 12:44:57 -04:00
Ryan Hunt e336f80ff8 Update syn to 0.12.6 2018-01-31 23:28:20 -06:00
Ingvar Stepanyan 70d8b95f78 Disallow unknown and conflicting repr markers 2018-01-31 09:35:29 -06:00
Ingvar Stepanyan 07eae4c171 Implement support for repr(C, Int)
Fixes #119
2018-01-31 09:35:29 -06:00
Ryan Hunt 33407202e1 Specify --lib with cargo expand and add crate testing 2018-01-29 15:17:23 -06:00
Ryan Hunt 4e481c1338 Add dependencies for tagged enums 2018-01-29 14:08:02 -06:00
Ingvar Stepanyan 905b9a09aa Add support for repr(C) tagged enums too 2018-01-29 11:36:59 -06:00
Ingvar Stepanyan 3b61c8ead5 Initial support for tagged enums 2018-01-29 11:36:59 -06:00
Kartikaya Gupta 2ccaa3e956 Add a derive_constructor option to generate struct constructors 2018-01-25 12:22:01 -06:00
Ryan Hunt b0d4578214 Fix broken test 2018-01-04 23:30:53 -06:00
Ryan Hunt 60d95258ba Add item renaming, prefixing, force including, and excluding 2018-01-04 23:29:21 -06:00
Ryan Hunt 1ae43feaaf Add the ability to specify additional includes 2018-01-04 17:25:43 -06:00
Ryan Hunt 21d917b723 Check for no_mangle and pub on functions and static items 2018-01-04 14:52:02 -06:00
Ingvar Stepanyan 4ee1a8bcc8 Remove obsolete template specialization 2017-11-18 14:40:42 -06:00
Ryan Hunt 864b4a22f9 Use Parser for single source mode 2017-11-14 02:00:04 -05:00
Ryan Hunt aa9c20bc03 Do not emit const char* for &str 2017-11-13 23:05:00 -05:00
Ryan Hunt 6a02ec4a7f Commit test expectations 2017-11-09 18:04:22 -05:00