refactor(irgen): 完善irgen代码和文档,提升扩展兼容性
This commit is contained in:
@@ -7,20 +7,20 @@
|
||||
|
||||
class SemanticContext {
|
||||
public:
|
||||
void BindVarUse(SysYParser::PrimaryContext* use,
|
||||
SysYParser::VarDeclContext* decl) {
|
||||
void BindVarUse(SysYParser::VarContext* use,
|
||||
SysYParser::VarDefContext* decl) {
|
||||
var_uses_[use] = decl;
|
||||
}
|
||||
|
||||
SysYParser::VarDeclContext* ResolveVarUse(
|
||||
const SysYParser::PrimaryContext* use) const {
|
||||
SysYParser::VarDefContext* ResolveVarUse(
|
||||
const SysYParser::VarContext* use) const {
|
||||
auto it = var_uses_.find(use);
|
||||
return it == var_uses_.end() ? nullptr : it->second;
|
||||
}
|
||||
|
||||
private:
|
||||
std::unordered_map<const SysYParser::PrimaryContext*,
|
||||
SysYParser::VarDeclContext*>
|
||||
std::unordered_map<const SysYParser::VarContext*,
|
||||
SysYParser::VarDefContext*>
|
||||
var_uses_;
|
||||
};
|
||||
|
||||
|
||||
@@ -8,10 +8,10 @@
|
||||
|
||||
class SymbolTable {
|
||||
public:
|
||||
void Add(const std::string& name, SysYParser::VarDeclContext* decl);
|
||||
void Add(const std::string& name, SysYParser::VarDefContext* decl);
|
||||
bool Contains(const std::string& name) const;
|
||||
SysYParser::VarDeclContext* Lookup(const std::string& name) const;
|
||||
SysYParser::VarDefContext* Lookup(const std::string& name) const;
|
||||
|
||||
private:
|
||||
std::unordered_map<std::string, SysYParser::VarDeclContext*> table_;
|
||||
std::unordered_map<std::string, SysYParser::VarDefContext*> table_;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user