Skip to content

Commit

Permalink
added BackendVarTransform.replaceEquationAttributes
Browse files Browse the repository at this point in the history
  • Loading branch information
vwaurich committed May 8, 2015
1 parent 3ad6e72 commit 074dd84
Showing 1 changed file with 47 additions and 21 deletions.
68 changes: 47 additions & 21 deletions Compiler/BackEnd/BackendVarTransform.mo
Expand Up @@ -34,7 +34,7 @@ encapsulated package BackendVarTransform
package: BackendVarTransform
description: BackendVarTransform contains a Binary Tree representation of variable replacements.

RCS: $Id$
RCS: $Id: BackendVarTransform.mo 25836 2015-04-30 07:08:15Z vwaurich $

This module contain a Binary tree representation of variable replacements
along with some functions for performing replacements of variables in equations"
Expand Down Expand Up @@ -1726,6 +1726,7 @@ algorithm
(e_1,true) = replaceExp(e, repl,inFuncTypeExpExpToBooleanOption);
(e_2,_) = ExpressionSimplify.simplify(e_1);
source = DAEUtil.addSymbolicTransformationSubstitution(true,source,e,e_2);
eqAttr = replaceEquationAttributes(eqAttr,repl);
then
(BackendDAE.SOLVED_EQUATION(cr,e_2,source,eqAttr)::inAcc,true);

Expand Down Expand Up @@ -2628,7 +2629,8 @@ algorithm
end match;
end replaceBindingExp;

protected function replaceEquationAttributes
protected function replaceEquationAttributes"replaces iterCrefs in the LoopInfo.
author:Waurich TUD 05-2015"
input BackendDAE.EquationAttributes eqAttrIn;
input VariableReplacements repl;
output BackendDAE.EquationAttributes eqAttrOut;
Expand All @@ -2643,38 +2645,62 @@ algorithm
list<BackendDAE.IterCref> crefs;
case(BackendDAE.EQUATION_ATTRIBUTES(differentiated=differentiated, kind=kind,subPartitionIndex=subPartitionIndex, loopInfo=BackendDAE.LOOP(loopId=id,startIt=startIt,endIt=endIt,crefs=crefs)),_)
equation
crefs = List.map1(crefs,replaceIterationCrefs,repl);
then BackendDAE.EQUATION_ATTRIBUTES(differentiated, kind, subPartitionIndex, BackendDAE.LOOP(id,startIt,endIt,crefs));
crefs = replaceIterationCrefs(crefs,repl,{});
if listEmpty(crefs) then loopInfo = BackendDAE.NO_LOOP();
else loopInfo = BackendDAE.LOOP(id,startIt,endIt,crefs);
end if;
then BackendDAE.EQUATION_ATTRIBUTES(differentiated, kind, subPartitionIndex, loopInfo);
else
then eqAttrIn;
end matchcontinue;
end replaceEquationAttributes;

protected function replaceIterationCrefs
input BackendDAE.IterCref iterCrefIn;
protected function replaceIterationCrefs"replaces iterated crefs in the equation attributes"
input list<BackendDAE.IterCref> iterCrefsIn;
input VariableReplacements repl;
output BackendDAE.IterCref iterCrefOut;
input list<BackendDAE.IterCref> foldIn;
output list<BackendDAE.IterCref> iterCrefsOut;
algorithm
iterCrefOut := matchcontinue(iterCrefIn,repl)
(iterCrefsOut) := matchcontinue(iterCrefsIn,repl,foldIn)
local
BackendDAE.IterCref itCref;
list<BackendDAE.IterCref> rest,itCrefLst;
DAE.ComponentRef cref;
DAE.Exp iterator, crefExp;
DAE.Operator op;
case(BackendDAE.ITER_CREF(cref = cref, iterator=iterator),_)
equation
(crefExp,_) = replaceCref(cref,repl);
{cref} = Expression.extractCrefsFromExp(crefExp);
then BackendDAE.ITER_CREF(cref, iterator);
case(BackendDAE.ACCUM_ITER_CREF(cref = cref, op=op),_)
equation
(crefExp,_) = replaceCref(cref,repl);
case({},_,_)
then foldIn;
case(BackendDAE.ITER_CREF(cref = cref, iterator=iterator)::rest,_,_)
algorithm
(crefExp,_) := replaceCref(cref,repl);
try
{cref} := Expression.extractCrefsFromExp(crefExp);
itCref := BackendDAE.ITER_CREF(cref, iterator);
itCrefLst := itCref::foldIn;
else
itCrefLst := foldIn;
end try;
itCrefLst := replaceIterationCrefs(rest,repl,itCrefLst);
then itCrefLst;
case(BackendDAE.ACCUM_ITER_CREF(cref = cref, op=op)::rest,_,_)
algorithm
(crefExp,_) := replaceCref(cref,repl);
if Expression.isNegativeUnary(crefExp) then
op = negateOperator(op);
op := negateOperator(op);
end if;
{cref} = Expression.extractCrefsFromExp(crefExp);
then BackendDAE.ACCUM_ITER_CREF(cref, op);
else
then iterCrefIn;
try
{cref} := Expression.extractCrefsFromExp(crefExp);
itCref := BackendDAE.ACCUM_ITER_CREF(cref, op);
itCrefLst := itCref::foldIn;
else
itCrefLst := foldIn;
end try;
itCrefLst := replaceIterationCrefs(rest,repl,itCrefLst);
then itCrefLst;
case(_::rest,_,_)
algorithm
itCrefLst := replaceIterationCrefs(rest,repl,foldIn);
then itCrefLst;
end matchcontinue;
end replaceIterationCrefs;

Expand Down

0 comments on commit 074dd84

Please sign in to comment.