Skip to content

Commit

Permalink
Fix the front-end part of ticket:4304
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
adrpo authored and OpenModelica-Hudson committed Mar 11, 2017
1 parent 9e033a1 commit b8fe184
Show file tree
Hide file tree
Showing 12 changed files with 250 additions and 20 deletions.
25 changes: 25 additions & 0 deletions Compiler/BackEnd/BackendDAECreate.mo
Expand Up @@ -495,6 +495,13 @@ algorithm
then
();

case DAE.INITIAL_ASSERT()
algorithm
(outEqns, outREqns, outIEqns) :=
lowerAlgorithm(el, inFunctions, outEqns, outREqns, outIEqns, DAE.NOT_EXPAND());
then
();

// terminate in equation section is converted to ALGORITHM
case DAE.TERMINATE()
algorithm
Expand All @@ -503,6 +510,13 @@ algorithm
then
();

case DAE.INITIAL_TERMINATE()
algorithm
(outEqns, outREqns, outIEqns) :=
lowerAlgorithm(el, inFunctions, outEqns, outREqns, outIEqns, DAE.NOT_EXPAND());
then
();

case DAE.NORETCALL()
algorithm
(outEqns, outREqns, outIEqns) :=
Expand Down Expand Up @@ -2573,14 +2587,25 @@ algorithm
case DAE.ASSERT(condition=DAE.BCONST(true))
then (inEquations, inREquations, inIEquations);

case DAE.INITIAL_ASSERT(condition=DAE.BCONST(true))
then (inEquations, inREquations, inIEquations);

case DAE.ASSERT(condition=cond, message=msg, level=level, source=source) equation
BackendDAEUtil.checkAssertCondition(cond, msg, level, ElementSource.getElementSourceFileInfo(source));
alg = DAE.ALGORITHM_STMTS({DAE.STMT_ASSERT(cond, msg, level, source)});
then (inEquations, BackendDAE.ALGORITHM(0, alg, source, inCrefExpansion, BackendDAE.EQ_ATTR_DEFAULT_DYNAMIC)::inREquations, inIEquations);

case DAE.INITIAL_ASSERT(condition=cond, message=msg, level=level, source=source) equation
BackendDAEUtil.checkAssertCondition(cond, msg, level, ElementSource.getElementSourceFileInfo(source));
alg = DAE.ALGORITHM_STMTS({DAE.STMT_ASSERT(cond, msg, level, source)});
then (inEquations, BackendDAE.ALGORITHM(0, alg, source, inCrefExpansion, BackendDAE.EQ_ATTR_DEFAULT_INITIAL)::inREquations, inIEquations);

case DAE.TERMINATE(message=msg, source=source)
then (inEquations, BackendDAE.ALGORITHM(0, DAE.ALGORITHM_STMTS({DAE.STMT_TERMINATE(msg, source)}), source, inCrefExpansion, BackendDAE.EQ_ATTR_DEFAULT_DYNAMIC)::inREquations, inIEquations);

case DAE.INITIAL_TERMINATE(message=msg, source=source)
then (inEquations, BackendDAE.ALGORITHM(0, DAE.ALGORITHM_STMTS({DAE.STMT_TERMINATE(msg, source)}), source, inCrefExpansion, BackendDAE.EQ_ATTR_DEFAULT_INITIAL)::inREquations, inIEquations);

case DAE.NORETCALL(exp=e, source=source) equation
alg = DAE.ALGORITHM_STMTS({DAE.STMT_NORETCALL(e, source)});
then (inEquations, BackendDAE.ALGORITHM(0, alg, source, inCrefExpansion, BackendDAE.EQ_ATTR_DEFAULT_DYNAMIC)::inREquations, inIEquations);
Expand Down
7 changes: 7 additions & 0 deletions Compiler/FrontEnd/CheckModel.mo
Expand Up @@ -253,10 +253,17 @@ algorithm
case DAE.ASSERT()
then inArg;

// assert in equation
case DAE.INITIAL_ASSERT()
then inArg;

// terminate in equation section is converted to ALGORITHM
case DAE.TERMINATE()
then inArg;

case DAE.INITIAL_TERMINATE()
then inArg;

case DAE.NORETCALL()
then inArg;

Expand Down
12 changes: 12 additions & 0 deletions Compiler/FrontEnd/DAE.mo
Expand Up @@ -320,11 +320,23 @@ public uniontype Element
ElementSource source "the origin of the component/equation/algorithm" ;
end ASSERT;

