mirror of
https://github.com/QB64-Phoenix-Edition/QB64pe.git
synced 2024-07-09 04:55:15 +00:00
Implements OPTION _EXPLICIT
When you use OPTION _EXPLICIT, all variables and arrays must be defined with DIM (or equivalent statement) before they can be used. QB64's case check already aids in avoiding mistakes on that front, but now you will run into a compiler error if a variable or array is used before being defined. Because OPTION _EXPLICIT sets a compiler behavior, it must come before any other statements in your code. As this is a non-QB4.5 feature, the keyword uses an underscore, in order to avoid conflicts with existing code.
This commit is contained in:
parent
8b608d3ce9
commit
a7a3b1663d
|
@ -707,6 +707,7 @@ DIM SHARED cleanupstringprocessingcall AS STRING
|
||||||
DIM SHARED recompile AS INTEGER 'forces recompilation
|
DIM SHARED recompile AS INTEGER 'forces recompilation
|
||||||
'COMMON SHARED cmemlist() AS INTEGER
|
'COMMON SHARED cmemlist() AS INTEGER
|
||||||
DIM SHARED optionbase AS INTEGER
|
DIM SHARED optionbase AS INTEGER
|
||||||
|
DIM SHARED optionexplicit AS _BYTE
|
||||||
|
|
||||||
DIM SHARED addmetastatic AS INTEGER
|
DIM SHARED addmetastatic AS INTEGER
|
||||||
DIM SHARED addmetadynamic AS INTEGER
|
DIM SHARED addmetadynamic AS INTEGER
|
||||||
|
@ -1276,6 +1277,7 @@ HashAdd "MOD", f, 0
|
||||||
f = HASHFLAG_RESERVED + HASHFLAG_CUSTOMSYNTAX
|
f = HASHFLAG_RESERVED + HASHFLAG_CUSTOMSYNTAX
|
||||||
HashAdd "LIST", f, 0
|
HashAdd "LIST", f, 0
|
||||||
HashAdd "BASE", f, 0
|
HashAdd "BASE", f, 0
|
||||||
|
HashAdd "_EXPLICIT", f, 0
|
||||||
HashAdd "AS", f, 0
|
HashAdd "AS", f, 0
|
||||||
HashAdd "IS", f, 0
|
HashAdd "IS", f, 0
|
||||||
HashAdd "OFF", f, 0
|
HashAdd "OFF", f, 0
|
||||||
|
@ -1426,6 +1428,7 @@ addmetastatic = 0
|
||||||
addmetadynamic = 0
|
addmetadynamic = 0
|
||||||
DynamicMode = 0
|
DynamicMode = 0
|
||||||
optionbase = 0
|
optionbase = 0
|
||||||
|
optionexplicit = 0
|
||||||
DataOffset = 0
|
DataOffset = 0
|
||||||
statementn = 0
|
statementn = 0
|
||||||
qberrorhappened = 0: qberrorcode = 0: qberrorline = 0
|
qberrorhappened = 0: qberrorcode = 0: qberrorline = 0
|
||||||
|
@ -9581,14 +9584,25 @@ DO
|
||||||
END IF
|
END IF
|
||||||
|
|
||||||
IF firstelement$ = "OPTION" THEN
|
IF firstelement$ = "OPTION" THEN
|
||||||
IF n <> 3 THEN a$ = "Expected OPTION BASE 0 or 1": GOTO errmes
|
IF n = 1 THEN a$ = "Expected OPTION BASE or OPTION _EXPLICIT": GOTO errmes
|
||||||
IF getelement$(a$, 2) <> "BASE" THEN a$ = "Expected OPTION BASE 0 or 1": GOTO errmes
|
e$ = getelement$(a$, 2)
|
||||||
l$ = getelement$(a$, 3)
|
SELECT CASE e$
|
||||||
IF l$ <> "0" AND l$ <> "1" THEN a$ = "Expected OPTION BASE 0 or 1": GOTO errmes
|
CASE "BASE"
|
||||||
IF l$ = "1" THEN optionbase = 1 ELSE optionbase = 0
|
l$ = getelement$(a$, 3)
|
||||||
l$ = "OPTION" + sp + "BASE" + sp + l$
|
IF l$ <> "0" AND l$ <> "1" THEN a$ = "Expected OPTION BASE 0 or 1": GOTO errmes
|
||||||
layoutdone = 1: IF LEN(layout$) THEN layout$ = layout$ + sp + l$ ELSE layout$ = l$
|
IF l$ = "1" THEN optionbase = 1 ELSE optionbase = 0
|
||||||
GOTO finishedline
|
l$ = "OPTION" + sp + "BASE" + sp + l$
|
||||||
|
layoutdone = 1: IF LEN(layout$) THEN layout$ = layout$ + sp + l$ ELSE layout$ = l$
|
||||||
|
GOTO finishedline
|
||||||
|
CASE "_EXPLICIT"
|
||||||
|
IF linenumber > 1 THEN a$ = "OPTION _EXPLICIT must come before any other statement": GOTO errmes
|
||||||
|
optionexplicit = -1
|
||||||
|
l$ = "OPTION" + sp + "_EXPLICIT"
|
||||||
|
layoutdone = 1: IF LEN(layout$) THEN layout$ = layout$ + sp + l$ ELSE layout$ = l$
|
||||||
|
GOTO finishedline
|
||||||
|
CASE ELSE
|
||||||
|
a$ = "Expected OPTION BASE or OPTION _EXPLICIT": GOTO errmes
|
||||||
|
END SELECT
|
||||||
END IF
|
END IF
|
||||||
|
|
||||||
'any other "unique" subs can be processed above
|
'any other "unique" subs can be processed above
|
||||||
|
@ -14573,6 +14587,7 @@ FUNCTION evaluate$ (a2$, typ AS LONG)
|
||||||
NEXT
|
NEXT
|
||||||
fakee$ = "10": FOR i2 = 2 TO nume: fakee$ = fakee$ + sp + "," + sp + "10": NEXT
|
fakee$ = "10": FOR i2 = 2 TO nume: fakee$ = fakee$ + sp + "," + sp + "10": NEXT
|
||||||
IF Debug THEN PRINT #9, "evaluate:creating undefined array using dim2(" + l$ + "," + dtyp$ + ",1," + fakee$ + ")"
|
IF Debug THEN PRINT #9, "evaluate:creating undefined array using dim2(" + l$ + "," + dtyp$ + ",1," + fakee$ + ")"
|
||||||
|
IF optionexplicit THEN Give_Error "Array not defined": EXIT FUNCTION
|
||||||
IF Error_Happened THEN EXIT FUNCTION
|
IF Error_Happened THEN EXIT FUNCTION
|
||||||
olddimstatic = dimstatic
|
olddimstatic = dimstatic
|
||||||
method = 1
|
method = 1
|
||||||
|
@ -14793,6 +14808,7 @@ FUNCTION evaluate$ (a2$, typ AS LONG)
|
||||||
LOOP
|
LOOP
|
||||||
|
|
||||||
IF Debug THEN PRINT #9, "CREATING VARIABLE:" + x$
|
IF Debug THEN PRINT #9, "CREATING VARIABLE:" + x$
|
||||||
|
IF optionexplicit THEN Give_Error "Variable not defined": EXIT FUNCTION
|
||||||
retval = dim2(x$, typ$, 1, "")
|
retval = dim2(x$, typ$, 1, "")
|
||||||
IF Error_Happened THEN EXIT FUNCTION
|
IF Error_Happened THEN EXIT FUNCTION
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue