diff options
author | John Hodge (sonata) <tpg@mutabah.net> | 2015-01-12 22:23:50 +0800 |
---|---|---|
committer | John Hodge (sonata) <tpg@mutabah.net> | 2015-01-12 22:23:50 +0800 |
commit | 6de0331230ceda3bdfa5b12829de519c21fcff9a (patch) | |
tree | 92fd13a44970a0b69ef2d7c17dd5d77af25de964 /src | |
parent | ed264377ef0e4ed3a5b96b39f3282b3c10d65455 (diff) | |
download | mrust-6de0331230ceda3bdfa5b12829de519c21fcff9a.tar.gz |
TypeRef print
Diffstat (limited to 'src')
-rw-r--r-- | src/common.hpp | 2 | ||||
-rw-r--r-- | src/convert/resolve.cpp | 2 | ||||
-rw-r--r-- | src/types.cpp | 50 |
3 files changed, 52 insertions, 2 deletions
diff --git a/src/common.hpp b/src/common.hpp index c7117722..a7b14fdd 100644 --- a/src/common.hpp +++ b/src/common.hpp @@ -12,6 +12,7 @@ #define DEBUG(ss) do{ ::std::cerr << __FUNCTION__ << ": " << ss << ::std::endl; } while(0) namespace AST { + template <typename T> inline ::std::ostream& operator<<(::std::ostream& os, const ::std::vector<T>& v) { if( v.size() > 0 ) @@ -27,6 +28,7 @@ inline ::std::ostream& operator<<(::std::ostream& os, const ::std::vector<T>& v) } return os; } + } #endif diff --git a/src/convert/resolve.cpp b/src/convert/resolve.cpp index 53a1edaf..7bc00030 100644 --- a/src/convert/resolve.cpp +++ b/src/convert/resolve.cpp @@ -190,7 +190,7 @@ void CPathResolver::resolve_path(AST::Path& path, ResolvePathMode mode) const void CPathResolver::resolve_type(TypeRef& type) const
{
- // TODO: Convert type into absolute
+ // TODO: Convert type into absolute (and check bindings)
DEBUG("type = " << type);
throw ParseError::Todo("CPathResolver::resolve_type()");
}
diff --git a/src/types.cpp b/src/types.cpp index c0a69f8d..eece7d5b 100644 --- a/src/types.cpp +++ b/src/types.cpp @@ -3,8 +3,56 @@ #include "types.hpp" #include "ast/ast.hpp" +template <typename T> +inline ::std::ostream& operator<<(::std::ostream& os, const ::std::vector<T>& v) { + if( v.size() > 0 ) + { + bool is_first = true; + for( const auto& i : v ) + { + if(!is_first) + os << ", "; + is_first = false; + os << i; + } + } + return os; +} + + ::std::ostream& operator<<(::std::ostream& os, const TypeRef& tr) { - os << "TypeRef(TODO)"; + os << "TypeRef("; + switch(tr.m_class) + { + case TypeRef::ANY: + os << "TagAny"; + break; + case TypeRef::UNIT: + os << "TagUnit"; + break; + case TypeRef::PRIMITIVE: + os << "TagPrimitive, " << tr.m_core_type; + break; + case TypeRef::TUPLE: + os << "TagTuple, {" << tr.m_inner_types << "}"; + break; + case TypeRef::REFERENCE: + os << "TagReference, " << (tr.m_is_inner_mutable ? "mut" : "const") << ", " << tr.m_inner_types[0]; + break; + case TypeRef::POINTER: + os << "TagPointer, " << (tr.m_is_inner_mutable ? "mut" : "const") << ", " << tr.m_inner_types[0]; + break; + case TypeRef::ARRAY: + os << "TagSizedArray, " << tr.m_inner_types[0] << ", " << tr.m_size_expr; + break; + case TypeRef::GENERIC: + os << "TagArg, " << tr.m_path[0].name(); + break; + case TypeRef::PATH: + os << "TagPath, " << tr.m_path; + break; + } + os << ")"; return os; } |