summary refs log tree commit diff stats
path: root/rod/ast.nim
diff options
context:
space:
mode:
Diffstat (limited to 'rod/ast.nim')
-rwxr-xr-xrod/ast.nim11
1 files changed, 11 insertions, 0 deletions
diff --git a/rod/ast.nim b/rod/ast.nim
index 7bdfef82c..ba0de6319 100755
--- a/rod/ast.nim
+++ b/rod/ast.nim
@@ -750,6 +750,12 @@ proc newSymNode(sym: PSym): PNode =
   result.typ = sym.typ
   result.info = sym.info
 
+proc newSymNode*(sym: PSym, info: TLineInfo): PNode = 
+  result = newNode(nkSym)
+  result.sym = sym
+  result.typ = sym.typ
+  result.info = info
+
 proc newNodeI(kind: TNodeKind, info: TLineInfo): PNode = 
   result = newNode(kind)
   result.info = info
@@ -869,6 +875,11 @@ proc len*(n: PNode): int {.inline.} =
   if isNil(n.sons): result = 0
   else: result = len(n.sons)
   
+proc safeLen*(n: PNode): int {.inline.} =
+  ## works even for leaves.
+  if n.kind in {nkNone..nkNilLit} or isNil(n.sons): result = 0
+  else: result = len(n.sons)
+  
 proc add*(father, son: PNode) =
   assert son != nil
   if isNil(father.sons): father.sons = @[]