type graph class

This commit is contained in:
ProgramSnail 2023-04-14 14:37:46 +03:00
parent 30ba8972e1
commit aa4e9fa721
6 changed files with 1073 additions and 22 deletions

View file

@ -12,7 +12,7 @@ namespace info {
class GlobalInfo {
public:
GlobalInfo() {
namespace_stack.push_back(&global_namespace_);
namespace_stack_.push_back(&global_namespace_);
}
void AddImport(ImportInfo&& import_info, const std::optional<std::string>& name = std::nullopt) {
@ -23,62 +23,80 @@ public:
}
}
void AddEnterNamespace(const std::string& type,
void AddEnterNamespace(const std::string& name,
const std::optional<NamespaceInfo::Modifier>& modifier = std::nullopt,
const std::optional<std::string>& variable = std::nullopt) {
NamespaceInfo* namespace_info = &namespace_stack.back()->namespaces[type].emplace_back();
namespace_stack.push_back(namespace_info);
NamespaceInfo* namespace_info = &namespace_stack_.back()->namespaces[name].emplace_back();
namespace_stack_.push_back(namespace_info);
namespace_info->modifier = modifier;
namespace_info->variable = variable;
namespace_info->type_name = type;
namespace_info->type_name = name;
}
void EnterNamespace(const std::string& name) { // TODO: enter sibling namespace, etc.
auto& namespace_parts = namespace_stack_.back()->namespaces[name];
for (auto& part : namespace_parts) {
if (part.variable == std::nullopt) {
namespace_stack_.push_back(&part);
}
}
}
void ExitAllNameNamespaces(const std::string& name) {
while(namespace_stack_.size() > 1 && namespace_stack_.back()->type_name == name) {
namespace_stack_.pop_back();
}
}
void ExitNamespace() {
if (namespace_stack.size() <= 1) {
if (namespace_stack_.size() <= 1) {
// error
return;
}
namespace_stack.pop_back();
namespace_stack_.pop_back();
}
void ToGlobalNamespace() {
namespace_stack.clear();
namespace_stack.push_back(&global_namespace_);
namespace_stack_.clear();
namespace_stack_.push_back(&global_namespace_);
}
void AddFunctionDeclaration(const std::string& name,
FunctionDeclarationInfo&& function_declaration_info) {
FunctionInfo* function_info = &namespace_stack.back()->functions[name];
FunctionInfo* function_info = &namespace_stack_.back()->functions[name];
function_info->declaration = std::move(function_declaration_info);
}
void AddFunctionDefinition(const std::string& name,
FunctionDefinitionInfo&& function_definition_info) {
FunctionInfo* function_info = &namespace_stack.back()->functions[name];
FunctionInfo* function_info = &namespace_stack_.back()->functions[name];
function_info->definition = std::move(function_definition_info);
}
void AddType(const std::string& type,
TypeInfo&& type_info) {
namespace_stack.back()->types[type] = std::move(type_info);
namespace_stack_.back()->types[type] = std::move(type_info);
}
void AddTypeclass(const std::string& typeclass,
TypeclassInfo&& typeclass_info) {
namespace_stack.back()->typeclasses[typeclass] = std::move(typeclass_info);
namespace_stack_.back()->typeclasses[typeclass] = std::move(typeclass_info);
}
// FindFunction
// FindType
void FindFunction(const std::vector<std::string>& path) {
// TODO
}
// FindVar ??
void FindType(const std::vector<std::string>& path) {
// TODO
}
private:
std::vector<NamespaceInfo*> namespace_stack;
std::vector<NamespaceInfo*> namespace_stack_;
NamespaceInfo global_namespace_;
std::vector<ImportInfo> imports_;