From 738fe6924dc27784ded377c83f7b3888db37221e Mon Sep 17 00:00:00 2001 From: FellippeHeitor Date: Mon, 31 Dec 2018 21:00:16 -0200 Subject: [PATCH] Improved detection of unused variables. --- source/ide/ide_methods.bas | 14 ++++++++------ source/qb64.bas | 29 +++++++++++++++-------------- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/source/ide/ide_methods.bas b/source/ide/ide_methods.bas index c74fe6dbe..724b6f40d 100644 --- a/source/ide/ide_methods.bas +++ b/source/ide/ide_methods.bas @@ -1298,14 +1298,16 @@ FUNCTION ide2 (ignore) IF mX = 1 AND SCREEN(mY, mX) = 26 THEN unusedVariableWarningX = mX unusedVariableWarningY = mY - findItem = INSTR(usedVariableList$, CHR$(1) + MKL$((mY - 3) + idesy) + CHR$(2)) - unusedVariableName$ = MID$(usedVariableList$, findItem + 6, INSTR(findItem, usedVariableList$, CHR$(10)) - findItem - 6) - findItem = INSTR(unusedVariableName$, CHR$(3)) + findItem = INSTR(usedVariableList$, CHR$(1) + MKL$((mY - 3) + idesy) + CHR$(2) + CHR$(3)) + unusedVariableName$ = MID$(usedVariableList$, findItem + 6, INSTR(findItem, usedVariableList$, CHR$(5)) - findItem - 6) + findItem = MID$(usedVariableList$, findItem + 6 + LEN(unusedVariableName$) INSTR(findItem, usedVariableList$, CHR$(3)) unusedVariableName$ = LEFT$(unusedVariableName$, findItem - 1) + " (" + MID$(unusedVariableName$, findItem + 1) + ") " unusedVariableWarning$ = LEFT$(" Variable hasn't yet been used: " + unusedVariableName$, idewx - 2) LOCATE mY, mX COLOR 0, 3 - PRINT CHR$(26) + unusedVariableWarning$ + PRINT CHR$(26) + LEFT$(unusedVariableWarning$, 32); + COLOR 15 + PRINT MID$(unusedVariableWarning$, 33); 'shadow COLOR 2, 0 @@ -8541,7 +8543,7 @@ SUB ideshowtext END IF IF l <= iden THEN - IF idecompiling = 0 AND INSTR(usedVariableList$, CHR$(1) + MKL$(l) + CHR$(2)) > 0 THEN + IF idecompiling = 0 AND INSTR(usedVariableList$, CHR$(1) + MKL$(l) + CHR$(2) + CHR$(4)) > 0 THEN LOCATE y + 3, 1 prevBG% = _BACKGROUNDCOLOR COLOR 13, 1 @@ -8929,7 +8931,7 @@ SUB ideshowtext FOR b = 1 TO IdeBmkN y = IdeBmk(b).y IF y >= idesy AND y <= idesy + (idewy - 9) THEN - IF INSTR(usedVariableList$, CHR$(1) + MKL$(y) + CHR$(2)) = 0 THEN + IF INSTR(usedVariableList$, CHR$(1) + MKL$(y) + CHR$(2) + CHR$(4)) = 0 THEN LOCATE 3 + y - idesy, 1: PRINT CHR$(197); END IF END IF diff --git a/source/qb64.bas b/source/qb64.bas index fd8277f30..8c21c2cf3 100644 --- a/source/qb64.bas +++ b/source/qb64.bas @@ -11631,7 +11631,10 @@ OPEN compilelog$ FOR OUTPUT AS #1: CLOSE #1 'Clear log - +OPEN "unusedVariableList.txt" FOR OUTPUT AS #1: CLOSE #1 +OPEN "unusedVariableList.txt" FOR BINARY AS #1 +PUT #1, 1, usedVariableList$ +CLOSE #1 @@ -24849,22 +24852,20 @@ SUB manageVariableList (name$, __cname$, action AS _BYTE) SELECT CASE action CASE 0 'add - usedVariableList$ = usedVariableList$ + CHR$(1) + MKL$(linenumber) + CHR$(2) - usedVariableList$ = usedVariableList$ + name$ + CHR$(3) + cname$ + CHR$(10) - totalUnusedVariables = totalUnusedVariables + 1 - 'usedVariableList$ = usedVariableList$ + "Adding " + cname$ + " at line" + STR$(linenumber) + CHR$(10) + s$ = CHR$(4) + MKI$(LEN(cname$)) + cname$ + CHR$(5) + IF INSTR(usedVariableList$, s$) = 0 THEN + ASC(s$, 1) = 3 + usedVariableList$ = usedVariableList$ + CHR$(1) + MKL$(linenumber) + CHR$(2) + usedVariableList$ = usedVariableList$ + s$ + name$ + CHR$(10) + totalUnusedVariables = totalUnusedVariables + 1 + 'usedVariableList$ = usedVariableList$ + "Adding " + cname$ + " at line" + STR$(linenumber) + CHR$(10) + END IF CASE ELSE 'find and remove - s$ = CHR$(3) + cname$ + CHR$(10) + s$ = CHR$(3) + cname$ + CHR$(5) findItem = INSTR(usedVariableList$, s$) IF findItem THEN - FOR i = findItem TO 1 STEP -1 - IF ASC(usedVariableList$, i) = 1 THEN - findItem = INSTR(findItem, usedVariableList$, CHR$(10)) - usedVariableList$ = LEFT$(usedVariableList$, i - 1) + MID$(usedVariableList$, findItem + 1) - totalUnusedVariables = totalUnusedVariables - 1 - EXIT FOR - END IF - NEXT + ASC(usedVariableList$, findItem) = 4 + totalUnusedVariables = totalUnusedVariables - 1 END IF 'usedVariableList$ = usedVariableList$ + STR$(action) + " Searching " + cname$ + " at line" + STR$(linenumber) + CHR$(10) END SELECT