Skip to content

Commit

Permalink
- support tuple equations in when equations with TSUB, this is not so…
Browse files Browse the repository at this point in the history
… good see Ticket #1932

- bugfix EquationSize for WhenEquations

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@13849 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Jens Frenkel committed Nov 9, 2012
1 parent d464706 commit 2bfbbe8
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 12 deletions.
74 changes: 63 additions & 11 deletions Compiler/BackEnd/BackendDAECreate.mo
Original file line number Diff line number Diff line change
Expand Up @@ -1530,6 +1530,14 @@ algorithm
then
(eqnl,reinit);

case (DAE.EQUATION(exp = DAE.TUPLE(PR=expl),scalar = e, source = source) :: xs,_,_,_,_)
equation
(e,source,_) = Inline.inlineExp(e, (SOME(functionTree),{DAE.NORM_INLINE()}), source);
eqnl = lowerWhenTupleEqn(expl,inCond,e,source,1,iEquationLst);
(eqnl,reinit) = lowerWhenEqn2(xs,inCond, functionTree, eqnl, iReinitStatementLst);
then
(eqnl,reinit);

case (DAE.EQUATION(exp = (cre as DAE.CREF(componentRef = cr)),scalar = e, source = source) :: xs,_,_,_,_)
equation
(e,source,_) = Inline.inlineExp(e, (SOME(functionTree),{DAE.NORM_INLINE()}), source);
Expand All @@ -1544,6 +1552,14 @@ algorithm
(eqnl,reinit) = lowerWhenEqn2(xs,inCond, functionTree, BackendDAE.WHEN_EQUATION(size,BackendDAE.WHEN_EQ(inCond,cr,e,NONE()),source) :: iEquationLst, iReinitStatementLst);
then
(eqnl,reinit);

case (DAE.COMPLEX_EQUATION(lhs = DAE.TUPLE(PR=expl),rhs = e, source = source) :: xs,_,_,_,_)
equation
(e,source,_) = Inline.inlineExp(e, (SOME(functionTree),{DAE.NORM_INLINE()}), source);
eqnl = lowerWhenTupleEqn(expl,inCond,e,source,1,iEquationLst);
(eqnl,reinit) = lowerWhenEqn2(xs,inCond, functionTree, eqnl, iReinitStatementLst);
then
(eqnl,reinit);

case ((el as DAE.IF_EQUATION(condition1=expl,equations2=eqnslst,equations3=eqns, source = source)) :: xs,_,_,_,_)
equation
Expand All @@ -1568,6 +1584,14 @@ algorithm
(eqnl,reinit) = lowerWhenEqn2(xs,inCond, functionTree, BackendDAE.WHEN_EQUATION(size,BackendDAE.WHEN_EQ(inCond,cr,e,NONE()),source) :: iEquationLst, iReinitStatementLst);
then
(eqnl,reinit);

case (DAE.ARRAY_EQUATION(exp = DAE.TUPLE(PR=expl),array = e, source = source) :: xs,_,_,_,_)
equation
(e,source,_) = Inline.inlineExp(e, (SOME(functionTree),{DAE.NORM_INLINE()}), source);
eqnl = lowerWhenTupleEqn(expl,inCond,e,source,1,iEquationLst);
(eqnl,reinit) = lowerWhenEqn2(xs,inCond, functionTree, eqnl, iReinitStatementLst);
then
(eqnl,reinit);

case (DAE.ASSERT(condition=cond,message = e,level = level,source = source) :: xs,_,_,_,_)
equation
Expand Down Expand Up @@ -1618,6 +1642,30 @@ algorithm
end matchcontinue;
end lowerWhenEqn2;

protected function lowerWhenTupleEqn
input list<DAE.Exp> explst;
input DAE.Exp inCond;
input DAE.Exp e;
input DAE.ElementSource source;
input Integer i;
input list<BackendDAE.Equation> iEquationLst;
output list<BackendDAE.Equation> outEquationLst;
algorithm
outEquationLst := match(explst,inCond,e,source,i,iEquationLst)
local
DAE.ComponentRef cr;
list<DAE.Exp> rest;
Integer size;
DAE.Type ty;
case ({},_,_,_,_,_) then iEquationLst;
case (DAE.CREF(componentRef = cr,ty=ty)::rest,_,_,_,_,_)
equation
size = Expression.sizeOf(ty);
then
lowerWhenTupleEqn(rest,inCond,e,source,i+1,BackendDAE.WHEN_EQUATION(size,BackendDAE.WHEN_EQ(inCond,cr,DAE.TSUB(e,i,ty),NONE()),source) ::iEquationLst);
end match;
end lowerWhenTupleEqn;

