diff options
author | John Hodge <tpg@mutabah.net> | 2016-10-07 14:36:03 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2016-10-07 14:36:03 +0800 |
commit | 88a508b48444c6e051676a21a2318d5858327528 (patch) | |
tree | 38742c1d0f3f9291ba5d009f383882549b2ff88b /src | |
parent | a552db72d08fa2b65444210765ab980933efd82e (diff) | |
download | mrust-88a508b48444c6e051676a21a2318d5858327528.tar.gz |
MIR From HIR Match - Array patterns
Diffstat (limited to 'src')
-rw-r--r-- | src/mir/from_hir_match.cpp | 37 |
1 files changed, 35 insertions, 2 deletions
diff --git a/src/mir/from_hir_match.cpp b/src/mir/from_hir_match.cpp index 083dc0ce..57bccdb5 100644 --- a/src/mir/from_hir_match.cpp +++ b/src/mir/from_hir_match.cpp @@ -1273,10 +1273,31 @@ void PatternRulesetBuilder::append_from(const Span& sp, const ::HIR::Pattern& pa } ), (Array, - // TODO: Slice patterns, sequential comparison/sub-match - TODO(sp, "Match over array"); + // Sequential match just like tuples. + m_field_path.push_back(0); + TU_MATCH_DEF(::HIR::Pattern::Data, (pat.m_data), (pe), + ( BUG(sp, "Matching array with invalid pattern - " << pat); ), + (Any, + for(unsigned int i = 0; i < e.size_val; i ++) { + this->append_from(sp, pat, *e.inner); + m_field_path.back() ++; + } + ), + (Slice, + assert(e.size_val == pe.sub_patterns.size()); + for(unsigned int i = 0; i < e.size_val; i ++) { + this->append_from(sp, pe.sub_patterns[i], *e.inner); + m_field_path.back() ++; + } + ), + (SplitSlice, + TODO(sp, "Match over array with SplitSlice pattern - " << pat); + ) + ) + m_field_path.pop_back(); ), (Slice, + // TODO: Slice patterns, sequential comparison/sub-match if( pat.m_data.is_Any() ) { } else { @@ -1293,6 +1314,18 @@ void PatternRulesetBuilder::append_from(const Span& sp, const ::HIR::Pattern& pa (Ref, this->append_from( sp, *pe.sub, *e.inner ); ), + (Slice, + if( e.inner->m_data.is_Slice() ) + { + TODO(sp, "Match &[T] with Slice - " << pat); + } + ), + (SplitSlice, + if( e.inner->m_data.is_Slice() ) + { + TODO(sp, "Match &[T] with SplitSlice - " << pat); + } + ), (Value, // TODO: Check type? Also handle named values and byte strings. if( pe.val.is_String() ) { |