Skip to content

Commit da5a55e

Browse files
authored
Improve dumping of modifiers in getModelInstance (#9163)
- Dump the structure of modifiers instead of just dumping them as strings. - Dump modifiers for classes too, including extends clauses. - Make the modifiers optional.
1 parent 622d016 commit da5a55e

File tree

11 files changed

+59
-45
lines changed

11 files changed

+59
-45
lines changed

OMCompiler/Compiler/FrontEnd/SCodeUtil.mo

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4290,6 +4290,7 @@ algorithm
42904290
case SCode.CLASS(classDef = SCode.DERIVED(modifications = mod)) then mod;
42914291
case SCode.CLASS(classDef = SCode.CLASS_EXTENDS(modifications = mod)) then mod;
42924292
case SCode.EXTENDS(modifications = mod) then mod;
4293+
else SCode.NOMOD();
42934294

42944295
end match;
42954296
end elementMod;

OMCompiler/Compiler/Script/NFApi.mo

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -934,6 +934,7 @@ algorithm
934934
json := JSON.addPair("name", dumpJSONNodePath(node), json);
935935
json := JSON.addPair("restriction",
936936
JSON.makeString(Restriction.toString(InstNode.restriction(node))), json);
937+
json := dumpJSONMod(SCodeUtil.elementMod(InstNode.definition(node)), json);
937938

938939
if not listEmpty(exts) then
939940
json := JSON.addPair("extends", dumpJSONExtends(exts), json);
@@ -1025,7 +1026,7 @@ algorithm
10251026
dumpJSONDims(elem.attributes.arrayDims, Type.arrayDims(comp.ty)), json);
10261027
end if;
10271028

1028-
json := JSON.addPair("modifier", JSON.makeString(SCodeDump.printModStr(elem.modifications)), json);
1029+
json := dumpJSONMod(elem.modifications, json);
10291030

10301031
//if not Type.isComplex(comp.ty) then
10311032
// json := dumpJSONBuiltinClassComponents(comp.classInst, elem.modifications, json);
@@ -1433,14 +1434,23 @@ end dumpJSONReplaceableElements;
14331434

14341435
function dumpJSONMod
14351436
input SCode.Mod mod;
1436-
output JSON json = JSON.emptyObject();
1437+
input output JSON json;
1438+
protected
1439+
JSON j = JSON.emptyObject();
14371440
algorithm
14381441
() := match mod
14391442
case SCode.Mod.MOD()
14401443
algorithm
1444+
if isSome(mod.binding) then
1445+
j := JSON.addPair("value",
1446+
JSON.makeString(Dump.printExpStr(Util.getOption(mod.binding))), j);
1447+
end if;
1448+
14411449
for sm in mod.subModLst loop
1442-
json := JSON.addPair(sm.ident, dumpJSONSubMod(sm), json);
1450+
j := JSON.addPair(sm.ident, dumpJSONSubMod(sm), j);
14431451
end for;
1452+
1453+
json := JSON.addPair("modifiers", j, json);
14441454
then
14451455
();
14461456

@@ -1457,14 +1467,14 @@ algorithm
14571467
() := match mod
14581468
case SCode.Mod.MOD()
14591469
algorithm
1460-
if not listEmpty(mod.subModLst) then
1461-
json := JSON.addPair("modifiers", dumpJSONMod(mod), json);
1462-
end if;
1463-
14641470
if isSome(mod.binding) then
14651471
json := JSON.addPair("value",
14661472
JSON.makeString(Dump.printExpStr(Util.getOption(mod.binding))), json);
14671473
end if;
1474+
1475+
if not listEmpty(mod.subModLst) then
1476+
json := dumpJSONMod(mod, json);
1477+
end if;
14681478
then
14691479
();
14701480

doc/instanceAPI/getModelInstance.schema.json

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
"description": "The kind of class",
1313
"type": "string"
1414
},
15+
"modifier": {
16+
"description": "Modifier from the SCode",
17+
"type": "#/definitions/modifier"
18+
},
1519
"extends": {
1620
"description": "The extends clauses in the class instance",
1721
"type": "array",
@@ -150,7 +154,7 @@
150154
},
151155
"modifier": {
152156
"description": "Modifier from the SCode",
153-
"type": "string"
157+
"type": "#/definitions/modifier"
154158
},
155159
"value": {
156160
"description": "The component's binding equation",
@@ -225,6 +229,22 @@
225229
}
226230
},
227231
"required": ["binding"]
232+
},
233+
"modifier": {
234+
"description": "A modifier",
235+
"type": "object",
236+
"properties": {
237+
"value": [
238+
"type": "string"
239+
],
240+
"modifiers": {
241+
"type": "array",
242+
"items": {
243+
"type": "#/definitions/modifier"
244+
}
245+
}
246+
},
247+
"required": []
228248
}
229249
}
230250
}

