Skip to content

Commit

Permalink
Fix InstUtil.splitInnerAndOtherTplLstElementMod.
Browse files Browse the repository at this point in the history
- Rewrote splitInnerAndOtherTplLstElementMod to use a for-loop
  instead of non-tail recursion.

Belonging to [master]:
  - OpenModelica/OMCompiler#2605
  • Loading branch information
perost authored and OpenModelica-Hudson committed Aug 13, 2018
1 parent 9840114 commit f2acbf5
Showing 1 changed file with 29 additions and 35 deletions.
64 changes: 29 additions & 35 deletions Compiler/FrontEnd/InstUtil.mo
Expand Up @@ -5960,44 +5960,38 @@ public function splitInnerAndOtherTplLstElementMod
"@author: adrpo
Split the elements into inner, inner outer and others"
input list<tuple<SCode.Element, DAE.Mod>> inTplLstElementMod;
output list<tuple<SCode.Element, DAE.Mod>> outInnerTplLstElementMod;
output list<tuple<SCode.Element, DAE.Mod>> outInnerOuterTplLstElementMod;
output list<tuple<SCode.Element, DAE.Mod>> outOtherTplLstElementMod;
output list<tuple<SCode.Element, DAE.Mod>> outInnerTplLstElementMod = {};
output list<tuple<SCode.Element, DAE.Mod>> outInnerOuterTplLstElementMod = {};
output list<tuple<SCode.Element, DAE.Mod>> outOtherTplLstElementMod = {};
protected
SCode.Element comp;
Absyn.InnerOuter io;
algorithm
(outInnerTplLstElementMod, outInnerOuterTplLstElementMod, outOtherTplLstElementMod) := matchcontinue (inTplLstElementMod)
local
list<tuple<SCode.Element, DAE.Mod>> rest,innerComps,innerouterComps,otherComps;
tuple<SCode.Element, DAE.Mod> comp;
Absyn.InnerOuter io;
for e in listReverse(inTplLstElementMod) loop
(comp, _) := e;

// empty case
case ({}) then ({},{},{});

// inner components
case ( ( comp as (SCode.COMPONENT(prefixes=SCode.PREFIXES(innerOuter = io)), _) ) :: rest)
equation
true = Absyn.isInner(io);
false = Absyn.isOuter(io);
(innerComps,innerouterComps,otherComps) = splitInnerAndOtherTplLstElementMod(rest);
then
(comp::innerComps,innerouterComps,otherComps);

// inner outer components
case ( ( comp as (SCode.COMPONENT(prefixes=SCode.PREFIXES(innerOuter = io)), _) ) :: rest)
equation
true = Absyn.isInner(io);
true = Absyn.isOuter(io);
(innerComps,innerouterComps,otherComps) = splitInnerAndOtherTplLstElementMod(rest);
then
(innerComps,comp::innerouterComps,otherComps);
() := match comp
case SCode.COMPONENT(prefixes = SCode.PREFIXES(innerOuter = io))
guard Absyn.isInner(io)
algorithm
if Absyn.isOuter(io) then
// inner outer components.
outInnerOuterTplLstElementMod := e :: outInnerOuterTplLstElementMod;
else
// inner components.
outInnerTplLstElementMod := e :: outInnerTplLstElementMod;
end if;
then
();

// any other components
case (comp :: rest)
equation
(innerComps,innerouterComps,otherComps) = splitInnerAndOtherTplLstElementMod(rest);
then
(innerComps,innerouterComps,comp::otherComps);
end matchcontinue;
else
algorithm
// any other components.
outOtherTplLstElementMod := e :: outOtherTplLstElementMod;
then
();
end match;
end for;
end splitInnerAndOtherTplLstElementMod;

public function splitEltsOrderInnerOuter "
Expand Down

0 comments on commit f2acbf5

Please sign in to comment.