remove conditionals on nimHasUserErrors, nimNoNilSeqs2, nimNoNilSeqs (#16861)

* cleanup docs for type(nil) | type(nil); simplify nimHasUserErrors

* simplify nimNoNilSeqs2

* simplify nimNoNilSeqs

* fixup
This commit is contained in:
Timothee Cour 2021-01-29 05:30:24 -08:00 • committed by GitHub
commit 6e267d28b3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 29 additions and 93 deletions

View file

@ -1127,11 +1127,7 @@ proc discardSons*(father: PNode)
type Indexable = PNode | PType
proc len*(n: Indexable): int {.inline.} =
when defined(nimNoNilSeqs):
result = n.sons.len
else:
if isNil(n.sons): result = 0
else: result = n.sons.len
result = n.sons.len
proc safeLen*(n: PNode): int {.inline.} =
## works even for leaves.
@ -1146,8 +1142,6 @@ proc safeArrLen*(n: PNode): int {.inline.} =
proc add*(father, son: Indexable) =
assert son != nil
when not defined(nimNoNilSeqs):
if isNil(father.sons): father.sons = @[]
father.sons.add(son)
proc addAllowNil*(father, son: Indexable) {.inline.} =
@ -1308,10 +1302,7 @@ proc copyObjectSet*(dest: var TObjectSet, src: TObjectSet) =
for i in 0..high(src.data): dest.data[i] = src.data[i]
proc discardSons*(father: PNode) =
when defined(nimNoNilSeqs):
father.sons = @[]
else:
father.sons = nil
father.sons = @[]
proc withInfo*(n: PNode, info: TLineInfo): PNode =
n.info = info
@ -1436,13 +1427,7 @@ proc mergeLoc(a: var TLoc, b: TLoc) =
if a.r == nil: a.r = b.r
proc newSons*(father: Indexable, length: int) =
when defined(nimNoNilSeqs):
setLen(father.sons, length)
else:
if isNil(father.sons):
newSeq(father.sons, length)
else:
setLen(father.sons, length)
setLen(father.sons, length)
proc assignType*(dest, src: PType) =
dest.kind = src.kind
@ -1576,26 +1561,17 @@ proc propagateToOwner*(owner, elem: PType; propagateHasAsgn = true) =
owner.flags.incl tfHasGCedMem
proc rawAddSon*(father, son: PType; propagateHasAsgn = true) =
when not defined(nimNoNilSeqs):
if isNil(father.sons): father.sons = @[]
father.sons.add(son)
if not son.isNil: propagateToOwner(father, son, propagateHasAsgn)
proc rawAddSonNoPropagationOfTypeFlags*(father, son: PType) =
when not defined(nimNoNilSeqs):
if isNil(father.sons): father.sons = @[]
father.sons.add(son)
proc addSonNilAllowed*(father, son: PNode) =
when not defined(nimNoNilSeqs):
if isNil(father.sons): father.sons = @[]
father.sons.add(son)
proc delSon*(father: PNode, idx: int) =
when defined(nimNoNilSeqs):
if father.len == 0: return
else:
if isNil(father.sons): return
if father.len == 0: return
for i in idx..<father.len - 1: father[i] = father[i + 1]
father.sons.setLen(father.len - 1)
@ -1766,10 +1742,7 @@ proc getStr*(a: PNode): string =
of nkStrLit..nkTripleStrLit: result = a.strVal
of nkNilLit:
# let's hope this fixes more problems than it creates:
when defined(nimNoNilSeqs):
result = ""
else:
result = nil
result = ""
else:
raiseRecoverableError("cannot extract string from invalid AST node")
#doAssert false, "getStr"