Skip to content

Commit

Permalink
Fix appending variables in correct order
Browse files Browse the repository at this point in the history
This fixes #3763.
  • Loading branch information
sjoelund authored and OpenModelica-Hudson committed Mar 14, 2016
1 parent b629d9d commit 6d761ce
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 26 deletions.
4 changes: 2 additions & 2 deletions Compiler/SimCode/SimCodeUtil.mo
Expand Up @@ -11585,7 +11585,7 @@ protected
list<tuple<DAE.ComponentRef, list<DAE.ComponentRef>>> spTA, spTB;
list<tuple<Integer, list<Integer>>> sparseInts;
list<SimCode.FmiUnknown> derivatives, outputs, discreteStates;
list<SimCodeVar.SimVar> varsA, varsB, varsC, clockedStates;
list<SimCodeVar.SimVar> varsA, varsB, clockedStates;
SimCode.HashTableCrefToSimVar crefSimVarHT;
list<DAE.ComponentRef> diffCrefsA, diffedCrefsA, derdiffCrefsA;
list<DAE.ComponentRef> diffCrefsB, diffedCrefsB;
Expand Down Expand Up @@ -11630,7 +11630,7 @@ algorithm
//print("-- merged matrixes CD\n");

delst := DoubleEndedList.fromList(getSimVars2Crefs(diffedCrefsB, crefSimVarHT));
DoubleEndedList.push_list_back(delst, getSimVars2Crefs(diffCrefsB, crefSimVarHT));
DoubleEndedList.push_list_front(delst, getSimVars2Crefs(diffCrefsB, crefSimVarHT));
DoubleEndedList.push_list_back(delst, getSimVars2Crefs(diffedCrefsA, crefSimVarHT));
DoubleEndedList.push_list_back(delst, getSimVars2Crefs(diffCrefsA, crefSimVarHT));
varsA := DoubleEndedList.toListAndClear(delst);
Expand Down
44 changes: 20 additions & 24 deletions Compiler/Util/DoubleEndedList.mo
Expand Up @@ -124,7 +124,7 @@ function push_list_front
input list<T> lst;
protected
Integer length=arrayGet(delst.length,1), lstLength;
list<T> work, tail={}, tmp;
list<T> work, oldHead, tmp, head;
T t;
algorithm
lstLength := listLength(lst);
Expand All @@ -133,21 +133,19 @@ algorithm
end if;
arrayUpdate(delst.length, 1, length+lstLength);
t::tmp := lst;
work := {t};
tail := work;
head := {t};
oldHead := arrayGet(delst.front, 1);
arrayUpdate(delst.front, 1, head);
for l in tmp loop
tmp := {l};
Dangerous.listSetRest(tail, tmp);
tail := tmp;
work := {l};
Dangerous.listSetRest(head, work);
head := work;
end for;
if length==0 then
arrayUpdate(delst.front, 1, work);
arrayUpdate(delst.back, 1, work);
return;
arrayUpdate(delst.back, 1, head);
else
Dangerous.listSetRest(head, oldHead);
end if;
tmp := arrayGet(delst.front,1);
Dangerous.listSetRest(tail, tmp);
arrayUpdate(delst.front, 1, work);
end push_list_front;

function push_back<T>
Expand All @@ -174,29 +172,27 @@ function push_list_back
input list<T> lst;
protected
Integer length=arrayGet(delst.length,1), lstLength;
list<T> work, tail={}, tmp;
list<T> tail={}, tmp;
T t;
algorithm
lstLength := listLength(lst);
if lstLength==0 then
return;
end if;
arrayUpdate(delst.length, 1, length+lstLength);
t::tmp := lst;
work := {t};
tail := work;
for l in tmp loop
tail := arrayGet(delst.back, 1);
t := listGet(lst, 1);
tmp := {t};
Dangerous.listSetRest(tail, tmp);
if length==0 then
arrayUpdate(delst.front, 1, tmp);
end if;
tail := tmp;
for l in listRest(lst) loop
tmp := {l};
Dangerous.listSetRest(tail, tmp);
tail := tmp;
end for;
if length==0 then
arrayUpdate(delst.front, 1, work);
arrayUpdate(delst.back, 1, work);
return;
end if;
tmp := arrayGet(delst.back,1);
Dangerous.listSetRest(tmp, tail);
arrayUpdate(delst.back, 1, tail);
end push_list_back;

Expand Down

0 comments on commit 6d761ce

Please sign in to comment.