Skip to content

Commit

Permalink
Dump conditional components in getModelInstance (#9322)
Browse files Browse the repository at this point in the history
  • Loading branch information
perost committed Aug 23, 2022
1 parent 2ce4fab commit 6b67b50
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 3 deletions.
8 changes: 6 additions & 2 deletions OMCompiler/Compiler/Script/NFApi.mo
Expand Up @@ -1030,10 +1030,14 @@ algorithm
elem := InstNode.definition(node);

() := match (comp, elem)
case (_, _)
case (_, SCode.Element.COMPONENT())
guard Component.isDeleted(comp)
algorithm

json := JSON.addPair("name", JSON.makeString(InstNode.name(node)), json);
json := dumpJSONSCodeMod(elem.modifications, json);
json := JSON.addPair("condition", JSON.makeBoolean(false), json);
json := JSON.addPairNotNull("prefixes", dumpJSONAttributes(elem.attributes, elem.prefixes), json);
json := dumpJSONCommentOpt(SOME(elem.comment), InstNode.parent(node), json);
then
();

Expand Down
2 changes: 1 addition & 1 deletion doc/instanceAPI/getModelInstance.schema.json
Expand Up @@ -308,7 +308,7 @@
"$ref": "#/definitions/annotation"
}
},
"required": ["name", "type"]
"required": ["name"]
}
]
},
Expand Down
@@ -0,0 +1,35 @@
// name: GetModelInstanceConditional1
// keywords:
// status: correct
// cflags: -d=newInst
//
//

loadString("
model M
parameter Real x if false;
end M;
");

getModelInstance(M, prettyPrint=true);

// Result:
// true
// "{
// \"name\": \"M\",
// \"restriction\": \"model\",
// \"components\": [
// {
// \"name\": \"x\",
// \"condition\": false,
// \"prefixes\": {
// \"variability\": \"parameter\"
// }
// }
// ],
// \"source\": {
// \"filename\": \"<interactive>\",
// \"location\": \"2:3-4:8\"
// }
// }"
// endResult
1 change: 1 addition & 0 deletions testsuite/openmodelica/instance-API/Makefile
Expand Up @@ -7,6 +7,7 @@ GetModelInstanceAnnotation3.mos \
GetModelInstanceAttributes1.mos \
GetModelInstanceAttributes2.mos \
GetModelInstanceComment1.mos \
GetModelInstanceConditional1.mos \
GetModelInstanceConnection1.mos \
GetModelInstanceDuplicate1.mos \
GetModelInstanceExp1.mos \
Expand Down

0 comments on commit 6b67b50

Please sign in to comment.