Browse Source

Moving getMemberValue from EnumDefinition to EnumType

cl-refactor
Lefteris Karapetsas 10 years ago
parent
commit
58c598b8cb
  1. 13
      libsolidity/AST.cpp
  2. 3
      libsolidity/AST.h
  3. 6
      libsolidity/ExpressionCompiler.cpp
  4. 12
      libsolidity/Types.cpp
  5. 2
      libsolidity/Types.h

13
libsolidity/AST.cpp

@ -280,19 +280,6 @@ TypePointer EnumDefinition::getType(ContractDefinition const*) const
return make_shared<TypeType>(make_shared<EnumType>(*this));
}
unsigned int EnumDefinition::getMemberValue(ASTString const& _member) const
{
unsigned int index = 0;
for (ASTPointer<EnumValue> 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<FunctionType>(*this);

3
libsolidity/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;

6
libsolidity/ExpressionCompiler.cpp

@ -492,8 +492,7 @@ void ExpressionCompiler::endVisit(MemberAccess const& _memberAccess)
case Type::Category::Enum:
{
EnumType const& type = dynamic_cast<EnumType const&>(*_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<EnumType const*>(type.getActualType().get())))
{
EnumDefinition const &enumDef = enumType->getEnumDefinition();
m_context << enumDef.getMemberValue(_memberAccess.getMemberName());
m_context << enumType->getMemberValue(_memberAccess.getMemberName());
return;
}

12
libsolidity/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<EnumValue> 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()),

2
libsolidity/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;

Loading…
Cancel
Save