diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2017-07-20 14:52:13 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-07-20 14:52:13 -0700 |
commit | 9dbc2cad27837d6e5c088eb8d3b85148502c67b4 (patch) | |
tree | b2510df39fe430af585c98cdf2e505f3de7cf77a /src/codegen/mod.rs | |
parent | 8f43c93497aacd2742757f71a92e903195ca986c (diff) | |
parent | 0b720a311ba243c66965a060af7dd3d9bc102315 (diff) |
Auto merge of #827 - fitzgen:issue-826-generating-methods-when-asked-not-to, r=emilio
Only whitelist items for which we intend to generate bindings
This means that we only need to check in one place, rather than at ever call site.
This makes it so that we don't generate methods for the test case, but if I add the `--target` flag like in the original #826 test case, then I get a panic about an unknown ABI. I figure this change is worth landing now, and we can land the fix for the panic as a follow up.
r? @upsuper
Diffstat (limited to 'src/codegen/mod.rs')
-rw-r--r-- | src/codegen/mod.rs | 41 |
1 files changed, 31 insertions, 10 deletions
diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 6f2bf96b..cf4fad50 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -294,6 +294,10 @@ impl CodeGenerator for Item { result: &mut CodegenResult<'a>, whitelisted_items: &ItemSet, _extra: &()) { + if !self.is_enabled_for_codegen(ctx) { + return; + } + if self.is_hidden(ctx) || result.seen(self.id()) { debug!("<Item as CodeGenerator>::codegen: Ignoring hidden or seen: \ self = {:?}", @@ -316,19 +320,13 @@ impl CodeGenerator for Item { module.codegen(ctx, result, whitelisted_items, self); } ItemKind::Function(ref fun) => { - if ctx.options().codegen_config.functions { - fun.codegen(ctx, result, whitelisted_items, self); - } + fun.codegen(ctx, result, whitelisted_items, self); } ItemKind::Var(ref var) => { - if ctx.options().codegen_config.vars { - var.codegen(ctx, result, whitelisted_items, self); - } + var.codegen(ctx, result, whitelisted_items, self); } ItemKind::Type(ref ty) => { - if ctx.options().codegen_config.types { - ty.codegen(ctx, result, whitelisted_items, self); - } + ty.codegen(ctx, result, whitelisted_items, self); } } } @@ -419,6 +417,7 @@ impl CodeGenerator for Var { item: &Item) { use ir::var::VarType; debug!("<Var as CodeGenerator>::codegen: item = {:?}", item); + debug_assert!(item.is_enabled_for_codegen(ctx)); let canonical_name = item.canonical_name(ctx); @@ -522,6 +521,7 @@ impl CodeGenerator for Type { whitelisted_items: &ItemSet, item: &Item) { debug!("<Type as CodeGenerator>::codegen: item = {:?}", item); + debug_assert!(item.is_enabled_for_codegen(ctx)); match *self.kind() { TypeKind::Void | @@ -705,6 +705,8 @@ impl<'a> CodeGenerator for Vtable<'a> { _whitelisted_items: &ItemSet, item: &Item) { assert_eq!(item.id(), self.item_id); + debug_assert!(item.is_enabled_for_codegen(ctx)); + // For now, generate an empty struct, later we should generate function // pointers and whatnot. let attributes = vec![attributes::repr("C")]; @@ -745,6 +747,8 @@ impl CodeGenerator for TemplateInstantiation { result: &mut CodegenResult<'a>, _whitelisted_items: &ItemSet, item: &Item) { + debug_assert!(item.is_enabled_for_codegen(ctx)); + // Although uses of instantiations don't need code generation, and are // just converted to rust types in fields, vars, etc, we take this // opportunity to generate tests for their layout here. If the @@ -1376,6 +1380,7 @@ impl CodeGenerator for CompInfo { whitelisted_items: &ItemSet, item: &Item) { debug!("<CompInfo as CodeGenerator>::codegen: item = {:?}", item); + debug_assert!(item.is_enabled_for_codegen(ctx)); // Don't output classes with template parameters that aren't types, and // also don't output template specializations, neither total or partial. @@ -1897,6 +1902,18 @@ impl MethodCodegen for Method { result: &mut CodegenResult<'a>, whitelisted_items: &ItemSet, _parent: &CompInfo) { + assert!({ + let cc = &ctx.options().codegen_config; + match self.kind() { + MethodKind::Constructor => cc.constructors, + MethodKind::Destructor => cc.destructors, + MethodKind::VirtualDestructor => cc.destructors, + MethodKind::Static | + MethodKind::Normal | + MethodKind::Virtual => cc.methods, + } + }); + if self.is_virtual() { return; // FIXME } @@ -2287,6 +2304,7 @@ impl CodeGenerator for Enum { _whitelisted_items: &ItemSet, item: &Item) { debug!("<Enum as CodeGenerator>::codegen: item = {:?}", item); + debug_assert!(item.is_enabled_for_codegen(ctx)); let name = item.canonical_name(ctx); let enum_ty = item.expect_type(); @@ -3026,6 +3044,7 @@ impl CodeGenerator for Function { _whitelisted_items: &ItemSet, item: &Item) { debug!("<Function as CodeGenerator>::codegen: item = {:?}", item); + debug_assert!(item.is_enabled_for_codegen(ctx)); // Similar to static member variables in a class template, we can't // generate bindings to template functions, because the set of @@ -3202,7 +3221,9 @@ impl CodeGenerator for ObjCInterface { ctx: &BindgenContext, result: &mut CodegenResult<'a>, _whitelisted_items: &ItemSet, - _: &Item) { + item: &Item) { + debug_assert!(item.is_enabled_for_codegen(ctx)); + let mut impl_items = vec![]; let mut trait_items = vec![]; |