summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Hodge <tpg@mutabah.net>2016-08-11 22:08:24 +0800
committerJohn Hodge <tpg@mutabah.net>2016-08-11 22:08:24 +0800
commit6616b8905392aa7faebc864534aa74cf461af758 (patch)
tree5d36ba1b5be38060d3d5340881b77d8195511e8a /src
parent0ee17e2a161cf0db080e9aaa6f251b40af5d9d0e (diff)
downloadmrust-6616b8905392aa7faebc864534aa74cf461af758.tar.gz
MIR Match - Struct match and binding
Diffstat (limited to 'src')
-rw-r--r--src/mir/from_hir_match.cpp83
1 files changed, 77 insertions, 6 deletions
diff --git a/src/mir/from_hir_match.cpp b/src/mir/from_hir_match.cpp
index bb266fee..4cfa5332 100644
--- a/src/mir/from_hir_match.cpp
+++ b/src/mir/from_hir_match.cpp
@@ -350,7 +350,58 @@ void PatternRulesetBuilder::append_from(const Span& sp, const ::HIR::Pattern& pa
)
),
(Struct,
- TODO(sp, "Match over struct - " << e.path);
+ //auto monomorph_cb = [&](const auto& ty)->const auto& {
+ // const auto& ge = ty.m_data.as_Generic();
+ // if( ge.
+ // };
+ auto monomorph = [&](const auto& ty) { return monomorphise_type(sp, pbe->m_params, e.path.m_data.as_Generic().m_params, ty); };
+ const auto& str_data = pbe->m_data;
+ TU_MATCHA( (str_data), (sd),
+ (Unit,
+ TU_MATCH_DEF( ::HIR::Pattern::Data, (pat.m_data), (pe),
+ ( BUG(sp, "Match not allowed, " << ty << " with " << pat); ),
+ (Any,
+ // Nothing.
+ ),
+ (Value,
+ TODO(sp, "Match over struct - Unit + Value");
+ )
+ )
+ ),
+ (Tuple,
+ TU_MATCH_DEF( ::HIR::Pattern::Data, (pat.m_data), (pe),
+ ( BUG(sp, "Match not allowed, " << ty << " with " << pat); ),
+ (Any,
+ TODO(sp, "Match over struct - Tuple + Any");
+ ),
+ (StructTuple,
+ TODO(sp, "Match over struct - Tuple + StructTuple");
+ ),
+ (StructTupleWildcard,
+ TODO(sp, "Match over struct - Tuple + StructTupleWildcard");
+ )
+ )
+ ),
+ (Named,
+ // TODO: Avoid needing to clone everything.
+ ::std::vector< ::HIR::TypeRef> types;
+ types.reserve( sd.size() );
+ for( const auto& fld : sd ) {
+ types.push_back( monomorph(fld.second.ent) );
+ }
+
+ TU_MATCH_DEF( ::HIR::Pattern::Data, (pat.m_data), (pe),
+ ( BUG(sp, "Match not allowed, " << ty << " with " << pat); ),
+ (Any,
+ for(const auto& sty : types)
+ this->append_from(sp, pat, sty);
+ ),
+ (Struct,
+ TODO(sp, "Match over struct - Named + Struct");
+ )
+ )
+ )
+ )
),
(Enum,
TU_MATCH_DEF( ::HIR::Pattern::Data, (pat.m_data), (pe),
@@ -394,14 +445,22 @@ void PatternRulesetBuilder::append_from(const Span& sp, const ::HIR::Pattern& pa
)
),
(TraitObject,
- ERROR(sp, E0000, "Attempting to match over a trait object");
+ if( pat.m_data.is_Any() ) {
+ }
+ else {
+ ERROR(sp, E0000, "Attempting to match over a trait object");
+ }
),
(Array,
// TODO: Slice patterns, sequential comparison/sub-match
TODO(sp, "Match over array");
),
(Slice,
- BUG(sp, "Hit match over `[T]` - must be `&[T]`");
+ if( pat.m_data.is_Any() ) {
+ }
+ else {
+ BUG(sp, "Hit match over `[T]` - must be `&[T]`");
+ }
),
(Borrow,
TU_MATCH_DEF( ::HIR::Pattern::Data, (pat.m_data), (pe),
@@ -415,13 +474,25 @@ void PatternRulesetBuilder::append_from(const Span& sp, const ::HIR::Pattern& pa
)
),
(Pointer,
- ERROR(sp, E0000, "Attempting to match over a pointer");
+ if( pat.m_data.is_Any() ) {
+ }
+ else {
+ ERROR(sp, E0000, "Attempting to match over a pointer");
+ }
),
(Function,
- ERROR(sp, E0000, "Attempting to match over a functon pointer");
+ if( pat.m_data.is_Any() ) {
+ }
+ else {
+ ERROR(sp, E0000, "Attempting to match over a functon pointer");
+ }
),
(Closure,
- ERROR(sp, E0000, "Attempting to match over a closure");
+ if( pat.m_data.is_Any() ) {
+ }
+ else {
+ ERROR(sp, E0000, "Attempting to match over a closure");
+ }
)
)
}