diff options
author | John Hodge (sonata) <tpg@mutabah.net> | 2015-01-18 17:14:20 +0800 |
---|---|---|
committer | John Hodge (sonata) <tpg@mutabah.net> | 2015-01-18 17:14:20 +0800 |
commit | c3ca711c49760e7f9467afd0811a0427c67e0dc1 (patch) | |
tree | 7fb69cf62e996c62b006049b110ce791ac8e7abf /src/types.cpp | |
parent | 3cbe4af9214824fe1314318f8f338e0cfbfc89a3 (diff) | |
download | mrust-c3ca711c49760e7f9467afd0811a0427c67e0dc1.tar.gz |
Generic param checks passing
Diffstat (limited to 'src/types.cpp')
-rw-r--r-- | src/types.cpp | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/types.cpp b/src/types.cpp index 230fae77..f674d446 100644 --- a/src/types.cpp +++ b/src/types.cpp @@ -4,6 +4,39 @@ #include "ast/ast.hpp" +bool TypeRef::operator==(const TypeRef& x) const +{ + if(m_class != x.m_class) + return false; + switch(m_class) + { + case TypeRef::ANY: + case TypeRef::UNIT: + return true; + case TypeRef::PRIMITIVE: + return m_core_type == x.m_core_type; + case TypeRef::TUPLE: + return m_inner_types == x.m_inner_types; + case TypeRef::REFERENCE: + case TypeRef::POINTER: + return m_is_inner_mutable == x.m_is_inner_mutable && m_inner_types == x.m_inner_types; + case TypeRef::ARRAY: + if(m_inner_types[0] != x.m_inner_types[0]) + return false; + if(m_size_expr.get()) + { + throw ::std::runtime_error("TODO: Sized array comparisons"); + } + return true; + case TypeRef::GENERIC: + throw ::std::runtime_error("BUGCHECK - Can't compare generic type"); + case TypeRef::PATH: + return m_path == x.m_path; + case TypeRef::ASSOCIATED: + return m_path == x.m_path && m_inner_types == x.m_inner_types; + } +} + ::std::ostream& operator<<(::std::ostream& os, const TypeRef& tr) { os << "TypeRef("; switch(tr.m_class) |