record INITIAL_ASSERT " The Modelica builtin assert"
Exp condition;
Exp message;
Exp level;
ElementSource source "the origin of the component/equation/algorithm" ;
end INITIAL_ASSERT;

record TERMINATE " The Modelica builtin terminate(msg)"
Exp message;
ElementSource source "the origin of the component/equation/algorithm" ;
end TERMINATE;

record INITIAL_TERMINATE " The Modelica builtin terminate(msg)"
Exp message;
ElementSource source "the origin of the component/equation/algorithm" ;
end INITIAL_TERMINATE;

record REINIT " reinit operator for reinitialization of states"
ComponentRef componentRef;
Exp exp;
Expand Down
93 changes: 80 additions & 13 deletions Compiler/FrontEnd/DAEDump.mo
Expand Up @@ -896,8 +896,10 @@ algorithm
list<DAE.Element> xs1,xs2;
list<list<DAE.Element>> trueBranches;
list<DAE.Exp> conds;
String s;
String s,s1,s2,sourceStr;
IOStream.IOStream str;
DAE.ElementSource src;
list<SCode.Comment> cmt;

case (DAE.INITIALEQUATION(exp1 = e1,exp2 = e2))
equation
Expand Down Expand Up @@ -954,6 +956,27 @@ algorithm
then
();

case (DAE.INITIAL_ASSERT(condition=e1,message = e2,source = src))
equation
cmt = ElementSource.getCommentsFromSource(src);
sourceStr = cmtListToString(cmt);
s1 = ExpressionDump.printExpStr(e1);
s2 = ExpressionDump.printExpStr(e2);
s = stringAppendList({" assert(",s1, ",",s2,") ", sourceStr, ";\n"});
Print.printBuf(s);
then
();

case (DAE.INITIAL_TERMINATE(message=e1,source = src))
equation
cmt = ElementSource.getCommentsFromSource(src);
sourceStr = cmtListToString(cmt);
s1 = ExpressionDump.printExpStr(e1);
s = stringAppendList({" terminate(",s1,") ", sourceStr, ";\n"});
Print.printBuf(s);
then
();

case (DAE.INITIAL_NORETCALL(exp = e1))
equation
ExpressionDump.printExp(e1);
Expand Down Expand Up @@ -2156,13 +2179,29 @@ algorithm
Print.printBuf(")");
then
();
case DAE.INITIAL_ASSERT(condition = e1,message = e2)
equation
Print.printBuf("INITIAL_ASSERT(");
ExpressionDump.printExp(e1);
Print.printBuf(",");
ExpressionDump.printExp(e2);
Print.printBuf(")");
then
();
case DAE.TERMINATE(message = e1)
equation
Print.printBuf("TERMINATE(");
ExpressionDump.printExp(e1);
Print.printBuf(")");
then
();
case DAE.INITIAL_TERMINATE(message = e1)
equation
Print.printBuf("INITIAL_TERMINATE(");
ExpressionDump.printExp(e1);
Print.printBuf(")");
then
();
case DAE.REINIT()
equation
Print.printBuf("REINIT()");
Expand Down Expand Up @@ -2935,17 +2974,6 @@ algorithm
then
str;

case ((DAE.ASSERT(condition=e1, message = e2, level = e3, source = src) :: xs), str)
equation
sourceStr = getSourceInformationStr(src);
s1 = ExpressionDump.printExpStr(e1);
s2 = ExpressionDump.printExpStr(e2);
s3 = ExpressionDump.printExpStr(e3);
str = IOStream.appendList(str, {" assert(",s1,",",s2,",",s3,")",sourceStr,";\n"});
str = dumpEquationsStream(xs, str);
then
str;

case (DAE.TERMINATE(message=e1, source = src) :: xs, str)
equation
sourceStr = getSourceInformationStr(src);
Expand Down Expand Up @@ -3075,13 +3103,14 @@ protected function dumpInitialEquationsStream "Dump initial equations to a strea
algorithm
outStream := matchcontinue (inElementLst, inStream)
local
String s1,s2;
String s1,s2,sourceStr;
DAE.Exp e1,e2,e;
list<DAE.Element> xs,xs1,xs2;
list<list<DAE.Element>> trueBranches;
DAE.ComponentRef c;
IOStream.IOStream str;
list<DAE.Exp> conds;
DAE.ElementSource src;

