Skip to content

Commit 4b52367

Browse files
authored
Strip comments when dumping SCode modifiers in NFApi (#13080)
Fixes #13074
1 parent d5c59c0 commit 4b52367

File tree

3 files changed

+56
-2
lines changed

3 files changed

+56
-2
lines changed

OMCompiler/Compiler/Script/NFApi.mo

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1934,7 +1934,7 @@ algorithm
19341934
then
19351935
json;
19361936

1937-
else JSON.makeString(Dump.printExpStr(exp));
1937+
else JSON.makeString(Dump.printExpStr(AbsynUtil.stripCommentExpressions(exp)));
19381938
end match;
19391939
end dumpJSONAbsynExpression;
19401940

@@ -2179,7 +2179,7 @@ algorithm
21792179
end if;
21802180

21812181
if isSome(mod.binding) then
2182-
binding_json := JSON.makeString(Dump.printExpStr(Util.getOption(mod.binding)));
2182+
binding_json := JSON.makeString(Dump.printExpStr(AbsynUtil.stripCommentExpressions(Util.getOption(mod.binding))));
21832183

21842184
if JSON.isNull(json) then
21852185
json := binding_json;
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// name: GetModelInstanceMod6
2+
// keywords:
3+
// status: correct
4+
// cflags: -d=newInst
5+
//
6+
//
7+
8+
loadString("
9+
model M
10+
Real x(start = 1
11+
// comment
12+
);
13+
14+
Real y(start = 2 /* comment */);
15+
end M;
16+
");
17+
18+
getModelInstance(M, prettyPrint = true);
19+
getErrorString();
20+
21+
// Result:
22+
// true
23+
// "{
24+
// \"name\": \"M\",
25+
// \"restriction\": \"model\",
26+
// \"elements\": [
27+
// {
28+
// \"$kind\": \"component\",
29+
// \"name\": \"x\",
30+
// \"type\": \"Real\",
31+
// \"modifiers\": {
32+
// \"start\": \"1\"
33+
// }
34+
// },
35+
// {
36+
// \"$kind\": \"component\",
37+
// \"name\": \"y\",
38+
// \"type\": \"Real\",
39+
// \"modifiers\": {
40+
// \"start\": \"2\"
41+
// }
42+
// }
43+
// ],
44+
// \"source\": {
45+
// \"filename\": \"<interactive>\",
46+
// \"lineStart\": 2,
47+
// \"columnStart\": 3,
48+
// \"lineEnd\": 8,
49+
// \"columnEnd\": 8
50+
// }
51+
// }"
52+
// ""
53+
// endResult

testsuite/openmodelica/instance-API/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ GetModelInstanceMod2.mos \
7070
GetModelInstanceMod3.mos \
7171
GetModelInstanceMod4.mos \
7272
GetModelInstanceMod5.mos \
73+
GetModelInstanceMod6.mos \
7374
GetModelInstanceProtected1.mos \
7475
GetModelInstanceReplaceable1.mos \
7576
GetModelInstanceReplaceable2.mos \

0 commit comments

Comments
 (0)