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
106
107
108
109
110
|
/*
*/
#include "generic_params.hpp"
namespace HIR {
::std::ostream& operator<<(::std::ostream& os, const GenericBound& x)
{
TU_MATCH(::HIR::GenericBound, (x), (e),
(Lifetime,
os << "'" << e.test << ": '" << e.valid_for;
),
(TypeLifetime,
os << e.type << ": '" << e.valid_for;
),
(TraitBound,
os << e.type << ": " << e.trait/*.m_path*/;
),
(TypeEquality,
os << e.type << " = " << e.other_type;
)
)
return os;
}
::std::ostream& operator<<(::std::ostream& os, const ::HIR::GenericParams::PrintArgs& x)
{
if( x.gp.m_lifetimes.size() > 0 || x.gp.m_types.size() > 0 )
{
os << "<";
for(const auto& lft : x.gp.m_lifetimes) {
os << "'" << lft << ",";
}
for(const auto& typ : x.gp.m_types) {
os << typ.m_name;
if( ! typ.m_is_sized )
os << ": ?Sized";
if( !typ.m_default.m_data.is_Infer() )
os << " = " << typ.m_default;
os << ",";
}
os << ">";
}
return os;
}
::std::ostream& operator<<(::std::ostream& os, const ::HIR::GenericParams::PrintBounds& x)
{
if( x.gp.m_bounds.size() > 0 )
{
os << " where ";
bool comma_needed = false;
for(const auto& b : x.gp.m_bounds)
{
if(comma_needed)
os << ", ";
os << b;
comma_needed = true;
}
}
return os;
}
}
::HIR::GenericParams HIR::GenericParams::clone() const
{
::HIR::GenericParams rv;
rv.m_types.reserve(m_types.size());
for(const auto& type : m_types)
{
rv.m_types.push_back(::HIR::TypeParamDef {
type.m_name,
type.m_default.clone(),
type.m_is_sized
});
}
rv.m_lifetimes = m_lifetimes;
rv.m_bounds.reserve(m_bounds.size());
for(const auto& bound : m_bounds)
{
TU_MATCH(::HIR::GenericBound, (bound), (e),
(Lifetime,
rv.m_bounds.push_back(::HIR::GenericBound::make_Lifetime(e));
),
(TypeLifetime,
rv.m_bounds.push_back(::HIR::GenericBound::make_TypeLifetime({
e.type.clone(),
e.valid_for
}));
),
(TraitBound,
rv.m_bounds.push_back(::HIR::GenericBound::make_TraitBound({
e.type.clone(),
e.trait.clone()
}));
)/*,
(NotTrait,
rv.m_bounds.push_back(::HIR::GenericBound::make_NotTrait({
e.type.clone(),
e.trait.clone()
}));
)*/,
(TypeEquality,
rv.m_bounds.push_back(::HIR::GenericBound::make_TypeEquality({
e.type.clone(),
e.other_type.clone()
}));
)
)
}
return rv;
}
|