case ({}, str) then str;

Expand Down Expand Up @@ -3143,6 +3172,25 @@ algorithm
then
str;

case ((DAE.INITIAL_ASSERT(condition=e1, message = e2, level = DAE.ENUM_LITERAL(index=1), source = src) :: xs), str)
equation
sourceStr = getSourceInformationStr(src);
s1 = ExpressionDump.printExpStr(e1);
s2 = ExpressionDump.printExpStr(e2);
str = IOStream.appendList(str, {" assert(",s1,",",s2,")", sourceStr, ";\n"});
str = dumpEquationsStream(xs, str);
then
str;

case (DAE.INITIAL_TERMINATE(message=e1, source = src) :: xs, str)
equation
sourceStr = getSourceInformationStr(src);
s1 = ExpressionDump.printExpStr(e1);
str = IOStream.appendList(str, {" terminate(",s1,")", sourceStr, ";\n"});
str = dumpEquationsStream(xs, str);
then
str;

case ((_ :: xs), str)
equation
str = dumpInitialEquationsStream(xs, str);
Expand Down Expand Up @@ -3888,6 +3936,16 @@ algorithm
then
str;

case (DAE.INITIAL_ASSERT(condition=e1,message = e2,source = src))
equation
cmt = ElementSource.getCommentsFromSource(src);
sourceStr = cmtListToString(cmt);
s1 = ExpressionDump.printExpStr(e1);
s2 = ExpressionDump.printExpStr(e2);
str = stringAppendList({" /* initial */ assert(",s1, ",",s2,") ", sourceStr, ";\n"});
then
str;

case (DAE.TERMINATE(message=e1,source = src))
equation
cmt = ElementSource.getCommentsFromSource(src);
Expand All @@ -3897,6 +3955,15 @@ algorithm
then
str;

case (DAE.INITIAL_TERMINATE(message=e1,source = src))
equation
cmt = ElementSource.getCommentsFromSource(src);
sourceStr = cmtListToString(cmt);
s1 = ExpressionDump.printExpStr(e1);
str = stringAppendList({" /* initial */ terminate(",s1,") ", sourceStr, ";\n"});
then
str;

case (DAE.REINIT(source = src))
equation
cmt = ElementSource.getCommentsFromSource(src);
Expand Down
62 changes: 58 additions & 4 deletions Compiler/FrontEnd/DAEUtil.mo
Expand Up @@ -449,11 +449,21 @@ algorithm
(DAE.DAE(elts2),DAE.DAE(elts3)) = splitDAEIntoVarsAndEquations(DAE.DAE(elts));
then (DAE.DAE(elts2),DAE.DAE(e::elts3));

case(DAE.DAE((e as DAE.INITIAL_ASSERT())::elts))
equation
(DAE.DAE(elts2),DAE.DAE(elts3)) = splitDAEIntoVarsAndEquations(DAE.DAE(elts));
then (DAE.DAE(elts2),DAE.DAE(e::elts3));

case(DAE.DAE((e as DAE.TERMINATE())::elts))
equation
(DAE.DAE(elts2),DAE.DAE(elts3)) = splitDAEIntoVarsAndEquations(DAE.DAE(elts));
then (DAE.DAE(elts2),DAE.DAE(e::elts3));

case(DAE.DAE((e as DAE.INITIAL_TERMINATE())::elts))
equation
(DAE.DAE(elts2),DAE.DAE(elts3)) = splitDAEIntoVarsAndEquations(DAE.DAE(elts));
then (DAE.DAE(elts2),DAE.DAE(e::elts3));

case(DAE.DAE((e as DAE.REINIT())::elts))
equation
(DAE.DAE(elts2),DAE.DAE(elts3)) = splitDAEIntoVarsAndEquations(DAE.DAE(elts));
Expand Down Expand Up @@ -2435,12 +2445,29 @@ algorithm
e_3 = toModelicaFormExp(e3);
then
(DAE.ASSERT(e_1,e_2,e_3,source)::elts_1);

case ((DAE.INITIAL_ASSERT(condition = e1,message=e2,level=e3,source = source)::elts))
equation
elts_1 = toModelicaFormElts(elts);
e_1 = toModelicaFormExp(e1);
e_2 = toModelicaFormExp(e2);
e_3 = toModelicaFormExp(e3);
then
(DAE.INITIAL_ASSERT(e_1,e_2,e_3,source)::elts_1);

