mirror of
https://codeberg.org/ProgramSnail/lang_2023.git
synced 2026-01-25 13:07:13 +00:00
type_check_visitor part
This commit is contained in:
parent
d13faf104d
commit
94ef8702fb
11 changed files with 496 additions and 288 deletions
|
|
@ -5,6 +5,7 @@
|
|||
#include <variant>
|
||||
#include <memory>
|
||||
#include <unordered_set>
|
||||
#include <unordered_map>
|
||||
|
||||
// for clangd
|
||||
#include "utils.hpp"
|
||||
|
|
@ -25,6 +26,7 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
std::optional<utils::IdType> InContext(const std::unordered_map<std::string, utils::IdType>& context);
|
||||
bool Same(const AbstractType& type) const;
|
||||
bool operator<(const AbstractType& type) const;
|
||||
bool operator>(const AbstractType& type) const;
|
||||
|
|
@ -41,9 +43,14 @@ public:
|
|||
TypeManager* type_manager)
|
||||
: type_id_(type_id), type_(type), type_manager_(type_manager) {}
|
||||
|
||||
std::optional<utils::IdType> InContext(const std::unordered_map<std::string, utils::IdType>& context);
|
||||
bool Same(const DefinedType& type) const;
|
||||
bool operator<(const DefinedType& type) const;
|
||||
bool operator>(const DefinedType& type) const;
|
||||
|
||||
utils::IdType GetTypeId() {
|
||||
return type_id_;
|
||||
}
|
||||
private:
|
||||
utils::IdType type_id_; // in defined types
|
||||
utils::IdType type_; // in types manager, created using context types (if specific type)
|
||||
|
|
@ -67,9 +74,14 @@ public:
|
|||
TypeManager* type_manager)
|
||||
: name_(name), fields_(fields), type_manager_(type_manager) {}
|
||||
|
||||
std::optional<utils::IdType> InContext(const std::unordered_map<std::string, utils::IdType>& context);
|
||||
bool Same(const TupleType& type) const;
|
||||
bool operator<(const TupleType& type) const;
|
||||
bool operator>(const TupleType& type) const;
|
||||
|
||||
const std::vector<std::pair<std::optional<std::string>, utils::IdType>>& GetFields() const {
|
||||
return fields_;
|
||||
}
|
||||
private:
|
||||
std::optional<std::string> name_;
|
||||
std::vector<std::pair<std::optional<std::string>, utils::IdType>> fields_;
|
||||
|
|
@ -83,9 +95,14 @@ public:
|
|||
const std::vector<TupleType>& constructors)
|
||||
: name_(name), constructors_(constructors){}
|
||||
|
||||
std::optional<utils::IdType> InContext(const std::unordered_map<std::string, utils::IdType>& context);
|
||||
bool Same(const VariantType& type) const;
|
||||
bool operator<(const VariantType& type) const;
|
||||
bool operator>(const VariantType& type) const;
|
||||
|
||||
const std::vector<TupleType>& GetConstructors() const {
|
||||
return constructors_;
|
||||
}
|
||||
private:
|
||||
std::optional<std::string> name_;
|
||||
std::vector<TupleType> constructors_;
|
||||
|
|
@ -98,6 +115,7 @@ public:
|
|||
TypeManager* type_manager)
|
||||
: type_(type), type_manager_(type_manager) {}
|
||||
|
||||
std::optional<utils::IdType> InContext(const std::unordered_map<std::string, utils::IdType>& context);
|
||||
bool Same(const OptionalType& type) const;
|
||||
bool operator<(const OptionalType& type) const;
|
||||
bool operator>(const OptionalType& type) const;
|
||||
|
|
@ -114,6 +132,7 @@ public:
|
|||
TypeManager* type_manager)
|
||||
: references_(references), type_(type), type_manager_(type_manager) {}
|
||||
|
||||
std::optional<utils::IdType> InContext(const std::unordered_map<std::string, utils::IdType>& context);
|
||||
bool Same(const ReferenceToType& type) const;
|
||||
bool operator<(const ReferenceToType& type) const;
|
||||
bool operator>(const ReferenceToType& type) const;
|
||||
|
|
@ -133,6 +152,7 @@ public:
|
|||
TypeManager* type_manager)
|
||||
: argument_types_(argument_types), return_type_(return_type), type_manager_(type_manager) {}
|
||||
|
||||
std::optional<utils::IdType> InContext(const std::unordered_map<std::string, utils::IdType>& context);
|
||||
bool Same(const FunctionType& type) const;
|
||||
bool operator<(const FunctionType& type) const;
|
||||
bool operator>(const FunctionType& type) const;
|
||||
|
|
@ -150,9 +170,14 @@ public:
|
|||
TypeManager* type_manager)
|
||||
: size_(size), elements_type_(elements_type), type_manager_(type_manager) {}
|
||||
|
||||
std::optional<utils::IdType> InContext(const std::unordered_map<std::string, utils::IdType>& context);
|
||||
bool Same(const ArrayType& type) const;
|
||||
bool operator<(const ArrayType& type) const;
|
||||
bool operator>(const ArrayType& type) const;
|
||||
|
||||
utils::IdType GetElementsType() {
|
||||
return elements_type_;
|
||||
}
|
||||
private:
|
||||
size_t size_; // = 0 for dynamic
|
||||
utils::IdType elements_type_;
|
||||
|
|
@ -164,8 +189,9 @@ public:
|
|||
template<typename T>
|
||||
explicit Type(T&& type) : type_(std::forward(type)) {}
|
||||
|
||||
bool Same(const Type& type) const; // some rule exceptions ??
|
||||
bool operator<(const Type& type) const; // TODO: some rule exceptions ??
|
||||
std::optional<utils::IdType> InContext(const std::unordered_map<std::string, utils::IdType>& context);
|
||||
bool Same(const Type& type) const;
|
||||
bool operator<(const Type& type) const; // TODO: rule exceptions
|
||||
bool operator>(const Type& type) const;
|
||||
private:
|
||||
std::variant<AbstractType,
|
||||
|
|
@ -186,10 +212,10 @@ public:
|
|||
template<typename T>
|
||||
std::optional<T*> GetType(utils::IdType type_id);
|
||||
|
||||
std::optional<Type*> GetAnyType(utils::IdType type_id);
|
||||
Type* GetAnyType(utils::IdType type_id);
|
||||
|
||||
void AddTypeRequirement(utils::IdType type, utils::IdType requrement); // TODO
|
||||
void EqualTypes(utils::IdType first_type, utils::IdType second_type); // TODO
|
||||
bool AddTypeRequirement(utils::IdType type, utils::IdType requrement);
|
||||
bool EqualTypes(utils::IdType first_type, utils::IdType second_type);
|
||||
private:
|
||||
std::vector<info::type::Type> types_;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue