Skip to content

Commit

Permalink
- Inline.mo: splitt function inlineEqOpt in two functions (inlineEq,i…
Browse files Browse the repository at this point in the history
…nlineEqOpt)

- Expression.mo: add functions traversingDerAndComponentRefFinder, expHasDerCref, traversingexpHasDerCref

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@11991 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Jens Frenkel committed Jun 5, 2012
1 parent 70ec769 commit 9c77c45
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 19 deletions.
76 changes: 76 additions & 0 deletions Compiler/FrontEnd/Expression.mo
Expand Up @@ -4567,6 +4567,40 @@ algorithm
end matchcontinue;
end traversingComponentRefFinder;

public function traversingDerAndComponentRefFinder "
Author: Frenkel TUD 2012-06
Exp traverser that Union the current ComponentRef with list if it is already there.
Returns a list containing, unique, all componentRef in an Expression and a second list
containing all componentRef from a der function."
input tuple<DAE.Exp, tuple<list<ComponentRef>,list<ComponentRef>>> inExp;
output tuple<DAE.Exp, tuple<list<ComponentRef>,list<ComponentRef>>> outExp;
algorithm
outExp := matchcontinue(inExp)
local
list<ComponentRef> crefs,dcrefs;
ComponentRef cr;
Type ty;
DAE.Exp e;

case((e as DAE.CREF(cr,ty), (crefs,dcrefs)))
equation
crefs = List.unionEltOnTrue(cr,crefs,ComponentReference.crefEqual);
// e = makeCrefExp(cr,ty);
then
((e, (crefs,dcrefs) ));

case((e as DAE.CALL(path = Absyn.IDENT(name = "der"),expLst={DAE.CREF(cr,ty)}), (crefs,dcrefs)))
equation
dcrefs = List.unionEltOnTrue(cr,dcrefs,ComponentReference.crefEqual);
// e = makeCrefExp(cr,ty);
then
((e, (crefs,dcrefs) ));

case(inExp) then inExp;

end matchcontinue;
end traversingDerAndComponentRefFinder;

public function expHasCref "
@author: Frenkel TUD 2011-04
returns true if the expression contains the cref"
Expand Down Expand Up @@ -4609,6 +4643,48 @@ algorithm
end matchcontinue;
end traversingexpHasCref;

public function expHasDerCref "
@author: Frenkel TUD 2012-06
returns true if the expression contains the cref in function der"
input DAE.Exp inExp;
input ComponentRef inCr;
output Boolean hasCref;
algorithm
hasCref := match(inExp,inCr)
local
Boolean b;

case(inExp,inCr)
equation
((_,(_,b))) = traverseExpTopDown(inExp, traversingexpHasDerCref, (inCr,false));
then
b;
end match;
end expHasDerCref;

public function traversingexpHasDerCref "
@author: Frenkel TUD 2012-06
Returns a true if the exp contains the componentRef in der"
input tuple<DAE.Exp, tuple<ComponentRef,Boolean>> inExp;
output tuple<DAE.Exp, Boolean, tuple<ComponentRef,Boolean>> outExp;
algorithm
outExp := matchcontinue(inExp)
local
Boolean b;
ComponentRef cr,cr1;
DAE.Exp e;

case ((e as DAE.CALL(path= Absyn.IDENT("der"),expLst={DAE.CREF(componentRef = cr1)}), (cr,false)))
equation
b = ComponentReference.crefEqualNoStringCompare(cr,cr1);
then
((e,not b,(cr,b)));

case (((e,(cr,b)))) then ((e,not b,(cr,b)));

end matchcontinue;
end traversingexpHasDerCref;

public function traverseCrefsFromExp "
Author: Frenkel TUD 2011-05, traverses all ComponentRef from an Expression."
input DAE.Exp inExp;
Expand Down
61 changes: 42 additions & 19 deletions Compiler/FrontEnd/Inline.mo
Expand Up @@ -183,65 +183,88 @@ function: inlineEqOpt
algorithm
outEquationOption := matchcontinue(inEquationOption,inElementList)
local
Functiontuple fns;
BackendDAE.Equation eqn;

case(NONE(),_) then NONE();
case(SOME(eqn),_)
equation
eqn = inlineEq(eqn,inElementList);
then
SOME(eqn);
case(_,_)
equation
Debug.fprintln(Flags.FAILTRACE,"Inline.inlineEqOpt failed");
then
fail();
end matchcontinue;
end inlineEqOpt;

public function inlineEq "
function: inlineEq
inlines function calls in equations"
input BackendDAE.Equation inEquation;
input Functiontuple fns;
output BackendDAE.Equation outEquation;
algorithm
outEquation := matchcontinue(inEquation,fns)
local
DAE.Exp e,e_1,e1,e1_1,e2,e2_1;
Integer i;
list<DAE.Exp> explst,explst_1,explst1,explst1_1,explst2,explst2_1;
DAE.ComponentRef cref;
BackendDAE.WhenEquation weq,weq_1;
DAE.ElementSource source "the origin of the element";

case(NONE(),_) then NONE();
case(SOME(BackendDAE.EQUATION(e1,e2,source)),fns)
case(BackendDAE.EQUATION(e1,e2,source),_)
equation
(e1_1,source) = inlineExp(e1,fns,source);
(e2_1,source) = inlineExp(e2,fns,source);
then
SOME(BackendDAE.EQUATION(e1_1,e2_1,source));
BackendDAE.EQUATION(e1_1,e2_1,source);

case(SOME(BackendDAE.ARRAY_EQUATION(i,explst,source)),fns)
case(BackendDAE.ARRAY_EQUATION(i,explst,source),_)
equation
(explst_1,source) = inlineExps(explst,fns,source);
then
SOME(BackendDAE.ARRAY_EQUATION(i,explst_1,source));
BackendDAE.ARRAY_EQUATION(i,explst_1,source);

case(SOME(BackendDAE.SOLVED_EQUATION(cref,e,source)),fns)
case(BackendDAE.SOLVED_EQUATION(cref,e,source),_)
equation
(e_1,source) = inlineExp(e,fns,source);
then
SOME(BackendDAE.SOLVED_EQUATION(cref,e_1,source));
BackendDAE.SOLVED_EQUATION(cref,e_1,source);

case(SOME(BackendDAE.RESIDUAL_EQUATION(e,source)),fns)
case(BackendDAE.RESIDUAL_EQUATION(e,source),_)
equation
(e_1,source) = inlineExp(e,fns,source);
then
SOME(BackendDAE.RESIDUAL_EQUATION(e_1,source));
BackendDAE.RESIDUAL_EQUATION(e_1,source);

case(SOME(BackendDAE.ALGORITHM(i,explst1,explst2,source)),fns)
case(BackendDAE.ALGORITHM(i,explst1,explst2,source),_)
equation
(explst1_1,source) = inlineExps(explst1,fns,source);
(explst2_1,source) = inlineExps(explst2,fns,source);
then
SOME(BackendDAE.ALGORITHM(i,explst1_1,explst2_1,source));
BackendDAE.ALGORITHM(i,explst1_1,explst2_1,source);

case(SOME(BackendDAE.WHEN_EQUATION(weq,source)),fns)
case(BackendDAE.WHEN_EQUATION(weq,source),_)
equation
(weq_1,source) = inlineWhenEq(weq,fns,source);
then
SOME(BackendDAE.WHEN_EQUATION(weq_1,source));
BackendDAE.WHEN_EQUATION(weq_1,source);

case(SOME(BackendDAE.COMPLEX_EQUATION(index=i,crefOrDerCref=explst,source=source)),fns)
case(BackendDAE.COMPLEX_EQUATION(index=i,crefOrDerCref=explst,source=source),_)
equation
(explst_1,source) = inlineExps(explst,fns,source);
then
SOME(BackendDAE.COMPLEX_EQUATION(i,explst_1,source));
case(_,_)
BackendDAE.COMPLEX_EQUATION(i,explst_1,source);
else
equation
Debug.fprintln(Flags.FAILTRACE,"Inline.inlineEqOpt failed");
Debug.fprintln(Flags.FAILTRACE,"Inline.inlineEq failed");
then
fail();
end matchcontinue;
end inlineEqOpt;
end inlineEq;

protected function inlineWhenEq
"function: inlineWhenEq
Expand Down

0 comments on commit 9c77c45

Please sign in to comment.