reprjs: style changes
This commit is contained in:
parent
a3df1b55f3
commit
fdcea66fd9
1 changed files with 12 additions and 12 deletions
|
|
@ -44,7 +44,7 @@ proc reprChar(x: char): string {.compilerRtl.} =
|
||||||
case x
|
case x
|
||||||
of '"': add(result, "\\\"")
|
of '"': add(result, "\\\"")
|
||||||
of '\\': add(result, "\\\\")
|
of '\\': add(result, "\\\\")
|
||||||
of '\127'..'\255', '\0'..'\31': add( result, "\\" & reprInt(ord(x)) )
|
of '\127'..'\255', '\0'..'\31': add(result, "\\" & reprInt(ord(x)))
|
||||||
else: add(result, x)
|
else: add(result, x)
|
||||||
add(result, "\'")
|
add(result, "\'")
|
||||||
|
|
||||||
|
|
@ -169,9 +169,9 @@ proc isPointedToNil(p: pointer): bool {.inline.}=
|
||||||
proc reprRef(result: var string, p: pointer, typ: PNimType,
|
proc reprRef(result: var string, p: pointer, typ: PNimType,
|
||||||
cl: var ReprClosure) =
|
cl: var ReprClosure) =
|
||||||
if p.isPointedToNil:
|
if p.isPointedToNil:
|
||||||
add(result , "nil")
|
add(result, "nil")
|
||||||
return
|
return
|
||||||
add( result, "ref " & reprPointer(p) )
|
add(result, "ref " & reprPointer(p))
|
||||||
add(result, " --> ")
|
add(result, " --> ")
|
||||||
if typ.base.kind != tyArray:
|
if typ.base.kind != tyArray:
|
||||||
{. emit: """
|
{. emit: """
|
||||||
|
|
@ -184,8 +184,8 @@ proc reprRef(result: var string, p: pointer, typ: PNimType,
|
||||||
proc reprRecordAux(result: var string, o: pointer, typ: PNimType, cl: var ReprClosure) =
|
proc reprRecordAux(result: var string, o: pointer, typ: PNimType, cl: var ReprClosure) =
|
||||||
add(result, "[")
|
add(result, "[")
|
||||||
|
|
||||||
var first: bool = true
|
var first = true
|
||||||
var val: pointer = o
|
var val = o
|
||||||
if typ.node.len == 0:
|
if typ.node.len == 0:
|
||||||
# if the object has only one field, len is 0 and sons is nil, the field is in node
|
# if the object has only one field, len is 0 and sons is nil, the field is in node
|
||||||
let key: cstring = typ.node.name
|
let key: cstring = typ.node.name
|
||||||
|
|
@ -206,7 +206,7 @@ proc reprRecordAux(result: var string, o: pointer, typ: PNimType, cl: var ReprCl
|
||||||
|
|
||||||
proc reprRecord(o: pointer, typ: PNimType, cl: var ReprClosure): string {.compilerRtl.} =
|
proc reprRecord(o: pointer, typ: PNimType, cl: var ReprClosure): string {.compilerRtl.} =
|
||||||
result = ""
|
result = ""
|
||||||
reprRecordAux(result, o, typ,cl)
|
reprRecordAux(result, o, typ, cl)
|
||||||
|
|
||||||
|
|
||||||
proc reprJsonStringify(p: int): string {.compilerRtl.} =
|
proc reprJsonStringify(p: int): string {.compilerRtl.} =
|
||||||
|
|
@ -224,17 +224,17 @@ proc reprAux(result: var string, p: pointer, typ: PNimType,
|
||||||
dec(cl.recDepth)
|
dec(cl.recDepth)
|
||||||
case typ.kind
|
case typ.kind
|
||||||
of tyInt..tyInt64, tyUInt..tyUInt64:
|
of tyInt..tyInt64, tyUInt..tyUInt64:
|
||||||
add( result, reprInt(cast[int](p)) )
|
add(result, reprInt(cast[int](p)))
|
||||||
of tyChar:
|
of tyChar:
|
||||||
add( result, reprChar(cast[char](p)) )
|
add(result, reprChar(cast[char](p)))
|
||||||
of tyBool:
|
of tyBool:
|
||||||
add( result, reprBool(cast[bool](p)) )
|
add(result, reprBool(cast[bool](p)))
|
||||||
of tyFloat..tyFloat128:
|
of tyFloat..tyFloat128:
|
||||||
add( result, reprFloat(cast[float](p)) )
|
add(result, reprFloat(cast[float](p)))
|
||||||
of tyString:
|
of tyString:
|
||||||
var fp: int
|
var fp: int
|
||||||
{. emit: "`fp` = `p`;\n" .}
|
{. emit: "`fp` = `p`;\n" .}
|
||||||
add( result, reprStr(cast[string](p)) )
|
add(result, reprStr(cast[string](p)))
|
||||||
of tyCString:
|
of tyCString:
|
||||||
var fp: cstring
|
var fp: cstring
|
||||||
{. emit: "`fp` = `p`;\n" .}
|
{. emit: "`fp` = `p`;\n" .}
|
||||||
|
|
@ -265,7 +265,7 @@ proc reprAux(result: var string, p: pointer, typ: PNimType,
|
||||||
else:
|
else:
|
||||||
add(result, reprPointer(p))
|
add(result, reprPointer(p))
|
||||||
else:
|
else:
|
||||||
add( result, "(invalid data!)" & reprJsonStringify(cast[int](p)) )
|
add(result, "(invalid data!)" & reprJsonStringify(cast[int](p)))
|
||||||
inc(cl.recDepth)
|
inc(cl.recDepth)
|
||||||
|
|
||||||
proc reprAny(p: pointer, typ: PNimType): string {.compilerRtl.} =
|
proc reprAny(p: pointer, typ: PNimType): string {.compilerRtl.} =
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue