Skip to content

Commit

Permalink
Add replaceable for modifiers in getModelInstance (#11337)
Browse files Browse the repository at this point in the history
  • Loading branch information
perost committed Oct 5, 2023
1 parent 5218400 commit 4b69a3e
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 0 deletions.
4 changes: 4 additions & 0 deletions OMCompiler/Compiler/Script/NFApi.mo
Expand Up @@ -2120,6 +2120,10 @@ algorithm

json := JSON.addPair("redeclare", JSON.makeBoolean(true), json);

if SCodeUtil.isElementReplaceable(mod.element) then
json := JSON.addPair("replaceable", JSON.makeBoolean(true), json);
end if;

binding_json := JSON.makeString(SCodeDump.unparseElementStr(mod.element));
json := JSON.addPair("$value", binding_json, json);

Expand Down
4 changes: 4 additions & 0 deletions doc/instanceAPI/getModelInstance.schema.json
Expand Up @@ -454,6 +454,10 @@
"redeclare": {
"type": "boolean",
"description": "Whether the modifier is a redeclare or not"
},
"replaceable": {
"type": "boolean",
"description": "Whether the modifier is a replaceable or not"
}
},
"additionalProperties": {
Expand Down
@@ -0,0 +1,72 @@
// name: GetModelInstanceReplaceable5
// keywords:
// status: correct
// cflags: -d=newInst
//
//

loadString("
package P
model A
replaceable Real x;
end A;

model M
A a(redeclare replaceable Real x = 1.0);
end M;
end P;
");

getModelInstance(P.M, prettyPrint = true);

// Result:
// true
// "{
// \"name\": \"P.M\",
// \"restriction\": \"model\",
// \"elements\": [
// {
// \"$kind\": \"component\",
// \"name\": \"a\",
// \"type\": {
// \"name\": \"P.A\",
// \"restriction\": \"model\",
// \"elements\": [
// {
// \"$kind\": \"component\",
// \"name\": \"x\",
// \"type\": \"Real\",
// \"value\": {
// \"binding\": 1
// },
// \"prefixes\": {
// \"replaceable\": true
// }
// }
// ],
// \"source\": {
// \"filename\": \"<interactive>\",
// \"lineStart\": 3,
// \"columnStart\": 5,
// \"lineEnd\": 5,
// \"columnEnd\": 10
// }
// },
// \"modifiers\": {
// \"x\": {
// \"redeclare\": true,
// \"replaceable\": true,
// \"$value\": \"redeclare replaceable Real x = 1.0\"
// }
// }
// }
// ],
// \"source\": {
// \"filename\": \"<interactive>\",
// \"lineStart\": 7,
// \"columnStart\": 5,
// \"lineEnd\": 9,
// \"columnEnd\": 10
// }
// }"
// endResult
1 change: 1 addition & 0 deletions testsuite/openmodelica/instance-API/Makefile
Expand Up @@ -63,6 +63,7 @@ GetModelInstanceReplaceable1.mos \
GetModelInstanceReplaceable2.mos \
GetModelInstanceReplaceable3.mos \
GetModelInstanceReplaceable4.mos \
GetModelInstanceReplaceable5.mos \
GetModelInstanceReplaceableComment.mos \
GetModelInstanceStateMachine1.mos \
ModifierToJSON1.mos \
Expand Down

0 comments on commit 4b69a3e

Please sign in to comment.