From 3e5d81578a10cfa1afc50c12074c67572499b4fb Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Tue, 19 Sep 2017 19:02:13 +0100 Subject: Avoid switch fallthrough in CompilerUtils --- libsolidity/codegen/CompilerUtils.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'libsolidity/codegen/CompilerUtils.cpp') diff --git a/libsolidity/codegen/CompilerUtils.cpp b/libsolidity/codegen/CompilerUtils.cpp index 37aa1aea..4d273b87 100644 --- a/libsolidity/codegen/CompilerUtils.cpp +++ b/libsolidity/codegen/CompilerUtils.cpp @@ -810,9 +810,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(_targetType); solAssert(targetType.isAddress(), "Function type can only be converted to address."); @@ -823,9 +822,7 @@ void CompilerUtils::convertType( 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) -- cgit v1.2.3 From cb6cdfe7801a3362a489d0fd39cc0ce5a7075fea Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Mon, 25 Sep 2017 09:41:04 +0100 Subject: Simplify switch statements by refactoring internal break statements --- libsolidity/codegen/CompilerUtils.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'libsolidity/codegen/CompilerUtils.cpp') diff --git a/libsolidity/codegen/CompilerUtils.cpp b/libsolidity/codegen/CompilerUtils.cpp index 4d273b87..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( @@ -820,15 +819,16 @@ void CompilerUtils::convertType( // stack:
m_context << Instruction::POP; - break; } - - // 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; } -- cgit v1.2.3 From ee65ecfb3b80d9c027bade21df883e897b1234c5 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Tue, 26 Sep 2017 22:46:33 +0100 Subject: Ensure that address types are always declared as 160bit --- libsolidity/codegen/CompilerUtils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libsolidity/codegen/CompilerUtils.cpp') diff --git a/libsolidity/codegen/CompilerUtils.cpp b/libsolidity/codegen/CompilerUtils.cpp index c1171c1d..ce97ed61 100644 --- a/libsolidity/codegen/CompilerUtils.cpp +++ b/libsolidity/codegen/CompilerUtils.cpp @@ -541,7 +541,7 @@ void CompilerUtils::convertType( else { solAssert(targetTypeCategory == Type::Category::Integer || targetTypeCategory == Type::Category::Contract, ""); - IntegerType addressType(0, IntegerType::Modifier::Address); + IntegerType addressType(160, IntegerType::Modifier::Address); IntegerType const& targetType = targetTypeCategory == Type::Category::Integer ? dynamic_cast(_targetType) : addressType; if (stackTypeCategory == Type::Category::RationalNumber) -- cgit v1.2.3 From 204214f0700179e3d8fa97c77d4f92acd349f015 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Tue, 26 Sep 2017 22:10:30 +0100 Subject: Split encodeToMemory to packedEncode and abiEncode --- libsolidity/codegen/CompilerUtils.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'libsolidity/codegen/CompilerUtils.cpp') diff --git a/libsolidity/codegen/CompilerUtils.cpp b/libsolidity/codegen/CompilerUtils.cpp index ce97ed61..f9b181ae 100644 --- a/libsolidity/codegen/CompilerUtils.cpp +++ b/libsolidity/codegen/CompilerUtils.cpp @@ -191,7 +191,7 @@ void CompilerUtils::encodeToMemory( { // Use the new JULIA-based encoding function auto stackHeightBefore = m_context.stackHeight(); - abiEncode(_givenTypes, targetTypes, _encodeAsLibraryTypes); + abiEncodeV2(_givenTypes, targetTypes, _encodeAsLibraryTypes); solAssert(stackHeightBefore - m_context.stackHeight() == sizeOnStack(_givenTypes), ""); return; } @@ -302,7 +302,7 @@ void CompilerUtils::encodeToMemory( popStackSlots(argSize + dynPointers + 1); } -void CompilerUtils::abiEncode( +void CompilerUtils::abiEncodeV2( TypePointers const& _givenTypes, TypePointers const& _targetTypes, bool _encodeAsLibraryTypes -- cgit v1.2.3