1
1
Fork 0
mirror of https://github.com/QB64-Phoenix-Edition/QB64pe.git synced 2024-07-01 13:50:36 +00:00

Improves warning system to add $include info.

This commit is contained in:
FellippeHeitor 2021-01-13 17:51:40 -03:00
parent 28c2bd9b49
commit c9ac352d87
2 changed files with 104 additions and 86 deletions

View file

@ -2828,6 +2828,8 @@ FUNCTION ide2 (ignore)
p$ = QuotedFilename$(COMMAND$(0)) + " " + QuotedFilename$(f$) p$ = QuotedFilename$(COMMAND$(0)) + " " + QuotedFilename$(f$)
IF errorLineInInclude > 0 AND idefocusline = idecy THEN IF errorLineInInclude > 0 AND idefocusline = idecy THEN
p$ = p$ + " -l:" + str2$(errorLineInInclude) p$ = p$ + " -l:" + str2$(errorLineInInclude)
ELSEIF warningInIncludeLine > 0 AND warningInInclude = idecy THEN
p$ = p$ + " -l:" + str2$(warningInIncludeLine)
END IF END IF
SHELL p$ SHELL p$
@ -9285,18 +9287,25 @@ FUNCTION idewarningbox
'-------- init -------- '-------- init --------
DIM warningLines(1 TO warningListItems) AS LONG DIM warningLines(1 TO warningListItems) AS LONG
DIM warningIncLines(1 TO warningListItems) AS LONG
DIM warningIncFiles(1 TO warningListItems) AS STRING
FOR x = 1 TO warningListItems FOR x = 1 TO warningListItems
warningLines(x) = CVL(LEFT$(warning$(x), 4)) warningLines(x) = CVL(LEFT$(warning$(x), 4))
IF warningLines(x) = 0 THEN IF warningLines(x) = 0 THEN
l$ = l$ + MID$(warning$(x), 5) l$ = l$ + MID$(warning$(x), INSTR(warning$(x), CHR$(2)) + 1)
IF x > 1 THEN ASC(l$, treeConnection) = 192 IF x > 1 THEN ASC(l$, treeConnection) = 192
ELSE ELSE
l2$ = "line" + STR$(warningLines(x)) warningIncLevel = CVL(MID$(warning$(x), 5, 4))
l3$ = SPACE$(maxLineNumberLength + 4) IF warningIncLevel > 0 THEN
RSET l3$ = l2$ warningIncLines(x) = CVL(MID$(warning$(x), 9, 4))
warningIncFiles(x) = MID$(warning$(x), 13, INSTR(warning$(x), CHR$(2)) - 13)
l3$ = "line" + STR$(warningIncLines(x)) + " in '" + warningIncFiles(x) + "'"
ELSE
l3$ = "line" + STR$(warningLines(x))
END IF
treeConnection = LEN(l$) + 1 treeConnection = LEN(l$) + 1
l$ = l$ + CHR$(195) + CHR$(196) + l3$ + ": " + MID$(warning$(x), 5) l$ = l$ + CHR$(195) + CHR$(196) + l3$ + ": " + MID$(warning$(x), INSTR(warning$(x), CHR$(2)) + 1)
END IF END IF
IF x < warningListItems THEN l$ = l$ + sep IF x < warningListItems THEN l$ = l$ + sep
NEXT NEXT
@ -9415,6 +9424,10 @@ FUNCTION idewarningbox
idegotobox_LastLineNum = warningLines(y) idegotobox_LastLineNum = warningLines(y)
AddQuickNavHistory idecy AddQuickNavHistory idecy
idecy = idegotobox_LastLineNum idecy = idegotobox_LastLineNum
IF warningIncLines(y) > 0 THEN
warningInInclude = idecy
warningInIncludeLine = warningIncLines(y)
END IF
ideselect = 0 ideselect = 0
EXIT FUNCTION EXIT FUNCTION
END IF END IF

View file

@ -92,7 +92,18 @@ _TITLE WindowTitle
DIM SHARED ConsoleMode, No_C_Compile_Mode, NoIDEMode DIM SHARED ConsoleMode, No_C_Compile_Mode, NoIDEMode
DIM SHARED VerboseMode AS _BYTE, QuietMode AS _BYTE, CMDLineFile AS STRING DIM SHARED VerboseMode AS _BYTE, QuietMode AS _BYTE, CMDLineFile AS STRING
DIM SHARED totalUnusedVariables AS LONG, usedVariableList$, bypassNextVariable AS _BYTE TYPE usedVarList
used AS _BYTE
linenumber AS LONG
includeLevel AS LONG
includedLine AS LONG
includedFile AS STRING
cname AS STRING
name AS STRING
END TYPE
REDIM SHARED usedVariableList(1000) AS usedVarList, totalVariablesCreated AS LONG
DIM SHARED totalUnusedVariables AS LONG, bypassNextVariable AS _BYTE
DIM SHARED totalWarnings AS LONG, warningListItems AS LONG, lastWarningHeader AS STRING DIM SHARED totalWarnings AS LONG, warningListItems AS LONG, lastWarningHeader AS STRING
DIM SHARED duplicateConstWarning AS _BYTE DIM SHARED duplicateConstWarning AS _BYTE
DIM SHARED emptySCWarning AS _BYTE DIM SHARED emptySCWarning AS _BYTE
@ -328,6 +339,7 @@ DIM SHARED optionexplicit AS _BYTE
DIM SHARED optionexplicitarray AS _BYTE DIM SHARED optionexplicitarray AS _BYTE
DIM SHARED optionexplicit_cmd AS _BYTE DIM SHARED optionexplicit_cmd AS _BYTE
DIM SHARED ideStartAtLine AS LONG, errorLineInInclude AS LONG DIM SHARED ideStartAtLine AS LONG, errorLineInInclude AS LONG
DIM SHARED warningInInclude AS LONG, warningInIncludeLine AS LONG
DIM SHARED outputfile_cmd$ DIM SHARED outputfile_cmd$
DIM SHARED compilelog$ DIM SHARED compilelog$
@ -1401,8 +1413,8 @@ subfunc = ""
SelectCaseCounter = 0 SelectCaseCounter = 0
ExecCounter = 0 ExecCounter = 0
UserDefineCount = 6 UserDefineCount = 6
usedVariableList$ = ""
totalUnusedVariables = 0 totalUnusedVariables = 0
totalVariablesCreated = 0
totalWarnings = 0 totalWarnings = 0
duplicateConstWarning = 0 duplicateConstWarning = 0
emptySCWarning = 0 emptySCWarning = 0
@ -2123,22 +2135,22 @@ DO
'just issue a warning instead of an error 'just issue a warning instead of an error
issueWarning = 0 issueWarning = 0
IF t AND ISSTRING THEN IF t AND ISSTRING THEN
IF conststring(hashresref) = e$ THEN issueWarning = -1 IF conststring(hashresref) = e$ THEN issueWarning = -1: thisconstval$ = e$
ELSE ELSE
IF t AND ISFLOAT THEN IF t AND ISFLOAT THEN
IF constfloat(hashresref) = constval## THEN issueWarning = -1 IF constfloat(hashresref) = constval## THEN issueWarning = -1: thisconstval$ = STR$(constval##)
ELSE ELSE
IF t AND ISUNSIGNED THEN IF t AND ISUNSIGNED THEN
IF constuinteger(hashresref) = constval~&& THEN issueWarning = -1 IF constuinteger(hashresref) = constval~&& THEN issueWarning = -1: thisconstval$ = STR$(constval~&&)
ELSE ELSE
IF constinteger(hashresref) = constval&& THEN issueWarning = -1 IF constinteger(hashresref) = constval&& THEN issueWarning = -1: thisconstval$ = STR$(constval&&)
END IF END IF
END IF END IF
END IF END IF
IF issueWarning THEN IF issueWarning THEN
IF NOT IgnoreWarnings THEN IF NOT IgnoreWarnings THEN
addWarning 0, "Constant already defined (same value):" addWarning 0, 0, 0, "", "Constant already defined (same value):"
addWarning linenumber, n$ addWarning linenumber, inclevel, inclinenumber(inclevel), incname$(inclevel), n$ + " =" + thisconstval$
IF idemode = 0 THEN IF idemode = 0 THEN
IF duplicateConstWarning = 0 THEN PRINT: PRINT "Warning: duplicate constant definition"; IF duplicateConstWarning = 0 THEN PRINT: PRINT "Warning: duplicate constant definition";
IF VerboseMode THEN IF VerboseMode THEN
@ -5859,8 +5871,8 @@ DO
IF SelectCaseCounter > 0 AND SelectCaseHasCaseBlock(SelectCaseCounter) = 0 THEN IF SelectCaseCounter > 0 AND SelectCaseHasCaseBlock(SelectCaseCounter) = 0 THEN
'warn user of empty SELECT CASE block 'warn user of empty SELECT CASE block
IF NOT IgnoreWarnings THEN IF NOT IgnoreWarnings THEN
addWarning 0, "Empty SELECT CASE block:" addWarning 0, 0, 0, "", "Empty SELECT CASE block:"
addWarning linenumber, "END SELECT" addWarning linenumber, inclevel, inclinenumber(inclevel), incname$(inclevel), "END SELECT"
IF idemode = 0 THEN IF idemode = 0 THEN
IF emptySCWarning = 0 THEN PRINT: PRINT "Warning: Empty SELECT CASE block"; IF emptySCWarning = 0 THEN PRINT: PRINT "Warning: Empty SELECT CASE block";
IF VerboseMode THEN IF VerboseMode THEN
@ -11508,48 +11520,33 @@ IF NOT IgnoreWarnings THEN
IF totalUnusedVariables > 1 THEN PRINT "s"; IF totalUnusedVariables > 1 THEN PRINT "s";
IF VerboseMode THEN IF VerboseMode THEN
PRINT ":" PRINT ":"
findItem = 0 FOR i = 1 TO totalVariablesCreated
DO IF usedVariableList(i).used = 0 THEN
s$ = CHR$(2) + "VAR:" + CHR$(3) PRINT SPACE$(4); usedVariableList(i).name; " ("; usedVariableList(i).cname; ", ";
findItem = INSTR(findItem + 1, usedVariableList$, s$) IF usedVariableList(i).includeLevel > 0 THEN
IF findItem = 0 THEN EXIT DO PRINT "line"; STR$(usedVariableList(i).includedLine); " in file '"; usedVariableList(i).includedFile; "')"
whichLine = CVL(MID$(usedVariableList$, findItem - 4, 4)) ELSE
varNameLen = CVI(MID$(usedVariableList$, findItem + 6, 2)) PRINT "line"; STR$(whichLine); ")"
internalVarName$ = MID$(usedVariableList$, findItem + 8, varNameLen) END IF
findLF = INSTR(findItem + 9 + varNameLen, usedVariableList$, CHR$(10)) END IF
varname$ = MID$(usedVariableList$, findItem + 9 + varNameLen, findLF - (findItem + 9 + varNameLen)) NEXT
PRINT SPACE$(4); varname$; " ("; internalVarName$; ", line"; STR$(whichLine); ")"
LOOP
ELSE ELSE
PRINT PRINT
END IF END IF
ELSE ELSE
findItem = 0
maxVarNameLen = 0 maxVarNameLen = 0
DO FOR i = 1 TO totalVariablesCreated
s$ = CHR$(2) + "VAR:" + CHR$(3) IF usedVariableList(i).used = 0 THEN
findItem = INSTR(findItem + 1, usedVariableList$, s$) IF LEN(usedVariableList(i).name) > maxVarNameLen THEN maxVarNameLen = LEN(usedVariableList(i).name)
IF findItem = 0 THEN EXIT DO END IF
varNameLen = CVI(MID$(usedVariableList$, findItem + 6, 2)) NEXT
internalVarName$ = MID$(usedVariableList$, findItem + 8, varNameLen)
findLF = INSTR(findItem + 9 + varNameLen, usedVariableList$, CHR$(10))
varname$ = MID$(usedVariableList$, findItem + 9 + varNameLen, findLF - (findItem + 9 + varNameLen))
IF LEN(varname$) > maxVarNameLen THEN maxVarNameLen = LEN(varname$)
LOOP
findItem = 0 addWarning 0, 0, 0, "", "Unused variables (" + LTRIM$(STR$(totalUnusedVariables)) + "):"
addWarning 0, "Unused variables (" + LTRIM$(STR$(totalUnusedVariables)) + "):" FOR i = 1 TO totalVariablesCreated
DO IF usedVariableList(i).used = 0 THEN
s$ = CHR$(2) + "VAR:" + CHR$(3) addWarning usedVariableList(i).linenumber, usedVariableList(i).includeLevel, usedVariableList(i).includedLine, usedVariableList(i).includedFile, usedVariableList(i).name + SPACE$((maxVarNameLen + 1) - LEN(usedVariableList(i).name)) + " (" + usedVariableList(i).cname + ")"
findItem = INSTR(findItem + 1, usedVariableList$, s$) END IF
IF findItem = 0 THEN EXIT DO NEXT
whichLine = CVL(MID$(usedVariableList$, findItem - 4, 4))
varNameLen = CVI(MID$(usedVariableList$, findItem + 6, 2))
internalVarName$ = MID$(usedVariableList$, findItem + 8, varNameLen)
findLF = INSTR(findItem + 9 + varNameLen, usedVariableList$, CHR$(10))
varname$ = MID$(usedVariableList$, findItem + 9 + varNameLen, findLF - (findItem + 9 + varNameLen))
addWarning whichLine, varname$ + SPACE$((maxVarNameLen + 1) - LEN(varname$)) + " (" + internalVarName$ + ")"
LOOP
END IF END IF
END IF END IF
END IF END IF
@ -25150,7 +25147,7 @@ SUB dump_udts
END SUB END SUB
SUB manageVariableList (name$, __cname$, action AS _BYTE) SUB manageVariableList (name$, __cname$, action AS _BYTE)
DIM findItem AS LONG, s$, cname$ DIM findItem AS LONG, s$, cname$, i AS LONG
cname$ = __cname$ cname$ = __cname$
findItem = INSTR(cname$, "[") findItem = INSTR(cname$, "[")
@ -25158,42 +25155,45 @@ SUB manageVariableList (name$, __cname$, action AS _BYTE)
cname$ = LEFT$(cname$, findItem - 1) cname$ = LEFT$(cname$, findItem - 1)
END IF END IF
found = 0
FOR i = 1 TO totalVariablesCreated
IF usedVariableList(i).cname = cname$ THEN found = -1: EXIT FOR
NEXT
SELECT CASE action SELECT CASE action
CASE 0 'add CASE 0 'add
s$ = CHR$(4) + MKI$(LEN(cname$)) + cname$ + CHR$(5) IF found = 0 THEN
IF INSTR(usedVariableList$, s$) = 0 THEN IF i > UBOUND(usedVariableList) THEN
ASC(s$, 1) = 3 REDIM _PRESERVE usedVariableList(UBOUND(usedVariableList) + 999) AS usedVarList
usedVariableList$ = usedVariableList$ + CHR$(1) + MKL$(linenumber) + MKL$(inclevel) + MKL$(inclinenumber(inclevel)) + incname$(inclevel) + CHR$(2)
usedVariableList$ = usedVariableList$ + "VAR:" + s$ + name$ + CHR$(10)
totalUnusedVariables = totalUnusedVariables + 1
'warning$(1) = warning$(1) + "Adding " + cname$ + " at line" + STR$(linenumber) + CHR$(10)
END IF END IF
CASE ELSE 'find and remove usedVariableList(i).used = 0
s$ = CHR$(3) + MKI$(LEN(cname$)) + cname$ + CHR$(5) usedVariableList(i).linenumber = linenumber
findItem = INSTR(usedVariableList$, s$) usedVariableList(i).includeLevel = inclevel
IF findItem THEN IF inclevel > 0 THEN
ASC(usedVariableList$, findItem) = 4 usedVariableList(i).includedLine = inclinenumber(inclevel)
thisincname$ = getfilepath$(incname$(inclevel))
thisincname$ = MID$(incname$(inclevel), LEN(thisincname$) + 1)
usedVariableList(i).includedFile = thisincname$
ELSE
usedVariableList(i).includedLine = 0
usedVariableList(i).includedFile = ""
END IF
usedVariableList(i).cname = cname$
usedVariableList(i).name = name$
totalUnusedVariables = totalUnusedVariables + 1
totalVariablesCreated = totalVariablesCreated + 1
END IF
CASE ELSE 'find and mark as used
IF found THEN
usedVariableList(i).used = -1
totalUnusedVariables = totalUnusedVariables - 1 totalUnusedVariables = totalUnusedVariables - 1
END IF END IF
'warning$(1) = warning$(1) + "Action:" + STR$(action) + " Searching " + cname$ + " at line" + STR$(linenumber) + CHR$(10)
END SELECT END SELECT
END SUB END SUB
SUB addWarning (lineNumber AS LONG, text$) SUB addWarning (whichLineNumber AS LONG, includeLevel AS LONG, incLineNumber AS LONG, incFileName$, text$)
IF NOT IgnoreWarnings THEN IF NOT IgnoreWarnings THEN
IF idemode = 0 THEN IF whichLineNumber > 0 THEN
PRINT
IF lineNumber = 0 THEN
PRINT "Warning: "; text$;
ELSE
IF VerboseMode THEN
PRINT "; "; text$; " (line"; STR$(lineNumber); ")"
ELSE
PRINT " (line"; STR$(lineNumber); ")"
END IF
END IF
ELSE
IF lineNumber > 0 THEN
totalWarnings = totalWarnings + 1 totalWarnings = totalWarnings + 1
ELSE ELSE
IF lastWarningHeader = text$ THEN IF lastWarningHeader = text$ THEN
@ -25205,7 +25205,12 @@ SUB addWarning (lineNumber AS LONG, text$)
warningListItems = warningListItems + 1 warningListItems = warningListItems + 1
IF warningListItems > UBOUND(warning$) THEN REDIM _PRESERVE warning$(warningListItems + 999) IF warningListItems > UBOUND(warning$) THEN REDIM _PRESERVE warning$(warningListItems + 999)
warning$(warningListItems) = MKL$(lineNumber) + MKL$(inclevel) + MKL$(inclinenumber(inclevel)) + incname$(inclevel) + CHR$(2) + text$ IF includeLevel > 0 THEN
thisincname$ = getfilepath$(incFileName$)
thisincname$ = MID$(incFileName$, LEN(thisincname$) + 1)
warning$(warningListItems) = MKL$(whichLineNumber) + MKL$(includeLevel) + MKL$(incLineNumber) + thisincname$ + CHR$(2) + text$
ELSE
warning$(warningListItems) = MKL$(whichLineNumber) + MKL$(0) + CHR$(2) + text$
END IF END IF
END IF END IF
END SUB END SUB