Skip to content

Commit d87d488

Browse files
author
vruge
committed
improved simplifyBinaryAddConstants
1 parent 5c5b56b commit d87d488

File tree

1 file changed

+11
-26
lines changed

1 file changed

+11
-26
lines changed

Compiler/FrontEnd/ExpressionSimplify.mo

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2492,7 +2492,6 @@ algorithm
24922492
list<DAE.Exp> e_lst,const_es1,notconst_es1,const_es1_1;
24932493
DAE.Exp res,e,e1,e2,res1,res2;
24942494
Type tp;
2495-
DAE.Operator op;
24962495

24972496
// e1 * e2
24982497
case ((e as DAE.BINARY(operator = DAE.MUL())))
@@ -2516,9 +2515,8 @@ algorithm
25162515
//e_lst_1 = List.map(e_lst,simplify2);
25172516
(const_es1, notconst_es1) =
25182517
List.splitOnTrue(e_lst, Expression.isConstValue);
2519-
if not listEmpty(notconst_es1) then
2520-
const_es1_1 = simplifyBinaryAddConstants(const_es1);
2521-
res1 = Expression.makeSum1(const_es1_1);
2518+
if not listEmpty(const_es1) then
2519+
res1 = simplifyBinaryAddConstants(const_es1);
25222520
res2 = Expression.makeSum1(notconst_es1); // Cannot simplify this, if const_es1_1 empty => infinite recursion.
25232521
res = Expression.expAdd(res1, res2);
25242522
else
@@ -2593,31 +2591,18 @@ protected function simplifyBinaryAddConstants
25932591
"author: PA
25942592
Adds all expressions in the list, given that they are constant."
25952593
input list<DAE.Exp> inExpLst;
2596-
output list<DAE.Exp> outExpLst;
2594+
output DAE.Exp outExp = DAE.RCONST(0.0);
2595+
protected
2596+
Type tp;
2597+
list<DAE.Exp> es;
25972598
algorithm
2598-
outExpLst := matchcontinue (inExpLst)
2599-
local
2600-
DAE.Exp e,e_1,e1;
2601-
list<DAE.Exp> es;
2602-
2603-
case ({}) then {};
2604-
2605-
case ({e}) then {e};
2599+
outExp :: es := inExpLst;
2600+
tp := Expression.typeof(outExp);
26062601

2607-
case ((e1 :: es))
2608-
equation
2609-
{e} = simplifyBinaryAddConstants(es);
2610-
e_1 = simplifyBinaryConst(DAE.ADD(DAE.T_REAL_DEFAULT), e1, e);
2611-
then
2612-
{e_1};
2602+
for e in es loop
2603+
outExp := simplifyBinaryConst(DAE.ADD(tp), outExp, e);
2604+
end for;
26132605

2614-
else
2615-
equation
2616-
true = Flags.isSet(Flags.FAILTRACE);
2617-
Debug.trace("- ExpressionSimplify.simplifyBinaryAddConstants failed\n");
2618-
then
2619-
fail();
2620-
end matchcontinue;
26212606
end simplifyBinaryAddConstants;
26222607

26232608
protected function simplifyBinaryMulConstants

0 commit comments

Comments
 (0)