Skip to content

Commit

Permalink
- fix some bugs
Browse files Browse the repository at this point in the history
  check for records improved
  rename BackendDAEUtil.traverseExp to traverseAlgorithmExps
- Expression.mo
  delete makeCrefExpNoType use crefExp 
  improve isConst

git-svn-id: https://openmodelica.org/svn/OpenModelica/branches/sjoelund-functiontree@6677 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Jens Frenkel committed Oct 28, 2010
1 parent dc7a066 commit 29d6412
Show file tree
Hide file tree
Showing 6 changed files with 204 additions and 178 deletions.
16 changes: 2 additions & 14 deletions Compiler/BackendDAECreate.mo
Expand Up @@ -2861,16 +2861,6 @@ algorithm
case (((e as DAE.RELATION(exp1 = e1,operator = op,exp2 = e2)),(zeroCrossings,(vars,knvars))))
equation
then ((e,((e :: zeroCrossings),(vars,knvars)))); /* All other functions generate zerocrossing. */
case (((e as DAE.ARRAY(array = {})),(zeroCrossings,(vars,knvars))))
equation
then ((e,(zeroCrossings,(vars,knvars))));
case ((e1 as DAE.ARRAY(ty = tp,scalar = scalar,array = (e :: el)),(zeroCrossings,(vars,knvars))))
equation
((_,(zeroCrossings_1,(vars,knvars)))) = Expression.traverseExp(e, collectZeroCrossings, (zeroCrossings,(vars,knvars)));
((e_1,(zeroCrossings_2,(vars,knvars)))) = collectZeroCrossings((DAE.ARRAY(tp,scalar,el),(zeroCrossings,(vars,knvars))));
zeroCrossings_3 = listAppend(zeroCrossings_1, zeroCrossings_2);
then
((e1,(zeroCrossings_3,(vars,knvars))));
case ((e,(zeroCrossings,(vars,knvars))))
equation
then ((e,(zeroCrossings,(vars,knvars))));
Expand Down Expand Up @@ -3057,10 +3047,9 @@ algorithm
list<DAE.Exp> expLst;
list<tuple<DAE.Exp,DAE.Exp>> exptpllst;
// a=b
case (BackendDAE.COMPLEX_EQUATION(index=i,lhs = DAE.CREF(componentRef=cr1), rhs = DAE.CREF(componentRef=cr2),source = source),funcs)
case (BackendDAE.COMPLEX_EQUATION(index=i,lhs = DAE.CREF(componentRef=cr1,ty= DAE.ET_COMPLEX(varLst=varLst,complexClassType=ClassInf.RECORD(_))), rhs = DAE.CREF(componentRef=cr2),source = source),funcs)
equation
// create as many equations as the dimension of the record
DAE.ET_COMPLEX(varLst=varLst) = ComponentReference.crefLastType(cr1);
e1lst = Util.listMap1(varLst,Expression.generateCrefsExpFromExpVar,cr1);
e2lst = Util.listMap1(varLst,Expression.generateCrefsExpFromExpVar,cr2);
exptpllst = Util.listThreadTuple(e1lst,e2lst);
Expand All @@ -3079,11 +3068,10 @@ algorithm
then
((complexEqs1,multiEqs2));
// a=Record()
case (BackendDAE.COMPLEX_EQUATION(index=i,lhs = DAE.CREF(componentRef=cr1), rhs = DAE.CALL(path=path,expLst=expLst),source = source),funcs)
case (BackendDAE.COMPLEX_EQUATION(index=i,lhs = DAE.CREF(componentRef=cr1,ty= DAE.ET_COMPLEX(varLst=varLst,complexClassType=ClassInf.RECORD(_))), rhs = DAE.CALL(path=path,expLst=expLst),source = source),funcs)
equation
SOME(DAE.RECORD_CONSTRUCTOR(path=fname)) = DAEUtil.avlTreeGet(funcs,path);
// create as many equations as the dimension of the record
DAE.ET_COMPLEX(varLst=varLst) = ComponentReference.crefLastType(cr1);
e1lst = Util.listMap1(varLst,Expression.generateCrefsExpFromExpVar,cr1);
exptpllst = Util.listThreadTuple(e1lst,expLst);
compmultilistlst = Util.listMap2(exptpllst,generateextendedRecordEqn,source,funcs);
Expand Down
1 change: 0 additions & 1 deletion Compiler/BackendDAEOptimize.mo
Expand Up @@ -58,7 +58,6 @@ protected import DAEUtil;
protected import Debug;
protected import Expression;
protected import ExpressionSolve;
protected import ExpressionSimplify;
protected import Derive;
protected import Error;
protected import RTOpts;
Expand Down
18 changes: 8 additions & 10 deletions Compiler/BackendDAEUtil.mo
Expand Up @@ -168,7 +168,7 @@ algorithm
list<tuple<DAE.Exp,list<DAE.ComponentRef>>> lstExpCrefs;
case (exp,vars)
equation
((_,(_,crefs))) = Expression.traverseExpTopDown(exp,traversecheckBackendDAEExp,((vars,{})));
((_,(_,crefs))) = Expression.traverseExp(exp,traversecheckBackendDAEExp,((vars,{})));
lstExpCrefs = Util.if_(listLength(crefs)>0,{(exp,crefs)},{});
then
lstExpCrefs;
Expand All @@ -190,15 +190,14 @@ algorithm
case ((e as DAE.CREF(componentRef = DAE.CREF_IDENT(ident="time")),(vars,crefs)))
then ((e, (vars,crefs)));
/* Special Case for Records */
case ((e as DAE.CREF(componentRef = cr),(vars,crefs)))
case ((e as DAE.CREF(componentRef = cr,ty= DAE.ET_COMPLEX(varLst=varLst,complexClassType=ClassInf.RECORD(_))),(vars,crefs)))
local
list<list<tuple<DAE.Exp,list<DAE.ComponentRef>>>> expcreflstlst;
list<tuple<DAE.Exp,list<DAE.ComponentRef>>> expcreflst;
list<list<DAE.ComponentRef>> creflstlst;
list<DAE.ComponentRef> crlst;
list<DAE.ExpVar> varLst;
equation
DAE.ET_COMPLEX(varLst=varLst) = ComponentReference.crefLastType(cr);
expl = Util.listMap1(varLst,Expression.generateCrefsExpFromExpVar,cr);
expcreflstlst = Util.listMap1(expl,checkBackendDAEExp,vars);
expcreflst = Util.listFlatten(expcreflstlst);
Expand Down Expand Up @@ -233,7 +232,7 @@ algorithm
failure((_,_) = BackendVariable.getVar(cr, vars));
then
((e, (vars,cr::crefs)));
case (_) then inTuple;
case inTuple then inTuple;
end matchcontinue;
end traversecheckBackendDAEExp;

Expand Down Expand Up @@ -1405,9 +1404,8 @@ algorithm
list<list<tuple<DAE.Exp, Boolean>>> mexp;
list<DAE.ExpVar> varLst;
/* Special Case for Records */
case ((DAE.CREF(componentRef = cr)),vars)
case ((DAE.CREF(componentRef = cr,ty= DAE.ET_COMPLEX(varLst=varLst,complexClassType=ClassInf.RECORD(_)))),vars)
equation
DAE.ET_COMPLEX(varLst=varLst) = ComponentReference.crefLastType(cr);
expl = Util.listMap1(varLst,Expression.generateCrefsExpFromExpVar,cr);
lst = Util.listMap1(expl, statesAndVarsExp, vars);
res = Util.listListUnionOnTrue(lst, Expression.expEqual);
Expand Down Expand Up @@ -4514,7 +4512,7 @@ algorithm
exps5 = traverseDAELowExpsEqns(ieqns,func,inTypeA);
exps6 = traverseDAELowExpsArrayEqns(ae,func,inTypeA);
alglst = arrayList(algs);
exps7 = Util.listMapFlat2(alglst, traverseExps,func,inTypeA);
exps7 = Util.listMapFlat2(alglst, traverseAlgorithmExps,func,inTypeA);
exps = Util.listFlatten({exps1,exps2,exps3,exps4,exps5,exps6,exps7});
then
exps;
Expand Down Expand Up @@ -4837,7 +4835,7 @@ algorithm
end matchcontinue;
end traverseDAELowExpsArrayEqn;

public function traverseExps "function: traverseExps
public function traverseAlgorithmExps "function: traverseAlgorithmExps

This function goes through the Algorithm structure and finds all the
expressions and performs the function on them
Expand Down Expand Up @@ -4865,11 +4863,11 @@ algorithm
then
talst;
end matchcontinue;
end traverseExps;
end traverseAlgorithmExps;

protected function traverseExpsStmts "function: traverseExps

helper for traverseExps.
helper for traverseAlgorithmExps.
"
replaceable type Type_a subtypeof Any;
replaceable type Type_b subtypeof Any;
Expand Down
6 changes: 1 addition & 5 deletions Compiler/ComponentReference.mo
Expand Up @@ -881,14 +881,10 @@ algorithm
b := matchcontinue(cr)
local
DAE.ComponentRef comp;
Boolean b;
case(DAE.CREF_IDENT(identType = DAE.ET_COMPLEX(complexClassType=ClassInf.RECORD(_)))) then true;
/* this case is false because it is not the last ident.
case(DAE.CREF_QUAL(identType = DAE.ET_COMPLEX(complexClassType=ClassInf.RECORD(_)))) then true;*/
case(DAE.CREF_QUAL(componentRef=comp))
equation
b = isRecord(comp);
then b;
case(DAE.CREF_QUAL(componentRef=comp)) then isRecord(comp);
case(_) then false;
end matchcontinue;
end isRecord;
Expand Down
2 changes: 1 addition & 1 deletion Compiler/DAEUtil.mo
Expand Up @@ -3747,7 +3747,7 @@ algorithm
case ((DAE.STMT_ASSIGN_ARR(type_ = tp,componentRef = cr, exp = e, source = source) :: xs),func,extraArg)
equation
(e_1, extraArg) = func(e, extraArg);
(e_2 as DAE.CREF(cr_1,_), extraArg) = func(DAE.CREF(cr,DAE.ET_OTHER()), extraArg);
(e_2 as DAE.CREF(cr_1,_), extraArg) = func(DAE.CREF(cr,tp), extraArg);
(xs_1, extraArg) = traverseDAEEquationsStmts(xs, func, extraArg);
then (DAE.STMT_ASSIGN_ARR(tp,cr_1,e_1,source) :: xs_1,extraArg);

Expand Down

0 comments on commit 29d6412

Please sign in to comment.