summaryrefslogtreecommitdiff
path: root/src/convert/resolve.cpp
diff options
context:
space:
mode:
authorJohn Hodge (sonata) <tpg@mutabah.net>2015-01-12 19:30:26 +0800
committerJohn Hodge (sonata) <tpg@mutabah.net>2015-01-12 19:30:26 +0800
commit4af0826c332c52af0796a2fe30074bbd6aba664b (patch)
treefae67e36abed7361016b3088315e0e917667b212 /src/convert/resolve.cpp
parent645ecea1a60e913ada6bdc8665d098d4b00a5f01 (diff)
downloadmrust-4af0826c332c52af0796a2fe30074bbd6aba664b.tar.gz
Path resolution working in one function (types still to come, need AST rep)
Diffstat (limited to 'src/convert/resolve.cpp')
-rw-r--r--src/convert/resolve.cpp38
1 files changed, 21 insertions, 17 deletions
diff --git a/src/convert/resolve.cpp b/src/convert/resolve.cpp
index ee906150..53a1edaf 100644
--- a/src/convert/resolve.cpp
+++ b/src/convert/resolve.cpp
@@ -18,7 +18,7 @@ class CPathResolver
// TODO: Maintain a stack of variable scopes
public:
- CPathResolver(const AST::Crate& crate, const AST::Module& mod);
+ CPathResolver(const AST::Crate& crate, const AST::Module& mod, AST::Path module_path);
enum ResolvePathMode {
MODE_EXPR, // Variables allowed
@@ -85,9 +85,10 @@ public:
}
};
-CPathResolver::CPathResolver(const AST::Crate& crate, const AST::Module& mod):
+CPathResolver::CPathResolver(const AST::Crate& crate, const AST::Module& mod, AST::Path module_path):
m_crate(crate),
- m_module(mod)
+ m_module(mod),
+ m_module_path( ::std::move(module_path) )
{
}
@@ -159,6 +160,14 @@ void CPathResolver::resolve_path(AST::Path& path, ResolvePathMode mode) const
return ;
}
}
+ for( const auto& item : m_module.statics() )
+ {
+ if( item.name == path[0].name() ) {
+ path = m_module_path + path;
+ path.resolve( m_crate );
+ return ;
+ }
+ }
for( const auto& import : m_module.imports() )
{
const ::std::string& bind_name = import.name;
@@ -244,28 +253,22 @@ void CPathResolver::handle_pattern(AST::Pattern& pat)
void CPathResolver::handle_function(AST::Function& fcn)
{
CResolvePaths_NodeVisitor node_visitor(*this);
-
- for( auto& arg : fcn.args() )
- m_locals.push_back(arg.first);
-
- fcn.code().visit_nodes( node_visitor );
+ DEBUG("Return type");
resolve_type(fcn.rettype());
-
+ DEBUG("Args");
for( auto& arg : fcn.args() )
resolve_type(arg.second);
-
+
+ DEBUG("Code");
+ for( auto& arg : fcn.args() )
+ m_locals.push_back(arg.first);
+ fcn.code().visit_nodes( node_visitor );
pop_scope();
if( m_locals.size() != 0 )
throw ParseError::BugCheck("m_locals.size() != 0");
}
-void ResolvePaths_HandleFunction(const AST::Crate& crate, const AST::Module& mod, AST::Function& fcn)
-{
- CPathResolver pr(crate, mod);
- pr.handle_function(fcn);
-}
-
void ResolvePaths_HandleModule_Use(const AST::Crate& crate, const AST::Path& modpath, AST::Module& mod)
{
DEBUG("modpath = " << modpath);
@@ -340,7 +343,8 @@ void ResolvePaths_HandleModule(const AST::Crate& crate, const AST::Path& modpath
{
for( auto& fcn : mod.functions() )
{
- ResolvePaths_HandleFunction(crate, mod, fcn.data);
+ CPathResolver pr(crate, mod, modpath);
+ pr.handle_function(fcn.data);
}
for( auto& submod : mod.submods() )