Skip to content

Commit

Permalink
Fixes from static error checker
Browse files Browse the repository at this point in the history
  • Loading branch information
sjoelund authored and OpenModelica-Hudson committed Dec 8, 2016
1 parent 4fc6fb7 commit e2c90ae
Show file tree
Hide file tree
Showing 17 changed files with 165 additions and 156 deletions.
20 changes: 10 additions & 10 deletions Compiler/BackEnd/CommonSubExpression.mo
Expand Up @@ -1549,10 +1549,10 @@ algorithm
//print("partition "+stringDelimitList(List.map(partition, intString), ", ")+"\n");
//print("pathVarIdxMap "+stringDelimitList(List.map(List.map1(pathVarIdcs,Array.getIndexFirst,varMap), intString), ", ")+"\n");

//get only the partition equations
eqLst := BackendEquation.equationList(allEqs);
eqLst := List.map1(partition,List.getIndexFirst,eqLst);
eqs := BackendEquation.listEquation(eqLst);
//get only the partition equations
eqLst := BackendEquation.equationList(allEqs);
eqLst := List.map1(partition,List.getIndexFirst,eqLst);
eqs := BackendEquation.listEquation(eqLst);

eqSys := BackendDAEUtil.createEqSystem(pathVars, eqs);
(_, m, mT) := BackendDAEUtil.getIncidenceMatrix(eqSys, BackendDAE.SOLVABLE(), NONE());
Expand Down Expand Up @@ -1794,12 +1794,12 @@ case (SHORTCUT_CSE(eqIdcs={eqIdx1, eqIdx2}, sharedVar=sharedVar)::rest, _, _, sy
//print("n2 "+intString(n2)+"\n");

if n <= 2 then
//print("FROM "+BackendDump.equationString(eq1)+"\n");
//print("AND "+BackendDump.equationString(eq2)+"\n");
eqNew = BackendDAE.EQUATION(lhs1,rhs1,DAE.emptyElementSource,BackendDAE.EQ_ATTR_DEFAULT_DYNAMIC);
//print("MADE A NEW EQUATION "+BackendDump.equationString(eqNew)+"\n\n");
//replace original equation
BackendEquation.setAtIndex(eqs,eqIdx1,eqNew);
//print("FROM "+BackendDump.equationString(eq1)+"\n");
//print("AND "+BackendDump.equationString(eq2)+"\n");
eqNew = BackendDAE.EQUATION(lhs1,rhs1,DAE.emptyElementSource,BackendDAE.EQ_ATTR_DEFAULT_DYNAMIC);
//print("MADE A NEW EQUATION "+BackendDump.equationString(eqNew)+"\n\n");
//replace original equation
BackendEquation.setAtIndex(eqs,eqIdx1,eqNew);
end if;

then commonSubExpressionUpdate(rest, m, mT, syst);
Expand Down
44 changes: 22 additions & 22 deletions Compiler/BackEnd/DumpHTML.mo
Expand Up @@ -581,10 +581,10 @@ algorithm

//setting variables for the html file
scripts := "var ctx = document.querySelector('canvas').getContext('2d');\n"::scripts;
scripts := "ctx.fillStyle = '#001D4B';\n"::scripts;
scripts := "ctx.font=\"18px Arial\";\n\n"::scripts;
scripts := "var blockSize = "+intString(blockSize)+";\n"::scripts;
scripts := "var matrixMargin = "+intString(matrixMargin)+";\n\n"::scripts;
scripts := "ctx.fillStyle = '#001D4B';\n"::scripts;
scripts := "ctx.font=\"18px Arial\";\n\n"::scripts;
scripts := "var blockSize = "+intString(blockSize)+";\n"::scripts;
scripts := "var matrixMargin = "+intString(matrixMargin)+";\n\n"::scripts;

// the functions to draw the matrix
scripts := "
Expand All @@ -595,28 +595,28 @@ function drawRectangle(px, py, blockSize, margin, ctx) {
function rowName(name, rowIdx, blockSize, margin, ctx) {
ctx.strokeText(name, 0, 18+margin+(rowIdx-1)*blockSize, margin);
return ctx;
}\n
}\n
function colName(name, colIdx, blockSize, margin, ctx) {
ctx.strokeText(name, 0, 18+margin+(colIdx-1)*blockSize, margin);
return ctx;
}\n
}\n
function makeLines(blockSize, margin, n, ctx) {
for (var x = 0; x < n+1; ++x) {
ctx.beginPath();
ctx.moveTo( x*blockSize + margin, margin);
ctx.lineTo( x*blockSize + margin, margin + (n)*blockSize);
ctx.stroke();
}\n

for (var x = 0; x < n+1; ++x) {
ctx.beginPath();
ctx.moveTo(margin, x*blockSize + margin);
ctx.lineTo(margin + (n)*blockSize, x*blockSize + margin);
ctx.stroke();
}\n
return ctx;
}
"::scripts;
for (var x = 0; x < n+1; ++x) {
ctx.beginPath();
ctx.moveTo( x*blockSize + margin, margin);
ctx.lineTo( x*blockSize + margin, margin + (n)*blockSize);
ctx.stroke();
}\n

