summaryrefslogtreecommitdiff
path: root/src/types.cpp
diff options
context:
space:
mode:
authorJohn Hodge (sonata) <tpg@mutabah.net>2015-01-23 14:18:25 +0800
committerJohn Hodge (sonata) <tpg@mutabah.net>2015-01-23 14:18:25 +0800
commit175b02f7934d574778c87028edc9a6ebb97d690c (patch)
treeb0a338ffdfa03016d3212e112192cfb396f7ea75 /src/types.cpp
parent450d55d26e0265858f60f5a118aac72cf392495f (diff)
downloadmrust-175b02f7934d574778c87028edc9a6ebb97d690c.tar.gz
Autoderef on method lookup, further provements to method lookup
Diffstat (limited to 'src/types.cpp')
-rw-r--r--src/types.cpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/types.cpp b/src/types.cpp
index 58d820f5..33b564dd 100644
--- a/src/types.cpp
+++ b/src/types.cpp
@@ -33,6 +33,39 @@ const char* coretype_name(const eCoreType ct ) {
return "NFI";
}
+/// Replace this type reference with a dereferenced version
+bool TypeRef::deref(bool is_implicit)
+{
+ switch(m_class)
+ {
+ case TypeRef::ANY:
+ // TODO: Check if the _ is bounded by Deref<Output=?>, if so use that
+ throw ::std::runtime_error("Dereferencing _");
+ break;
+ case TypeRef::UNIT:
+ throw ::std::runtime_error("Dereferencing ()");
+ case TypeRef::PRIMITIVE:
+ throw ::std::runtime_error("Dereferencing a primtive type");
+ case TypeRef::GENERIC:
+ throw ::std::runtime_error("Dereferencing a generic");
+ case TypeRef::REFERENCE:
+ *this = m_inner_types[0];
+ return true;
+ case TypeRef::POINTER:
+ // raw pointers can't be implicitly dereferenced
+ if( is_implicit )
+ return false;
+ *this = m_inner_types[0];
+ return true;
+ case TypeRef::TUPLE:
+ case TypeRef::ARRAY:
+ case TypeRef::PATH:
+ throw ::std::runtime_error("TODO: Search for an impl of Deref");
+ case TypeRef::ASSOCIATED:
+ throw ::std::runtime_error("TODO: TypeRef::deref on ASSOCIATED");
+ }
+}
+
/// Merge the contents of the passed type with this type
///
/// \note Both types must be of the same form (i.e. both be tuples)