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

Commit f103a0d

Browse files
perostOpenModelica-Hudson
authored andcommitted
[NF] Create equations for complex bindings.
Belonging to [master]: - #2305
1 parent fb72969 commit f103a0d

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

Compiler/NFFrontEnd/NFExpression.mo

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2580,6 +2580,16 @@ public
25802580
end match;
25812581
end isInteger;
25822582

2583+
function isRecord
2584+
input Expression exp;
2585+
output Boolean isRecord;
2586+
algorithm
2587+
isRecord := match exp
2588+
case RECORD() then true;
2589+
else false;
2590+
end match;
2591+
end isRecord;
2592+
25832593
function fillType
25842594
input Type ty;
25852595
input Expression fillExp;

Compiler/NFFrontEnd/NFFlatten.mo

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ algorithm
215215
(vars, sections) := match cls
216216
case Class.INSTANCED_BUILTIN()
217217
then flattenSimpleComponent(comp_node, c, vis, cls.attributes, prefix, vars, sections);
218-
else flattenComplexComponent(comp_node, cls, ty, vis, prefix, vars, sections);
218+
else flattenComplexComponent(comp_node, c, cls, ty, vis, prefix, vars, sections);
219219
end match;
220220
then
221221
();
@@ -283,6 +283,7 @@ end flattenTypeAttribute;
283283

284284
function flattenComplexComponent
285285
input InstNode node;
286+
input Component comp;
286287
input Class cls;
287288
input Type ty;
288289
input Visibility visibility;
@@ -292,12 +293,30 @@ function flattenComplexComponent
292293
protected
293294
list<Dimension> dims;
294295
ComponentRef name;
296+
Binding binding;
297+
Expression binding_exp;
298+
Equation eq;
295299
algorithm
296300
dims := Type.arrayDims(ty);
297301
name := ComponentRef.prefixCref(node, ty, {}, prefix);
298302

299303
// Flatten the class directly if the component is a scalar, otherwise scalarize it.
300304
if listEmpty(dims) then
305+
binding := Component.getBinding(comp);
306+
307+
if Binding.isBound(binding) then
308+
binding_exp := Binding.getTypedExp(binding);
309+
310+
if not Expression.isRecord(binding_exp) then
311+
eq := Equation.EQUALITY(Expression.CREF(ty, name), binding_exp, ty,
312+
ElementSource.createElementSource(InstNode.info(node)));
313+
sections := Sections.prependEquation(eq, sections);
314+
binding := Binding.UNBOUND();
315+
else
316+
// TODO: Split record expressions and pass them to flattenClass.
317+
end if;
318+
end if;
319+
301320
(vars, sections) := flattenClass(cls, name, visibility, vars, sections);
302321
else
303322
(vars, sections) := flattenArray(cls, dims, name, visibility, vars, sections);

0 commit comments

Comments
 (0)