20
20
#include " rust-ast-builder-type.h"
21
21
#include " rust-common.h"
22
22
#include " rust-expr.h"
23
+ #include " rust-path.h"
23
24
#include " rust-token.h"
24
25
#include " rust-make-unique.h"
25
26
@@ -42,6 +43,33 @@ Builder::call (std::unique_ptr<Expr> &&path,
42
43
new CallExpr (std::move (path), std::move (args), {}, loc));
43
44
}
44
45
46
+ std::unique_ptr<Expr>
47
+ Builder::call (std::unique_ptr<Path> &&path,
48
+ std::vector<std::unique_ptr<Expr>> &&args) const
49
+ {
50
+ return call (std::unique_ptr<Expr> (
51
+ new PathInExpression (std::move (path), {}, loc)),
52
+ std::move (args));
53
+ }
54
+
55
+ std::unique_ptr<Expr>
56
+ Builder::call (std::unique_ptr<Expr> &&path, std::unique_ptr<Expr> &&arg) const
57
+ {
58
+ auto args = std::vector<std::unique_ptr<Expr>> ();
59
+ args.emplace_back (std::move (arg));
60
+
61
+ return call (std::move (path), std::move (args));
62
+ }
63
+
64
+ std::unique_ptr<Expr>
65
+ Builder::call (std::unique_ptr<Path> &&path, std::unique_ptr<Expr> &&arg) const
66
+ {
67
+ auto args = std::vector<std::unique_ptr<Expr>> ();
68
+ args.emplace_back (std::move (arg));
69
+
70
+ return call (std::move (path), std::move (args));
71
+ }
72
+
45
73
std::unique_ptr<Expr>
46
74
Builder::array (std::vector<std::unique_ptr<Expr>> &&members) const
47
75
{
@@ -56,6 +84,13 @@ Builder::identifier (std::string name) const
56
84
return std::unique_ptr<Expr> (new IdentifierExpr (name, {}, loc));
57
85
}
58
86
87
+ std::unique_ptr<Pattern>
88
+ Builder::identifier_pattern (std::string name, bool mut) const
89
+ {
90
+ return std::unique_ptr<Pattern> (
91
+ new IdentifierPattern (name, loc, false , mut));
92
+ }
93
+
59
94
std::unique_ptr<Expr>
60
95
Builder::tuple_idx (std::string receiver, int idx) const
61
96
{
@@ -117,6 +152,22 @@ Builder::path_in_expression (std::vector<std::string> &&segments) const
117
152
return PathInExpression (std::move (path_segments), {}, loc);
118
153
}
119
154
155
+ PathInExpression
156
+ Builder::path_in_expression (LangItem::Kind lang_item) const
157
+ {
158
+ return PathInExpression (lang_item, {}, loc);
159
+ }
160
+
161
+ std::unique_ptr<Expr>
162
+ Builder::block (std::unique_ptr<Stmt> &&stmt,
163
+ std::unique_ptr<Expr> &&tail_expr) const
164
+ {
165
+ auto stmts = std::vector<std::unique_ptr<Stmt>> ();
166
+ stmts.emplace_back (std::move (stmt));
167
+
168
+ return block (std::move (stmts), std::move (tail_expr));
169
+ }
170
+
120
171
std::unique_ptr<Expr>
121
172
Builder::block (std::vector<std::unique_ptr<Stmt>> &&stmts,
122
173
std::unique_ptr<Expr> &&tail_expr) const
@@ -189,6 +240,46 @@ Builder::wildcard () const
189
240
return std::unique_ptr<Pattern> (new WildcardPattern (loc));
190
241
}
191
242
243
+ std::unique_ptr<Path>
244
+ Builder::lang_item_path (LangItem::Kind kind) const
245
+ {
246
+ return std::unique_ptr<Path> (new LangItemPath (kind, loc));
247
+ }
248
+
249
+ std::unique_ptr<Expr>
250
+ Builder::match (std::unique_ptr<Expr> &&scrutinee,
251
+ std::vector<MatchCase> &&cases)
252
+ {
253
+ return std::unique_ptr<Expr> (
254
+ new MatchExpr (std::move (scrutinee), std::move (cases), {}, {}, loc));
255
+ }
256
+
257
+ MatchArm
258
+ Builder::match_arm (std::unique_ptr<Pattern> &&pattern)
259
+ {
260
+ auto patterns = std::vector<std::unique_ptr<Pattern>> ();
261
+ patterns.emplace_back (std::move (pattern));
262
+
263
+ return MatchArm (std::move (patterns), loc);
264
+ }
265
+
266
+ MatchCase
267
+ Builder::match_case (std::unique_ptr<Pattern> &&pattern,
268
+ std::unique_ptr<Expr> &&expr)
269
+ {
270
+ return MatchCase (match_arm (std::move (pattern)), std::move (expr));
271
+ }
272
+
273
+ std::unique_ptr<Expr>
274
+ Builder::loop (std::vector<std::unique_ptr<Stmt>> &&stmts)
275
+ {
276
+ auto block = std::unique_ptr<BlockExpr> (
277
+ new BlockExpr (std::move (stmts), nullptr , {}, {}, LoopLabel::error (), loc,
278
+ loc));
279
+
280
+ return std::unique_ptr<Expr> (new LoopExpr (std::move (block), loc));
281
+ }
282
+
192
283
std::unique_ptr<Type>
193
284
Builder::new_type (Type &type)
194
285
{
0 commit comments