Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
ConstructorArrayExpression.cpp
Go to the documentation of this file.
1
3
7
10
11namespace storm {
12namespace expressions {
13
14ConstructorArrayExpression::ConstructorArrayExpression(ExpressionManager const& manager, Type const& type, std::shared_ptr<BaseExpression const> const& size,
15 storm::expressions::Variable indexVar, std::shared_ptr<BaseExpression const> const& elementExpression)
16 : ArrayExpression(manager, type), sizeExpression(size), indexVar(indexVar), elementExpression(elementExpression) {
17 // Intentionally left empty
18}
19
20void ConstructorArrayExpression::gatherVariables(std::set<storm::expressions::Variable>& variables) const {
21 // The indexVar should not be gathered (unless it is already contained).
22 bool indexVarContained = variables.find(indexVar) != variables.end();
23 sizeExpression->gatherVariables(variables);
24 elementExpression->gatherVariables(variables);
25 if (!indexVarContained) {
26 variables.erase(indexVar);
27 }
28}
29
31 if (sizeExpression->containsVariables()) {
32 return true;
33 }
34 // The index variable should not count
35 std::set<storm::expressions::Variable> variables;
36 elementExpression->gatherVariables(variables);
37 variables.erase(indexVar);
38 return !variables.empty();
39}
40
41std::shared_ptr<BaseExpression const> ConstructorArrayExpression::simplify() const {
42 return std::shared_ptr<BaseExpression const>(
43 new ConstructorArrayExpression(getManager(), getType(), sizeExpression->simplify(), indexVar, elementExpression->simplify()));
44}
45
46boost::any ConstructorArrayExpression::accept(ExpressionVisitor& visitor, boost::any const& data) const {
47 auto janiVisitor = dynamic_cast<JaniExpressionVisitor*>(&visitor);
48 STORM_LOG_THROW(janiVisitor != nullptr, storm::exceptions::UnexpectedException, "Visitor of jani expression should be of type JaniVisitor.");
49 return janiVisitor->visit(*this, data);
50}
51
52void ConstructorArrayExpression::printToStream(std::ostream& stream) const {
53 stream << "array[ " << *elementExpression << " | " << indexVar.getExpression() << " < " << *sizeExpression << " ]";
54}
55
56std::shared_ptr<BaseExpression const> ConstructorArrayExpression::size() const {
57 return sizeExpression;
58}
59
60std::shared_ptr<BaseExpression const> ConstructorArrayExpression::at(uint64_t i) const {
61 std::map<storm::expressions::Variable, storm::expressions::Expression> substitution;
62 substitution.emplace(indexVar, this->getManager().integer(i));
63 return storm::jani::substituteJaniExpression(elementExpression->toExpression(), substitution, false).getBaseExpressionPointer();
64}
65
66std::shared_ptr<BaseExpression const> const& ConstructorArrayExpression::getElementExpression() const {
67 return elementExpression;
68}
69
73
74} // namespace expressions
75} // namespace storm
The base class of all array expressions.
ExpressionManager const & getManager() const
Retrieves the manager responsible for this expression.
Type const & getType() const
Retrieves the type 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
virtual void printToStream(std::ostream &stream) const override
Prints the expression to the given stream.
virtual boost::any accept(ExpressionVisitor &visitor, boost::any const &data) const override
Accepts the given visitor by calling its visit method.
virtual std::shared_ptr< BaseExpression const > at(uint64_t i) const override
virtual bool containsVariables() const override
Retrieves whether the expression contains a variable.
virtual void gatherVariables(std::set< storm::expressions::Variable > &variables) const override
Retrieves the set of all variables that appear in the expression.
ConstructorArrayExpression(ExpressionManager const &manager, Type const &type, std::shared_ptr< BaseExpression const > const &size, storm::expressions::Variable indexVar, std::shared_ptr< BaseExpression const > const &elementExpression)
virtual std::shared_ptr< BaseExpression const > simplify() const override
Simplifies the expression according to some simple rules.
std::shared_ptr< BaseExpression const > const & getElementExpression() const
storm::expressions::Variable const & getIndexVar() const
std::shared_ptr< BaseExpression const > const & getBaseExpressionPointer() const
Retrieves a pointer to the base expression underlying this expression object.
This class is responsible for managing a set of typed variables and all expressions using these varia...
storm::expressions::Expression getExpression() const
Retrieves an expression that represents the variable.
Definition Variable.cpp:34
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:30
storm::expressions::Expression substituteJaniExpression(storm::expressions::Expression const &expression, std::map< storm::expressions::Variable, storm::expressions::Expression > const &identifierToExpressionMap, bool const substituteTranscendentalNumbers)
LabParser.cpp.
Definition cli.cpp:18