Skip to content

Commit

Permalink
Pull out helper to apply address member to contract members
Browse files Browse the repository at this point in the history
  • Loading branch information
axic committed Sep 28, 2017
1 parent aa6de49 commit d5d1a08
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
12 changes: 8 additions & 4 deletions libsolidity/ast/Types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1660,12 +1660,17 @@ MemberList::MemberMap ContractType::nativeMembers(ContractDefinition const*) con
&it.second->declaration()
));
}
// Add overloads from address only if there is no conflict
addNonConflictingAddressMembers(members);
return members;
}

void ContractType::addNonConflictingAddressMembers(MemberList::MemberMap& _members)
{
MemberList::MemberMap addressMembers = IntegerType(160, IntegerType::Modifier::Address).nativeMembers(nullptr);
for (auto const& addressMember: addressMembers)
{
bool clash = false;
for (auto const& member: members)
for (auto const& member: _members)
{
if (
member.name == addressMember.name &&
Expand All @@ -1686,13 +1691,12 @@ MemberList::MemberMap ContractType::nativeMembers(ContractDefinition const*) con
}

if (!clash)
members.push_back(MemberList::Member(
_members.push_back(MemberList::Member(
addressMember.name,
addressMember.type,
addressMember.declaration
));
}
return members;
}

shared_ptr<FunctionType const> const& ContractType::newExpressionType() const
Expand Down
2 changes: 2 additions & 0 deletions libsolidity/ast/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,8 @@ class ContractType: public Type
std::vector<std::tuple<VariableDeclaration const*, u256, unsigned>> stateVariables() const;

private:
static void addNonConflictingAddressMembers(MemberList::MemberMap& _members);

ContractDefinition const& m_contract;
/// If true, it is the "super" type of the current contract, i.e. it contains only inherited
/// members.
Expand Down

0 comments on commit d5d1a08

Please sign in to comment.