* fixes #8916 by removing `tyString`, `tySeq`, mod. marshal, typeinfo Need to check in `typeinfo` for nil of the underlying pointer. In marshal don't have to check for nil of seq anymore. * remove reference to string, sequence in `isNil` doc string
This commit is contained in:
parent
c495e97ec4
commit
9cdd9be5a5
3 changed files with 29 additions and 15 deletions
|
|
@ -228,8 +228,14 @@ proc `[]=`*(x: Any, i: int, y: Any) =
|
||||||
proc len*(x: Any): int =
|
proc len*(x: Any): int =
|
||||||
## len for an any `x` that represents an array or a sequence.
|
## len for an any `x` that represents an array or a sequence.
|
||||||
case x.rawType.kind
|
case x.rawType.kind
|
||||||
of tyArray: result = x.rawType.size div x.rawType.base.size
|
of tyArray:
|
||||||
of tySequence: result = cast[PGenSeq](cast[ppointer](x.value)[]).len
|
result = x.rawType.size div x.rawType.base.size
|
||||||
|
of tySequence:
|
||||||
|
let pgenSeq = cast[PGenSeq](cast[ppointer](x.value)[])
|
||||||
|
if isNil(pgenSeq):
|
||||||
|
result = 0
|
||||||
|
else:
|
||||||
|
result = pgenSeq.len
|
||||||
else: assert false
|
else: assert false
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -240,10 +246,9 @@ proc base*(x: Any): Any =
|
||||||
|
|
||||||
|
|
||||||
proc isNil*(x: Any): bool =
|
proc isNil*(x: Any): bool =
|
||||||
## `isNil` for an any `x` that represents a sequence, string, cstring,
|
## `isNil` for an any `x` that represents a cstring, proc or
|
||||||
## proc or some pointer type.
|
## some pointer type.
|
||||||
assert x.rawType.kind in {tyString, tyCString, tyRef, tyPtr, tyPointer,
|
assert x.rawType.kind in {tyCString, tyRef, tyPtr, tyPointer, tyProc}
|
||||||
tySequence, tyProc}
|
|
||||||
result = isNil(cast[ppointer](x.value)[])
|
result = isNil(cast[ppointer](x.value)[])
|
||||||
|
|
||||||
proc getPointer*(x: Any): pointer =
|
proc getPointer*(x: Any): pointer =
|
||||||
|
|
@ -716,5 +721,3 @@ when isMainModule:
|
||||||
for i in 0 .. m.len-1:
|
for i in 0 .. m.len-1:
|
||||||
for j in 0 .. m[i].len-1:
|
for j in 0 .. m[i].len-1:
|
||||||
echo getString(m[i][j])
|
echo getString(m[i][j])
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -54,8 +54,6 @@ proc storeAny(s: Stream, a: Any, stored: var IntSet) =
|
||||||
else:
|
else:
|
||||||
s.write($int(ch))
|
s.write($int(ch))
|
||||||
of akArray, akSequence:
|
of akArray, akSequence:
|
||||||
if a.kind == akSequence and isNil(a): s.write("null")
|
|
||||||
else:
|
|
||||||
s.write("[")
|
s.write("[")
|
||||||
for i in 0 .. a.len-1:
|
for i in 0 .. a.len-1:
|
||||||
if i > 0: s.write(", ")
|
if i > 0: s.write(", ")
|
||||||
|
|
|
||||||
|
|
@ -105,3 +105,16 @@ r = to[Something](data2)
|
||||||
|
|
||||||
echo r.x, " ", r.y
|
echo r.x, " ", r.y
|
||||||
|
|
||||||
|
|
||||||
|
type
|
||||||
|
Foo = object
|
||||||
|
a1: string
|
||||||
|
a2: string
|
||||||
|
a3: seq[string]
|
||||||
|
a4: seq[int]
|
||||||
|
a5: seq[int]
|
||||||
|
a6: seq[int]
|
||||||
|
var foo = Foo(a2: "", a4: @[], a6: @[1])
|
||||||
|
foo.a6.setLen 0
|
||||||
|
doAssert $$foo == """{"a1": "", "a2": "", "a3": [], "a4": [], "a5": [], "a6": []}"""
|
||||||
|
testit(foo)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue