diff options
author | John Hodge (sonata) <tpg@mutabah.net> | 2015-01-05 08:43:45 +0800 |
---|---|---|
committer | John Hodge (sonata) <tpg@mutabah.net> | 2015-01-05 08:43:45 +0800 |
commit | eac8e3d68b9ca67f97c1f9aedef01e8e93cde323 (patch) | |
tree | 47fc3f527b7f3d03718277347e13c3ee4bb779d2 /src/ast/ast.cpp | |
parent | 4a9e7dc0e4976c03a8dbceeacc5e474509b237f9 (diff) | |
download | mrust-eac8e3d68b9ca67f97c1f9aedef01e8e93cde323.tar.gz |
Implementing path lookup (bottom level of resolve)
Diffstat (limited to 'src/ast/ast.cpp')
-rw-r--r-- | src/ast/ast.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/ast/ast.cpp b/src/ast/ast.cpp index 994d3999..438aa2cd 100644 --- a/src/ast/ast.cpp +++ b/src/ast/ast.cpp @@ -4,10 +4,12 @@ #include "../types.hpp"
#include <iostream>
#include "../parse/parseerror.hpp"
+#include <algorithm>
namespace AST {
+// --- AST::PathNode
PathNode::PathNode(::std::string name, ::std::vector<TypeRef> args):
m_name(name),
m_params(args)
@@ -22,6 +24,36 @@ const ::std::vector<TypeRef>& PathNode::args() const return m_params;
}
+// --- AST::Path
+void Path::resolve(const Crate& crate)
+{
+ DEBUG("*this = " << *this);
+ if(m_class != ABSOLUTE)
+ throw ParseError::BugCheck("Calling Path::resolve on non-absolute path");
+
+ const Module* mod = &crate.root_module();
+ for(int i = 0; i < m_nodes.size(); i ++ )
+ {
+ const PathNode& node = m_nodes[i];
+ auto& sms = mod->submods();
+
+ auto it = ::std::find_if(sms.begin(), sms.end(), [&node](const ::std::pair<Module,bool>& x) {
+ return x.first.name() == node.name();
+ });
+ if( it != sms.end() )
+ continue;
+
+ // Start searching for:
+ // - Re-exports
+ // - Functions
+ // - Structs
+ // - Enums (and variants)
+
+ }
+
+ throw ParseError::Todo("Path::resolve");
+}
+
Path& Path::operator+=(const Path& other)
{
for(auto& node : other.m_nodes)
|