Skip to content
This repository was archived by the owner on May 18, 2019. It is now read-only.

Commit e2c90ae

Browse files
sjoelundOpenModelica-Hudson
authored andcommitted
Fixes from static error checker
1 parent 4fc6fb7 commit e2c90ae

File tree

17 files changed

+165
-156
lines changed

17 files changed

+165
-156
lines changed

Compiler/BackEnd/CommonSubExpression.mo

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1549,10 +1549,10 @@ algorithm
15491549
//print("partition "+stringDelimitList(List.map(partition, intString), ", ")+"\n");
15501550
//print("pathVarIdxMap "+stringDelimitList(List.map(List.map1(pathVarIdcs,Array.getIndexFirst,varMap), intString), ", ")+"\n");
15511551

1552-
//get only the partition equations
1553-
eqLst := BackendEquation.equationList(allEqs);
1554-
eqLst := List.map1(partition,List.getIndexFirst,eqLst);
1555-
eqs := BackendEquation.listEquation(eqLst);
1552+
//get only the partition equations
1553+
eqLst := BackendEquation.equationList(allEqs);
1554+
eqLst := List.map1(partition,List.getIndexFirst,eqLst);
1555+
eqs := BackendEquation.listEquation(eqLst);
15561556

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

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

18051805
then commonSubExpressionUpdate(rest, m, mT, syst);

Compiler/BackEnd/DumpHTML.mo

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -581,10 +581,10 @@ algorithm
581581

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

589589
// the functions to draw the matrix
590590
scripts := "
@@ -595,28 +595,28 @@ function drawRectangle(px, py, blockSize, margin, ctx) {
595595
function rowName(name, rowIdx, blockSize, margin, ctx) {
596596
ctx.strokeText(name, 0, 18+margin+(rowIdx-1)*blockSize, margin);
597597
return ctx;
598-
}\n
598+
}\n
599599
function colName(name, colIdx, blockSize, margin, ctx) {
600600
ctx.strokeText(name, 0, 18+margin+(colIdx-1)*blockSize, margin);
601601
return ctx;
602-
}\n
602+
}\n
603603
function makeLines(blockSize, margin, n, ctx) {
604-
for (var x = 0; x < n+1; ++x) {
605-
ctx.beginPath();
606-
ctx.moveTo( x*blockSize + margin, margin);
607-
ctx.lineTo( x*blockSize + margin, margin + (n)*blockSize);
608-
ctx.stroke();
609-
}\n
610-
611-
for (var x = 0; x < n+1; ++x) {
612-
ctx.beginPath();
613-
ctx.moveTo(margin, x*blockSize + margin);
614-
ctx.lineTo(margin + (n)*blockSize, x*blockSize + margin);
615-
ctx.stroke();
616-
}\n
617-
return ctx;
618-
}
619-
"::scripts;
604+
for (var x = 0; x < n+1; ++x) {
605+
ctx.beginPath();
606+
ctx.moveTo( x*blockSize + margin, margin);
607+
ctx.lineTo( x*blockSize + margin, margin + (n)*blockSize);
608+
ctx.stroke();
609+
}\n
610+
611+
for (var x = 0; x < n+1; ++x) {
612+
ctx.beginPath();
613+
ctx.moveTo(margin, x*blockSize + margin);
614+
ctx.lineTo(margin + (n)*blockSize, x*blockSize + margin);
615+
ctx.stroke();
616+
}\n
617+
return ctx;
618+
}
619+
"::scripts;
620620

621621
size := arrayLength(m);
622622

Compiler/BackEnd/HpcOmTaskGraph.mo

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6634,33 +6634,33 @@ end dumpPartitionData;
66346634

66356635
public function setUpHpcOmMapping "author: waurich 12-2015
66366636
Creates mappings between simcode and backendDAE for the hpcom module."
6637-
input BackendDAE.BackendDAE daeIn;
6638-
input SimCode.SimCode simCodeIn;
6639-
input Integer lastEqMappingIdx;
6640-
input list<tuple<Integer,Integer>> equationSccMappingIn; //Maps each simEq to the scc
6641-
output array<Integer> simeqCompMapping; //Maps each simEq to the scc
6642-
output array<list<Integer>> sccSimEqMapping; //Maps each scc to a list of simEqs
6643-
output array<list<Integer>> daeSccSimEqMapping; //Maps each scc to a list of simEqs, including removed equations like asserts
6644-
protected
6645-
Integer highestSccIdx, compCountPlusDummy;
6646-
list<tuple<Integer,Integer>> equationSccMapping,equationSccMapping1;
6647-
BackendDAE.StrongComponents allComps;
6648-
algorithm
6649-
(allComps,_) := getSystemComponents(daeIn);
6650-
highestSccIdx := findHighestSccIdxInMapping(equationSccMappingIn,-1);
6651-
compCountPlusDummy := listLength(allComps)+1;
6652-
equationSccMapping1 := removeDummyStateFromMapping(equationSccMappingIn);
6653-
//the mapping can contain a dummy state as first scc
6654-
equationSccMapping := if intEq(highestSccIdx, compCountPlusDummy) then equationSccMapping1 else equationSccMappingIn;
6655-
sccSimEqMapping := convertToSccSimEqMapping(equationSccMapping, listLength(allComps));
6656-
simeqCompMapping := convertToSimeqCompMapping(equationSccMapping, lastEqMappingIdx);
6657-
//for the dae-system
6658-
daeSccSimEqMapping := listArray(List.map(SimCodeUtil.getRemovedEquationSimEqSysIdxes(simCodeIn),List.create));
6637+
input BackendDAE.BackendDAE daeIn;
6638+
input SimCode.SimCode simCodeIn;
6639+
input Integer lastEqMappingIdx;
6640+
input list<tuple<Integer,Integer>> equationSccMappingIn; //Maps each simEq to the scc
6641+
output array<Integer> simeqCompMapping; //Maps each simEq to the scc
6642+
output array<list<Integer>> sccSimEqMapping; //Maps each scc to a list of simEqs
6643+
output array<list<Integer>> daeSccSimEqMapping; //Maps each scc to a list of simEqs, including removed equations like asserts
6644+
protected
6645+
Integer highestSccIdx, compCountPlusDummy;
6646+
list<tuple<Integer,Integer>> equationSccMapping,equationSccMapping1;
6647+
BackendDAE.StrongComponents allComps;
6648+
algorithm
6649+
(allComps,_) := getSystemComponents(daeIn);
6650+
highestSccIdx := findHighestSccIdxInMapping(equationSccMappingIn,-1);
6651+
compCountPlusDummy := listLength(allComps)+1;
6652+
equationSccMapping1 := removeDummyStateFromMapping(equationSccMappingIn);
6653+
//the mapping can contain a dummy state as first scc
6654+
equationSccMapping := if intEq(highestSccIdx, compCountPlusDummy) then equationSccMapping1 else equationSccMappingIn;
6655+
sccSimEqMapping := convertToSccSimEqMapping(equationSccMapping, listLength(allComps));
6656+
simeqCompMapping := convertToSimeqCompMapping(equationSccMapping, lastEqMappingIdx);
6657+
//for the dae-system
6658+
daeSccSimEqMapping := listArray(List.map(SimCodeUtil.getRemovedEquationSimEqSysIdxes(simCodeIn),List.create));
66596659
daeSccSimEqMapping := arrayAppend(sccSimEqMapping,daeSccSimEqMapping);
66606660

6661-
//_ = getSimEqIdxSimEqMapping(simCode.allEquations, arrayLength(simeqCompMapping)); // CAN WE REMOVE IT????
6662-
//dumpSimEqSCCMapping(simeqCompMapping);
6663-
//dumpSccSimEqMapping(sccSimEqMapping);
6661+
//_ = getSimEqIdxSimEqMapping(simCode.allEquations, arrayLength(simeqCompMapping)); // CAN WE REMOVE IT????
6662+
//dumpSimEqSCCMapping(simeqCompMapping);
6663+
//dumpSccSimEqMapping(sccSimEqMapping);
66646664
end setUpHpcOmMapping;
66656665

66666666
protected function findHighestSccIdxInMapping "author: marcusw

Compiler/BackEnd/SymbolicJacobian.mo

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2393,15 +2393,15 @@ algorithm
23932393
try // this might fail because of algorithms TODO: fix it!
23942394
(b1, _) := BackendEquation.traverseExpsOfEquationList_WithStop(inResidualEqns, traverserhasEqnNonDiffParts, ({}, true, false));
23952395
(b2, _) := BackendEquation.traverseExpsOfEquationList_WithStop(inOtherEqns, traverserhasEqnNonDiffParts, ({}, true, false));
2396-
if not (b1 and b2) then
2397-
if Flags.isSet(Flags.FAILTRACE) then
2398-
Debug.traceln("Skip symbolic jacobian for non-linear system " + name + "\n");
2399-
end if;
2400-
out := false;
2401-
else
2402-
out := true;
2403-
end if;
2404-
else
2396+
if not (b1 and b2) then
2397+
if Flags.isSet(Flags.FAILTRACE) then
2398+
Debug.traceln("Skip symbolic jacobian for non-linear system " + name + "\n");
2399+
end if;
2400+
out := false;
2401+
else
2402+
out := true;
2403+
end if;
2404+
else
24052405
out := false;
24062406
end try;
24072407
else
@@ -2424,39 +2424,39 @@ protected
24242424
BackendDAE.Variables diffVars, oVars, resVars;
24252425
BackendDAE.EquationArray resEqns, oEqns;
24262426
algorithm
2427-
try
2428-
// check non-linear flag
2429-
if not isLinear and not Flags.isSet(Flags.NLS_ANALYTIC_JACOBIAN) then
2430-
onlySparsePattern := true;
2431-
end if;
2432-
// generate jacobian name
2433-
if isLinear then
2434-
prename := "LS";
2435-
else
2436-
prename := "NLS";
2437-
end if;
2438-
name := prename + "Jac" + intString(System.tmpTickIndex(Global.backendDAE_jacobianSeq));
2439-
2440-
if debug then
2441-
print("*** "+ prename + "-JAC *** start creating Jacobian for a torn system " + name + " of size " + intString(listLength(inTearingSet.tearingvars)) + " time: " + realString(clock()) + "\n");
2442-
end if;
2443-
2444-
(diffVars, resVars, oVars, resEqns, oEqns) := prepareTornStrongComponentData(inVars, inEqns, inTearingSet.tearingvars, inTearingSet.residualequations, inTearingSet.innerEquations);
2445-
2446-
if debug then
2447-
print("*** "+ prename + "-JAC *** prepared all data for differentiation at time: " + realString(clock()) + "\n");
2448-
end if;
2427+
try
2428+
// check non-linear flag
2429+
if not isLinear and not Flags.isSet(Flags.NLS_ANALYTIC_JACOBIAN) then
2430+
onlySparsePattern := true;
2431+
end if;
2432+
// generate jacobian name
2433+
if isLinear then
2434+
prename := "LS";
2435+
else
2436+
prename := "NLS";
2437+
end if;
2438+
name := prename + "Jac" + intString(System.tmpTickIndex(Global.backendDAE_jacobianSeq));
2439+
2440+
if debug then
2441+
print("*** "+ prename + "-JAC *** start creating Jacobian for a torn system " + name + " of size " + intString(listLength(inTearingSet.tearingvars)) + " time: " + realString(clock()) + "\n");
2442+
end if;
2443+
2444+
(diffVars, resVars, oVars, resEqns, oEqns) := prepareTornStrongComponentData(inVars, inEqns, inTearingSet.tearingvars, inTearingSet.residualequations, inTearingSet.innerEquations);
2445+
2446+
if debug then
2447+
print("*** "+ prename + "-JAC *** prepared all data for differentiation at time: " + realString(clock()) + "\n");
2448+
end if;
24492449

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

2455-
// generate generic jacobian backend dae
2455+
// generate generic jacobian backend dae
24562456
(outJacobian, outShared) := getSymbolicJacobian(diffVars, resEqns, resVars, oEqns, oVars, inShared, inVars, name, onlySparsePattern);
2457-
else
2458-
fail();
2459-
end try;
2457+
else
2458+
fail();
2459+
end try;
24602460
end calculateTearingSetJacobian;
24612461

24622462
protected function calculateJacobianComponent
@@ -3424,7 +3424,7 @@ end traverserjacobianNonlinearExp;
34243424
protected function jacobianConstant "author: PA
34253425
Checks if Jacobian is constant, i.e. all expressions in each equation are constant."
34263426
input list<tuple<Integer, Integer, BackendDAE.Equation>> inTplIntegerIntegerEquationLst;
3427-
output Boolean outBoolean;
3427+
output Boolean outBoolean=true;
34283428
protected
34293429
DAE.Exp e1,e2, e;
34303430
tuple<Integer, Integer, BackendDAE.Equation> tpl;

Compiler/FrontEnd/Inst.mo

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5479,8 +5479,8 @@ algorithm
54795479
/* adrpo: reuse it if is already there! */
54805480
try
54815481
ht := getGlobalRoot(Global.instHashIndex);
5482-
ht := BaseHashTable.clear(ht);
5483-
setGlobalRoot(Global.instHashIndex, ht);
5482+
ht := BaseHashTable.clear(ht);
5483+
setGlobalRoot(Global.instHashIndex, ht);
54845484
else
54855485
setGlobalRoot(Global.instHashIndex, emptyInstHashTable());
54865486
end try;

Compiler/FrontEnd/InstStateMachineUtil.mo

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -229,35 +229,35 @@ algorithm
229229
(DAE.DAE(dAElist), _, _) := DAEUtil.traverseDAE(DAE.DAE(dAElist), emptyTree, traverserHelperSubsOuterByInnerExp, outerOutputCrefToInnerCref);
230230

231231
if Flags.getConfigBool(Flags.CT_STATE_MACHINES) then
232-
// == HACK Let's deal with continuous-time ==
233-
crefs := BaseHashTable.hashTableKeyList(outerOutputCrefToSMCompCref);
234-
for cref in crefs loop
235-
nOfHits := 0;
236-
// traverse dae expressions and search for der(cref) occurances
237-
(_, _, (_,(_, nOfHits))) := DAEUtil.traverseDAE(DAE.DAE(dAElist), emptyTree, Expression.traverseSubexpressionsHelper, (traversingCountDer, (cref, 0)));
238-
if nOfHits > 0 then
239-
derCrefsAcc := cref :: derCrefsAcc;
240-
end if;
241-
end for;
232+
// == HACK Let's deal with continuous-time ==
233+
crefs := BaseHashTable.hashTableKeyList(outerOutputCrefToSMCompCref);
234+
for cref in crefs loop
235+
nOfHits := 0;
236+
// traverse dae expressions and search for der(cref) occurances
237+
(_, _, (_,(_, nOfHits))) := DAEUtil.traverseDAE(DAE.DAE(dAElist), emptyTree, Expression.traverseSubexpressionsHelper, (traversingCountDer, (cref, 0)));
238+
if nOfHits > 0 then
239+
derCrefsAcc := cref :: derCrefsAcc;
240+
end if;
241+
end for;
242242
// print("InstStateMachineUtil.mergeVariableDefinitions derCrefsAcc:\n" + stringDelimitList(List.map(derCrefsAcc, ComponentReference.crefStr), ", ") + "\n");
243-
derCrefsSet := HashSet.emptyHashSetSized(listLength(derCrefsAcc));
244-
derCrefsSet := List.fold(derCrefsAcc, BaseHashSet.add, derCrefsSet);
245-
// Split the mapping from inner crefs to outer output crefs in a "continuous" part and the rest
246-
for hashEntry in BaseHashTable.hashTableList(innerCrefToOuterOutputCrefs) loop
247-
(_, outerOutputCrefs) := hashEntry;
248-
hasDer := List.exist(outerOutputCrefs, function BaseHashSet.has(hashSet=derCrefsSet));
249-
if hasDer then
250-
innerCrefToOuterOutputCrefs_der := hashEntry :: innerCrefToOuterOutputCrefs_der;
251-
else
252-
innerCrefToOuterOutputCrefs_nonDer := hashEntry :: innerCrefToOuterOutputCrefs_nonDer;
253-
end if;
254-
end for;
255-
// 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}
256-
aliasEqns_der := List.flatten( List.map(innerCrefToOuterOutputCrefs_der, freshAliasEqn_der) );
257-
// Create merging equations for 'der' entries
258-
mergeEqns_der := listAppend(List.map(innerCrefToOuterOutputCrefs_der, freshMergingEqn_der), aliasEqns_der);
243+
derCrefsSet := HashSet.emptyHashSetSized(listLength(derCrefsAcc));
244+
derCrefsSet := List.fold(derCrefsAcc, BaseHashSet.add, derCrefsSet);
245+
// Split the mapping from inner crefs to outer output crefs in a "continuous" part and the rest
246+
for hashEntry in BaseHashTable.hashTableList(innerCrefToOuterOutputCrefs) loop
247+
(_, outerOutputCrefs) := hashEntry;
248+
hasDer := List.exist(outerOutputCrefs, function BaseHashSet.has(hashSet=derCrefsSet));
249+
if hasDer then
250+
innerCrefToOuterOutputCrefs_der := hashEntry :: innerCrefToOuterOutputCrefs_der;
251+
else
252+
innerCrefToOuterOutputCrefs_nonDer := hashEntry :: innerCrefToOuterOutputCrefs_nonDer;
253+
end if;
254+
end for;
255+
// 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}
256+
aliasEqns_der := List.flatten( List.map(innerCrefToOuterOutputCrefs_der, freshAliasEqn_der) );
257+
// Create merging equations for 'der' entries
258+
mergeEqns_der := listAppend(List.map(innerCrefToOuterOutputCrefs_der, freshMergingEqn_der), aliasEqns_der);
259259
// Create merging equations for 'nonDer' entries
260-
mergeEqns := listAppend(List.map(innerCrefToOuterOutputCrefs_nonDer, freshMergingEqn), mergeEqns_der);
260+
mergeEqns := listAppend(List.map(innerCrefToOuterOutputCrefs_nonDer, freshMergingEqn), mergeEqns_der);
261261
else
262262
// FIXME add support for outers that don't have "inner outer" or "inner" at closest instance level (requires to introduce a fresh intermediate variable)
263263
mergeEqns := List.map(BaseHashTable.hashTableList(innerCrefToOuterOutputCrefs), freshMergingEqn);

Compiler/FrontEnd/Lookup.mo

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1746,10 +1746,10 @@ algorithm
17461746
equation
17471747
cr = lookupQualifiedImportedVarInFrame(qimports, id);
17481748
Util.setStatefulBoolean(inState,true);
1749-
// if the first name of the import A.B is equal with the scope we are in, skip it!
1750-
cr = if FNode.name(FNode.fromRef(FGraph.lastScopeRef(env))) == ComponentReference.crefFirstIdent(cr)
1751-
then ComponentReference.crefStripFirstIdent(cr)
1752-
else cr;
1749+
// if the first name of the import A.B is equal with the scope we are in, skip it!
1750+
cr = if FNode.name(FNode.fromRef(FGraph.lastScopeRef(env))) == ComponentReference.crefFirstIdent(cr)
1751+
then ComponentReference.crefStripFirstIdent(cr)
1752+
else cr;
17531753
f::prevFrames = listReverse(FGraph.currentScope(env));
17541754
env = FGraph.setScope(env, {f});
17551755
(cache,p_env,attr,ty,bind,cnstForRange,splicedExpData,componentEnv,name) = lookupVarInPackages(cache,env,cr,prevFrames,inState);

Compiler/FrontEnd/UnitAbsynBuilder.mo

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1561,12 +1561,12 @@ protected
15611561
algorithm
15621562
for unitStr in inUnits loop
15631563
if boolNot(stringEq(baseUnitStr, unitStr)) then // skip same units
1564-
unit := str2unit(unitStr, NONE());
1565-
b := valueEq(baseUnit, unit);
1566-
if b then
1567-
outUnits := unitStr::outUnits;
1568-
end if;
1569-
end if;
1564+
unit := str2unit(unitStr, NONE());
1565+
b := valueEq(baseUnit, unit);
1566+
if b then
1567+
outUnits := unitStr::outUnits;
1568+
end if;
1569+
end if;
15701570
end for;
15711571
end getDerivedUnitsHelper;
15721572

Compiler/Parsers/SimpleModelicaParser.mo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2821,7 +2821,7 @@ end LA1;
28212821
function LAk "Do look-ahead k tokens and see if the tokens match one of the given ones."
28222822
extends partialParser;
28232823
input list<list<TokenId>> idsLst "k sets of tokens to check";
2824-
output Boolean found;
2824+
output Boolean found=true;
28252825
protected
28262826
TokenId id;
28272827
list<Token> tmp;

0 commit comments

Comments
 (0)