Skip to content

Commit

Permalink
[NF] Propagate record bindings more.
Browse files Browse the repository at this point in the history
- Propagate record bindings to records in records.
  • Loading branch information
perost committed Oct 15, 2019
1 parent fa2931a commit be71e4e
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 3 deletions.
1 change: 0 additions & 1 deletion .CI/compliance-newinst.failures
Expand Up @@ -116,7 +116,6 @@ ModelicaCompliance.Functions.HigherOrder.Quadrature2
ModelicaCompliance.Functions.Records.RecordConstructorConstantModifiable
ModelicaCompliance.Functions.Records.RecordConstructorDefaultValue
ModelicaCompliance.Functions.Records.RecordConstructorDefaultValueDependent
ModelicaCompliance.Functions.Records.RecordConstructorWithRecordInput
ModelicaCompliance.Functions.Restrictions.FunctionAssignInput
ModelicaCompliance.Inheritance.Flattening.DuplicateInheritedNeqClasses
ModelicaCompliance.Inheritance.Restrictions.ArrayClassWithComp
Expand Down
6 changes: 4 additions & 2 deletions OMCompiler/Compiler/NFFrontEnd/NFFlatten.mo
Expand Up @@ -276,7 +276,7 @@ algorithm
vis := if InstNode.isProtected(component) then Visibility.PROTECTED else visibility;

if isComplexComponent(ty) then
(vars, sections) := flattenComplexComponent(comp_node, c, cls, ty, vis, prefix, vars, sections);
(vars, sections) := flattenComplexComponent(comp_node, c, cls, ty, vis, outerBinding, prefix, vars, sections);
else
(vars, sections) := flattenSimpleComponent(comp_node, c, vis, outerBinding,
Class.getTypeAttributes(cls), prefix, vars, sections);
Expand Down Expand Up @@ -510,6 +510,7 @@ function flattenComplexComponent
input Class cls;
input Type ty;
input Visibility visibility;
input Option<Binding> outerBinding;
input ComponentRef prefix;
input output list<Variable> vars;
input output Sections sections;
Expand All @@ -524,7 +525,7 @@ protected
Variability comp_var, binding_var;
algorithm
dims := Type.arrayDims(ty);
binding := Component.getBinding(comp);
binding := if isSome(outerBinding) then Util.getOption(outerBinding) else Component.getBinding(comp);

// Create an equation if there's a binding on a complex component.
if Binding.isExplicitlyBound(binding) then
Expand Down Expand Up @@ -828,6 +829,7 @@ algorithm
// CEVAL_BINDINGs are temporary bindings generated by the constant
// evaluation and no longer needed after flattening.
case Binding.CEVAL_BINDING() then NFBinding.EMPTY_BINDING;
case Binding.FLAT_BINDING() then binding;

case Binding.INVALID_BINDING()
algorithm
Expand Down
1 change: 1 addition & 0 deletions testsuite/flattening/modelica/scodeinst/Makefile
Expand Up @@ -703,6 +703,7 @@ RecordBinding1.mo \
RecordBinding2.mo \
RecordBinding3.mo \
RecordBinding4.mo \
RecordBinding5.mo \
RecordConstructor1.mo \
RecordConstructor2.mo \
RecordExtends1.mo \
Expand Down
46 changes: 46 additions & 0 deletions testsuite/flattening/modelica/scodeinst/RecordBinding5.mo
@@ -0,0 +1,46 @@
// name: RecordBinding5
// keywords:
// status: correct
// cflags: -d=newInst
//

record R1
Real [:, :] table;
end R1;

record R2
R1 r1_table[:];
end R2;

record R3
R2 r2_table[:];
end R3;

model RecordBinding5
parameter R1 r1(table = {{1, 2, 3}, {4, 5, 6}});
parameter R2 r2(r1_table = {r1});
parameter R3 r3(r2_table = {r2});
end RecordBinding5;

// Result:
// class RecordBinding5
// parameter Real r1.table[1,1] = 1.0;
// parameter Real r1.table[1,2] = 2.0;
// parameter Real r1.table[1,3] = 3.0;
// parameter Real r1.table[2,1] = 4.0;
// parameter Real r1.table[2,2] = 5.0;
// parameter Real r1.table[2,3] = 6.0;
// parameter Real r2.r1_table[1].table[1,1] = r1.table[1,1];
// parameter Real r2.r1_table[1].table[1,2] = r1.table[1,2];
// parameter Real r2.r1_table[1].table[1,3] = r1.table[1,3];
// parameter Real r2.r1_table[1].table[2,1] = r1.table[2,1];
// parameter Real r2.r1_table[1].table[2,2] = r1.table[2,2];
// parameter Real r2.r1_table[1].table[2,3] = r1.table[2,3];
// parameter Real r3.r2_table[1].r1_table[1].table[1,1] = r2.r1_table[1].table[1,1];
// parameter Real r3.r2_table[1].r1_table[1].table[1,2] = r2.r1_table[1].table[1,2];
// parameter Real r3.r2_table[1].r1_table[1].table[1,3] = r2.r1_table[1].table[1,3];
// parameter Real r3.r2_table[1].r1_table[1].table[2,1] = r2.r1_table[1].table[2,1];
// parameter Real r3.r2_table[1].r1_table[1].table[2,2] = r2.r1_table[1].table[2,2];
// parameter Real r3.r2_table[1].r1_table[1].table[2,3] = r2.r1_table[1].table[2,3];
// end RecordBinding5;
// endResult

0 comments on commit be71e4e

Please sign in to comment.