[Examples] Fix some Clang-tidy modernize-use-default and Include What You Use warnings; other minor fixes.
Differential revision: https://reviews.llvm.org/D26433
llvm-svn: 287384
diff --git a/llvm/examples/Kaleidoscope/Chapter8/toy.cpp b/llvm/examples/Kaleidoscope/Chapter8/toy.cpp
index f880bb8..f7bb814 100644
--- a/llvm/examples/Kaleidoscope/Chapter8/toy.cpp
+++ b/llvm/examples/Kaleidoscope/Chapter8/toy.cpp
@@ -1,26 +1,33 @@
#include "llvm/ADT/APFloat.h"
+#include "llvm/ADT/Optional.h"
#include "llvm/ADT/STLExtras.h"
-#include "llvm/ADT/SmallVector.h"
-#include "llvm/Analysis/Passes.h"
+#include "llvm/IR/BasicBlock.h"
+#include "llvm/IR/Constants.h"
+#include "llvm/IR/DerivedTypes.h"
+#include "llvm/IR/Function.h"
+#include "llvm/IR/Instructions.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/LegacyPassManager.h"
-#include "llvm/IR/Metadata.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Type.h"
#include "llvm/IR/Verifier.h"
#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/Host.h"
+#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/TargetRegistry.h"
#include "llvm/Support/TargetSelect.h"
#include "llvm/Target/TargetMachine.h"
#include "llvm/Target/TargetOptions.h"
-#include "llvm/Transforms/Scalar.h"
+#include <algorithm>
+#include <cassert>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <map>
#include <memory>
#include <string>
+#include <system_error>
#include <utility>
#include <vector>
@@ -132,11 +139,14 @@
//===----------------------------------------------------------------------===//
// Abstract Syntax Tree (aka Parse Tree)
//===----------------------------------------------------------------------===//
+
namespace {
+
/// ExprAST - Base class for all expression nodes.
class ExprAST {
public:
- virtual ~ExprAST() {}
+ virtual ~ExprAST() = default;
+
virtual Value *codegen() = 0;
};
@@ -146,6 +156,7 @@
public:
NumberExprAST(double Val) : Val(Val) {}
+
Value *codegen() override;
};
@@ -155,8 +166,9 @@
public:
VariableExprAST(const std::string &Name) : Name(Name) {}
- const std::string &getName() const { return Name; }
+
Value *codegen() override;
+ const std::string &getName() const { return Name; }
};
/// UnaryExprAST - Expression class for a unary operator.
@@ -167,6 +179,7 @@
public:
UnaryExprAST(char Opcode, std::unique_ptr<ExprAST> Operand)
: Opcode(Opcode), Operand(std::move(Operand)) {}
+
Value *codegen() override;
};
@@ -179,6 +192,7 @@
BinaryExprAST(char Op, std::unique_ptr<ExprAST> LHS,
std::unique_ptr<ExprAST> RHS)
: Op(Op), LHS(std::move(LHS)), RHS(std::move(RHS)) {}
+
Value *codegen() override;
};
@@ -191,6 +205,7 @@
CallExprAST(const std::string &Callee,
std::vector<std::unique_ptr<ExprAST>> Args)
: Callee(Callee), Args(std::move(Args)) {}
+
Value *codegen() override;
};
@@ -202,6 +217,7 @@
IfExprAST(std::unique_ptr<ExprAST> Cond, std::unique_ptr<ExprAST> Then,
std::unique_ptr<ExprAST> Else)
: Cond(std::move(Cond)), Then(std::move(Then)), Else(std::move(Else)) {}
+
Value *codegen() override;
};
@@ -216,6 +232,7 @@
std::unique_ptr<ExprAST> Body)
: VarName(VarName), Start(std::move(Start)), End(std::move(End)),
Step(std::move(Step)), Body(std::move(Body)) {}
+
Value *codegen() override;
};
@@ -229,6 +246,7 @@
std::vector<std::pair<std::string, std::unique_ptr<ExprAST>>> VarNames,
std::unique_ptr<ExprAST> Body)
: VarNames(std::move(VarNames)), Body(std::move(Body)) {}
+
Value *codegen() override;
};
@@ -246,6 +264,7 @@
bool IsOperator = false, unsigned Prec = 0)
: Name(Name), Args(std::move(Args)), IsOperator(IsOperator),
Precedence(Prec) {}
+
Function *codegen();
const std::string &getName() const { return Name; }
@@ -269,8 +288,10 @@
FunctionAST(std::unique_ptr<PrototypeAST> Proto,
std::unique_ptr<ExprAST> Body)
: Proto(std::move(Proto)), Body(std::move(Body)) {}
+
Function *codegen();
};
+
} // end anonymous namespace
//===----------------------------------------------------------------------===//