Coding style fix

This commit is contained in:
mingchuan 2019-06-03 18:01:11 +08:00
parent cfbbb194d1
commit 492f945973
No known key found for this signature in database
GPG Key ID: 607CD25FA2D03651
4 changed files with 35 additions and 24 deletions

View File

@ -414,7 +414,8 @@ string ABIFunctions::abiEncodingFunctionCalldataArrayWithoutCleanup(
fromArrayType.isByteArray() || fromArrayType.isByteArray() ||
*fromArrayType.baseType() == *TypeProvider::uint256() || *fromArrayType.baseType() == *TypeProvider::uint256() ||
*fromArrayType.baseType() == FixedBytesType(32), *fromArrayType.baseType() == FixedBytesType(32),
""); ""
);
solAssert(fromArrayType.calldataStride() == toArrayType.memoryStride(), ""); solAssert(fromArrayType.calldataStride() == toArrayType.memoryStride(), "");
solAssert( solAssert(

View File

@ -1055,28 +1055,27 @@ void ArrayUtils::accessIndex(ArrayType const& _arrayType, bool _doBoundsCheck, b
switch (location) switch (location)
{ {
case DataLocation::Memory: case DataLocation::Memory:
// stack: <base_ref> <index>
if (!_arrayType.isByteArray())
m_context << u256(_arrayType.memoryHeadSize()) << Instruction::MUL;
if (_arrayType.isDynamicallySized())
m_context << u256(32) << Instruction::ADD;
if (_keepReference)
m_context << Instruction::DUP2;
m_context << Instruction::ADD;
break;
case DataLocation::CallData: case DataLocation::CallData:
if (!_arrayType.isByteArray()) if (!_arrayType.isByteArray())
{
if (location == DataLocation::CallData)
{ {
if (_arrayType.baseType()->isDynamicallyEncoded()) if (_arrayType.baseType()->isDynamicallyEncoded())
m_context << u256(0x20); m_context << u256(0x20);
else else
m_context << _arrayType.baseType()->calldataEncodedSize(); m_context << _arrayType.baseType()->calldataEncodedSize();
}
else
m_context << u256(_arrayType.memoryHeadSize());
m_context << Instruction::MUL; m_context << Instruction::MUL;
} }
// stack: <base_ref> <index * size> // stack: <base_ref> <index * size>
if (location == DataLocation::Memory && _arrayType.isDynamicallySized())
m_context << u256(32) << Instruction::ADD;
if (_keepReference) if (_keepReference)
m_context << Instruction::DUP2; m_context << Instruction::DUP2;
m_context << Instruction::ADD; m_context << Instruction::ADD;
break; break;
case DataLocation::Storage: case DataLocation::Storage:

View File

@ -816,7 +816,12 @@ void CompilerUtils::convertType(
} }
else else
{ {
solAssert(targetTypeCategory == Type::Category::Integer || targetTypeCategory == Type::Category::Contract || targetTypeCategory == Type::Category::Address, ""); solAssert(
targetTypeCategory == Type::Category::Integer ||
targetTypeCategory == Type::Category::Contract ||
targetTypeCategory == Type::Category::Address,
""
);
IntegerType addressType(160); IntegerType addressType(160);
IntegerType const& targetType = targetTypeCategory == Type::Category::Integer IntegerType const& targetType = targetTypeCategory == Type::Category::Integer
? dynamic_cast<IntegerType const&>(_targetType) : addressType; ? dynamic_cast<IntegerType const&>(_targetType) : addressType;
@ -923,7 +928,6 @@ void CompilerUtils::convertType(
// stack: <mem start> <source ref> (variably sized) <length> <mem data pos> // stack: <mem start> <source ref> (variably sized) <length> <mem data pos>
if (targetType.baseType()->isValueType()) if (targetType.baseType()->isValueType())
{ {
solAssert(typeOnStack.baseType()->isValueType(), "");
copyToStackTop(2 + stackSize, stackSize); copyToStackTop(2 + stackSize, stackSize);
ArrayUtils(m_context).copyArrayToMemory(typeOnStack); ArrayUtils(m_context).copyArrayToMemory(typeOnStack);
} }
@ -960,7 +964,8 @@ void CompilerUtils::convertType(
targetType.isByteArray() && targetType.isByteArray() &&
typeOnStack.isByteArray() && typeOnStack.isByteArray() &&
typeOnStack.location() == DataLocation::CallData, typeOnStack.location() == DataLocation::CallData,
"Invalid conversion to calldata type."); "Invalid conversion to calldata type."
);
break; break;
} }
break; break;

View File

@ -54,7 +54,13 @@ class StackHeightChecker
public: public:
explicit StackHeightChecker(CompilerContext const& _context): explicit StackHeightChecker(CompilerContext const& _context):
m_context(_context), stackHeight(m_context.stackHeight()) {} m_context(_context), stackHeight(m_context.stackHeight()) {}
void check() { solAssert(m_context.stackHeight() == stackHeight, std::string("I sense a disturbance in the stack: ") + to_string(m_context.stackHeight()) + " vs " + to_string(stackHeight)); } void check()
{
solAssert(
m_context.stackHeight() == stackHeight,
std::string("I sense a disturbance in the stack: ") + to_string(m_context.stackHeight()) + " vs " + to_string(stackHeight)
);
}
private: private:
CompilerContext const& m_context; CompilerContext const& m_context;
unsigned stackHeight; unsigned stackHeight;
@ -893,9 +899,9 @@ bool ContractCompiler::visit(VariableDeclarationStatement const& _variableDeclar
// Local variable slots are reserved when their declaration is visited, // Local variable slots are reserved when their declaration is visited,
// and freed in the end of their scope. // and freed in the end of their scope.
for (auto _decl: _variableDeclarationStatement.declarations()) for (auto decl: _variableDeclarationStatement.declarations())
if (_decl) if (decl)
appendStackVariableInitialisation(*_decl); appendStackVariableInitialisation(*decl);
StackHeightChecker checker(m_context); StackHeightChecker checker(m_context);
if (Expression const* expression = _variableDeclarationStatement.initialValue()) if (Expression const* expression = _variableDeclarationStatement.initialValue())