summaryrefslogtreecommitdiff
path: root/src/hir/type.cpp
diff options
context:
space:
mode:
authorJohn Hodge <tpg@mutabah.net>2016-07-17 12:31:08 +0800
committerJohn Hodge <tpg@mutabah.net>2016-07-17 12:31:08 +0800
commit923d403d45dbcfe4d02c0fd2923ef97760ff1659 (patch)
treebbb37fef28a7977d94848afe614e5079beda54f7 /src/hir/type.cpp
parentb9543cd50d06c3478987cf3ab6ea4215fd9124e6 (diff)
downloadmrust-923d403d45dbcfe4d02c0fd2923ef97760ff1659.tar.gz
HIR - Allow sorting of types and paths
Diffstat (limited to 'src/hir/type.cpp')
-rw-r--r--src/hir/type.cpp88
1 files changed, 88 insertions, 0 deletions
diff --git a/src/hir/type.cpp b/src/hir/type.cpp
index 14fa4c46..7695f066 100644
--- a/src/hir/type.cpp
+++ b/src/hir/type.cpp
@@ -263,6 +263,94 @@ bool ::HIR::TypeRef::operator==(const ::HIR::TypeRef& x) const
)
throw "";
}
+Ordering HIR::TypeRef::ord(const ::HIR::TypeRef& x) const
+{
+ Ordering rv;
+
+ ORD( static_cast<unsigned int>(m_data.tag()), static_cast<unsigned int>(x.m_data.tag()) );
+
+ TU_MATCH(::HIR::TypeRef::Data, (m_data, x.m_data), (te, xe),
+ (Infer,
+ // TODO: Should comparing inferrence vars be an error?
+ return ::ord( te.index, xe.index );
+ ),
+ (Diverge,
+ return OrdEqual;
+ ),
+ (Primitive,
+ return ::ord( static_cast<unsigned>(te), static_cast<unsigned>(xe) );
+ ),
+ (Path,
+ ORD( (unsigned)te.path.m_data.tag(), (unsigned)xe.path.m_data.tag() );
+ TU_MATCH(::HIR::Path::Data, (te.path.m_data, xe.path.m_data), (tpe, xpe),
+ (Generic,
+ return ::ord(tpe, xpe);
+ ),
+ (UfcsInherent,
+ ORD(*tpe.type, *xpe.type);
+ ORD(tpe.item, xpe.item);
+ return ::ord(tpe.params, xpe.params);
+ ),
+ (UfcsKnown,
+ ORD(*tpe.type, *xpe.type);
+ ORD(tpe.trait, xpe.trait);
+ ORD(tpe.item, xpe.item);
+ return ::ord(tpe.params, xpe.params);
+ ),
+ (UfcsUnknown,
+ ORD(*tpe.type, *xpe.type);
+ ORD(tpe.item, xpe.item);
+ return ::ord(tpe.params, xpe.params);
+ )
+ )
+ ),
+ (Generic,
+ ORD(te.name, xe.name);
+ if( (rv = ::ord(te.binding, xe.binding)) != OrdEqual )
+ return rv;
+ return OrdEqual;
+ ),
+ (TraitObject,
+ ORD(te.m_trait, xe.m_trait);
+ ORD(te.m_markers, xe.m_markers);
+ return OrdEqual;
+ //return ::ord(te.m_lifetime, xe.m_lifetime);
+ ),
+ (Array,
+ ORD(*te.inner, *xe.inner);
+ ORD(te.size_val, xe.size_val);
+ if( te.size_val == ~0u )
+ assert(!"TOD: Compre array types with non-resolved sizes");
+ return OrdEqual;
+ ),
+ (Slice,
+ return ::ord(*te.inner, *xe.inner);
+ ),
+ (Tuple,
+ return ::ord(te, xe);
+ ),
+ (Borrow,
+ ORD( static_cast<unsigned>(te.type), static_cast<unsigned>(xe.type) );
+ return ::ord(*te.inner, *xe.inner);
+ ),
+ (Pointer,
+ ORD( static_cast<unsigned>(te.type), static_cast<unsigned>(xe.type) );
+ return ::ord(*te.inner, *xe.inner);
+ ),
+ (Function,
+ ORD(te.is_unsafe, xe.is_unsafe);
+ ORD(te.m_abi, xe.m_abi);
+ ORD(te.m_arg_types, xe.m_arg_types);
+ return ::ord(*te.m_rettype, *xe.m_rettype);
+ ),
+ (Closure,
+ ORD( (::std::uintptr_t)te.node, xe.node);
+ //assert( te.m_rettype == xe.m_rettype );
+ return OrdEqual;
+ )
+ )
+ throw "";
+}
namespace {