mirror of
https://codeberg.org/ProgramSnail/lang_2023.git
synced 2026-01-25 13:07:13 +00:00
big part of type_chack_visitor done
This commit is contained in:
parent
adccf6feec
commit
f7080ba856
7 changed files with 427 additions and 171 deletions
|
|
@ -31,6 +31,9 @@ public:
|
|||
bool Same(const AbstractType& type) const;
|
||||
bool operator<(const AbstractType& type) const;
|
||||
bool operator>(const AbstractType& type) const;
|
||||
|
||||
std::optional<utils::IdType> GetFieldType(const std::string& name) const;
|
||||
|
||||
private:
|
||||
utils::AbstractTypeModifier modifier_;
|
||||
std::string name_;
|
||||
|
|
@ -50,6 +53,8 @@ public:
|
|||
bool operator<(const DefinedType& type) const;
|
||||
bool operator>(const DefinedType& type) const;
|
||||
|
||||
std::optional<utils::IdType> GetFieldType(const std::string& name) const;
|
||||
|
||||
utils::IdType GetTypeId() const {
|
||||
return type_id_;
|
||||
}
|
||||
|
|
@ -86,6 +91,8 @@ public:
|
|||
bool operator<(const TupleType& type) const;
|
||||
bool operator>(const TupleType& type) const;
|
||||
|
||||
std::optional<utils::IdType> GetFieldType(const std::string& name) const;
|
||||
|
||||
const std::vector<std::pair<std::optional<std::string>, utils::IdType>>& GetFields() const {
|
||||
return fields_;
|
||||
}
|
||||
|
|
@ -100,21 +107,29 @@ class VariantType {
|
|||
public:
|
||||
VariantType() = default;
|
||||
VariantType(const std::optional<std::string>& name,
|
||||
const std::vector<TupleType>& constructors)
|
||||
: name_(name), constructors_(constructors){}
|
||||
const std::vector<TupleType>& constructors,
|
||||
std::optional<size_t> current_constructor)
|
||||
: name_(name), constructors_(constructors), current_constructor_(current_constructor) {}
|
||||
|
||||
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;
|
||||
|
||||
std::optional<utils::IdType> GetFieldType(const std::string& name) const;
|
||||
|
||||
const std::vector<TupleType>& GetConstructors() const {
|
||||
return constructors_;
|
||||
}
|
||||
|
||||
const void SetCurrentConstructor(size_t constructor) {
|
||||
current_constructor_ = constructor;
|
||||
}
|
||||
|
||||
private:
|
||||
std::optional<std::string> name_;
|
||||
std::vector<TupleType> constructors_;
|
||||
std::optional<size_t> current_constructor_;
|
||||
};
|
||||
|
||||
class OptionalType {
|
||||
|
|
@ -129,6 +144,8 @@ public:
|
|||
bool operator<(const OptionalType& type) const;
|
||||
bool operator>(const OptionalType& type) const;
|
||||
|
||||
std::optional<utils::IdType> GetFieldType(const std::string& name) const;
|
||||
|
||||
private:
|
||||
utils::IdType type_;
|
||||
TypeManager* type_manager_ = nullptr;
|
||||
|
|
@ -147,6 +164,8 @@ public:
|
|||
bool operator<(const ReferenceToType& type) const;
|
||||
bool operator>(const ReferenceToType& type) const;
|
||||
|
||||
std::optional<utils::IdType> GetFieldType(const std::string& name) const;
|
||||
|
||||
private:
|
||||
std::vector<utils::ReferenceModifier> references_;
|
||||
utils::IdType type_;
|
||||
|
|
@ -168,6 +187,8 @@ public:
|
|||
bool operator<(const FunctionType& type) const;
|
||||
bool operator>(const FunctionType& type) const;
|
||||
|
||||
std::optional<utils::IdType> GetFieldType(const std::string& name) const;
|
||||
|
||||
private:
|
||||
std::vector<utils::IdType> argument_types_;
|
||||
utils::IdType return_type_;
|
||||
|
|
@ -187,6 +208,8 @@ public:
|
|||
bool operator<(const ArrayType& type) const;
|
||||
bool operator>(const ArrayType& type) const;
|
||||
|
||||
std::optional<utils::IdType> GetFieldType(const std::string& name) const;
|
||||
|
||||
utils::IdType GetElementsType() {
|
||||
return elements_type_;
|
||||
}
|
||||
|
|
@ -199,6 +222,8 @@ private:
|
|||
|
||||
class Type {
|
||||
public:
|
||||
Type() = default;
|
||||
|
||||
template<typename T>
|
||||
explicit Type(T&& type) : type_(std::forward(type)) {}
|
||||
|
||||
|
|
@ -207,6 +232,8 @@ public:
|
|||
bool operator<(const Type& type) const; // TODO: rule exceptions
|
||||
bool operator>(const Type& type) const;
|
||||
|
||||
std::optional<utils::IdType> GetFieldType(const std::string& name) const;
|
||||
|
||||
private:
|
||||
std::variant<AbstractType,
|
||||
DefinedType,
|
||||
|
|
@ -215,24 +242,29 @@ private:
|
|||
VariantType,
|
||||
ReferenceToType,
|
||||
FunctionType,
|
||||
ArrayType> type_;
|
||||
ArrayType,
|
||||
OptionalType> type_;
|
||||
};
|
||||
|
||||
class TypeManager {
|
||||
public:
|
||||
template<typename T>
|
||||
utils::IdType AddType(const T&& type);
|
||||
utils::IdType AddType(T&& type, utils::ValueType value_type);
|
||||
|
||||
utils::IdType AddAnyType(Type&& type, utils::ValueType value_type);
|
||||
|
||||
template<typename T>
|
||||
std::optional<T*> GetType(utils::IdType type_id);
|
||||
|
||||
Type* GetAnyType(utils::IdType type_id);
|
||||
|
||||
utils::ValueType GetValueType(utils::IdType type_id);
|
||||
|
||||
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_;
|
||||
std::vector<std::pair<info::type::Type, utils::ValueType>> types_;
|
||||
};
|
||||
|
||||
} // namespace info::type
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue