@@ -1016,7 +1016,7 @@ algorithm
10161016 local
10171017 list< DAE . Statement > stmts;
10181018 VarTransform . VariableReplacements repl;
1019- DAE . ComponentRef cr;
1019+ DAE . ComponentRef cr, cr1, cr2 ;
10201020 DAE . ElementSource source;
10211021 DAE . Exp exp, exp1, exp2;
10221022 DAE . Statement stmt;
@@ -1053,6 +1053,31 @@ algorithm
10531053 (repl,assertStmts) = mergeFunctionBody(stmts,iRepl,stmt::assertStmtsIn);
10541054 then
10551055 (repl,assertStmts);
1056+ // if a then x := b; else x := c; end if; => x := if a then b else c;
1057+ case (DAE . STMT_IF (exp = exp,
1058+ statementLst = {DAE . STMT_ASSIGN (exp1 = DAE . CREF (componentRef = cr1), exp = exp1)},
1059+ else_= DAE . ELSE (statementLst= {DAE . STMT_ASSIGN (exp1 = DAE . CREF (componentRef = cr2), exp = exp2)}))::stmts,_,_)
1060+ guard ComponentReference . crefEqual(cr1, cr2)
1061+ equation
1062+ (exp,_) = VarTransform . replaceExp(exp,iRepl,NONE ());
1063+ (exp1,_) = VarTransform . replaceExp(exp1,iRepl,NONE ());
1064+ (exp2,_) = VarTransform . replaceExp(exp2,iRepl,NONE ());
1065+ repl = VarTransform . addReplacementNoTransitive(iRepl,cr1,DAE . IFEXP (exp,exp1,exp2));
1066+ (repl,assertStmts) = mergeFunctionBody(stmts,repl,assertStmtsIn);
1067+ then (repl,assertStmts);
1068+
1069+ case (DAE . STMT_IF (exp = exp,
1070+ statementLst = {DAE . STMT_ASSIGN_ARR (lhs = DAE . CREF (componentRef = cr1), exp = exp1)},
1071+ else_= DAE . ELSE (statementLst= {DAE . STMT_ASSIGN_ARR (lhs = DAE . CREF (componentRef = cr2), exp = exp2)}))::stmts,_,_)
1072+ guard ComponentReference . crefEqual(cr1, cr2)
1073+ equation
1074+ (exp,_) = VarTransform . replaceExp(exp,iRepl,NONE ());
1075+ (exp1,_) = VarTransform . replaceExp(exp1,iRepl,NONE ());
1076+ (exp2,_) = VarTransform . replaceExp(exp2,iRepl,NONE ());
1077+ repl = VarTransform . addReplacementNoTransitive(iRepl,cr1,DAE . IFEXP (exp,exp1,exp2));
1078+ (repl,assertStmts) = mergeFunctionBody(stmts,repl,assertStmtsIn);
1079+ then (repl,assertStmts);
1080+
10561081 end match;
10571082end mergeFunctionBody;
10581083
0 commit comments