libsolidity/formal/BMC.cpp
// Here we consider the execution of two branches similar to WhileStatement.
Here we consider the execution of two branches similar to WhileStatement.
Here we consider the execution of two branches similar to WhileStatement .
bool BMC::visit(ForStatement const& _node)
{
	if (_node.initializationExpression())
		_node.initializationExpression()->accept(*this);
	auto indicesBeforeLoop = copyVariableIndices();
	auto touchedVars = touchedVariables(_node.body());
	if (_node.condition())
		touchedVars += touchedVariables(*_node.condition());
	if (_node.loopExpression())
		touchedVars += touchedVariables(*_node.loopExpression());
	m_context.resetVariables(touchedVars);
	if (_node.condition())
	{
		_node.condition()->accept(*this);
		if (isRootFunction())
			addVerificationTarget(
				VerificationTarget::Type::ConstantCondition,
				expr(*_node.condition()),
				_node.condition()
			);
	}
	m_context.pushSolver();
	if (_node.condition())
		m_context.addAssertion(expr(*_node.condition()));
	_node.body().accept(*this);
	if (_node.loopExpression())
		_node.loopExpression()->accept(*this);
	m_context.popSolver();
	auto indicesAfterLoop = copyVariableIndices();
	resetVariableIndices(indicesBeforeLoop);
	if (_node.condition())
		_node.condition()->accept(*this);
	auto forCondition = _node.condition() ? expr(*_node.condition()) : smtutil::Expression(true);
	mergeVariables(touchedVars, forCondition, indicesAfterLoop, copyVariableIndices());
	m_loopExecutionHappened = true;
	return false;
}
bool BMC :: visit ( ForStatement const & _node ) { if ( _node . initializationExpression ( ) ) _node . initializationExpression ( ) -> accept ( * this ) ; auto indicesBeforeLoop = copyVariableIndices ( ) ; auto touchedVars = touchedVariables ( _node . body ( ) ) ; if ( _node . condition ( ) ) touchedVars += touchedVariables ( * _node . condition ( ) ) ; if ( _node . loopExpression ( ) ) touchedVars += touchedVariables ( * _node . loopExpression ( ) ) ; m_context . resetVariables ( touchedVars ) ; if ( _node . condition ( ) ) { _node . condition ( ) -> accept ( * this ) ; if ( isRootFunction ( ) ) addVerificationTarget ( VerificationTarget :: Type :: ConstantCondition , expr ( * _node . condition ( ) ) , _node . condition ( ) ) ; } m_context . pushSolver ( ) ; if ( _node . condition ( ) ) m_context . addAssertion ( expr ( * _node . condition ( ) ) ) ; _node . body ( ) . accept ( * this ) ; if ( _node . loopExpression ( ) ) _node . loopExpression ( ) -> accept ( * this ) ; m_context . popSolver ( ) ; auto indicesAfterLoop = copyVariableIndices ( ) ; resetVariableIndices ( indicesBeforeLoop ) ; if ( _node . condition ( ) ) _node . condition ( ) -> accept ( * this ) ; auto forCondition = _node . condition ( ) ? expr ( * _node . condition ( ) ) : smtutil :: Expression ( true ) ; mergeVariables ( touchedVars , forCondition , indicesAfterLoop , copyVariableIndices ( ) ) ; m_loopExecutionHappened = true ; return false ; }
Here we consider the execution of two branches similar to WhileStatement.
Here we consider the execution of two branches similar to WhileStatement .
// Do not reset the init expression part. // We reset the execution to before the loop // and visit the condition.