summaryrefslogtreecommitdiff
path: root/src/codegen/mod.rs
AgeCommit message (Collapse)Author
2017-09-22Rename derive_debug → impl_debug.Sergey Pepyakin
2017-09-22Generate base names upon constructon.Sergey Pepyakin
2017-09-19Derive Ord when possibleSergey Pepyakin
2017-09-19Emit derive(PartialOrd)Sergey Pepyakin
2017-09-14Add a `Builder::blacklist_type`Alexey Zabelin
This deprecates `Builder::hide_type`. Related to #984. - [x] Add Builder::blacklist_type, that does the same thing as hide_type - [x] Mark Builder::hide_type as #[deprecated = "Use blacklist_type instead"] - [x] Make hide_type delegate to blacklist_type - [x] Rename the BindgenOptions::hidden_types member to BindgenOptions::blacklisted_types - [x] Rename ir::context::BindgenContext::hidden_by_name to blacklisted_by_name - [x] Rename ir::item::Item::is_hidden to is_blacklisted
2017-09-11Make bindgen generate enums as constants by defaultCldfire
Also simplifies the logic that determines which enum variation gets chosen.
2017-09-07Use `quote` instead of `syntex` for Rust code generationNick Fitzgerald
The `syntex` crate is unmaintained. It is slow to build, and additionally it requires that we pre-process `src/codegen/mod.rs` before we build the `bindgen` crate. The `quote` crate provides similar quasi-quoting functionality, is maintained, and builds faster. It doesn't have a typed API or builders, however; it only deals with tokens. Before this commit: ``` $ cargo clean; cargo build <snip> Finished dev [unoptimized + debuginfo] target(s) in 98.75 secs ``` After this commit: ``` $ cargo clean; cargo build <snip> Finished dev [unoptimized + debuginfo] target(s) in 46.26 secs ``` Build time is cut in half! But what about run time? Before this commit: ``` Generated Stylo bindings in: Duration { secs: 3, nanos: 521105668 } ``` After this commit: ``` Generated Stylo bindings in: Duration { secs: 3, nanos: 548797242 } ``` So it appears to be about 20ms slower at generating Stylo bindings, but I suspect this is well within the noise. Finally, this also lets us remove that nasty `mem::transmute` inside `bindgen::ir::BindgenContext::gen` that was used for the old `syntex` context. Now `BindgenContext` doesn't have a lifetime parameter either. This should make it easier to revisit doing our analyses in parallel with `rayon`, since that context was one of the things that made it hard for `BindgenContext` to implement `Sync`. Fixes #925
2017-09-06Check derive_copy optionmchlrhw
2017-08-30Squash commit for --time-phases command line optionJackson O'Donnell
initial timer branch commit added time_phases builder parameter create timers for BindgenContex analyses, codegen time parse added docstrings added fitzgens suggestions add --time-phases to bindgen::Builder::command_line_flags
2017-08-29Auto merge of #936 - jhod0:no_fieldgen_on_opaque, r=fitzgenbors-servo
Avoid generating fields/methods for opaque objects WIP fix for issue #929 With libclang 4, passes all tests on my machine except `dump_preprocessed_input`, but that fails on the master branch as well
2017-08-29removed commented code, added punctuationJackson O'Donnell
2017-08-28no fields or methods created for opaqueJackson O'Donnell
2017-08-24Simplify helpers::blobMalo Jaffré
Thanks @fitzgen for the detailed instructions. Fixes #928.
2017-08-21Can derive EqZhiting Zhu
2017-08-21Rename `TypeKind::Named` to `TypeKind::TypeParam`Anna Liao
Also renames a bunch of other things referring to named types to refer to type parameters. Fixes #915
2017-08-14Can derive PartialEq analysisZhiting Zhu
2017-08-14Fixes compilation warnings with rustc 1.21.0-nightly (13d94d5fa 2017-08-10)Bastian Köcher
2017-08-14Fixes alignment errors with new Rust union typeBastian Köcher
This fix creates a new private field with the required aligned size. This new private field ensures that the union has the required size.
2017-08-13Re-add --rust-target to replace --unstable-rustTravis Finkenauer
Instead of specifying whether or not to use stable, specify the Rust release to support (one of several stable/beta releases or nightly). The `--unstable-rust` option is still accepted and implies nightly. The definitions of `RustTarget` and `RustFeatures` are created with macros. For each test that uses unions, there is a version that uses the latest stable and 1.0. This also fixes the bug where unions were generated with non-Copy fields.
2017-08-10Auto merge of #899 - bkchr:manual_debug_impl, r=fitzgenbors-servo
Implements Debug trait for types which do not support derive Debug For types that do not support derive Debug be implemented automatically by rust, we know can generate implementations of the Debug trait. This code generation is hidden behind the '--force-derive-debug' command-line flag. Should solve: #875 Sorry for the extra noise in lib.rs, codegen/mod.rs etc, that was rustfmt.
2017-08-10Implements Debug trait for types which do not support derive DebugBastian Köcher
For types that do not support derive Debug be implemented automatically by rust, we know can generate implementations of the Debug trait. This code generation is hidden behind the '--force-derive-debug' command-line flag.
2017-08-09Can derive Hash analysiszzhu
2017-08-04Revert "Add --rust-target to replace --unstable-rust"Nick Fitzgerald
This reverts commit 0bb7b9f1c4652f63f41eba4064b79c044fd3d955. It turns out our CI stopped running test expectations in an earlier regression (from d73507e; fix incoming) and so this pull request actually introduced a bunch of failures when compiling the test expectations and running their unit tests :(
2017-08-04Add --rust-target to replace --unstable-rustTravis Finkenauer
Instead of specifying whether or not to use stable, specify the Rust release to support (one of several stable/beta releases or nightly). The --unstable-rust option is still accepted and implies nightly. The definitions of `RustTarget` and `RustFeatures` are created with macros. For each test that uses unions, there is a version that uses the latest stable release and stable 1.0.
2017-08-03Can derive copy analysiszzhu
2017-07-27can derive default analysiszzhu
2017-07-27Remove the `CanDeriveDebug::Extra` associated typeNick Fitzgerald
Similar to `HasVtable::Extra`, it is no longer needed.
2017-07-25Merge pull request #853 from fitzgen/rust-lang-nurseryNick Fitzgerald
s/servo/rust-lang-nursery/ \o/
2017-07-25s/servo/rust-lang-nursery/ \o/Nick Fitzgerald
Fixes #852
2017-07-25has vtable analysiszzhu
2017-07-22Remove whitelisted_items as arg to codegen funcsOmar Akkila
2017-07-21ir: Track the codegen-reachable items, and use it instead of ↵Emilio Cobos Álvarez
whitelisted_items() for code generation. This standardizes the behavior change at #834, but without regressions. I've added a few more tests for #833 here.
2017-07-21Auto merge of #829 - servo:disambig, r=emiliobors-servo
Use fully disambiguated name instead of a number for layout tests (fixes #394) These numbers cause tons of churn in the diffs for checked in bindings. r? @fitzgen
2017-07-20Only traverse the IR graph to compute whitelisted items onceNick Fitzgerald
We used to do this traversal all the time, but we can do it the one time, after we finish constructing the IR graph and before we begin computing any of our analyses.
2017-07-20Use fully disambiguated name instead of a number for layout tests (fixes #394)Manish Goregaokar
2017-07-20Only whitelist items which we intend to generate code forNick Fitzgerald
This makes only generating certain kinds of items more robust, since we don't need to keep checking whether codegen is enabled for different kinds of items all over the place, and can do it the once. It should also reduce the number of items we have to consider in our various analyses for which we don't ultimately care about the answer. Fixes #826
2017-07-10codegen: Make comments indentation-aware.Emilio Cobos Álvarez
This commit moves comment processing to a central place (well, two, because of field docs, but that's fine). Also, it makes comments indentation aware, so multiline comments don't appear garbled. Finally, it also fixes an out-of-bounds panic when processing an empty multiline comment.
2017-07-09codegen: Fix some sloppiness in our handling of opaque types.Emilio Cobos Álvarez
Fixes #801
2017-06-22Allow marking specific template instantiations as opaqueNick Fitzgerald
If a template has a specialization that bindgen doesn't understand, it can be helpful to mark it as opaque and continue making forward progress in the meantime. This is something we need in the SpiderMonkey bindings.
2017-06-21Auto merge of #741 - tmfink:feature-699-constified-enum-module, r=emiliobors-servo
Feature 699 constified enum module This is a work in progress for issue #699 that adds the `--constified-enum-module` option to bindgen. @emilio, could you give me some guidance on fixing the uses of the enum variant types? In the example below, `foo` should be replaced with `foo::Type`. I'm not sure of the proper way to rename `Item`s after the structures have been defined. My initial thought was to redefine the `CodeGenerator` trait to take a mutable reference to `item`, but that will not work because of the borrow checker. Thoughts? Todo: - [x] put constified enum variants in a `mod` - [x] ensure references to constified enum `foo` are changed to `foo::Type` - [x] handle `typedef` enums ----- Given the input header `tests/headers/constify-module-enums.h`: ~~~c // bindgen-flags: --constified-enum-module foo enum foo { THIS, SHOULD_BE, A_CONSTANT, }; struct bar { enum foo this_should_work; }; ~~~ `$ cargo run -- tests/headers/constify-module-enums.h --constified-enum-module foo --no-layout-tests` will output: ~~~rust /* automatically generated by rust-bindgen */ pub mod foo { pub type Type = ::std::os::raw::c_uint; pub const THIS: Type = 0; pub const SHOULD_BE: Type = 1; pub const A_CONSTANT: Type = 2; } #[repr(C)] #[derive(Debug, Copy)] pub struct bar { pub this_should_work: foo, } impl Clone for bar { fn clone(&self) -> Self { *self } } ~~~
2017-06-20Auto merge of #770 - fitzgen:issue-769-bad-instantiation-test, r=emiliobors-servo
Ensure that every item is in some module's children list Previously, if an item's parent was not a module (eg a nested class definition whose parent it the outer class definition) and the parent was not whitelisted but the item was transitively whitelisted, then we could generate uses of the item without emitting any definition for it. This could happen because we were relying on the outer type calling for code generation on its inner types, but that relies on us doing code generation for the outer type, which won't happen if the outer type is not whitelisted. This commit avoids this gotcha by ensuring that all items end up in a module's children list, and so will be code generated even if their parent is not whitelisted. This does have the downside of changing the relative order of some of the emitted code, and so this has a big diff (as will the next bindgen update for downstream dependencies) but I actually think the newer order makes more sense, for what that is worth. Fixes #769 r? @emilio
2017-06-20Ensure that every item is in some module's children listNick Fitzgerald
Previously, if an item's parent was not a module (eg a nested class definition whose parent it the outer class definition) and the parent was not whitelisted but the item was transitively whitelisted, then we could generate uses of the item without emitting any definition for it. This could happen because we were relying on the outer type calling for code generation on its inner types, but that relies on us doing code generation for the outer type, which won't happen if the outer type is not whitelisted. This commit avoids this gotcha by ensuring that all items end up in a module's children list, and so will be code generated even if their parent is not whitelisted. Fixes #769
2017-06-20codegen: Inline {read,write}_unaligned in order to support rust 1.15.Emilio Cobos Álvarez
... Which is what Firefox uses right now.
2017-06-19Rename `AsNamed` to `AsTemplateParam`Nick Fitzgerald
And also its trait methods `is_named` and `as_named` into `is_template_param` and `as_template_param` respectively. These new names better reflect what the trait is about.
2017-06-18codegen: Fix bitfield getter/setters so they work with NPOT sizes.Emilio Cobos Álvarez
2017-06-17ir: use a bigger integer for the bitfield mask in 32bit, to avoid overflows.Emilio Cobos Álvarez
Like the ones seen in https://bugzilla.mozilla.org/show_bug.cgi?id=1365254#c22
2017-06-17ir: Correct size calculation of a bitfield unit.Emilio Cobos Álvarez
Fixes #734
2017-06-17codegen: Remove trailing whitespace.Emilio Cobos Álvarez
2017-06-16codegen: Respect prepend_enum_name in constified variants.Emilio Cobos Álvarez
Fixes #755
2017-06-11Adds `--constified-enum-module` option per #699Travis Finkenauer