mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Use selfbalance for `address(this).balance`.
This commit is contained in:
@@ -1229,6 +1229,28 @@ bool ExpressionCompiler::visit(MemberAccess const& _memberAccess)
|
||||
utils().leftShiftNumberOnStack(224);
|
||||
return false;
|
||||
}
|
||||
// Another special case for `address(this).balance`. Post-Istanbul, we can use the selfbalance
|
||||
// opcode.
|
||||
if (
|
||||
m_context.evmVersion().hasSelfBalance() &&
|
||||
member == "balance" &&
|
||||
_memberAccess.expression().annotation().type->category() == Type::Category::Address
|
||||
)
|
||||
if (FunctionCall const* funCall = dynamic_cast<FunctionCall const*>(&_memberAccess.expression()))
|
||||
if (auto const* addr = dynamic_cast<ElementaryTypeNameExpression const*>(&funCall->expression()))
|
||||
if (
|
||||
addr->typeName().token() == Token::Address &&
|
||||
funCall->arguments().size() == 1
|
||||
)
|
||||
if (auto arg = dynamic_cast<Identifier const*>( funCall->arguments().front().get()))
|
||||
if (
|
||||
arg->name() == "this" &&
|
||||
dynamic_cast<MagicVariableDeclaration const*>(arg->annotation().referencedDeclaration)
|
||||
)
|
||||
{
|
||||
m_context << Instruction::SELFBALANCE;
|
||||
return false;
|
||||
}
|
||||
|
||||
_memberAccess.expression().accept(*this);
|
||||
switch (_memberAccess.expression().annotation().type->category())
|
||||
|
||||
Reference in New Issue
Block a user