Skip to content

Commit

Permalink
fix some issues from static code analysis
Browse files Browse the repository at this point in the history
ticket:3954
  • Loading branch information
hkiel authored and OpenModelica-Hudson committed Jun 17, 2016
1 parent a38e0f0 commit ce35531
Show file tree
Hide file tree
Showing 14 changed files with 51 additions and 60 deletions.
2 changes: 1 addition & 1 deletion Compiler/BackEnd/CommonSubExpression.mo
Expand Up @@ -1090,7 +1090,7 @@ public function cseBinary "authors: Jan Hagemann and Lennart Ochel (FH Bielefeld
This module eliminates common subexpressions in an acausal environment.
NOTE: This is currently just an experimental prototype to demonstrate interesting effects."
input BackendDAE.BackendDAE inDAE;
output BackendDAE.BackendDAE outDAE = inDAE;
output BackendDAE.BackendDAE outDAE;
algorithm
outDAE := BackendDAEUtil.mapEqSystemAndFold(inDAE, CSE1, 1);
end cseBinary;
Expand Down
3 changes: 1 addition & 2 deletions Compiler/BackEnd/DAEQuery.mo
Expand Up @@ -85,11 +85,10 @@ public function getEquations
input BackendDAE.BackendDAE inBackendDAE;
output String strEqs;
protected
BackendDAE.Shared shared;
BackendDAE.EqSystem syst;
list<String> ls1;
algorithm
BackendDAE.DAE({syst}, shared) := inBackendDAE;
BackendDAE.DAE({syst}, _) := inBackendDAE;
ls1 := List.map(BackendEquation.equationList(syst.orderedEqs), equationStr);
strEqs := "EqStr = {" + stringDelimitList(ls1, ",") + "};";
end getEquations;
Expand Down
5 changes: 2 additions & 3 deletions Compiler/BackEnd/EvaluateFunctions.mo
Expand Up @@ -895,7 +895,7 @@ algorithm
elements = DAEUtil.getFunctionElements(func);
if listEmpty(elements) then
// its a record
eLst = lst;
//eLst = lst;
else
// its a call, get the scalar outputs
SOME(func) = DAE.AvlTreePathFunction.get(funcs,path);
Expand Down Expand Up @@ -1069,7 +1069,6 @@ algorithm
case(DAE.CREF(componentRef=cref,ty = DAE.T_COMPLEX(complexClassType=ClassInf.RECORD(),varLst=varLst)))
equation
true = listLength(varLst)==1;
DAE.CREF(componentRef=cref) = expIn;
crefs = getRecordScalars(cref);
true = listLength(crefs)==1;
cref = listHead(crefs);
Expand Down Expand Up @@ -1574,7 +1573,7 @@ algorithm
Boolean b1,b2;
DAE.Exp e1, e2;
DAE.Statement stmt;
case(DAE.STMT_ASSIGN(exp1=e1,exp=e2),_)
case(DAE.STMT_ASSIGN(),_)
equation
({stmt},_) = BackendVarTransform.replaceStatementLst({stmtIn},repl,NONE(),{},false);
DAE.STMT_ASSIGN(exp1=e1,exp=e2) = stmt;
Expand Down
12 changes: 6 additions & 6 deletions Compiler/BackEnd/FindZeroCrossings.mo
Expand Up @@ -898,11 +898,11 @@ algorithm
then (inExp, true, inTpl);

// coditions that are zerocrossings.
case (DAE.LUNARY(exp=e1, operator=op), ((zeroCrossings, relations, samples, numRelations, numMathFunctions), (eq_count, vars, globalKnownVars))) equation
case (DAE.LUNARY(exp=e1, operator=op), ((zeroCrossings, relations, samples, numRelations, numMathFunctions), _)) equation
if Flags.isSet(Flags.RELIDX) then
print("continues LUNARY: " + intString(numRelations) + "\n");
end if;
(e1, ((_, relations, samples, numRelations, numMathFunctions), tp1 as (eq_count, vars, globalKnownVars))) = Expression.traverseExpTopDown(e1, collectZC, ((zeroCrossings, relations, samples, numRelations, numMathFunctions), (eq_count, vars, globalKnownVars)));
(e1, ((_, relations, samples, numRelations, numMathFunctions), tp1 as (eq_count, vars, globalKnownVars))) = Expression.traverseExpTopDown(e1, collectZC, inTpl);
e_1 = DAE.LUNARY(op, e1);
zc = createZeroCrossing(e_1, {eq_count});
zc_lst = List.select1(zeroCrossings, zcEqual, zc);
Expand Down Expand Up @@ -1108,7 +1108,7 @@ algorithm
then (inExp, true, inTpl);

