diff options
author | John Hodge <tpg@mutabah.net> | 2016-11-05 11:00:19 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2016-11-05 11:00:19 +0800 |
commit | 608c5910a35babf09fef14f33fbfac831cc94bef (patch) | |
tree | 9d6ac4e03c2ead5157bb776d78097b4b20fdc303 | |
parent | 6072655369db89d8c8ec0f79ef03f04f695f7459 (diff) | |
download | mrust-608c5910a35babf09fef14f33fbfac831cc94bef.tar.gz |
MIR Gen Match - StructTuple pattern
-rw-r--r-- | src/mir/from_hir_match.cpp | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/src/mir/from_hir_match.cpp b/src/mir/from_hir_match.cpp index 5cf5ff1e..d127c6d1 100644 --- a/src/mir/from_hir_match.cpp +++ b/src/mir/from_hir_match.cpp @@ -768,11 +768,10 @@ void PatternRulesetBuilder::append_from(const Span& sp, const ::HIR::Pattern& pa TU_MATCH_DEF( ::HIR::Pattern::Data, (pat.m_data), (pe), ( BUG(sp, "Match not allowed, " << ty << " with " << pat); ), (Any, - // Nothing. - //this->push_rule( PatternRule::make_Any({}) ); + // _ on a unit-like type, unconditional ), (Value, - //TODO(sp, "Match over struct - Unit + Value"); + // Unit-like struct value, nothing to match (it's unconditional) ) ) ), @@ -791,7 +790,17 @@ void PatternRulesetBuilder::append_from(const Span& sp, const ::HIR::Pattern& pa } ), (StructTuple, - TODO(sp, "Match over struct - TypeRef::Tuple + Pattern::StructTuple"); + assert( sd.size() == pe.sub_patterns.size() ); + for(unsigned int i = 0; i < sd.size(); i ++) + { + const auto& fld = sd[i]; + const auto& fld_pat = pe.sub_patterns[i]; + + ::HIR::TypeRef tmp; + const auto& sty_mono = (monomorphise_type_needed(fld.ent) ? tmp = monomorph(fld.ent) : fld.ent); + this->append_from(sp, fld_pat, sty_mono); + m_field_path.back() ++; + } ) ) m_field_path.pop_back(); |