bugfix: removed newSons legacy

This commit is contained in:
Araq 2012-01-07 11:10:14 +01:00
commit 0e22a51095
4 changed files with 15 additions and 10 deletions

View file

@ -877,8 +877,10 @@ proc len*(n: PType): int =
else: result = len(n.sons) else: result = len(n.sons)
proc newSons(father: PType, length: int) = proc newSons(father: PType, length: int) =
if isNil(father.sons): father.sons = @[] if isNil(father.sons):
setlen(father.sons, len(father.sons) + length) newSeq(father.sons, length)
else:
setlen(father.sons, length)
proc addSon(father, son: PType) = proc addSon(father, son: PType) =
if isNil(father.sons): father.sons = @[] if isNil(father.sons): father.sons = @[]
@ -890,8 +892,10 @@ proc sonsLen(n: PNode): int =
else: result = len(n.sons) else: result = len(n.sons)
proc newSons(father: PNode, length: int) = proc newSons(father: PNode, length: int) =
if isNil(father.sons): father.sons = @[] if isNil(father.sons):
setlen(father.sons, len(father.sons) + length) newSeq(father.sons, length)
else:
setlen(father.sons, length)
proc addSon(father, son: PNode) = proc addSon(father, son: PNode) =
assert son != nil assert son != nil
@ -937,7 +941,7 @@ proc shallowCopy*(src: PNode): PNode =
of nkSym: result.sym = src.sym of nkSym: result.sym = src.sym
of nkIdent: result.ident = src.ident of nkIdent: result.ident = src.ident
of nkStrLit..nkTripleStrLit: result.strVal = src.strVal of nkStrLit..nkTripleStrLit: result.strVal = src.strVal
else: newSons(result, sonsLen(src)) else: newSeq(result.sons, sonsLen(src))
proc copyTree(src: PNode): PNode = proc copyTree(src: PNode): PNode =
# copy a whole syntax tree; performs deep copying # copy a whole syntax tree; performs deep copying
@ -954,8 +958,7 @@ proc copyTree(src: PNode): PNode =
of nkIdent: result.ident = src.ident of nkIdent: result.ident = src.ident
of nkStrLit..nkTripleStrLit: result.strVal = src.strVal of nkStrLit..nkTripleStrLit: result.strVal = src.strVal
else: else:
result.sons = nil newSeq(result.sons, sonsLen(src))
newSons(result, sonsLen(src))
for i in countup(0, sonsLen(src) - 1): for i in countup(0, sonsLen(src) - 1):
result.sons[i] = copyTree(src.sons[i]) result.sons[i] = copyTree(src.sons[i])

View file

@ -583,6 +583,7 @@ proc StrTableIncl*(t: var TStrTable, n: PSym): bool =
# returns true if n is already in the string table: # returns true if n is already in the string table:
# It is essential that `n` is written nevertheless! # It is essential that `n` is written nevertheless!
# This way the newest redefinition is picked by the semantic analyses! # This way the newest redefinition is picked by the semantic analyses!
assert n.name != nil
var h: THash = n.name.h and high(t.data) var h: THash = n.name.h and high(t.data)
while true: while true:
var it = t.data[h] var it = t.data[h]

View file

@ -246,6 +246,7 @@ proc semGenericStmt(c: PContext, n: PNode,
of nkProcDef, nkMethodDef, nkConverterDef, nkMacroDef, nkTemplateDef, of nkProcDef, nkMethodDef, nkConverterDef, nkMacroDef, nkTemplateDef,
nkIteratorDef, nkLambda: nkIteratorDef, nkLambda:
checkSonsLen(n, bodyPos + 1) checkSonsLen(n, bodyPos + 1)
if n.kind != nkLambda:
addPrelimDecl(c, newSymS(skUnknown, getIdentNode(n.sons[0]), c)) addPrelimDecl(c, newSymS(skUnknown, getIdentNode(n.sons[0]), c))
openScope(c.tab) openScope(c.tab)
n.sons[genericParamsPos] = semGenericStmt(c, n.sons[genericParamsPos], n.sons[genericParamsPos] = semGenericStmt(c, n.sons[genericParamsPos],

View file

@ -1,8 +1,7 @@
version 0.8.14 version 0.8.14
============== ==============
- BUG: type TX = TTable[string, int] - fix remaining generics bugs
- BUG: temp2.nim triggers weird compiler bug
- fix line info in assertions - fix line info in assertions
- implicit invokation of `items`/`pairs` seems nice; ensure items(23) does - implicit invokation of `items`/`pairs` seems nice; ensure items(23) does
not compile though not compile though
@ -48,6 +47,7 @@ Bugs
- bug: stress testing basic method example (eval example) - bug: stress testing basic method example (eval example)
without ``-d:release`` leaks memory; good way to figure out how a without ``-d:release`` leaks memory; good way to figure out how a
fixed amount of stack can hold an arbitrary number of GC roots! fixed amount of stack can hold an arbitrary number of GC roots!
- BUG: temp2.nim triggers weird compiler and except.nim bug
version 0.9.XX version 0.9.XX