for (var x = 0; x < n+1; ++x) {
ctx.beginPath();
ctx.moveTo(margin, x*blockSize + margin);
ctx.lineTo(margin + (n)*blockSize, x*blockSize + margin);
ctx.stroke();
}\n
return ctx;
}
"::scripts;

size := arrayLength(m);

Expand Down
50 changes: 25 additions & 25 deletions Compiler/BackEnd/HpcOmTaskGraph.mo
Expand Up @@ -6634,33 +6634,33 @@ end dumpPartitionData;

public function setUpHpcOmMapping "author: waurich 12-2015
Creates mappings between simcode and backendDAE for the hpcom module."
input BackendDAE.BackendDAE daeIn;
input SimCode.SimCode simCodeIn;
input Integer lastEqMappingIdx;
input list<tuple<Integer,Integer>> equationSccMappingIn; //Maps each simEq to the scc
output array<Integer> simeqCompMapping; //Maps each simEq to the scc
output array<list<Integer>> sccSimEqMapping; //Maps each scc to a list of simEqs
output array<list<Integer>> daeSccSimEqMapping; //Maps each scc to a list of simEqs, including removed equations like asserts
protected
Integer highestSccIdx, compCountPlusDummy;
list<tuple<Integer,Integer>> equationSccMapping,equationSccMapping1;
BackendDAE.StrongComponents allComps;
algorithm
(allComps,_) := getSystemComponents(daeIn);
highestSccIdx := findHighestSccIdxInMapping(equationSccMappingIn,-1);
compCountPlusDummy := listLength(allComps)+1;
equationSccMapping1 := removeDummyStateFromMapping(equationSccMappingIn);
//the mapping can contain a dummy state as first scc
equationSccMapping := if intEq(highestSccIdx, compCountPlusDummy) then equationSccMapping1 else equationSccMappingIn;
sccSimEqMapping := convertToSccSimEqMapping(equationSccMapping, listLength(allComps));
simeqCompMapping := convertToSimeqCompMapping(equationSccMapping, lastEqMappingIdx);
//for the dae-system
daeSccSimEqMapping := listArray(List.map(SimCodeUtil.getRemovedEquationSimEqSysIdxes(simCodeIn),List.create));
input BackendDAE.BackendDAE daeIn;
input SimCode.SimCode simCodeIn;
input Integer lastEqMappingIdx;
input list<tuple<Integer,Integer>> equationSccMappingIn; //Maps each simEq to the scc
output array<Integer> simeqCompMapping; //Maps each simEq to the scc
output array<list<Integer>> sccSimEqMapping; //Maps each scc to a list of simEqs
output array<list<Integer>> daeSccSimEqMapping; //Maps each scc to a list of simEqs, including removed equations like asserts
protected
Integer highestSccIdx, compCountPlusDummy;
list<tuple<Integer,Integer>> equationSccMapping,equationSccMapping1;
BackendDAE.StrongComponents allComps;
algorithm
(allComps,_) := getSystemComponents(daeIn);
highestSccIdx := findHighestSccIdxInMapping(equationSccMappingIn,-1);
compCountPlusDummy := listLength(allComps)+1;
equationSccMapping1 := removeDummyStateFromMapping(equationSccMappingIn);
//the mapping can contain a dummy state as first scc
equationSccMapping := if intEq(highestSccIdx, compCountPlusDummy) then equationSccMapping1 else equationSccMappingIn;
sccSimEqMapping := convertToSccSimEqMapping(equationSccMapping, listLength(allComps));
simeqCompMapping := convertToSimeqCompMapping(equationSccMapping, lastEqMappingIdx);
//for the dae-system
daeSccSimEqMapping := listArray(List.map(SimCodeUtil.getRemovedEquationSimEqSysIdxes(simCodeIn),List.create));
daeSccSimEqMapping := arrayAppend(sccSimEqMapping,daeSccSimEqMapping);

