Fixes #5062 (#5527); JS: holes in enums

This commit is contained in:
Silvio 2017-03-15 10:33:37 +01:00 • committed by Andreas Rumpf
commit 51cd3bd86f
9 changed files with 95 additions and 27 deletions

View file

@ -1634,16 +1634,8 @@ proc genRepr(p: PProc, n: PNode, r: var TCompRes) =
of tyEnum, tyOrdinal:
gen(p, n.sons[1], r)
useMagic(p, "cstrToNimstr")
var offset = ""
if t.kind == tyEnum:
let firstFieldOffset = t.n.sons[0].sym.position
if firstFieldOffset < 0:
offset = "+" & $(-firstFieldOffset)
elif firstFieldOffset > 0:
offset = "-" & $firstFieldOffset
r.kind = resExpr
r.res = "cstrToNimstr($1.node.sons[$2$3].name)" % [genTypeInfo(p, t), r.res, rope(offset)]
r.res = "cstrToNimstr($1.node.sons[$2].name)" % [genTypeInfo(p, t), r.res]
else:
# XXX:
internalError(n.info, "genRepr: Not implemented")

View file

@ -104,10 +104,10 @@ proc genEnumInfo(p: PProc, typ: PType, name: Rope) =
let field = typ.n.sons[i].sym
if i > 0: add(s, ", " & tnl)
let extName = if field.ast == nil: field.name.s else: field.ast.strVal
addf(s, "{kind: 1, offset: $1, typ: $2, name: $3, len: 0, sons: null}",
addf(s, "\"$1\": {kind: 1, offset: $1, typ: $2, name: $3, len: 0, sons: null}",
[rope(field.position), name, makeJSString(extName)])
var n = ("var NNI$1 = {kind: 2, offset: 0, typ: null, " &
"name: null, len: $2, sons: [$3]};$n") % [rope(typ.id), rope(length), s]
"name: null, len: $2, sons: {$3}};$n") % [rope(typ.id), rope(length), s]
s = ("var $1 = {size: 0, kind: $2, base: null, node: null, " &
"finalizer: null};$n") % [name, rope(ord(typ.kind))]
prepend(p.g.typeInfo, s)