diff --git a/AST.cpp b/AST.cpp index 5aa672184..683452027 100644 --- a/AST.cpp +++ b/AST.cpp @@ -280,19 +280,6 @@ TypePointer EnumDefinition::getType(ContractDefinition const*) const return make_shared(make_shared(*this)); } - -unsigned int EnumDefinition::getMemberValue(ASTString const& _member) const -{ - unsigned int index = 0; - for (ASTPointer const& decl: m_members) - { - if (decl->getName() == _member) - return index; - ++index; - } - BOOST_THROW_EXCEPTION(createTypeError("Requested unknown enum value ." + _member)); -} - TypePointer FunctionDefinition::getType(ContractDefinition const*) const { return make_shared(*this); diff --git a/AST.h b/AST.h index 25c18f4f7..4167537e5 100644 --- a/AST.h +++ b/AST.h @@ -333,9 +333,6 @@ public: virtual TypePointer getType(ContractDefinition const*) const override; - /// @returns the value that the string has in the Enum - unsigned int getMemberValue(ASTString const& _member) const; - /// Checks that the members do not include any duplicate names void checkValidityOfMembers() const; diff --git a/ExpressionCompiler.cpp b/ExpressionCompiler.cpp index 00c2dafd1..63324fe58 100644 --- a/ExpressionCompiler.cpp +++ b/ExpressionCompiler.cpp @@ -492,8 +492,7 @@ void ExpressionCompiler::endVisit(MemberAccess const& _memberAccess) case Type::Category::Enum: { EnumType const& type = dynamic_cast(*_memberAccess.getExpression().getType()); - EnumDefinition const& enumDef = type.getEnumDefinition(); - m_context << enumDef.getMemberValue(_memberAccess.getMemberName()); + m_context << type.getMemberValue(_memberAccess.getMemberName()); break; } case Type::Category::TypeType: @@ -516,8 +515,7 @@ void ExpressionCompiler::endVisit(MemberAccess const& _memberAccess) } else if ((enumType = dynamic_cast(type.getActualType().get()))) { - EnumDefinition const &enumDef = enumType->getEnumDefinition(); - m_context << enumDef.getMemberValue(_memberAccess.getMemberName()); + m_context << enumType->getMemberValue(_memberAccess.getMemberName()); return; } diff --git a/Types.cpp b/Types.cpp index 06c0af320..c4a808f89 100644 --- a/Types.cpp +++ b/Types.cpp @@ -687,6 +687,18 @@ bool EnumType::isExplicitlyConvertibleTo(Type const& _convertTo) const return _convertTo.getCategory() == getCategory() || _convertTo.getCategory() == Category::Integer; } +unsigned int EnumType::getMemberValue(ASTString const& _member) const +{ + unsigned int index = 0; + for (ASTPointer const& decl: m_enum.getMembers()) + { + if (decl->getName() == _member) + return index; + ++index; + } + BOOST_THROW_EXCEPTION(m_enum.createTypeError("Requested unknown enum value ." + _member)); +} + FunctionType::FunctionType(FunctionDefinition const& _function, bool _isInternal): m_location(_isInternal ? Location::Internal : Location::External), m_isConstant(_function.isDeclaredConst()), diff --git a/Types.h b/Types.h index d8b1b6b7a..3b4eee57f 100644 --- a/Types.h +++ b/Types.h @@ -384,6 +384,8 @@ public: virtual bool isExplicitlyConvertibleTo(Type const& _convertTo) const override; EnumDefinition const& getEnumDefinition() const { return m_enum; } + /// @returns the value that the string has in the Enum + unsigned int getMemberValue(ASTString const& _member) const; private: EnumDefinition const& m_enum;