diff options
author | John Hodge <tpg@mutabah.net> | 2016-10-16 10:31:00 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2016-10-16 10:31:00 +0800 |
commit | f353d572ea66b9bfcfdc9a4e50548838a9e8c7c3 (patch) | |
tree | 7eb8b34804e85f8e0b2fe3eba9e71da9b141803d /src/resolve | |
parent | c2cec3e30a0f142bc2e44d756463558ab8d2f1e1 (diff) | |
download | mrust-f353d572ea66b9bfcfdc9a4e50548838a9e8c7c3.tar.gz |
Resolve - Handle glob imports from external enums
Diffstat (limited to 'src/resolve')
-rw-r--r-- | src/resolve/index.cpp | 46 | ||||
-rw-r--r-- | src/resolve/use.cpp | 6 |
2 files changed, 38 insertions, 14 deletions
diff --git a/src/resolve/index.cpp b/src/resolve/index.cpp index 3a309305..421f4ae1 100644 --- a/src/resolve/index.cpp +++ b/src/resolve/index.cpp @@ -436,20 +436,42 @@ void Resolve_Index_Module_Wildcard(AST::Crate& crate, AST::Module& mod, bool han } ), (Enum, - ASSERT_BUG(sp, e.enum_, "Glob import but enum pointer not set - " << i_data.path); - DEBUG("Glob enum " << i_data.path); - unsigned int idx = 0; - for( const auto& ev : e.enum_->variants() ) { - ::AST::Path p = i_data.path + ev.m_name; - p.bind( ::AST::PathBinding::make_EnumVar({e.enum_, idx}) ); - if( ev.m_data.is_Struct() ) { - _add_item_type ( sp, mod, ev.m_name, i.is_pub, mv$(p), false ); + ASSERT_BUG(sp, e.enum_ || e.hir, "Glob import but enum pointer not set - " << i_data.path); + if( e.enum_ ) + { + DEBUG("Glob enum " << i_data.path << " (AST)"); + unsigned int idx = 0; + for( const auto& ev : e.enum_->variants() ) { + ::AST::Path p = i_data.path + ev.m_name; + p.bind( ::AST::PathBinding::make_EnumVar({e.enum_, idx}) ); + if( ev.m_data.is_Struct() ) { + _add_item_type ( sp, mod, ev.m_name, i.is_pub, mv$(p), false ); + } + else { + _add_item_value( sp, mod, ev.m_name, i.is_pub, mv$(p), false ); + } + + idx += 1; } - else { - _add_item_value( sp, mod, ev.m_name, i.is_pub, mv$(p), false ); + } + else + { + DEBUG("Glob enum " << i_data.path << " (HIR)"); + unsigned int idx = 0; + for( const auto& ev : e.hir->m_variants ) + { + ::AST::Path p = i_data.path + ev.first; + p.bind( ::AST::PathBinding::make_EnumVar({nullptr, idx, e.hir}) ); + + if( ev.second.is_Struct() ) { + _add_item_type ( sp, mod, ev.first, i.is_pub, mv$(p), false ); + } + else { + _add_item_value( sp, mod, ev.first, i.is_pub, mv$(p), false ); + } + + idx += 1; } - - idx += 1; } ) ) diff --git a/src/resolve/use.cpp b/src/resolve/use.cpp index e717f617..7d372fc3 100644 --- a/src/resolve/use.cpp +++ b/src/resolve/use.cpp @@ -96,6 +96,7 @@ void Resolve_Use_Mod(const ::AST::Crate& crate, ::AST::Module& mod, ::AST::Path // TODO: Have Resolve_Use_GetBinding return the actual path use_stmt_data.path.bind( Resolve_Use_GetBinding(span, crate, use_stmt_data.path, parent_modules) ); + DEBUG("'" << use_stmt.name << "' = " << use_stmt_data.path); // - If doing a glob, ensure the item type is valid if( use_stmt.name == "" ) @@ -139,6 +140,7 @@ void Resolve_Use_Mod(const ::AST::Crate& crate, ::AST::Module& mod, ::AST::Path } ASSERT_BUG(span, allow != Lookup::Any, ""); use_stmt_data.alt_binding = Resolve_Use_GetBinding(span, crate, use_stmt_data.path, parent_modules, allow); + DEBUG("- Alt Binding: " << use_stmt_data.alt_binding); } } @@ -491,7 +493,7 @@ namespace { if( it2 == e.m_variants.end() ) { ERROR(span, E0000, "Unable to find variant " << path); } - return ::AST::PathBinding::make_EnumVar({ nullptr, static_cast<unsigned int>(it2 - e.m_variants.begin()) }); + return ::AST::PathBinding::make_EnumVar({ nullptr, static_cast<unsigned int>(it2 - e.m_variants.begin()), &e }); ) ) } @@ -517,7 +519,7 @@ namespace { return ::AST::PathBinding::make_TypeAlias({nullptr}); ), (Enum, - return ::AST::PathBinding::make_Enum({nullptr}); + return ::AST::PathBinding::make_Enum({nullptr, &e}); ), (Struct, return ::AST::PathBinding::make_Struct({nullptr, &e}); |