mirror of
https://codeberg.org/ProgramSnail/lang_2023.git
synced 2026-01-25 13:07:13 +00:00
better global_info API, better const/var/static handling, const typeclass requirements, fixes
This commit is contained in:
parent
047ead6fa3
commit
4f54bb4bd7
15 changed files with 381 additions and 213 deletions
|
|
@ -1,6 +1,5 @@
|
|||
#pragma once
|
||||
|
||||
#include <asm-generic/errno.h>
|
||||
#include <string>
|
||||
#include <functional>
|
||||
#include <unordered_map>
|
||||
|
|
@ -8,6 +7,7 @@
|
|||
// for clangd
|
||||
#include "definitions.hpp"
|
||||
#include "interpreter_tree.hpp"
|
||||
#include "typeclass_graph.hpp"
|
||||
#include "utils.hpp"
|
||||
|
||||
namespace info {
|
||||
|
|
@ -40,11 +40,11 @@ public:
|
|||
void AddImport(definition::Import&& import_info, const std::optional<std::string>& name = std::nullopt);
|
||||
|
||||
void AddEnterNamespace(const std::string& name,
|
||||
std::optional<utils::IsConstModifier> modifier,
|
||||
utils::ClassInternalsModifier modifier,
|
||||
const interpreter::tokens::BaseNode& base_node);
|
||||
|
||||
void EnterNamespace(const std::string& name,
|
||||
std::optional<utils::IsConstModifier> modifier);
|
||||
utils::ClassInternalsModifier modifier);
|
||||
|
||||
void ExitNamespace();
|
||||
|
||||
|
|
@ -77,28 +77,117 @@ public:
|
|||
utils::IdType AddPartition(const std::vector<std::string>& path, // including name
|
||||
interpreter::tokens::PartitionStatement* node);
|
||||
|
||||
std::optional<utils::IdType> FindNamespace(const std::optional<std::vector<std::string>>& path);
|
||||
std::optional<utils::IdType> FindNamespaceId(const std::optional<std::vector<std::string>>& path);
|
||||
|
||||
std::optional<utils::IdType> FindFunction(const std::optional<std::vector<std::string>>& path,
|
||||
const std::string& name);
|
||||
std::optional<utils::IdType> FindFunctionId(const std::optional<std::vector<std::string>>& path,
|
||||
const std::string& name);
|
||||
|
||||
std::optional<utils::IdType> FindMethod(const std::optional<std::vector<std::string>>& path,
|
||||
const std::string& type,
|
||||
const std::string& name,
|
||||
utils::IsConstModifier modifier);
|
||||
std::optional<utils::IdType> FindMethodId(const std::optional<std::vector<std::string>>& path,
|
||||
const std::string& type,
|
||||
const std::string& name,
|
||||
utils::IsConstModifier modifier);
|
||||
|
||||
std::optional<utils::IdType> FindType(const std::optional<std::vector<std::string>>& path,
|
||||
const std::string& type);
|
||||
std::optional<utils::IdType> FindTypeId(const std::optional<std::vector<std::string>>& path,
|
||||
const std::string& type);
|
||||
|
||||
std::optional<utils::IdType> FindLocalType(const std::string& type);
|
||||
std::optional<utils::IdType> FindLocalTypeId(const std::string& type);
|
||||
|
||||
std::optional<utils::IdType> FindAbstractType(const std::string& abstract_type);
|
||||
std::optional<utils::IdType> FindAbstractTypeId(const std::string& abstract_type);
|
||||
|
||||
std::optional<utils::IdType> FindTypeclass(const std::string& typeclass);
|
||||
std::optional<utils::IdType> FindTypeclassId(const std::string& typeclass);
|
||||
|
||||
std::optional<utils::IdType> FindConstructor(const std::optional<std::vector<std::string>>& path,
|
||||
std::optional<utils::IdType> FindConstructorId(const std::optional<std::vector<std::string>>& path,
|
||||
const std::string& constructor);
|
||||
|
||||
std::optional<definition::Namespace*> FindNamespace(const std::optional<std::vector<std::string>>& path) {
|
||||
std::optional<utils::IdType> id = FindNamespaceId(path);
|
||||
if (!id.has_value()) {
|
||||
return std::nullopt;
|
||||
}
|
||||
return &global_info_.GetNamespaceInfo(id.value());
|
||||
}
|
||||
|
||||
std::optional<definition::Function*> FindFunction(const std::optional<std::vector<std::string>>& path,
|
||||
const std::string& name) {
|
||||
std::optional<utils::IdType> id = FindFunctionId(path, name);
|
||||
if (!id.has_value()) {
|
||||
return std::nullopt;
|
||||
}
|
||||
return &global_info_.GetFunctionInfo(id.value());
|
||||
}
|
||||
|
||||
std::optional<definition::Function*> FindMethod(const std::optional<std::vector<std::string>>& path,
|
||||
const std::string& type,
|
||||
const std::string& name,
|
||||
utils::IsConstModifier modifier) {
|
||||
std::optional<utils::IdType> id = FindFunctionId(path, name);
|
||||
if (!id.has_value()) {
|
||||
return std::nullopt;
|
||||
}
|
||||
return &global_info_.GetFunctionInfo(id.value());
|
||||
}
|
||||
|
||||
std::optional<definition::Type*> FindAnyType(const std::optional<std::vector<std::string>>& path,
|
||||
const std::string& type) {
|
||||
std::optional<utils::IdType> id = FindTypeId(path, type);
|
||||
if (!id.has_value()) {
|
||||
return std::nullopt;
|
||||
}
|
||||
return &global_info_.GetAnyTypeInfo(id.value());
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
std::optional<T*> FindType(const std::optional<std::vector<std::string>>& path,
|
||||
const std::string& type) {
|
||||
std::optional<utils::IdType> id = FindTypeId(path, type);
|
||||
if (!id.has_value()) {
|
||||
return std::nullopt;
|
||||
}
|
||||
return global_info_.GetTypeInfo<T>(id.value());
|
||||
}
|
||||
|
||||
std::optional<definition::Type*> FindAnyLocalType(const std::string& type) {
|
||||
std::optional<utils::IdType> id = FindLocalTypeId(type);
|
||||
if (!id.has_value()) {
|
||||
return std::nullopt;
|
||||
}
|
||||
return &global_info_.GetAnyTypeInfo(id.value());
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
std::optional<T*> FindLocalType(const std::string& type) {
|
||||
std::optional<utils::IdType> id = FindLocalTypeId(type);
|
||||
if (!id.has_value()) {
|
||||
return std::nullopt;
|
||||
}
|
||||
return global_info_.GetTypeInfo<T>(id.value());
|
||||
}
|
||||
|
||||
std::optional<definition::AbstractType*> FindAbstractType(const std::string& abstract_type) {
|
||||
std::optional<utils::IdType> id = FindAbstractTypeId(abstract_type);
|
||||
if (!id.has_value()) {
|
||||
return std::nullopt;
|
||||
}
|
||||
return &global_info_.GetAbstractTypeInfo(id.value());
|
||||
}
|
||||
|
||||
std::optional<definition::Typeclass*> FindTypeclass(const std::string& typeclass) {
|
||||
std::optional<utils::IdType> id = FindTypeclassId(typeclass);
|
||||
if (!id.has_value()) {
|
||||
return std::nullopt;
|
||||
}
|
||||
return &global_info_.GetTypeclassInfo(id.value());
|
||||
}
|
||||
|
||||
std::optional<definition::Constructor*> FindConstructor(const std::optional<std::vector<std::string>>& path,
|
||||
const std::string& constructor) {
|
||||
std::optional<utils::IdType> id = FindConstructorId(path, constructor);
|
||||
if (!id.has_value()) {
|
||||
return std::nullopt;
|
||||
}
|
||||
return &global_info_.GetConstructorInfo(id.value());
|
||||
}
|
||||
|
||||
NamespaceVisitor CreateVisitor() {
|
||||
return global_info_.CreateVisitor();
|
||||
}
|
||||
|
|
@ -107,6 +196,10 @@ public:
|
|||
return &global_info_;
|
||||
}
|
||||
|
||||
TypeclassGraph* GetTypeclassGraph() {
|
||||
return global_info_.GetTypeclassGraph();
|
||||
}
|
||||
|
||||
const std::vector<std::string>& GetCurrentPath() {
|
||||
return current_path_;
|
||||
}
|
||||
|
|
@ -128,7 +221,7 @@ public:
|
|||
const std::vector<std::string>& path);
|
||||
|
||||
std::unordered_map<std::string, utils::IdType>*
|
||||
ChooseNamespaces(std::optional<utils::IsConstModifier> modifier,
|
||||
ChooseNamespaces(utils::ClassInternalsModifier modifier,
|
||||
utils::IdType namespace_id);
|
||||
private:
|
||||
GlobalInfo& global_info_;
|
||||
|
|
@ -145,6 +238,10 @@ public:
|
|||
return functions_.at(id);
|
||||
}
|
||||
|
||||
definition::Type& GetAnyTypeInfo(utils::IdType id) {
|
||||
return types_.at(id);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
std::optional<T*> GetTypeInfo(utils::IdType id) {
|
||||
if (!std::holds_alternative<T>(types_.at(id).type)) {
|
||||
|
|
@ -153,8 +250,8 @@ public:
|
|||
return &std::get<T>(types_[id].type);
|
||||
}
|
||||
|
||||
definition::Type& GetAnyTypeInfo(utils::IdType id) {
|
||||
return types_.at(id);
|
||||
definition::AbstractType& GetAbstractTypeInfo(utils::IdType id) {
|
||||
return abstract_types_.at(id);
|
||||
}
|
||||
|
||||
definition::Typeclass& GetTypeclassInfo(utils::IdType id) {
|
||||
|
|
@ -190,6 +287,10 @@ public:
|
|||
return ans;
|
||||
}
|
||||
|
||||
TypeclassGraph* GetTypeclassGraph() {
|
||||
return &typeclass_graph_;
|
||||
}
|
||||
|
||||
private:
|
||||
const utils::IdType GlobalNamespaceId = 0;
|
||||
|
||||
|
|
@ -209,6 +310,8 @@ private:
|
|||
|
||||
std::vector<definition::Import> imports_;
|
||||
std::unordered_map<std::string, definition::Import> usages_;
|
||||
|
||||
TypeclassGraph typeclass_graph_;
|
||||
};
|
||||
|
||||
} // namespace info
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue