mirror of
https://codeberg.org/ProgramSnail/lang_2023.git
synced 2026-01-25 21:17:11 +00:00
88 lines
2.4 KiB
C++
88 lines
2.4 KiB
C++
#pragma once
|
|
|
|
#include <string>
|
|
#include <unordered_map>
|
|
|
|
// for clangd
|
|
#include "symbols_info.hpp"
|
|
|
|
namespace info {
|
|
|
|
// TODO: partitions
|
|
class GlobalInfo {
|
|
public:
|
|
GlobalInfo() {
|
|
namespace_stack.push_back(&global_namespace_);
|
|
}
|
|
|
|
void AddImport(ImportInfo&& import_info, const std::optional<std::string>& name = std::nullopt) {
|
|
if (name.has_value()) {
|
|
usages_[name.value()] = std::move(import_info);
|
|
} else {
|
|
imports_.push_back(std::move(import_info));
|
|
}
|
|
}
|
|
|
|
void AddEnterNamespace(const std::string& type,
|
|
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);
|
|
|
|
namespace_info->modifier = modifier;
|
|
namespace_info->variable = variable;
|
|
namespace_info->type_name = type;
|
|
}
|
|
|
|
void ExitNamespace() {
|
|
if (namespace_stack.size() <= 1) {
|
|
// error
|
|
return;
|
|
}
|
|
|
|
namespace_stack.pop_back();
|
|
}
|
|
|
|
void ToGlobalNamespace() {
|
|
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];
|
|
|
|
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];
|
|
|
|
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);
|
|
}
|
|
|
|
void AddTypeclass(const std::string& typeclass,
|
|
TypeclassInfo&& typeclass_info) {
|
|
namespace_stack.back()->typeclasses[typeclass] = std::move(typeclass_info);
|
|
}
|
|
|
|
// FindFunction
|
|
// FindType
|
|
|
|
// FindVar ??
|
|
|
|
private:
|
|
std::vector<NamespaceInfo*> namespace_stack;
|
|
|
|
NamespaceInfo global_namespace_;
|
|
std::vector<ImportInfo> imports_;
|
|
std::unordered_map<std::string, ImportInfo> usages_;
|
|
};
|
|
|
|
} // namespace info
|