Skip to content

Commit

Permalink
convert some matchcontinue to match
Browse files Browse the repository at this point in the history
makes some functions tail recursive
  • Loading branch information
hkiel authored and OpenModelica-Hudson committed Feb 2, 2016
1 parent 905b903 commit dcc0ed6
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 39 deletions.
13 changes: 6 additions & 7 deletions Compiler/FrontEnd/ClassInf.mo
Expand Up @@ -234,7 +234,7 @@ public function printState
input State inState;
algorithm
_:=
matchcontinue (inState)
match (inState)
local Absyn.Path p;

case UNKNOWN(path = p)
Expand Down Expand Up @@ -334,7 +334,7 @@ algorithm
Print.printBuf(Absyn.pathString(p));
Print.printBuf(printStateStr(inState));
then ();
end matchcontinue;
end match;
end printState;

public function getStateName "Returns the classname of the state."
Expand Down Expand Up @@ -663,9 +663,8 @@ public function matchingState "
output Boolean outBoolean;
algorithm
outBoolean:=
matchcontinue (inState,inStateLst)
match (inState,inStateLst)
local
State st,first;
list<State> rest;
Boolean res;
case (_,{}) then false;
Expand All @@ -685,12 +684,12 @@ algorithm
// BTH
case (TYPE_CLOCK(),(TYPE_CLOCK() :: _)) then true;
case (TYPE_ENUM(),(TYPE_ENUM() :: _)) then true;
case (st,(_ :: rest))
case (_,(_ :: rest))
equation
res = matchingState(st, rest);
res = matchingState(inState, rest);
then
res;
end matchcontinue;
end match;
end matchingState;

public function isFunction
Expand Down
54 changes: 27 additions & 27 deletions Compiler/FrontEnd/Graphviz.mo
Expand Up @@ -144,37 +144,37 @@ protected function makeLabel "Creates a label from a list of strings."
protected
Label s0,s1;
algorithm
s0 := makeLabelReq(sl);
s0 := makeLabelReq(sl,"");
s1 := stringAppend("\"", s0);
s2 := stringAppend(s1, "\"");
end makeLabel;

protected function makeLabelReq "Helper function to makeLabel"
input list<String> inStringLst;
input String inString;
output String outString;
algorithm
outString := matchcontinue (inStringLst)
outString := match (inStringLst)
local
Label s,res,s1,s2,old;
Label s,s1,s2;
list<Label> rest;

case {s} then s;
case {s} then stringAppend(inString, s);

case {s1,s2}
equation
s = stringAppend(s1, "\\n");
res = stringAppend(s, s2);
then
res;
s = stringAppend(inString, s1);
s = stringAppend(s, "\\n");
s = stringAppend(s, s2);
then s;

case (s1 :: rest)
equation
old = makeLabelReq(rest);
s = stringAppend(s1, "\\n");
res = stringAppend(s, old);
s = stringAppend(inString, s1);
s = stringAppend(s, "\\n");
then
res;
end matchcontinue;
makeLabelReq(rest, s);
end match;
end makeLabelReq;

protected function dumpChildren "Helper function to dumpNode"
Expand Down Expand Up @@ -252,37 +252,37 @@ protected function makeAttr "Creates a string from an Attribute list."
protected
Label res,s;
algorithm
res := makeAttrReq(l);
res := makeAttrReq(l, "");
s := stringAppend("[", res);
str := stringAppend(s, "]");
end makeAttr;

protected function makeAttrReq "Helper function to makeAttrReq."
protected function makeAttrReq "Helper function to makeAttr."
input list<Attribute> inAttributeLst;
input String inString;
output String outString;
algorithm
outString := matchcontinue (inAttributeLst)
outString := match (inAttributeLst)
local
Label s,str,name,v,old,s_1,s_2;
Label s,name,v;
list<Attribute> rest;

case {ATTR(name = name,value = v)}
equation
s = stringAppend(name, "=");
str = stringAppend(s, v);
s = stringAppend(inString, name);
s = stringAppend(s, "=");
then
str;
stringAppend(s, v);

case ((ATTR(name = name,value = v) :: rest))
equation
old = makeAttrReq(rest);
s = stringAppend(name, "=");
s_1 = stringAppend(s, v);
s_2 = stringAppend(s_1, ",");
str = stringAppend(s_2, old);
s = stringAppend(inString, name);
s = stringAppend(s, "=");
s = stringAppend(s, v);
s = stringAppend(s, ",");
then
str;
end matchcontinue;
makeAttrReq(rest, s);
end match;
end makeAttrReq;

annotation(__OpenModelica_Interface="frontend");
Expand Down
4 changes: 2 additions & 2 deletions Compiler/FrontEnd/Inline.mo
Expand Up @@ -1333,7 +1333,7 @@ protected function getRhsExp
input list<DAE.Element> inElementList;
output DAE.Exp outExp;
algorithm
outExp := matchcontinue(inElementList)
outExp := match(inElementList)
local
list<DAE.Element> cdr;
DAE.Exp res;
Expand All @@ -1351,7 +1351,7 @@ algorithm
res = getRhsExp(cdr);
then
res;
end matchcontinue;
end match;
end getRhsExp;

protected function replaceArgs
Expand Down
6 changes: 3 additions & 3 deletions Compiler/FrontEnd/MMath.mo
Expand Up @@ -156,10 +156,10 @@ public function intGcd "returns the greatest common divisor for two Integers"
input Integer i2;
output Integer i;
algorithm
i := matchcontinue(i1,i2)
i := match(i1,i2)
case (_,0) then i1;
else intGcd(i2,intMod(i1,i2));
end matchcontinue;
end match;
end intGcd;

/* Tests */
Expand All @@ -169,7 +169,7 @@ algorithm
_ := matchcontinue()

case() equation
RATIONAL(7,6) = addRational(RATIONAL(1,2),RATIONAL(2,3));
RATIONAL(7,6) = addRational(RATIONAL(1,2),RATIONAL(2,3));
RATIONAL(2,1) = addRational(RATIONAL(1,2),RATIONAL(3,2));

RATIONAL(1,1) = subRational(RATIONAL(3,2),RATIONAL(1,2));
Expand Down

0 comments on commit dcc0ed6

Please sign in to comment.