From b0c8f3e6c149f4488037ea83192fdabe1754f787 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Sj=C3=B6lund?= Date: Thu, 3 Apr 2014 08:52:58 +0000 Subject: [PATCH] Removing dead statements with the script git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@19956 f25d12d1-65f4-0310-ae8a-bbce733d8d8e --- Compiler/BackEnd/BackendDAEOptimize.mo | 1 - Compiler/BackEnd/BackendQSS.mo | 3 -- Compiler/BackEnd/EvaluateFunctions.mo | 1 - Compiler/BackEnd/FindZeroCrossings.mo | 1 - Compiler/BackEnd/HpcOmEqSystems.mo | 1 - Compiler/BackEnd/HpcOmSimCode.mo | 1 - Compiler/BackEnd/HpcOmTaskGraph.mo | 6 --- Compiler/BackEnd/OnRelaxation.mo | 1 - Compiler/BackEnd/SimCodeUtil.mo | 1 - Compiler/BackEnd/Tearing.mo | 2 - Compiler/BackEnd/Uncertainties.mo | 2 - Compiler/FrontEnd/ExpressionSimplify.mo | 1 - Compiler/FrontEnd/InnerOuter.mo | 2 - Compiler/FrontEnd/Inst.mo | 1 - Compiler/FrontEnd/InstExtends.mo | 1 - Compiler/FrontEnd/Lookup.mo | 1 - Compiler/FrontEnd/Patternm.mo | 12 ++++- Compiler/FrontEnd/Static.mo | 1 - Compiler/FrontEnd/Types.mo | 2 - Compiler/Main/Main.mo | 2 - Compiler/Script/CevalScript.mo | 1 - Compiler/Script/Interactive.mo | 2 - Compiler/Template/TplAbsyn.mo | 1 - Compiler/Util/BaseHashSet.mo | 2 - Compiler/Util/Error.mo | 4 +- Compiler/boot/refactor-fix-notifications.py | 51 ++++++++++++++++----- 26 files changed, 53 insertions(+), 51 deletions(-) diff --git a/Compiler/BackEnd/BackendDAEOptimize.mo b/Compiler/BackEnd/BackendDAEOptimize.mo index 7619c3ff1d6..945d31c8ea2 100644 --- a/Compiler/BackEnd/BackendDAEOptimize.mo +++ b/Compiler/BackEnd/BackendDAEOptimize.mo @@ -4907,7 +4907,6 @@ algorithm tmpEqns = BackendEquation.listEquation(eqnlst); (explst,_) = BackendDAEUtil.getEqnSysRhs(tmpEqns,BackendVariable.listVar1(varlst),SOME(funcs)); ((_,tpl)) = Expression.traverseExpList(explst,countOperationsExp,tpl); - (i1,i2,i3,i4) = tpl; then countOperationstraverseComps(rest,isyst,ishared,tpl); case ((comp as BackendDAE.TORNSYSTEM(tearingvars=vlst, otherEqnVarTpl=eqnvartpllst, linear=false))::rest,_,BackendDAE.SHARED(functionTree=funcs),_) diff --git a/Compiler/BackEnd/BackendQSS.mo b/Compiler/BackEnd/BackendQSS.mo index f14f451a22b..1c0240993b5 100644 --- a/Compiler/BackEnd/BackendQSS.mo +++ b/Compiler/BackEnd/BackendQSS.mo @@ -461,9 +461,6 @@ algorithm then stringAppend(stringAppend("x[",intString(p+1)),"]"); case (DAE.CREF_QUAL(ident,identType,subscriptLst,r),_,_,_) equation - ident=DAE.derivativeNamePrefix; - identType=DAE.T_REAL_DEFAULT; - subscriptLst={}; p = List.positionOnTrue(r,states,ComponentReference.crefEqual); then stringAppend(stringAppend("der(x[",intString(p+1)),"])"); case (_,_,_,_) diff --git a/Compiler/BackEnd/EvaluateFunctions.mo b/Compiler/BackEnd/EvaluateFunctions.mo index 0ef9bcf8ea7..b13e93d9dce 100644 --- a/Compiler/BackEnd/EvaluateFunctions.mo +++ b/Compiler/BackEnd/EvaluateFunctions.mo @@ -186,7 +186,6 @@ algorithm (eq,(shared,addEqs,idx+1)); else equation - (shared,addEqs,idx) = tplIn; then (eqIn,tplIn); end matchcontinue; diff --git a/Compiler/BackEnd/FindZeroCrossings.mo b/Compiler/BackEnd/FindZeroCrossings.mo index 6c8f30432dd..ff862f5e3ad 100644 --- a/Compiler/BackEnd/FindZeroCrossings.mo +++ b/Compiler/BackEnd/FindZeroCrossings.mo @@ -306,7 +306,6 @@ algorithm case (v, _, ((e as BackendDAE.SOLVED_EQUATION(componentRef = cref, exp = e1, source= source_, differentiated=diffed))::xs), eq_count, {}, _, countRelations, countMathFunctions, zcs, relationsLst, sampleLst, eqnsAccum, whenClauseAccum) equation - eq_count_1 = eq_count + 1; (eres1, countRelations, countMathFunctions, res, relationsLst, sampleLst) = findZeroCrossings3(e1, zcs, relationsLst, sampleLst, countRelations, countMathFunctions, eq_count, -1, v, knvars); eqnsAccum = listAppend({BackendDAE.SOLVED_EQUATION(cref, eres1, source_, diffed)}, eqnsAccum); (res1, eq_reslst, wc_reslst, countRelations, countMathFunctions, relationsLst, sampleLst) = findZeroCrossings2(v, knvars, xs, eq_count, {}, 0, countRelations, countMathFunctions, res, relationsLst, sampleLst, eqnsAccum, whenClauseAccum); diff --git a/Compiler/BackEnd/HpcOmEqSystems.mo b/Compiler/BackEnd/HpcOmEqSystems.mo index 07a95846092..d25972e55e7 100644 --- a/Compiler/BackEnd/HpcOmEqSystems.mo +++ b/Compiler/BackEnd/HpcOmEqSystems.mo @@ -755,7 +755,6 @@ algorithm mapIncRowEqn = listArray(List.intRange(nEqs)); mapEqnIncRow = Util.arrayMap(mapIncRowEqn,List.create); (sysTmp,compsTmp) = BackendDAETransform.strongComponentsScalar(sysTmp,shared,mapEqnIncRow,mapIncRowEqn); - sysTmp = BackendDAE.EQSYSTEM(vars,eqArr,SOME(m),SOME(mt),matching,{}); compsTmp = listAppend(compsIn,compsTmp); matchingTmp = BackendDAE.MATCHING(ass1, ass2, compsTmp); then diff --git a/Compiler/BackEnd/HpcOmSimCode.mo b/Compiler/BackEnd/HpcOmSimCode.mo index cc316008c36..13e41d81043 100644 --- a/Compiler/BackEnd/HpcOmSimCode.mo +++ b/Compiler/BackEnd/HpcOmSimCode.mo @@ -173,7 +173,6 @@ algorithm Real graphCosts; Integer graphOps; case (BackendDAE.DAE(eqs=eqs), _, _, _, _, _, _, _, _, _, _, _) equation - uniqueEqIndex = 1; //Setup //----- diff --git a/Compiler/BackEnd/HpcOmTaskGraph.mo b/Compiler/BackEnd/HpcOmTaskGraph.mo index 197caf110c5..cd66026896a 100644 --- a/Compiler/BackEnd/HpcOmTaskGraph.mo +++ b/Compiler/BackEnd/HpcOmTaskGraph.mo @@ -683,7 +683,6 @@ algorithm eqDescLst = stringListStringChar(eqString); eqDescLst = List.map(eqDescLst,prepareXML); eqString = stringCharListString(eqDescLst); - descLst = eqString::iEqDesc; //get the variable string varLst = BackendVariable.varList(orderedVars); //var = listGet(varLst,arrayGet(ass2,i)); @@ -702,7 +701,6 @@ algorithm eqDescLst = stringListStringChar(eqString); eqDescLst = List.map(eqDescLst,prepareXML); eqString = stringCharListString(eqDescLst); - descLst = eqString::iEqDesc; //get the variable string varLst = BackendVariable.varList(orderedVars); //var = listGet(varLst,arrayGet(ass2,i)); @@ -739,7 +737,6 @@ algorithm eqDescLst = stringListStringChar(eqString); eqDescLst = List.map(eqDescLst,prepareXML); eqString = stringCharListString(eqDescLst); - descLst = eqString::iEqDesc; //get the variable string varLst = BackendVariable.varList(orderedVars); //var = listGet(varLst,arrayGet(ass2,i)); @@ -4723,7 +4720,6 @@ algorithm costValue2 = costValueParent +. costValue2; costValue2 = realMax(costValue1,costValue2); levelValue2 = intMax(levelValueParent+1,levelValue1); - parentCount2 = parentCount1-1; rootInfo = (levelValue2,costValue2,parentCount1); nodeInfoTmp = arrayUpdate(nodeInfoIn,rootNode,rootInfo); childNodes = arrayGet(graphIn,rootNode); @@ -4750,7 +4746,6 @@ algorithm costValue2 = costValueParent +. costValue2; costValue2 = realMax(costValue1,costValue2); levelValue2 = intMax(levelValueParent+1,levelValue1); - parentCount2 = parentCount1-1; rootInfo = (levelValue2,costValue2,parentCount1-1); nodeInfoTmp = arrayUpdate(nodeInfoIn,rootNode,rootInfo); childNodes = arrayGet(graphIn,rootNode); @@ -4761,7 +4756,6 @@ algorithm foldTmp; else equation - (childNodesIn,nodeInfoIn) = foldIn; (rootNodes,rootParents) = rootNodeInfo; rootNode = listGet(rootNodes,rootIdx); rootParent = listGet(rootParents,rootIdx); diff --git a/Compiler/BackEnd/OnRelaxation.mo b/Compiler/BackEnd/OnRelaxation.mo index 6a408293f29..d5f01f3cfca 100644 --- a/Compiler/BackEnd/OnRelaxation.mo +++ b/Compiler/BackEnd/OnRelaxation.mo @@ -2901,7 +2901,6 @@ algorithm case (c::rest,_,_,_,_,_,_,_,_,_,_,_,_) equation r = ass2[c]; - b = queuemark[c]; // print("Process Colum " +& intString(c) +& " Rows " +& stringDelimitList(List.map(r,intString),", ") +& " " +& boolString(b) +&"\n"); (colums1,b2) = getIndexQueque1(r,c,mT,mark,rowmarks,{},false); // BackendDump.debuglst((colums1,intString,", ","\n")); diff --git a/Compiler/BackEnd/SimCodeUtil.mo b/Compiler/BackEnd/SimCodeUtil.mo index 14ad26da1f1..ccbb99eee4c 100644 --- a/Compiler/BackEnd/SimCodeUtil.mo +++ b/Compiler/BackEnd/SimCodeUtil.mo @@ -10056,7 +10056,6 @@ algorithm equation (_, indx) = get1(key, hashTable); // print("adding when present, indx =" );print(intString(indx));print("\n"); - indx_1 = indx - 1; varr_1 = valueArraySetnth(varr, indx, newv); then SimCode.HASHTABLE(hashvec, varr_1, bsize, n); case (_, _) diff --git a/Compiler/BackEnd/Tearing.mo b/Compiler/BackEnd/Tearing.mo index 178c4fd4208..10f6df2eed6 100644 --- a/Compiler/BackEnd/Tearing.mo +++ b/Compiler/BackEnd/Tearing.mo @@ -3590,7 +3590,6 @@ algorithm equation true = List.isNotEmpty(currLoop); true = indxCol == listLength(arrayGet(aIn,indxRow)); - parent = indxRow; child = listGet(arrayGet(aIn,indxRow),indxCol); currLoop = child::currLoop; print("append loop and jump to next vertex "+&stringDelimitList(List.map(currLoop,intString),",")+&"\n"); @@ -3600,7 +3599,6 @@ algorithm equation true = indxCol < listLength(arrayGet(aIn,indxRow)); print("now we have more loops\n"); - parent = indxRow; row = arrayGet(aIn,indxRow); unfinLoops = traceMooreLoops(unfinLoops,currLoop,row,2); child = listGet(arrayGet(aIn,indxRow),indxCol); diff --git a/Compiler/BackEnd/Uncertainties.mo b/Compiler/BackEnd/Uncertainties.mo index 651ae02f2b1..835a2c672a2 100644 --- a/Compiler/BackEnd/Uncertainties.mo +++ b/Compiler/BackEnd/Uncertainties.mo @@ -2697,7 +2697,6 @@ algorithm case(-1,DAE.CREF(_,_)) equation tp=Expression.typeof(eIn); - e=DAE.UNARY(DAE.UMINUS(tp),eIn); then eIn; case(1,DAE.CREF(_,_)) then eIn; @@ -2877,7 +2876,6 @@ algorithm case (_,_,_,e1 as DAE.CREF(componentRef = cr1),e2 as DAE.CREF(componentRef = cr2)) equation source=getSourceIfApproximated(eqn); - tp = DAE.T_REAL_DEFAULT; //Assume is real new_sets=pushToSetList(sets,cr1,e1,1,cr2,e2,1,source); then (new_sets,eqn_acc); // a = -b; diff --git a/Compiler/FrontEnd/ExpressionSimplify.mo b/Compiler/FrontEnd/ExpressionSimplify.mo index 57871b684f7..ccf41c42f11 100644 --- a/Compiler/FrontEnd/ExpressionSimplify.mo +++ b/Compiler/FrontEnd/ExpressionSimplify.mo @@ -2881,7 +2881,6 @@ algorithm case (DAE.BINARY(exp1 = e1,operator = DAE.POW(ty = _),exp2 = DAE.UNARY(operator = DAE.UMINUS(ty = tp),exp = DAE.ICONST(integer = icoeff)))) equation coeff_1 = intReal(icoeff); - coeff_2 = 0.0 -. coeff_1; then (e1,coeff_1); diff --git a/Compiler/FrontEnd/InnerOuter.mo b/Compiler/FrontEnd/InnerOuter.mo index b6172f2048f..b73c193a61e 100644 --- a/Compiler/FrontEnd/InnerOuter.mo +++ b/Compiler/FrontEnd/InnerOuter.mo @@ -1939,7 +1939,6 @@ algorithm equation (_,indx) = get1(key, hashTable); //print("adding when present, indx =" );print(intString(indx));print("\n"); - indx_1 = indx - 1; varr_1 = valueArraySetnth(varr, indx, newv); // print("Updated NEW to IH: key:" +& ComponentReference.printComponentRefStr(key) +& " value: " +& printInnerDefStr(value) +& "\n"); then HASHTABLE(hashvec,varr_1,bsize,n); @@ -2010,7 +2009,6 @@ algorithm case (_,HASHTABLE(hashvec,varr,bsize,n)) equation (_,indx) = get1(key, hashTable); - indx_1 = indx - 1; varr_1 = valueArrayClearnth(varr, indx); then HASHTABLE(hashvec,varr_1,bsize,n); else diff --git a/Compiler/FrontEnd/Inst.mo b/Compiler/FrontEnd/Inst.mo index 8f5588c82d8..a7c35c13b21 100644 --- a/Compiler/FrontEnd/Inst.mo +++ b/Compiler/FrontEnd/Inst.mo @@ -1883,7 +1883,6 @@ algorithm equation false = numIter < Global.recursionDepthLimit; n = Env.printEnvPathStr(env); - strDepth = intString(Global.recursionDepthLimit); // print("partialInstClassIn recursion depth... " +& n +& "\n"); Error.addSourceMessage(Error.RECURSION_DEPTH_REACHED,{n},SCode.elementInfo(c)); then fail(); diff --git a/Compiler/FrontEnd/InstExtends.mo b/Compiler/FrontEnd/InstExtends.mo index 71f9d4f3680..c9c35062e55 100644 --- a/Compiler/FrontEnd/InstExtends.mo +++ b/Compiler/FrontEnd/InstExtends.mo @@ -695,7 +695,6 @@ algorithm equation str1 = SCodeDump.unparseElementStr(inClass,SCodeDump.defaultOptions); str2 = Env.printEnvPathStr(inEnv); - strDepth = intString(Global.recursionDepthLimit); // print("instDerivedClassesWork recursion depth... " +& str1 +& " " +& str2 +& "\n"); Error.addSourceMessage(Error.RECURSION_DEPTH_DERIVED,{str1,str2},inInfo); then fail(); diff --git a/Compiler/FrontEnd/Lookup.mo b/Compiler/FrontEnd/Lookup.mo index 1680fe3f04b..253d2326db9 100644 --- a/Compiler/FrontEnd/Lookup.mo +++ b/Compiler/FrontEnd/Lookup.mo @@ -2594,7 +2594,6 @@ algorithm case(expl,dims) equation str2 = intString(dims); - exp = DAE.ARRAY(DAE.T_INTEGER_DEFAULT,false,expl); str1 = stringDelimitList(List.map(expl,ExpressionDump.printExpStr)," and position " ); Error.addMessage(Error.ARRAY_INDEX_OUT_OF_BOUNDS,{str1,str2}); then diff --git a/Compiler/FrontEnd/Patternm.mo b/Compiler/FrontEnd/Patternm.mo index 427e44785ed..37c188a8b68 100644 --- a/Compiler/FrontEnd/Patternm.mo +++ b/Compiler/FrontEnd/Patternm.mo @@ -1089,7 +1089,7 @@ algorithm // TODO: Can skip matchcontinue and failure if there was an AvlTree.exists(key) _ = AvlTreeString.avlTreeGet(localsTree,name); failure(_ = AvlTreeString.avlTreeGet(useTree,name)); - Error.assertionOrAddSourceMessage(not Flags.isSet(Flags.PATTERNM_ALL_INFO),Error.META_UNUSED_AS_BINDING,{name},info); + Error.assertionOrAddSourceMessage(not Flags.isSet(Flags.PATTERNM_ALL_INFO),Error.META_UNUSED_ASSIGNMENT,{name},info); then ((DAE.CREF(DAE.WILD(),ty),extra)); case ((DAE.PATTERN(pattern=pat),extra)) equation @@ -2590,7 +2590,7 @@ protected function statementListFindDeadStoreRemoveEmptyStatements output AvlTreeString.AvlTree useTree; algorithm (body,useTree) := List.map1Fold(listReverse(inBody),statementFindDeadStore,localsTree,inUseTree); - body := List.select(body,Algorithm.isNotDummyStatement); + body := List.select(body,isNotDummyStatement); body := listReverse(body); end statementListFindDeadStoreRemoveEmptyStatements; @@ -2731,4 +2731,12 @@ algorithm end match; end elseFindDeadStore; +protected function isNotDummyStatement + input DAE.Statement statement; + output Boolean b; +algorithm + b := Algorithm.isNotDummyStatement(statement); + Error.assertionOrAddSourceMessage(b or not Flags.isSet(Flags.PATTERNM_ALL_INFO),Error.META_DEAD_CODE,{"Statement optimised away"},DAEUtil.getElementSourceFileInfo(Algorithm.getStatementSource(statement))); +end isNotDummyStatement; + end Patternm; diff --git a/Compiler/FrontEnd/Static.mo b/Compiler/FrontEnd/Static.mo index 2b5726f8012..fc1c1d22de5 100644 --- a/Compiler/FrontEnd/Static.mo +++ b/Compiler/FrontEnd/Static.mo @@ -7500,7 +7500,6 @@ algorithm case (cache,env,fn,args,nargs,impl,_,st,pre,_) equation - t4 = args; failure((_,_,_) = Lookup.lookupType(cache,env, fn, NONE())) "msg" ; scope = Env.printEnvPathStr(env) +& " (looking for a function or record)"; fn_str = Absyn.pathString(fn); diff --git a/Compiler/FrontEnd/Types.mo b/Compiler/FrontEnd/Types.mo index ae2c21f77ae..313b7c76a78 100644 --- a/Compiler/FrontEnd/Types.mo +++ b/Compiler/FrontEnd/Types.mo @@ -4389,7 +4389,6 @@ algorithm ty2 = arrayElementType(ty2); ety1 = simplifyType(ty2); ty2 = liftArrayListDims(ty2, dims); - exp = DAE.ARRAY(DAE.T_ARRAY(ety1, dims, DAE.emptyTypeSource), sc, elist_1); //TODO: Verify correctness of return value. then (DAE.ARRAY(DAE.T_ARRAY(ety1, dims, DAE.emptyTypeSource),sc,elist_1), ty2); @@ -4588,7 +4587,6 @@ algorithm case (DAE.TUPLE(elist),DAE.T_TUPLE(tupleType = tys1),ty2 as DAE.T_METABOXED(ty = DAE.T_UNKNOWN(source =_), source = ts2),_) equation true = Config.acceptMetaModelicaGrammar(); - e_1 = DAE.META_TUPLE(elist); tys2 = List.fill(ty2, listLength(tys1)); (elist_1,tys_1) = matchTypeTuple(elist, tys1, tys2, printFailtrace); then diff --git a/Compiler/Main/Main.mo b/Compiler/Main/Main.mo index 79e1f36c7af..950a3a1c2a4 100644 --- a/Compiler/Main/Main.mo +++ b/Compiler/Main/Main.mo @@ -255,7 +255,6 @@ algorithm else equation true = Util.isSome(inStatements) or Util.isSome(inProgram); - _ = setStackOverflowSignal(false); Error.addMessage(Error.STACK_OVERFLOW, {inCommand}); then ("", inSymbolTable); @@ -1160,7 +1159,6 @@ algorithm print(" Most OpenModelica release distributions have scripts that set OPENMODELICAHOME for you.\n\n"); // Functions used by external code that needs to be included for linking - _ = Absyn.isDerCref; then fail(); end matchcontinue; end main2; diff --git a/Compiler/Script/CevalScript.mo b/Compiler/Script/CevalScript.mo index a85f5226c3f..234d89825b1 100644 --- a/Compiler/Script/CevalScript.mo +++ b/Compiler/Script/CevalScript.mo @@ -4942,7 +4942,6 @@ algorithm Debug.fprintln(Flags.DYN_LOAD, "buildModel: Compiling done."); // SimCodegen.generateMakefileBeast(makefilename, filenameprefix, libs, file_dir); win1 = getWithinStatement(classname); - p2 = Absyn.PROGRAM({cdef},win1,ts); compileModel(filenameprefix, libs, file_dir,method_str); // (p as Absyn.PROGRAM(globalBuildTimes=Absyn.TIMESTAMP(r1,r2))) = Interactive.updateProgram2(p2,p,false); st2 = st; // Interactive.replaceSymbolTableProgram(st,p); diff --git a/Compiler/Script/Interactive.mo b/Compiler/Script/Interactive.mo index c2de30cf108..e22a5aab201 100644 --- a/Compiler/Script/Interactive.mo +++ b/Compiler/Script/Interactive.mo @@ -1352,7 +1352,6 @@ algorithm Absyn.CLASS(name,false,false,false,Absyn.R_MODEL(),Absyn.dummyParts,Absyn.dummyInfo) }, Absyn.WITHIN(path_1),Absyn.dummyTimeStamp), p); newst = setSymbolTableAST(st, newp); - resstr = stringAppend(name, "\n"); then ("true",newst); @@ -10146,7 +10145,6 @@ algorithm newp; case ((model_ as Absyn.CREF_IDENT(name = _)),nargs,p as Absyn.PROGRAM(globalBuildTimes=ts)) equation - exp = Absyn.CALL(model_,Absyn.FUNCTIONARGS({},nargs)); modelpath = Absyn.crefToPath(model_) "Class on top level" ; cdef = getPathedClassInProgram(modelpath, p); cdef_1 = addClassAnnotationToClass(cdef, nargs); diff --git a/Compiler/Template/TplAbsyn.mo b/Compiler/Template/TplAbsyn.mo index 1b69eadf882..6a62f2a0b04 100644 --- a/Compiler/Template/TplAbsyn.mo +++ b/Compiler/Template/TplAbsyn.mo @@ -3811,7 +3811,6 @@ algorithm case ( (ident, mexp) :: fms, _, _, usedLocals, astDefs) equation failure( _ = lookupTupleList(fields, ident) ); - reason = "#Error - unresolved type - cannot find field '" +& ident +& "'#"; //locals = addLocalValue(ident, UNRESOLVED_TYPE(reason), locals); Debug.fprint(Flags.FAILTRACE, "Error - rewriteMatchExpByLocalNamesRecord failed to find field '" +& ident +& "'\n"); (fms, usedLocals) = rewriteMatchExpByLocalNamesRecord(fms, fields, inLocalNames, usedLocals, astDefs); diff --git a/Compiler/Util/BaseHashSet.mo b/Compiler/Util/BaseHashSet.mo index cc73602291f..4efe44e97cf 100644 --- a/Compiler/Util/BaseHashSet.mo +++ b/Compiler/Util/BaseHashSet.mo @@ -152,7 +152,6 @@ algorithm equation (_,indx) = get1(key, hashSet); //print("adding when present, indx =" );print(intString(indx));print("\n"); - indx_1 = indx - 1; varr_1 = valueArraySetnth(varr, indx, key); then ((hashvec,varr_1,bsize,n,fntpl)); @@ -264,7 +263,6 @@ algorithm case (_,(hashvec,varr,bsize,n,fntpl)) equation (_,indx) = get1(key, hashSet); - indx_1 = indx - 1; varr_1 = valueArrayClearnth(varr, indx); then ((hashvec,varr_1,bsize,n,fntpl)); case (_,_) diff --git a/Compiler/Util/Error.mo b/Compiler/Util/Error.mo index f033656c0a8..295862e9927 100644 --- a/Compiler/Util/Error.mo +++ b/Compiler/Util/Error.mo @@ -646,7 +646,6 @@ public constant Message GENERATE_SEPARATE_CODE_DEPENDENCIES_FAILED = MESSAGE(242 public constant Message CYCLIC_DEFAULT_VALUE = MESSAGE(243, SCRIPTING(), ERROR(), Util.gettext("The default value of %s causes a cyclic dependency.")); - public constant Message UNBOUND_PARAMETER_WITH_START_VALUE_WARNING = MESSAGE(499, TRANSLATION(), WARNING(), Util.gettext("Parameter %s has no value, and is fixed during initialization (fixed=true), using available start value (start=%s) as default value.")); public constant Message UNBOUND_PARAMETER_WARNING = MESSAGE(500, TRANSLATION(), WARNING(), @@ -786,6 +785,9 @@ public constant Message FOUND_NON_NUMERIC_TYPES = MESSAGE(5032, TRANSLATION(), E Util.gettext("Operator %s expects numeric types as operands, but got '%s and %s'.")); public constant Message STRUCTURAL_PARAMETER_OR_CONSTANT_WITH_NO_BINDING = MESSAGE(5033, TRANSLATION(), ERROR(), Util.gettext("Could not evaluate structural parameter (or constant): %s which gives dimensions of array: %s. Array dimensions must be known at compile time.")); +public constant Message META_UNUSED_ASSIGNMENT = MESSAGE(5034, TRANSLATION(), NOTIFICATION(), + Util.gettext("Removing unused assignment to: %s.")); + public constant Message COMPILER_ERROR = MESSAGE(5999, TRANSLATION(), ERROR(), Util.notrans("%s")); public constant Message COMPILER_WARNING = MESSAGE(6000, TRANSLATION(), WARNING(), diff --git a/Compiler/boot/refactor-fix-notifications.py b/Compiler/boot/refactor-fix-notifications.py index 6e6e13495e7..e40c2ed83cb 100755 --- a/Compiler/boot/refactor-fix-notifications.py +++ b/Compiler/boot/refactor-fix-notifications.py @@ -32,11 +32,13 @@ def disable(self): lambda s,s2: {'fileName':s2[0],'startLine':int(s2[1]),'startCol':int(s2[2]),'endLine':int(s2[3]),'endCol':int(s2[4])}) UNUSED_LOCAL = (Suppress("Notification: Unused local variable: ") + Word(alphanums + "_") + "." + StringEnd()).setParseAction( lambda s,s2: {'unused_local':s2[0]}) +DEAD_STATEMENT = Literal("Notification: Dead code elimination: Statement optimised away.").setParseAction( + lambda s,s2: {'dead_statement':True}) USE_MATCH = Literal("Notification: This matchcontinue expression has no overlapping patterns and should be using match instead of matchcontinue.").setParseAction( lambda s,s2: {'mc_to_match':True}) UNKNOWN = Suppress("Notification:") -NOTIFICATION = (Suppress("[") + FILEINFO + Suppress("]") + (UNUSED_LOCAL|USE_MATCH|UNKNOWN)) +NOTIFICATION = (Suppress("[") + FILEINFO + Suppress("]") + (UNUSED_LOCAL|DEAD_STATEMENT|USE_MATCH|UNKNOWN)) def runOMC(arg): try: @@ -46,7 +48,14 @@ def runOMC(arg): raise def infoStr(info): - return "%s:%d:%d" % (info['fileName'],info['startLine'],info['endLine']) + start = info['startLine'] + end = info['endLine'] + return "%s:%s" % (info['fileName'].split("/")[-1],("%d-%d" % (start,end) if start<>end else "%d" % start)) + +def printWarning(info,s): + print infoStr(info) + " " + bcolors.FAIL + s + bcolors.ENDC +def printInfo(info,s): + print infoStr(info) + " " + s def fixFile(stamp,logFile,moFile): runOMC(arg) @@ -61,16 +70,35 @@ def fixFile(stamp,logFile,moFile): len1 = len(lst) lst = [n for n in lst if n[0]['fileName'] == moFile] len2 = len(lst) - lst.sort(key=lambda n: n[0]['fileName'] + str(n[0]['endLine']),reverse=True) + lst.sort(key=lambda n: "%s%07d" % (n[0]['fileName'],n[0]['endLine']),reverse=True) + maxLine = sys.maxsize for n in lst: - startLine = n[0]['startLine'] - endLine = n[0]['endLine'] + info = n[0] + startLine = info['startLine'] + endLine = info['endLine'] + startCol = info['startCol'] + endCol = info['endCol'] + if startLine >= maxLine: + printWarning(info,'Skipping entry because a previous operation changed this line number') + pass msg = None if len(n)==2 and n[1].has_key('unused_local'): pass #print "Unused local %s" % n #print moContents[endLine-1] + elif len(n)==2 and n[1].has_key('dead_statement'): + if startLine <> endLine: + printWarning(info,'Dead statement spanning multiple rows') + continue + sOrig = moContents[startLine-1] + s = (sOrig[:startCol-1] + sOrig[endCol:]).strip() + if s <> "": + printWarning(info,"After removing statement '%s' remains" % s) + continue + del moContents[startLine-1] + maxLine = startLine + printInfo(info,"Removed dead statement %s" % sOrig.strip()) elif len(n)==2 and n[1].has_key('mc_to_match'): success1 = False success2 = False @@ -81,7 +109,7 @@ def fixFile(stamp,logFile,moFile): elif moContents[startLine-1].count("matchcontinue") == 0: startLine += 1 else: - msg = bcolors.WARNING + "Found 2 matchcontinue on the same line (%d): %s" (startLine,moContents[startLine-1].strip()) + bcolors.ENDC + msg = bcolors.FAIL + "Found 2 matchcontinue on the same line (%d): %s" (startLine,moContents[startLine-1].strip()) + bcolors.ENDC break while success1 and endLine > startLine: if moContents[endLine-1].count("matchcontinue") == 1: @@ -91,17 +119,18 @@ def fixFile(stamp,logFile,moFile): elif moContents[endLine-1].count("matchcontinue") == 0: startLine += 1 else: - msg = bcolors.WARNING + "Found 2 matchcontinue on the same line (%d): %s" (endLine,moContents[endLine-1].strip()) + bcolors.ENDC + msg = bcolors.FAIL + "Found 2 matchcontinue on the same line (%d): %s" (endLine,moContents[endLine-1].strip()) + bcolors.ENDC break if success2: moContents[startLine-1] = moContents[startLine-1].replace("matchcontinue","match") moContents[endLine-1] = moContents[endLine-1].replace("matchcontinue","match") + maxLine = startLine else: - startLine = n[0]['startLine'] - endLine = n[0]['endLine'] + startLine = info['startLine'] + endLine = info['endLine'] if msg is None: - msg = bcolors.WARNING + "Failed" + bcolors.ENDC - print "%s Matchcontinue to match: %s\n%6d: %s\n%6d: %s" % (infoStr(n[0]),msg,startLine,moContents[startLine-1].strip(),endLine,moContents[endLine-1].strip()) + msg = bcolors.FAIL + "Failed" + bcolors.ENDC + print "%s Matchcontinue to match: %s\n%6d: %s\n%6d: %s" % (infoStr(info),msg,startLine,moContents[startLine-1].strip(),endLine,moContents[endLine-1].strip()) mo.close() mo = open(moFile, 'w') mo.writelines(moContents)