+#include "llvm/ADT/STLExtras.h"
#include <cctype>
#include <cstdio>
#include <cstdlib>
#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
//===----------------------------------------------------------------------===//
/// 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);
}
getNextToken(); // eat identifier.
if (CurTok != '(') // Simple variable ref.
- return helper::make_unique<VariableExprAST>(IdName);
+ return llvm::make_unique<VariableExprAST>(IdName);
// Call.
getNextToken(); // eat (
// Eat the ')'.
getNextToken();
- return helper::make_unique<CallExprAST>(IdName, std::move(Args));
+ return llvm::make_unique<CallExprAST>(IdName, std::move(Args));
}
/// primary
}
// 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));
}
}
// 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
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;
}
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;
}