[docs] kaleidoscope example chapter 2 - constr's

Stanislav Manilov stanislav.manilov at gmail.com
Thu Mar 19 08:38:09 PDT 2015


The complete code listing at the end of the second chapter of the tutorial
had inconsistent constructors for the classes that represent the AST. The
constructors that were already there are now finished to initialize the
private fields of the classes.

This code is available later in the tutorial, but it makes the listing more
consistent if it is added here, as some of the AST classes already had this
feature.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150319/c3f723d2/attachment.html>
-------------- next part --------------
Index: examples/Kaleidoscope/Chapter2/toy.cpp
===================================================================
--- examples/Kaleidoscope/Chapter2/toy.cpp	(revision 232725)
+++ examples/Kaleidoscope/Chapter2/toy.cpp	(working copy)
@@ -84,8 +84,9 @@
 
 /// NumberExprAST - Expression class for numeric literals like "1.0".
 class NumberExprAST : public ExprAST {
+  double Val;
 public:
-  NumberExprAST(double val) {}
+  NumberExprAST(double val) : Val(val) {}
 };
 
 /// VariableExprAST - Expression class for referencing a variable, like "a".
@@ -97,8 +98,11 @@
 
 /// BinaryExprAST - Expression class for a binary operator.
 class BinaryExprAST : public ExprAST {
+  char Op;
+  ExprAST *LHS, *RHS;
 public:
-  BinaryExprAST(char op, ExprAST *lhs, ExprAST *rhs) {}
+  BinaryExprAST(char op, ExprAST *lhs, ExprAST *rhs) 
+    : Op(op), LHS(lhs), RHS(rhs) {}
 };
 
 /// CallExprAST - Expression class for function calls.
@@ -124,8 +128,11 @@
 
 /// FunctionAST - This class represents a function definition itself.
 class FunctionAST {
+  PrototypeAST *Proto;
+  ExprAST *Body;
 public:
-  FunctionAST(PrototypeAST *proto, ExprAST *body) {}
+  FunctionAST(PrototypeAST *proto, ExprAST *body)
+    : Proto(proto), Body(body) {}
 };
 } // end anonymous namespace
 


More information about the llvm-commits mailing list