case ((DAE.TERMINATE(message = e1,source = source)::elts))
equation
elts_1 = toModelicaFormElts(elts);
e_1 = toModelicaFormExp(e1);
then
(DAE.TERMINATE(e_1,source)::elts_1);

case ((DAE.INITIAL_TERMINATE(message = e1,source = source)::elts))
equation
elts_1 = toModelicaFormElts(elts);
e_1 = toModelicaFormExp(e1);
then
(DAE.INITIAL_TERMINATE(e_1,source)::elts_1);
end match;
end toModelicaFormElts;

Expand Down Expand Up @@ -4137,13 +4164,31 @@ algorithm
then
();

case DAE.INITIAL_ASSERT(condition = e1, message = e2, level = e3)
algorithm
(new_e1, arg) := func(e1, arg);
if not referenceEq(e1, new_e1) then element.condition := new_e1; end if;
(new_e2, arg) := func(e2, arg);
if not referenceEq(e2, new_e2) then element.message := new_e2; end if;
(new_e3, arg) := func(e3, arg);
if not referenceEq(e3, new_e3) then element.level := new_e3; end if;
then
();

case DAE.TERMINATE(message = e1)
algorithm
(new_e1, arg) := func(e1, arg);
if not referenceEq(e1, new_e1) then element.message := new_e1; end if;
then
();

case DAE.INITIAL_TERMINATE(message = e1)
algorithm
(new_e1, arg) := func(e1, arg);
if not referenceEq(e1, new_e1) then element.message := new_e1; end if;
then
();

case DAE.NORETCALL(exp = e1)
algorithm
(new_e1, arg) := func(e1, arg);
Expand Down Expand Up @@ -5051,6 +5096,7 @@ algorithm
_ := match e
case DAE.VAR()
algorithm variables := e :: variables; then ();

case DAE.INITIALEQUATION()
algorithm initialEquations := e :: initialEquations; then ();
case DAE.INITIAL_ARRAY_EQUATION()
Expand All @@ -5061,6 +5107,15 @@ algorithm
algorithm initialEquations := e :: initialEquations; then ();
case DAE.INITIAL_IF_EQUATION()
algorithm initialEquations := e :: initialEquations; then ();
case DAE.INITIAL_ASSERT()
algorithm initialEquations := e :: initialEquations; then ();
case DAE.INITIAL_TERMINATE()
algorithm initialEquations := e :: initialEquations; then ();
case DAE.INITIAL_NORETCALL()
algorithm initialEquations := e :: initialEquations; then ();
case DAE.INITIALALGORITHM()
algorithm initialAlgorithms := e :: initialAlgorithms; then ();

case DAE.EQUATION()
algorithm equations := e :: equations; then ();
case DAE.EQUEQUATION()
Expand All @@ -5073,6 +5128,8 @@ algorithm
algorithm equations := e :: equations; then ();
case DAE.ASSERT()
algorithm equations := e :: equations; then ();
case DAE.TERMINATE()
algorithm equations := e :: equations; then ();
case DAE.IF_EQUATION()
algorithm equations := e :: equations; then ();
case DAE.WHEN_EQUATION()
Expand All @@ -5081,10 +5138,7 @@ algorithm
algorithm equations := e :: equations; then ();
case DAE.NORETCALL()
algorithm equations := e :: equations; then ();
case DAE.INITIAL_NORETCALL()
algorithm initialEquations := e :: initialEquations; then ();
case DAE.INITIALALGORITHM()
algorithm initialAlgorithms := e :: initialAlgorithms; then ();

case DAE.ALGORITHM()
algorithm algorithms := e :: algorithms; then ();
case DAE.CONSTRAINT()
Expand Down
2 changes: 2 additions & 0 deletions Compiler/FrontEnd/ElementSource.mo
Expand Up @@ -372,7 +372,9 @@ algorithm
case DAE.COMP() then element.source;
case DAE.EXTOBJECTCLASS() then element.source;
case DAE.ASSERT() then element.source;
case DAE.INITIAL_ASSERT() then element.source;
case DAE.TERMINATE() then element.source;
case DAE.INITIAL_TERMINATE() then element.source;
case DAE.REINIT() then element.source;
case DAE.NORETCALL() then element.source;
case DAE.CONSTRAINT() then element.source;
Expand Down

0 comments on commit b8fe184

Please sign in to comment.