mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Moving getMemberValue from EnumDefinition to EnumType
This commit is contained in:
parent
1e4c93d5d3
commit
fbd39323af
13
AST.cpp
13
AST.cpp
@ -280,19 +280,6 @@ TypePointer EnumDefinition::getType(ContractDefinition const*) const
|
|||||||
return make_shared<TypeType>(make_shared<EnumType>(*this));
|
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
|
TypePointer FunctionDefinition::getType(ContractDefinition const*) const
|
||||||
{
|
{
|
||||||
return make_shared<FunctionType>(*this);
|
return make_shared<FunctionType>(*this);
|
||||||
|
3
AST.h
3
AST.h
@ -333,9 +333,6 @@ public:
|
|||||||
|
|
||||||
virtual TypePointer getType(ContractDefinition const*) const override;
|
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
|
/// Checks that the members do not include any duplicate names
|
||||||
void checkValidityOfMembers() const;
|
void checkValidityOfMembers() const;
|
||||||
|
|
||||||
|
@ -492,8 +492,7 @@ void ExpressionCompiler::endVisit(MemberAccess const& _memberAccess)
|
|||||||
case Type::Category::Enum:
|
case Type::Category::Enum:
|
||||||
{
|
{
|
||||||
EnumType const& type = dynamic_cast<EnumType const&>(*_memberAccess.getExpression().getType());
|
EnumType const& type = dynamic_cast<EnumType const&>(*_memberAccess.getExpression().getType());
|
||||||
EnumDefinition const& enumDef = type.getEnumDefinition();
|
m_context << type.getMemberValue(_memberAccess.getMemberName());
|
||||||
m_context << enumDef.getMemberValue(_memberAccess.getMemberName());
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Type::Category::TypeType:
|
case Type::Category::TypeType:
|
||||||
@ -516,8 +515,7 @@ void ExpressionCompiler::endVisit(MemberAccess const& _memberAccess)
|
|||||||
}
|
}
|
||||||
else if ((enumType = dynamic_cast<EnumType const*>(type.getActualType().get())))
|
else if ((enumType = dynamic_cast<EnumType const*>(type.getActualType().get())))
|
||||||
{
|
{
|
||||||
EnumDefinition const &enumDef = enumType->getEnumDefinition();
|
m_context << enumType->getMemberValue(_memberAccess.getMemberName());
|
||||||
m_context << enumDef.getMemberValue(_memberAccess.getMemberName());
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
12
Types.cpp
12
Types.cpp
@ -687,6 +687,18 @@ bool EnumType::isExplicitlyConvertibleTo(Type const& _convertTo) const
|
|||||||
return _convertTo.getCategory() == getCategory() || _convertTo.getCategory() == Category::Integer;
|
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):
|
FunctionType::FunctionType(FunctionDefinition const& _function, bool _isInternal):
|
||||||
m_location(_isInternal ? Location::Internal : Location::External),
|
m_location(_isInternal ? Location::Internal : Location::External),
|
||||||
m_isConstant(_function.isDeclaredConst()),
|
m_isConstant(_function.isDeclaredConst()),
|
||||||
|
2
Types.h
2
Types.h
@ -384,6 +384,8 @@ public:
|
|||||||
virtual bool isExplicitlyConvertibleTo(Type const& _convertTo) const override;
|
virtual bool isExplicitlyConvertibleTo(Type const& _convertTo) const override;
|
||||||
|
|
||||||
EnumDefinition const& getEnumDefinition() const { return m_enum; }
|
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:
|
private:
|
||||||
EnumDefinition const& m_enum;
|
EnumDefinition const& m_enum;
|
||||||
|
Loading…
Reference in New Issue
Block a user