summaryrefslogtreecommitdiff
path: root/src/trans/codegen_c.cpp
diff options
context:
space:
mode:
authorJohn Hodge <tpg@mutabah.net>2016-12-24 15:54:24 +1100
committerJohn Hodge <tpg@mutabah.net>2016-12-24 15:54:24 +1100
commit9f16fcdf9dafa2da0d7b566e6acf66a5a92857de (patch)
tree022c0a7e2e1a5db5f27f93e1804fd9fc219698b6 /src/trans/codegen_c.cpp
parentd501dd243154e006d95d7223152da0a5f5fc6720 (diff)
downloadmrust-9f16fcdf9dafa2da0d7b566e6acf66a5a92857de.tar.gz
Trans - Generate Box destructors
Diffstat (limited to 'src/trans/codegen_c.cpp')
-rw-r--r--src/trans/codegen_c.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/trans/codegen_c.cpp b/src/trans/codegen_c.cpp
index e1f4b0ad..cd103d19 100644
--- a/src/trans/codegen_c.cpp
+++ b/src/trans/codegen_c.cpp
@@ -134,6 +134,7 @@ namespace {
emit_ctype( monomorph(ty), inner );
}
};
+ m_of << "// struct " << p << "\n";
m_of << "struct s_" << Trans_Mangle(p) << " {\n";
TU_MATCHA( (item.m_data), (e),
(Unit,
@@ -197,6 +198,18 @@ namespace {
if( item.m_markings.has_drop_impl ) {
m_of << "\t" << Trans_Mangle( ::HIR::Path(struct_ty.clone(), m_resolve.m_lang_Drop, "drop") ) << "(rv);\n";
}
+ else if( const auto* ity = m_resolve.is_type_owned_box(struct_ty) )
+ {
+ // Obtain inner pointer
+ // TODO: This is very specific to the structure of the official liballoc's Box.
+ ::HIR::TypeRef inner_ptr = ::HIR::TypeRef::new_pointer( ::HIR::BorrowType::Unique, ity->clone() );
+ m_of << "\t"; emit_ctype(inner_ptr, FMT_CB(ss, ss << "tmp0"; )); m_of << " = rv->_0._0._0;\n";
+ // Call destructor of inner data
+ emit_destructor_call(::MIR::LValue::make_Temporary({0}), *ity, true);
+ // Emit a call to box_free for the type
+ ::HIR::GenericPath box_free { m_crate.get_lang_item_path(sp, "box_free"), { ity->clone() } };
+ m_of << "\t" << Trans_Mangle(box_free) << "(tmp0);\n";
+ }
auto self = ::MIR::LValue::make_Deref({ box$(::MIR::LValue::make_Return({})) });
auto fld_lv = ::MIR::LValue::make_Field({ box$(self), 0 });