Skip to content

Commit

Permalink
[NF] Create equations for complex bindings.
Browse files Browse the repository at this point in the history
Belonging to [master]:
  - OpenModelica/OMCompiler#2305
  • Loading branch information
perost authored and OpenModelica-Hudson committed Mar 22, 2018
1 parent fb72969 commit f103a0d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
10 changes: 10 additions & 0 deletions Compiler/NFFrontEnd/NFExpression.mo
Expand Up @@ -2580,6 +2580,16 @@ public
end match;
end isInteger;

function isRecord
input Expression exp;
output Boolean isRecord;
algorithm
isRecord := match exp
case RECORD() then true;
else false;
end match;
end isRecord;

function fillType
input Type ty;
input Expression fillExp;
Expand Down
21 changes: 20 additions & 1 deletion Compiler/NFFrontEnd/NFFlatten.mo
Expand Up @@ -215,7 +215,7 @@ algorithm
(vars, sections) := match cls
case Class.INSTANCED_BUILTIN()
then flattenSimpleComponent(comp_node, c, vis, cls.attributes, prefix, vars, sections);
else flattenComplexComponent(comp_node, cls, ty, vis, prefix, vars, sections);
else flattenComplexComponent(comp_node, c, cls, ty, vis, prefix, vars, sections);
end match;
then
();
Expand Down Expand Up @@ -283,6 +283,7 @@ end flattenTypeAttribute;

function flattenComplexComponent
input InstNode node;
input Component comp;
input Class cls;
input Type ty;
input Visibility visibility;
Expand All @@ -292,12 +293,30 @@ function flattenComplexComponent
protected
list<Dimension> dims;
ComponentRef name;
Binding binding;
Expression binding_exp;
Equation eq;
algorithm
dims := Type.arrayDims(ty);
name := ComponentRef.prefixCref(node, ty, {}, prefix);

// Flatten the class directly if the component is a scalar, otherwise scalarize it.
if listEmpty(dims) then
binding := Component.getBinding(comp);

if Binding.isBound(binding) then
binding_exp := Binding.getTypedExp(binding);

if not Expression.isRecord(binding_exp) then
eq := Equation.EQUALITY(Expression.CREF(ty, name), binding_exp, ty,
ElementSource.createElementSource(InstNode.info(node)));
sections := Sections.prependEquation(eq, sections);
binding := Binding.UNBOUND();
else
// TODO: Split record expressions and pass them to flattenClass.
end if;
end if;

(vars, sections) := flattenClass(cls, name, visibility, vars, sections);
else
(vars, sections) := flattenArray(cls, dims, name, visibility, vars, sections);
Expand Down

0 comments on commit f103a0d

Please sign in to comment.