Skip to content

Commit d5a5c50

Browse files
author
bors-servo
authored
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
2 parents bcf0832 + 6f401c5 commit d5a5c50

File tree

3 files changed

+22
-23
lines changed

3 files changed

+22
-23
lines changed

src/codegen/mod.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ pub mod struct_layout;
77
use self::helpers::attributes;
88
use self::struct_layout::StructLayoutTracker;
99

10+
use super::BindgenOptions;
11+
1012
use ir::analysis::HasVtable;
1113
use ir::annotations::FieldAccessorKind;
1214
use ir::comment;
@@ -3327,7 +3329,7 @@ impl CodeGenerator for ObjCInterface {
33273329
}
33283330
}
33293331

3330-
pub fn codegen(context: &mut BindgenContext) -> Vec<quote::Tokens> {
3332+
pub(crate) fn codegen(context: BindgenContext) -> (Vec<quote::Tokens>, BindgenOptions) {
33313333
context.gen(|context| {
33323334
let _t = context.timer("codegen");
33333335
let counter = Cell::new(0);

src/ir/context.rs

+8-11
Original file line numberDiff line numberDiff line change
@@ -1152,17 +1152,15 @@ impl BindgenContext {
11521152

11531153
/// Enter the code generation phase, invoke the given callback `cb`, and
11541154
/// leave the code generation phase.
1155-
pub fn gen<F, Out>(&mut self, cb: F) -> Out
1155+
pub(crate) fn gen<F, Out>(mut self, cb: F) -> (Out, BindgenOptions)
11561156
where
11571157
F: FnOnce(&Self) -> Out,
11581158
{
11591159
self.in_codegen = true;
11601160

1161-
if !self.collected_typerefs() {
1162-
self.resolve_typerefs();
1163-
self.compute_bitfield_units();
1164-
self.process_replacements();
1165-
}
1161+
self.resolve_typerefs();
1162+
self.compute_bitfield_units();
1163+
self.process_replacements();
11661164

11671165
self.deanonymize_fields();
11681166

@@ -1189,9 +1187,8 @@ impl BindgenContext {
11891187
self.compute_cannot_derive_hash();
11901188
self.compute_cannot_derive_partialord_partialeq_or_eq();
11911189

1192-
let ret = cb(self);
1193-
self.in_codegen = false;
1194-
ret
1190+
let ret = cb(&self);
1191+
(ret, self.options)
11951192
}
11961193

11971194
/// When the `testing_only_extra_assertions` feature is enabled, this
@@ -1416,9 +1413,9 @@ impl BindgenContext {
14161413
}
14171414

14181415
/// Resolve a function with the given id.
1419-
///
1416+
///
14201417
/// Panics if there is no item for the given `FunctionId` or if the resolved
1421-
/// item is not a `Function`.
1418+
/// item is not a `Function`.
14221419
pub fn resolve_func(&self, func_id: FunctionId) -> &Function {
14231420
self.resolve_item(func_id).kind().expect_function()
14241421
}

src/lib.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -858,7 +858,7 @@ impl Builder {
858858
}
859859

860860
/// Set whether `Ord` should be derived by default.
861-
/// We can't compute `Ord` without computing `PartialOrd`,
861+
/// We can't compute `Ord` without computing `PartialOrd`,
862862
/// so we set the same option to derive_partialord.
863863
pub fn derive_ord(mut self, doit: bool) -> Self {
864864
self.options.derive_ord = doit;
@@ -1475,7 +1475,7 @@ fn ensure_libclang_is_loaded() {
14751475
/// Generated Rust bindings.
14761476
#[derive(Debug)]
14771477
pub struct Bindings {
1478-
context: BindgenContext,
1478+
options: BindgenOptions,
14791479
module: quote::Tokens,
14801480
}
14811481

@@ -1559,10 +1559,10 @@ impl Bindings {
15591559
try!(parse(&mut context));
15601560
}
15611561

1562-
let items = codegen::codegen(&mut context);
1562+
let (items, options) = codegen::codegen(context);
15631563

15641564
Ok(Bindings {
1565-
context: context,
1565+
options: options,
15661566
module: quote! {
15671567
#( #items )*
15681568
}
@@ -1600,11 +1600,11 @@ impl Bindings {
16001600
"/* automatically generated by rust-bindgen */\n\n".as_bytes(),
16011601
)?;
16021602

1603-
for line in self.context.options().raw_lines.iter() {
1603+
for line in self.options.raw_lines.iter() {
16041604
writer.write(line.as_bytes())?;
16051605
writer.write("\n".as_bytes())?;
16061606
}
1607-
if !self.context.options().raw_lines.is_empty() {
1607+
if !self.options.raw_lines.is_empty() {
16081608
writer.write("\n".as_bytes())?;
16091609
}
16101610

@@ -1614,9 +1614,10 @@ impl Bindings {
16141614

16151615
/// Checks if rustfmt_bindings is set and runs rustfmt on the file
16161616
fn rustfmt_generated_file(&self, file: &Path) -> io::Result<()> {
1617-
let _t = self.context.timer("rustfmt_generated_file");
1617+
let _t = time::Timer::new("rustfmt_generated_file")
1618+
.with_output(self.options.time_phases);
16181619

1619-
if !self.context.options().rustfmt_bindings {
1620+
if !self.options.rustfmt_bindings {
16201621
return Ok(());
16211622
}
16221623

@@ -1629,8 +1630,7 @@ impl Bindings {
16291630

16301631
let mut cmd = Command::new(rustfmt);
16311632

1632-
if let Some(path) = self.context
1633-
.options()
1633+
if let Some(path) = self.options
16341634
.rustfmt_configuration_file
16351635
.as_ref()
16361636
.and_then(|f| f.to_str())
@@ -1677,7 +1677,7 @@ fn filter_builtins(ctx: &BindgenContext, cursor: &clang::Cursor) -> bool {
16771677
}
16781678

16791679
/// Parse one `Item` from the Clang cursor.
1680-
pub fn parse_one(
1680+
fn parse_one(
16811681
ctx: &mut BindgenContext,
16821682
cursor: clang::Cursor,
16831683
parent: Option<ItemId>,

0 commit comments

Comments
 (0)