From 6ea735843647ce000bfafd3f01dda27fb9c48000 Mon Sep 17 00:00:00 2001 From: David Blaikie Date: Tue, 3 Nov 2015 16:23:21 +0000 Subject: [PATCH] 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 --- examples/Kaleidoscope/Chapter2/toy.cpp | 34 +++++++++++++++++--------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/examples/Kaleidoscope/Chapter2/toy.cpp b/examples/Kaleidoscope/Chapter2/toy.cpp index bcba554b246..69f35996129 100644 --- a/examples/Kaleidoscope/Chapter2/toy.cpp +++ b/examples/Kaleidoscope/Chapter2/toy.cpp @@ -1,10 +1,22 @@ -#include "llvm/ADT/STLExtras.h" #include #include #include +#include #include #include +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 +static + typename std::enable_if::value, std::unique_ptr>::type + make_unique(Args &&... args) { + return std::unique_ptr(new T(std::forward(args)...)); +} +} + //===----------------------------------------------------------------------===// // Lexer //===----------------------------------------------------------------------===// @@ -189,7 +201,7 @@ static std::unique_ptr ParseExpression(); /// numberexpr ::= number static std::unique_ptr ParseNumberExpr() { - auto Result = llvm::make_unique(NumVal); + auto Result = helper::make_unique(NumVal); getNextToken(); // consume the number return std::move(Result); } @@ -216,7 +228,7 @@ static std::unique_ptr ParseIdentifierExpr() { getNextToken(); // eat identifier. if (CurTok != '(') // Simple variable ref. - return llvm::make_unique(IdName); + return helper::make_unique(IdName); // Call. getNextToken(); // eat ( @@ -240,7 +252,7 @@ static std::unique_ptr ParseIdentifierExpr() { // Eat the ')'. getNextToken(); - return llvm::make_unique(IdName, std::move(Args)); + return helper::make_unique(IdName, std::move(Args)); } /// primary @@ -292,8 +304,8 @@ static std::unique_ptr ParseBinOpRHS(int ExprPrec, } // Merge LHS/RHS. - LHS = - llvm::make_unique(BinOp, std::move(LHS), std::move(RHS)); + LHS = helper::make_unique(BinOp, std::move(LHS), + std::move(RHS)); } } @@ -329,7 +341,7 @@ static std::unique_ptr ParsePrototype() { // success. getNextToken(); // eat ')'. - return llvm::make_unique(FnName, std::move(ArgNames)); + return helper::make_unique(FnName, std::move(ArgNames)); } /// definition ::= 'def' prototype expression @@ -340,7 +352,7 @@ static std::unique_ptr ParseDefinition() { return nullptr; if (auto E = ParseExpression()) - return llvm::make_unique(std::move(Proto), std::move(E)); + return helper::make_unique(std::move(Proto), std::move(E)); return nullptr; } @@ -348,9 +360,9 @@ static std::unique_ptr ParseDefinition() { static std::unique_ptr ParseTopLevelExpr() { if (auto E = ParseExpression()) { // Make an anonymous proto. - auto Proto = llvm::make_unique("__anon_expr", - std::vector()); - return llvm::make_unique(std::move(Proto), std::move(E)); + auto Proto = helper::make_unique("__anon_expr", + std::vector()); + return helper::make_unique(std::move(Proto), std::move(E)); } return nullptr; } -- 2.34.1