Skip to content

Commit

Permalink
- get rid of some BackendDAEUtil.varlist
Browse files Browse the repository at this point in the history
- BackendDAEUtil.mo
  - fix rml bug, replaceable type Type_a subtypeof Any was not defined 

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@6963 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Jens Frenkel committed Nov 11, 2010
1 parent 4a56c0c commit b294d0d
Show file tree
Hide file tree
Showing 6 changed files with 2,741 additions and 2,673 deletions.
51 changes: 28 additions & 23 deletions Compiler/BackendDAETransform.mo
Expand Up @@ -1969,12 +1969,11 @@ protected function varStateSelectHeuristicPrio3
output Real prio;
algorithm
prio := matchcontinue(cr,vars)
local list<BackendDAE.Var> varLst,sameIdentVarLst; Real c,prio;
local Integer i; Real c,prio;
case(cr,vars)
equation
varLst = BackendDAEUtil.varList(vars);
sameIdentVarLst = Util.listSelect1(varLst,cr,varHasSameLastIdent);
c = intReal(listLength(sameIdentVarLst));
((_,i)) = BackendVariable.traverseBackendDAEVars(vars,varHasSameLastIdent,(cr,0));
c = intReal(i);
prio = c *. 0.01;
then prio;
end matchcontinue;
Expand All @@ -1985,17 +1984,21 @@ protected function varHasSameLastIdent
Helper funciton to varStateSelectHeuristicPrio3.
Returns true if the variable has the same name (the last identifier)
as the variable name given as second argument."
input BackendDAE.Var v;
input DAE.ComponentRef cr;
output Boolean b;
input tuple<BackendDAE.Var, tuple<DAE.ComponentRef,Integer>> inTpl;
output tuple<BackendDAE.Var, tuple<DAE.ComponentRef,Integer>> outTpl;
algorithm
b := matchcontinue(v,cr)
local DAE.ComponentRef cr2; DAE.Ident id1,id2;
case(BackendDAE.VAR(varName=cr2 ),cr )
outTpl := matchcontinue(inTpl)
local
DAE.ComponentRef cr,cr2;
DAE.Ident id1,id2;
BackendDAE.Var v;
Integer i;
case((v,(cr,i)))
equation
cr2 = BackendVariable.varCref(v);
true = ComponentReference.crefLastIdentEqual(cr,cr2);
then true;
case(_,_) then false;
then ((v,(cr,i+1)));
case inTpl then inTpl;
end matchcontinue;
end varHasSameLastIdent;

Expand All @@ -2012,9 +2015,7 @@ algorithm
list<BackendDAE.Var> varLst,sameCompVarLst;
case(cr,vars)
equation
varLst = BackendDAEUtil.varList(vars);
sameCompVarLst = Util.listSelect1(varLst,cr,varInSameComponent);
_::_ = Util.listSelect(sameCompVarLst,BackendVariable.isDummyStateVar);
((_,true)) = BackendVariable.traverseBackendDAEVars(vars,varInSameComponent,(cr,false));
then -1.0;
case(cr,vars) then 0.0;
end matchcontinue;
Expand All @@ -2025,17 +2026,21 @@ protected function varInSameComponent
Helper funciton to varStateSelectHeuristicPrio2.
Returns true if the variable is defined in the same sub
component as the variable name given as second argument."
input BackendDAE.Var v;
input DAE.ComponentRef cr;
output Boolean b;
input tuple<BackendDAE.Var, tuple<DAE.ComponentRef,Boolean>> inTpl;
output tuple<BackendDAE.Var, tuple<DAE.ComponentRef,Boolean>> outTpl;
algorithm
b := matchcontinue(v,cr)
local DAE.ComponentRef cr2; DAE.Ident id1,id2;
case(BackendDAE.VAR(varName=cr2 ),cr )
outTpl := matchcontinue(inTpl)
local
DAE.ComponentRef cr,cr2;
BackendDAE.Var v;
case((v,(cr,true))) then ((v,(cr,true)));
case((v,(cr,_)))
equation
cr2 = BackendVariable.varCref(v);
true = BackendVariable.isDummyStateVar(v);
true = ComponentReference.crefEqualNoStringCompare(ComponentReference.crefStripLastIdent(cr2),ComponentReference.crefStripLastIdent(cr));
then true;
case(_,_) then false;
then ((v,(cr,true)));
case inTpl then inTpl;
end matchcontinue;
end varInSameComponent;

Expand Down
92 changes: 45 additions & 47 deletions Compiler/BackendDAEUtil.mo
Expand Up @@ -709,6 +709,7 @@ algorithm
outBinTree := matchcontinue (inBackendDAE)
local
list<BackendDAE.Var> v_lst;
list<DAE.ComponentRef> cr_lst;
BackendDAE.BinTree bt;
BackendDAE.Variables v,kn;
BackendDAE.EquationArray e,re,ia;
Expand All @@ -717,55 +718,32 @@ algorithm
BackendDAE.EventInfo ev;
case (BackendDAE.DAE(orderedVars = v,knownVars = kn,orderedEqs = e,removedEqs = re,initialEqs = ia,arrayEqs = ae,algorithms = al,eventInfo = ev))
equation
v_lst = varList(v);
bt = statesDaelow2(v_lst, BackendDAE.emptyBintree);
cr_lst = BackendVariable.traverseBackendDAEVars(v,traversingisStateVarCrefFinder,{});
bt = treeAddList(BackendDAE.emptyBintree,cr_lst);
then
bt;
end matchcontinue;
end statesDaelow;

protected function statesDaelow2
"function: statesDaelow2
author: PA
Helper function to statesDaelow."
input list<BackendDAE.Var> inVarLst;
input BackendDAE.BinTree inBinTree;
output BackendDAE.BinTree outBinTree;
protected function traversingisStateVarCrefFinder
"autor: Frenkel TUD 2010-11"
input tuple<BackendDAE.Var, list<DAE.ComponentRef>> inTpl;
output tuple<BackendDAE.Var, list<DAE.ComponentRef>> outTpl;
algorithm
outBinTree := matchcontinue (inVarLst,inBinTree)
outTpl:=
matchcontinue (inTpl)
local
BackendDAE.BinTree bt;
DAE.ComponentRef cr;
BackendDAE.Var v;
list<BackendDAE.Var> vs;

case ({},bt) then bt;

case ((v :: vs),bt)
equation
BackendDAE.STATE() = BackendVariable.varKind(v);
cr = BackendVariable.varCref(v);
bt = treeAdd(bt, cr, 0);
bt = statesDaelow2(vs, bt);
then
bt;
/* is not realy a state
case ((v :: vs),bt)
list<DAE.ComponentRef> cr_lst;
DAE.ComponentRef cr;
case ((v,cr_lst))
equation
BackendDAE.DUMMY_STATE() = BackendVariable.varKind(v);
true = BackendVariable.isStateVar(v);
cr = BackendVariable.varCref(v);
bt = treeAdd(bt, cr, 0);
bt = statesDaelow2(vs, bt);
then
bt;
*/
case ((v :: vs),bt)
equation
bt = statesDaelow2(vs, bt);
then
bt;
then ((v,cr::cr_lst));
case inTpl then inTpl;
end matchcontinue;
end statesDaelow2;
end traversingisStateVarCrefFinder;

public function emptyVars
"function: emptyVars
Expand Down Expand Up @@ -949,7 +927,7 @@ algorithm
case (BackendDAE.VARIABLE_ARRAY(numberOfElements = 0,varOptArr = arr)) then {};
case (BackendDAE.VARIABLE_ARRAY(numberOfElements = 1,varOptArr = arr))
equation
SOME(elt) = arr[0 + 1];
SOME(elt) = arr[1];
then
{elt};
case (BackendDAE.VARIABLE_ARRAY(numberOfElements = n,arrSize = size,varOptArr = arr))
Expand Down Expand Up @@ -1830,7 +1808,7 @@ algorithm
outIntegerArray:=
matchcontinue (inBackendDAE1,inIntegerArray2,inIncidenceMatrix3,inIncidenceMatrixT4,inIntegerArray5,inIntegerArray6)
local
list<BackendDAE.Var> v_lst,statevar_lst;
list<BackendDAE.Var> statevar_lst;
BackendDAE.BackendDAE dae;
array<BackendDAE.Value> arr_1,arr;
array<list<BackendDAE.Value>> m,mt;
Expand All @@ -1842,8 +1820,7 @@ algorithm

case ((dae as BackendDAE.DAE(orderedVars = v,knownVars = kn,orderedEqs = e,removedEqs = se,initialEqs = ie,arrayEqs = ae,algorithms = alg)),arr,m,mt,a1,a2)
equation
v_lst = varList(v);
statevar_lst = Util.listSelect(v_lst, BackendVariable.isStateVar);
statevar_lst = BackendVariable.traverseBackendDAEVars(v,traversingisStateVarFinder,{});
((dae,arr_1,m,mt,a1,a2)) = Util.listFold(statevar_lst, markStateEquation, (dae,arr,m,mt,a1,a2));
then
arr_1;
Expand All @@ -1856,6 +1833,24 @@ algorithm
end matchcontinue;
end markStateEquations;

protected function traversingisStateVarFinder
"autor: Frenkel TUD 2010-11"
input tuple<BackendDAE.Var, list<BackendDAE.Var>> inTpl;
output tuple<BackendDAE.Var, list<BackendDAE.Var>> outTpl;
algorithm
outTpl:=
matchcontinue (inTpl)
local
BackendDAE.Var v;
list<BackendDAE.Var> v_lst;
case ((v,v_lst))
equation
true = BackendVariable.isStateVar(v);
then ((v,v::v_lst));
case inTpl then inTpl;
end matchcontinue;
end traversingisStateVarFinder;

protected function markStateEquation
"function: markStateEquation
This function is a helper function to mark_state_equations
Expand Down Expand Up @@ -4207,6 +4202,7 @@ protected function traverseBackendDAEExpsVars "function: traverseBackendDAEExpsV

Helper for traverseBackendDAEExps
"
replaceable type Type_a subtypeof Any;
input BackendDAE.Variables inVariables;
input FuncExpType func;
input Type_a inTypeA;
Expand Down Expand Up @@ -4234,11 +4230,12 @@ algorithm
end matchcontinue;
end traverseBackendDAEExpsVars;

protected function traverseBackendDAEExpsArrayNoCopy "
public function traverseBackendDAEExpsArrayNoCopy "
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> array;
input FuncExpType func;
input FuncArrayType arrayfunc;
Expand All @@ -4247,17 +4244,17 @@ protected function traverseBackendDAEExpsArrayNoCopy "
input Type_b inTypeB;
output Type_b outTypeB;
partial function FuncExpType
input tuple<DAE.Exp, Type_b> inTpl;
output tuple<DAE.Exp, Type_b> outTpl;
input tuple<Type_c, Type_b> inTpl;
output tuple<Type_c, Type_b> outTpl;
end FuncExpType;
partial function FuncArrayType
input Type_a inTypeB;
input FuncExpType func;
input Type_b inTypeA;
output Type_b outTypeA;
partial function FuncExpType
input tuple<DAE.Exp, Type_b> inTpl;
output tuple<DAE.Exp, Type_b> outTpl;
input tuple<Type_c, Type_b> inTpl;
output tuple<Type_c, Type_b> outTpl;
end FuncExpType;
end FuncArrayType;
algorithm
Expand All @@ -4280,6 +4277,7 @@ protected function traverseBackendDAEExpsVar "function: traverseBackendDAEExpsVa
Helper traverseBackendDAEExpsVar. Get all exps from a Var.
DAE.ET_OTHER is used as type for componentref. Not important here.
We only use the exp list for finding function calls"
replaceable type Type_a subtypeof Any;
input Option<BackendDAE.Var> inVar;
input FuncExpType func;
input Type_a inTypeA;
Expand Down
65 changes: 65 additions & 0 deletions Compiler/BackendVariable.mo
Expand Up @@ -2736,4 +2736,69 @@ algorithm
end matchcontinue;
end mergeVariables;

public function traverseBackendDAEVars "function: traverseBackendDAEVars
author: Frenkel TUD

traverse all vars of a BackenDAE.Variables array.
"
replaceable type Type_a subtypeof Any;
input BackendDAE.Variables inVariables;
input FuncExpType func;
input Type_a inTypeA;
output Type_a outTypeA;
partial function FuncExpType
input tuple<BackendDAE.Var, Type_a> inTpl;
output tuple<BackendDAE.Var, Type_a> outTpl;
end FuncExpType;
algorithm
outTypeA:=
matchcontinue (inVariables,func,inTypeA)
local
array<Option<BackendDAE.Var>> varOptArr;
Type_a ext_arg_1,ext_arg_2,ext_arg_3;
case (BackendDAE.VARIABLES(varArr = BackendDAE.VARIABLE_ARRAY(varOptArr=varOptArr)),func,inTypeA)
equation
ext_arg_1 = BackendDAEUtil.traverseBackendDAEExpsArrayNoCopy(varOptArr,func,traverseBackendDAEVar,1,arrayLength(varOptArr),inTypeA);
then
ext_arg_1;
case (_,_,_)
equation
Debug.fprintln("failtrace", "- BackendVariable.traverseBackendDAEVars failed");
then
fail();
end matchcontinue;
end traverseBackendDAEVars;

protected function traverseBackendDAEVar "function: traverseBackendDAEVar
author: Frenkel TUD
Helper traverseBackendDAEVars."
replaceable type Type_a subtypeof Any;
input Option<BackendDAE.Var> inVar;
input FuncExpType func;
input Type_a inTypeA;
output Type_a outTypeA;
partial function FuncExpType
input tuple<BackendDAE.Var, Type_a> inTpl;
output tuple<BackendDAE.Var, Type_a> outTpl;
end FuncExpType;
algorithm
outTypeA:=
matchcontinue (inVar,func,inTypeA)
local
BackendDAE.Var v;
Type_a ext_arg;
case (NONE(),func,inTypeA) then inTypeA;
case (SOME(v),func,inTypeA)
equation
((_,ext_arg)) = func((v,inTypeA));
then
ext_arg;
case (_,_,_)
equation
Debug.fprintln("failtrace", "- BackendVariable.traverseBackendDAEVar failed");
then
fail();
end matchcontinue;
end traverseBackendDAEVar;

end BackendVariable;

0 comments on commit b294d0d

Please sign in to comment.