summary refs log tree commit diff stats
path: root/compiler/semexprs.nim
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/semexprs.nim')
-rw-r--r--compiler/semexprs.nim772
1 files changed, 385 insertions, 387 deletions
diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim
index 2e9c5e1f5..c87ab21b1 100644
--- a/compiler/semexprs.nim
+++ b/compiler/semexprs.nim
@@ -225,13 +225,13 @@ proc isOwnedSym(c: PContext; n: PNode): bool =
   result = s != nil and sfSystemModule in s.owner.flags and s.name.s == "owned"
 
 proc semConv(c: PContext, n: PNode): PNode =
-  if len(n) != 2:
+  if n.len != 2:
     localError(c.config, n.info, "a type conversion takes exactly one argument")
     return n
 
   result = newNodeI(nkConv, n.info)
 
-  var targetType = semTypeNode(c, n.sons[0], nil)
+  var targetType = semTypeNode(c, n[0], nil)
   if targetType.kind == tyTypeDesc:
     internalAssert c.config, targetType.len > 0
     if targetType.base.kind == tyNone:
@@ -252,7 +252,7 @@ proc semConv(c: PContext, n: PNode): PNode =
   maybeLiftType(targetType, c, n[0].info)
 
   if targetType.kind in {tySink, tyLent} or isOwnedSym(c, n[0]):
-    let baseType = semTypeNode(c, n.sons[1], nil).skipTypes({tyTypeDesc})
+    let baseType = semTypeNode(c, n[1], nil).skipTypes({tyTypeDesc})
     let t = newTypeS(targetType.kind, c)
     if targetType.kind == tyOwned:
       t.flags.incl tfHasOwned
@@ -261,23 +261,23 @@ proc semConv(c: PContext, n: PNode): PNode =
     result.typ = makeTypeDesc(c, t)
     return
 
-  result.addSon copyTree(n.sons[0])
+  result.add copyTree(n[0])
 
   # special case to make MyObject(x = 3) produce a nicer error message:
   if n[1].kind == nkExprEqExpr and
       targetType.skipTypes(abstractPtrs).kind == tyObject:
     localError(c.config, n.info, "object construction uses ':', not '='")
-  var op = semExprWithType(c, n.sons[1])
+  var op = semExprWithType(c, n[1])
   if targetType.isMetaType:
     let final = inferWithMetatype(c, targetType, op, true)
-    result.addSon final
+    result.add final
     result.typ = final.typ
     return
 
   result.typ = targetType
   # XXX op is overwritten later on, this is likely added too early
   # here or needs to be overwritten too then.
-  addSon(result, op)
+  result.add op
 
   if not isSymChoice(op):
     let status = checkConvertible(c, result.typ, op)
@@ -285,13 +285,13 @@ proc semConv(c: PContext, n: PNode): PNode =
     of convOK:
       # handle SomeProcType(SomeGenericProc)
       if op.kind == nkSym and op.sym.isGenericRoutine:
-        result.sons[1] = fitNode(c, result.typ, result.sons[1], result.info)
+        result[1] = fitNode(c, result.typ, result[1], result.info)
       elif op.kind in {nkPar, nkTupleConstr} and targetType.kind == tyTuple:
         op = fitNode(c, targetType, op, result.info)
     of convNotNeedeed:
       message(c.config, n.info, hintConvFromXtoItselfNotNeeded, result.typ.typeToString)
     of convNotLegal:
-      result = fitNode(c, result.typ, result.sons[1], result.info)
+      result = fitNode(c, result.typ, result[1], result.info)
       if result == nil:
         localError(c.config, n.info, "illegal conversion from '$1' to '$2'" %
           [op.typ.typeToString, result.typ.typeToString])
@@ -301,23 +301,23 @@ proc semConv(c: PContext, n: PNode): PNode =
       localError(c.config, n.info, errGenerated, value & " can't be converted to " &
         result.typ.typeToString)
   else:
-    for i in 0 ..< len(op):
-      let it = op.sons[i]
+    for i in 0..<op.len:
+      let it = op[i]
       let status = checkConvertible(c, result.typ, it)
       if status in {convOK, convNotNeedeed}:
         markUsed(c, n.info, it.sym)
         onUse(n.info, it.sym)
         markIndirect(c, it.sym)
         return it
-    errorUseQualifier(c, n.info, op.sons[0].sym)
+    errorUseQualifier(c, n.info, op[0].sym)
 
 proc semCast(c: PContext, n: PNode): PNode =
   ## Semantically analyze a casting ("cast[type](param)")
   checkSonsLen(n, 2, c.config)
-  let targetType = semTypeNode(c, n.sons[0], nil)
-  let castedExpr = semExprWithType(c, n.sons[1])
+  let targetType = semTypeNode(c, n[0], nil)
+  let castedExpr = semExprWithType(c, n[1])
   if tfHasMeta in targetType.flags:
-    localError(c.config, n.sons[0].info, "cannot cast to a non concrete type: '$1'" % $targetType)
+    localError(c.config, n[0].info, "cannot cast to a non concrete type: '$1'" % $targetType)
   if not isCastable(c.config, targetType, castedExpr.typ):
     let tar = $targetType
     let alt = typeToString(targetType, preferDesc)
@@ -325,24 +325,24 @@ proc semCast(c: PContext, n: PNode): PNode =
     localError(c.config, n.info, "expression cannot be cast to " & msg)
   result = newNodeI(nkCast, n.info)
   result.typ = targetType
-  addSon(result, copyTree(n.sons[0]))
-  addSon(result, castedExpr)
+  result.add copyTree(n[0])
+  result.add castedExpr
 
 proc semLowHigh(c: PContext, n: PNode, m: TMagic): PNode =
   const
     opToStr: array[mLow..mHigh, string] = ["low", "high"]
-  if len(n) != 2:
+  if n.len != 2:
     localError(c.config, n.info, errXExpectsTypeOrValue % opToStr[m])
   else:
-    n.sons[1] = semExprWithType(c, n.sons[1], {efDetermineType})
-    var typ = skipTypes(n.sons[1].typ, abstractVarRange + {tyTypeDesc, tyUserTypeClassInst})
+    n[1] = semExprWithType(c, n[1], {efDetermineType})
+    var typ = skipTypes(n[1].typ, abstractVarRange + {tyTypeDesc, tyUserTypeClassInst})
     case typ.kind
     of tySequence, tyString, tyCString, tyOpenArray, tyVarargs:
       n.typ = getSysType(c.graph, n.info, tyInt)
     of tyArray:
-      n.typ = typ.sons[0] # indextype
+      n.typ = typ[0] # indextype
     of tyInt..tyInt64, tyChar, tyBool, tyEnum, tyUInt..tyUInt64, tyFloat..tyFloat64:
-      n.typ = n.sons[1].typ.skipTypes({tyTypeDesc})
+      n.typ = n[1].typ.skipTypes({tyTypeDesc})
     of tyGenericParam:
       # prepare this for resolving in semtypinst:
       # we must use copyTree here in order to avoid creating a cycle
@@ -397,8 +397,7 @@ proc isOpImpl(c: PContext, n: PNode, flags: TExprFlags): PNode =
       res = false
   else:
     maybeLiftType(t2, c, n.info)
-    var m: TCandidate
-    initCandidate(c, m, t2)
+    var m = newCandidate(c, t2)
     if efExplain in flags:
       m.diagnostics = @[]
       m.diagnosticsEnabled = true
@@ -408,7 +407,7 @@ proc isOpImpl(c: PContext, n: PNode, flags: TExprFlags): PNode =
   result.typ = n.typ
 
 proc semIs(c: PContext, n: PNode, flags: TExprFlags): PNode =
-  if len(n) != 3:
+  if n.len != 3:
     localError(c.config, n.info, "'is' operator takes 2 arguments")
 
   let boolType = getSysType(c.graph, n.info, tyBool)
@@ -416,10 +415,10 @@ proc semIs(c: PContext, n: PNode, flags: TExprFlags): PNode =
   n.typ = boolType
   var liftLhs = true
 
-  n.sons[1] = semExprWithType(c, n[1], {efDetermineType, efWantIterator})
+  n[1] = semExprWithType(c, n[1], {efDetermineType, efWantIterator})
   if n[2].kind notin {nkStrLit..nkTripleStrLit}:
     let t2 = semTypeNode(c, n[2], nil)
-    n.sons[2] = newNodeIT(nkType, n[2].info, t2)
+    n[2] = newNodeIT(nkType, n[2].info, t2)
     if t2.kind == tyStatic:
       let evaluated = tryConstExpr(c, n[1])
       if evaluated != nil:
@@ -435,7 +434,7 @@ proc semIs(c: PContext, n: PNode, flags: TExprFlags): PNode =
       # not allow regular values to be matched against the type:
       liftLhs = false
   else:
-    n.sons[2] = semExpr(c, n[2])
+    n[2] = semExpr(c, n[2])
 
   var lhsType = n[1].typ
   if lhsType.kind != tyTypeDesc:
@@ -452,15 +451,15 @@ proc semIs(c: PContext, n: PNode, flags: TExprFlags): PNode =
 
 proc semOpAux(c: PContext, n: PNode) =
   const flags = {efDetermineType}
-  for i in 1 ..< n.len:
-    var a = n.sons[i]
-    if a.kind == nkExprEqExpr and len(a) == 2:
-      let info = a.sons[0].info
-      a.sons[0] = newIdentNode(considerQuotedIdent(c, a.sons[0], a), info)
-      a.sons[1] = semExprWithType(c, a.sons[1], flags)
-      a.typ = a.sons[1].typ
+  for i in 1..<n.len:
+    var a = n[i]
+    if a.kind == nkExprEqExpr and a.len == 2:
+      let info = a[0].info
+      a[0] = newIdentNode(considerQuotedIdent(c, a[0], a), info)
+      a[1] = semExprWithType(c, a[1], flags)
+      a.typ = a[1].typ
     else:
-      n.sons[i] = semExprWithType(c, a, flags)
+      n[i] = semExprWithType(c, a, flags)
 
 proc overloadedCallOpr(c: PContext, n: PNode): PNode =
   # quick check if there is *any* () operator overloaded:
@@ -469,24 +468,24 @@ proc overloadedCallOpr(c: PContext, n: PNode): PNode =
     result = nil
   else:
     result = newNodeI(nkCall, n.info)
-    addSon(result, newIdentNode(par, n.info))
-    for i in 0 ..< len(n): addSon(result, n.sons[i])
+    result.add newIdentNode(par, n.info)
+    for i in 0..<n.len: result.add n[i]
     result = semExpr(c, result)
 
 proc changeType(c: PContext; n: PNode, newType: PType, check: bool) =
   case n.kind
   of nkCurly, nkBracket:
-    for i in 0 ..< len(n):
-      changeType(c, n.sons[i], elemType(newType), check)
+    for i in 0..<n.len:
+      changeType(c, n[i], elemType(newType), check)
   of nkPar, nkTupleConstr:
     let tup = newType.skipTypes({tyGenericInst, tyAlias, tySink, tyDistinct})
     if tup.kind != tyTuple:
       if tup.kind == tyObject: return
       globalError(c.config, n.info, "no tuple type for constructor")
-    elif len(n) > 0 and n.sons[0].kind == nkExprColonExpr:
+    elif n.len > 0 and n[0].kind == nkExprColonExpr:
       # named tuple?
-      for i in 0 ..< len(n):
-        var m = n.sons[i].sons[0]
+      for i in 0..<n.len:
+        var m = n[i][0]
         if m.kind != nkSym:
           globalError(c.config, m.info, "invalid tuple constructor")
           return
@@ -495,18 +494,18 @@ proc changeType(c: PContext; n: PNode, newType: PType, check: bool) =
           if f == nil:
             globalError(c.config, m.info, "unknown identifier: " & m.sym.name.s)
             return
-          changeType(c, n.sons[i].sons[1], f.typ, check)
+          changeType(c, n[i][1], f.typ, check)
         else:
-          changeType(c, n.sons[i].sons[1], tup.sons[i], check)
+          changeType(c, n[i][1], tup[i], check)
     else:
-      for i in 0 ..< len(n):
-        changeType(c, n.sons[i], tup.sons[i], check)
+      for i in 0..<n.len:
+        changeType(c, n[i], tup[i], check)
         when false:
-          var m = n.sons[i]
-          var a = newNodeIT(nkExprColonExpr, m.info, newType.sons[i])
-          addSon(a, newSymNode(newType.n.sons[i].sym))
-          addSon(a, m)
-          changeType(m, tup.sons[i], check)
+          var m = n[i]
+          var a = newNodeIT(nkExprColonExpr, m.info, newType[i])
+          a.add newSymNode(newType.n[i].sym)
+          a.add m
+          changeType(m, tup[i], check)
   of nkCharLit..nkUInt64Lit:
     if check and n.kind != nkUInt64Lit:
       let value = n.intVal
@@ -522,12 +521,12 @@ proc changeType(c: PContext; n: PNode, newType: PType, check: bool) =
 proc arrayConstrType(c: PContext, n: PNode): PType =
   var typ = newTypeS(tyArray, c)
   rawAddSon(typ, nil)     # index type
-  if len(n) == 0:
+  if n.len == 0:
     rawAddSon(typ, newTypeS(tyEmpty, c)) # needs an empty basetype!
   else:
-    var t = skipTypes(n.sons[0].typ, {tyGenericInst, tyVar, tyLent, tyOrdinal, tyAlias, tySink})
+    var t = skipTypes(n[0].typ, {tyGenericInst, tyVar, tyLent, tyOrdinal, tyAlias, tySink})
     addSonSkipIntLit(typ, t)
-  typ.sons[0] = makeRangeType(c, 0, len(n) - 1, n.info)
+  typ[0] = makeRangeType(c, 0, n.len - 1, n.info)
   result = typ
 
 proc semArrayConstr(c: PContext, n: PNode, flags: TExprFlags): PNode =
@@ -538,13 +537,13 @@ proc semArrayConstr(c: PContext, n: PNode, flags: TExprFlags): PNode =
     firstIndex, lastIndex: Int128
     indexType = getSysType(c.graph, n.info, tyInt)
     lastValidIndex = lastOrd(c.config, indexType)
-  if len(n) == 0:
+  if n.len == 0:
     rawAddSon(result.typ, newTypeS(tyEmpty, c)) # needs an empty basetype!
     lastIndex = toInt128(-1)
   else:
-    var x = n.sons[0]
-    if x.kind == nkExprColonExpr and len(x) == 2:
-      var idx = semConstExpr(c, x.sons[0])
+    var x = n[0]
+    if x.kind == nkExprColonExpr and x.len == 2:
+      var idx = semConstExpr(c, x[0])
       if not isOrdinalType(idx.typ):
         localError(c.config, idx.info, "expected ordinal value for array " &
                    "index, got '$1'" % renderTree(idx))
@@ -553,51 +552,51 @@ proc semArrayConstr(c: PContext, n: PNode, flags: TExprFlags): PNode =
         lastIndex = firstIndex
         indexType = idx.typ
         lastValidIndex = lastOrd(c.config, indexType)
-        x = x.sons[1]
+        x = x[1]
 
     let yy = semExprWithType(c, x)
     var typ = yy.typ
-    addSon(result, yy)
-    #var typ = skipTypes(result.sons[0].typ, {tyGenericInst, tyVar, tyLent, tyOrdinal})
-    for i in 1 ..< len(n):
+    result.add yy
+    #var typ = skipTypes(result[0].typ, {tyGenericInst, tyVar, tyLent, tyOrdinal})
+    for i in 1..<n.len:
       if lastIndex == lastValidIndex:
         let validIndex = makeRangeType(c, toInt64(firstIndex), toInt64(lastValidIndex), n.info,
                                        indexType)
         localError(c.config, n.info, "size of array exceeds range of index " &
           "type '$1' by $2 elements" % [typeToString(validIndex), $(n.len-i)])
 
-      x = n.sons[i]
-      if x.kind == nkExprColonExpr and len(x) == 2:
-        var idx = semConstExpr(c, x.sons[0])
+      x = n[i]
+      if x.kind == nkExprColonExpr and x.len == 2:
+        var idx = semConstExpr(c, x[0])
         idx = fitNode(c, indexType, idx, x.info)
         if lastIndex+1 != getOrdValue(idx):
           localError(c.config, x.info, "invalid order in array constructor")
-        x = x.sons[1]
+        x = x[1]
 
       let xx = semExprWithType(c, x, flags*{efAllowDestructor})
       result.add xx
       typ = commonType(typ, xx.typ)
-      #n.sons[i] = semExprWithType(c, x, flags*{efAllowDestructor})
-      #addSon(result, fitNode(c, typ, n.sons[i]))
+      #n[i] = semExprWithType(c, x, flags*{efAllowDestructor})
+      #result.add fitNode(c, typ, n[i])
       inc(lastIndex)
     addSonSkipIntLit(result.typ, typ)
