diff options
author | John Hodge <tpg@mutabah.net> | 2015-11-04 11:52:06 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2015-11-04 11:52:06 +0800 |
commit | 5d0917df41ad7fedb3fda04d8cb18b495d8adf03 (patch) | |
tree | f79a8525894dbcb9559cd6fad39b21ab162ee70b /src/ast | |
parent | 3e4d93ca2f810ab7d1324817127953d251896b61 (diff) | |
download | mrust-5d0917df41ad7fedb3fda04d8cb18b495d8adf03.tar.gz |
Improve name resolution logic
Diffstat (limited to 'src/ast')
-rw-r--r-- | src/ast/ast.hpp | 2 | ||||
-rw-r--r-- | src/ast/path.hpp | 16 |
2 files changed, 16 insertions, 2 deletions
diff --git a/src/ast/ast.hpp b/src/ast/ast.hpp index f4f2b474..f057d9a3 100644 --- a/src/ast/ast.hpp +++ b/src/ast/ast.hpp @@ -742,9 +742,11 @@ public: ItemRef(): m_type(None) {}
Type tag() const { return m_type; }
+ bool is_None() const { return m_type == None; }
const Type& as_None() const { return m_type; } // HACK: Returns &Type in place of &void
#define _(ty,ident) \
ItemRef(const ty& ref): m_type(ident), m_ref(&ref) {} \
+ bool is_##ident() const { return m_type == ident; } \
const ty& as_##ident() const { assert(m_type == ident); return *(const ty*)m_ref; }
_(AST::Module, Module)
_(::std::string, Crate)
diff --git a/src/ast/path.hpp b/src/ast/path.hpp index 23b4dc11..a2178a8a 100644 --- a/src/ast/path.hpp +++ b/src/ast/path.hpp @@ -266,7 +266,19 @@ public: bool is_valid() const { return !m_class.is_Invalid(); } bool is_absolute() const { return m_class.is_Absolute(); } bool is_relative() const { return m_class.is_Relative() || m_class.is_Super() || m_class.is_Self(); } - size_t size() const { return nodes().size(); } + + size_t size() const { + TU_MATCH(Class, (m_class), (ent), + (Invalid, assert(!m_class.is_Invalid()); throw ::std::runtime_error("Path::nodes() on Invalid"); ), + (Local, return 1;), + (Relative, return ent.nodes.size();), + (Self, return ent.nodes.size();), + (Super, return ent.nodes.size();), + (Absolute, return ent.nodes.size();), + (UFCS, return ent.nodes.size();) + ) + throw ::std::runtime_error("Path::nodes() fell off"); + } const ::std::string& crate() const { return m_crate; } bool is_concrete() const; @@ -283,7 +295,7 @@ public: (Self, return ent.nodes;), (Super, return ent.nodes;), (Absolute, return ent.nodes;), - (UFCS, return ent.nodes;) + (UFCS, return ent.nodes;) ) throw ::std::runtime_error("Path::nodes() fell off"); } |