-
Notifications
You must be signed in to change notification settings - Fork 174
Expand file tree
/
Copy pathcpp_function_type.hpp
More file actions
202 lines (170 loc) · 6.04 KB
/
cpp_function_type.hpp
File metadata and controls
202 lines (170 loc) · 6.04 KB
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
// Copyright (C) 2017-2023 Jonathan Müller and cppast contributors
// SPDX-License-Identifier: MIT
#ifndef CPPAST_CPP_FUNCTION_TYPE_HPP_INCLUDED
#define CPPAST_CPP_FUNCTION_TYPE_HPP_INCLUDED
#include <cppast/cpp_type.hpp>
namespace cppast
{
/// A [cppast::cpp_type]() that is a function.
///
/// A function pointer is created by wrapping it in [cppast::cpp_pointer_type]().
class cpp_function_type final : public cpp_type
{
public:
/// Builds a [cppast::cpp_function_type]().
class builder
{
public:
/// \effects Sets the return type.
explicit builder(std::unique_ptr<cpp_type> return_type)
: func_(new cpp_function_type(std::move(return_type)))
{}
/// \effects Adds an parameter type.
void add_parameter(std::unique_ptr<cpp_type> arg)
{
func_->parameters_.push_back(*func_, std::move(arg));
}
/// \effects Adds an ellipsis, marking it as variadic.
void is_variadic()
{
func_->variadic_ = true;
}
/// \returns The finished [cppast::cpp_function_type]().
std::unique_ptr<cpp_function_type> finish()
{
return std::move(func_);
}
private:
std::unique_ptr<cpp_function_type> func_;
};
/// \returns A reference to the return [cppast::cpp_type]().
const cpp_type& return_type() const noexcept
{
return *return_type_;
}
/// \returns An iteratable object iterating over the parameter types.
detail::iteratable_intrusive_list<cpp_type> parameter_types() const noexcept
{
return type_safe::ref(parameters_);
}
/// \returns Whether or not the function is variadic (C-style ellipsis).
bool is_variadic() const noexcept
{
return variadic_;
}
private:
cpp_function_type(std::unique_ptr<cpp_type> return_type)
: return_type_(std::move(return_type)), variadic_(false)
{}
cpp_type_kind do_get_kind() const noexcept override
{
return cpp_type_kind::function_t;
}
std::unique_ptr<cpp_type> return_type_;
detail::intrusive_list<cpp_type> parameters_;
bool variadic_;
};
/// A [cppast::cpp_type]() that is a member function.
///
/// A member function with cv qualifier is created by wrapping it in
/// [cppast::cpp_cv_qualified_type](). A member function with reference qualifier is created by
/// wrapping it in [cppast::cpp_reference_type](). A member function pointer is created by wrapping
/// it in [cppast::cpp_pointer_type]().
class cpp_member_function_type final : public cpp_type
{
public:
/// Builds a [cppast::cpp_member_function_type]().
class builder
{
public:
/// \effects Sets the class and return type.
builder(std::unique_ptr<cpp_type> class_type, std::unique_ptr<cpp_type> return_type)
: func_(new cpp_member_function_type(std::move(class_type), std::move(return_type)))
{}
/// \effects Adds a parameter type.
void add_parameter(std::unique_ptr<cpp_type> arg)
{
func_->parameters_.push_back(*func_, std::move(arg));
}
/// \effects Adds an ellipsis, marking it as variadic.
void is_variadic()
{
func_->variadic_ = true;
}
/// \returns The finished [cppast::cpp_member_function_type]().
std::unique_ptr<cpp_member_function_type> finish()
{
return std::move(func_);
}
private:
std::unique_ptr<cpp_member_function_type> func_;
};
/// \returns A reference to the class [cppast::cpp_type]().
const cpp_type& class_type() const noexcept
{
return *class_type_;
}
/// \returns A reference to the return [cppast::cpp_type]().
const cpp_type& return_type() const noexcept
{
return *return_type_;
}
/// \returns An iteratable object iterating over the parameter types.
detail::iteratable_intrusive_list<cpp_type> parameter_types() const noexcept
{
return type_safe::ref(parameters_);
}
/// \returns Whether or not the function is variadic (C-style ellipsis).
bool is_variadic() const noexcept
{
return variadic_;
}
private:
cpp_member_function_type(std::unique_ptr<cpp_type> class_type,
std::unique_ptr<cpp_type> return_type)
: class_type_(std::move(class_type)), return_type_(std::move(return_type)), variadic_(false)
{}
cpp_type_kind do_get_kind() const noexcept override
{
return cpp_type_kind::member_function_t;
}
std::unique_ptr<cpp_type> class_type_, return_type_;
detail::intrusive_list<cpp_type> parameters_;
bool variadic_;
};
/// A [cppast::cpp_type]() that is a member object.
///
/// A member object pointer is created by wrapping it in [cppast::cpp_pointer_type]().
class cpp_member_object_type final : public cpp_type
{
public:
/// \returns A newly created member object type.
static std::unique_ptr<cpp_member_object_type> build(std::unique_ptr<cpp_type> class_type,
std::unique_ptr<cpp_type> object_type)
{
return std::unique_ptr<cpp_member_object_type>(
new cpp_member_object_type(std::move(class_type), std::move(object_type)));
}
/// \returns A reference to the class [cppast::cpp_type]().
const cpp_type& class_type() const noexcept
{
return *class_type_;
}
/// \returns A reference to the object [cppast::cpp_type]().
const cpp_type& object_type() const noexcept
{
return *object_type_;
}
private:
cpp_member_object_type(std::unique_ptr<cpp_type> class_type,
std::unique_ptr<cpp_type> object_type)
: class_type_(std::move(class_type)), object_type_(std::move(object_type))
{}
cpp_type_kind do_get_kind() const noexcept override
{
return cpp_type_kind::member_object_t;
}
std::unique_ptr<cpp_type> class_type_, object_type_;
};
} // namespace cppast
#endif // CPPAST_CPP_FUNCTION_TYPE_HPP_INCLUDED