summaryrefslogtreecommitdiff
path: root/src/convert/resolve.cpp
diff options
context:
space:
mode:
authorJohn Hodge (sonata) <tpg@mutabah.net>2015-01-05 08:43:45 +0800
committerJohn Hodge (sonata) <tpg@mutabah.net>2015-01-05 08:43:45 +0800
commiteac8e3d68b9ca67f97c1f9aedef01e8e93cde323 (patch)
tree47fc3f527b7f3d03718277347e13c3ee4bb779d2 /src/convert/resolve.cpp
parent4a9e7dc0e4976c03a8dbceeacc5e474509b237f9 (diff)
downloadmrust-eac8e3d68b9ca67f97c1f9aedef01e8e93cde323.tar.gz
Implementing path lookup (bottom level of resolve)
Diffstat (limited to 'src/convert/resolve.cpp')
-rw-r--r--src/convert/resolve.cpp24
1 files changed, 21 insertions, 3 deletions
diff --git a/src/convert/resolve.cpp b/src/convert/resolve.cpp
index b32b10a5..6ea3fcc6 100644
--- a/src/convert/resolve.cpp
+++ b/src/convert/resolve.cpp
@@ -248,21 +248,35 @@ void ResolvePaths_HandleFunction(const AST::Crate& crate, const AST::Module& mod
pr.handle_function(fcn);
}
-void ResolvePaths_HandleModule(const AST::Crate& crate, const AST::Path& modpath, AST::Module& mod)
+void ResolvePaths_HandleModule_Use(const AST::Crate& crate, const AST::Path& modpath, AST::Module& mod)
{
- // TODO: Handle 'use' statements in an earlier pass, to avoid dependency issues?
- // - Maybe resolve wildcards etc when used?
for( auto& imp : mod.imports() )
{
// TODO: Handle 'super' and 'self' imports
+ // - Any other type of import will be absolute
+
if( imp.name == "" )
{
+ if( imp.is_pub ) {
+ throw ParseError::Generic("Wildcard uses can't be public");
+ }
+
// Wildcard import
+ AST::Path& basepath = imp.data;
+ basepath.resolve(crate);
throw ParseError::Todo("ResolvePaths_HandleModule - wildcard use");
}
}
+ for( auto& submod : mod.submods() )
+ {
+ ResolvePaths_HandleModule_Use(crate, modpath + submod.first.name(), submod.first);
+ }
+}
+
+void ResolvePaths_HandleModule(const AST::Crate& crate, const AST::Path& modpath, AST::Module& mod)
+{
for( auto& fcn : mod.functions() )
{
ResolvePaths_HandleFunction(crate, mod, fcn.first);
@@ -276,5 +290,9 @@ void ResolvePaths_HandleModule(const AST::Crate& crate, const AST::Path& modpath
void ResolvePaths(AST::Crate& crate)
{
+ // Handle 'use' statements in an initial parss
+ ResolvePaths_HandleModule_Use(crate, AST::Path(AST::Path::TagAbsolute()), crate.root_module());
+
+ // Then do path resolution on all other item
ResolvePaths_HandleModule(crate, AST::Path(AST::Path::TagAbsolute()), crate.root_module());
}