llvm.org GIT mirror llvm / 4cd6605
[Kaleidoscope] Make Chapter 2 use llvm::make_unique, rather than a helper. This essentially reverts r251936, minimizing the difference between Chapter2 and Chapter 3, and making Chapter 2's code match the tutorial text. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@281945 91177308-0d34-0410-b5e6-96231b3b80d8 Lang Hames 3 years ago
2 changed file(s) with 15 addition(s) and 22 deletion(s). Raw diff Collapse all Expand all
0 set(LLVM_LINK_COMPONENTS
1 Support
2 )
3
4 add_kaleidoscope_chapter(Kaleidoscope-Ch2
15 toy.cpp
26 )
0 #include "llvm/ADT/STLExtras.h"
1 #include
12 #include
23 #include
56 #include
67 #include
78
8 namespace helper {
9 // Cloning make_unique here until it's standard in C++14.
10 // Using a namespace to avoid conflicting with MSVC's std::make_unique (which
11 // ADL can sometimes find in unqualified calls).
12 template
13 static
14 typename std::enable_if::value, std::unique_ptr>::type
15 make_unique(Args &&... args) {
16 return std::unique_ptr(new T(std::forward(args)...));
17 }
18 } // end namespace helper
19
209 //===----------------------------------------------------------------------===//
2110 // Lexer
2211 //===----------------------------------------------------------------------===//
201190
202191 /// numberexpr ::= number
203192 static std::unique_ptr ParseNumberExpr() {
204 auto Result = helper::make_unique(NumVal);
193 auto Result = llvm::make_unique(NumVal);
205194 getNextToken(); // consume the number
206195 return std::move(Result);
207196 }
228217 getNextToken(); // eat identifier.
229218
230219 if (CurTok != '(') // Simple variable ref.
231 return helper::make_unique(IdName);
220 return llvm::make_unique(IdName);
232221
233222 // Call.
234223 getNextToken(); // eat (
252241 // Eat the ')'.
253242 getNextToken();
254243
255 return helper::make_unique(IdName, std::move(Args));
244 return llvm::make_unique(IdName, std::move(Args));
256245 }
257246
258247 /// primary
304293 }
305294
306295 // Merge LHS/RHS.
307 LHS = helper::make_unique(BinOp, std::move(LHS),
308 std::move(RHS));
296 LHS = llvm::make_unique(BinOp, std::move(LHS),
297 std::move(RHS));
309298 }
310299 }
311300
341330 // success.
342331 getNextToken(); // eat ')'.
343332
344 return helper::make_unique(FnName, std::move(ArgNames));
333 return llvm::make_unique(FnName, std::move(ArgNames));
345334 }
346335
347336 /// definition ::= 'def' prototype expression
352341 return nullptr;
353342
354343 if (auto E = ParseExpression())
355 return helper::make_unique(std::move(Proto), std::move(E));
344 return llvm::make_unique(std::move(Proto), std::move(E));
356345 return nullptr;
357346 }
358347
360349 static std::unique_ptr ParseTopLevelExpr() {
361350 if (auto E = ParseExpression()) {
362351 // Make an anonymous proto.
363 auto Proto = helper::make_unique("__anon_expr",
364 std::vector());
365 return helper::make_unique(std::move(Proto), std::move(E));
352 auto Proto = llvm::make_unique("__anon_expr",
353 std::vector());
354 return llvm::make_unique(std::move(Proto), std::move(E));
366355 }
367356 return nullptr;
368357 }