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 pathASTVisitor.cpp
More file actions
124 lines (99 loc) · 4.02 KB
/
ASTVisitor.cpp
File metadata and controls
124 lines (99 loc) · 4.02 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
#include "Sema/ASTVisitor.h"
void ASTVisitor::resolve(const SharedPtr<ModuleNode> &module) {
module->accept(shared_from_this());
}
void ASTVisitor::visit(const SharedPtr<ModuleNode> &module) {
for (const SharedPtr<StmtNode> &stmt: module->childStmts) {
stmt->accept(shared_from_this());
}
}
void ASTVisitor::visit(const SharedPtr<VarDeclNode> &varDecl) {
if (varDecl->initVal) {
varDecl->initVal->accept(shared_from_this());
}
}
void ASTVisitor::visit(const SharedPtr<ParmVarDeclNode> ¶mVarDecl) {}
void ASTVisitor::visit(const SharedPtr<FunctionDeclNode> &funcDecl) {
for (const SharedPtr<ParmVarDeclNode> ¶mVarDecl : funcDecl->params) {
paramVarDecl->accept(shared_from_this());
}
funcDecl->body->accept(shared_from_this());
}
void ASTVisitor::visit(const SharedPtr<BooleanLiteralExprNode> &boolLiteralExpr) {}
void ASTVisitor::visit(const SharedPtr<IntegerLiteralExprNode> &intLiteralExpr) {}
void ASTVisitor::visit(const SharedPtr<FloatLiteralExprNode> &floatLiteralExpr) {}
void ASTVisitor::visit(const SharedPtr<StringLiteralExprNode> &strLiteralExpr) {}
void ASTVisitor::visit(const SharedPtr<ArrayLiteralExprNode> &arrayLiteralExpr) {
for (const SharedPtr<ExprNode> &expr : arrayLiteralExpr->elements) {
expr->accept(shared_from_this());
}
}
void ASTVisitor::visit(const SharedPtr<IdentifierExprNode> &varExpr) {}
void ASTVisitor::visit(const SharedPtr<CallExprNode> &callExpr) {
for (const SharedPtr<ExprNode> &argExpr: callExpr->args) {
argExpr->accept(shared_from_this());
}
}
void ASTVisitor::visit(const SharedPtr<UnaryOperatorExprNode> &uopExpr) {
uopExpr->subExpr->accept(shared_from_this());
}
void ASTVisitor::visit(const SharedPtr<BinaryOperatorExprNode> &bopExpr) {
bopExpr->lhs->accept(shared_from_this());
bopExpr->rhs->accept(shared_from_this());
}
void ASTVisitor::visit(const SharedPtr<ArraySubscriptExprNode> &asExpr) {
asExpr->baseExpr->accept(shared_from_this());
for (const SharedPtr<ExprNode> &indexExpr:asExpr->indexExprs) {
indexExpr->accept(shared_from_this());
}
}
void ASTVisitor::visit(const SharedPtr<ExprStmtNode> &exprStmt) {
exprStmt->expr->accept(shared_from_this());
}
void ASTVisitor::visit(const SharedPtr<CompoundStmtNode> &compStmt) {
for (const SharedPtr<StmtNode> &stmt: compStmt->childStmts) {
stmt->accept(shared_from_this());
}
}
void ASTVisitor::visit(const SharedPtr<VarDeclStmtNode> &varDeclStmt) {
for (const SharedPtr<VarDeclNode> &varDecl : varDeclStmt->childVarDecls) {
varDecl->accept(shared_from_this());
}
}
void ASTVisitor::visit(const SharedPtr<FunctionDeclStmtNode> &funcDeclStmt) {
funcDeclStmt->childFunctionDecl->accept(shared_from_this());
}
void ASTVisitor::visit(const SharedPtr<IfStmtNode> &ifStmt) {
ifStmt->condition->accept(shared_from_this());
ifStmt->thenBody->accept(shared_from_this());
if (ifStmt->elseBody) {
ifStmt->elseBody->accept(shared_from_this());
}
}
void ASTVisitor::visit(const SharedPtr<WhileStmtNode> &whileStmt) {
whileStmt->condition->accept(shared_from_this());
whileStmt->body->accept(shared_from_this());
}
void ASTVisitor::visit(const SharedPtr<ForStmtNode> &forStmt) {
if (forStmt->initVarStmt) {
forStmt->initVarStmt->accept(shared_from_this());
} else {
for (const SharedPtr<ExprNode> &initExpr: forStmt->initExprs) {
initExpr->accept(shared_from_this());
}
}
if (forStmt->condition) {
forStmt->condition->accept(shared_from_this());
}
forStmt->body->accept(shared_from_this());
for (const SharedPtr<ExprNode> &updateExpr: forStmt->updates) {
updateExpr->accept(shared_from_this());
}
}
void ASTVisitor::visit(const SharedPtr<ContinueStmtNode> &continueStmt) {}
void ASTVisitor::visit(const SharedPtr<BreakStmtNode> &breakStmt) {}
void ASTVisitor::visit(const SharedPtr<ReturnStmtNode> &returnStmt) {
if (returnStmt->returnExpr) {
returnStmt->returnExpr->accept(shared_from_this());
}
}