From 8db9243d0c2f511b6c355612f4f57ea89b4991f5 Mon Sep 17 00:00:00 2001 From: Adrian Pop Date: Sat, 26 Jun 2021 01:40:24 +0200 Subject: [PATCH] fix #7594 (#7615) - make getComponentsTest work with new instantiation and -d=nfAPI - make getComponentsTest work with old instantiation via -d=-newInst --- .../Compiler/Script/CevalScriptBackend.mo | 23 ++--- .../openmodelica/interactive-API/Makefile | 4 +- .../interactive-API/getComponentsTestNF.mos | 93 +++++++++++++++++++ .../interactive-API/getComponentsTestOF.mos | 93 +++++++++++++++++++ 4 files changed, 197 insertions(+), 16 deletions(-) create mode 100644 testsuite/openmodelica/interactive-API/getComponentsTestNF.mos create mode 100644 testsuite/openmodelica/interactive-API/getComponentsTestOF.mos diff --git a/OMCompiler/Compiler/Script/CevalScriptBackend.mo b/OMCompiler/Compiler/Script/CevalScriptBackend.mo index 014b67d584d..a68a207741d 100644 --- a/OMCompiler/Compiler/Script/CevalScriptBackend.mo +++ b/OMCompiler/Compiler/Script/CevalScriptBackend.mo @@ -1856,6 +1856,7 @@ algorithm Absyn.Path path,classpath,className,baseClassPath; SCode.Program scodeP,sp; FCore.Graph env; + Interactive.GraphicEnvCache genv; Absyn.Program p,ip,pnew,newp; list newps; GlobalScript.SimulationOptions simOpt; @@ -2224,14 +2225,9 @@ algorithm case (cache,_,"getComponentsTest",{Values.CODE(Absyn.C_TYPENAME(classpath))},_) equation absynClass = Interactive.getPathedClassInProgram(classpath, SymbolTable.getAbsyn()); - sp = SymbolTable.getSCode(); - (cache, env) = Inst.makeEnvFromProgram(sp); - (cache,(cl as SCode.CLASS(name=name,encapsulatedPrefix=encflag,restriction=restr)),env) = Lookup.lookupClass(cache, env, classpath, NONE()); - env = FGraph.openScope(env, encflag, name, FGraph.restrictionToScopeType(restr)); - (_, env) = Inst.partialInstClassIn(cache, env, InnerOuter.emptyInstHierarchy, DAE.NOMOD(), DAE.NOPRE(), - ClassInf.start(restr, FGraph.getGraphName(env)), cl, SCode.PUBLIC(), {}, 0); - valsLst = list(getComponentInfo(c, env, isProtected=false) for c in Interactive.getPublicComponentsInClass(absynClass)); - valsLst = listAppend(list(getComponentInfo(c, env, isProtected=true) for c in Interactive.getProtectedComponentsInClass(absynClass)), valsLst); + genv = Interactive.getClassEnv(SymbolTable.getAbsyn(), classpath); + valsLst = list(getComponentInfo(c, genv, isProtected=false) for c in Interactive.getPublicComponentsInClass(absynClass)); + valsLst = listAppend(list(getComponentInfo(c, genv, isProtected=true) for c in Interactive.getProtectedComponentsInClass(absynClass)), valsLst); then (cache,ValuesUtil.makeArray(List.flatten(valsLst))); case (cache,_,"getComponentsTest",{Values.CODE(Absyn.C_TYPENAME(_))},_) @@ -8037,7 +8033,7 @@ end compareInitialStateFuncArgs; function getComponentInfo input Absyn.Element comp; - input FCore.Graph inEnv; + input Interactive.GraphicEnvCache inEnv; input Boolean isProtected; output list vs; algorithm @@ -8061,10 +8057,7 @@ algorithm typename := matchcontinue () case () equation - (_,_,env) = Lookup.lookupClass(FCore.emptyCache(), inEnv, p, NONE()); - SOME(envpath) = FGraph.getScopePath(env); - tpname = AbsynUtil.pathLastIdent(p); - p_1 = AbsynUtil.joinPaths(envpath, Absyn.IDENT(tpname)); + (_, p_1) = Interactive.mkFullyQual(inEnv, p); then AbsynUtil.pathString(p_1); else AbsynUtil.pathString(p); end matchcontinue; @@ -8072,9 +8065,7 @@ algorithm dims1 := list(Dump.printSubscriptStr(sub) for sub in attr.arrayDim); r_1 := Interactive.keywordReplaceable(comp.redeclareKeywords); - inout_str := innerOuterStr(comp.innerOuter); - variability_str := attrVariabilityStr(attr); dir_str := attrDirectionStr(attr); @@ -8185,6 +8176,8 @@ algorithm String c1,s2; case Absyn.COMPONENTITEM(component = Absyn.COMPONENT(name = c1),comment = SOME(Absyn.COMMENT(_,SOME(s2)))) then (c1, s2); + case Absyn.COMPONENTITEM(component = Absyn.COMPONENT(name = c1),comment = SOME(Absyn.COMMENT(_,_))) + then (c1, ""); case Absyn.COMPONENTITEM(component = Absyn.COMPONENT(name = c1),comment = NONE()) then (c1, ""); end match; diff --git a/testsuite/openmodelica/interactive-API/Makefile b/testsuite/openmodelica/interactive-API/Makefile index 965debf1769..8f8f253253d 100644 --- a/testsuite/openmodelica/interactive-API/Makefile +++ b/testsuite/openmodelica/interactive-API/Makefile @@ -91,7 +91,9 @@ Ticket6287and6288.mos \ Ticket6300.mos \ Ticket6307.mos \ Ticket6406.mos \ -ReadOnlyPkg.mos +ReadOnlyPkg.mos \ +getComponentsTestNF.mos \ +getComponentsTestOF.mos # test that currently fail. Move up when fixed. # Run make testfailing diff --git a/testsuite/openmodelica/interactive-API/getComponentsTestNF.mos b/testsuite/openmodelica/interactive-API/getComponentsTestNF.mos new file mode 100644 index 00000000000..00819c74c2a --- /dev/null +++ b/testsuite/openmodelica/interactive-API/getComponentsTestNF.mos @@ -0,0 +1,93 @@ +// name: getComponentsTestNF.mos +// keywords: +// status: correct +// cflags: -d=nfAPI +// + +loadModel(Modelica, {"4.0.0"}); getErrorString(); +y := getComponentsTest(Modelica.Thermal.HeatTransfer.Examples.TwoMasses); getErrorString(); + +// Result: +// true +// "" +// {record OpenModelica.Scripting.getComponentsTest.Component +// className = "Modelica.Units.SI.Temperature", +// name = "T_final_K", +// comment = "Projected final temperature", +// isProtected = false, +// isFinal = false, +// isFlow = false, +// isStream = false, +// isReplaceable = false, +// variability = "parameter", +// innerOuter = "", +// inputOutput = "", +// dimensions = {} +// end OpenModelica.Scripting.getComponentsTest.Component;,record OpenModelica.Scripting.getComponentsTest.Component +// className = "Modelica.Thermal.HeatTransfer.Components.HeatCapacitor", +// name = "mass1", +// comment = "", +// isProtected = false, +// isFinal = false, +// isFlow = false, +// isStream = false, +// isReplaceable = false, +// variability = "", +// innerOuter = "", +// inputOutput = "", +// dimensions = {} +// end OpenModelica.Scripting.getComponentsTest.Component;,record OpenModelica.Scripting.getComponentsTest.Component +// className = "Modelica.Thermal.HeatTransfer.Components.HeatCapacitor", +// name = "mass2", +// comment = "", +// isProtected = false, +// isFinal = false, +// isFlow = false, +// isStream = false, +// isReplaceable = false, +// variability = "", +// innerOuter = "", +// inputOutput = "", +// dimensions = {} +// end OpenModelica.Scripting.getComponentsTest.Component;,record OpenModelica.Scripting.getComponentsTest.Component +// className = "Modelica.Thermal.HeatTransfer.Components.ThermalConductor", +// name = "conduction", +// comment = "", +// isProtected = false, +// isFinal = false, +// isFlow = false, +// isStream = false, +// isReplaceable = false, +// variability = "", +// innerOuter = "", +// inputOutput = "", +// dimensions = {} +// end OpenModelica.Scripting.getComponentsTest.Component;,record OpenModelica.Scripting.getComponentsTest.Component +// className = "Modelica.Thermal.HeatTransfer.Celsius.TemperatureSensor", +// name = "Tsensor1", +// comment = "", +// isProtected = false, +// isFinal = false, +// isFlow = false, +// isStream = false, +// isReplaceable = false, +// variability = "", +// innerOuter = "", +// inputOutput = "", +// dimensions = {} +// end OpenModelica.Scripting.getComponentsTest.Component;,record OpenModelica.Scripting.getComponentsTest.Component +// className = "Modelica.Thermal.HeatTransfer.Celsius.TemperatureSensor", +// name = "Tsensor2", +// comment = "", +// isProtected = false, +// isFinal = false, +// isFlow = false, +// isStream = false, +// isReplaceable = false, +// variability = "", +// innerOuter = "", +// inputOutput = "", +// dimensions = {} +// end OpenModelica.Scripting.getComponentsTest.Component;} +// "" +// endResult diff --git a/testsuite/openmodelica/interactive-API/getComponentsTestOF.mos b/testsuite/openmodelica/interactive-API/getComponentsTestOF.mos new file mode 100644 index 00000000000..99f7ea606b5 --- /dev/null +++ b/testsuite/openmodelica/interactive-API/getComponentsTestOF.mos @@ -0,0 +1,93 @@ +// name: getComponentsTestOF.mos +// keywords: +// status: correct +// cflags: -d=-newInst +// + +loadModel(Modelica, {"4.0.0"}); getErrorString(); +y := getComponentsTest(Modelica.Thermal.HeatTransfer.Examples.TwoMasses); getErrorString(); + +// Result: +// true +// "" +// {record OpenModelica.Scripting.getComponentsTest.Component +// className = ".Modelica.Units.SI.Temperature", +// name = "T_final_K", +// comment = "Projected final temperature", +// isProtected = false, +// isFinal = false, +// isFlow = false, +// isStream = false, +// isReplaceable = false, +// variability = "parameter", +// innerOuter = "", +// inputOutput = "", +// dimensions = {} +// end OpenModelica.Scripting.getComponentsTest.Component;,record OpenModelica.Scripting.getComponentsTest.Component +// className = ".Modelica.Thermal.HeatTransfer.Components.HeatCapacitor", +// name = "mass1", +// comment = "", +// isProtected = false, +// isFinal = false, +// isFlow = false, +// isStream = false, +// isReplaceable = false, +// variability = "", +// innerOuter = "", +// inputOutput = "", +// dimensions = {} +// end OpenModelica.Scripting.getComponentsTest.Component;,record OpenModelica.Scripting.getComponentsTest.Component +// className = ".Modelica.Thermal.HeatTransfer.Components.HeatCapacitor", +// name = "mass2", +// comment = "", +// isProtected = false, +// isFinal = false, +// isFlow = false, +// isStream = false, +// isReplaceable = false, +// variability = "", +// innerOuter = "", +// inputOutput = "", +// dimensions = {} +// end OpenModelica.Scripting.getComponentsTest.Component;,record OpenModelica.Scripting.getComponentsTest.Component +// className = ".Modelica.Thermal.HeatTransfer.Components.ThermalConductor", +// name = "conduction", +// comment = "", +// isProtected = false, +// isFinal = false, +// isFlow = false, +// isStream = false, +// isReplaceable = false, +// variability = "", +// innerOuter = "", +// inputOutput = "", +// dimensions = {} +// end OpenModelica.Scripting.getComponentsTest.Component;,record OpenModelica.Scripting.getComponentsTest.Component +// className = ".Modelica.Thermal.HeatTransfer.Celsius.TemperatureSensor", +// name = "Tsensor1", +// comment = "", +// isProtected = false, +// isFinal = false, +// isFlow = false, +// isStream = false, +// isReplaceable = false, +// variability = "", +// innerOuter = "", +// inputOutput = "", +// dimensions = {} +// end OpenModelica.Scripting.getComponentsTest.Component;,record OpenModelica.Scripting.getComponentsTest.Component +// className = ".Modelica.Thermal.HeatTransfer.Celsius.TemperatureSensor", +// name = "Tsensor2", +// comment = "", +// isProtected = false, +// isFinal = false, +// isFlow = false, +// isStream = false, +// isReplaceable = false, +// variability = "", +// innerOuter = "", +// inputOutput = "", +// dimensions = {} +// end OpenModelica.Scripting.getComponentsTest.Component;} +// "" +// endResult