1
1
Fork 0
mirror of https://github.com/QB64Official/qb64.git synced 2024-07-16 13:05:14 +00:00

Propagates DIM SHARED variables to all SUBs.

`vwatch_local_vars` will make direct reference to SHARED variables, so they can be watched in whatever scope.
This commit is contained in:
FellippeHeitor 2021-07-24 11:51:01 -03:00
parent 5886488b72
commit 6436ee76bf

View file

@ -115,6 +115,8 @@ TYPE usedVarList
includedLine AS LONG includedLine AS LONG
includedFile AS STRING includedFile AS STRING
scope AS LONG scope AS LONG
subfunc AS STRING
localIndex AS LONG
cname AS STRING cname AS STRING
name AS STRING name AS STRING
END TYPE END TYPE
@ -7528,7 +7530,7 @@ DO
IF optionexplicit THEN a$ = "Variable '" + n$ + "' (" + symbol2fulltypename$(typ$) + ") not defined": GOTO errmes IF optionexplicit THEN a$ = "Variable '" + n$ + "' (" + symbol2fulltypename$(typ$) + ") not defined": GOTO errmes
bypassNextVariable = -1 bypassNextVariable = -1
retval = dim2(n$, typ$, method, "") retval = dim2(n$, typ$, method, "")
manageVariableList "", vWatchNewVariable$, 2 manageVariableList "", vWatchNewVariable$, 0, 2
IF Error_Happened THEN GOTO errmes IF Error_Happened THEN GOTO errmes
'note: variable created! 'note: variable created!
@ -14218,6 +14220,7 @@ END SUB
SUB vWatchVariable (this$, action AS _BYTE) SUB vWatchVariable (this$, action AS _BYTE)
STATIC totalLocalVariables AS LONG, localVariablesList$ STATIC totalLocalVariables AS LONG, localVariablesList$
STATIC totalMainModuleVariables AS LONG, mainModuleVariablesList$ STATIC totalMainModuleVariables AS LONG, mainModuleVariablesList$
STATIC totalSharedVariablesFromMainModule AS LONG, mainModuleSharedVariablesList$
SELECT CASE action SELECT CASE action
CASE -1 'reset CASE -1 'reset
@ -14225,6 +14228,8 @@ SUB vWatchVariable (this$, action AS _BYTE)
localVariablesList$ = "" localVariablesList$ = ""
totalMainModuleVariables = 0 totalMainModuleVariables = 0
mainModuleVariablesList$ = "" mainModuleVariablesList$ = ""
totalSharedVariablesFromMainModule = 0
mainModuleSharedVariablesList$ = ""
CASE 0 'add CASE 0 'add
IF INSTR(vWatchVariableExclusions$, "@" + this$ + "@") > 0 OR LEFT$(this$, 12) = "_SUB_VWATCH_" THEN IF INSTR(vWatchVariableExclusions$, "@" + this$ + "@") > 0 OR LEFT$(this$, 12) = "_SUB_VWATCH_" THEN
EXIT SUB EXIT SUB
@ -14234,11 +14239,16 @@ SUB vWatchVariable (this$, action AS _BYTE)
IF subfunc = "" THEN IF subfunc = "" THEN
totalMainModuleVariables = totalMainModuleVariables + 1 totalMainModuleVariables = totalMainModuleVariables + 1
mainModuleVariablesList$ = mainModuleVariablesList$ + "vwatch_local_vars[" + str2$(totalMainModuleVariables - 1) + "] = &" + this$ + ";" + CRLF mainModuleVariablesList$ = mainModuleVariablesList$ + "vwatch_local_vars[" + str2$(totalMainModuleVariables - 1) + "] = &" + this$ + ";" + CRLF
IF dimshared = 1 THEN
'DIM SHARED variables will be appended to every SUB
totalSharedVariablesFromMainModule = totalSharedVariablesFromMainModule + 1
mainModuleSharedVariablesList$ = mainModuleSharedVariablesList$ + MKL$(LEN(this$)) + this$
END IF
ELSE ELSE
totalLocalVariables = totalLocalVariables + 1 totalLocalVariables = totalLocalVariables + 1
localVariablesList$ = localVariablesList$ + "vwatch_local_vars[" + str2$(totalLocalVariables - 1) + "] = &" + this$ + ";" + CRLF localVariablesList$ = localVariablesList$ + "vwatch_local_vars[" + str2$(totalLocalVariables - 1) + "] = &" + this$ + ";" + CRLF
manageVariableList id.cn, this$, totalLocalVariables - 1, 0
END IF END IF
manageVariableList RTRIM$(id.cn), this$, 0
CASE 1 'dump to data[].txt & reset CASE 1 'dump to data[].txt & reset
IF subfunc = "" THEN IF subfunc = "" THEN
IF totalMainModuleVariables > 0 THEN IF totalMainModuleVariables > 0 THEN
@ -14251,8 +14261,18 @@ SUB vWatchVariable (this$, action AS _BYTE)
mainModuleVariablesList$ = "" mainModuleVariablesList$ = ""
totalMainModuleVariables = 0 totalMainModuleVariables = 0
ELSE ELSE
IF totalLocalVariables > 0 THEN IF totalLocalVariables + totalSharedVariablesFromMainModule > 0 THEN
PRINT #13, "void *vwatch_local_vars["; totalLocalVariables; "];" PRINT #13, "void *vwatch_local_vars["; (totalLocalVariables + totalSharedVariablesFromMainModule); "];"
i = totalLocalVariables
tempShared$ = mainModuleSharedVariablesList$
tempVar$ = ""
DO UNTIL i = totalLocalVariables + totalSharedVariablesFromMainModule
length = CVL(LEFT$(tempShared$, 4))
tempVar$ = MID$(tempShared$, 5, length)
tempShared$ = MID$(tempShared$, 5 + length)
localVariablesList$ = localVariablesList$ + "vwatch_local_vars[" + str2$(i) + "] = &" + tempVar$ + ";" + CRLF
i = i + 1
LOOP
PRINT #13, localVariablesList$ PRINT #13, localVariablesList$
ELSE ELSE
PRINT #13, "void *vwatch_local_vars[0];" PRINT #13, "void *vwatch_local_vars[0];"
@ -16137,7 +16157,7 @@ FUNCTION evaluate$ (a2$, typ AS LONG)
IF optionexplicit THEN Give_Error "Variable '" + x$ + "' (" + symbol2fulltypename$(typ$) + ") not defined": EXIT FUNCTION IF optionexplicit THEN Give_Error "Variable '" + x$ + "' (" + symbol2fulltypename$(typ$) + ") not defined": EXIT FUNCTION
bypassNextVariable = -1 bypassNextVariable = -1
retval = dim2(x$, typ$, 1, "") retval = dim2(x$, typ$, 1, "")
manageVariableList "", vWatchNewVariable$, 3 manageVariableList "", vWatchNewVariable$, 0, 3
IF Error_Happened THEN EXIT FUNCTION IF Error_Happened THEN EXIT FUNCTION
simplevarfound: simplevarfound:
@ -18579,7 +18599,7 @@ FUNCTION findid& (n2$)
t = id.t t = id.t
temp$ = refer$(str2$(i), t, 1) temp$ = refer$(str2$(i), t, 1)
manageVariableList "", temp$, 1 manageVariableList "", temp$, 0, 1
currentid = i currentid = i
EXIT FUNCTION EXIT FUNCTION
@ -25869,7 +25889,7 @@ SUB dump_udts
CLOSE #f CLOSE #f
END SUB END SUB
SUB manageVariableList (__name$, __cname$, action AS _BYTE) SUB manageVariableList (__name$, __cname$, localIndex AS LONG, action AS _BYTE)
DIM findItem AS LONG, cname$, i AS LONG, name$ DIM findItem AS LONG, cname$, i AS LONG, name$
name$ = __name$ name$ = __name$
cname$ = __cname$ cname$ = __cname$
@ -25905,9 +25925,11 @@ SUB manageVariableList (__name$, __cname$, action AS _BYTE)
usedVariableList(i).includedFile = "" usedVariableList(i).includedFile = ""
END IF END IF
usedVariableList(i).scope = subfuncn usedVariableList(i).scope = subfuncn
usedVariableList(i).subfunc = subfunc
usedVariableList(i).cname = cname$ usedVariableList(i).cname = cname$
IF LEN(RTRIM$(id.musthave)) > 0 THEN name$ = name$ + RTRIM$(id.musthave) usedVariableList(i).localIndex = localIndex
usedVariableList(i).name = name$ IF LEN(RTRIM$(id.mayhave)) = 0 AND LEN(RTRIM$(id.musthave)) > 0 THEN usedVariableList(i).name = name$ + RTRIM$(id.musthave)
IF LEN(RTRIM$(id.musthave)) = 0 AND LEN(RTRIM$(id.mayhave)) > 0 THEN usedVariableList(i).name = name$ + RTRIM$(id.mayhave)
totalVariablesCreated = totalVariablesCreated + 1 totalVariablesCreated = totalVariablesCreated + 1
END IF END IF
CASE ELSE 'find and mark as used CASE ELSE 'find and mark as used