Skip to content

Commit aa171bb

Browse files
committed
- Removed some useless information from the pattern matching algorithm
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@7002 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
1 parent 1855643 commit aa171bb

File tree

4 files changed

+2356
-2390
lines changed

4 files changed

+2356
-2390
lines changed

Compiler/DFA.mo

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1465,7 +1465,6 @@ end printSimpleArcs;
14651465
public function matchContinueToSwitch
14661466
input Absyn.MatchType matchType;
14671467
input RenamedPatMatrix2 patMat;
1468-
input list<list<Absyn.ElementItem>> caseLocalDecls;
14691468
input list<Absyn.Exp> inputVarList; // matchcontinue (var1,var2,...)
14701469
input list<Absyn.ElementItem> declList;
14711470
input list<Absyn.Exp> resVarList;
@@ -1485,15 +1484,14 @@ protected
14851484
algorithm
14861485
(dfaEnv, invalidDecls, cache) := getMatchContinueInvalidDeclsAndInitialEnv(inputVarList, resVarList, cache, localEnv, info);
14871486
Util.SUCCESS() := checkShadowing(declList,invalidDecls,Util.SUCCESS());
1488-
(outCache, cases) := matchContinueToSwitch2(patMat, caseLocalDecls, inputVarList, resVarList, rhlist, elseRhSide, cache, localEnv, invalidDecls, dfaEnv, info);
1487+
(outCache, cases) := matchContinueToSwitch2(patMat, inputVarList, resVarList, rhlist, elseRhSide, cache, localEnv, invalidDecls, dfaEnv, info);
14891488
alg := Absyn.ALG_MATCHCASES(matchType,inputVarList,cases);
14901489
algItem := Absyn.ALGORITHMITEM(alg, NONE(), info);
14911490
expr := Absyn.VALUEBLOCK(declList,Absyn.VALUEBLOCKALGORITHMS({algItem}),Absyn.BOOL(true));
14921491
end matchContinueToSwitch;
14931492

14941493
protected function matchContinueToSwitch2
14951494
input RenamedPatMatrix2 patMat;
1496-
input list<list<Absyn.ElementItem>> caseLocalDecls;
14971495
input list<Absyn.Exp> inputVarList;
14981496
input list<Absyn.Exp> resVarList;
14991497
input RightHandList rhlist;
@@ -1506,7 +1504,7 @@ protected function matchContinueToSwitch2
15061504
output Env.Cache outCache;
15071505
output list<Absyn.Exp> exprs;
15081506
algorithm
1509-
(outCache, exprs) := matchcontinue (patMat, caseLocalDecls, inputVarList, resVarList, rhlist, elseRhSide, cache, localEnv, invalidDecls, initialDfaEnv, info)
1507+
(outCache, exprs) := matchcontinue (patMat, inputVarList, resVarList, rhlist, elseRhSide, cache, localEnv, invalidDecls, initialDfaEnv, info)
15101508
local
15111509
RenamedPatList firstCase;
15121510
RenamedPatMatrix2 restCase;
@@ -1524,34 +1522,34 @@ algorithm
15241522
list<list<Absyn.AlgorithmItem>> caseAlgs;
15251523
list<String> dfaEnvIdents;
15261524

1527-
case ({}, {}, _, _, {}, NONE(), localCache, _, _, _, _) then (localCache, {});
1525+
case ({}, _, _, {}, NONE(), localCache, _, _, _, _) then (localCache, {});
15281526

1529-
case ({}, {firstDecls}, _, _, {}, SOME(RIGHTHANDSIDE(_,body,result,_)), localCache, _, _, _, info)
1527+
case ({}, _, _, {}, SOME(RIGHTHANDSIDE(localList,body,result,_)), localCache, _, _, _, info)
15301528
equation
1531-
Util.SUCCESS() = checkShadowing(firstDecls,invalidDecls,Util.SUCCESS());
1529+
Util.SUCCESS() = checkShadowing(localList,invalidDecls,Util.SUCCESS());
15321530
exp2 = createListFromExpression(result,resVarList);
15331531
algs3 = createLastAssignments(resVarList,exp2,info);
15341532
algs = {};
1535-
els = firstDecls;
1533+
els = localList;
15361534
expr = Absyn.VALUEBLOCK(els,Absyn.VALUEBLOCKMATCHCASE(algs,body,algs3),Absyn.BOOL(true));
15371535
then (localCache, {expr});
15381536

1539-
case (firstCase :: restCase, firstDecls :: restDecls,inputVarList, resVarList, RIGHTHANDSIDE(localList,body,result,_) :: restRh, elseRhSide, localCache, localEnv, invalidDecls, initialDfaEnv, info)
1537+
case (firstCase :: restCase, inputVarList, resVarList, RIGHTHANDSIDE(localList,body,result,_) :: restRh, elseRhSide, localCache, localEnv, invalidDecls, initialDfaEnv, info)
15401538
equation
15411539
dfaEnv = initialDfaEnv;
1542-
Util.SUCCESS() = checkShadowing(firstDecls,invalidDecls,Util.SUCCESS());
1540+
Util.SUCCESS() = checkShadowing(localList,invalidDecls,Util.SUCCESS());
15431541

15441542
exp2 = createListFromExpression(result,resVarList);
15451543

15461544
// Create the assignments that assign the return variables
15471545
algs3 = createLastAssignments(resVarList,exp2,info);
15481546
(localCache, dfaEnv, els, algs) = generatePathVarDeclarationsList(firstCase, inputVarList, localCache, localEnv, dfaEnv, info);
1549-
els = listAppend(els, firstDecls);
1547+
els = listAppend(els, localList);
15501548
expr = Absyn.VALUEBLOCK(els,Absyn.VALUEBLOCKMATCHCASE(algs,body,algs3),Absyn.BOOL(true));
1551-
(cache, exp2) = matchContinueToSwitch2(restCase, restDecls, inputVarList, resVarList, restRh, elseRhSide, localCache, localEnv, invalidDecls, initialDfaEnv, info);
1549+
(cache, exp2) = matchContinueToSwitch2(restCase, inputVarList, resVarList, restRh, elseRhSide, localCache, localEnv, invalidDecls, initialDfaEnv, info);
15521550
then (cache, expr :: exp2);
15531551

1554-
case (_,_,_,_,_,_,_,_,_,_,_)
1552+
case (_,_,_,_,_,_,_,_,_,_)
15551553
equation
15561554
Debug.fprintln("matchcase", "- DFA.matchContinueToSwitch2 failed");
15571555
then fail();

Compiler/Error.mo

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,5 +1032,20 @@ algorithm
10321032
end matchcontinue;
10331033
end fixFilenameForTestsuite;
10341034

1035+
public function assertion
1036+
"Used to make compiler-internal assertions. These messages are not meant
1037+
to be shown to a user, but rather to show internal error messages."
1038+
input Boolean b;
1039+
input String message;
1040+
algorithm
1041+
_ := match (b,message)
1042+
case (true,_) then ();
1043+
else
1044+
equation
1045+
addMessage(INTERNAL_ERROR, {message});
1046+
then fail();
1047+
end match;
1048+
end assertion;
1049+
10351050
end Error;
10361051

Compiler/Patternm.mo

Lines changed: 2 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,6 @@ algorithm
790790
// Get the pattern matrix, etc.
791791
(localCache,inputVarList,declList,rhList2,rhList,patMat,elseRhSide) = ASTtoMatrixForm(localMatchCont,localCache,localEnv,info);
792792
Absyn.MATCHEXP(matchTy=matchType,cases=cases) = localMatchCont;
793-
caseLocalDeclList = Util.listMap(cases, getCaseDecls);
794793
patMat2 = arrayList(patMat);
795794

796795
// A small fix.
@@ -815,56 +814,10 @@ algorithm
815814
// The rhList version is a "light" version of the rightHandSides so that
816815
// we do not have to carry around a lot of extra code in the pattern match algorithm
817816
patMat2 = Util.listlistTranspose(patMat2);
818-
(localCache, expr) = DFA.matchContinueToSwitch(matchType,patMat2,caseLocalDeclList,inputVarList,declList,localResultVarList,rhList2,elseRhSide,localCache,localEnv,info);
817+
// Error.assertion(listLength(patMat2) == listLength(cases), "Patternm.matchmain didn't get a correct matrix");
818+
(localCache, expr) = DFA.matchContinueToSwitch(matchType,patMat2,inputVarList,declList,localResultVarList,rhList2,elseRhSide,localCache,localEnv,info);
819819
then (localCache, expr);
820-
/*
821820

822-
case (localMatchCont,localResultVarList,localCache,localEnv)
823-
equation
824-
// Get the pattern matrix, etc.
825-
(localCache,inputVarList,declList,rhList2,rhList,patMat,elseRhSide) =
826-
ASTtoMatrixForm(localMatchCont,localCache,localEnv);
827-
patMat2 = arrayList(patMat);
828-
829-
// A small fix.
830-
patMat2 = DFA.matrixFix(patMat2);
831-
832-
// -------------------
833-
// ---Type Checking---
834-
// -------------------
835-
// Two sorts of type checkings are performed:
836-
// - The type of the input variables are looked up
837-
// and matched against the patterns in each case clause
838-
// - The type of the return variables are looked up
839-
// and matched against the return expression of each case clause
840-
// Check to make sure that the number of patterns in each case-clause
841-
// equals the number of input variables is done in the function fillMatrix
842-
// -------------
843-
//typeCheck1(localCache,localEnv,patMat2,inputVarList);
844-
//typeCheck2(localCache,localEnv,rhList2,localResultVarList);
845-
// -------------
846-
847-
// Start the pattern matching
848-
// The rhList version is a "light" version of the rightHandSides so that
849-
// we do not have to carry around a lot of extra code in the pattern match algorithm
850-
(dfaState,stampTemp,_) = matchFuncHelper(patMat2,rhList,DFA.STATE({}),1,{});
851-
//print("Done with the matching");
852-
nCases = listLength(rhList);
853-
dfaRec = DFA.DFArec(declList,{},NONE(),dfaState,stampTemp,nCases);
854-
855-
// Light version or not ---------------------
856-
// In a light version state labels will not be generated.
857-
// Light versions are generated when there is only one case-clause
858-
// which is the case for instance when we have rhs pattern matching
859-
// such as (_,var1,5) = func(...);
860-
lightVs = Util.if_((nCases == 1),true,false);
861-
//-------------------------------------------
862-
863-
// Transform the DFA into a valueblock with nested if-elseif-else statements.
864-
(localCache,expr) =
865-
DFA.fromDFAtoIfNodes(dfaRec,inputVarList,localResultVarList,localCache,localEnv,rhList2,lightVs);
866-
then (localCache,expr);
867-
*/
868821
case (exp,_,_,_,_)
869822
equation
870823
true = RTOpts.debugFlag("matchcase");

0 commit comments

Comments
 (0)