Storm
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 ;
90 if (isArrayAccess()) {
91 for (auto const& i : arrayIndexVector) {
92 result += "[" + i.toString() + "]";
93 }
94 }
95 return result;
96}
97
98bool LValue::operator<(LValue const& other) const {
99 if (isVariable()) {
100 return !other.isVariable() || variable->getExpressionVariable() < other.getVariable().getExpressionVariable();
101 } else {
102 STORM_LOG_ASSERT(isArrayAccess(), "Unhandled LValue.");
103 if (other.isVariable()) {
104 return false;
105 }
106 STORM_LOG_ASSERT(other.isArrayAccess(), "Unhandled LValue.");
107 if (getVariable().getExpressionVariable() < other.getVariable().getExpressionVariable()) {
108 return true;
109 } else if (other.getVariable().getExpressionVariable() < getVariable().getExpressionVariable()) {
110 return false;
111 } else {
112 return std::lexicographical_compare(arrayIndexVector.begin(), arrayIndexVector.end(), other.getArrayIndexVector().begin(),
113 other.getArrayIndexVector().end(), std::less<storm::expressions::Expression>());
114 }
115 }
116}
117
118bool LValue::operator==(LValue const& other) const {
119 if (getVariable().getExpressionVariable() == other.getVariable().getExpressionVariable()) {
120 if (isArrayAccess()) {
121 if (other.isArrayAccess() && arrayIndexVector.size() == other.getArrayIndexVector().size()) {
123 for (uint64_t i = 0; i < arrayIndexVector.size(); ++i) {
124 if (!checker.isSyntacticallyEqual(arrayIndexVector[i], other.getArrayIndexVector()[i])) {
125 return false;
126 }
127 }
128 return true;
129 } else {
130 return false;
131 }
132 } else {
133 STORM_LOG_ASSERT(isVariable(), "Unhandled kind of LValue");
134 return other.isVariable();
135 }
136 } else {
137 return false;
138 }
139}
140
141std::ostream& operator<<(std::ostream& stream, LValue const& lValue) {
142 stream << lValue.getName();
143 return stream;
144}
145
146} // namespace jani
147} // 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:118
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:98
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
std::ostream & operator<<(std::ostream &stream, Assignment const &assignment)
LabParser.cpp.
Definition cli.cpp:18