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

Extends the new DIM syntax to SHARED (subs)

e.g. SHARED AS _BYTE array(), index
This commit is contained in:
Fellippe Heitor 2021-01-26 04:01:36 -03:00
parent 61796209bd
commit fd0b44aee4

View file

@ -7009,8 +7009,10 @@ DO
'get variable name
n$ = getelement$(ca$, i): i = i + 1
IF n$ = "" THEN a$ = "Expected SHARED variable-name": GOTO errmes
IF n$ = "" THEN a$ = "Expected SHARED variable-name or SHARED AS type variable-name": GOTO errmes
IF UCASE$(n$) <> "AS" THEN
'traditional dim syntax for SHARED
s$ = removesymbol(n$)
IF Error_Happened THEN GOTO errmes
l2$ = s$ 'either symbol or nothing
@ -7070,6 +7072,7 @@ DO
s$ = defineextaz(v)
END IF
NormalSharedBlock:
'switch to main module
oldsubfunc$ = subfunc$
subfunc$ = ""
@ -7125,7 +7128,16 @@ DO
'note: variable created!
shrfound:
IF newSharedSyntax = 0 THEN
l$ = l$ + sp + RTRIM$(id.cn) + l2$
ELSE
IF sharedAsLayoutAdded = 0 THEN
sharedAsLayoutAdded = -1
l$ = l$ + l2$ + sp$ + RTRIM$(id.cn) + l3$
ELSE
l$ = l$ + sp$ + RTRIM$(id.cn) + l3$
END IF
END IF
ids(currentid).share = ids(currentid).share OR 2 'set as temporarily shared
@ -7145,11 +7157,94 @@ DO
CLOSE #13: OPEN tmpdir$ + "data" + str2$(subfuncn) + ".txt" FOR APPEND AS #13
CLOSE #19: OPEN tmpdir$ + "free" + str2$(subfuncn) + ".txt" FOR APPEND AS #19
IF newSharedSyntax THEN RETURN
IF getelement$(a$, i) = "," THEN i = i + 1: l$ = l$ + sp2 + ",": GOTO subfuncshr
IF getelement$(a$, i) <> "" THEN a$ = "Expected ,": GOTO errmes
layoutdone = 1: IF LEN(layout$) THEN layout$ = layout$ + sp + l$ ELSE layout$ = l$
GOTO finishedline
ELSE
'new dim syntax for SHARED!
i = i - 1 'relocate back to "AS"
'estabilish the data type:
t$ = ""
ts$ = ""
t3$ = ""
n$ = ""
previousElement$ = ""
l2$ = sp + "AS"
sharedAsLayoutAdded = 0
getshrtyp2:
i = i + 1
t2$ = getelement$(a$, i)
IF t2$ <> "," AND t2$ <> "(" AND t2$ <> "" THEN
'get first variable name
n$ = getelement$(ca$, i)
IF LEN(previousElement$) THEN
IF t$ = "" THEN t$ = previousElement$ ELSE t$ = t$ + " " + previousElement$
IF t3$ = "" THEN t3$ = previousElement$ ELSE t3$ = t3$ + sp + previousElement$
END IF
previousElement$ = t2$
GOTO getshrtyp2
END IF
IF t$ = "" THEN a$ = "Expected SHARED AS type variable-name or SHARED variable-name AS type": GOTO errmes
t = typname2typ(t$)
IF Error_Happened THEN GOTO errmes
IF t AND ISINCONVENTIONALMEMORY THEN t = t - ISINCONVENTIONALMEMORY
IF t AND ISPOINTER THEN t = t - ISPOINTER
IF t AND ISREFERENCE THEN t = t - ISREFERENCE
tsize = typname2typsize
method = 0
IF (t AND ISUDT) = 0 THEN
ts$ = type2symbol$(t$)
ELSE
t3$ = RTRIM$(udtxcname(t AND 511))
IF RTRIM$(udtxcname(t AND 511)) = "_MEM" AND UCASE$(t$) = "MEM" AND qb64prefix_set = 1 THEN
t3$ = MID$(RTRIM$(udtxcname(t AND 511)), 2)
END IF
END IF
IF Error_Happened THEN GOTO errmes
l2$ = l2$ + sp + t3$
subfuncshr2:
s$ = removesymbol(n$)
IF Error_Happened THEN GOTO errmes
IF s$ <> "" THEN
a$ = "Cannot use type symbol with SHARED AS type variable-name (" + s$ + ")"
GOTO errmes
END IF
'array?
a = 0
l3$ = ""
IF getelement$(a$, i) = "(" THEN
IF getelement$(a$, i + 1) <> ")" THEN a$ = "Expected ()": GOTO errmes
i = i + 2
a = 1
l3$ = sp2 + "(" + sp2 + ")"
END IF
newSharedSyntax = -1
GOSUB NormalSharedBlock
newSharedSyntax = 0
IF getelement$(a$, i) = "," THEN
i = i + 1
l$ = l$ + sp2 + ","
'get next variable name
n$ = getelement$(ca$, i): i = i + 1
GOTO subfuncshr2
END IF
IF getelement$(a$, i) <> "" THEN a$ = "Expected ,": GOTO errmes
layoutdone = 1: IF LEN(layout$) THEN layout$ = layout$ + sp + l$ ELSE layout$ = l$
GOTO finishedline
END IF
END IF
END IF
@ -7509,7 +7604,7 @@ DO
'look for new dim syntax: DIM AS variabletype var1, var2, etc....
e$ = getelement$(a$, i)
IF e$ <> "AS" THEN
'no "AS", so this is the standard dim syntax
'no "AS", so this is the traditional dim syntax
dimnext:
notype = 0
listarray = 0
@ -7519,7 +7614,7 @@ DO
'chaincommonarray=0
varname$ = getelement(ca$, i): i = i + 1
IF varname$ = "" THEN a$ = "Expected DIM variable-name or DIM AS data-type variable-name": GOTO errmes
IF varname$ = "" THEN a$ = "Expected " + firstelement$ + " variable-name or " + firstelement$ + " AS type variable-name": GOTO errmes
'get the next element
IF i >= n + 1 THEN e$ = "" ELSE e$ = getelement(a$, i): i = i + 1
@ -8077,6 +8172,7 @@ DO
newDimSyntaxTypePassBack = 0
'estabilish the data type:
appendname$ = ""
appendtype$ = sp + "AS"
typ$ = ""
varname$ = ""
@ -8099,7 +8195,7 @@ DO
notype = 0
listarray = 0
IF typ$ = "" OR varname$ = "" THEN a$ = "Expected " + firstelement$ + " AS data-type variable-name or " + firstelement$ + " variable-name AS data-type": GOTO errmes
IF typ$ = "" OR varname$ = "" THEN a$ = "Expected " + firstelement$ + " AS type variable-name or " + firstelement$ + " variable-name AS type": GOTO errmes
'get the next element
IF i >= n + 1 THEN e$ = "" ELSE e$ = getelement(a$, i): i = i + 1
@ -8149,7 +8245,7 @@ DO
IF validname(varname$) = 0 THEN a$ = "Invalid variable name": GOTO errmes
IF s$ <> "" THEN
a$ = "Cannot use type symbol with DIM AS data-type variable-name (" + s$ + ")"
a$ = "Cannot use type symbol with " + firstelement$ + " AS type variable-name (" + s$ + ")"
GOTO errmes
END IF