Skip to content

Commit

Permalink
Delete loop connections (#10195)
Browse files Browse the repository at this point in the history
* delete connection in loops

* added test cases for deleting loop connections

---------

Co-authored-by: rahulp13 <rahulp13@users.noreply.github.com>
  • Loading branch information
rahulp13 and rahulp13 committed Mar 21, 2023
1 parent dfed337 commit e243033
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 6 deletions.
13 changes: 12 additions & 1 deletion OMCompiler/Compiler/Script/Interactive.mo
Expand Up @@ -9553,7 +9553,8 @@ protected function deleteEquationInEqlist
algorithm
outAbsynEquationItemLst := match (inAbsynEquationItemLst1,inComponentRef2,inComponentRef3)
local
list<Absyn.EquationItem> res,xs;
list<Absyn.EquationItem> res,xs,loopRes,forEqList;
Absyn.ForIterators forIterator;
Absyn.ComponentRef cn1,cn2,c1,c2;
Absyn.EquationItem x;

Expand All @@ -9563,6 +9564,16 @@ algorithm
AbsynUtil.crefEqual(c1,cn1) and AbsynUtil.crefEqual(c2,cn2)
then
deleteEquationInEqlist(xs, c1, c2);
case ((Absyn.EQUATIONITEM(equation_ = Absyn.EQ_FOR(forEquations = forEqList, iterators = forIterator)) :: xs),c1,c2)
equation
res = deleteEquationInEqlist(xs, c1, c2);
loopRes = deleteEquationInEqlist(forEqList, c1, c2);

if listLength(loopRes) > 0 then
loopRes = { Absyn.EQUATIONITEM(Absyn.EQ_FOR(forIterator, loopRes), NONE(), AbsynUtil.dummyInfo) };
end if;
then
listAppend(loopRes, res);
case ((x :: xs),c1,c2)
equation
res = deleteEquationInEqlist(xs, c1, c2);
Expand Down
84 changes: 79 additions & 5 deletions testsuite/openmodelica/interactive-API/DeleteConnection.mos
Expand Up @@ -3,17 +3,45 @@
// cflags: -d=-newInst

loadString("
model M
equation
connect(c1[1],c2);
connect(c1,c2);
end M;
model M
equation
connect(c1[1],c2);
connect(c1,c2);
end M;
");
deleteConnection(c1[1],c2,M);
list();
deleteConnection(c1,c2,M);
list();

deleteClass(M); getErrorString();

loadString("
model M
equation
connect(c1[1],c2);
for i in 1:n-1 loop
connect(c3[i],c4[i+1]);
for j in n*2:n loop
connect(c5[j],c6[i+1]);
end for;
connect(c2[i],c3[i+1]);
end for;
connect(c1,c2);
end M;
");
deleteConnection(c1[1],c2,M);
list();
deleteConnection(c3[i],c4[i+1],M);
list();
deleteConnection(c5[j],c6[i+1],M);
list();
deleteConnection(c1,c2,M);
list();
deleteConnection(c2[i],c3[i + 1],M);
list();


// Result:
// true
// Ok
Expand All @@ -26,4 +54,50 @@ list();
// equation
//
// end M;"
// true
// ""
// true
// Ok
// "model M
// equation
// for i in 1:n - 1 loop
// connect(c3[i], c4[i + 1]);
// for j in n*2:n loop
// connect(c5[j], c6[i + 1]);
// end for;
// connect(c2[i], c3[i + 1]);
// end for;
// connect(c1, c2);
// end M;"
// Ok
// "model M
// equation
// for i in 1:n - 1 loop
// for j in n*2:n loop
// connect(c5[j], c6[i + 1]);
// end for;
// connect(c2[i], c3[i + 1]);
// end for;
// connect(c1, c2);
// end M;"
// Ok
// "model M
// equation
// for i in 1:n - 1 loop
// connect(c2[i], c3[i + 1]);
// end for;
// connect(c1, c2);
// end M;"
// Ok
// "model M
// equation
// for i in 1:n - 1 loop
// connect(c2[i], c3[i + 1]);
// end for;
// end M;"
// Ok
// "model M
// equation
//
// end M;"
// endResult

0 comments on commit e243033

Please sign in to comment.