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.

26 lines
524 B

// 维护对象符号的多层作用域。
#pragma once
#include <string>
#include <string_view>
#include <unordered_map>
#include <vector>
#include "sem/Sema.h"
class SymbolTable {
public:
SymbolTable();
void EnterScope();
void ExitScope();
bool Add(const ObjectBinding& symbol);
bool ContainsInCurrentScope(std::string_view name) const;
const ObjectBinding* Lookup(std::string_view name) const;
size_t Depth() const;
private:
std::vector<std::unordered_map<std::string, ObjectBinding>> scopes_;
};