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 pathDeclNode.h
More file actions
106 lines (80 loc) · 2.44 KB
/
DeclNode.h
File metadata and controls
106 lines (80 loc) · 2.44 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
#pragma once
#include "Entity/Type.h"
#include "AST/Node.h"
#include "AST/StmtNode.h"
#include "AST/ExprNode.h"
enum class VarModifier {
Let, Const, Param
};
/// 声明节点
class DeclNode : public Node {
public:
~DeclNode() override = default;
};
/// 变量声明节点
class VarDeclNode : public DeclNode {
public:
explicit VarDeclNode();
VarDeclNode(
VarModifier modifier,
const SharedPtr<Type> &type
);
VarDeclNode(
VarModifier modifier,
String name,
const SharedPtr<Type> &type
);
VarDeclNode(
VarModifier modifier,
String name,
const SharedPtr<Type> &type,
const SharedPtr<ExprNode> &initVal
);
~VarDeclNode() override = default;
void bindChildrenInversely() override;
void accept(const SharedPtr<ASTVisitor> &visitor) override;
bool isConstant() const;
VarModifier modifier;
String name;
SharedPtr<Type> type = nullptr;
SharedPtr<ExprNode> initVal = nullptr;
// 当前变量声明的alloca/load ir
LLVMValue *code = nullptr;
};
/// 函数参数声明节点
class ParmVarDeclNode : public VarDeclNode {
public:
explicit ParmVarDeclNode(const SharedPtr<Type> &type);
ParmVarDeclNode(const String &name, const SharedPtr<Type> &type);
~ParmVarDeclNode() override = default;
void accept(const SharedPtr<ASTVisitor> &visitor) override;
};
/// 函数声明节点
class FunctionDeclNode : public DeclNode {
public:
static SharedPtrMap<String, FunctionDeclNode> getBuiltinFunctions();
FunctionDeclNode(
String name,
const SharedPtrVector<ParmVarDeclNode> ¶ms
);
FunctionDeclNode(
String name,
const SharedPtrVector<ParmVarDeclNode> ¶ms,
const SharedPtr<Type> &returnType
);
FunctionDeclNode(
String name,
const SharedPtrVector<ParmVarDeclNode> ¶ms,
const SharedPtr<Type> &returnType,
const SharedPtr<CompoundStmtNode> &body
);
~FunctionDeclNode() override = default;
void bindChildrenInversely() override;
void accept(const SharedPtr<ASTVisitor> &visitor) override;
String name;
SharedPtrVector<ParmVarDeclNode> params;
SharedPtr<Type> returnType = nullptr;
SharedPtr<CompoundStmtNode> body = nullptr;
SharedPtr<Scope> internalScope = nullptr;
SharedPtr<ReturnStmtNode> refReturnStmt;
};