Skip to content

Commit

Permalink
Fix #6188 (#7504)
Browse files Browse the repository at this point in the history
- Propagate binding equations on redeclared components.
  • Loading branch information
perost committed May 28, 2021
1 parent 6865347 commit b7d5bf7
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 7 deletions.
29 changes: 25 additions & 4 deletions OMCompiler/Compiler/NFFrontEnd/NFInst.mo
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,7 @@ algorithm
inst_cls as Class.EXPANDED_CLASS(elements = cls_tree) := InstNode.getClass(node);

// Fetch modification on the class definition (for class extends).
mod := instElementModifier(InstNode.definition(node), par);
mod := instElementModifier(InstNode.definition(node), node, par);
mod := Modifier.propagate(mod, node, par);
// Merge with any outer modifications.
outer_mod := Modifier.propagate(cls.modifier, node, par);
Expand Down Expand Up @@ -846,7 +846,7 @@ algorithm
Class.EXPANDED_DERIVED(baseClass = base_node) := InstNode.getClass(node);

// Merge outer modifiers and attributes.
mod := instElementModifier(InstNode.definition(node), InstNode.rootParent(node));
mod := instElementModifier(InstNode.definition(node), node, InstNode.rootParent(node));
mod := Modifier.propagate(mod, node, par);
outer_mod := Modifier.propagate(cls.modifier, node, par);
outer_mod := Modifier.merge(outerMod, outer_mod);
Expand Down Expand Up @@ -881,7 +881,7 @@ algorithm
updateComponentType(parent, node);
cls_tree := Class.classTree(InstNode.getClass(node));

mod := instElementModifier(InstNode.definition(node), InstNode.parent(node));
mod := instElementModifier(InstNode.definition(node), node, InstNode.parent(node));
outer_mod := Modifier.merge(outerMod, cls.modifier);
mod := Modifier.merge(outer_mod, mod);
applyModifier(mod, cls_tree, InstNode.name(node));
Expand Down Expand Up @@ -1487,7 +1487,7 @@ algorithm

case SCode.COMPONENT(info = info)
algorithm
mod := instElementModifier(component, parent);
mod := instElementModifier(component, node, parent);
mod := Modifier.merge(mod, innerMod);
mod := Modifier.merge(outerMod, mod);
checkOuterComponentMod(mod, component, node);
Expand Down Expand Up @@ -1546,13 +1546,15 @@ end instComponentDef;

function instElementModifier
input SCode.Element element;
input InstNode component;
input InstNode parent;
output Modifier mod;
protected
Modifier cc_mod;
algorithm
cc_mod := instConstrainingMod(element, parent);
mod := Modifier.fromElement(element, parent);
mod := propagateRedeclaredMod(mod, component);
mod := Modifier.merge(mod, cc_mod);
end instElementModifier;

Expand All @@ -1577,6 +1579,25 @@ algorithm
end match;
end instConstrainingMod;

function propagateRedeclaredMod
input Modifier mod;
input InstNode component;
output Modifier outMod;
protected
InstNode parent;
algorithm
outMod := match component
case InstNode.COMPONENT_NODE(nodeType = InstNodeType.REDECLARED_COMP(parent = parent))
algorithm
parent := InstNode.getDerivedNode(parent);
outMod := propagateRedeclaredMod(mod, parent);
then
Modifier.propagateBinding(outMod, parent, parent);

else mod;
end match;
end propagateRedeclaredMod;

function updateComponentConnectorType
input output Component.Attributes attributes;
input Restriction restriction;
Expand Down
22 changes: 19 additions & 3 deletions OMCompiler/Compiler/NFFrontEnd/NFModifier.mo
Original file line number Diff line number Diff line change
Expand Up @@ -434,9 +434,6 @@ public
input output Modifier mod;
input InstNode origin;
input InstNode parent;
protected
Integer dim_count;
list<Subscript> subs;
algorithm
() := match mod
case MODIFIER()
Expand All @@ -450,6 +447,25 @@ public
end match;
end propagate;

function propagateBinding
input output Modifier mod;
input InstNode origin;
input InstNode parent;
protected
list<Subscript> subs;
algorithm
() := match mod
case MODIFIER()
algorithm
subs := {Subscript.SPLIT_PROXY(origin, parent)};
mod.binding := Binding.propagate(mod.binding, subs);
then
();

else ();
end match;
end propagateBinding;

function propagateSubMod
input String name;
input output Modifier submod;
Expand Down
1 change: 1 addition & 0 deletions testsuite/flattening/modelica/scodeinst/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,7 @@ RedeclareMod4.mo \
RedeclareMod5.mo \
RedeclareMod6.mo \
RedeclareMod7.mo \
RedeclareMod8.mo \
redeclare10.mo \
redeclare11.mo \
redeclare12.mo \
Expand Down
33 changes: 33 additions & 0 deletions testsuite/flattening/modelica/scodeinst/RedeclareMod8.mo
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// name: RedeclareMod8
// keywords:
// status: correct
// cflags: -d=newInst
//

record A
Real x;
end A;

model PB
replaceable parameter A a;
end PB;

model B
extends PB;
end B;

model C
replaceable parameter A[1] na;
replaceable B[1] nb;
end C;

model RedeclareMod8
C c(nb(redeclare A a = c.na));
end RedeclareMod8;

// Result:
// class RedeclareMod8
// parameter Real c.na[1].x;
// parameter Real c.nb[1].a.x = c.na[1].x;
// end RedeclareMod8;
// endResult

0 comments on commit b7d5bf7

Please sign in to comment.