diff options
author | John Hodge <tpg@mutabah.net> | 2016-10-30 18:34:38 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2016-10-30 18:34:38 +0800 |
commit | e87f3ee6f2c8bbbfd1e18285528dfa305479b2ee (patch) | |
tree | 186e4c51de05194188a62d75e0e44e1a6007a0e2 /src/resolve | |
parent | 649f9f98efe3f1b138c34f3762a5feba9dde457c (diff) | |
download | mrust-e87f3ee6f2c8bbbfd1e18285528dfa305479b2ee.tar.gz |
HIR+Resolve - Refactor handling of enum variant imports
Diffstat (limited to 'src/resolve')
-rw-r--r-- | src/resolve/absolute.cpp | 38 | ||||
-rw-r--r-- | src/resolve/index.cpp | 14 | ||||
-rw-r--r-- | src/resolve/use.cpp | 20 |
3 files changed, 32 insertions, 40 deletions
diff --git a/src/resolve/absolute.cpp b/src/resolve/absolute.cpp index f9d1b5ea..da3a5619 100644 --- a/src/resolve/absolute.cpp +++ b/src/resolve/absolute.cpp @@ -798,8 +798,8 @@ namespace { TU_MATCH(::HIR::TypeItem, (it->second->ent), (e), (Import, // - Update path then restart - auto newpath = AST::Path(e.m_crate_name, {}); - for(const auto& n : e.m_components) + auto newpath = AST::Path(e.path.m_crate_name, {}); + for(const auto& n : e.path.m_components) newpath.nodes().push_back( AST::PathNode(n) ); for(unsigned int j = i + 1; j < path.nodes().size(); j ++) newpath.nodes().push_back( mv$(path.nodes()[j]) ); @@ -904,15 +904,11 @@ namespace { { auto v = hmod->m_mod_items.find(name); if( v != hmod->m_mod_items.end() ) { - const auto& ti = v->second->ent; - if( ti.is_Import() ) { - DEBUG("= Import " << ti.as_Import()); - Resolve_Absolute_Path_BindAbsolute__hir_from_import(context, sp, false, path, ti.as_Import()); - return ; - } TU_MATCH(::HIR::TypeItem, (v->second->ent), (e), (Import, - throw ""; + DEBUG("= Import " << e.path); + Resolve_Absolute_Path_BindAbsolute__hir_from_import(context, sp, false, path, e.path); + return ; ), (Trait, path.bind( ::AST::PathBinding::make_Trait({nullptr, &e}) ); @@ -941,13 +937,13 @@ namespace { { auto v = hmod->m_mod_items.find(name); if( v != hmod->m_mod_items.end() ) { - if( v->second->ent.is_Import() ) { - Resolve_Absolute_Path_BindAbsolute__hir_from_import(context, sp, false, path, v->second->ent.as_Import()); - TODO(sp, "Imports in HIR mod items"); - } TU_MATCH_DEF(::HIR::TypeItem, (v->second->ent), (e), ( ), + (Import, + Resolve_Absolute_Path_BindAbsolute__hir_from_import(context, sp, false, path, e.path); + TODO(sp, "Imports in HIR mod items - " << e.path); + ), (Struct, // Bind and update path path.bind( ::AST::PathBinding::make_Struct({nullptr, &e}) ); @@ -960,12 +956,12 @@ namespace { { auto v = hmod->m_value_items.find(name); if( v != hmod->m_value_items.end() ) { - if( v->second->ent.is_Import() ) { - TODO(sp, "Imports in HIR val items - " << v->second->ent.as_Import()); - } TU_MATCH_DEF(::HIR::ValueItem, (v->second->ent), (e), ( ), + (Import, + TODO(sp, "Imports in HIR val items - " << e.path); + ), (Constant, // Bind and update path path.bind( ::AST::PathBinding::make_Static({nullptr, nullptr}) ); @@ -981,14 +977,10 @@ namespace { { auto v = hmod->m_value_items.find(name); if( v != hmod->m_value_items.end() ) { - if( v->second->ent.is_Import() ) { - Resolve_Absolute_Path_BindAbsolute__hir_from_import(context, sp, true, path, v->second->ent.as_Import()); + TU_MATCH(::HIR::ValueItem, (v->second->ent), (e), + (Import, + Resolve_Absolute_Path_BindAbsolute__hir_from_import(context, sp, true, path, e.path); return ; - } - TU_MATCH_DEF(::HIR::ValueItem, (v->second->ent), (e), - ( - // TODO: Handle other values types - TODO(sp, "Bind item type " << v->second->ent.tag_str()); ), (Function, path.bind( ::AST::PathBinding::make_Function({nullptr/*, &e*/}) ); diff --git a/src/resolve/index.cpp b/src/resolve/index.cpp index 93e5c742..09d3909b 100644 --- a/src/resolve/index.cpp +++ b/src/resolve/index.cpp @@ -268,7 +268,7 @@ void Resolve_Index_Module_Wildcard__glob_in_hir_mod(const Span& sp, const AST::C if( ve.is_public ) { AST::Path p; if( ve.ent.is_Import() ) { - p = hir_to_ast( ve.ent.as_Import() ); + p = hir_to_ast( ve.ent.as_Import().path ); } else { p = path + it.first; @@ -302,7 +302,7 @@ void Resolve_Index_Module_Wildcard__glob_in_hir_mod(const Span& sp, const AST::C AST::Path p; const auto* vep = &ve.ent; if( ve.ent.is_Import() ) { - const auto& spath = ve.ent.as_Import(); + const auto& spath = ve.ent.as_Import().path; p = hir_to_ast( spath ); ASSERT_BUG(sp, crate.m_extern_crates.count(spath.m_crate_name) == 1, "Crate " << spath.m_crate_name << " is not loaded"); @@ -526,15 +526,15 @@ void Resolve_Index_Module_Normalise_Path_ext(const ::AST::Crate& crate, const Sp const auto* item_ptr = &it->second->ent; if( item_ptr->is_Import() ) { const auto& e = item_ptr->as_Import(); - const auto& ec = crate.m_extern_crates.at( e.m_crate_name ); - item_ptr = &ec.m_hir->get_typeitem_by_path(sp, e, true); // ignore_crate_name=true + const auto& ec = crate.m_extern_crates.at( e.path.m_crate_name ); + item_ptr = &ec.m_hir->get_typeitem_by_path(sp, e.path, true); // ignore_crate_name=true } TU_MATCH_DEF(::HIR::TypeItem, (*item_ptr), (e), ( BUG(sp, "Path " << path << " pointed to non-module in component " << i); ), (Import, - BUG(sp, "Recursive import in " << path << " - " << it->second->ent.as_Import() << " -> " << e); + BUG(sp, "Recursive import in " << path << " - " << it->second->ent.as_Import().path << " -> " << e.path); ), (Enum, if( i != info.nodes.size() - 2 ) { @@ -560,7 +560,7 @@ void Resolve_Index_Module_Normalise_Path_ext(const ::AST::Crate& crate, const Sp TU_IFLET( ::HIR::TypeItem, it_m->second->ent, Import, e, // Replace the path with this path (maintaining binding) auto binding = path.binding().clone(); - path = hir_to_ast(e); + path = hir_to_ast(e.path); path.bind( mv$(binding) ); ) return ; @@ -573,7 +573,7 @@ void Resolve_Index_Module_Normalise_Path_ext(const ::AST::Crate& crate, const Sp TU_IFLET( ::HIR::ValueItem, it_v->second->ent, Import, e, // Replace the path with this path (maintaining binding) auto binding = path.binding().clone(); - path = hir_to_ast(e); + path = hir_to_ast(e.path); path.bind( mv$(binding) ); ) return ; diff --git a/src/resolve/use.cpp b/src/resolve/use.cpp index 7063e7f0..b5afcbc3 100644 --- a/src/resolve/use.cpp +++ b/src/resolve/use.cpp @@ -471,10 +471,10 @@ namespace { TU_IFLET( ::HIR::TypeItem, (it->second->ent), Module, mod, hmod = &mod; ) - else TU_IFLET( ::HIR::TypeItem, (it->second->ent), Import, import_path, - hmod = get_hir_mod_by_path(sp, crate, import_path); + else TU_IFLET( ::HIR::TypeItem, (it->second->ent), Import, import, + hmod = get_hir_mod_by_path(sp, crate, import.path); if( !hmod ) - BUG(sp, ""); + BUG(sp, "Import in module position didn't resolve as a module - " << import.path); ) else TU_IFLET( ::HIR::TypeItem, (it->second->ent), Enum, enm, if( &node == &path.m_components.back() ) { @@ -519,7 +519,7 @@ namespace { ), (Import, bool is_enum = false; - auto ptr = get_hir_modenum_by_path(span, crate, e, is_enum); + auto ptr = get_hir_modenum_by_path(span, crate, e.path, is_enum); if( !ptr ) BUG(span, "Path component " << nodes[i].name() << " pointed to non-module (" << path << ")"); if( is_enum ) { @@ -566,12 +566,12 @@ namespace { if( item_ptr->is_Import() ) { const auto& e = item_ptr->as_Import(); // This doesn't need to recurse - it can just do a single layer (as no Import should refer to another) - const auto& ec = crate.m_extern_crates.at( e.m_crate_name ); - item_ptr = &ec.m_hir->get_typeitem_by_path(span, e, true); // ignore_crate_name=true + const auto& ec = crate.m_extern_crates.at( e.path.m_crate_name ); + item_ptr = &ec.m_hir->get_typeitem_by_path(span, e.path, true); // ignore_crate_name=true } TU_MATCHA( (*item_ptr), (e), (Import, - BUG(span, "Recursive import in " << path << " - " << it->second->ent.as_Import() << " -> " << e); + BUG(span, "Recursive import in " << path << " - " << it->second->ent.as_Import().path << " -> " << e.path); ), (Module, return ::AST::PathBinding::make_Module({nullptr, &e}); @@ -599,12 +599,12 @@ namespace { if( item_ptr->is_Import() ) { const auto& e = item_ptr->as_Import(); // This doesn't need to recurse - it can just do a single layer (as no Import should refer to another) - const auto& ec = crate.m_extern_crates.at( e.m_crate_name ); - item_ptr = &ec.m_hir->get_valitem_by_path(span, e, true); // ignore_crate_name=true + const auto& ec = crate.m_extern_crates.at( e.path.m_crate_name ); + item_ptr = &ec.m_hir->get_valitem_by_path(span, e.path, true); // ignore_crate_name=true } TU_MATCHA( (*item_ptr), (e), (Import, - BUG(span, "Recursive import in " << path << " - " << it2->second->ent.as_Import() << " -> " << e); + BUG(span, "Recursive import in " << path << " - " << it2->second->ent.as_Import().path << " -> " << e.path); ), (Constant, return ::AST::PathBinding::make_Static({ nullptr }); |