Skip to content

Commit

Permalink
- fix bugs
Browse files Browse the repository at this point in the history
- DAEUtil.mo
  - improve function traverseDAEEquationsStmts

git-svn-id: https://openmodelica.org/svn/OpenModelica/branches/sjoelund-functiontree@6690 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Jens Frenkel committed Oct 28, 2010
1 parent 05f689c commit 4a2b23b
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 141 deletions.
134 changes: 10 additions & 124 deletions Compiler/Algorithm.mo
Expand Up @@ -693,133 +693,19 @@ public function getAllExpsStmts "function: getAllExpsStmts
input list<Statement> stmts;
output list<DAE.Exp> exps;
list<list<DAE.Exp>> expslist;
list<Statement> stms;
algorithm
expslist := Util.listMap(stmts, getAllExpsStmt);
exps := Util.listFlatten(expslist);
(stms,exps) := DAEUtil.traverseDAEEquationsStmts(stmts,getAllExpsStmtsCollecter,{});
end getAllExpsStmts;

protected function getAllExpsStmt "function: getAllExpsStmt
Returns all expressions in a statement."
input Statement inStatement;
output list<DAE.Exp> outExpExpLst;
algorithm
outExpExpLst:=
matchcontinue (inStatement)
local
DAE.Exp crexp,exp,e1,e2;
DAE.ExpType expty;
DAE.ComponentRef cr;
list<DAE.Exp> exps,explist,exps1,elseexps,fargs;
list<Statement> stmts;
Else else_;
Boolean flag;
Ident id;
Statement elsew;
Absyn.Path fname;
case DAE.STMT_ASSIGN(type_ = expty,exp1 = (e2 as DAE.CREF(cr,_)),exp = exp)
equation
crexp = Expression.makeCrefExp(cr,expty);
then
{crexp,exp};
case DAE.STMT_ASSIGN(type_ = expty,exp1 = (e2 as DAE.ASUB(e1,ea2)),exp = exp)
local list<DAE.Exp> ea2;
equation
then
{e2,exp};
case DAE.STMT_TUPLE_ASSIGN(type_ = expty,expExpLst = explist,exp = exp)
equation
exps = listAppend(explist, {exp});
then
exps;
case DAE.STMT_ASSIGN_ARR(type_ = expty,componentRef = cr,exp = exp)
equation
crexp = Expression.makeCrefExp(cr,expty);
then
{crexp,exp};
case DAE.STMT_IF(exp = exp,statementLst = stmts,else_ = else_)
equation
exps1 = getAllExpsStmts(stmts);
elseexps = getAllExpsElse(else_);
exps = listAppend(exps1, elseexps);
then
(exp :: exps);
case DAE.STMT_FOR(type_ = expty,iterIsArray = flag,ident = id,exp = exp,statementLst = stmts)
equation
exps = getAllExpsStmts(stmts);
then
(exp :: exps);
case DAE.STMT_WHILE(exp = exp,statementLst = stmts)
equation
exps = getAllExpsStmts(stmts);
then
(exp :: exps);
case DAE.STMT_WHEN(exp = exp,statementLst = stmts, elseWhen=SOME(elsew))
equation
exps1 = getAllExpsStmt(elsew);
exps = list_append(getAllExpsStmts(stmts),exps1);
then
(exp :: exps);
case DAE.STMT_WHEN(exp = exp,statementLst = stmts)
equation
exps = getAllExpsStmts(stmts);
then
(exp :: exps);
case DAE.STMT_ASSERT(cond = e1,msg= e2) then {e1,e2};
case DAE.STMT_BREAK(source = _) then {};
case DAE.STMT_RETURN(source = _) then {};
case DAE.STMT_FAILURE(body = stmts) then getAllExpsStmts(stmts);
case DAE.STMT_THROW(source = _) then {};
case DAE.STMT_TRY(tryBody = stmts)
equation
exps = getAllExpsStmts(stmts);
then
exps;
case DAE.STMT_CATCH(catchBody = stmts)
equation
exps = getAllExpsStmts(stmts);
then
exps;

case DAE.STMT_NORETCALL(exp = e1) then {e1};

case(DAE.STMT_REINIT(var = e1, value = e2)) then {e1,e2};

case(DAE.STMT_MATCHCASES(caseStmt = exps)) then exps;

case _
equation
Debug.fprintln("failtrace", "- Algorithm.getAllExpsStmt failed");
then
fail();
end matchcontinue;
end getAllExpsStmt;

protected function getAllExpsElse "function: getAllExpsElse
Helper function to getAllExpsStmt."
input Else inElse;
output list<DAE.Exp> outExpExpLst;
function getAllExpsStmtsCollecter
input DAE.Exp exp;
input list<DAE.Exp> inExps;
output DAE.Exp oexp;
output list<DAE.Exp> outExps;
algorithm
outExpExpLst:=
matchcontinue (inElse)
local
list<DAE.Exp> exps1,elseexps,exps;
DAE.Exp exp;
list<Statement> stmts;
Else else_;
case DAE.NOELSE() then {};
case DAE.ELSEIF(exp = exp,statementLst = stmts,else_ = else_)
equation
exps1 = getAllExpsStmts(stmts);
elseexps = getAllExpsElse(else_);
exps = listAppend(exps1, elseexps);
then
(exp :: exps);
case DAE.ELSE(statementLst = stmts)
equation
exps = getAllExpsStmts(stmts);
then
exps;
end matchcontinue;
end getAllExpsElse;
oexp:=exp;
outExps:=listAppend(inExps,{exp});
end getAllExpsStmtsCollecter;

end Algorithm;
7 changes: 1 addition & 6 deletions Compiler/BackendDAECreate.mo
Expand Up @@ -1721,12 +1721,7 @@ algorithm
inputs2 = BackendDAEUtil.statesAndVarsExp(e1,vars);
inputs = Util.listListUnionOnTrue({inputs1, inputs2}, Expression.expEqual);
then (inputs,{});
case(vars, DAE.STMT_TERMINATE(msg = e2))
equation
inputs = BackendDAEUtil.statesAndVarsExp(e2, vars);
then
(inputs, {});
// TODO: is the reinit var a input or a output
case(vars, DAE.STMT_TERMINATE(msg = _)) then ({}, {});
case(vars, DAE.STMT_REINIT(var = e as DAE.CREF(componentRef = _), value = e2))
equation
inputs = BackendDAEUtil.statesAndVarsExp(e2, vars);
Expand Down
64 changes: 53 additions & 11 deletions Compiler/DAEUtil.mo
Expand Up @@ -3750,6 +3750,24 @@ algorithm
(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);
case (((x as DAE.STMT_ASSIGN_ARR(type_ = tp,componentRef = cr, exp = e, source = source)) :: xs),func,extraArg)
equation
(e_1, extraArg) = func(e, extraArg);
failure((DAE.CREF(_,_), _) = func(DAE.CREF(cr,tp), extraArg));
true = RTOpts.debugFlag("failtrace");
print(DAEDump.ppStatementStr(x));
print("Warning, not allowed to set the componentRef to a expression in DAEUtil.traverseDAEEquationsStmts\n");
(xs_1, extraArg) = traverseDAEEquationsStmts(xs, func, extraArg);
then (DAE.STMT_ASSIGN_ARR(tp,cr,e_1,source) :: xs_1,extraArg);

case (((x as DAE.STMT_IF(exp=e,statementLst=stmts,else_ = el, source = source)) :: xs),func,extraArg)
local Algorithm.Else el,el_1;
equation
(el_1,extraArg) = traverseDAEEquationsStmtsElse(el,func,extraArg);
(stmts2,extraArg) = traverseDAEEquationsStmts(stmts,func,extraArg);
(e_1,extraArg) = func(e, extraArg);
(xs_1,extraArg) = traverseDAEEquationsStmts(xs, func, extraArg);
then (DAE.STMT_IF(e_1,stmts2,el_1,source) :: xs_1,extraArg);

case (((x as DAE.STMT_FOR(type_=tp,iterIsArray=b1,ident=id1,exp=e,statementLst=stmts, source = source)) :: xs),func,extraArg)
equation
Expand Down Expand Up @@ -3816,21 +3834,45 @@ algorithm
equation
(xs_1, extraArg) = traverseDAEEquationsStmts(xs, func, extraArg);
then (x :: xs_1,extraArg);

case (((x as DAE.STMT_IF(exp=e,statementLst=stmts,else_ = el, source = source)) :: xs),func,extraArg)
local Algorithm.Else el,el_1;
// MetaModelica extension. KS
case (((x as DAE.STMT_FAILURE(body=stmts, source = source)) :: xs),func,extraArg)
equation
(el_1,extraArg) = traverseDAEEquationsStmtsElse(el,func,extraArg);
(stmts2,extraArg) = traverseDAEEquationsStmts(stmts,func,extraArg);
(e_1,extraArg) = func(e, extraArg);
(xs_1,extraArg) = traverseDAEEquationsStmts(xs, func, extraArg);
then (DAE.STMT_IF(e_1,stmts2,el_1,source) :: xs_1,extraArg);

(stmts2, extraArg) = traverseDAEEquationsStmts(stmts,func,extraArg);
(xs_1, extraArg) = traverseDAEEquationsStmts(xs, func, extraArg);
then (DAE.STMT_FAILURE(stmts2,source) :: xs_1,extraArg);
case (((x as DAE.STMT_TRY(tryBody=stmts, source = source)) :: xs),func,extraArg)
equation
(stmts2, extraArg) = traverseDAEEquationsStmts(stmts,func,extraArg);
(xs_1, extraArg) = traverseDAEEquationsStmts(xs, func, extraArg);
then (DAE.STMT_TRY(stmts2,source) :: xs_1,extraArg);
case (((x as DAE.STMT_CATCH(catchBody=stmts, source = source)) :: xs),func,extraArg)
equation
(stmts2, extraArg) = traverseDAEEquationsStmts(stmts,func,extraArg);
(xs_1, extraArg) = traverseDAEEquationsStmts(xs, func, extraArg);
then (DAE.STMT_CATCH(stmts2,source) :: xs_1,extraArg);
case (((x as DAE.STMT_THROW(source = source)) :: xs),func,extraArg)
equation
(xs_1, extraArg) = traverseDAEEquationsStmts(xs, func, extraArg);
then (x :: xs_1,extraArg);
case (((x as DAE.STMT_GOTO(source = source)) :: xs),func,extraArg)
equation
(xs_1, extraArg) = traverseDAEEquationsStmts(xs, func, extraArg);
then (x :: xs_1,extraArg);
case (((x as DAE.STMT_LABEL(source = source)) :: xs),func,extraArg)
equation
(xs_1, extraArg) = traverseDAEEquationsStmts(xs, func, extraArg);
then (x :: xs_1,extraArg);
case (((x as DAE.STMT_MATCHCASES(matchType = matchType, inputExps = expl1,caseStmt=expl2, source = source)) :: xs),func,extraArg)
local Absyn.MatchType matchType;
equation
(expl1, extraArg) = traverseDAEExpList(expl1,func,extraArg);
(expl1, extraArg) = traverseDAEExpList(expl1,func,extraArg);
(xs_1, extraArg) = traverseDAEEquationsStmts(xs, func, extraArg);
then (DAE.STMT_MATCHCASES(matchType,expl1,expl2,source) :: xs_1,extraArg);
case ((x :: xs),func,extraArg)
equation
print("Warning, not implemented in replace_equations_stmts\n");
(xs_1,extraArg) = traverseDAEEquationsStmts(xs, func, extraArg);
then (x :: xs_1,extraArg);
then (x :: xs_1,extraArg);
end matchcontinue;
end traverseDAEEquationsStmts;

Expand Down

0 comments on commit 4a2b23b

Please sign in to comment.