summaryrefslogtreecommitdiff
path: root/src/ast/path.cpp
diff options
context:
space:
mode:
authorJohn Hodge <tpg@mutabah.net>2015-03-21 15:41:00 +0800
committerJohn Hodge <tpg@mutabah.net>2015-03-21 15:41:00 +0800
commit75205189d5e33a33193fa76a29f7518a9797299d (patch)
treee4ca2323a7bafbe53da289bb20b6ef24508ea387 /src/ast/path.cpp
parent6411b7c7d220ae9af5e54d0fdae66e4e44faf01f (diff)
downloadmrust-75205189d5e33a33193fa76a29f7518a9797299d.tar.gz
Move wildcard use to Path::resolve, add 'bool' type
Diffstat (limited to 'src/ast/path.cpp')
-rw-r--r--src/ast/path.cpp65
1 files changed, 52 insertions, 13 deletions
diff --git a/src/ast/path.cpp b/src/ast/path.cpp
index 4f83ae34..338a0b15 100644
--- a/src/ast/path.cpp
+++ b/src/ast/path.cpp
@@ -56,9 +56,10 @@ typename ::std::vector<Item<T> >::const_iterator find_named(const ::std::vector<
});
}
+/// Resolve a path into a canonical form, and bind it to the target value
void Path::resolve(const Crate& root_crate)
{
- DEBUG("*this = " << *this);
+ TRACE_FUNCTION_F("*this = "<< *this);
if(m_class != ABSOLUTE)
throw ParseError::BugCheck("Calling Path::resolve on non-absolute path");
DEBUG("m_crate = '" << m_crate << "'");
@@ -102,18 +103,7 @@ void Path::resolve(const Crate& root_crate)
continue;
}
}
-
- // Start searching for:
- // - Re-exports
- {
- auto& imp = mod->imports();
- auto it = find_named(imp, node.name());
- if( it != imp.end() )
- {
- DEBUG("Re-exported path " << it->data);
- throw ParseError::Todo("Path::resolve() re-export");
- }
- }
+
// Type Aliases
{
auto& items = mod->type_aliases();
@@ -232,6 +222,55 @@ void Path::resolve(const Crate& root_crate)
}
}
+ // - Re-exports
+ // > Comes last, as it's a potentially expensive operation
+ {
+ for( const auto& imp : mod->imports() )
+ {
+ if( !imp.is_pub )
+ {
+ // not public, ignore
+ }
+ else if( imp.name == node.name() )
+ {
+ // replace nodes 0:i with the source path
+ DEBUG("Re-exported path " << imp.data);
+ AST::Path newpath = imp.data;
+ for( unsigned int j = i+1; j < m_nodes.size(); j ++ )
+ {
+ newpath.m_nodes.push_back( m_nodes[j] );
+ }
+ DEBUG("- newpath = " << newpath);
+ // TODO: This should check for recursion somehow
+ newpath.resolve(root_crate);
+
+ *this = newpath;
+ DEBUG("Alias resolved, *this = " << *this);
+ return ;
+ }
+ else if( imp.name == "" )
+ {
+ // Loop avoidance, don't check this
+ if( &imp.data == this )
+ continue ;
+
+ if( !imp.data.is_bound() )
+ {
+ // not yet bound, so run resolution (recursion)
+ DEBUG("Recursively resolving pub wildcard use " << imp.data);
+ //imp.data.resolve(root_crate);
+ throw ParseError::Todo("Path::resolve() wildcard re-export call resolve");
+ }
+
+ throw ParseError::Todo("Path::resolve() wildcard re-export");
+ }
+ else
+ {
+ // Can't match, ignore
+ }
+ }
+ }
+
throw ParseError::Generic("Unable to find component '" + node.name() + "'");
}