diff options
-rw-r--r-- | src/resolve/absolute.cpp | 73 | ||||
-rw-r--r-- | src/resolve/index.cpp | 2 | ||||
-rw-r--r-- | src/resolve/use.cpp | 25 |
3 files changed, 59 insertions, 41 deletions
diff --git a/src/resolve/absolute.cpp b/src/resolve/absolute.cpp index cb02914a..76b4160f 100644 --- a/src/resolve/absolute.cpp +++ b/src/resolve/absolute.cpp @@ -960,6 +960,7 @@ void Resolve_Absolute_Path_BindAbsolute(Context& context, const Span& sp, Contex return ; } + const ::AST::Module* mod = &context.m_crate.m_root_module; for(unsigned int i = 0; i < path_abs.nodes.size() - 1; i ++ ) { @@ -1002,6 +1003,11 @@ void Resolve_Absolute_Path_BindAbsolute(Context& context, const Span& sp, Contex (Trait, assert( e.trait_ || e.hir ); auto trait_path = ::AST::Path(name_ref.path); + // HACK! If this was an import, recurse on it to fix paths. (Ideally, all index entries should have the canonical path, but don't currently) + if( name_ref.is_import ) { + auto lm = Context::LookupMode::Type; + Resolve_Absolute_Path_BindAbsolute(context, sp, lm, trait_path); + } if( !n.args().is_empty() ) { trait_path.nodes().back().args() = mv$(n.args()); } @@ -1714,6 +1720,31 @@ void Resolve_Absolute_ImplItems(Context& item_context, ::AST::NamedList< ::AST: } } +void Resolve_Absolute_Function(Context& item_context, ::AST::Function& fcn) +{ + TRACE_FUNCTION_F(""); + item_context.push( fcn.params(), GenericSlot::Level::Method ); + Resolve_Absolute_Generic(item_context, fcn.params()); + + Resolve_Absolute_Type( item_context, fcn.rettype() ); + for(auto& arg : fcn.args()) + Resolve_Absolute_Type( item_context, arg.second ); + + { + auto _h = item_context.enter_rootblock(); + item_context.push_block(); + for(auto& arg : fcn.args()) { + Resolve_Absolute_Pattern( item_context, false, arg.first ); + } + + Resolve_Absolute_Expr( item_context, fcn.code() ); + + item_context.pop_block(); + } + + item_context.pop( fcn.params() ); +} + void Resolve_Absolute_ImplItems(Context& item_context, ::std::vector< ::AST::Impl::ImplItem >& items) { TRACE_FUNCTION_F(""); @@ -1740,26 +1771,7 @@ void Resolve_Absolute_ImplItems(Context& item_context, ::std::vector< ::AST::Im ), (Function, DEBUG("Function - " << i.name); - item_context.push( e.params(), GenericSlot::Level::Method ); - Resolve_Absolute_Generic(item_context, e.params()); - - Resolve_Absolute_Type( item_context, e.rettype() ); - for(auto& arg : e.args()) - Resolve_Absolute_Type( item_context, arg.second ); - - { - auto _h = item_context.enter_rootblock(); - item_context.push_block(); - for(auto& arg : e.args()) { - Resolve_Absolute_Pattern( item_context, false, arg.first ); - } - - Resolve_Absolute_Expr( item_context, e.code() ); - - item_context.pop_block(); - } - - item_context.pop( e.params() ); + Resolve_Absolute_Function(item_context, e); ), (Static, DEBUG("Static - " << i.name); @@ -1867,26 +1879,7 @@ void Resolve_Absolute_Mod( Context item_context, ::AST::Module& mod ) ), (Function, DEBUG("Function - " << i.name); - item_context.push( e.params(), GenericSlot::Level::Method ); - Resolve_Absolute_Generic(item_context, e.params()); - - Resolve_Absolute_Type( item_context, e.rettype() ); - for(auto& arg : e.args()) - Resolve_Absolute_Type( item_context, arg.second ); - - { - auto _h = item_context.enter_rootblock(); - item_context.push_block(); - for(auto& arg : e.args()) { - Resolve_Absolute_Pattern( item_context, false, arg.first ); - } - - Resolve_Absolute_Expr( item_context, e.code() ); - - item_context.pop_block(); - } - - item_context.pop( e.params() ); + Resolve_Absolute_Function(item_context, e); ), (Static, DEBUG("Static - " << i.name); diff --git a/src/resolve/index.cpp b/src/resolve/index.cpp index 4e1766c6..0ff94db4 100644 --- a/src/resolve/index.cpp +++ b/src/resolve/index.cpp @@ -144,6 +144,8 @@ void Resolve_Index_Module_Base(const AST::Crate& crate, AST::Module& mod) { if( i.name != "" ) { + // TODO: Ensure that the path is canonical? + const auto& sp = i.data.sp; struct H { static void handle_pb(const Span& sp, AST::Module& mod, const AST::Named<AST::UseStmt>& i, const AST::PathBinding& pb, bool allow_collide) diff --git a/src/resolve/use.cpp b/src/resolve/use.cpp index a5fcec90..6f2db9d8 100644 --- a/src/resolve/use.cpp +++ b/src/resolve/use.cpp @@ -1,5 +1,9 @@ /* - * Absolutise and check all 'use' statements + * MRustC - Rust Compiler + * - By John Hodge (Mutabah/thePowersGang) + * + * resolve/use.cpp + * - Absolutise and check all 'use' statements */ #include <main_bindings.hpp> #include <ast/crate.hpp> @@ -25,6 +29,7 @@ void Resolve_Use(::AST::Crate& crate) Resolve_Use_Mod(crate, crate.m_root_module, ::AST::Path("", {})); } +// - Convert self::/super:: paths into non-canonical absolute forms ::AST::Path Resolve_Use_AbsolutisePath(const Span& span, const ::AST::Path& base_path, ::AST::Path path) { TU_MATCH(::AST::Path::Class, (path.m_class), (e), @@ -85,6 +90,7 @@ void Resolve_Use_Mod(const ::AST::Crate& crate, ::AST::Module& mod, ::AST::Path if( !use_stmt.data.path.m_class.is_Absolute() ) BUG(span, "Use path is not absolute after absolutisation"); + // 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) ); // - If doing a glob, ensure the item type is valid @@ -231,6 +237,7 @@ void Resolve_Use_Mod(const ::AST::Crate& crate, ::AST::Module& mod, ::AST::Path } } + // If the desired item is an anon module (starts with #) then parse and index if( des_item_name.size() > 0 && des_item_name[0] == '#' ) { unsigned int idx = 0; if( ::std::sscanf(des_item_name.c_str(), "#%u", &idx) != 1 ) { @@ -242,6 +249,7 @@ void Resolve_Use_Mod(const ::AST::Crate& crate, ::AST::Module& mod, ::AST::Path return ::AST::PathBinding::make_Module({mod.anon_mods()[idx]}); } + // Seach for the name defined in the module. for( const auto& item : mod.items() ) { if( item.data.is_None() ) @@ -304,6 +312,7 @@ void Resolve_Use_Mod(const ::AST::Crate& crate, ::AST::Module& mod, ::AST::Path if( imp.data.path.binding().is_Unbound() ) { DEBUG(" > Needs resolve"); // TODO: Handle possibility of recursion + //out_path = imp.data.path; return Resolve_Use_GetBinding(sp2, crate, Resolve_Use_AbsolutisePath(sp2, mod.path(), imp.data.path), parent_modules, allow); } else { @@ -332,6 +341,7 @@ void Resolve_Use_Mod(const ::AST::Crate& crate, ::AST::Module& mod, ::AST::Path break; } } + //out_path = imp.data.path; return imp.data.path.binding().clone(); } } @@ -346,6 +356,9 @@ void Resolve_Use_Mod(const ::AST::Crate& crate, ::AST::Module& mod, ::AST::Path binding_ = Resolve_Use_GetBinding(sp2, crate, Resolve_Use_AbsolutisePath(sp2, mod.path(), imp.data.path), parent_modules); binding = &binding_; } + else { + //out_path = imp.data.path; + } TU_MATCH_DEF(::AST::PathBinding, (*binding), (e), ( @@ -489,21 +502,30 @@ void Resolve_Use_Mod(const ::AST::Crate& crate, ::AST::Module& mod, ::AST::Path ::AST::PathBinding Resolve_Use_GetBinding(const Span& span, const ::AST::Crate& crate, const ::AST::Path& path, slice< const ::AST::Module* > parent_modules, Lookup allow) { + //::AST::Path rv; + + // If the path is directly referring to an external crate - call __ext if( path.m_class.is_Absolute() && path.m_class.as_Absolute().crate != "" ) { const auto& path_abs = path.m_class.as_Absolute(); return Resolve_Use_GetBinding__ext(span, crate, path, crate.m_extern_crates.at( path_abs.crate ), 0, allow); } + const AST::Module* mod = &crate.m_root_module; const auto& nodes = path.nodes(); for( unsigned int i = 0; i < nodes.size()-1; i ++ ) { + // TODO: If this came from an import, return the real path? + + //rv = Resolve_Use_CanoniseAndBind_Mod(span, crate, *mod, mv$(rv), nodes[i].name(), parent_modules, Lookup::Type); + //const auto& b = rv.binding(); auto b = Resolve_Use_GetBinding_Mod(span, crate, *mod, nodes[i].name(), parent_modules, Lookup::Type); TU_MATCH_DEF(::AST::PathBinding, (b), (e), ( ERROR(span, E0000, "Unexpected item type in import"); ), (Crate, + // TODO: Mangle the original path (or return a new path somehow) return Resolve_Use_GetBinding__ext(span, crate, path, *e.crate_, i+1, allow); ), (Enum, @@ -533,6 +555,7 @@ void Resolve_Use_Mod(const ::AST::Crate& crate, ::AST::Module& mod, ::AST::Path if( !e.module_ ) { assert(e.hir); + // TODO: Mangle the original path (or return a new path somehow) return Resolve_Use_GetBinding__ext(span, crate, path, *e.hir, i+1, allow); } mod = e.module_; |