From 8304aca1c1a1941ee5ce33a58ce08add518a68d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20=C5=9Aliwak?= Date: Mon, 18 Sep 2023 15:58:29 +0200 Subject: [PATCH] TypeSystemHelper: Add isPrimitiveType() --- .../experimental/ast/TypeSystemHelper.cpp | 18 ++++++++++-------- .../experimental/ast/TypeSystemHelper.h | 1 + 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/libsolidity/experimental/ast/TypeSystemHelper.cpp b/libsolidity/experimental/ast/TypeSystemHelper.cpp index 2b4d379ad..bc7dd4fcc 100644 --- a/libsolidity/experimental/ast/TypeSystemHelper.cpp +++ b/libsolidity/experimental/ast/TypeSystemHelper.cpp @@ -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 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 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 TypeEnvironmentHelpers::typeVars(Type _type) const diff --git a/libsolidity/experimental/ast/TypeSystemHelper.h b/libsolidity/experimental/ast/TypeSystemHelper.h index 5149d34bd..fd55c1bf8 100644 --- a/libsolidity/experimental/ast/TypeSystemHelper.h +++ b/libsolidity/experimental/ast/TypeSystemHelper.h @@ -35,6 +35,7 @@ struct TypeSystemHelpers TypeSystem const& typeSystem; std::tuple> destTypeConstant(Type _type) const; bool isTypeConstant(Type _type) const; + bool isPrimitiveType(Type _type, PrimitiveType _primitiveType) const; Type tupleType(std::vector _elements) const; std::vector destTupleType(Type _tupleType) const; Type sumType(std::vector _elements) const;