summaryrefslogtreecommitdiff
path: root/src/types.cpp
blob: eece7d5b00cd53f4e4eb560f7a4aa84ca1e64e98 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
 */
#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(";
    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;
}

SERIALISE_TYPE(TypeRef::, "TypeRef", {
    // TODO: TypeRef serialise
})