Skip to content

Commit

Permalink
[NF] Improve modifier merging.
Browse files Browse the repository at this point in the history
- Split the modifier in redeclare modifiers into inner and outer
  modifiers, to make it possible to merge them in the correct order.
  • Loading branch information
perost committed Aug 25, 2020
1 parent 4dc6664 commit 1623955
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 9 deletions.
1 change: 1 addition & 0 deletions .CI/compliance-newinst.failures
Expand Up @@ -148,6 +148,7 @@ ModelicaCompliance.Redeclare.ConstrainingType.RedeclareConstrainingTypeClass
ModelicaCompliance.Redeclare.ConstrainingType.RedeclareConstrainingTypeComponent
ModelicaCompliance.Redeclare.ConstrainingType.RedeclareConstrainingTypeMod
ModelicaCompliance.Redeclare.ConstrainingType.RedeclareConstrainingTypeSubtype
ModelicaCompliance.Redeclare.ConstrainingType.RedeclareMod
ModelicaCompliance.Redeclare.ConstrainingType.RedeclareNonSubtypeClass
ModelicaCompliance.Redeclare.ConstrainingType.RedeclareNonSubtypeClassImpl
ModelicaCompliance.Redeclare.ConstrainingType.RedeclareNonSubtypeComponent
Expand Down
11 changes: 6 additions & 5 deletions OMCompiler/Compiler/NFFrontEnd/NFInst.mo
Expand Up @@ -1182,7 +1182,7 @@ algorithm
mod := Class.getModifier(cls);

if Modifier.isRedeclare(mod) then
Modifier.REDECLARE(element = redecl_node, mod = mod) := mod;
Modifier.REDECLARE(element = redecl_node, outerMod = mod) := mod;
cls_node := redeclareClass(redecl_node, cls_node, mod);
Mutable.update(cls_ptr, cls_node);
end if;
Expand Down Expand Up @@ -1393,7 +1393,7 @@ protected
Component comp;
SCode.Element def;
InstNode comp_node, rdcl_node;
Modifier outer_mod, cc_mod = innerMod;
Modifier outer_mod, inner_mod, cc_mod = innerMod;
SCode.Mod cc_smod;
String name;
InstNode parent;
Expand All @@ -1413,10 +1413,11 @@ algorithm

if Modifier.isRedeclare(outer_mod) then
checkOuterComponentMod(outer_mod, def, comp_node);
instComponentDef(def, Modifier.NOMOD(), Modifier.NOMOD(), NFComponent.DEFAULT_ATTR,
useBinding, comp_node, parent, instLevel, originalAttr, isRedeclared = true);

Modifier.REDECLARE(element = rdcl_node, mod = outer_mod) := outer_mod;
Modifier.REDECLARE(element = rdcl_node, innerMod = inner_mod, outerMod = outer_mod) := outer_mod;

instComponentDef(def, Modifier.NOMOD(), inner_mod, NFComponent.DEFAULT_ATTR,
useBinding, comp_node, parent, instLevel, originalAttr, isRedeclared = true);

cc_smod := SCodeUtil.getConstrainingMod(def);
if not SCodeUtil.isEmptyMod(cc_smod) then
Expand Down
9 changes: 5 additions & 4 deletions OMCompiler/Compiler/NFFrontEnd/NFModifier.mo
Expand Up @@ -144,7 +144,8 @@ uniontype Modifier
SCode.Final finalPrefix;
SCode.Each eachPrefix;
InstNode element;
Modifier mod;
Modifier innerMod;
Modifier outerMod;
end REDECLARE;

record NOMOD end NOMOD;
Expand Down Expand Up @@ -190,7 +191,7 @@ public
Inst.partialInstClass(node);
end if;
then
REDECLARE(mod.finalPrefix, mod.eachPrefix, node, NOMOD());
REDECLARE(mod.finalPrefix, mod.eachPrefix, node, NOMOD(), NOMOD());

end match;
end create;
Expand Down Expand Up @@ -418,13 +419,13 @@ public

case (REDECLARE(), MODIFIER())
algorithm
outerMod.mod := merge(outerMod.mod, innerMod);
outerMod.innerMod := merge(outerMod.innerMod, innerMod);
then
outerMod;

case (MODIFIER(), REDECLARE())
algorithm
innerMod.mod := merge(outerMod, innerMod.mod);
innerMod.outerMod := merge(outerMod, innerMod.outerMod);
then
innerMod;

Expand Down
1 change: 1 addition & 0 deletions testsuite/flattening/modelica/scodeinst/Makefile
Expand Up @@ -775,6 +775,7 @@ RedeclareMod3.mo \
RedeclareMod4.mo \
RedeclareMod5.mo \
RedeclareMod6.mo \
RedeclareMod7.mo \
redeclare10.mo \
redeclare11.mo \
redeclare12.mo \
Expand Down
24 changes: 24 additions & 0 deletions testsuite/flattening/modelica/scodeinst/RedeclareMod7.mo
@@ -0,0 +1,24 @@
// name: RedeclareMod7
// keywords:
// status: correct
// cflags: -d=newInst
//

model A
replaceable Real x;
end A;

model B
extends A(x = 2.0);
end B;

model RedeclareMod7
B b(redeclare Real x = 3.0);
end RedeclareMod7;


// Result:
// class RedeclareMod7
// Real b.x = 3.0;
// end RedeclareMod7;
// endResult

0 comments on commit 1623955

Please sign in to comment.