'nil' as a statement is deprecated, use an empty 'discard' instead

This commit is contained in:
Araq 2014-01-19 16:54:59 +01:00
commit 73c6efdf66
54 changed files with 170 additions and 170 deletions

View file

@ -54,7 +54,7 @@ proc isPartOfAux(a, b: PType, marker: var TIntSet): TAnalysisResult =
for i in countup(0, sonsLen(a) - 1):
result = isPartOfAux(a.sons[i], b, marker)
if result == arYes: return
else: nil
else: discard
proc isPartOf(a, b: PType): TAnalysisResult =
## checks iff 'a' can be part of 'b'. Iterates over VALUE types!
@ -140,7 +140,7 @@ proc isPartOf*(a, b: PNode): TAnalysisResult =
result = isPartOf(a[1], b[1])
of nkObjUpConv, nkObjDownConv, nkCheckedFieldExpr:
result = isPartOf(a[0], b[0])
else: nil
else: discard
# Calls return a new location, so a default of ``arNo`` is fine.
else:
# go down recursively; this is quite demanding:
@ -177,6 +177,6 @@ proc isPartOf*(a, b: PNode): TAnalysisResult =
if isPartOf(a.typ, b.typ) != arNo:
result = isPartOf(a[0], b)
if result == arNo: result = arMaybe
else: nil
else: nil
else: discard
else: discard

View file

@ -1257,7 +1257,7 @@ proc propagateToOwner*(owner, elem: PType) =
owner.flags.incl tfNeedsInit
if tfNeedsInit in elem.flags:
if owner.kind in HaveTheirOwnEmpty: nil
if owner.kind in HaveTheirOwnEmpty: discard
else: owner.flags.incl tfNeedsInit
if tfShared in elem.flags:

View file

@ -73,7 +73,7 @@ proc isInCurrentFrame(p: BProc, n: PNode): bool =
result = false
of nkObjUpConv, nkObjDownConv, nkCheckedFieldExpr:
result = isInCurrentFrame(p, n.sons[0])
else: nil
else: discard
proc openArrayLoc(p: BProc, n: PNode): PRope =
var a: TLoc

View file

@ -202,7 +202,7 @@ proc asgnComplexity(n: PNode): int =
of nkRecList:
for t in items(n):
result += asgnComplexity(t)
else: nil
else: discard
proc optAsgnLoc(a: TLoc, t: PType, field: PRope): TLoc =
result.k = locField
@ -228,7 +228,7 @@ proc genOptAsgnObject(p: BProc, dest, src: TLoc, flags: TAssignmentFlags,
optAsgnLoc(src, field.typ, field.loc.r), flags)
of nkRecList:
for child in items(t): genOptAsgnObject(p, dest, src, flags, child)
else: nil
else: discard
proc genGenericAsgn(p: BProc, dest, src: TLoc, flags: TAssignmentFlags) =
# Consider:
@ -1901,7 +1901,7 @@ proc expr(p: BProc, n: PNode, d: var TLoc) =
of nkClosure: genClosure(p, n, d)
of nkMetaNode: expr(p, n.sons[0], d)
of nkEmpty: nil
of nkEmpty: discard
of nkWhileStmt: genWhileStmt(p, n)
of nkVarSection, nkLetSection: genVarStmt(p, n)
of nkConstSection: genConstStmt(p, n)
@ -1931,7 +1931,7 @@ proc expr(p: BProc, n: PNode, d: var TLoc) =
of nkCommentStmt, nkIteratorDef, nkIncludeStmt,
nkImportStmt, nkImportExceptStmt, nkExportStmt, nkExportExceptStmt,
nkFromStmt, nkTemplateDef, nkMacroDef:
nil
discard
of nkPragma: genPragma(p, n)
of nkProcDef, nkMethodDef, nkConverterDef:
if (n.sons[genericParamsPos].kind == nkEmpty):

View file

@ -285,7 +285,7 @@ proc readMergeSections(cfilename: string, m: var TMergeSections) =
withCFile(cfilename):
readKey(L, k)
if k == "NIM_merge_INFO":
nil
discard
elif ^L.bufpos == '*' and ^(L.bufpos+1) == '/':
inc(L.bufpos, 2)
# read back into section

View file

@ -83,7 +83,7 @@ proc genTraverseProc(c: var TTraversalClosure, accessor: PRope, typ: PType) =
if typ.callConv == ccClosure:
lineCg(p, cpsStmts, c.visitorFrmt, rfmt(nil, "$1.ClEnv", accessor))
else:
nil
discard
proc genTraverseProcSeq(c: var TTraversalClosure, accessor: PRope, typ: PType) =
var p = c.p

View file

@ -25,7 +25,7 @@ proc mangleField(name: string): string =
of 'A'..'Z':
add(result, chr(ord(name[i]) - ord('A') + ord('a')))
of '_':
nil
discard
of 'a'..'z', '0'..'9':
add(result, name[i])
else:
@ -48,7 +48,7 @@ proc mangle(name: string): string =
of 'A'..'Z':
add(result, chr(ord(name[i]) - ord('A') + ord('a')))
of '_':
nil
discard
of 'a'..'z', '0'..'9':
add(result, name[i])
else:

View file

@ -319,7 +319,7 @@ proc genObjectInit(p: BProc, section: TCProcSection, t: PType, a: TLoc,
takeAddr: bool) =
case analyseObjectWithTypeField(t)
of frNone:
nil
discard
of frHeader:
var r = rdLoc(a)
if not takeAddr: r = ropef("(*$1)", [r])
@ -832,7 +832,7 @@ proc genProcNoForward(m: BModule, prc: PSym) =
discard cgsym(m, prc.name.s)
return
genProcPrototype(m, prc)
if lfNoDecl in prc.loc.flags: nil
if lfNoDecl in prc.loc.flags: discard
elif prc.typ.callConv == ccInline:
# We add inline procs to the calling module to enable C based inlining.
# This also means that a check with ``q.declaredThings`` is wrong, we need

