1
1
Fork 0
mirror of https://github.com/QB64-Phoenix-Edition/QB64pe.git synced 2024-06-26 17:10:38 +00:00

Implements unused variables indicator

An arrow to the left of the line where a variable was defined will be shown after compilation to indicate that variable hasn't been used throughout the program.
This commit is contained in:
FellippeHeitor 2018-11-21 00:47:46 -02:00
parent eab36fc4aa
commit 47685d82b0
2 changed files with 138 additions and 4 deletions

View file

@ -1255,8 +1255,17 @@ FUNCTION ide2 (ignore)
QuickNavHover = -1
LOCATE 2, 4
COLOR 15, 3
PRINT " " + CHR$(17) + " back to line "; str2$(QuickNavHistory(QuickNavTotal)); " ";
popup$ = " " + CHR$(17) + " back to line " + str2$(QuickNavHistory(QuickNavTotal)) + " "
PRINT popup$;
'shadow
COLOR 2, 0
FOR x2 = 6 TO 4 + LEN(popup$)
LOCATE 3, x2: PRINT CHR$(SCREEN(3, x2));
NEXT
PCOPY 3, 0
IF mB THEN
ideselect = 0
idecy = QuickNavHistory(QuickNavTotal)
@ -1269,6 +1278,7 @@ FUNCTION ide2 (ignore)
QuickNavHover = 0
GOSUB UpdateTitleOfMainWindow
GOSUB DrawQuickNav
ideshowtext
PCOPY 3, 0
END IF
END IF
@ -1277,11 +1287,44 @@ FUNCTION ide2 (ignore)
QuickNavHover = 0
GOSUB UpdateTitleOfMainWindow
GOSUB DrawQuickNav
ideshowtext
PCOPY 3, 0
END IF
END IF
END IF
IF mX > 0 AND mY > 0 THEN
IF showingUnusedVariableWarning = 0 THEN
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))
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$
'shadow
COLOR 2, 0
FOR x2 = mX + 2 TO mX + LEN(unusedVariableWarning$) + 1
LOCATE mY + 1, x2: PRINT CHR$(SCREEN(mY + 1, x2));
NEXT
PCOPY 3, 0
showingUnusedVariableWarning = -1
END IF
ELSE
IF unusedVariableWarningX <> mX OR unusedVariableWarningY <> mY THEN
ideshowtext
PCOPY 3, 0
showingUnusedVariableWarning = 0
END IF
END IF
END IF
IF _WINDOWHASFOCUS THEN
LOCATE , , 1
_PALETTECOLOR 5, IDEBracketHighlightColor, 0
@ -8498,6 +8541,14 @@ SUB ideshowtext
END IF
IF l <= iden THEN
IF idecompiling = 0 AND INSTR(usedVariableList$, CHR$(1) + MKL$(l) + CHR$(2)) > 0 THEN
LOCATE y + 3, 1
prevBG% = _BACKGROUNDCOLOR
COLOR 13, 1
PRINT CHR$(26); 'indicate there's an unused variable defined on this line
COLOR , prevBG%
END IF
a$ = idegetline(l)
link_idecx = 0
rgb_idecx = 0
@ -8878,7 +8929,9 @@ SUB ideshowtext
FOR b = 1 TO IdeBmkN
y = IdeBmk(b).y
IF y >= idesy AND y <= idesy + (idewy - 9) THEN
LOCATE 3 + y - idesy, 1: PRINT CHR$(197);
IF INSTR(usedVariableList$, CHR$(1) + MKL$(y) + CHR$(2)) = 0 THEN
LOCATE 3 + y - idesy, 1: PRINT CHR$(197);
END IF
END IF
NEXT

View file

