Skip to content

Commit

Permalink
use BaseHashTable.hasKey() instead of failing/passing get()
Browse files Browse the repository at this point in the history
Belonging to [master]:
  - OpenModelica/OMCompiler#2306
  • Loading branch information
hkiel authored and OpenModelica-Hudson committed Mar 23, 2018
1 parent ff5f8bf commit 35f216d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 32 deletions.
15 changes: 5 additions & 10 deletions Compiler/BackEnd/BackendDAECreate.mo
Expand Up @@ -2339,38 +2339,33 @@ algorithm
case ({}, _, _)
then
iHt;
case (DAE.EQUEQUATION(cr1=cr, cr2=cr2, source=source)::rest, _, _)
case (DAE.EQUEQUATION(cr1=cr, cr2=cr2, source=source)::rest, _, _) guard not BaseHashTable.hasKey(cr, iHt)
equation
failure( _ = BaseHashTable.get(cr, iHt));
e = Expression.crefExp(cr2);
false = Expression.expHasCrefNoPreorDer(e, cr);
ht = BaseHashTable.add((cr, (e, source)), iHt);
then
lowerWhenIfEqnsElse(rest, functionTree, ht);
case (DAE.DEFINE(componentRef=cr, exp=e, source=source)::rest, _, _)
case (DAE.DEFINE(componentRef=cr, exp=e, source=source)::rest, _, _) guard not BaseHashTable.hasKey(cr, iHt)
equation
failure( _ = BaseHashTable.get(cr, iHt));
false = Expression.expHasCrefNoPreorDer(e, cr);
ht = BaseHashTable.add((cr, (e, source)), iHt);
then
lowerWhenIfEqnsElse(rest, functionTree, ht);
case (DAE.EQUATION(exp=DAE.CREF(componentRef=cr), scalar=e, source=source)::rest, _, _)
case (DAE.EQUATION(exp=DAE.CREF(componentRef=cr), scalar=e, source=source)::rest, _, _) guard not BaseHashTable.hasKey(cr, iHt)
equation
failure( _ = BaseHashTable.get(cr, iHt));
false = Expression.expHasCrefNoPreorDer(e, cr);
ht = BaseHashTable.add((cr, (e, source)), iHt);
then
lowerWhenIfEqnsElse(rest, functionTree, ht);
case (DAE.COMPLEX_EQUATION(lhs=DAE.CREF(componentRef=cr), rhs=e, source=source)::rest, _, _)
case (DAE.COMPLEX_EQUATION(lhs=DAE.CREF(componentRef=cr), rhs=e, source=source)::rest, _, _) guard not BaseHashTable.hasKey(cr, iHt)
equation
failure( _ = BaseHashTable.get(cr, iHt));
false = Expression.expHasCrefNoPreorDer(e, cr);
ht = BaseHashTable.add((cr, (e, source)), iHt);
then
lowerWhenIfEqnsElse(rest, functionTree, ht);
case (DAE.ARRAY_EQUATION(exp=DAE.CREF(componentRef=cr), array=e, source=source)::rest, _, _)
case (DAE.ARRAY_EQUATION(exp=DAE.CREF(componentRef=cr), array=e, source=source)::rest, _, _) guard not BaseHashTable.hasKey(cr, iHt)
equation
failure( _ = BaseHashTable.get(cr, iHt));
false = Expression.expHasCrefNoPreorDer(e, cr);
ht = BaseHashTable.add((cr, (e, source)), iHt);
then
Expand Down
17 changes: 3 additions & 14 deletions Compiler/BackEnd/BackendDAEOptimize.mo
Expand Up @@ -2394,16 +2394,14 @@ algorithm
case ({},_)
then
iHt;
case (BackendDAE.EQUATION(exp=DAE.CREF(componentRef=cr), scalar=e)::rest,_)
case (BackendDAE.EQUATION(exp=DAE.CREF(componentRef=cr), scalar=e)::rest,_) guard not BaseHashTable.hasKey(cr, iHt)
equation
failure( _ = BaseHashTable.get(cr, iHt));
false = Expression.expHasCref(e, cr);
ht = BaseHashTable.add((cr,e), iHt);
then
simplifySolvedIfEqnsElse(rest,ht);
case (BackendDAE.EQUATION(exp=DAE.UNARY(operator=DAE.UMINUS(), exp=DAE.CREF(componentRef=cr)), scalar=e)::rest,_)
case (BackendDAE.EQUATION(exp=DAE.UNARY(operator=DAE.UMINUS(), exp=DAE.CREF(componentRef=cr)), scalar=e)::rest,_) guard not BaseHashTable.hasKey(cr, iHt)
equation
failure( _ = BaseHashTable.get(cr, iHt));
false = Expression.expHasCref(e, cr);
e = Expression.negate(e);
ht = BaseHashTable.add((cr,e), iHt);
Expand Down Expand Up @@ -2986,16 +2984,7 @@ protected function semiLinearGetSA
input list<DAE.Exp> iAcc;
output list<DAE.Exp> oAcc;
algorithm
oAcc := matchcontinue(key,iHt1,iAcc)
case (_,_,_)
equation
_ = BaseHashTable.get(key,iHt1);
then
iAcc;
case(_,_,_)
then
key::iAcc;
end matchcontinue;
oAcc := if BaseHashTable.hasKey(key, iHt1) then iAcc else key::iAcc;
end semiLinearGetSA;

protected function semiLinearOptimize1
Expand Down
4 changes: 1 addition & 3 deletions Compiler/BackEnd/BackendEquation.mo
Expand Up @@ -640,9 +640,7 @@ algorithm
then (inExp, inTuple);

// already there
case (DAE.CREF(componentRef = cr), (_, _, ht))
equation
_ = BaseHashTable.get(cr, ht);
case (DAE.CREF(componentRef = cr), (_, _, ht)) guard BaseHashTable.hasKey(cr, ht)
then (inExp, inTuple);

// known
Expand Down
8 changes: 3 additions & 5 deletions Compiler/FrontEnd/Lookup.mo
Expand Up @@ -417,7 +417,7 @@ starts to traverse."
output HashTableStringToPath.HashTable outHt;
output list<DAE.Type> outMetarecordTypes;
algorithm
(outCache,outHt,outMetarecordTypes) := matchcontinue (inCache, inEnv, path, str, inHt, inAcc)
(outCache,outHt,outMetarecordTypes) := match (inCache, inEnv, path, str, inHt, inAcc)
local
FCore.Cache cache;
FCore.Graph env;
Expand All @@ -427,9 +427,7 @@ algorithm
list<DAE.Type> acc;
HashTableStringToPath.HashTable ht;

case (cache, _, _, _, ht, acc)
equation
_ = BaseHashTable.get(str, ht);
case (cache, _, _, _, ht, acc) guard BaseHashTable.hasKey(str, ht)
then (cache, ht, acc);
case (cache, env, _, _, ht, acc)
equation
Expand All @@ -440,7 +438,7 @@ algorithm
uniontypePaths = List.flatten(List.map(uniontypeTypes, Types.getUniontypePaths));
(cache, ht, acc) = lookupMetarecordsRecursive2(cache, env, uniontypePaths, ht, acc);
then (cache,ht,acc);
end matchcontinue;
end match;
end lookupMetarecordsRecursive3;

public function lookupClass "Tries to find a specified class in an environment"
Expand Down

0 comments on commit 35f216d

Please sign in to comment.