diff --git a/OMCompiler/Compiler/FrontEnd/ModelicaBuiltin.mo b/OMCompiler/Compiler/FrontEnd/ModelicaBuiltin.mo index 40c967110ab..4f1a7a8a4cc 100644 --- a/OMCompiler/Compiler/FrontEnd/ModelicaBuiltin.mo +++ b/OMCompiler/Compiler/FrontEnd/ModelicaBuiltin.mo @@ -3148,6 +3148,21 @@ annotation( preferredView="text"); end getElementModifierNames; +function setComponentModifierValue = setElementModifierValue; + +function setElementModifierValue + input TypeName className; + input TypeName elementName; + input ExpressionOrModification modifier; + output Boolean success; +external "builtin"; +annotation( + Documentation(info=" + Sets a modifier on an element in a class definition. +"), + preferredView="text"); +end setElementModifierValue; + function getElementModifierValue input TypeName className; input TypeName modifier; diff --git a/OMCompiler/Compiler/NFFrontEnd/NFModelicaBuiltin.mo b/OMCompiler/Compiler/NFFrontEnd/NFModelicaBuiltin.mo index f02626400fc..acb19988e17 100644 --- a/OMCompiler/Compiler/NFFrontEnd/NFModelicaBuiltin.mo +++ b/OMCompiler/Compiler/NFFrontEnd/NFModelicaBuiltin.mo @@ -3401,6 +3401,21 @@ annotation( preferredView="text"); end getElementModifierNames; +function setComponentModifierValue = setElementModifierValue; + +function setElementModifierValue + input TypeName className; + input TypeName elementName; + input ExpressionOrModification modifier; + output Boolean success; +external "builtin"; +annotation( + Documentation(info=" + Sets a modifier on an element in a class definition. +"), + preferredView="text"); +end setElementModifierValue; + function getElementModifierValue input TypeName className; input TypeName modifier; diff --git a/OMCompiler/Compiler/Script/CevalScriptBackend.mo b/OMCompiler/Compiler/Script/CevalScriptBackend.mo index 6216f4f0385..1ac6b78ae5e 100644 --- a/OMCompiler/Compiler/Script/CevalScriptBackend.mo +++ b/OMCompiler/Compiler/Script/CevalScriptBackend.mo @@ -1841,6 +1841,7 @@ algorithm list> valsLst; SourceInfo info; System.StatFileType statFileType; + Absyn.Modification mod; case ("getAvailableIndexReductionMethods",_) equation @@ -2631,6 +2632,16 @@ algorithm then Values.STRING(str); + case ("setElementModifierValue", + {Values.CODE(Absyn.C_TYPENAME(classpath)), + Values.CODE(Absyn.C_TYPENAME(path)), + Values.CODE(Absyn.C_MODIFICATION(modification = mod))}) + algorithm + (p, b) := InteractiveUtil.setElementModifier(classpath, path, mod, SymbolTable.getAbsyn()); + SymbolTable.setAbsyn(p); + then + Values.BOOL(b); + case ("removeComponentModifiers", Values.CODE(Absyn.C_TYPENAME(path)):: Values.STRING(str1):: diff --git a/OMCompiler/Compiler/Script/Interactive.mo b/OMCompiler/Compiler/Script/Interactive.mo index 5b893fa301d..5ed3ccae192 100644 --- a/OMCompiler/Compiler/Script/Interactive.mo +++ b/OMCompiler/Compiler/Script/Interactive.mo @@ -940,30 +940,6 @@ algorithm args := getApiFunctionArgs(inStatement); outResult := match(fn_name) - case "setComponentModifierValue" - algorithm - {Absyn.CREF(componentRef = class_), - Absyn.CREF(componentRef = cr), - Absyn.CODE(code = Absyn.C_MODIFICATION(modification = mod))} := args; - (p, outResult) := setComponentModifier(class_, cr, mod, p); - SymbolTable.setAbsyn(p); - then - outResult; - - case "setElementModifierValue" - algorithm - {Absyn.CREF(componentRef = class_), - Absyn.CREF(componentRef = cr), - Absyn.CODE(code = cn)} := args; - mod := match cn - case Absyn.C_MODIFICATION(modification = mod) then mod; - case Absyn.C_ELEMENT(element = el) then fail(); - end match; - (p, outResult) := InteractiveUtil.setElementModifier(class_, cr, mod, p); - SymbolTable.setAbsyn(p); - then - outResult; - case "setParameterValue" algorithm {Absyn.CREF(componentRef = class_), Absyn.CREF(componentRef = crident), exp} := args; @@ -5431,256 +5407,6 @@ algorithm end try; end removeComponentModifiers; -protected function setComponentModifier - "Sets a submodifier of a component." - input Absyn.ComponentRef inClass; - input Absyn.ComponentRef inComponentName; - input Absyn.Modification inMod; - input Absyn.Program inProgram; - output Absyn.Program outProgram; - output String outResult; -protected - Absyn.Path p_class; - Absyn.Within within_; - Absyn.Class cls; -algorithm - try - p_class := AbsynUtil.crefToPath(inClass); - within_ := InteractiveUtil.buildWithin(p_class); - cls := InteractiveUtil.getPathedClassInProgram(p_class, inProgram); - cls := setComponentSubmodifierInClass(cls, inComponentName, inMod); - outProgram := InteractiveUtil.updateProgram(Absyn.PROGRAM({cls}, within_), inProgram); - outResult := "Ok"; - else - outProgram := inProgram; - outResult := "Error"; - end try; -end setComponentModifier; - -protected function setComponentSubmodifierInClass -" Sets a sub modifier on a component in a class. - inputs: (Absyn.Class, - Absyn.Ident, /* component name */ - Absyn.ComponentRef, /* subvariable path */ - Absyn.Modification) - outputs: Absyn.Class" - input Absyn.Class inClass; - input Absyn.ComponentRef inComponentName; - input Absyn.Modification inMod; - output Absyn.Class outClass = inClass; -algorithm - (outClass, true) := AbsynUtil.traverseClassComponents(inClass, - function setComponentSubmodifierInCompitems(inComponentName = - inComponentName, inMod = inMod), false); -end setComponentSubmodifierInClass; - -public function setComponentSubmodifierInCompitems - "Helper function to setComponentSubmodifierInClass. Sets the modifier in a - ComponentItem." - input list inComponents; - input Boolean inFound; - input Absyn.ComponentRef inComponentName; - input Absyn.Modification inMod; - output list outComponents = {}; - output Boolean outFound; - output Boolean outContinue; -protected - Absyn.ComponentItem item; - list rest_items = inComponents; - Absyn.Component comp; - list args_old, args_new; - Absyn.EqMod eqmod_old, eqmod_new; - String comp_id; -algorithm - comp_id := AbsynUtil.crefFirstIdent(inComponentName); - - // Try to find the component we're looking for. - while not listEmpty(rest_items) loop - item :: rest_items := rest_items; - - if AbsynUtil.componentName(item) == comp_id then - // Found component, propagate the modifier to it. - _ := match item - case Absyn.COMPONENTITEM(component = comp as Absyn.COMPONENT()) - algorithm - comp.modification := propagateMod(AbsynUtil.crefToPath(inComponentName), - inMod, comp.modification); - item.component := comp; - then - (); - end match; - - // Reassemble the item list and return. - outComponents := List.append_reverse(outComponents, item :: rest_items); - outFound := true; - outContinue := false; - return; - end if; - outComponents := item :: outComponents; - end while; - - // Component not found, continue looking. - outComponents := inComponents; - outFound := false; - outContinue := true; -end setComponentSubmodifierInCompitems; - -public function propagateMod - input Absyn.Path inComponentName; - input Absyn.Modification inNewMod; - input Option inOldMod; - output Option outMod; -protected - list new_args, old_args; - Absyn.EqMod new_eqmod, old_eqmod; - Absyn.Modification mod; -algorithm - if isSome(inOldMod) then - SOME(Absyn.CLASSMOD(elementArgLst = old_args, eqMod = old_eqmod)) := inOldMod; - else - old_args := {}; - old_eqmod := Absyn.NOMOD(); - end if; - - if AbsynUtil.pathIsIdent(inComponentName) then - Absyn.CLASSMOD(elementArgLst = new_args, eqMod = new_eqmod) := inNewMod; - - // If we have no eqmod but a list of submods, keep the old eqmod. - if valueEq(new_eqmod, Absyn.NOMOD()) and not listEmpty(new_args) then - new_eqmod := old_eqmod; - end if; - - new_args := mergeElementArgs(old_args, new_args); - mod := Absyn.CLASSMOD(new_args, new_eqmod); - else - new_args := propagateMod2(inComponentName, old_args, inNewMod); - mod := Absyn.CLASSMOD(new_args, old_eqmod); - end if; - - outMod := if AbsynUtil.isEmptyMod(mod) then NONE() else SOME(mod); -end propagateMod; - -protected function mergeElementArgs - input list inOldArgs; - input list inNewArgs; - output list outArgs = inOldArgs; -protected - Boolean found; -algorithm - if listEmpty(inOldArgs) then - outArgs := inNewArgs; - elseif listEmpty(inNewArgs) then - outArgs := inOldArgs; - else - for narg in inNewArgs loop - (outArgs, found) := List.replaceOnTrue(narg, outArgs, - function AbsynUtil.elementArgEqualName(inArg2 = narg)); - - if not found then - outArgs := narg :: outArgs; - end if; - end for; - end if; -end mergeElementArgs; - -protected function propagateMod2 - input Absyn.Path inComponentName; - input list inSubMods; - input Absyn.Modification inNewMod; - output list outSubMods = {}; -protected - Absyn.ElementArg submod; - list rest_submods = inSubMods; - Absyn.Modification new_mod; - Absyn.Path comp_name, comp_rest; -algorithm - // Search through the submods to see if one matches the component name. - while not listEmpty(rest_submods) loop - submod :: rest_submods := rest_submods; - comp_name := AbsynUtil.pathRest(inComponentName); - comp_rest := comp_name; - - // Try to find the submod whose path matches the best. If the have a - // component name a.b.c, then first check a.b.c, then a.b, then a. - while true loop - if AbsynUtil.pathEqual(comp_name, AbsynUtil.elementArgName(submod)) then - // Found matching submod, propagate the modifier to it. - _ := match(submod) - case Absyn.MODIFICATION() - algorithm - if not AbsynUtil.pathIsIdent(comp_name) then - comp_name := AbsynUtil.pathPrefix(comp_name); - comp_rest := AbsynUtil.removePrefix(comp_name, comp_rest); - end if; - - submod.modification := propagateMod(comp_rest, inNewMod, submod.modification); - - if isSome(submod.modification) then - rest_submods := submod :: rest_submods; - end if; - then - (); - - case Absyn.REDECLARATION() - algorithm - rest_submods := List.append_reverse(inNewMod.elementArgLst, rest_submods); - then - (); - - else (); - end match; - - outSubMods := List.append_reverse(outSubMods, rest_submods); - return; - end if; - - if AbsynUtil.pathIsIdent(comp_name) then - // Nothing left of the path, break and continue with next submod. - break; - else - // Remove the last part of the component name and see if that matches - // instead. - comp_name := AbsynUtil.pathPrefix(comp_name); - end if; - end while; - - outSubMods := submod :: outSubMods; - end while; - - if not AbsynUtil.isEmptyMod(inNewMod) then - // No matching submod was found, create a new submod and insert it into the list. - submod := createNestedSubMod(AbsynUtil.pathRest(inComponentName), inNewMod); - outSubMods := listReverse(submod :: outSubMods); - else - outSubMods := inSubMods; - end if; -end propagateMod2; - -protected function createNestedSubMod - input Absyn.Path inComponentName; - input Absyn.Modification inMod; - output Absyn.ElementArg outSubMod; -protected - Absyn.ElementArg e; -algorithm - if AbsynUtil.pathIsIdent(inComponentName) then - outSubMod := match inMod - case Absyn.CLASSMOD(elementArgLst = {e as Absyn.REDECLARATION()}) - then - e; - else - Absyn.MODIFICATION(false, Absyn.NON_EACH(), inComponentName, - SOME(inMod), NONE(), AbsynUtil.dummyInfo); - end match; - else - outSubMod := createNestedSubMod(AbsynUtil.pathRest(inComponentName), inMod); - outSubMod := Absyn.MODIFICATION(false, Absyn.NON_EACH(), - AbsynUtil.pathFirstPath(inComponentName), - SOME(Absyn.CLASSMOD({outSubMod}, Absyn.NOMOD())), NONE(), - AbsynUtil.dummyInfo); - end if; -end createNestedSubMod; - public function getComponentModifierValue input Absyn.ComponentRef classRef; input Absyn.ComponentRef varRef; diff --git a/OMCompiler/Compiler/Script/InteractiveUtil.mo b/OMCompiler/Compiler/Script/InteractiveUtil.mo index ff1a1e7ee4f..a9205779b77 100644 --- a/OMCompiler/Compiler/Script/InteractiveUtil.mo +++ b/OMCompiler/Compiler/Script/InteractiveUtil.mo @@ -307,27 +307,22 @@ end stripModifiersKeepRedeclares; public function setElementModifier "Sets a submodifier of an element." - input Absyn.ComponentRef inClass; - input Absyn.ComponentRef inElementName; + input Absyn.Path inClass; + input Absyn.Path inElementName; input Absyn.Modification inMod; - input Absyn.Program inProgram; - output Absyn.Program outProgram; - output String outResult; + input output Absyn.Program program; + output Boolean outResult; protected - Absyn.Path p_class; Absyn.Within within_; Absyn.Class cls; algorithm try - p_class := AbsynUtil.crefToPath(inClass); - within_ := buildWithin(p_class); - cls := getPathedClassInProgram(p_class, inProgram); - cls := setElementSubmodifierInClass(cls, inElementName, inMod); - outProgram := updateProgram(Absyn.PROGRAM({cls}, within_), inProgram); - outResult := "Ok"; + cls := getPathedClassInProgram(inClass, program); + (cls, outResult) := setElementSubmodifierInClass(cls, inElementName, inMod); + within_ := buildWithin(inClass); + program := updateProgram(Absyn.PROGRAM({cls}, within_), program); else - outProgram := inProgram; - outResult := "Error"; + outResult := false; end try; end setElementModifier; @@ -339,94 +334,76 @@ protected function setElementSubmodifierInClass Absyn.Modification) outputs: Absyn.Class" input Absyn.Class inClass; - input Absyn.ComponentRef inElementName; + input Absyn.Path inElementName; input Absyn.Modification inMod; output Absyn.Class outClass = inClass; -protected - Boolean found = false; + output Boolean found; algorithm - try - (outClass, found) := AbsynUtil.traverseClassElements(inClass, - function setSubmodifierInElement(inElementName = - inElementName, inMod = inMod), false); - else - // do nothing - end try; - // not found in elements, try components - if not found then - (outClass, true) := AbsynUtil.traverseClassComponents(inClass, - function Interactive.setComponentSubmodifierInCompitems(inComponentName = - inElementName, inMod = inMod), false); - end if; + (outClass, found) := AbsynUtil.traverseClassElements(inClass, + function setSubmodifierInElement(elementName = inElementName, mod = inMod), false); end setElementSubmodifierInClass; protected function setSubmodifierInElement "Helper function to setElementSubmodifierInClass. Sets the modifier in an Element." - input Absyn.Element inElement; - input Boolean inFound; - input Absyn.ComponentRef inElementName; - input Absyn.Modification inMod; - output Absyn.Element outElement = inElement; - output Boolean outFound; - output Boolean outContinue; + input output Absyn.Element element; + input output Boolean found; + input Absyn.Path elementName; + input Absyn.Modification mod; + output Boolean outContinue = true; protected list args_old, args_new; Absyn.EqMod eqmod_old, eqmod_new; String el_id, id = ""; - Absyn.Element el = inElement; - Absyn.ElementSpec elSpec; + Absyn.ElementSpec el_spec; algorithm - el_id := AbsynUtil.crefFirstIdent(inElementName); - elSpec := AbsynUtil.elementSpec(inElement); - if AbsynUtil.isClassOrComponentElementSpec(elSpec) then - // this will fail if no class or component (extends, import, etc) - id := AbsynUtil.elementSpecName(elSpec); - else - outFound := false; - outContinue := true; + el_id := AbsynUtil.pathFirstIdent(elementName); + el_spec := AbsynUtil.elementSpec(element); + + if not AbsynUtil.isClassOrComponentElementSpec(el_spec) then return; end if; - if (el_id == id) then + // this will fail if no class or component (extends, import, etc) + id := AbsynUtil.elementSpecName(el_spec); + + if el_id == id then try - outElement := match el + () := match element case Absyn.ELEMENT() algorithm - el.specification := setSubmodifierInElementSpec(inElementName, el.specification, inMod); - then el; + element.specification := setSubmodifierInElementSpec(elementName, mod, element.specification); + then (); end match; - outFound := true; + found := true; outContinue := false; else - outFound := false; - outContinue := true; end try; - else // element not found, continue looking. - outFound := false; - outContinue := true; end if; end setSubmodifierInElement; function setSubmodifierInElementSpec - input Absyn.ComponentRef inElementName; - input Absyn.ElementSpec inElSpec; - input Absyn.Modification inMod; - output Absyn.ElementSpec outElSpec; -protected - Absyn.ElementSpec elSpec = inElSpec; + input Absyn.Path elementName; + input Absyn.Modification mod; + input output Absyn.ElementSpec elSpec; algorithm - outElSpec := match elSpec + () := match elSpec case Absyn.CLASSDEF() algorithm - elSpec.class_ := setSubmodifierInClass(inElementName, elSpec.class_, inMod); + elSpec.class_ := setSubmodifierInClass(elementName, elSpec.class_, mod); + then + (); + + case Absyn.COMPONENTS() + algorithm + elSpec.components := setComponentSubmodifierInCompitems(elSpec.components, false, elementName, mod); then - elSpec; + (); end match; end setSubmodifierInElementSpec; function setSubmodifierInClass - input Absyn.ComponentRef inElementName; + input Absyn.Path inElementName; input Absyn.Class inClass; input Absyn.Modification inMod; output Absyn.Class outClass; @@ -443,7 +420,7 @@ algorithm body := match body case Absyn.DERIVED() algorithm - SOME(mod) := Interactive.propagateMod(AbsynUtil.crefToPath(inElementName), inMod, SOME(Absyn.CLASSMOD(body.arguments, Absyn.NOMOD()))); + SOME(mod) := propagateMod(inElementName, inMod, SOME(Absyn.CLASSMOD(body.arguments, Absyn.NOMOD()))); body.arguments := match mod case Absyn.CLASSMOD() then mod.elementArgLst; end match; then body; end match; @@ -453,12 +430,58 @@ algorithm end match; end setSubmodifierInClass; +public function setComponentSubmodifierInCompitems + "Helper function to setComponentSubmodifierInClass. Sets the modifier in a + ComponentItem." + input list inComponents; + input Boolean inFound; + input Absyn.Path inComponentName; + input Absyn.Modification inMod; + output list outComponents = {}; + output Boolean outFound; + output Boolean outContinue; +protected + Absyn.ComponentItem item; + list rest_items = inComponents; + Absyn.Component comp; + list args_old, args_new; + Absyn.EqMod eqmod_old, eqmod_new; + String comp_id; +algorithm + comp_id := AbsynUtil.pathFirstIdent(inComponentName); + + // Try to find the component we're looking for. + while not listEmpty(rest_items) loop + item :: rest_items := rest_items; + + if AbsynUtil.componentName(item) == comp_id then + // Found component, propagate the modifier to it. + _ := match item + case Absyn.COMPONENTITEM(component = comp as Absyn.COMPONENT()) + algorithm + comp.modification := propagateMod(inComponentName, inMod, comp.modification); + item.component := comp; + then + (); + end match; + + // Reassemble the item list and return. + outComponents := List.append_reverse(outComponents, item :: rest_items); + outFound := true; + outContinue := false; + return; + end if; + outComponents := item :: outComponents; + end while; + + // Component not found, continue looking. + outComponents := inComponents; + outFound := false; + outContinue := true; +end setComponentSubmodifierInCompitems; + public function setSubmodifierInElementargs -" Helper function to setComponentSubmodifierInCompitems - inputs: (Absyn.ElementArg list, - Absyn.ComponentRef, /* subcomponent name */ - Absyn.Modification) - outputs: Absyn.ElementArg list" + "Helper function to setComponentSubmodifierInCompitems" input list inAbsynElementArgLst; input Absyn.Path inPath; input Absyn.Modification inModification; @@ -586,6 +609,162 @@ algorithm end match; end findPathModification; +public function propagateMod + input Absyn.Path inComponentName; + input Absyn.Modification inNewMod; + input Option inOldMod; + output Option outMod; +protected + list new_args, old_args; + Absyn.EqMod new_eqmod, old_eqmod; + Absyn.Modification mod; +algorithm + if isSome(inOldMod) then + SOME(Absyn.CLASSMOD(elementArgLst = old_args, eqMod = old_eqmod)) := inOldMod; + else + old_args := {}; + old_eqmod := Absyn.NOMOD(); + end if; + + if AbsynUtil.pathIsIdent(inComponentName) then + Absyn.CLASSMOD(elementArgLst = new_args, eqMod = new_eqmod) := inNewMod; + + // If we have no eqmod but a list of submods, keep the old eqmod. + if valueEq(new_eqmod, Absyn.NOMOD()) and not listEmpty(new_args) then + new_eqmod := old_eqmod; + end if; + + new_args := mergeElementArgs(old_args, new_args); + mod := Absyn.CLASSMOD(new_args, new_eqmod); + else + new_args := propagateMod2(inComponentName, old_args, inNewMod); + mod := Absyn.CLASSMOD(new_args, old_eqmod); + end if; + + outMod := if AbsynUtil.isEmptyMod(mod) then NONE() else SOME(mod); +end propagateMod; + +protected function mergeElementArgs + input list inOldArgs; + input list inNewArgs; + output list outArgs = inOldArgs; +protected + Boolean found; +algorithm + if listEmpty(inOldArgs) then + outArgs := inNewArgs; + elseif listEmpty(inNewArgs) then + outArgs := inOldArgs; + else + for narg in inNewArgs loop + (outArgs, found) := List.replaceOnTrue(narg, outArgs, + function AbsynUtil.elementArgEqualName(inArg2 = narg)); + + if not found then + outArgs := narg :: outArgs; + end if; + end for; + end if; +end mergeElementArgs; + +protected function propagateMod2 + input Absyn.Path inComponentName; + input list inSubMods; + input Absyn.Modification inNewMod; + output list outSubMods = {}; +protected + Absyn.ElementArg submod; + list rest_submods = inSubMods; + Absyn.Modification new_mod; + Absyn.Path comp_name, comp_rest; +algorithm + // Search through the submods to see if one matches the component name. + while not listEmpty(rest_submods) loop + submod :: rest_submods := rest_submods; + comp_name := AbsynUtil.pathRest(inComponentName); + comp_rest := comp_name; + + // Try to find the submod whose path matches the best. If the have a + // component name a.b.c, then first check a.b.c, then a.b, then a. + while true loop + if AbsynUtil.pathEqual(comp_name, AbsynUtil.elementArgName(submod)) then + // Found matching submod, propagate the modifier to it. + _ := match(submod) + case Absyn.MODIFICATION() + algorithm + if not AbsynUtil.pathIsIdent(comp_name) then + comp_name := AbsynUtil.pathPrefix(comp_name); + comp_rest := AbsynUtil.removePrefix(comp_name, comp_rest); + end if; + + submod.modification := propagateMod(comp_rest, inNewMod, submod.modification); + + if isSome(submod.modification) then + rest_submods := submod :: rest_submods; + end if; + then + (); + + case Absyn.REDECLARATION() + algorithm + rest_submods := List.append_reverse(inNewMod.elementArgLst, rest_submods); + then + (); + + else (); + end match; + + outSubMods := List.append_reverse(outSubMods, rest_submods); + return; + end if; + + if AbsynUtil.pathIsIdent(comp_name) then + // Nothing left of the path, break and continue with next submod. + break; + else + // Remove the last part of the component name and see if that matches + // instead. + comp_name := AbsynUtil.pathPrefix(comp_name); + end if; + end while; + + outSubMods := submod :: outSubMods; + end while; + + if not AbsynUtil.isEmptyMod(inNewMod) then + // No matching submod was found, create a new submod and insert it into the list. + submod := createNestedSubMod(AbsynUtil.pathRest(inComponentName), inNewMod); + outSubMods := listReverse(submod :: outSubMods); + else + outSubMods := inSubMods; + end if; +end propagateMod2; + +protected function createNestedSubMod + input Absyn.Path inComponentName; + input Absyn.Modification inMod; + output Absyn.ElementArg outSubMod; +protected + Absyn.ElementArg e; +algorithm + if AbsynUtil.pathIsIdent(inComponentName) then + outSubMod := match inMod + case Absyn.CLASSMOD(elementArgLst = {e as Absyn.REDECLARATION()}) + then + e; + else + Absyn.MODIFICATION(false, Absyn.NON_EACH(), inComponentName, + SOME(inMod), NONE(), AbsynUtil.dummyInfo); + end match; + else + outSubMod := createNestedSubMod(AbsynUtil.pathRest(inComponentName), inMod); + outSubMod := Absyn.MODIFICATION(false, Absyn.NON_EACH(), + AbsynUtil.pathFirstPath(inComponentName), + SOME(Absyn.CLASSMOD({outSubMod}, Absyn.NOMOD())), NONE(), + AbsynUtil.dummyInfo); + end if; +end createNestedSubMod; + public function getElementModifierValue input Absyn.ComponentRef classRef; input Absyn.ComponentRef varRef; diff --git a/OMEdit/OMEditLIB/OMC/OMCProxy.cpp b/OMEdit/OMEditLIB/OMC/OMCProxy.cpp index 75110b609a6..a6fcce165b1 100644 --- a/OMEdit/OMEditLIB/OMC/OMCProxy.cpp +++ b/OMEdit/OMEditLIB/OMC/OMCProxy.cpp @@ -1092,7 +1092,7 @@ bool OMCProxy::setElementModifierValue(QString className, QString modifierName, expression = QString("%1(%2, %3, $Code(=%4))").arg(sapi).arg(className).arg(modifierName).arg(modifierValue); } sendCommand(expression); - if (getResult().toLower().compare("ok") == 0) { + if (StringHandler::unparseBool(getResult())) { return true; } else { QString msg = tr("Unable to set the element modifier value using command %1").arg(expression); diff --git a/testsuite/openmodelica/interactive-API/Bug3783.mos b/testsuite/openmodelica/interactive-API/Bug3783.mos index 301a2be35b7..f5eb98dca70 100644 --- a/testsuite/openmodelica/interactive-API/Bug3783.mos +++ b/testsuite/openmodelica/interactive-API/Bug3783.mos @@ -32,7 +32,7 @@ list(Bug3783); getErrorString(); // Placement(visible = true, transformation(origin = {-26, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); // end Bug3783;" // "" -// Ok +// true // "" // {"p"} // "" diff --git a/testsuite/openmodelica/interactive-API/Ticket6287and6288.mos b/testsuite/openmodelica/interactive-API/Ticket6287and6288.mos index bd5d94dabd1..0efc8a472df 100644 --- a/testsuite/openmodelica/interactive-API/Ticket6287and6288.mos +++ b/testsuite/openmodelica/interactive-API/Ticket6287and6288.mos @@ -59,7 +59,7 @@ getAllSubtypeOf(DC_Drive2.DCPM_Utilities.MachineData,DC_Drive2.DCPM_Utilities.Dr // Evaluating: getErrorString() // "" // Evaluating: setElementModifierValue(DC_Drive.Examples.DCPMCurrentControlled, driveData.machineData, $Code()) -// Ok +// true // Evaluating: getErrorString() // "" // Evaluating: getElementModifierNames(DC_Drive.Examples.DCPMCurrentControlled, "driveData") @@ -67,7 +67,7 @@ getAllSubtypeOf(DC_Drive2.DCPM_Utilities.MachineData,DC_Drive2.DCPM_Utilities.Dr // Evaluating: getErrorString() // "" // Evaluating: setElementModifierValue(DC_Drive.Examples.DCPMCurrentControlled, driveData.machineData, $Code((redeclare DC_Drive.DriveParameters.MachineDataSets.M48V machineData))) -// Ok +// true // Evaluating: getErrorString() // "" // Evaluating: getElementModifierNames(DC_Drive.Examples.DCPMCurrentControlled, "driveData") diff --git a/testsuite/openmodelica/interactive-API/interactive_api_calls.mos b/testsuite/openmodelica/interactive-API/interactive_api_calls.mos index dacbed82d36..52b976abcf2 100644 --- a/testsuite/openmodelica/interactive-API/interactive_api_calls.mos +++ b/testsuite/openmodelica/interactive-API/interactive_api_calls.mos @@ -491,7 +491,7 @@ getMessagesStringInternal(unique = false); // not unique // Evaluating: getErrorString() // "" // Evaluating: setComponentModifierValue(TestPack.MyModel, r1, $Code( = 2)) -// Ok +// true // Evaluating: getErrorString() // "" // Evaluating: list(TestPack.MyModel) @@ -506,7 +506,7 @@ getMessagesStringInternal(unique = false); // not unique // Evaluating: getErrorString() // "" // Evaluating: setComponentModifierValue(TestPack.MyModel, r1.start, $Code( = 2)) -// Ok +// true // Evaluating: getErrorString() // "" // Evaluating: list(TestPack.MyModel) @@ -517,7 +517,7 @@ getMessagesStringInternal(unique = false); // not unique // Evaluating: getErrorString() // "" // Evaluating: setComponentModifierValue(TestPack.MyModel, r1, $Code( = Resistor(R = 2))) -// Ok +// true // Evaluating: getErrorString() // "" // Evaluating: list(TestPack.MyModel) @@ -532,7 +532,7 @@ getMessagesStringInternal(unique = false); // not unique // Evaluating: getErrorString() // "" // Evaluating: setComponentModifierValue(TestPack.MyModel, r1.min, $Code( = 10)) -// Ok +// true // Evaluating: getErrorString() // "" // Evaluating: list(TestPack.MyModel) @@ -570,7 +570,7 @@ getMessagesStringInternal(unique = false); // not unique // Evaluating: getErrorString() // "" // Evaluating: setComponentModifierValue(TestPack.MyModel, r1.min, $Code()) -// Ok +// true // Evaluating: getErrorString() // "" // Evaluating: list(TestPack.MyModel) @@ -581,7 +581,7 @@ getMessagesStringInternal(unique = false); // not unique // Evaluating: getErrorString() // "" // Evaluating: setComponentModifierValue(TestPack.MyModel, r1, $Code()) -// Ok +// true // Evaluating: getErrorString() // "" // Evaluating: list(TestPack.MyModel) @@ -592,7 +592,7 @@ getMessagesStringInternal(unique = false); // not unique // Evaluating: getErrorString() // "" // Evaluating: setComponentModifierValue(TestPack.MyModel, r1.start, $Code()) -// Ok +// true // Evaluating: getErrorString() // "" // Evaluating: list(TestPack.MyModel) diff --git a/testsuite/openmodelica/interactive-API/interactive_api_param.mos b/testsuite/openmodelica/interactive-API/interactive_api_param.mos index ea666f8422d..1ed8b0852c4 100644 --- a/testsuite/openmodelica/interactive-API/interactive_api_param.mos +++ b/testsuite/openmodelica/interactive-API/interactive_api_param.mos @@ -115,11 +115,11 @@ isExtendsModifierFinal(K6,Resistor,x); // Evaluating: getComponentModifierValue(C, b1.a1) // "" // Evaluating: setComponentModifierValue(C, b1.a1, $Code((p1 = 45))) -// Ok +// true // Evaluating: getComponentModifierValue(C, b1.a1) // "" // Evaluating: setComponentModifierValue(C, b1.a2, $Code( = 33)) -// Ok +// true // Evaluating: getComponentModifierValue(C, b1.a2) // "33" // Evaluating: getExtendsModifierNames(D2, B2) @@ -131,7 +131,7 @@ isExtendsModifierFinal(K6,Resistor,x); // Evaluating: getExtendsModifierValue(D2, B2, a.x) // 10 // Evaluating: setComponentModifierValue(E, a.p1, $Code()) -// Ok +// true // Evaluating: getComponentModifierNames(E, "a") // {"p2"} // Evaluating: getInheritanceCount(T1) @@ -147,7 +147,7 @@ isExtendsModifierFinal(K6,Resistor,x); // Evaluating: getExtendsModifierNames(Resistance, Real) // {unit} // Evaluating: setComponentModifierValue(Q, x.start, $Code( = 4)) -// Ok +// true // Evaluating: getComponentModifierValue(Q, x.start) // "4" // Evaluating: getComponentModifierValue(Q, x) @@ -155,7 +155,7 @@ isExtendsModifierFinal(K6,Resistor,x); // Evaluating: getExtendsModifierNames(Modelica.Blocks.Interfaces.BooleanInput, Modelica.Blocks.Interfaces.BooleanSignal) // {} // Evaluating: setComponentModifierValue(M, x.start, $Code()) -// Ok +// true // Evaluating: getComponentModifierNames(M, "x") // {} // Evaluating: getComponentModifierValue(M, x) @@ -163,25 +163,25 @@ isExtendsModifierFinal(K6,Resistor,x); // Evaluating: getComponentModifierValue(M2, x) // "1" // Evaluating: setComponentModifierValue(M2, x, $Code()) -// Ok +// true // Evaluating: setComponentModifierValue(M3, x, $Code()) -// Ok +// true // Evaluating: getComponentModifierNames(M, "x") // {} // Evaluating: getComponentModifierValue(M3, x) // "" // Evaluating: setComponentModifierValue(M4, x, $Code()) -// Ok +// true // Evaluating: setComponentModifierValue(M5, x.start, $Code()) -// Ok +// true // Evaluating: setComponentModifierValue(M7, a1.x.fixed, $Code()) -// Ok +// true // Evaluating: setComponentModifierValue(M7, a1.x.fixed, $Code( = false)) -// Ok +// true // Evaluating: getComponentModifierValue(M7, a1.x.fixed) // "false" // Evaluating: setComponentModifierValue(M7, a1.x.fixed, $Code( = true)) -// Ok +// true // Evaluating: getComponentModifierValue(M7, a1.x.fixed) // "true" // Evaluating: getComponentModifierNames(M5, "x") diff --git a/testsuite/openmodelica/interactive-API/setComponentModifierValue.mos b/testsuite/openmodelica/interactive-API/setComponentModifierValue.mos index 0562761ac8c..72deaa4baa8 100644 --- a/testsuite/openmodelica/interactive-API/setComponentModifierValue.mos +++ b/testsuite/openmodelica/interactive-API/setComponentModifierValue.mos @@ -49,17 +49,17 @@ setComponentModifierValue(M, q, $Code(=1)); // Result: // true // "" -// Ok -// Ok -// Ok -// Ok -// Ok -// Ok -// Ok -// Ok -// Ok -// Ok -// Ok +// true +// true +// true +// true +// true +// true +// true +// true +// true +// true +// true // "model M // model A // model B @@ -81,9 +81,9 @@ setComponentModifierValue(M, q, $Code(=1)); // A a2(b(x = 12)); // Real w(min = 5, start = 4) = 3; // end M;" -// Ok -// Ok -// Ok +// true +// true +// true // "model M // model A // model B @@ -105,5 +105,5 @@ setComponentModifierValue(M, q, $Code(=1)); // A a2; // Real w(start = 4) = 3; // end M;" -// Error +// false // endResult diff --git a/testsuite/openmodelica/interactive-API/setElementModifierValue.mos b/testsuite/openmodelica/interactive-API/setElementModifierValue.mos index 1b42d43fe8e..c80c937e9af 100644 --- a/testsuite/openmodelica/interactive-API/setElementModifierValue.mos +++ b/testsuite/openmodelica/interactive-API/setElementModifierValue.mos @@ -22,12 +22,12 @@ list(M); // Result: // true -// Ok +// true // "" // "model M // ClasswithReplaceable classwithReplaceable(redeclare ClassB testClass \"A\"); // end M;" -// Ok +// true // "" // "model M // ClasswithReplaceable classwithReplaceable(redeclare ClassB testClass \"B\");