getTypeImpl now returns pragmas for object types (#9538)

This commit is contained in:
jcosborn 2018-10-30 00:41:12 -05:00 • committed by Andreas Rumpf
commit 69c0a9c6fb
2 changed files with 25 additions and 9 deletions

View file

@ -82,12 +82,9 @@ proc mapTypeToAstX(cache: IdentCache; t: PType; info: TLineInfo;
id id
template newIdentDefs(s): untyped = newIdentDefs(s, s.typ) template newIdentDefs(s): untyped = newIdentDefs(s, s.typ)
if inst: if inst and not allowRecursion and t.sym != nil:
if t.sym != nil: # if this node has a symbol # getTypeInst behavior: return symbol
if not allowRecursion: # getTypeInst behavior: return symbol
return atomicType(t.sym) return atomicType(t.sym)
#else: # getTypeImpl behavior: turn off recursion
# allowRecursion = false
case t.kind case t.kind
of tyNone: result = atomicType("none", mNone) of tyNone: result = atomicType("none", mNone)
@ -160,9 +157,10 @@ proc mapTypeToAstX(cache: IdentCache; t: PType; info: TLineInfo;
of tyObject: of tyObject:
if inst: if inst:
result = newNodeX(nkObjectTy) result = newNodeX(nkObjectTy)
result.add newNodeI(nkEmpty, info) # pragmas not reconstructed yet result.add t.sym.ast[2][0].copyTree # copy object pragmas
if t.sons[0] == nil: result.add newNodeI(nkEmpty, info) # handle parent object if t.sons[0] == nil:
else: result.add newNodeI(nkEmpty, info)
else: # handle parent object
var nn = newNodeX(nkOfInherit) var nn = newNodeX(nkOfInherit)
nn.add mapTypeToAst(t.sons[0], info) nn.add mapTypeToAst(t.sons[0], info)
result.add nn result.add nn

View file

@ -183,3 +183,21 @@ test(Vec4[float32]):
# bug #4862 # bug #4862
static: static:
discard typedesc[(int, int)].getTypeImpl discard typedesc[(int, int)].getTypeImpl
# custom pragmas
template myAttr() {.pragma.}
template myAttr2() {.pragma.}
template myAttr3() {.pragma.}
template serializationKey(key: string) {.pragma.}
type
MyObj = object {.packed,myAttr,serializationKey: "one".}
myField {.myAttr2,serializationKey: "two".}: int
myField2 {.myAttr3,serializationKey: "three".}: float
# field pragmas not currently supported
test(MyObj):
type
_ = object {.packed,myAttr,serializationKey: "one".}
myField: int
myField2: float