mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
[SMTChecker_Bool] Fix PR comments; Add support to gt, ge, lt, le. and tests.
This commit is contained in:
@@ -205,7 +205,7 @@ void SMTChecker::endVisit(Assignment const& _assignment)
|
||||
_assignment.location(),
|
||||
"Assertion checker does not yet implement compound assignment."
|
||||
);
|
||||
else if (_assignment.annotation().type->category() != Type::Category::Integer)
|
||||
else if (!SSAVariable::supportedType(_assignment.annotation().type->category()))
|
||||
m_errorReporter.warning(
|
||||
_assignment.location(),
|
||||
"Assertion checker does not yet implement type " + _assignment.annotation().type->toString()
|
||||
@@ -266,14 +266,15 @@ void SMTChecker::endVisit(UnaryOperation const& _op)
|
||||
{
|
||||
case Token::Not: // !
|
||||
{
|
||||
solAssert(_op.annotation().type->category() == Type::Category::Bool, "");
|
||||
solAssert(SSAVariable::typeBool(_op.annotation().type->category()), "");
|
||||
defineExpr(_op, !expr(_op.subExpression()));
|
||||
break;
|
||||
}
|
||||
case Token::Inc: // ++ (pre- or postfix)
|
||||
case Token::Dec: // -- (pre- or postfix)
|
||||
{
|
||||
solAssert(_op.annotation().type->category() == Type::Category::Integer, "");
|
||||
|
||||
solAssert(SSAVariable::typeInteger(_op.annotation().type->category()), "");
|
||||
solAssert(_op.subExpression().annotation().lValueRequested, "");
|
||||
if (Identifier const* identifier = dynamic_cast<Identifier const*>(&_op.subExpression()))
|
||||
{
|
||||
@@ -370,7 +371,7 @@ void SMTChecker::endVisit(Identifier const& _identifier)
|
||||
{
|
||||
// Will be translated as part of the node that requested the lvalue.
|
||||
}
|
||||
else if (SSAVariable::supportedType(_identifier.annotation().type.get()))
|
||||
else if (SSAVariable::supportedType(_identifier.annotation().type->category()))
|
||||
defineExpr(_identifier, currentValue(*decl));
|
||||
else if (FunctionType const* fun = dynamic_cast<FunctionType const*>(_identifier.annotation().type.get()))
|
||||
{
|
||||
@@ -444,21 +445,36 @@ void SMTChecker::arithmeticOperation(BinaryOperation const& _op)
|
||||
void SMTChecker::compareOperation(BinaryOperation const& _op)
|
||||
{
|
||||
solAssert(_op.annotation().commonType, "");
|
||||
if (SSAVariable::supportedType(_op.annotation().commonType.get()))
|
||||
if (SSAVariable::supportedType(_op.annotation().commonType->category()))
|
||||
{
|
||||
smt::Expression left(expr(_op.leftExpression()));
|
||||
smt::Expression right(expr(_op.rightExpression()));
|
||||
Token::Value op = _op.getOperator();
|
||||
smt::Expression value = (
|
||||
op == Token::Equal ? (left == right) :
|
||||
op == Token::NotEqual ? (left != right) :
|
||||
op == Token::LessThan ? (left < right) :
|
||||
op == Token::LessThanOrEqual ? (left <= right) :
|
||||
op == Token::GreaterThan ? (left > right) :
|
||||
/*op == Token::GreaterThanOrEqual*/ (left >= right)
|
||||
);
|
||||
shared_ptr<smt::Expression> value;
|
||||
if (SSAVariable::typeInteger(_op.annotation().commonType->category()))
|
||||
{
|
||||
value = make_shared<smt::Expression>(
|
||||
op == Token::Equal ? (left == right) :
|
||||
op == Token::NotEqual ? (left != right) :
|
||||
op == Token::LessThan ? (left < right) :
|
||||
op == Token::LessThanOrEqual ? (left <= right) :
|
||||
op == Token::GreaterThan ? (left > right) :
|
||||
/*op == Token::GreaterThanOrEqual*/ (left >= right)
|
||||
);
|
||||
}
|
||||
else // Bool
|
||||
{
|
||||
value = make_shared<smt::Expression>(
|
||||
op == Token::Equal ? (left == right) :
|
||||
op == Token::NotEqual ? (left != right) :
|
||||
op == Token::LessThan ? (!left && right) :
|
||||
op == Token::LessThanOrEqual ? (!left || right) :
|
||||
op == Token::GreaterThan ? (left && !right) :
|
||||
/*op == Token::GreaterThanOrEqual*/ (left || !right)
|
||||
);
|
||||
}
|
||||
// TODO: check that other values for op are not possible.
|
||||
defineExpr(_op, value);
|
||||
defineExpr(_op, *value);
|
||||
}
|
||||
else
|
||||
m_errorReporter.warning(
|
||||
@@ -728,10 +744,10 @@ void SMTChecker::mergeVariables(vector<Declaration const*> const& _variables, sm
|
||||
|
||||
bool SMTChecker::createVariable(VariableDeclaration const& _varDecl)
|
||||
{
|
||||
if (SSAVariable::supportedType(_varDecl.type().get()))
|
||||
if (SSAVariable::supportedType(_varDecl.type()->category()))
|
||||
{
|
||||
solAssert(m_variables.count(&_varDecl) == 0, "");
|
||||
m_variables.emplace(&_varDecl, SSAVariable(&_varDecl, *m_interface));
|
||||
m_variables.emplace(&_varDecl, SSAVariable(_varDecl, *m_interface));
|
||||
return true;
|
||||
}
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user