Storm 1.11.1.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
LValue.cpp
Go to the documentation of this file.
2
7
8namespace storm {
9namespace jani {
10
11LValue::LValue(storm::jani::Variable const& variable) : variable(&variable) {
12 // Intentionally left empty
13}
14
15LValue::LValue(storm::jani::Variable const& variable, std::vector<storm::expressions::Expression> const& index) : variable(&variable), arrayIndexVector(index) {
16 STORM_LOG_THROW(variable.getType().isArrayType(), storm::exceptions::NotSupportedException, "Expecting an array Variable");
17 // Intentionally left empty
18}
19
20bool LValue::isVariable() const {
21 return arrayIndexVector.empty();
22}
23
24bool LValue::isArray() const {
25 return variable->getType().isArrayType();
26}
27
29 return *variable;
30}
31
33 return !isVariable();
34}
35
37 return isArrayAccess() && variable->getType().asArrayType().getNestingDegree() == arrayIndexVector.size();
38}
39
40std::vector<storm::expressions::Expression>& LValue::getArrayIndexVector() {
41 STORM_LOG_ASSERT(isArray(), "Tried to get the array index of an LValue that does not refer to an array.");
42 return arrayIndexVector;
43}
44
45std::vector<storm::expressions::Expression> const& LValue::getArrayIndexVector() const {
46 STORM_LOG_ASSERT(isArray(), "Tried to get the array index of an LValue that does not refer to an array.");
47 return arrayIndexVector;
48}
49
51 STORM_LOG_ASSERT(isArray(), "Tried to check for variables in the array index of an LValue that does not refer to an array.");
52 for (auto const& expr : arrayIndexVector) {
53 if (expr.containsVariables()) {
54 return true;
55 }
56 }
57 return false;
58}
59
60void LValue::setArrayIndex(std::vector<storm::expressions::Expression> const& newIndex) {
61 STORM_LOG_ASSERT(isArray(), "Tried to set the array index of an LValue that does not refer to an array.");
62 arrayIndexVector = newIndex;
63}
64
66 STORM_LOG_ASSERT(isArray(), "Tried to add an array access index to an LValue that doesn't consider an array.");
67 arrayIndexVector.push_back(index);
68}
69
70bool LValue::isTransient() const {
71 return variable->isTransient();
72}
73
74LValue LValue::changeAssignmentVariables(std::map<Variable const*, std::reference_wrapper<Variable const>> const& remapping) const {
75 auto it = remapping.find(variable);
76 if (it == remapping.end()) {
77 return *this;
78 } else {
79 if (isArrayAccess()) {
80 return LValue(it->second, arrayIndexVector);
81 } else {
82 return LValue(it->second);
83 }
84 }
85}
86
87std::string LValue::getName() const {
88 std::string result = getVariable().getName();
89 if (isArrayAccess()) {
90 for (auto const& i : arrayIndexVector) {
91 result += "[" + i.toString() + "]";
92 }
93 }
94 return result;
95}
96
97bool LValue::operator<(LValue const& other) const {
98 if (isVariable()) {
99 return !other.isVariable() || variable->getExpressionVariable() < other.getVariable().getExpressionVariable();
100 } else {
101 STORM_LOG_ASSERT(isArrayAccess(), "Unhandled LValue.");
102 if (other.isVariable()) {
103 return false;
104 }
105 STORM_LOG_ASSERT(other.isArrayAccess(), "Unhandled LValue.");
106 if (getVariable().getExpressionVariable() < other.getVariable().getExpressionVariable()) {
107 return true;
108 } else if (other.getVariable().getExpressionVariable() < getVariable().getExpressionVariable()) {
109 return false;
110 } else {
111 return std::lexicographical_compare(arrayIndexVector.begin(), arrayIndexVector.end(), other.getArrayIndexVector().begin(),
112 other.getArrayIndexVector().end(), std::less<storm::expressions::Expression>());
113 }
114 }
115}
116
117bool LValue::operator==(LValue const& other) const {
118 if (getVariable().getExpressionVariable() == other.getVariable().getExpressionVariable()) {
119 if (isArrayAccess()) {
120 if (other.isArrayAccess() && arrayIndexVector.size() == other.getArrayIndexVector().size()) {
122 for (uint64_t i = 0; i < arrayIndexVector.size(); ++i) {
123 if (!checker.isSyntacticallyEqual(arrayIndexVector[i], other.getArrayIndexVector()[i])) {
124 return false;
125 }
126 }
127 return true;
128 } else {
129 return false;
130 }
131 } else {
132 STORM_LOG_ASSERT(isVariable(), "Unhandled kind of LValue");
133 return other.isVariable();
134 }
135 } else {
136 return false;
137 }
138}
139
140std::ostream& operator<<(std::ostream& stream, LValue const& lValue) {
141 stream << lValue.getName();
142 return stream;
143}
144
145} // namespace jani
146} // namespace storm
bool isSyntacticallyEqual(storm::expressions::Expression const &expression1, storm::expressions::Expression const &expression2)
uint64_t getNestingDegree() const
Definition ArrayType.cpp:34
ArrayType const & asArrayType() const
Definition JaniType.cpp:47
virtual bool isArrayType() const
Definition JaniType.cpp:19
bool arrayIndexContainsVariable() const
Definition LValue.cpp:50
bool operator==(LValue const &other) const
Definition LValue.cpp:117
bool isFullArrayAccess() const
Returns true if the lValue refers to an array access.
Definition LValue.cpp:36
std::string getName() const
Definition LValue.cpp:87
void addArrayAccessIndex(storm::expressions::Expression const &index)
Adds an array access index.
Definition LValue.cpp:65
void setArrayIndex(std::vector< storm::expressions::Expression > const &newIndex)
Definition LValue.cpp:60
bool isTransient() const
Definition LValue.cpp:70
LValue changeAssignmentVariables(std::map< Variable const *, std::reference_wrapper< Variable const > > const &remapping) const
Definition LValue.cpp:74
bool operator<(LValue const &other) const
Definition LValue.cpp:97
LValue(storm::jani::Variable const &variable)
Definition LValue.cpp:11
bool isVariable() const
Definition LValue.cpp:20
bool isArray() const
Returns true if the lValue refers to a variable (potentially of type array).
Definition LValue.cpp:24
std::vector< storm::expressions::Expression > & getArrayIndexVector()
Returns the referred variable. In case of an array access, this is the referred array variable.
Definition LValue.cpp:40
bool isArrayAccess() const
Returns true if the lValue refers either to an array variable or to an array access.
Definition LValue.cpp:32
storm::jani::Variable const & getVariable() const
To check if the array is fully accessed, so result will be of the most inner child Type....
Definition LValue.cpp:28
storm::expressions::Variable const & getExpressionVariable() const
Retrieves the associated expression variable.
Definition Variable.cpp:26
JaniType & getType()
Definition Variable.cpp:67
bool isTransient() const
Definition Variable.cpp:42
std::string const & getName() const
Retrieves the name of the variable.
Definition Variable.cpp:34
#define STORM_LOG_ASSERT(cond, message)
Definition macros.h:11
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:30
LabParser.cpp.