@@ -8,16 +8,18 @@ encapsulated package Tpl
88 $Id$
99"
1010
11- protected import Config ;
12- protected import ClockIndexes ;
13- protected import Debug ;
14- protected import Error ;
15- protected import File ;
16- protected import Flags ;
17- protected import List ;
18- protected import Print ;
19- protected import StringUtil ;
20- protected import System ;
11+ protected
12+ import Config ;
13+ import ClockIndexes ;
14+ import Debug ;
15+ import Error ;
16+ import File ;
17+ import Flags ;
18+ import List ;
19+ import Print ;
20+ import StackOverflow ;
21+ import StringUtil ;
22+ import System ;
2123
2224// indentation will be implemented through spaces
2325// where tabs will be converted where 1 tab = 4 spaces ??
@@ -1999,27 +2001,45 @@ algorithm
19992001 end match;
20002002end failIfTrue;
20012003
2002- public function tplCallWithFailErrorNoArg
2004+ protected function tplCallHandleErrors
20032005 input Tpl_Fun inFun;
20042006 input output Text txt = emptyTxt;
2007+ input Integer nArg;
20052008
20062009 partial function Tpl_Fun
20072010 input Text in_txt;
20082011 output Text out_txt;
20092012 end Tpl_Fun ;
20102013algorithm
2014+ try
20112015 try
20122016 txt := inFun(txt);
20132017 else
2014- addTemplateErrorFunc(0 , inFun);
2018+ addTemplateErrorFunc(nArg , inFun);
20152019 fail();
20162020 end try ;
2021+ else
2022+ addTemplateErrorFunc(nArg, inFun);
2023+ fail();
2024+ end try annotation(__OpenModelica_stackOverflowCheckpoint= true );
2025+ end tplCallHandleErrors;
2026+
2027+ public function tplCallWithFailErrorNoArg
2028+ input Tpl_Fun inFun;
2029+ input output Text txt = emptyTxt;
2030+
2031+ partial function Tpl_Fun
2032+ input Text in_txt;
2033+ output Text out_txt;
2034+ end Tpl_Fun ;
2035+ algorithm
2036+ txt := tplCallHandleErrors(inFun, txt, 0 );
20172037end tplCallWithFailErrorNoArg;
20182038
20192039public function tplCallWithFailError
20202040 input Tpl_Fun inFun;
20212041 input ArgType1 inArg;
2022- output Text outTxt ;
2042+ input output Text txt = emptyTxt ;
20232043
20242044 partial function Tpl_Fun
20252045 input Text in_txt;
@@ -2028,25 +2048,15 @@ public function tplCallWithFailError
20282048 end Tpl_Fun ;
20292049protected
20302050 ArgType1 arg;
2031- Text txt;
20322051algorithm
2033- outTxt := matchcontinue(inFun, inArg)
2034- case (_, arg)
2035- equation
2036- txt = inFun(emptyTxt, arg);
2037- then txt;
2038- else
2039- equation
2040- addTemplateErrorFunc(1 , inFun);
2041- then fail();
2042- end matchcontinue;
2052+ txt := tplCallHandleErrors(function inFun(inArgA= inArg), txt, 1 );
20432053end tplCallWithFailError;
20442054
20452055public function tplCallWithFailError2
20462056 input Tpl_Fun inFun;
20472057 input ArgType1 inArgA;
20482058 input ArgType2 inArgB;
2049- output Text outTxt ;
2059+ input output Text txt = emptyTxt ;
20502060
20512061 partial function Tpl_Fun
20522062 input Text in_txt;
@@ -2057,20 +2067,8 @@ public function tplCallWithFailError2
20572067protected
20582068 ArgType1 argA;
20592069 ArgType2 argB;
2060- Text txt;
20612070algorithm
2062- outTxt := matchcontinue(inFun, inArgA, inArgB)
2063- local
2064- String file,symbol;
2065- case (_, argA, argB)
2066- equation
2067- txt = inFun(emptyTxt, argA, argB);
2068- then txt;
2069- else
2070- equation
2071- addTemplateErrorFunc(2 , inFun);
2072- then fail();
2073- end matchcontinue;
2071+ txt := tplCallHandleErrors(function inFun(inArgA= inArgA, inArgB= inArgB), txt, 2 );
20742072end tplCallWithFailError2;
20752073
20762074function tplCallWithFailError3
@@ -2088,12 +2086,7 @@ function tplCallWithFailError3
20882086 output Text out_txt;
20892087 end Tpl_Fun ;
20902088algorithm
2091- try
2092- txt := inFun(txt, inArgA, inArgB, inArgC);
2093- else
2094- addTemplateErrorFunc(3 , inFun);
2095- fail();
2096- end try ;
2089+ txt := tplCallHandleErrors(function inFun(inArgA= inArgA, inArgB= inArgB, inArgC= inArgC), txt, 3 );
20972090end tplCallWithFailError3;
20982091
20992092function tplCallWithFailError4
@@ -2113,12 +2106,7 @@ function tplCallWithFailError4
21132106 output Text out_txt;
21142107 end Tpl_Fun ;
21152108algorithm
2116- try
2117- txt := func (txt, argA, argB, argC, argD);
2118- else
2119- addTemplateErrorFunc(4 , func );
2120- fail();
2121- end try ;
2109+ txt := tplCallHandleErrors(function func (inArgA= argA, inArgB= argB, inArgC= argC, inArgD= argD), txt, 4 );
21222110end tplCallWithFailError4;
21232111
21242112public function tplString
@@ -2592,5 +2580,17 @@ algorithm
25922580 end match;
25932581end handleTok;
25942582
2583+ public function debugSusan
2584+ output Boolean b;
2585+ algorithm
2586+ b := Flags . isSet(Flags . SUSAN_MATCHCONTINUE_DEBUG );
2587+ end debugSusan;
2588+
2589+ public function fakeStackOverflow
2590+ algorithm
2591+ Error . addInternalError("Stack overflow: \n " + StackOverflow . generateReadableMessage(), sourceInfo());
2592+ StackOverflow . triggerStackOverflow();
2593+ end fakeStackOverflow;
2594+
25952595annotation(__OpenModelica_Interface= "susan" );
25962596end Tpl ;
0 commit comments