Skip to content

Commit

Permalink
- Propagate input expressions of match expressions to codegen so we c…
Browse files Browse the repository at this point in the history
…an revert changes to them in each iteration

- Added test for Util.listSplitOnTrue


git-svn-id: https://openmodelica.org/svn/OpenModelica/branches/sjoelund-functiontree@6407 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Oct 18, 2010
1 parent 7ec410e commit 9386d7f
Show file tree
Hide file tree
Showing 16 changed files with 520 additions and 369 deletions.
1 change: 1 addition & 0 deletions Compiler/Absyn.mo
Expand Up @@ -573,6 +573,7 @@ uniontype Algorithm "The Algorithm type describes one algorithm statement in an

record ALG_MATCHCASES
MatchType matchType;
list<Exp> inputExps;
list<Exp> switchCases;
end ALG_MATCHCASES;

Expand Down
7 changes: 4 additions & 3 deletions Compiler/BackendVarTransform.mo
Expand Up @@ -417,7 +417,7 @@ algorithm
DAE.Statement statement,statement_1;
DAE.ExpType type_;
DAE.Exp e1_1,e2_1,e1,e2,e_1,e,e1_2,e2_2;
list<DAE.Exp> expExpLst,expExpLst_1;
list<DAE.Exp> expExpLst,expExpLst_1,inputExps;
DAE.Else else_,else_1;
DAE.ElementSource source;
String str;
Expand Down Expand Up @@ -565,12 +565,13 @@ algorithm
es_1 = replaceStatementLst(es, repl);
then
(DAE.STMT_LABEL(str,source):: es_1);
case ((DAE.STMT_MATCHCASES(matchType=matchType,caseStmt=expExpLst,source=source)::es),repl)
case ((DAE.STMT_MATCHCASES(matchType=matchType,inputExps=inputExps,caseStmt=expExpLst,source=source)::es),repl)
equation
inputExps = Util.listMap2(inputExps,VarTransform.replaceExp,repl, NONE);
expExpLst_1 = Util.listMap2(expExpLst,VarTransform.replaceExp,repl, NONE);
es_1 = replaceStatementLst(es, repl);
then
(DAE.STMT_MATCHCASES(matchType,expExpLst_1,source):: es_1);
(DAE.STMT_MATCHCASES(matchType,inputExps,expExpLst_1,source):: es_1);
case ((statement::es),repl)
equation
es_1 = replaceStatementLst(es, repl);
Expand Down
1 change: 1 addition & 0 deletions Compiler/DAE.mo
Expand Up @@ -572,6 +572,7 @@ uniontype Statement "There are four kinds of statements. Assignments (`a := b;\

record STMT_MATCHCASES "match[continue] helper"
Absyn.MatchType matchType;
list<Exp> inputExps "for now these are idents; they should be full expressions (but the cases are not split into matching and assignments...)";
list<Exp> caseStmt;
ElementSource source "the origin of the component/equation/algorithm";
end STMT_MATCHCASES;
Expand Down
12 changes: 6 additions & 6 deletions Compiler/DAELow.mo
Expand Up @@ -9676,7 +9676,7 @@ algorithm
list<DAE.Statement> rest,st,stlst,stlst1;
DAE.Statement s,s1;
DAE.Exp e,e1,e_1,e1_1;
list<DAE.Exp> elst,elst1;
list<DAE.Exp> elst,elst1,inputExps;
DAE.ExpType t;
DAE.ComponentRef cr,cr1;
DAE.Else else_,else_1;
Expand Down Expand Up @@ -9811,12 +9811,12 @@ algorithm
st = replaceDummyDerAlgs1(rest,inExp2,inExp3);
then
(DAE.STMT_LABEL(labelName,source)::st);
case (DAE.STMT_MATCHCASES(matchType=matchType,caseStmt=elst,source=source)::rest,inExp2,inExp3)
case (DAE.STMT_MATCHCASES(matchType=matchType,inputExps=inputExps,caseStmt=elst,source=source)::rest,inExp2,inExp3)
equation
(elst1,_) = Exp.replaceListExp(elst,inExp2,inExp3);
st = replaceDummyDerAlgs1(rest,inExp2,inExp3);
then
(DAE.STMT_MATCHCASES(matchType,elst1,source)::st);
(DAE.STMT_MATCHCASES(matchType,inputExps,elst1,source)::st);
case (_,_,_)
equation
print("-DAELow.replaceDummyDerAlgs1 failed\n");
Expand Down Expand Up @@ -10018,7 +10018,7 @@ algorithm
list<DAE.Statement> rest,st,stlst,stlst1;
DAE.Statement s,s1;
DAE.Exp e,e1,e_1,e1_1;
list<DAE.Exp> elst,elst1;
list<DAE.Exp> elst,elst1,inputExps;
DAE.ExpType t;
DAE.ComponentRef cr,cr1;
DAE.Else else_,else_1;
Expand Down Expand Up @@ -10154,12 +10154,12 @@ algorithm
(st,vars) = replaceDummyDerOthersAlgs1(rest,inVariables);
then
(DAE.STMT_LABEL(labelName,source)::st,vars);
case (DAE.STMT_MATCHCASES(matchType=matchType,caseStmt=elst,source=source)::rest,inVariables)
case (DAE.STMT_MATCHCASES(matchType=matchType,inputExps=inputExps,caseStmt=elst,source=source)::rest,inVariables)
equation
(elst1,vars) = replaceDummyDerOthersExpLst(elst,inVariables);
(st,vars1) = replaceDummyDerOthersAlgs1(rest,vars);
then
(DAE.STMT_MATCHCASES(matchType,elst1,source)::st,vars1);
(DAE.STMT_MATCHCASES(matchType,inputExps,elst1,source)::st,vars1);
case (_,_)
equation
print("-DAELow.replaceDummyDerOthersAlgs1 failed\n");
Expand Down
2 changes: 1 addition & 1 deletion Compiler/DFA.mo
Expand Up @@ -1491,7 +1491,7 @@ algorithm
(dfaEnv, invalidDecls, cache) := getMatchContinueInvalidDeclsAndInitialEnv(inputVarList, resVarList, cache, localEnv, info);
checkShadowing(declList,invalidDecls);
(outCache, cases) := matchContinueToSwitch2(patMat, caseLocalDecls, inputVarList, resVarList, rhlist, elseRhSide, cache, localEnv, invalidDecls, dfaEnv, info);
alg := Absyn.ALG_MATCHCASES(matchType,cases);
alg := Absyn.ALG_MATCHCASES(matchType,inputVarList,cases);
algItem := Absyn.ALGORITHMITEM(alg, NONE(), info);
expr := Absyn.VALUEBLOCK(declList,Absyn.VALUEBLOCKALGORITHMS({algItem}),Absyn.BOOL(true));
end matchContinueToSwitch;
Expand Down
6 changes: 4 additions & 2 deletions Compiler/Dump.mo
Expand Up @@ -5994,7 +5994,7 @@ algorithm
Absyn.ForIterators iterators;
Absyn.ComponentRef functionCall;
Absyn.FunctionArgs functionArgs;
list<Absyn.Exp> switchCases;
list<Absyn.Exp> inputExps, switchCases;
String label;
Absyn.AlgorithmItem equ;
Absyn.MatchType matchType;
Expand Down Expand Up @@ -6076,10 +6076,12 @@ algorithm
equation
Print.printBuf("record Absyn.ALG_THROW end Absyn.ALG_THROW;");
then ();
case Absyn.ALG_MATCHCASES(matchType,switchCases)
case Absyn.ALG_MATCHCASES(matchType,inputExps,switchCases)
equation
Print.printBuf("record Absyn.ALG_MATCHCASES matchType = ");
printMatchTypeAsCorbaString(matchType);
Print.printBuf(", inputExps = ");
printListAsCorbaString(inputExps, printExpAsCorbaString, ",");
Print.printBuf(", switchCases = ");
printListAsCorbaString(switchCases, printExpAsCorbaString, ",");
Print.printBuf(" end Absyn.ALG_MATCHCASES;");
Expand Down
7 changes: 4 additions & 3 deletions Compiler/Inline.mo
Expand Up @@ -804,7 +804,7 @@ algorithm
Algorithm.Statement stmt,stmt_1;
DAE.ExpType t;
DAE.Exp e,e_1,e1,e1_1,e2,e2_1;
list<DAE.Exp> explst,explst_1;
list<DAE.Exp> explst,explst_1,inputExps;
DAE.ComponentRef cref;
Algorithm.Else a_else,a_else_1;
list<Algorithm.Statement> stmts,stmts_1;
Expand Down Expand Up @@ -894,11 +894,12 @@ algorithm
stmts_1 = Util.listMap1(stmts,inlineStatement,fns);
then
DAE.STMT_CATCH(stmts_1,source);
case(DAE.STMT_MATCHCASES(matchType,explst,source),fns)
case(DAE.STMT_MATCHCASES(matchType,inputExps,explst,source),fns)
equation
inputExps = Util.listMap1(inputExps,inlineExp,fns);
explst_1 = Util.listMap1(explst,inlineExp,fns);
then
DAE.STMT_MATCHCASES(matchType,explst_1,source);
DAE.STMT_MATCHCASES(matchType,inputExps,explst_1,source);
case(stmt,_) then stmt;
end matchcontinue;
end inlineStatement;
Expand Down
16 changes: 7 additions & 9 deletions Compiler/InstSection.mo
Expand Up @@ -2346,9 +2346,10 @@ algorithm
Absyn.ComponentRef cr;
Absyn.Exp e,cond,msg, assignComp,var,value,elseWhenC,vb,matchExp;
Boolean impl,onlyCref,tupleExp;
list<DAE.Exp> expl_1,expl_2;
list<Absyn.Exp> absynExpList,inputExps,expl;
list<DAE.Exp> expl_1,expl_2,inputExpsDAE;
Absyn.MatchType matchType;
list<DAE.Properties> cprops, eprops;
list<Absyn.Exp> expl;
String s,i;
list<DAE.Statement> tb_1,fb_1,sl_1,stmts;
list<tuple<DAE.Exp, DAE.Properties, list<DAE.Statement>>> eib_1;
Expand Down Expand Up @@ -2798,16 +2799,13 @@ algorithm
(cache,{stmt});

// Helper statement for matchcontinue
case (cache,env,ih,pre,SCode.ALG_MATCHCASES(matchType = matchType, switchCases = absynExpList, comment = comment, info = info),source,_,impl,unrollForLoops)
local
Absyn.MatchType matchType;
list<Absyn.Exp> absynExpList;
list<DAE.Exp> expExpList;
case (cache,env,ih,pre,SCode.ALG_MATCHCASES(matchType = matchType, inputExps = inputExps, switchCases = expl, comment = comment, info = info),source,_,impl,unrollForLoops)
equation
true = RTOpts.acceptMetaModelicaGrammar();
(cache,expExpList,_,_) = Static.elabExpList(cache,env, absynExpList, impl, NONE,true,pre,info);
(cache,expl_1,_,_) = Static.elabExpList(cache,env, expl, impl, NONE,true,pre,info);
(cache,inputExpsDAE,_,_) = Static.elabExpList(cache,env, inputExps, impl, NONE,true,pre,info);
source = DAEUtil.addElementSourceFileInfo(source, info);
stmt = DAE.STMT_MATCHCASES(matchType,expExpList,source);
stmt = DAE.STMT_MATCHCASES(matchType,inputExpsDAE,expl_1,source);
then (cache,{stmt});

//------------------------------------------
Expand Down
14 changes: 8 additions & 6 deletions Compiler/PartFn.mo
Expand Up @@ -838,7 +838,7 @@ algorithm
list<DAE.Function> dae;
DAE.ExpType ty;
DAE.Exp e,e_1,e1,e1_1,e2,e2_1;
list<DAE.Exp> elst,elst_1;
list<DAE.Exp> elst,elst_1,inputExps;
DAE.Else els,els_1;
Boolean b;
Ident i;
Expand Down Expand Up @@ -936,12 +936,13 @@ algorithm
(cdr_1,dae) = elabStmts(cdr,dae);
then
(DAE.STMT_CATCH(stmts_1,source) :: cdr_1,dae);
case(DAE.STMT_MATCHCASES(matchType,elst,source) :: cdr,dae)
case(DAE.STMT_MATCHCASES(matchType,inputExps,elst,source) :: cdr,dae)
equation
(elst_1,dae) = elabExpList(elst,dae);
(inputExps,dae) = elabExpList(inputExps,dae);
(cdr_1,dae) = elabStmts(cdr,dae);
then
(DAE.STMT_MATCHCASES(matchType,elst_1,source) :: cdr_1,dae);
(DAE.STMT_MATCHCASES(matchType,inputExps,elst_1,source) :: cdr_1,dae);
case(stmt :: cdr,dae)
equation
(cdr_1,dae) = elabStmts(cdr,dae);
Expand Down Expand Up @@ -1558,7 +1559,7 @@ algorithm
DAE.Statement stmt,stmt_1;
list<Integer> ilst;
DAE.Exp e,e_1,e1,e1_1,e2,e2_1;
list<DAE.Exp> elst,elst_1;
list<DAE.Exp> elst,elst_1,inputExps;
DAE.ElementSource source;
Absyn.MatchType matchType;
case({},_,_,_,_) then {};
Expand Down Expand Up @@ -1657,12 +1658,13 @@ algorithm
cdr_1 = fixCallsAlg(cdr,dae,p,inputs,current);
then
DAE.STMT_CATCH(stmts_1,source) :: cdr_1;
case(DAE.STMT_MATCHCASES(matchType,elst,source) :: cdr,dae,p,inputs,current)
case(DAE.STMT_MATCHCASES(matchType,inputExps,elst,source) :: cdr,dae,p,inputs,current)
equation
inputExps = Util.listMap1(inputExps,handleExpList2,(p,inputs,dae,current));
elst_1 = Util.listMap1(elst,handleExpList2,(p,inputs,dae,current));
cdr_1 = fixCallsAlg(cdr,dae,p,inputs,current);
then
DAE.STMT_MATCHCASES(matchType,elst_1,source) :: cdr_1;
DAE.STMT_MATCHCASES(matchType,inputExps,elst_1,source) :: cdr_1;
case(stmt :: cdr,dae,p,inputs,current)
equation
cdr_1 = fixCallsAlg(cdr,dae,p,inputs,current);
Expand Down
7 changes: 4 additions & 3 deletions Compiler/SCode.mo
Expand Up @@ -408,6 +408,7 @@ public uniontype Statement "The Statement type describes one algorithm statement

record ALG_MATCHCASES
Absyn.MatchType matchType;
list<Absyn.Exp> inputExps;
list<Absyn.Exp> switchCases;
Option<Comment> comment;
Absyn.Info info;
Expand Down Expand Up @@ -2519,7 +2520,7 @@ algorithm
Absyn.ForIterators iterators;
Absyn.FunctionArgs functionArgs;
Absyn.Info info;
list<Absyn.Exp> switchCases,conditions;
list<Absyn.Exp> inputExps,switchCases,conditions;
list<list<Statement>> stmtsList;
list<Statement> body,trueBranch,elseBranch;
list<tuple<Absyn.Exp, list<Statement>>> branches;
Expand Down Expand Up @@ -2587,8 +2588,8 @@ algorithm
case ALG_THROW(comment,info)
then Absyn.ALGORITHMITEM(Absyn.ALG_THROW(),NONE(),info);

case ALG_MATCHCASES(matchType,switchCases,comment,info)
then Absyn.ALGORITHMITEM(Absyn.ALG_MATCHCASES(matchType,switchCases),NONE(),info);
case ALG_MATCHCASES(matchType,inputExps,switchCases,comment,info)
then Absyn.ALGORITHMITEM(Absyn.ALG_MATCHCASES(matchType,inputExps,switchCases),NONE(),info);

case ALG_GOTO(labelName,comment,info)
then Absyn.ALGORITHMITEM(Absyn.ALG_GOTO(labelName),NONE(),info);
Expand Down
6 changes: 3 additions & 3 deletions Compiler/SCodeUtil.mo
Expand Up @@ -690,7 +690,7 @@ algorithm
Absyn.ForIterators iterators;
Absyn.FunctionArgs functionArgs;
Absyn.Exp assignComponent,value,boolExpr,elseIfBoolExpr;
list<Absyn.Exp> conditions,switchCases;
list<Absyn.Exp> conditions,switchCases,inputExps;
list<SCode.Statement> stmts,stmts1,stmts2;
list<list<SCode.Statement>> stmtsList;
list<tuple<Absyn.Exp, list<Absyn.AlgorithmItem>>> branches;
Expand Down Expand Up @@ -749,8 +749,8 @@ algorithm
case (Absyn.ALG_THROW(),comment,info)
then SCode.ALG_THROW(comment,info);

case (Absyn.ALG_MATCHCASES(matchType,switchCases),comment,info)
then SCode.ALG_MATCHCASES(matchType,switchCases,comment,info);
case (Absyn.ALG_MATCHCASES(matchType,inputExps,switchCases),comment,info)
then SCode.ALG_MATCHCASES(matchType,inputExps,switchCases,comment,info);

case (Absyn.ALG_GOTO(labelName),comment,info)
then SCode.ALG_GOTO(labelName,comment,info);
Expand Down

0 comments on commit 9386d7f

Please sign in to comment.