From cb21e44e941ece5fc751ba61b941270229b079c0 Mon Sep 17 00:00:00 2001 From: FellippeHeitor Date: Sun, 31 Mar 2019 20:22:53 -0300 Subject: [PATCH] If merely redefining a CONST with same value, just issue a warning. --- source/qb64.bas | 43 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 39 insertions(+), 4 deletions(-) diff --git a/source/qb64.bas b/source/qb64.bas index c46afe1af..6ebcccff4 100644 --- a/source/qb64.bas +++ b/source/qb64.bas @@ -112,7 +112,7 @@ DIM SHARED ConsoleMode, No_C_Compile_Mode, Cloud, NoIDEMode DIM SHARED VerboseMode AS _BYTE, CMDLineFile AS STRING DIM SHARED totalUnusedVariables AS LONG, usedVariableList$, bypassNextVariable AS _BYTE -DIM SHARED totalWarnings AS LONG, warningListItems AS LONG +DIM SHARED totalWarnings AS LONG, warningListItems AS LONG, lastWarningHeader AS STRING DIM SHARED ExeIconSet AS LONG DIM SHARED VersionInfoSet AS _BYTE @@ -1435,6 +1435,7 @@ usedVariableList$ = "" totalUnusedVariables = 0 totalWarnings = 0 warningListItems = 0 +lastWarningHeader = "" REDIM SHARED warning$(1000) uniquenumbern = 0 @@ -2353,7 +2354,31 @@ DO hashres = HashFind(hashname$, hashchkflags, hashresflags, hashresref) DO WHILE hashres IF hashresflags AND HASHFLAG_CONSTANT THEN - IF constsubfunc(hashresref) = subfuncn THEN a$ = "Name already in use": GOTO errmes + IF constsubfunc(hashresref) = subfuncn THEN + 'If merely redefining a CONST with same value + 'just issue a warning instead of an error + issueWarning = 0 + IF t AND ISSTRING THEN + IF conststring(hashresref) = e$ THEN issueWarning = -1 + ELSE + IF t AND ISFLOAT THEN + IF constfloat(hashresref) = constval## THEN issueWarning = -1 + ELSE + IF t AND ISUNSIGNED THEN + IF constuinteger(hashresref) = constval~&& THEN issueWarning = -1 + ELSE + IF constinteger(hashresref) = constval&& THEN issueWarning = -1 + END IF + END IF + END IF + IF issueWarning THEN + addWarning 0, "Constant already defined (same value):" + addWarning linenumber, n$ + GOTO constAddDone + ELSE + a$ = "Name already in use": GOTO errmes + END IF + END IF END IF IF hashresflags AND HASHFLAG_RESERVED THEN a$ = "Name already in use": GOTO errmes @@ -2391,6 +2416,8 @@ DO END IF END IF + constAddDone: + IF pending THEN 'l$ = l$ + sp2 + "," GOTO constdefpendingpp @@ -24994,11 +25021,19 @@ SUB manageVariableList (name$, __cname$, action AS _BYTE) END SUB SUB addWarning (lineNumber AS LONG, text$) + IF lineNumber > 0 THEN + totalWarnings = totalWarnings + 1 + ELSE + IF lastWarningHeader = text$ THEN + EXIT SUB + ELSE + lastWarningHeader = text$ + END IF + END IF + warningListItems = warningListItems + 1 IF warningListItems > UBOUND(warning$) THEN REDIM _PRESERVE warning$(warningListItems + 999) - warning$(warningListItems) = MKL$(lineNumber) + text$ - IF lineNumber > 0 THEN totalWarnings = totalWarnings + 1 END SUB '$INCLUDE:'utilities\strings.bas'