diff options
author | liana <liana@ethdev.com> | 2015-01-27 20:21:20 +0800 |
---|---|---|
committer | liana <liana@ethdev.com> | 2015-01-27 20:21:20 +0800 |
commit | cad3d87482464017870080c54e3392bc5503ab20 (patch) | |
tree | 6536708d412afea48e11ca70a68231eb8bffe5e5 /ExpressionCompiler.cpp | |
parent | 6ba82b14273d033571b4ea96a49603f2e1304ff0 (diff) | |
download | dexon-solidity-cad3d87482464017870080c54e3392bc5503ab20.tar.gz dexon-solidity-cad3d87482464017870080c54e3392bc5503ab20.tar.zst dexon-solidity-cad3d87482464017870080c54e3392bc5503ab20.zip |
- cosmetic changes
Diffstat (limited to 'ExpressionCompiler.cpp')
-rw-r--r-- | ExpressionCompiler.cpp | 27 |
1 files changed, 12 insertions, 15 deletions
diff --git a/ExpressionCompiler.cpp b/ExpressionCompiler.cpp index 630a5e91..bd8c8653 100644 --- a/ExpressionCompiler.cpp +++ b/ExpressionCompiler.cpp @@ -637,14 +637,12 @@ void ExpressionCompiler::appendTypeConversion(Type const& _typeOnStack, Type con // only to shift right because of opposite alignment IntegerType const& targetIntegerType = dynamic_cast<IntegerType const&>(_targetType); StaticStringType const& typeOnStack = dynamic_cast<StaticStringType const&>(_typeOnStack); - if (targetIntegerType.isHash()) - { - solAssert(targetIntegerType.getNumBits() == typeOnStack.getNumBytes() * 8, "The size should be the same."); - m_context << (u256(1) << 256 - typeOnStack.getNumBytes() * 8) << - eth::Instruction::SWAP1 << eth::Instruction::DIV; - } + solAssert(targetIntegerType.isHash(), "Only conversion between String and Hash is allowed."); + solAssert(targetIntegerType.getNumBits() == typeOnStack.getNumBytes() * 8, "The size should be the same."); + m_context << (u256(1) << (256 - typeOnStack.getNumBytes() * 8)) << eth::Instruction::SWAP1 << eth::Instruction::DIV; } - else { + else + { solAssert(targetTypeCategory == Type::Category::STRING, "Invalid type conversion requested."); // nothing to do, strings are high-order-bit-aligned //@todo clear lower-order bytes if we allow explicit conversion to shorter strings @@ -659,17 +657,16 @@ void ExpressionCompiler::appendTypeConversion(Type const& _typeOnStack, Type con // only to shift left because of opposite alignment StaticStringType const& targetStringType = dynamic_cast<StaticStringType const&>(_targetType); IntegerType const& typeOnStack = dynamic_cast<IntegerType const&>(_typeOnStack); - if (typeOnStack.isHash()) - { - solAssert(typeOnStack.getNumBits() == targetStringType.getNumBytes() * 8, "The size should be the same."); - m_context << (u256(1) << 256 - typeOnStack.getNumBits()) << eth::Instruction::MUL; - } - } else + solAssert(typeOnStack.isHash(), "Only conversion between String and Hash is allowed."); + solAssert(typeOnStack.getNumBits() == targetStringType.getNumBytes() * 8, "The size should be the same."); + m_context << (u256(1) << (256 - typeOnStack.getNumBits())) << eth::Instruction::MUL; + } + else { solAssert(targetTypeCategory == Type::Category::INTEGER || targetTypeCategory == Type::Category::CONTRACT, ""); IntegerType addressType(0, IntegerType::Modifier::ADDRESS); IntegerType const& targetType = targetTypeCategory == Type::Category::INTEGER - ? dynamic_cast<IntegerType const&>(_targetType) : addressType; + ? dynamic_cast<IntegerType const&>(_targetType) : addressType; if (stackTypeCategory == Type::Category::INTEGER_CONSTANT) { IntegerConstantType const& constType = dynamic_cast<IntegerConstantType const&>(_typeOnStack); @@ -681,7 +678,7 @@ void ExpressionCompiler::appendTypeConversion(Type const& _typeOnStack, Type con else { IntegerType const& typeOnStack = stackTypeCategory == Type::Category::INTEGER - ? dynamic_cast<IntegerType const&>(_typeOnStack) : addressType; + ? dynamic_cast<IntegerType const&>(_typeOnStack) : addressType; // Widening: clean up according to source type width // Non-widening and force: clean up according to target type bits if (targetType.getNumBits() > typeOnStack.getNumBits()) |