Skip to content
This repository was archived by the owner on May 18, 2019. It is now read-only.

Commit b91fa8f

Browse files
hkielOpenModelica-Hudson
authored andcommitted
avoid recursions
Belonging to [master]: - #2085
1 parent 926d8af commit b91fa8f

File tree

5 files changed

+30
-62
lines changed

5 files changed

+30
-62
lines changed

Compiler/BackEnd/Initialization.mo

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ protected
439439
algorithm
440440
outEqns := match(inWEqn)
441441
case BackendDAE.WHEN_STMTS(condition=condition,whenStmtLst=whenStmtLst) algorithm
442-
active := Expression.containsInitialCall(condition, false);
442+
active := Expression.containsInitialCall(condition);
443443
for stmt in whenStmtLst loop
444444
_ := match stmt
445445
case BackendDAE.ASSIGN(left = DAE.CREF(componentRef = cr), right = e) equation
@@ -531,7 +531,7 @@ algorithm
531531

532532
// active when equation during initialization
533533
case DAE.STMT_WHEN(exp=condition, statementLst=stmts) guard
534-
Expression.containsInitialCall(condition, false)
534+
Expression.containsInitialCall(condition)
535535
equation
536536
stmts = List.foldr(stmts, List.consr, inAcc);
537537
then (stmts, inLeftCrs);

Compiler/FrontEnd/Ceval.mo

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1419,29 +1419,18 @@ protected function cevalMatrixElt "Evaluates the expression of a matrix construc
14191419
input Boolean inBoolean "impl";
14201420
input Absyn.Msg inMsg;
14211421
input Integer numIter;
1422-
output FCore.Cache outCache;
1423-
output list<Values.Value> outValues;
1424-
algorithm
1425-
(outCache, outValues) :=
1426-
match (inCache, inEnv, inMatrix, inBoolean, inMsg)
1427-
local
1428-
Values.Value v;
1429-
list<Values.Value> vl;
1430-
FCore.Graph env;
1431-
list<DAE.Exp> expl;
1432-
list<list<DAE.Exp>> expll;
1433-
Boolean impl;
1434-
Absyn.Msg msg;
1435-
FCore.Cache cache;
1436-
case (cache,env,(expl :: expll),impl,msg)
1437-
equation
1438-
(cache,vl,_) = cevalList(cache,env,expl,impl,NONE(),msg,numIter);
1439-
v = ValuesUtil.makeArray(vl);
1440-
(cache,vl)= cevalMatrixElt(cache,env, expll, impl,msg,numIter);
1441-
then
1442-
(cache,v :: vl);
1443-
case (cache,_,{},_,_) then (cache,{});
1444-
end match;
1422+
output FCore.Cache outCache = inCache;
1423+
output list<Values.Value> outValues = {};
1424+
protected
1425+
Values.Value v;
1426+
list<Values.Value> vl;
1427+
algorithm
1428+
for expl in inMatrix loop
1429+
(outCache,vl,_) := cevalList(outCache,inEnv,expl,inBoolean,NONE(),inMsg,numIter);
1430+
v := ValuesUtil.makeArray(vl);
1431+
outValues := v::outValues;
1432+
end for;
1433+
outValues := listReverseInPlace(outValues);
14451434
end cevalMatrixElt;
14461435

14471436
protected function cevalBuiltinSize "Evaluates the size operator."
@@ -4490,16 +4479,14 @@ public function cevalList "This function does constant
44904479
output Option<GlobalScript.SymbolTable> outInteractiveInteractiveSymbolTableOption;
44914480
protected
44924481
list<DAE.Exp> expLstNew = inExpExpLst;
4493-
DAE.Exp exp;
44944482
Values.Value v;
44954483
Option<GlobalScript.SymbolTable> st = inST;
44964484

