style(sema): 规范符号表代码位置
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
// 基于语法树的极简语义检查与名称绑定。
|
||||
// 基于语法树的语义检查与名称绑定。
|
||||
#pragma once
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
@@ -3,3 +3,17 @@
|
||||
// - 变量/函数/参数/常量的注册、查找与遮蔽规则
|
||||
|
||||
#include "sem/SymbolTable.h"
|
||||
|
||||
void SymbolTable::Add(const std::string& name,
|
||||
SysYParser::VarDeclContext* decl) {
|
||||
table_[name] = decl;
|
||||
}
|
||||
|
||||
bool SymbolTable::Contains(const std::string& name) const {
|
||||
return table_.find(name) != table_.end();
|
||||
}
|
||||
|
||||
SysYParser::VarDeclContext* SymbolTable::Lookup(const std::string& name) const {
|
||||
auto it = table_.find(name);
|
||||
return it == table_.end() ? nullptr : it->second;
|
||||
}
|
||||
|
||||
@@ -8,16 +8,9 @@
|
||||
|
||||
class SymbolTable {
|
||||
public:
|
||||
void Add(const std::string& name, SysYParser::VarDeclContext* decl) {
|
||||
table_[name] = decl;
|
||||
}
|
||||
bool Contains(const std::string& name) const {
|
||||
return table_.find(name) != table_.end();
|
||||
}
|
||||
SysYParser::VarDeclContext* Lookup(const std::string& name) const {
|
||||
auto it = table_.find(name);
|
||||
return it == table_.end() ? nullptr : it->second;
|
||||
}
|
||||
void Add(const std::string& name, SysYParser::VarDeclContext* decl);
|
||||
bool Contains(const std::string& name) const;
|
||||
SysYParser::VarDeclContext* Lookup(const std::string& name) const;
|
||||
|
||||
private:
|
||||
std::unordered_map<std::string, SysYParser::VarDeclContext*> table_;
|
||||
|
||||
Reference in New Issue
Block a user