[llvm] r281945 - [Kaleidoscope] Make Chapter 2 use llvm::make_unique, rather than a helper.

Lang Hames via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 19 16:00:27 PDT 2016


Author: lhames
Date: Mon Sep 19 18:00:27 2016
New Revision: 281945

URL: http://llvm.org/viewvc/llvm-project?rev=281945&view=rev
Log:
[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.


Modified:
    llvm/trunk/examples/Kaleidoscope/Chapter2/CMakeLists.txt
    llvm/trunk/examples/Kaleidoscope/Chapter2/toy.cpp

Modified: llvm/trunk/examples/Kaleidoscope/Chapter2/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/examples/Kaleidoscope/Chapter2/CMakeLists.txt?rev=281945&r1=281944&r2=281945&view=diff
==============================================================================
--- llvm/trunk/examples/Kaleidoscope/Chapter2/CMakeLists.txt (original)
+++ llvm/trunk/examples/Kaleidoscope/Chapter2/CMakeLists.txt Mon Sep 19 18:00:27 2016
@@ -1,3 +1,7 @@
+set(LLVM_LINK_COMPONENTS
+  Support
+  )
+
 add_kaleidoscope_chapter(Kaleidoscope-Ch2
   toy.cpp
   )

Modified: llvm/trunk/examples/Kaleidoscope/Chapter2/toy.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/examples/Kaleidoscope/Chapter2/toy.cpp?rev=281945&r1=281944&r2=281945&view=diff
==============================================================================
--- llvm/trunk/examples/Kaleidoscope/Chapter2/toy.cpp (original)
+++ llvm/trunk/examples/Kaleidoscope/Chapter2/toy.cpp Mon Sep 19 18:00:27 2016
@@ -1,3 +1,4 @@
+#include "llvm/ADT/STLExtras.h"
 #include <cctype>
 #include <cstdio>
 #include <cstdlib>
@@ -6,18 +7,6 @@
 #include <string>
 #include <vector>
 
-namespace helper {
-// Cloning make_unique here until it's standard in C++14.
-// Using a namespace to avoid conflicting with MSVC's std::make_unique (which
-// ADL can sometimes find in unqualified calls).
-template <class T, class... Args>
-static
-    typename std::enable_if<!std::is_array<T>::value, std::unique_ptr<T>>::type
-    make_unique(Args &&... args) {
-  return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
-}
-} // end namespace helper
-
 //===----------------------------------------------------------------------===//
 // Lexer
 //===----------------------------------------------------------------------===//
@@ -202,7 +191,7 @@ static std::unique_ptr<ExprAST> ParseExp
 
 /// numberexpr ::= number
 static std::unique_ptr<ExprAST> ParseNumberExpr() {
-  auto Result = helper::make_unique<NumberExprAST>(NumVal);
+  auto Result = llvm::make_unique<NumberExprAST>(NumVal);
   getNextToken(); // consume the number
   return std::move(Result);
 }
@@ -229,7 +218,7 @@ static std::unique_ptr<ExprAST> ParseIde
   getNextToken(); // eat identifier.
 
   if (CurTok != '(') // Simple variable ref.
-    return helper::make_unique<VariableExprAST>(IdName);
+    return llvm::make_unique<VariableExprAST>(IdName);
 
   // Call.
   getNextToken(); // eat (
@@ -253,7 +242,7 @@ static std::unique_ptr<ExprAST> ParseIde
   // Eat the ')'.
   getNextToken();
 
-  return helper::make_unique<CallExprAST>(IdName, std::move(Args));
+  return llvm::make_unique<CallExprAST>(IdName, std::move(Args));
 }
 
 /// primary
@@ -305,8 +294,8 @@ static std::unique_ptr<ExprAST> ParseBin
     }
 
     // Merge LHS/RHS.
-    LHS = helper::make_unique<BinaryExprAST>(BinOp, std::move(LHS),
-                                             std::move(RHS));
+    LHS = llvm::make_unique<BinaryExprAST>(BinOp, std::move(LHS),
+                                           std::move(RHS));
   }
 }
 
@@ -342,7 +331,7 @@ static std::unique_ptr<PrototypeAST> Par
   // success.
   getNextToken(); // eat ')'.
 
-  return helper::make_unique<PrototypeAST>(FnName, std::move(ArgNames));
+  return llvm::make_unique<PrototypeAST>(FnName, std::move(ArgNames));
 }
 
 /// definition ::= 'def' prototype expression
@@ -353,7 +342,7 @@ static std::unique_ptr<FunctionAST> Pars
     return nullptr;
 
   if (auto E = ParseExpression())
-    return helper::make_unique<FunctionAST>(std::move(Proto), std::move(E));
+    return llvm::make_unique<FunctionAST>(std::move(Proto), std::move(E));
   return nullptr;
 }
 
@@ -361,9 +350,9 @@ static std::unique_ptr<FunctionAST> Pars
 static std::unique_ptr<FunctionAST> ParseTopLevelExpr() {
   if (auto E = ParseExpression()) {
     // Make an anonymous proto.
-    auto Proto = helper::make_unique<PrototypeAST>("__anon_expr",
-                                                   std::vector<std::string>());
-    return helper::make_unique<FunctionAST>(std::move(Proto), std::move(E));
+    auto Proto = llvm::make_unique<PrototypeAST>("__anon_expr",
+                                                 std::vector<std::string>());
+    return llvm::make_unique<FunctionAST>(std::move(Proto), std::move(E));
   }
   return nullptr;
 }




More information about the llvm-commits mailing list