summary refs log tree commit diff stats
path: root/compiler/ast.nim
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/ast.nim')
-rwxr-xr-xcompiler/ast.nim20
1 files changed, 18 insertions, 2 deletions
diff --git a/compiler/ast.nim b/compiler/ast.nim
index 76260b586..65d7bccf1 100755
--- a/compiler/ast.nim
+++ b/compiler/ast.nim
@@ -189,7 +189,8 @@ type
     nkProcTy,             # proc type
     nkEnumTy,             # enum body
     nkEnumFieldDef,       # `ident = expr` in an enumeration
-    nkReturnToken         # token used for interpretation
+    nkReturnToken,        # token used for interpretation
+    nkClosure             # (prc, env)-pair (internally used for code gen)
   TNodeKinds* = set[TNodeKind]
 
 type
@@ -220,7 +221,7 @@ type
     sfDiscriminant,   # field is a discriminant in a record/object
     sfDeprecated,     # symbol is deprecated
     sfError,          # usage of symbol should trigger a compile-time error
-    sfInClosure,      # variable is accessed by a closure
+    sfInnerProc,      # proc is an inner proc
     sfThread,         # proc will run as a thread
                       # variable is a thread variable
     sfCompileTime,    # proc can be evaluated at compile time
@@ -976,6 +977,14 @@ proc hasSonWith(n: PNode, kind: TNodeKind): bool =
       return true
   result = false
 
+proc containsNode*(n: PNode, kinds: TNodeKinds): bool =
+  if n == nil: return
+  case n.kind
+  of nkEmpty..nkNilLit: result = n.kind in kinds
+  else:
+    for i in countup(0, sonsLen(n) - 1):
+      if n.kind in kinds or containsNode(n.sons[i], kinds): return true
+
 proc hasSubnodeWith(n: PNode, kind: TNodeKind): bool = 
   case n.kind
   of nkEmpty..nkNilLit: result = n.kind == kind
@@ -1030,3 +1039,10 @@ proc isGenericRoutine*(s: PSym): bool =
     result = s.ast != nil and s.ast[genericParamsPos].kind != nkEmpty
   else: nil
 
+proc isRoutine*(s: PSym): bool {.inline.} =
+  result = s.kind in {skProc, skTemplate, skMacro, skIterator, skMethod,
+                      skConverter}
+
+iterator items*(n: PNode): PNode =
+  for i in 0.. <n.len: yield n.sons[i]
+