- modifications according to PR review

This commit is contained in:
liana 2015-01-26 13:24:16 +01:00
parent 3075fc598d
commit ef885d0212

View File

@ -629,7 +629,9 @@ void ExpressionCompiler::appendTypeConversion(Type const& _typeOnStack, Type con
Type::Category stackTypeCategory = _typeOnStack.getCategory(); Type::Category stackTypeCategory = _typeOnStack.getCategory();
Type::Category targetTypeCategory = _targetType.getCategory(); Type::Category targetTypeCategory = _targetType.getCategory();
if (stackTypeCategory == Type::Category::STRING && targetTypeCategory == Type::Category::INTEGER) if (stackTypeCategory == Type::Category::STRING)
{
if (targetTypeCategory == Type::Category::INTEGER)
{ {
// conversion from string to hash. no need to clean the high bit // conversion from string to hash. no need to clean the high bit
// only to shift right because of opposite alignment // only to shift right because of opposite alignment
@ -638,10 +640,16 @@ void ExpressionCompiler::appendTypeConversion(Type const& _typeOnStack, Type con
if (targetIntegerType.isHash()) if (targetIntegerType.isHash())
{ {
solAssert(targetIntegerType.getNumBits() == sourceStringType.getNumBytes() * 8, "The size should be the same."); solAssert(targetIntegerType.getNumBits() == sourceStringType.getNumBytes() * 8, "The size should be the same.");
m_context << u256(std::pow(2, 256 - sourceStringType.getNumBytes() * 8)) << m_context << (u256(1) << 256 - sourceStringType.getNumBytes() * 8) <<
eth::Instruction::SWAP1 << eth::Instruction::DIV; 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) else if (targetTypeCategory == Type::Category::STRING && stackTypeCategory == Type::Category::INTEGER)
{ {
// conversion from hash to string. no need to clean the high bit // conversion from hash to string. no need to clean the high bit
@ -651,7 +659,7 @@ void ExpressionCompiler::appendTypeConversion(Type const& _typeOnStack, Type con
if (sourceIntegerType.isHash()) if (sourceIntegerType.isHash())
{ {
solAssert(sourceIntegerType.getNumBits() == targetStringType.getNumBytes() * 8, "The size should be the same."); 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 || else if (stackTypeCategory == Type::Category::INTEGER || stackTypeCategory == Type::Category::CONTRACT ||
@ -681,12 +689,6 @@ void ExpressionCompiler::appendTypeConversion(Type const& _typeOnStack, Type con
appendHighBitsCleanup(targetType); 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) else if (_typeOnStack != _targetType)
// All other types should not be convertible to non-equal types. // All other types should not be convertible to non-equal types.
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Invalid type conversion requested.")); BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Invalid type conversion requested."));