Skip to content

Commit

Permalink
Susan now reports a template call failure as an error (to prevent con…
Browse files Browse the repository at this point in the history
…fusion from other reasons of failure, e.g., simulation fail)

- fortunately, it was not observed in current templates
  when some day a call of a function from within a template will fail,
  the added error message will say it happened (I've tested it will)

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@15199 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
pavolpr committed Feb 17, 2013
1 parent e3fc4eb commit c661013
Showing 1 changed file with 82 additions and 8 deletions.
90 changes: 82 additions & 8 deletions Compiler/Template/Tpl.mo
Expand Up @@ -1530,6 +1530,80 @@ algorithm
end match;
end failIfTrue;

protected function tplCallWithFailError
input Tpl_Fun inFun;
input ArgType1 inArg;
output Text outTxt;

partial function Tpl_Fun
input Text in_txt;
input ArgType1 inArgA;
output Text out_txt;
end Tpl_Fun;
algorithm
outTxt := matchcontinue(inFun, inArg)
case(inFun, inArg)
equation
outTxt = inFun(emptyTxt, inArg);
then outTxt;
else
equation
addTemplateError("A template call failed (a call with 1 parameter). One possible reason could be that a template imported function call failed (which should not happen for functions called from within template code; templates preserve pure 'match'/non-failing semantics).");
then fail();
end matchcontinue;
end tplCallWithFailError;

protected function tplCallWithFailError2
input Tpl_Fun inFun;
input ArgType1 inArgA;
input ArgType2 inArgB;
output Text outTxt;

partial function Tpl_Fun
input Text in_txt;
input ArgType1 inArgA;
input ArgType2 inArgB;
output Text out_txt;
end Tpl_Fun;
algorithm
outTxt := matchcontinue(inFun, inArgA, inArgB)
case(inFun, inArgA, inArgB)
equation
outTxt = inFun(emptyTxt, inArgA, inArgB);
then outTxt;
else
equation
addTemplateError("A template call failed (a call with 2 parameters). One possible reason could be that a template imported function call failed (which should not happen for functions called from within template code; templates preserve pure 'match'/non-failing semantics).");
then fail();
end matchcontinue;
end tplCallWithFailError2;

protected function tplCallWithFailError3
input Tpl_Fun inFun;
input ArgType1 inArgA;
input ArgType2 inArgB;
input ArgType3 inArgC;
output Text outTxt;

partial function Tpl_Fun
input Text in_txt;
input ArgType1 inArgA;
input ArgType2 inArgB;
input ArgType3 inArgC;
output Text out_txt;
end Tpl_Fun;
algorithm
outTxt := matchcontinue(inFun, inArgA, inArgB, inArgC)
case(inFun, inArgA, inArgB, inArgC)
equation
outTxt = inFun(emptyTxt, inArgA, inArgB, inArgC);
then outTxt;
else
equation
addTemplateError("A template call failed (a call with 3 parameters). One possible reason could be that a template imported function call failed (which should not happen for functions called from within template code; templates preserve pure 'match'/non-failing semantics).");
then fail();
end matchcontinue;
end tplCallWithFailError3;

public function tplString
input Tpl_Fun inFun;
Expand All @@ -1546,7 +1620,7 @@ protected
Integer nErr;
algorithm
nErr := Error.getNumErrorMessages();
txt := inFun(emptyTxt, inArg);
txt := tplCallWithFailError(inFun, inArg);
failIfTrue(Error.getNumErrorMessages() > nErr);
outString := textString(txt);
end tplString;
Expand All @@ -1568,7 +1642,7 @@ protected
Integer nErr;
algorithm
nErr := Error.getNumErrorMessages();
txt := inFun(emptyTxt, inArgA, inArgB);
txt := tplCallWithFailError2(inFun, inArgA, inArgB);
failIfTrue(Error.getNumErrorMessages() > nErr);
outString := textString(txt);
end tplString2;
Expand All @@ -1592,7 +1666,7 @@ protected
Integer nErr;
algorithm
nErr := Error.getNumErrorMessages();
txt := inFun(emptyTxt, inArgA, inArgB, inArgC);
txt := tplCallWithFailError3(inFun, inArgA, inArgB, inArgC);
failIfTrue(Error.getNumErrorMessages() > nErr);
outString := textString(txt);
end tplString3;
Expand All @@ -1611,7 +1685,7 @@ protected
Integer nErr;
algorithm
nErr := Error.getNumErrorMessages();
txt := inFun(emptyTxt, inArg);
txt := tplCallWithFailError(inFun, inArg);
failIfTrue(Error.getNumErrorMessages() > nErr);
textStringBuf(txt);
end tplPrint;
Expand All @@ -1632,7 +1706,7 @@ protected
Integer nErr;
algorithm
nErr := Error.getNumErrorMessages();
txt := inFun(emptyTxt, inArgA, inArgB);
txt := tplCallWithFailError2(inFun, inArgA, inArgB);
failIfTrue(Error.getNumErrorMessages() > nErr);
textStringBuf(txt);
end tplPrint2;
Expand All @@ -1655,7 +1729,7 @@ protected
Integer nErr;
algorithm
nErr := Error.getNumErrorMessages();
txt := inFun(emptyTxt, inArgA, inArgB, inArgC);
txt := tplCallWithFailError3(inFun, inArgA, inArgB, inArgC);
failIfTrue(Error.getNumErrorMessages() > nErr);
textStringBuf(txt);
end tplPrint3;
Expand All @@ -1675,7 +1749,7 @@ protected
Integer nErr;
algorithm
nErr := Error.getNumErrorMessages();
_ := inFun(emptyTxt, inArg, inArg2);
_ := tplCallWithFailError2(inFun, inArg, inArg2);
failIfTrue(Error.getNumErrorMessages() > nErr);
end tplNoret2;

Expand All @@ -1692,7 +1766,7 @@ protected
Integer nErr;
algorithm
nErr := Error.getNumErrorMessages();
_ := inFun(emptyTxt, inArg);
_ := tplCallWithFailError(inFun, inArg);
failIfTrue(Error.getNumErrorMessages() > nErr);
end tplNoret;

Expand Down

0 comments on commit c661013

Please sign in to comment.