Skip to content

Commit 61571e8

Browse files
perostOpenModelica-Hudson
authored andcommitted
[NF] Merge constraining class modifiers.
- Merge modifiers from constrainedby clauses when instantiating replaceable components, instead of only doing it when actually redeclaring a component. Belonging to [master]: - OpenModelica/OMCompiler#2972 - OpenModelica/OpenModelica-testsuite#1135
1 parent 04f1061 commit 61571e8

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

Compiler/NFFrontEnd/NFInst.mo

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1324,18 +1324,18 @@ algorithm
13241324

13251325
if Modifier.isRedeclare(outer_mod) then
13261326
checkOuterComponentMod(outer_mod, def, comp_node);
1327-
instComponentDef(def, Modifier.NOMOD(), cc_mod, NFComponent.DEFAULT_ATTR,
1327+
instComponentDef(def, Modifier.NOMOD(), Modifier.NOMOD(), NFComponent.DEFAULT_ATTR,
13281328
useBinding, comp_node, parent, originalAttr, isRedeclared = true);
13291329

13301330
Modifier.REDECLARE(element = rdcl_node, mod = outer_mod) := outer_mod;
1331+
13311332
cc_smod := SCode.getConstrainingMod(def);
13321333
if not SCode.isEmptyMod(cc_smod) then
13331334
name := InstNode.name(node);
13341335
cc_mod := Modifier.create(cc_smod, name, ModifierScope.COMPONENT(name), {}, parent);
13351336
end if;
13361337

13371338
outer_mod := Modifier.merge(InstNode.getModifier(rdcl_node), outer_mod);
1338-
//outer_mod := Modifier.merge(outer_mod, cc_mod);
13391339
InstNode.setModifier(outer_mod, rdcl_node);
13401340
redeclareComponent(rdcl_node, node, Modifier.NOMOD(), cc_mod, attributes, node);
13411341
else
@@ -1357,7 +1357,7 @@ algorithm
13571357
() := match component
13581358
local
13591359
SourceInfo info;
1360-
Modifier decl_mod, mod;
1360+
Modifier decl_mod, mod, cc_mod;
13611361
list<Dimension> dims, ty_dims;
13621362
Binding binding, condition;
13631363
Component.Attributes attr, ty_attr;
@@ -1370,7 +1370,9 @@ algorithm
13701370
case SCode.COMPONENT(info = info)
13711371
algorithm
13721372
decl_mod := Modifier.fromElement(component, {}, parent);
1373-
mod := Modifier.merge(decl_mod, innerMod);
1373+
cc_mod := instConstrainingMod(component, parent);
1374+
mod := Modifier.merge(decl_mod, cc_mod);
1375+
mod := Modifier.merge(mod, innerMod);
13741376
mod := Modifier.merge(outerMod, mod);
13751377
mod := Modifier.addParent(node, mod);
13761378
checkOuterComponentMod(mod, component, node);
@@ -1418,6 +1420,27 @@ algorithm
14181420
end match;
14191421
end instComponentDef;
14201422

1423+
function instConstrainingMod
1424+
input SCode.Element element;
1425+
input InstNode parent;
1426+
output Modifier ccMod;
1427+
algorithm
1428+
ccMod := match element
1429+
local
1430+
SCode.Mod smod;
1431+
1432+
case SCode.Element.CLASS(prefixes = SCode.Prefixes.PREFIXES(replaceablePrefix =
1433+
SCode.Replaceable.REPLACEABLE(cc = SOME(SCode.ConstrainClass.CONSTRAINCLASS(modifier = smod)))))
1434+
then Modifier.create(smod, element.name, ModifierScope.CLASS(element.name), {}, parent);
1435+
1436+
case SCode.Element.COMPONENT(prefixes = SCode.Prefixes.PREFIXES(replaceablePrefix =
1437+
SCode.Replaceable.REPLACEABLE(cc = SOME(SCode.ConstrainClass.CONSTRAINCLASS(modifier = smod)))))
1438+
then Modifier.create(smod, element.name, ModifierScope.COMPONENT(element.name), {}, parent);
1439+
1440+
else Modifier.NOMOD();
1441+
end match;
1442+
end instConstrainingMod;
1443+
14211444
function updateComponentConnectorType
14221445
input output Component.Attributes attributes;
14231446
input Restriction restriction;

0 commit comments

Comments
 (0)