[Kaleidoscope] Clang-format the Kaleidoscope tutorials.

Also reduces changes between tutorial chapters.

llvm-svn: 245472
diff --git a/llvm/docs/tutorial/LangImpl1.rst b/llvm/docs/tutorial/LangImpl1.rst
index 6840bd6..0240986 100644
--- a/llvm/docs/tutorial/LangImpl1.rst
+++ b/llvm/docs/tutorial/LangImpl1.rst
@@ -169,14 +169,16 @@
       tok_eof = -1,
 
       // commands
-      tok_def = -2, tok_extern = -3,
+      tok_def = -2,
+      tok_extern = -3,
 
       // primary
-      tok_identifier = -4, tok_number = -5,
+      tok_identifier = -4,
+      tok_number = -5,
     };
 
-    static std::string IdentifierStr;  // Filled in if tok_identifier
-    static double NumVal;              // Filled in if tok_number
+    static std::string IdentifierStr; // Filled in if tok_identifier
+    static double NumVal;             // Filled in if tok_number
 
 Each token returned by our lexer will either be one of the Token enum
 values or it will be an 'unknown' character like '+', which is returned
@@ -217,8 +219,10 @@
         while (isalnum((LastChar = getchar())))
           IdentifierStr += LastChar;
 
-        if (IdentifierStr == "def") return tok_def;
-        if (IdentifierStr == "extern") return tok_extern;
+        if (IdentifierStr == "def")
+          return tok_def;
+        if (IdentifierStr == "extern")
+          return tok_extern;
         return tok_identifier;
       }
 
