Skip to content

Commit

Permalink
- some cleanup
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@25027 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
lochel committed Mar 11, 2015
1 parent 1ed8384 commit 8dff8e6
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 51 deletions.
17 changes: 9 additions & 8 deletions Compiler/BackEnd/BackendVarTransform.mo
Expand Up @@ -973,19 +973,20 @@ algorithm outExp := matchcontinue(inExp,inType)
end avoidDoubleHashLookup;


public function replacementEmpty
public function isReplacementEmpty
input VariableReplacements repl;
output Boolean empty;
algorithm
empty := match(repl)
local
HashTable2.HashTable ht;
case REPLACEMENTS(hashTable = ht,derConst=NONE())
then
intLt(BaseHashTable.hashTableCurrentSize(ht),1);
case REPLACEMENTS(derConst=SOME(_)) then false;

case REPLACEMENTS(hashTable=ht, derConst=NONE())
then intLt(BaseHashTable.hashTableCurrentSize(ht), 1);

case REPLACEMENTS(derConst=SOME(_)) then false;
end match;
end replacementEmpty;
end isReplacementEmpty;

public function replacementCurrentSize
input VariableReplacements repl;
Expand Down Expand Up @@ -1547,7 +1548,7 @@ algorithm
case(_,_,_)
equation
// Do not do empty replacements; it just takes time ;)
false = replacementEmpty(repl);
false = isReplacementEmpty(repl);
((_,_,eqns,replacementPerformed)) = BackendEquation.traverseEquationArray(inEqns,replaceEquationTraverser,(repl,inFuncTypeExpExpToBooleanOption,{},false));
outEqns = if replacementPerformed then BackendEquation.listEquation(eqns) else inEqns;
then
Expand Down Expand Up @@ -1600,7 +1601,7 @@ algorithm
case(_,_,_)
equation
// Do not do empty replacements; it just takes time ;)
false = replacementEmpty(repl);
false = isReplacementEmpty(repl);
(eqns,replacementPerformed) = replaceEquations2(inEqns,repl,inFuncTypeExpExpToBooleanOption,{},false);
then
(eqns,replacementPerformed);
Expand Down
90 changes: 47 additions & 43 deletions Compiler/BackEnd/EvaluateParameter.mo
Expand Up @@ -140,7 +140,10 @@ protected
BackendVarTransform.VariableReplacements repl;
algorithm
(outDAE,repl) := evaluateParameters(inDAE,BackendVariable.isFinalOrProtectedVar);
outDAE := replaceEvaluatedParametersEqns(BackendVarTransform.replacementEmpty(repl),outDAE,repl);

if not BackendVarTransform.isReplacementEmpty(repl) then
outDAE := replaceEvaluatedParametersEqns(outDAE, repl);
end if;
end evaluateReplaceFinalParameters;

public function evaluateReplaceEvaluateParameters
Expand All @@ -152,7 +155,10 @@ protected
BackendVarTransform.VariableReplacements repl;
algorithm
(outDAE,repl) := evaluateParameters(inDAE,BackendVariable.hasVarEvaluateAnnotation);
outDAE := replaceEvaluatedParametersEqns(BackendVarTransform.replacementEmpty(repl),outDAE,repl);

if not BackendVarTransform.isReplacementEmpty(repl) then
outDAE := replaceEvaluatedParametersEqns(outDAE, repl);
end if;
end evaluateReplaceEvaluateParameters;

public function evaluateReplaceFinalEvaluateParameters "author: Frenkel TUD
Expand All @@ -163,7 +169,10 @@ protected
BackendVarTransform.VariableReplacements repl;
algorithm
(outDAE,repl) := evaluateParameters(inDAE,BackendVariable.hasVarEvaluateAnnotationOrFinal);
outDAE := replaceEvaluatedParametersEqns(BackendVarTransform.replacementEmpty(repl),outDAE,repl);

if not BackendVarTransform.isReplacementEmpty(repl) then
outDAE := replaceEvaluatedParametersEqns(outDAE, repl);
end if;
end evaluateReplaceFinalEvaluateParameters;

public function evaluateReplaceProtectedFinalEvaluateParameters "author: Frenkel TUD
Expand All @@ -174,7 +183,10 @@ protected
BackendVarTransform.VariableReplacements repl;
algorithm
(outDAE,repl) := evaluateParameters(inDAE,BackendVariable.hasVarEvaluateAnnotationOrFinalOrProtected);
outDAE := replaceEvaluatedParametersEqns(BackendVarTransform.replacementEmpty(repl),outDAE,repl);

if not BackendVarTransform.isReplacementEmpty(repl) then
outDAE := replaceEvaluatedParametersEqns(outDAE, repl);
end if;
end evaluateReplaceProtectedFinalEvaluateParameters;

/*
Expand Down Expand Up @@ -1041,51 +1053,43 @@ algorithm
end matchcontinue;
end replaceEvaluatedParameterTraverser;

protected function replaceEvaluatedParametersEqns
"author Frenkel TUD"
input Boolean replacementsEmpty;
protected function replaceEvaluatedParametersEqns "author Frenkel TUD"
input BackendDAE.BackendDAE inDAE;
input BackendVarTransform.VariableReplacements repl;
input BackendVarTransform.VariableReplacements inRepl;
output BackendDAE.BackendDAE outDAE;
protected
DAE.FunctionTree funcs;
BackendDAE.Variables knvars, exobj, av;
BackendDAE.EquationArray remeqns, inieqns;
list<DAE.Constraint> constrs;
list<DAE.ClassAttributes> clsAttrs;
FCore.Cache cache;
FCore.Graph graph;
BackendDAE.EventInfo einfo;
BackendDAE.ExternalObjectClasses eoc;
BackendDAE.SymbolicJacobians symjacs;
BackendDAE.BackendDAEType btp;
list<BackendDAE.Equation> eqnslst;
BackendDAE.EqSystems systs;
Boolean b;
BackendDAE.ExtraInfo ei;
algorithm
outDAE := match (replacementsEmpty,inDAE,repl)
local
DAE.FunctionTree funcs;
BackendDAE.Variables knvars,exobj,av;
BackendDAE.EquationArray remeqns,inieqns;
list<DAE.Constraint> constrs;
list<DAE.ClassAttributes> clsAttrs;
FCore.Cache cache;
FCore.Graph graph;
BackendDAE.EventInfo einfo;
BackendDAE.ExternalObjectClasses eoc;
BackendDAE.SymbolicJacobians symjacs;
BackendDAE.BackendDAEType btp;
list<BackendDAE.Equation> eqnslst;
BackendDAE.EqSystems systs;
BackendDAE.Shared shared;
Boolean b;
BackendDAE.ExtraInfo ei;
BackendDAE.DAE(systs, BackendDAE.SHARED(knvars, exobj, av, inieqns, remeqns, constrs, clsAttrs, cache, graph, funcs, einfo, eoc, btp, symjacs, ei)) := inDAE;

// do nothing if there are no replacements
case (true,_,_) then inDAE;
// do replacements in initial equations
eqnslst := BackendEquation.equationList(inieqns);
(eqnslst, b) := BackendVarTransform.replaceEquations(eqnslst, inRepl, NONE());
inieqns := if b then BackendEquation.listEquation(eqnslst) else inieqns;

case (false,BackendDAE.DAE(systs,BackendDAE.SHARED(knvars,exobj,av,inieqns,remeqns,constrs,clsAttrs,cache,graph,funcs,einfo,eoc,btp,symjacs,ei)),_)
equation
// do replacements in initial equations
eqnslst = BackendEquation.equationList(inieqns);
(eqnslst,b) = BackendVarTransform.replaceEquations(eqnslst, repl,NONE());
inieqns = if b then BackendEquation.listEquation(eqnslst) else inieqns;
// do replacements in simple equations
eqnslst = BackendEquation.equationList(remeqns);
(eqnslst,b) = BackendVarTransform.replaceEquations(eqnslst, repl,NONE());
remeqns = if b then BackendEquation.listEquation(eqnslst) else remeqns;
// do replacements in systems
systs = List.map1(systs,replaceEvaluatedParametersSystemEqns,repl);
then
BackendDAE.DAE(systs,BackendDAE.SHARED(knvars,exobj,av,inieqns,remeqns,constrs,clsAttrs,cache,graph,funcs,einfo,eoc,btp,symjacs,ei));
// do replacements in simple equations
eqnslst := BackendEquation.equationList(remeqns);
(eqnslst, b) := BackendVarTransform.replaceEquations(eqnslst, inRepl, NONE());
remeqns := if b then BackendEquation.listEquation(eqnslst) else remeqns;

end match;
// do replacements in systems
systs := List.map1(systs, replaceEvaluatedParametersSystemEqns, inRepl);

outDAE := BackendDAE.DAE(systs, BackendDAE.SHARED(knvars, exobj, av, inieqns, remeqns, constrs, clsAttrs, cache, graph, funcs, einfo, eoc, btp, symjacs, ei));
end replaceEvaluatedParametersEqns;

protected function replaceEvaluatedParametersSystemEqns
Expand Down

0 comments on commit 8dff8e6

Please sign in to comment.