Skip to content

Commit

Permalink
- Made SimCodeUtil.setVariableIndexHelper tail recursive to fix some …
Browse files Browse the repository at this point in the history
…test cases

  for the bootstrapped compiler.


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@21200 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
perost committed Jun 19, 2014
1 parent cd63ceb commit 7beba6b
Showing 1 changed file with 25 additions and 19 deletions.
44 changes: 25 additions & 19 deletions Compiler/BackEnd/SimCodeUtil.mo
Expand Up @@ -8020,12 +8020,17 @@ protected function setVariableIndexHelper
output list<SimCode.SimVar> outVars;
output Integer outIndex;
algorithm
(outVars, outIndex) := matchcontinue (inVars, inIndex)
local
list<SimCode.SimVar> vars;
list<SimCode.SimVar> xs;
SimCode.SimVar var;
(outVars, outIndex) := List.mapFold(inVars, setVariableIndexHelper2, inIndex);
end setVariableIndexHelper;

protected function setVariableIndexHelper2
input SimCode.SimVar inVar;
input Integer inIndex;
output SimCode.SimVar outVar;
output Integer outIndex;
algorithm
(outVar, outIndex) := match(inVar, inIndex)
local
DAE.ComponentRef name;
BackendDAE.VarKind kind;
String comment, unit, displayUnit;
Expand All @@ -8040,22 +8045,23 @@ algorithm
DAE.ElementSource source;
SimCode.Causality causality;
list<String> numArrayElement;
Integer index_;
Integer index_, next_index;

case ((SimCode.SIMVAR(name, kind, comment, unit, displayUnit, index, minVal, maxVal, initVal, nomVal, isFixed, type_, isDiscrete, arrayCref, aliasvar, source, causality, _, numArrayElement, isValueChangeable, isProtected) :: xs), index_)
case (SimCode.SIMVAR(name, kind, comment, unit, displayUnit, index, minVal,
maxVal, initVal, nomVal, isFixed, type_, isDiscrete, arrayCref, aliasvar,
source, causality, _, numArrayElement, isValueChangeable, isProtected),
index_)
equation
var = SimCode.SIMVAR(name, kind, comment, unit, displayUnit, index, minVal, maxVal, initVal, nomVal, isFixed, type_, isDiscrete, arrayCref, aliasvar, source, causality, SOME(index_), numArrayElement, isValueChangeable, isProtected);
(vars, index_) = setVariableIndexHelper(xs, index_ + 1);
then
((var::vars), index_);
case ((_ :: xs), index_)
equation
(vars, index_) = setVariableIndexHelper(xs, index_);
then
(vars, index_);
case ({}, index_) then ({}, index_);
end matchcontinue;
end setVariableIndexHelper;
next_index = index_ + 1;
then
(SimCode.SIMVAR(name, kind, comment, unit, displayUnit, index,
minVal, maxVal, initVal, nomVal, isFixed, type_, isDiscrete, arrayCref,
aliasvar, source, causality, SOME(index_), numArrayElement,
isValueChangeable, isProtected), next_index);

else (inVar, inIndex);
end match;
end setVariableIndexHelper2;

public function createCrefToSimVarHT
input SimCode.ModelInfo modelInfo;
Expand Down

0 comments on commit 7beba6b

Please sign in to comment.