diff options
Diffstat (limited to 'src/lib.rs')
-rw-r--r-- | src/lib.rs | 101 |
1 files changed, 54 insertions, 47 deletions
@@ -16,6 +16,8 @@ // `quote!` nests quite deeply. #![recursion_limit="128"] +#[macro_use] +extern crate bitflags; extern crate cexpr; #[macro_use] #[allow(unused_extern_crates)] @@ -100,48 +102,53 @@ fn args_are_cpp(clang_args: &[String]) -> bool { .any(|w| w[0] == "-x=c++" || w[1] == "-x=c++" || w == &["-x", "c++"]); } -/// A type used to indicate which kind of items do we have to generate. -/// -/// TODO(emilio): Use `bitflags!` -#[derive(Debug, Clone)] -pub struct CodegenConfig { - /// Whether to generate functions. - pub functions: bool, - /// Whether to generate types. - pub types: bool, - /// Whether to generate constants. - pub vars: bool, - /// Whether to generate methods. - pub methods: bool, - /// Whether to generate constructors. - pub constructors: bool, - /// Whether to generate destructors. - pub destructors: bool, +bitflags! { + /// A type used to indicate which kind of items we have to generate. + pub struct CodegenConfig: u32 { + /// Whether to generate functions. + const FUNCTIONS = 1 << 0; + /// Whether to generate types. + const TYPES = 1 << 1; + /// Whether to generate constants. + const VARS = 1 << 2; + /// Whether to generate methods. + const METHODS = 1 << 3; + /// Whether to generate constructors + const CONSTRUCTORS = 1 << 4; + /// Whether to generate destructors. + const DESTRUCTORS = 1 << 5; + } } impl CodegenConfig { - /// Generate all kinds of items. - pub fn all() -> Self { - CodegenConfig { - functions: true, - types: true, - vars: true, - methods: true, - constructors: true, - destructors: true, - } + /// Returns true if functions should be generated. + pub fn functions(self) -> bool { + self.contains(CodegenConfig::FUNCTIONS) } - /// Generate nothing. - pub fn nothing() -> Self { - CodegenConfig { - functions: false, - types: false, - vars: false, - methods: false, - constructors: false, - destructors: false, - } + /// 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) } } @@ -393,7 +400,7 @@ impl Builder { output_vector.push("--disable-name-namespacing".into()); } - if !self.options.codegen_config.functions { + if !self.options.codegen_config.functions() { output_vector.push("--ignore-functions".into()); } @@ -401,28 +408,28 @@ impl Builder { //Temporary placeholder for below 4 options let mut options: Vec<String> = Vec::new(); - if self.options.codegen_config.functions { + if self.options.codegen_config.functions() { options.push("function".into()); } - if self.options.codegen_config.types { + if self.options.codegen_config.types() { options.push("types".into()); } - if self.options.codegen_config.vars { + if self.options.codegen_config.vars() { options.push("vars".into()); } - if self.options.codegen_config.methods { + if self.options.codegen_config.methods() { options.push("methods".into()); } - if self.options.codegen_config.constructors { + if self.options.codegen_config.constructors() { options.push("constructors".into()); } - if self.options.codegen_config.destructors { + if self.options.codegen_config.destructors() { options.push("destructors".into()); } output_vector.push(options.join(",")); - if !self.options.codegen_config.methods { + if !self.options.codegen_config.methods() { output_vector.push("--ignore-methods".into()); } @@ -1070,13 +1077,13 @@ impl Builder { /// Ignore functions. pub fn ignore_functions(mut self) -> Builder { - self.options.codegen_config.functions = false; + self.options.codegen_config.remove(CodegenConfig::FUNCTIONS); self } /// Ignore methods. pub fn ignore_methods(mut self) -> Builder { - self.options.codegen_config.methods = false; + self.options.codegen_config.remove(CodegenConfig::METHODS); self } |