Skip to content

Commit

Permalink
remove some matchcontinue
Browse files Browse the repository at this point in the history
  • Loading branch information
hkiel committed Feb 28, 2016
1 parent f5881f2 commit ca1480a
Showing 1 changed file with 15 additions and 32 deletions.
47 changes: 15 additions & 32 deletions Compiler/FrontEnd/ExpressionSimplify.mo
Expand Up @@ -874,7 +874,7 @@ protected function simplifyMatch "simplifies MetaModelica match expressions"
input DAE.Exp exp;
output DAE.Exp outExp;
algorithm
outExp := matchcontinue exp
outExp := match exp
local
DAE.Exp e,e1,e2,e1_1,e2_1;
Boolean b,b1,b2;
Expand All @@ -891,17 +891,18 @@ algorithm
case DAE.MATCHEXPRESSION(inputs={}, et=ty, localDecls={}, cases={
DAE.CASE(patterns={},localDecls={},body={},result=SOME(e))
})
equation
false = Types.isTuple(ty);
guard
not Types.isTuple(ty)
then e;

case DAE.MATCHEXPRESSION(inputs={e}, et=ty, localDecls={}, cases={
DAE.CASE(patterns={DAE.PAT_CONSTANT(exp=DAE.BCONST(b1))},localDecls={},body={},result=SOME(e1)),
DAE.CASE(patterns={DAE.PAT_CONSTANT(exp=DAE.BCONST(b2))},localDecls={},body={},result=SOME(e2))
})
guard
not boolEq(b1,b2) and
not Types.isTuple(ty)
equation
false = boolEq(b1,b2);
false = Types.isTuple(ty);
e1_1 = if b1 then e1 else e2;
e2_1 = if b1 then e2 else e1;
e = DAE.IFEXP(e, e1_1, e2_1);
Expand All @@ -911,15 +912,16 @@ algorithm
DAE.CASE(patterns={DAE.PAT_CONSTANT(exp=DAE.BCONST(b1))},localDecls={},body={},result=SOME(e1)),
DAE.CASE(patterns={DAE.PAT_WILD()},localDecls={},body={},result=SOME(e2))
})
guard
not Types.isTuple(ty)
equation
false = Types.isTuple(ty);
e1_1 = if b1 then e1 else e2;
e2_1 = if b1 then e2 else e1;
e = DAE.IFEXP(e, e1_1, e2_1);
then e;

else exp;
end matchcontinue;
end match;
end simplifyMatch;

protected function simplifyCast "help function to simplify1"
Expand Down Expand Up @@ -1548,31 +1550,12 @@ public function cevalBuiltinStringFormat
input Boolean leftJustified;
output String outString;
algorithm
outString := matchcontinue(inString, stringLength, minLength, leftJustified)
local
String str;
Integer fill_size;
// The string is longer than the minimum length, do nothing.
case (_, _, _, _)
equation
true = stringLength >= minLength;
then
inString;
// leftJustified is false, append spaces at the beginning of the string.
case (_, _, _, false)
equation
fill_size = minLength - stringLength;
str = stringAppendList(List.fill(" ", fill_size)) + inString;
then
str;
// leftJustified is true, append spaces at the end of the string.
case (_, _, _, true)
equation
fill_size = minLength - stringLength;
str = inString + stringAppendList(List.fill(" ", fill_size));
then
str;
end matchcontinue;
outString := if stringLength >= minLength then inString
else
if leftJustified then
inString + stringAppendList(List.fill(" ", minLength - stringLength))
else
stringAppendList(List.fill(" ", minLength - stringLength)) + inString;
end cevalBuiltinStringFormat;

protected function simplifyStringAppendList
Expand Down

0 comments on commit ca1480a

Please sign in to comment.