diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2017-10-12 15:32:34 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-12 15:32:34 -0500 |
commit | d5a5c50ebf05b84ec16a9989697159be49874ed2 (patch) | |
tree | 4424ca0c94975b293b439cde579e3c0e2e55474a | |
parent | bcf0832760328afbc417784fb95a9c499ade3c7a (diff) | |
parent | 6f401c5ef4f082ed73c28cc53a57912e9352b349 (diff) |
Auto merge of #1079 - fitzgen:move-self-into-gen, r=pepyakin
Move `self` into `ir::BindgenContext::gen`
Small clean up. See each commit for details.
r? @pepyakin
-rw-r--r-- | src/codegen/mod.rs | 4 | ||||
-rw-r--r-- | src/ir/context.rs | 19 | ||||
-rw-r--r-- | src/lib.rs | 22 |
3 files changed, 22 insertions, 23 deletions
diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index d1ca904f..38214054 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -7,6 +7,8 @@ pub mod struct_layout; use self::helpers::attributes; use self::struct_layout::StructLayoutTracker; +use super::BindgenOptions; + use ir::analysis::HasVtable; use ir::annotations::FieldAccessorKind; use ir::comment; @@ -3327,7 +3329,7 @@ impl CodeGenerator for ObjCInterface { } } -pub fn codegen(context: &mut BindgenContext) -> Vec<quote::Tokens> { +pub(crate) fn codegen(context: BindgenContext) -> (Vec<quote::Tokens>, BindgenOptions) { context.gen(|context| { let _t = context.timer("codegen"); let counter = Cell::new(0); diff --git a/src/ir/context.rs b/src/ir/context.rs index c84e66ca..560f6ec2 100644 --- a/src/ir/context.rs +++ b/src/ir/context.rs @@ -1152,17 +1152,15 @@ impl BindgenContext { /// Enter the code generation phase, invoke the given callback `cb`, and /// leave the code generation phase. - pub fn gen<F, Out>(&mut self, cb: F) -> Out + pub(crate) fn gen<F, Out>(mut self, cb: F) -> (Out, BindgenOptions) where F: FnOnce(&Self) -> Out, { self.in_codegen = true; - if !self.collected_typerefs() { - self.resolve_typerefs(); - self.compute_bitfield_units(); - self.process_replacements(); - } + self.resolve_typerefs(); + self.compute_bitfield_units(); + self.process_replacements(); self.deanonymize_fields(); @@ -1189,9 +1187,8 @@ impl BindgenContext { self.compute_cannot_derive_hash(); self.compute_cannot_derive_partialord_partialeq_or_eq(); - let ret = cb(self); - self.in_codegen = false; - ret + let ret = cb(&self); + (ret, self.options) } /// When the `testing_only_extra_assertions` feature is enabled, this @@ -1416,9 +1413,9 @@ impl BindgenContext { } /// Resolve a function with the given id. - /// + /// /// Panics if there is no item for the given `FunctionId` or if the resolved - /// item is not a `Function`. + /// item is not a `Function`. pub fn resolve_func(&self, func_id: FunctionId) -> &Function { self.resolve_item(func_id).kind().expect_function() } @@ -858,7 +858,7 @@ impl Builder { } /// Set whether `Ord` should be derived by default. - /// We can't compute `Ord` without computing `PartialOrd`, + /// We can't compute `Ord` without computing `PartialOrd`, /// so we set the same option to derive_partialord. pub fn derive_ord(mut self, doit: bool) -> Self { self.options.derive_ord = doit; @@ -1475,7 +1475,7 @@ fn ensure_libclang_is_loaded() { /// Generated Rust bindings. #[derive(Debug)] pub struct Bindings { - context: BindgenContext, + options: BindgenOptions, module: quote::Tokens, } @@ -1559,10 +1559,10 @@ impl Bindings { try!(parse(&mut context)); } - let items = codegen::codegen(&mut context); + let (items, options) = codegen::codegen(context); Ok(Bindings { - context: context, + options: options, module: quote! { #( #items )* } @@ -1600,11 +1600,11 @@ impl Bindings { "/* automatically generated by rust-bindgen */\n\n".as_bytes(), )?; - for line in self.context.options().raw_lines.iter() { + for line in self.options.raw_lines.iter() { writer.write(line.as_bytes())?; writer.write("\n".as_bytes())?; } - if !self.context.options().raw_lines.is_empty() { + if !self.options.raw_lines.is_empty() { writer.write("\n".as_bytes())?; } @@ -1614,9 +1614,10 @@ impl Bindings { /// Checks if rustfmt_bindings is set and runs rustfmt on the file fn rustfmt_generated_file(&self, file: &Path) -> io::Result<()> { - let _t = self.context.timer("rustfmt_generated_file"); + let _t = time::Timer::new("rustfmt_generated_file") + .with_output(self.options.time_phases); - if !self.context.options().rustfmt_bindings { + if !self.options.rustfmt_bindings { return Ok(()); } @@ -1629,8 +1630,7 @@ impl Bindings { let mut cmd = Command::new(rustfmt); - if let Some(path) = self.context - .options() + if let Some(path) = self.options .rustfmt_configuration_file .as_ref() .and_then(|f| f.to_str()) @@ -1677,7 +1677,7 @@ fn filter_builtins(ctx: &BindgenContext, cursor: &clang::Cursor) -> bool { } /// Parse one `Item` from the Clang cursor. -pub fn parse_one( +fn parse_one( ctx: &mut BindgenContext, cursor: clang::Cursor, parent: Option<ItemId>, |