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.h
More file actions
177 lines (119 loc) · 4.2 KB
/
ExprNode.h
File metadata and controls
177 lines (119 loc) · 4.2 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#pragma once
#include "Entity/Type.h"
#include "AST/Node.h"
#include "AST/StmtNode.h"
class FunctionDeclNode;
/// 表达式节点
class ExprNode : public Node {
public:
ExprNode() = default;
explicit ExprNode(const SharedPtr<Type> &type);
~ExprNode() override = default;
SharedPtr<Type> type = nullptr;
// 当前表达式的ir
LLVMValue *code = nullptr;
};
/// 字面量表达式节点
class LiteralExprNode : public ExprNode {
public:
LiteralExprNode() = default;
explicit LiteralExprNode(const SharedPtr<Type> &type);
};
/// 布尔值字面量表达式节点
class BooleanLiteralExprNode : public LiteralExprNode {
public:
explicit BooleanLiteralExprNode(bool literal);
~BooleanLiteralExprNode() override = default;
void accept(const SharedPtr<ASTVisitor> &visitor) override;
bool literal;
};
/// 整数字面量表达式节点
class IntegerLiteralExprNode : public LiteralExprNode {
public:
explicit IntegerLiteralExprNode(long literal);
~IntegerLiteralExprNode() override = default;
void accept(const SharedPtr<ASTVisitor> &visitor) override;
long literal;
};
/// 浮点数字面量表达式节点
class FloatLiteralExprNode : public LiteralExprNode {
public:
explicit FloatLiteralExprNode(double literal);
~FloatLiteralExprNode() override = default;
void accept(const SharedPtr<ASTVisitor> &visitor) override;
double literal;
};
/// 字符串字面量表达式节点
class StringLiteralExprNode : public LiteralExprNode {
public:
explicit StringLiteralExprNode();
explicit StringLiteralExprNode(String literal);
~StringLiteralExprNode() override = default;
void accept(const SharedPtr<ASTVisitor> &visitor) override;
String literal;
};
/// 数组字面量表达式
class ArrayLiteralExprNode : public LiteralExprNode {
public:
explicit ArrayLiteralExprNode();
explicit ArrayLiteralExprNode(const SharedPtr<Type> &type);
~ArrayLiteralExprNode() override = default;
void accept(const SharedPtr<ASTVisitor> &visitor) override;
SharedPtrVector<ExprNode> elements;
};
/// 标识符表达式节点
class IdentifierExprNode : public ExprNode {
public:
explicit IdentifierExprNode(String name);
~IdentifierExprNode() override = default;
void accept(const SharedPtr<ASTVisitor> &visitor) override;
String name;
SharedPtr<VarDeclNode> refVarDecl = nullptr;
};
/// 函数调用表达式节点
class CallExprNode : public ExprNode {
public:
CallExprNode(String calleeName, const SharedPtrVector<ExprNode> &args);
~CallExprNode() override = default;
void bindChildrenInversely() override;
void accept(const SharedPtr<ASTVisitor> &visitor) override;
String calleeName;
SharedPtrVector<ExprNode> args;
SharedPtr<FunctionDeclNode> refFuncDecl = nullptr;
};
/// 一元运算表达式节点
class UnaryOperatorExprNode : public ExprNode {
public:
UnaryOperatorExprNode(unsigned int opCode, const SharedPtr<ExprNode> &subExpr);
~UnaryOperatorExprNode() override = default;
void bindChildrenInversely() override;
void accept(const SharedPtr<ASTVisitor> &visitor) override;
unsigned int opCode;
bool isPostfix = false;
SharedPtr<ExprNode> subExpr = nullptr;
};
/// 二元运算表达式节点
class BinaryOperatorExprNode : public ExprNode {
public:
BinaryOperatorExprNode(unsigned int opCode, const SharedPtr<ExprNode> &lhs, const SharedPtr<ExprNode> &rhs);
~BinaryOperatorExprNode() override = default;
void bindChildrenInversely() override;
void accept(const SharedPtr<ASTVisitor> &visitor) override;
unsigned int opCode;
SharedPtr<ExprNode> lhs = nullptr, rhs = nullptr;
};
/// 数组下标表达式
class ArraySubscriptExprNode : public ExprNode {
public:
ArraySubscriptExprNode(const SharedPtr<ExprNode> &baseExpr, const SharedPtrVector<ExprNode> &indexExprs);
~ArraySubscriptExprNode() override = default;
void accept(const SharedPtr<ASTVisitor> &visitor) override;
SharedPtr<ExprNode> baseExpr = nullptr;
SharedPtrVector<ExprNode> indexExprs;
};
//class ArithmeticExprNode;
//class BitwiseExprNode;
//class ComparisonExprNode;
//class LogicalExprNode;
//class AssignmentExprNode;
//class StringOperationExprNode;