diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2017-04-03 18:11:11 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-03 18:11:11 -0500 |
commit | 5e85271697255498603e852eaa0723da5f41f1bf (patch) | |
tree | 300e99521f0ff6baf2677363fb59696d283283e8 /src/codegen/mod.rs | |
parent | d4fce37939fbcebd04e7b7efec6930cfd717b13d (diff) | |
parent | 1f53966ee6b872b7443b335a84d9cf1b57394f13 (diff) |
Auto merge of #608 - emilio:destructor-codegen, r=fitzgen
Destructor codegen
Based on #542, and on top of #606, with a bunch more tests and fixes.
Diffstat (limited to 'src/codegen/mod.rs')
-rw-r--r-- | src/codegen/mod.rs | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index fb6c839d..5586c146 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -1597,6 +1597,24 @@ impl CodeGenerator for CompInfo { self); } } + + if ctx.options().codegen_config.destructors { + if let Some((is_virtual, destructor)) = self.destructor() { + let kind = if is_virtual { + MethodKind::VirtualDestructor + } else { + MethodKind::Destructor + }; + + Method::new(kind, destructor, false) + .codegen_method(ctx, + &mut methods, + &mut method_names, + result, + whitelisted_items, + self); + } + } } // NB: We can't use to_rust_ty here since for opaque types this tries to @@ -1693,6 +1711,7 @@ impl MethodCodegen for Method { if self.is_virtual() { return; // FIXME } + // First of all, output the actual function. let function_item = ctx.resolve_item(self.signature()); function_item.codegen(ctx, result, whitelisted_items, &()); @@ -1701,6 +1720,7 @@ impl MethodCodegen for Method { let signature_item = ctx.resolve_item(function.signature()); let mut name = match self.kind() { MethodKind::Constructor => "new".into(), + MethodKind::Destructor => "destruct".into(), _ => function.name().to_owned(), }; @@ -1801,11 +1821,7 @@ impl MethodCodegen for Method { exprs[0] = quote_expr!(ctx.ext_cx(), &mut __bindgen_tmp); } else if !self.is_static() { assert!(!exprs.is_empty()); - exprs[0] = if self.is_const() { - quote_expr!(ctx.ext_cx(), &*self) - } else { - quote_expr!(ctx.ext_cx(), &mut *self) - }; + exprs[0] = quote_expr!(ctx.ext_cx(), self); }; let call = aster::expr::ExprBuilder::new() |