aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity
diff options
context:
space:
mode:
authorAlex Beregszaszi <alex@rtfs.hu>2016-12-01 20:12:10 +0800
committerAlex Beregszaszi <alex@rtfs.hu>2017-02-01 20:23:47 +0800
commit767ec1d670808cd479ac74780bff51a1f1900f04 (patch)
treecd4ff439885a636907be37d63ce0fb5bacae8913 /libsolidity
parentc1a675da4f01728784c9b7e1d82665bb8dfbcc99 (diff)
downloaddexon-solidity-767ec1d670808cd479ac74780bff51a1f1900f04.tar.gz
dexon-solidity-767ec1d670808cd479ac74780bff51a1f1900f04.tar.zst
dexon-solidity-767ec1d670808cd479ac74780bff51a1f1900f04.zip
Support explicit conversion of external function type to address
Diffstat (limited to 'libsolidity')
-rw-r--r--libsolidity/ast/Types.cpp11
-rw-r--r--libsolidity/ast/Types.h1
-rw-r--r--libsolidity/codegen/CompilerUtils.cpp12
-rw-r--r--libsolidity/codegen/ContractCompiler.cpp2
4 files changed, 25 insertions, 1 deletions
diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp
index dbabc8db..4a64b4c8 100644
--- a/libsolidity/ast/Types.cpp
+++ b/libsolidity/ast/Types.cpp
@@ -2158,6 +2158,17 @@ bool FunctionType::operator==(Type const& _other) const
return true;
}
+bool FunctionType::isExplicitlyConvertibleTo(Type const& _convertTo) const
+{
+ if (m_location == Location::External && _convertTo.category() == Category::Integer)
+ {
+ IntegerType const& convertTo = dynamic_cast<IntegerType const&>(_convertTo);
+ if (convertTo.isAddress())
+ return true;
+ }
+ return _convertTo.category() == category();
+}
+
TypePointer FunctionType::unaryOperatorResult(Token::Value _operator) const
{
if (_operator == Token::Value::Delete)
diff --git a/libsolidity/ast/Types.h b/libsolidity/ast/Types.h
index a5147f17..3917dca2 100644
--- a/libsolidity/ast/Types.h
+++ b/libsolidity/ast/Types.h
@@ -922,6 +922,7 @@ public:
virtual std::string identifier() const override;
virtual bool operator==(Type const& _other) const override;
+ virtual bool isExplicitlyConvertibleTo(Type const& _convertTo) const override;
virtual TypePointer unaryOperatorResult(Token::Value _operator) const override;
virtual std::string canonicalName(bool /*_addDataLocation*/) const override;
virtual std::string toString(bool _short) const override;
diff --git a/libsolidity/codegen/CompilerUtils.cpp b/libsolidity/codegen/CompilerUtils.cpp
index 477f021a..469bd0ed 100644
--- a/libsolidity/codegen/CompilerUtils.cpp
+++ b/libsolidity/codegen/CompilerUtils.cpp
@@ -787,6 +787,18 @@ void CompilerUtils::convertType(Type const& _typeOnStack, Type const& _targetTyp
if (_cleanupNeeded)
m_context << Instruction::ISZERO << Instruction::ISZERO;
break;
+ case Type::Category::Function:
+ {
+ solAssert(targetTypeCategory == Type::Category::Integer, "Invalid conversion for function type.");
+ IntegerType const& targetType = dynamic_cast<IntegerType const&>(_targetType);
+ solAssert(targetType.isAddress(), "Function type can only be converted to address.");
+ FunctionType const& typeOnStack = dynamic_cast<FunctionType const&>(_typeOnStack);
+ solAssert(typeOnStack.location() == FunctionType::Location::External, "Only external function type can be converted.");
+
+ // stack: <address> <function_id>
+ m_context << Instruction::POP;
+ break;
+ }
default:
// All other types should not be convertible to non-equal types.
solAssert(_typeOnStack == _targetType, "Invalid type conversion requested.");
diff --git a/libsolidity/codegen/ContractCompiler.cpp b/libsolidity/codegen/ContractCompiler.cpp
index 4d33927d..f4279906 100644
--- a/libsolidity/codegen/ContractCompiler.cpp
+++ b/libsolidity/codegen/ContractCompiler.cpp
@@ -42,7 +42,7 @@ class StackHeightChecker
public:
StackHeightChecker(CompilerContext const& _context):
m_context(_context), stackHeight(m_context.stackHeight()) {}
- void check() { solAssert(m_context.stackHeight() == stackHeight, "I sense a disturbance in the stack."); }
+ void check() { solAssert(m_context.stackHeight() == stackHeight, "I sense a disturbance in the stack. "); }
private:
CompilerContext const& m_context;
unsigned stackHeight;