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

Commit 3153fe6

Browse files
hkielOpenModelica-Hudson
authored andcommitted
make SimCodeUtil.createAllDiffedSimVars tail recursive
fix ticket:4534
1 parent fee2c22 commit 3153fe6

File tree

1 file changed

+44
-36
lines changed

1 file changed

+44
-36
lines changed

Compiler/SimCode/SimCodeUtil.mo

Lines changed: 44 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4889,7 +4889,7 @@ protected function createAllDiffedSimVars "author: wbraun"
48894889
input list<SimCodeVar.SimVar> iVars;
48904890
output list<SimCodeVar.SimVar> outVars;
48914891
algorithm
4892-
outVars := matchcontinue(inVars, inCref, inAllVars, inIndex, inMatrixName, iVars)
4892+
outVars := match(inVars, inCref, inAllVars, inIndex, inMatrixName, iVars)
48934893
local
48944894
BackendDAE.Var v1;
48954895
SimCodeVar.SimVar r1;
@@ -4899,51 +4899,59 @@ algorithm
48994899
Boolean isProtected;
49004900
Boolean hideResult = false;
49014901
Integer index;
4902+
BackendDAE.VarKind varkind;
4903+
4904+
case({}, _, _, _, _, _) then listReverse(iVars);
49024905

4903-
case({}, _, _, _, _, _)
4904-
then listReverse(iVars);
49054906
// skip for dicrete variable
49064907
case(BackendDAE.VAR(varKind=BackendDAE.DISCRETE())::restVar, cref, _, _, _, _) equation
49074908
then
49084909
createAllDiffedSimVars(restVar, cref, inAllVars, inIndex, inMatrixName, iVars);
49094910

