aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity
diff options
context:
space:
mode:
authorchriseth <c@ethdev.com>2017-03-10 00:03:53 +0800
committerchriseth <c@ethdev.com>2017-03-14 21:21:33 +0800
commit47cd8964b8617e5c7e93232719224c8334a4c764 (patch)
treeea29137b7c499b0ddbef1e62bb8a4d401c694224 /libsolidity
parent9aab3b8639afa6e30e866e052a412b6f39c6ef6c (diff)
downloaddexon-solidity-47cd8964b8617e5c7e93232719224c8334a4c764.tar
dexon-solidity-47cd8964b8617e5c7e93232719224c8334a4c764.tar.gz
dexon-solidity-47cd8964b8617e5c7e93232719224c8334a4c764.tar.bz2
dexon-solidity-47cd8964b8617e5c7e93232719224c8334a4c764.tar.lz
dexon-solidity-47cd8964b8617e5c7e93232719224c8334a4c764.tar.xz
dexon-solidity-47cd8964b8617e5c7e93232719224c8334a4c764.tar.zst
dexon-solidity-47cd8964b8617e5c7e93232719224c8334a4c764.zip
Require and Assert.
Diffstat (limited to 'libsolidity')
-rw-r--r--libsolidity/analysis/GlobalContext.cpp7
-rw-r--r--libsolidity/ast/Types.h3
-rw-r--r--libsolidity/codegen/ExpressionCompiler.cpp8
3 files changed, 12 insertions, 6 deletions
diff --git a/libsolidity/analysis/GlobalContext.cpp b/libsolidity/analysis/GlobalContext.cpp
index 069d10f5..d8f1603a 100644
--- a/libsolidity/analysis/GlobalContext.cpp
+++ b/libsolidity/analysis/GlobalContext.cpp
@@ -66,9 +66,10 @@ m_magicVariables(vector<shared_ptr<MagicVariableDeclaration const>>{make_shared<
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)),
-// Disabled until decision about semantics of assert is made.
-// make_shared<MagicVariableDeclaration>("assert",
-// make_shared<FunctionType>(strings{"bool"}, strings{}, FunctionType::Location::Assert)),
+ make_shared<MagicVariableDeclaration>("assert",
+ make_shared<FunctionType>(strings{"bool"}, strings{}, FunctionType::Location::Assert)),
+ make_shared<MagicVariableDeclaration>("require",
+ make_shared<FunctionType>(strings{"bool"}, strings{}, FunctionType::Location::Require)),
make_shared<MagicVariableDeclaration>("revert",
make_shared<FunctionType>(strings(), strings(), FunctionType::Location::Revert))})
{
diff --git a/libsolidity/ast/Types.h b/libsolidity/ast/Types.h
index 022b67c4..960b7e86 100644
--- a/libsolidity/ast/Types.h
+++ b/libsolidity/ast/Types.h
@@ -847,7 +847,8 @@ public:
ArrayPush, ///< .push() to a dynamically sized array in storage
ByteArrayPush, ///< .push() to a dynamically sized byte array in storage
ObjectCreation, ///< array creation using new
- Assert ///< assert()
+ Assert, ///< assert()
+ Require ///< require()
};
virtual Category category() const override { return Category::Function; }
diff --git a/libsolidity/codegen/ExpressionCompiler.cpp b/libsolidity/codegen/ExpressionCompiler.cpp
index 5192ffa6..744a80c4 100644
--- a/libsolidity/codegen/ExpressionCompiler.cpp
+++ b/libsolidity/codegen/ExpressionCompiler.cpp
@@ -879,14 +879,18 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
break;
}
case Location::Assert:
+ case Location::Require:
{
arguments.front()->accept(*this);
utils().convertType(*arguments.front()->annotation().type, *function.parameterTypes().front(), false);
// jump if condition was met
m_context << Instruction::ISZERO << Instruction::ISZERO;
auto success = m_context.appendConditionalJump();
- // condition was not met, flag an error
- m_context << Instruction::INVALID;
+ if (function.location() == Location::Assert)
+ // condition was not met, flag an error
+ m_context << Instruction::INVALID;
+ else
+ m_context << u256(0) << u256(0) << Instruction::REVERT;
// the success branch
m_context << success;
break;