@ -111,6 +111,8 @@ IF OS_BITS = 32 THEN _TITLE "QB64 x32" ELSE _TITLE "QB64 x64"
DIM SHARED ConsoleMode, No_C_Compile_Mode, Cloud, NoIDEMode
DIM SHARED CMDLineFile AS STRING
DIM SHARED totalUnusedVariables AS LONG, usedVariableList$, bypassNextVariable AS _BYTE
DIM SHARED warning$(100), totalWarnings AS LONG
DIM SHARED ExeIconSet AS LONG
DIM SHARED VersionInfoSet AS _BYTE
@ -1429,7 +1431,9 @@ subfunc = ""
SelectCaseCounter = 0
ExecCounter = 0
UserDefineCount = 6
usedVariableList$ = ""
totalUnusedVariables = 0
totalWarnings = 0
''create a type for storing memory blocks
''UDT
@ -7280,6 +7284,7 @@ DO
'create variable
IF LEN(s$) THEN typ$ = s$ ELSE typ$ = t$
IF optionexplicit THEN a$ = "Variable '" + n$ + "' (" + symbol2fulltypename$(typ$) + ") not defined": GOTO errmes
bypassNextVariable = -1
retval = dim2(n$, typ$, method, "")
IF Error_Happened THEN GOTO errmes
'note: variable created!
@ -14725,6 +14730,11 @@ FUNCTION dim2 (varname$, typ2$, method, elements$)
Give_Error "Unknown type": EXIT FUNCTION
dim2exitfunc:
IF bypassNextVariable = 0 THEN
manageVariableList cvarname$, n$, 0
END IF
bypassNextVariable = 0
IF dimsfarray THEN
ids(idn).sfid = glinkid
ids(idn).sfarg = glinkarg
@ -15116,6 +15126,7 @@ FUNCTION evaluate$ (a2$, typ AS LONG)
END IF 'varname
NEXT
END IF 'subfuncn
bypassNextVariable = -1
ignore = dim2(l$, dtyp$, method, fakee$)
IF Error_Happened THEN EXIT FUNCTION
dimstatic = olddimstatic
@ -15310,6 +15321,7 @@ FUNCTION evaluate$ (a2$, typ AS LONG)
IF Debug THEN PRINT #9, "CREATING VARIABLE:" + x$
IF optionexplicit THEN Give_Error "Variable '" + x$ + "' (" + symbol2fulltypename$(typ$) + ") not defined": EXIT FUNCTION
bypassNextVariable = -1
retval = dim2(x$, typ$, 1, "")
IF Error_Happened THEN EXIT FUNCTION
@ -17736,6 +17748,32 @@ FUNCTION findid& (n2$)
id = ids(i)
t = id.t
IF t = 0 THEN
t = id.arraytype
IF t AND ISUDT THEN
manageVariableList "", scope$ + "ARRAY_UDT_" + RTRIM$(id.n), 2
ELSE
n$ = id2fulltypename$
IF LEFT$(n$, 1) = "_" THEN
manageVariableList "", scope$ + "ARRAY" + n$ + "_" + RTRIM$(id.n), 2
ELSE
manageVariableList "", scope$ + "ARRAY_" + n$ + "_" + RTRIM$(id.n), 2
END IF
END IF
ELSE
IF t AND ISUDT THEN
manageVariableList "", scope$ + "UDT_" + RTRIM$(id.n), 2
ELSE
n$ = id2fulltypename$
IF LEFT$(n$, 1) = "_" THEN
manageVariableList "", scope$ + MID$(n$, 2) + "_" + RTRIM$(id.n), 2
ELSE
manageVariableList "", scope$ + n$ + "_" + RTRIM$(id.n), 2
END IF
END IF
END IF
currentid = i
EXIT FUNCTION
@ -21255,7 +21293,6 @@ SUB setrefer (a2$, typ2 AS LONG, e2$, method AS LONG)
getid idnumber
IF Error_Happened THEN EXIT SUB
'UDT?
IF typ AND ISUDT THEN
@ -21345,6 +21382,8 @@ SUB setrefer (a2$, typ2 AS LONG, e2$, method AS LONG)
'print "setUDTrefer:"+r$,e$
tlayout$ = tl$
IF LEFT$(r$, 1) = "*" THEN r$ = MID$(r$, 2)
manageVariableList "", scope$ + n$, 1
EXIT SUB
END IF
@ -21378,6 +21417,8 @@ SUB setrefer (a2$, typ2 AS LONG, e2$, method AS LONG)
END IF
PRINT #12, cleanupstringprocessingcall$ + "0);"
tlayout$ = tl$
IF LEFT$(r$, 1) = "*" THEN r$ = MID$(r$, 2)
manageVariableList "", r$, 1
EXIT SUB
END IF
@ -21452,6 +21493,8 @@ SUB setrefer (a2$, typ2 AS LONG, e2$, method AS LONG)
PRINT #12, cleanupstringprocessingcall$ + "0);"
IF arrayprocessinghappened THEN arrayprocessinghappened = 0
tlayout$ = tl$
IF LEFT$(r$, 1) = "*" THEN r$ = MID$(r$, 2)
manageVariableList "", r$, 1
EXIT SUB
END IF
@ -21482,6 +21525,8 @@ SUB setrefer (a2$, typ2 AS LONG, e2$, method AS LONG)
IF stringprocessinghappened THEN PRINT #12, cleanupstringprocessingcall$ + "0);": stringprocessinghappened = 0
IF arrayprocessinghappened THEN arrayprocessinghappened = 0
tlayout$ = tl$
IF LEFT$(r$, 1) = "*" THEN r$ = MID$(r$, 2)
manageVariableList "", r$, 1
EXIT SUB
END IF
@ -21508,6 +21553,10 @@ SUB setrefer (a2$, typ2 AS LONG, e2$, method AS LONG)
IF stringprocessinghappened THEN PRINT #12, cleanupstringprocessingcall$ + "0);": stringprocessinghappened = 0
IF arrayprocessinghappened THEN arrayprocessinghappened = 0
tlayout$ = tl$
IF LEFT$(r$, 1) = "*" THEN r$ = MID$(r$, 2)
manageVariableList "", r$, 1
EXIT SUB
END IF 'variable
@ -24789,6 +24838,38 @@ SUB dump_udts
CLOSE #f
END SUB
SUB manageVariableList (name$, __cname$, action AS _BYTE)
DIM findItem AS LONG, s$, cname$
cname$ = __cname$
findItem = INSTR(cname$, "[")
IF findItem THEN
cname$ = LEFT$(cname$, findItem - 1)
END IF
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)
CASE ELSE 'find and remove
s$ = CHR$(3) + cname$ + CHR$(10)
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
END IF
'usedVariableList$ = usedVariableList$ + STR$(action) + " Searching " + cname$ + " at line" + STR$(linenumber) + CHR$(10)
END SELECT
END SUB
'$INCLUDE:'utilities\strings.bas'
'$INCLUDE:'subs_functions\extensions\opengl\opengl_methods.bas'