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 pathReferenceResolver.h
More file actions
55 lines (40 loc) · 1.61 KB
/
ReferenceResolver.h
File metadata and controls
55 lines (40 loc) · 1.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
#pragma once
#include "Entity/Scope.h"
#include "Sema/ASTVisitor.h"
/// 引用消解器
class ReferenceResolver final : public ASTVisitorWithScope {
public:
void visit(const SharedPtr<ModuleNode> &module) override;
void visit(const SharedPtr<VarDeclNode> &varDecl) override;
void visit(const SharedPtr<ParmVarDeclNode> ¶mVarDecl) override;
void visit(const SharedPtr<FunctionDeclNode> &funcDecl) override;
void visit(const SharedPtr<IdentifierExprNode> &varExpr) override;
void visit(const SharedPtr<CallExprNode> &callExpr) override;
void visit(const SharedPtr<CompoundStmtNode> &compStmt) override;
void visit(const SharedPtr<ForStmtNode> &forStmt) override;
void visit(const SharedPtr<ContinueStmtNode> &continueStmt) override;
void visit(const SharedPtr<BreakStmtNode> &breakStmt) override;
void visit(const SharedPtr<ReturnStmtNode> &returnStmt) override;
private:
/**
* @brief 查找变量
* @details 沿着当前作用域递归向上查找变量
*
* @param name 变量名
* @return 变量定义节点
*/
inline SharedPtr<VarDeclNode> resolveVariable(const String &name) {
return getCurrentScope()->resolveVariable(name);
}
/**
* @brief 查找函数
* @details 在顶级作用域中查找函数
*
* @param name 函数名
* @return 函数定义节点
*/
inline SharedPtr<FunctionDeclNode> resolveFunction(const String &name) {
return getCurrentScope()->getTopLevel()->resolveFunction(name);
}
static SharedPtr<StmtNode> resolveRefIterationStmt(const SharedPtr<Node> &node);
};