forked from NUDT-compiler/nudt-compiler-cpp
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
18 lines
484 B
18 lines
484 B
// 维护局部变量声明的注册与查找。
|
|
|
|
#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;
|
|
}
|