Skip to content

Commit b8fe184

Browse files
adrpoOpenModelica-Hudson
authored andcommitted
Fix the front-end part of ticket:4304
- add new DAE.INITIAL_ASSERT and handle it in the front-end - add new DAE.INITIAL_TERMINATE and handle it in the front-end - added preliminary back-end handling
1 parent 9e033a1 commit b8fe184

File tree

12 files changed

+250
-20
lines changed

12 files changed

+250
-20
lines changed

Compiler/BackEnd/BackendDAECreate.mo

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,13 @@ algorithm
495495
then
496496
();
497497

498+
case DAE.INITIAL_ASSERT()
499+
algorithm
500+
(outEqns, outREqns, outIEqns) :=
501+
lowerAlgorithm(el, inFunctions, outEqns, outREqns, outIEqns, DAE.NOT_EXPAND());
502+
then
503+
();
504+
498505
// terminate in equation section is converted to ALGORITHM
499506
case DAE.TERMINATE()
500507
algorithm
@@ -503,6 +510,13 @@ algorithm
503510
then
504511
();
505512

513+
case DAE.INITIAL_TERMINATE()
514+
algorithm
515+
(outEqns, outREqns, outIEqns) :=
516+
lowerAlgorithm(el, inFunctions, outEqns, outREqns, outIEqns, DAE.NOT_EXPAND());
517+
then
518+
();
519+
506520
case DAE.NORETCALL()
507521
algorithm
508522
(outEqns, outREqns, outIEqns) :=
@@ -2573,14 +2587,25 @@ algorithm
25732587
case DAE.ASSERT(condition=DAE.BCONST(true))
25742588
then (inEquations, inREquations, inIEquations);
25752589

2590+
case DAE.INITIAL_ASSERT(condition=DAE.BCONST(true))
2591+
then (inEquations, inREquations, inIEquations);
2592+
25762593
case DAE.ASSERT(condition=cond, message=msg, level=level, source=source) equation
25772594
BackendDAEUtil.checkAssertCondition(cond, msg, level, ElementSource.getElementSourceFileInfo(source));
25782595
alg = DAE.ALGORITHM_STMTS({DAE.STMT_ASSERT(cond, msg, level, source)});
25792596
then (inEquations, BackendDAE.ALGORITHM(0, alg, source, inCrefExpansion, BackendDAE.EQ_ATTR_DEFAULT_DYNAMIC)::inREquations, inIEquations);
25802597

2598+
case DAE.INITIAL_ASSERT(condition=cond, message=msg, level=level, source=source) equation
2599+
BackendDAEUtil.checkAssertCondition(cond, msg, level, ElementSource.getElementSourceFileInfo(source));
2600+
alg = DAE.ALGORITHM_STMTS({DAE.STMT_ASSERT(cond, msg, level, source)});
2601+
then (inEquations, BackendDAE.ALGORITHM(0, alg, source, inCrefExpansion, BackendDAE.EQ_ATTR_DEFAULT_INITIAL)::inREquations, inIEquations);
2602+
25812603
case DAE.TERMINATE(message=msg, source=source)
25822604
then (inEquations, BackendDAE.ALGORITHM(0, DAE.ALGORITHM_STMTS({DAE.STMT_TERMINATE(msg, source)}), source, inCrefExpansion, BackendDAE.EQ_ATTR_DEFAULT_DYNAMIC)::inREquations, inIEquations);
25832605

2606+
case DAE.INITIAL_TERMINATE(message=msg, source=source)
2607+
then (inEquations, BackendDAE.ALGORITHM(0, DAE.ALGORITHM_STMTS({DAE.STMT_TERMINATE(msg, source)}), source, inCrefExpansion, BackendDAE.EQ_ATTR_DEFAULT_INITIAL)::inREquations, inIEquations);
2608+
25842609
case DAE.NORETCALL(exp=e, source=source) equation
25852610
alg = DAE.ALGORITHM_STMTS({DAE.STMT_NORETCALL(e, source)});
25862611
then (inEquations, BackendDAE.ALGORITHM(0, alg, source, inCrefExpansion, BackendDAE.EQ_ATTR_DEFAULT_DYNAMIC)::inREquations, inIEquations);

Compiler/FrontEnd/CheckModel.mo

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,10 +253,17 @@ algorithm
253253
case DAE.ASSERT()
254254
then inArg;
255255

256+
// assert in equation
257+
case DAE.INITIAL_ASSERT()
258+
then inArg;
259+
256260
// terminate in equation section is converted to ALGORITHM
257261
case DAE.TERMINATE()
258262
then inArg;
259263

264+
case DAE.INITIAL_TERMINATE()
265+
then inArg;
266+
260267
case DAE.NORETCALL()
261268
then inArg;
262269

Compiler/FrontEnd/DAE.mo

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,11 +320,23 @@ public uniontype Element
320320
ElementSource source "the origin of the component/equation/algorithm" ;
321321
end ASSERT;
322322

323+
record INITIAL_ASSERT " The Modelica builtin assert"
324+
Exp condition;
325+
Exp message;
326+
Exp level;
327+
ElementSource source "the origin of the component/equation/algorithm" ;
328+
end INITIAL_ASSERT;
329+
323330
record TERMINATE " The Modelica builtin terminate(msg)"
324331
Exp message;
325332
ElementSource source "the origin of the component/equation/algorithm" ;
326333
end TERMINATE;
327334

335+
record INITIAL_TERMINATE " The Modelica builtin terminate(msg)"
336+
Exp message;
337+
ElementSource source "the origin of the component/equation/algorithm" ;
338+
end INITIAL_TERMINATE;
339+
328340
record REINIT " reinit operator for reinitialization of states"
329341
ComponentRef componentRef;
330342
Exp exp;

Compiler/FrontEnd/DAEDump.mo

Lines changed: 80 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -896,8 +896,10 @@ algorithm
896896
list<DAE.Element> xs1,xs2;
897897
list<list<DAE.Element>> trueBranches;
898898
list<DAE.Exp> conds;
899-
String s;
899+
String s,s1,s2,sourceStr;
900900
IOStream.IOStream str;
901+
DAE.ElementSource src;
902+
list<SCode.Comment> cmt;
901903

902904
case (DAE.INITIALEQUATION(exp1 = e1,exp2 = e2))
903905
equation
@@ -954,6 +956,27 @@ algorithm
954956
then
955957
();
956958

959+
case (DAE.INITIAL_ASSERT(condition=e1,message = e2,source = src))
960+
equation
961+
cmt = ElementSource.getCommentsFromSource(src);
962+
sourceStr = cmtListToString(cmt);
963+
s1 = ExpressionDump.printExpStr(e1);
964+
s2 = ExpressionDump.printExpStr(e2);
965+
s = stringAppendList({" assert(",s1, ",",s2,") ", sourceStr, ";\n"});
966+
Print.printBuf(s);
967+
then
968+
();
969+
970+
case (DAE.INITIAL_TERMINATE(message=e1,source = src))
971+
equation
972+
cmt = ElementSource.getCommentsFromSource(src);
973+
sourceStr = cmtListToString(cmt);
974+
s1 = ExpressionDump.printExpStr(e1);
975+
s = stringAppendList({" terminate(",s1,") ", sourceStr, ";\n"});
976+
Print.printBuf(s);
977+
then
978+
();
979+
957980
case (DAE.INITIAL_NORETCALL(exp = e1))
958981
equation
959982
ExpressionDump.printExp(e1);
@@ -2156,13 +2179,29 @@ algorithm
21562179
Print.printBuf(")");
21572180
then
21582181
();
2182+
case DAE.INITIAL_ASSERT(condition = e1,message = e2)
2183+
equation
2184+
Print.printBuf("INITIAL_ASSERT(");
2185+
ExpressionDump.printExp(e1);
2186+
Print.printBuf(",");
2187+
ExpressionDump.printExp(e2);
2188+
Print.printBuf(")");
2189+
then
2190+
();
21592191
case DAE.TERMINATE(message = e1)
21602192
equation
21612193
Print.printBuf("TERMINATE(");
21622194
ExpressionDump.printExp(e1);
21632195
Print.printBuf(")");
21642196
then
21652197
();
2198+
case DAE.INITIAL_TERMINATE(message = e1)
2199+
equation
2200+
Print.printBuf("INITIAL_TERMINATE(");
2201+
ExpressionDump.printExp(e1);
2202+
Print.printBuf(")");
2203+
then
2204+
();
21662205
case DAE.REINIT()
21672206
equation
21682207
Print.printBuf("REINIT()");
@@ -2935,17 +2974,6 @@ algorithm
29352974
then
29362975
str;
29372976

2938-
case ((DAE.ASSERT(condition=e1, message = e2, level = e3, source = src) :: xs), str)
2939-
equation
2940-
sourceStr = getSourceInformationStr(src);
2941-
s1 = ExpressionDump.printExpStr(e1);
2942-
s2 = ExpressionDump.printExpStr(e2);
2943-
s3 = ExpressionDump.printExpStr(e3);
2944-
str = IOStream.appendList(str, {" assert(",s1,",",s2,",",s3,")",sourceStr,";\n"});
2945-
str = dumpEquationsStream(xs, str);
2946-
then
2947-
str;
2948-
29492977
case (DAE.TERMINATE(message=e1, source = src) :: xs, str)
29502978
equation
29512979
sourceStr = getSourceInformationStr(src);
@@ -3075,13 +3103,14 @@ protected function dumpInitialEquationsStream "Dump initial equations to a strea
30753103
algorithm
30763104
outStream := matchcontinue (inElementLst, inStream)
30773105
local
3078-
String s1,s2;
3106+
String s1,s2,sourceStr;
30793107
DAE.Exp e1,e2,e;
30803108
list<DAE.Element> xs,xs1,xs2;
30813109
list<list<DAE.Element>> trueBranches;
30823110
DAE.ComponentRef c;
30833111
IOStream.IOStream str;
30843112
list<DAE.Exp> conds;
3113+
DAE.ElementSource src;
30853114

30863115
case ({}, str) then str;
30873116

@@ -3143,6 +3172,25 @@ algorithm
31433172
then
31443173
str;
31453174

3175+
case ((DAE.INITIAL_ASSERT(condition=e1, message = e2, level = DAE.ENUM_LITERAL(index=1), source = src) :: xs), str)
3176+
equation
3177+
sourceStr = getSourceInformationStr(src);
3178+
s1 = ExpressionDump.printExpStr(e1);
3179+
s2 = ExpressionDump.printExpStr(e2);
3180+
str = IOStream.appendList(str, {" assert(",s1,",",s2,")", sourceStr, ";\n"});
3181+
str = dumpEquationsStream(xs, str);
3182+
then
3183+
str;
3184+
3185+
case (DAE.INITIAL_TERMINATE(message=e1, source = src) :: xs, str)
3186+
equation
3187+
sourceStr = getSourceInformationStr(src);
3188+
s1 = ExpressionDump.printExpStr(e1);
3189+
str = IOStream.appendList(str, {" terminate(",s1,")", sourceStr, ";\n"});
3190+
str = dumpEquationsStream(xs, str);
3191+
then
3192+
str;
3193+
31463194
case ((_ :: xs), str)
31473195
equation
31483196
str = dumpInitialEquationsStream(xs, str);
@@ -3888,6 +3936,16 @@ algorithm
38883936
then
38893937
str;
38903938

3939+
case (DAE.INITIAL_ASSERT(condition=e1,message = e2,source = src))
3940+
equation
3941+
cmt = ElementSource.getCommentsFromSource(src);
3942+
sourceStr = cmtListToString(cmt);
3943+
s1 = ExpressionDump.printExpStr(e1);
3944+
s2 = ExpressionDump.printExpStr(e2);
3945+
str = stringAppendList({" /* initial */ assert(",s1, ",",s2,") ", sourceStr, ";\n"});
3946+
then
3947+
str;
3948+
38913949
case (DAE.TERMINATE(message=e1,source = src))
38923950
equation
38933951
cmt = ElementSource.getCommentsFromSource(src);
@@ -3897,6 +3955,15 @@ algorithm
38973955
then
38983956
str;
38993957

3958+
case (DAE.INITIAL_TERMINATE(message=e1,source = src))
3959+
equation
3960+
cmt = ElementSource.getCommentsFromSource(src);
3961+
sourceStr = cmtListToString(cmt);
3962+
s1 = ExpressionDump.printExpStr(e1);
3963+
str = stringAppendList({" /* initial */ terminate(",s1,") ", sourceStr, ";\n"});
3964+
then
3965+
str;
3966+
39003967
case (DAE.REINIT(source = src))
39013968
equation
39023969
cmt = ElementSource.getCommentsFromSource(src);

Compiler/FrontEnd/DAEUtil.mo

Lines changed: 58 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -449,11 +449,21 @@ algorithm
449449
(DAE.DAE(elts2),DAE.DAE(elts3)) = splitDAEIntoVarsAndEquations(DAE.DAE(elts));
450450
then (DAE.DAE(elts2),DAE.DAE(e::elts3));
451451

452+
case(DAE.DAE((e as DAE.INITIAL_ASSERT())::elts))
453+
equation
454+
(DAE.DAE(elts2),DAE.DAE(elts3)) = splitDAEIntoVarsAndEquations(DAE.DAE(elts));
455+
then (DAE.DAE(elts2),DAE.DAE(e::elts3));
456+
452457
case(DAE.DAE((e as DAE.TERMINATE())::elts))
453458
equation
454459
(DAE.DAE(elts2),DAE.DAE(elts3)) = splitDAEIntoVarsAndEquations(DAE.DAE(elts));
455460
then (DAE.DAE(elts2),DAE.DAE(e::elts3));
456461

462+
case(DAE.DAE((e as DAE.INITIAL_TERMINATE())::elts))
463+
equation
464+
(DAE.DAE(elts2),DAE.DAE(elts3)) = splitDAEIntoVarsAndEquations(DAE.DAE(elts));
465+
then (DAE.DAE(elts2),DAE.DAE(e::elts3));
466+
457467
case(DAE.DAE((e as DAE.REINIT())::elts))
458468
equation
459469
(DAE.DAE(elts2),DAE.DAE(elts3)) = splitDAEIntoVarsAndEquations(DAE.DAE(elts));
@@ -2435,12 +2445,29 @@ algorithm
24352445
e_3 = toModelicaFormExp(e3);
24362446
then
24372447
(DAE.ASSERT(e_1,e_2,e_3,source)::elts_1);
2448+
2449+
case ((DAE.INITIAL_ASSERT(condition = e1,message=e2,level=e3,source = source)::elts))
2450+
equation
2451+
elts_1 = toModelicaFormElts(elts);
2452+
e_1 = toModelicaFormExp(e1);
2453+
e_2 = toModelicaFormExp(e2);
2454+
e_3 = toModelicaFormExp(e3);
2455+
then
2456+
(DAE.INITIAL_ASSERT(e_1,e_2,e_3,source)::elts_1);
2457+
24382458
case ((DAE.TERMINATE(message = e1,source = source)::elts))
24392459
equation
24402460
elts_1 = toModelicaFormElts(elts);
24412461
e_1 = toModelicaFormExp(e1);
24422462
then
24432463
(DAE.TERMINATE(e_1,source)::elts_1);
2464+
2465+
case ((DAE.INITIAL_TERMINATE(message = e1,source = source)::elts))
2466+
equation
2467+
elts_1 = toModelicaFormElts(elts);
2468+
e_1 = toModelicaFormExp(e1);
2469+
then
2470+
(DAE.INITIAL_TERMINATE(e_1,source)::elts_1);
24442471
end match;
24452472
end toModelicaFormElts;
24462473

@@ -4137,13 +4164,31 @@ algorithm
41374164
then
41384165
();
41394166