View file

@ -66,7 +66,7 @@ proc sameMethodBucket(a, b: PSym): bool =
if sameType(aa, bb) or
(aa.kind == tyObject) and (bb.kind == tyObject) and
(inheritanceDiff(bb, aa) < 0):
nil
discard
else:
return
result = true

View file

@ -39,7 +39,7 @@ proc addDotDependency(c: PPassContext, n: PNode): PNode =
of nkStmtList, nkBlockStmt, nkStmtListExpr, nkBlockExpr:
for i in countup(0, sonsLen(n) - 1): discard addDotDependency(c, n.sons[i])
else:
nil
discard
proc generateDot(project: string) =
writeRope(ropef("digraph $1 {$n$2}$n", [

View file

@ -27,7 +27,7 @@ proc close(p: PPassContext, n: PNode): PNode =
try:
generateIndex(g.doc)
except EIO:
nil
discard
proc processNode(c: PPassContext, n: PNode): PNode =
result = n
@ -46,4 +46,4 @@ proc myOpen(module: PSym): PPassContext =
const docgen2Pass* = makePass(open = myOpen, process = processNode, close = close)
proc finishDoc2Pass*(project: string) =
nil
discard

View file

@ -55,7 +55,7 @@ proc scanPar(p: var TTmplParser, d: int) =
of ']': dec(p.bracket)
of '{': inc(p.curly)
of '}': dec(p.curly)
else: nil
else: discard
inc(i)
proc withInExpr(p: TTmplParser): bool {.inline.} =

View file

@ -439,7 +439,7 @@ proc impliesLe(fact, x, c: PNode): TImplication =
if leValue(c, fact.sons[1].pred): result = impNo
of mNot, mOr, mAnd: internalError(x.info, "impliesLe")
else: nil
else: discard
proc impliesLt(fact, x, c: PNode): TImplication =
# x < 3 same as x <= 2:

View file

@ -81,7 +81,7 @@ proc hlo(c: PContext, n: PNode): PNode =
else:
# perform type checking, so that the replacement still fits:
if isEmptyType(n.typ) and isEmptyType(result.typ):
nil
discard
else:
result = fitNode(c, n.typ, result)
# optimization has been applied so check again:

View file

@ -143,7 +143,7 @@ proc mangle(name: string): string =
of 'A'..'Z':
add(result, chr(ord(name[i]) - ord('A') + ord('a')))
of '_':
nil
discard
of 'a'..'z', '0'..'9':
add(result, name[i])
else: add(result, 'X' & toHex(ord(name[i]), 2))
@ -996,10 +996,10 @@ proc genSym(p: PProc, n: PNode, r: var TCompRes) =
r.res = s.loc.r
if lfNoDecl in s.loc.flags or s.magic != mNone or
{sfImportc, sfInfixCall} * s.flags != {}:
nil
discard
elif s.kind == skMethod and s.getBody.kind == nkEmpty:
# we cannot produce code for the dispatcher yet:
nil
discard
elif sfForward in s.flags:
p.g.forwarded.add(s)
elif not p.g.generatedSyms.containsOrIncl(s.id):
@ -1336,10 +1336,10 @@ proc genMagic(p: PProc, n: PNode, r: var TCompRes) =
else:
unaryExpr(p, n, r, "", "($1.length-1)")
of mInc:
if not (optOverflowCheck in p.options): binaryExpr(p, n, r, "", "$1 += $2")
if optOverflowCheck notin p.options: binaryExpr(p, n, r, "", "$1 += $2")
else: binaryExpr(p, n, r, "addInt", "$1 = addInt($1, $2)")
of ast.mDec:
if not (optOverflowCheck in p.options): binaryExpr(p, n, r, "", "$1 -= $2")
if optOverflowCheck notin p.options: binaryExpr(p, n, r, "", "$1 -= $2")
else: binaryExpr(p, n, r, "subInt", "$1 = subInt($1, $2)")
of mSetLengthStr: binaryExpr(p, n, r, "", "$1.length = ($2)-1")
of mSetLengthSeq: binaryExpr(p, n, r, "", "$1.length = $2")
@ -1544,7 +1544,7 @@ proc gen(p: PProc, n: PNode, r: var TCompRes) =
r.res = toRope(n.intVal)
of nkNilLit:
if isEmptyType(n.typ):
nil
discard
elif mapType(n.typ) == etyBaseIndex:
r.typ = etyBaseIndex
r.address = toRope"null" | toRope"nil"
@ -1592,12 +1592,12 @@ proc gen(p: PProc, n: PNode, r: var TCompRes) =
of nkChckRange: genRangeChck(p, n, r, "chckRange")
of nkStringToCString: convStrToCStr(p, n, r)
of nkCStringToString: convCStrToStr(p, n, r)
of nkEmpty: nil
of nkEmpty: discard
of nkLambdaKinds:
let s = n.sons[namePos].sym
discard mangleName(s)
r.res = s.loc.r
if lfNoDecl in s.loc.flags or s.magic != mNone: nil
if lfNoDecl in s.loc.flags or s.magic != mNone: discard
elif not p.g.generatedSyms.containsOrIncl(s.id):
app(p.locals, genProc(p, s))
of nkMetaNode: gen(p, n.sons[0], r)
@ -1614,7 +1614,7 @@ proc gen(p: PProc, n: PNode, r: var TCompRes) =
of nkIfStmt, nkIfExpr: genIf(p, n, r)
of nkWhileStmt: genWhileStmt(p, n)
of nkVarSection, nkLetSection: genVarStmt(p, n)
of nkConstSection: nil
of nkConstSection: discard
of nkForStmt, nkParForStmt:
internalError(n.info, "for statement not eliminated")
of nkCaseStmt:
@ -1633,7 +1633,7 @@ proc gen(p: PProc, n: PNode, r: var TCompRes) =
of nkRaiseStmt: genRaiseStmt(p, n)
of nkTypeSection, nkCommentStmt, nkIteratorDef, nkIncludeStmt,
nkImportStmt, nkImportExceptStmt, nkExportStmt, nkExportExceptStmt,
nkFromStmt, nkTemplateDef, nkMacroDef, nkPragma: nil
nkFromStmt, nkTemplateDef, nkMacroDef, nkPragma: discard
of nkProcDef, nkMethodDef, nkConverterDef:
var s = n.sons[namePos].sym
if {sfExportc, sfCompilerProc} * s.flags == {sfExportc}:

View file

@ -1,7 +1,7 @@
#
#
# The Nimrod Compiler
# (c) Copyright 2013 Andreas Rumpf
# (c) Copyright 2014 Andreas Rumpf
#
# See the file "copying.txt", included in this
# distribution, for details about the copyright.
@ -275,7 +275,7 @@ proc captureVar(o: POuterContext, i: PInnerContext, local: PSym,
addCapturedVar(it, local)
if it == e:
# common case: local directly in current environment:
nil
discard
else:
# it's in some upper environment:
access = indirectAccess(access, addDep(e, it, i.fn), info)
@ -314,7 +314,7 @@ proc gatherVars(o: POuterContext, i: PInnerContext, n: PNode) =
if o.currentEnv != env:
discard addDep(o.currentEnv, env, i.fn)
internalError(n.info, "too complex environment handling required")
of nkEmpty..pred(nkSym), succ(nkSym)..nkNilLit: nil
of nkEmpty..pred(nkSym), succ(nkSym)..nkNilLit: discard
else:
for k in countup(0, sonsLen(n) - 1):
gatherVars(o, i, n.sons[k])
@ -351,7 +351,7 @@ proc makeClosure(prc, env: PSym, info: TLineInfo): PNode =
proc transformInnerProc(o: POuterContext, i: PInnerContext, n: PNode): PNode =
case n.kind
of nkEmpty..pred(nkSym), succ(nkSym)..nkNilLit: nil
of nkEmpty..pred(nkSym), succ(nkSym)..nkNilLit: discard
of nkSym:
let s = n.sym
if s == i.fn:
@ -371,7 +371,7 @@ proc transformInnerProc(o: POuterContext, i: PInnerContext, n: PNode): PNode =
of nkProcDef, nkMethodDef, nkConverterDef, nkMacroDef, nkTemplateDef,
nkIteratorDef:
# don't recurse here:
nil
discard
else:
for j in countup(0, sonsLen(n) - 1):
let x = transformInnerProc(o, i, n.sons[j])
@ -386,7 +386,7 @@ proc searchForInnerProcs(o: POuterContext, n: PNode) =
if n == nil: return
case n.kind
of nkEmpty..pred(nkSym), succ(nkSym)..nkNilLit:
nil
discard
of nkSym:
if isInnerProc(n.sym, o.fn) and not containsOrIncl(o.processed, n.sym.id):
var inner = newInnerContext(n.sym)
@ -422,7 +422,7 @@ proc searchForInnerProcs(o: POuterContext, n: PNode) =
# counts, not the block where it is captured!
for i in countup(0, sonsLen(n) - 1):
var it = n.sons[i]
if it.kind == nkCommentStmt: nil
if it.kind == nkCommentStmt: discard
elif it.kind == nkIdentDefs:
var L = sonsLen(it)
if it.sons[0].kind != nkSym: internalError(it.info, "transformOuter")
@ -441,7 +441,7 @@ proc searchForInnerProcs(o: POuterContext, n: PNode) =
nkIteratorDef:
# don't recurse here:
# XXX recurse here and setup 'up' pointers
nil
discard
else:
for i in countup(0, sonsLen(n) - 1):
searchForInnerProcs(o, n.sons[i])
@ -500,7 +500,7 @@ proc generateClosureCreation(o: POuterContext, scope: PEnv): PNode =
proc transformOuterProc(o: POuterContext, n: PNode): PNode =
if n == nil: return nil
case n.kind
of nkEmpty..pred(nkSym), succ(nkSym)..nkNilLit: nil
of nkEmpty..pred(nkSym), succ(nkSym)..nkNilLit: discard
of nkSym:
var local = n.sym
var closure = PEnv(idTableGet(o.lambdasToEnv, local))
@ -540,7 +540,7 @@ proc transformOuterProc(o: POuterContext, n: PNode): PNode =
of nkProcDef, nkMethodDef, nkConverterDef, nkMacroDef, nkTemplateDef,
nkIteratorDef:
# don't recurse here:
nil
discard
of nkHiddenStdConv, nkHiddenSubConv, nkConv:
let x = transformOuterProc(o, n.sons[1])
if x != nil: n.sons[1] = x
@ -625,7 +625,7 @@ proc transfIterBody(c: var TIterContext, n: PNode): PNode =
if interestingIterVar(s) and c.iter.id == s.owner.id:
if not containsOrIncl(c.capturedVars, s.id): addField(c.tup, s)
result = indirectAccess(newSymNode(c.closureParam), s, n.info)
of nkEmpty..pred(nkSym), succ(nkSym)..nkNilLit: nil
of nkEmpty..pred(nkSym), succ(nkSym)..nkNilLit: discard
of nkYieldStmt:
inc c.state.typ.n.sons[1].intVal
let stateNo = c.state.typ.n.sons[1].intVal

View file

@ -434,7 +434,7 @@ proc handleHexChar(L: var TLexer, xi: var int) =
of 'A'..'F':
xi = (xi shl 4) or (ord(L.buf[L.bufpos]) - ord('A') + 10)
inc(L.bufpos)
else: nil
else: discard
proc handleDecChars(L: var TLexer, xi: var int) =
while L.buf[L.bufpos] in {'0'..'9'}:

View file

@ -286,7 +286,7 @@ proc initOverloadIter*(o: var TOverloadIter, c: PContext, n: PNode): PSym =
o.symChoiceIndex = 1
o.inSymChoice = initIntSet()
incl(o.inSymChoice, result.id)
else: nil
else: discard
if result != nil and result.kind == skStub: loadStub(result)
proc lastOverloadScope*(o: TOverloadIter): int =

View file

@ -113,7 +113,7 @@ type
warnDifferentHeaps, warnWriteToForeignHeap, warnImplicitClosure,
warnEachIdentIsTuple, warnShadowIdent,
warnProveInit, warnProveField, warnProveIndex,
warnUninit, warnUser,
warnUninit, warnGcMem, warnUser,
hintSuccess, hintSuccessX,
hintLineTooLong, hintXDeclaredButNotUsed, hintConvToBaseNotNeeded,
hintConvFromXtoItselfNotNeeded, hintExprAlwaysX, hintQuitCalled,
@ -370,6 +370,7 @@ const
warnProveField: "cannot prove that field '$1' is accessible [ProveField]",
warnProveIndex: "cannot prove index '$1' is valid [ProveIndex]",
warnUninit: "'$1' might not have been initialized [Uninit]",
warnGcMem: "'$1' uses GC'ed memory [GcMem]",
warnUser: "$1 [User]",
hintSuccess: "operation successful [Success]",
hintSuccessX: "operation successful ($# lines compiled; $# sec total; $#) [SuccessX]",
@ -389,7 +390,7 @@ const
hintUser: "$1 [User]"]
const
WarningsToStr*: array[0..23, string] = ["CannotOpenFile", "OctalEscape",
WarningsToStr*: array[0..24, string] = ["CannotOpenFile", "OctalEscape",
"XIsNeverRead", "XmightNotBeenInit",
"Deprecated", "ConfigDeprecated",
"SmallLshouldNotBeUsed", "UnknownMagic",
@ -397,7 +398,7 @@ const
"CommentXIgnored", "NilStmt",
"AnalysisLoophole", "DifferentHeaps", "WriteToForeignHeap",
"ImplicitClosure", "EachIdentIsTuple", "ShadowIdent",
"ProveInit", "ProveField", "ProveIndex", "Uninit", "User"]
"ProveInit", "ProveField", "ProveIndex", "Uninit", "GcMem", "User"]
HintsToStr*: array[0..15, string] = ["Success", "SuccessX", "LineTooLong",
"XDeclaredButNotUsed", "ConvToBaseNotNeeded", "ConvFromXtoItselfNotNeeded",
@ -856,6 +857,5 @@ ropes.errorHandler = proc (err: TRopesError, msg: string, useWarning: bool) =
of rTokenTooLong:
internalError("ropes: token too long: " & msg)
of rCannotOpenFile:
rawMessage(if useWarning: warnCannotOpenFile else: errCannotOpenFile,
msg)
rawMessage(if useWarning: warnCannotOpenFile else: errCannotOpenFile, msg)

View file

@ -101,11 +101,11 @@ proc jumpToDirective(L: var TLexer, tok: var TToken, dest: TJumpDest) =
break
if nestedIfs > 0: dec(nestedIfs)
else:
nil
discard
ppGetTok(L, tok)
elif tok.tokType == tkEof:
elif tok.tokType == tkEof:
lexMessage(L, errTokenExpected, "@end")
else:
else:
ppGetTok(L, tok)
proc parseDirective(L: var TLexer, tok: var TToken) =

View file

@ -16,3 +16,5 @@ import:testability
@if windows:
cincludes: "$lib/wrappers/libffi/common"
@end
cs:partial

View file

@ -1817,7 +1817,7 @@ proc parseStmt(p: var TParser): PNode =
withInd(p):
while true:
if p.tok.indent == p.currInd:
nil
discard
elif p.tok.tokType == tkSemiColon:
getTok(p)
if p.tok.indent < 0 or p.tok.indent == p.currInd: discard

View file

@ -41,7 +41,7 @@ proc cleanUp(c: PPassContext, n: PNode): PNode =
if sfDeadCodeElim notin getModule(s).flags and not astNeeded(s):
s.ast.sons[bodyPos] = ast.emptyNode # free the memory
else:
nil
discard
const cleanupPass* = makePass(process = cleanUp, close = cleanUp)

View file

@ -40,7 +40,7 @@ proc canonKind(n: PNode): TNodeKind =
of nkCallKinds: result = nkCall
of nkStrLit..nkTripleStrLit: result = nkStrLit
of nkFastAsgn: result = nkAsgn
else: nil
else: discard
proc sameKinds(a, b: PNode): bool {.inline.} =
result = a.kind == b.kind or a.canonKind == b.canonKind
@ -267,7 +267,7 @@ proc applyRule*(c: PContext, s: PSym, n: PNode): PNode =
var rs = result.sons[i]
let param = params.sons[i].sym
case whichAlias(param)
of aqNone: nil
of aqNone: discard
of aqShouldAlias:
# it suffices that it aliases for sure with *some* other param:
var ok = false

View file

@ -60,7 +60,7 @@ proc searchForProcOld*(c: PContext, scope: PScope, fn: PSym): PSym =
localError(fn.info, errNotOverloadable, fn.name.s)
return
of paramsNotEqual:
nil
discard
result = nextIdentIter(it, scope.symbols)
proc searchForProcNew(c: PContext, scope: PScope, fn: PSym): PSym =

View file

@ -236,7 +236,7 @@ proc containsNL(s: string): bool =
of '\x0D', '\x0A':
return true
else:
nil
discard
result = false
proc pushCom(g: var TSrcGen, n: PNode) =
@ -487,7 +487,7 @@ proc hasCom(n: PNode): bool =
result = false
if n.comment != nil: return true
case n.kind
of nkEmpty..nkNilLit: nil
of nkEmpty..nkNilLit: discard
else:
for i in countup(0, sonsLen(n) - 1):
if hasCom(n.sons[i]): return true
@ -769,7 +769,7 @@ proc gsub(g: var TSrcGen, n: PNode, c: TContext) =
if n.comment != nil: pushCom(g, n)
case n.kind # atoms:
of nkTripleStrLit: putRawStr(g, tkTripleStrLit, n.strVal)
of nkEmpty: nil
of nkEmpty: discard
of nkType: put(g, tkInvalid, atom(n))
of nkSym, nkIdent: gident(g, n)
of nkIntLit: put(g, tkIntLit, atom(n))
@ -1273,7 +1273,7 @@ proc renderModule(n: PNode, filename: string,
case n.sons[i].kind
of nkTypeSection, nkConstSection, nkVarSection, nkLetSection,
nkCommentStmt: putNL(g)
else: nil
else: discard
gcoms(g)
if optStdout in gGlobalOptions:
write(stdout, g.buf)

View file

@ -539,7 +539,7 @@ proc cmdChangeTriggersRecompilation(old, new: TCommands): bool =
of cmdNone, cmdDoc, cmdInterpret, cmdPretty, cmdGenDepend, cmdDump,
cmdCheck, cmdParse, cmdScan, cmdIdeTools, cmdDef,
cmdRst2html, cmdRst2tex, cmdInteractive, cmdRun:
nil
discard
# else: trigger recompilation:
result = true

View file

@ -573,7 +573,7 @@ proc process(c: PPassContext, n: PNode): PNode =
of nkPragma:
addStmt(w, n)
else:
nil
discard
proc myOpen(module: PSym): PPassContext =
if module.id < 0: internalError("rodwrite: module ID not set")

View file

@ -71,7 +71,7 @@ proc pickBestCandidate(c: PContext, headSymbol: PNode,
var cmp = cmpCandidates(best, z)
if cmp < 0: best = z # x is better than the best so far
elif cmp == 0: alt = z # x is as good as the best so far
else: nil
else: discard
sym = nextOverloadIter(o, c, headSymbol)
proc notFoundError*(c: PContext, n: PNode, errors: seq[string]) =

View file

@ -168,7 +168,7 @@ proc checkConvertible(c: PContext, castDest, src: PType): TConvStatus =
if not compareTypes(castDest, src, dcEqIgnoreDistinct):
result = convNotLegal
else:
nil
discard
proc isCastable(dst, src: PType): bool =
#const
@ -204,7 +204,7 @@ proc semConv(c: PContext, n: PNode): PNode =
if not isSymChoice(op):
let status = checkConvertible(c, result.typ, op.typ)
case status
of convOK: nil
of convOK: discard
of convNotNeedeed:
message(n.info, hintConvFromXtoItselfNotNeeded, result.typ.typeToString)
of convNotLegal:
@ -397,7 +397,7 @@ proc changeType(n: PNode, newType: PType, check: bool) =
of nkPar:
if newType.kind != tyTuple:
internalError(n.info, "changeType: no tuple type for constructor")
elif newType.n == nil: nil
elif newType.n == nil: discard
elif sonsLen(n) > 0 and n.sons[0].kind == nkExprColonExpr:
for i in countup(0, sonsLen(n) - 1):
var m = n.sons[i].sons[0]
@ -423,7 +423,7 @@ proc changeType(n: PNode, newType: PType, check: bool) =
if value < firstOrd(newType) or value > lastOrd(newType):
localError(n.info, errGenerated, "cannot convert " & $value &
" to " & typeToString(newType))
else: nil
else: discard
n.typ = newType
proc arrayConstrType(c: PContext, n: PNode): PType =
@ -513,7 +513,7 @@ proc fixAbstractType(c: PContext, n: PNode) =
# an implicitly constructed array (passed to an open array):
n.sons[i] = semArrayConstr(c, it, {})
else:
nil
discard
#if (it.typ == nil):
# InternalError(it.info, "fixAbstractType: " & renderTree(it))
@ -677,7 +677,7 @@ proc semOverloadedCallAnalyseEffects(c: PContext, n: PNode, nOrig: PNode,
return
let callee = result.sons[0].sym
case callee.kind
of skMacro, skTemplate: nil
of skMacro, skTemplate: discard
else:
if (callee.kind == skIterator) and (callee.id == c.p.owner.id):
localError(n.info, errRecursiveDependencyX, callee.name.s)
@ -1098,7 +1098,7 @@ proc takeImplicitAddr(c: PContext, n: PNode): PNode =
of nkHiddenDeref, nkDerefExpr: return n.sons[0]
of nkBracketExpr:
if len(n) == 1: return n.sons[0]
else: nil
else: discard
var valid = isAssignable(c, n)
if valid != arLValue:
if valid == arLocalLValue:
@ -1207,7 +1207,7 @@ proc semProcBody(c: PContext, n: PNode): PNode =
# transform ``expr`` to ``result = expr``, but not if the expr is already
# ``result``:
if result.kind == nkSym and result.sym == c.p.resultSym:
nil
discard
elif result.kind == nkNilLit:
# or ImplicitlyDiscardable(result):
# new semantic: 'result = x' triggers the void context
@ -1244,7 +1244,7 @@ proc semYieldVarResult(c: PContext, n: PNode, restype: PType) =
a.sons[i] = takeImplicitAddr(c, a.sons[i])
else:
localError(n.sons[0].info, errXExpected, "tuple constructor")
else: nil
else: discard
proc semYield(c: PContext, n: PNode): PNode =
result = n
@ -1472,7 +1472,7 @@ proc tryExpr(c: PContext, n: PNode,
result = semExpr(c, n, flags)
if msgs.gErrorCounter != oldErrorCount: result = nil
except ERecoverableError:
nil
discard
# undo symbol table changes (as far as it's possible):
c.generics = oldGenerics
c.inGenericContext = oldInGenericContext
@ -1590,9 +1590,9 @@ proc semSetConstr(c: PContext, n: PNode): PNode =
typ = skipTypes(n.sons[i].typ, {tyGenericInst, tyVar, tyOrdinal})
if not isOrdinalType(typ):
localError(n.info, errOrdinalTypeExpected)
typ = makeRangeType(c, 0, MaxSetElements - 1, n.info)
typ = makeRangeType(c, 0, MaxSetElements-1, n.info)
elif lengthOrd(typ) > MaxSetElements:
typ = makeRangeType(c, 0, MaxSetElements - 1, n.info)
typ = makeRangeType(c, 0, MaxSetElements-1, n.info)
addSonSkipIntLit(result.typ, typ)
for i in countup(0, sonsLen(n) - 1):
var m: PNode
@ -1629,27 +1629,27 @@ proc semTableConstr(c: PContext, n: PNode): PNode =
if lastKey != n.len: illFormedAst(n)
result = semExpr(c, result)
type
TParKind = enum
type
TParKind = enum
paNone, paSingle, paTupleFields, paTuplePositions
proc checkPar(n: PNode): TParKind =
proc checkPar(n: PNode): TParKind =
var length = sonsLen(n)
if length == 0:
result = paTuplePositions # ()
elif length == 1:
result = paSingle # (expr)
else:
else:
if n.sons[0].kind == nkExprColonExpr: result = paTupleFields
else: result = paTuplePositions
for i in countup(0, length - 1):
if result == paTupleFields:
for i in countup(0, length - 1):
if result == paTupleFields:
if (n.sons[i].kind != nkExprColonExpr) or
not (n.sons[i].sons[0].kind in {nkSym, nkIdent}):
not (n.sons[i].sons[0].kind in {nkSym, nkIdent}):
localError(n.sons[i].info, errNamedExprExpected)
return paNone
else:
if n.sons[i].kind == nkExprColonExpr:
else:
if n.sons[i].kind == nkExprColonExpr:
localError(n.sons[i].info, errNamedExprNotAllowed)
return paNone
@ -1659,8 +1659,7 @@ proc semTupleFieldsConstr(c: PContext, n: PNode, flags: TExprFlags): PNode =
typ.n = newNodeI(nkRecList, n.info) # nkIdentDefs
var ids = initIntSet()
for i in countup(0, sonsLen(n) - 1):
if (n.sons[i].kind != nkExprColonExpr) or
not (n.sons[i].sons[0].kind in {nkSym, nkIdent}):
if n[i].kind != nkExprColonExpr or n[i][0].kind notin {nkSym, nkIdent}:
illFormedAst(n.sons[i])
var id: PIdent
if n.sons[i].sons[0].kind == nkIdent: id = n.sons[i].sons[0].ident

View file

@ -222,7 +222,7 @@ proc getIntervalType*(m: TMagic, n: PNode): PType =
commutativeOp(min)
of mMaxI, mMaxI64:
commutativeOp(max)
else: nil
else: discard
discard """
mShlI, mShlI64,
@ -546,7 +546,7 @@ proc foldArrayAccess(m: PSym, n: PNode): PNode =
if (idx >= 0) and (idx < len(x.strVal)):
result.intVal = ord(x.strVal[int(idx)])
elif idx == len(x.strVal):
nil
discard
else:
localError(n.info, errIndexOutOfBounds)
else: discard

View file

@ -53,7 +53,7 @@ proc semTypeTraits(c: PContext, n: PNode): PNode =
if t.sonsLen > 0:
# This is either a type known to sem or a typedesc
# param to a regular proc (again, known at instantiation)
result = evalTypeTrait(n[0], t, GetCurrOwner())
result = evalTypeTrait(n[0], t, getCurrOwner())
else:
# a typedesc variable, pass unmodified to evals
result = n

View file

@ -136,6 +136,7 @@ proc discardCheck(c: PContext, result: PNode) =
if result.typ != nil and result.typ.kind notin {tyStmt, tyEmpty}:
if result.kind == nkNilLit:
result.typ = nil
message(result.info, warnNilStatement)
elif implicitlyDiscardable(result):
var n = result
result.typ = nil
@ -145,10 +146,11 @@ proc discardCheck(c: PContext, result: PNode) =
elif c.inTypeClass > 0 and result.typ.kind == tyBool:
let verdict = semConstExpr(c, result)
if verdict.intVal == 0:
localError(result.info, "type class predicate failed.")
localError(result.info, "type class predicate failed")
elif result.typ.kind != tyError and gCmd != cmdInteractive:
if result.typ.kind == tyNil:
fixNilType(result)
message(result.info, warnNilStatement)
else:
var n = result
while n.kind in skipForDiscardable: n = n.lastSon
@ -996,7 +998,7 @@ proc semProcAux(c: PContext, n: PNode, kind: TSymKind,
if proto == nil:
s.typ.callConv = lastOptionEntry(c).defaultCC
# add it here, so that recursive procs are possible:
if sfGenSym in s.flags: nil
if sfGenSym in s.flags: discard
elif kind in OverloadableSyms:
if not typeIsDetermined:
addInterfaceOverloadableSymAt(c, s.scope, s)
@ -1252,9 +1254,9 @@ proc semStmtList(c: PContext, n: PNode): PNode =
of LastBlockStmts:
for j in countup(i + 1, length - 1):
case n.sons[j].kind
of nkPragma, nkCommentStmt, nkNilLit, nkEmpty: nil
of nkPragma, nkCommentStmt, nkNilLit, nkEmpty: discard
else: localError(n.sons[j].info, errStmtInvalidAfterReturn)
else: nil
else: discard
if result.len == 1:
result = result.sons[0]
when false:

View file

@ -537,7 +537,7 @@ proc semRecordNodeAux(c: PContext, n: PNode, check: var TIntSet, pos: var int,
if a.kind == nkEmpty: addSon(father, newSymNode(f))
else: addSon(a, newSymNode(f))
if a.kind != nkEmpty: addSon(father, a)
of nkEmpty: nil
of nkEmpty: discard
else: illFormedAst(n)
proc addInheritedFieldsAux(c: PContext, check: var TIntSet, pos: var int,
@ -615,7 +615,7 @@ proc addParamOrResult(c: PContext, param: PSym, kind: TSymKind) =
let typedescId = getIdent"typedesc"
template shouldHaveMeta(t) =
InternalAssert tfHasMeta in t.flags
internalAssert tfHasMeta in t.flags
# result.lastSon.flags.incl tfHasMeta
proc liftParamType(c: PContext, procKind: TSymKind, genericParams: PNode,
@ -745,7 +745,7 @@ proc liftParamType(c: PContext, procKind: TSymKind, genericParams: PNode,
else:
result = addImplicitGeneric(newTypeS(tyAnything, c))
else: nil
else: discard
# result = liftingWalk(paramType)
@ -939,7 +939,7 @@ proc semTypeNode(c: PContext, n: PNode, prev: PType): PType =
result = nil
if gCmd == cmdIdeTools: suggestExpr(c, n)
case n.kind
of nkEmpty: nil
of nkEmpty: discard
of nkTypeOfExpr:
# for ``type(countup(1,3))``, see ``tests/ttoseq``.
checkSonsLen(n, 1)
@ -977,7 +977,7 @@ proc semTypeNode(c: PContext, n: PNode, prev: PType): PType =
result = freshType(result, prev)
result.flags.incl(tfNotNil)
else:
LocalError(n.info, errGenerated, "invalid type")
localError(n.info, errGenerated, "invalid type")
of 2:
let negated = semTypeNode(c, n.sons[1], prev)
result = makeNotType(c, negated)
@ -1137,7 +1137,7 @@ proc processMagicType(c: PContext, m: PSym) =
of mSet: setMagicType(m, tySet, 0)
of mSeq: setMagicType(m, tySequence, 0)
of mOrdinal: setMagicType(m, tyOrdinal, 0)
of mPNimrodNode: nil
of mPNimrodNode: discard
else: localError(m.info, errTypeExpected)
proc semGenericConstraints(c: PContext, x: PType): PType =

View file

@ -22,7 +22,7 @@ proc checkPartialConstructedType(info: TLineInfo, t: PType) =
proc checkConstructedType*(info: TLineInfo, typ: PType) =
var t = typ.skipTypes({tyDistinct})
if t.kind in tyTypeClasses: nil
if t.kind in tyTypeClasses: discard
elif tfAcyclic in t.flags and skipTypes(t, abstractInst).kind != tyObject:
localError(info, errInvalidPragmaX, "acyclic")
elif t.kind == tyVar and t.sons[0].kind == tyVar:
@ -364,7 +364,7 @@ proc replaceTypeVarsTAux(cl: var TReplTypeVars, t: PType): PType =
of tyGenericInst:
result = instCopyType(cl, t)
for i in 1 .. <result.sonsLen:
result.sons[i] = ReplaceTypeVarsT(cl, result.sons[i])
result.sons[i] = replaceTypeVarsT(cl, result.sons[i])
propagateToOwner(result, result.lastSon)
else:

View file

@ -381,7 +381,7 @@ proc procTypeRel(c: var TCandidate, f, a: PType): TTypeRelation =
when useEffectSystem:
if not compatibleEffects(f, a): return isNone
of tyNil: result = f.allowsNil
else: nil
else: discard
proc typeRangeRel(f, a: PType): TTypeRelation {.noinline.} =
let
@ -477,7 +477,7 @@ proc typeRel(c: var TCandidate, f, aOrig: PType, doBind = true): TTypeRelation =
of tyAnything:
return if f.kind == tyAnything: isGeneric
else: isNone
else: nil
else: discard
case f.kind
of tyEnum:
@ -530,7 +530,7 @@ proc typeRel(c: var TCandidate, f, aOrig: PType, doBind = true): TTypeRelation =
result = typeRel(c, f.sons[1], a.sons[1])
if result < isGeneric: result = isNone
elif lengthOrd(fRange) != lengthOrd(a): result = isNone
else: nil
else: discard
of tyOpenArray, tyVarargs:
case a.kind
of tyOpenArray, tyVarargs:
@ -551,7 +551,7 @@ proc typeRel(c: var TCandidate, f, aOrig: PType, doBind = true): TTypeRelation =
result = isConvertible
elif typeRel(c, base(f), a.sons[0]) >= isGeneric:
result = isConvertible
else: nil
else: discard
of tySequence:
case a.kind
of tySequence:
@ -563,7 +563,7 @@ proc typeRel(c: var TCandidate, f, aOrig: PType, doBind = true): TTypeRelation =
elif tfNotNil in f.flags and tfNotNil notin a.flags:
result = isNilConversion
of tyNil: result = f.allowsNil
else: nil
else: discard
of tyOrdinal:
if isOrdinalType(a):
var x = if a.kind == tyOrdinal: a.sons[0] else: a
@ -607,7 +607,7 @@ proc typeRel(c: var TCandidate, f, aOrig: PType, doBind = true): TTypeRelation =
elif tfNotNil in f.flags and tfNotNil notin a.flags:
result = isNilConversion
of tyNil: result = f.allowsNil
else: nil
else: discard
of tyRef:
case a.kind
of tyRef:
@ -616,7 +616,7 @@ proc typeRel(c: var TCandidate, f, aOrig: PType, doBind = true): TTypeRelation =
elif tfNotNil in f.flags and tfNotNil notin a.flags:
result = isNilConversion
of tyNil: result = f.allowsNil
else: nil
else: discard
of tyProc:
result = procTypeRel(c, f, a)
if result != isNone and tfNotNil in f.flags and tfNotNil notin a.flags:
@ -632,7 +632,7 @@ proc typeRel(c: var TCandidate, f, aOrig: PType, doBind = true): TTypeRelation =
of tyProc:
if a.callConv != ccClosure: result = isConvertible
of tyPtr, tyCString: result = isConvertible
else: nil
else: discard
of tyString:
case a.kind
of tyString:
@ -641,7 +641,7 @@ proc typeRel(c: var TCandidate, f, aOrig: PType, doBind = true): TTypeRelation =
else:
result = isEqual
of tyNil: result = f.allowsNil
else: nil
else: discard
of tyCString:
# conversion from string to cstring is automatic:
case a.kind
@ -659,7 +659,7 @@ proc typeRel(c: var TCandidate, f, aOrig: PType, doBind = true): TTypeRelation =
(skipTypes(a.sons[0], {tyRange}).kind in {tyInt..tyInt64}) and
(a.sons[1].kind == tyChar):
result = isConvertible
else: nil
else: discard
of tyEmpty:
if a.kind == tyEmpty: result = isEqual
@ -691,7 +691,7 @@ proc typeRel(c: var TCandidate, f, aOrig: PType, doBind = true): TTypeRelation =
if x.kind == tyGenericInvokation or f.sons[0].kind != tyGenericBody:
#InternalError("typeRel: tyGenericInvokation -> tyGenericInvokation")
# simply no match for now:
nil
discard
elif x.kind == tyGenericInst and
(f.sons[0] == x.sons[0]) and
(sonsLen(x) - 1 == sonsLen(f)):
@ -947,10 +947,10 @@ proc matchUserTypeClass*(c: PContext, m: var TCandidate,
if e == nil: return nil
case e.kind
of nkReturnStmt: nil
of nkTypeSection: nil
of nkConstDef: nil
else: nil
of nkReturnStmt: discard
of nkTypeSection: discard
of nkConstDef: discard
else: discard
result = arg
put(m.bindings, f, a)
@ -976,7 +976,7 @@ proc paramTypesMatchAux(m: var TCandidate, f, argType: PType,
var
r: TTypeRelation
a = if c.InTypeClass > 0: argType.skipTypes({tyTypeDesc})
a = if c.inTypeClass > 0: argType.skipTypes({tyTypeDesc})
else: argType
case fMaybeStatic.kind

View file

@ -103,7 +103,7 @@ proc suggestObject(c: PContext, n: PNode, outputs: var int) =
suggestObject(c, n.sons[0], outputs)
for i in countup(1, L-1): suggestObject(c, lastSon(n.sons[i]), outputs)
of nkSym: suggestField(c, n.sym, outputs)
else: nil
else: discard
proc nameFits(c: PContext, s: PSym, n: PNode): bool =
var op = n.sons[0]

View file

@ -193,7 +193,7 @@ proc transformConstSection(c: PTransf, v: PNode): PTransNode =
proc hasContinue(n: PNode): bool =
case n.kind
of nkEmpty..nkNilLit, nkForStmt, nkParForStmt, nkWhileStmt: nil
of nkEmpty..nkNilLit, nkForStmt, nkParForStmt, nkWhileStmt: discard
of nkContinueStmt: result = true
else:
for i in countup(0, sonsLen(n) - 1):
@ -536,7 +536,7 @@ proc getMergeOp(n: PNode): PSym =
if (n.sons[0].kind == nkSym) and (n.sons[0].sym.kind == skProc) and
(sfMerge in n.sons[0].sym.flags):
result = n.sons[0].sym
else: nil
else: discard
proc flattenTreeAux(d, a: PNode, op: PSym) =
var op2 = getMergeOp(a)

View file

@ -345,7 +345,7 @@ proc canFormAcycleAux(marker: var TIntSet, typ: PType, startId: int): bool =
# # damn inheritance may introduce cycles:
# result = true
of tyProc: result = typ.callConv == ccClosure
else: nil
else: discard
proc canFormAcycle(typ: PType): bool =
var marker = initIntSet()
@ -432,10 +432,10 @@ proc typeToString(typ: PType, prefer: TPreferedDesc = preferName): string =
if t.len == 0: result = "typedesc"
else: result = "typedesc[" & typeToString(t.sons[0]) & "]"
of tyStatic:
InternalAssert t.len > 0
internalAssert t.len > 0
result = "static[" & typeToString(t.sons[0]) & "]"
of tyTypeClass:
InternalAssert t.sym != nil and t.sym.owner != nil
internalAssert t.sym != nil and t.sym.owner != nil
return t.sym.owner.name.s
of tyBuiltInTypeClass:
return "TypeClass"
@ -446,7 +446,7 @@ proc typeToString(typ: PType, prefer: TPreferedDesc = preferName): string =
of tyNot:
result = "not " & typeToString(t.sons[0])
of tyExpr:
InternalAssert t.len == 0
internalAssert t.len == 0
result = "expr"
of tyFromExpr:
result = renderTree(t.n)