Skip to content

Commit

Permalink
Improve InteractiveUtil.mergeElementArgs (#11483)
Browse files Browse the repository at this point in the history
- Remove empty submodifiers recursively after merging modifiers in
  mergeElementArgs.
  • Loading branch information
perost committed Oct 31, 2023
1 parent 2856ad7 commit ea3d8a9
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
28 changes: 27 additions & 1 deletion OMCompiler/Compiler/Script/InteractiveUtil.mo
Expand Up @@ -616,10 +616,36 @@ algorithm
end if;
end for;

outArgs := list(arg for arg guard not AbsynUtil.isEmptySubMod(arg) in outArgs);
outArgs := removeEmptySubMods(outArgs);
end if;
end mergeElementArgs;

function removeEmptySubMods
input list<Absyn.ElementArg> subMods;
output list<Absyn.ElementArg> outSubMods = {};
protected
Absyn.Modification mod;
algorithm
for m in subMods loop
() := match m
case Absyn.ElementArg.MODIFICATION(modification = SOME(mod))
algorithm
mod.elementArgLst := removeEmptySubMods(mod.elementArgLst);
m.modification := if AbsynUtil.isEmptyMod(mod) then NONE() else SOME(mod);
then
();

else ();
end match;

if not AbsynUtil.isEmptySubMod(m) then
outSubMods := m :: outSubMods;
end if;
end for;

outSubMods := Dangerous.listReverseInPlace(outSubMods);
end removeEmptySubMods;

protected function propagateMod2
input Absyn.Path inComponentName;
input list<Absyn.ElementArg> inSubMods;
Expand Down
18 changes: 18 additions & 0 deletions testsuite/openmodelica/interactive-API/setElementModifierValue.mos
Expand Up @@ -36,6 +36,14 @@ setElementModifierValue(M, classwithReplaceable, $Code((final A, B = 2)));
getErrorString();
list(M);

setElementModifierValue(M, classwithReplaceable, $Code((A(fixed = true))));
getErrorString();
list(M);

setElementModifierValue(M, classwithReplaceable, $Code((A(fixed))));
getErrorString();
list(M);

// Result:
// true
// true
Expand Down Expand Up @@ -68,4 +76,14 @@ list(M);
// "model M
// ClasswithReplaceable classwithReplaceable(otherClass(redeclare ClassB testClass \"C\"), final A, B = 2);
// end M;"
// true
// ""
// "model M
// ClasswithReplaceable classwithReplaceable(otherClass(redeclare ClassB testClass \"C\"), A(fixed = true), B = 2);
// end M;"
// true
// ""
// "model M
// ClasswithReplaceable classwithReplaceable(otherClass(redeclare ClassB testClass \"C\"), B = 2);
// end M;"
// endResult

0 comments on commit ea3d8a9

Please sign in to comment.