mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
-redesigned appendTypeConversion function
This commit is contained in:
parent
ef885d0212
commit
6ba82b1427
@ -636,11 +636,11 @@ void ExpressionCompiler::appendTypeConversion(Type const& _typeOnStack, Type con
|
|||||||
// 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
|
||||||
IntegerType const& targetIntegerType = dynamic_cast<IntegerType const&>(_targetType);
|
IntegerType const& targetIntegerType = dynamic_cast<IntegerType const&>(_targetType);
|
||||||
StaticStringType const& sourceStringType = dynamic_cast<StaticStringType const&>(_typeOnStack);
|
StaticStringType const& typeOnStack = dynamic_cast<StaticStringType const&>(_typeOnStack);
|
||||||
if (targetIntegerType.isHash())
|
if (targetIntegerType.isHash())
|
||||||
{
|
{
|
||||||
solAssert(targetIntegerType.getNumBits() == sourceStringType.getNumBytes() * 8, "The size should be the same.");
|
solAssert(targetIntegerType.getNumBits() == typeOnStack.getNumBytes() * 8, "The size should be the same.");
|
||||||
m_context << (u256(1) << 256 - sourceStringType.getNumBytes() * 8) <<
|
m_context << (u256(1) << 256 - typeOnStack.getNumBytes() * 8) <<
|
||||||
eth::Instruction::SWAP1 << eth::Instruction::DIV;
|
eth::Instruction::SWAP1 << eth::Instruction::DIV;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -650,20 +650,21 @@ void ExpressionCompiler::appendTypeConversion(Type const& _typeOnStack, Type con
|
|||||||
//@todo clear lower-order bytes if we allow explicit conversion to shorter strings
|
//@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 (stackTypeCategory == Type::Category::INTEGER || stackTypeCategory == Type::Category::CONTRACT ||
|
||||||
|
stackTypeCategory == Type::Category::INTEGER_CONSTANT)
|
||||||
|
{
|
||||||
|
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
|
||||||
// only to shift left because of opposite alignment
|
// only to shift left because of opposite alignment
|
||||||
StaticStringType const& targetStringType = dynamic_cast<StaticStringType const&>(_targetType);
|
StaticStringType const& targetStringType = dynamic_cast<StaticStringType const&>(_targetType);
|
||||||
IntegerType const& sourceIntegerType = dynamic_cast<IntegerType const&>(_typeOnStack);
|
IntegerType const& typeOnStack = dynamic_cast<IntegerType const&>(_typeOnStack);
|
||||||
if (sourceIntegerType.isHash())
|
if (typeOnStack.isHash())
|
||||||
{
|
{
|
||||||
solAssert(sourceIntegerType.getNumBits() == targetStringType.getNumBytes() * 8, "The size should be the same.");
|
solAssert(typeOnStack.getNumBits() == targetStringType.getNumBytes() * 8, "The size should be the same.");
|
||||||
m_context << (u256(1) << 256 - sourceIntegerType.getNumBits()) << eth::Instruction::MUL;
|
m_context << (u256(1) << 256 - typeOnStack.getNumBits()) << eth::Instruction::MUL;
|
||||||
}
|
}
|
||||||
}
|
} else
|
||||||
else if (stackTypeCategory == Type::Category::INTEGER || stackTypeCategory == Type::Category::CONTRACT ||
|
|
||||||
stackTypeCategory == Type::Category::INTEGER_CONSTANT)
|
|
||||||
{
|
{
|
||||||
solAssert(targetTypeCategory == Type::Category::INTEGER || targetTypeCategory == Type::Category::CONTRACT, "");
|
solAssert(targetTypeCategory == Type::Category::INTEGER || targetTypeCategory == Type::Category::CONTRACT, "");
|
||||||
IntegerType addressType(0, IntegerType::Modifier::ADDRESS);
|
IntegerType addressType(0, IntegerType::Modifier::ADDRESS);
|
||||||
@ -689,6 +690,7 @@ void ExpressionCompiler::appendTypeConversion(Type const& _typeOnStack, Type con
|
|||||||
appendHighBitsCleanup(targetType);
|
appendHighBitsCleanup(targetType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
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."));
|
||||||
|
Loading…
Reference in New Issue
Block a user