@@ -1025,27 +1025,27 @@ type Indexable = PNode | PType
10251025
10261026proc len * (n: Indexable ): int {.inline .} =
10271027 when defined (nimNoNilSeqs):
1028- result = len ( n.sons)
1028+ result = n.sons.len
10291029 else :
10301030 if isNil (n.sons): result = 0
1031- else : result = len ( n.sons)
1031+ else : result = n.sons.len
10321032
10331033proc safeLen * (n: PNode ): int {.inline .} =
10341034 # # works even for leaves.
10351035 if n.kind in {nkNone.. nkNilLit}: result = 0
1036- else : result = len (n)
1036+ else : result = n.len
10371037
10381038proc safeArrLen * (n: PNode ): int {.inline .} =
10391039 # # works for array-like objects (strings passed as openArray in VM).
1040- if n.kind in {nkStrLit.. nkTripleStrLit}:result = len ( n.strVal)
1040+ if n.kind in {nkStrLit.. nkTripleStrLit}:result = n.strVal.len
10411041 elif n.kind in {nkNone.. nkFloat128Lit}: result = 0
1042- else : result = len (n)
1042+ else : result = n.len
10431043
1044- proc add * (father, son: PNode ) =
1044+ proc add * (father, son: Indexable ) =
10451045 assert son != nil
10461046 when not defined (nimNoNilSeqs):
10471047 if isNil (father.sons): father.sons = @ []
1048- add ( father.sons, son)
1048+ father.sons. add ( son)
10491049
10501050template `[]` * (n: Indexable , i: int ): Indexable = n.sons[i]
10511051template `[]=` * (n: Indexable , i: int ; x: Indexable ) = n.sons[i] = x
@@ -1144,18 +1144,18 @@ const # for all kind of hash tables:
11441144
11451145proc copyStrTable * (dest: var TStrTable , src: TStrTable ) =
11461146 dest.counter = src.counter
1147- setLen (dest.data, len ( src.data) )
1148- for i in 0 .. high (src.data): dest.data[i] = src.data[i]
1147+ setLen (dest.data, src.data.len )
1148+ for i in 0 .. high (src.data): dest.data[i] = src.data[i]
11491149
11501150proc copyIdTable * (dest: var TIdTable , src: TIdTable ) =
11511151 dest.counter = src.counter
1152- newSeq (dest.data, len ( src.data) )
1153- for i in 0 .. high (src.data): dest.data[i] = src.data[i]
1152+ newSeq (dest.data, src.data.len )
1153+ for i in 0 .. high (src.data): dest.data[i] = src.data[i]
11541154
11551155proc copyObjectSet * (dest: var TObjectSet , src: TObjectSet ) =
11561156 dest.counter = src.counter
1157- setLen (dest.data, len ( src.data) )
1158- for i in 0 .. high (src.data): dest.data[i] = src.data[i]
1157+ setLen (dest.data, src.data.len )
1158+ for i in 0 .. high (src.data): dest.data[i] = src.data[i]
11591159
11601160proc discardSons * (father: PNode ) =
11611161 when defined (nimNoNilSeqs):
@@ -1286,12 +1286,6 @@ proc newStrNode*(strVal: string; info: TLineInfo): PNode =
12861286 result = newNodeI (nkStrLit, info)
12871287 result .strVal = strVal
12881288
1289- proc addSon * (father, son: PNode ) =
1290- assert son != nil
1291- when not defined (nimNoNilSeqs):
1292- if isNil (father.sons): father.sons = @ []
1293- add (father.sons, son)
1294-
12951289proc newProcNode * (kind: TNodeKind , info: TLineInfo , body: PNode ,
12961290 params,
12971291 name, pattern, genericParams,
@@ -1366,8 +1360,8 @@ proc assignType*(dest, src: PType) =
13661360 mergeLoc (dest.sym.loc, src.sym.loc)
13671361 else :
13681362 dest.sym = src.sym
1369- newSons (dest, len ( src) )
1370- for i in 0 ..< len ( src) : dest.sons [i] = src.sons [i]
1363+ newSons (dest, src.len )
1364+ for i in 0 ..< src.len : dest[i] = src[i]
13711365
13721366proc copyType * (t: PType , owner: PSym , keepId: bool ): PType =
13731367 result = newType (t.kind, owner)
@@ -1503,27 +1497,26 @@ proc propagateToOwner*(owner, elem: PType) =
15031497proc rawAddSon * (father, son: PType ) =
15041498 when not defined (nimNoNilSeqs):
15051499 if isNil (father.sons): father.sons = @ []
1506- add ( father.sons, son)
1500+ father.sons. add ( son)
15071501 if not son.isNil: propagateToOwner (father, son)
15081502
15091503proc rawAddSonNoPropagationOfTypeFlags * (father, son: PType ) =
15101504 when not defined (nimNoNilSeqs):
15111505 if isNil (father.sons): father.sons = @ []
1512- add ( father.sons, son)
1506+ father.sons. add ( son)
15131507
15141508proc addSonNilAllowed * (father, son: PNode ) =
15151509 when not defined (nimNoNilSeqs):
15161510 if isNil (father.sons): father.sons = @ []
1517- add ( father.sons, son)
1511+ father.sons. add ( son)
15181512
15191513proc delSon * (father: PNode , idx: int ) =
15201514 when defined (nimNoNilSeqs):
15211515 if father.len == 0 : return
15221516 else :
15231517 if isNil (father.sons): return
1524- var length = len (father)
1525- for i in idx .. length - 2 : father.sons[i] = father.sons[i + 1 ]
1526- setLen (father.sons, length - 1 )
1518+ for i in idx..< father.len - 1 : father[i] = father[i + 1 ]
1519+ father.sons.setLen (father.len - 1 )
15271520
15281521proc copyNode * (src: PNode ): PNode =
15291522 # does not copy its sons!
@@ -1562,7 +1555,7 @@ proc shallowCopy*(src: PNode): PNode =
15621555 of nkSym: result .sym = src.sym
15631556 of nkIdent: result .ident = src.ident
15641557 of nkStrLit.. nkTripleStrLit: result .strVal = src.strVal
1565- else : newSeq (result .sons, len ( src) )
1558+ else : newSeq (result .sons, src.len )
15661559
15671560proc copyTree * (src: PNode ): PNode =
15681561 # copy a whole syntax tree; performs deep copying
@@ -1583,21 +1576,21 @@ proc copyTree*(src: PNode): PNode =
15831576 of nkIdent: result .ident = src.ident
15841577 of nkStrLit.. nkTripleStrLit: result .strVal = src.strVal
15851578 else :
1586- newSeq (result .sons, len ( src) )
1587- for i in 0 ..< len ( src) :
1588- result .sons [i] = copyTree (src.sons [i])
1579+ newSeq (result .sons, src.len )
1580+ for i in 0 ..< src.len :
1581+ result [i] = copyTree (src[i])
15891582
15901583proc hasSonWith * (n: PNode , kind: TNodeKind ): bool =
1591- for i in 0 ..< len (n) :
1592- if n.sons [i].kind == kind:
1584+ for i in 0 ..< n.len :
1585+ if n[i].kind == kind:
15931586 return true
15941587 result = false
15951588
15961589proc hasNilSon * (n: PNode ): bool =
1597- for i in 0 ..< safeLen (n) :
1598- if n.sons [i] == nil :
1590+ for i in 0 ..< n.safeLen :
1591+ if n[i] == nil :
15991592 return true
1600- elif hasNilSon (n.sons [i]):
1593+ elif hasNilSon (n[i]):
16011594 return true
16021595 result = false
16031596
@@ -1606,15 +1599,15 @@ proc containsNode*(n: PNode, kinds: TNodeKinds): bool =
16061599 case n.kind
16071600 of nkEmpty.. nkNilLit: result = n.kind in kinds
16081601 else :
1609- for i in 0 ..< len (n) :
1610- if n.kind in kinds or containsNode (n.sons [i], kinds): return true
1602+ for i in 0 ..< n.len :
1603+ if n.kind in kinds or containsNode (n[i], kinds): return true
16111604
16121605proc hasSubnodeWith * (n: PNode , kind: TNodeKind ): bool =
16131606 case n.kind
16141607 of nkEmpty.. nkNilLit: result = n.kind == kind
16151608 else :
1616- for i in 0 ..< len (n) :
1617- if (n.sons [i].kind == kind) or hasSubnodeWith (n.sons [i], kind):
1609+ for i in 0 ..< n.len :
1610+ if (n[i].kind == kind) or hasSubnodeWith (n[i], kind):
16181611 return true
16191612 result = false
16201613
@@ -1710,19 +1703,19 @@ proc requiredParams*(s: PSym): int =
17101703 # Returns the number of required params (without default values)
17111704 # XXX: Perhaps we can store this in the `offset` field of the
17121705 # symbol instead?
1713- for i in 1 ..< s.typ.len:
1706+ for i in 1 ..< s.typ.len:
17141707 if s.typ.n[i].sym.ast != nil :
17151708 return i - 1
17161709 return s.typ.len - 1
17171710
17181711proc hasPattern * (s: PSym ): bool {.inline .} =
1719- result = isRoutine (s) and s.ast.sons [patternPos].kind != nkEmpty
1712+ result = isRoutine (s) and s.ast[patternPos].kind != nkEmpty
17201713
17211714iterator items * (n: PNode ): PNode =
1722- for i in 0 ..< n.safeLen: yield n.sons [i]
1715+ for i in 0 ..< n.safeLen: yield n[i]
17231716
17241717iterator pairs * (n: PNode ): tuple [i: int , n: PNode ] =
1725- for i in 0 ..< n.safeLen: yield (i, n.sons [i])
1718+ for i in 0 ..< n.safeLen: yield (i, n[i])
17261719
17271720proc isAtom * (n: PNode ): bool {.inline .} =
17281721 result = n.kind >= nkNone and n.kind <= nkNilLit
@@ -1740,7 +1733,7 @@ proc makeStmtList*(n: PNode): PNode =
17401733
17411734proc skipStmtList * (n: PNode ): PNode =
17421735 if n.kind in {nkStmtList, nkStmtListExpr}:
1743- for i in 0 .. n.len- 2 :
1736+ for i in 0 ..< n.len- 1 :
17441737 if n[i].kind notin {nkEmpty, nkCommentStmt}: return n
17451738 result = n.lastSon
17461739 else :
@@ -1797,7 +1790,7 @@ when false:
17971790 proc containsNil * (n: PNode ): bool =
17981791 # only for debugging
17991792 if n.isNil: return true
1800- for i in 0 ..< n.safeLen:
1793+ for i in 0 ..< n.safeLen:
18011794 if n[i].containsNil: return true
18021795
18031796template hasDestructor * (t: PType ): bool = {tfHasAsgn, tfHasOwned} * t.flags != {}
@@ -1831,11 +1824,11 @@ proc newProcType*(info: TLineInfo; owner: PSym): PType =
18311824 # result.n[0] used to be `nkType`, but now it's `nkEffectList` because
18321825 # the effects are now stored in there too ... this is a bit hacky, but as
18331826 # usual we desperately try to save memory:
1834- addSon ( result .n, newNodeI (nkEffectList, info) )
1827+ result .n. add newNodeI (nkEffectList, info)
18351828
18361829proc addParam * (procType: PType ; param: PSym ) =
18371830 param.position = procType.len- 1
1838- addSon ( procType.n, newSymNode (param) )
1831+ procType.n. add newSymNode (param)
18391832 rawAddSon (procType, param.typ)
18401833
18411834template destructor * (t: PType ): PSym = t.attachedOps[attachedDestructor]
0 commit comments