summaryrefslogtreecommitdiff
path: root/src/ast/path.cpp
diff options
context:
space:
mode:
authorJohn Hodge <tpg@mutabah.net>2015-03-30 17:52:31 +0800
committerJohn Hodge <tpg@mutabah.net>2015-03-30 17:52:31 +0800
commitace202ef3d35cb5010e9164900c2c825dd6d3e8e (patch)
tree62fb10e28e795aef13c82d7717384b1affb3c3da /src/ast/path.cpp
parent86e4115964dee385d167fda110ed700012168d06 (diff)
downloadmrust-ace202ef3d35cb5010e9164900c2c825dd6d3e8e.tar.gz
Add ordering to TypeRef and Path (to generalise operator== and operator<
Diffstat (limited to 'src/ast/path.cpp')
-rw-r--r--src/ast/path.cpp24
1 files changed, 20 insertions, 4 deletions
diff --git a/src/ast/path.cpp b/src/ast/path.cpp
index c06a63a4..381685a9 100644
--- a/src/ast/path.cpp
+++ b/src/ast/path.cpp
@@ -25,9 +25,14 @@ const ::std::vector<TypeRef>& PathNode::args() const
{
return m_params;
}
-bool PathNode::operator==(const PathNode& x) const
+Ordering PathNode::ord(const PathNode& x) const
{
- return m_name == x.m_name && m_params == x.m_params;
+ Ordering rv;
+ rv = ::ord(m_name, x.m_name);
+ if(rv != OrdEqual) return rv;
+ rv = ::ord(m_params, x.m_params);
+ if(rv != OrdEqual) return rv;
+ return OrdEqual;
}
::std::ostream& operator<<(::std::ostream& os, const PathNode& pn) {
os << pn.m_name;
@@ -356,9 +361,20 @@ Path& Path::operator+=(const Path& other)
return *this;
}
-bool Path::operator==(const Path& x) const
+Ordering Path::ord(const Path& x) const
{
- return m_class == x.m_class && m_crate == x.m_crate && m_nodes == x.m_nodes;
+ Ordering rv;
+
+ rv = ::ord( (unsigned)m_class, (unsigned)x.m_class );
+ if( rv != OrdEqual ) return rv;
+
+ rv = ::ord( m_crate, x.m_crate );
+ if( rv != OrdEqual ) return rv;
+
+ rv = ::ord( m_nodes, x.m_nodes );
+ if( rv != OrdEqual ) return rv;
+
+ return OrdEqual;
}
void Path::print_pretty(::std::ostream& os) const