mirror of
https://github.com/QB64Official/qb64.git
synced 2024-07-04 22:20:24 +00:00
Improved detection of unused variables.
This commit is contained in:
parent
47685d82b0
commit
738fe6924d
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue