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

Commit 72ee122

Browse files
perostOpenModelica-Hudson
authored andcommitted
[NF] Improve handling of conditional components.
- Correctly handle connections where the connectors themselves are not deleted but contain children that are. Belonging to [master]: - #2529 - OpenModelica/OpenModelica-testsuite#982
1 parent 0fb948c commit 72ee122

File tree

5 files changed

+62
-3
lines changed

5 files changed

+62
-3
lines changed

Compiler/NFFrontEnd/NFComponent.mo

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,10 @@ uniontype Component
195195
Modifier modifier;
196196
end TYPE_ATTRIBUTE;
197197

198+
record DELETED_COMPONENT
199+
Component component;
200+
end DELETED_COMPONENT;
201+
198202
function new
199203
input SCode.Element definition;
200204
output Component component;
@@ -325,6 +329,7 @@ uniontype Component
325329
case UNTYPED_COMPONENT() then InstNode.getType(component.classInst);
326330
case ITERATOR() then component.ty;
327331
case TYPE_ATTRIBUTE() then component.ty;
332+
case DELETED_COMPONENT() then getType(component.component);
328333
else Type.UNKNOWN();
329334
end match;
330335
end getType;
@@ -628,6 +633,7 @@ uniontype Component
628633
cty := match component
629634
case UNTYPED_COMPONENT(attributes = Attributes.ATTRIBUTES(connectorType = cty)) then cty;
630635
case TYPED_COMPONENT(attributes = Attributes.ATTRIBUTES(connectorType = cty)) then cty;
636+
case DELETED_COMPONENT() then connectorType(component.component);
631637
else ConnectorType.POTENTIAL;
632638
end match;
633639
end connectorType;
@@ -752,6 +758,8 @@ uniontype Component
752758

753759
case TYPED_COMPONENT(condition = condition)
754760
then Binding.isBound(condition) and Expression.isFalse(Binding.getTypedExp(condition));
761+
762+
case DELETED_COMPONENT() then true;
755763
else false;
756764
end match;
757765
end isDeleted;

Compiler/NFFrontEnd/NFComponentRef.mo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,7 @@ public
739739
InstNode node;
740740

741741
case CREF(node = node, origin = Origin.CREF)
742-
then InstNode.isComponent(node) and Component.isDeleted(InstNode.component(node)) or isDeleted(cref.restCref);
742+
then InstNode.isComponent(node) and Component.isDeleted(InstNode.component(node));
743743
else false;
744744
end match;
745745
end isDeleted;

Compiler/NFFrontEnd/NFConnectionSets.mo

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,13 @@ package ConnectionSets
106106

107107
for c1 in lhsl loop
108108
c2 :: rhsl := rhsl;
109-
sets := merge(c1, c2, sets);
109+
110+
// Connections involving deleted conditional connectors are filtered out
111+
// when collecting the connections, but if the connectors themselves
112+
// contain connectors that have been deleted we need to remove them here.
113+
if not (Connector.isDeleted(c1) or Connector.isDeleted(c2)) then
114+
sets := merge(c1, c2, sets);
115+
end if;
110116
end for;
111117
end addConnection;
112118

Compiler/NFFrontEnd/NFConnector.mo

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,11 @@ public
147147
isInside := f == Face.INSIDE;
148148
end isInside;
149149

150+
function isDeleted
151+
input Connector conn;
152+
output Boolean isDeleted = ComponentRef.isDeleted(conn.name);
153+
end isDeleted;
154+
150155
function name
151156
input Connector conn;
152157
output ComponentRef name = conn.name;

Compiler/NFFrontEnd/NFFlatten.mo

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,9 @@ algorithm
243243
() := match c
244244
case Component.TYPED_COMPONENT(condition = condition, ty = ty)
245245
algorithm
246-
// Don't add the component if it has a condition that's false.
246+
// Delete the component if it has a condition that's false.
247247
if Binding.isBound(condition) and Expression.isFalse(Binding.getTypedExp(condition)) then
248+
deleteComponent(component);
248249
return;
249250
end if;
250251

@@ -269,6 +270,45 @@ algorithm
269270
end match;
270271
end flattenComponent;
271272

273+
function deleteComponent
274+
"Recursively marks components as deleted."
275+
input InstNode compNode;
276+
protected
277+
Component comp;
278+
algorithm
279+
if not InstNode.isEmpty(compNode) then
280+
comp := InstNode.component(compNode);
281+
InstNode.updateComponent(Component.DELETED_COMPONENT(comp), compNode);
282+
deleteClassComponents(Component.classInstance(comp));
283+
end if;
284+
end deleteComponent;
285+
286+
function deleteClassComponents
287+
input InstNode clsNode;
288+
protected
289+
Class cls = InstNode.getClass(clsNode);
290+
array<InstNode> comps;
291+
algorithm
292+
() := match cls
293+
case Class.INSTANCED_CLASS(elements = ClassTree.FLAT_TREE(components = comps))
294+
guard not Restriction.isType(cls.restriction)
295+
algorithm
296+
for c in comps loop
297+
deleteComponent(c);
298+
end for;
299+
then
300+
();
301+
302+
case Class.TYPED_DERIVED()
303+
algorithm
304+
deleteClassComponents(cls.baseClass);
305+
then
306+
();
307+
308+
else ();
309+
end match;
310+
end deleteClassComponents;
311+
272312
function isComplexComponent
273313
input Type ty;
274314
output Boolean isComplex;

0 commit comments

Comments
 (0)