AST#
-
namespace stapl
-
namespace ast#
Namespace of AST nodes and utility functions.
Typedefs
-
using ExprNode = std::variant<LiteralExprNode<int>, LiteralExprNode<double>, LiteralExprNode<bool>, VariableExprNode, std::unique_ptr<struct UnaryExprNode>, std::unique_ptr<struct BinaryExprNode>, std::unique_ptr<struct CallExprNode>>#
Variant for expression nodes.
-
using StmtNode = std::variant<LetStmtNode, AssignmentStmtNode, std::unique_ptr<struct IfStmtNode>, std::unique_ptr<struct WhileStmtNode>, BreakStmtNode, ContinueStmtNode, ReturnStmtNode, std::unique_ptr<struct CompoundStmtNode>>#
Variant for statement nodes.
-
using DeclNode = std::variant<FunctionDeclNode>#
Variant for declaration nodes.
Functions
-
template<typename T>
inline bool operator==(const std::unique_ptr<T> &p1, const std::unique_ptr<T> &p2)# Comparision operator overload for unique pointers of AST nodes.
- Parameters:
p1 –
std::unique_ptron the LHS.p2 –
std::unique_ptron the RHS.
- Returns:
Whether the objects referenced by
p1andp2are equal.
-
template<typename T>
struct LiteralExprNode# - #include <ast.h>
AST node for literal expressions, such as numbers.
- Todo:
Add support for types other than
int,doubleandbool.
Public Functions
-
LiteralExprNode(LiteralExprNode<T>&&) = default#
Move constructor.
-
explicit LiteralExprNode(T value)#
Instantiate from literal value.
- Parameters:
value – Literal value.
-
LiteralExprNode<T> &operator=(LiteralExprNode<T>&&) = default#
Move assignment operator.
-
bool operator==(const LiteralExprNode<T> &rhs) const = default#
Comparision operator overload.
- Parameters:
rhs –
LiteralExprNode<T>on the RHS.- Returns:
Whether the objects referenced by
thisandrhsare equal.
-
struct VariableExprNode#
- #include <ast.h>
AST node for variable expressions.
Public Functions
-
VariableExprNode(VariableExprNode&&) = default#
Move constructor.
-
explicit VariableExprNode(const std::string &name)#
Instantiate from variable name.
- Parameters:
name – Variable name.
-
VariableExprNode &operator=(VariableExprNode&&) = default#
Move assignment operator.
-
bool operator==(const VariableExprNode &rhs) const = default#
Comparision operator overload.
- Parameters:
rhs –
VariableExprNodeon the RHS.- Returns:
Whether the objects referenced by
thisandrhsare equal.
-
VariableExprNode(VariableExprNode&&) = default#
-
struct UnaryExprNode#
- #include <ast.h>
AST node for unary expressions.
Public Functions
-
UnaryExprNode(UnaryExprNode&&) = default#
Move constructor.
-
explicit UnaryExprNode(const std::string &op, ExprNode rhs)#
Instantiate from operator and operand.
- Parameters:
op – Operator of the unary expression.
rhs – Operand of the unary expression.
-
UnaryExprNode &operator=(UnaryExprNode&&) = default#
Move assignment operator.
-
bool operator==(const UnaryExprNode &rhs) const = default#
Comparision operator overload.
- Parameters:
rhs –
UnaryExprNodeon the RHS.- Returns:
Whether the objects referenced by
thisandrhsare equal.
-
UnaryExprNode(UnaryExprNode&&) = default#
-
struct BinaryExprNode#
- #include <ast.h>
AST node for binary expressions.
Public Functions
-
BinaryExprNode(BinaryExprNode&&) = default#
Move constructor.
-
explicit BinaryExprNode(const std::string &op, ExprNode lhs, ExprNode rhs)#
Instantiate from operator and operands.
- Parameters:
op – Operator of the binary expression.
lhs – LHS of the binary expression.
rhs – RHS of the binary expression.
-
BinaryExprNode &operator=(BinaryExprNode&&) = default#
Move assignment operator.
-
bool operator==(const BinaryExprNode &rhs) const = default#
Comparision operator overload.
- Parameters:
rhs –
BinaryExprNodeon the RHS.- Returns:
Whether the objects referenced by
thisandrhsare equal.
-
BinaryExprNode(BinaryExprNode&&) = default#
-
struct CallExprNode#
- #include <ast.h>
AST node for function call expressions.
Public Functions
-
CallExprNode(CallExprNode&&) = default#
Move constructor.
-
explicit CallExprNode(const std::string &callee, std::vector<ExprNode> args)#
Instantiate from function name and arguments.
- Parameters:
callee – Function to call.
args – Arguments of the function call.
-
CallExprNode &operator=(CallExprNode&&) = default#
Move assignment operator.
-
bool operator==(const CallExprNode &rhs) const = default#
Comparision operator overload.
- Parameters:
rhs –
CallExprNodeon the RHS.- Returns:
Whether the objects referenced by
thisandrhsare equal.
-
CallExprNode(CallExprNode&&) = default#
-
struct PrototypeNode#
- #include <ast.h>
AST node for function prototype.
Public Functions
-
PrototypeNode(PrototypeNode&&) = default#
Move constructor.
-
explicit PrototypeNode(const std::string &name, std::vector<std::pair<std::string, std::string>> args, const std::string &return_type)#
Instantiate from function name, pair of argument names and types, and return type.
- Parameters:
name – Function name.
args – Arguments names and types of the function.
return_type – Return type name of the function.
-
PrototypeNode &operator=(PrototypeNode&&) = default#
Move assignment operator.
-
bool operator==(const PrototypeNode &rhs) const = default#
Comparision operator overload.
- Parameters:
rhs –
PrototypeNodeon the RHS.- Returns:
Whether the objects referenced by
thisandrhsare equal.
-
PrototypeNode(PrototypeNode&&) = default#
-
struct LetStmtNode#
- #include <ast.h>
AST node for let statement.
Public Functions
-
LetStmtNode(LetStmtNode&&) = default#
Move constructor.
-
explicit LetStmtNode(const std::string &var_name, const std::string &var_type)#
Instantiate from variable name and type.
- Parameters:
var_name – Variable name.
var_type – Type name of the variable.
-
LetStmtNode &operator=(LetStmtNode&&) = default#
Move assignment operator.
-
bool operator==(const LetStmtNode &rhs) const = default#
Comparision operator overload.
- Parameters:
rhs –
LetStmtNodeon the RHS.- Returns:
Whether the objects referenced by
thisandrhsare equal.
-
LetStmtNode(LetStmtNode&&) = default#
-
struct AssignmentStmtNode#
- #include <ast.h>
AST node for assignment statement.
Public Functions
-
AssignmentStmtNode(AssignmentStmtNode&&) = default#
Move constructor.
-
explicit AssignmentStmtNode(const std::string &var_name, ExprNode assign_expr)#
Instantiate from variable name and assignment expression.
- Parameters:
var_name – Name of the variable to be assigned.
assign_expr – Expression to be assigned.
-
AssignmentStmtNode &operator=(AssignmentStmtNode&&) = default#
Move assignment operator.
-
bool operator==(const AssignmentStmtNode &rhs) const = default#
Comparision operator overload.
- Parameters:
rhs –
AssignmentStmtNodeon the RHS.- Returns:
Whether the objects referenced by
thisandrhsare equal.
-
AssignmentStmtNode(AssignmentStmtNode&&) = default#
-
struct ReturnStmtNode#
- #include <ast.h>
AST node for return statement.
Public Functions
-
ReturnStmtNode(ReturnStmtNode&&) = default#
Move constructor.
-
explicit ReturnStmtNode(ExprNode return_expr)#
Instantiate from expression to be returned.
- Parameters:
return_expr – Expression to be returned.
-
ReturnStmtNode &operator=(ReturnStmtNode&&) = default#
Move assignment operator.
-
bool operator==(const ReturnStmtNode &rhs) const = default#
Comparision operator overload.
- Parameters:
rhs –
ReturnStmtNodeon the RHS.- Returns:
Whether the objects referenced by
thisandrhsare equal.
-
ReturnStmtNode(ReturnStmtNode&&) = default#
-
struct BreakStmtNode#
- #include <ast.h>
AST node for break statement.
Public Functions
-
BreakStmtNode(BreakStmtNode&&) = default#
Move constructor.
-
explicit BreakStmtNode() = default#
Default constructor.
-
BreakStmtNode &operator=(BreakStmtNode&&) = default#
Move assignment operator.
-
bool operator==(const BreakStmtNode &rhs) const = default#
Comparision operator overload.
- Parameters:
rhs –
BreakStmtNodeon the RHS.- Returns:
Whether the objects referenced by
thisandrhsare equal.
-
BreakStmtNode(BreakStmtNode&&) = default#
-
struct ContinueStmtNode#
- #include <ast.h>
AST node for continue statement.
Public Functions
-
ContinueStmtNode(ContinueStmtNode&&) = default#
Move constructor.
-
explicit ContinueStmtNode() = default#
Default constructor.
-
ContinueStmtNode &operator=(ContinueStmtNode&&) = default#
Move assignment operator.
-
bool operator==(const ContinueStmtNode &rhs) const = default#
Comparision operator overload.
- Parameters:
rhs –
ContinueStmtNodeon the RHS.- Returns:
Whether the objects referenced by
thisandrhsare equal.
-
ContinueStmtNode(ContinueStmtNode&&) = default#
-
struct IfStmtNode#
- #include <ast.h>
AST node for if statement.
Public Functions
-
IfStmtNode(IfStmtNode&&) = default#
Move constructor.
-
explicit IfStmtNode(ExprNode condition, StmtNode then_stmt, StmtNode else_stmt)#
Instantiate from condition expression, statement to be executed if the condition is true, and statement to be executed if the condition is false.
- Parameters:
condition – Condition expression.
then_stmt – Statement to be executed if the condition is true.
else_stmt – Statement to be executed if the condition is false.
-
IfStmtNode &operator=(IfStmtNode&&) = default#
Move assignment operator.
-
bool operator==(const IfStmtNode &rhs) const = default#
Comparision operator overload.
- Parameters:
rhs –
IfStmtNodeon the RHS.- Returns:
Whether the objects referenced by
thisandrhsare equal.
-
IfStmtNode(IfStmtNode&&) = default#
-
struct WhileStmtNode#
- #include <ast.h>
AST node for while statement.
Public Functions
-
WhileStmtNode(WhileStmtNode&&) = default#
Move constructor.
-
explicit WhileStmtNode(ExprNode condition, StmtNode body)#
Instantiate from condition expression and statement to be executed if the condition is true.
- Parameters:
condition – Condition expression.
body – Statement to be executed if the condition is true.
-
WhileStmtNode &operator=(WhileStmtNode&&) = default#
Move assignment operator.
-
bool operator==(const WhileStmtNode &rhs) const = default#
Comparision operator overload.
- Parameters:
rhs –
WhileStmtNodeon the RHS.- Returns:
Whether the objects referenced by
thisandrhsare equal.
-
WhileStmtNode(WhileStmtNode&&) = default#
-
struct CompoundStmtNode#
- #include <ast.h>
AST node for compound statement.
Public Functions
-
CompoundStmtNode(CompoundStmtNode&&) = default#
Move constructor.
-
explicit CompoundStmtNode(std::vector<StmtNode> stmts)#
Instantiate from statements in the compound statement.
- Parameters:
stmts – Statements in the compound statement.
-
CompoundStmtNode &operator=(CompoundStmtNode&&) = default#
Move assignment operator.
-
bool operator==(const CompoundStmtNode &rhs) const = default#
Comparision operator overload.
- Parameters:
rhs –
CompoundStmtNodeon the RHS.- Returns:
Whether the objects referenced by
thisandrhsare equal.
-
CompoundStmtNode(CompoundStmtNode&&) = default#
-
struct FunctionDeclNode#
- #include <ast.h>
AST node for function definition.
Public Functions
-
FunctionDeclNode(FunctionDeclNode&&) = default#
Move constructor.
-
explicit FunctionDeclNode(PrototypeNode proto, StmtNode func_body)#
Instantiate from prototype and function body.
- Parameters:
proto – Prototype of the function.
func_body – Body of the function.
-
explicit FunctionDeclNode(PrototypeNode proto)#
Constructor for extern functions.
-
FunctionDeclNode &operator=(FunctionDeclNode&&) = default#
Move assignment operator.
-
bool operator==(const FunctionDeclNode &rhs) const = default#
Comparision operator overload.
- Parameters:
rhs –
FunctionDeclNodeon the RHS.- Returns:
Whether the objects referenced by
thisandrhsare equal.
Public Members
-
PrototypeNode proto#
Prototype of the function.
-
FunctionDeclNode(FunctionDeclNode&&) = default#
-
using ExprNode = std::variant<LiteralExprNode<int>, LiteralExprNode<double>, LiteralExprNode<bool>, VariableExprNode, std::unique_ptr<struct UnaryExprNode>, std::unique_ptr<struct BinaryExprNode>, std::unique_ptr<struct CallExprNode>>#
-
namespace ast#
-
namespace stapl
-
namespace ast
Namespace of AST nodes and utility functions.
-
class ASTPrinter#
- #include <ast_printer.h>
A visitor for printing AST nodes.
Public Functions
-
std::string operator()(const LiteralExprNode<int> &node) const#
Represent
LiteralExprNode<int>as string.- Parameters:
node – The node to represent.
- Returns:
The string representation of the node.
-
std::string operator()(const LiteralExprNode<double> &node) const#
Represent
LiteralExprNode<double>as string.- Parameters:
node – The node to represent.
- Returns:
The string representation of the node.
-
std::string operator()(const LiteralExprNode<bool> &node) const#
Represent
LiteralExprNode<bool>as string.- Parameters:
node – The node to represent.
- Returns:
The string representation of the node.
-
std::string operator()(const VariableExprNode &node) const#
Represent
VariableExprNodeas string.- Parameters:
node – The node to represent.
- Returns:
The string representation of the node.
-
std::string operator()(const std::unique_ptr<UnaryExprNode> &node) const#
Represent
UnaryExprNodeas string.- Parameters:
node – The node to represent.
- Returns:
The string representation of the node.
-
std::string operator()(const std::unique_ptr<BinaryExprNode> &node) const#
Represent
BinaryExprNodeas string.- Parameters:
node – The node to represent.
- Returns:
The string representation of the node.
-
std::string operator()(const std::unique_ptr<CallExprNode> &node) const#
Represent
CallExprNodeas string.- Parameters:
node – The node to represent.
- Returns:
The string representation of the node.
-
std::string operator()(const PrototypeNode &node) const#
Represent
PrototypeNodeas string.- Parameters:
node – The node to represent.
- Returns:
The string representation of the node.
-
std::string operator()(const LetStmtNode &node) const#
Represent
LetStmtNodeas string.- Parameters:
node – The node to represent.
- Returns:
The string representation of the node.
-
std::string operator()(const AssignmentStmtNode &node) const#
Represent
AssignmentStmtNodeas string.- Parameters:
node – The node to represent.
- Returns:
The string representation of the node.
-
std::string operator()(const std::unique_ptr<IfStmtNode> &node) const#
Represent
IfStmtNodeas string.- Parameters:
node – The node to represent.
- Returns:
The string representation of the node.
-
std::string operator()(const std::unique_ptr<WhileStmtNode> &node) const#
Represent
WhileStmtNodeas string.- Parameters:
node – The node to represent.
- Returns:
The string representation of the node.
-
std::string operator()(const BreakStmtNode &node) const#
Represent
BreakStmtNodeas string.- Parameters:
node – The node to represent.
- Returns:
The string representation of the node.
-
std::string operator()(const ContinueStmtNode &node) const#
Represent
ContinueStmtNodeas string.- Parameters:
node – The node to represent.
- Returns:
The string representation of the node.
-
std::string operator()(const ReturnStmtNode &node) const#
Represent
ReturnStmtNodeas string.- Parameters:
node – The node to represent.
- Returns:
The string representation of the node.
-
std::string operator()(const std::unique_ptr<CompoundStmtNode> &node) const#
Represent
CompoundStmtNodeas string.- Parameters:
node – The node to represent.
- Returns:
The string representation of the node.
-
std::string operator()(const FunctionDeclNode &node) const#
Represent
FunctionDeclNodeas string.- Parameters:
node – The node to represent.
- Returns:
The string representation of the node.
-
std::string operator()(const LiteralExprNode<int> &node) const#
-
class ASTPrinter#
-
namespace ast