44974485
algorithm
4498-
while not listEmpty(expLstNew) loop
4499-
exp::expLstNew := expLstNew;
4486+
for exp in expLstNew loop
45004487
(outCache, v, st) := ceval(outCache, inEnv, exp, inBoolean, st, inMsg, numIter+1);
45014488
outValuesValueLst := v :: outValuesValueLst;
4502-
end while;
4489+
end for;
45034490
outValuesValueLst := listReverseInPlace(outValuesValueLst);
45044491
outInteractiveInteractiveSymbolTableOption := st;
45054492
end cevalList;

Compiler/FrontEnd/DAEUtil.mo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3091,7 +3091,7 @@ protected function verifyBoolWhenEquationBranch
30913091
input list<DAE.Element> inEqs;
30923092
output list<DAE.ComponentRef> crefs;
30933093
protected
3094-
Boolean initCond = Expression.containsInitialCall(inCond, false);
3094+
Boolean initCond = Expression.containsInitialCall(inCond);
30953095
algorithm
30963096
crefs := verifyBoolWhenEquation1(inEqs, initCond);
30973097
end verifyBoolWhenEquationBranch;

Compiler/FrontEnd/Expression.mo

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4983,23 +4983,17 @@ public function containsInitialCall "public function containsInitialCall
49834983
only in one of the two forms when initial() then or when {…,initial(),…}
49844984
then. [...]"
49854985
input DAE.Exp condition; // expression of a when-clause
4986-
input Boolean inB; // use false for primary calls - it us for internal use only
49874986
output Boolean res;
49884987
algorithm
4989-
res := match(condition, inB)
4988+
res := match(condition)
49904989
local
4991-
Boolean b;
49924990
list<Exp> array;
49934991

4994-
case (_, true) equation
4995-
then true;
4996-
4997-
case (DAE.CALL(path = Absyn.IDENT(name = "initial")), _) equation
4992+
case (DAE.CALL(path = Absyn.IDENT(name = "initial")))
49984993
then true;
49994994

5000-
case (DAE.ARRAY(array=array), _) equation
5001-
b = List.fold(array, containsInitialCall, inB);
5002-
then b;
4995+
case (DAE.ARRAY(array=array))
4996+
then List.mapBoolOr(array, containsInitialCall);
50034997

50044998
else false;
50054999
end match;

Compiler/FrontEnd/PrefixUtil.mo

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,29 +1042,16 @@ public function prefixExpList "This function prefixes a list of expressions usin
10421042
input InnerOuter.InstHierarchy inIH;
10431043
input list<DAE.Exp> inExpExpLst;
10441044
input Prefix.Prefix inPrefix;
1045-
output FCore.Cache outCache;
1046-
output list<DAE.Exp> outExpExpLst;
1045+
output FCore.Cache outCache = inCache;
1046+
output list<DAE.Exp> outExpExpLst = {};
1047+
protected
1048+
DAE.Exp e_1;
10471049
algorithm
1048-
(outCache,outExpExpLst) := match (inCache,inEnv,inIH,inExpExpLst,inPrefix)
1049-
local
1050-
DAE.Exp e_1,e;
1051-
list<DAE.Exp> es_1,es;
1052-
FCore.Graph env;
1053-
Prefix.Prefix p;
1054-
FCore.Cache cache;
1055-
InstanceHierarchy ih;
1056-
1057-
// handle empty case
1058-
case (cache,_,_,{},_) then (cache,{});
1059-
1060-
// yuppie! we have a list of expressions
1061-
case (cache,env,ih,(e :: es),p)
1062-
equation
1063-
(cache,e_1) = prefixExp(cache, env, ih, e, p);
1064-
(cache,es_1) = prefixExpList(cache, env, ih, es, p);
1065-
then
1066-
(cache,e_1 :: es_1);
1067-
end match;
1050+
for e in inExpExpLst loop
1051+
(outCache,e_1) := prefixExp(outCache, inEnv, inIH, e, inPrefix);
1052+
outExpExpLst := e_1::outExpExpLst;
1053+
end for;
1054+
outExpExpLst := Dangerous.listReverseInPlace(outExpExpLst);
10681055
end prefixExpList;
10691056

10701057
//--------------------------------------------

0 commit comments

Comments
 (0)