//_ = getSimEqIdxSimEqMapping(simCode.allEquations, arrayLength(simeqCompMapping)); // CAN WE REMOVE IT????
//dumpSimEqSCCMapping(simeqCompMapping);
//dumpSccSimEqMapping(sccSimEqMapping);
//_ = getSimEqIdxSimEqMapping(simCode.allEquations, arrayLength(simeqCompMapping)); // CAN WE REMOVE IT????
//dumpSimEqSCCMapping(simeqCompMapping);
//dumpSccSimEqMapping(sccSimEqMapping);
end setUpHpcOmMapping;

protected function findHighestSccIdxInMapping "author: marcusw
Expand Down
72 changes: 36 additions & 36 deletions Compiler/BackEnd/SymbolicJacobian.mo
Expand Up @@ -2393,15 +2393,15 @@ algorithm
try // this might fail because of algorithms TODO: fix it!
(b1, _) := BackendEquation.traverseExpsOfEquationList_WithStop(inResidualEqns, traverserhasEqnNonDiffParts, ({}, true, false));
(b2, _) := BackendEquation.traverseExpsOfEquationList_WithStop(inOtherEqns, traverserhasEqnNonDiffParts, ({}, true, false));
if not (b1 and b2) then
if Flags.isSet(Flags.FAILTRACE) then
Debug.traceln("Skip symbolic jacobian for non-linear system " + name + "\n");
end if;
out := false;
else
out := true;
end if;
else
if not (b1 and b2) then
if Flags.isSet(Flags.FAILTRACE) then
Debug.traceln("Skip symbolic jacobian for non-linear system " + name + "\n");
end if;
out := false;
else
out := true;
end if;
else
out := false;
end try;
else
Expand All @@ -2424,39 +2424,39 @@ protected
BackendDAE.Variables diffVars, oVars, resVars;
BackendDAE.EquationArray resEqns, oEqns;
algorithm
try
// check non-linear flag
if not isLinear and not Flags.isSet(Flags.NLS_ANALYTIC_JACOBIAN) then
onlySparsePattern := true;
end if;
// generate jacobian name
if isLinear then
prename := "LS";
else
prename := "NLS";
end if;
name := prename + "Jac" + intString(System.tmpTickIndex(Global.backendDAE_jacobianSeq));

if debug then
print("*** "+ prename + "-JAC *** start creating Jacobian for a torn system " + name + " of size " + intString(listLength(inTearingSet.tearingvars)) + " time: " + realString(clock()) + "\n");
end if;

(diffVars, resVars, oVars, resEqns, oEqns) := prepareTornStrongComponentData(inVars, inEqns, inTearingSet.tearingvars, inTearingSet.residualequations, inTearingSet.innerEquations);

if debug then
print("*** "+ prename + "-JAC *** prepared all data for differentiation at time: " + realString(clock()) + "\n");
end if;
try
// check non-linear flag
if not isLinear and not Flags.isSet(Flags.NLS_ANALYTIC_JACOBIAN) then
onlySparsePattern := true;
end if;
// generate jacobian name
if isLinear then
prename := "LS";
else
prename := "NLS";
end if;
name := prename + "Jac" + intString(System.tmpTickIndex(Global.backendDAE_jacobianSeq));

if debug then
print("*** "+ prename + "-JAC *** start creating Jacobian for a torn system " + name + " of size " + intString(listLength(inTearingSet.tearingvars)) + " time: " + realString(clock()) + "\n");
end if;

(diffVars, resVars, oVars, resEqns, oEqns) := prepareTornStrongComponentData(inVars, inEqns, inTearingSet.tearingvars, inTearingSet.residualequations, inTearingSet.innerEquations);

if debug then
print("*** "+ prename + "-JAC *** prepared all data for differentiation at time: " + realString(clock()) + "\n");
end if;

//check if we are able to calc symbolic jacobian
if not (isLinear or checkForSymbolicJacobian(BackendEquation.equationList(resEqns), BackendEquation.equationList(oEqns), name)) then
onlySparsePattern := true;
end if;

// generate generic jacobian backend dae
// generate generic jacobian backend dae
(outJacobian, outShared) := getSymbolicJacobian(diffVars, resEqns, resVars, oEqns, oVars, inShared, inVars, name, onlySparsePattern);
else
fail();
end try;
else
fail();
end try;
end calculateTearingSetJacobian;

protected function calculateJacobianComponent
Expand Down Expand Up @@ -3424,7 +3424,7 @@ end traverserjacobianNonlinearExp;
protected function jacobianConstant "author: PA
Checks if Jacobian is constant, i.e. all expressions in each equation are constant."
input list<tuple<Integer, Integer, BackendDAE.Equation>> inTplIntegerIntegerEquationLst;
output Boolean outBoolean;
output Boolean outBoolean=true;
protected
DAE.Exp e1,e2, e;
tuple<Integer, Integer, BackendDAE.Equation> tpl;
Expand Down
4 changes: 2 additions & 2 deletions Compiler/FrontEnd/Inst.mo
Expand Up @@ -5479,8 +5479,8 @@ algorithm
/* adrpo: reuse it if is already there! */
try
ht := getGlobalRoot(Global.instHashIndex);
ht := BaseHashTable.clear(ht);
setGlobalRoot(Global.instHashIndex, ht);
ht := BaseHashTable.clear(ht);
setGlobalRoot(Global.instHashIndex, ht);
else
setGlobalRoot(Global.instHashIndex, emptyInstHashTable());
end try;
Expand Down
54 changes: 27 additions & 27 deletions Compiler/FrontEnd/InstStateMachineUtil.mo
Expand Up @@ -229,35 +229,35 @@ algorithm
(DAE.DAE(dAElist), _, _) := DAEUtil.traverseDAE(DAE.DAE(dAElist), emptyTree, traverserHelperSubsOuterByInnerExp, outerOutputCrefToInnerCref);

