Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
JaniReduceNestingExpressionVisitor.cpp
Go to the documentation of this file.
2
3namespace storm {
4
5namespace jani {
9} // namespace jani
10
11namespace expressions {
12
16
17boost::any JaniReduceNestingExpressionVisitor::visit(ValueArrayExpression const& expression, boost::any const& data) {
18 uint64_t size = expression.size()->evaluateAsInt();
19 std::vector<std::shared_ptr<BaseExpression const>> newElements;
20 newElements.reserve(size);
21 bool changed = false;
22 for (uint64_t i = 0; i < size; ++i) {
23 newElements.push_back(boost::any_cast<std::shared_ptr<BaseExpression const>>(expression.at(i)->accept(*this, data)));
24 changed = changed || expression.at(i).get() != newElements.back().get();
25 }
26
27 if (changed) {
28 return std::const_pointer_cast<BaseExpression const>(
29 std::shared_ptr<BaseExpression>(new ValueArrayExpression(expression.getManager(), expression.getType(), newElements)));
30 } else {
31 return expression.getSharedPointer();
32 }
33}
34
35boost::any JaniReduceNestingExpressionVisitor::visit(ConstructorArrayExpression const& expression, boost::any const& data) {
36 std::shared_ptr<BaseExpression const> newSize = boost::any_cast<std::shared_ptr<BaseExpression const>>(expression.size()->accept(*this, data));
37 std::shared_ptr<BaseExpression const> elementExpression =
38 boost::any_cast<std::shared_ptr<BaseExpression const>>(expression.getElementExpression()->accept(*this, data));
39
40 // If the arguments did not change, we simply push the expression itself.
41 if (newSize.get() == expression.size().get() && elementExpression.get() == expression.getElementExpression().get()) {
42 return expression.getSharedPointer();
43 } else {
44 return std::const_pointer_cast<BaseExpression const>(std::shared_ptr<BaseExpression>(
45 new ConstructorArrayExpression(expression.getManager(), expression.getType(), newSize, expression.getIndexVar(), elementExpression)));
46 }
47}
48
49boost::any JaniReduceNestingExpressionVisitor::visit(ArrayAccessExpression const& expression, boost::any const& data) {
50 std::shared_ptr<BaseExpression const> firstExpression =
51 boost::any_cast<std::shared_ptr<BaseExpression const>>(expression.getFirstOperand()->accept(*this, data));
52 std::shared_ptr<BaseExpression const> secondExpression =
53 boost::any_cast<std::shared_ptr<BaseExpression const>>(expression.getSecondOperand()->accept(*this, data));
54
55 // If the arguments did not change, we simply push the expression itself.
56 if (firstExpression.get() == expression.getFirstOperand().get() && secondExpression.get() == expression.getSecondOperand().get()) {
57 return expression.getSharedPointer();
58 } else {
59 return std::const_pointer_cast<BaseExpression const>(
60 std::shared_ptr<BaseExpression>(new ArrayAccessExpression(expression.getManager(), expression.getType(), firstExpression, secondExpression)));
61 }
62}
63
64boost::any JaniReduceNestingExpressionVisitor::visit(FunctionCallExpression const& expression, boost::any const& data) {
65 std::vector<std::shared_ptr<BaseExpression const>> newArguments;
66 newArguments.reserve(expression.getNumberOfArguments());
67 for (uint64_t i = 0; i < expression.getNumberOfArguments(); ++i) {
68 newArguments.push_back(boost::any_cast<std::shared_ptr<BaseExpression const>>(expression.getArgument(i)->accept(*this, data)));
69 }
70 return std::const_pointer_cast<BaseExpression const>(std::shared_ptr<BaseExpression>(
71 new FunctionCallExpression(expression.getManager(), expression.getType(), expression.getFunctionIdentifier(), newArguments)));
72}
73
74boost::any JaniReduceNestingExpressionVisitor::visit(TranscendentalNumberLiteralExpression const& expression, boost::any const& data) {
75 // No substitution is required for constants
76 return expression.getSharedPointer();
77}
78} // namespace expressions
79} // namespace storm
ExpressionManager const & getManager() const
Retrieves the manager responsible for this expression.
Type const & getType() const
Retrieves the type of the expression.
std::shared_ptr< BaseExpression const > getSharedPointer() const
Retrieves a shared pointer to this expression.
std::shared_ptr< BaseExpression const > const & getSecondOperand() const
Retrieves the second operand of the expression.
std::shared_ptr< BaseExpression const > const & getFirstOperand() const
Retrieves the first operand of the expression.
Represents an array of the given size, where the i'th entry is determined by the elementExpression,...
virtual std::shared_ptr< BaseExpression const > size() const override
std::shared_ptr< BaseExpression const > const & getElementExpression() const
storm::expressions::Variable const & getIndexVar() const
Represents an array with a given list of elements.
std::shared_ptr< BaseExpression const > getArgument(uint64_t i) const
virtual boost::any visit(ValueArrayExpression const &expression, boost::any const &data) override
Expression reduceNesting(Expression const &expression)
Reduces the nesting in the given expression.
Represents an array with a given list of elements.
virtual std::shared_ptr< BaseExpression const > size() const override
virtual std::shared_ptr< BaseExpression const > at(uint64_t i) const override
storm::expressions::Expression reduceNestingInJaniExpression(storm::expressions::Expression const &expression)
LabParser.cpp.
Definition cli.cpp:18