protected function lowerWhenIfEqns2
"function: lowerWhenIfEqns
autor: Frenkel TUD 2012-11
Expand All @@ -1634,14 +1682,16 @@ algorithm
DAE.Exp e;
DAE.ElementSource source;
list<tuple<DAE.ComponentRef,tuple<DAE.Exp,DAE.ElementSource>>> rest;
Integer size;
case ({},_,_,_)
then
inEqns;
case ((cr,(e,source))::rest,_,_,_)
equation
source = DAEUtil.mergeSources(iSource,source);
size = Expression.sizeOf(ComponentReference.crefTypeConsiderSubs(cr));
then
lowerWhenIfEqns2(rest,inCond,iSource,BackendDAE.WHEN_EQUATION(1,BackendDAE.WHEN_EQ(inCond,cr,e,NONE()),source)::inEqns);
lowerWhenIfEqns2(rest,inCond,iSource,BackendDAE.WHEN_EQUATION(size,BackendDAE.WHEN_EQ(inCond,cr,e,NONE()),source)::inEqns);
end match;
end lowerWhenIfEqns2;

Expand Down Expand Up @@ -1911,6 +1961,13 @@ algorithm
then
mergeClauses(trueEqns,elseEqnsRest,res::inEquationLst);

case (BackendDAE.WHEN_EQUATION(size=size,whenEquation=BackendDAE.WHEN_EQ(condition=cond,left = cr,right=rightSide),source=source)::trueEqns, _,_)
equation
(foundEquation, elseEqnsRest) = getWhenEquationFromVariable(cr,elseEqnList);
res = BackendDAE.WHEN_EQUATION(size,BackendDAE.WHEN_EQ(cond,cr,rightSide,SOME(foundEquation)),source);
then
mergeClauses(trueEqns,elseEqnsRest,res::inEquationLst);

case ({},{},_) then inEquationLst;

else
Expand Down Expand Up @@ -1940,12 +1997,6 @@ algorithm
true = ComponentReference.crefEqualNoStringCompare(cr1,cr2);
then (eq, rest);

case (cr1,(eq2 as BackendDAE.WHEN_EQUATION(whenEquation=BackendDAE.WHEN_EQ(left=cr2)))::rest)
equation
false = ComponentReference.crefEqualNoStringCompare(cr1,cr2);
(eq,rest2) = getWhenEquationFromVariable(cr1,rest);
then (eq, eq2::rest2);

case (_,{})
equation
Error.addMessage(Error.DIFFERENT_VARIABLES_SOLVED_IN_ELSEWHEN, {});
Expand Down Expand Up @@ -2739,13 +2790,14 @@ algorithm
outVariables := matchcontinue (inEquation,inKnVariables,inVariables)
local
DAE.ComponentRef cr;
BackendDAE.Var var;
list<DAE.ComponentRef> crlst;
list<BackendDAE.Var> vars;
list<DAE.Statement> statementLst;
case (BackendDAE.WHEN_EQUATION(whenEquation = BackendDAE.WHEN_EQ(left = cr)),_,_)
equation
((var :: _),_) = BackendVariable.getVar(cr, inVariables);
var = BackendVariable.setVarKind(var,BackendDAE.DISCRETE());
then BackendVariable.addVar(var, inVariables);
(vars,_) = BackendVariable.getVar(cr, inVariables);
vars = List.map1(vars,BackendVariable.setVarKind,BackendDAE.DISCRETE());
then BackendVariable.addVars(vars, inVariables);
case (BackendDAE.ALGORITHM(alg=DAE.ALGORITHM_STMTS(statementLst = statementLst)),_,_)
then detectImplicitDiscreteAlgsStatemens(inVariables,inKnVariables,statementLst,false);
else inVariables;
Expand Down
2 changes: 1 addition & 1 deletion Compiler/BackEnd/BackendEquation.mo
Original file line number Diff line number Diff line change
Expand Up @@ -1826,7 +1826,7 @@ algorithm
size;
case BackendDAE.SOLVED_EQUATION(source=_) then 1;
case BackendDAE.RESIDUAL_EQUATION(source=_) then 1;
case BackendDAE.WHEN_EQUATION(size=size) then 1;
case BackendDAE.WHEN_EQUATION(size=size) then size;
case BackendDAE.ALGORITHM(size=size) then size;
case BackendDAE.COMPLEX_EQUATION(size=size) then size;
case BackendDAE.IF_EQUATION(eqnsfalse=eqnsfalse)
Expand Down

0 comments on commit 2bfbbe8

Please sign in to comment.