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 pathExprNode.cpp
More file actions
95 lines (68 loc) · 3.61 KB
/
ExprNode.cpp
File metadata and controls
95 lines (68 loc) · 3.61 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
#include <utility>
#include "AST/ExprNode.h"
#include "Sema/ASTVisitor.h"
ExprNode::ExprNode(const SharedPtr<Type> &type) : type(type) {}
LiteralExprNode::LiteralExprNode(const SharedPtr<Type> &type) : ExprNode(type) {}
BooleanLiteralExprNode::BooleanLiteralExprNode(bool literal) : literal(literal), LiteralExprNode(BasicType::BOOLEAN_TYPE) {}
void BooleanLiteralExprNode::accept(const SharedPtr<ASTVisitor> &visitor) {
visitor->visit(staticPtrCast<BooleanLiteralExprNode>(shared_from_this()));
}
IntegerLiteralExprNode::IntegerLiteralExprNode(long literal) : literal(literal), LiteralExprNode(BasicType::INTEGER_TYPE) {}
void IntegerLiteralExprNode::accept(const SharedPtr<ASTVisitor> &visitor) {
visitor->visit(staticPtrCast<IntegerLiteralExprNode>(shared_from_this()));
}
FloatLiteralExprNode::FloatLiteralExprNode(double literal) : literal(literal), LiteralExprNode(BasicType::FLOAT_TYPE) {}
void FloatLiteralExprNode::accept(const SharedPtr<ASTVisitor> &visitor) {
visitor->visit(staticPtrCast<FloatLiteralExprNode>(shared_from_this()));
}
StringLiteralExprNode::StringLiteralExprNode() : LiteralExprNode(BasicType::STRING_TYPE) {}
StringLiteralExprNode::StringLiteralExprNode(String literal) : literal(std::move(literal)), LiteralExprNode(BasicType::STRING_TYPE) {}
void StringLiteralExprNode::accept(const SharedPtr<ASTVisitor> &visitor) {
visitor->visit(staticPtrCast<StringLiteralExprNode>(shared_from_this()));
}
ArrayLiteralExprNode::ArrayLiteralExprNode() : LiteralExprNode(BasicType::UNKNOWN_TYPE) {}
ArrayLiteralExprNode::ArrayLiteralExprNode(const SharedPtr<Type> &type) : LiteralExprNode(type) {}
void ArrayLiteralExprNode::accept(const SharedPtr<ASTVisitor> &visitor) {
visitor->visit(staticPtrCast<ArrayLiteralExprNode>(shared_from_this()));
}
IdentifierExprNode::IdentifierExprNode(String name) : name(std::move(name)) {}
void IdentifierExprNode::accept(const SharedPtr<ASTVisitor> &visitor) {
visitor->visit(staticPtrCast<IdentifierExprNode>(shared_from_this()));
}
CallExprNode::CallExprNode(String calleeName, const SharedPtrVector<ExprNode> &args) : calleeName(std::move(calleeName)), args(args) {}
void CallExprNode::accept(const SharedPtr<ASTVisitor> &visitor) {
visitor->visit(staticPtrCast<CallExprNode>(shared_from_this()));
}
void CallExprNode::bindChildrenInversely() {
auto self = shared_from_this();
for (const SharedPtr<ExprNode> &arg: args) {
arg->parent = self;
}
}
UnaryOperatorExprNode::UnaryOperatorExprNode(unsigned int opCode, const SharedPtr<ExprNode> &subExpr) : opCode(opCode), subExpr(subExpr) {}
void UnaryOperatorExprNode::accept(const SharedPtr<ASTVisitor> &visitor) {
visitor->visit(staticPtrCast<UnaryOperatorExprNode>(shared_from_this()));
}
void UnaryOperatorExprNode::bindChildrenInversely() {
subExpr->parent = shared_from_this();
}
BinaryOperatorExprNode::BinaryOperatorExprNode(
unsigned int opCode,
const SharedPtr<ExprNode> &lhs,
const SharedPtr<ExprNode> &rhs
) : opCode(opCode),
lhs(lhs),
rhs(rhs) {}
void BinaryOperatorExprNode::accept(const SharedPtr<ASTVisitor> &visitor) {
visitor->visit(staticPtrCast<BinaryOperatorExprNode>(shared_from_this()));
}
void BinaryOperatorExprNode::bindChildrenInversely() {
lhs->parent = rhs->parent = shared_from_this();
}
void ArraySubscriptExprNode::accept(const SharedPtr<ASTVisitor> &visitor) {
visitor->visit(staticPtrCast<ArraySubscriptExprNode>(shared_from_this()));
}
ArraySubscriptExprNode::ArraySubscriptExprNode(
const SharedPtr<ExprNode> &baseExpr,
const SharedPtrVector<ExprNode> &indexExprs
) : baseExpr(baseExpr), indexExprs(indexExprs) {}