diff options
author | John Hodge <tpg@mutabah.net> | 2016-08-13 10:31:30 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2016-08-13 10:31:30 +0800 |
commit | 7b55e470e275f2182a5bb41413cded0fe9446d3a (patch) | |
tree | 0a85eec0d6711f5a8d7f6b0639e18c0b02832a92 /src/mir/from_hir.cpp | |
parent | 6f05ff4714639025eb890cf7b8201d585335e446 (diff) | |
download | mrust-7b55e470e275f2182a5bb41413cded0fe9446d3a.tar.gz |
MIR Gen - Destructure struct patterns
Diffstat (limited to 'src/mir/from_hir.cpp')
-rw-r--r-- | src/mir/from_hir.cpp | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/mir/from_hir.cpp b/src/mir/from_hir.cpp index 6f166f65..78930715 100644 --- a/src/mir/from_hir.cpp +++ b/src/mir/from_hir.cpp @@ -87,6 +87,7 @@ namespace { } ), (StructValue, + // Nothing. ), (StructTuple, for(unsigned int i = 0; i < e.sub_patterns.size(); i ++ ) @@ -95,9 +96,16 @@ namespace { } ), (StructTupleWildcard, + // Nothing. ), (Struct, - TODO(sp, "Destructure using " << pat); + const auto& str = *e.binding; + const auto& fields = str.m_data.as_Named(); + 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.clone() ), idx}), allow_refutable); + } ), // Refutable (Value, |