// conditions that are zerocrossings.
case (DAE.LUNARY(exp=e1, operator=op), (iterator, inExpLst, DAE.RANGE(), (zeroCrossings, relations, samples, numRelations, numMathFunctions), tp1)) equation
case (DAE.LUNARY(exp=e1, operator=op), (iterator, _, DAE.RANGE(), (zeroCrossings, _, _, numRelations, numMathFunctions), _)) equation
true = Expression.expContains(inExp, iterator);
if Flags.isSet(Flags.RELIDX) then
print("continues LUNARY with Iterator: " + intString(numRelations) + "\n");
Expand All @@ -1129,7 +1129,7 @@ algorithm
then (e_1, false, (iterator, inExpLst, range2, (zeroCrossings, relations, samples, numRelations, numMathFunctions), tp1));

// coditions that are zerocrossings.
case (DAE.LUNARY(exp=e1, operator=op), (iterator, inExpLst, range, (zeroCrossings, relations, samples, numRelations, numMathFunctions), tp1 as (alg_indx, _, _))) equation
case (DAE.LUNARY(exp=e1, operator=op), (_, _, _, (zeroCrossings, _, _, numRelations, _), _)) equation
if Flags.isSet(Flags.RELIDX) then
print("continues LUNARY: " + intString(numRelations) + "\n");
end if;
Expand All @@ -1151,7 +1151,7 @@ algorithm
//fcall(Flags.RELIDX, BackendDump.debugExpStr, (inExp, "\n"));
then (inExp, true, inTpl);

case (DAE.LBINARY(exp1=e1, operator=op, exp2=e2), (iterator, inExpLst, range, (zeroCrossings, relations, samples, numRelations, numMathFunctions), tp1)) equation
case (DAE.LBINARY(exp1=e1, operator=op, exp2=e2), (iterator, inExpLst, _, (zeroCrossings, _, _, numRelations, numMathFunctions), _)) equation
if Flags.isSet(Flags.RELIDX) then
print("continues LBINARY: " + intString(numRelations) + "\n");
BackendDump.debugExpStr(inExp, "\n");
Expand All @@ -1174,7 +1174,7 @@ algorithm
end if;
then (e_1, false, (iterator, inExpLst, range, (zeroCrossings, relations, samples, numRelations1, numMathFunctions), tp1));

case (DAE.LBINARY(exp1=e1, operator=op, exp2=e2), (iterator, inExpLst, range, (zeroCrossings, relations, samples, numRelations, numMathFunctions), (alg_indx, _, _))) equation
case (DAE.LBINARY(exp1=e1, operator=op, exp2=e2), (_, _, _, (zeroCrossings, _, _, numRelations, _), _)) equation
if Flags.isSet(Flags.RELIDX) then
print("continues LBINARY: " + intString(numRelations) + "\n");
BackendDump.debugExpStr(inExp, "\n");
Expand Down
4 changes: 0 additions & 4 deletions Compiler/BackEnd/Initialization.mo
Expand Up @@ -1121,7 +1121,6 @@ protected
algorithm
// filter empty systems
eqs := {};
outRemovedEqns := {};
dumpVars := DoubleEndedList.fromList({});
removedEqns := DoubleEndedList.fromList({});
for syst in inInitDAE.eqs loop
Expand Down Expand Up @@ -2459,9 +2458,6 @@ end removeInitializationStuff2;
protected function replaceHomotopyWithSimplified
input BackendDAE.BackendDAE inDAE;
output BackendDAE.BackendDAE outDAE = inDAE;
protected
list<BackendDAE.Equation> removedEqsList = {};
BackendDAE.Shared shared = inDAE.shared;
algorithm
for eqs in outDAE.eqs loop
_ := BackendDAEUtil.traverseBackendDAEExpsEqnsWithUpdate(eqs.orderedEqs, replaceHomotopyWithSimplified1, false);
Expand Down
2 changes: 1 addition & 1 deletion Compiler/FrontEnd/ComponentReference.mo
Expand Up @@ -685,7 +685,7 @@ package CompareWithGenericSubscript "Package that can be modified to do differen
constant CompareWithSubsType compareSubscript=CompareWithSubsType.WithGenericSubscript;
function compare
input DAE.ComponentRef cr1, cr2;
output Integer res=0;
output Integer res;
algorithm
res := match (cr1, cr2)
case (DAE.CREF_IDENT(),DAE.CREF_IDENT())
Expand Down
8 changes: 4 additions & 4 deletions Compiler/FrontEnd/ConnectUtil.mo
Expand Up @@ -1662,8 +1662,8 @@ algorithm
case SetTrieNode.SET_TRIE_LEAF(insideElement = ie, outsideElement = oe,
flowAssociation = flow_cr)
algorithm
ie := insertFlowAssociationInStreamElement(sets.insideElement, flow_cr);
oe := insertFlowAssociationInStreamElement(sets.outsideElement, flow_cr);
ie := insertFlowAssociationInStreamElement(ie, flow_cr);
oe := insertFlowAssociationInStreamElement(oe, flow_cr);
prefix_cr := buildElementPrefix(prefix);
setArray := setArrayAddElement(ie, prefix_cr, setArray);
setArray := setArrayAddElement(oe, prefix_cr, setArray);
Expand Down Expand Up @@ -1833,10 +1833,10 @@ algorithm
DAE;

case Set.SET(ty = ConnectorType.FLOW(), elements = eql)
then DAEUtil.joinDaes(generateFlowEquations(set.elements), DAE);
then DAEUtil.joinDaes(generateFlowEquations(eql), DAE);

case Set.SET(ty = ConnectorType.STREAM(), elements = eql)
then DAEUtil.joinDaes(generateStreamEquations(set.elements, flowThreshold), DAE);
then DAEUtil.joinDaes(generateStreamEquations(eql, flowThreshold), DAE);

// Should never happen.
case Set.SET(ty = ConnectorType.NO_TYPE())
Expand Down
2 changes: 1 addition & 1 deletion Compiler/FrontEnd/DAEUtil.mo
Expand Up @@ -2697,7 +2697,7 @@ algorithm
equation
true = Absyn.pathEqual(functionName(fn),path);
then fn;
case (path,fn::fns) then getNamedFunctionFromList(path, fns);
case (path,_::fns) then getNamedFunctionFromList(path, fns);
case (path,{})
equation
true = Flags.isSet(Flags.FAILTRACE);
Expand Down
56 changes: 27 additions & 29 deletions Compiler/FrontEnd/Expression.mo
Expand Up @@ -5425,7 +5425,7 @@ public function traverseExpList<ArgT> "Calls traverseExpBottomUp for each elemen
input list<DAE.Exp> inExpl;
input FuncExpType rel;
input ArgT iext_arg;
output list<DAE.Exp> expl = {};
output list<DAE.Exp> expl;
output ArgT ext_arg = iext_arg;
partial function FuncExpType
input DAE.Exp inExp;
Expand Down Expand Up @@ -6078,7 +6078,7 @@ protected function traverseExpTypeDims2<ArgT>
output ArgT outArg;
end FuncType;
protected
Boolean changed = false;
Boolean changed;
DAE.Exp exp, new_exp;
algorithm
for dim in inDims loop
Expand Down Expand Up @@ -7720,7 +7720,7 @@ end isEvaluatedConstWork;
protected function isConstWork
"Returns true if an expression is constant"
input DAE.Exp inExp;
output Boolean outBoolean = false;
output Boolean outBoolean;
algorithm
outBoolean := match (inExp)
local
Expand Down Expand Up @@ -8163,25 +8163,27 @@ end isWholeDim;

