type_check_visitor part

This commit is contained in:
ProgramSnail 2023-05-03 15:03:57 +03:00
parent d13faf104d
commit 94ef8702fb
11 changed files with 496 additions and 288 deletions

View file

@ -1,66 +0,0 @@
#pragma once
#include <string>
////////////////////////////////////////////////////////////////////////////////////////
// Temporary frozen, TODO
////////////////////////////////////////////////////////////////////////////////////////
#pragma once
#include <unordered_map>
// for calngd
#include "utils.hpp"
#include "interpreter_tree.hpp"
#include "error_handling.hpp"
namespace info {
class TypeclassGraph {
public:
struct TypeclassMethod {
std::string name;
interpreter::tokens::FunctionDeclaration* definition = nullptr;
};
struct ParametrizedTypeclass {
utils::IdType typeclass;
std::vector<utils::IdType> parameter_ids; // ??
};
struct TypeclassVertex {
std::vector<std::pair<std::string, std::vector<ParametrizedTypeclass>>> parameters;
std::vector<TypeclassMethod> methods;
std::vector<ParametrizedTypeclass> dependencies;
interpreter::tokens::TypeclassDefinitionStatement* definition = nullptr;
};
utils::IdType AddTypeclass(const TypeclassVertex& typeclass) { // TODO: universal reference
for (auto& method : typeclass.methods) {
if (method_to_typeclass_.count(method.name) != 0) {
error_handling::HandleTypecheckError("");
}
}
for (auto& method : typeclass.methods) {
method_to_typeclass_[method.name] = typeclasses_.size();
}
typeclasses_.push_back(typeclass);
return typeclasses_.size() - 1;
}
std::optional<utils::IdType> FindMethodTypeclass(const std::string& name) {
auto method_iter = method_to_typeclass_.find(name);
if (method_iter == method_to_typeclass_.end()) {
return std::nullopt;
}
return method_iter->second;
}
const TypeclassVertex& GetTypeclass(utils::IdType id) {
return typeclasses_.at(id);
}
private:
std::unordered_map<std::string, utils::IdType> method_to_typeclass_;
std::vector<TypeclassVertex> typeclasses_;
};
} // namespace info