-    for i in 0 ..< result.len:
-      result.sons[i] = fitNode(c, typ, result.sons[i], result.sons[i].info)
-  result.typ.sons[0] = makeRangeType(c, toInt64(firstIndex), toInt64(lastIndex), n.info,
+    for i in 0..<result.len:
+      result[i] = fitNode(c, typ, result[i], result[i].info)
+  result.typ[0] = makeRangeType(c, toInt64(firstIndex), toInt64(lastIndex), n.info,
                                      indexType)
 
 proc fixAbstractType(c: PContext, n: PNode) =
-  for i in 1 ..< n.len:
-    let it = n.sons[i]
+  for i in 1..<n.len:
+    let it = n[i]
     # do not get rid of nkHiddenSubConv for OpenArrays, the codegen needs it:
     if it.kind == nkHiddenSubConv and
         skipTypes(it.typ, abstractVar).kind notin {tyOpenArray, tyVarargs}:
-      if skipTypes(it.sons[1].typ, abstractVar).kind in
+      if skipTypes(it[1].typ, abstractVar).kind in
             {tyNil, tyTuple, tySet} or it[1].isArrayConstr:
         var s = skipTypes(it.typ, abstractVar)
         if s.kind != tyUntyped:
-          changeType(c, it.sons[1], s, check=true)
-        n.sons[i] = it.sons[1]
+          changeType(c, it[1], s, check=true)
+        n[i] = it[1]
 
 proc isAssignable(c: PContext, n: PNode; isUnsafeAddr=false): TAssignableResult =
   result = parampatterns.isAssignable(c.p.owner, n, isUnsafeAddr)
@@ -629,17 +628,17 @@ proc hasUnresolvedArgs(c: PContext, n: PNode): bool =
       return false
   else:
     for i in 0..<n.safeLen:
-      if hasUnresolvedArgs(c, n.sons[i]): return true
+      if hasUnresolvedArgs(c, n[i]): return true
     return false
 
 proc newHiddenAddrTaken(c: PContext, n: PNode): PNode =
   if n.kind == nkHiddenDeref and not (c.config.cmd == cmdCompileToCpp or
                                       sfCompileToCpp in c.module.flags):
     checkSonsLen(n, 1, c.config)
-    result = n.sons[0]
+    result = n[0]
   else:
     result = newNodeIT(nkHiddenAddr, n.info, makeVarType(c, n.typ))
-    addSon(result, n)
+    result.add n
     if isAssignable(c, n) notin {arLValue, arLocalLValue}:
       localError(c.config, n.info, errVarForOutParamNeededX % renderNotLValue(n))
 
@@ -654,16 +653,16 @@ proc analyseIfAddressTaken(c: PContext, n: PNode): PNode =
       result = newHiddenAddrTaken(c, n)
   of nkDotExpr:
     checkSonsLen(n, 2, c.config)
-    if n.sons[1].kind != nkSym:
+    if n[1].kind != nkSym:
       internalError(c.config, n.info, "analyseIfAddressTaken")
       return
-    if skipTypes(n.sons[1].sym.typ, abstractInst-{tyTypeDesc}).kind notin {tyVar, tyLent}:
-      incl(n.sons[1].sym.flags, sfAddrTaken)
+    if skipTypes(n[1].sym.typ, abstractInst-{tyTypeDesc}).kind notin {tyVar, tyLent}:
+      incl(n[1].sym.flags, sfAddrTaken)
       result = newHiddenAddrTaken(c, n)
   of nkBracketExpr:
     checkMinSonsLen(n, 1, c.config)
-    if skipTypes(n.sons[0].typ, abstractInst-{tyTypeDesc}).kind notin {tyVar, tyLent}:
-      if n.sons[0].kind == nkSym: incl(n.sons[0].sym.flags, sfAddrTaken)
+    if skipTypes(n[0].typ, abstractInst-{tyTypeDesc}).kind notin {tyVar, tyLent}:
+      if n[0].kind == nkSym: incl(n[0].sym.flags, sfAddrTaken)
       result = newHiddenAddrTaken(c, n)
   else:
     result = newHiddenAddrTaken(c, n)
@@ -678,14 +677,14 @@ proc analyseIfAddressTakenInCall(c: PContext, n: PNode) =
 
   # get the real type of the callee
   # it may be a proc var with a generic alias type, so we skip over them
-  var t = n.sons[0].typ.skipTypes({tyGenericInst, tyAlias, tySink})
+  var t = n[0].typ.skipTypes({tyGenericInst, tyAlias, tySink})
 
-  if n.sons[0].kind == nkSym and n.sons[0].sym.magic in FakeVarParams:
+  if n[0].kind == nkSym and n[0].sym.magic in FakeVarParams:
     # BUGFIX: check for L-Value still needs to be done for the arguments!
     # note sometimes this is eval'ed twice so we check for nkHiddenAddr here:
-    for i in 1 ..< len(n):
-      if i < len(t) and t.sons[i] != nil and
-          skipTypes(t.sons[i], abstractInst-{tyTypeDesc}).kind == tyVar:
+    for i in 1..<n.len:
+      if i < t.len and t[i] != nil and
+          skipTypes(t[i], abstractInst-{tyTypeDesc}).kind == tyVar:
         let it = n[i]
         if isAssignable(c, it) notin {arLValue, arLocalLValue}:
           if it.kind != nkHiddenAddr:
@@ -699,23 +698,23 @@ proc analyseIfAddressTakenInCall(c: PContext, n: PNode) =
         localError(c.config, n.info, errXStackEscape % renderTree(n[1], {renderNoComments}))
 
     return
-  for i in 1 ..< len(n):
+  for i in 1..<n.len:
     let n = if n.kind == nkHiddenDeref: n[0] else: n
-    if n.sons[i].kind == nkHiddenCallConv:
+    if n[i].kind == nkHiddenCallConv:
       # we need to recurse explicitly here as converters can create nested
       # calls and then they wouldn't be analysed otherwise
-      analyseIfAddressTakenInCall(c, n.sons[i])
-    if i < len(t) and
-        skipTypes(t.sons[i], abstractInst-{tyTypeDesc}).kind == tyVar:
-      if n.sons[i].kind != nkHiddenAddr:
-        n.sons[i] = analyseIfAddressTaken(c, n.sons[i])
+      analyseIfAddressTakenInCall(c, n[i])
+    if i < t.len and
+        skipTypes(t[i], abstractInst-{tyTypeDesc}).kind == tyVar:
+      if n[i].kind != nkHiddenAddr:
+        n[i] = analyseIfAddressTaken(c, n[i])
 
 include semmagic
 
 proc evalAtCompileTime(c: PContext, n: PNode): PNode =
   result = n
-  if n.kind notin nkCallKinds or n.sons[0].kind != nkSym: return
-  var callee = n.sons[0].sym
+  if n.kind notin nkCallKinds or n[0].kind != nkSym: return
+  var callee = n[0].sym
   # workaround for bug #537 (overly aggressive inlining leading to
   # wrong NimNode semantics):
   if n.typ != nil and tfTriggersCompileTime in n.typ.flags: return
@@ -723,14 +722,14 @@ proc evalAtCompileTime(c: PContext, n: PNode): PNode =
   # constant folding that is necessary for correctness of semantic pass:
   if callee.magic != mNone and callee.magic in ctfeWhitelist and n.typ != nil:
     var call = newNodeIT(nkCall, n.info, n.typ)
-    call.add(n.sons[0])
+    call.add(n[0])
     var allConst = true
-    for i in 1 ..< n.len:
-      var a = getConstExpr(c.module, n.sons[i], c.graph)
+    for i in 1..<n.len:
+      var a = getConstExpr(c.module, n[i], c.graph)
       if a == nil:
         allConst = false
-        a = n.sons[i]
-        if a.kind == nkHiddenStdConv: a = a.sons[1]
+        a = n[i]
+        if a.kind == nkHiddenStdConv: a = a[1]
       call.add(a)
     if allConst:
       result = semfold.getConstExpr(c.module, call, c.graph)
@@ -743,7 +742,7 @@ proc evalAtCompileTime(c: PContext, n: PNode): PNode =
     # done until we have a more robust infrastructure for
     # implicit statics.
     if n.len > 1:
-      for i in 1 ..< n.len:
+      for i in 1..<n.len:
         # see bug #2113, it's possible that n[i].typ for errornous code:
         if n[i].typ.isNil or n[i].typ.kind != tyStatic or
             tfUnresolved notin n[i].typ.flags:
@@ -768,9 +767,9 @@ proc evalAtCompileTime(c: PContext, n: PNode): PNode =
     if n.typ != nil and typeAllowed(n.typ, skConst) != nil: return
 
     var call = newNodeIT(nkCall, n.info, n.typ)
-    call.add(n.sons[0])
-    for i in 1 ..< n.len:
-      let a = getConstExpr(c.module, n.sons[i], c.graph)
+    call.add(n[0])
+    for i in 1..<n.len:
+      let a = getConstExpr(c.module, n[i], c.graph)
       if a == nil: return n
       call.add(a)
 
@@ -818,10 +817,10 @@ proc semOverloadedCallAnalyseEffects(c: PContext, n: PNode, nOrig: PNode,
       {skProc, skFunc, skMethod, skConverter, skMacro, skTemplate}, flags)
 
   if result != nil:
-    if result.sons[0].kind != nkSym:
+    if result[0].kind != nkSym:
       internalError(c.config, "semOverloadedCallAnalyseEffects")
       return
-    let callee = result.sons[0].sym
+    let callee = result[0].sym
     case callee.kind
     of skMacro, skTemplate: discard
     else:
@@ -829,7 +828,7 @@ proc semOverloadedCallAnalyseEffects(c: PContext, n: PNode, nOrig: PNode,
         localError(c.config, n.info, errRecursiveDependencyIteratorX % callee.name.s)
         # error correction, prevents endless for loop elimination in transf.
         # See bug #2051:
-        result.sons[0] = newSymNode(errorSym(c, n))
+        result[0] = newSymNode(errorSym(c, n))
 
 proc semObjConstr(c: PContext, n: PNode, flags: TExprFlags): PNode
 
@@ -840,7 +839,7 @@ proc resolveIndirectCall(c: PContext; n, nOrig: PNode;
   if result.state != csMatch:
     # try to deref the first argument:
     if implicitDeref in c.features and canDeref(n):
-      n.sons[1] = n.sons[1].tryDeref
+      n[1] = n[1].tryDeref
       initCandidate(c, result, t)
       matches(c, n, nOrig, result)
 
@@ -851,12 +850,12 @@ proc bracketedMacro(n: PNode): PSym =
       result = nil
 
 proc setGenericParams(c: PContext, n: PNode) =
-  for i in 1 ..< n.len:
+  for i in 1..<n.len:
     n[i].typ = semTypeNode(c, n[i], nil)
 
 proc afterCallActions(c: PContext; n, orig: PNode, flags: TExprFlags): PNode =
   result = n
-  let callee = result.sons[0].sym
+  let callee = result[0].sym
   case callee.kind
   of skMacro: result = semMacroExpr(c, result, orig, callee, flags)
   of skTemplate: result = semTemplateExpr(c, result, callee, flags)
@@ -869,7 +868,7 @@ proc afterCallActions(c: PContext; n, orig: PNode, flags: TExprFlags): PNode =
       result = magicsAfterOverloadResolution(c, result, flags)
     when false:
       if result.typ != nil and
-          not (result.typ.kind == tySequence and result.typ.sons[0].kind == tyEmpty):
+          not (result.typ.kind == tySequence and result.typ[0].kind == tyEmpty):
         liftTypeBoundOps(c, result.typ, n.info)
     #result = patchResolvedTypeBoundOp(c, result)
   if c.matchedConcept == nil:
@@ -878,26 +877,26 @@ proc afterCallActions(c: PContext; n, orig: PNode, flags: TExprFlags): PNode =
 proc semIndirectOp(c: PContext, n: PNode, flags: TExprFlags): PNode =
   result = nil
   checkMinSonsLen(n, 1, c.config)
-  var prc = n.sons[0]
-  if n.sons[0].kind == nkDotExpr:
-    checkSonsLen(n.sons[0], 2, c.config)
-    let n0 = semFieldAccess(c, n.sons[0])
+  var prc = n[0]
+  if n[0].kind == nkDotExpr:
+    checkSonsLen(n[0], 2, c.config)
+    let n0 = semFieldAccess(c, n[0])
     if n0.kind == nkDotCall:
       # it is a static call!
       result = n0
       result.kind = nkCall
       result.flags.incl nfExplicitCall
-      for i in 1 ..< len(n): addSon(result, n.sons[i])
+      for i in 1..<n.len: result.add n[i]
       return semExpr(c, result, flags)
     else:
-      n.sons[0] = n0
+      n[0] = n0
   else:
-    n.sons[0] = semExpr(c, n.sons[0], {efInCall})
-    let t = n.sons[0].typ
+    n[0] = semExpr(c, n[0], {efInCall})
+    let t = n[0].typ
     if t != nil and t.kind in {tyVar, tyLent}:
-      n.sons[0] = newDeref(n.sons[0])
-    elif n.sons[0].kind == nkBracketExpr:
-      let s = bracketedMacro(n.sons[0])
+      n[0] = newDeref(n[0])
+    elif n[0].kind == nkBracketExpr:
+      let s = bracketedMacro(n[0])
       if s != nil:
         setGenericParams(c, n[0])
         return semDirectOp(c, n, flags)
@@ -905,8 +904,8 @@ proc semIndirectOp(c: PContext, n: PNode, flags: TExprFlags): PNode =
   let nOrig = n.copyTree
   semOpAux(c, n)
   var t: PType = nil
-  if n.sons[0].typ != nil:
-    t = skipTypes(n.sons[0].typ, abstractInst+{tyOwned}-{tyTypeDesc, tyDistinct})
+  if n[0].typ != nil:
+    t = skipTypes(n[0].typ, abstractInst+{tyOwned}-{tyTypeDesc, tyDistinct})
   if t != nil and t.kind == tyProc:
     # This is a proc variable, apply normal overload resolution
     let m = resolveIndirectCall(c, n, nOrig, t)
@@ -918,16 +917,16 @@ proc semIndirectOp(c: PContext, n: PNode, flags: TExprFlags): PNode =
       else:
         var hasErrorType = false
         var msg = "type mismatch: got <"
-        for i in 1 ..< len(n):
-          if i > 1: add(msg, ", ")
-          let nt = n.sons[i].typ
-          add(msg, typeToString(nt))
+        for i in 1..<n.len:
+          if i > 1: msg.add(", ")
+          let nt = n[i].typ
+          msg.add(typeToString(nt))
           if nt.kind == tyError:
             hasErrorType = true
             break
         if not hasErrorType:
-          add(msg, ">\nbut expected one of: \n" &
-              typeToString(n.sons[0].typ))
+          msg.add(">\nbut expected one of: \n" &
+              typeToString(n[0].typ))
           localError(c.config, n.info, msg)
         return errorNode(c, n)
       result = nil
@@ -945,8 +944,8 @@ proc semIndirectOp(c: PContext, n: PNode, flags: TExprFlags): PNode =
     if result == nil:
       # XXX: hmm, what kind of symbols will end up here?
       # do we really need to try the overload resolution?
-      n.sons[0] = prc
-      nOrig.sons[0] = prc
+      n[0] = prc
+      nOrig[0] = prc
       n.flags.incl nfExprCall
       result = semOverloadedCallAnalyseEffects(c, n, nOrig, flags)
       if result == nil: return errorNode(c, n)
@@ -955,7 +954,7 @@ proc semIndirectOp(c: PContext, n: PNode, flags: TExprFlags): PNode =
       # See bug #904 of how to trigger it:
       return result
   #result = afterCallActions(c, result, nOrig, flags)
-  if result.sons[0].kind == nkSym:
+  if result[0].kind == nkSym:
     result = afterCallActions(c, result, nOrig, flags)
   else:
     fixAbstractType(c, result)
@@ -974,11 +973,11 @@ proc buildEchoStmt(c: PContext, n: PNode): PNode =
   result = newNodeI(nkCall, n.info)
   var e = strTableGet(c.graph.systemModule.tab, getIdent(c.cache, "echo"))
   if e != nil:
-    add(result, newSymNode(e))
+    result.add(newSymNode(e))
   else:
     localError(c.config, n.info, "system needs: echo")
-    add(result, errorNode(c, n))
-  add(result, n)
+    result.add(errorNode(c, n))
+  result.add(n)
   result = semExpr(c, result)
 
 proc semExprNoType(c: PContext, n: PNode): PNode =
@@ -1006,50 +1005,50 @@ proc lookupInRecordAndBuildCheck(c: PContext, n, r: PNode, field: PIdent,
   result = nil
   case r.kind
   of nkRecList:
-    for i in 0 ..< len(r):
-      result = lookupInRecordAndBuildCheck(c, n, r.sons[i], field, check)
+    for i in 0..<r.len:
+      result = lookupInRecordAndBuildCheck(c, n, r[i], field, check)
       if result != nil: return
   of nkRecCase:
     checkMinSonsLen(r, 2, c.config)
-    if (r.sons[0].kind != nkSym): illFormedAst(r, c.config)
-    result = lookupInRecordAndBuildCheck(c, n, r.sons[0], field, check)
+    if (r[0].kind != nkSym): illFormedAst(r, c.config)
+    result = lookupInRecordAndBuildCheck(c, n, r[0], field, check)
     if result != nil: return
-    let setType = createSetType(c, r.sons[0].typ)
+    let setType = createSetType(c, r[0].typ)
     var s = newNodeIT(nkCurly, r.info, setType)
-    for i in 1 ..< len(r):
-      var it = r.sons[i]
+    for i in 1..<r.len:
+      var it = r[i]
       case it.kind
       of nkOfBranch:
         result = lookupInRecordAndBuildCheck(c, n, lastSon(it), field, check)
         if result == nil:
-          for j in 0..len(it)-2: addSon(s, copyTree(it.sons[j]))
+          for j in 0..<it.len-1: s.add copyTree(it[j])
         else:
           if check == nil:
             check = newNodeI(nkCheckedFieldExpr, n.info)
-            addSon(check, c.graph.emptyNode) # make space for access node
+            check.add c.graph.emptyNode # make space for access node
           s = newNodeIT(nkCurly, n.info, setType)
-          for j in 0 .. len(it) - 2: addSon(s, copyTree(it.sons[j]))
+          for j in 0..<it.len - 1: s.add copyTree(it[j])
           var inExpr = newNodeIT(nkCall, n.info, getSysType(c.graph, n.info, tyBool))
-          addSon(inExpr, newSymNode(c.graph.opContains, n.info))
-          addSon(inExpr, s)
-          addSon(inExpr, copyTree(r.sons[0]))
-          addSon(check, inExpr)
-          #addSon(check, semExpr(c, inExpr))
+          inExpr.add newSymNode(c.graph.opContains, n.info)
+          inExpr.add s
+          inExpr.add copyTree(r[0])
+          check.add inExpr
+          #check.add semExpr(c, inExpr)
           return
       of nkElse:
         result = lookupInRecordAndBuildCheck(c, n, lastSon(it), field, check)
         if result != nil:
           if check == nil:
             check = newNodeI(nkCheckedFieldExpr, n.info)
-            addSon(check, c.graph.emptyNode) # make space for access node
+            check.add c.graph.emptyNode # make space for access node
           var inExpr = newNodeIT(nkCall, n.info, getSysType(c.graph, n.info, tyBool))
-          addSon(inExpr, newSymNode(c.graph.opContains, n.info))
-          addSon(inExpr, s)
-          addSon(inExpr, copyTree(r.sons[0]))
+          inExpr.add newSymNode(c.graph.opContains, n.info)
+          inExpr.add s
+          inExpr.add copyTree(r[0])
           var notExpr = newNodeIT(nkCall, n.info, getSysType(c.graph, n.info, tyBool))
-          addSon(notExpr, newSymNode(c.graph.opNot, n.info))
-          addSon(notExpr, inExpr)
-          addSon(check, notExpr)
+          notExpr.add newSymNode(c.graph.opNot, n.info)
+          notExpr.add inExpr
+          check.add notExpr
           return
       else: illFormedAst(it, c.config)
   of nkSym:
@@ -1087,13 +1086,13 @@ proc readTypeParameter(c: PContext, typ: PType,
         discard
 
   if typ.kind != tyUserTypeClass:
-    let ty = if typ.kind == tyCompositeTypeClass: typ.sons[1].skipGenericAlias
+    let ty = if typ.kind == tyCompositeTypeClass: typ[1].skipGenericAlias
              else: typ.skipGenericAlias
-    let tbody = ty.sons[0]
-    for s in 0 .. tbody.len-2:
-      let tParam = tbody.sons[s]
+    let tbody = ty[0]
+    for s in 0..<tbody.len-1:
+      let tParam = tbody[s]
       if tParam.sym.name.id == paramName.id:
-        let rawTyp = ty.sons[s + 1]
+        let rawTyp = ty[s + 1]
         if rawTyp.kind == tyStatic:
           if rawTyp.n != nil:
             return rawTyp.n
@@ -1227,12 +1226,12 @@ proc semSym(c: PContext, n: PNode, sym: PSym, flags: TExprFlags): PNode =
             result.add makeDeref(newSymNode(p.selfSym))
             result.add newSymNode(f) # we now have the correct field
             if check != nil:
-              check.sons[0] = result
+              check[0] = result
               check.typ = result.typ
               result = check
             return result
-          if ty.sons[0] == nil: break
-          ty = skipTypes(ty.sons[0], skipPtrs)
+          if ty[0] == nil: break
+          ty = skipTypes(ty[0], skipPtrs)
     # old code, not sure if it's live code:
     markUsed(c, n.info, s)
     onUse(n.info, s)
@@ -1250,7 +1249,7 @@ proc builtinFieldAccess(c: PContext, n: PNode, flags: TExprFlags): PNode =
   # tests/bind/tbindoverload.nim wants an early exit here, but seems to
   # work without now. template/tsymchoicefield doesn't like an early exit
   # here at all!
-  #if isSymChoice(n.sons[1]): return
+  #if isSymChoice(n[1]): return
   when defined(nimsuggest):
     if c.config.cmd == cmdIdeTools:
       suggestExpr(c, n)
@@ -1262,15 +1261,15 @@ proc builtinFieldAccess(c: PContext, n: PNode, flags: TExprFlags): PNode =
       result = symChoice(c, n, s, scClosed)
       if result.kind == nkSym: result = semSym(c, n, s, flags)
     else:
-      markUsed(c, n.sons[1].info, s)
+      markUsed(c, n[1].info, s)
       result = semSym(c, n, s, flags)
-    onUse(n.sons[1].info, s)
+    onUse(n[1].info, s)
     return
 
-  n.sons[0] = semExprWithType(c, n.sons[0], flags+{efDetermineType})
-  #restoreOldStyleType(n.sons[0])
-  var i = considerQuotedIdent(c, n.sons[1], n)
-  var ty = n.sons[0].typ
+  n[0] = semExprWithType(c, n[0], flags+{efDetermineType})
+  #restoreOldStyleType(n[0])
+  var i = considerQuotedIdent(c, n[1], n)
+  var ty = n[0].typ
   var f: PSym = nil
   result = nil
 
@@ -1311,7 +1310,7 @@ proc builtinFieldAccess(c: PContext, n: PNode, flags: TExprFlags): PNode =
       ty = ty.base
       argIsType = true
   else:
-    argIsType = isTypeExpr(n.sons[0])
+    argIsType = isTypeExpr(n[0])
 
   if argIsType:
     ty = ty.skipTypes(tyDotOpTransparent)
@@ -1321,7 +1320,7 @@ proc builtinFieldAccess(c: PContext, n: PNode, flags: TExprFlags): PNode =
       while ty != nil:
         f = getSymFromList(ty.n, i)
         if f != nil: break
-        ty = ty.sons[0]         # enum inheritance
+        ty = ty[0]         # enum inheritance
       if f != nil:
         result = newSymNode(f)
         result.info = n.info
@@ -1340,7 +1339,7 @@ proc builtinFieldAccess(c: PContext, n: PNode, flags: TExprFlags): PNode =
       return
     # XXX: This is probably not relevant any more
     # reset to prevent 'nil' bug: see "tests/reject/tenumitems.nim":
-    ty = n.sons[0].typ
+    ty = n[0].typ
     return nil
   if ty.kind in tyUserTypeClasses and ty.isResolvedUserTypeClass:
     ty = ty.lastSon
@@ -1352,8 +1351,8 @@ proc builtinFieldAccess(c: PContext, n: PNode, flags: TExprFlags): PNode =
       check = nil
       f = lookupInRecordAndBuildCheck(c, n, ty.n, i, check)
       if f != nil: break
-      if ty.sons[0] == nil: break
-      ty = skipTypes(ty.sons[0], skipPtrs)
+      if ty[0] == nil: break
+      ty = skipTypes(ty[0], skipPtrs)
     if f != nil:
       let visibilityCheckNeeded =
         if n[1].kind == nkSym and n[1].sym == f:
@@ -1361,43 +1360,43 @@ proc builtinFieldAccess(c: PContext, n: PNode, flags: TExprFlags): PNode =
         else: true
       if not visibilityCheckNeeded or fieldVisible(c, f):
         # is the access to a public field or in the same module or in a friend?
-        markUsed(c, n.sons[1].info, f)
-        onUse(n.sons[1].info, f)
-        n.sons[0] = makeDeref(n.sons[0])
-        n.sons[1] = newSymNode(f) # we now have the correct field
+        markUsed(c, n[1].info, f)
+        onUse(n[1].info, f)
+        n[0] = makeDeref(n[0])
+        n[1] = newSymNode(f) # we now have the correct field
         n.typ = f.typ
         if check == nil:
           result = n
         else:
-          check.sons[0] = n
+          check[0] = n
           check.typ = n.typ
           result = check
   elif ty.kind == tyTuple and ty.n != nil:
     f = getSymFromList(ty.n, i)
     if f != nil:
-      markUsed(c, n.sons[1].info, f)
-      onUse(n.sons[1].info, f)
-      n.sons[0] = makeDeref(n.sons[0])
-      n.sons[1] = newSymNode(f)
+      markUsed(c, n[1].info, f)
+      onUse(n[1].info, f)
+      n[0] = makeDeref(n[0])
+      n[1] = newSymNode(f)
       n.typ = f.typ
       result = n
 
   # we didn't find any field, let's look for a generic param
   if result == nil:
-    let t = n.sons[0].typ.skipTypes(tyDotOpTransparent)
+    let t = n[0].typ.skipTypes(tyDotOpTransparent)
     tryReadingGenericParam(t)
 
 proc dotTransformation(c: PContext, n: PNode): PNode =
-  if isSymChoice(n.sons[1]):
+  if isSymChoice(n[1]):
     result = newNodeI(nkDotCall, n.info)
-    addSon(result, n.sons[1])
-    addSon(result, copyTree(n[0]))
+    result.add n[1]
+    result.add copyTree(n[0])
   else:
-    var i = considerQuotedIdent(c, n.sons[1], n)
+    var i = considerQuotedIdent(c, n[1], n)
     result = newNodeI(nkDotCall, n.info)
     result.flags.incl nfDotField
-    addSon(result, newIdentNode(i, n[1].info))
-    addSon(result, copyTree(n[0]))
+    result.add newIdentNode(i, n[1].info)
+    result.add copyTree(n[0])
 
 proc semFieldAccess(c: PContext, n: PNode, flags: TExprFlags): PNode =
   # this is difficult, because the '.' is used in many different contexts
@@ -1409,22 +1408,22 @@ proc semFieldAccess(c: PContext, n: PNode, flags: TExprFlags): PNode =
 proc buildOverloadedSubscripts(n: PNode, ident: PIdent): PNode =
   result = newNodeI(nkCall, n.info)
   result.add(newIdentNode(ident, n.info))
-  for i in 0 .. n.len-1: result.add(n[i])
+  for s in n: result.add s
 
 proc semDeref(c: PContext, n: PNode): PNode =
   checkSonsLen(n, 1, c.config)
-  n.sons[0] = semExprWithType(c, n.sons[0])
+  n[0] = semExprWithType(c, n[0])
   result = n
-  var t = skipTypes(n.sons[0].typ, {tyGenericInst, tyVar, tyLent, tyAlias, tySink, tyOwned})
+  var t = skipTypes(n[0].typ, {tyGenericInst, tyVar, tyLent, tyAlias, tySink, tyOwned})
   case t.kind
   of tyRef, tyPtr: n.typ = t.lastSon
   else: result = nil
-  #GlobalError(n.sons[0].info, errCircumNeedsPointer)
+  #GlobalError(n[0].info, errCircumNeedsPointer)
 
 proc semSubscript(c: PContext, n: PNode, flags: TExprFlags): PNode =
   ## returns nil if not a built-in subscript operator; also called for the
   ## checking of assignments
-  if len(n) == 1:
+  if n.len == 1:
     let x = semDeref(c, n)
     if x == nil: return nil
     result = newNodeIT(nkDerefExpr, x.info, x.typ)
@@ -1432,9 +1431,9 @@ proc semSubscript(c: PContext, n: PNode, flags: TExprFlags): PNode =
     return
   checkMinSonsLen(n, 2, c.config)
   # make sure we don't evaluate generic macros/templates
-  n.sons[0] = semExprWithType(c, n.sons[0],
+  n[0] = semExprWithType(c, n[0],
                               {efNoEvaluateGeneric})
-  var arr = skipTypes(n.sons[0].typ, {tyGenericInst, tyUserTypeClassInst, tyOwned,
+  var arr = skipTypes(n[0].typ, {tyGenericInst, tyUserTypeClassInst, tyOwned,
                                       tyVar, tyLent, tyPtr, tyRef, tyAlias, tySink})
   if arr.kind == tyStatic:
     if arr.base.kind == tyNone:
@@ -1450,20 +1449,20 @@ proc semSubscript(c: PContext, n: PNode, flags: TExprFlags): PNode =
   of tyArray, tyOpenArray, tyVarargs, tySequence, tyString, tyCString,
     tyUncheckedArray:
     if n.len != 2: return nil
-    n.sons[0] = makeDeref(n.sons[0])
-    for i in 1 ..< len(n):
-      n.sons[i] = semExprWithType(c, n.sons[i],
+    n[0] = makeDeref(n[0])
+    for i in 1..<n.len:
+      n[i] = semExprWithType(c, n[i],
                                   flags*{efInTypeof, efDetermineType})
     # Arrays index type is dictated by the range's type
     if arr.kind == tyArray:
-      var indexType = arr.sons[0]
-      var arg = indexTypesMatch(c, indexType, n.sons[1].typ, n.sons[1])
+      var indexType = arr[0]
+      var arg = indexTypesMatch(c, indexType, n[1].typ, n[1])
       if arg != nil:
-        n.sons[1] = arg
+        n[1] = arg
         result = n
         result.typ = elemType(arr)
     # Other types have a bit more of leeway
-    elif n.sons[1].typ.skipTypes(abstractRange-{tyDistinct}).kind in
+    elif n[1].typ.skipTypes(abstractRange-{tyDistinct}).kind in
         {tyInt..tyInt64, tyUInt..tyUInt64}:
       result = n
       result.typ = elemType(arr)
@@ -1476,31 +1475,31 @@ proc semSubscript(c: PContext, n: PNode, flags: TExprFlags): PNode =
     #result = symNodeFromType(c, semTypeNode(c, n, nil), n.info)
   of tyTuple:
     if n.len != 2: return nil
-    n.sons[0] = makeDeref(n.sons[0])
+    n[0] = makeDeref(n[0])
     # [] operator for tuples requires constant expression:
-    n.sons[1] = semConstExpr(c, n.sons[1])
-    if skipTypes(n.sons[1].typ, {tyGenericInst, tyRange, tyOrdinal, tyAlias, tySink}).kind in
+    n[1] = semConstExpr(c, n[1])
+    if skipTypes(n[1].typ, {tyGenericInst, tyRange, tyOrdinal, tyAlias, tySink}).kind in
         {tyInt..tyInt64}:
-      let idx = getOrdValue(n.sons[1])
-      if idx >= 0 and idx < len(arr): n.typ = arr.sons[toInt(idx)]
+      let idx = getOrdValue(n[1])
+      if idx >= 0 and idx < arr.len: n.typ = arr[toInt(idx)]
       else: localError(c.config, n.info, "invalid index value for tuple subscript")
       result = n
     else:
       result = nil
   else:
-    let s = if n.sons[0].kind == nkSym: n.sons[0].sym
-            elif n[0].kind in nkSymChoices: n.sons[0][0].sym
+    let s = if n[0].kind == nkSym: n[0].sym
+            elif n[0].kind in nkSymChoices: n[0][0].sym
             else: nil
     if s != nil:
       case s.kind
       of skProc, skFunc, skMethod, skConverter, skIterator:
         # type parameters: partial generic specialization
-        n.sons[0] = semSymGenericInstantiation(c, n.sons[0], s)
+        n[0] = semSymGenericInstantiation(c, n[0], s)
         result = explicitGenericInstantiation(c, n, s)
         if result == n:
-          n.sons[0] = copyTree(result)
+          n[0] = copyTree(result)
         else:
-          n.sons[0] = result
+          n[0] = result
       of skMacro, skTemplate:
         if efInCall in flags:
           # We are processing macroOrTmpl[] in macroOrTmpl[](...) call.
@@ -1557,9 +1556,9 @@ proc takeImplicitAddr(c: PContext, n: PNode; isLent: bool): PNode =
         root.name.s, renderTree(n, {renderNoComments}), explanationsBaseUrl])
   case n.kind
   of nkHiddenAddr, nkAddr: return n
-  of nkHiddenDeref, nkDerefExpr: return n.sons[0]
+  of nkHiddenDeref, nkDerefExpr: return n[0]
   of nkBracketExpr:
-    if len(n) == 1: return n.sons[0]
+    if n.len == 1: return n[0]
   else: discard
   let valid = isAssignable(c, n, isLent)
   if valid != arLValue:
@@ -1572,10 +1571,10 @@ proc takeImplicitAddr(c: PContext, n: PNode; isLent: bool): PNode =
 
 proc asgnToResultVar(c: PContext, n, le, ri: PNode) {.inline.} =
   if le.kind == nkHiddenDeref:
-    var x = le.sons[0]
+    var x = le[0]
     if x.typ.kind in {tyVar, tyLent} and x.kind == nkSym and x.sym.kind == skResult:
-      n.sons[0] = x # 'result[]' --> 'result'
-      n.sons[1] = takeImplicitAddr(c, ri, x.typ.kind == tyLent)
+      n[0] = x # 'result[]' --> 'result'
+      n[1] = takeImplicitAddr(c, ri, x.typ.kind == tyLent)
       x.typ.flags.incl tfVarIsPtr
       #echo x.info, " setting it for this type ", typeToString(x.typ), " ", n.info
 
@@ -1633,7 +1632,7 @@ proc goodLineInfo(arg: PNode): TLineInfo =
 
 proc semAsgn(c: PContext, n: PNode; mode=asgnNormal): PNode =
   checkSonsLen(n, 2, c.config)
-  var a = n.sons[0]
+  var a = n[0]
   case a.kind
   of nkDotExpr:
     # r.f = x
@@ -1654,8 +1653,8 @@ proc semAsgn(c: PContext, n: PNode; mode=asgnNormal): PNode =
     # --> `[]=`(a, i, x)
     a = semSubscript(c, a, {efLValue})
     if a == nil:
-      result = buildOverloadedSubscripts(n.sons[0], getIdent(c.cache, "[]="))
-      add(result, n[1])
+      result = buildOverloadedSubscripts(n[0], getIdent(c.cache, "[]="))
+      result.add(n[1])
       if mode == noOverloadedSubscript:
         bracketNotFoundError(c, result)
         return n
@@ -1664,8 +1663,8 @@ proc semAsgn(c: PContext, n: PNode; mode=asgnNormal): PNode =
         return result
   of nkCurlyExpr:
     # a{i} = x -->  `{}=`(a, i, x)
-    result = buildOverloadedSubscripts(n.sons[0], getIdent(c.cache, "{}="))
-    add(result, n[1])
+    result = buildOverloadedSubscripts(n[0], getIdent(c.cache, "{}="))
+    result.add(n[1])
     return semExprNoType(c, result)
   of nkPar, nkTupleConstr:
     if a.len >= 2:
@@ -1677,7 +1676,7 @@ proc semAsgn(c: PContext, n: PNode; mode=asgnNormal): PNode =
       a = semExprWithType(c, a, {efLValue})
   else:
     a = semExprWithType(c, a, {efLValue})
-  n.sons[0] = a
+  n[0] = a
   # a = b # both are vars, means: a[] = b[]
   # a = b # b no 'var T' means: a = addr(b)
   var le = a.typ
@@ -1691,10 +1690,10 @@ proc semAsgn(c: PContext, n: PNode; mode=asgnNormal): PNode =
                renderTree(a, {renderNoComments}))
   else:
     let
-      lhs = n.sons[0]
+      lhs = n[0]
       lhsIsResult = lhs.kind == nkSym and lhs.sym.kind == skResult
     var
-      rhs = semExprWithType(c, n.sons[1],
+      rhs = semExprWithType(c, n[1],
         if lhsIsResult: {efAllowDestructor} else: {})
     if lhsIsResult:
       n.typ = c.enforceVoidContext
@@ -1708,16 +1707,16 @@ proc semAsgn(c: PContext, n: PNode; mode=asgnNormal): PNode =
           typeAllowedCheck(c.config, n.info, rhsTyp, skResult)
           lhs.typ = rhsTyp
           c.p.resultSym.typ = rhsTyp
-          c.p.owner.typ.sons[0] = rhsTyp
+          c.p.owner.typ[0] = rhsTyp
         else:
           typeMismatch(c.config, n.info, lhs.typ, rhsTyp)
     borrowCheck(c, n, lhs, rhs)
 
-    n.sons[1] = fitNode(c, le, rhs, goodLineInfo(n[1]))
+    n[1] = fitNode(c, le, rhs, goodLineInfo(n[1]))
     when false: liftTypeBoundOps(c, lhs.typ, lhs.info)
 
     fixAbstractType(c, n)
-    asgnToResultVar(c, n, n.sons[0], n.sons[1])
+    asgnToResultVar(c, n, n[0], n[1])
   result = n
 
 proc semReturn(c: PContext, n: PNode): PNode =
@@ -1725,16 +1724,16 @@ proc semReturn(c: PContext, n: PNode): PNode =
   checkSonsLen(n, 1, c.config)
   if c.p.owner.kind in {skConverter, skMethod, skProc, skFunc, skMacro} or
       (not c.p.owner.typ.isNil and isClosureIterator(c.p.owner.typ)):
-    if n.sons[0].kind != nkEmpty:
+    if n[0].kind != nkEmpty:
       # transform ``return expr`` to ``result = expr; return``
       if c.p.resultSym != nil:
-        var a = newNodeI(nkAsgn, n.sons[0].info)
-        addSon(a, newSymNode(c.p.resultSym))
-        addSon(a, n.sons[0])
-        n.sons[0] = semAsgn(c, a)
+        var a = newNodeI(nkAsgn, n[0].info)
+        a.add newSymNode(c.p.resultSym)
+        a.add n[0]
+        n[0] = semAsgn(c, a)
         # optimize away ``result = result``:
         if n[0][1].kind == nkSym and n[0][1].sym == c.p.resultSym:
-          n.sons[0] = c.graph.emptyNode
+          n[0] = c.graph.emptyNode
       else:
         localError(c.config, n.info, errNoReturnTypeDeclared)
   else:
@@ -1756,8 +1755,8 @@ proc semProcBody(c: PContext, n: PNode): PNode =
       fixNilType(c, result)
     else:
       var a = newNodeI(nkAsgn, n.info, 2)
-      a.sons[0] = newSymNode(c.p.resultSym)
-      a.sons[1] = result
+      a[0] = newSymNode(c.p.resultSym)
+      a[1] = result
       result = semAsgn(c, a)
   else:
     discardCheck(c, result, {})
@@ -1767,12 +1766,12 @@ proc semProcBody(c: PContext, n: PNode): PNode =
     if isEmptyType(result.typ):
       # we inferred a 'void' return type:
       c.p.resultSym.typ = errorType(c)
-      c.p.owner.typ.sons[0] = nil
+      c.p.owner.typ[0] = nil
     else:
       localError(c.config, c.p.resultSym.info, errCannotInferReturnType %
         c.p.owner.name.s)
-  if isInlineIterator(c.p.owner.typ) and c.p.owner.typ.sons[0] != nil and
-      c.p.owner.typ.sons[0].kind == tyUntyped:
+  if isInlineIterator(c.p.owner.typ) and c.p.owner.typ[0] != nil and
+      c.p.owner.typ[0].kind == tyUntyped:
     localError(c.config, c.p.owner.info, errCannotInferReturnType %
       c.p.owner.name.s)
   closeScope(c)
@@ -1782,22 +1781,22 @@ proc semYieldVarResult(c: PContext, n: PNode, restype: PType) =
   case t.kind
   of tyVar, tyLent:
     t.flags.incl tfVarIsPtr # bugfix for #4048, #4910, #6892
-    if n.sons[0].kind in {nkHiddenStdConv, nkHiddenSubConv}:
-      n.sons[0] = n.sons[0].sons[1]
-    n.sons[0] = takeImplicitAddr(c, n.sons[0], t.kind == tyLent)
+    if n[0].kind in {nkHiddenStdConv, nkHiddenSubConv}:
+      n[0] = n[0][1]
+    n[0] = takeImplicitAddr(c, n[0], t.kind == tyLent)
   of tyTuple:
     for i in 0..<t.len:
-      let e = skipTypes(t.sons[i], {tyGenericInst, tyAlias, tySink})
+      let e = skipTypes(t[i], {tyGenericInst, tyAlias, tySink})
       if e.kind in {tyVar, tyLent}:
         e.flags.incl tfVarIsPtr # bugfix for #4048, #4910, #6892
-        if n.sons[0].kind in {nkPar, nkTupleConstr}:
-          n.sons[0].sons[i] = takeImplicitAddr(c, n.sons[0].sons[i], e.kind == tyLent)
-        elif n.sons[0].kind in {nkHiddenStdConv, nkHiddenSubConv} and
-             n.sons[0].sons[1].kind in {nkPar, nkTupleConstr}:
-          var a = n.sons[0].sons[1]
-          a.sons[i] = takeImplicitAddr(c, a.sons[i], e.kind == tyLent)
+        if n[0].kind in {nkPar, nkTupleConstr}:
+          n[0][i] = takeImplicitAddr(c, n[0][i], e.kind == tyLent)
+        elif n[0].kind in {nkHiddenStdConv, nkHiddenSubConv} and
+             n[0][1].kind in {nkPar, nkTupleConstr}:
+          var a = n[0][1]
+          a[i] = takeImplicitAddr(c, a[i], e.kind == tyLent)
         else:
-          localError(c.config, n.sons[0].info, errXExpected, "tuple constructor")
+          localError(c.config, n[0].info, errXExpected, "tuple constructor")
   else: discard
 
 proc semYield(c: PContext, n: PNode): PNode =
@@ -1805,25 +1804,25 @@ proc semYield(c: PContext, n: PNode): PNode =
   checkSonsLen(n, 1, c.config)
   if c.p.owner == nil or c.p.owner.kind != skIterator:
     localError(c.config, n.info, errYieldNotAllowedHere)
-  elif n.sons[0].kind != nkEmpty:
-    n.sons[0] = semExprWithType(c, n.sons[0]) # check for type compatibility:
+  elif n[0].kind != nkEmpty:
+    n[0] = semExprWithType(c, n[0]) # check for type compatibility:
     var iterType = c.p.owner.typ
-    let restype = iterType.sons[0]
+    let restype = iterType[0]
     if restype != nil:
       if restype.kind != tyUntyped:
-        n.sons[0] = fitNode(c, restype, n.sons[0], n.info)
-      if n.sons[0].typ == nil: internalError(c.config, n.info, "semYield")
+        n[0] = fitNode(c, restype, n[0], n.info)
+      if n[0].typ == nil: internalError(c.config, n.info, "semYield")
 
       if resultTypeIsInferrable(restype):
-        let inferred = n.sons[0].typ
-        iterType.sons[0] = inferred
+        let inferred = n[0].typ
+        iterType[0] = inferred
         if c.p.resultSym != nil:
           c.p.resultSym.typ = inferred
 
       semYieldVarResult(c, n, restype)
     else:
       localError(c.config, n.info, errCannotReturnExpr)
-  elif c.p.owner.typ.sons[0] != nil:
+  elif c.p.owner.typ[0] != nil:
     localError(c.config, n.info, errGenerated, "yield statement must yield a value")
 
 proc lookUpForDefined(c: PContext, i: PIdent, onlyCurrentScope: bool): PSym =
@@ -1840,7 +1839,7 @@ proc lookUpForDefined(c: PContext, n: PNode, onlyCurrentScope: bool): PSym =
     result = nil
     if onlyCurrentScope: return
     checkSonsLen(n, 2, c.config)
-    var m = lookUpForDefined(c, n.sons[0], onlyCurrentScope)
+    var m = lookUpForDefined(c, n[0], onlyCurrentScope)
     if m != nil and m.kind == skModule:
       let ident = considerQuotedIdent(c, n[1], n)
       if m == c.module:
@@ -1852,7 +1851,7 @@ proc lookUpForDefined(c: PContext, n: PNode, onlyCurrentScope: bool): PSym =
   of nkSym:
     result = n.sym
   of nkOpenSymChoice, nkClosedSymChoice:
-    result = n.sons[0].sym
+    result = n[0].sym
   else:
     localError(c.config, n.info, "identifier expected, but got: " & renderTree(n))
     result = nil
@@ -1864,7 +1863,7 @@ proc semDefined(c: PContext, n: PNode, onlyCurrentScope: bool): PNode =
   if not onlyCurrentScope and considerQuotedIdent(c, n[0], n).s == "defined":
     let d = considerQuotedIdent(c, n[1], n)
     result.intVal = ord isDefined(c.config, d.s)
-  elif lookUpForDefined(c, n.sons[1], onlyCurrentScope) != nil:
+  elif lookUpForDefined(c, n[1], onlyCurrentScope) != nil:
     result.intVal = 1
   result.info = n.info
   result.typ = getSysType(c.graph, n.info, tyBool)
@@ -1904,14 +1903,14 @@ proc semExpandToAst(c: PContext, n: PNode): PNode =
     let expandedSym = expectMacroOrTemplateCall(c, macroCall)
     if expandedSym.kind == skError: return n
 
-    macroCall.sons[0] = newSymNode(expandedSym, macroCall.info)
+    macroCall[0] = newSymNode(expandedSym, macroCall.info)
     markUsed(c, n.info, expandedSym)
     onUse(n.info, expandedSym)
 
   if isCallExpr(macroCall):
-    for i in 1 ..< macroCall.len:
-      #if macroCall.sons[0].typ.sons[i].kind != tyUntyped:
-      macroCall.sons[i] = semExprWithType(c, macroCall[i], {})
+    for i in 1..<macroCall.len:
+      #if macroCall[0].typ[i].kind != tyUntyped:
+      macroCall[i] = semExprWithType(c, macroCall[i], {})
     # performing overloading resolution here produces too serious regressions:
     let headSymbol = macroCall[0]
     var cands = 0
@@ -1928,17 +1927,17 @@ proc semExpandToAst(c: PContext, n: PNode): PNode =
     elif cands >= 2:
       localError(c.config, n.info, "ambiguous symbol in 'getAst' context: " & $macroCall)
     else:
-      let info = macroCall.sons[0].info
-      macroCall.sons[0] = newSymNode(cand, info)
+      let info = macroCall[0].info
+      macroCall[0] = newSymNode(cand, info)
       markUsed(c, info, cand)
       onUse(info, cand)
 
     # we just perform overloading resolution here:
-    #n.sons[1] = semOverloadedCall(c, macroCall, macroCall, {skTemplate, skMacro})
+    #n[1] = semOverloadedCall(c, macroCall, macroCall, {skTemplate, skMacro})
   else:
     localError(c.config, n.info, "getAst takes a call, but got " & n.renderTree)
   # Preserve the magic symbol in order to be handled in evals.nim
-  internalAssert c.config, n.sons[0].sym.magic == mExpandToAst
+  internalAssert c.config, n[0].sym.magic == mExpandToAst
   #n.typ = getSysSym("NimNode").typ # expandedSym.getReturnType
   if n.kind == nkStmtList and n.len == 1: result = n[0]
   else: result = n
@@ -1946,8 +1945,8 @@ proc semExpandToAst(c: PContext, n: PNode): PNode =
 
 proc semExpandToAst(c: PContext, n: PNode, magicSym: PSym,
                     flags: TExprFlags = {}): PNode =
-  if len(n) == 2:
-    n.sons[0] = newSymNode(magicSym, n.info)
+  if n.len == 2:
+    n[0] = newSymNode(magicSym, n.info)
     result = semExpandToAst(c, n)
   else:
     result = semDirectOp(c, n, flags)
@@ -1969,15 +1968,15 @@ proc processQuotations(c: PContext; n: var PNode, op: string,
       if examinedOp == op:
         returnQuote n[1]
       elif examinedOp.startsWith(op):
-        n.sons[0] = newIdentNode(getIdent(c.cache, examinedOp.substr(op.len)), n.info)
+        n[0] = newIdentNode(getIdent(c.cache, examinedOp.substr(op.len)), n.info)
   elif n.kind == nkAccQuoted and op == "``":
     returnQuote n[0]
   elif n.kind == nkIdent:
     if n.ident.s == "result":
       n = ids[0]
 
-  for i in 0 ..< n.safeLen:
-    processQuotations(c, n.sons[i], op, quotes, ids)
+  for i in 0..<n.safeLen:
+    processQuotations(c, n[i], op, quotes, ids)
 
 proc semQuoteAst(c: PContext, n: PNode): PNode =
   if n.len != 2 and n.len != 3:
@@ -2010,7 +2009,7 @@ proc semQuoteAst(c: PContext, n: PNode): PNode =
               pragmas = c.graph.emptyNode, exceptions = c.graph.emptyNode)
 
   if ids.len > 0:
-    dummyTemplate.sons[paramsPos] = newNodeI(nkFormalParams, n.info)
+    dummyTemplate[paramsPos] = newNodeI(nkFormalParams, n.info)
     dummyTemplate[paramsPos].add getSysSym(c.graph, n.info, "untyped").newSymNode # return type
     ids.add getSysSym(c.graph, n.info, "untyped").newSymNode # params type
     ids.add c.graph.emptyNode # no default value
@@ -2048,7 +2047,7 @@ proc tryExpr(c: PContext, n: PNode, flags: TExprFlags = {}): PNode =
   # open a scope for temporary symbol inclusions:
   let oldScope = c.currentScope
   openScope(c)
-  let oldOwnerLen = len(c.graph.owners)
+  let oldOwnerLen = c.graph.owners.len
   let oldGenerics = c.generics
   let oldErrorOutputs = c.config.m.errorOutputs
   if efExplain notin flags: c.config.m.errorOutputs = {}
@@ -2083,14 +2082,14 @@ proc tryExpr(c: PContext, n: PNode, flags: TExprFlags = {}): PNode =
 
 proc semCompiles(c: PContext, n: PNode, flags: TExprFlags): PNode =
   # we replace this node by a 'true' or 'false' node:
-  if len(n) != 2: return semDirectOp(c, n, flags)
+  if n.len != 2: return semDirectOp(c, n, flags)
 
   result = newIntNode(nkIntLit, ord(tryExpr(c, n[1], flags) != nil))
   result.info = n.info
   result.typ = getSysType(c.graph, n.info, tyBool)
 
 proc semShallowCopy(c: PContext, n: PNode, flags: TExprFlags): PNode =
-  if len(n) == 3:
+  if n.len == 3:
     # XXX ugh this is really a hack: shallowCopy() can be overloaded only
     # with procs that take not 2 parameters:
     result = newNodeI(nkFastAsgn, n.info)
@@ -2113,7 +2112,7 @@ proc instantiateCreateFlowVarCall(c: PContext; t: PType;
     localError(c.config, info, "system needs: nimCreateFlowVar")
   var bindings: TIdTable
   initIdTable(bindings)
-  bindings.idTablePut(sym.ast[genericParamsPos].sons[0].typ, t)
+  bindings.idTablePut(sym.ast[genericParamsPos][0].typ, t)
   result = c.semGenerateInstance(c, sym, bindings, info)
   # since it's an instantiation, we unmark it as a compilerproc. Otherwise
   # codegen would fail:
@@ -2123,15 +2122,15 @@ proc instantiateCreateFlowVarCall(c: PContext; t: PType;
 
 proc setMs(n: PNode, s: PSym): PNode =
   result = n
-  n.sons[0] = newSymNode(s)
-  n.sons[0].info = n.info
+  n[0] = newSymNode(s)
+  n[0].info = n.info
 
 proc semSizeof(c: PContext, n: PNode): PNode =
-  if len(n) != 2:
+  if n.len != 2:
     localError(c.config, n.info, errXExpectsTypeOrValue % "sizeof")
   else:
-    n.sons[1] = semExprWithType(c, n.sons[1], {efDetermineType})
-    #restoreOldStyleType(n.sons[1])
+    n[1] = semExprWithType(c, n[1], {efDetermineType})
+    #restoreOldStyleType(n[1])
   n.typ = getSysType(c.graph, n.info, tyInt)
   result = foldSizeOf(c.config, n, n)
 
@@ -2143,7 +2142,7 @@ proc semMagic(c: PContext, n: PNode, s: PSym, flags: TExprFlags): PNode =
     markUsed(c, n.info, s)
     checkSonsLen(n, 2, c.config)
     result[0] = newSymNode(s, n[0].info)
-    result[1] = semAddrArg(c, n.sons[1], s.name.s == "unsafeAddr")
+    result[1] = semAddrArg(c, n[1], s.name.s == "unsafeAddr")
     result.typ = makePtrType(c, result[1].typ)
   of mTypeOf:
     markUsed(c, n.info, s)
@@ -2180,9 +2179,9 @@ proc semMagic(c: PContext, n: PNode, s: PSym, flags: TExprFlags): PNode =
       localError(c.config, n.info, "use the {.experimental.} pragma to enable 'parallel'")
     result = setMs(n, s)
     var x = n.lastSon
-    if x.kind == nkDo: x = x.sons[bodyPos]
+    if x.kind == nkDo: x = x[bodyPos]
     inc c.inParallelStmt
-    result.sons[1] = semStmt(c, x, {})
+    result[1] = semStmt(c, x, {})
     dec c.inParallelStmt
   of mSpawn:
     markUsed(c, n.info, s)
@@ -2191,8 +2190,8 @@ proc semMagic(c: PContext, n: PNode, s: PSym, flags: TExprFlags): PNode =
       result = n
     else:
       result = setMs(n, s)
-      for i in 1 ..< n.len:
-        result.sons[i] = semExpr(c, n.sons[i])
+      for i in 1..<n.len:
+        result[i] = semExpr(c, n[i])
       let typ = result[^1].typ
       if not typ.isEmptyType:
         if spawnResult(typ, c.inParallelStmt > 0) == srFlowVar:
@@ -2205,7 +2204,7 @@ proc semMagic(c: PContext, n: PNode, s: PSym, flags: TExprFlags): PNode =
   of mProcCall:
     markUsed(c, n.info, s)
     result = setMs(n, s)
-    result.sons[1] = semExpr(c, n.sons[1])
+    result[1] = semExpr(c, n[1])
     result.typ = n[1].typ
   of mPlugin:
     markUsed(c, n.info, s)
@@ -2216,7 +2215,7 @@ proc semMagic(c: PContext, n: PNode, s: PSym, flags: TExprFlags): PNode =
     if result == nil:
       result = errorNode(c, n)
     else:
-      let callee = result.sons[0].sym
+      let callee = result[0].sym
       if callee.magic == mNone:
         semFinishOperands(c, result)
       activate(c, result)
@@ -2264,41 +2263,41 @@ proc semWhen(c: PContext, n: PNode, semCheck = true): PNode =
   #   ...
   var whenNimvm = false
   var typ = commonTypeBegin
-  if n.sons.len == 2 and n.sons[0].kind == nkElifBranch and
-      n.sons[1].kind == nkElse:
-    let exprNode = n.sons[0].sons[0]
+  if n.len == 2 and n[0].kind == nkElifBranch and
+      n[1].kind == nkElse:
+    let exprNode = n[0][0]
     if exprNode.kind == nkIdent:
       whenNimvm = lookUp(c, exprNode).magic == mNimvm
     elif exprNode.kind == nkSym:
       whenNimvm = exprNode.sym.magic == mNimvm
     if whenNimvm: n.flags.incl nfLL
 
-  for i in 0 ..< len(n):
-    var it = n.sons[i]
+  for i in 0..<n.len:
+    var it = n[i]
     case it.kind
     of nkElifBranch, nkElifExpr:
       checkSonsLen(it, 2, c.config)
       if whenNimvm:
         if semCheck:
-          it.sons[1] = semExpr(c, it.sons[1])
-          typ = commonType(typ, it.sons[1].typ)
+          it[1] = semExpr(c, it[1])
+          typ = commonType(typ, it[1].typ)
         result = n # when nimvm is not elimited until codegen
       else:
-        let e = forceBool(c, semConstExpr(c, it.sons[0]))
+        let e = forceBool(c, semConstExpr(c, it[0]))
         if e.kind != nkIntLit:
           # can happen for cascading errors, assume false
           # InternalError(n.info, "semWhen")
           discard
         elif e.intVal != 0 and result == nil:
-          setResult(it.sons[1])
+          setResult(it[1])
     of nkElse, nkElseExpr:
       checkSonsLen(it, 1, c.config)
       if result == nil or whenNimvm:
         if semCheck:
-          it.sons[0] = semExpr(c, it.sons[0])
-          typ = commonType(typ, it.sons[0].typ)
+          it[0] = semExpr(c, it[0])
+          typ = commonType(typ, it[0].typ)
         if result == nil:
-          result = it.sons[0]
+          result = it[0]
     else: illFormedAst(n, c.config)
   if result == nil:
     result = newNodeI(nkEmpty, n.info)
@@ -2311,58 +2310,58 @@ proc semWhen(c: PContext, n: PNode, semCheck = true): PNode =
 proc semSetConstr(c: PContext, n: PNode): PNode =
   result = newNodeI(nkCurly, n.info)
   result.typ = newTypeS(tySet, c)
-  if len(n) == 0:
+  if n.len == 0:
     rawAddSon(result.typ, newTypeS(tyEmpty, c))
   else:
     # only semantic checking for all elements, later type checking:
     var typ: PType = nil
-    for i in 0 ..< len(n):
-      if isRange(n.sons[i]):
-        checkSonsLen(n.sons[i], 3, c.config)
-        n.sons[i].sons[1] = semExprWithType(c, n.sons[i].sons[1])
-        n.sons[i].sons[2] = semExprWithType(c, n.sons[i].sons[2])
+    for i in 0..<n.len:
+      if isRange(n[i]):
+        checkSonsLen(n[i], 3, c.config)
+        n[i][1] = semExprWithType(c, n[i][1])
+        n[i][2] = semExprWithType(c, n[i][2])
         if typ == nil:
-          typ = skipTypes(n.sons[i].sons[1].typ,
+          typ = skipTypes(n[i][1].typ,
                           {tyGenericInst, tyVar, tyLent, tyOrdinal, tyAlias, tySink})
-        n.sons[i].typ = n.sons[i].sons[2].typ # range node needs type too
-      elif n.sons[i].kind == nkRange:
+        n[i].typ = n[i][2].typ # range node needs type too
+      elif n[i].kind == nkRange:
         # already semchecked
         if typ == nil:
-          typ = skipTypes(n.sons[i].sons[0].typ,
+          typ = skipTypes(n[i][0].typ,
                           {tyGenericInst, tyVar, tyLent, tyOrdinal, tyAlias, tySink})
       else:
-        n.sons[i] = semExprWithType(c, n.sons[i])
+        n[i] = semExprWithType(c, n[i])
         if typ == nil:
-          typ = skipTypes(n.sons[i].typ, {tyGenericInst, tyVar, tyLent, tyOrdinal, tyAlias, tySink})
+          typ = skipTypes(n[i].typ, {tyGenericInst, tyVar, tyLent, tyOrdinal, tyAlias, tySink})
     if not isOrdinalType(typ, allowEnumWithHoles=true):
       localError(c.config, n.info, errOrdinalTypeExpected)
       typ = makeRangeType(c, 0, MaxSetElements-1, n.info)
     elif lengthOrd(c.config, typ) > MaxSetElements:
       typ = makeRangeType(c, 0, MaxSetElements-1, n.info)
     addSonSkipIntLit(result.typ, typ)
-    for i in 0 ..< len(n):
+    for i in 0..<n.len:
       var m: PNode
-      let info = n.sons[i].info
-      if isRange(n.sons[i]):
+      let info = n[i].info
+      if isRange(n[i]):
         m = newNodeI(nkRange, info)
-        addSon(m, fitNode(c, typ, n.sons[i].sons[1], info))
-        addSon(m, fitNode(c, typ, n.sons[i].sons[2], info))
-      elif n.sons[i].kind == nkRange: m = n.sons[i] # already semchecked
+        m.add fitNode(c, typ, n[i][1], info)
+        m.add fitNode(c, typ, n[i][2], info)
+      elif n[i].kind == nkRange: m = n[i] # already semchecked
       else:
-        m = fitNode(c, typ, n.sons[i], info)
-      addSon(result, m)
+        m = fitNode(c, typ, n[i], info)
+      result.add m
 
 proc semTableConstr(c: PContext, n: PNode): PNode =
   # we simply transform ``{key: value, key2, key3: value}`` to
   # ``[(key, value), (key2, value2), (key3, value2)]``
   result = newNodeI(nkBracket, n.info)
   var lastKey = 0
-  for i in 0..n.len-1:
-    var x = n.sons[i]
-    if x.kind == nkExprColonExpr and len(x) == 2:
-      for j in lastKey ..< i:
+  for i in 0..<n.len:
+    var x = n[i]
+    if x.kind == nkExprColonExpr and x.len == 2:
+      for j in lastKey..<i:
         var pair = newNodeI(nkTupleConstr, x.info)
-        pair.add(n.sons[j])
+        pair.add(n[j])
         pair.add(x[1])
         result.add(pair)
 
@@ -2381,25 +2380,24 @@ type
     paNone, paSingle, paTupleFields, paTuplePositions
 
 proc checkPar(c: PContext; n: PNode): TParKind =
-  var length = len(n)
-  if length == 0:
+  if n.len == 0:
     result = paTuplePositions # ()
-  elif length == 1:
-    if n.sons[0].kind == nkExprColonExpr: result = paTupleFields
+  elif n.len == 1:
+    if n[0].kind == nkExprColonExpr: result = paTupleFields
     elif n.kind == nkTupleConstr: result = paTuplePositions
     else: result = paSingle         # (expr)
   else:
-    if n.sons[0].kind == nkExprColonExpr: result = paTupleFields
+    if n[0].kind == nkExprColonExpr: result = paTupleFields
     else: result = paTuplePositions
-    for i in 0 ..< length:
+    for i in 0..<n.len:
       if result == paTupleFields:
-        if (n.sons[i].kind != nkExprColonExpr) or
-            n.sons[i].sons[0].kind notin {nkSym, nkIdent}:
-          localError(c.config, n.sons[i].info, errNamedExprExpected)
+        if (n[i].kind != nkExprColonExpr) or
+            n[i][0].kind notin {nkSym, nkIdent}:
+          localError(c.config, n[i].info, errNamedExprExpected)
           return paNone
       else:
-        if n.sons[i].kind == nkExprColonExpr:
-          localError(c.config, n.sons[i].info, errNamedExprNotAllowed)
+        if n[i].kind == nkExprColonExpr:
+          localError(c.config, n[i].info, errNamedExprNotAllowed)
           return paNone
 
 proc semTupleFieldsConstr(c: PContext, n: PNode, flags: TExprFlags): PNode =
@@ -2407,35 +2405,35 @@ proc semTupleFieldsConstr(c: PContext, n: PNode, flags: TExprFlags): PNode =
   var typ = newTypeS(tyTuple, c)
   typ.n = newNodeI(nkRecList, n.info) # nkIdentDefs
   var ids = initIntSet()
-  for i in 0 ..< len(n):
+  for i in 0..<n.len:
     if n[i].kind != nkExprColonExpr:
-      illFormedAst(n.sons[i], c.config)
+      illFormedAst(n[i], c.config)
     let id = considerQuotedIdent(c, n[i][0])
     if containsOrIncl(ids, id.id):
-      localError(c.config, n.sons[i].info, errFieldInitTwice % id.s)
-    n.sons[i].sons[1] = semExprWithType(c, n.sons[i].sons[1],
+      localError(c.config, n[i].info, errFieldInitTwice % id.s)
+    n[i][1] = semExprWithType(c, n[i][1],
                                         flags*{efAllowDestructor})
 
-    if n.sons[i].sons[1].typ.kind == tyTypeDesc:
-      localError(c.config, n.sons[i].sons[1].info, "typedesc not allowed as tuple field.")
-      n.sons[i].sons[1].typ = errorType(c)
+    if n[i][1].typ.kind == tyTypeDesc:
+      localError(c.config, n[i][1].info, "typedesc not allowed as tuple field.")
+      n[i][1].typ = errorType(c)
 
-    var f = newSymS(skField, n.sons[i].sons[0], c)
-    f.typ = skipIntLit(n.sons[i].sons[1].typ)
+    var f = newSymS(skField, n[i][0], c)
+    f.typ = skipIntLit(n[i][1].typ)
     f.position = i
     rawAddSon(typ, f.typ)
-    addSon(typ.n, newSymNode(f))
-    n.sons[i].sons[0] = newSymNode(f)
-    addSon(result, n.sons[i])
+    typ.n.add newSymNode(f)
+    n[i][0] = newSymNode(f)
+    result.add n[i]
   result.typ = typ
 
 proc semTuplePositionsConstr(c: PContext, n: PNode, flags: TExprFlags): PNode =
   result = n                  # we don't modify n, but compute the type:
   result.kind = nkTupleConstr
   var typ = newTypeS(tyTuple, c)  # leave typ.n nil!
-  for i in 0 ..< len(n):
-    n.sons[i] = semExprWithType(c, n.sons[i], flags*{efAllowDestructor})
-    addSonSkipIntLit(typ, n.sons[i].typ)
+  for i in 0..<n.len:
+    n[i] = semExprWithType(c, n[i], flags*{efAllowDestructor})
+    addSonSkipIntLit(typ, n[i].typ)
   result.typ = typ
 
 include semobjconstr
@@ -2445,18 +2443,18 @@ proc semBlock(c: PContext, n: PNode; flags: TExprFlags): PNode =
   inc(c.p.nestedBlockCounter)
   checkSonsLen(n, 2, c.config)
   openScope(c) # BUGFIX: label is in the scope of block!
-  if n.sons[0].kind != nkEmpty:
-    var labl = newSymG(skLabel, n.sons[0], c)
+  if n[0].kind != nkEmpty:
+    var labl = newSymG(skLabel, n[0], c)
     if sfGenSym notin labl.flags:
       addDecl(c, labl)
     elif labl.owner == nil:
       labl.owner = c.p.owner
-    n.sons[0] = newSymNode(labl, n.sons[0].info)
-    suggestSym(c.config, n.sons[0].info, labl, c.graph.usageSym)
+    n[0] = newSymNode(labl, n[0].info)
+    suggestSym(c.config, n[0].info, labl, c.graph.usageSym)
     styleCheckDef(c.config, labl)
     onDef(n[0].info, labl)
-  n.sons[1] = semExpr(c, n.sons[1], flags)
-  n.typ = n.sons[1].typ
+  n[1] = semExpr(c, n[1], flags)
+  n.typ = n[1].typ
   if isEmptyType(n.typ): n.kind = nkBlockStmt
   else: n.kind = nkBlockExpr
   closeScope(c)
@@ -2484,7 +2482,7 @@ proc semExportExcept(c: PContext, n: PNode): PNode =
 proc semExport(c: PContext, n: PNode): PNode =
   result = newNodeI(nkExportStmt, n.info)
   for i in 0..<n.len:
-    let a = n.sons[i]
+    let a = n[i]
     var o: TOverloadIter
     var s = initOverloadIter(o, c, a)
     if s == nil:
@@ -2517,7 +2515,7 @@ proc semTupleConstr(c: PContext, n: PNode, flags: TExprFlags): PNode =
   if tupexp.len > 0: # don't interpret () as type
     isTupleType = tupexp[0].typ.kind == tyTypeDesc
     # check if either everything or nothing is tyTypeDesc
-    for i in 1 ..< tupexp.len:
+    for i in 1..<tupexp.len:
       if isTupleType != (tupexp[i].typ.kind == tyTypeDesc):
         localError(c.config, tupexp[i].info, "Mixing types and values in tuples is not allowed.")
         return(errorNode(c,n))
@@ -2530,7 +2528,7 @@ proc semTupleConstr(c: PContext, n: PNode, flags: TExprFlags): PNode =
 
 proc shouldBeBracketExpr(n: PNode): bool =
   assert n.kind in nkCallKinds
-  let a = n.sons[0]
+  let a = n[0]
   if a.kind in nkCallKinds:
     let b = a[0]
     if b.kind in nkSymChoices:
@@ -2538,7 +2536,7 @@ proc shouldBeBracketExpr(n: PNode): bool =
         if b[i].kind == nkSym and b[i].sym.magic == mArrGet:
           let be = newNodeI(nkBracketExpr, n.info)
           for i in 1..<a.len: be.add(a[i])
-          n.sons[0] = be
+          n[0] = be
           return true
 
 proc semExpr(c: PContext, n: PNode, flags: TExprFlags = {}): PNode =
@@ -2614,7 +2612,7 @@ proc semExpr(c: PContext, n: PNode, flags: TExprFlags = {}): PNode =
       result = semExpr(c, result, flags)
   of nkBind:
     message(c.config, n.info, warnDeprecated, "bind is deprecated")
-    result = semExpr(c, n.sons[0], flags)
+    result = semExpr(c, n[0], flags)
   of nkTypeOfExpr, nkTupleTy, nkTupleClassTy, nkRefTy..nkEnumTy, nkStaticTy:
     if c.matchedConcept != nil and n.len == 1:
       let modifier = n.modifierTypeKindOfNode
@@ -2630,10 +2628,10 @@ proc semExpr(c: PContext, n: PNode, flags: TExprFlags = {}): PNode =
     #when defined(nimsuggest):
     #  if gIdeCmd == ideCon and c.config.m.trackPos == n.info: suggestExprNoCheck(c, n)
     let mode = if nfDotField in n.flags: {} else: {checkUndeclared}
-    var s = qualifiedLookUp(c, n.sons[0], mode)
+    var s = qualifiedLookUp(c, n[0], mode)
     if s != nil:
-      #if c.config.cmd == cmdPretty and n.sons[0].kind == nkDotExpr:
-      #  pretty.checkUse(n.sons[0].sons[1].info, s)
+      #if c.config.cmd == cmdPretty and n[0].kind == nkDotExpr:
+      #  pretty.checkUse(n[0][1].info, s)
       case s.kind
       of skMacro, skTemplate:
         result = semDirectOp(c, n, flags)
@@ -2658,9 +2656,9 @@ proc semExpr(c: PContext, n: PNode, flags: TExprFlags = {}): PNode =
         isSymChoice(n[0][0]):
       # indirectOp can deal with explicit instantiations; the fixes
       # the 'newSeq[T](x)' bug
-      setGenericParams(c, n.sons[0])
+      setGenericParams(c, n[0])
       result = semDirectOp(c, n, flags)
-    elif isSymChoice(n.sons[0]) or nfDotField in n.flags:
+    elif isSymChoice(n[0]) or nfDotField in n.flags:
       result = semDirectOp(c, n, flags)
     else:
       result = semIndirectOp(c, n, flags)
@@ -2702,7 +2700,7 @@ proc semExpr(c: PContext, n: PNode, flags: TExprFlags = {}): PNode =
     of paNone: result = errorNode(c, n)
     of paTuplePositions: result = semTupleConstr(c, n, flags)
     of paTupleFields: result = semTupleFieldsConstr(c, n, flags)
-    of paSingle: result = semExpr(c, n.sons[0], flags)
+    of paSingle: result = semExpr(c, n[0], flags)
   of nkCurly: result = semSetConstr(c, n)
   of nkBracket: result = semArrayConstr(c, n, flags)
   of nkObjConstr: result = semObjConstr(c, n, flags)
@@ -2711,11 +2709,11 @@ proc semExpr(c: PContext, n: PNode, flags: TExprFlags = {}): PNode =
   of nkAddr:
     result = n
     checkSonsLen(n, 1, c.config)
-    result[0] = semAddrArg(c, n.sons[0])
+    result[0] = semAddrArg(c, n[0])
     result.typ = makePtrType(c, result[0].typ)
   of nkHiddenAddr, nkHiddenDeref:
     checkSonsLen(n, 1, c.config)
-    n.sons[0] = semExpr(c, n.sons[0], flags)
+    n[0] = semExpr(c, n[0], flags)
   of nkCast: result = semCast(c, n)
   of nkIfExpr, nkIfStmt: result = semIf(c, n, flags)
   of nkHiddenStdConv, nkHiddenSubConv, nkConv, nkHiddenCallConv:
@@ -2795,14 +2793,14 @@ proc semExpr(c: PContext, n: PNode, flags: TExprFlags = {}): PNode =
   of nkDefer:
     if c.currentScope == c.topLevelScope:
       localError(c.config, n.info, "defer statement not supported at top level")
-    n.sons[0] = semExpr(c, n.sons[0])
-    if not n.sons[0].typ.isEmptyType and not implicitlyDiscardable(n.sons[0]):
+    n[0] = semExpr(c, n[0])
+    if not n[0].typ.isEmptyType and not implicitlyDiscardable(n[0]):
       localError(c.config, n.info, "'defer' takes a 'void' expression")
     #localError(c.config, n.info, errGenerated, "'defer' not allowed in this context")
   of nkGotoState, nkState:
     if n.len != 1 and n.len != 2: illFormedAst(n, c.config)
-    for i in 0 ..< n.len:
-      n.sons[i] = semExpr(c, n.sons[i])
+    for i in 0..<n.len:
+      n[i] = semExpr(c, n[i])
   of nkComesFrom: discard "ignore the comes from information for now"
   else:
     localError(c.config, n.info, "invalid expression: " &