Skip to content

Commit

Permalink
[NF] Generate correct DAE for tuple assignments.
Browse files Browse the repository at this point in the history
Belonging to [master]:
  - OpenModelica/OMCompiler#2167
  • Loading branch information
perost authored and OpenModelica-Hudson committed Feb 6, 2018
1 parent 4b2df5a commit c4493da
Showing 1 changed file with 53 additions and 7 deletions.
60 changes: 53 additions & 7 deletions Compiler/NFFrontEnd/NFConvertDAE.mo
Expand Up @@ -661,13 +661,7 @@ algorithm
DAE.Type ty;
list<DAE.Statement> body;

case Statement.ASSIGNMENT()
algorithm
ty := Type.toDAE(Expression.typeOf(stmt.lhs));
e1 := Expression.toDAE(stmt.lhs);
e2 := Expression.toDAE(stmt.rhs);
then
DAE.Statement.STMT_ASSIGN(ty, e1, e2, stmt.source);
case Statement.ASSIGNMENT() then convertAssignment(stmt);

case Statement.FUNCTION_ARRAY_INIT()
algorithm
Expand Down Expand Up @@ -712,6 +706,58 @@ algorithm
end match;
end convertStatement;

function convertAssignment
input Statement stmt;
output DAE.Statement daeStmt;
protected
Expression lhs, rhs;
DAE.ElementSource src;
Type ty;
DAE.Type dty;
DAE.Exp dlhs, drhs;
list<Expression> expl;
algorithm
Statement.ASSIGNMENT(lhs, rhs, src) := stmt;
ty := Expression.typeOf(lhs);

if Type.isTuple(ty) then
Expression.TUPLE(elements = expl) := lhs;

daeStmt := match expl
// () := call(...) => call(...)
case {} then DAE.Statement.STMT_NORETCALL(Expression.toDAE(rhs), src);

// (lhs) := call(...) => lhs := TSUB[call(...), 1]
case {lhs}
algorithm
ty := Expression.typeOf(lhs);
dty := Type.toDAE(ty);
dlhs := Expression.toDAE(lhs);
drhs := DAE.Exp.TSUB(Expression.toDAE(rhs), 1, dty);

if Type.isArray(ty) then
daeStmt := DAE.Statement.STMT_ASSIGN_ARR(dty, dlhs, drhs, src);
else
daeStmt := DAE.Statement.STMT_ASSIGN(dty, dlhs, drhs, src);
end if;
then
daeStmt;

else
algorithm
dty := Type.toDAE(ty);
drhs := Expression.toDAE(rhs);
then
DAE.Statement.STMT_TUPLE_ASSIGN(dty, list(Expression.toDAE(e) for e in expl), drhs, src);
end match;
else
dty := Type.toDAE(ty);
dlhs := Expression.toDAE(lhs);
drhs := Expression.toDAE(rhs);
daeStmt := DAE.Statement.STMT_ASSIGN(dty, dlhs, drhs, src);
end if;
end convertAssignment;

function convertForStatement
input Statement forStmt;
output DAE.Statement forDAE;
Expand Down

0 comments on commit c4493da

Please sign in to comment.