testsuite/openmodelica/instance-API/GetModelInstanceAttributes1.mos

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ getModelInstance(M, prettyPrint = true);
2424
// {
2525
// \"name\": \"pi\",
2626
// \"type\": \"Real\",
27-
// \"modifier\": \" = 3\",
27+
// \"modifiers\": {
28+
// \"value\": \"3\"
29+
// },
2830
// \"value\": {
2931
// \"binding\": 3
3032
// },
@@ -35,7 +37,11 @@ getModelInstance(M, prettyPrint = true);
3537
// {
3638
// \"name\": \"deg\",
3739
// \"type\": \"Real\",
38-
// \"modifier\": \"(start = pi)\",
40+
// \"modifiers\": {
41+
// \"start\": {
42+
// \"value\": \"pi\"
43+
// }
44+
// },
3945
// \"prefixes\": {
4046
//
4147
// }

testsuite/openmodelica/instance-API/GetModelInstanceAttributes2.mos

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ getModelInstance(M, prettyPrint = true);
4343
// {
4444
// \"name\": \"w\",
4545
// \"type\": \"Real\",
46-
// \"modifier\": \"\",
4746
// \"prefixes\": {
4847
// \"public\": false,
4948
// \"replaceable\": true,
@@ -53,7 +52,6 @@ getModelInstance(M, prettyPrint = true);
5352
// {
5453
// \"name\": \"z\",
5554
// \"type\": \"Real\",
56-
// \"modifier\": \"\",
5755
// \"prefixes\": {
5856
// \"inner\": true
5957
// }
@@ -65,39 +63,34 @@ getModelInstance(M, prettyPrint = true);
6563
// {
6664
// \"name\": \"z\",
6765
// \"type\": \"Real\",
68-
// \"modifier\": \"\",
6966
// \"prefixes\": {
7067
// \"outer\": true
7168
// }
7269
// },
7370
// {
7471
// \"name\": \"x\",
7572
// \"type\": \"Real\",
76-
// \"modifier\": \"\",
7773
// \"prefixes\": {
7874
// \"final\": true
7975
// }
8076
// },
8177
// {
8278
// \"name\": \"y\",
8379
// \"type\": \"Real\",
84-
// \"modifier\": \"\",
8580
// \"prefixes\": {
8681
// \"input\": true
8782
// }
8883
// },
8984
// {
9085
// \"name\": \"z\",
9186
// \"type\": \"Real\",
92-
// \"modifier\": \"\",
9387
// \"prefixes\": {
9488
// \"inner\": true
9589
// }
9690
// },
9791
// {
9892
// \"name\": \"w\",
9993
// \"type\": \"Real\",
100-
// \"modifier\": \"\",
10194
// \"prefixes\": {
10295
// \"public\": false,
10396
// \"replaceable\": true,
@@ -113,30 +106,26 @@ getModelInstance(M, prettyPrint = true);
113106
// {
114107
// \"name\": \"e\",
115108
// \"type\": \"Real\",
116-
// \"modifier\": \"\",
117109
// \"prefixes\": {
118110
//
119111
// }
120112
// },
121113
// {
122114
// \"name\": \"f\",
123115
// \"type\": \"Real\",
124-
// \"modifier\": \"\",
125116
// \"prefixes\": {
126117
// \"connector\": \"flow\"
127118
// }
128119
// },
129120
// {
130121
// \"name\": \"s\",
131122
// \"type\": \"Real\",
132-
// \"modifier\": \"\",
133123
// \"prefixes\": {
134124
// \"connector\": \"stream\"
135125
// }
136126
// }
137127
// ]
138128
// },
139-
// \"modifier\": \"\",
140129
// \"prefixes\": {
141130
// \"public\": false,
142131
// \"variability\": \"parameter\"

