Browse Source
Add check that undefined constants / parameters do not appear in the 'if' part of IfThenElseExpressions
main
Add check that undefined constants / parameters do not appear in the 'if' part of IfThenElseExpressions
main
5 changed files with 129 additions and 0 deletions
-
71src/storm/storage/expressions/CheckIfThenElseGuardVisitor.cpp
-
36src/storm/storage/expressions/CheckIfThenElseGuardVisitor.h
-
7src/storm/storage/expressions/Expression.cpp
-
10src/storm/storage/expressions/Expression.h
-
5src/storm/storage/prism/Command.cpp
@ -0,0 +1,71 @@ |
|||||
|
#include "storm/storage/expressions/CheckIfThenElseGuardVisitor.h"
|
||||
|
|
||||
|
#include "storm/storage/expressions/Expressions.h"
|
||||
|
|
||||
|
namespace storm { |
||||
|
namespace expressions { |
||||
|
|
||||
|
CheckIfThenElseGuardVisitor::CheckIfThenElseGuardVisitor(std::set<storm::expressions::Variable> const& variables) : variables(variables) { |
||||
|
// Intentionally left empty.
|
||||
|
} |
||||
|
|
||||
|
bool CheckIfThenElseGuardVisitor::check(storm::expressions::Expression const& expression) { |
||||
|
return boost::any_cast<bool>(expression.accept(*this, boost::none)); |
||||
|
} |
||||
|
|
||||
|
boost::any CheckIfThenElseGuardVisitor::visit(IfThenElseExpression const& expression, boost::any const& data) { |
||||
|
// check whether the 'if' condition depends on one of the variables
|
||||
|
if (expression.getCondition()->toExpression().containsVariable(variables)) { |
||||
|
return true; |
||||
|
} else { |
||||
|
// recurse
|
||||
|
return |
||||
|
boost::any_cast<bool>(expression.getThenExpression()->accept(*this, data)) || |
||||
|
boost::any_cast<bool>(expression.getElseExpression()->accept(*this, data)); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
boost::any CheckIfThenElseGuardVisitor::visit(BinaryBooleanFunctionExpression const& expression, boost::any const& data) { |
||||
|
return |
||||
|
boost::any_cast<bool>(expression.getFirstOperand()->accept(*this, data)) || |
||||
|
boost::any_cast<bool>(expression.getSecondOperand()->accept(*this, data)); |
||||
|
} |
||||
|
|
||||
|
boost::any CheckIfThenElseGuardVisitor::visit(BinaryNumericalFunctionExpression const& expression, boost::any const& data) { |
||||
|
return |
||||
|
boost::any_cast<bool>(expression.getFirstOperand()->accept(*this, data)) || |
||||
|
boost::any_cast<bool>(expression.getSecondOperand()->accept(*this, data)); |
||||
|
} |
||||
|
|
||||
|
boost::any CheckIfThenElseGuardVisitor::visit(BinaryRelationExpression const& expression, boost::any const& data) { |
||||
|
return |
||||
|
boost::any_cast<bool>(expression.getFirstOperand()->accept(*this, data)) || |
||||
|
boost::any_cast<bool>(expression.getSecondOperand()->accept(*this, data)); |
||||
|
} |
||||
|
|
||||
|
boost::any CheckIfThenElseGuardVisitor::visit(VariableExpression const& expression, boost::any const&) { |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
boost::any CheckIfThenElseGuardVisitor::visit(UnaryBooleanFunctionExpression const& expression, boost::any const& data) { |
||||
|
return expression.getOperand()->accept(*this, data); |
||||
|
} |
||||
|
|
||||
|
boost::any CheckIfThenElseGuardVisitor::visit(UnaryNumericalFunctionExpression const& expression, boost::any const& data) { |
||||
|
return expression.getOperand()->accept(*this, data); |
||||
|
} |
||||
|
|
||||
|
boost::any CheckIfThenElseGuardVisitor::visit(BooleanLiteralExpression const& expression, boost::any const&) { |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
boost::any CheckIfThenElseGuardVisitor::visit(IntegerLiteralExpression const& expression, boost::any const&) { |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
boost::any CheckIfThenElseGuardVisitor::visit(RationalLiteralExpression const& expression, boost::any const&) { |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
} |
@ -0,0 +1,36 @@ |
|||||
|
#pragma once |
||||
|
|
||||
|
#include "storm/storage/expressions/ExpressionVisitor.h" |
||||
|
#include <set> |
||||
|
|
||||
|
namespace storm { |
||||
|
namespace expressions { |
||||
|
|
||||
|
class Expression; |
||||
|
class Variable; |
||||
|
|
||||
|
// Visits all sub-expressions and returns true if any of them is an IfThenElseExpression |
||||
|
// where the 'if' part depends on one of the variables in the set passed in the constructor. |
||||
|
class CheckIfThenElseGuardVisitor : public ExpressionVisitor { |
||||
|
public: |
||||
|
CheckIfThenElseGuardVisitor(std::set<storm::expressions::Variable> const& variables); |
||||
|
|
||||
|
bool check(storm::expressions::Expression const& expression); |
||||
|
|
||||
|
virtual boost::any visit(IfThenElseExpression const& expression, boost::any const& data) override; |
||||
|
virtual boost::any visit(BinaryBooleanFunctionExpression const& expression, boost::any const& data) override; |
||||
|
virtual boost::any visit(BinaryNumericalFunctionExpression const& expression, boost::any const& data) override; |
||||
|
virtual boost::any visit(BinaryRelationExpression const& expression, boost::any const& data) override; |
||||
|
virtual boost::any visit(VariableExpression const& expression, boost::any const& data) override; |
||||
|
virtual boost::any visit(UnaryBooleanFunctionExpression const& expression, boost::any const& data) override; |
||||
|
virtual boost::any visit(UnaryNumericalFunctionExpression const& expression, boost::any const& data) override; |
||||
|
virtual boost::any visit(BooleanLiteralExpression const& expression, boost::any const& data) override; |
||||
|
virtual boost::any visit(IntegerLiteralExpression const& expression, boost::any const& data) override; |
||||
|
virtual boost::any visit(RationalLiteralExpression const& expression, boost::any const& data) override; |
||||
|
|
||||
|
private: |
||||
|
std::set<storm::expressions::Variable> const& variables; |
||||
|
}; |
||||
|
|
||||
|
} |
||||
|
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue