Skip to content

Commit

Permalink
use match instead of matchcontinue where possible
Browse files Browse the repository at this point in the history
use try/catch instead of matchcontinue


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@24082 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Henning Kiel committed Jan 17, 2015
1 parent 7752284 commit 7fc2156
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 52 deletions.
8 changes: 4 additions & 4 deletions Compiler/FrontEnd/Static.mo
Expand Up @@ -10334,12 +10334,12 @@ public function applySubscriptsVariability
input DAE.Const inSubsConst;
output SCode.Variability outVariability;
algorithm
outVariability := matchcontinue(inVariability, inSubsConst)
outVariability := match(inVariability, inSubsConst)
case (SCode.PARAM(), DAE.C_VAR()) then SCode.VAR();
case (SCode.CONST(), DAE.C_VAR()) then SCode.VAR();
case (SCode.CONST(), DAE.C_PARAM()) then SCode.PARAM();
else inVariability;
end matchcontinue;
end match;
end applySubscriptsVariability;

public function makeEnumerationArray
Expand Down Expand Up @@ -12075,7 +12075,7 @@ protected function subscriptCrefType2
input DAE.Type inType;
output DAE.Type outType;
algorithm
outType := matchcontinue (inComponentRef,inType)
outType := match (inComponentRef,inType)
local
DAE.Type t,t_1;
list<DAE.Subscript> subs;
Expand All @@ -12092,7 +12092,7 @@ algorithm
t_1 = subscriptCrefType2(c, t);
then
t_1;
end matchcontinue;
end match;
end subscriptCrefType2;

protected function subscriptType "Given an array dimensionality and a list of subscripts, this
Expand Down
67 changes: 29 additions & 38 deletions Compiler/FrontEnd/Types.mo
Expand Up @@ -1220,10 +1220,10 @@ public function arrayType "Test whether a type is an array type."
input DAE.Type inType;
output Boolean outBoolean;
algorithm
outBoolean := matchcontinue (inType)
outBoolean := match (inType)
case (DAE.T_ARRAY()) then true;
else false;
end matchcontinue;
end match;
end arrayType;

public function setVarInput "Sets a DAE.Var to input"
Expand Down Expand Up @@ -2976,18 +2976,13 @@ public function getFixedVarAttributeParameterOrConstant
input DAE.Type tp;
output Boolean fix;
algorithm
fix := matchcontinue(tp)
try
// there is a fixed!
case _
equation
fix = getFixedVarAttribute(tp);
then
fix;

fix := getFixedVarAttribute(tp);
else
// there is no fixed!
else true;

end matchcontinue;
fix := true;
end try;
end getFixedVarAttributeParameterOrConstant;

public function getFixedVarAttribute "Returns the value of the fixed attribute of a builtin type"
Expand Down Expand Up @@ -3098,32 +3093,32 @@ public function isInputAttr "Returns true if the Attributes of a variable indica
input DAE.Attributes inAttributes;
output Boolean outBoolean;
algorithm
outBoolean := matchcontinue (inAttributes)
outBoolean := match (inAttributes)
case DAE.ATTR(direction = Absyn.INPUT()) then true;
case _ then false;
end matchcontinue;
end match;
end isInputAttr;

public function isOutputAttr "Returns true if the Attributes of a variable indicates
that the variable is output."
input DAE.Attributes inAttributes;
output Boolean outBoolean;
algorithm
outBoolean := matchcontinue (inAttributes)
outBoolean := match (inAttributes)
case DAE.ATTR(direction = Absyn.OUTPUT()) then true;
case _ then false;
end matchcontinue;
end match;
end isOutputAttr;

public function isBidirAttr "Returns true if the Attributes of a variable indicates that the variable
is bidirectional, i.e. neither input nor output."
input DAE.Attributes inAttributes;
output Boolean outBoolean;
algorithm
outBoolean := matchcontinue (inAttributes)
outBoolean := match (inAttributes)
case DAE.ATTR(direction = Absyn.BIDIR()) then true;
case _ then false;
end matchcontinue;
end match;
end isBidirAttr;

public function isPublicAttr
Expand Down Expand Up @@ -3735,7 +3730,7 @@ algorithm
end matchcontinue;
end isPropTuple;

public function isPropArray " Return true if properties contain an array type."
public function isPropArray "Return true if properties contain an array type."
input DAE.Properties p;
output Boolean b;
protected
Expand Down Expand Up @@ -3985,15 +3980,11 @@ public function typesElabEquivalent
input DAE.Type inType2;
output Boolean isEqual;
algorithm
isEqual := matchcontinue(inType1, inType2)
local
DAE.Type ty1, ty2;

case (ty1, ty2)
then ttypesElabEquivalent(ty1, ty2);

else false;
end matchcontinue;
try
isEqual := ttypesElabEquivalent(inType1, inType2);
else
isEqual := false;
end try;
end typesElabEquivalent;

protected function ttypesElabEquivalent
Expand Down Expand Up @@ -5203,15 +5194,15 @@ public function constOr "Returns the *or* operator of two Const's.
input DAE.Const inConst2;
output DAE.Const outConst;
algorithm
outConst := matchcontinue (inConst1,inConst2)
outConst := match (inConst1,inConst2)
case (DAE.C_CONST(),_) then DAE.C_CONST();
case (_,DAE.C_CONST()) then DAE.C_CONST();
case (DAE.C_PARAM(),_) then DAE.C_PARAM();
case (_,DAE.C_PARAM()) then DAE.C_PARAM();
case (DAE.C_UNKNOWN(),_) then DAE.C_UNKNOWN();
case (_, DAE.C_UNKNOWN()) then DAE.C_UNKNOWN();
else DAE.C_VAR();
end matchcontinue;
end match;
end constOr;

public function boolConst "author: PA
Expand Down Expand Up @@ -5544,7 +5535,7 @@ public function isBoxedType
input DAE.Type ty;
output Boolean b;
algorithm
b := matchcontinue (ty)
b := match (ty)
case (DAE.T_STRING()) then true;
case (DAE.T_METAOPTION()) then true;
case (DAE.T_METALIST()) then true;
Expand All @@ -5562,7 +5553,7 @@ algorithm
case (DAE.T_CODE()) then true;
case (DAE.T_COMPLEX(complexClassType = ClassInf.EXTERNAL_OBJ(_))) then true;
case _ then false;
end matchcontinue;
end match;
end isBoxedType;

public function boxIfUnboxedType
Expand Down Expand Up @@ -6330,14 +6321,14 @@ public function resTypeToListTypes
input DAE.Type inType;
output list<DAE.Type> outType;
algorithm
outType := matchcontinue (inType)
outType := match (inType)
local
list<DAE.Type> tys;
Type ty;
case DAE.T_TUPLE(types = tys) then tys;
case DAE.T_NORETCALL() then {};
case ty then {ty};
end matchcontinue;
end match;
end resTypeToListTypes;

public function getRealOrIntegerDimensions
Expand Down Expand Up @@ -6887,7 +6878,7 @@ public function liftArraySubscript "Lifts a type to an array using DAE.Subscript
input DAE.Subscript inSubscript;
output DAE.Type outType;
algorithm
outType := matchcontinue (inType,inSubscript)
outType := match (inType,inSubscript)
local
Type ty;
Integer i;
Expand All @@ -6904,7 +6895,7 @@ algorithm
// All other kinds of subscripts denote an index, so the type stays the same
case (ty,_)
then ty;
end matchcontinue;
end match;
end liftArraySubscript;

public function liftArraySubscriptList "
Expand Down Expand Up @@ -7938,10 +7929,10 @@ public function hasBinding
input DAE.Var inVar;
output Boolean b;
algorithm
b := matchcontinue(inVar)
b := match (inVar)
case (DAE.TYPES_VAR(binding = DAE.UNBOUND())) then false;
else true;
end matchcontinue;
end match;
end hasBinding;

public function typeErrorSanityCheck
Expand Down
8 changes: 4 additions & 4 deletions Compiler/FrontEnd/UnitAbsynBuilder.mo
Expand Up @@ -564,7 +564,7 @@ protected function printTypeParameterStr "help function to printUnit"
input tuple<MMath.Rational,UnitAbsyn.TypeParameter> typeParam;
output String str;
algorithm
str := matchcontinue(typeParam)
str := match(typeParam)
local String name; Integer i1,i2,i3,indx;
case((MMath.RATIONAL(0,0),UnitAbsyn.TYPEPARAMETER(name,indx))) equation
str = name + "[indx =" + intString(indx) + "]";
Expand All @@ -575,7 +575,7 @@ algorithm
case((MMath.RATIONAL(i1,i2),UnitAbsyn.TYPEPARAMETER(name,indx))) equation
str = name+ "^("+ intString(i1) + "/" + intString(i2)+")" + "[indx=" + intString(indx) + "]";
then str;
end matchcontinue;
end match;
end printTypeParameterStr;

public function splitRationals "splits a list of Rationals into a list of numerators and denominators"
Expand Down Expand Up @@ -1492,12 +1492,12 @@ parent expression as type of a constant expression"
input Option<DAE.Operator> op;
output UnitAbsyn.Unit unit;
algorithm
unit := matchcontinue(op)
unit := match(op)
case(NONE()) then UnitAbsyn.UNSPECIFIED();
case(SOME(DAE.ADD(_))) then UnitAbsyn.UNSPECIFIED();
case(SOME(DAE.SUB(_))) then UnitAbsyn.UNSPECIFIED();
case(SOME(_)) then str2unit("1",NONE());
end matchcontinue;
end match;
end selectConstantUnit;

public function unit2str "Translate a unit to a string"
Expand Down
13 changes: 7 additions & 6 deletions Compiler/FrontEnd/UnitChecker.mo
Expand Up @@ -246,7 +246,7 @@ protected function chooseResult "Returns the first result that is UnitAbsyn.INCO
protected
UnitAbsyn.UnitCheckResult incon;
algorithm
resout := matchcontinue(res1,res2,res3)
resout := match(res1,res2,res3)
case(UnitAbsyn.CONSISTENT(),UnitAbsyn.CONSISTENT(),UnitAbsyn.CONSISTENT()) then UnitAbsyn.CONSISTENT();
case(UnitAbsyn.CONSISTENT(),UnitAbsyn.CONSISTENT(),incon) then incon;
case(UnitAbsyn.CONSISTENT(),incon,_) then incon;
Expand All @@ -256,7 +256,7 @@ algorithm
true = Flags.isSet(Flags.FAILTRACE);
Debug.trace("UnitChecker::chooseResult() failed\n");
then fail();
end matchcontinue;
end match;
end chooseResult;

protected function unify
Expand Down Expand Up @@ -410,15 +410,16 @@ public function unitHasUnknown
input UnitAbsyn.Unit u;
output Boolean res;
algorithm
res := matchcontinue(u)
res := match(u)
local
UnitAbsyn.SpecUnit su;
Boolean unk;
case(UnitAbsyn.SPECIFIED(su))
equation
false = hasUnknown(su);
then false;
unk = hasUnknown(su);
then unk;
else true;
end matchcontinue;
end match;
end unitHasUnknown;

public function mulSpecUnit "Multiplying two units corresponds to adding the units and joining the typeParameter list."
Expand Down

0 comments on commit 7fc2156

Please sign in to comment.