Skip to content

Commit

Permalink
Static analysis
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@24696 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Feb 22, 2015
1 parent 6382bf1 commit a369e43
Show file tree
Hide file tree
Showing 26 changed files with 113 additions and 117 deletions.
4 changes: 2 additions & 2 deletions Compiler/BackEnd/BackendDAECreate.mo
Expand Up @@ -521,7 +521,7 @@ algorithm
();

// variables: states and algebraic variables without binding equation
case DAE.VAR(componentRef = cr, binding = NONE()) guard(isStateOrAlgvar(inElement))
case DAE.VAR(binding = NONE()) guard(isStateOrAlgvar(inElement))
algorithm
outVars := lowerDynamicVar(inElement, inFunctions) :: outVars;
then
Expand Down Expand Up @@ -2170,7 +2170,7 @@ algorithm
rest = listAppend(rest2, rest);
then (wheneq, rest);

case (cr1, (eq as BackendDAE.WHEN_EQUATION(whenEquation=wheneq as BackendDAE.WHEN_EQ(left=cr2)))::rest, rest2)
case (cr1, (eq as BackendDAE.WHEN_EQUATION(whenEquation=BackendDAE.WHEN_EQ()))::rest, rest2)
equation
(wheneq, rest) = getWhenEquationFromVariable(cr1, rest, eq::rest2);
then (wheneq, rest);
Expand Down
10 changes: 5 additions & 5 deletions Compiler/BackEnd/BackendDAEOptimize.mo
Expand Up @@ -1873,7 +1873,7 @@ algorithm

case ((comp as BackendDAE.EQUATIONSYSTEM(eqns=eqs,jac=jac,jacType=BackendDAE.JAC_LINEAR()))::rest,_,_,_)
equation
(eqnlst,varlst,_) = BackendDAETransform.getEquationAndSolvedVar(comp, BackendEquation.getEqnsFromEqSystem(isyst), BackendVariable.daeVars(isyst));
(_,_,_) = BackendDAETransform.getEquationAndSolvedVar(comp, BackendEquation.getEqnsFromEqSystem(isyst), BackendVariable.daeVars(isyst));
size = listLength(eqs);
density = realDiv(intReal(getNumJacEntries(jac)),intReal(size*size ));
allOps = BackendDAE.COUNTER(comp,0,0,0,0,0,0,0,0);
Expand Down Expand Up @@ -1946,11 +1946,11 @@ algorithm
compInfo = BackendDAE.TORN_ANALYSE(comp,torn,other,listLength(tornEqs));
then
countOperationstraverseComps(rest,isyst,ishared,compInfo::compInfosIn);
case (BackendDAE.TORNSYSTEM(tearingvars=vlst, residualequations=tornEqs, otherEqnVarTpl= eqnvartpllst, linear = false)::rest,_,BackendDAE.SHARED(functionTree=funcs),_)
case (BackendDAE.TORNSYSTEM(residualequations=tornEqs, otherEqnVarTpl= eqnvartpllst, linear = false)::rest,_,BackendDAE.SHARED(),_)
equation
comp = List.first(inComps);
eqns = BackendEquation.getEqnsFromEqSystem(isyst);
vars = BackendVariable.daeVars(isyst);
_ = BackendVariable.daeVars(isyst);
// the torn equations
eqnlst = BackendEquation.getEqns(tornEqs,eqns);
explst = List.map(eqnlst,BackendEquation.getEquationRHS);
Expand Down Expand Up @@ -2204,7 +2204,7 @@ algorithm
case (DAE.DIV_ARR(ty=tp),(i1,i2,i3,i4,i5,i6,i7,i8)) equation
i = Expression.sizeOf(tp);
then (i1,i2,i3+i,i4,i5,i6,i7,i8);
case (DAE.MUL_ARRAY_SCALAR(ty=tp),(i1,i2,i3,i4,i5,i6,i7,i8)) equation
case (DAE.MUL_ARRAY_SCALAR(),(i1,i2,i3,i4,i5,i6,i7,i8)) equation
then (i1,i2+1,i3,i4,i5,i6,i7,i8);
case (DAE.ADD_ARRAY_SCALAR(),(i1,i2,i3,i4,i5,i6,i7,i8))
then (i1+1,i2,i3,i4,i5,i6,i7,i8);
Expand Down Expand Up @@ -4112,7 +4112,7 @@ algorithm
end if;
then (outExp, (vars, eqnLst, shared, addVar, true));

case (DAE.CALL(path=Absyn.IDENT(name="der"), expLst=expLst), (vars, eqnLst, shared, addVar, _)) equation
case (DAE.CALL(path=Absyn.IDENT(name="der")), (_, _, _, _, _)) equation
str = "BackendDAEOptimize.introduceDerAlias failed for: " + ExpressionDump.printExpStr(inExp) + "\n";
Error.addMessage(Error.INTERNAL_ERROR, {str});
then fail();
Expand Down
8 changes: 4 additions & 4 deletions Compiler/BackEnd/BackendEquation.mo
Expand Up @@ -2901,7 +2901,7 @@ author:Waurich TUD 2014-10"
input BackendDAE.Equation eq;
output DAE.Exp rhs;
algorithm
rhs := matchcontinue(eq)
rhs := match(eq)
local
DAE.Exp exp1;
case(BackendDAE.EQUATION(scalar = exp1))
Expand All @@ -2917,15 +2917,15 @@ algorithm
else
//equation print("BackendEquation.getEquationRHS failed!\n!");
then fail();
end matchcontinue;
end match;
end getEquationRHS;

public function getEquationLHS"gets the left hand side expression of an equation.
author:Waurich TUD 2014-10"
input BackendDAE.Equation eq;
output DAE.Exp lhs;
algorithm
lhs := matchcontinue(eq)
lhs := match(eq)
local
DAE.Exp exp1;
DAE.ComponentRef cref;
Expand All @@ -2942,7 +2942,7 @@ algorithm
else
//equation print("BackendEquation.getEquationLHS failed!\n");
then fail();
end matchcontinue;
end match;
end getEquationLHS;

annotation(__OpenModelica_Interface="backend");
Expand Down
20 changes: 10 additions & 10 deletions Compiler/BackEnd/CommonSubExpression.mo
Expand Up @@ -110,7 +110,7 @@ algorithm
HashTableExpToExp.HashTable HT;
HashTableExpToIndex.HashTable HT2, HT3;

case BackendDAE.EQSYSTEM(orderedVars, orderedEqs, m, mT, matching, stateSets, partitionKind) equation
case BackendDAE.EQSYSTEM(orderedVars, orderedEqs, _, _, _, stateSets, partitionKind) equation
// BackendDump.dumpEquationList(eqList, "############## Equation-Liste: ###########");
// BackendDump.dumpVarList(varList, "############## Variablen-Liste: ###########");
// TODO: merge HT and HT2
Expand Down Expand Up @@ -197,7 +197,7 @@ algorithm
list<DAE.Exp> expLst;
DAE.ElementSource source;

case (key as DAE.BINARY(exp1, op, exp2), ((HT, HT2, HT3, eqLst, varLst), source)) equation
case (key as DAE.BINARY(_, _, _), ((HT, HT2, HT3, eqLst, varLst), source)) equation
true = Flags.getConfigBool(Flags.CSE_BINARY);
value = BaseHashTable.get(key, HT);
value2 = BaseHashTable.get(value, HT2);
Expand Down Expand Up @@ -372,7 +372,7 @@ algorithm
then (inExp, false, inTuple);


case (DAE.CALL(path=path, attr=DAE.CALL_ATTR(ty=tp)), (HT, HT2, i)) equation
case (DAE.CALL( attr=DAE.CALL_ATTR(ty=tp)), (HT, HT2, i)) equation
true = Flags.getConfigBool(Flags.CSE_CALL) or Flags.getConfigBool(Flags.CSE_EACHCALL);
if BaseHashTable.hasKey(inExp, HT) then
value = BaseHashTable.get(inExp, HT);
Expand Down Expand Up @@ -482,7 +482,7 @@ algorithm
then (value, i+1);

// Expanding.
case DAE.T_ARRAY(ty=tp, dims=dims) equation
case DAE.T_ARRAY(dims=_) equation
str = "$CSE" + intString(inUniqueCSEIndex);
cr = DAE.CREF_IDENT(str, inType, {});
crefs = ComponentReference.expandCref(cr, false);
Expand All @@ -499,7 +499,7 @@ algorithm


// record types
case DAE.T_COMPLEX(varLst=varLst,complexClassType=ClassInf.RECORD(path),source=tpSource) equation
case DAE.T_COMPLEX(varLst=varLst,complexClassType=ClassInf.RECORD(path)) equation
str = "$CSE" + intString(inUniqueCSEIndex);
cr = DAE.CREF_IDENT(str, inType, {});
crefs = ComponentReference.expandCref(cr, true);
Expand Down Expand Up @@ -579,7 +579,7 @@ algorithm
expLst = List.map(expLst, prepareExpForReplace);
then DAE.TUPLE(expLst);

case DAE.ARRAY(array=e::_, ty=ty, scalar=scalar) equation
case DAE.ARRAY(array=e::_, ty=ty) equation
cr = Expression.expCref(e);
cr = ComponentReference.crefStripLastSubs(cr);
cr = ComponentReference.crefSetType(cr, ty);
Expand Down Expand Up @@ -750,7 +750,7 @@ algorithm
{varIdx2} = varIdcs2;
{sharedVarIdx} = sharedVarIdcs;
{eq1,eq2} = BackendEquation.getEqns(partition,eqs);
sharedVar = BackendVariable.getVarAt(vars,sharedVarIdx);
_ = BackendVariable.getVarAt(vars,sharedVarIdx);
var1 = BackendVariable.getVarAt(vars,varIdx1);
var2 = BackendVariable.getVarAt(vars,varIdx2);

Expand Down Expand Up @@ -885,7 +885,7 @@ algorithm
//print("eqs2 "+stringDelimitList(List.map(eqs2,intString),", ")+"\n");
//true = intEq(listLength(eqs1),1) or intEq(listLength(eqs2),1); // choose the variable to be removed, that does not influence the causalization
if intLe(listLength(eqs2),listLength(eqs1)) then varIdxAlias = varIdx2; varIdxRepl = varIdx1; else varIdxAlias = varIdx1; varIdxRepl = varIdx2; end if;
if intLe(listLength(eqs2),listLength(eqs1)) then eqIdxDel = eqIdx2; eqIdxLeft = eqIdx1; else eqIdxDel = eqIdx1; eqIdxLeft = eqIdx2; end if;
if intLe(listLength(eqs2),listLength(eqs1)) then eqIdxDel = eqIdx2; _ = eqIdx1; else eqIdxDel = eqIdx1; _ = eqIdx2; end if;

var1 = BackendVariable.getVarAt(vars,varIdxAlias);
var2 = BackendVariable.getVarAt(vars,varIdxRepl);
Expand Down Expand Up @@ -946,14 +946,14 @@ author:Waurich TUD 2014-11"
input CommonSubExp cse;
output String s;
algorithm
s := matchcontinue(cse)
s := match(cse)
local
list<Integer> eqIdcs;
list<Integer> sharedVars;
list<Integer> aliasVars;
case(ASSIGNMENT_CSE(eqIdcs=eqIdcs,sharedVars=sharedVars,aliasVars=aliasVars))
then "ASSIGN_CSE: eqs{"+stringDelimitList(List.map(eqIdcs,intString),", ")+"}"+" sharedVars{"+stringDelimitList(List.map(sharedVars,intString),", ")+"}"+" aliasVars{"+stringDelimitList(List.map(aliasVars,intString),", ")+"}";
end matchcontinue;
end match;
end printCSE;
annotation(__OpenModelica_Interface="backend");

Expand Down
4 changes: 2 additions & 2 deletions Compiler/BackEnd/DynamicOptimization.mo
Expand Up @@ -386,7 +386,7 @@ algorithm
list<BackendDAE.Var> varLst:={};
BackendDAE.Variables vars;

case BackendDAE.EQSYSTEM(orderedVars, orderedEqs, m, mT, matching, stateSets, partitionKind) algorithm
case BackendDAE.EQSYSTEM(orderedVars, orderedEqs, _, _, _, stateSets, partitionKind) algorithm
vars := BackendVariable.daeKnVars(outShared);

((_, idercr, icr, varLst)) := BackendDAEUtil.traverseBackendDAEExpsEqnsWithUpdate(orderedEqs, traverserinputDerivativesForDynOpt, (vars, idercr, icr, varLst));
Expand All @@ -405,7 +405,7 @@ algorithm
v := BackendVariable.setVarKind(v,BackendDAE.OPT_INPUT_DER());
outShared := BackendVariable.addKnVarDAE(v, outShared);
end for;
vars := BackendVariable.daeKnVars(outShared);
_ := BackendVariable.daeKnVars(outShared);
//BackendDump.printVariables(vars);
then (BackendDAE.EQSYSTEM(orderedVars, orderedEqs, NONE(),NONE(),BackendDAE.NO_MATCHING(), stateSets, partitionKind), true);

Expand Down
36 changes: 18 additions & 18 deletions Compiler/BackEnd/ExpressionSolve.mo
Expand Up @@ -482,7 +482,7 @@ algorithm
(Expression.negate(inExp2),{});

// !cr = exp
case (DAE.LUNARY(operator = DAE.NOT(ty=_), exp = DAE.CREF(componentRef = cr1)),_,DAE.CREF(componentRef = cr))
case (DAE.LUNARY(operator = DAE.NOT(), exp = DAE.CREF(componentRef = cr1)),_,DAE.CREF(componentRef = cr))
equation
true = ComponentReference.crefEqual(cr1,cr);
// cr not in e2
Expand Down Expand Up @@ -861,7 +861,7 @@ algorithm
(e1, res, true);

// sqrt(f(a)) = f(a)^n = c => f(a) = c^(1/n)
case (DAE.BINARY(e1,DAE.POW(_),e2 as DAE.RCONST(0.5)), _, _)
case (DAE.BINARY(e1,DAE.POW(_),DAE.RCONST(0.5)), _, _)
equation
false = expHasCref(inExp2, inExp3);
true = expHasCref(e1, inExp3);
Expand Down Expand Up @@ -915,37 +915,37 @@ algorithm
DAE.Type tp;

// exp(f(x)) - exp(g(x)) = 0
case(DAE.BINARY(DAE.CALL(path = Absyn.IDENT("exp"), expLst={e1}), op as DAE.SUB(tp),
case(DAE.BINARY(DAE.CALL(path = Absyn.IDENT("exp"), expLst={e1}), DAE.SUB(_),
DAE.CALL(path = Absyn.IDENT("exp"), expLst={e2})),DAE.RCONST(0.0),_)
then (e1, e2, true);
// log(f(x)) - log(g(x)) = 0
case(DAE.BINARY(DAE.CALL(path = Absyn.IDENT("log"), expLst={e1}), op as DAE.SUB(tp),
case(DAE.BINARY(DAE.CALL(path = Absyn.IDENT("log"), expLst={e1}), DAE.SUB(_),
DAE.CALL(path = Absyn.IDENT("log"), expLst={e2})),DAE.RCONST(0.0),_)
then (e1, e2, true);
// log10(f(x)) - log10(g(x)) = 0
case(DAE.BINARY(DAE.CALL(path = Absyn.IDENT("log10"), expLst={e1}), op as DAE.SUB(tp),
case(DAE.BINARY(DAE.CALL(path = Absyn.IDENT("log10"), expLst={e1}), DAE.SUB(_),
DAE.CALL(path = Absyn.IDENT("log10"), expLst={e2})),DAE.RCONST(0.0),_)
then (e1, e2, true);
// sinh(f(x)) - sinh(g(x)) = 0
case(DAE.BINARY(DAE.CALL(path = Absyn.IDENT("sinh"), expLst={e1}), op as DAE.SUB(tp),
case(DAE.BINARY(DAE.CALL(path = Absyn.IDENT("sinh"), expLst={e1}), DAE.SUB(_),
DAE.CALL(path = Absyn.IDENT("sinh"), expLst={e2})),DAE.RCONST(0.0),_)
then (e1, e2, true);
// tanh(f(x)) - tanh(g(x)) = 0
case(DAE.BINARY(DAE.CALL(path = Absyn.IDENT("tanh"), expLst={e1}), op as DAE.SUB(tp),
case(DAE.BINARY(DAE.CALL(path = Absyn.IDENT("tanh"), expLst={e1}), DAE.SUB(_),
DAE.CALL(path = Absyn.IDENT("tanh"), expLst={e2})),DAE.RCONST(0.0),_)
then (e1, e2, true);
// sqrt(f(x)) - sqrt(g(x)) = 0
case(DAE.BINARY(DAE.CALL(path = Absyn.IDENT("sqrt"), expLst={e1}), op as DAE.SUB(tp),
case(DAE.BINARY(DAE.CALL(path = Absyn.IDENT("sqrt"), expLst={e1}), DAE.SUB(_),
DAE.CALL(path = Absyn.IDENT("sqrt"), expLst={e2})),DAE.RCONST(0.0),_)
then (e1, e2, true);

// sinh(f(x)) - cosh(g(x)) = 0
case(DAE.BINARY(DAE.CALL(path = Absyn.IDENT("sinh"), expLst={e1}), op as DAE.SUB(tp),
case(DAE.BINARY(DAE.CALL(path = Absyn.IDENT("sinh"), expLst={e1}), DAE.SUB(_),
DAE.CALL(path = Absyn.IDENT("cosh"), expLst={e2})),DAE.RCONST(0.0),_)
equation
true = Expression.expEqual(e1,e2);
then (e1, inExp2, true);
case(DAE.BINARY(DAE.CALL(path = Absyn.IDENT("cosh"), expLst={e1}), op as DAE.SUB(tp),
case(DAE.BINARY(DAE.CALL(path = Absyn.IDENT("cosh"), expLst={e1}), DAE.SUB(_),
DAE.CALL(path = Absyn.IDENT("sinh"), expLst={e2})),DAE.RCONST(0.0),_)
equation
true = Expression.expEqual(e1,e2);
Expand All @@ -954,13 +954,13 @@ algorithm


// y*sinh(x) - z*cosh(x) = 0
case(DAE.BINARY(DAE.BINARY(e3,DAE.MUL(),DAE.CALL(path = Absyn.IDENT("sinh"), expLst={e1})), op as DAE.SUB(tp),
case(DAE.BINARY(DAE.BINARY(e3,DAE.MUL(),DAE.CALL(path = Absyn.IDENT("sinh"), expLst={e1})), DAE.SUB(tp),
DAE.BINARY(e4,DAE.MUL(),DAE.CALL(path = Absyn.IDENT("cosh"), expLst={e2}))),DAE.RCONST(0.0),_)
equation
true = Expression.expEqual(e1,e2);
e = Expression.makePureBuiltinCall("tanh",{e1},tp);
then (Expression.expMul(e3,e), e4, true);
case(DAE.BINARY(DAE.BINARY(e4,DAE.MUL(),DAE.CALL(path = Absyn.IDENT("cosh"), expLst={e2})), op as DAE.SUB(tp),
case(DAE.BINARY(DAE.BINARY(e4,DAE.MUL(),DAE.CALL(path = Absyn.IDENT("cosh"), expLst={e2})), DAE.SUB(tp),
DAE.BINARY(e3,DAE.MUL(),DAE.CALL(path = Absyn.IDENT("sinh"), expLst={e1}))),DAE.RCONST(0.0),_)
equation
true = Expression.expEqual(e1,e2);
Expand All @@ -970,9 +970,9 @@ algorithm


// sqrt(x) - x = 0 -> x = x^2
case(DAE.BINARY(DAE.CALL(path = Absyn.IDENT("sqrt"), expLst={e1}), op as DAE.SUB(tp),e2), DAE.RCONST(0.0),_)
case(DAE.BINARY(DAE.CALL(path = Absyn.IDENT("sqrt"), expLst={e1}), DAE.SUB(_),e2), DAE.RCONST(0.0),_)
then (e1, Expression.expPow(e2, DAE.RCONST(2.0)), true);
case(DAE.BINARY(e2, op as DAE.SUB(tp),DAE.CALL(path = Absyn.IDENT("sqrt"), expLst={e1})), DAE.RCONST(0.0),_)
case(DAE.BINARY(e2, DAE.SUB(_),DAE.CALL(path = Absyn.IDENT("sqrt"), expLst={e1})), DAE.RCONST(0.0),_)
equation
then (e1, Expression.expPow(e2, DAE.RCONST(2.0)), true);

Expand Down Expand Up @@ -1225,7 +1225,7 @@ protected function unifyFunCallsWork
true = expHasCref(e, X);
then (e, true, iT);

case(DAE.CALL(path = Absyn.IDENT(name = "semiLinear"),expLst = {e1, e2, e3}),X)
case(DAE.CALL(path = Absyn.IDENT(name = "semiLinear"),expLst = {e1, e2, e3}),_)
equation
false = Expression.isZero(e1);
tp = Expression.typeof(e1);
Expand Down Expand Up @@ -1363,7 +1363,7 @@ algorithm
case (DAE.CALL(path = Absyn.IDENT(name = "semiLinear"),expLst = {DAE.RCONST(real = 0.0), e1, e2}),DAE.RCONST(real = 0.0),_)
then (e1,e2,true);
// smooth(i,f(a)) = rhs -> f(a) = rhs
case (DAE.CALL(path = Absyn.IDENT(name = "smooth"),expLst = {e1, e2}),_,_)
case (DAE.CALL(path = Absyn.IDENT(name = "smooth"),expLst = {_, e2}),_,_)
then (e2, inExp2, true);
// noEvent(f(a)) = rhs -> f(a) = rhs
case (DAE.CALL(path = Absyn.IDENT(name = "noEvent"),expLst = {e2}),_,_)
Expand Down Expand Up @@ -1392,7 +1392,7 @@ author: vitalij
Option<DAE.FunctionTree> functions;
Boolean b;

case(DAE.CALL(path =_),(X, functions))
case(DAE.CALL(),(X, functions))
equation
//print("\nIn: ");print(ExpressionDump.printExpStr(inExp));
true = expHasCref(inExp, X);
Expand Down Expand Up @@ -1842,7 +1842,7 @@ algorithm
false = expHasCref(e1, inExp3);

(lhs, asserts1, eqns, var, depth) = solveWork(e2, inExp2, inExp3, functions, uniqueEqIndex, idepth);
(rhs, asserts2, eqns1, var1, depth) = solveWork(e3, inExp2, inExp3, functions, uniqueEqIndex, depth);
(rhs,_, eqns1, var1, depth) = solveWork(e3, inExp2, inExp3, functions, uniqueEqIndex, depth);

res = DAE.IFEXP(e1,lhs,rhs);
asserts = listAppend(asserts1,asserts1);
Expand Down

0 comments on commit a369e43

Please sign in to comment.