aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity
diff options
context:
space:
mode:
authorAlex Beregszaszi <alex@rtfs.hu>2017-02-09 09:37:53 +0800
committerAlex Beregszaszi <alex@rtfs.hu>2017-02-10 21:29:17 +0800
commitf8461e9e31b96e6656b8dcabd73de2e5176e6fe3 (patch)
tree585f8d6d45b6085c807d69d55a09746898f4b5de /libsolidity
parentaf8e31b023723bfc6baa224931ef6570cd8d9a32 (diff)
downloaddexon-solidity-f8461e9e31b96e6656b8dcabd73de2e5176e6fe3.tar.gz
dexon-solidity-f8461e9e31b96e6656b8dcabd73de2e5176e6fe3.tar.zst
dexon-solidity-f8461e9e31b96e6656b8dcabd73de2e5176e6fe3.zip
Implement assert as a global function
Diffstat (limited to 'libsolidity')
-rw-r--r--libsolidity/analysis/GlobalContext.cpp4
-rw-r--r--libsolidity/ast/Types.h7
-rw-r--r--libsolidity/codegen/ExpressionCompiler.cpp8
3 files changed, 15 insertions, 4 deletions
diff --git a/libsolidity/analysis/GlobalContext.cpp b/libsolidity/analysis/GlobalContext.cpp
index e46868be..cc418c5e 100644
--- a/libsolidity/analysis/GlobalContext.cpp
+++ b/libsolidity/analysis/GlobalContext.cpp
@@ -65,7 +65,9 @@ m_magicVariables(vector<shared_ptr<MagicVariableDeclaration const>>{make_shared<
make_shared<MagicVariableDeclaration>("ecrecover",
make_shared<FunctionType>(strings{"bytes32", "uint8", "bytes32", "bytes32"}, strings{"address"}, FunctionType::Location::ECRecover)),
make_shared<MagicVariableDeclaration>("ripemd160",
- make_shared<FunctionType>(strings(), strings{"bytes20"}, FunctionType::Location::RIPEMD160, true))})
+ make_shared<FunctionType>(strings(), strings{"bytes20"}, FunctionType::Location::RIPEMD160, true)),
+ make_shared<MagicVariableDeclaration>("assert",
+ make_shared<FunctionType>(strings{"bool"}, strings{}, FunctionType::Location::Assert))})
{
}
diff --git a/libsolidity/ast/Types.h b/libsolidity/ast/Types.h
index e280b32c..83d840e0 100644
--- a/libsolidity/ast/Types.h
+++ b/libsolidity/ast/Types.h
@@ -819,8 +819,8 @@ public:
{
Internal, ///< stack-call using plain JUMP
External, ///< external call using CALL
- CallCode, ///< extercnal call using CALLCODE, i.e. not exchanging the storage
- DelegateCall, ///< extercnal call using DELEGATECALL, i.e. not exchanging the storage
+ CallCode, ///< external call using CALLCODE, i.e. not exchanging the storage
+ DelegateCall, ///< external call using DELEGATECALL, i.e. not exchanging the storage
Bare, ///< CALL without function hash
BareCallCode, ///< CALLCODE without function hash
BareDelegateCall, ///< DELEGATECALL without function hash
@@ -844,7 +844,8 @@ public:
MulMod, ///< MULMOD
ArrayPush, ///< .push() to a dynamically sized array in storage
ByteArrayPush, ///< .push() to a dynamically sized byte array in storage
- ObjectCreation ///< array creation using new
+ ObjectCreation, ///< array creation using new
+ Assert ///< assert()
};
virtual Category category() const override { return Category::Function; }
diff --git a/libsolidity/codegen/ExpressionCompiler.cpp b/libsolidity/codegen/ExpressionCompiler.cpp
index d74d9dd3..a99e3d40 100644
--- a/libsolidity/codegen/ExpressionCompiler.cpp
+++ b/libsolidity/codegen/ExpressionCompiler.cpp
@@ -863,6 +863,14 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
m_context << Instruction::POP;
break;
}
+ case Location::Assert:
+ {
+ arguments.front()->accept(*this);
+ utils().convertType(*arguments.front()->annotation().type, *function.parameterTypes().front(), true);
+ m_context << Instruction::ISZERO;
+ m_context.appendConditionalJumpTo(m_context.errorTag());
+ break;
+ }
default:
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Invalid function type."));
}