Skip to content

Commit

Permalink
[NF] Split record crefs in binding equations.
Browse files Browse the repository at this point in the history
  • Loading branch information
perost authored and OpenModelica-Hudson committed Oct 17, 2018
1 parent e14b054 commit 18e3271
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
20 changes: 10 additions & 10 deletions Compiler/NFFrontEnd/NFExpression.mo
Expand Up @@ -4400,34 +4400,34 @@ public
end match;
end recordElement;

function splitRecord
input Expression recordExp;
output list<Expression> recordFields;
function splitRecordCref
input Expression exp;
output Expression outExp;
algorithm
recordFields := match recordExp
outExp := match exp
local
InstNode cls;
array<InstNode> comps;
ComponentRef cr, field_cr;
Type ty;

case RECORD() then recordExp.elements;
list<Expression> fields;

case CREF(ty = Type.COMPLEX(cls = cls), cref = cr)
algorithm
comps := ClassTree.getComponents(Class.classTree(InstNode.getClass(cls)));
recordFields := {};
fields := {};

for i in arrayLength(comps):-1:1 loop
ty := InstNode.getType(comps[i]);
field_cr := ComponentRef.prefixCref(comps[i], ty, {}, cr);
recordFields := CREF(ty, field_cr) :: recordFields;
fields := CREF(ty, field_cr) :: fields;
end for;
then
recordFields;
RECORD(InstNode.scopePath(cls), exp.ty, fields);

else exp;
end match;
end splitRecord;
end splitRecordCref;

function retype
input output Expression exp;
Expand Down
2 changes: 2 additions & 0 deletions Compiler/NFFrontEnd/NFFlatten.mo
Expand Up @@ -527,6 +527,8 @@ algorithm
binding_exp := SimplifyExp.simplify(binding_exp);
end if;

binding_exp := Expression.splitRecordCref(binding_exp);

// TODO: This will probably not work so well if the binding is an array that
// contains record non-literals. In that case we should probably
// create an equation for each non-literal in the array, and pass the
Expand Down

0 comments on commit 18e3271

Please sign in to comment.