From d6d880dc53c8615589b3077ba5339376ade92089 Mon Sep 17 00:00:00 2001 From: hrkrshnn Date: Thu, 21 Jan 2021 20:28:06 +0100 Subject: [PATCH] Old codegen: implemented shortcut for
.code.length --- libsolidity/codegen/ExpressionCompiler.cpp | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/libsolidity/codegen/ExpressionCompiler.cpp b/libsolidity/codegen/ExpressionCompiler.cpp index 2abf03453..4a3b7c7b4 100644 --- a/libsolidity/codegen/ExpressionCompiler.cpp +++ b/libsolidity/codegen/ExpressionCompiler.cpp @@ -1473,6 +1473,29 @@ bool ExpressionCompiler::visit(MemberAccess const& _memberAccess) return false; } + // Another special case for `address.code.length`, which should simply call extcodesize + if ( + auto innerExpression = dynamic_cast(&_memberAccess.expression()); + member == "length" && + innerExpression && + innerExpression->memberName() == "code" && + innerExpression->expression().annotation().type->category() == Type::Category::Address + ) + { + solAssert(innerExpression->annotation().type->category() == Type::Category::Array, ""); + + innerExpression->expression().accept(*this); + + utils().convertType( + *innerExpression->expression().annotation().type, + *TypeProvider::address(), + true + ); + m_context << Instruction::EXTCODESIZE; + + return false; + } + _memberAccess.expression().accept(*this); switch (_memberAccess.expression().annotation().type->category()) {