if Flags.getConfigBool(Flags.CT_STATE_MACHINES) then
// == HACK Let's deal with continuous-time ==
crefs := BaseHashTable.hashTableKeyList(outerOutputCrefToSMCompCref);
for cref in crefs loop
nOfHits := 0;
// traverse dae expressions and search for der(cref) occurances
(_, _, (_,(_, nOfHits))) := DAEUtil.traverseDAE(DAE.DAE(dAElist), emptyTree, Expression.traverseSubexpressionsHelper, (traversingCountDer, (cref, 0)));
if nOfHits > 0 then
derCrefsAcc := cref :: derCrefsAcc;
end if;
end for;
// == HACK Let's deal with continuous-time ==
crefs := BaseHashTable.hashTableKeyList(outerOutputCrefToSMCompCref);
for cref in crefs loop
nOfHits := 0;
// traverse dae expressions and search for der(cref) occurances
(_, _, (_,(_, nOfHits))) := DAEUtil.traverseDAE(DAE.DAE(dAElist), emptyTree, Expression.traverseSubexpressionsHelper, (traversingCountDer, (cref, 0)));
if nOfHits > 0 then
derCrefsAcc := cref :: derCrefsAcc;
end if;
end for;
// print("InstStateMachineUtil.mergeVariableDefinitions derCrefsAcc:\n" + stringDelimitList(List.map(derCrefsAcc, ComponentReference.crefStr), ", ") + "\n");
derCrefsSet := HashSet.emptyHashSetSized(listLength(derCrefsAcc));
derCrefsSet := List.fold(derCrefsAcc, BaseHashSet.add, derCrefsSet);
// Split the mapping from inner crefs to outer output crefs in a "continuous" part and the rest
for hashEntry in BaseHashTable.hashTableList(innerCrefToOuterOutputCrefs) loop
(_, outerOutputCrefs) := hashEntry;
hasDer := List.exist(outerOutputCrefs, function BaseHashSet.has(hashSet=derCrefsSet));
if hasDer then
innerCrefToOuterOutputCrefs_der := hashEntry :: innerCrefToOuterOutputCrefs_der;
else
innerCrefToOuterOutputCrefs_nonDer := hashEntry :: innerCrefToOuterOutputCrefs_nonDer;
end if;
end for;
// Create aliases between inner and outer of 'der' entries, e.g., a tuple (x -> {a.x, b.x}) will be transformed to alias equations {x = a.x, x = b.x}
aliasEqns_der := List.flatten( List.map(innerCrefToOuterOutputCrefs_der, freshAliasEqn_der) );
// Create merging equations for 'der' entries
mergeEqns_der := listAppend(List.map(innerCrefToOuterOutputCrefs_der, freshMergingEqn_der), aliasEqns_der);
derCrefsSet := HashSet.emptyHashSetSized(listLength(derCrefsAcc));
derCrefsSet := List.fold(derCrefsAcc, BaseHashSet.add, derCrefsSet);
// Split the mapping from inner crefs to outer output crefs in a "continuous" part and the rest
for hashEntry in BaseHashTable.hashTableList(innerCrefToOuterOutputCrefs) loop
(_, outerOutputCrefs) := hashEntry;
hasDer := List.exist(outerOutputCrefs, function BaseHashSet.has(hashSet=derCrefsSet));
if hasDer then
innerCrefToOuterOutputCrefs_der := hashEntry :: innerCrefToOuterOutputCrefs_der;
else
innerCrefToOuterOutputCrefs_nonDer := hashEntry :: innerCrefToOuterOutputCrefs_nonDer;
end if;
end for;
// Create aliases between inner and outer of 'der' entries, e.g., a tuple (x -> {a.x, b.x}) will be transformed to alias equations {x = a.x, x = b.x}
aliasEqns_der := List.flatten( List.map(innerCrefToOuterOutputCrefs_der, freshAliasEqn_der) );
// Create merging equations for 'der' entries
mergeEqns_der := listAppend(List.map(innerCrefToOuterOutputCrefs_der, freshMergingEqn_der), aliasEqns_der);
// Create merging equations for 'nonDer' entries
mergeEqns := listAppend(List.map(innerCrefToOuterOutputCrefs_nonDer, freshMergingEqn), mergeEqns_der);
mergeEqns := listAppend(List.map(innerCrefToOuterOutputCrefs_nonDer, freshMergingEqn), mergeEqns_der);
else
// FIXME add support for outers that don't have "inner outer" or "inner" at closest instance level (requires to introduce a fresh intermediate variable)
mergeEqns := List.map(BaseHashTable.hashTableList(innerCrefToOuterOutputCrefs), freshMergingEqn);
Expand Down
8 changes: 4 additions & 4 deletions Compiler/FrontEnd/Lookup.mo
Expand Up @@ -1746,10 +1746,10 @@ algorithm
equation
cr = lookupQualifiedImportedVarInFrame(qimports, id);
Util.setStatefulBoolean(inState,true);
// if the first name of the import A.B is equal with the scope we are in, skip it!
cr = if FNode.name(FNode.fromRef(FGraph.lastScopeRef(env))) == ComponentReference.crefFirstIdent(cr)
then ComponentReference.crefStripFirstIdent(cr)
else cr;
// if the first name of the import A.B is equal with the scope we are in, skip it!
cr = if FNode.name(FNode.fromRef(FGraph.lastScopeRef(env))) == ComponentReference.crefFirstIdent(cr)
then ComponentReference.crefStripFirstIdent(cr)
else cr;
f::prevFrames = listReverse(FGraph.currentScope(env));
env = FGraph.setScope(env, {f});
(cache,p_env,attr,ty,bind,cnstForRange,splicedExpData,componentEnv,name) = lookupVarInPackages(cache,env,cr,prevFrames,inState);
Expand Down
12 changes: 6 additions & 6 deletions Compiler/FrontEnd/UnitAbsynBuilder.mo
Expand Up @@ -1561,12 +1561,12 @@ protected
algorithm
for unitStr in inUnits loop
if boolNot(stringEq(baseUnitStr, unitStr)) then // skip same units
unit := str2unit(unitStr, NONE());
b := valueEq(baseUnit, unit);
if b then
outUnits := unitStr::outUnits;
end if;
end if;
unit := str2unit(unitStr, NONE());
b := valueEq(baseUnit, unit);
if b then
outUnits := unitStr::outUnits;
end if;
end if;
end for;
end getDerivedUnitsHelper;

Expand Down
2 changes: 1 addition & 1 deletion Compiler/Parsers/SimpleModelicaParser.mo
Expand Up @@ -2821,7 +2821,7 @@ end LA1;
function LAk "Do look-ahead k tokens and see if the tokens match one of the given ones."
extends partialParser;
input list<list<TokenId>> idsLst "k sets of tokens to check";
output Boolean found;
output Boolean found=true;
protected
TokenId id;
list<Token> tmp;
Expand Down

0 comments on commit e2c90ae

Please sign in to comment.