mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Implement assert as a global function
This commit is contained in:
parent
af8e31b023
commit
f8461e9e31
@ -1,6 +1,7 @@
|
|||||||
### 0.4.10 (unreleased)
|
### 0.4.10 (unreleased)
|
||||||
|
|
||||||
Features:
|
Features:
|
||||||
|
* Add ``assert(condition)`` to abort execution.
|
||||||
* Type system: Support explicit conversion of external function to address.
|
* Type system: Support explicit conversion of external function to address.
|
||||||
|
|
||||||
Bugfixes:
|
Bugfixes:
|
||||||
|
@ -65,7 +65,9 @@ m_magicVariables(vector<shared_ptr<MagicVariableDeclaration const>>{make_shared<
|
|||||||
make_shared<MagicVariableDeclaration>("ecrecover",
|
make_shared<MagicVariableDeclaration>("ecrecover",
|
||||||
make_shared<FunctionType>(strings{"bytes32", "uint8", "bytes32", "bytes32"}, strings{"address"}, FunctionType::Location::ECRecover)),
|
make_shared<FunctionType>(strings{"bytes32", "uint8", "bytes32", "bytes32"}, strings{"address"}, FunctionType::Location::ECRecover)),
|
||||||
make_shared<MagicVariableDeclaration>("ripemd160",
|
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))})
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -819,8 +819,8 @@ public:
|
|||||||
{
|
{
|
||||||
Internal, ///< stack-call using plain JUMP
|
Internal, ///< stack-call using plain JUMP
|
||||||
External, ///< external call using CALL
|
External, ///< external call using CALL
|
||||||
CallCode, ///< extercnal call using CALLCODE, i.e. not exchanging the storage
|
CallCode, ///< external call using CALLCODE, i.e. not exchanging the storage
|
||||||
DelegateCall, ///< extercnal call using DELEGATECALL, i.e. not exchanging the storage
|
DelegateCall, ///< external call using DELEGATECALL, i.e. not exchanging the storage
|
||||||
Bare, ///< CALL without function hash
|
Bare, ///< CALL without function hash
|
||||||
BareCallCode, ///< CALLCODE without function hash
|
BareCallCode, ///< CALLCODE without function hash
|
||||||
BareDelegateCall, ///< DELEGATECALL without function hash
|
BareDelegateCall, ///< DELEGATECALL without function hash
|
||||||
@ -844,7 +844,8 @@ public:
|
|||||||
MulMod, ///< MULMOD
|
MulMod, ///< MULMOD
|
||||||
ArrayPush, ///< .push() to a dynamically sized array in storage
|
ArrayPush, ///< .push() to a dynamically sized array in storage
|
||||||
ByteArrayPush, ///< .push() to a dynamically sized byte 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; }
|
virtual Category category() const override { return Category::Function; }
|
||||||
|
@ -863,6 +863,14 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
|
|||||||
m_context << Instruction::POP;
|
m_context << Instruction::POP;
|
||||||
break;
|
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:
|
default:
|
||||||
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Invalid function type."));
|
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Invalid function type."));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user