This repository was archived by the owner on Jan 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathStmtNode.cpp
More file actions
141 lines (113 loc) · 4.26 KB
/
StmtNode.cpp
File metadata and controls
141 lines (113 loc) · 4.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#include "AST/StmtNode.h"
#include "AST/DeclNode.h"
#include "Sema/ASTVisitor.h"
ExprStmtNode::ExprStmtNode(const SharedPtr<ExprNode> &expr) : expr(expr) {}
void ExprStmtNode::accept(const SharedPtr<ASTVisitor> &visitor) {
visitor->visit(staticPtrCast<ExprStmtNode>(shared_from_this()));
}
void ExprStmtNode::bindChildrenInversely() {
expr->parent = shared_from_this();
}
CompoundStmtNode::CompoundStmtNode(const SharedPtrVector<StmtNode> &childStmts) : childStmts(childStmts) {}
bool CompoundStmtNode::isEmpty() const {
return childStmts.empty();
}
void CompoundStmtNode::accept(const SharedPtr<ASTVisitor> &visitor) {
visitor->visit(staticPtrCast<CompoundStmtNode>(shared_from_this()));
}
void CompoundStmtNode::bindChildrenInversely() {
auto self = shared_from_this();
for (const SharedPtr<StmtNode> &stmt: childStmts) {
stmt->parent = self;
}
}
void VarDeclStmtNode::pushVarDecl(const SharedPtr<VarDeclNode> &varDecl) {
childVarDecls.push_back(varDecl);
}
void VarDeclStmtNode::accept(const SharedPtr<ASTVisitor> &visitor) {
visitor->visit(staticPtrCast<VarDeclStmtNode>(shared_from_this()));
}
void VarDeclStmtNode::bindChildrenInversely() {
auto self = shared_from_this();
for (const SharedPtr<VarDeclNode> &varDecl: childVarDecls) {
varDecl->parent = self;
}
}
FunctionDeclStmtNode::FunctionDeclStmtNode(
const SharedPtr<FunctionDeclNode> &childFunctionDecl
) : childFunctionDecl(childFunctionDecl) {}
void FunctionDeclStmtNode::accept(const SharedPtr<ASTVisitor> &visitor) {
visitor->visit(staticPtrCast<FunctionDeclStmtNode>(shared_from_this()));
}
void FunctionDeclStmtNode::bindChildrenInversely() {
childFunctionDecl->parent = shared_from_this();
}
IfStmtNode::IfStmtNode(
const SharedPtr<ExprNode> &condition,
const SharedPtr<StmtNode> &thenStmt,
const SharedPtr<StmtNode> &elseStmt
) : condition(condition), thenBody(thenStmt), elseBody(elseStmt) {}
void IfStmtNode::accept(const SharedPtr<ASTVisitor> &visitor) {
visitor->visit(staticPtrCast<IfStmtNode>(shared_from_this()));
}
void IfStmtNode::bindChildrenInversely() {
auto self = shared_from_this();
condition->parent = thenBody->parent = self;
if (elseBody) {
elseBody->parent = self;
}
}
WhileStmtNode::WhileStmtNode(
const SharedPtr<ExprNode> &condition,
const SharedPtr<StmtNode> &body
) : condition(condition), body(body) {}
void WhileStmtNode::accept(const SharedPtr<ASTVisitor> &visitor) {
visitor->visit(staticPtrCast<WhileStmtNode>(shared_from_this()));
}
void WhileStmtNode::bindChildrenInversely() {
condition->parent = body->parent = shared_from_this();
}
ForStmtNode::ForStmtNode(
const SharedPtr<VarDeclStmtNode> &forInitVarDecls,
const SharedPtrVector<ExprNode> &forInitExprList,
const SharedPtr<ExprNode> &forCondition,
const SharedPtrVector<ExprNode> &forUpdate,
const SharedPtr<StmtNode> &body
) : initVarStmt(forInitVarDecls),
initExprs(forInitExprList),
condition(forCondition),
updates(forUpdate), body(body) {}
void ForStmtNode::accept(const SharedPtr<ASTVisitor> &visitor) {
visitor->visit(staticPtrCast<ForStmtNode>(shared_from_this()));
}
void ForStmtNode::bindChildrenInversely() {
auto self = shared_from_this();
if (initVarStmt) {
initVarStmt->parent = self;
}
for (const SharedPtr<ExprNode> &forInitExpr: initExprs) {
forInitExpr->parent = self;
}
if (condition) {
condition->parent = self;
}
for (const SharedPtr<ExprNode> &forUpdateItem: updates) {
forUpdateItem->parent = self;
}
body->parent = self;
}
void ContinueStmtNode::accept(const SharedPtr<ASTVisitor> &visitor) {
visitor->visit(staticPtrCast<ContinueStmtNode>(shared_from_this()));
}
void BreakStmtNode::accept(const SharedPtr<ASTVisitor> &visitor) {
visitor->visit(staticPtrCast<BreakStmtNode>(shared_from_this()));
}
ReturnStmtNode::ReturnStmtNode(const SharedPtr<ExprNode> &argument) : returnExpr(argument) {}
void ReturnStmtNode::accept(const SharedPtr<ASTVisitor> &visitor) {
visitor->visit(staticPtrCast<ReturnStmtNode>(shared_from_this()));
}
void ReturnStmtNode::bindChildrenInversely() {
if (returnExpr) {
returnExpr->parent = shared_from_this();
}
}