llvm-journey

LLVM Journey
git clone git://0xff.ir/g/llvm-journey.git
Log | Files | Refs | README | LICENSE

commit 7ff0624a307a999987c3dad5adc8554de51ed0c8
parent 6661dca50043e1a52adb48db45cb0c6ef7c6afa8
Author: Mohammad-Reza Nabipoor <m.nabipoor@yahoo.com>
Date:   Sat, 19 Sep 2020 07:09:37 +0430

README.md: Add description of remaining types of AST

Diffstat:
MREADME.md | 35++++++++++++++++++++++++++++++++---
1 file changed, 32 insertions(+), 3 deletions(-)

diff --git a/README.md b/README.md @@ -188,8 +188,7 @@ Each node of AST (Abstract Syntax Tree) can be saved in `ASTNode` class. It's a polymorphic type that accepts an instance of type `T` that satisfies the following requirements: -- `T` is a - [SemiRegular type](https://en.cppreference.com/w/cpp/concepts/semiregular) +- `T` is a [Regular type][regular] - The following functions are defined: - `std::string to_string(const T&);` - `kal::NodeType node_type(cons T&);` @@ -212,4 +211,34 @@ enum class NodeType For more information about implementation details of this polymorphic type and the benefits of this design, you can watch [this great talk by Sean Parent](https://youtu.be/QGcVXgEVMJg). -If you're impatient you can go directly to time `49:13`. +If you're impatient you can go directly to time +[49:13](https://youtu.be/QGcVXgEVMJg?t=49m13s). + + +Current implementation provides the following [regular][regular] types for AST +nodes: + - `kal::Number` + - `double value` + - `kal::Variable` + - `std::string name` + - `kal::BinaryOp` + - `char op` + - `ASTNode lhs` + - `ASTNode rhs` + - `kal::Call` + - `std::string callee` + - `std::vector<ASTNode> args` + - `kal::Prototype` + - `std::string name` + - `std::vector<std::string> params` + - `kal::Function` + - `Prototype proto` + - `ASTNode body` + +All of these types are implemented as `struct` (all members are `public`). +Because there's no invariant to establish. +(See C++ Core Guidelines C.2). + + +[regular]: https://en.cppreference.com/w/cpp/concepts/regular +[cppcore_c2]: https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#c2-use-class-if-the-class-has-an-invariant-use-struct-if-the-data-members-can-vary-independently