diff options
author | Sébastien Duquette <ekse.0x@gmail.com> | 2018-08-13 20:23:38 -0400 |
---|---|---|
committer | Emilio Cobos Álvarez <emilio@crisal.io> | 2018-08-14 21:56:53 +0200 |
commit | a1c9129238b5c8f5101d25b5a407d491d4234800 (patch) | |
tree | af36dbbb6b564751f19fba9c5e7268a59387dd95 | |
parent | b47a4c641b7e6ca2584937a5bde0d9fdb2206bc7 (diff) |
address comments
-rw-r--r-- | Cargo.lock | 2 | ||||
-rw-r--r-- | Cargo.toml | 2 | ||||
-rw-r--r-- | src/codegen/mod.rs | 27 | ||||
-rw-r--r-- | src/ir/item.rs | 23 | ||||
-rw-r--r-- | src/ir/traversal.rs | 29 | ||||
-rw-r--r-- | src/lib.rs | 44 |
6 files changed, 72 insertions, 55 deletions
@@ -23,7 +23,7 @@ dependencies = [ [[package]] name = "bindgen" -version = "0.37.4" +version = "0.38.0" dependencies = [ "bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "cexpr 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -14,7 +14,7 @@ readme = "README.md" repository = "https://github.com/rust-lang-nursery/rust-bindgen" documentation = "https://docs.rs/bindgen" homepage = "https://rust-lang-nursery.github.io/rust-bindgen/" -version = "0.37.4" +version = "0.38.0" build = "build.rs" include = [ diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 35646c0d..27ddcfea 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -14,7 +14,6 @@ use self::helpers::attributes; use self::struct_layout::StructLayoutTracker; use super::BindgenOptions; -use super::CodegenConfig; use ir::analysis::{HasVtable, Sizedness}; use ir::annotations::FieldAccessorKind; @@ -1843,11 +1842,7 @@ impl CodeGenerator for CompInfo { } let mut method_names = Default::default(); - if ctx - .options() - .codegen_config - .contains(CodegenConfig::METHODS) - { + if ctx.options().codegen_config.methods() { for method in self.methods() { assert!(method.kind() != MethodKind::Constructor); method.codegen_method( @@ -1860,11 +1855,7 @@ impl CodeGenerator for CompInfo { } } - if ctx - .options() - .codegen_config - .contains(CodegenConfig::CONSTRUCTORS) - { + if ctx.options().codegen_config.constructors() { for sig in self.constructors() { Method::new( MethodKind::Constructor, @@ -1881,11 +1872,7 @@ impl CodeGenerator for CompInfo { } } - if ctx - .options() - .codegen_config - .contains(CodegenConfig::DESTRUCTORS) - { + if ctx.options().codegen_config.destructors() { if let Some((kind, destructor)) = self.destructor() { debug_assert!(kind.is_destructor()); Method::new(kind, destructor, false).codegen_method( @@ -1992,18 +1979,18 @@ impl MethodCodegen for Method { let cc = &ctx.options().codegen_config; match self.kind() { MethodKind::Constructor => { - cc.contains(CodegenConfig::CONSTRUCTORS) + cc.constructors() } MethodKind::Destructor => { - cc.contains(CodegenConfig::DESTRUCTORS) + cc.destructors() } MethodKind::VirtualDestructor { .. } => { - cc.contains(CodegenConfig::DESTRUCTORS) + cc.destructors() } MethodKind::Static | MethodKind::Normal | MethodKind::Virtual { .. } => { - cc.contains(CodegenConfig::METHODS) + cc.methods() } } }); diff --git a/src/ir/item.rs b/src/ir/item.rs index 67ba9947..c467c27f 100644 --- a/src/ir/item.rs +++ b/src/ir/item.rs @@ -13,7 +13,6 @@ use super::function::{Function, FunctionKind}; use super::item_kind::ItemKind; use super::layout::Opaque; use super::module::Module; -use super::super::CodegenConfig; use super::super::codegen::CONSTIFIED_ENUM_MODULE_REPR_NAME; use super::template::{AsTemplateParam, TemplateParameters}; use super::traversal::{EdgeKind, Trace, Tracer}; @@ -952,21 +951,21 @@ impl Item { let cc = &ctx.options().codegen_config; match *self.kind() { ItemKind::Module(..) => true, - ItemKind::Var(_) => cc.contains(CodegenConfig::VARS), - ItemKind::Type(_) => cc.contains(CodegenConfig::TYPES), + ItemKind::Var(_) => cc.vars(), + ItemKind::Type(_) => cc.types(), ItemKind::Function(ref f) => match f.kind() { - FunctionKind::Function => cc.contains(CodegenConfig::FUNCTIONS), + FunctionKind::Function => cc.functions(), FunctionKind::Method(MethodKind::Constructor) => { - cc.contains(CodegenConfig::CONSTRUCTORS) + cc.constructors() } - FunctionKind::Method(MethodKind::Destructor) - | FunctionKind::Method(MethodKind::VirtualDestructor { + FunctionKind::Method(MethodKind::Destructor) | + FunctionKind::Method(MethodKind::VirtualDestructor { .. - }) => cc.contains(CodegenConfig::DESTRUCTORS), - FunctionKind::Method(MethodKind::Static) - | FunctionKind::Method(MethodKind::Normal) - | FunctionKind::Method(MethodKind::Virtual { .. }) => { - cc.contains(CodegenConfig::METHODS) + }) => cc.destructors(), + FunctionKind::Method(MethodKind::Static) | + FunctionKind::Method(MethodKind::Normal) | + FunctionKind::Method(MethodKind::Virtual { .. }) => { + cc.methods() } }, } diff --git a/src/ir/traversal.rs b/src/ir/traversal.rs index d69e7541..dba6ce0e 100644 --- a/src/ir/traversal.rs +++ b/src/ir/traversal.rs @@ -1,6 +1,5 @@ //! Traversal of the graph of IR items and types. -use super::super::CodegenConfig; use super::context::{BindgenContext, ItemId}; use super::item::ItemSet; use std::collections::{BTreeMap, VecDeque}; @@ -224,20 +223,20 @@ pub fn codegen_edges(ctx: &BindgenContext, edge: Edge) -> bool { // We statically know the kind of item that non-generic edges can point // to, so we don't need to actually resolve the item and check // `Item::is_enabled_for_codegen`. - EdgeKind::TemplateParameterDefinition - | EdgeKind::TemplateArgument - | EdgeKind::TemplateDeclaration - | EdgeKind::BaseMember - | EdgeKind::Field - | EdgeKind::InnerType - | EdgeKind::FunctionReturn - | EdgeKind::FunctionParameter - | EdgeKind::VarType - | EdgeKind::TypeReference => cc.contains(CodegenConfig::TYPES), - EdgeKind::InnerVar => cc.contains(CodegenConfig::VARS), - EdgeKind::Method => cc.contains(CodegenConfig::METHODS), - EdgeKind::Constructor => cc.contains(CodegenConfig::CONSTRUCTORS), - EdgeKind::Destructor => cc.contains(CodegenConfig::DESTRUCTORS), + EdgeKind::TemplateParameterDefinition | + EdgeKind::TemplateArgument | + EdgeKind::TemplateDeclaration | + EdgeKind::BaseMember | + EdgeKind::Field | + EdgeKind::InnerType | + EdgeKind::FunctionReturn | + EdgeKind::FunctionParameter | + EdgeKind::VarType | + EdgeKind::TypeReference => cc.types(), + EdgeKind::InnerVar => cc.vars(), + EdgeKind::Method => cc.methods(), + EdgeKind::Constructor => cc.constructors(), + EdgeKind::Destructor => cc.destructors() } } @@ -106,17 +106,49 @@ bitflags! { /// A type used to indicate which kind of items we have to generate. pub struct CodegenConfig: u32 { /// Whether to generate functions. - const FUNCTIONS = 0b1 << 0; + const FUNCTIONS = 1 << 0; /// Whether to generate types. - const TYPES = 0b1 << 1; + const TYPES = 1 << 1; /// Whether to generate constants. - const VARS = 0b1 << 2; + const VARS = 1 << 2; /// Whether to generate methods. - const METHODS = 0b1 << 3; + const METHODS = 1 << 3; /// Whether to generate constructors - const CONSTRUCTORS = 0b1 << 4; + const CONSTRUCTORS = 1 << 4; /// Whether to generate destructors. - const DESTRUCTORS = 0b1 << 5; + const DESTRUCTORS = 1 << 5; + } +} + +impl CodegenConfig { + /// Returns true if functions should be generated. + pub fn functions(self) -> bool { + self.contains(CodegenConfig::FUNCTIONS) + } + + /// Returns true if types should be generated. + pub fn types(self) -> bool { + self.contains(CodegenConfig::TYPES) + } + + /// Returns true if constants should be generated. + pub fn vars(self) -> bool { + self.contains(CodegenConfig::VARS) + } + + /// Returns true if methds should be generated. + pub fn methods(self) -> bool { + self.contains(CodegenConfig::METHODS) + } + + /// Returns true if constructors should be generated. + pub fn constructors(self) -> bool { + self.contains(CodegenConfig::CONSTRUCTORS) + } + + /// Returns true if destructors should be generated. + pub fn destructors(self) -> bool { + self.contains(CodegenConfig::DESTRUCTORS) } } |