new symbol table structure

This commit is contained in:
ProgramSnail 2023-04-17 11:31:00 +03:00
parent 782a48c4ff
commit 25355974a2
5 changed files with 82 additions and 57 deletions

View file

@ -59,8 +59,8 @@ public:
namespace_stack_({&global_info.global_namespace_}) {}
template<typename T>
std::optional<T*> FindSomething(const std::optional<std::vector<std::string>>& path,
std::function<std::optional<T*>(NamespaceInfo*)> search_func);
std::optional<T> FindSomething(const std::optional<std::vector<std::string>>& path,
std::function<std::optional<T>(NamespaceInfo*)> search_func);
std::optional<NamespaceInfo*> FindNamespaceIn(NamespaceInfo* current_namespace,
const std::vector<std::string>& path);
@ -74,22 +74,25 @@ public:
return NamespaceVisitor(*this);
}
// TODO: remember about vector realloc
FunctionInfo* GetFunctionInfo(utils::IdType id) {
return functions_.GetValue(id);
return &functions_[id];
}
// TODO: remember about vector realloc
TypeInfo* GetTypeInfo(utils::IdType id) {
return types_.GetValue(id);
return &types_[id];
}
// TODO: remember about vector realloc
TypeclassInfo* GetTypeclassInfo(utils::IdType id) {
return typeclasses_.GetValue(id);
return &typeclasses_[id];
}
private:
utils::Storage<FunctionInfo*> functions_;
utils::Storage<TypeInfo*> types_;
utils::Storage<TypeclassInfo*> typeclasses_;
std::vector<FunctionInfo> functions_;
std::vector<TypeInfo> types_;
std::vector<TypeclassInfo> typeclasses_;
NamespaceInfo global_namespace_;
std::vector<ImportInfo> imports_;