@@ -80,6 +80,7 @@ import ExpressionSimplify;
8080import FBuiltin;
8181import Flags;
8282import FGraph;
83+ import GC;
8384import GlobalScriptDump;
8485import GlobalScriptUtil;
8586import InnerOuter;
@@ -94,6 +95,7 @@ import Parser;
9495import Prefix;
9596import Print;
9697import Refactor;
98+ import StackOverflow;
9799import Static;
98100import StaticScript;
99101import StringUtil;
@@ -322,19 +324,22 @@ public function evaluate2
322324"Helper function to evaluate."
323325 input GlobalScript.Statements inStatements;
324326 output String outString;
327+ protected
328+ GlobalScript.Statement stmt;
329+ String str, str_1;
325330algorithm
326- outString := matchcontinue inStatements
331+ GlobalScript.ISTMTS(interactiveStmtLst = {stmt}) := inStatements;
332+ try /* Stack overflow */
333+ outString := matchcontinue stmt
327334 local
328- String str,str_1;
329- GlobalScript.Statements stmts;
330335 Absyn.AlgorithmItem algitem;
331336 Boolean outres;
332337 Absyn.Exp exp;
333338 Boolean partialInst, gen, evalfunc, keepArrays;
334339 SourceInfo info;
335340
336341 // evaluate graphical API
337- case (stmts as GlobalScript.ISTMTS(interactiveStmtLst = {GlobalScript. IEXP(exp = Absyn.CALL())} ))
342+ case GlobalScript.IEXP(exp = Absyn.CALL())
338343 equation
339344 // adrpo: always evaluate the graphicalAPI with these options so instantiation is faster!
340345 partialInst = System.getPartialInstantiation();
@@ -344,26 +349,41 @@ algorithm
344349 keepArrays = Flags.getConfigBool(Flags.KEEP_ARRAYS);
345350 Flags.setConfigBool(Flags.KEEP_ARRAYS, false);
346351 Inst.initInstHashTable();
347- str = evaluateGraphicalApi(stmts , partialInst, gen, evalfunc, keepArrays);
352+ str = evaluateGraphicalApi(stmt , partialInst, gen, evalfunc, keepArrays);
348353 str_1 = stringAppend(str, "\n");
349354 then str_1;
350355
351356 // Evaluate algorithm statements in evaluateAlgStmt()
352- case GlobalScript.ISTMTS(interactiveStmtLst = {GlobalScript. IALG(algItem = (algitem as Absyn.ALGORITHMITEM()))} )
357+ case GlobalScript.IALG(algItem = (algitem as Absyn.ALGORITHMITEM()))
353358 equation
354359 Inst.initInstHashTable();
355360 str = evaluateAlgStmt(algitem);
356361 str_1 = stringAppend(str, "\n");
357362 then str_1;
358363
359364 // Evaluate expressions in evaluate_exprToStr()
360- case GlobalScript.ISTMTS(interactiveStmtLst = {GlobalScript. IEXP(exp = exp, info = info)} )
365+ case GlobalScript.IEXP(exp = exp, info = info)
361366 equation
362367 Inst.initInstHashTable();
363368 str = evaluateExprToStr(exp, info);
364369 str_1 = stringAppend(str, "\n");
365370 then str_1;
366371 end matchcontinue;
372+ else
373+ str := "";
374+ str_1 := "";
375+ GC.gcollect();
376+ str := StackOverflow.getReadableMessage();
377+ if Config.getRunningTestsuite() then
378+ /* It's useful to print the name of the component we failed on.
379+ * But we crash in different places, so for the testsuite we skip this.
380+ */
381+ Error.clearCurrentComponent();
382+ end if;
383+ Error.addMessage(Error.STACK_OVERFLOW_DETAILED, {GlobalScriptDump.printIstmtStr(stmt), str});
384+ Error.clearCurrentComponent();
385+ outString := "\n";
386+ end try annotation(__OpenModelica_stackOverflowCheckpoint=true);
367387end evaluate2;
368388
369389protected function evaluateAlgStmt
@@ -839,47 +859,43 @@ end getTypeOfVariable;
839859
840860protected function getApiFunctionNameInfo
841861 "Returns the name of the called API function."
842- input GlobalScript.Statements inStmts ;
862+ input GlobalScript.Statement inStmt ;
843863 output String outName;
844864 output SourceInfo outInfo;
845865algorithm
846- GlobalScript.ISTMTS(interactiveStmtLst = {GlobalScript. IEXP(
866+ GlobalScript.IEXP(
847867 exp = Absyn.CALL(function_ = Absyn.CREF_IDENT(name = outName)),
848868 info = outInfo
849- )}) := inStmts ;
869+ ) := inStmt ;
850870end getApiFunctionNameInfo;
851871
852872protected function getApiFunctionArgs
853873 "Returns a list of arguments to the function in the interactive statement list."
854- input GlobalScript.Statements inStmts ;
874+ input GlobalScript.Statement inStmt ;
855875 output list<Absyn.Exp> outArgs;
856876algorithm
857- outArgs := match(inStmts )
877+ outArgs := match(inStmt )
858878 local
859879 list<Absyn.Exp> args;
860880
861- case (GlobalScript.ISTMTS(interactiveStmtLst = { GlobalScript.IEXP(exp = Absyn.CALL(functionArgs =
862- Absyn.FUNCTIONARGS(args = args)))})) then args;
881+ case GlobalScript.IEXP(exp = Absyn.CALL(functionArgs =
882+ Absyn.FUNCTIONARGS(args = args))) then args;
863883 else {};
864884 end match;
865885end getApiFunctionArgs;
866886
867887protected function getApiFunctionNamedArgs
868888 "Returns a list of named arguments to the function in the interactive statement list."
869- input GlobalScript.Statements inStmts ;
889+ input GlobalScript.Statement inStmt ;
870890 output list<Absyn.NamedArg> outArgs;
871891algorithm
872- outArgs := match(inStmts)
873- local list<Absyn.NamedArg> args;
874- case (GlobalScript.ISTMTS(interactiveStmtLst = {GlobalScript.IEXP(exp = Absyn.CALL(functionArgs =
875- Absyn.FUNCTIONARGS(argNames = args)))})) then args;
876- end match;
892+ GlobalScript.IEXP(exp = Absyn.CALL(functionArgs = Absyn.FUNCTIONARGS(argNames = outArgs))) := inStmt;
877893end getApiFunctionNamedArgs;
878894
879895protected function evaluateGraphicalApi
880896"Evaluating graphical api.
881897 NOTE: the graphical API is always evaluated with checkModel ON and -d=nogen,noevalfunc ON"
882- input GlobalScript.Statements inStatements ;
898+ input GlobalScript.Statement inStatement ;
883899 input Boolean isPartialInst;
884900 input Boolean flagGen;
885901 input Boolean flagEvalFunc;
@@ -891,7 +907,7 @@ protected
891907 Boolean failed = false;
892908algorithm
893909 try
894- outResult := evaluateGraphicalApi_dispatch(inStatements );
910+ outResult := evaluateGraphicalApi_dispatch(inStatement );
895911 else
896912 failed := true;
897913 end try;
@@ -907,7 +923,7 @@ end evaluateGraphicalApi;
907923
908924protected function evaluateGraphicalApi_dispatch
909925"This function evaluates all primitives in the graphical api."
910- input GlobalScript.Statements inStatements ;
926+ input GlobalScript.Statement inStatement ;
911927 output String outResult;
912928protected
913929 String fn_name, name;
@@ -928,9 +944,9 @@ protected
928944 Absyn.Exp exp;
929945 list<Absyn.Exp> dimensions;
930946algorithm
931- fn_name := getApiFunctionNameInfo(inStatements );
947+ fn_name := getApiFunctionNameInfo(inStatement );
932948 p := SymbolTable.getAbsyn();
933- args := getApiFunctionArgs(inStatements );
949+ args := getApiFunctionArgs(inStatement );
934950
935951 outResult := match(fn_name)
936952 case "setComponentModifierValue"
@@ -990,7 +1006,7 @@ algorithm
9901006 {Absyn.CREF(componentRef = Absyn.CREF_IDENT(name = name)),
9911007 Absyn.CREF(componentRef = tp),
9921008 Absyn.CREF(componentRef = model_)} := args;
993- nargs := getApiFunctionNamedArgs(inStatements );
1009+ nargs := getApiFunctionNamedArgs(inStatement );
9941010 p := addComponent(name, tp, model_, nargs, p);
9951011 Print.clearBuf();
9961012 then
@@ -1001,7 +1017,7 @@ algorithm
10011017 {Absyn.CREF(componentRef = Absyn.CREF_IDENT(name = name)),
10021018 Absyn.CREF(componentRef = tp),
10031019 Absyn.CREF(componentRef = model_)} := args;
1004- nargs := getApiFunctionNamedArgs(inStatements );
1020+ nargs := getApiFunctionNamedArgs(inStatement );
10051021 (p, outResult) := updateComponent(name, tp, model_, nargs, p);
10061022 then
10071023 outResult;
@@ -1010,7 +1026,7 @@ algorithm
10101026 algorithm
10111027 {Absyn.CREF(componentRef = Absyn.CREF_IDENT(name = name)),
10121028 Absyn.CREF(componentRef = model_)} := args;
1013- {} := getApiFunctionNamedArgs(inStatements );
1029+ {} := getApiFunctionNamedArgs(inStatement );
10141030 p := deleteOrUpdateComponent(name, model_, p, NONE());
10151031 Print.clearBuf();
10161032 then "true";
@@ -1033,7 +1049,7 @@ algorithm
10331049 case "getComponents"
10341050 algorithm
10351051 {Absyn.CREF(componentRef = cr)} := args;
1036- nargs := getApiFunctionNamedArgs(inStatements );
1052+ nargs := getApiFunctionNamedArgs(inStatement );
10371053 outResult := getComponents(cr, useQuotes(nargs));
10381054 then
10391055 outResult;
@@ -1102,7 +1118,7 @@ algorithm
11021118 {Absyn.CREF(componentRef = cr1),
11031119 Absyn.CREF(componentRef = cr2),
11041120 Absyn.CREF(componentRef = cr)} := args;
1105- nargs := getApiFunctionNamedArgs(inStatements );
1121+ nargs := getApiFunctionNamedArgs(inStatement );
11061122 (outResult, p) := addConnection(cr, cr1, cr2, nargs, p);
11071123 then
11081124 outResult;
@@ -1121,7 +1137,7 @@ algorithm
11211137 {Absyn.CREF(componentRef = cr1),
11221138 Absyn.CREF(componentRef = cr2),
11231139 Absyn.CREF(componentRef = cr)} := args;
1124- nargs := getApiFunctionNamedArgs(inStatements );
1140+ nargs := getApiFunctionNamedArgs(inStatement );
11251141 (_, p) := deleteConnection(cr, cr1, cr2, p);
11261142 (outResult, p) := addConnection(cr, cr1, cr2, nargs, p);
11271143 then
@@ -1374,7 +1390,7 @@ algorithm
13741390 case "getExtendsModifierNames"
13751391 algorithm
13761392 {Absyn.CREF(componentRef = class_), Absyn.CREF(componentRef = cr)} := args;
1377- nargs := getApiFunctionNamedArgs(inStatements );
1393+ nargs := getApiFunctionNamedArgs(inStatement );
13781394 then
13791395 getExtendsModifierNames(class_, cr, useQuotes(nargs), p);
13801396
@@ -1476,7 +1492,7 @@ algorithm
14761492 case "getLocalVariables"
14771493 algorithm
14781494 {Absyn.CREF(componentRef = cr)} := args;
1479- nargs := getApiFunctionNamedArgs(inStatements );
1495+ nargs := getApiFunctionNamedArgs(inStatement );
14801496 path := Absyn.crefToPath(cr);
14811497 cls := getPathedClassInProgram(path, p);
14821498 env := SymbolTable.buildEnv();
0 commit comments