aboutsummaryrefslogtreecommitdiffstats
path: root/ExpressionCompiler.cpp
diff options
context:
space:
mode:
authorliana <liana@ethdev.com>2015-01-26 20:24:16 +0800
committerliana <liana@ethdev.com>2015-01-26 20:24:16 +0800
commitef885d0212cecb14a76d28d57581a57bc286efbd (patch)
tree823a5616f45201df3f1df5ead30fe9200a71d362 /ExpressionCompiler.cpp
parent3075fc598deebb17010c30f1d75eb170edaf83cd (diff)
downloaddexon-solidity-ef885d0212cecb14a76d28d57581a57bc286efbd.tar.gz
dexon-solidity-ef885d0212cecb14a76d28d57581a57bc286efbd.tar.zst
dexon-solidity-ef885d0212cecb14a76d28d57581a57bc286efbd.zip
- modifications according to PR review
Diffstat (limited to 'ExpressionCompiler.cpp')
-rw-r--r--ExpressionCompiler.cpp34
1 files changed, 18 insertions, 16 deletions
diff --git a/ExpressionCompiler.cpp b/ExpressionCompiler.cpp
index 9d282c1c..2c3b4078 100644
--- a/ExpressionCompiler.cpp
+++ b/ExpressionCompiler.cpp
@@ -629,17 +629,25 @@ void ExpressionCompiler::appendTypeConversion(Type const& _typeOnStack, Type con
Type::Category stackTypeCategory = _typeOnStack.getCategory();
Type::Category targetTypeCategory = _targetType.getCategory();
- if (stackTypeCategory == Type::Category::STRING && targetTypeCategory == Type::Category::INTEGER)
+ if (stackTypeCategory == Type::Category::STRING)
{
- // conversion from string to hash. no need to clean the high bit
- // only to shift right because of opposite alignment
- IntegerType const& targetIntegerType = dynamic_cast<IntegerType const&>(_targetType);
- StaticStringType const& sourceStringType = dynamic_cast<StaticStringType const&>(_typeOnStack);
- if (targetIntegerType.isHash())
+ if (targetTypeCategory == Type::Category::INTEGER)
{
- solAssert(targetIntegerType.getNumBits() == sourceStringType.getNumBytes() * 8, "The size should be the same.");
- m_context << u256(std::pow(2, 256 - sourceStringType.getNumBytes() * 8)) <<
- eth::Instruction::SWAP1 << eth::Instruction::DIV;
+ // conversion from string to hash. no need to clean the high bit
+ // only to shift right because of opposite alignment
+ IntegerType const& targetIntegerType = dynamic_cast<IntegerType const&>(_targetType);
+ StaticStringType const& sourceStringType = dynamic_cast<StaticStringType const&>(_typeOnStack);
+ if (targetIntegerType.isHash())
+ {
+ solAssert(targetIntegerType.getNumBits() == sourceStringType.getNumBytes() * 8, "The size should be the same.");
+ m_context << (u256(1) << 256 - sourceStringType.getNumBytes() * 8) <<
+ eth::Instruction::SWAP1 << eth::Instruction::DIV;
+ }
+ }
+ 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
}
}
else if (targetTypeCategory == Type::Category::STRING && stackTypeCategory == Type::Category::INTEGER)
@@ -651,7 +659,7 @@ void ExpressionCompiler::appendTypeConversion(Type const& _typeOnStack, Type con
if (sourceIntegerType.isHash())
{
solAssert(sourceIntegerType.getNumBits() == targetStringType.getNumBytes() * 8, "The size should be the same.");
- m_context << u256(std::pow(2, 256 - sourceIntegerType.getNumBits())) << eth::Instruction::MUL;
+ m_context << (u256(1) << 256 - sourceIntegerType.getNumBits()) << eth::Instruction::MUL;
}
}
else if (stackTypeCategory == Type::Category::INTEGER || stackTypeCategory == Type::Category::CONTRACT ||
@@ -681,12 +689,6 @@ void ExpressionCompiler::appendTypeConversion(Type const& _typeOnStack, Type con
appendHighBitsCleanup(targetType);
}
}
- else if (stackTypeCategory == Type::Category::STRING)
- {
- 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
- }
else if (_typeOnStack != _targetType)
// All other types should not be convertible to non-equal types.
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Invalid type conversion requested."));