Skip to content

Commit

Permalink
fix #7594 (#7615)
Browse files Browse the repository at this point in the history
- make getComponentsTest work with new instantiation and -d=nfAPI
- make getComponentsTest work with old instantiation via -d=-newInst
  • Loading branch information
adrpo committed Jun 25, 2021
1 parent 81066b9 commit 8db9243
Show file tree
Hide file tree
Showing 4 changed files with 197 additions and 16 deletions.
23 changes: 8 additions & 15 deletions OMCompiler/Compiler/Script/CevalScriptBackend.mo
Expand Up @@ -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<Absyn.Program> newps;
GlobalScript.SimulationOptions simOpt;
Expand Down Expand Up @@ -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(_))},_)
Expand Down Expand Up @@ -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<Values.Value> vs;
algorithm
Expand All @@ -8061,20 +8057,15 @@ 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;
vs := {};

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);

Expand Down Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion testsuite/openmodelica/interactive-API/Makefile
Expand Up @@ -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
Expand Down
93 changes: 93 additions & 0 deletions 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
93 changes: 93 additions & 0 deletions 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

0 comments on commit 8db9243

Please sign in to comment.