From 4455197bebd63090768c9eee8f53cf225e44b64e Mon Sep 17 00:00:00 2001 From: John Hodge Date: Wed, 31 Aug 2016 15:10:46 +0800 Subject: Resolve - Hack in support for multiple bindings for one use --- src/resolve/index.cpp | 85 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 50 insertions(+), 35 deletions(-) (limited to 'src/resolve/index.cpp') diff --git a/src/resolve/index.cpp b/src/resolve/index.cpp index a8f92027..7ae6cde1 100644 --- a/src/resolve/index.cpp +++ b/src/resolve/index.cpp @@ -133,42 +133,57 @@ void Resolve_Index_Module_Base(const AST::Crate& crate, AST::Module& mod) if( i.name != "" ) { const auto& sp = i.data.sp; - const auto& b = i.data.path.binding(); - TU_MATCH(::AST::PathBinding, (b), (e), - (Unbound, - BUG(sp, "Import left unbound ("<m_data.is_Tuple() ) { - _add_item_value(sp, mod, i.name, i.is_pub, i.data.path); + struct H { + static void handle_pb(const Span& sp, AST::Module& mod, const AST::Named& i, const AST::PathBinding& pb, bool allow_collide) + { + TU_MATCH(::AST::PathBinding, (pb), (e), + (Unbound, + ), + (Variable, + BUG(sp, "Import was bound to variable"); + ), + (TypeParameter, + BUG(sp, "Import was bound to type parameter"); + ), + (TraitMethod, + BUG(sp, "Import was bound to trait method"); + ), + (StructMethod, + BUG(sp, "Import was bound to struct method"); + ), + + (Crate , _add_item(sp, mod, IndexName::Namespace, i.name, i.is_pub, i.data.path, !allow_collide); ), + (Module, _add_item(sp, mod, IndexName::Namespace, i.name, i.is_pub, i.data.path, !allow_collide); ), + (Enum, _add_item_type(sp, mod, i.name, i.is_pub, i.data.path, !allow_collide); ), + (Trait, _add_item_type(sp, mod, i.name, i.is_pub, i.data.path, !allow_collide); ), + (TypeAlias,_add_item_type(sp, mod, i.name, i.is_pub, i.data.path, !allow_collide); ), + + (Struct, + _add_item_type(sp, mod, i.name, i.is_pub, i.data.path, !allow_collide); + // TODO: Items from extern crates don't populate e.struct_ correctly + // - If the struct is a tuple-like struct, it presents in the value namespace + if( e.struct_ && e.struct_->m_data.is_Tuple() ) { + _add_item_value(sp, mod, i.name, i.is_pub, i.data.path, !allow_collide); + } + ), + (Static , _add_item_value(sp, mod, i.name, i.is_pub, i.data.path, !allow_collide); ), + (Function, _add_item_value(sp, mod, i.name, i.is_pub, i.data.path, !allow_collide); ), + (EnumVar , _add_item_value(sp, mod, i.name, i.is_pub, i.data.path, !allow_collide); ) + ) } - ), - (Static , _add_item_value(sp, mod, i.name, i.is_pub, i.data.path); ), - (Function, _add_item_value(sp, mod, i.name, i.is_pub, i.data.path); ), - (EnumVar , _add_item_value(sp, mod, i.name, i.is_pub, i.data.path); ) - ) + }; + if( i.data.path.binding().is_Unbound() ) { + BUG(sp, "Import left unbound ("<