aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity/codegen
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2018-02-14 00:08:35 +0800
committerGitHub <noreply@github.com>2018-02-14 00:08:35 +0800
commit23484ba6a4ab17df58dfa1d27b486c10265ce4ae (patch)
tree64944b4cc71593944dc461b288cf25dfdf68cb9e /libsolidity/codegen
parentf84b2c451425a5913ef3decc18cf56ef95988d83 (diff)
parentaea9e7fe549d93436a1eb355258ea1b11b5dfb22 (diff)
downloaddexon-solidity-23484ba6a4ab17df58dfa1d27b486c10265ce4ae.tar.gz
dexon-solidity-23484ba6a4ab17df58dfa1d27b486c10265ce4ae.tar.zst
dexon-solidity-23484ba6a4ab17df58dfa1d27b486c10265ce4ae.zip
Merge pull request #3498 from ethereum/allowthisfselector
Allow `this.f.selector` to be pure.
Diffstat (limited to 'libsolidity/codegen')
-rw-r--r--libsolidity/codegen/ExpressionCompiler.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/libsolidity/codegen/ExpressionCompiler.cpp b/libsolidity/codegen/ExpressionCompiler.cpp
index bb8c4a94..8e1cf019 100644
--- a/libsolidity/codegen/ExpressionCompiler.cpp
+++ b/libsolidity/codegen/ExpressionCompiler.cpp
@@ -1014,6 +1014,30 @@ bool ExpressionCompiler::visit(MemberAccess const& _memberAccess)
_memberAccess.expression().accept(*this);
return false;
}
+ // Another special case for `this.f.selector` which does not need the address.
+ // There are other uses of `.selector` which do need the address, but we want this
+ // specific use to be a pure expression.
+ if (
+ _memberAccess.expression().annotation().type->category() == Type::Category::Function &&
+ member == "selector"
+ )
+ if (auto const* expr = dynamic_cast<MemberAccess const*>(&_memberAccess.expression()))
+ if (auto const* exprInt = dynamic_cast<Identifier const*>(&expr->expression()))
+ if (exprInt->name() == "this")
+ if (Declaration const* declaration = expr->annotation().referencedDeclaration)
+ {
+ u256 identifier;
+ if (auto const* variable = dynamic_cast<VariableDeclaration const*>(declaration))
+ identifier = FunctionType(*variable).externalIdentifier();
+ else if (auto const* function = dynamic_cast<FunctionDefinition const*>(declaration))
+ identifier = FunctionType(*function).externalIdentifier();
+ else
+ solAssert(false, "Contract member is neither variable nor function.");
+ m_context << identifier;
+ /// need to store store it as bytes4
+ utils().leftShiftNumberOnStack(224);
+ return false;
+ }
_memberAccess.expression().accept(*this);
switch (_memberAccess.expression().annotation().type->category())