public function isInt ""
input DAE.Type it;
output Boolean re = false;
output Boolean re;
algorithm
re := match(it)
local
Type t1,t2;
Type t1;
case(DAE.T_INTEGER()) then true;
case(DAE.T_ARRAY(ty=t2)) then isInt(t2);
case(DAE.T_ARRAY(ty=t1)) then isInt(t1);
else false;
end match;
end isInt;

public function isReal ""
input DAE.Type it;
output Boolean re = false;
output Boolean re;
algorithm
re := match(it)
local
Type t1,t2;
Type t1;
case(DAE.T_REAL()) then true;
case(DAE.T_ARRAY(ty=t2)) then isReal(t2);
case(DAE.T_ARRAY(ty=t1)) then isReal(t1);
else false;
end match;
end isReal;

Expand Down Expand Up @@ -8556,7 +8558,7 @@ This function takes a list of Exp, assumes they are all ICONST
and checks wheter the ICONST are in order."
input Integer expectedValue;
input list<DAE.Exp> integers;
output Boolean ob = false;
output Boolean ob;
algorithm
ob := match(expectedValue,integers)
local
Expand All @@ -8567,6 +8569,7 @@ algorithm
case(x1, DAE.ICONST(x2)::expl) guard intEq(x1, x2)
then
expIntOrder(x1+1,expl);
else false;
end match;
end expIntOrder;

Expand Down Expand Up @@ -9445,7 +9448,7 @@ public function expStructuralEqualList
"Returns true if the two lists of expressions are structural equal."
input list<DAE.Exp> inExp1;
input list<DAE.Exp> inExp2;
output Boolean outBoolean = false;
output Boolean outBoolean;
algorithm
outBoolean := match (inExp1,inExp2)
local
Expand All @@ -9456,14 +9459,15 @@ algorithm
case (e1::es1,e2::es2) guard expStructuralEqual(e1,e2)
then
expStructuralEqualList(es1, es2);
else false;
end match;
end expStructuralEqualList;

protected function expStructuralEqualListLst
"Returns true if the two lists of lists of expressions are structural equal."
input list<list<DAE.Exp>> inExp1;
input list<list<DAE.Exp>> inExp2;
output Boolean outBoolean = false;
output Boolean outBoolean;
algorithm
outBoolean := match (inExp1,inExp2)
local
Expand All @@ -9474,6 +9478,7 @@ algorithm
case (e1::es1,e2::es2) guard expStructuralEqualList(e1,e2)
then
expStructuralEqualListLst(es1, es2);
else false;
end match;
end expStructuralEqualListLst;

Expand Down Expand Up @@ -10037,7 +10042,7 @@ public function subscriptContain "This function checks whether sub2 contains sub
input list<DAE.Subscript> issl2;
output Boolean contained;
algorithm
contained := matchcontinue(issl1,issl2)
contained := match(issl1,issl2)
local
Boolean b;
Subscript ss1,ss2;
Expand Down Expand Up @@ -10079,14 +10084,14 @@ algorithm
then
b;
else false;
end matchcontinue;
end match;
end subscriptContain;

protected function subscriptContain2 "
"
input Integer inInt;
input list<DAE.Exp> inExp2;
output Boolean contained = false;
output Boolean contained;
algorithm
contained := match(inInt,inExp2)
local
Expand All @@ -10106,6 +10111,7 @@ algorithm
b2 = if b then true else subscriptContain2(i,expl);
then
b2;
else false;
end match;
end subscriptContain2;