4167+
case DAE.INITIAL_ASSERT(condition = e1, message = e2, level = e3)
4168+
algorithm
4169+
(new_e1, arg) := func(e1, arg);
4170+
if not referenceEq(e1, new_e1) then element.condition := new_e1; end if;
4171+
(new_e2, arg) := func(e2, arg);
4172+
if not referenceEq(e2, new_e2) then element.message := new_e2; end if;
4173+
(new_e3, arg) := func(e3, arg);
4174+
if not referenceEq(e3, new_e3) then element.level := new_e3; end if;
4175+
then
4176+
();
4177+
41404178
case DAE.TERMINATE(message = e1)
41414179
algorithm
41424180
(new_e1, arg) := func(e1, arg);
41434181
if not referenceEq(e1, new_e1) then element.message := new_e1; end if;
41444182
then
41454183
();
41464184

4185+
case DAE.INITIAL_TERMINATE(message = e1)
4186+
algorithm
4187+
(new_e1, arg) := func(e1, arg);
4188+
if not referenceEq(e1, new_e1) then element.message := new_e1; end if;
4189+
then
4190+
();
4191+
41474192
case DAE.NORETCALL(exp = e1)
41484193
algorithm
41494194
(new_e1, arg) := func(e1, arg);
@@ -5051,6 +5096,7 @@ algorithm
50515096
_ := match e
50525097
case DAE.VAR()
50535098
algorithm variables := e :: variables; then ();
5099+
50545100
case DAE.INITIALEQUATION()
50555101
algorithm initialEquations := e :: initialEquations; then ();
50565102
case DAE.INITIAL_ARRAY_EQUATION()
@@ -5061,6 +5107,15 @@ algorithm
50615107
algorithm initialEquations := e :: initialEquations; then ();
50625108
case DAE.INITIAL_IF_EQUATION()
50635109
algorithm initialEquations := e :: initialEquations; then ();
5110+
case DAE.INITIAL_ASSERT()
5111+
algorithm initialEquations := e :: initialEquations; then ();
5112+
case DAE.INITIAL_TERMINATE()
5113+
algorithm initialEquations := e :: initialEquations; then ();
5114+
case DAE.INITIAL_NORETCALL()
5115+
algorithm initialEquations := e :: initialEquations; then ();
5116+
case DAE.INITIALALGORITHM()
5117+
algorithm initialAlgorithms := e :: initialAlgorithms; then ();
5118+
50645119
case DAE.EQUATION()
50655120
algorithm equations := e :: equations; then ();
50665121
case DAE.EQUEQUATION()
@@ -5073,6 +5128,8 @@ algorithm
50735128
algorithm equations := e :: equations; then ();
50745129
case DAE.ASSERT()
50755130
algorithm equations := e :: equations; then ();
5131+
case DAE.TERMINATE()
5132+
algorithm equations := e :: equations; then ();
50765133
case DAE.IF_EQUATION()
50775134
algorithm equations := e :: equations; then ();
50785135
case DAE.WHEN_EQUATION()
@@ -5081,10 +5138,7 @@ algorithm
50815138
algorithm equations := e :: equations; then ();
50825139
case DAE.NORETCALL()
50835140
algorithm equations := e :: equations; then ();
5084-
case DAE.INITIAL_NORETCALL()
5085-
algorithm initialEquations := e :: initialEquations; then ();
5086-
case DAE.INITIALALGORITHM()
5087-
algorithm initialAlgorithms := e :: initialAlgorithms; then ();
5141+
50885142
case DAE.ALGORITHM()
50895143
algorithm algorithms := e :: algorithms; then ();
50905144
case DAE.CONSTRAINT()

Compiler/FrontEnd/ElementSource.mo

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,9 @@ algorithm
372372
case DAE.COMP() then element.source;
373373
case DAE.EXTOBJECTCLASS() then element.source;
374374
case DAE.ASSERT() then element.source;
375+
case DAE.INITIAL_ASSERT() then element.source;
375376
case DAE.TERMINATE() then element.source;
377+
case DAE.INITIAL_TERMINATE() then element.source;
376378
case DAE.REINIT() then element.source;
377379
case DAE.NORETCALL() then element.source;
378380
case DAE.CONSTRAINT() then element.source;

0 commit comments

Comments
 (0)