Skip to content
This repository was archived by the owner on May 18, 2019. It is now read-only.

Commit 69b294b

Browse files
vwaurichOpenModelica-Hudson
authored andcommitted
fix for when in algorithms
1 parent 62633fb commit 69b294b

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

Compiler/BackEnd/FindZeroCrossings.mo

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ algorithm
161161
Integer index, indexOrig, size, sizePre;
162162
BackendDAE.EquationArray equationArray;
163163
DAE.Algorithm alg_;
164-
list<DAE.Statement> stmts, preStmts;
164+
list<DAE.Statement> stmts, preStmts, allPreStmts, allStmts;
165165
HashTableExpToIndex.HashTable ht;
166166
DAE.Expand crefExpand;
167167
BackendDAE.EquationAttributes attr;
@@ -176,20 +176,27 @@ algorithm
176176
then (eqn, (equationArray, vars, eqns, index, ht));
177177

178178
// removed algorithm
179-
case (BackendDAE.ALGORITHM(size=0, alg=alg_, source=source, expand=crefExpand, attr=attr), (equationArray, vars, eqns, index, ht)) equation
180-
DAE.ALGORITHM_STMTS(statementLst=stmts) = alg_;
181-
size = -index;
182-
(stmts, preStmts, index) = encapsulateWhenConditions_Algorithms(stmts, vars, index);
183-
sizePre = listLength(preStmts);
184-
size = size+index-sizePre;
185-
186-
alg_ = DAE.ALGORITHM_STMTS(stmts);
187-
eqn = BackendDAE.ALGORITHM(size, alg_, source, crefExpand, attr);
188-
equationArray = BackendEquation.addEquation(eqn, equationArray);
179+
case (BackendDAE.ALGORITHM(size=0, alg=alg_, source=source, expand=crefExpand, attr=attr), (equationArray, vars, eqns, index, ht)) algorithm
180+
DAE.ALGORITHM_STMTS(statementLst=stmts) := alg_;
181+
size := -index;
182+
allPreStmts := {};
183+
allStmts := {};
184+
for stmt in stmts loop
185+
(stmts, preStmts, index) := encapsulateWhenConditions_Algorithms({stmt}, vars, index);
186+
allPreStmts := listAppend(preStmts,allPreStmts);
187+
allStmts := listAppend(stmts,allStmts);
188+
end for;
189+
stmts := listReverse(allStmts);
190+
sizePre := listLength(allPreStmts);
191+
size := size+index-sizePre;
192+
193+
alg_ := DAE.ALGORITHM_STMTS(stmts);
194+
eqn := BackendDAE.ALGORITHM(size, alg_, source, crefExpand, attr);
195+
equationArray := BackendEquation.addEquation(eqn, equationArray);
189196

190197
if sizePre > 0 then
191-
alg_ = DAE.ALGORITHM_STMTS(preStmts);
192-
eqn2 = BackendDAE.ALGORITHM(sizePre, alg_, source, crefExpand, attr);
198+
alg_ := DAE.ALGORITHM_STMTS(allPreStmts);
199+
eqn2 := BackendDAE.ALGORITHM(sizePre, alg_, source, crefExpand, attr);
193200
DoubleEndedList.push_front(eqns, eqn2);
194201
end if;
195202
then (eqn, (equationArray, vars, eqns, index, ht));

0 commit comments

Comments
 (0)