parent
a58c982a49
commit
7a5b614edc
4 changed files with 50 additions and 11 deletions
|
|
@ -71,7 +71,7 @@ proc genVarTuple(p: BProc, n: PNode) =
|
||||||
field.r = "$1.Field$2" % [rdLoc(tup), rope(i)]
|
field.r = "$1.Field$2" % [rdLoc(tup), rope(i)]
|
||||||
else:
|
else:
|
||||||
if t.n.sons[i].kind != nkSym: internalError(p.config, n.info, "genVarTuple")
|
if t.n.sons[i].kind != nkSym: internalError(p.config, n.info, "genVarTuple")
|
||||||
field.r = "$1.$2" % [rdLoc(tup), mangleRecFieldName(p.module, t.n.sons[i].sym, t)]
|
field.r = "$1.$2" % [rdLoc(tup), mangleRecFieldName(p.module, t.n.sons[i].sym)]
|
||||||
putLocIntoDest(p, v.loc, field)
|
putLocIntoDest(p, v.loc, field)
|
||||||
|
|
||||||
proc genDeref(p: BProc, e: PNode, d: var TLoc; enforceDeref=false)
|
proc genDeref(p: BProc, e: PNode, d: var TLoc; enforceDeref=false)
|
||||||
|
|
|
||||||
|
|
@ -430,9 +430,8 @@ proc genProcParams(m: BModule, t: PType, rettype, params: var Rope,
|
||||||
else: add(params, ")")
|
else: add(params, ")")
|
||||||
params = "(" & params
|
params = "(" & params
|
||||||
|
|
||||||
proc mangleRecFieldName(m: BModule; field: PSym, rectype: PType): Rope =
|
proc mangleRecFieldName(m: BModule; field: PSym): Rope =
|
||||||
if (rectype.sym != nil) and
|
if {sfImportc, sfExportc} * field.flags != {}:
|
||||||
({sfImportc, sfExportc} * rectype.sym.flags != {}):
|
|
||||||
result = field.loc.r
|
result = field.loc.r
|
||||||
else:
|
else:
|
||||||
result = rope(mangleField(m, field.name))
|
result = rope(mangleField(m, field.name))
|
||||||
|
|
@ -484,7 +483,7 @@ proc genRecordFieldsAux(m: BModule, n: PNode,
|
||||||
let field = n.sym
|
let field = n.sym
|
||||||
if field.typ.kind == tyVoid: return
|
if field.typ.kind == tyVoid: return
|
||||||
#assert(field.ast == nil)
|
#assert(field.ast == nil)
|
||||||
let sname = mangleRecFieldName(m, field, rectype)
|
let sname = mangleRecFieldName(m, field)
|
||||||
let ae = if accessExpr != nil: "$1.$2" % [accessExpr, sname]
|
let ae = if accessExpr != nil: "$1.$2" % [accessExpr, sname]
|
||||||
else: sname
|
else: sname
|
||||||
fillLoc(field.loc, locField, n, ae, OnUnknown)
|
fillLoc(field.loc, locField, n, ae, OnUnknown)
|
||||||
|
|
|
||||||
|
|
@ -587,12 +587,12 @@ proc semCaseBranch(c: PContext, t, branch: PNode, branchIndex: int,
|
||||||
checkForOverlap(c, t, i, branchIndex)
|
checkForOverlap(c, t, i, branchIndex)
|
||||||
|
|
||||||
proc semRecordNodeAux(c: PContext, n: PNode, check: var IntSet, pos: var int,
|
proc semRecordNodeAux(c: PContext, n: PNode, check: var IntSet, pos: var int,
|
||||||
father: PNode, rectype: PType)
|
father: PNode, rectype: PType, hasCaseFields = false)
|
||||||
proc semRecordCase(c: PContext, n: PNode, check: var IntSet, pos: var int,
|
proc semRecordCase(c: PContext, n: PNode, check: var IntSet, pos: var int,
|
||||||
father: PNode, rectype: PType) =
|
father: PNode, rectype: PType) =
|
||||||
var a = copyNode(n)
|
var a = copyNode(n)
|
||||||
checkMinSonsLen(n, 2, c.config)
|
checkMinSonsLen(n, 2, c.config)
|
||||||
semRecordNodeAux(c, n.sons[0], check, pos, a, rectype)
|
semRecordNodeAux(c, n.sons[0], check, pos, a, rectype, hasCaseFields = true)
|
||||||
if a.sons[0].kind != nkSym:
|
if a.sons[0].kind != nkSym:
|
||||||
internalError(c.config, "semRecordCase: discriminant is no symbol")
|
internalError(c.config, "semRecordCase: discriminant is no symbol")
|
||||||
return
|
return
|
||||||
|
|
@ -619,13 +619,13 @@ proc semRecordCase(c: PContext, n: PNode, check: var IntSet, pos: var int,
|
||||||
checkSonsLen(b, 1, c.config)
|
checkSonsLen(b, 1, c.config)
|
||||||
else: illFormedAst(n, c.config)
|
else: illFormedAst(n, c.config)
|
||||||
delSon(b, sonsLen(b) - 1)
|
delSon(b, sonsLen(b) - 1)
|
||||||
semRecordNodeAux(c, lastSon(n.sons[i]), check, pos, b, rectype)
|
semRecordNodeAux(c, lastSon(n.sons[i]), check, pos, b, rectype, hasCaseFields = true)
|
||||||
if chckCovered and covered != lengthOrd(c.config, a.sons[0].typ):
|
if chckCovered and covered != lengthOrd(c.config, a.sons[0].typ):
|
||||||
localError(c.config, a.info, "not all cases are covered")
|
localError(c.config, a.info, "not all cases are covered")
|
||||||
addSon(father, a)
|
addSon(father, a)
|
||||||
|
|
||||||
proc semRecordNodeAux(c: PContext, n: PNode, check: var IntSet, pos: var int,
|
proc semRecordNodeAux(c: PContext, n: PNode, check: var IntSet, pos: var int,
|
||||||
father: PNode, rectype: PType) =
|
father: PNode, rectype: PType, hasCaseFields = false) =
|
||||||
if n == nil: return
|
if n == nil: return
|
||||||
case n.kind
|
case n.kind
|
||||||
of nkRecWhen:
|
of nkRecWhen:
|
||||||
|
|
@ -694,7 +694,7 @@ proc semRecordNodeAux(c: PContext, n: PNode, check: var IntSet, pos: var int,
|
||||||
f.position = pos
|
f.position = pos
|
||||||
if fieldOwner != nil and
|
if fieldOwner != nil and
|
||||||
{sfImportc, sfExportc} * fieldOwner.flags != {} and
|
{sfImportc, sfExportc} * fieldOwner.flags != {} and
|
||||||
f.loc.r == nil:
|
not hasCaseFields and f.loc.r == nil:
|
||||||
f.loc.r = rope(f.name.s)
|
f.loc.r = rope(f.name.s)
|
||||||
f.flags = f.flags + ({sfImportc, sfExportc} * fieldOwner.flags)
|
f.flags = f.flags + ({sfImportc, sfExportc} * fieldOwner.flags)
|
||||||
inc(pos)
|
inc(pos)
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
discard """
|
discard """
|
||||||
file: "tcgbug.nim"
|
file: "tcgbug.nim"
|
||||||
output: "success"
|
output: '''success
|
||||||
|
M1 M2
|
||||||
|
'''
|
||||||
"""
|
"""
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
@ -36,3 +38,41 @@ type
|
||||||
|
|
||||||
var k = PFuture[void]()
|
var k = PFuture[void]()
|
||||||
|
|
||||||
|
|
||||||
|
##bug #9297
|
||||||
|
import strutils
|
||||||
|
|
||||||
|
type
|
||||||
|
MyKind = enum
|
||||||
|
M1, M2, M3
|
||||||
|
|
||||||
|
MyObject {.exportc: "ExtObject"} = object
|
||||||
|
case kind: MyKind
|
||||||
|
of M1: a:int
|
||||||
|
of M2: b:float
|
||||||
|
of M3: c:cstring
|
||||||
|
|
||||||
|
MyObjectRef {.exportc: "ExtObject2"} = ref object
|
||||||
|
case kind: MyKind
|
||||||
|
of M1: a:int
|
||||||
|
of M2: b:float
|
||||||
|
of M3: c:cstring
|
||||||
|
|
||||||
|
proc newMyObject(kind: MyKind, val: string): MyObject =
|
||||||
|
result.kind = kind
|
||||||
|
|
||||||
|
case kind
|
||||||
|
of M1: result.a = parseInt(val)
|
||||||
|
of M2: result.b = parseFloat(val)
|
||||||
|
of M3: result.c = val
|
||||||
|
|
||||||
|
proc newMyObjectRef(kind: MyKind, val: string): MyObjectRef =
|
||||||
|
new(result)
|
||||||
|
result.kind = kind
|
||||||
|
case kind
|
||||||
|
of M1: result.a = parseInt(val)
|
||||||
|
of M2: result.b = parseFloat(val)
|
||||||
|
of M3: result.c = val
|
||||||
|
|
||||||
|
|
||||||
|
echo newMyObject(M1, "2").kind, " ", newMyObjectRef(M2, "3").kind
|
||||||
Loading…
Add table
Add a link
Reference in a new issue