[Kaleidoscope] Clang-format the Kaleidoscope tutorials.
[oota-llvm.git] / docs / tutorial / LangImpl7.rst
index 33f48535f1655cf5e3d2b89ac49f67135f00dcfd..8c35f2ac0191fdbf4b94027c1697e67b7f1e6fb6 100644 (file)
@@ -358,7 +358,8 @@ from the stack slot:
     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 @@ the unabridged code):
 
         // 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 @@ the unabridged code):
 
       // 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 @@ allowed.
 
         // 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 @@ this:
     ...
     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 @@ var/in, it looks like this:
     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 @@ do is add it as a primary expression:
     ///   ::= 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 @@ AST node:
       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 @@ previous value that we replace in OldBindings.
         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 @@ we evaluate the body of the var/in expression:
 
       // 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: