Skip to content

Commit

Permalink
- Fixed else for match expressions
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@6198 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Sep 23, 2010
1 parent d73eb81 commit 4efbb1a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
23 changes: 17 additions & 6 deletions Compiler/DFA.mo
Expand Up @@ -2131,6 +2131,7 @@ public function matchContinueToSwitch
input list<Absyn.ElementItem> declList;
input list<Absyn.Exp> resVarList;
input RightHandList rhlist;
input Option<RightHandSide> elseRhSide;
input Env.Cache cache;
input Env.Env localEnv;
output Env.Cache outCache;
Expand All @@ -2144,7 +2145,7 @@ protected
algorithm
(dfaEnv, invalidDecls, cache) := getMatchContinueInvalidDeclsAndInitialEnv(inputVarList, resVarList, cache, localEnv);
checkShadowing(declList,invalidDecls);
(outCache, cases) := matchContinueToSwitch2(patMat, caseLocalDecls, inputVarList, resVarList, rhlist, cache, localEnv, invalidDecls, dfaEnv);
(outCache, cases) := matchContinueToSwitch2(patMat, caseLocalDecls, inputVarList, resVarList, rhlist, elseRhSide, cache, localEnv, invalidDecls, dfaEnv);
alg := Absyn.ALG_MATCHCASES(matchType,cases);
algItem := Absyn.ALGORITHMITEM(alg, NONE(), Absyn.dummyInfo);
expr := Absyn.VALUEBLOCK(declList,Absyn.VALUEBLOCKALGORITHMS({algItem}),Absyn.BOOL(true));
Expand All @@ -2156,14 +2157,15 @@ protected function matchContinueToSwitch2
input list<Absyn.Exp> inputVarList;
input list<Absyn.Exp> resVarList;
input RightHandList rhlist;
input Option<RightHandSide> elseRhSide;
input Env.Cache cache;
input Env.Env localEnv;
input list<String> invalidDecls;
input list<tuple<Absyn.Ident,Absyn.TypeSpec>> initialDfaEnv;
output Env.Cache outCache;
output list<Absyn.Exp> expr;
algorithm
(outCache, expr) := matchcontinue (patMat, caseLocalDecls, inputVarList, resVarList, rhlist, cache, localEnv, invalidDecls, initialDfaEnv)
(outCache, expr) := matchcontinue (patMat, caseLocalDecls, inputVarList, resVarList, rhlist, elseRhSide, cache, localEnv, invalidDecls, initialDfaEnv)
local
RenamedPatList firstCase;
RenamedPatMatrix2 restCase;
Expand All @@ -2180,8 +2182,17 @@ algorithm
tuple<Integer,list<Absyn.AlgorithmItem>> res;
list<list<Absyn.AlgorithmItem>> caseAlgs;
list<String> dfaEnvIdents;
case ({}, {}, _, _, {}, localCache, _, _, _) then (localCache, {});
case (firstCase :: restCase, firstDecls :: restDecls,inputVarList, resVarList, RIGHTHANDSIDE(localList,body,result,_) :: restRh, localCache, localEnv, invalidDecls, initialDfaEnv)
case ({}, {}, _, _, {}, NONE(), localCache, _, _, _) then (localCache, {});
case ({}, {firstDecls}, _, _, {}, SOME(RIGHTHANDSIDE(_,body,result,_)), localCache, _, _, _)
equation
checkShadowing(firstDecls,invalidDecls);
exp2 = createListFromExpression(result);
algs3 = createLastAssignments(resVarList,exp2,{});
algs = {};
els = firstDecls;
expr = Absyn.VALUEBLOCK(els,Absyn.VALUEBLOCKMATCHCASE(algs,body,algs3),Absyn.BOOL(true));
then (localCache, {expr});
case (firstCase :: restCase, firstDecls :: restDecls,inputVarList, resVarList, RIGHTHANDSIDE(localList,body,result,_) :: restRh, elseRhSide, localCache, localEnv, invalidDecls, initialDfaEnv)
equation
dfaEnv = initialDfaEnv;
checkShadowing(firstDecls,invalidDecls);
Expand All @@ -2193,9 +2204,9 @@ algorithm
(localCache, dfaEnv, els, algs) = generatePathVarDeclarationsList(firstCase, inputVarList, localCache, localEnv, dfaEnv);
els = listAppend(els, firstDecls);
expr = Absyn.VALUEBLOCK(els,Absyn.VALUEBLOCKMATCHCASE(algs,body,algs3),Absyn.BOOL(true));
(cache, exp2) = matchContinueToSwitch2(restCase, restDecls, inputVarList, resVarList, restRh, localCache, localEnv, invalidDecls, initialDfaEnv);
(cache, exp2) = matchContinueToSwitch2(restCase, restDecls, inputVarList, resVarList, restRh, elseRhSide, localCache, localEnv, invalidDecls, initialDfaEnv);
then (cache, expr :: exp2);
case (_,_,_,_,_,_,_,_,_)
case (_,_,_,_,_,_,_,_,_,_)
equation
Debug.fprintln("matchcase", "- DFA.matchContinueToSwitch2 failed");
then fail();
Expand Down
5 changes: 3 additions & 2 deletions Compiler/Patternm.mo
Expand Up @@ -262,7 +262,8 @@ algorithm
RightHandList localRhListIn,localRhLightList,var2,var3;
Option<RightHandSide> var5;
Integer localCaseNum;
case ({},localRhListIn,localRhLightList,localPatListIn,_,localCache,_) equation then (localCache,localRhListIn,localRhLightList,localPatListIn,NONE());
case ({},localRhListIn,localRhLightList,localPatListIn,_,localCache,_)
equation then (localCache,localRhListIn,localRhLightList,localPatListIn,NONE());
case (Absyn.CASE(localPat,localDecl,localEq,localRes,_) :: rest,
localRhListIn,localRhLightList,localPatListIn,localCaseNum,localCache,localEnv)
equation
Expand Down Expand Up @@ -828,7 +829,7 @@ algorithm
// The rhList version is a "light" version of the rightHandSides so that
// we do not have to carry around a lot of extra code in the pattern match algorithm
patMat2 = Util.listlistTranspose(patMat2);
(localCache, expr) = DFA.matchContinueToSwitch(matchType,patMat2,caseLocalDeclList,inputVarList,declList,localResultVarList,rhList2,localCache,localEnv);
(localCache, expr) = DFA.matchContinueToSwitch(matchType,patMat2,caseLocalDeclList,inputVarList,declList,localResultVarList,rhList2,elseRhSide,localCache,localEnv);
then (localCache, expr);
/*
Expand Down

0 comments on commit 4efbb1a

Please sign in to comment.