mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Correcting and testing enum member access
This commit is contained in:
parent
a989f6f97a
commit
e7f40863ef
20
Types.cpp
20
Types.cpp
@ -682,19 +682,6 @@ string EnumType::toString() const
|
||||
return string("enum ") + m_enum.getName();
|
||||
}
|
||||
|
||||
MemberList const& EnumType::getMembers() const
|
||||
{
|
||||
// We need to lazy-initialize it because of recursive references.
|
||||
if (!m_members)
|
||||
{
|
||||
map<string, shared_ptr<Type const>> members;
|
||||
for (ASTPointer<EnumDeclaration> const& enumValue: m_enum.getMembers())
|
||||
members.insert(make_pair(enumValue->getName(), make_shared<EnumType>(m_enum)));
|
||||
m_members.reset(new MemberList(members));
|
||||
}
|
||||
return *m_members;
|
||||
}
|
||||
|
||||
FunctionType::FunctionType(FunctionDefinition const& _function, bool _isInternal):
|
||||
m_location(_isInternal ? Location::Internal : Location::External),
|
||||
m_isConstant(_function.isDeclaredConst()),
|
||||
@ -957,6 +944,13 @@ MemberList const& TypeType::getMembers() const
|
||||
if (!f->isConstructor() && !f->getName().empty())
|
||||
members[f->getName()] = make_shared<FunctionType>(*f);
|
||||
}
|
||||
else if (m_actualType->getCategory() == Category::Enum)
|
||||
{
|
||||
EnumDefinition const& enumDef = dynamic_cast<EnumType const&>(*m_actualType).getEnumDefinition();
|
||||
for (ASTPointer<EnumDeclaration> const& enumValue: enumDef.getMembers())
|
||||
members.insert(make_pair(enumValue->getName(), make_shared<EnumType>(enumDef)));
|
||||
m_members.reset(new MemberList(members));
|
||||
}
|
||||
m_members.reset(new MemberList(members));
|
||||
}
|
||||
return *m_members;
|
||||
|
3
Types.h
3
Types.h
@ -379,8 +379,9 @@ public:
|
||||
virtual bool operator==(Type const& _other) const override;
|
||||
virtual unsigned getSizeOnStack() const override { return 1; /*@todo*/ }
|
||||
virtual std::string toString() const override;
|
||||
virtual bool isValueType() const override { return true; }
|
||||
|
||||
virtual MemberList const& getMembers() const override;
|
||||
EnumDefinition const& getEnumDefinition() const { return m_enum; }
|
||||
|
||||
private:
|
||||
EnumDefinition const& m_enum;
|
||||
|
Loading…
Reference in New Issue
Block a user