Skip to content

Commit

Permalink
improved guarding for if-exp
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@21962 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Vitalij Ruge committed Aug 24, 2014
1 parent 574188a commit c0579fb
Showing 1 changed file with 32 additions and 13 deletions.
45 changes: 32 additions & 13 deletions Compiler/BackEnd/ExpressionSolve.mo
Expand Up @@ -859,25 +859,44 @@ algorithm
end matchcontinue;
end hasOnlyFactors;

protected function isCrefInIFEXP " Returns true if expression is DAE.IFEXP(f(cr)) or sign(f(cr)) for cr = incr"

protected function isCrefInIFEXP " Returns true if expression is DAE.IFEXP(f(cr)) or e.g. sign(f(cr)) for cr = incr"
input DAE.Exp e;
input DAE.ComponentRef incr;
output Boolean res;
algorithm
res := match(e,incr)
local DAE.Exp e1;

case(DAE.IFEXP(e1,_,_),_)
then Expression.expHasCref(e1, incr);
case(DAE.CALL(path = Absyn.IDENT(name = "sign"),expLst = {e1}),_)
then Expression.expHasCref(e1, incr);
case(DAE.CAST(exp =e1),_)
then isCrefInIFEXP(e1,incr);
else
then false;
end match;
res := isCrefInIFEXPwork(e, incr, false);
end isCrefInIFEXP;

protected function isCrefInIFEXPwork " helper for isCrefInIFEXP"
input DAE.Exp e;
input DAE.ComponentRef incr;
input Boolean inres;
output Boolean res;
algorithm
res := match(e,incr, inres)
local DAE.Exp e1, e2; Boolean b;

case(_,_,true) then true;
case(DAE.BINARY(e1, DAE.ADD(_),e2),_,_)
equation
b = isCrefInIFEXPwork(e1,incr, inres);
b = isCrefInIFEXPwork(e2,incr, b);
then b;
case(DAE.BINARY(e1, DAE.SUB(_),e2),_,_)
equation
b = isCrefInIFEXPwork(e1,incr, inres);
b = isCrefInIFEXPwork(e2,incr, b);
then b;
case(DAE.IFEXP(e1,_,_),_,_) then Expression.expHasCref(e1, incr);
case(DAE.CALL(path = Absyn.IDENT(name = "sign"),expLst = {e1}),_,_) then Expression.expHasCref(e1, incr);
case(DAE.CALL(path = Absyn.IDENT(name = "smooth"),expLst = {_,e1}),_,_) then isCrefInIFEXPwork(e1,incr,inres);
case(DAE.CALL(path = Absyn.IDENT(name = "semiLinear"),expLst = {e1,_,_}),_,_)then Expression.expHasCref(e1,incr);
case(DAE.CAST(exp =e1),_,_) then isCrefInIFEXPwork(e1,incr,inres);
case(_,_,_) then false;
end match;
end isCrefInIFEXPwork;

protected function isInverseCref " Returns true if expression is 1/cr for a ComponentRef cr"
input DAE.Exp e;
input DAE.ComponentRef cr;
Expand Down

0 comments on commit c0579fb

Please sign in to comment.