summaryrefslogtreecommitdiff
path: root/src/trans/trans_list.hpp
blob: e80a2b6e05303d9b4768efbc815eb624ef7ba650 (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
62
63
64
65
66
67
68
69
/*
 * MRustC - Rust Compiler
 * - By John Hodge (Mutabah/thePowersGang)
 *
 * trans/trans_list.hpp
 * - A list of items that require translation
 */
#pragma once

#include <hir/type.hpp>
#include <hir/path.hpp>
#include <hir_typeck/common.hpp>

namespace HIR {
class Crate;
class Function;
class Static;
}

struct Trans_Params
{
    Span    sp;
    ::HIR::PathParams   pp_method;
    ::HIR::PathParams   pp_impl;
    ::HIR::TypeRef  self_type;

    Trans_Params() {}
    Trans_Params(const Span& sp):
        sp(sp)
    {}

    t_cb_generic get_cb() const;
    ::HIR::TypeRef monomorph(const ::HIR::Crate& crate, const ::HIR::TypeRef& p) const;
    ::HIR::Path monomorph(const ::HIR::Crate& crate, const ::HIR::Path& p) const;
    ::HIR::GenericPath monomorph(const ::HIR::Crate& crate, const ::HIR::GenericPath& p) const;
    ::HIR::PathParams monomorph(const ::HIR::Crate& crate, const ::HIR::PathParams& p) const;

    bool has_types() const {
        return pp_method.m_types.size() > 0 || pp_impl.m_types.size() > 0;
    }
};

struct TransList_Function
{
    const ::HIR::Function*  ptr;
    Trans_Params    pp;
};
struct TransList_Static
{
    const ::HIR::Static*    ptr;
    Trans_Params    pp;
};

class TransList
{
public:
    ::std::map< ::HIR::Path, ::std::unique_ptr<TransList_Function> > m_functions;
    ::std::map< ::HIR::Path, ::std::unique_ptr<TransList_Static> > m_statics;
    ::std::map< ::HIR::Path, Trans_Params> m_vtables;

    ::std::vector< ::HIR::TypeRef>  m_types;

    TransList_Function* add_function(::HIR::Path p);
    TransList_Static* add_static(::HIR::Path p);
    bool add_vtable(::HIR::Path p, Trans_Params pp) {
        return m_vtables.insert( ::std::make_pair( mv$(p), mv$(pp) ) ).second;
    }
};