@@ -250,7 +254,8 @@
 
       if (LastChar == '#') {
         // Comment until end of line.
-        do LastChar = getchar();
+        do
+          LastChar = getchar();
         while (LastChar != EOF && LastChar != '\n' && LastChar != '\r');
 
         if (LastChar != EOF)
diff --git a/llvm/docs/tutorial/LangImpl2.rst b/llvm/docs/tutorial/LangImpl2.rst
index 4b28e02..09c55e6 100644
--- a/llvm/docs/tutorial/LangImpl2.rst
+++ b/llvm/docs/tutorial/LangImpl2.rst
@@ -44,6 +44,7 @@
     /// NumberExprAST - Expression class for numeric literals like "1.0".
     class NumberExprAST : public ExprAST {
       double Val;
+
     public:
       NumberExprAST(double Val) : Val(Val) {}
     };
@@ -65,6 +66,7 @@
     /// VariableExprAST - Expression class for referencing a variable, like "a".
     class VariableExprAST : public ExprAST {
       std::string Name;
+
     public:
       VariableExprAST(const std::string &Name) : Name(Name) {}
     };
@@ -73,6 +75,7 @@
     class BinaryExprAST : public ExprAST {
       char Op;
       std::unique_ptr<ExprAST> LHS, RHS;
+
     public:
       BinaryExprAST(char op, std::unique_ptr<ExprAST> LHS,
                     std::unique_ptr<ExprAST> RHS)
@@ -83,6 +86,7 @@
     class CallExprAST : public ExprAST {
       std::string Callee;
       std::vector<ExprAST*> Args;
+
     public:
       CallExprAST(const std::string &Callee,
                   std::vector<std::unique_ptr<ExprAST>> Args)
@@ -111,6 +115,7 @@
     class PrototypeAST {
       std::string Name;
       std::vector<std::string> Args;
+
     public:
       PrototypeAST(const std::string &name, std::vector<std::string> Args)
         : Name(name), Args(std::move(Args)) {}
@@ -120,6 +125,7 @@
     class FunctionAST {
       std::unique_ptr<PrototypeAST> Proto;
       std::unique_ptr<ExprAST> Body;
+
     public:
       FunctionAST(std::unique_ptr<PrototypeAST> Proto,
                   std::unique_ptr<ExprAST> Body)
@@ -171,9 +177,14 @@
 
 
     /// Error* - These are little helper functions for error handling.
-    ExprAST *Error(const char *Str) { fprintf(stderr, "Error: %s\n", Str);return 0;}
-    PrototypeAST *ErrorP(const char *Str) { Error(Str); return 0; }
-    FunctionAST *ErrorF(const char *Str) { Error(Str); return 0; }
+    std::unique_ptr<ExprAST> Error(const char *Str) {
+      fprintf(stderr, "Error: %s\n", Str);
+      return nullptr;
+    }
+    std::unique_ptr<PrototypeAST> ErrorP(const char *Str) {
+      Error(Str);
+      return nullptr;
+    }
 
 The ``Error`` routines are simple helper routines that our parser will
 use to handle errors. The error recovery in our parser will not be the
@@ -216,13 +227,14 @@
 
     /// parenexpr ::= '(' expression ')'
     static std::unique_ptr<ExprAST> ParseParenExpr() {
-      getNextToken();  // eat (.
+      getNextToken(); // eat (.
       auto V = ParseExpression();
-      if (!V) return nullptr;
+      if (!V)
+        return nullptr;
 
       if (CurTok != ')')
         return Error("expected ')'");
-      getNextToken();  // eat ).
+      getNextToken(); // eat ).
       return V;
     }
 
@@ -267,11 +279,13 @@
       std::vector<std::unique_ptr<ExprAST>> Args;
       if (CurTok != ')') {
         while (1) {
-          auto Arg = ParseExpression();
-          if (!Arg) return nullptr;
-          Args.push_back(std::move(Arg));
+          if (auto Arg = ParseExpression())
+            Args.push_back(std::move(Arg));
+          else
+            return nullptr;
 
-          if (CurTok == ')') break;
+          if (CurTok == ')')
+            break;
 
           if (CurTok != ',')
             return Error("Expected ')' or ',' in argument list");
@@ -309,10 +323,14 @@
     ///   ::= parenexpr
     static std::unique_ptr<ExprAST> ParsePrimary() {
       switch (CurTok) {
-      default: return Error("unknown token when expecting an expression");
-      case tok_identifier: return ParseIdentifierExpr();
-      case tok_number:     return ParseNumberExpr();
-      case '(':            return ParseParenExpr();
+      default:
+        return Error("unknown token when expecting an expression");
+      case tok_identifier:
+        return ParseIdentifierExpr();
+      case tok_number:
+        return ParseNumberExpr();
+      case '(':
+        return ParseParenExpr();
       }
     }
 
@@ -396,7 +414,8 @@
     ///
     static std::unique_ptr<ExprAST> ParseExpression() {
       auto LHS = ParsePrimary();
-      if (!LHS) return nullptr;
+      if (!LHS)
+        return nullptr;
 
       return ParseBinOpRHS(0, std::move(LHS));
     }
@@ -446,7 +465,8 @@
 
         // Parse the primary expression after the binary operator.
         auto RHS = ParsePrimary();
-        if (!RHS) return nullptr;
+        if (!RHS)
+          return nullptr;
 
 As such, this code eats (and remembers) the binary operator and then
 parses the primary expression that follows. This builds up the whole
@@ -505,7 +525,8 @@
         int NextPrec = GetTokPrecedence();
         if (TokPrec < NextPrec) {
           RHS = ParseBinOpRHS(TokPrec+1, std::move(RHS));
-          if (RHS == 0) return 0;
+          if (!RHS)
+            return nullptr;
         }
         // Merge LHS/RHS.
         LHS = llvm::make_unique<BinaryExprAST>(BinOp, std::move(LHS),
@@ -633,11 +654,20 @@
       while (1) {
         fprintf(stderr, "ready> ");
         switch (CurTok) {
-        case tok_eof:    return;
-        case ';':        getNextToken(); break;  // ignore top-level semicolons.
-        case tok_def:    HandleDefinition(); break;
-        case tok_extern: HandleExtern(); break;
-        default:         HandleTopLevelExpression(); break;
+        case tok_eof:
+          return;
+        case ';': // ignore top-level semicolons.
+          getNextToken();
+          break;
+        case tok_def:
+          HandleDefinition();
+          break;
+        case tok_extern:
+          HandleExtern();
+          break;
+        default:
+          HandleTopLevelExpression();
+          break;
         }
       }
     }
diff --git a/llvm/docs/tutorial/LangImpl3.rst b/llvm/docs/tutorial/LangImpl3.rst
index 0920aa3..a2d23e7 100644
--- a/llvm/docs/tutorial/LangImpl3.rst
+++ b/llvm/docs/tutorial/LangImpl3.rst
@@ -41,6 +41,7 @@
     /// NumberExprAST - Expression class for numeric literals like "1.0".
     class NumberExprAST : public ExprAST {
       double Val;
+
     public:
       NumberExprAST(double Val) : Val(Val) {}
       virtual Value *Codegen();
@@ -72,7 +73,10 @@
 
 .. code-block:: c++
 
-    Value *ErrorV(const char *Str) { Error(Str); return 0; }
+    Value *ErrorV(const char *Str) {
+      Error(Str);
+      return nullptr;
+    }
 
     static Module *TheModule;
     static IRBuilder<> Builder(getGlobalContext());
@@ -145,18 +149,23 @@
     Value *BinaryExprAST::Codegen() {
       Value *L = LHS->Codegen();
       Value *R = RHS->Codegen();
-      if (L == 0 || R == 0) return 0;
+      if (!L || !R)
+        return nullptr;
 
       switch (Op) {
-      case '+': return Builder.CreateFAdd(L, R, "addtmp");
-      case '-': return Builder.CreateFSub(L, R, "subtmp");
-      case '*': return Builder.CreateFMul(L, R, "multmp");
+      case '+':
+        return Builder.CreateFAdd(L, R, "addtmp");
+      case '-':
+        return Builder.CreateFSub(L, R, "subtmp");
+      case '*':
+        return Builder.CreateFMul(L, R, "multmp");
       case '<':
         L = Builder.CreateFCmpULT(L, R, "cmptmp");
         // Convert bool 0/1 to double 0.0 or 1.0
         return Builder.CreateUIToFP(L, Type::getDoubleTy(getGlobalContext()),
                                     "booltmp");
-      default: return ErrorV("invalid binary operator");
+      default:
+        return ErrorV("invalid binary operator");
       }
     }
 
@@ -201,17 +210,18 @@
     Value *CallExprAST::Codegen() {
       // Look up the name in the global module table.
       Function *CalleeF = TheModule->getFunction(Callee);
-      if (CalleeF == 0)
+      if (!CalleeF)
         return ErrorV("Unknown function referenced");
 
       // If argument mismatch error.
       if (CalleeF->arg_size() != Args.size())
         return ErrorV("Incorrect # arguments passed");
 
-      std::vector<Value*> ArgsV;
+      std::vector<Value *> ArgsV;
       for (unsigned i = 0, e = Args.size(); i != e; ++i) {
         ArgsV.push_back(Args[i]->Codegen());
-        if (ArgsV.back() == 0) return 0;
+        if (!ArgsV.back())
+          return nullptr;
       }
 
       return Builder.CreateCall(CalleeF, ArgsV, "calltmp");
@@ -253,10 +263,11 @@
       // Make the function type:  double(double,double) etc.
       std::vector<Type*> Doubles(Args.size(),
                                  Type::getDoubleTy(getGlobalContext()));
-      FunctionType *FT = FunctionType::get(Type::getDoubleTy(getGlobalContext()),
-                                           Doubles, false);
+      FunctionType *FT =
+        FunctionType::get(Type::getDoubleTy(getGlobalContext()), Doubles, false);
 
-      Function *F = Function::Create(FT, Function::ExternalLinkage, Name, TheModule);
+      Function *F =
+        Function::Create(FT, Function::ExternalLinkage, Name, TheModule);
 
 This code packs a lot of power into a few lines. Note first that this
 function returns a "Function\*" instead of a "Value\*". Because a
@@ -321,13 +332,13 @@
         // If F already has a body, reject this.
         if (!F->empty()) {
           ErrorF("redefinition of function");
-          return 0;
+          return nullptr;
         }
 
         // If F took a different number of args, reject.
         if (F->arg_size() != Args.size()) {
           ErrorF("redefinition of function with different # args");
-          return 0;
+          return nullptr;
         }
       }
 
@@ -351,6 +362,7 @@
         // Add arguments to variable symbol table.
         NamedValues[Args[Idx]] = AI;
       }
+
       return F;
     }
 
@@ -368,8 +380,8 @@
       NamedValues.clear();
 
       Function *TheFunction = Proto->Codegen();
-      if (TheFunction == 0)
-        return 0;
+      if (!TheFunction)
+        return nullptr;
 
 Code generation for function definitions starts out simply enough: we
 just codegen the prototype (Proto) and verify that it is ok. We then
@@ -423,7 +435,7 @@
 
       // Error reading body, remove function.
       TheFunction->eraseFromParent();
-      return 0;
+      return nullptr;
     }
 
 The only piece left here is handling of the error case. For simplicity,
diff --git a/llvm/docs/tutorial/LangImpl4.rst b/llvm/docs/tutorial/LangImpl4.rst
index 8abb745..497a4c5 100644
--- a/llvm/docs/tutorial/LangImpl4.rst
+++ b/llvm/docs/tutorial/LangImpl4.rst
@@ -400,8 +400,7 @@
 .. code-block:: c++
 
     /// putchard - putchar that takes a double and returns 0.
-    extern "C"
-    double putchard(double X) {
+    extern "C" double putchard(double X) {
       putchar((char)X);
       return 0;
     }
diff --git a/llvm/docs/tutorial/LangImpl5.rst b/llvm/docs/tutorial/LangImpl5.rst
index add0e18..c0420fa 100644
--- a/llvm/docs/tutorial/LangImpl5.rst
+++ b/llvm/docs/tutorial/LangImpl5.rst
@@ -66,7 +66,9 @@
 .. code-block:: c++
 
       // control
-      tok_if = -6, tok_then = -7, tok_else = -8,
+      tok_if = -6,
+      tok_then = -7,
+      tok_else = -8,
 
 Once we have that, we recognize the new keywords in the lexer. This is
 pretty simple stuff:
@@ -74,11 +76,16 @@
 .. code-block:: c++
 
         ...
-        if (IdentifierStr == "def") return tok_def;
-        if (IdentifierStr == "extern") return tok_extern;
-        if (IdentifierStr == "if") return tok_if;
-        if (IdentifierStr == "then") return tok_then;
-        if (IdentifierStr == "else") return tok_else;
+        if (IdentifierStr == "def")
+          return tok_def;
+        if (IdentifierStr == "extern")
+          return tok_extern;
+        if (IdentifierStr == "if")
+          return tok_if;
+        if (IdentifierStr == "then")
+          return tok_then;
+        if (IdentifierStr == "else")
+          return tok_else;
         return tok_identifier;
 
 AST Extensions for If/Then/Else
@@ -91,6 +98,7 @@
     /// IfExprAST - Expression class for if/then/else.
     class IfExprAST : public ExprAST {
       std::unique<ExprAST> Cond, Then, Else;
+
     public:
       IfExprAST(std::unique_ptr<ExprAST> Cond, std::unique_ptr<ExprAST> Then,
                 std::unique_ptr<ExprAST> Else)
@@ -115,14 +123,16 @@
 
       // condition.
       auto Cond = ParseExpression();
-      if (!Cond) return nullptr;
+      if (!Cond)
+        return nullptr;
 
       if (CurTok != tok_then)
         return Error("expected then");
       getNextToken();  // eat the then
 
       auto Then = ParseExpression();
-      if (Then) return nullptr;
+      if (!Then)
+        return nullptr;
 
       if (CurTok != tok_else)
         return Error("expected else");
@@ -130,7 +140,8 @@
       getNextToken();
 
       auto Else = ParseExpression();
-      if (!Else) return nullptr;
+      if (!Else)
+        return nullptr;
 
       return llvm::make_unique<IfExprAST>(std::move(Cond), std::move(Then),
                                           std::move(Else));
@@ -142,11 +153,16 @@
 
     static std::unique_ptr<ExprAST> ParsePrimary() {
       switch (CurTok) {
-      default: return Error("unknown token when expecting an expression");
-      case tok_identifier: return ParseIdentifierExpr();
-      case tok_number:     return ParseNumberExpr();
-      case '(':            return ParseParenExpr();
-      case tok_if:         return ParseIfExpr();
+      default:
+        return Error("unknown token when expecting an expression");
+      case tok_identifier:
+        return ParseIdentifierExpr();
+      case tok_number:
+        return ParseNumberExpr();
+      case '(':
+        return ParseParenExpr();
+      case tok_if:
+        return ParseIfExpr();
       }
     }
 
@@ -271,12 +287,12 @@
 
     Value *IfExprAST::Codegen() {
       Value *CondV = Cond->Codegen();
-      if (!CondV) return nullptr;
+      if (!CondV)
+        return nullptr;
 
       // Convert condition to a bool by comparing equal to 0.0.
-      CondV = Builder.CreateFCmpONE(CondV,
-                                  ConstantFP::get(getGlobalContext(), APFloat(0.0)),
-                                    "ifcond");
+      CondV = Builder.CreateFCmpONE(
+          CondV, ConstantFP::get(getGlobalContext(), APFloat(0.0)), "ifcond");
 
 This code is straightforward and similar to what we saw before. We emit
 the expression for the condition, then compare that value to zero to get
@@ -288,7 +304,8 @@
 
       // Create blocks for the then and else cases.  Insert the 'then' block at the
       // end of the function.
-      BasicBlock *ThenBB = BasicBlock::Create(getGlobalContext(), "then", TheFunction);
+      BasicBlock *ThenBB =
+          BasicBlock::Create(getGlobalContext(), "then", TheFunction);
       BasicBlock *ElseBB = BasicBlock::Create(getGlobalContext(), "else");
       BasicBlock *MergeBB = BasicBlock::Create(getGlobalContext(), "ifcont");
 
@@ -321,7 +338,8 @@
       Builder.SetInsertPoint(ThenBB);
 
       Value *ThenV = Then->Codegen();
-      if (ThenV == 0) return 0;
+      if (!ThenV)
+        return nullptr;
 
       Builder.CreateBr(MergeBB);
       // Codegen of 'Then' can change the current block, update ThenBB for the PHI.
@@ -362,7 +380,8 @@
       Builder.SetInsertPoint(ElseBB);
 
       Value *ElseV = Else->Codegen();
-      if (ElseV == 0) return 0;
+      if (!ElseV)
+        return nullptr;
 
       Builder.CreateBr(MergeBB);
       // Codegen of 'Else' can change the current block, update ElseBB for the PHI.
@@ -380,8 +399,8 @@
       // Emit merge block.
       TheFunction->getBasicBlockList().push_back(MergeBB);
       Builder.SetInsertPoint(MergeBB);
-      PHINode *PN = Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()), 2,
-                                      "iftmp");
+      PHINode *PN =
+        Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()), 2, "iftmp");
 
       PN->addIncoming(ThenV, ThenBB);
       PN->addIncoming(ElseV, ElseBB);
@@ -446,13 +465,20 @@
       tok_for = -9, tok_in = -10
 
       ... in gettok ...
-      if (IdentifierStr == "def") return tok_def;
-      if (IdentifierStr == "extern") return tok_extern;
-      if (IdentifierStr == "if") return tok_if;
-      if (IdentifierStr == "then") return tok_then;
-      if (IdentifierStr == "else") return tok_else;
-      if (IdentifierStr == "for") return tok_for;
-      if (IdentifierStr == "in") return tok_in;
+      if (IdentifierStr == "def")
+        return tok_def;
+      if (IdentifierStr == "extern")
+        return tok_extern;
+      if (IdentifierStr == "if")
+        return tok_if;
+      if (IdentifierStr == "then")
+        return tok_then;
+      if (IdentifierStr == "else")
+        return tok_else;
+      if (IdentifierStr == "for")
+        return tok_for;
+      if (IdentifierStr == "in")
+        return tok_in;
       return tok_identifier;
 
 AST Extensions for the 'for' Loop
@@ -467,6 +493,7 @@
     class ForExprAST : public ExprAST {
       std::string VarName;
       std::unique_ptr<ExprAST> Start, End, Step, Body;
+
     public:
       ForExprAST(const std::string &VarName, std::unique_ptr<ExprAST> Start,
                  std::unique_ptr<ExprAST> End, std::unique_ptr<ExprAST> Step,
@@ -502,20 +529,23 @@
 
 
       auto Start = ParseExpression();
-      if (!Start) return nullptr;
+      if (!Start)
+        return nullptr;
       if (CurTok != ',')
         return Error("expected ',' after for start value");
       getNextToken();
 
       auto End = ParseExpression();
-      if (!End) return nullptr;
+      if (!End)
+        return nullptr;
 
       // The step value is optional.
       std::unique_ptr<ExprAST> Step;
       if (CurTok == ',') {
         getNextToken();
         Step = ParseExpression();
-        if (!Step) return nullptr;
+        if (!Step)
+          return nullptr;
       }
 
       if (CurTok != tok_in)
@@ -523,7 +553,8 @@
       getNextToken();  // eat 'in'.
 
       auto Body = ParseExpression();
-      if (!Body) return nullptr;
+      if (!Body)
+        return nullptr;
 
       return llvm::make_unique<ForExprAST>(IdName, std::move(Start),
                                            std::move(End), std::move(Step),
@@ -593,7 +624,8 @@
       // block.
       Function *TheFunction = Builder.GetInsertBlock()->getParent();
       BasicBlock *PreheaderBB = Builder.GetInsertBlock();
-      BasicBlock *LoopBB = BasicBlock::Create(getGlobalContext(), "loop", TheFunction);
+      BasicBlock *LoopBB =
+          BasicBlock::Create(getGlobalContext(), "loop", TheFunction);
 
       // Insert an explicit fall through from the current block to the LoopBB.
       Builder.CreateBr(LoopBB);
@@ -610,7 +642,8 @@
       Builder.SetInsertPoint(LoopBB);
 
       // Start the PHI node with an entry for Start.
-      PHINode *Variable = Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()), 2, VarName.c_str());
+      PHINode *Variable = Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()),
+                                            2, VarName.c_str());
       Variable->addIncoming(StartVal, PreheaderBB);
 
 Now that the "preheader" for the loop is set up, we switch to emitting
@@ -630,8 +663,8 @@
       // Emit the body of the loop.  This, like any other expr, can change the
       // current BB.  Note that we ignore the value computed by the body, but don't
       // allow an error.
-      if (Body->Codegen() == 0)
-        return 0;
+      if (!Body->Codegen())
+        return nullptr;
 
 Now the code starts to get more interesting. Our 'for' loop introduces a
 new variable to the symbol table. This means that our symbol table can
@@ -653,10 +686,11 @@
 .. code-block:: c++
 
       // Emit the step value.
-      Value *StepVal;
+      Value *StepVal = nullptr;
       if (Step) {
         StepVal = Step->Codegen();
-        if (StepVal == 0) return 0;
+        if (!StepVal)
+          return nullptr;
       } else {
         // If not specified, use 1.0.
         StepVal = ConstantFP::get(getGlobalContext(), APFloat(1.0));
@@ -673,12 +707,12 @@
 
       // Compute the end condition.
       Value *EndCond = End->Codegen();
-      if (EndCond == 0) return EndCond;
+      if (!EndCond)
+        return nullptr;
 
       // Convert condition to a bool by comparing equal to 0.0.
-      EndCond = Builder.CreateFCmpONE(EndCond,
-                                  ConstantFP::get(getGlobalContext(), APFloat(0.0)),
-                                      "loopcond");
+      EndCond = Builder.CreateFCmpONE(
+          EndCond, ConstantFP::get(getGlobalContext(), APFloat(0.0)), "loopcond");
 
 Finally, we evaluate the exit value of the loop, to determine whether
 the loop should exit. This mirrors the condition evaluation for the
@@ -688,7 +722,8 @@
 
       // Create the "after loop" block and insert it.
       BasicBlock *LoopEndBB = Builder.GetInsertBlock();
-      BasicBlock *AfterBB = BasicBlock::Create(getGlobalContext(), "afterloop", TheFunction);
+      BasicBlock *AfterBB =
+          BasicBlock::Create(getGlobalContext(), "afterloop", TheFunction);
 
       // Insert the conditional branch into the end of LoopEndBB.
       Builder.CreateCondBr(EndCond, LoopBB, AfterBB);
diff --git a/llvm/docs/tutorial/LangImpl6.rst b/llvm/docs/tutorial/LangImpl6.rst
index b313818..4918cb0 100644
--- a/llvm/docs/tutorial/LangImpl6.rst
+++ b/llvm/docs/tutorial/LangImpl6.rst
@@ -96,15 +96,20 @@
     enum Token {
       ...
       // operators
-      tok_binary = -11, tok_unary = -12
+      tok_binary = -11,
+      tok_unary = -12
     };
     ...
     static int gettok() {
     ...
-        if (IdentifierStr == "for") return tok_for;
-        if (IdentifierStr == "in") return tok_in;
-        if (IdentifierStr == "binary") return tok_binary;
-        if (IdentifierStr == "unary") return tok_unary;
+        if (IdentifierStr == "for")
+          return tok_for;
+        if (IdentifierStr == "in")
+          return tok_in;
+        if (IdentifierStr == "binary")
+          return tok_binary;
+        if (IdentifierStr == "unary")
+          return tok_unary;
         return tok_identifier;
 
 This just adds lexer support for the unary and binary keywords, like we
@@ -131,6 +136,7 @@
       std::vector<std::string> Args;
       bool IsOperator;
       unsigned Precedence;  // Precedence if a binary op.
+
     public:
       PrototypeAST(const std::string &name, std::vector<std::string> Args,
                    bool IsOperator = false, unsigned Prec = 0)
@@ -211,8 +217,8 @@
       if (Kind && ArgNames.size() != Kind)
         return ErrorP("Invalid number of operands for operator");
 
-      return llvm::make_unique<PrototypeAST>(FnName, std::move(ArgNames),
-                                             Kind != 0, BinaryPrecedence);
+      return llvm::make_unique<PrototypeAST>(FnName, std::move(ArgNames), Kind != 0,
+                                             BinaryPrecedence);
     }
 
 This is all fairly straightforward parsing code, and we have already
@@ -232,23 +238,28 @@
     Value *BinaryExprAST::Codegen() {
       Value *L = LHS->Codegen();
       Value *R = RHS->Codegen();
-      if (L == 0 || R == 0) return 0;
+      if (!L || !R)
+        return nullptr;
 
       switch (Op) {
-      case '+': return Builder.CreateFAdd(L, R, "addtmp");
-      case '-': return Builder.CreateFSub(L, R, "subtmp");
-      case '*': return Builder.CreateFMul(L, R, "multmp");
+      case '+':
+        return Builder.CreateFAdd(L, R, "addtmp");
+      case '-':
+        return Builder.CreateFSub(L, R, "subtmp");
+      case '*':
+        return Builder.CreateFMul(L, R, "multmp");
       case '<':
         L = Builder.CreateFCmpULT(L, R, "cmptmp");
         // Convert bool 0/1 to double 0.0 or 1.0
         return Builder.CreateUIToFP(L, Type::getDoubleTy(getGlobalContext()),
                                     "booltmp");
-      default: break;
+      default:
+        break;
       }
 
       // If it wasn't a builtin binary operator, it must be a user defined one. Emit
       // a call to it.
-      Function *F = TheModule->getFunction(std::string("binary")+Op);
+      Function *F = TheModule->getFunction(std::string("binary") + Op);
       assert(F && "binary operator not found!");
 
       Value *Ops[2] = { L, R };
@@ -269,8 +280,8 @@
       NamedValues.clear();
 
       Function *TheFunction = Proto->Codegen();
-      if (TheFunction == 0)
-        return 0;
+      if (!TheFunction)
+        return nullptr;
 
       // If this is an operator, install it.
       if (Proto->isBinaryOp())
@@ -308,6 +319,7 @@
     class UnaryExprAST : public ExprAST {
       char Opcode;
       std::unique_ptr<ExprAST> Operand;
+
     public:
       UnaryExprAST(char Opcode, std::unique_ptr<ExprAST> Operand)
         : Opcode(Opcode), Operand(std::move(Operand)) {}
@@ -357,7 +369,8 @@
       ...
         // Parse the unary expression after the binary operator.
         auto RHS = ParseUnary();
-        if (!RHS) return nullptr;
+        if (!RHS)
+          return nullptr;
       ...
     }
     /// expression
@@ -365,7 +378,8 @@
     ///
     static std::unique_ptr<ExprAST> ParseExpression() {
       auto LHS = ParseUnary();
-      if (!LHS) return nullptr;
+      if (!LHS)
+        return nullptr;
 
       return ParseBinOpRHS(0, std::move(LHS));
     }
@@ -416,10 +430,11 @@
 
     Value *UnaryExprAST::Codegen() {
       Value *OperandV = Operand->Codegen();
-      if (OperandV == 0) return 0;
+      if (!OperandV)
+        return nullptr;
 
       Function *F = TheModule->getFunction(std::string("unary")+Opcode);
-      if (F == 0)
+      if (!F)
         return ErrorV("Unknown unary operator");
 
       return Builder.CreateCall(F, OperandV, "unop");
diff --git a/llvm/docs/tutorial/LangImpl7.rst b/llvm/docs/tutorial/LangImpl7.rst
index 33f4853..8c35f2a 100644
--- a/llvm/docs/tutorial/LangImpl7.rst
+++ b/llvm/docs/tutorial/LangImpl7.rst
@@ -358,7 +358,8 @@
     Value *VariableExprAST::Codegen() {
       // Look this variable up in the function.
       Value *V = NamedValues[Name];
-      if (V == 0) return ErrorV("Unknown variable name");
+      if (!V)
+        return ErrorV("Unknown variable name");
 
       // Load the value.
       return Builder.CreateLoad(V, Name.c_str());
@@ -378,7 +379,8 @@
 
         // Emit the start code first, without 'variable' in scope.
       Value *StartVal = Start->Codegen();
-      if (StartVal == 0) return 0;
+      if (!StartVal)
+        return nullptr;
 
       // Store the value into the alloca.
       Builder.CreateStore(StartVal, Alloca);
@@ -386,7 +388,8 @@
 
       // Compute the end condition.
       Value *EndCond = End->Codegen();
-      if (EndCond == 0) return EndCond;
+      if (!EndCond)
+        return nullptr;
 
       // Reload, increment, and restore the alloca.  This handles the case where
       // the body of the loop mutates the variable.
@@ -588,11 +591,13 @@
 
         // Codegen the RHS.
         Value *Val = RHS->Codegen();
-        if (Val == 0) return 0;
+        if (!Val)
+          return nullptr;
 
         // Look up the name.
         Value *Variable = NamedValues[LHSE->getName()];
-        if (Variable == 0) return ErrorV("Unknown variable name");
+        if (!Variable)
+          return ErrorV("Unknown variable name");
 
         Builder.CreateStore(Val, Variable);
         return Val;
@@ -649,10 +654,14 @@
     ...
     static int gettok() {
     ...
-        if (IdentifierStr == "in") return tok_in;
-        if (IdentifierStr == "binary") return tok_binary;
-        if (IdentifierStr == "unary") return tok_unary;
-        if (IdentifierStr == "var") return tok_var;
+        if (IdentifierStr == "in")
+          return tok_in;
+        if (IdentifierStr == "binary")
+          return tok_binary;
+        if (IdentifierStr == "unary")
+          return tok_unary;
+        if (IdentifierStr == "var")
+          return tok_var;
         return tok_identifier;
     ...
 
@@ -665,6 +674,7 @@
     class VarExprAST : public ExprAST {
       std::vector<std::pair<std::string, std::unique_ptr<ExprAST>>> VarNames;
       std::unique_ptr<ExprAST> Body;
+
     public:
       VarExprAST(std::vector<std::pair<std::string, std::unique_ptr<ExprAST>>> VarNames,
                  std::unique_ptr<ExprAST> body)
@@ -692,13 +702,20 @@
     ///   ::= varexpr
     static std::unique_ptr<ExprAST> ParsePrimary() {
       switch (CurTok) {
-      default: return Error("unknown token when expecting an expression");
-      case tok_identifier: return ParseIdentifierExpr();
-      case tok_number:     return ParseNumberExpr();
-      case '(':            return ParseParenExpr();
-      case tok_if:         return ParseIfExpr();
-      case tok_for:        return ParseForExpr();
-      case tok_var:        return ParseVarExpr();
+      default:
+        return Error("unknown token when expecting an expression");
+      case tok_identifier:
+        return ParseIdentifierExpr();
+      case tok_number:
+        return ParseNumberExpr();
+      case '(':
+        return ParseParenExpr();
+      case tok_if:
+        return ParseIfExpr();
+      case tok_for:
+        return ParseForExpr();
+      case tok_var:
+        return ParseVarExpr();
       }
     }
 
@@ -756,7 +773,8 @@
       getNextToken();  // eat 'in'.
 
       auto Body = ParseExpression();
-      if (!Body) return nullptr;
+      if (!Body)
+        return nullptr;
 
       return llvm::make_unique<VarExprAST>(std::move(VarNames),
                                            std::move(Body));
@@ -791,7 +809,8 @@
         Value *InitVal;
         if (Init) {
           InitVal = Init->Codegen();
-          if (InitVal == 0) return 0;
+          if (!InitVal)
+            return nullptr;
         } else { // If not specified, use 0.0.
           InitVal = ConstantFP::get(getGlobalContext(), APFloat(0.0));
         }
@@ -816,7 +835,8 @@
 
       // Codegen the body, now that all vars are in scope.
       Value *BodyVal = Body->Codegen();
-      if (BodyVal == 0) return 0;
+      if (!BodyVal)
+        return nullptr;
 
 Finally, before returning, we restore the previous variable bindings:
 
diff --git a/llvm/docs/tutorial/LangImpl8.rst b/llvm/docs/tutorial/LangImpl8.rst
index 2f994c2..77e3e42 100644
--- a/llvm/docs/tutorial/LangImpl8.rst
+++ b/llvm/docs/tutorial/LangImpl8.rst
@@ -307,10 +307,12 @@
      SourceLocation Loc;
 
      public:
+       ExprAST(SourceLocation Loc = CurLoc) : Loc(Loc) {}
+       virtual ~ExprAST() {}
+       virtual Value* Codegen() = 0;
        int getLine() const { return Loc.Line; }
        int getCol() const { return Loc.Col; }
-       ExprAST(SourceLocation Loc = CurLoc) : Loc(Loc) {}
-       virtual std::ostream &dump(std::ostream &out, int ind) {
+       virtual raw_ostream &dump(raw_ostream &out, int ind) {
          return out << ':' << getLine() << ':' << getCol() << '\n';
        }
 
@@ -399,9 +401,9 @@
   DILocalVariable D = DBuilder->createParameterVariable(
       Scope, Args[Idx], Idx + 1, Unit, Line, KSDbgInfo.getDoubleTy(), true);
 
-  Instruction *Call = DBuilder->insertDeclare(
-      Alloca, D, DBuilder->createExpression(), Builder.GetInsertBlock());
-  Call->setDebugLoc(DebugLoc::get(Line, 0, Scope));
+  DBuilder->insertDeclare(Alloca, D, DBuilder->createExpression(),
+                          DebugLoc::get(Line, 0, Scope),
+                          Builder.GetInsertBlock());
 
 Here we're doing a few things. First, we're grabbing our current scope
 for the variable so we can say what range of code our variable is valid
@@ -409,7 +411,7 @@
 the name, source location, type, and since it's an argument, the argument
 index. Third, we create an ``lvm.dbg.declare`` call to indicate at the IR
 level that we've got a variable in an alloca (and it gives a starting
-location for the variable). Lastly, we set a source location for the
+location for the variable), and setting a source location for the
 beginning of the scope on the declare.
 
 One interesting thing to note at this point is that various debuggers have