testsuite/openmodelica/instance-API/GetModelInstanceConnection1.mos

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,22 +46,19 @@ getModelInstance(M, prettyPrint = true);
4646
// {
4747
// \"name\": \"e\",
4848
// \"type\": \"Real\",
49-
// \"modifier\": \"\",
5049
// \"prefixes\": {
5150
//
5251
// }
5352
// },
5453
// {
5554
// \"name\": \"f\",
5655
// \"type\": \"Real\",
57-
// \"modifier\": \"\",
5856
// \"prefixes\": {
5957
// \"connector\": \"flow\"
6058
// }
6159
// }
6260
// ]
6361
// },
64-
// \"modifier\": \"\",
6562
// \"prefixes\": {
6663
//
6764
// }
@@ -75,22 +72,19 @@ getModelInstance(M, prettyPrint = true);
7572
// {
7673
// \"name\": \"e\",
7774
// \"type\": \"Real\",
78-
// \"modifier\": \"\",
7975
// \"prefixes\": {
8076
//
8177
// }
8278
// },
8379
// {
8480
// \"name\": \"f\",
8581
// \"type\": \"Real\",
86-
// \"modifier\": \"\",
8782
// \"prefixes\": {
8883
// \"connector\": \"flow\"
8984
// }
9085
// }
9186
// ]
9287
// },
93-
// \"modifier\": \"\",
9488
// \"prefixes\": {
9589
//
9690
// }
@@ -108,22 +102,19 @@ getModelInstance(M, prettyPrint = true);
108102
// {
109103
// \"name\": \"e\",
110104
// \"type\": \"Real\",
111-
// \"modifier\": \"\",
112105
// \"prefixes\": {
113106
//
114107
// }
115108
// },
116109
// {
117110
// \"name\": \"f\",
118111
// \"type\": \"Real\",
119-
// \"modifier\": \"\",
120112
// \"prefixes\": {
121113
// \"connector\": \"flow\"
122114
// }
123115
// }
124116
// ]
125117
// },
126-
// \"modifier\": \"\",
127118
// \"prefixes\": {
128119
//
129120
// }

testsuite/openmodelica/instance-API/GetModelInstanceDuplicate1.mos

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ getModelInstance(B, prettyPrint = true);
3131
// {
3232
// \"name\": \"x\",
3333
// \"type\": \"Real\",
34-
// \"modifier\": \"\",
3534
// \"prefixes\": {
3635
//
3736
// }
@@ -43,7 +42,6 @@ getModelInstance(B, prettyPrint = true);
4342
// {
4443
// \"name\": \"x\",
4544
// \"type\": \"Real\",
46-
// \"modifier\": \"\",
4745
// \"prefixes\": {
4846
//
4947
// }

testsuite/openmodelica/instance-API/GetModelInstanceExp1.mos

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ getModelInstance(M, prettyPrint = true);
2828
// {
2929
// \"name\": \"x\",
3030
// \"type\": \"Real\",
31-
// \"modifier\": \" = 2.0\",
31+
// \"modifiers\": {
32+
// \"value\": \"2.0\"
33+
// },
3234
// \"value\": {
3335
// \"binding\": 2
3436
// },
@@ -53,7 +55,9 @@ getModelInstance(M, prettyPrint = true);
5355
// \"3\"
5456
// ]
5557
// },
56-
// \"modifier\": \" = {1, 2, 3}\",
58+
// \"modifiers\": {
59+
// \"value\": \"{1, 2, 3}\"
60+
// },
5761
// \"value\": {
5862
// \"binding\": [
5963
// 1,
@@ -67,15 +71,16 @@ getModelInstance(M, prettyPrint = true);
6771
// }
6872
// ]
6973
// },
70-
// \"modifier\": \"\",
7174
// \"prefixes\": {
7275
//
7376
// }
7477
// },
7578
// {
7679
// \"name\": \"y\",
7780
// \"type\": \"Real\",
78-
// \"modifier\": \" = a.x[1]\",
81+
// \"modifiers\": {
82+
// \"value\": \"a.x[1]\"
83+
// },
7984
// \"value\": {
8085
// \"binding\": {
8186
// \"$kind\": \"cref\",

testsuite/openmodelica/instance-API/GetModelInstanceExtends1.mos

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ getModelInstance(M, prettyPrint=true);
3232
// {
3333
// \"name\": \"x\",
3434
// \"type\": \"Real\",
35-
// \"modifier\": \"\",
3635
// \"prefixes\": {
3736
//
3837
// }
@@ -44,15 +43,13 @@ getModelInstance(M, prettyPrint=true);
4443
// {
4544
// \"name\": \"y\",
4645
// \"type\": \"Real\",
47-
// \"modifier\": \"\",
4846
// \"prefixes\": {
4947
//
5048
// }
5149
// },
5250
// {
5351
// \"name\": \"z\",
5452
// \"type\": \"Real\",
55-
// \"modifier\": \"\",
5653
// \"prefixes\": {
5754
//
5855
// }

testsuite/openmodelica/instance-API/GetModelInstanceInnerOuter1.mos

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,19 @@ getModelInstance(B, prettyPrint=true);
3333
// {
3434
// \"name\": \"x\",
3535
// \"type\": \"Real\",
36-
// \"modifier\": \"\",
3736
// \"prefixes\": {
3837
// \"inner\": true
3938
// }
4039
// }
4140
// ]
4241
// },
43-
// \"modifier\": \"\",
4442
// \"prefixes\": {
4543
//
4644
// }
4745
// },
4846
// {
4947
// \"name\": \"x\",
5048
// \"type\": \"Real\",
51-
// \"modifier\": \"\",
5249
// \"prefixes\": {
5350
// \"inner\": true
5451
// }

0 commit comments

Comments
 (0)