Skip to content

Commit

Permalink
Fix for #2668:
Browse files Browse the repository at this point in the history
- Fixed simplification rule for matrix +/- array so that it doesn't swap lhs and rhs.
- Some optimizations for ExpressionSimplify.


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@20224 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
perost committed Apr 22, 2014
1 parent 7d6b0fb commit bfefaaa
Show file tree
Hide file tree
Showing 2 changed files with 137 additions and 249 deletions.
54 changes: 43 additions & 11 deletions Compiler/FrontEnd/Expression.mo
Expand Up @@ -6619,10 +6619,7 @@ algorithm

case (DAE.ARRAY(array = ae),_) then isConstWorkList(ae,true);

case (DAE.MATRIX(matrix = matrix),_)
equation
res = List.fold(matrix,isConstWorkList,true);
then res;
case (DAE.MATRIX(matrix = matrix),_) then isConstWorkListList(matrix, true);

case (DAE.RANGE(start=e1,step=NONE(),stop=e2),_) then isConstWork(e1,isConstWork(e2,true));

Expand Down Expand Up @@ -6673,14 +6670,8 @@ algorithm
case (DAE.BCONST(bool = _),_) then true;
case (DAE.SCONST(string = _),_) then true;
case (DAE.ENUM_LITERAL(name = _),_) then true;

case (DAE.ARRAY(array = ae),_) then isConstValueWorkList(ae,true);

case (DAE.MATRIX(matrix = matrix),_)
equation
res = List.fold(matrix,isConstValueWorkList,true);
then res;

case (DAE.MATRIX(matrix = matrix),_) then isConstValueWorkListList(matrix, true);
else false;

end match;
Expand Down Expand Up @@ -6709,6 +6700,22 @@ algorithm
end match;
end isConstWorkList;

protected function isConstWorkListList
input list<list<DAE.Exp>> inExps;
input Boolean inIsConst;
output Boolean outIsConst;
algorithm
outIsConst := match(inExps, inIsConst)
local
list<DAE.Exp> e;
list<list<DAE.Exp>> exps;

case (_, false) then false;
case (e :: exps, _) then isConstWorkListList(exps, isConstWorkList(e, true));
else false;
end match;
end isConstWorkListList;

public function isConstValueWorkList
"Returns true if a list of expressions is a constant value"
input list<DAE.Exp> inExps;
Expand All @@ -6724,6 +6731,22 @@ algorithm
end match;
end isConstValueWorkList;

protected function isConstValueWorkListList
input list<list<DAE.Exp>> inExps;
input Boolean inIsConst;
output Boolean outIsConst;
algorithm
outIsConst := match(inExps, inIsConst)
local
list<DAE.Exp> e;
list<list<DAE.Exp>> exps;

case (_, false) then false;
case (e :: exps, _) then isConstValueWorkListList(exps, isConstWorkList(e, true));
else false;
end match;
end isConstValueWorkListList;

public function isNotConst
"author: PA
Check if expression is not constant."
Expand Down Expand Up @@ -10163,4 +10186,13 @@ algorithm
end matchcontinue;
end replaceDerOpInExpTraverser;

public function makeBinaryExp
input DAE.Exp inLhs;
input DAE.Operator inOp;
input DAE.Exp inRhs;
output DAE.Exp outExp;
algorithm
outExp := DAE.BINARY(inLhs, inOp, inRhs);
end makeBinaryExp;

end Expression;

0 comments on commit bfefaaa

Please sign in to comment.