diff options
author | John Hodge <tpg@mutabah.net> | 2016-12-23 22:22:03 +1100 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2016-12-23 22:22:03 +1100 |
commit | 23f87f12c70bca2992006bfac27659761185b134 (patch) | |
tree | 2adefc40ed5c0ed90277cfbced43e1e68a2a0bce /src/mir/from_hir.cpp | |
parent | 9265ea5e5c5af464f75a9ad1b397202ab2954206 (diff) | |
download | mrust-23f87f12c70bca2992006bfac27659761185b134.tar.gz |
MIR Gen - Track split state for temporaries (incomplete)
Diffstat (limited to 'src/mir/from_hir.cpp')
-rw-r--r-- | src/mir/from_hir.cpp | 27 |
1 files changed, 11 insertions, 16 deletions
diff --git a/src/mir/from_hir.cpp b/src/mir/from_hir.cpp index 8951599b..a3410d35 100644 --- a/src/mir/from_hir.cpp +++ b/src/mir/from_hir.cpp @@ -190,6 +190,7 @@ namespace { { destructure_from_ex(sp, e.leading[i], ::MIR::LValue::make_Field({ box$( lval.clone() ), i}), allow_refutable); } + // TODO: Is there a binding in the middle? unsigned int ofs = e.total_size - e.trailing.size(); for(unsigned int i = 0; i < e.trailing.size(); i ++ ) { @@ -230,28 +231,22 @@ namespace { ), (EnumTuple, const auto& enm = *e.binding_ptr; - if( enm.m_variants.size() > 1 ) + ASSERT_BUG(sp, enm.m_variants.size() == 1 || allow_refutable, "Refutable pattern not expected - " << pat); + auto lval_var = ::MIR::LValue::make_Downcast({ box$(mv$(lval)), e.binding_idx }); + for(unsigned int i = 0; i < e.sub_patterns.size(); i ++ ) { - ASSERT_BUG(sp, allow_refutable, "Refutable pattern not expected - " << pat); - auto lval_var = ::MIR::LValue::make_Downcast({ box$(mv$(lval)), e.binding_idx }); - for(unsigned int i = 0; i < e.sub_patterns.size(); i ++ ) - { - destructure_from_ex(sp, e.sub_patterns[i], ::MIR::LValue::make_Field({ box$( lval_var.clone() ), i}), allow_refutable); - } + destructure_from_ex(sp, e.sub_patterns[i], ::MIR::LValue::make_Field({ box$( lval_var.clone() ), i}), allow_refutable); } ), (EnumStruct, - ASSERT_BUG(sp, allow_refutable, "Refutable pattern not expected - " << pat); const auto& enm = *e.binding_ptr; - if( enm.m_variants.size() > 1 ) + ASSERT_BUG(sp, enm.m_variants.size() == 1 || allow_refutable, "Refutable pattern not expected - " << pat); + const auto& fields = enm.m_variants[e.binding_idx].second.as_Struct(); + auto lval_var = ::MIR::LValue::make_Downcast({ box$(mv$(lval)), e.binding_idx }); + for(const auto& fld_pat : e.sub_patterns) { - const auto& fields = enm.m_variants[e.binding_idx].second.as_Struct(); - auto lval_var = ::MIR::LValue::make_Downcast({ box$(mv$(lval)), e.binding_idx }); - for(const auto& fld_pat : e.sub_patterns) - { - unsigned idx = ::std::find_if( fields.begin(), fields.end(), [&](const auto&x){ return x.first == fld_pat.first; } ) - fields.begin(); - destructure_from_ex(sp, fld_pat.second, ::MIR::LValue::make_Field({ box$( lval_var.clone() ), idx}), allow_refutable); - } + unsigned idx = ::std::find_if( fields.begin(), fields.end(), [&](const auto&x){ return x.first == fld_pat.first; } ) - fields.begin(); + destructure_from_ex(sp, fld_pat.second, ::MIR::LValue::make_Field({ box$( lval_var.clone() ), idx}), allow_refutable); } ), (Slice, |