Expand Down Expand Up @@ -11613,22 +11619,14 @@ public function checkDimensionSizes
DIM_UNKNOWN if checkModel is used."
input DAE.Dimension dim;
output Boolean value;
protected
Integer i;
DAE.Exp e;
algorithm
value := matchcontinue(dim)
case DAE.DIM_INTEGER(integer = i) then true;
case DAE.DIM_ENUM(size = i) then true;
value := match(dim)
case DAE.DIM_INTEGER() then true;
case DAE.DIM_ENUM() then true;
case DAE.DIM_BOOLEAN() then true;
case DAE.DIM_EXP(exp = e) then true;
case DAE.DIM_EXP()
then
false;
case DAE.DIM_UNKNOWN()
then
false;
end matchcontinue;
case DAE.DIM_EXP() then true;
case DAE.DIM_UNKNOWN() then false;
end match;
end checkDimensionSizes;

public function dimensionsList
Expand Down
6 changes: 3 additions & 3 deletions Compiler/Script/CevalScript.mo
Expand Up @@ -2023,7 +2023,7 @@ algorithm
(cache,env) := generateFunctions2(cache,env,p,fullScodeProgram,cl,name,info,cleanCache);
(cache,env) := generateFunctions(cache,env,p,fullScodeProgram,sp,cleanCache);
then (cache,env);
case (cache,env,_,SCode.CLASS(encapsulatedPrefix=SCode.NOT_ENCAPSULATED(),name=name,info=info as SOURCEINFO(fileName=file))::_,_)
case (_,_,_,SCode.CLASS(encapsulatedPrefix=SCode.NOT_ENCAPSULATED(),name=name,info=info as SOURCEINFO(fileName=file))::_,_)
equation
(n,_) = System.regex(file, "ModelicaBuiltin.mo$", 1, false, false);
Error.assertion(n > 0, "Not an encapsulated class (required for separate compilation): " + name, info);
Expand Down Expand Up @@ -2137,7 +2137,7 @@ function getNonPartialElementsForInstantiatedClass "Gets the non-partial element
input SCode.Program sp;
input SCode.Element cl;
input Absyn.Path p;
output list<SCode.Element> elts={};
output list<SCode.Element> elts;
protected
FCore.Graph env;
SCode.Element elt;
Expand Down Expand Up @@ -3116,7 +3116,7 @@ algorithm
Boolean isDir;
list<String> mps,names;
String gd,mp,bp,str,name,version,fileName;
case ("modelica://",name,_,mp,_)
case ("modelica://",name,_,_,_)
equation
(name::names) = System.strtok(name,".");
Absyn.CLASS(info=SOURCEINFO(fileName=fileName)) = Interactive.getPathedClassInProgram(Absyn.IDENT(name),program);
Expand Down
2 changes: 1 addition & 1 deletion Compiler/Script/CevalScriptBackend.mo
Expand Up @@ -2660,7 +2660,7 @@ algorithm
_ = DAEUtil.getFunctionList(FCore.getFunctionTree(cache)); // Make sure that the functions are valid before returning success
then (cache,env,dae,GlobalScript.SYMBOLTABLE(p,fp,ic_1,iv,cf,lf));

case (cache,env,_,st as GlobalScript.SYMBOLTABLE(ast=p),_,_)
case (_,_,_,GlobalScript.SYMBOLTABLE(ast=p),_,_)
equation
str = Absyn.pathString(className);
failure(_ = Interactive.getPathedClassInProgram(className, p));
Expand Down
3 changes: 1 addition & 2 deletions Compiler/Util/DiffAlgorithm.mo
Expand Up @@ -76,15 +76,14 @@ function diff<T>
protected
Integer start1, end1, start2, end2, len1, len2;
array<T> arr1, arr2;
list<tuple<Diff,list<T>>> prefixes = {}, suffixes = {};
algorithm
arr1 := listArray(seq1);
arr2 := listArray(seq2);
start1 := 1;
start2 := 1;
end1 := arrayLength(arr1);
end2 := arrayLength(arr2);
out := diffSeq(arr1, arr2, equals, isWhitespace, toString, 1, arrayLength(arr1), 1, arrayLength(arr2));
out := diffSeq(arr1, arr2, equals, isWhitespace, toString, start1, end1, start2, end2);
end diff;

partial function partialPrintDiff<T>
Expand Down

0 comments on commit ce35531

Please sign in to comment.