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 | |
parent | 4a9e7dc0e4976c03a8dbceeacc5e474509b237f9 (diff) | |
download | mrust-eac8e3d68b9ca67f97c1f9aedef01e8e93cde323.tar.gz |
Implementing path lookup (bottom level of resolve)
Diffstat (limited to 'src/ast')
-rw-r--r-- | src/ast/ast.cpp | 32 | ||||
-rw-r--r-- | src/ast/path.hpp | 9 |
2 files changed, 41 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)
diff --git a/src/ast/path.hpp b/src/ast/path.hpp index 182802f2..05439e06 100644 --- a/src/ast/path.hpp +++ b/src/ast/path.hpp @@ -11,6 +11,8 @@ class TypeRef; namespace AST { +class Crate; + class TypeParam { public: @@ -73,6 +75,11 @@ public: ret.m_nodes.push_back(ent); return ret; } + Path operator+(PathNode&& pn) const { + Path tmp; + tmp.append( ::std::move(pn) ); + return Path(*this) += tmp; + } Path operator+(const ::std::string& s) const { Path tmp; tmp.append(PathNode(s, {})); @@ -87,6 +94,8 @@ public: m_nodes.push_back(node); } + void resolve(const Crate& crate); + bool is_relative() const { return m_class == RELATIVE; } size_t size() const { return m_nodes.size(); } ::std::vector<PathNode>& nodes() { return m_nodes; } |