diff options
Diffstat (limited to 'compiler/ast.nim')
-rw-r--r-- | compiler/ast.nim | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/compiler/ast.nim b/compiler/ast.nim index 0cc4daf22..f9b43ed13 100644 --- a/compiler/ast.nim +++ b/compiler/ast.nim @@ -1009,6 +1009,12 @@ proc safeLen*(n: PNode): int {.inline.} = if n.kind in {nkNone..nkNilLit} or isNil(n.sons): result = 0 else: result = len(n.sons) +proc safeArrLen*(n: PNode): int {.inline.} = + ## works for array-like objects (strings passed as openArray in VM). + if n.kind in {nkStrLit..nkTripleStrLit}:result = len(n.strVal) + elif n.kind in {nkNone..nkFloat128Lit}: result = 0 + else: result = len(n) + proc add*(father, son: PNode) = assert son != nil if isNil(father.sons): father.sons = @[] |