Skip to content

Commit

Permalink
Use filterOnTrue instead of filter
Browse files Browse the repository at this point in the history
  • Loading branch information
hkiel committed Feb 17, 2016
1 parent 3cd16cc commit d41fb97
Show file tree
Hide file tree
Showing 14 changed files with 114 additions and 82 deletions.
2 changes: 1 addition & 1 deletion Compiler/BackEnd/BackendDAECreate.mo
Expand Up @@ -3290,7 +3290,7 @@ algorithm
VarTransform.VariableReplacements repl;
case(DAE.FUNCTION_DEF(body=body),_)
equation
params = List.filter(body,DAEUtil.isParameter);
params = List.filterOnTrue(body,DAEUtil.isParameter);
false = listEmpty(params);
crefs = List.map(params,DAEUtil.varCref);
crefs_new = List.map1r(crefs,ComponentReference.prependStringCref,pathName);
Expand Down
5 changes: 3 additions & 2 deletions Compiler/BackEnd/Matching.mo
Expand Up @@ -544,7 +544,7 @@ protected
list<Integer> vars,vars_1;
algorithm
vars := BackendDAEUtil.varsInEqn(m, i);
vars_1 := List.filter1(vars, isNotVMarked, (imark, vmark));
vars_1 := List.filter1OnTrue(vars, isNotVMarked, (imark, vmark));
(outAssignments1,outAssignments2) := forallUnmarkedVarsInEqnBody(m, mt, i, imark, emark, vmark, vars_1, ass1, ass2);
end forallUnmarkedVarsInEqn;

Expand All @@ -553,12 +553,13 @@ protected function isNotVMarked
This function succeds for variables that are not marked."
input Integer i;
input tuple<Integer,array<Integer>> inTpl;
output Boolean outB;
protected
Integer imark;
array<Integer> vmark;
algorithm
(imark,vmark) := inTpl;
false := intEq(imark,vmark[i]);
outB := not intEq(imark,vmark[i]);
end isNotVMarked;

protected function forallUnmarkedVarsInEqnBody
Expand Down
8 changes: 6 additions & 2 deletions Compiler/BackEnd/StateMachineFeatures.mo
Expand Up @@ -504,7 +504,7 @@ algorithm
crefLocalsSet := List.fold(List.map(outLocal, BackendVariable.varCref), BaseHashSet.add, HashSet.emptyHashSet());
crefSharedSet := List.fold(List.map(outShared, BackendVariable.varCref), BaseHashSet.add, HashSet.emptyHashSet());
// collect all inner outer outputs together with the index of the state they occur in
outStateInnerOuters := listAppend(outStateInnerOuters, List.map(List.filter(outLocal,filterInnerOuters), function Util.makeTuple(inValue1=i)));
outStateInnerOuters := listAppend(outStateInnerOuters, List.map(List.filterOnTrue(outLocal,filterInnerOuters), function Util.makeTuple(inValue1=i)));

// SMS_PRE.initialState.activeState == i
relExp := DAE.RELATION(activeStateRefExp, DAE.EQUAL(DAE.T_INTEGER_DEFAULT), DAE.ICONST(i),-1, NONE());
Expand Down Expand Up @@ -600,8 +600,12 @@ end addInnerOuterConnection;
protected function filterInnerOuters "
Helper function to synthesizeAutomatonEqsModeToDataflow"
input BackendDAE.Var inElement;
output Boolean outB;
algorithm
BackendDAE.VAR(innerOuter=DAE.INNER_OUTER()) := inElement;
outB := match inElement
case BackendDAE.VAR(innerOuter=DAE.INNER_OUTER()) then true;
else false;
end match;
end filterInnerOuters;

protected function handleResets "
Expand Down
8 changes: 6 additions & 2 deletions Compiler/FrontEnd/Absyn.mo
Expand Up @@ -5500,16 +5500,20 @@ algorithm
list<ElementItem> elts1,elts2;
case (PUBLIC(elts1),elts2)
equation
elts1 = List.filter(elts1,filterAnnotationItem);
elts1 = List.filterOnTrue(elts1,filterAnnotationItem);
then listAppend(elts1,elts2);
else elts;
end match;
end getFunctionInterfaceParts;

protected function filterAnnotationItem
input ElementItem elt;
output Boolean outB;
algorithm
ELEMENTITEM() := elt;
outB := match elt
case ELEMENTITEM() then true;
else false;
end match;
end filterAnnotationItem;

public function getExternalDecl
Expand Down
8 changes: 5 additions & 3 deletions Compiler/FrontEnd/DAEUtil.mo
Expand Up @@ -1422,13 +1422,15 @@ algorithm
end isAfterIndexInlineFunc;

public function isParameter "author: LS
Succeeds if element is parameter.
True if element is parameter.
"
input DAE.Element inElement;
output Boolean outB;
algorithm
_:=
outB :=
match (inElement)
case DAE.VAR(kind = DAE.PARAM()) then ();
case DAE.VAR(kind = DAE.PARAM()) then true;
else false;
end match;
end isParameter;

Expand Down
10 changes: 6 additions & 4 deletions Compiler/FrontEnd/InstStateMachineUtil.mo
Expand Up @@ -422,7 +422,7 @@ algorithm
outOuterAcc := match inElem
case DAE.SM_COMP(componentRef=componentRef, dAElist=dAElist)
algorithm
outerOutputs := List.filter(dAElist, isOuterOutput);
outerOutputs := List.filterOnTrue(dAElist, isOuterOutput);
outerOutputCrefs := List.map(outerOutputs, DAEUtil.varCref);
outerOutputCrefToSMCompCref := List.map(outerOutputCrefs, function Util.makeTuple(inValue2=componentRef));
then List.fold(outerOutputCrefToSMCompCref, BaseHashTable.addUnique, outOuterAcc);
Expand All @@ -435,13 +435,15 @@ Author: BTH
Helper function to collectOuterOutputs.
"
input DAE.Element inElem;
output Boolean outB;
algorithm
_ := match inElem
outB := match inElem
local
DAE.VarDirection direction;
Absyn.InnerOuter innerOuter;
case DAE.VAR(direction=direction as DAE.OUTPUT(), innerOuter=innerOuter as Absyn.OUTER()) then ();
case DAE.VAR(direction=direction as DAE.OUTPUT(), innerOuter=innerOuter as Absyn.INNER_OUTER()) then ();
case DAE.VAR(direction=direction as DAE.OUTPUT(), innerOuter=innerOuter as Absyn.OUTER()) then true;
case DAE.VAR(direction=direction as DAE.OUTPUT(), innerOuter=innerOuter as Absyn.INNER_OUTER()) then true;
else false;
end match;
end isOuterOutput;

Expand Down
25 changes: 13 additions & 12 deletions Compiler/FrontEnd/InstUtil.mo
Expand Up @@ -5343,8 +5343,8 @@ algorithm
*/
case (id,els,SCode.EXTERNALDECL(lang = lang))
equation
(outvar :: {}) = List.filter(els, isOutputVar);
invars = List.filter(els, isInputVar);
(outvar :: {}) = List.filterOnTrue(els, isOutputVar);
invars = List.filterOnTrue(els, isInputVar);
explists = List.map(invars, instExtMakeCrefs);
exps = List.flatten(explists);
{Absyn.CREF(retcref)} = instExtMakeCrefs(outvar);
Expand All @@ -5353,7 +5353,7 @@ algorithm
extdecl;
case (id,els,SCode.EXTERNALDECL(lang = lang))
equation
inoutvars = List.filter(els, isInoutVar);
inoutvars = List.filterOnTrue(els, isInoutVar);
explists = List.map(inoutvars, instExtMakeCrefs);
exps = List.flatten(explists);
extdecl = SCode.EXTERNALDECL(SOME(id),lang,NONE(),exps,NONE());
Expand All @@ -5371,29 +5371,30 @@ end instExtMakeExternaldecl;
protected function isInoutVar
"Succeds for Elements that are input or output components"
input SCode.Element inElement;
output Boolean b;
algorithm
_ := matchcontinue (inElement)
local SCode.Element e;
case e equation isOutputVar(e); then ();
case e equation isInputVar(e); then ();
end matchcontinue;
b := isOutputVar(inElement) or isInputVar(inElement);
end isInoutVar;

protected function isOutputVar
"Succeds for element that is output component"
input SCode.Element inElement;
output Boolean b;
algorithm
_ := match (inElement)
case SCode.COMPONENT(attributes = SCode.ATTR(direction = Absyn.OUTPUT())) then ();
b := match (inElement)
case SCode.COMPONENT(attributes = SCode.ATTR(direction = Absyn.OUTPUT())) then true;
else false;
end match;
end isOutputVar;

protected function isInputVar
"Succeds for element that is input component"
input SCode.Element inElement;
output Boolean b;
algorithm
_ := match (inElement)
case SCode.COMPONENT(attributes = SCode.ATTR(direction = Absyn.INPUT())) then ();
b := match (inElement)
case SCode.COMPONENT(attributes = SCode.ATTR(direction = Absyn.INPUT())) then true;
else false;
end match;
end isInputVar;

Expand Down
11 changes: 6 additions & 5 deletions Compiler/FrontEnd/NFSCodeDependency.mo
Expand Up @@ -595,7 +595,7 @@ protected
list<String> el_names;
algorithm
// Remove all 'extends ExternalObject'.
el := List.filter(inElements, isNotExternalObject);
el := List.filterOnTrue(inElements, isNotExternalObject);
// Check if length of the new list is different to the old, i.e. if we
// actually found and removed any 'extends ExternalObject'.
false := (listLength(el) == listLength(inElements));
Expand Down Expand Up @@ -628,12 +628,13 @@ algorithm
end elementName;

protected function isNotExternalObject
"Fails on 'extends ExternalObject', otherwise succeeds."
"False on 'extends ExternalObject', otherwise true."
input SCode.Element inElement;
output Boolean b;
algorithm
_ := match(inElement)
case SCode.EXTENDS(baseClassPath = Absyn.IDENT("ExternalObject")) then fail();
else ();
b := match(inElement)
case SCode.EXTENDS(baseClassPath = Absyn.IDENT("ExternalObject")) then false;
else true;
end match;
end isNotExternalObject;

Expand Down
9 changes: 5 additions & 4 deletions Compiler/FrontEnd/NFSCodeFlattenImports.mo
Expand Up @@ -133,7 +133,7 @@ algorithm
case (SCode.PARTS(el, neql, ieql, nal, ial, nco, clats, extdecl), _, _)
equation
// Lookup elements.
el = List.filter(el, isNotImport);
el = List.filterOnTrue(el, isNotImport);
(el, env) = List.mapFold(el, flattenElement, inEnv);

// Lookup equations and algorithm names.
Expand Down Expand Up @@ -184,10 +184,11 @@ end flattenDerivedClassDef;

protected function isNotImport
input SCode.Element inElement;
output Boolean outB;
algorithm
_ := match(inElement)
case SCode.IMPORT() then fail();
else ();
outB := match(inElement)
case SCode.IMPORT() then false;
else true;
end match;
end isNotImport;

Expand Down
11 changes: 6 additions & 5 deletions Compiler/FrontEnd/Patternm.mo
Expand Up @@ -483,7 +483,7 @@ algorithm
Util.SUCCESS() = checkInvalidPatternNamedArgs(invalidArgs,fieldNameList,Util.SUCCESS(),info);
(cache,patterns) = elabPatternTuple(cache,env,funcArgs,fieldTypeList,info,lhs);
namedPatterns = List.thread3Tuple(patterns, fieldNameList, List.map(fieldTypeList,Types.simplifyType));
namedPatterns = List.filter(namedPatterns, filterEmptyPattern);
namedPatterns = List.filterOnTrue(namedPatterns, filterEmptyPattern);
then (cache,DAE.PAT_CALL_NAMED(fqPath,namedPatterns));

case (cache,_,_,_,_,_,_)
Expand Down Expand Up @@ -1403,7 +1403,7 @@ algorithm
list<DAE.Pattern> patterns;
case ((DAE.PAT_CALL_NAMED(name, namedPatterns),a))
equation
namedPatterns = List.filter(namedPatterns, filterEmptyPattern);
namedPatterns = List.filterOnTrue(namedPatterns, filterEmptyPattern);
pat = if listEmpty(namedPatterns) then DAE.PAT_WILD() else DAE.PAT_CALL_NAMED(name, namedPatterns);
then ((pat,a));
case ((pat as DAE.PAT_CALL_TUPLE(patterns),a))
Expand Down Expand Up @@ -2347,10 +2347,11 @@ end traverseCasesTopDown;

protected function filterEmptyPattern
input tuple<DAE.Pattern,String,DAE.Type> tpl;
output Boolean outB;
algorithm
_ := match tpl
case ((DAE.PAT_WILD(),_,_)) then fail();
else ();
outB := match tpl
case ((DAE.PAT_WILD(),_,_)) then false;
else true;
end match;
end filterEmptyPattern;

Expand Down
9 changes: 5 additions & 4 deletions Compiler/FrontEnd/SCode.mo
Expand Up @@ -3865,16 +3865,17 @@ public function removeBuiltinsFromTopScope
input Program inProgram;
output Program outProgram;
algorithm
outProgram := List.filter(inProgram, isNotBuiltinClass);
outProgram := List.filterOnTrue(inProgram, isNotBuiltinClass);
end removeBuiltinsFromTopScope;

protected function isNotBuiltinClass
input Element inClass;
output Boolean b;
algorithm
_ := match(inClass)
b := match(inClass)
case CLASS(classDef = PARTS(externalDecl =
SOME(EXTERNALDECL(lang = SOME("builtin"))))) then fail();
else ();
SOME(EXTERNALDECL(lang = SOME("builtin"))))) then false;
else true;
end match;
end isNotBuiltinClass;

Expand Down

0 comments on commit d41fb97

Please sign in to comment.