4910-
case(BackendDAE.VAR(varName=currVar, varKind=BackendDAE.STATE(), values = dae_var_attr)::restVar, cref, _, _, _, _) equation
4911-
BackendVariable.getVarSingle(currVar, inAllVars);
4912-
currVar = ComponentReference.crefPrefixDer(currVar);
4913-
derivedCref = Differentiate.createDifferentiatedCrefName(currVar, cref, inMatrixName);
4914-
isProtected = getProtected(dae_var_attr);
4915-
r1 = SimCodeVar.SIMVAR(derivedCref, BackendDAE.STATE_DER(), "", "", "", inIndex, NONE(), NONE(), NONE(), NONE(), false, DAE.T_REAL_DEFAULT, false, NONE(), SimCodeVar.NOALIAS(), DAE.emptyElementSource, SimCodeVar.NONECAUS(), NONE(), {}, false, isProtected, hideResult, NONE());
4916-
then
4917-
createAllDiffedSimVars(restVar, cref, inAllVars, inIndex+1, inMatrixName, r1::iVars);
4918-
4919-
case(BackendDAE.VAR(varName=currVar, values = dae_var_attr)::restVar, cref, _, _, _, _) equation
4920-
BackendVariable.getVarSingle(currVar, inAllVars);
4921-
derivedCref = Differentiate.createDifferentiatedCrefName(currVar, cref, inMatrixName);
4922-
isProtected = getProtected(dae_var_attr);
4923-
r1 = SimCodeVar.SIMVAR(derivedCref, BackendDAE.STATE_DER(), "", "", "", inIndex, NONE(), NONE(), NONE(), NONE(), false, DAE.T_REAL_DEFAULT, false, NONE(), SimCodeVar.NOALIAS(), DAE.emptyElementSource, SimCodeVar.NONECAUS(), NONE(), {}, false, isProtected, hideResult, NONE());
4924-
then
4925-
createAllDiffedSimVars(restVar, cref, inAllVars, inIndex+1, inMatrixName, r1::iVars);
4926-
4927-
case(BackendDAE.VAR(varName=currVar, varKind=BackendDAE.STATE(), values = dae_var_attr)::restVar, cref, _, _, _, _) equation
4928-
currVar = ComponentReference.crefPrefixDer(currVar);
4929-
derivedCref = Differentiate.createDifferentiatedCrefName(currVar, cref, inMatrixName);
4930-
isProtected = getProtected(dae_var_attr);
4931-
r1 = SimCodeVar.SIMVAR(derivedCref, BackendDAE.VARIABLE(), "", "", "", -1, NONE(), NONE(), NONE(), NONE(), false, DAE.T_REAL_DEFAULT, false, NONE(), SimCodeVar.NOALIAS(), DAE.emptyElementSource, SimCodeVar.NONECAUS(), NONE(), {}, false, isProtected, hideResult, NONE());
4932-
then
4933-
createAllDiffedSimVars(restVar, cref, inAllVars, inIndex, inMatrixName, r1::iVars);
4934-
4935-
case(BackendDAE.VAR(varName=currVar, values = dae_var_attr)::restVar, cref, _, _, _, _) equation
4936-
derivedCref = Differentiate.createDifferentiatedCrefName(currVar, cref, inMatrixName);
4937-
isProtected = getProtected(dae_var_attr);
4938-
r1 = SimCodeVar.SIMVAR(derivedCref, BackendDAE.VARIABLE(), "", "", "", -1, NONE(), NONE(), NONE(), NONE(), false, DAE.T_REAL_DEFAULT, false, NONE(), SimCodeVar.NOALIAS(), DAE.emptyElementSource, SimCodeVar.NONECAUS(), NONE(), {}, false, isProtected, hideResult, NONE());
4939-
then
4940-
createAllDiffedSimVars(restVar, cref, inAllVars, inIndex, inMatrixName, r1::iVars);
4941-
4911+
case(BackendDAE.VAR(varName=currVar, varKind=varkind, values = dae_var_attr)::restVar, cref, _, index, _, _) algorithm
4912+
try
4913+
BackendVariable.getVarSingle(currVar, inAllVars);
4914+
r1 := match (varkind)
4915+
case BackendDAE.STATE()
4916+
equation
4917+
currVar = ComponentReference.crefPrefixDer(currVar);
4918+
derivedCref = Differentiate.createDifferentiatedCrefName(currVar, cref, inMatrixName);
4919+
isProtected = getProtected(dae_var_attr);
4920+
index = index + 1;
4921+
then
4922+
SimCodeVar.SIMVAR(derivedCref, BackendDAE.STATE_DER(), "", "", "", inIndex, NONE(), NONE(), NONE(), NONE(), false, DAE.T_REAL_DEFAULT, false, NONE(), SimCodeVar.NOALIAS(), DAE.emptyElementSource, SimCodeVar.NONECAUS(), NONE(), {}, false, isProtected, hideResult, NONE());
4923+
else
4924+
equation
4925+
derivedCref = Differentiate.createDifferentiatedCrefName(currVar, cref, inMatrixName);
4926+
isProtected = getProtected(dae_var_attr);
4927+
index = index + 1;
4928+
then
4929+
SimCodeVar.SIMVAR(derivedCref, BackendDAE.STATE_DER(), "", "", "", inIndex, NONE(), NONE(), NONE(), NONE(), false, DAE.T_REAL_DEFAULT, false, NONE(), SimCodeVar.NOALIAS(), DAE.emptyElementSource, SimCodeVar.NONECAUS(), NONE(), {}, false, isProtected, hideResult, NONE());
4930+
end match;
4931+
else
4932+
r1 := match (varkind)
4933+
case BackendDAE.STATE()
4934+
equation
4935+
currVar = ComponentReference.crefPrefixDer(currVar);
4936+
derivedCref = Differentiate.createDifferentiatedCrefName(currVar, cref, inMatrixName);
4937+
isProtected = getProtected(dae_var_attr);
4938+
then
4939+
SimCodeVar.SIMVAR(derivedCref, BackendDAE.VARIABLE(), "", "", "", -1, NONE(), NONE(), NONE(), NONE(), false, DAE.T_REAL_DEFAULT, false, NONE(), SimCodeVar.NOALIAS(), DAE.emptyElementSource, SimCodeVar.NONECAUS(), NONE(), {}, false, isProtected, hideResult, NONE());
4940+
else
4941+
equation
4942+
derivedCref = Differentiate.createDifferentiatedCrefName(currVar, cref, inMatrixName);
4943+
isProtected = getProtected(dae_var_attr);
4944+
then
4945+
SimCodeVar.SIMVAR(derivedCref, BackendDAE.VARIABLE(), "", "", "", -1, NONE(), NONE(), NONE(), NONE(), false, DAE.T_REAL_DEFAULT, false, NONE(), SimCodeVar.NOALIAS(), DAE.emptyElementSource, SimCodeVar.NONECAUS(), NONE(), {}, false, isProtected, hideResult, NONE());
4946+
end match;
4947+
end try;
4948+
then
4949+
createAllDiffedSimVars(restVar, cref, inAllVars, index, inMatrixName, r1::iVars);
49424950
else
49434951
equation
49444952
Error.addInternalError("function createAllDiffedSimVars failed", sourceInfo());
49454953
then fail();
4946-
end matchcontinue;
4954+
end match;
49474955
end createAllDiffedSimVars;
49484956

49494957
protected function collectAllJacobianEquations

0 commit comments

Comments
 (0)