TypeSystemHelper: Add isPrimitiveType()

This commit is contained in:
Kamil Śliwak 2023-09-18 15:58:29 +02:00
parent 1072f1bd55
commit 8304aca1c1
2 changed files with 11 additions and 8 deletions

View File

@ -224,6 +224,14 @@ bool TypeSystemHelpers::isTypeConstant(Type _type) const
}, _type);
}
bool TypeSystemHelpers::isPrimitiveType(Type _type, PrimitiveType _primitiveType) const
{
if (!isTypeConstant(_type))
return false;
auto constructor = std::get<0>(destTypeConstant(_type));
return constructor == typeSystem.constructor(_primitiveType);
}
experimental::Type TypeSystemHelpers::functionType(experimental::Type _argType, experimental::Type _resultType) const
{
return typeSystem.type(PrimitiveType::Function, {_argType, _resultType});
@ -239,10 +247,7 @@ std::tuple<experimental::Type, experimental::Type> TypeSystemHelpers::destFuncti
bool TypeSystemHelpers::isFunctionType(Type _type) const
{
if (!isTypeConstant(_type))
return false;
auto constructor = std::get<0>(destTypeConstant(_type));
return constructor == typeSystem.constructor(PrimitiveType::Function);
return isPrimitiveType(_type, PrimitiveType::Function);
}
experimental::Type TypeSystemHelpers::typeFunctionType(experimental::Type _argType, experimental::Type _resultType) const
@ -260,10 +265,7 @@ std::tuple<experimental::Type, experimental::Type> TypeSystemHelpers::destTypeFu
bool TypeSystemHelpers::isTypeFunctionType(Type _type) const
{
if (!isTypeConstant(_type))
return false;
auto constructor = std::get<0>(destTypeConstant(_type));
return constructor == typeSystem.constructor(PrimitiveType::TypeFunction);
return isPrimitiveType(_type, PrimitiveType::TypeFunction);
}
std::vector<experimental::Type> TypeEnvironmentHelpers::typeVars(Type _type) const

View File

@ -35,6 +35,7 @@ struct TypeSystemHelpers
TypeSystem const& typeSystem;
std::tuple<TypeConstructor, std::vector<Type>> destTypeConstant(Type _type) const;
bool isTypeConstant(Type _type) const;
bool isPrimitiveType(Type _type, PrimitiveType _primitiveType) const;
Type tupleType(std::vector<Type> _elements) const;
std::vector<Type> destTupleType(Type _tupleType) const;
Type sumType(std::vector<Type> _elements) const;