Skip to content

Commit

Permalink
make traverseExpsOfExpList tail recursive
Browse files Browse the repository at this point in the history
  • Loading branch information
vruge authored and OpenModelica-Hudson committed Feb 15, 2016
1 parent a38fd9a commit bc07b69
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions Compiler/BackEnd/BackendEquation.mo
Expand Up @@ -1092,8 +1092,8 @@ protected function traverseExpsOfExpList<T> "author Frenkel TUD:
input list<DAE.Exp> inExpl;
input FuncExpType rel;
input T inExtArg;
output list<DAE.Exp> outExpl;
output T outTypeA;
output list<DAE.Exp> outExpl = {};
output T outTypeA = inExtArg;

partial function FuncExpType
input DAE.Exp inExp;
Expand All @@ -1102,20 +1102,13 @@ protected function traverseExpsOfExpList<T> "author Frenkel TUD:
output T outA;
end FuncExpType;
algorithm
(outExpl, outTypeA) := match (inExpl)
local
DAE.Exp e, e1;
list<DAE.Exp> expl1, res;
T extArg;

case {}
then ({}, inExtArg);
for e in inExpl loop
(e, outTypeA) := rel(e, outTypeA);
outExpl := e :: outExpl;
end for;

case e::res equation
(e1, extArg) = rel(e, inExtArg);
(expl1, extArg) = traverseExpsOfExpList(res, rel, extArg);
then (e1::expl1, extArg);
end match;
outExpl := listReverse(outExpl);
end traverseExpsOfExpList;

protected function traverseExpsOfExpList_WithStop<T> "author Frenkel TUD
Expand Down

0 comments on commit bc07b69

Please sign in to comment.