Skip to content
This repository has been archived by the owner on May 18, 2019. It is now read-only.

Commit

Permalink
Add support for inline of some if-statements
Browse files Browse the repository at this point in the history
If-statements that look like if-expressions can now be inlined.
This fixes an issue reported in ticket:4423.

Belonging to [master]:
  - #2076
  - OpenModelica/OpenModelica-testsuite#810
  • Loading branch information
sjoelund authored and OpenModelica-Hudson committed Jan 3, 2018
1 parent 70f05e5 commit 62a0b9d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Compiler/FrontEnd/DAEDump.mo
Expand Up @@ -1790,7 +1790,7 @@ public function ppStmtListStr "
Helper function to pp_stmt_str
"
input list<DAE.Statement> inAlgorithmStatementLst;
input Integer inInteger;
input Integer inInteger=0;
output String outString;
algorithm
outString:=
Expand Down
27 changes: 26 additions & 1 deletion Compiler/FrontEnd/Inline.mo
Expand Up @@ -1016,7 +1016,7 @@ algorithm
local
list<DAE.Statement> stmts;
VarTransform.VariableReplacements repl;
DAE.ComponentRef cr;
DAE.ComponentRef cr, cr1, cr2;
DAE.ElementSource source;
DAE.Exp exp, exp1, exp2;
DAE.Statement stmt;
Expand Down Expand Up @@ -1053,6 +1053,31 @@ algorithm
(repl,assertStmts) = mergeFunctionBody(stmts,iRepl,stmt::assertStmtsIn);
then
(repl,assertStmts);
// if a then x := b; else x := c; end if; => x := if a then b else c;
case (DAE.STMT_IF(exp = exp,
statementLst = {DAE.STMT_ASSIGN(exp1 = DAE.CREF(componentRef = cr1), exp = exp1)},
else_=DAE.ELSE(statementLst={DAE.STMT_ASSIGN(exp1 = DAE.CREF(componentRef = cr2), exp = exp2)}))::stmts,_,_)
guard ComponentReference.crefEqual(cr1, cr2)
equation
(exp,_) = VarTransform.replaceExp(exp,iRepl,NONE());
(exp1,_) = VarTransform.replaceExp(exp1,iRepl,NONE());
(exp2,_) = VarTransform.replaceExp(exp2,iRepl,NONE());
repl = VarTransform.addReplacementNoTransitive(iRepl,cr1,DAE.IFEXP(exp,exp1,exp2));
(repl,assertStmts) = mergeFunctionBody(stmts,repl,assertStmtsIn);
then (repl,assertStmts);

case (DAE.STMT_IF(exp = exp,
statementLst = {DAE.STMT_ASSIGN_ARR(lhs = DAE.CREF(componentRef = cr1), exp = exp1)},
else_=DAE.ELSE(statementLst={DAE.STMT_ASSIGN_ARR(lhs = DAE.CREF(componentRef = cr2), exp = exp2)}))::stmts,_,_)
guard ComponentReference.crefEqual(cr1, cr2)
equation
(exp,_) = VarTransform.replaceExp(exp,iRepl,NONE());
(exp1,_) = VarTransform.replaceExp(exp1,iRepl,NONE());
(exp2,_) = VarTransform.replaceExp(exp2,iRepl,NONE());
repl = VarTransform.addReplacementNoTransitive(iRepl,cr1,DAE.IFEXP(exp,exp1,exp2));
(repl,assertStmts) = mergeFunctionBody(stmts,repl,assertStmtsIn);
then (repl,assertStmts);

end match;
end mergeFunctionBody;

Expand Down

0 comments on commit 62a0b9d

Please sign in to comment.