diff options
author | John Hodge <tpg@mutabah.net> | 2016-09-11 18:23:24 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2016-09-11 18:23:24 +0800 |
commit | 058047f175ba166764a77956542bec786d59d21a (patch) | |
tree | 89de69d676d34185000e804a09dd0122b66acb2d /src/resolve/absolute.cpp | |
parent | a98cb27dedfe3b5005ac2d7b6d876ced4b4b6fc7 (diff) | |
download | mrust-058047f175ba166764a77956542bec786d59d21a.tar.gz |
Resolve Absolute - Support path splitting based on HIR traits
Diffstat (limited to 'src/resolve/absolute.cpp')
-rw-r--r-- | src/resolve/absolute.cpp | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/src/resolve/absolute.cpp b/src/resolve/absolute.cpp index d6159dd3..874664dd 100644 --- a/src/resolve/absolute.cpp +++ b/src/resolve/absolute.cpp @@ -990,7 +990,7 @@ void Resolve_Absolute_Path_BindAbsolute(Context& context, const Span& sp, Contex return ; ), (Trait, - assert( e.trait_ ); + assert( e.trait_ || e.hir ); auto trait_path = ::AST::Path(name_ref.path); if( !n.args().is_empty() ) { trait_path.nodes().back().args() = mv$(n.args()); @@ -999,16 +999,30 @@ void Resolve_Absolute_Path_BindAbsolute(Context& context, const Span& sp, Contex // - What if this item is from a nested trait? ::AST::Path new_path; bool found = false; - //switch(mode) - //{ - //case Context::LookupMode::Value: { - assert(i+1 < path_abs.nodes.size()); - auto it = ::std::find_if( e.trait_->items().begin(), e.trait_->items().end(), [&](const auto& x){ return x.name == path_abs.nodes[i+1].name(); } ); + assert(i+1 < path_abs.nodes.size()); + const auto& item_name = path_abs.nodes[i+1].name(); + if( e.trait_ ) + { + auto it = ::std::find_if( e.trait_->items().begin(), e.trait_->items().end(), [&](const auto& x){ return x.name == item_name; } ); if( it != e.trait_->items().end() ) { found = true; } - // } break; - //} + } + else + { + switch(mode) + { + case Context::LookupMode::Constant: + case Context::LookupMode::Pattern: + case Context::LookupMode::Variable: + found = (e.hir->m_values.count(item_name) != 0); + break; + case Context::LookupMode::Namespace: + case Context::LookupMode::Type: + found = (e.hir->m_types.count(item_name) != 0); + break; + } + } if( !found ) { new_path = ::AST::Path(::AST::Path::TagUfcs(), ::TypeRef(sp, mv$(trait_path))); } |