diff options
author | chriseth <chris@ethereum.org> | 2017-09-26 17:38:22 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-26 17:38:22 +0800 |
commit | af4d8779bb84e52607410bc512307a408d7f21a1 (patch) | |
tree | 3c330992c9aa4e591d439ae44b25bef7ed37b0fb | |
parent | a72237f2754258ca385eee88bddfa4de3fce8d8f (diff) | |
parent | cb6cdfe7801a3362a489d0fd39cc0ce5a7075fea (diff) | |
download | dexon-solidity-af4d8779bb84e52607410bc512307a408d7f21a1.tar dexon-solidity-af4d8779bb84e52607410bc512307a408d7f21a1.tar.gz dexon-solidity-af4d8779bb84e52607410bc512307a408d7f21a1.tar.bz2 dexon-solidity-af4d8779bb84e52607410bc512307a408d7f21a1.tar.lz dexon-solidity-af4d8779bb84e52607410bc512307a408d7f21a1.tar.xz dexon-solidity-af4d8779bb84e52607410bc512307a408d7f21a1.tar.zst dexon-solidity-af4d8779bb84e52607410bc512307a408d7f21a1.zip |
Merge pull request #2934 from ethereum/fallthrough
Remove last two instances of switch fall-through
-rw-r--r-- | libsolidity/codegen/CompilerUtils.cpp | 19 | ||||
-rw-r--r-- | libsolidity/codegen/ExpressionCompiler.cpp | 90 |
2 files changed, 56 insertions, 53 deletions
diff --git a/libsolidity/codegen/CompilerUtils.cpp b/libsolidity/codegen/CompilerUtils.cpp index 37aa1aea..c1171c1d 100644 --- a/libsolidity/codegen/CompilerUtils.cpp +++ b/libsolidity/codegen/CompilerUtils.cpp @@ -596,7 +596,6 @@ void CompilerUtils::convertType( storeInMemoryDynamic(IntegerType(256)); // stack: mempos datapos storeStringData(data); - break; } else solAssert( @@ -810,9 +809,8 @@ void CompilerUtils::convertType( if (_cleanupNeeded) m_context << Instruction::ISZERO << Instruction::ISZERO; break; - case Type::Category::Function: - { - if (targetTypeCategory == Type::Category::Integer) + default: + if (stackTypeCategory == Type::Category::Function && targetTypeCategory == Type::Category::Integer) { IntegerType const& targetType = dynamic_cast<IntegerType const&>(_targetType); solAssert(targetType.isAddress(), "Function type can only be converted to address."); @@ -821,17 +819,16 @@ void CompilerUtils::convertType( // stack: <address> <function_id> m_context << Instruction::POP; - break; } - } - // fall-through - default: - // All other types should not be convertible to non-equal types. - solAssert(_typeOnStack == _targetType, "Invalid type conversion requested."); - if (_cleanupNeeded && _targetType.canBeStored() && _targetType.storageBytes() < 32) + else + { + // All other types should not be convertible to non-equal types. + solAssert(_typeOnStack == _targetType, "Invalid type conversion requested."); + if (_cleanupNeeded && _targetType.canBeStored() && _targetType.storageBytes() < 32) m_context << ((u256(1) << (8 * _targetType.storageBytes())) - 1) << Instruction::AND; + } break; } diff --git a/libsolidity/codegen/ExpressionCompiler.cpp b/libsolidity/codegen/ExpressionCompiler.cpp index c94baa10..b286594a 100644 --- a/libsolidity/codegen/ExpressionCompiler.cpp +++ b/libsolidity/codegen/ExpressionCompiler.cpp @@ -1014,59 +1014,65 @@ bool ExpressionCompiler::visit(MemberAccess const& _memberAccess) switch (_memberAccess.expression().annotation().type->category()) { case Type::Category::Contract: + case Type::Category::Integer: { bool alsoSearchInteger = false; - ContractType const& type = dynamic_cast<ContractType const&>(*_memberAccess.expression().annotation().type); - if (type.isSuper()) + if (_memberAccess.expression().annotation().type->category() == Type::Category::Contract) { - solAssert(!!_memberAccess.annotation().referencedDeclaration, "Referenced declaration not resolved."); - utils().pushCombinedFunctionEntryLabel(m_context.superFunction( - dynamic_cast<FunctionDefinition const&>(*_memberAccess.annotation().referencedDeclaration), - type.contractDefinition() - )); + ContractType const& type = dynamic_cast<ContractType const&>(*_memberAccess.expression().annotation().type); + if (type.isSuper()) + { + solAssert(!!_memberAccess.annotation().referencedDeclaration, "Referenced declaration not resolved."); + utils().pushCombinedFunctionEntryLabel(m_context.superFunction( + dynamic_cast<FunctionDefinition const&>(*_memberAccess.annotation().referencedDeclaration), + type.contractDefinition() + )); + } + else + { + // ordinary contract type + if (Declaration const* declaration = _memberAccess.annotation().referencedDeclaration) + { + u256 identifier; + if (auto const* variable = dynamic_cast<VariableDeclaration const*>(declaration)) + identifier = FunctionType(*variable).externalIdentifier(); + else if (auto const* function = dynamic_cast<FunctionDefinition const*>(declaration)) + identifier = FunctionType(*function).externalIdentifier(); + else + solAssert(false, "Contract member is neither variable nor function."); + utils().convertType(type, IntegerType(0, IntegerType::Modifier::Address), true); + m_context << identifier; + } + else + // not found in contract, search in members inherited from address + alsoSearchInteger = true; + } } else + alsoSearchInteger = true; + + if (alsoSearchInteger) { - // ordinary contract type - if (Declaration const* declaration = _memberAccess.annotation().referencedDeclaration) + if (member == "balance") { - u256 identifier; - if (auto const* variable = dynamic_cast<VariableDeclaration const*>(declaration)) - identifier = FunctionType(*variable).externalIdentifier(); - else if (auto const* function = dynamic_cast<FunctionDefinition const*>(declaration)) - identifier = FunctionType(*function).externalIdentifier(); - else - solAssert(false, "Contract member is neither variable nor function."); - utils().convertType(type, IntegerType(0, IntegerType::Modifier::Address), true); - m_context << identifier; + utils().convertType( + *_memberAccess.expression().annotation().type, + IntegerType(0, IntegerType::Modifier::Address), + true + ); + m_context << Instruction::BALANCE; } + else if ((set<string>{"send", "transfer", "call", "callcode", "delegatecall"}).count(member)) + utils().convertType( + *_memberAccess.expression().annotation().type, + IntegerType(0, IntegerType::Modifier::Address), + true + ); else - // not found in contract, search in members inherited from address - alsoSearchInteger = true; + solAssert(false, "Invalid member access to integer"); } - if (!alsoSearchInteger) - break; - } - // fall-through - case Type::Category::Integer: - if (member == "balance") - { - utils().convertType( - *_memberAccess.expression().annotation().type, - IntegerType(0, IntegerType::Modifier::Address), - true - ); - m_context << Instruction::BALANCE; - } - else if ((set<string>{"send", "transfer", "call", "callcode", "delegatecall"}).count(member)) - utils().convertType( - *_memberAccess.expression().annotation().type, - IntegerType(0, IntegerType::Modifier::Address), - true - ); - else - solAssert(false, "Invalid member access to integer"); break; + } case Type::Category::Function: if (member == "selector") { |