Merge pull request #3966 from gmpreussner/devel
Fixed negative enum values not getting stringified.
This commit is contained in:
commit
f99d3d5e7d
1 changed files with 8 additions and 8 deletions
|
|
@ -74,22 +74,22 @@ proc reprChar(x: char): string {.compilerRtl.} =
|
||||||
|
|
||||||
proc reprEnum(e: int, typ: PNimType): string {.compilerRtl.} =
|
proc reprEnum(e: int, typ: PNimType): string {.compilerRtl.} =
|
||||||
# we read an 'int' but this may have been too large, so mask the other bits:
|
# we read an 'int' but this may have been too large, so mask the other bits:
|
||||||
let e = if typ.size == 1: e and 0xff
|
let b = (sizeof(int)-typ.size)*8 # bits
|
||||||
elif typ.size == 2: e and 0xffff
|
let m = 1 shl (b-1) # mask
|
||||||
elif typ.size == 4: e and 0xffffffff
|
var o = e and ((1 shl b)-1) # clear upper bits
|
||||||
else: e
|
o = (o xor m) - m # sign extend
|
||||||
# XXX we need a proper narrowing based on signedness here
|
# XXX we need a proper narrowing based on signedness here
|
||||||
#e and ((1 shl (typ.size*8)) - 1)
|
#e and ((1 shl (typ.size*8)) - 1)
|
||||||
if ntfEnumHole notin typ.flags:
|
if ntfEnumHole notin typ.flags:
|
||||||
if e <% typ.node.len:
|
if o <% typ.node.len:
|
||||||
return $typ.node.sons[e].name
|
return $typ.node.sons[o].name
|
||||||
else:
|
else:
|
||||||
# ugh we need a slow linear search:
|
# ugh we need a slow linear search:
|
||||||
var n = typ.node
|
var n = typ.node
|
||||||
var s = n.sons
|
var s = n.sons
|
||||||
for i in 0 .. n.len-1:
|
for i in 0 .. n.len-1:
|
||||||
if s[i].offset == e: return $s[i].name
|
if s[i].offset == o: return $s[i].name
|
||||||
result = $e & " (invalid data!)"
|
result = $o & " (invalid data!)"
|
||||||
|
|
||||||
type
|
type
|
||||||
PByteArray = ptr array[0.. 0xffff, int8]
|
PByteArray = ptr array[0.. 0xffff, int8]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue