From 437041e4f038efbef03d0129dc0a3c22f751210b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Per=20=C3=96stlund?= Date: Thu, 2 Nov 2023 13:42:04 +0100 Subject: [PATCH] Dump connections in for-loops for getModelInstance (#11491) --- OMCompiler/Compiler/NFFrontEnd/NFInst.mo | 6 + OMCompiler/Compiler/Script/NFApi.mo | 7 + .../GetModelInstanceConnection5.mos | 169 ++++++++++++++++++ testsuite/openmodelica/instance-API/Makefile | 1 + 4 files changed, 183 insertions(+) create mode 100644 testsuite/openmodelica/instance-API/GetModelInstanceConnection5.mos diff --git a/OMCompiler/Compiler/NFFrontEnd/NFInst.mo b/OMCompiler/Compiler/NFFrontEnd/NFInst.mo index 7a25d74e2be..2a02937044f 100644 --- a/OMCompiler/Compiler/NFFrontEnd/NFInst.mo +++ b/OMCompiler/Compiler/NFFrontEnd/NFInst.mo @@ -3082,6 +3082,12 @@ algorithm guard name == "transition" or name == "initialState" then eq :: outEql; + case SCode.Equation.EQ_FOR() + algorithm + eq.eEquationLst := filterInstanceAPIEquations(eq.eEquationLst); + then + if listEmpty(eq.eEquationLst) then outEql else eq :: outEql; + case SCode.Equation.EQ_IF() algorithm eq.thenBranch := list(filterInstanceAPIEquations(eql) for eql in eq.thenBranch); diff --git a/OMCompiler/Compiler/Script/NFApi.mo b/OMCompiler/Compiler/Script/NFApi.mo index 88506ce9d34..d831d33607a 100644 --- a/OMCompiler/Compiler/Script/NFApi.mo +++ b/OMCompiler/Compiler/Script/NFApi.mo @@ -1951,6 +1951,13 @@ algorithm then (); + case Equation.FOR() + algorithm + (connections, transitions, initialStates) := + sortEquations(eq.body, connections, transitions, initialStates); + then + (); + case Equation.IF() algorithm for b in eq.branches loop diff --git a/testsuite/openmodelica/instance-API/GetModelInstanceConnection5.mos b/testsuite/openmodelica/instance-API/GetModelInstanceConnection5.mos new file mode 100644 index 00000000000..19a498ec5d8 --- /dev/null +++ b/testsuite/openmodelica/instance-API/GetModelInstanceConnection5.mos @@ -0,0 +1,169 @@ +// name: GetModelInstanceConnection4 +// keywords: +// status: correct +// cflags: -d=newInst +// +// + +loadString(" +model M + connector C + Real e; + flow Real f; + end C; + + parameter Integer N = 3; + C c1[N], c2[N]; +equation + for i loop + connect(c1[i], c2[i]); + end for; +end M; +"); + +getModelInstance(M, prettyPrint = true); + +// Result: +// true +// "{ +// \"name\": \"M\", +// \"restriction\": \"model\", +// \"elements\": [ +// { +// \"$kind\": \"component\", +// \"name\": \"N\", +// \"type\": \"Integer\", +// \"modifiers\": \"3\", +// \"value\": { +// \"binding\": 3 +// }, +// \"prefixes\": { +// \"variability\": \"parameter\" +// } +// }, +// { +// \"$kind\": \"component\", +// \"name\": \"c1\", +// \"type\": { +// \"name\": \"C\", +// \"restriction\": \"connector\", +// \"elements\": [ +// { +// \"$kind\": \"component\", +// \"name\": \"e\", +// \"type\": \"Real\" +// }, +// { +// \"$kind\": \"component\", +// \"name\": \"f\", +// \"type\": \"Real\", +// \"prefixes\": { +// \"connector\": \"flow\" +// } +// } +// ], +// \"source\": { +// \"filename\": \"\", +// \"lineStart\": 3, +// \"columnStart\": 3, +// \"lineEnd\": 6, +// \"columnEnd\": 8 +// } +// }, +// \"dims\": { +// \"absyn\": [ +// \"N\" +// ], +// \"typed\": [ +// \"3\" +// ] +// } +// }, +// { +// \"$kind\": \"component\", +// \"name\": \"c2\", +// \"type\": { +// \"name\": \"C\", +// \"restriction\": \"connector\", +// \"elements\": [ +// { +// \"$kind\": \"component\", +// \"name\": \"e\", +// \"type\": \"Real\" +// }, +// { +// \"$kind\": \"component\", +// \"name\": \"f\", +// \"type\": \"Real\", +// \"prefixes\": { +// \"connector\": \"flow\" +// } +// } +// ], +// \"source\": { +// \"filename\": \"\", +// \"lineStart\": 3, +// \"columnStart\": 3, +// \"lineEnd\": 6, +// \"columnEnd\": 8 +// } +// }, +// \"dims\": { +// \"absyn\": [ +// \"N\" +// ], +// \"typed\": [ +// \"3\" +// ] +// } +// } +// ], +// \"connections\": [ +// { +// \"lhs\": { +// \"$kind\": \"cref\", +// \"parts\": [ +// { +// \"name\": \"c1\", +// \"subscripts\": [ +// { +// \"$kind\": \"cref\", +// \"parts\": [ +// { +// \"name\": \"i\" +// } +// ] +// } +// ] +// } +// ] +// }, +// \"rhs\": { +// \"$kind\": \"cref\", +// \"parts\": [ +// { +// \"name\": \"c2\", +// \"subscripts\": [ +// { +// \"$kind\": \"cref\", +// \"parts\": [ +// { +// \"name\": \"i\" +// } +// ] +// } +// ] +// } +// ] +// } +// } +// ], +// \"source\": { +// \"filename\": \"\", +// \"lineStart\": 2, +// \"columnStart\": 1, +// \"lineEnd\": 14, +// \"columnEnd\": 6 +// } +// }" +// endResult diff --git a/testsuite/openmodelica/instance-API/Makefile b/testsuite/openmodelica/instance-API/Makefile index 420010569bd..2ae91f4e6d9 100644 --- a/testsuite/openmodelica/instance-API/Makefile +++ b/testsuite/openmodelica/instance-API/Makefile @@ -30,6 +30,7 @@ GetModelInstanceConnection1.mos \ GetModelInstanceConnection2.mos \ GetModelInstanceConnection3.mos \ GetModelInstanceConnection4.mos \ +GetModelInstanceConnection5.mos \ GetModelInstanceDerived1.mos \ GetModelInstanceDerived2.mos \ GetModelInstanceDerived3.mos \