diff options
author | chriseth <c@ethdev.com> | 2015-12-21 22:37:24 +0800 |
---|---|---|
committer | chriseth <c@ethdev.com> | 2015-12-21 22:37:24 +0800 |
commit | 6f78998aaf0bafe9fc68ffa4d0d37f2364d6f81e (patch) | |
tree | 9cf3862fe47d52a542e3fb79f33612a7f6c7f18e /libsolidity | |
parent | 6c6295b74e6e93d838672e70109880e27bb5f614 (diff) | |
parent | 54e3637d234653e0f0e282220e3a628766a86adb (diff) | |
download | dexon-solidity-6f78998aaf0bafe9fc68ffa4d0d37f2364d6f81e.tar dexon-solidity-6f78998aaf0bafe9fc68ffa4d0d37f2364d6f81e.tar.gz dexon-solidity-6f78998aaf0bafe9fc68ffa4d0d37f2364d6f81e.tar.bz2 dexon-solidity-6f78998aaf0bafe9fc68ffa4d0d37f2364d6f81e.tar.lz dexon-solidity-6f78998aaf0bafe9fc68ffa4d0d37f2364d6f81e.tar.xz dexon-solidity-6f78998aaf0bafe9fc68ffa4d0d37f2364d6f81e.tar.zst dexon-solidity-6f78998aaf0bafe9fc68ffa4d0d37f2364d6f81e.zip |
Merge pull request #309 from chriseth/fix_cross_contract_enum_access
Add structs and enums to contract types.
Diffstat (limited to 'libsolidity')
-rw-r--r-- | libsolidity/ast/Types.cpp | 27 | ||||
-rw-r--r-- | libsolidity/codegen/ExpressionCompiler.cpp | 16 |
2 files changed, 29 insertions, 14 deletions
diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp index 49347022..b8c004e2 100644 --- a/libsolidity/ast/Types.cpp +++ b/libsolidity/ast/Types.cpp @@ -1042,12 +1042,14 @@ MemberList::MemberMap ContractType::nativeMembers(ContractDefinition const*) con } } else + { for (auto const& it: m_contract.interfaceFunctions()) members.push_back(MemberList::Member( it.second->declaration().name(), it.second->asMemberFunction(m_contract.isLibrary()), &it.second->declaration() )); + } return members; } @@ -1858,6 +1860,12 @@ MemberList::MemberMap TypeType::nativeMembers(ContractDefinition const* _current if (m_actualType->category() == Category::Contract) { ContractDefinition const& contract = dynamic_cast<ContractType const&>(*m_actualType).contractDefinition(); + bool isBase = false; + if (_currentScope != nullptr) + { + auto const& currentBases = _currentScope->annotation().linearizedBaseContracts; + isBase = (find(currentBases.begin(), currentBases.end(), &contract) != currentBases.end()); + } if (contract.isLibrary()) for (auto const& it: contract.interfaceFunctions()) members.push_back(MemberList::Member( @@ -1865,14 +1873,19 @@ MemberList::MemberMap TypeType::nativeMembers(ContractDefinition const* _current it.second->asMemberFunction(true), // use callcode &it.second->declaration() )); - else if (_currentScope != nullptr) + if (isBase) { - auto const& currentBases = _currentScope->annotation().linearizedBaseContracts; - if (find(currentBases.begin(), currentBases.end(), &contract) != currentBases.end()) - // We are accessing the type of a base contract, so add all public and protected - // members. Note that this does not add inherited functions on purpose. - for (Declaration const* decl: contract.inheritableMembers()) - members.push_back(MemberList::Member(decl->name(), decl->type(), decl)); + // We are accessing the type of a base contract, so add all public and protected + // members. Note that this does not add inherited functions on purpose. + for (Declaration const* decl: contract.inheritableMembers()) + members.push_back(MemberList::Member(decl->name(), decl->type(), decl)); + } + else + { + for (auto const& stru: contract.definedStructs()) + members.push_back(MemberList::Member(stru->name(), stru->type(), stru)); + for (auto const& enu: contract.definedEnums()) + members.push_back(MemberList::Member(enu->name(), enu->type(), enu)); } } else if (m_actualType->category() == Category::Enum) diff --git a/libsolidity/codegen/ExpressionCompiler.cpp b/libsolidity/codegen/ExpressionCompiler.cpp index dcdab2a7..2fd0b2c4 100644 --- a/libsolidity/codegen/ExpressionCompiler.cpp +++ b/libsolidity/codegen/ExpressionCompiler.cpp @@ -913,14 +913,16 @@ void ExpressionCompiler::endVisit(MemberAccess const& _memberAccess) if (dynamic_cast<ContractType const*>(type.actualType().get())) { - auto const& funType = dynamic_cast<FunctionType const&>(*_memberAccess.annotation().type); - if (funType.location() != FunctionType::Location::Internal) - m_context << funType.externalIdentifier(); - else + if (auto funType = dynamic_cast<FunctionType const*>(_memberAccess.annotation().type.get())) { - auto const* function = dynamic_cast<FunctionDefinition const*>(_memberAccess.annotation().referencedDeclaration); - solAssert(!!function, "Function not found in member access"); - m_context << m_context.functionEntryLabel(*function).pushTag(); + if (funType->location() != FunctionType::Location::Internal) + m_context << funType->externalIdentifier(); + else + { + auto const* function = dynamic_cast<FunctionDefinition const*>(_memberAccess.annotation().referencedDeclaration); + solAssert(!!function, "Function not found in member access"); + m_context << m_context.functionEntryLabel(*function).pushTag(); + } } } else if (auto enumType = dynamic_cast<EnumType const*>(type.actualType().get())) |