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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
/*
* 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>
class StaticTraitResolve;
namespace HIR {
class Crate;
class Function;
class Static;
}
// TODO: This is very similar to "hir_typeck/common.hpp" MonomorphState
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 ::StaticTraitResolve& resolve, const ::HIR::TypeRef& p) const;
::HIR::Path monomorph(const ::StaticTraitResolve& resolve, const ::HIR::Path& p) const;
::HIR::GenericPath monomorph(const ::StaticTraitResolve& resolve, const ::HIR::GenericPath& p) const;
::HIR::PathParams monomorph(const ::StaticTraitResolve& resolve, const ::HIR::PathParams& p) const;
bool has_types() const {
return pp_method.m_types.size() > 0 || pp_impl.m_types.size() > 0;
}
};
struct CachedFunction {
::HIR::TypeRef ret_ty;
::HIR::Function::args_t arg_tys;
::MIR::FunctionPointer code;
};
struct TransList_Function
{
const ::HIR::Path* path; // Pointer into the list (std::map pointers are stable)
const ::HIR::Function* ptr;
Trans_Params pp;
// If `pp.has_types` is true, the below is valid
CachedFunction monomorphised;
TransList_Function(const ::HIR::Path& path):
path(&path),
ptr(nullptr)
{}
};
struct TransList_Static
{
const ::HIR::Static* ptr;
Trans_Params pp;
};
struct TransList_Const
{
const ::HIR::Constant* ptr;
Trans_Params pp;
};
class TransList
{
public:
TransList() = default;
TransList(TransList&&) = default;
TransList(const TransList&) = delete;
TransList& operator=(TransList&&) = default;
TransList& operator=(const TransList&) = delete;
::std::map< ::HIR::Path, ::std::unique_ptr<TransList_Function> > m_functions;
::std::map< ::HIR::Path, ::std::unique_ptr<TransList_Static> > m_statics;
/// Constants that are still Defer
::std::map< ::HIR::Path, ::std::unique_ptr<TransList_Const> > m_constants;
::std::map< ::HIR::Path, Trans_Params> m_vtables;
/// Required type_id values
::std::set< ::HIR::TypeRef> m_typeids;
/// Required struct/enum constructor impls
::std::set< ::HIR::GenericPath> m_constructors;
// Automatic Clone impls
::std::set< ::HIR::TypeRef> auto_clone_impls;
// .second is `true` if this is a from a reference to the type
::std::vector< ::std::pair<::HIR::TypeRef, bool> > m_types;
TransList_Function* add_function(::HIR::Path p);
TransList_Static* add_static(::HIR::Path p);
TransList_Const* add_const(::HIR::Path p);
bool add_vtable(::HIR::Path p, Trans_Params pp) {
return m_vtables.insert( ::std::make_pair( mv$(p), mv$(pp) ) ).second;
}
};
|