Skip to content

Commit

Permalink
- added templateError() imported function
Browse files Browse the repository at this point in the history
  to be used inside templates to report an "unexpected template error", 
  usage is like this:
  
  match arg
  case pattern  then << a template ... >>
  case pattern2 then << a template ... >>
  else templateError("unknown case in this template")

  templates still won't fail, but the call to
  


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@8232 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
pavolpr committed Mar 15, 2011
1 parent c7a71fb commit f7550cf
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 4 deletions.
30 changes: 30 additions & 0 deletions Compiler/BackEnd/SimCode.mo
Expand Up @@ -817,6 +817,36 @@ algorithm
outEqn := listAppend(inEqn1,inEqn2);
end appendLists;


//TODO: ?? should this function be in Tpl.mo ?
public function templateError
"Reports a template error via the Error module."
input String inErrMsg;
output String outErrMsg;

algorithm
outErrMsg := matchcontinue (inErrMsg)
local
String errmsg;
case (inErrMsg)
equation
errmsg = "TemplateError '" +& inErrMsg +& "'";
//TODO: create a special category for this error ... Error.TEMPLATE_ERROR
Error.addMessage(Error.INTERNAL_ERROR, {errmsg});
errmsg = "###>>> " +& errmsg +& " <<<###"; //to be output in the generated code
then
errmsg;

case (_)
equation
Debug.fprint("failtrace", "-!!!Tpl.textFile failed - a system error ?\n");
then
fail();

end matchcontinue;
end templateError;


/** end of TypeView published functions **/


Expand Down
47 changes: 43 additions & 4 deletions Compiler/Template/Tpl.mo
Expand Up @@ -7,7 +7,7 @@ protected import System;
protected import Util;
protected import Print;
protected import CevalScript;

protected import Error;


// indentation will be implemented through spaces
Expand Down Expand Up @@ -90,6 +90,22 @@ uniontype IterOptions
StringToken wrapSeparator;
end ITER_OPTIONS;
end IterOptions;


uniontype SourceInfo "
The _sourceinfo_ type ... source location information.
It is copied from Absyn.Info (for now) to prevent direct dependency from Absyn to Tpl and TplAbsyn,
perhaps, it will be changed to Absyn.Info in the future (easy to do then)."
record SOURCE_INFO
String fileName;
//Boolean isReadOnly "isReadOnly : (true|false). Should be true for libraries" ;
Integer lineNumberStart;
Integer columnNumberStart;
Integer lineNumberEnd;
Integer columnNumberEnd ;
//TimeStamp buildTimes "Build and edit times";
end SOURCE_INFO;
end SourceInfo;

//by default, we will parse new lines in every non-token string
public function writeStr
Expand Down Expand Up @@ -1512,6 +1528,15 @@ algorithm
outString := textString( MEM_TEXT({inStringToken},{}) );
end strTokString;

protected function failIfTrue
input Boolean istrue;
algorithm
_ := matchcontinue istrue
case ( false ) then ();
case ( _ ) then fail();
end matchcontinue;
end failIfTrue;


public function tplString
input Tpl_Fun inFun;
Expand All @@ -1527,8 +1552,11 @@ public function tplString
replaceable type Type_a subtypeof Any;
protected
Text txt;
Integer nErr;
algorithm
nErr := Error.getNumErrorMessages();
txt := inFun(emptyTxt, inArg);
failIfTrue(Error.getNumErrorMessages() > nErr);
outString := textString(txt);
end tplString;

Expand All @@ -1550,8 +1578,11 @@ public function tplString2
replaceable type Type_b subtypeof Any;
protected
Text txt;
Integer nErr;
algorithm
nErr := Error.getNumErrorMessages();
txt := inFun(emptyTxt, inArgA, inArgB);
failIfTrue(Error.getNumErrorMessages() > nErr);
outString := textString(txt);
end tplString2;

Expand All @@ -1577,11 +1608,16 @@ public function tplString3
replaceable type Type_c subtypeof Any;
protected
Text txt;
Integer nErr;
algorithm
nErr := Error.getNumErrorMessages();
txt := inFun(emptyTxt, inArgA, inArgB, inArgC);
failIfTrue(Error.getNumErrorMessages() > nErr);
outString := textString(txt);
end tplString3;



public function tplNoret
input Tpl_Fun inFun;
input Type_a inArg;
Expand All @@ -1592,9 +1628,13 @@ public function tplNoret
output Text out_txt;
replaceable type Type_a subtypeof Any;
end Tpl_Fun;
replaceable type Type_a subtypeof Any;
replaceable type Type_a subtypeof Any;
protected
Integer nErr;
algorithm
_ := inFun(emptyTxt, inArg);
nErr := Error.getNumErrorMessages();
_ := inFun(emptyTxt, inArg);
failIfTrue(Error.getNumErrorMessages() > nErr);
end tplNoret;


Expand Down Expand Up @@ -1642,5 +1682,4 @@ algorithm
end textFile;



end Tpl;
3 changes: 3 additions & 0 deletions Compiler/Template/TplAbsyn.mo
Expand Up @@ -63,6 +63,8 @@ uniontype TypeSignature
end UNRESOLVED_TYPE;
end TypeSignature;

type SourceInfo = Tpl.SourceInfo;
/*
uniontype SourceInfo
record SOURCE_INFO
String fileName;
Expand All @@ -74,6 +76,7 @@ uniontype SourceInfo
//TimeStamp buildTimes "Build and edit times";
end SOURCE_INFO;
end SourceInfo;
*/

public
uniontype Expression
Expand Down
7 changes: 7 additions & 0 deletions Compiler/susan_codegen/SimCode/SimCodeTV.mo
Expand Up @@ -487,6 +487,13 @@ package SimCode
input Integer i;
output String s;
end twodigit;

function templateError
"Reports a template error via the Error module."
input String inErrMsg;
output String outErrMsg;
end templateError;

end SimCode;


Expand Down

0 comments on commit f7550cf

Please sign in to comment.