summaryrefslogtreecommitdiff
path: root/src/ast/path.cpp
diff options
context:
space:
mode:
authorJohn Hodge (sonata) <tpg@mutabah.net>2015-01-18 12:35:22 +0800
committerJohn Hodge (sonata) <tpg@mutabah.net>2015-01-18 12:35:22 +0800
commit0390dc8a92c3c8d12421d529915ab350234301c3 (patch)
treea2becfe84d9202f1a7464411871669f07ee1d6e1 /src/ast/path.cpp
parent0c9d8ed4cbe8d74a511176cd6577c9c3d0eb3ef6 (diff)
downloadmrust-0390dc8a92c3c8d12421d529915ab350234301c3.tar.gz
Added pretty type printing, non-expr typecheck correctly fails on too many params (forgot to move iterator to associated types)
Diffstat (limited to 'src/ast/path.cpp')
-rw-r--r--src/ast/path.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/ast/path.cpp b/src/ast/path.cpp
index 8f77f008..e1a265bf 100644
--- a/src/ast/path.cpp
+++ b/src/ast/path.cpp
@@ -7,6 +7,8 @@
#include "../parse/parseerror.hpp"
#include <algorithm>
+#define PRETTY_PATH_PRINT 1
+
namespace AST {
// --- AST::PathNode
@@ -23,6 +25,19 @@ const ::std::vector<TypeRef>& PathNode::args() const
{
return m_params;
}
+::std::ostream& operator<<(::std::ostream& os, const PathNode& pn) {
+ #if PRETTY_PATH_PRINT
+ os << "::";
+ #endif
+ os << pn.m_name;
+ if( pn.m_params.size() )
+ {
+ os << "<";
+ os << pn.m_params;
+ os << ">";
+ }
+ return os;
+}
SERIALISE_TYPE(PathNode::, "PathNode", {
s << m_name;
s << m_params;
@@ -286,6 +301,20 @@ Path& Path::operator+=(const Path& other)
}
::std::ostream& operator<<(::std::ostream& os, const Path& path)
{
+ #if PRETTY_PATH_PRINT
+ switch(path.m_class)
+ {
+ case Path::RELATIVE:
+ os << "self";
+ case Path::ABSOLUTE:
+ for(const auto& n : path.m_nodes)
+ os << n;
+ break;
+ case Path::LOCAL:
+ os << path.m_nodes[0].name();
+ break;
+ }
+ #else
switch(path.m_class)
{
case Path::RELATIVE:
@@ -298,6 +327,7 @@ Path& Path::operator+=(const Path& other)
os << "Path(TagLocal, " << path.m_nodes[0].name() << ")";
break;
}
+ #endif
return os;
}
::Serialiser& operator<<(Serialiser& s, Path::Class pc)