llvm.org GIT mirror llvm / 6ea7358
Kaleidoscope-ch2: Remove the dependence on LLVM by cloning make_unique into this project git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@251936 91177308-0d34-0410-b5e6-96231b3b80d8 David Blaikie 3 years ago
1 changed file(s) with 23 addition(s) and 11 deletion(s). Raw diff Collapse all Expand all
None #include "llvm/ADT/STLExtras.h"
1 #include
21 #include
32 #include
3 #include
44 #include
55 #include
6
7 namespace helper {
8 // Cloning make_unique here until it's standard in C++14.
9 // Using a namespace to avoid conflicting with MSVC's std::make_unique (which
10 // ADL can sometimes find in unqualified calls).
11 template
12 static
13 typename std::enable_if::value, std::unique_ptr>::type
14 make_unique(Args &&... args) {
15 return std::unique_ptr(new T(std::forward(args)...));
16 }
17 }
618
719 //===----------------------------------------------------------------------===//
820 // Lexer
188200
189201 /// numberexpr ::= number
190202 static std::unique_ptr ParseNumberExpr() {
191 auto Result = llvm::make_unique(NumVal);
203 auto Result = helper::make_unique(NumVal);
192204 getNextToken(); // consume the number
193205 return std::move(Result);
194206 }
215227 getNextToken(); // eat identifier.
216228
217229 if (CurTok != '(') // Simple variable ref.
218 return llvm::make_unique(IdName);
230 return helper::make_unique(IdName);
219231
220232 // Call.
221233 getNextToken(); // eat (
239251 // Eat the ')'.
240252 getNextToken();
241253
242 return llvm::make_unique(IdName, std::move(Args));
254 return helper::make_unique(IdName, std::move(Args));
243255 }
244256
245257 /// primary
291303 }
292304
293305 // Merge LHS/RHS.
294 LHS =
295 llvm::make_unique(BinOp, std::move(LHS), std::move(RHS));
306 LHS = helper::make_unique(BinOp, std::move(LHS),
307 std::move(RHS));
296308 }
297309 }
298310
328340 // success.
329341 getNextToken(); // eat ')'.
330342
331 return llvm::make_unique(FnName, std::move(ArgNames));
343 return helper::make_unique(FnName, std::move(ArgNames));
332344 }
333345
334346 /// definition ::= 'def' prototype expression
339351 return nullptr;
340352
341353 if (auto E = ParseExpression())
342 return llvm::make_unique(std::move(Proto), std::move(E));
354 return helper::make_unique(std::move(Proto), std::move(E));
343355 return nullptr;
344356 }
345357
347359 static std::unique_ptr ParseTopLevelExpr() {
348360 if (auto E = ParseExpression()) {
349361 // Make an anonymous proto.
350 auto Proto = llvm::make_unique("__anon_expr",
351 std::vector());
352 return llvm::make_unique(std::move(Proto), std::move(E));
362 auto Proto = helper::make_unique("__anon_expr",
363 std::vector());
364 return helper::make_unique(std::move(Proto), std::move(E));
353365 }
354366 return nullptr;
355367 }