Skip to content

Commit

Permalink
- fixed #2867 by fixing the calculation of adjacency rows for ASUB ex…
Browse files Browse the repository at this point in the history
…pressions

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@23216 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Willi Braun committed Nov 5, 2014
1 parent d989224 commit c4259c1
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 13 deletions.
34 changes: 27 additions & 7 deletions Compiler/BackEnd/BackendDAEUtil.mo
Expand Up @@ -2884,12 +2884,13 @@ algorithm
Boolean b;
list<DAE.Exp> explst;
Option<DAE.Exp> stepvalueopt;
Integer istart,istep,istop;
Integer istart,istep,istop, i;
list<DAE.ComponentRef> crlst;
Option<DAE.FunctionTree> ofunctionTree;
DAE.FunctionTree functionTree;
tuple<BackendDAE.Variables,list<Integer>,Option<DAE.FunctionTree>> tpl;
Integer diffindx;
String str;

case (e as DAE.LBINARY(exp1 = _),tpl)
then (e,false,tpl);
Expand All @@ -2902,6 +2903,7 @@ algorithm
then (e,false,tpl);
case (e as DAE.RANGE(ty = _),tpl)
then (e,false,tpl);

case (e as DAE.ASUB(exp = DAE.CREF(componentRef = cr), sub=explst),(vars,pa,ofunctionTree))
equation
{DAE.RANGE(start=startvalue,step=stepvalueopt,stop=stopvalue)} = ExpressionSimplify.simplifyList(explst, {});
Expand All @@ -2915,11 +2917,15 @@ algorithm
pa = incidenceRowExp1(varslst,p,pa,0);
then (e,false,(vars,pa,ofunctionTree));

// if it could not simplified take all found
case (e as DAE.ASUB(exp = e1),tpl)
case (e as DAE.ASUB(exp = e1, sub={DAE.ICONST(i)}),tpl)
equation
e1 = Expression.nthArrayExp(e1, i);
(_,tpl) = Expression.traverseExpTopDown(e1, traversingincidenceRowExpSolvableFinder, tpl);
then (e,false,tpl);
then (e, false, tpl);

// otherwise
case (e as DAE.ASUB(exp = e1),tpl)
then fail();

case (e as DAE.TSUB(exp = e1),tpl)
equation
Expand Down Expand Up @@ -3117,6 +3123,8 @@ algorithm
DAE.Exp e,e1,e2;
list<BackendDAE.Var> varslst;
Boolean b;
Integer i;
String str;

case (e as DAE.CREF(componentRef = cr),(vars,pa))
equation
Expand Down Expand Up @@ -3154,6 +3162,15 @@ algorithm
b = Flags.getConfigBool(Flags.DELAY_BREAK_LOOP) and Expression.expEqual(e1,e2);
then (inExp,not b,inTpl);

case (e as DAE.ASUB(exp = e1, sub={DAE.ICONST(i)}),(vars,pa))
equation
e1 = Expression.nthArrayExp(e1, i);
(_, (_, res)) = Expression.traverseExpTopDown(e1, traversingincidenceRowExpFinder, (vars, pa));
then (inExp, false, (vars, res));

case (e as DAE.ASUB(exp = e1),(vars,pa))
then fail();

else (inExp,true,inTpl);
end matchcontinue;
end traversingincidenceRowExpFinder;
Expand Down Expand Up @@ -5112,7 +5129,7 @@ algorithm
list<DAE.Exp> elst;
list<BackendDAE.Var> varslst;
Boolean b,bs;
Integer mark;
Integer mark,i;
array<Integer> rowmark;
BinaryTree.BinTree bt;
case (e as DAE.LUNARY(exp = e1),(vars,bs,(mark,rowmark),pa))
Expand Down Expand Up @@ -5156,11 +5173,14 @@ algorithm
(_,(vars,_,_,pa)) = Expression.traverseExpTopDown(e3, traversingadjacencyRowExpSolvableEnhancedFinder, (vars,true,(mark,rowmark),pa));
then (e,false,(vars,bs,(mark,rowmark),pa));

case (e as DAE.ASUB(exp = e1,sub=elst),(vars,bs,(mark,rowmark),pa))
case (e as DAE.ASUB(exp = e1,sub={DAE.ICONST(i)}),(vars,bs,(mark,rowmark),pa))
equation
e1 = Expression.nthArrayExp(e1, i);
(_,(vars,_,_,pa)) = Expression.traverseExpTopDown(e1, traversingadjacencyRowExpSolvableEnhancedFinder, (vars,bs,(mark,rowmark),pa));
(_,(vars,_,_,pa)) = Expression.traverseExpListTopDown(elst, traversingadjacencyRowExpSolvableEnhancedFinder, (vars,true,(mark,rowmark),pa));
then (e,false,(vars,bs,(mark,rowmark),pa));

case (e as DAE.ASUB(exp = e1,sub=elst),(vars,bs,(mark,rowmark),pa))
then fail();

case (e as DAE.CREF(componentRef = cr),(vars,bs,(mark,rowmark),pa))
equation
Expand Down
26 changes: 20 additions & 6 deletions Compiler/FrontEnd/Expression.mo
Expand Up @@ -1869,17 +1869,31 @@ public function nthArrayExp
input Integer inInteger;
output DAE.Exp outExp;
algorithm
outExp := match (inExp,inInteger)
outExp := matchcontinue (inExp,inInteger)
local
DAE.Exp e;
DAE.Exp e, e1, e2, e_1, e_2, eres;
list<DAE.Exp> expl;
Integer indx;
case (DAE.ARRAY(array = expl),indx)
Operator op;
Type ty;
case (e as DAE.BINARY(operator = op, exp1 = e1, exp2 = e2),_)
equation
e = listNth(expl, indx);
ty = typeofOp(op);
true = Types.isArray(ty, {});
e_1 = nthArrayExp(e1, inInteger);
e_2 = nthArrayExp(e2, inInteger);
eres = DAE.BINARY(e_1, op, e_2);
then
e;
end match;
eres;

case ((e as DAE.ARRAY(array = expl)),indx)
equation
e1 = listNth(expl, indx-1);
then
e1;

case (_, _) then inExp;
end matchcontinue;
end nthArrayExp;

public function expLastSubs
Expand Down

0 comments on commit c4259c1

Please sign in to comment.