Skip to content

Commit ef9136d

Browse files
committed
Move codegen config checks into Codegen impls
This means that we only need to check in one place, rather than at ever call site.
1 parent 10ea03c commit ef9136d

File tree

3 files changed

+77
-42
lines changed

3 files changed

+77
-42
lines changed

src/codegen/mod.rs

Lines changed: 47 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1760,49 +1760,43 @@ impl CodeGenerator for CompInfo {
17601760
}
17611761

17621762
let mut method_names = Default::default();
1763-
if ctx.options().codegen_config.methods {
1764-
for method in self.methods() {
1765-
assert!(method.kind() != MethodKind::Constructor);
1766-
method.codegen_method(ctx,
1767-
&mut methods,
1768-
&mut method_names,
1769-
result,
1770-
whitelisted_items,
1771-
self);
1772-
}
1773-
}
1774-
1775-
if ctx.options().codegen_config.constructors {
1776-
for sig in self.constructors() {
1777-
Method::new(MethodKind::Constructor,
1778-
*sig,
1779-
/* const */
1780-
false)
1781-
.codegen_method(ctx,
1782-
&mut methods,
1783-
&mut method_names,
1784-
result,
1785-
whitelisted_items,
1786-
self);
1787-
}
1788-
}
1789-
1790-
if ctx.options().codegen_config.destructors {
1791-
if let Some((is_virtual, destructor)) = self.destructor() {
1792-
let kind = if is_virtual {
1793-
MethodKind::VirtualDestructor
1794-
} else {
1795-
MethodKind::Destructor
1796-
};
1763+
for method in self.methods() {
1764+
assert!(method.kind() != MethodKind::Constructor);
1765+
method.codegen_method(ctx,
1766+
&mut methods,
1767+
&mut method_names,
1768+
result,
1769+
whitelisted_items,
1770+
self);
1771+
}
1772+
1773+
for sig in self.constructors() {
1774+
Method::new(MethodKind::Constructor,
1775+
*sig,
1776+
/* const */
1777+
false)
1778+
.codegen_method(ctx,
1779+
&mut methods,
1780+
&mut method_names,
1781+
result,
1782+
whitelisted_items,
1783+
self);
1784+
}
1785+
1786+
if let Some((is_virtual, destructor)) = self.destructor() {
1787+
let kind = if is_virtual {
1788+
MethodKind::VirtualDestructor
1789+
} else {
1790+
MethodKind::Destructor
1791+
};
17971792

1798-
Method::new(kind, destructor, false)
1799-
.codegen_method(ctx,
1800-
&mut methods,
1801-
&mut method_names,
1802-
result,
1803-
whitelisted_items,
1804-
self);
1805-
}
1793+
Method::new(kind, destructor, false)
1794+
.codegen_method(ctx,
1795+
&mut methods,
1796+
&mut method_names,
1797+
result,
1798+
whitelisted_items,
1799+
self);
18061800
}
18071801
}
18081802

@@ -1897,6 +1891,17 @@ impl MethodCodegen for Method {
18971891
result: &mut CodegenResult<'a>,
18981892
whitelisted_items: &ItemSet,
18991893
_parent: &CompInfo) {
1894+
let config = &ctx.options().codegen_config;
1895+
match self.kind() {
1896+
MethodKind::Constructor if !config.constructors => return,
1897+
MethodKind::Destructor if !config.destructors => return,
1898+
MethodKind::VirtualDestructor if !config.destructors => return,
1899+
MethodKind::Static if !config.methods => return,
1900+
MethodKind::Normal if !config.methods => return,
1901+
MethodKind::Virtual if !config.methods => return,
1902+
_ => {}
1903+
}
1904+
19001905
if self.is_virtual() {
19011906
return; // FIXME
19021907
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/* automatically generated by rust-bindgen */
2+
3+
4+
#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
5+
6+
7+
#[repr(C)]
8+
#[derive(Debug, Default, Copy)]
9+
pub struct Foo {
10+
pub _address: u8,
11+
}
12+
#[test]
13+
fn bindgen_test_layout_Foo() {
14+
assert_eq!(::std::mem::size_of::<Foo>() , 1usize , concat ! (
15+
"Size of: " , stringify ! ( Foo ) ));
16+
assert_eq! (::std::mem::align_of::<Foo>() , 1usize , concat ! (
17+
"Alignment of " , stringify ! ( Foo ) ));
18+
}
19+
impl Clone for Foo {
20+
fn clone(&self) -> Self { *self }
21+
}
22+
extern "C" {
23+
#[link_name = "_ZN3Foo4testEv"]
24+
pub fn Foo_test(this: *mut Foo);
25+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// bindgen-flags: --ignore-methods
2+
3+
struct Foo {
4+
void test();
5+
};

0 commit comments

Comments
 (0)