Skip to content

Commit

Permalink
Add each and final to instance API (#9295)
Browse files Browse the repository at this point in the history
- Add information about `each` and `final` to modifiers in the instance
  API.
  • Loading branch information
perost committed Aug 15, 2022
1 parent 654f2c9 commit 66bbb14
Show file tree
Hide file tree
Showing 4 changed files with 152 additions and 0 deletions.
8 changes: 8 additions & 0 deletions OMCompiler/Compiler/Script/NFApi.mo
Expand Up @@ -1484,6 +1484,14 @@ algorithm
json := JSON.addPair(m.ident, dumpJSONSCodeMod_impl(m.mod), json);
end for;

if SCodeUtil.finalBool(mod.finalPrefix) then
json := JSON.addPair("final", JSON.makeBoolean(true), json);
end if;

if SCodeUtil.eachBool(mod.eachPrefix) then
json := JSON.addPair("each", JSON.makeBoolean(true), json);
end if;

if isSome(mod.binding) then
binding_json := JSON.makeString(Dump.printExpStr(Util.getOption(mod.binding)));

Expand Down
8 changes: 8 additions & 0 deletions doc/instanceAPI/getModelInstance.schema.json
Expand Up @@ -275,6 +275,14 @@
"$value": {
"type": "string",
"description": "The string representation of the binding equation"
},
"final": {
"type": "boolean",
"description": "Whether the modifier is final or not"
},
"each": {
"type": "boolean",
"description": "Whether the modifier is each or not"
}
},
"additionalProperties": {
Expand Down
135 changes: 135 additions & 0 deletions testsuite/openmodelica/instance-API/GetModelInstanceMod2.mos
@@ -0,0 +1,135 @@
// name: GetModelInstanceMod2
// keywords:
// status: correct
// cflags: -d=newInst
//
//

loadString("
model A
Real x;
Real y;
end A;

model M
A a1[2](final x = {2.0, 3.0}, each y = 1);
A a2[3](x = {1.0, 2.0, 3.0}, each final y = 2);
end M;
");

getModelInstance(M, prettyPrint = true);

// Result:
// true
// "{
// \"name\": \"M\",
// \"restriction\": \"model\",
// \"components\": [
// {
// \"name\": \"a1\",
// \"type\": {
// \"name\": \"A\",
// \"restriction\": \"model\",
// \"components\": [
// {
// \"name\": \"x\",
// \"type\": \"Real\",
// \"value\": {
// \"binding\": [
// 2,
// 3
// ]
// },
// \"prefixes\": {
//
// }
// },
// {
// \"name\": \"y\",
// \"type\": \"Real\",
// \"value\": {
// \"binding\": 1
// },
// \"prefixes\": {
//
// }
// }
// ]
// },
// \"dims\": {
// \"absyn\": [
// \"2\"
// ],
// \"typed\": [
// \"2\"
// ]
// },
// \"modifiers\": {
// \"x\": {
// \"final\": true,
// \"$value\": \"{2.0, 3.0}\"
// },
// \"y\": {
// \"each\": true,
// \"$value\": \"1\"
// }
// },
// \"prefixes\": {
//
// }
// },
// {
// \"name\": \"a2\",
// \"type\": {
// \"name\": \"A\",
// \"restriction\": \"model\",
// \"components\": [
// {
// \"name\": \"x\",
// \"type\": \"Real\",
// \"value\": {
// \"binding\": [
// 1,
// 2,
// 3
// ]
// },
// \"prefixes\": {
//
// }
// },
// {
// \"name\": \"y\",
// \"type\": \"Real\",
// \"value\": {
// \"binding\": 2
// },
// \"prefixes\": {
//
// }
// }
// ]
// },
// \"dims\": {
// \"absyn\": [
// \"3\"
// ],
// \"typed\": [
// \"3\"
// ]
// },
// \"modifiers\": {
// \"x\": \"{1.0, 2.0, 3.0}\",
// \"y\": {
// \"final\": true,
// \"each\": true,
// \"$value\": \"2\"
// }
// },
// \"prefixes\": {
//
// }
// }
// ]
// }"
// endResult
1 change: 1 addition & 0 deletions testsuite/openmodelica/instance-API/Makefile
Expand Up @@ -13,6 +13,7 @@ GetModelInstanceExp1.mos \
GetModelInstanceExtends1.mos \
GetModelInstanceInnerOuter1.mos \
GetModelInstanceMod1.mos \
GetModelInstanceMod2.mos \
GetModelInstanceReplaceable1.mos \


Expand Down

0 comments on commit 66bbb14

Please sign in to comment.