Skip to content

Commit

Permalink
- BackendEquation.mo
Browse files Browse the repository at this point in the history
  add function traverseBackendDAEEqnsWithUpdate
- BackendDAEUtil.mo
  add function traverseBackendDAEArrayNoCopyWithUpdate

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@7035 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Jens Frenkel committed Nov 15, 2010
1 parent 5daa72b commit d0e4187
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 0 deletions.
47 changes: 47 additions & 0 deletions Compiler/BackendDAEUtil.mo
Expand Up @@ -4274,6 +4274,53 @@ algorithm
end matchcontinue;
end traverseBackendDAEArrayNoCopyWithStop;

public function traverseBackendDAEArrayNoCopyWithUpdate "
help function to traverseBackendDAEExps
author: Frenkel TUD"
replaceable type Type_a subtypeof Any;
replaceable type Type_b subtypeof Any;
replaceable type Type_c subtypeof Any;
input array<Type_a> inArray;
input FuncExpTypeWithUpdate func;
input FuncArrayTypeWithUpdate arrayfunc;
input Integer pos "iterated 1..len";
input Integer len "length of array";
input Type_b inTypeB;
output array<Type_a> outArray;
output Type_b outTypeB;
partial function FuncExpType
input tuple<Type_c, Type_b> inTpl;
output tuple<Type_c, Type_b> outTpl;
end FuncExpType;
partial function FuncArrayTypeWithUpdate
input Type_a inTypeA;
input FuncExpType func;
input Type_b inTypeB;
output Type_a outTypeA;
output Type_b outTypeB;
partial function FuncExpTypeWithUpdate
input tuple<Type_c, Type_b> inTpl;
output tuple<Type_c, Type_b> outTpl;
end FuncExpTypeWithUpdate;
end FuncArrayTypeWithUpdate;
algorithm
(outArray,outTypeB) := matchcontinue(inArray,func,arrayfunc,pos,len,inTypeB)
local
array<Type_a> array;
Type_a new_a;
Type_b ext_arg_1,ext_arg_2;
case(array,_,_,pos,len,inTypeB) equation
true = pos > len;
then (array,inTypeB);

case(array,func,arrayfunc,pos,len,inTypeB) equation
(new_a,ext_arg_1) = arrayfunc(array[pos],func,inTypeB);
array = arrayUpdate(array,pos,new_a);
(array,ext_arg_2) = traverseBackendDAEArrayNoCopyWithUpdate(array,func,arrayfunc,pos+1,len,ext_arg_1);
then (array,ext_arg_2);
end matchcontinue;
end traverseBackendDAEArrayNoCopyWithUpdate;

protected function traverseBackendDAEExpsVar "function: traverseBackendDAEExpsVar
author: Frenkel TUD
Helper traverseBackendDAEExpsVar. Get all exps from a Var.
Expand Down
66 changes: 66 additions & 0 deletions Compiler/BackendEquation.mo
Expand Up @@ -433,6 +433,72 @@ algorithm
end matchcontinue;
end traverseBackendDAEOptEqnWithStop;

public function traverseBackendDAEEqnsWithUpdate "function: traverseBackendDAEEqnsWithUpdate
author: Frenkel TUD

traverses all equations of a BackendDAE.EquationArray.
"
replaceable type Type_a subtypeof Any;
input BackendDAE.EquationArray inEquationArray;
input FuncExpType func;
input Type_a inTypeA;
output BackendDAE.EquationArray outEquationArray;
output Type_a outTypeA;
partial function FuncExpType
input tuple<BackendDAE.Equation, Type_a> inTpl;
output tuple<BackendDAE.Equation, Type_a> outTpl;
end FuncExpType;
algorithm
(outEquationArray,outTypeA) :=
matchcontinue (inEquationArray,func,inTypeA)
local
Integer numberOfElement, arrSize;
array<Option<BackendDAE.Equation>> equOptArr;
Type_a ext_arg;
case ((BackendDAE.EQUATION_ARRAY(numberOfElement=numberOfElement,arrSize=arrSize,equOptArr = equOptArr)),func,inTypeA)
equation
(equOptArr,ext_arg) = BackendDAEUtil.traverseBackendDAEArrayNoCopyWithUpdate(equOptArr,func,traverseBackendDAEOptEqnWithUpdate,1,arrayLength(equOptArr),inTypeA);
then (BackendDAE.EQUATION_ARRAY(numberOfElement,arrSize,equOptArr),ext_arg);
case (_,_,_)
equation
Debug.fprintln("failtrace", "- BackendEquation.traverseBackendDAEEqnsWithStop failed");
then
fail();
end matchcontinue;
end traverseBackendDAEEqnsWithUpdate;

protected function traverseBackendDAEOptEqnWithUpdate "function: traverseBackendDAEOptEqnWithUpdate
author: Frenkel TUD 2010-11
Helper for traverseBackendDAEExpsEqnsWithUpdate."
replaceable type Type_a subtypeof Any;
input Option<BackendDAE.Equation> inEquation;
input FuncExpType func;
input Type_a inTypeA;
output Option<BackendDAE.Equation> outEquation;
output Type_a outTypeA;
partial function FuncExpType
input tuple<BackendDAE.Equation, Type_a> inTpl;
output tuple<BackendDAE.Equation, Type_a> outTpl;
end FuncExpType;
algorithm
(outEquation,outTypeA):= matchcontinue (inEquation,func,inTypeA)
local
BackendDAE.Equation eqn,eqn1;
Type_a ext_arg;
case (NONE(),func,inTypeA) then (NONE(),inTypeA);
case (SOME(eqn),func,inTypeA)
equation
((eqn1,ext_arg)) = func((eqn,inTypeA));
then
(SOME(eqn1),ext_arg);
case (_,_,_)
equation
Debug.fprintln("failtrace", "- BackendEquation.traverseBackendDAEOptEqnWithUpdate failed");
then
fail();
end matchcontinue;
end traverseBackendDAEOptEqnWithUpdate;

public function equationEqual "Returns true if two equations are equal"
input BackendDAE.Equation e1;
input BackendDAE.Equation e2;
Expand Down

0 comments on commit d0e4187

Please sign in to comment.