aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity/formal/SMTChecker.cpp
diff options
context:
space:
mode:
authorLeonardo Alt <leo@ethereum.org>2018-06-12 16:58:24 +0800
committerLeonardo Alt <leo@ethereum.org>2018-06-12 16:58:50 +0800
commit207d5859d1edc7ed5c41fbdf62fd7fb929531103 (patch)
treeec660df51776a548e5e8c954faa851127bce9610 /libsolidity/formal/SMTChecker.cpp
parent48652c88af44436d6a9d881918bfa93576516adb (diff)
downloaddexon-solidity-207d5859d1edc7ed5c41fbdf62fd7fb929531103.tar
dexon-solidity-207d5859d1edc7ed5c41fbdf62fd7fb929531103.tar.gz
dexon-solidity-207d5859d1edc7ed5c41fbdf62fd7fb929531103.tar.bz2
dexon-solidity-207d5859d1edc7ed5c41fbdf62fd7fb929531103.tar.lz
dexon-solidity-207d5859d1edc7ed5c41fbdf62fd7fb929531103.tar.xz
dexon-solidity-207d5859d1edc7ed5c41fbdf62fd7fb929531103.tar.zst
dexon-solidity-207d5859d1edc7ed5c41fbdf62fd7fb929531103.zip
Refactoring Declaration -> VariableDeclaration (more precise)
Diffstat (limited to 'libsolidity/formal/SMTChecker.cpp')
-rw-r--r--libsolidity/formal/SMTChecker.cpp51
1 files changed, 25 insertions, 26 deletions
diff --git a/libsolidity/formal/SMTChecker.cpp b/libsolidity/formal/SMTChecker.cpp
index 773fc332..a4d9500b 100644
--- a/libsolidity/formal/SMTChecker.cpp
+++ b/libsolidity/formal/SMTChecker.cpp
@@ -109,7 +109,7 @@ bool SMTChecker::visit(IfStatement const& _node)
checkBooleanNotConstant(_node.condition(), "Condition is always $VALUE.");
auto countersEndTrue = visitBranch(_node.trueStatement(), expr(_node.condition()));
- vector<Declaration const*> touchedVariables = m_variableUsage->touchedVariables(_node.trueStatement());
+ vector<VariableDeclaration const*> touchedVariables = m_variableUsage->touchedVariables(_node.trueStatement());
decltype(countersEndTrue) countersEndFalse;
if (_node.falseStatement())
{
@@ -229,10 +229,10 @@ void SMTChecker::endVisit(Assignment const& _assignment)
);
else if (Identifier const* identifier = dynamic_cast<Identifier const*>(&_assignment.leftHandSide()))
{
- Declaration const* decl = identifier->annotation().referencedDeclaration;
- if (knownVariable(*decl))
+ VariableDeclaration const& decl = dynamic_cast<VariableDeclaration const&>(*identifier->annotation().referencedDeclaration);
+ if (knownVariable(decl))
{
- assignment(*decl, _assignment.rightHandSide(), _assignment.location());
+ assignment(decl, _assignment.rightHandSide(), _assignment.location());
defineExpr(_assignment, expr(_assignment.rightHandSide()));
}
else
@@ -295,12 +295,12 @@ void SMTChecker::endVisit(UnaryOperation const& _op)
solAssert(_op.subExpression().annotation().lValueRequested, "");
if (Identifier const* identifier = dynamic_cast<Identifier const*>(&_op.subExpression()))
{
- Declaration const* decl = identifier->annotation().referencedDeclaration;
- if (knownVariable(*decl))
+ VariableDeclaration const& decl = dynamic_cast<VariableDeclaration const&>(*identifier->annotation().referencedDeclaration);
+ if (knownVariable(decl))
{
- auto innerValue = currentValue(*decl);
+ auto innerValue = currentValue(decl);
auto newValue = _op.getOperator() == Token::Inc ? innerValue + 1 : innerValue - 1;
- assignment(*decl, newValue, _op.location());
+ assignment(decl, newValue, _op.location());
defineExpr(_op, _op.isPrefixOperation() ? newValue : innerValue);
}
else
@@ -382,14 +382,15 @@ void SMTChecker::endVisit(FunctionCall const& _funCall)
void SMTChecker::endVisit(Identifier const& _identifier)
{
- Declaration const* decl = _identifier.annotation().referencedDeclaration;
- solAssert(decl, "");
if (_identifier.annotation().lValueRequested)
{
// Will be translated as part of the node that requested the lvalue.
}
else if (SSAVariable::isSupportedType(_identifier.annotation().type->category()))
- defineExpr(_identifier, currentValue(*decl));
+ {
+ VariableDeclaration const& decl = dynamic_cast<VariableDeclaration const&>(*(_identifier.annotation().referencedDeclaration));
+ defineExpr(_identifier, currentValue(decl));
+ }
else if (FunctionType const* fun = dynamic_cast<FunctionType const*>(_identifier.annotation().type.get()))
{
if (fun->kind() == FunctionType::Kind::Assert || fun->kind() == FunctionType::Kind::Require)
@@ -529,12 +530,12 @@ smt::Expression SMTChecker::division(smt::Expression _left, smt::Expression _rig
return _left / _right;
}
-void SMTChecker::assignment(Declaration const& _variable, Expression const& _value, SourceLocation const& _location)
+void SMTChecker::assignment(VariableDeclaration const& _variable, Expression const& _value, SourceLocation const& _location)
{
assignment(_variable, expr(_value), _location);
}
-void SMTChecker::assignment(Declaration const& _variable, smt::Expression const& _value, SourceLocation const& _location)
+void SMTChecker::assignment(VariableDeclaration const& _variable, smt::Expression const& _value, SourceLocation const& _location)
{
TypePointer type = _variable.type();
if (auto const* intType = dynamic_cast<IntegerType const*>(type.get()))
@@ -729,8 +730,7 @@ void SMTChecker::resetStateVariables()
{
for (auto const& variable: m_variables)
{
- VariableDeclaration const& _decl = dynamic_cast<VariableDeclaration const&>(*variable.first);
- if (_decl.isStateVariable())
+ if (variable.first->isStateVariable())
{
newValue(*variable.first);
setUnknownValue(*variable.first);
@@ -738,7 +738,7 @@ void SMTChecker::resetStateVariables()
}
}
-void SMTChecker::resetVariables(vector<Declaration const*> _variables)
+void SMTChecker::resetVariables(vector<VariableDeclaration const*> _variables)
{
for (auto const* decl: _variables)
{
@@ -747,9 +747,9 @@ void SMTChecker::resetVariables(vector<Declaration const*> _variables)
}
}
-void SMTChecker::mergeVariables(vector<Declaration const*> const& _variables, smt::Expression const& _condition, VariableSequenceCounters const& _countersEndTrue, VariableSequenceCounters const& _countersEndFalse)
+void SMTChecker::mergeVariables(vector<VariableDeclaration const*> const& _variables, smt::Expression const& _condition, VariableSequenceCounters const& _countersEndTrue, VariableSequenceCounters const& _countersEndFalse)
{
- set<Declaration const*> uniqueVars(_variables.begin(), _variables.end());
+ set<VariableDeclaration const*> uniqueVars(_variables.begin(), _variables.end());
for (auto const* decl: uniqueVars)
{
int trueCounter = _countersEndTrue.at(decl).index();
@@ -786,37 +786,37 @@ string SMTChecker::uniqueSymbol(Expression const& _expr)
return "expr_" + to_string(_expr.id());
}
-bool SMTChecker::knownVariable(Declaration const& _decl)
+bool SMTChecker::knownVariable(VariableDeclaration const& _decl)
{
return m_variables.count(&_decl);
}
-smt::Expression SMTChecker::currentValue(Declaration const& _decl)
+smt::Expression SMTChecker::currentValue(VariableDeclaration const& _decl)
{
solAssert(knownVariable(_decl), "");
return m_variables.at(&_decl)();
}
-smt::Expression SMTChecker::valueAtSequence(Declaration const& _decl, int _sequence)
+smt::Expression SMTChecker::valueAtSequence(VariableDeclaration const& _decl, int _sequence)
{
solAssert(knownVariable(_decl), "");
return m_variables.at(&_decl)(_sequence);
}
-smt::Expression SMTChecker::newValue(Declaration const& _decl)
+smt::Expression SMTChecker::newValue(VariableDeclaration const& _decl)
{
solAssert(knownVariable(_decl), "");
++m_variables.at(&_decl);
return m_variables.at(&_decl)();
}
-void SMTChecker::setZeroValue(Declaration const& _decl)
+void SMTChecker::setZeroValue(VariableDeclaration const& _decl)
{
solAssert(knownVariable(_decl), "");
m_variables.at(&_decl).setZeroValue();
}
-void SMTChecker::setUnknownValue(Declaration const& _decl)
+void SMTChecker::setUnknownValue(VariableDeclaration const& _decl)
{
solAssert(knownVariable(_decl), "");
m_variables.at(&_decl).setUnknownValue();
@@ -898,8 +898,7 @@ void SMTChecker::removeLocalVariables()
{
for (auto it = m_variables.begin(); it != m_variables.end(); )
{
- VariableDeclaration const& _decl = dynamic_cast<VariableDeclaration const&>(*it->first);
- if (_decl.isLocalVariable())
+ if (it->first->isLocalVariable())
it = m_variables.erase(it);
else
++it;