Skip to content

Commit

Permalink
- inline condition of when equation only once
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@12288 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Jens Frenkel committed Jul 5, 2012
1 parent eec678d commit 2caa5f5
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions Compiler/BackEnd/BackendDAECreate.mo
Expand Up @@ -123,7 +123,7 @@ algorithm
reqnarr := BackendDAEUtil.listEquation(reqns);
ieqnarr := BackendDAEUtil.listEquation(ieqns);
constrarra := listArray(constrs);
einfo := Inline.inlineEventInfo(BackendDAE.EVENT_INFO(whenclauses_1,{}),(SOME(functionTree),{DAE.NORM_INLINE()}));
einfo := BackendDAE.EVENT_INFO(whenclauses_1,{});
aliasVars := BackendDAEUtil.emptyAliasVariables();
outBackendDAE := BackendDAE.DAE(BackendDAE.EQSYSTEM(vars_1,eqnarr,NONE(),NONE(),BackendDAE.NO_MATCHING())::{},BackendDAE.SHARED(knvars,extVars,aliasVars,ieqnarr,reqnarr,constrarra,inCache,inEnv,functionTree,einfo,extObjCls,BackendDAE.SIMULATION(),{}));
BackendDAEUtil.checkBackendDAEWithErrorMsg(outBackendDAE);
Expand Down Expand Up @@ -1298,8 +1298,9 @@ algorithm
list<DAE.Element> eqnl;
DAE.Element elsePart;
String scond;
DAE.ElementSource source;

case (DAE.WHEN_EQUATION(condition = cond,equations = eqnl,elsewhen_ = NONE()),i,_,whenList)
case (DAE.WHEN_EQUATION(condition = cond,equations = eqnl,elsewhen_ = NONE(),source=source),i,_,whenList)
equation
(res,reinit) = lowerWhenEqn2(listReverse(eqnl), i, functionTree, {}, {});
equation_count = listLength(res);
Expand All @@ -1308,14 +1309,15 @@ algorithm
extra = Util.if_(hasReinit, 1, 0);
tot_count = equation_count + extra;
i_1 = i + tot_count;
(cond,source) = Inline.inlineExp(cond, (SOME(functionTree),{DAE.NORM_INLINE()}), source);
whenClauseList1 = makeWhenClauses(equation_count, cond, {});
whenClauseList2 = makeWhenClauses(extra, cond, reinit);
whenClauseList3 = listAppend(whenClauseList2, whenClauseList1);
whenClauseList4 = listAppend(whenClauseList3, whenList);
then
(res,i_1,whenClauseList4);

case (DAE.WHEN_EQUATION(condition = cond,equations = eqnl,elsewhen_ = SOME(elsePart)),i,_,whenList)
case (DAE.WHEN_EQUATION(condition = cond,equations = eqnl,elsewhen_ = SOME(elsePart),source=source),i,_,whenList)
equation
(elseEqnLst,nextWhenIndex,elseClauseList) = lowerWhenEqn(elsePart,i,functionTree,whenList);
(trueEqnLst,reinit) = lowerWhenEqn2(listReverse(eqnl), nextWhenIndex, functionTree, {}, {});
Expand All @@ -1324,6 +1326,7 @@ algorithm
hasReinit = (reinit_count > 0);
extra = Util.if_(hasReinit, 1, 0);
tot_count = equation_count + extra;
(cond,source) = Inline.inlineExp(cond, (SOME(functionTree),{DAE.NORM_INLINE()}), source);
whenClauseList1 = makeWhenClauses(equation_count, cond, {});
whenClauseList2 = makeWhenClauses(extra, cond, reinit);
whenClauseList3 = listAppend(whenClauseList2, whenClauseList1);
Expand Down Expand Up @@ -1380,6 +1383,13 @@ algorithm
then
(eqnl,reinit);

case ((DAE.ARRAY_EQUATION(exp = (cre as DAE.CREF(componentRef = cr)),array = e,source = source) :: xs),i,_,_,_)
equation
(e,source) = Inline.inlineExp(e, (SOME(functionTree),{DAE.NORM_INLINE()}), source);
(eqnl,reinit) = lowerWhenEqn2(xs, i + 1, functionTree, BackendDAE.WHEN_EQUATION(BackendDAE.WHEN_EQ(i,cr,e,NONE()),source) :: iEquationLst, iReinitStatementLst);
then
(eqnl,reinit);

case ((DAE.ASSERT(condition=cond,message = e,source = source) :: xs),i,_,_,_)
equation
(cond,source) = Inline.inlineExp(cond, (SOME(functionTree),{DAE.NORM_INLINE()}), source);
Expand All @@ -1401,14 +1411,7 @@ algorithm
(eqnl,reinit) = lowerWhenEqn2(xs, i, functionTree, iEquationLst, BackendDAE.TERMINATE(e,source) :: iReinitStatementLst);
then
(eqnl,reinit);

case ((DAE.ARRAY_EQUATION(exp = (cre as DAE.CREF(componentRef = cr)),array = e,source = source) :: xs),i,_,_,_)
equation
(e,source) = Inline.inlineExp(e, (SOME(functionTree),{DAE.NORM_INLINE()}), source);
(eqnl,reinit) = lowerWhenEqn2(xs, i + 1, functionTree, BackendDAE.WHEN_EQUATION(BackendDAE.WHEN_EQ(i,cr,e,NONE()),source) :: iEquationLst, iReinitStatementLst);
then
(eqnl,reinit);


// failure
case ((el::xs), i,_,_,_)
equation
Expand Down

0 comments on commit 2caa5f5

Please sign in to comment.