From 6de0331230ceda3bdfa5b12829de519c21fcff9a Mon Sep 17 00:00:00 2001 From: "John Hodge (sonata)" Date: Mon, 12 Jan 2015 22:23:50 +0800 Subject: TypeRef print --- src/common.hpp | 2 ++ src/convert/resolve.cpp | 2 +- src/types.cpp | 50 ++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 52 insertions(+), 2 deletions(-) (limited to 'src') 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 inline ::std::ostream& operator<<(::std::ostream& os, const ::std::vector& v) { if( v.size() > 0 ) @@ -27,6 +28,7 @@ inline ::std::ostream& operator<<(::std::ostream& os, const ::std::vector& 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 +inline ::std::ostream& operator<<(::std::ostream& os, const ::std::vector& 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; } -- cgit v1.2.3