diff options
author | John Hodge <tpg@mutabah.net> | 2016-09-28 16:45:59 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2016-09-28 16:45:59 +0800 |
commit | 5aff985733c4d221f9cf8f3df02b9b3d2a633478 (patch) | |
tree | 99747ba7c689317f2b80dee94d6eb645dd729689 /src/resolve/absolute.cpp | |
parent | 17259a289ff52ce6028ac78b107d0d697a9cf478 (diff) | |
download | mrust-5aff985733c4d221f9cf8f3df02b9b3d2a633478.tar.gz |
Resolve Absolute - Support extern imports that refer to enum variants
Diffstat (limited to 'src/resolve/absolute.cpp')
-rw-r--r-- | src/resolve/absolute.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/resolve/absolute.cpp b/src/resolve/absolute.cpp index e5576fc8..7273f88b 100644 --- a/src/resolve/absolute.cpp +++ b/src/resolve/absolute.cpp @@ -687,6 +687,27 @@ namespace { ( TODO(sp, "Unknown item type in path - " << i << " " << p << " - " << it->second->ent.tag_str()); ), + (Enum, + if( i != p.m_components.size() - 2 ) { + ERROR(sp, E0000, "Enum as path component in unexpected location - " << p); + } + const auto& varname = p.m_components.back(); + auto it = ::std::find_if( e.m_variants.begin(), e.m_variants.end(), [&](const auto&x){return x.first == varname;} ); + ASSERT_BUG(sp, it != e.m_variants.end(), "Extern crate import path points to non-present variant - " << p); + unsigned int var_idx = it - e.m_variants.begin(); + auto pb = ::AST::PathBinding::make_EnumVar({nullptr, var_idx, &e}); + + // Construct output path (with same set of parameters) + AST::Path rv( p.m_crate_name, {} ); + rv.nodes().reserve( p.m_components.size() ); + for(const auto& c : p.m_components) + rv.nodes().push_back( AST::PathNode(c) ); + rv.nodes().back().args() = mv$( path.nodes().back().args() ); + rv.bind( mv$(pb) ); + path = mv$(rv); + + return ; + ), (Module, hmod = &e; ) @@ -731,6 +752,7 @@ namespace { ) } + // Construct output path (with same set of parameters) AST::Path rv( p.m_crate_name, {} ); rv.nodes().reserve( p.m_components.size() ); for(const auto& c : p.m_components) |