summary refs log tree commit diff stats
path: root/compiler/semtempl.nim
diff options
context:
space:
mode:
authorClyybber <darkmine956@gmail.com>2019-09-09 11:54:15 +0200
committerAndreas Rumpf <rumpf_a@web.de>2019-09-09 11:54:15 +0200
commited1d41c51e5b3772fdea9e08733dbf46dfb4428e (patch)
tree48add0b4f759aad5f212894000424df82751eeaa /compiler/semtempl.nim
parentaa95ae6af93e04c5465d76347ab2150bf13d9669 (diff)
downloadNim-ed1d41c51e5b3772fdea9e08733dbf46dfb4428e.tar.gz
Small ast.nim cleanup (#12156)
* Remove sonsLen
* Use Indexable
Diffstat (limited to 'compiler/semtempl.nim')
-rw-r--r--compiler/semtempl.nim40
1 files changed, 20 insertions, 20 deletions
diff --git a/compiler/semtempl.nim b/compiler/semtempl.nim
index bb8748460..8c39a7676 100644
--- a/compiler/semtempl.nim
+++ b/compiler/semtempl.nim
@@ -34,7 +34,7 @@ type
     spNone, spGenSym, spInject
 
 proc symBinding(n: PNode): TSymBinding =
-  for i in 0 ..< sonsLen(n):
+  for i in 0 ..< len(n):
     var it = n.sons[i]
     var key = if it.kind == nkExprColonExpr: it.sons[0] else: it
     if key.kind == nkIdent:
@@ -207,7 +207,7 @@ proc addLocalDecl(c: var TemplCtx, n: var PNode, k: TSymKind) =
     else:
       replaceIdentBySym(c.c, n, ident)
   else:
-    if (n.kind == nkPragmaExpr and sonsLen(n) >= 2 and n.sons[1].kind == nkPragma):
+    if (n.kind == nkPragmaExpr and len(n) >= 2 and n.sons[1].kind == nkPragma):
       let pragmaNode = n.sons[1]
       for i in 0..<pragmaNode.sons.len:
         openScope(c)
@@ -314,12 +314,12 @@ proc semRoutineInTemplBody(c: var TemplCtx, n: PNode, k: TSymKind): PNode =
   closeScope(c)
 
 proc semTemplSomeDecl(c: var TemplCtx, n: PNode, symKind: TSymKind; start=0) =
-  for i in start ..< sonsLen(n):
+  for i in start ..< len(n):
     var a = n.sons[i]
     if a.kind == nkCommentStmt: continue
     if (a.kind != nkIdentDefs) and (a.kind != nkVarTuple): illFormedAst(a, c.c.config)
     checkMinSonsLen(a, 3, c.c.config)
-    var L = sonsLen(a)
+    var L = len(a)
     when defined(nimsuggest):
       inc c.c.inTypeContext
     a.sons[L-2] = semTemplBody(c, a.sons[L-2])
@@ -371,7 +371,7 @@ proc semTemplBody(c: var TemplCtx, n: PNode): PNode =
   of nkEmpty, nkSym..nkNilLit, nkComesFrom:
     discard
   of nkIfStmt:
-    for i in 0 ..< sonsLen(n):
+    for i in 0 ..< len(n):
       var it = n.sons[i]
       if it.len == 2:
         openScope(c)
@@ -382,27 +382,27 @@ proc semTemplBody(c: var TemplCtx, n: PNode): PNode =
         n.sons[i] = semTemplBodyScope(c, it)
   of nkWhileStmt:
     openScope(c)
-    for i in 0 ..< sonsLen(n):
+    for i in 0 ..< len(n):
       n.sons[i] = semTemplBody(c, n.sons[i])
     closeScope(c)
   of nkCaseStmt:
     openScope(c)
     n.sons[0] = semTemplBody(c, n.sons[0])
-    for i in 1 ..< sonsLen(n):
+    for i in 1 ..< len(n):
       var a = n.sons[i]
       checkMinSonsLen(a, 1, c.c.config)
-      var L = sonsLen(a)
+      var L = len(a)
       for j in 0 .. L-2:
         a.sons[j] = semTemplBody(c, a.sons[j])
       a.sons[L-1] = semTemplBodyScope(c, a.sons[L-1])
     closeScope(c)
   of nkForStmt, nkParForStmt:
-    var L = sonsLen(n)
+    var L = len(n)
     openScope(c)
     n.sons[L-2] = semTemplBody(c, n.sons[L-2])
     for i in 0 .. L - 3:
       if n[i].kind == nkVarTuple:
-        for j in 0 ..< sonsLen(n[i])-1:
+        for j in 0 ..< len(n[i])-1:
           addLocalDecl(c, n[i][j], skForVar)
       else:
         addLocalDecl(c, n.sons[i], skForVar)
@@ -427,10 +427,10 @@ proc semTemplBody(c: var TemplCtx, n: PNode): PNode =
   of nkTryStmt, nkHiddenTryStmt:
     checkMinSonsLen(n, 2, c.c.config)
     n.sons[0] = semTemplBodyScope(c, n.sons[0])
-    for i in 1 ..< sonsLen(n):
+    for i in 1 ..< len(n):
       var a = n.sons[i]
       checkMinSonsLen(a, 1, c.c.config)
-      var L = sonsLen(a)
+      var L = len(a)
       openScope(c)
       for j in 0 .. L-2:
         if a.sons[j].isInfixAs():
@@ -447,7 +447,7 @@ proc semTemplBody(c: var TemplCtx, n: PNode): PNode =
     n.sons[0] = semTemplBody(c, n.sons[0])
     semTemplSomeDecl(c, n, skParam, 1)
   of nkConstSection:
-    for i in 0 ..< sonsLen(n):
+    for i in 0 ..< len(n):
       var a = n.sons[i]
       if a.kind == nkCommentStmt: continue
       if (a.kind != nkConstDef): illFormedAst(a, c.c.config)
@@ -456,13 +456,13 @@ proc semTemplBody(c: var TemplCtx, n: PNode): PNode =
       a.sons[1] = semTemplBody(c, a.sons[1])
       a.sons[2] = semTemplBody(c, a.sons[2])
   of nkTypeSection:
-    for i in 0 ..< sonsLen(n):
+    for i in 0 ..< len(n):
       var a = n.sons[i]
       if a.kind == nkCommentStmt: continue
       if (a.kind != nkTypeDef): illFormedAst(a, c.c.config)
       checkSonsLen(a, 3, c.c.config)
       addLocalDecl(c, a.sons[0], skType)
-    for i in 0 ..< sonsLen(n):
+    for i in 0 ..< len(n):
       var a = n.sons[i]
       if a.kind == nkCommentStmt: continue
       if (a.kind != nkTypeDef): illFormedAst(a, c.c.config)
@@ -596,7 +596,7 @@ proc semTemplBodyDirty(c: var TemplCtx, n: PNode): PNode =
       if s != nil and contains(c.toBind, s.id):
         return symChoice(c.c, n, s, scClosed)
     result = n
-    for i in 0 ..< sonsLen(n):
+    for i in 0 ..< len(n):
       result.sons[i] = semTemplBodyDirty(c, n.sons[i])
 
 proc semTemplateDef(c: PContext, n: PNode): PNode =
@@ -642,7 +642,7 @@ proc semTemplateDef(c: PContext, n: PNode): PNode =
       if optNimV019 in c.config.globalOptions:
         param.flags.excl sfGenSym
       if param.typ.kind != tyUntyped: allUntyped = false
-    if sonsLen(gp) > 0:
+    if len(gp) > 0:
       if n.sons[genericParamsPos].kind == nkEmpty:
         # we have a list of implicit type parameters:
         n.sons[genericParamsPos] = gp
@@ -755,7 +755,7 @@ proc semPatternBody(c: var TemplCtx, n: PNode): PNode =
     if stupidStmtListExpr(n):
       result = semPatternBody(c, n.lastSon)
     else:
-      for i in 0 ..< sonsLen(n):
+      for i in 0 ..< len(n):
         result.sons[i] = semPatternBody(c, n.sons[i])
   of nkCallKinds:
     let s = qualifiedLookUp(c.c, n.sons[0], {})
@@ -788,7 +788,7 @@ proc semPatternBody(c: var TemplCtx, n: PNode): PNode =
         result.sons[1] = semPatternBody(c, n.sons[1])
         return
 
-    for i in 0 ..< sonsLen(n):
+    for i in 0 ..< len(n):
       result.sons[i] = semPatternBody(c, n.sons[i])
   else:
     # dotExpr is ambiguous: note that we explicitly allow 'x.TemplateParam',
@@ -804,7 +804,7 @@ proc semPatternBody(c: var TemplCtx, n: PNode): PNode =
     of nkPar:
       if n.len == 1: return semPatternBody(c, n.sons[0])
     else: discard
-    for i in 0 ..< sonsLen(n):
+    for i in 0 ..< len(n):
       result.sons[i] = semPatternBody(c, n.sons[i])
 
 proc semPattern(c: PContext, n: PNode): PNode =