summaryrefslogtreecommitdiff
path: root/src/convert/resolve.cpp
diff options
context:
space:
mode:
authorJohn Hodge (sonata) <tpg@mutabah.net>2015-01-18 19:28:14 +0800
committerJohn Hodge (sonata) <tpg@mutabah.net>2015-01-18 19:28:14 +0800
commitdef96a573903b5fcb95e8a8dffb94a3a9a7f8501 (patch)
treea45104be0bc74144d5979090950647ad27f855d9 /src/convert/resolve.cpp
parentc3ca711c49760e7f9467afd0811a0427c67e0dc1 (diff)
downloadmrust-def96a573903b5fcb95e8a8dffb94a3a9a7f8501.tar.gz
Most types iterating well, special case for Self type
Diffstat (limited to 'src/convert/resolve.cpp')
-rw-r--r--src/convert/resolve.cpp56
1 files changed, 45 insertions, 11 deletions
diff --git a/src/convert/resolve.cpp b/src/convert/resolve.cpp
index 2e961f1f..5c71cd8f 100644
--- a/src/convert/resolve.cpp
+++ b/src/convert/resolve.cpp
@@ -151,6 +151,7 @@ void CPathResolver::end_scope()
void CPathResolver::handle_path(AST::Path& path, CASTIterator::PathMode mode)
{
+ INDENT();
DEBUG("path = " << path);
// Handle generic components of the path
@@ -179,6 +180,7 @@ void CPathResolver::handle_path(AST::Path& path, CASTIterator::PathMode mode)
// If there's a single node, and we're in expresion mode, look for a variable
// Otherwise, search for a type
bool is_trivial_path = path.size() == 1 && path[0].args().size() == 0;
+
LocalItem::Type search_type = (is_trivial_path && mode == MODE_EXPR ? LocalItem::VAR : LocalItem::TYPE);
auto local = lookup_local( search_type, path[0].name() );
if( local.is_some() )
@@ -230,14 +232,20 @@ void CPathResolver::handle_path(AST::Path& path, CASTIterator::PathMode mode)
return ;
}
}
- for( const auto& item_fcn : m_module->functions() )
+ for( const auto& import : m_module->imports() )
{
- if( item_fcn.name == path[0].name() ) {
- path = m_module_path + path;
+ const ::std::string& bind_name = import.name;
+ const AST::Path& bind_path = import.data;
+ if( bind_name == "" ) {
+ }
+ else if( bind_name == path[0].name() ) {
+ path = AST::Path::add_tailing(bind_path, path);
path.resolve( m_crate );
return ;
}
}
+
+ // Types
for( const auto& item : m_module->structs() )
{
if( item.name == path[0].name() ) {
@@ -246,7 +254,7 @@ void CPathResolver::handle_path(AST::Path& path, CASTIterator::PathMode mode)
return ;
}
}
- for( const auto& item : m_module->statics() )
+ for( const auto& item : m_module->enums() )
{
if( item.name == path[0].name() ) {
path = m_module_path + path;
@@ -254,14 +262,28 @@ void CPathResolver::handle_path(AST::Path& path, CASTIterator::PathMode mode)
return ;
}
}
- for( const auto& import : m_module->imports() )
+ for( const auto& item : m_module->traits() )
{
- const ::std::string& bind_name = import.name;
- const AST::Path& bind_path = import.data;
- if( bind_name == "" ) {
+ if( item.name == path[0].name() ) {
+ path = m_module_path + path;
+ path.resolve( m_crate );
+ return ;
}
- else if( bind_name == path[0].name() ) {
- path = AST::Path::add_tailing(bind_path, path);
+ }
+
+ // Values / Functions
+ for( const auto& item_fcn : m_module->functions() )
+ {
+ if( item_fcn.name == path[0].name() ) {
+ path = m_module_path + path;
+ path.resolve( m_crate );
+ return ;
+ }
+ }
+ for( const auto& item : m_module->statics() )
+ {
+ if( item.name == path[0].name() ) {
+ path = m_module_path + path;
path.resolve( m_crate );
return ;
}
@@ -272,13 +294,22 @@ void CPathResolver::handle_path(AST::Path& path, CASTIterator::PathMode mode)
if( mode != MODE_BIND )
throw ParseError::Generic("Name resolution failed");
}
+
+ UNINDENT();
}
void CPathResolver::handle_type(TypeRef& type)
{
if( type.is_path() && type.path().is_relative() && type.path().size() == 1 )
{
const auto& name = type.path()[0].name();
- if( lookup_local(LocalItem::TYPE, name).is_some() )
+
+ if( name == "Self" )
+ {
+ // TODO: Handle "Self" correctly
+ // THIS IS WRONG! (well, I think)
+ type = TypeRef(TypeRef::TagArg(), "Self");
+ }
+ else if( lookup_local(LocalItem::TYPE, name).is_some() )
{
type = TypeRef(TypeRef::TagArg(), name);
}
@@ -433,6 +464,7 @@ void SetCrateName_Mod(::std::string name, AST::Module& mod)
// - Convert all paths into absolute paths (or local variable references)
void ResolvePaths(AST::Crate& crate)
{
+ DEBUG(" >>>");
// Pre-process external crates to tag all paths
for(auto& ec : crate.extern_crates())
{
@@ -441,8 +473,10 @@ void ResolvePaths(AST::Crate& crate)
// Handle 'use' statements in an initial parss
ResolvePaths_HandleModule_Use(crate, AST::Path(AST::Path::TagAbsolute()), crate.root_module());
+ DEBUG(" ---");
// Then do path resolution on all other items
CPathResolver pr(crate);
pr.handle_module(AST::Path(AST::Path::TagAbsolute()), crate.root_module());
+ DEBUG(" <<<");
}