mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
appendArgumentsCopyToMemory() has more complicated logic now
- Plus other fixes.
This commit is contained in:
parent
337b952f53
commit
76c9f13626
8
AST.cpp
8
AST.cpp
@ -490,7 +490,7 @@ void FunctionCall::checkTypeRequirements()
|
|||||||
if (functionType->getLocation() != FunctionType::Location::SHA3 && parameterTypes.size() != m_arguments.size())
|
if (functionType->getLocation() != FunctionType::Location::SHA3 && parameterTypes.size() != m_arguments.size())
|
||||||
BOOST_THROW_EXCEPTION(createTypeError("Wrong argument count for function call."));
|
BOOST_THROW_EXCEPTION(createTypeError("Wrong argument count for function call."));
|
||||||
|
|
||||||
if (m_names.empty()) // LTODO: Totally ignoring sha3 case for named arguments for now just for the rebase to work
|
if (m_names.empty())
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < m_arguments.size(); ++i)
|
for (size_t i = 0; i < m_arguments.size(); ++i)
|
||||||
{
|
{
|
||||||
@ -501,14 +501,14 @@ void FunctionCall::checkTypeRequirements()
|
|||||||
BOOST_THROW_EXCEPTION(createTypeError("SHA3 called with argument that can't live outside storage"));
|
BOOST_THROW_EXCEPTION(createTypeError("SHA3 called with argument that can't live outside storage"));
|
||||||
#endif
|
#endif
|
||||||
if (!m_arguments[i]->getType()->isImplicitlyConvertibleTo(*parameterTypes[0]))
|
if (!m_arguments[i]->getType()->isImplicitlyConvertibleTo(*parameterTypes[0]))
|
||||||
BOOST_THROW_EXCEPTION(createTypeError(std::string("SHA3 argument ") +
|
BOOST_THROW_EXCEPTION(m_arguments[i]->createTypeError("SHA3 argument can't be converted to hash"));
|
||||||
boost::lexical_cast<std::string>(i + 1) +
|
|
||||||
std::string("can't be converted to hash")));
|
|
||||||
|
|
||||||
} else if (!m_arguments[i]->getType()->isImplicitlyConvertibleTo(*parameterTypes[i]))
|
} else if (!m_arguments[i]->getType()->isImplicitlyConvertibleTo(*parameterTypes[i]))
|
||||||
BOOST_THROW_EXCEPTION(createTypeError("Invalid type for argument in function call."));
|
BOOST_THROW_EXCEPTION(createTypeError("Invalid type for argument in function call."));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (functionType->getLocation() == FunctionType::Location::SHA3)
|
||||||
|
BOOST_THROW_EXCEPTION(createTypeError("Named arguments can't be used for SHA3."));
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
auto const& parameterNames = functionType->getParameterNames();
|
auto const& parameterNames = functionType->getParameterNames();
|
||||||
|
@ -275,7 +275,7 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
|
|||||||
m_context << u256(0) << eth::Instruction::CODECOPY;
|
m_context << u256(0) << eth::Instruction::CODECOPY;
|
||||||
|
|
||||||
unsigned length = bytecode.size();
|
unsigned length = bytecode.size();
|
||||||
length += appendArgumentsCopyToMemory(function.getParameterTypes(), arguments, length);
|
length += appendArgumentsCopyToMemory(arguments, function.getParameterTypes(), length);
|
||||||
// size, offset, endowment
|
// size, offset, endowment
|
||||||
m_context << u256(length) << u256(0);
|
m_context << u256(length) << u256(0);
|
||||||
if (function.valueSet())
|
if (function.valueSet())
|
||||||
@ -327,7 +327,7 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
|
|||||||
break;
|
break;
|
||||||
case Location::SHA3:
|
case Location::SHA3:
|
||||||
{
|
{
|
||||||
unsigned length = appendSameTypeArgumentsCopyToMemory(function.getParameterTypes().front(), arguments, 0);
|
unsigned length = appendArgumentsCopyToMemory(arguments);
|
||||||
m_context << u256(length) << u256(0) << eth::Instruction::SHA3;
|
m_context << u256(length) << u256(0) << eth::Instruction::SHA3;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -800,7 +800,7 @@ void ExpressionCompiler::appendExternalFunctionCall(FunctionType const& _functio
|
|||||||
|
|
||||||
// reserve space for the function identifier
|
// reserve space for the function identifier
|
||||||
unsigned dataOffset = bare ? 0 : CompilerUtils::dataStartOffset;
|
unsigned dataOffset = bare ? 0 : CompilerUtils::dataStartOffset;
|
||||||
dataOffset += appendArgumentsCopyToMemory(_functionType.getParameterTypes(), _arguments, dataOffset);
|
dataOffset += appendArgumentsCopyToMemory(_arguments, _functionType.getParameterTypes(), dataOffset);
|
||||||
|
|
||||||
//@todo only return the first return value for now
|
//@todo only return the first return value for now
|
||||||
Type const* firstType = _functionType.getReturnParameterTypes().empty() ? nullptr :
|
Type const* firstType = _functionType.getReturnParameterTypes().empty() ? nullptr :
|
||||||
@ -836,38 +836,44 @@ void ExpressionCompiler::appendExternalFunctionCall(FunctionType const& _functio
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned ExpressionCompiler::appendArgumentsCopyToMemory(TypePointers const& _types,
|
unsigned ExpressionCompiler::appendArgumentsCopyToMemory(vector<ASTPointer<Expression const>> const& _arguments,
|
||||||
vector<ASTPointer<Expression const>> const& _arguments,
|
TypePointers const& _types,
|
||||||
unsigned _memoryOffset)
|
unsigned _memoryOffset)
|
||||||
{
|
{
|
||||||
unsigned length = 0;
|
unsigned length = 0;
|
||||||
|
if (!_types.empty())
|
||||||
|
{
|
||||||
for (unsigned i = 0; i < _arguments.size(); ++i)
|
for (unsigned i = 0; i < _arguments.size(); ++i)
|
||||||
length += appendExpressionCopyToMemory(*_types[i], *_arguments[i], _memoryOffset + length);
|
length += appendExpressionCopyToMemory(*_types[i], *_arguments[i], _memoryOffset + length);
|
||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned ExpressionCompiler::appendSameTypeArgumentsCopyToMemory(TypePointer const& _type,
|
// without type conversion
|
||||||
vector<ASTPointer<Expression const>> const& _arguments,
|
|
||||||
unsigned _memoryOffset)
|
|
||||||
{
|
|
||||||
unsigned length = 0;
|
|
||||||
for (unsigned i = 0; i < _arguments.size(); ++i)
|
for (unsigned i = 0; i < _arguments.size(); ++i)
|
||||||
length += appendExpressionCopyToMemory(*_type, *_arguments[i], _memoryOffset + length);
|
{
|
||||||
|
_arguments[i]->accept(*this);
|
||||||
|
length += moveTypeToMemory(*_arguments[i]->getType(), _arguments[i]->getLocation(), _memoryOffset + length);
|
||||||
|
}
|
||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned ExpressionCompiler::moveTypeToMemory(Type const& _type, Location const& _location, unsigned _memoryOffset)
|
||||||
|
{
|
||||||
|
unsigned const c_numBytes = CompilerUtils::getPaddedSize(_type.getCalldataEncodedSize());
|
||||||
|
if (c_numBytes == 0 || c_numBytes > 32)
|
||||||
|
BOOST_THROW_EXCEPTION(CompilerError()
|
||||||
|
<< errinfo_sourceLocation(_location)
|
||||||
|
<< errinfo_comment("Type " + _type.toString() + " not yet supported."));
|
||||||
|
bool const c_leftAligned = _type.getCategory() == Type::Category::STRING;
|
||||||
|
bool const c_padToWords = true;
|
||||||
|
return CompilerUtils(m_context).storeInMemory(_memoryOffset, c_numBytes, c_leftAligned, c_padToWords);
|
||||||
|
}
|
||||||
|
|
||||||
unsigned ExpressionCompiler::appendTypeConversionAndMoveToMemory(Type const& _expectedType, Type const& _type,
|
unsigned ExpressionCompiler::appendTypeConversionAndMoveToMemory(Type const& _expectedType, Type const& _type,
|
||||||
Location const& _location, unsigned _memoryOffset)
|
Location const& _location, unsigned _memoryOffset)
|
||||||
{
|
{
|
||||||
appendTypeConversion(_type, _expectedType, true);
|
appendTypeConversion(_type, _expectedType, true);
|
||||||
unsigned const c_numBytes = CompilerUtils::getPaddedSize(_expectedType.getCalldataEncodedSize());
|
return moveTypeToMemory(_expectedType, _location, _memoryOffset);
|
||||||
if (c_numBytes == 0 || c_numBytes > 32)
|
|
||||||
BOOST_THROW_EXCEPTION(CompilerError()
|
|
||||||
<< errinfo_sourceLocation(_location)
|
|
||||||
<< errinfo_comment("Type " + _expectedType.toString() + " not yet supported."));
|
|
||||||
bool const c_leftAligned = _expectedType.getCategory() == Type::Category::STRING;
|
|
||||||
bool const c_padToWords = true;
|
|
||||||
return CompilerUtils(m_context).storeInMemory(_memoryOffset, c_numBytes, c_leftAligned, c_padToWords);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned ExpressionCompiler::appendExpressionCopyToMemory(Type const& _expectedType,
|
unsigned ExpressionCompiler::appendExpressionCopyToMemory(Type const& _expectedType,
|
||||||
|
@ -94,19 +94,16 @@ private:
|
|||||||
bool bare = false);
|
bool bare = false);
|
||||||
/// Appends code that copies the given arguments to memory (with optional offset).
|
/// Appends code that copies the given arguments to memory (with optional offset).
|
||||||
/// @returns the number of bytes copied to memory
|
/// @returns the number of bytes copied to memory
|
||||||
unsigned appendArgumentsCopyToMemory(TypePointers const& _types,
|
unsigned appendArgumentsCopyToMemory(std::vector<ASTPointer<Expression const>> const& _arguments,
|
||||||
std::vector<ASTPointer<Expression const>> const& _arguments,
|
TypePointers const& _types = {},
|
||||||
unsigned _memoryOffset = 0);
|
unsigned _memoryOffset = 0);
|
||||||
/// Appends code that copies a type to memory.
|
/// Appends code that copies a type to memory.
|
||||||
/// @returns the number of bytes copied to memory
|
/// @returns the number of bytes copied to memory
|
||||||
unsigned appendTypeConversionAndMoveToMemory(Type const& _expectedType, Type const& _type,
|
unsigned appendTypeConversionAndMoveToMemory(Type const& _expectedType, Type const& _type,
|
||||||
Location const& _location, unsigned _memoryOffset = 0);
|
Location const& _location, unsigned _memoryOffset = 0);
|
||||||
/// Appends code that copies the given arguments that should all have the
|
/// Appends code that moves a type to memory
|
||||||
/// same @a _type to memory (with optional offset).
|
|
||||||
/// @returns the number of bytes copied to memory
|
/// @returns the number of bytes copied to memory
|
||||||
unsigned appendSameTypeArgumentsCopyToMemory(TypePointer const& _type,
|
unsigned moveTypeToMemory(Type const& _type, Location const& _location, unsigned _memoryOffset);
|
||||||
std::vector<ASTPointer<Expression const>> const& _arguments,
|
|
||||||
unsigned _memoryOffset = 0);
|
|
||||||
/// Appends code that evaluates a single expression and copies it to memory (with optional offset).
|
/// Appends code that evaluates a single expression and copies it to memory (with optional offset).
|
||||||
/// @returns the number of bytes copied to memory
|
/// @returns the number of bytes copied to memory
|
||||||
unsigned appendExpressionCopyToMemory(Type const& _expectedType, Expression const& _expression,
|
unsigned appendExpressionCopyToMemory(Type const& _expectedType, Expression const& _expression,
|
||||||
|
Loading…
Reference in New Issue
Block a user