2023-03-26 15:20:53 +03:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <string>
|
2023-04-14 16:43:56 +03:00
|
|
|
#include <functional>
|
2023-03-26 15:20:53 +03:00
|
|
|
#include <unordered_map>
|
|
|
|
|
|
|
|
|
|
// for clangd
|
|
|
|
|
#include "symbols_info.hpp"
|
2023-04-17 11:14:33 +03:00
|
|
|
#include "utils.hpp"
|
2023-03-26 15:20:53 +03:00
|
|
|
|
|
|
|
|
namespace info {
|
|
|
|
|
|
2023-04-07 12:13:31 +03:00
|
|
|
// TODO: partitions
|
2023-03-26 15:20:53 +03:00
|
|
|
class GlobalInfo {
|
2023-04-17 11:14:33 +03:00
|
|
|
friend class NamespaceVisitor;
|
2023-03-26 15:20:53 +03:00
|
|
|
public:
|
2023-04-17 11:14:33 +03:00
|
|
|
class NamespaceVisitor {
|
|
|
|
|
friend GlobalInfo;
|
|
|
|
|
NamespaceVisitor() = delete;
|
|
|
|
|
public:
|
|
|
|
|
void AddImport(ImportInfo&& import_info, const std::optional<std::string>& name = std::nullopt);
|
2023-04-07 12:13:31 +03:00
|
|
|
|
2023-04-17 11:14:33 +03:00
|
|
|
void AddEnterNamespace(const std::string& name,
|
|
|
|
|
const std::optional<NamespaceInfo::Modifier>& modifier = std::nullopt,
|
|
|
|
|
const std::optional<std::string>& variable = std::nullopt);
|
2023-04-07 12:13:31 +03:00
|
|
|
|
2023-04-17 11:14:33 +03:00
|
|
|
void EnterNamespace(const std::string& name);
|
2023-04-14 14:37:46 +03:00
|
|
|
|
2023-04-17 11:14:33 +03:00
|
|
|
void ExitNamespace();
|
2023-04-14 14:37:46 +03:00
|
|
|
|
2023-04-17 11:14:33 +03:00
|
|
|
void ToGlobalNamespace();
|
2023-04-07 12:13:31 +03:00
|
|
|
|
2023-04-17 11:14:33 +03:00
|
|
|
utils::IdType AddFunctionDeclaration(const std::string& name,
|
|
|
|
|
FunctionDeclarationInfo&& function_declaration_info);
|
2023-04-07 12:13:31 +03:00
|
|
|
|
2023-04-17 11:14:33 +03:00
|
|
|
utils::IdType AddFunctionDefinition(const std::string& name,
|
|
|
|
|
FunctionDefinitionInfo&& function_definition_info);
|
2023-04-07 12:13:31 +03:00
|
|
|
|
2023-04-17 11:14:33 +03:00
|
|
|
utils::IdType AddType(const std::string& type, TypeInfo&& type_info);
|
2023-04-07 12:13:31 +03:00
|
|
|
|
2023-04-17 11:14:33 +03:00
|
|
|
utils::IdType AddTypeclass(const std::string& typeclass, TypeclassInfo&& typeclass_info);
|
2023-04-07 12:13:31 +03:00
|
|
|
|
2023-04-17 11:14:33 +03:00
|
|
|
std::optional<NamespaceInfo*> FindNamespace(const std::optional<std::vector<std::string>>& path);
|
2023-04-07 12:13:31 +03:00
|
|
|
|
2023-04-17 11:14:33 +03:00
|
|
|
std::optional<utils::IdType> FindFunction(const std::optional<std::vector<std::string>>& path,
|
|
|
|
|
const std::string& name);
|
2023-04-07 12:13:31 +03:00
|
|
|
|
2023-04-17 11:14:33 +03:00
|
|
|
std::optional<utils::IdType> FindMethod(const std::optional<std::vector<std::string>>& path,
|
|
|
|
|
const std::string& type,
|
|
|
|
|
const std::string& name);
|
2023-04-07 12:13:31 +03:00
|
|
|
|
2023-04-17 11:14:33 +03:00
|
|
|
std::optional<utils::IdType> FindType(const std::optional<std::vector<std::string>>& path,
|
|
|
|
|
const std::string type);
|
2023-04-07 12:13:31 +03:00
|
|
|
|
2023-04-17 11:14:33 +03:00
|
|
|
std::optional<utils::IdType> FindTypeclass(const std::optional<std::vector<std::string>>& path,
|
|
|
|
|
const std::string typeclass);
|
|
|
|
|
private:
|
|
|
|
|
NamespaceVisitor(GlobalInfo& global_info) : global_info_(global_info),
|
|
|
|
|
namespace_stack_({&global_info.global_namespace_}) {}
|
2023-04-07 12:13:31 +03:00
|
|
|
|
2023-04-17 11:14:33 +03:00
|
|
|
template<typename T>
|
|
|
|
|
std::optional<T*> FindSomething(const std::optional<std::vector<std::string>>& path,
|
|
|
|
|
std::function<std::optional<T*>(NamespaceInfo*)> search_func);
|
2023-04-14 16:43:56 +03:00
|
|
|
|
2023-04-17 11:14:33 +03:00
|
|
|
std::optional<NamespaceInfo*> FindNamespaceIn(NamespaceInfo* current_namespace,
|
|
|
|
|
const std::vector<std::string>& path);
|
|
|
|
|
private:
|
|
|
|
|
std::vector<NamespaceInfo*> namespace_stack_;
|
2023-04-14 16:43:56 +03:00
|
|
|
|
2023-04-17 11:14:33 +03:00
|
|
|
GlobalInfo& global_info_;
|
|
|
|
|
};
|
2023-04-14 16:43:56 +03:00
|
|
|
|
2023-04-17 11:14:33 +03:00
|
|
|
NamespaceVisitor CreateVisitor() {
|
|
|
|
|
return NamespaceVisitor(*this);
|
2023-04-14 16:43:56 +03:00
|
|
|
}
|
|
|
|
|
|
2023-04-17 11:14:33 +03:00
|
|
|
FunctionInfo* GetFunctionInfo(utils::IdType id) {
|
|
|
|
|
return functions_.GetValue(id);
|
2023-04-14 14:37:46 +03:00
|
|
|
}
|
2023-04-07 12:13:31 +03:00
|
|
|
|
2023-04-17 11:14:33 +03:00
|
|
|
TypeInfo* GetTypeInfo(utils::IdType id) {
|
|
|
|
|
return types_.GetValue(id);
|
2023-04-14 16:43:56 +03:00
|
|
|
}
|
|
|
|
|
|
2023-04-17 11:14:33 +03:00
|
|
|
TypeclassInfo* GetTypeclassInfo(utils::IdType id) {
|
|
|
|
|
return typeclasses_.GetValue(id);
|
2023-04-14 14:37:46 +03:00
|
|
|
}
|
2023-03-26 15:20:53 +03:00
|
|
|
|
|
|
|
|
private:
|
2023-04-17 11:14:33 +03:00
|
|
|
utils::Storage<FunctionInfo*> functions_;
|
|
|
|
|
utils::Storage<TypeInfo*> types_;
|
|
|
|
|
utils::Storage<TypeclassInfo*> typeclasses_;
|
2023-04-07 12:13:31 +03:00
|
|
|
|
2023-03-26 15:20:53 +03:00
|
|
|
NamespaceInfo global_namespace_;
|
2023-04-07 12:13:31 +03:00
|
|
|
std::vector<ImportInfo> imports_;
|
|
|
|
|
std::unordered_map<std::string, ImportInfo> usages_;
|
2023-03-26 15:20:53 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace info
|