Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
ValueArrayExpression.cpp
Go to the documentation of this file.
2
5
8
9namespace storm {
10namespace expressions {
11
13 std::vector<std::shared_ptr<BaseExpression const>> const& elements)
14 : ArrayExpression(manager, type), elements(elements) {
15 // Intentionally left empty
16}
17
18void ValueArrayExpression::gatherVariables(std::set<storm::expressions::Variable>& variables) const {
19 for (auto const& e : elements) {
20 e->gatherVariables(variables);
21 }
22}
23
25 for (auto const& e : elements) {
26 if (e->containsVariables()) {
27 return true;
28 }
29 }
30 return false;
31}
32
33std::shared_ptr<BaseExpression const> ValueArrayExpression::simplify() const {
34 std::vector<std::shared_ptr<BaseExpression const>> simplifiedElements;
35 simplifiedElements.reserve(elements.size());
36 for (auto const& e : elements) {
37 simplifiedElements.push_back(e->simplify());
38 }
39 return std::shared_ptr<BaseExpression const>(new ValueArrayExpression(getManager(), getType(), simplifiedElements));
40}
41
42boost::any ValueArrayExpression::accept(ExpressionVisitor& visitor, boost::any const& data) const {
43 auto janiVisitor = dynamic_cast<JaniExpressionVisitor*>(&visitor);
44 STORM_LOG_THROW(janiVisitor != nullptr, storm::exceptions::UnexpectedException, "Visitor of jani expression should be of type JaniVisitor.");
45 return janiVisitor->visit(*this, data);
46}
47
48void ValueArrayExpression::printToStream(std::ostream& stream) const {
49 stream << "array[ ";
50 bool first = true;
51 for (auto const& e : elements) {
52 if (!first) {
53 stream << " , ";
54 }
55 first = false;
56 stream << *e;
57 }
58 stream << " ]";
59}
60
61std::shared_ptr<BaseExpression const> ValueArrayExpression::size() const {
62 return getManager().integer(elements.size()).getBaseExpressionPointer();
63}
64
65std::shared_ptr<BaseExpression const> ValueArrayExpression::at(uint64_t i) const {
66 STORM_LOG_THROW(i < elements.size(), storm::exceptions::InvalidArgumentException,
67 "Tried to access the element with index " << i << " of an array of size " << elements.size() << ".");
68 return elements[i];
69}
70
71} // namespace expressions
72} // namespace storm
The base class of all array expressions.
virtual void gatherVariables(std::set< storm::expressions::Variable > &variables) const =0
Retrieves the set of all variables that appear in the expression.
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 > 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...
Expression integer(int_fast64_t value) const
Creates an expression that characterizes the given integer literal.
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
virtual std::shared_ptr< BaseExpression const > simplify() const override
Simplifies the expression according to some simple rules.
virtual void gatherVariables(std::set< storm::expressions::Variable > &variables) const override
Retrieves the set of all variables that appear in the expression.
ValueArrayExpression(ExpressionManager const &manager, Type const &type, std::vector< std::shared_ptr< BaseExpression const > > const &elements)
virtual bool containsVariables() const override
Retrieves whether the expression contains a variable.
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.
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:30
LabParser.cpp.
Definition cli.cpp:18