bugfixes; step one for 'var T' as return type support
This commit is contained in:
parent
e7135c449d
commit
2f066395ba
27 changed files with 234 additions and 68 deletions
|
|
@ -186,8 +186,8 @@ type
|
|||
nkReturnToken # token used for interpretation
|
||||
TNodeKinds* = set[TNodeKind]
|
||||
|
||||
type
|
||||
TSymFlag* = enum # already 30 flags!
|
||||
type
|
||||
TSymFlag* = enum # already 29 flags!
|
||||
sfUsed, # read access of sym (for warnings) or simply used
|
||||
sfStar, # symbol has * visibility
|
||||
sfMinus, # symbol has - visibility
|
||||
|
|
@ -204,7 +204,6 @@ type
|
|||
sfRegister, # variable should be placed in a register
|
||||
sfPure, # object is "pure" that means it has no type-information
|
||||
|
||||
sfResult, # variable is 'result' in proc
|
||||
sfNoSideEffect, # proc has no side effects
|
||||
sfSideEffect, # proc may have side effects; cannot prove it has none
|
||||
sfMainModule, # module is the main module
|
||||
|
|
@ -293,6 +292,7 @@ type
|
|||
skType, # a type
|
||||
skConst, # a constant
|
||||
skVar, # a variable
|
||||
skResult, # special 'result' variable
|
||||
skProc, # a proc
|
||||
skMethod, # a method
|
||||
skIterator, # an iterator
|
||||
|
|
|
|||
|
|
@ -136,7 +136,7 @@ proc getStorageLoc(n: PNode): TStorageLoc =
|
|||
case n.sym.kind
|
||||
of skParam, skForVar, skTemp:
|
||||
result = OnStack
|
||||
of skVar:
|
||||
of skVar, skResult:
|
||||
if sfGlobal in n.sym.flags: result = OnHeap
|
||||
else: result = OnStack
|
||||
of skConst:
|
||||
|
|
@ -206,6 +206,10 @@ proc genGenericAsgn(p: BProc, dest, src: TLoc, flags: TAssignmentFlags) =
|
|||
proc genAssignment(p: BProc, dest, src: TLoc, flags: TAssignmentFlags) =
|
||||
# This function replaces all other methods for generating
|
||||
# the assignment operation in C.
|
||||
if src.t != nil and src.t.kind == tyPtr:
|
||||
# little HACK to suppor the new 'var T' as return type:
|
||||
appcg(p, cpsStmts, "$1 = $2;$n", [rdLoc(dest), rdLoc(src)])
|
||||
return
|
||||
var ty = skipTypes(dest.t, abstractVarRange)
|
||||
case ty.kind
|
||||
of tyRef:
|
||||
|
|
@ -1648,7 +1652,7 @@ proc expr(p: BProc, e: PNode, d: var TLoc) =
|
|||
genComplexConst(p, sym, d)
|
||||
of skEnumField:
|
||||
putIntoDest(p, d, e.typ, toRope(sym.position))
|
||||
of skVar:
|
||||
of skVar, skResult:
|
||||
if sfGlobal in sym.flags: genVarPrototype(p.module, sym)
|
||||
if ((sym.loc.r == nil) or (sym.loc.t == nil)):
|
||||
InternalError(e.info, "expr: var not init " & sym.name.s)
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ proc mangleName(s: PSym): PRope =
|
|||
case s.kind
|
||||
of skProc, skMethod, skConverter, skConst:
|
||||
result = toRope("@")
|
||||
of skVar:
|
||||
of skVar, skResult:
|
||||
if sfGlobal in s.flags: result = toRope("@")
|
||||
else: result = toRope("%")
|
||||
of skForVar, skTemp, skParam, skType, skEnumField, skModule:
|
||||
|
|
@ -153,7 +153,7 @@ proc getGlobalTempName(): PRope =
|
|||
|
||||
proc ccgIntroducedPtr(s: PSym): bool =
|
||||
var pt = s.typ
|
||||
assert(not (sfResult in s.flags))
|
||||
assert skResult != s.kind
|
||||
case pt.Kind
|
||||
of tyObject:
|
||||
# XXX quick hack floatSize*2 for the pegs module under 64bit
|
||||
|
|
|
|||
|
|
@ -534,7 +534,7 @@ proc cgsym(m: BModule, name: string): PRope =
|
|||
if sym != nil:
|
||||
case sym.kind
|
||||
of skProc, skMethod, skConverter: genProc(m, sym)
|
||||
of skVar: genVarPrototype(m, sym)
|
||||
of skVar, skResult: genVarPrototype(m, sym)
|
||||
of skType: discard getTypeDesc(m, sym.typ)
|
||||
else: InternalError("cgsym: " & name)
|
||||
else:
|
||||
|
|
|
|||
|
|
@ -810,7 +810,7 @@ proc generateDoc(d: PDoc, n: PNode) =
|
|||
|
||||
proc genSection(d: PDoc, kind: TSymKind) =
|
||||
const sectionNames: array[skModule..skTemplate, string] = [
|
||||
"Imports", "Types", "Consts", "Vars", "Procs", "Methods",
|
||||
"Imports", "Types", "Consts", "Vars", "Vars", "Procs", "Methods",
|
||||
"Iterators", "Converters", "Macros", "Templates"
|
||||
]
|
||||
if d.section[kind] == nil: return
|
||||
|
|
|
|||
|
|
@ -832,7 +832,7 @@ proc genAddr(p: var TProc, n: PNode, r: var TCompRes) =
|
|||
s = n.sons[0].sym
|
||||
if s.loc.r == nil: InternalError(n.info, "genAddr: 3")
|
||||
case s.kind
|
||||
of skVar:
|
||||
of skVar, skResult:
|
||||
if mapType(n.typ) == etyObject:
|
||||
# make addr() a no-op:
|
||||
r.kind = etyNone
|
||||
|
|
@ -863,7 +863,7 @@ proc genSym(p: var TProc, n: PNode, r: var TCompRes) =
|
|||
if s.loc.r == nil:
|
||||
InternalError(n.info, "symbol has no generated name: " & s.name.s)
|
||||
case s.kind
|
||||
of skVar, skParam, skTemp:
|
||||
of skVar, skParam, skTemp, skResult:
|
||||
var k = mapType(s.typ)
|
||||
if k == etyBaseIndex:
|
||||
r.kind = etyBaseIndex
|
||||
|
|
|
|||
|
|
@ -293,7 +293,7 @@ proc evalVariable(c: PStackFrame, sym: PSym, flags: TEvalFlags): PNode =
|
|||
# which can be modified.
|
||||
var x = c
|
||||
while x != nil:
|
||||
if sfResult in sym.flags:
|
||||
if sym.kind == skResult:
|
||||
result = x.params[0]
|
||||
if result == nil: result = emptyNode
|
||||
return
|
||||
|
|
@ -425,7 +425,8 @@ proc evalSwap(c: PEvalContext, n: PNode): PNode =
|
|||
proc evalSym(c: PEvalContext, n: PNode, flags: TEvalFlags): PNode =
|
||||
case n.sym.kind
|
||||
of skProc, skConverter, skMacro: result = n.sym.ast.sons[codePos]
|
||||
of skVar, skForVar, skTemp: result = evalVariable(c.tos, n.sym, flags)
|
||||
of skVar, skForVar, skTemp, skResult:
|
||||
result = evalVariable(c.tos, n.sym, flags)
|
||||
of skParam:
|
||||
# XXX what about LValue?
|
||||
result = c.tos.params[n.sym.position + 1]
|
||||
|
|
|
|||
|
|
@ -393,7 +393,7 @@ proc UseMagic(m: BModule, name: string) =
|
|||
if sym != nil:
|
||||
case sym.kind
|
||||
of skProc, skMethod, skConverter: genProc(m, sym)
|
||||
of skVar: genVarPrototype(m, sym)
|
||||
of skVar, skResult: genVarPrototype(m, sym)
|
||||
of skType: discard getTypeDesc(m, sym.typ)
|
||||
else: InternalError("useMagic: " & name)
|
||||
elif not (sfSystemModule in m.module.flags):
|
||||
|
|
|
|||
|
|
@ -56,7 +56,8 @@ type
|
|||
errResultCannotBeOpenArray, errSizeTooBig, errSetTooBig,
|
||||
errBaseTypeMustBeOrdinal, errInheritanceOnlyWithNonFinalObjects,
|
||||
errInheritanceOnlyWithEnums, errIllegalRecursionInTypeX,
|
||||
errCannotInstantiateX, errExprHasNoAddress, errVarForOutParamNeeded,
|
||||
errCannotInstantiateX, errExprHasNoAddress, errXStackEscape,
|
||||
errVarForOutParamNeeded,
|
||||
errPureTypeMismatch, errTypeMismatch, errButExpected, errButExpectedX,
|
||||
errAmbiguousCallXYZ, errWrongNumberOfArguments, errXCannotBePassedToProcVar,
|
||||
errXCannotBeInParamDecl, errPragmaOnlyInHeaderOfProc, errImplOfXNotAllowed,
|
||||
|
|
@ -227,6 +228,7 @@ const
|
|||
errIllegalRecursionInTypeX: "illegal recursion in type \'$1\'",
|
||||
errCannotInstantiateX: "cannot instantiate: \'$1\'",
|
||||
errExprHasNoAddress: "expression has no address",
|
||||
errXStackEscape: "address of '$1' may not escape its stack frame",
|
||||
errVarForOutParamNeeded: "for a \'var\' type a variable needs to be passed",
|
||||
errPureTypeMismatch: "type mismatch",
|
||||
errTypeMismatch: "type mismatch: got (",
|
||||
|
|
|
|||
|
|
@ -50,6 +50,10 @@ proc addResult(c: PContext, t: PType, info: TLineInfo)
|
|||
proc addResultNode(c: PContext, n: PNode)
|
||||
proc instGenericContainer(c: PContext, n: PNode, header: PType): PType
|
||||
|
||||
proc ParamsTypeCheck(c: PContext, typ: PType) {.inline.} =
|
||||
if not typeAllowed(typ, skConst):
|
||||
GlobalError(typ.n.info, errXisNoType, typeToString(typ))
|
||||
|
||||
proc semConstExpr(c: PContext, n: PNode): PNode =
|
||||
result = semExprWithType(c, n)
|
||||
if result == nil:
|
||||
|
|
|
|||
|
|
@ -21,20 +21,31 @@ proc semTemplateExpr(c: PContext, n: PNode, s: PSym, semCheck = true): PNode =
|
|||
|
||||
proc semFieldAccess(c: PContext, n: PNode, flags: TExprFlags = {}): PNode
|
||||
|
||||
proc newDeref(n: PNode): PNode {.inline.} =
|
||||
result = newNodeIT(nkHiddenDeref, n.info, n.typ.sons[0])
|
||||
addSon(result, n)
|
||||
|
||||
proc semExprWithType(c: PContext, n: PNode, flags: TExprFlags = {}): PNode =
|
||||
result = semExpr(c, n, flags)
|
||||
if result.kind == nkEmpty:
|
||||
# do not produce another redundant error message:
|
||||
raiseRecoverableError()
|
||||
if result.typ != nil:
|
||||
if result.typ.kind == tyVar:
|
||||
var d = newNodeIT(nkHiddenDeref, result.info, result.typ.sons[0])
|
||||
addSon(d, result)
|
||||
result = d
|
||||
if result.typ.kind == tyVar: result = newDeref(result)
|
||||
else:
|
||||
GlobalError(n.info, errExprXHasNoType,
|
||||
renderTree(result, {renderNoComments}))
|
||||
|
||||
proc semExprWithTypeNoDeref(c: PContext, n: PNode,
|
||||
flags: TExprFlags = {}): PNode =
|
||||
result = semExpr(c, n, flags)
|
||||
if result.kind == nkEmpty:
|
||||
# do not produce another redundant error message:
|
||||
raiseRecoverableError()
|
||||
if result.typ == nil:
|
||||
GlobalError(n.info, errExprXHasNoType,
|
||||
renderTree(result, {renderNoComments}))
|
||||
|
||||
proc semSymGenericInstantiation(c: PContext, n: PNode, s: PSym): PNode =
|
||||
result = symChoice(c, n, s)
|
||||
|
||||
|
|
@ -67,7 +78,7 @@ proc semSym(c: PContext, n: PNode, s: PSym, flags: TExprFlags): PNode =
|
|||
result = newSymNode(s, n.info)
|
||||
of skMacro: result = semMacroExpr(c, n, s)
|
||||
of skTemplate: result = semTemplateExpr(c, n, s)
|
||||
of skVar:
|
||||
of skVar, skResult:
|
||||
markUsed(n, s)
|
||||
# if a proc accesses a global variable, it is not side effect free:
|
||||
if sfGlobal in s.flags: incl(c.p.owner.flags, sfSideEffect)
|
||||
|
|
@ -330,33 +341,37 @@ type
|
|||
TAssignableResult = enum
|
||||
arNone, # no l-value and no discriminant
|
||||
arLValue, # is an l-value
|
||||
arLocalLValue, # is an l-value, but local var; must not escape
|
||||
# its stack frame!
|
||||
arDiscriminant # is a discriminant
|
||||
|
||||
proc isAssignable(n: PNode): TAssignableResult =
|
||||
proc isAssignable(c: PContext, n: PNode): TAssignableResult =
|
||||
result = arNone
|
||||
case n.kind
|
||||
of nkSym:
|
||||
if n.sym.kind in {skVar, skTemp}: result = arLValue
|
||||
of nkSym:
|
||||
if n.sym.kind in {skVar, skResult, skTemp}:
|
||||
if c.p.owner.id == n.sym.owner.id: result = arLocalLValue
|
||||
else: result = arLValue
|
||||
of nkDotExpr:
|
||||
if skipTypes(n.sons[0].typ, abstractInst).kind in {tyVar, tyPtr, tyRef}:
|
||||
result = arLValue
|
||||
else:
|
||||
result = isAssignable(n.sons[0])
|
||||
if result == arLValue and sfDiscriminant in n.sons[1].sym.flags:
|
||||
result = isAssignable(c, n.sons[0])
|
||||
if result != arNone and sfDiscriminant in n.sons[1].sym.flags:
|
||||
result = arDiscriminant
|
||||
of nkBracketExpr:
|
||||
if skipTypes(n.sons[0].typ, abstractInst).kind in {tyVar, tyPtr, tyRef}:
|
||||
result = arLValue
|
||||
else:
|
||||
result = isAssignable(n.sons[0])
|
||||
else:
|
||||
result = isAssignable(c, n.sons[0])
|
||||
of nkHiddenStdConv, nkHiddenSubConv, nkConv:
|
||||
# Object and tuple conversions are still addressable, so we skip them
|
||||
if skipTypes(n.typ, abstractPtrs).kind in {tyOpenArray, tyTuple, tyObject}:
|
||||
result = isAssignable(n.sons[1])
|
||||
result = isAssignable(c, n.sons[1])
|
||||
of nkHiddenDeref, nkDerefExpr:
|
||||
result = arLValue
|
||||
of nkObjUpConv, nkObjDownConv, nkCheckedFieldExpr:
|
||||
result = isAssignable(n.sons[0])
|
||||
result = isAssignable(c, n.sons[0])
|
||||
else:
|
||||
nil
|
||||
|
||||
|
|
@ -367,7 +382,7 @@ proc newHiddenAddrTaken(c: PContext, n: PNode): PNode =
|
|||
else:
|
||||
result = newNodeIT(nkHiddenAddr, n.info, makeVarType(c, n.typ))
|
||||
addSon(result, n)
|
||||
if isAssignable(n) != arLValue:
|
||||
if isAssignable(c, n) notin {arLValue, arLocalLValue}:
|
||||
localError(n.info, errVarForOutParamNeeded)
|
||||
|
||||
proc analyseIfAddressTaken(c: PContext, n: PNode): PNode =
|
||||
|
|
@ -403,7 +418,7 @@ proc analyseIfAddressTakenInCall(c: PContext, n: PNode) =
|
|||
for i in countup(1, sonsLen(n) - 1):
|
||||
if i < sonsLen(t) and t.sons[i] != nil and
|
||||
skipTypes(t.sons[i], abstractInst).kind == tyVar:
|
||||
if isAssignable(n.sons[i]) != arLValue:
|
||||
if isAssignable(c, n.sons[i]) notin {arLValue, arLocalLValue}:
|
||||
LocalError(n.sons[i].info, errVarForOutParamNeeded)
|
||||
return
|
||||
for i in countup(1, sonsLen(n) - 1):
|
||||
|
|
@ -751,7 +766,30 @@ proc propertyWriteAccess(c: PContext, n, a: PNode): PNode =
|
|||
else:
|
||||
globalError(n.Info, errUndeclaredFieldX, id.s)
|
||||
|
||||
proc semAsgn(c: PContext, n: PNode): PNode =
|
||||
proc takeImplicitAddr(c: PContext, n: PNode): PNode =
|
||||
case n.kind
|
||||
of nkHiddenAddr, nkAddr: return n
|
||||
of nkHiddenDeref, nkDerefExpr: return n.sons[0]
|
||||
of nkBracketExpr:
|
||||
if len(n) == 1: return n.sons[0]
|
||||
else: nil
|
||||
var valid = isAssignable(c, n)
|
||||
if valid != arLValue:
|
||||
if valid == arLocalLValue:
|
||||
GlobalError(n.info, errXStackEscape, renderTree(n, {renderNoComments}))
|
||||
else:
|
||||
GlobalError(n.info, errExprHasNoAddress)
|
||||
result = newNodeIT(nkHiddenAddr, n.info, makePtrType(c, n.typ))
|
||||
result.add(n)
|
||||
|
||||
proc asgnToResultVar(c: PContext, n, le, ri: PNode) {.inline.} =
|
||||
if le.kind == nkHiddenDeref:
|
||||
var x = le.sons[0]
|
||||
if x.typ.kind == tyVar and x.kind == nkSym and x.sym.kind == skResult:
|
||||
n.sons[0] = x # 'result[]' --> 'result'
|
||||
n.sons[1] = takeImplicitAddr(c, ri)
|
||||
|
||||
proc semAsgn(c: PContext, n: PNode): PNode =
|
||||
checkSonsLen(n, 2)
|
||||
var a = n.sons[0]
|
||||
case a.kind
|
||||
|
|
@ -762,8 +800,8 @@ proc semAsgn(c: PContext, n: PNode): PNode =
|
|||
if a == nil:
|
||||
return propertyWriteAccess(c, n, n[0])
|
||||
of nkBracketExpr:
|
||||
# a[i..j] = x
|
||||
# --> `[..]=`(a, i, j, x)
|
||||
# a[i] = x
|
||||
# --> `[]=`(a, i, x)
|
||||
a = semSubscript(c, a, {efLValue})
|
||||
if a == nil:
|
||||
result = buildOverloadedSubscripts(n.sons[0], inAsgn=true)
|
||||
|
|
@ -772,15 +810,19 @@ proc semAsgn(c: PContext, n: PNode): PNode =
|
|||
else:
|
||||
a = semExprWithType(c, a, {efLValue})
|
||||
n.sons[0] = a
|
||||
n.sons[1] = semExprWithType(c, n.sons[1])
|
||||
# a = b # both are vars, means: a[] = b[]
|
||||
# a = b # b no 'var T' means: a = addr(b)
|
||||
var le = a.typ
|
||||
if skipTypes(le, {tyGenericInst}).kind != tyVar and IsAssignable(a) == arNone:
|
||||
if skipTypes(le, {tyGenericInst}).kind != tyVar and
|
||||
IsAssignable(c, a) == arNone:
|
||||
# Direct assignment to a discriminant is allowed!
|
||||
localError(a.info, errXCannotBeAssignedTo,
|
||||
renderTree(a, {renderNoComments}))
|
||||
else:
|
||||
else:
|
||||
n.sons[1] = semExprWithType(c, n.sons[1])
|
||||
n.sons[1] = fitNode(c, le, n.sons[1])
|
||||
fixAbstractType(c, n)
|
||||
asgnToResultVar(c, n, n.sons[0], n.sons[1])
|
||||
result = n
|
||||
|
||||
proc lookUpForDefined(c: PContext, i: PIdent, onlyCurrentScope: bool): PSym =
|
||||
|
|
@ -1144,7 +1186,7 @@ proc semExpr(c: PContext, n: PNode, flags: TExprFlags = {}): PNode =
|
|||
result = n
|
||||
checkSonsLen(n, 1)
|
||||
n.sons[0] = semExprWithType(c, n.sons[0])
|
||||
if isAssignable(n.sons[0]) != arLValue:
|
||||
if isAssignable(c, n.sons[0]) notin {arLValue, arLocalLValue}:
|
||||
GlobalError(n.info, errExprHasNoAddress)
|
||||
n.typ = makePtrType(c, n.sons[0].typ)
|
||||
of nkHiddenAddr, nkHiddenDeref:
|
||||
|
|
|
|||
|
|
@ -100,6 +100,7 @@ proc generateInstance(c: PContext, fn: PSym, pt: TIdTable,
|
|||
result.typ = newTypeS(tyProc, c)
|
||||
addSon(result.typ, nil)
|
||||
result.typ.callConv = fn.typ.callConv
|
||||
ParamsTypeCheck(c, result.typ)
|
||||
var oldPrc = GenericCacheGet(c, entry)
|
||||
if oldPrc == nil:
|
||||
# add it here, so that recursive generic procs are possible:
|
||||
|
|
|
|||
|
|
@ -164,7 +164,7 @@ proc SemReturn(c: PContext, n: PNode): PNode =
|
|||
addSon(a, n.sons[0])
|
||||
n.sons[0] = semAsgn(c, a)
|
||||
# optimize away ``result = result``:
|
||||
if n[0][1].kind == nkSym and sfResult in n[0][1].sym.flags:
|
||||
if n[0][1].kind == nkSym and n[0][1].sym.kind == skResult:
|
||||
n.sons[0] = ast.emptyNode
|
||||
|
||||
proc SemYield(c: PContext, n: PNode): PNode =
|
||||
|
|
@ -544,10 +544,9 @@ proc sideEffectsCheck(c: PContext, s: PSym) =
|
|||
|
||||
proc addResult(c: PContext, t: PType, info: TLineInfo) =
|
||||
if t != nil:
|
||||
var s = newSym(skVar, getIdent"result", getCurrOwner())
|
||||
var s = newSym(skResult, getIdent"result", getCurrOwner())
|
||||
s.info = info
|
||||
s.typ = t
|
||||
incl(s.flags, sfResult)
|
||||
incl(s.flags, sfUsed)
|
||||
addDecl(c, s)
|
||||
c.p.resultSym = s
|
||||
|
|
@ -569,7 +568,8 @@ proc semLambda(c: PContext, n: PNode): PNode =
|
|||
if n.sons[paramsPos].kind != nkEmpty:
|
||||
semParamList(c, n.sons[ParamsPos], nil, s)
|
||||
addParams(c, s.typ.n)
|
||||
else:
|
||||
ParamsTypeCheck(c, s.typ)
|
||||
else:
|
||||
s.typ = newTypeS(tyProc, c)
|
||||
addSon(s.typ, nil)
|
||||
s.typ.callConv = ccClosure
|
||||
|
|
@ -664,6 +664,7 @@ proc semProcAux(c: PContext, n: PNode, kind: TSymKind,
|
|||
if sfBorrow in s.flags:
|
||||
LocalError(n.sons[codePos].info, errImplOfXNotAllowed, s.name.s)
|
||||
if n.sons[genericParamsPos].kind == nkEmpty:
|
||||
ParamsTypeCheck(c, s.typ)
|
||||
pushProcCon(c, s)
|
||||
if (s.typ.sons[0] != nil) and (kind != skIterator):
|
||||
addResult(c, s.typ.sons[0], n.info)
|
||||
|
|
|
|||
|
|
@ -107,7 +107,7 @@ proc analyseSym(c: PProcCtx, n: PNode): TThreadOwner =
|
|||
result = c.mapping[v.id]
|
||||
if result != toUndefined: return
|
||||
case v.kind
|
||||
of skVar:
|
||||
of skVar, skResult:
|
||||
result = toNil
|
||||
if sfGlobal in v.flags:
|
||||
if sfThreadVar in v.flags:
|
||||
|
|
@ -192,9 +192,13 @@ proc analyseCall(c: PProcCtx, n: PNode): TThreadOwner =
|
|||
if prc.ast.sons[codePos].kind == nkEmpty and
|
||||
{sfNoSideEffect, sfThread, sfImportc} * prc.flags == {}:
|
||||
Message(n.info, warnAnalysisLoophole, renderTree(n))
|
||||
if result == toUndefined: result = toNil
|
||||
if prc.typ.sons[0] != nil:
|
||||
if prc.ast.len > resultPos:
|
||||
result = newCtx.mapping[prc.ast.sons[resultPos].sym.id]
|
||||
# if the proc body does not set 'result', nor 'return's something
|
||||
# explicitely, it returns a binary zero, so 'toNil' is correct:
|
||||
if result == toUndefined: result = toNil
|
||||
else:
|
||||
result = toNil
|
||||
else:
|
||||
|
|
|
|||
|
|
@ -480,8 +480,8 @@ proc semObjectNode(c: PContext, n: PNode, prev: PType): PType =
|
|||
# n.sons[0] contains the pragmas (if any). We process these later...
|
||||
checkSonsLen(n, 3)
|
||||
if n.sons[1].kind != nkEmpty:
|
||||
base = semTypeNode(c, n.sons[1].sons[0], nil)
|
||||
var concreteBase = skipGenericInvokation(skipTypes(base, skipPtrs))
|
||||
base = skipTypes(semTypeNode(c, n.sons[1].sons[0], nil), skipPtrs)
|
||||
var concreteBase = skipGenericInvokation(base)
|
||||
if concreteBase.kind == tyObject and tfFinal notin concreteBase.flags:
|
||||
addInheritedFields(c, check, pos, concreteBase)
|
||||
else:
|
||||
|
|
@ -528,10 +528,10 @@ proc addTypeVarsOfGenericBody(c: PContext, t: PType, genericParams: PNode,
|
|||
|
||||
proc paramType(c: PContext, n, genericParams: PNode, cl: var TIntSet): PType =
|
||||
result = semTypeNode(c, n, nil)
|
||||
if (genericParams != nil) and (sonsLen(genericParams) == 0):
|
||||
if genericParams != nil and sonsLen(genericParams) == 0:
|
||||
result = addTypeVarsOfGenericBody(c, result, genericParams, cl)
|
||||
#if result.kind == tyGenericInvokation: debug(result)
|
||||
|
||||
|
||||
proc semProcTypeNode(c: PContext, n, genericParams: PNode,
|
||||
prev: PType): PType =
|
||||
var
|
||||
|
|
|
|||
|
|
@ -526,12 +526,12 @@ proc gatherVars(c: PTransf, n: PNode, marked: var TIntSet, owner: PSym,
|
|||
container: PNode) =
|
||||
# gather used vars for closure generation
|
||||
case n.kind
|
||||
of nkSym:
|
||||
of nkSym:
|
||||
var s = n.sym
|
||||
var found = false
|
||||
case s.kind
|
||||
of skVar: found = sfGlobal notin s.flags
|
||||
of skTemp, skForVar, skParam: found = true
|
||||
of skTemp, skForVar, skParam, skResult: found = true
|
||||
else: nil
|
||||
if found and owner.id != s.owner.id and not ContainsOrIncl(marked, s.id):
|
||||
incl(s.flags, sfInClosure)
|
||||
|
|
|
|||
|
|
@ -758,8 +758,8 @@ proc typeAllowedNode(marker: var TIntSet, n: PNode, kind: TSymKind): bool =
|
|||
result = typeAllowedNode(marker, n.sons[i], kind)
|
||||
if not result: return
|
||||
|
||||
proc typeAllowedAux(marker: var TIntSet, typ: PType, kind: TSymKind): bool =
|
||||
assert(kind in {skVar, skConst, skParam})
|
||||
proc typeAllowedAux(marker: var TIntSet, typ: PType, kind: TSymKind): bool =
|
||||
assert(kind in {skVar, skConst, skParam, skResult})
|
||||
# if we have already checked the type, return true, because we stop the
|
||||
# evaluation if something is wrong:
|
||||
result = true
|
||||
|
|
@ -773,13 +773,14 @@ proc typeAllowedAux(marker: var TIntSet, typ: PType, kind: TSymKind): bool =
|
|||
of tyVar:
|
||||
result = false # ``var var`` is always an invalid type:
|
||||
of tyOpenArray:
|
||||
result = (kind == skParam) and typeAllowedAux(marker, t2, kind)
|
||||
else: result = (kind != skConst) and typeAllowedAux(marker, t2, kind)
|
||||
result = kind == skParam and typeAllowedAux(marker, t2, kind)
|
||||
else:
|
||||
result = kind in {skParam, skResult} and typeAllowedAux(marker, t2, kind)
|
||||
of tyProc:
|
||||
for i in countup(1, sonsLen(t) - 1):
|
||||
result = typeAllowedAux(marker, t.sons[i], skParam)
|
||||
if not result: return
|
||||
if t.sons[0] != nil: result = typeAllowedAux(marker, t.sons[0], skVar)
|
||||
if t.sons[0] != nil: result = typeAllowedAux(marker, t.sons[0], skResult)
|
||||
of tyExpr, tyStmt, tyTypeDesc:
|
||||
result = true
|
||||
of tyGenericBody, tyGenericParam, tyForward, tyNone, tyGenericInvokation:
|
||||
|
|
@ -799,10 +800,11 @@ proc typeAllowedAux(marker: var TIntSet, typ: PType, kind: TSymKind): bool =
|
|||
result = (kind == skParam) and typeAllowedAux(marker, t.sons[0], skVar)
|
||||
of tySequence:
|
||||
result = (kind != skConst) and typeAllowedAux(marker, t.sons[0], skVar) or
|
||||
(t.sons[0].kind == tyEmpty)
|
||||
of tyArray:
|
||||
result = typeAllowedAux(marker, t.sons[1], skVar)
|
||||
of tyPtr, tyRef:
|
||||
t.sons[0].kind == tyEmpty
|
||||
of tyArray:
|
||||
result = typeAllowedAux(marker, t.sons[1], skVar) or
|
||||
t.sons[1].kind == tyEmpty
|
||||
of tyPtr, tyRef:
|
||||
result = typeAllowedAux(marker, t.sons[0], skVar)
|
||||
of tyArrayConstr, tyTuple, tySet:
|
||||
for i in countup(0, sonsLen(t) - 1):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue