From b698207664e45b9b0bb9944b5c97084dfc593ed6 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Wed, 25 Mar 2015 11:33:14 +0800 Subject: HACK - Handle the case of core::iter::order importing core::ord, but also defining an 'ord' function --- src/ast/ast.cpp | 14 +++++++++++--- src/ast/ast.hpp | 2 +- src/ast/path.cpp | 2 +- src/convert/resolve.cpp | 3 ++- 4 files changed, 15 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/ast/ast.cpp b/src/ast/ast.cpp index 5559a4d8..988762e6 100644 --- a/src/ast/ast.cpp +++ b/src/ast/ast.cpp @@ -500,9 +500,10 @@ typename ::std::vector >::const_iterator find_named(const ::std::vector< }); } -Module::ItemRef Module::find_item(const ::std::string& needle, bool ignore_private_wildcard) const +Module::ItemRef Module::find_item(const ::std::string& needle, bool allow_leaves, bool ignore_private_wildcard) const { TRACE_FUNCTION_F("needle = " << needle); + // Sub-modules { auto& sms = submods(); @@ -537,7 +538,10 @@ Module::ItemRef Module::find_item(const ::std::string& needle, bool ignore_priva auto& items = this->functions(); auto it = find_named(items, needle); if( it != items.end() ) { - return ItemRef(it->data); + if( allow_leaves ) + return ItemRef(it->data); + else + DEBUG("Skipping static, leaves not allowed"); } } @@ -573,7 +577,11 @@ Module::ItemRef Module::find_item(const ::std::string& needle, bool ignore_priva auto& items = this->statics(); auto it = find_named(items, needle); if( it != items.end() ) { - return ItemRef(it->data); + if( allow_leaves ) { + return ItemRef(it->data); + } + else + DEBUG("Skipping static, leaves not allowed"); } } diff --git a/src/ast/ast.hpp b/src/ast/ast.hpp index f6834071..9a640024 100644 --- a/src/ast/ast.hpp +++ b/src/ast/ast.hpp @@ -637,7 +637,7 @@ public: _(Item, Use) #undef _ }; - ItemRef find_item(const ::std::string& needle, bool ignore_private_wildcard = true) const; + ItemRef find_item(const ::std::string& needle, bool allow_leaves = true, bool ignore_private_wildcard = true) const; ::std::vector& attrs() { return m_attrs; } itemlist_fcn_t& functions() { return m_functions; } diff --git a/src/ast/path.cpp b/src/ast/path.cpp index 83cc98dc..4cf74368 100644 --- a/src/ast/path.cpp +++ b/src/ast/path.cpp @@ -102,7 +102,7 @@ void Path::resolve(const Crate& root_crate) continue ; } - auto item = mod->find_item(node.name()); + auto item = mod->find_item(node.name(), is_last); // Only allow leaf nodes (functions and statics) if this is the last node switch( item.type() ) { // Not found diff --git a/src/convert/resolve.cpp b/src/convert/resolve.cpp index be2bd1bb..66dc1b3a 100644 --- a/src/convert/resolve.cpp +++ b/src/convert/resolve.cpp @@ -232,7 +232,8 @@ void CPathResolver::end_scope() // > Search module-level definitions bool lookup_path_in_module(const AST::Crate& crate, const AST::Module& module, const AST::Path& mod_path, AST::Path& path) { - auto item = module.find_item(path[0].name(), false); + // - Allow leaf nodes if path is a single node, don't skip private wildcard imports + auto item = module.find_item(path[0].name(), (path.size() == 1), false); switch(item.type()) { case AST::Module::ItemRef::ITEM_none: -- cgit v1.2.3