-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathASTNode.cpp
153 lines (119 loc) · 2.64 KB
/
ASTNode.cpp
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
142
143
144
145
146
147
148
149
150
151
152
//
// Created by nalle on 8/1/2017.
//
#include "ASTNode.h"
#include "ASTVisitor.h"
void ASTNode::accept(ASTVisitor &visitor)
{
visitor.visit(shared_from_this());
}
void ASTExp::accept(ASTVisitor &visitor)
{
visitor.visit(shared_from_this());
}
size_t ASTNode::getLine()
{
return mLine;
}
size_t ASTNode::getColumn()
{
return mColumn;
}
ASTOp::ASTOp(std::shared_ptr<ASTExp> left, std::shared_ptr<ASTExp> right)
: mLeft(left)
, mRight(right)
{
}
std::shared_ptr<ASTExp> ASTOp::getLeft(void)
{
return mLeft;
}
std::shared_ptr<ASTExp> ASTOp::getRight(void)
{
return mRight;
}
void ASTOp::accept(ASTVisitor &visitor)
{
visitor.visit(std::static_pointer_cast<ASTOp>(shared_from_this()));
}
ASTVar::ASTVar(std::string &&varName)
: mVarName(std::move(varName))
{
}
ASTVar::ASTVar(const std::string &varName)
: mVarName(varName)
{
}
std::string ASTVar::getVarName(void)
{
return mVarName;
}
void ASTVar::accept(ASTVisitor &visitor)
{
visitor.visit(std::static_pointer_cast<ASTVar>(shared_from_this()));
}
ASTNum::ASTNum(std::string &&valueStr)
: mValueStr(std::move(valueStr))
{
}
ASTNum::ASTNum(const std::string &valueStr)
: mValueStr(valueStr)
{
}
std::string ASTNum::getValueStr(void)
{
return mValueStr;
}
void ASTNum::accept(ASTVisitor &visitor)
{
visitor.visit(std::static_pointer_cast<ASTNum>(shared_from_this()));
}
ASTAssign::ASTAssign(std::shared_ptr<ASTVar> left, std::shared_ptr<ASTExp> right)
: mLeft(left)
, mRight(right)
{
}
std::shared_ptr<ASTVar> ASTAssign::getLeft(void)
{
return mLeft;
}
std::shared_ptr<ASTExp> ASTAssign::getRight(void)
{
return mRight;
}
void ASTAssign::accept(ASTVisitor &visitor)
{
visitor.visit(std::static_pointer_cast<ASTAssign>(shared_from_this()));
}
ASTAdd::ASTAdd(std::shared_ptr<ASTExp> left, std::shared_ptr<ASTExp> right)
: ASTOp(left, right)
{
}
void ASTAdd::accept(ASTVisitor &visitor)
{
visitor.visit(std::static_pointer_cast<ASTAdd>(shared_from_this()));
}
ASTDiv::ASTDiv(std::shared_ptr<ASTExp> left, std::shared_ptr<ASTExp> right)
: ASTOp(left, right)
{
}
void ASTDiv::accept(ASTVisitor &visitor)
{
visitor.visit(std::static_pointer_cast<ASTDiv>(shared_from_this()));
}
ASTMul::ASTMul(std::shared_ptr<ASTExp> left, std::shared_ptr<ASTExp> right)
: ASTOp(left, right)
{
}
void ASTMul::accept(ASTVisitor &visitor)
{
visitor.visit(std::static_pointer_cast<ASTMul>(shared_from_this()));
}
ASTSub::ASTSub(std::shared_ptr<ASTExp> left, std::shared_ptr<ASTExp> right)
: ASTOp(left, right)
{
}
void ASTSub::accept(ASTVisitor &visitor)
{
visitor.visit(std::static_pointer_cast<ASTSub>(shared_from_this()));
}